def accept(self, irc, msg, args, user, target_nick): """ accept <nick> - Accepts a challenge from another player """ dungeon_info = self._get_dungeon_and_user_id(irc, msg) if dungeon_info is not None: dungeon = dungeon_info["dungeon"] player = dungeon_info["player"] combatant = dungeon.get_living_unit_by_name(target_nick) if combatant is not None: player.add_battle(combatant=combatant, rounds=3) combatant.add_battle(combatant=player, rounds=3) pnick = player.nick player_announcer = PlayerAnnouncer(irc=irc, destination=pnick) player_announcer.challenge_accepted(combatant=combatant) dungeon.announcer.challenge_accepted(attacker=player, target=combatant) else: irc.error("That target seems to be dead or non-existent.")
def challenge(self, irc, msg, args, user, unit_name): """ challenge <target> - Challenge target to battle """ """ 1. Get player and unit 2. Get last battle for player and target and make sure both are not None 3. The unit that did not go last is the attacker, or the challenger """ dungeon_info = self._get_dungeon_and_user_id(irc, msg) if dungeon_info is not None: dungeon = dungeon_info["dungeon"] player = dungeon_info["player"] combatant = dungeon.get_living_unit_by_name(unit_name) if combatant is not None: can_battle = player.can_battle_unit(unit=combatant) if can_battle is not True: irc.error("You can't challenge that: %s" % can_battle) return last_battle = player.get_last_incomplete_battle( combatant=combatant) """ If there is an existing battle, they cannot challenge """ if last_battle is not None: irc.error("You're already battling that") return combatant_announcer = PlayerAnnouncer(irc=irc, destination=combatant.nick) player_announcer = PlayerAnnouncer(irc=irc, destination=player.nick) """ New battle if this is a NPC """ if combatant.is_npc: player.add_battle(combatant=combatant, rounds=3) combatant.add_battle(combatant=player, rounds=3) dungeon.announcer.challenge_accepted(attacker=player, target=combatant) player_announcer.challenge_accepted(combatant=combatant) else: """ We don't really need to tell players that their challenge was sent to a NPC since the NPC always accepts. """ player_announcer.challenge_sent(combatant=combatant) """ Combatant is not a player. Let them know they've received a challenge. """ combatant_announcer.challenge_received(combatant=player) """ Schedule challenge forfeit if the challenge was not accepted within the timeout. challenge_timeout = 30 def check_challenge_timeout(): challenge = combatant.get_last_battle_by_combatant(combatant=player) if challenge is not None: seconds_since_challenge = time.time() - challenge.created_at if seconds_since_challenge >= challenge_timeout: player.cancel_challenge(combatant=combatant) schedule.addEvent(check_challenge_timeout, time.time() + challenge_timeout, name="check_challenge_timeout") """ else: irc.error("Invalid target")