def drop_bomb(self): """ Tell the spaz to drop one of his bombs, and returns the resulting bomb object. If the spaz has no bombs or is otherwise unable to drop a bomb, returns None. """ if (self.land_mine_count <= 0 and self.bomb_count <= 0 and not any( self.exbomb_count.values())) or self.frozen: return None assert self.node pos = self.node.position_forward vel = self.node.velocity bomb_type: str dropping_bomb: bool if self.land_mine_count > 0: dropping_bomb = False self.set_land_mine_count(self.land_mine_count - 1) bomb_type = 'land_mine' else: self.init_bomb_count() for exbomb_type in self.exbomb_count: if self.exbomb_count[exbomb_type] > 0: self.dec_bomb_count(exbomb_type) bomb_type = exbomb_type dropping_bomb = False break else: dropping_bomb = True bomb_type = self.bomb_type bomb = stdbomb.Bomb(position=(pos[0], pos[1] - 0.0, pos[2]), velocity=(vel[0], vel[1], vel[2]), bomb_type=bomb_type, blast_radius=self.blast_radius, source_player=self.source_player, owner=self.node).autoretain() assert bomb.node if dropping_bomb: self.bomb_count -= 1 bomb.node.add_death_action( ba.WeakCall(self.handlemessage, stdspaz.BombDiedMessage())) self._pick_up(bomb.node) for clb in self._dropped_bomb_callbacks: clb(self, bomb) return bomb
def _update(self) -> None: # Misc. periodic updating. xpos = random.uniform(-7.1, 6.0) ypos = random.uniform(3.5, 3.5) zpos = random.uniform(-8.2, 3.7) # Prune dead eggs from our list. self._eggs = [e for e in self._eggs if e] # Spawn more eggs if we've got space. if len(self._eggs) < int(self._max_eggs): # Occasionally spawn a land-mine in addition. if self._pro_mode and random.random() < 0.25: mine = bomb.Bomb(position=(xpos, ypos, zpos), bomb_type='land_mine').autoretain() mine.arm() else: self._eggs.append(Egg(position=(xpos, ypos, zpos)))
def _drop_bomb(self): """Drop a certain amount of bombs.""" if self.drop_count < self.amount: activity = ba.getactivity() assert isinstance(activity, ba.GameActivity) highest_pos = activity.map.get_def_bound_box('map_bounds')[4] drop_position = (self.position[0] + random.uniform(1.5, -1.5), highest_pos, self.position[2] + random.uniform(1.5, -1.5)) stdbomb.Bomb(bomb_type=self.bomb_type, position=drop_position, blast_radius=3, velocity=self.velocity, source_player=self._source_player).autoretain() self.drop_count += 1 else: self.drop_timer = None
def summon_tnt(x, y, z): stdbomb.Bomb(bomb_type='tnt', blast_radius=3, position=(x, z + 4, y), velocity=(0, -10, 0)).autoretain()
def lucky_block_callback(self: stdspaz.Spaz, msg: ba.PowerupMessage): event_number = random.randint(1, 15) if event_number in (1, 2, 3): powerup_type = stdpowerup.PowerupBoxFactory().get_random_powerup_type() self.node.handlemessage(ba.PowerupMessage(poweruptype=powerup_type)) elif event_number == 4: ba.camerashake(1) ba.emitfx(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), velocity=(0, 0, 0), count=700, spread=0.7, chunk_type='spark') powerup_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() stdpowerup.PowerupBox(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), poweruptype=powerup_type, expire=True).autoretain() powerup_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() stdpowerup.PowerupBox(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), poweruptype=powerup_type, expire=True).autoretain() powerup_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() stdpowerup.PowerupBox(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), poweruptype=powerup_type, expire=True).autoretain() elif event_number == 5: stdbomb.Bomb(position=(self.node.position[0], self.node.position[1] + 3, self.node.position[2]), source_player=self.source_player, owner=self.node, blast_radius=6).autoretain() elif event_number == 6: self.node.handlemessage(ba.FreezeMessage()) elif event_number == 7: chunk_type = ('ice', 'rock', 'metal', 'spark', 'splinter', 'slime') ba.emitfx(position=self.node.position, velocity=(random.random() * 2, random.random() * 2, random.random() * 2), count=600, spread=random.random(), chunk_type=random.choice(chunk_type)) ba.camerashake(1) ba.playsound(ba.getsound('corkPop')) # position=self.node.position? elif event_number == 8: position = self.node.position def rain_wrapper(): p_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() new_position = (-10 + position[0] + random.random() * 20, position[1] + 6, -10 + position[2] + random.random() * 20) stdpowerup.PowerupBox(poweruptype=p_type, position=new_position).autoretain() if random.random() > 0.04: ba.timer(0.1, rain_wrapper) rain_wrapper() elif event_number == 9: stdbomb.Blast(position=self.node.position, velocity=self.node.velocity, blast_radius=1.0, blast_type='normal', source_player=None, hit_type='punch', hit_subtype='normal') elif event_number == 10: def blast(x: int, y: int, z: int) -> None: # add sound ba.NodeActor(node=ba.newnode('scorch', attrs={ 'position': (x, z, y), 'size': 0.2, 'big': False, })).autoretain() def smoke(x: int, y: int, z: int) -> None: ba.emitfx(position=(x, z, y), velocity=(0, 2, 0), count=1, emit_type='tendrils', tendril_type='smoke') ba.emitfx(position=(x, z, y), velocity=(0, 2, 0), count=int(1.0 + random.random() * 2), scale=0.8, spread=1.5, chunk_type='spark') star_positions = [ (2, 0), (0, 2), (-1.2, -1.6), (1.82, 0.83), (-1.83, 0.82), (1.23, -1.57), (-1.25, 1.56), (-0.65, 1.89), (0.82, 1.82), (1.27, 1.55), (1.82, -0.84), (0.31, -1.98), (-0.42, -1.96), (-1.75, -0.96), (-2, -0.14), (-0.69, -0.07), (-0.39, 0.82), (0.41, 0.82), (0.71, -0.06), (0.01, -0.62), (-0.99, 0.82), (-1.26, 0.37), (-0.89, -0.65), (-0.52, -1.05), (0.59, -1.07), (0.96, -0.8), (1.22, 0.35), (1.07, 0.82), (0.21, 1.39), (-0.17, 1.48), # --- (-1.94, 0.47), (-1.51, 1.31), (-0.95, 1.76), (-0.38, 1.96), (0.45, 1.95), (1.05, 1.7), (1.57, 1.24), (1.94, 0.49), (1.96, -0.42), (1.62, -1.17), (0.84, -1.82), (-0.78, -1.84), (-1.5, -1.33), (-1.91, -0.59), (-1.99, 0.17), (-1, 0.17), (-0.7, 0.82), (-0.27, 1.19), (0.29, 1.15), (0.77, 0.82), (1, 0.17), (0.84, -0.42), (0.31, -0.85), (-0.8, -1.27), (-1, -1), (-0.56, 0.33), (-0.47, 0.61), (0.52, 0.51), (-0.1, 0.82), (0.13, 0.82), (0.6, 0.27), (0.46, -0.27), (0.29, -0.4), (-0.44, -0.27), (-0.24, -0.42), (-1.36, 0.82), (-1.53, 0.59), (1.35, 0.83), (1.55, 0.61), (0.85, -1.28), (1.08, -1.13), (0.78, -0.34), (-0.21, -0.8), (0.11, 1.68) ] class Sparkling(ba.Actor): def __init__(self, position: Sequence[float], target: ba.Node): super().__init__() # nah; nodes not needed self.position = position self.position = (self.position[0], self.position[1] + 0.5, self.position[2]) self.target = target ba.timer(0.001, ba.WeakCall(self._update)) def _sparkle(self): ba.emitfx(position=self.position, velocity=(0, 1, 0), count=int(random.random() * 5 + 5), scale=0.8, spread=0.3, chunk_type='spark') def _blast(self): stdbomb.Blast(position=self.position, velocity=self.target.velocity, blast_radius=2, blast_type='normal', source_player=None, hit_type='punch', hit_subtype='normal').autoretain() def _update(self): if not self.target: del self # commit suicide because we have no goal in our existing :( return d = ba.Vec3(self.target.position) - ba.Vec3(self.position) if d.length() < 0.1: self._blast() del self return d = d.normalized() * 0.04 from math import sin, cos self.position = (self.position[0] + d.x + sin(ba.time() * 2) * 0.03, self.position[1] + d.y, self.position[2] + d.z + cos(ba.time() * 2) * 0.03) self._sparkle() ba.timer(0.001, ba.WeakCall(self._update)) def sparkling(x, y, z): Sparkling(position=(x, z, y), target=self.node).autoretain() def summon_tnt(x, y, z): stdbomb.Bomb(bomb_type='tnt', blast_radius=3, position=(x, z + 4, y), velocity=(0, -10, 0)).autoretain() scale = 1 delta = 0.02 op = self.node.position for i, (x, y) in enumerate(star_positions): ba.timer( i * delta, ba.Call(blast, self.node.position[0] + x * scale, self.node.position[2] + y * scale, self.node.position[1])) for i in range(4): ba.timer((len(star_positions)) * delta + i * 0.2, ba.Call(summon_tnt, op[0], op[2], op[1])) ba.timer((len(star_positions)) * delta + 1.0, ba.Call(sparkling, self.node.position[0], self.node.position[2], self.node.position[1])) def last_blast(): stdbomb.Blast(position=self.node.position, velocity=(self.node.velocity[0], self.node.velocity[1] + 10, self.node.velocity[2]), blast_radius=2, blast_type='normal', source_player=None, hit_type='punch', hit_subtype='normal').autoretain() # ba.timer( # 2 * len(star_positions) * delta + 0.2, # last_blast) elif event_number == 11: offset = -15 case = 1 if random.random() < 0.5 else -1 while offset < 15: velocity = (case * (12 + 8 * random.random()), -0.1, 0) stdbomb.Bomb(bomb_type='tnt', position=(self.node.position[0] - case * 10, self.node.position[1] + 3, self.node.position[2] + offset), velocity=velocity).autoretain() offset += 1.5 elif event_number == 12: color = { 0.0: (0, 0, 3), 0.5: (0, 3, 0), 1.0: (3, 0, 0), 1.5: (0, 0, 3) } # FIXME # ba.animate_array(self.node, 'color', 3, color, True) # self.node.handlemessage('celebrate', 100000000) elif event_number == 13: CompanionCube(position=(self.node.position[0], self.node.position[1] + 1, self.node.position[2]), velocity=(0, 10, 0)).autoretain() elif event_number == 14: ba.emitfx(position=self.node.position, count=100, emit_type='tendrils', tendril_type='smoke') elif event_number == 15: def drop_man(): botset: stdbot.SpazBotSet activity = ba.getactivity() if not hasattr(activity, 'botset'): activity.botset = botset = stdbot.SpazBotSet() botset = activity.botset aoi_bounds = self.activity.globalsnode.area_of_interest_bounds botset.spawn_bot( stdbot.BrawlerBotLite, (random.randrange(int(aoi_bounds[0]), int(aoi_bounds[3]) + 1), aoi_bounds[4] - 1, random.randrange(int(aoi_bounds[2]), int(aoi_bounds[5]) + 1)), spawn_time=0.001) def lightning_bolt(position, radius=1): ba.camerashake(4) vignette_outer = self.activity.globalsnode.vignette_outer # if ba.getactivity().tint is None: # ba.getactivity().std_tint = ba.sharedobj('globals').vignette_outer # vignette_outer = ba.sharedobj('globals').vignette_outer # else: # vignette_outer = ba.getactivity().tint light = ba.newnode('light', attrs={ 'position': position, 'color': (0.4, 0.4, 0.8), 'volume_intensity_scale': 1.0, 'radius': radius }) ba.animate(light, 'intensity', { 0: 1, 50: radius, 150: radius / 2, 250: 0, 260: radius, 410: radius / 2, 510: 0 }, timeformat=ba.TimeFormat.MILLISECONDS, suppress_format_warning=True) ba.animate_array(self.activity.globalsnode, 'vignette_outer', 3, { 0: vignette_outer, 0.2: (0.2, 0.2, 0.2), 0.51: vignette_outer }) # ba.playsound( # ba.getsound('grom'), # volume=10, # position=(0, 10, 0)) lightning_bolt(self.node.position) for time in range(15): ba.timer(time, drop_man)
def lucky_block_callback(self: stdspaz.Spaz, msg: ba.PowerupMessage): event_number = random.randint(1, 15) if event_number in (1, 2, 3): powerup_type = stdpowerup.PowerupBoxFactory().get_random_powerup_type() self.node.handlemessage(ba.PowerupMessage(poweruptype=powerup_type)) elif event_number == 4: ba.camerashake(1) ba.emitfx(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), velocity=(0, 0, 0), count=700, spread=0.7, chunk_type='spark') powerup_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() stdpowerup.PowerupBox(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), poweruptype=powerup_type, expire=True).autoretain() powerup_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() stdpowerup.PowerupBox(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), poweruptype=powerup_type, expire=True).autoretain() powerup_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() stdpowerup.PowerupBox(position=(self.node.position[0], self.node.position[1] + 4, self.node.position[2]), poweruptype=powerup_type, expire=True).autoretain() elif event_number == 5: stdbomb.Bomb(position=(self.node.position[0], self.node.position[1] + 3, self.node.position[2]), source_player=self.source_player, owner=self.node, blast_radius=6).autoretain() elif event_number == 6: self.node.handlemessage(ba.FreezeMessage()) elif event_number == 7: chunk_type = ('ice', 'rock', 'metal', 'spark', 'splinter', 'slime') ba.emitfx(position=self.node.position, velocity=(random.random() * 2, random.random() * 2, random.random() * 2), count=600, spread=random.random(), chunk_type=random.choice(chunk_type)) ba.camerashake(1) ba.playsound(ba.getsound('corkPop')) # position=self.node.position? elif event_number == 8: position = self.node.position def rain_wrapper(): p_type = stdpowerup.PowerupBoxFactory.get( ).get_random_powerup_type() new_position = (-10 + position[0] + random.random() * 20, position[1] + 6, -10 + position[2] + random.random() * 20) stdpowerup.PowerupBox(poweruptype=p_type, position=new_position).autoretain() if random.random() > 0.04: ba.timer(0.1, rain_wrapper) rain_wrapper() elif event_number == 9: stdbomb.Blast(position=self.node.position, velocity=self.node.velocity, blast_radius=1.0, blast_type='normal', source_player=None, hit_type='punch', hit_subtype='normal') elif event_number == 10: # Blast-square under spaz x = self.node.position[0] - 2 while x < self.node.position[0] + 2: y = self.node.position[2] - 2 while y < self.node.position[2] + 2: stdbomb.Blast(position=(x, self.node.position[1], y), velocity=(self.node.velocity[0], self.node.velocity[1] + 10, self.node.velocity[2]), blast_radius=0.5, blast_type='normal', source_player=None, hit_type='punch', hit_subtype='normal') y += 1 x += 1 elif event_number == 11: offset = -15 case = 1 if random.random() < 0.5 else -1 while offset < 15: velocity = (case * (12 + 8 * random.random()), -0.1, 0) stdbomb.Bomb(bomb_type='tnt', position=(self.node.position[0] - case * 10, self.node.position[1] + 3, self.node.position[2] + offset), velocity=velocity).autoretain() offset += 1.5 elif event_number == 12: color = { 0.0: (0, 0, 3), 0.5: (0, 3, 0), 1.0: (3, 0, 0), 1.5: (0, 0, 3) } # FIXME # ba.animate_array(self.node, 'color', 3, color, True) # self.node.handlemessage('celebrate', 100000000) elif event_number == 13: CompanionCube(position=(self.node.position[0], self.node.position[1] + 1, self.node.position[2]), velocity=(0, 10, 0)).autoretain() elif event_number == 14: ba.emitfx(position=self.node.position, count=100, emit_type='tendrils', tendril_type='smoke') elif event_number == 15: def drop_man(): botset: stdbot.SpazBotSet activity = ba.getactivity() if not hasattr(activity, 'botset'): activity.botset = botset = stdbot.SpazBotSet() botset = activity.botset aoi_bounds = self.activity.globalsnode.area_of_interest_bounds botset.spawn_bot( stdbot.BrawlerBotLite, (random.randrange(int(aoi_bounds[0]), int(aoi_bounds[3]) + 1), aoi_bounds[4] - 1, random.randrange(int(aoi_bounds[2]), int(aoi_bounds[5]) + 1)), spawn_time=0.001) def lightning_bolt(position, radius=1): ba.camerashake(4) vignette_outer = self.activity.globalsnode.vignette_outer # if ba.getactivity().tint is None: # ba.getactivity().std_tint = ba.sharedobj('globals').vignette_outer # vignette_outer = ba.sharedobj('globals').vignette_outer # else: # vignette_outer = ba.getactivity().tint light = ba.newnode('light', attrs={ 'position': position, 'color': (0.4, 0.4, 0.8), 'volume_intensity_scale': 1.0, 'radius': radius }) ba.animate(light, 'intensity', { 0: 1, 50: radius, 150: radius / 2, 250: 0, 260: radius, 410: radius / 2, 510: 0 }, timeformat=ba.TimeFormat.MILLISECONDS, suppress_format_warning=True) ba.animate_array(self.activity.globalsnode, 'vignette_outer', 3, { 0: vignette_outer, 0.2: (0.2, 0.2, 0.2), 0.51: vignette_outer }) # ba.playsound( # ba.getsound('grom'), # volume=10, # position=(0, 10, 0)) lightning_bolt(self.node.position) for time in range(15): ba.timer(time, drop_man)
def _drop_bomb(self, position: Sequence[float], velocity: Sequence[float]) -> None: bomb.Bomb(position=position, velocity=velocity).autoretain()