[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.
# Here's the behavior of each icon.
class Icon(ba.Actor):
"""Creates in in-game icon on screen."""
@ -194,10 +196,10 @@ class Icon(ba.Actor):
# Animate text and icon
animation_end_time = 1.5 if bool(self.activity.settings['Epic Mode']) else 3.0
ba.animate(self._marked_icon,'opacity', {
ba.animate(self._marked_icon, 'opacity', {
0: 1.0,
animation_end_time: 0.0})
ba.animate(self._marked_text,'opacity', {
ba.animate(self._marked_text, 'opacity', {
0: 1.0,
animation_end_time: 0.0})
@ -223,6 +225,8 @@ class Icon(ba.Actor):
# 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.
class PotatoPlayerSpaz(PlayerSpaz):
def __init__(self, *args, **kwargs):
@ -233,27 +237,27 @@ class PotatoPlayerSpaz(PlayerSpaz):
# Define a marked light
self.marked_light = ba.newnode('light',
owner=self.node,
attrs={'position':self.node.position,
'radius':0.15,
'intensity':0.0,
'height_attenuated':False,
attrs={'position': self.node.position,
'radius': 0.15,
'intensity': 0.0,
'height_attenuated': False,
'color': (1.0, 0.0, 0.0)})
# Pulsing red light when the player is Marked
ba.animate(self.marked_light,'radius',{
ba.animate(self.marked_light, 'radius', {
0: 0.1,
0.3: 0.15,
0.6: 0.1},
loop = True)
self.node.connectattr('position_center',self.marked_light,'position')
loop=True)
self.node.connectattr('position_center', self.marked_light, 'position')
# Marked timer. It should be above our head, so we attach the text to the offset that's attached to the player.
self.marked_timer_offset = ba.newnode('math', owner = self.node, attrs = {
self.marked_timer_offset = ba.newnode('math', owner=self.node, attrs={
'input1': (0, 1.2, 0),
'operation': 'add'})
self.node.connectattr('torso_position', self.marked_timer_offset, 'input2')
self.marked_timer_text = ba.newnode('text', owner = self.node, attrs = {
self.marked_timer_text = ba.newnode('text', owner=self.node, attrs={
'text': '',
'in_world': True,
'shadow': 0.4,
@ -276,22 +280,22 @@ class PotatoPlayerSpaz(PlayerSpaz):
# Bring a light
bomb.bomb_marked_light = ba.newnode('light',
owner=bomb.node,
attrs={'position':bomb.node.position,
'radius':0.04,
'intensity':0.0,
'height_attenuated':False,
attrs={'position': bomb.node.position,
'radius': 0.04,
'intensity': 0.0,
'height_attenuated': False,
'color': (1.0, 0.0, 0.0)})
# Attach the light to the bomb
bomb.node.connectattr('position',bomb.bomb_marked_light,'position')
bomb.node.connectattr('position', bomb.bomb_marked_light, 'position')
# Let's adjust all lights for all bombs that we own.
self.set_bombs_marked()
# When the bomb physics node dies, call a function.
bomb.node.add_death_action(
ba.WeakCall(self.bomb_died, bomb))
# 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.
def bomb_died(self, bomb):
self.dropped_bombs.remove(bomb)
@ -317,7 +321,8 @@ class PotatoPlayerSpaz(PlayerSpaz):
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.
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 self.source_player.state == PlayerState.STUNNED and msg._source_player != PlayerState.MARKED:
self.node.handlemessage('flash')
@ -465,16 +470,19 @@ class PotatoPlayerSpaz(PlayerSpaz):
self.marked_timer_text.color[1],
self.marked_timer_text.color[2],
0.0)
ba.animate(self.marked_light,'intensity',{
ba.animate(self.marked_light, 'intensity', {
0: self.marked_light.intensity,
0.5: 0.0})
# Continue with the rest of the behavior.
super().handlemessage(msg)
# 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).
class Player(ba.Player['Team']):
"""Our player type for this game."""
@ -498,13 +506,15 @@ class Player(ba.Player['Team']):
# When stun time is up, call this function.
def stun_remove(self) -> None:
# 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
# with this issue in PlayerSpaz's edited HitMessage in line 312.
Blast(position=self.actor.node.position,
velocity=self.actor.node.velocity,
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()
# Let's switch our state back to healthy.
self.set_state(PlayerState.REGULAR)
@ -524,10 +534,13 @@ class Player(ba.Player['Team']):
stun_time = FALL_PENALTIES[len(FALL_PENALTIES) - 1]
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
self.stunned_update_timer = ba.Timer(0.1, ba.Call(self.stunned_timer_tick), repeat = True) # Call a function every 0.1 seconds
# Remove our stun once the time is up
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.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.
# 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',
count=int(20.0+random.random()*20),
scale=1.0,
spread=1.0);
spread=1.0)
if bool(self.settings['Marked Players use Impact Bombs']):
target.actor.bomb_type = 'impact'
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.
def pass_mark(self, marked_player: Player, hit_player: Player) -> None:
# 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:
self.mark(hit_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
if len(alive_players) < 2:
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.
self._end_game_timer = ba.Timer(1.25, ba.Call(self.end_game))
else:
@ -780,7 +795,8 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
def get_alive_players(self) -> Sequence[ba.Player]:
alive_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():
alive_players.append(player)
return alive_players
@ -808,8 +824,10 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
# Pick one victim at random.
all_victims = [random.choice(possible_targets)]
self.elimination_timer_display = self.settings['Elimination Timer'] # 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
# Set time until marked players explode
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
for new_victim in all_victims:
# _marked_sounds is an array.
@ -1003,11 +1021,12 @@ class HotPotato(ba.TeamGameActivity[Player, ba.Team]):
def handlemessage(self, msg: Any) -> Any:
# This is called if the player dies.
if isinstance(msg, ba.PlayerDiedMessage):
super().handlemessage(msg) #
super().handlemessage(msg)
player = msg.getplayer(Player)
# 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

View file

@ -24,6 +24,8 @@ if TYPE_CHECKING:
pass
# ba_meta export plugin
class BombRadiusVisualizer(ba.Plugin):
# We use a decorator to add extra code to existing code, increasing mod compatibility.
@ -43,11 +45,12 @@ class BombRadiusVisualizer(ba.Plugin):
# 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.
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={
'shape': 'circle',
'color': (1, 0, 0),
'opacity':0.05,
'opacity': 0.05,
'draw_beauty': False,
'additive': False
})
@ -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.
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={
'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),
'draw_beauty': False,
'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.
# We transplant the old function's arguments into our version.
bastd.actor.bomb.Bomb.__init__ = new_bomb_init(bastd.actor.bomb.Bomb.__init__)

View file

@ -24,6 +24,8 @@ if TYPE_CHECKING:
pass
# ba_meta export plugin
class Quickturn(ba.Plugin):
class FootConnectMessage:
@ -54,41 +56,42 @@ class Quickturn(ba.Plugin):
move_length = math.hypot(move[0], move[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]
vel_norm = [v/vel_length for v in vel]
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)
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)
# https://easings.net/#easeInOutQuart
if turn_power < 0.55:
turn_power = 8 * turn_power * turn_power * turn_power * turn_power
else:
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 = min(pow(boost_power,8),160)
boost_power = math.sqrt(math.pow(vel[0], 2) + math.pow(vel[1], 2)) * 8
boost_power = min(pow(boost_power, 8), 160)
self.last_wavedash_time_ms = t_ms
# FX
ba.emitfx(position=self.node.position,
velocity=(vel[0]*0.5,-1,vel[1]*0.5),
velocity=(vel[0]*0.5, -1, vel[1]*0.5),
chunk_type='spark',
count=5,
scale=boost_power / 160 * turn_power,
spread=0.25);
spread=0.25)
# Boost itself
pos = self.node.position
for i in range(6):
self.node.handlemessage('impulse',pos[0],0.2+pos[1]+i*0.1,pos[2],
0,0,0,
self.node.handlemessage('impulse', pos[0], 0.2+pos[1]+i*0.1, pos[2],
0, 0, 0,
boost_power * turn_power,
boost_power * turn_power,0,0,
move[0],0,move[1])
boost_power * turn_power, 0, 0,
move[0], 0, move[1])
def new_spaz_init(func):
def wrapper(*args, **kwargs):
@ -108,18 +111,21 @@ class Quickturn(ba.Plugin):
func(*args, **kwargs)
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),
('message', 'our_node', 'at_disconnect', Quickturn.FootDisconnectMessage)))
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 wrapper(*args, **kwargs):
if args[1] == Quickturn.FootConnectMessage:
args[0].grounded += 1
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)
return wrapper

View file

@ -28,6 +28,8 @@ if TYPE_CHECKING:
pass
# ba_meta export plugin
class RagdollBGone(ba.Plugin):
# We use a decorator to add extra code to existing code, increasing mod compatibility.
@ -78,18 +80,22 @@ class RagdollBGone(ba.Plugin):
args[0].node.position[2])
# This function allows us to spawn particles like sparks and bomb shrapnel.
# 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,
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,
spread=0.2,
chunk_type='spark')
# Make a Spaz death noise if we're not gibbed.
if not args[0].shattered:
death_sounds = args[0].node.death_sounds # 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
ba.playsound(sound, position=args[0].node.position) # Play the sound where our Spaz is
# Get our Spaz's death noises, these change depending on character skins
death_sounds = args[0].node.death_sounds
# 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.
# Removing stuff is weird and prone to errors, so we're gonna delay it.
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.
# "self.node" is a visual representation of the character while "self" is his game logic.
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
# Worry no longer! We're not gonna remove all the base game code!