[ci] auto-format

This commit is contained in:
TheMikirog 2022-11-13 20:06:02 +00:00 committed by github-actions[bot]
parent 02cb7871ee
commit 05d2f1a4f7
4 changed files with 340 additions and 304 deletions

View file

@ -70,6 +70,8 @@ class PlayerState(Enum):
# To make the game easier to parse, I added Elimination style icons to the bottom of the screen. # To make the game easier to parse, I added Elimination style icons to the bottom of the screen.
# Here's the behavior of each icon. # Here's the behavior of each icon.
class Icon(ba.Actor): class Icon(ba.Actor):
"""Creates in in-game icon on screen.""" """Creates in in-game icon on screen."""
@ -223,6 +225,8 @@ class Icon(ba.Actor):
# This gamemode heavily relies on edited player behavior. # This gamemode heavily relies on edited player behavior.
# We need that amount of control, so we're gonna create our own class and use the original PlayerSpaz as our blueprint. # We need that amount of control, so we're gonna create our own class and use the original PlayerSpaz as our blueprint.
class PotatoPlayerSpaz(PlayerSpaz): class PotatoPlayerSpaz(PlayerSpaz):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -289,9 +293,9 @@ class PotatoPlayerSpaz(PlayerSpaz):
bomb.node.add_death_action( bomb.node.add_death_action(
ba.WeakCall(self.bomb_died, bomb)) ba.WeakCall(self.bomb_died, bomb))
# Here's the function that gets called when one of the player's bombs dies. # Here's the function that gets called when one of the player's bombs dies.
# We reference the player's dropped_bombs list and remove the bomb that died. # We reference the player's dropped_bombs list and remove the bomb that died.
def bomb_died(self, bomb): def bomb_died(self, bomb):
self.dropped_bombs.remove(bomb) self.dropped_bombs.remove(bomb)
@ -317,7 +321,8 @@ class PotatoPlayerSpaz(PlayerSpaz):
self.activity.pass_mark(msg._source_player, self._player) self.activity.pass_mark(msg._source_player, self._player)
# When stun timer runs out, we explode. Let's make sure our own explosion does throw us around. # When stun timer runs out, we explode. Let's make sure our own explosion does throw us around.
if msg.hit_type == 'stun_blast' and msg._source_player == self.source_player: return True if msg.hit_type == 'stun_blast' and msg._source_player == self.source_player:
return True
# If the attacker is healthy and we're stunned, do a flash and play a sound, then ignore the rest of the code. # If the attacker is healthy and we're stunned, do a flash and play a sound, then ignore the rest of the code.
if self.source_player.state == PlayerState.STUNNED and msg._source_player != PlayerState.MARKED: if self.source_player.state == PlayerState.STUNNED and msg._source_player != PlayerState.MARKED:
self.node.handlemessage('flash') self.node.handlemessage('flash')
@ -472,9 +477,12 @@ class PotatoPlayerSpaz(PlayerSpaz):
# Continue with the rest of the behavior. # Continue with the rest of the behavior.
super().handlemessage(msg) super().handlemessage(msg)
# If a message is something we haven't modified yet, let's pass it along to the original. # If a message is something we haven't modified yet, let's pass it along to the original.
else: super().handlemessage(msg) else:
super().handlemessage(msg)
# A concept of a player is very useful to reference if we don't have a player character present (maybe they died). # A concept of a player is very useful to reference if we don't have a player character present (maybe they died).
class Player(ba.Player['Team']): class Player(ba.Player['Team']):
"""Our player type for this game.""" """Our player type for this game."""
@ -498,13 +506,15 @@ class Player(ba.Player['Team']):
# When stun time is up, call this function. # When stun time is up, call this function.
def stun_remove(self) -> None: def stun_remove(self) -> None:
# Let's proceed only if we're stunned # Let's proceed only if we're stunned
if self.state != PlayerState.STUNNED: return if self.state != PlayerState.STUNNED:
return
# Do an explosion where we're standing. Normally it would throw us around, but we dealt # Do an explosion where we're standing. Normally it would throw us around, but we dealt
# with this issue in PlayerSpaz's edited HitMessage in line 312. # with this issue in PlayerSpaz's edited HitMessage in line 312.
Blast(position=self.actor.node.position, Blast(position=self.actor.node.position,
velocity=self.actor.node.velocity, velocity=self.actor.node.velocity,
blast_radius=2.5, blast_radius=2.5,
hit_type='stun_blast', # This hit type allows us to ignore our own stun blast explosions. # This hit type allows us to ignore our own stun blast explosions.
hit_type='stun_blast',
source_player=self).autoretain() source_player=self).autoretain()
# Let's switch our state back to healthy. # Let's switch our state back to healthy.
self.set_state(PlayerState.REGULAR) self.set_state(PlayerState.REGULAR)
@ -524,10 +534,13 @@ class Player(ba.Player['Team']):
stun_time = FALL_PENALTIES[len(FALL_PENALTIES) - 1] stun_time = FALL_PENALTIES[len(FALL_PENALTIES) - 1]
self.stunned_time_remaining = stun_time # Set our stun time remaining self.stunned_time_remaining = stun_time # Set our stun time remaining
self.stunned_timer = ba.Timer(stun_time + 0.1, ba.Call(self.stun_remove)) # Remove our stun once the time is up # Remove our stun once the time is up
self.stunned_update_timer = ba.Timer(0.1, ba.Call(self.stunned_timer_tick), repeat = True) # Call a function every 0.1 seconds self.stunned_timer = ba.Timer(stun_time + 0.1, ba.Call(self.stun_remove))
self.stunned_update_timer = ba.Timer(0.1, ba.Call(
self.stunned_timer_tick), repeat=True) # Call a function every 0.1 seconds
self.fall_times += 1 # Increase the amount of times we fell by one self.fall_times += 1 # Increase the amount of times we fell by one
self.actor.marked_timer_text.text = str(stun_time) # Change the text above the Spaz's head to total stun time # Change the text above the Spaz's head to total stun time
self.actor.marked_timer_text.text = str(stun_time)
# If we were stunned, but now we're not, let's reconnect our controls. # If we were stunned, but now we're not, let's reconnect our controls.
# CODING CHALLENGE: to punch or bomb immediately after the stun ends, you need to # CODING CHALLENGE: to punch or bomb immediately after the stun ends, you need to
@ -683,7 +696,7 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
chunk_type='spark', chunk_type='spark',
count=int(20.0+random.random()*20), count=int(20.0+random.random()*20),
scale=1.0, scale=1.0,
spread=1.0); spread=1.0)
if bool(self.settings['Marked Players use Impact Bombs']): if bool(self.settings['Marked Players use Impact Bombs']):
target.actor.bomb_type = 'impact' target.actor.bomb_type = 'impact'
target.actor.marked_timer_text.text = str(self.elimination_timer_display) target.actor.marked_timer_text.text = str(self.elimination_timer_display)
@ -703,7 +716,8 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
# more control over the mark spreading mechanic. # more control over the mark spreading mechanic.
def pass_mark(self, marked_player: Player, hit_player: Player) -> None: def pass_mark(self, marked_player: Player, hit_player: Player) -> None:
# Make sure both players meet the requirements # Make sure both players meet the requirements
if not marked_player or not hit_player: return if not marked_player or not hit_player:
return
if marked_player.state == PlayerState.MARKED and hit_player.state != PlayerState.MARKED: if marked_player.state == PlayerState.MARKED and hit_player.state != PlayerState.MARKED:
self.mark(hit_player) self.mark(hit_player)
self.remove_mark(marked_player) self.remove_mark(marked_player)
@ -769,7 +783,8 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
# Is there only one player remaining? Or none at all? Let's end the gamemode # Is there only one player remaining? Or none at all? Let's end the gamemode
if len(alive_players) < 2: if len(alive_players) < 2:
if len(alive_players) == 1: if len(alive_players) == 1:
self.match_placement.append(alive_players[0].team) # Let's add our lone survivor to the match placement list. # Let's add our lone survivor to the match placement list.
self.match_placement.append(alive_players[0].team)
# Wait a while to let this sink in before we announce our victor. # Wait a while to let this sink in before we announce our victor.
self._end_game_timer = ba.Timer(1.25, ba.Call(self.end_game)) self._end_game_timer = ba.Timer(1.25, ba.Call(self.end_game))
else: else:
@ -780,7 +795,8 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
def get_alive_players(self) -> Sequence[ba.Player]: def get_alive_players(self) -> Sequence[ba.Player]:
alive_players = [] alive_players = []
for player in self.players: for player in self.players:
if player.state == PlayerState.ELIMINATED: continue # Ignore players who have been eliminated if player.state == PlayerState.ELIMINATED:
continue # Ignore players who have been eliminated
if player.is_alive(): if player.is_alive():
alive_players.append(player) alive_players.append(player)
return alive_players return alive_players
@ -808,8 +824,10 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
# Pick one victim at random. # Pick one victim at random.
all_victims = [random.choice(possible_targets)] all_victims = [random.choice(possible_targets)]
self.elimination_timer_display = self.settings['Elimination Timer'] # Set time until marked players explode # Set time until marked players explode
self.marked_tick_timer = ba.Timer(1.0, ba.Call(self._eliminate_tick), repeat=True) # Set a timer that calls _eliminate_tick every second self.elimination_timer_display = self.settings['Elimination Timer']
# Set a timer that calls _eliminate_tick every second
self.marked_tick_timer = ba.Timer(1.0, ba.Call(self._eliminate_tick), repeat=True)
# Mark all chosen victims and play a sound # Mark all chosen victims and play a sound
for new_victim in all_victims: for new_victim in all_victims:
# _marked_sounds is an array. # _marked_sounds is an array.
@ -1003,11 +1021,12 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
def handlemessage(self, msg: Any) -> Any: def handlemessage(self, msg: Any) -> Any:
# This is called if the player dies. # This is called if the player dies.
if isinstance(msg, ba.PlayerDiedMessage): if isinstance(msg, ba.PlayerDiedMessage):
super().handlemessage(msg) # super().handlemessage(msg)
player = msg.getplayer(Player) player = msg.getplayer(Player)
# If a player gets eliminated, don't respawn # If a player gets eliminated, don't respawn
if msg.how == 'marked_elimination': return if msg.how == 'marked_elimination':
return
self.spawn_player(player) # Spawn a new player character self.spawn_player(player) # Spawn a new player character

View file

@ -24,6 +24,8 @@ if TYPE_CHECKING:
pass pass
# ba_meta export plugin # ba_meta export plugin
class BombRadiusVisualizer(ba.Plugin): class BombRadiusVisualizer(ba.Plugin):
# We use a decorator to add extra code to existing code, increasing mod compatibility. # We use a decorator to add extra code to existing code, increasing mod compatibility.
@ -43,7 +45,8 @@ class BombRadiusVisualizer(ba.Plugin):
# This is going to make a slightly opaque red circle, signifying damaging area. # This is going to make a slightly opaque red circle, signifying damaging area.
# We aren't defining the size, because we're gonna animate it shortly after. # We aren't defining the size, because we're gonna animate it shortly after.
args[0].radius_visualizer = ba.newnode('locator', args[0].radius_visualizer = ba.newnode('locator',
owner=args[0].node, # Remove itself when the bomb node dies. # Remove itself when the bomb node dies.
owner=args[0].node,
attrs={ attrs={
'shape': 'circle', 'shape': 'circle',
'color': (1, 0, 0), 'color': (1, 0, 0),
@ -64,10 +67,12 @@ class BombRadiusVisualizer(ba.Plugin):
# Let's do a second circle, this time just the outline to where the damaging area ends. # Let's do a second circle, this time just the outline to where the damaging area ends.
args[0].radius_visualizer_circle = ba.newnode('locator', args[0].radius_visualizer_circle = ba.newnode('locator',
owner=args[0].node, # Remove itself when the bomb node dies. # Remove itself when the bomb node dies.
owner=args[0].node,
attrs={ attrs={
'shape': 'circleOutline', 'shape': 'circleOutline',
'size':[args[0].blast_radius * 2.0], # Here's that bomb's blast radius value again! # Here's that bomb's blast radius value again!
'size': [args[0].blast_radius * 2.0],
'color': (1, 1, 0), 'color': (1, 1, 0),
'draw_beauty': False, 'draw_beauty': False,
'additive': True 'additive': True
@ -86,4 +91,3 @@ class BombRadiusVisualizer(ba.Plugin):
# Finally we """travel through the game files""" to replace the function we want with our own version. # Finally we """travel through the game files""" to replace the function we want with our own version.
# We transplant the old function's arguments into our version. # We transplant the old function's arguments into our version.
bastd.actor.bomb.Bomb.__init__ = new_bomb_init(bastd.actor.bomb.Bomb.__init__) bastd.actor.bomb.Bomb.__init__ = new_bomb_init(bastd.actor.bomb.Bomb.__init__)

View file

@ -24,6 +24,8 @@ if TYPE_CHECKING:
pass pass
# ba_meta export plugin # ba_meta export plugin
class Quickturn(ba.Plugin): class Quickturn(ba.Plugin):
class FootConnectMessage: class FootConnectMessage:
@ -54,19 +56,20 @@ class Quickturn(ba.Plugin):
move_length = math.hypot(move[0], move[1]) move_length = math.hypot(move[0], move[1])
vel_length = math.hypot(vel[0], vel[1]) vel_length = math.hypot(vel[0], vel[1])
if vel_length < 0.6: return if vel_length < 0.6:
return
move_norm = [m/move_length for m in move] move_norm = [m/move_length for m in move]
vel_norm = [v/vel_length for v in vel] vel_norm = [v/vel_length for v in vel]
dot = sum(x*y for x, y in zip(move_norm, vel_norm)) dot = sum(x*y for x, y in zip(move_norm, vel_norm))
turn_power = min(round(math.acos(dot) / math.pi, 2)*1.3, 1) turn_power = min(round(math.acos(dot) / math.pi, 2)*1.3, 1)
# https://easings.net/#easeInOutQuart # https://easings.net/#easeInOutQuart
if turn_power < 0.55: if turn_power < 0.55:
turn_power = 8 * turn_power * turn_power * turn_power * turn_power turn_power = 8 * turn_power * turn_power * turn_power * turn_power
else: else:
turn_power = 0.55 - pow(-2 * turn_power + 2, 4) / 2 turn_power = 0.55 - pow(-2 * turn_power + 2, 4) / 2
if turn_power < 0.1: return if turn_power < 0.1:
return
boost_power = math.sqrt(math.pow(vel[0], 2) + math.pow(vel[1], 2)) * 8 boost_power = math.sqrt(math.pow(vel[0], 2) + math.pow(vel[1], 2)) * 8
boost_power = min(pow(boost_power, 8), 160) boost_power = min(pow(boost_power, 8), 160)
@ -79,7 +82,7 @@ class Quickturn(ba.Plugin):
chunk_type='spark', chunk_type='spark',
count=5, count=5,
scale=boost_power / 160 * turn_power, scale=boost_power / 160 * turn_power,
spread=0.25); spread=0.25)
# Boost itself # Boost itself
pos = self.node.position pos = self.node.position
@ -108,18 +111,21 @@ class Quickturn(ba.Plugin):
func(*args, **kwargs) func(*args, **kwargs)
args[0].roller_material.add_actions( args[0].roller_material.add_actions(
conditions=('they_have_material', bastd.gameutils.SharedObjects.get().footing_material), conditions=('they_have_material',
bastd.gameutils.SharedObjects.get().footing_material),
actions=(('message', 'our_node', 'at_connect', Quickturn.FootConnectMessage), actions=(('message', 'our_node', 'at_connect', Quickturn.FootConnectMessage),
('message', 'our_node', 'at_disconnect', Quickturn.FootDisconnectMessage))) ('message', 'our_node', 'at_disconnect', Quickturn.FootDisconnectMessage)))
return wrapper return wrapper
bastd.actor.spazfactory.SpazFactory.__init__ = new_factory(bastd.actor.spazfactory.SpazFactory.__init__) bastd.actor.spazfactory.SpazFactory.__init__ = new_factory(
bastd.actor.spazfactory.SpazFactory.__init__)
def new_handlemessage(func): def new_handlemessage(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
if args[1] == Quickturn.FootConnectMessage: if args[1] == Quickturn.FootConnectMessage:
args[0].grounded += 1 args[0].grounded += 1
elif args[1] == Quickturn.FootDisconnectMessage: elif args[1] == Quickturn.FootDisconnectMessage:
if args[0].grounded > 0: args[0].grounded -= 1 if args[0].grounded > 0:
args[0].grounded -= 1
func(*args, **kwargs) func(*args, **kwargs)
return wrapper return wrapper

View file

@ -28,6 +28,8 @@ if TYPE_CHECKING:
pass pass
# ba_meta export plugin # ba_meta export plugin
class RagdollBGone(ba.Plugin): class RagdollBGone(ba.Plugin):
# We use a decorator to add extra code to existing code, increasing mod compatibility. # We use a decorator to add extra code to existing code, increasing mod compatibility.
@ -80,16 +82,20 @@ class RagdollBGone(ba.Plugin):
# We're gonna use sparks here. # We're gonna use sparks here.
ba.emitfx(position=pos, # Here we place our edited position. ba.emitfx(position=pos, # Here we place our edited position.
velocity=args[0].node.velocity, velocity=args[0].node.velocity,
count=random.randrange(2, 5), # Random amount of sparks between 2 and 5 # Random amount of sparks between 2 and 5
count=random.randrange(2, 5),
scale=3.0, scale=3.0,
spread=0.2, spread=0.2,
chunk_type='spark') chunk_type='spark')
# Make a Spaz death noise if we're not gibbed. # Make a Spaz death noise if we're not gibbed.
if not args[0].shattered: if not args[0].shattered:
death_sounds = args[0].node.death_sounds # Get our Spaz's death noises, these change depending on character skins # Get our Spaz's death noises, these change depending on character skins
sound = death_sounds[random.randrange(len(death_sounds))] # Pick a random death noise death_sounds = args[0].node.death_sounds
ba.playsound(sound, position=args[0].node.position) # Play the sound where our Spaz is # Pick a random death noise
sound = death_sounds[random.randrange(len(death_sounds))]
# Play the sound where our Spaz is
ba.playsound(sound, position=args[0].node.position)
# Delete our Spaz node immediately. # Delete our Spaz node immediately.
# Removing stuff is weird and prone to errors, so we're gonna delay it. # Removing stuff is weird and prone to errors, so we're gonna delay it.
ba.timer(0.001, args[0].node.delete) ba.timer(0.001, args[0].node.delete)
@ -98,7 +104,8 @@ class RagdollBGone(ba.Plugin):
# Notice how we're targeting the Spaz and not it's node. # Notice how we're targeting the Spaz and not it's node.
# "self.node" is a visual representation of the character while "self" is his game logic. # "self.node" is a visual representation of the character while "self" is his game logic.
args[0]._dead = True args[0]._dead = True
args[0].hitpoints = 0 # Set his health to zero. This value is independent from the health bar above his head. # Set his health to zero. This value is independent from the health bar above his head.
args[0].hitpoints = 0
return return
# Worry no longer! We're not gonna remove all the base game code! # Worry no longer! We're not gonna remove all the base game code!