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