def make_ne_wall(): """ Make a corner wall (`\`) :return: """ return Construction(image_source='Wall_NE.png', passable=False, fighter=FighterComponent(max_hp=10), descriptor=DescriptorComponent(name='Wall segment'), faction=FactionComponent(faction='decorations'))\
def make_tree(): """ Impassable wall :return: """ return Construction(image_source='Tree.png', passable=False, descriptor=DescriptorComponent(name='Tree'), faction=FactionComponent(faction='decorations'))
def make_v_wall(): """ The same as make_h_wall, but with a vertical image :return: """ return Construction( image_source='Wall_vertical.png', passable=False, fighter=FighterComponent(max_hp=10), descriptor=DescriptorComponent(name='Wall segment'), faction=FactionComponent(faction='decorations'))
def make_h_wall(): """ Horizontal wall. Unlike a tree, this has a fighter component with 10 HP and can be destroyed :return: """ return Construction( image_source='Wall_horizontal.png', passable=False, fighter=FighterComponent(max_hp=10), descriptor=DescriptorComponent(name='Wall segment'), faction=FactionComponent(faction='decorations'))
def affect(self, map, location): if self.effect_type == 'spawn_construction': # Spawn something in construction layer unless there already is something if not map.get_item(location=location, layer='constructions'): map.add_item(item=self.effect_value, location=location, layer='constructions') map.game_events.append( GameEvent(event_type='construction_spawned', actor=self.effect_value, location=location)) return True else: return False elif self.effect_type == 'explode': # Blow up, dealing effect_value damage to all fighters on this and neighbouring tiles and # destroying items with 50% chance. Spawn an impassable hole where explosion occured map.game_events.append( GameEvent(event_type='exploded', location=location)) destroyed_items = False for tile in map.get_neighbour_coordinates(location=location, return_query=True): for victim in map.get_column(tile): if hasattr(victim, 'fighter') and victim.fighter: if isinstance(victim, Construction) and tile == location: # Deal over-the-top damage to constructions on ground zero # This means that, barring incredible defense, explosion under a costruction should # kill it outright victim.fighter.get_damaged(victim.fighter.max_hp * 2) victim.fighter.get_damaged(self.effect_value) for victim in map.get_column(tile): # Items are checked in a separate cycle because items could've been dropped by killed enemies if isinstance(victim, Item) and (random() > 0.5 or tile == location): map.delete_item(layer='items', location=tile) map.game_events.append( GameEvent(event_type='was_destroyed', actor=victim, location=tile)) destroyed_items = True hole = Construction(image_source='Hole.png', passable=False, air_passable=True) map.add_item(item=hole, location=location, layer='constructions') map.game_events.append( GameEvent(event_type='construction_spawned', actor=hole, location=location)) if destroyed_items: map.extend_log('Some items were destroyed') return True
def make_hole(): """ Explosion-produced hole :return: """ return Construction(image_source='Hole.png', passable=False)