def player_move_or_attack(player, direction, try_running): """ Returns true if the player makes an attack or moves successfully; false if the attempt to move fails. """ goal = player.pos + direction if (goal.x < 0 or goal.y < 0 or goal.x >= player.current_map.width or goal.y >= player.current_map.height): log.message(player.current_map.out_of_bounds(goal)) return False # Is there an attackable object? target_obj = None for obj in player.current_map.objects: if obj.fighter and obj.pos == goal: target_obj = obj break if target_obj is not None: # Make sure we're not going up or down a cliff if not player.current_map.is_blocked_from( player.pos, target_obj.pos, ignore=target_obj): actions.attack(player.fighter, target_obj) return True return False # Is there an interactable object? target_obj = None for obj in player.current_map.objects: if obj.interactable and obj.pos == goal: target_obj = obj break if target_obj is not None: target_obj.interactable.use_function(player, target_obj) return True elevation_before_moving = player.current_map.elevation( player.pos.x, player.pos.y) if actions.move(player, direction): player.current_map.fov_needs_recompute = True if player.current_map.xp_visit: player.current_map.xp_visit(player.current_map, player) if player.current_map.is_outdoors: new_region = player.current_map.region[player.pos.x][player.pos.y] new_elevation = player.current_map.region_elevations[new_region] if new_elevation != elevation_before_moving: player.current_map.fov_elevation_changed = True player.fighter.exhaustion += actions.CLIMB_EXHAUSTION if try_running: player.game_state = 'running' player.run_direction = direction # Automatically sweep up ammunition after a shooting spree ammo_eq = actions.get_equipped_in_slot(player, 'quiver') if ammo_eq: for obj in player.current_map.objects: if (obj.pos == player.pos and obj.item and obj.item.can_combine(ammo_eq.owner)): actions.pick_up(player, obj) return True return False
def player_move_or_attack(player, direction, try_running): """ Returns true if the player makes an attack or moves successfully; false if the attempt to move fails. """ goal = player.pos + direction if (goal.x < 0 or goal.y < 0 or goal.x >= player.current_map.width or goal.y >= player.current_map.height): log.message(player.current_map.out_of_bounds(goal)) return False # Is there an attackable object? target = None for object in player.current_map.objects: if object.fighter and object.pos == goal: target = object break if target is not None: actions.attack(player.fighter, target) return True else: if actions.move(player, direction): player.current_map.fov_needs_recompute = True if try_running: player.game_state = 'running' player.run_direction = direction return True return False
def basic_monster(monster, player): if libtcodpy.map_is_in_fov(monster.current_map.fov_map, monster.x_pos, monster.y_pos): if monster.distance_to(player) >= 2: actions.move_towards(monster, player.x_pos, player.y_pos) elif player.fighter.hp > 0: actions.attack(monster.fighter, player)
def player_move_or_attack(player, direction, try_running): """ Returns true if the player makes an attack or moves successfully; false if the attempt to move fails. """ goal = player.pos + direction if (goal.x < 0 or goal.y < 0 or goal.x >= player.current_map.width or goal.y >= player.current_map.height): log.message(player.current_map.out_of_bounds(goal)) return False # Is there an attackable object? target_obj = None for obj in player.current_map.objects: if obj.fighter and obj.pos == goal: target_obj = obj break if target_obj is not None: # Make sure we're not going up or down a cliff if not player.current_map.is_blocked_from(player.pos, target_obj.pos, ignore=target_obj): actions.attack(player.fighter, target_obj) return True return False # Is there an interactable object? target_obj = None for obj in player.current_map.objects: if obj.interactable and obj.pos == goal: target_obj = obj break if target_obj is not None: target_obj.interactable.use_function(player, target_obj) return True elevation_before_moving = player.current_map.elevation(player.pos.x, player.pos.y) if actions.move(player, direction): player.current_map.fov_needs_recompute = True if player.current_map.xp_visit: player.current_map.xp_visit(player.current_map, player) if player.current_map.is_outdoors: new_region = player.current_map.region[player.pos.x][player.pos.y] new_elevation = player.current_map.region_elevations[new_region] if new_elevation != elevation_before_moving: player.current_map.fov_elevation_changed = True player.fighter.exhaustion += actions.CLIMB_EXHAUSTION if try_running: player.game_state = 'running' player.run_direction = direction # Automatically sweep up ammunition after a shooting spree ammo_eq = actions.get_equipped_in_slot(player, 'quiver') if ammo_eq: for obj in player.current_map.objects: if (obj.pos == player.pos and obj.item and obj.item.can_combine(ammo_eq.owner)): actions.pick_up(player, obj) return True return False
def basic_monster(monster, player, metadata): """ A basic monster takes its turn. if you can see it, it can see you. """ if libtcod.map_is_in_fov(monster.current_map.fov_map, monster.x, monster.y): if monster.distance_to(metadata.target) >= 2: actions.move_towards(monster, metadata.target.pos) elif metadata.target.fighter.hp > 0: actions.attack(monster.fighter, metadata.target)
def hostile_monster(monster, player, metadata): """ A basic monster takes its turn. if you can see it, it can see you. """ _spotting(monster, metadata) if metadata.active_turns > 0: metadata.active_turns -= 1 if monster.pos.distance(metadata.last_seen_pos) >= 2: actions.move_towards(monster, metadata.last_seen_pos) elif (monster.pos.distance(metadata.target.pos) < 2 and metadata.target.fighter.hp > 0): if not monster.current_map.is_blocked_from( monster.pos, metadata.target.pos, ignore=metadata.target): actions.attack(monster.fighter, metadata.target)
def player_move_or_attack(player, dx, dy): x = player.x_pos + dx y = player.y_pos + dy target = None for entity in player.current_map.map_entities: if entity.fighter and entity.x_pos == x and entity.y_pos == y: target = entity break if target is not None: actions.attack(player.fighter, target) else: if actions.move(player, dx, dy): player.current_map.fov_needs_recompute = True
def hostile_monster(monster, player, metadata): """ A basic monster takes its turn. if you can see it, it can see you. """ _spotting(monster, metadata) if metadata.active_turns > 0: metadata.active_turns -= 1 if monster.pos.distance(metadata.last_seen_pos) >= 2: actions.move_towards(monster, metadata.last_seen_pos) elif (monster.pos.distance(metadata.target.pos) < 2 and metadata.target.fighter.hp > 0): if not monster.current_map.is_blocked_from(monster.pos, metadata.target.pos, ignore=metadata.target): actions.attack(monster.fighter, metadata.target)
def order(self, order, order_vars=None): if order == "Attack": if not self.canAttack(): print("Bad Attack order") exit() self.lastAttack = self.army.battle.round self.attackUnit(order_vars) elif order == "Feed": if self.hasTrait("Ravenous") and self.canFeed(): self.heal() else: print("Bad Feed Order") exit() elif order == "Sap": if not self.hasTrait("Twisting Roots"): print("Bad Twisting Roots order") exit() #TODO safety that order_vars is correct type if order_vars.utype == "Fortification": #TODO sapping print("Not implented") exit() elif order == "Charge": attack(self, order_vars, True) elif order == "Disengage": if self.moraleCheck(13): self.disengages() elif order == "None": pass else: print("bad order") exit() self.exhaust() return
def action_detail(request): if request.method == 'POST': serializer = ActionSerializer(data=request.data) if serializer.is_valid(): tile_acting = serializer.validated_data['tile_acting'] tile_effected = serializer.validated_data['tile_effected'] map = serializer.validated_data['map'] action_type = serializer.validated_data['action_type'] # Validation rules for suspicious calls if tile_acting.owner != request.user: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) if tile_acting.map != map or tile_effected.map != map: return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) if action_type == "ATT": tile_acting, tile_effected = attack(map, tile_acting, tile_effected) # if tile_effected.tiles == 0, prompt for movement action details on UI if action_type == "MOVE": units_to_move = serializer.validated_data['units'] tile_acting, tile_effected = move(map, tile_acting, tile_effected, units_to_move) serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def attackUnit(self, unit): attack(self, unit)
def available_actions(self): if self.enemy.is_alive(): return [actions.flee(title=self), actions.attack(enemy=self.enemy)] else: return self.adjacent_moves()
def checkClicked(self): mousePOS = p.mouse.get_pos() if self.currentButt != None: if self.currentButt.getName() == "Attack": actions.attack(self.hero, self.enemy, True)
def atakuj(enemy, army): actions.attack(enemy, army)