mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-10-08 14:54:36 +00:00
commit
230ae028e0
2 changed files with 72 additions and 63 deletions
|
|
@ -14,6 +14,12 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"versions": {
|
"versions": {
|
||||||
|
"2.0.0": {
|
||||||
|
"api_version": 8,
|
||||||
|
"commit_sha": "a941899",
|
||||||
|
"released_on": "20-07-2023",
|
||||||
|
"md5sum": "19f033445a8fe30fc7f4f62d94a54444"
|
||||||
|
},
|
||||||
"1.0.0": {
|
"1.0.0": {
|
||||||
"api_version": 7,
|
"api_version": 7,
|
||||||
"commit_sha": "e59073b",
|
"commit_sha": "e59073b",
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,20 @@
|
||||||
# BY Stary_Agent
|
# BY Stary_Agent
|
||||||
"""Hockey game and support classes."""
|
"""Hockey game and support classes."""
|
||||||
|
|
||||||
# ba_meta require api 7
|
# ba_meta require api 8
|
||||||
# (see https://ballistica.net/wiki/meta-tag-system)
|
# (see https://ballistica.net/wiki/meta-tag-system)
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import ba
|
import babase
|
||||||
from bastd.actor.playerspaz import PlayerSpaz
|
import bauiv1 as bui
|
||||||
from bastd.actor.scoreboard import Scoreboard
|
import bascenev1 as bs
|
||||||
from bastd.actor.powerupbox import PowerupBoxFactory
|
from bascenev1lib.actor.playerspaz import PlayerSpaz
|
||||||
from bastd.gameutils import SharedObjects
|
from bascenev1lib.actor.scoreboard import Scoreboard
|
||||||
|
from bascenev1lib.actor.powerupbox import PowerupBoxFactory
|
||||||
|
from bascenev1lib.gameutils import SharedObjects
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Any, Sequence, Dict, Type, List, Optional, Union
|
from typing import Any, Sequence, Dict, Type, List, Optional, Union
|
||||||
|
|
@ -26,7 +28,7 @@ class PuckDiedMessage:
|
||||||
self.puck = puck
|
self.puck = puck
|
||||||
|
|
||||||
|
|
||||||
class Puck(ba.Actor):
|
class Puck(bs.Actor):
|
||||||
"""A lovely giant hockey puck."""
|
"""A lovely giant hockey puck."""
|
||||||
|
|
||||||
def __init__(self, position: Sequence[float] = (0.0, 1.0, 0.0)):
|
def __init__(self, position: Sequence[float] = (0.0, 1.0, 0.0)):
|
||||||
|
|
@ -41,10 +43,10 @@ class Puck(ba.Actor):
|
||||||
assert activity is not None
|
assert activity is not None
|
||||||
assert isinstance(activity, HockeyGame)
|
assert isinstance(activity, HockeyGame)
|
||||||
pmats = [shared.object_material, activity.puck_material]
|
pmats = [shared.object_material, activity.puck_material]
|
||||||
self.node = ba.newnode('prop',
|
self.node = bs.newnode('prop',
|
||||||
delegate=self,
|
delegate=self,
|
||||||
attrs={
|
attrs={
|
||||||
'model': activity.puck_model,
|
'mesh': activity.puck_model,
|
||||||
'color_texture': activity.puck_tex,
|
'color_texture': activity.puck_tex,
|
||||||
'body': 'sphere',
|
'body': 'sphere',
|
||||||
'reflection': 'soft',
|
'reflection': 'soft',
|
||||||
|
|
@ -54,10 +56,10 @@ class Puck(ba.Actor):
|
||||||
'position': self._spawn_pos,
|
'position': self._spawn_pos,
|
||||||
'materials': pmats
|
'materials': pmats
|
||||||
})
|
})
|
||||||
ba.animate(self.node, 'model_scale', {0: 0, 0.2: 1.3, 0.26: 1})
|
bs.animate(self.node, 'mesh_scale', {0: 0, 0.2: 1.3, 0.26: 1})
|
||||||
|
|
||||||
def handlemessage(self, msg: Any) -> Any:
|
def handlemessage(self, msg: Any) -> Any:
|
||||||
if isinstance(msg, ba.DieMessage):
|
if isinstance(msg, bs.DieMessage):
|
||||||
assert self.node
|
assert self.node
|
||||||
self.node.delete()
|
self.node.delete()
|
||||||
activity = self._activity()
|
activity = self._activity()
|
||||||
|
|
@ -65,11 +67,11 @@ class Puck(ba.Actor):
|
||||||
activity.handlemessage(PuckDiedMessage(self))
|
activity.handlemessage(PuckDiedMessage(self))
|
||||||
|
|
||||||
# If we go out of bounds, move back to where we started.
|
# If we go out of bounds, move back to where we started.
|
||||||
elif isinstance(msg, ba.OutOfBoundsMessage):
|
elif isinstance(msg, bs.OutOfBoundsMessage):
|
||||||
assert self.node
|
assert self.node
|
||||||
self.node.position = self._spawn_pos
|
self.node.position = self._spawn_pos
|
||||||
|
|
||||||
elif isinstance(msg, ba.HitMessage):
|
elif isinstance(msg, bs.HitMessage):
|
||||||
assert self.node
|
assert self.node
|
||||||
assert msg.force_direction is not None
|
assert msg.force_direction is not None
|
||||||
self.node.handlemessage(
|
self.node.handlemessage(
|
||||||
|
|
@ -90,31 +92,31 @@ class Puck(ba.Actor):
|
||||||
super().handlemessage(msg)
|
super().handlemessage(msg)
|
||||||
|
|
||||||
|
|
||||||
class Player(ba.Player['Team']):
|
class Player(bs.Player['Team']):
|
||||||
"""Our player type for this game."""
|
"""Our player type for this game."""
|
||||||
|
|
||||||
|
|
||||||
class Team(ba.Team[Player]):
|
class Team(bs.Team[Player]):
|
||||||
"""Our team type for this game."""
|
"""Our team type for this game."""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
|
||||||
|
|
||||||
# ba_meta export game
|
# ba_meta export bascenev1.GameActivity
|
||||||
class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
class HockeyGame(bs.TeamGameActivity[Player, Team]):
|
||||||
"""Ice hockey game."""
|
"""Ice hockey game."""
|
||||||
|
|
||||||
name = 'Epic Soccer'
|
name = 'Epic Soccer'
|
||||||
description = 'Score some goals.'
|
description = 'Score some goals.'
|
||||||
available_settings = [
|
available_settings = [
|
||||||
ba.IntSetting(
|
bs.IntSetting(
|
||||||
'Score to Win',
|
'Score to Win',
|
||||||
min_value=1,
|
min_value=1,
|
||||||
default=1,
|
default=1,
|
||||||
increment=1,
|
increment=1,
|
||||||
),
|
),
|
||||||
ba.IntChoiceSetting(
|
bs.IntChoiceSetting(
|
||||||
'Time Limit',
|
'Time Limit',
|
||||||
choices=[
|
choices=[
|
||||||
('None', 0),
|
('None', 0),
|
||||||
|
|
@ -126,7 +128,7 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
],
|
],
|
||||||
default=0,
|
default=0,
|
||||||
),
|
),
|
||||||
ba.FloatChoiceSetting(
|
bs.FloatChoiceSetting(
|
||||||
'Respawn Times',
|
'Respawn Times',
|
||||||
choices=[
|
choices=[
|
||||||
('Shorter', 0.1),
|
('Shorter', 0.1),
|
||||||
|
|
@ -138,31 +140,32 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
default=1.0,
|
default=1.0,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
default_music = ba.MusicType.HOCKEY
|
default_music = bs.MusicType.HOCKEY
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def supports_session_type(cls, sessiontype: Type[ba.Session]) -> bool:
|
def supports_session_type(cls, sessiontype: Type[bs.Session]) -> bool:
|
||||||
return issubclass(sessiontype, ba.DualTeamSession)
|
return issubclass(sessiontype, bs.DualTeamSession)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_supported_maps(cls, sessiontype: Type[ba.Session]) -> List[str]:
|
def get_supported_maps(cls, sessiontype: Type[bs.Session]) -> List[str]:
|
||||||
return ba.getmaps('football')
|
assert babase.app.classic is not None
|
||||||
|
return babase.app.classic.getmaps('football')
|
||||||
|
|
||||||
def __init__(self, settings: dict):
|
def __init__(self, settings: dict):
|
||||||
super().__init__(settings)
|
super().__init__(settings)
|
||||||
shared = SharedObjects.get()
|
shared = SharedObjects.get()
|
||||||
self.slow_motion = True
|
self.slow_motion = True
|
||||||
self._scoreboard = Scoreboard()
|
self._scoreboard = Scoreboard()
|
||||||
self._cheer_sound = ba.getsound('cheer')
|
self._cheer_sound = bui.getsound('cheer')
|
||||||
self._chant_sound = ba.getsound('crowdChant')
|
self._chant_sound = bui.getsound('crowdChant')
|
||||||
self._foghorn_sound = ba.getsound('foghorn')
|
self._foghorn_sound = bui.getsound('foghorn')
|
||||||
self._swipsound = ba.getsound('swip')
|
self._swipsound = bui.getsound('swip')
|
||||||
self._whistle_sound = ba.getsound('refWhistle')
|
self._whistle_sound = bui.getsound('refWhistle')
|
||||||
self.puck_model = ba.getmodel('bomb')
|
self.puck_model = bs.getmesh('bomb')
|
||||||
self.puck_tex = ba.gettexture('landMine')
|
self.puck_tex = bs.gettexture('landMine')
|
||||||
self.puck_scored_tex = ba.gettexture('landMineLit')
|
self.puck_scored_tex = bs.gettexture('landMineLit')
|
||||||
self._puck_sound = ba.getsound('metalHit')
|
self._puck_sound = bs.getsound('metalHit')
|
||||||
self.puck_material = ba.Material()
|
self.puck_material = bs.Material()
|
||||||
self.puck_material.add_actions(actions=(('modify_part_collision',
|
self.puck_material.add_actions(actions=(('modify_part_collision',
|
||||||
'friction', 0.5)))
|
'friction', 0.5)))
|
||||||
self.puck_material.add_actions(conditions=('they_have_material',
|
self.puck_material.add_actions(conditions=('they_have_material',
|
||||||
|
|
@ -193,15 +196,15 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
conditions=('they_have_material',
|
conditions=('they_have_material',
|
||||||
PowerupBoxFactory.get().powerup_material),
|
PowerupBoxFactory.get().powerup_material),
|
||||||
actions=(('modify_part_collision', 'physical', False),
|
actions=(('modify_part_collision', 'physical', False),
|
||||||
('message', 'their_node', 'at_connect', ba.DieMessage())))
|
('message', 'their_node', 'at_connect', bs.DieMessage())))
|
||||||
self._score_region_material = ba.Material()
|
self._score_region_material = bs.Material()
|
||||||
self._score_region_material.add_actions(
|
self._score_region_material.add_actions(
|
||||||
conditions=('they_have_material', self.puck_material),
|
conditions=('they_have_material', self.puck_material),
|
||||||
actions=(('modify_part_collision', 'collide',
|
actions=(('modify_part_collision', 'collide',
|
||||||
True), ('modify_part_collision', 'physical', False),
|
True), ('modify_part_collision', 'physical', False),
|
||||||
('call', 'at_connect', self._handle_score)))
|
('call', 'at_connect', self._handle_score)))
|
||||||
self._puck_spawn_pos: Optional[Sequence[float]] = None
|
self._puck_spawn_pos: Optional[Sequence[float]] = None
|
||||||
self._score_regions: Optional[List[ba.NodeActor]] = None
|
self._score_regions: Optional[List[bs.NodeActor]] = None
|
||||||
self._puck: Optional[Puck] = None
|
self._puck: Optional[Puck] = None
|
||||||
self._score_to_win = int(settings['Score to Win'])
|
self._score_to_win = int(settings['Score to Win'])
|
||||||
self._time_limit = float(settings['Time Limit'])
|
self._time_limit = float(settings['Time Limit'])
|
||||||
|
|
@ -228,8 +231,8 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
defs = self.map.defs
|
defs = self.map.defs
|
||||||
self._score_regions = []
|
self._score_regions = []
|
||||||
self._score_regions.append(
|
self._score_regions.append(
|
||||||
ba.NodeActor(
|
bs.NodeActor(
|
||||||
ba.newnode('region',
|
bs.newnode('region',
|
||||||
attrs={
|
attrs={
|
||||||
'position': defs.boxes['goal1'][0:3],
|
'position': defs.boxes['goal1'][0:3],
|
||||||
'scale': defs.boxes['goal1'][6:9],
|
'scale': defs.boxes['goal1'][6:9],
|
||||||
|
|
@ -237,8 +240,8 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
'materials': [self._score_region_material]
|
'materials': [self._score_region_material]
|
||||||
})))
|
})))
|
||||||
self._score_regions.append(
|
self._score_regions.append(
|
||||||
ba.NodeActor(
|
bs.NodeActor(
|
||||||
ba.newnode('region',
|
bs.newnode('region',
|
||||||
attrs={
|
attrs={
|
||||||
'position': defs.boxes['goal2'][0:3],
|
'position': defs.boxes['goal2'][0:3],
|
||||||
'scale': defs.boxes['goal2'][6:9],
|
'scale': defs.boxes['goal2'][6:9],
|
||||||
|
|
@ -246,19 +249,19 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
'materials': [self._score_region_material]
|
'materials': [self._score_region_material]
|
||||||
})))
|
})))
|
||||||
self._update_scoreboard()
|
self._update_scoreboard()
|
||||||
ba.playsound(self._chant_sound)
|
self._chant_sound.play()
|
||||||
|
|
||||||
def on_team_join(self, team: Team) -> None:
|
def on_team_join(self, team: Team) -> None:
|
||||||
self._update_scoreboard()
|
self._update_scoreboard()
|
||||||
|
|
||||||
def _handle_puck_player_collide(self) -> None:
|
def _handle_puck_player_collide(self) -> None:
|
||||||
collision = ba.getcollision()
|
collision = bs.getcollision()
|
||||||
try:
|
try:
|
||||||
puck = collision.sourcenode.getdelegate(Puck, True)
|
puck = collision.sourcenode.getdelegate(Puck, True)
|
||||||
player = collision.opposingnode.getdelegate(PlayerSpaz,
|
player = collision.opposingnode.getdelegate(PlayerSpaz,
|
||||||
True).getplayer(
|
True).getplayer(
|
||||||
Player, True)
|
Player, True)
|
||||||
except ba.NotFoundError:
|
except bs.NotFoundError:
|
||||||
return
|
return
|
||||||
|
|
||||||
puck.last_players_to_touch[player.team.id] = player
|
puck.last_players_to_touch[player.team.id] = player
|
||||||
|
|
@ -277,7 +280,7 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
if self._puck.scored:
|
if self._puck.scored:
|
||||||
return
|
return
|
||||||
|
|
||||||
region = ba.getcollision().sourcenode
|
region = bs.getcollision().sourcenode
|
||||||
index = 0
|
index = 0
|
||||||
for index in range(len(self._score_regions)):
|
for index in range(len(self._score_regions)):
|
||||||
if region == self._score_regions[index].node:
|
if region == self._score_regions[index].node:
|
||||||
|
|
@ -291,7 +294,7 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
# Tell all players to celebrate.
|
# Tell all players to celebrate.
|
||||||
for player in team.players:
|
for player in team.players:
|
||||||
if player.actor:
|
if player.actor:
|
||||||
player.actor.handlemessage(ba.CelebrateMessage(2.0))
|
player.actor.handlemessage(bs.CelebrateMessage(2.0))
|
||||||
|
|
||||||
# If we've got the player from the scoring team that last
|
# If we've got the player from the scoring team that last
|
||||||
# touched us, give them points.
|
# touched us, give them points.
|
||||||
|
|
@ -306,30 +309,30 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
if team.score >= self._score_to_win:
|
if team.score >= self._score_to_win:
|
||||||
self.end_game()
|
self.end_game()
|
||||||
|
|
||||||
ba.playsound(self._foghorn_sound)
|
self._foghorn_sound.play()
|
||||||
ba.playsound(self._cheer_sound)
|
self._cheer_sound.play()
|
||||||
|
|
||||||
self._puck.scored = True
|
self._puck.scored = True
|
||||||
|
|
||||||
# Change puck texture to something cool
|
# Change puck texture to something cool
|
||||||
self._puck.node.color_texture = self.puck_scored_tex
|
self._puck.node.color_texture = self.puck_scored_tex
|
||||||
# Kill the puck (it'll respawn itself shortly).
|
# Kill the puck (it'll respawn itself shortly).
|
||||||
ba.timer(1.0, self._kill_puck)
|
bs.timer(1.0, self._kill_puck)
|
||||||
|
|
||||||
light = ba.newnode('light',
|
light = bs.newnode('light',
|
||||||
attrs={
|
attrs={
|
||||||
'position': ba.getcollision().position,
|
'position': bs.getcollision().position,
|
||||||
'height_attenuated': False,
|
'height_attenuated': False,
|
||||||
'color': (1, 0, 0)
|
'color': (1, 0, 0)
|
||||||
})
|
})
|
||||||
ba.animate(light, 'intensity', {0: 0, 0.5: 1, 1.0: 0}, loop=True)
|
bs.animate(light, 'intensity', {0: 0, 0.5: 1, 1.0: 0}, loop=True)
|
||||||
ba.timer(1.0, light.delete)
|
bs.timer(1.0, light.delete)
|
||||||
|
|
||||||
ba.cameraflash(duration=10.0)
|
bs.cameraflash(duration=10.0)
|
||||||
self._update_scoreboard()
|
self._update_scoreboard()
|
||||||
|
|
||||||
def end_game(self) -> None:
|
def end_game(self) -> None:
|
||||||
results = ba.GameResults()
|
results = bs.GameResults()
|
||||||
for team in self.teams:
|
for team in self.teams:
|
||||||
results.set_team_score(team, team.score)
|
results.set_team_score(team, team.score)
|
||||||
self.end(results=results)
|
self.end(results=results)
|
||||||
|
|
@ -342,7 +345,7 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
def handlemessage(self, msg: Any) -> Any:
|
def handlemessage(self, msg: Any) -> Any:
|
||||||
|
|
||||||
# Respawn dead players if they're still in the game.
|
# Respawn dead players if they're still in the game.
|
||||||
if isinstance(msg, ba.PlayerDiedMessage):
|
if isinstance(msg, bs.PlayerDiedMessage):
|
||||||
# Augment standard behavior...
|
# Augment standard behavior...
|
||||||
super().handlemessage(msg)
|
super().handlemessage(msg)
|
||||||
self.respawn_player(msg.getplayer(Player))
|
self.respawn_player(msg.getplayer(Player))
|
||||||
|
|
@ -350,23 +353,23 @@ class HockeyGame(ba.TeamGameActivity[Player, Team]):
|
||||||
# Respawn dead pucks.
|
# Respawn dead pucks.
|
||||||
elif isinstance(msg, PuckDiedMessage):
|
elif isinstance(msg, PuckDiedMessage):
|
||||||
if not self.has_ended():
|
if not self.has_ended():
|
||||||
ba.timer(3.0, self._spawn_puck)
|
bs.timer(3.0, self._spawn_puck)
|
||||||
else:
|
else:
|
||||||
super().handlemessage(msg)
|
super().handlemessage(msg)
|
||||||
|
|
||||||
def _flash_puck_spawn(self) -> None:
|
def _flash_puck_spawn(self) -> None:
|
||||||
light = ba.newnode('light',
|
light = bs.newnode('light',
|
||||||
attrs={
|
attrs={
|
||||||
'position': self._puck_spawn_pos,
|
'position': self._puck_spawn_pos,
|
||||||
'height_attenuated': False,
|
'height_attenuated': False,
|
||||||
'color': (1, 0, 0)
|
'color': (1, 0, 0)
|
||||||
})
|
})
|
||||||
ba.animate(light, 'intensity', {0.0: 0, 0.25: 1, 0.5: 0}, loop=True)
|
bs.animate(light, 'intensity', {0.0: 0, 0.25: 1, 0.5: 0}, loop=True)
|
||||||
ba.timer(1.0, light.delete)
|
bs.timer(1.0, light.delete)
|
||||||
|
|
||||||
def _spawn_puck(self) -> None:
|
def _spawn_puck(self) -> None:
|
||||||
ba.playsound(self._swipsound)
|
self._swipsound.play()
|
||||||
ba.playsound(self._whistle_sound)
|
self._whistle_sound.play()
|
||||||
self._flash_puck_spawn()
|
self._flash_puck_spawn()
|
||||||
assert self._puck_spawn_pos is not None
|
assert self._puck_spawn_pos is not None
|
||||||
self._puck = Puck(position=self._puck_spawn_pos)
|
self._puck = Puck(position=self._puck_spawn_pos)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue