def _combat(self, model, action_factory, rng): """ Attack enemies """ character = self.character player = model.player c_location = character.location p_location = player.location distance = ((c_location[0] - p_location[0]) ** 2 + (c_location[1] - p_location[1]) ** 2) ** 0.5 if distance == 1: direction = find_direction(c_location, p_location) pyherc.vtable['\ufdd0:attack'](character, direction) else: path, connections, updated = a_star(c_location, p_location, character.level) next_tile = path[1] direction = find_direction(character.location, next_tile) if pyherc.vtable['\ufdd0:is-move-legal'](character, direction, 'walk', action_factory): pyherc.vtable['\ufdd0:move'](character, direction, action_factory) else: character.tick = character.tick + 10
def _combat(self, model, action_factory, rng): """ Attack enemies """ character = self.character player = model.player c_location = character.location p_location = player.location distance = ((c_location[0] - p_location[0])**2 + (c_location[1] - p_location[1])**2)**0.5 if distance == 1: direction = find_direction(c_location, p_location) pyherc.vtable['\ufdd0:attack'](character, direction) else: path, connections, updated = a_star(c_location, p_location, character.level) next_tile = path[1] direction = find_direction(character.location, next_tile) if pyherc.vtable['\ufdd0:is-move-legal'](character, direction, 'walk', action_factory): pyherc.vtable['\ufdd0:move'](character, direction, action_factory) else: character.tick = character.tick + 10
def __call__(self, caster): """ Performs the casting :param caster: character doing the casting :type caster: Character """ add_history_value(caster, 'hit_points') spell_factory = SpellGeneratorBuilder().build() effects_factory = get_effect_creator({ 'heal medium wounds': { 'type': Heal, 'duration': None, 'frequency': None, 'tick': 0, 'healing': 10, 'icon': None, 'title': 'Heal medium wounds', 'description': 'Heals medium amount of damage' }, # noqa 'cause wound': { 'type': DamageEffect, 'duration': None, 'frequency': None, 'tick': 0, 'damage': 5, 'damage_type': 'magic', 'icon': None, 'title': 'Cause minor wound', 'description': 'Causes minor amount of damage' }, # noqa 'fire': { 'type': DamageEffect, 'duration': 30, 'frequency': 5, 'tick': 0, 'damage': 3, 'damage_type': 'fire', 'icon': None, 'title': 'Fire', 'description': 'You are on fire!' } }) spell_casting_factory = ( SpellCastingFactoryBuilder().with_spell_factory( spell_factory).with_effects_factory(effects_factory).build()) set_action_factory(ActionFactoryBuilder().with_spellcasting_factory( spell_casting_factory).build() ) # TODO: mutating global state is bad if self.target: direction = find_direction(caster.location, self.target.location) else: direction = 1 cast(caster, direction=direction, spell_name=self.spell_name)
def _patrol(self, model, action_factory, rng): """ Patrol around the level """ character = self.character level = self.character.level while (self.destination is None or character.location == self.destination): self.destination = find_free_space(level) path, connections, updated = a_star(character.location, self.destination, level) next_tile = path[1] direction = find_direction(character.location, next_tile) if pyherc.vtable['\ufdd0:is-move-legal'](character, direction, 'walk', action_factory): pyherc.vtable['\ufdd0:move'](character, direction, action_factory) else: character.tick = character.tick + 10
def __call__(self, caster): """ Performs the casting :param caster: character doing the casting :type caster: Character """ add_history_value(caster, 'hit_points') spell_factory = SpellGeneratorBuilder().build() effects_factory = get_effect_creator({'heal medium wounds': {'type': Heal, 'duration': None, 'frequency': None, 'tick': 0, 'healing': 10, 'icon': None, 'title': 'Heal medium wounds', 'description': 'Heals medium amount of damage'}, # noqa 'cause wound': {'type': DamageEffect, 'duration': None, 'frequency': None, 'tick': 0, 'damage': 5, 'damage_type': 'magic', 'icon': None, 'title': 'Cause minor wound', 'description': 'Causes minor amount of damage'}, # noqa 'fire': {'type': DamageEffect, 'duration': 30, 'frequency': 5, 'tick': 0, 'damage': 3, 'damage_type': 'fire', 'icon': None, 'title': 'Fire', 'description': 'You are on fire!'}}) spell_casting_factory = (SpellCastingFactoryBuilder() .with_spell_factory(spell_factory) .with_effects_factory(effects_factory) .build()) set_action_factory(ActionFactoryBuilder() .with_spellcasting_factory(spell_casting_factory) .build()) # TODO: mutating global state is bad if self.target: direction = find_direction(caster.location, self.target.location) else: direction = 1 cast(caster, direction=direction, spell_name=self.spell_name)
def impl(context, character_name, location_name): character = get_character(context, character_name) place = get_location(context, location_name) path, connections, updated = a_star(whole_level, character.location, #TODO: adjacent nodes as first param place.location, character.level) assert len(path) > 1 for tile in path[1:]: direction = find_direction(character.location, tile) pyherc.vtable['\ufdd0:move'](character, direction)
def mouseEvent(self, event): """ Handle mouse events """ if self.model.player is None: return player = self.model.player next_creature = self.model.get_next_creature(self.rules_engine) if next_creature == player: point = self.view.mapToScene(event.pos()) x = int(point.x() / 32) y = int(point.y() / 32) player = self.model.player level = player.level location = player.location # if player was clicked, take stairs or open menu if (x, y) == location: if get_portal(level, location): if pyherc.vtable['\ufdd0:is-move-legal'](player, 9): pyherc.vtable['\ufdd0:move'](player, 9) else: self.MenuRequested.emit() elif is_move( event, player, (x, y)): # TODO: maybe moving should be possible with mouse? move(event, player, (x, y)) else: direction = find_direction(location, (x, y)) distance = distance_between(location, (x, y)) if distance == 1: #melee attack? if pyherc.vtable['\ufdd0:is-attack-legal'](player, direction): pyherc.vtable['\ufdd0:attack'](player, direction) else: if (location[0] == x) or (location[1] == y): if pyherc.vtable['\ufdd0:is-attack-legal'](player, direction): pyherc.vtable['\ufdd0:attack'](player, direction) self.process_npc()
def mouseEvent(self, event): """ Handle mouse events """ if self.model.player is None: return player = self.model.player next_creature = self.model.get_next_creature(self.rules_engine) if next_creature == player: point = self.view.mapToScene(event.pos()) x = int(point.x() / 32) y = int(point.y() / 32) player = self.model.player level = player.level location = player.location # if player was clicked, take stairs or open menu if (x, y) == location: if get_portal(level, location): if pyherc.vtable['\ufdd0:is-move-legal'](player, 9): pyherc.vtable['\ufdd0:move'](player, 9) else: self.MenuRequested.emit() elif is_move(event, player, (x, y)): # TODO: maybe moving should be possible with mouse? move(event, player, (x, y)) else: direction = find_direction(location, (x, y)) distance = distance_between(location, (x, y)) if distance == 1: #melee attack? if pyherc.vtable['\ufdd0:is-attack-legal'](player, direction): pyherc.vtable['\ufdd0:attack'](player, direction) else: if (location[0] == x) or (location[1] == y): if pyherc.vtable['\ufdd0:is-attack-legal'](player, direction): pyherc.vtable['\ufdd0:attack'](player, direction) self.process_npc()
def __call__(self, attacker): """ Performs the hit :param attacker: character attacking :type attacker: Character """ add_history_value(self.target, 'hit_points') rng = mock() when(rng).randint(1, 6).thenReturn(1) action_factory = (ActionFactoryBuilder().with_drink_factory(). with_inventory_factory().build()) set_action_factory( action_factory) # TODO: mutating global state is bad pyherc.vtable['\ufdd0:attack'](attacker, find_direction(attacker.location, self.target.location))
def __call__(self, attacker): """ Performs the hit :param attacker: character attacking :type attacker: Character """ add_history_value(self.target, 'hit_points') rng = mock() when(rng).randint(1, 6).thenReturn(1) action_factory = (ActionFactoryBuilder() .with_drink_factory() .with_inventory_factory() .build()) set_action_factory(action_factory) # TODO: mutating global state is bad pyherc.vtable['\ufdd0:attack'](attacker, find_direction(attacker.location, self.target.location))