def validate_kill(cls, attacker, victim): my_team = Team.get_by_id(attacker.team) if not my_team: logging.error("KILL: unable to get my team {} to validate kill"\ .format(attacker.team)) raise my_target = my_team.to_kill victim_team = Team.get_by_id(victim.team) if not victim_team: logging.error("KILL: unable to get vicitm team to validate kill") raise if victim_team.key.id() != my_target: logging.debug("KILL: target team {} != victim team {}".format(victim_team.key.id(), my_target)) raise TeamError if attacker.state == "DEAD": logging.debug("KILL: Attacker is DEAD") raise MeError(attacker.state) if victim.state != "ALIVE": logging.debug("KILL: Victim is DEAD") raise TargetError(victim.state) if victim.invul: logging.debug("KILL: Victim is INVUL") raise TargetError("INVUL") if attacker.disarm: logging.debug("KILL: Attacker is DISARM") raise MeError("DISARM") logging.info("KILL: kill validated")
def validate_kill(cls, attacker, victim): my_team = Team.get_by_id(attacker.team) if not my_team: logging.error("KILL: unable to get my team {} to validate kill".format(attacker.team)) raise my_target = my_team.to_kill victim_team = Team.get_by_id(victim.team) if not victim_team: logging.error("KILL: unable to get vicitm team to validate kill") raise if victim_team.key.id() != my_target: logging.debug("KILL: target team {} != victim team {}".format(victim_team.key.id(), my_target)) raise TeamError if attacker.state == "DEAD": logging.debug("KILL: Attacker is DEAD") raise MeError(attacker.state) if victim.state != "ALIVE": logging.debug("KILL: Victim is DEAD") raise TargetError(victim.state) if victim.invul: logging.debug("KILL: Victim is INVUL") raise TargetError("INVUL") if attacker.disarm: logging.debug("KILL: Attacker is DISARM") raise MeError("DISARM") logging.info("KILL: kill validated")
def validate_disarm(cls, attacker, victim): my_team = Team.get_by_id(attacker.team) if not my_team: logging.error("DISARM: unable to get my team {} to validate kill"\ .format(attacker.team)) raise my_target = my_team.target_of victim_team = Team.get_by_id(victim.team) if not victim_team: logging.error("DISARM: unable to get vicitm team to validate kill") raise if victim_team.key.id() != my_target: logging.debug("DISARM: target team != victim team") raise TeamError if attacker.state == "DEAD": logging.debug("DISARM: Attacker is DEAD") raise MeError(attacker.state) if victim.state == "DEAD": logging.debug("DISARM: Victim is DEAD") raise TargetError(victim.state)
def handler(cls, attacker, victim_codename): logging.info("SNIPE start.") victim = Util.get_victim(victim_codename) logging.info("Attacker {}".format(attacker)) logging.info("Victim {}".format(victim)) """ validation """ outgoing = [] try: Kill.validate_kill(attacker, victim) if attacker.role != "SNIPER": raise MeError("not SNIPER") except (TeamError, MeError, TargetError) as message: outgoing.append((WEI_HAN, message.message)) outgoing.append((attacker.key.id(), message.message)) return outgoing except: message = "[ERR] Unknown Error in SNIPE" outgoing.append((WEI_HAN, message)) outgoing.append((attacker.key.id(), message)) return outgoing action = Action() action.attacker = attacker.key.id() action.action = "SNIPE" action.victim = victim.key.id() action.datetime = datetime.now() action_key = action.put() attacker = Player.get_by_id(action.attacker) attacker.killed.append(str(action_key.id())) attacker.put() victim.state = "DEAD" victim.killed_by = str(action_key.id()) victim.put() message = "{} has been SNIPED.".format(victim_codename) outgoing.append((victim.key.id(), "You have been SNIPED. (Ref {}).".\ format(action_key.id()))) outgoing.append(("*", message)) outgoing += Team.push(Team.get_by_id(victim.team)) return outgoing
def handler(cls, ref, params, From): logging.debug("REPLY {}".format(ref)) lookup = Action.get_by_id(int(ref)) if not lookup: raise ReplyError("ref num", ref) response = params[0] if response != "Y" and response != "y" and response != "N" and response != "n": raise ReplyError(response, ref) if lookup.action == "DISARM": return Disarm.reply_handler(lookup, response) else: output_msg = [] if lookup.action == "KILL": output_msg += Kill.reply_handler(lookup, response) elif lookup.action == "BOMB": output_msg += Bomb.reply_handler(lookup, response, From) """ Generate push if necessary """ output_msg += Team.push(Team.get_by_id(From.team)) return output_msg raise ReplyError(response, ref)