示例#1
0
    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")
示例#2
0
    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")
示例#3
0
    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
示例#4
0
    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
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()
        self.testbed.init_taskqueue_stub(root_path=".")
        self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        # Setup fixture
        today = Util.next_day() - timedelta(days=1)

        # Make Team 1 and populate with player 1a, 1b, 1c. 
        # p1a is ALIVE and DEMO
        # p1b is ALIVE, DISARM, and SNIPER
        # p1c is ALIVE, MEDIC
        self.team1 = Team(id = "Team1", to_kill="Team2", target_of="Team3")
        self.p1a = Player(id="+1", realname="player1a", codename="p1a",\
                team="Team1", state="ALIVE", role="DEMO", can_set_after=today)
        self.team1.demo = "+1"
        self.p1a.put()
        self.p1b = Player(id="+2", realname="player1b", codename="p1b",\
                team="Team1", state="ALIVE", disarm=True, role="SNIPER",\
                can_set_after=today)
        self.team1.sniper="+2"
        self.p1b.put()
        self.p1c = Player(id="+3", realname="player1c", codename="p1c",\
                team="Team1", state="ALIVE", role="MEDIC", can_set_after=today)
        self.team1.medic="+3"
        self.p1c.put()
        self.team1.put()

        # Make Team 2 and populate with player 2a, 2b, 2c.
        # p2a is ALIVE
        # p2b is DEAD
        # p2c is INVUL
        self.team2 = Team(id="Team2", to_kill="Team3", target_of="Team1")
        self.p2a = Player(id="+4", realname="player2a", codename="p2a",\
                team="Team2", state="ALIVE", role="DEMO", can_set_after=today)
        self.team2.demo = "+4"
        self.p2a.put()
        self.p2b = Player(id="+5", realname="player2b", codename="p2b",\
                team="Team2", state="DEAD", role="SNIPER", can_set_after=today)
        self.team2.sniper="+5"
        self.p2b.put()
        self.p2c = Player(id="+6", realname="player2c", codename="p2c",\
                team="Team2", state="ALIVE", invul=True, role="MEDIC",\
                can_set_after=today)
        self.team2.medic="+6"
        self.p2c.put()
        self.team2.put()
        
        # Make Team 3 and populate with player 3a, 3b, 3c.
        self.team3 = Team(id="Team3", to_kill="Team1", target_of="Team2")
        self.p3a = Player(id="+7", realname="player3a", codename="p3a",\
                team="Team3", state="ALIVE", role="DEMO", can_set_after=today)
        self.team3.demo = "+7"
        self.p3a.put()
        self.p3b = Player(id="+8", realname="player3b", codename="p3b",\
                team="Team3", state="ALIVE", role="SPY", can_set_after=today)
        self.team3.sniper="+8"
        self.p3b.put()
        self.p3c = Player(id="+9", realname="player3c", codename="p3c",\
                team="Team3", state="ALIVE", role="MEDIC", can_set_after=today)
        self.team3.medic="+9"
        self.p3c.put()
        self.team3.put()
示例#8
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        ndb.get_context().clear_cache()
        self.testbed.init_taskqueue_stub(root_path=".")
        self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
        # Setup fixture
        today = Util.next_day() - timedelta(days=1)

        # Make Team 1 and populate with player 1a, 1b, 1c.
        # p1a is ALIVE and DEMO
        # p1b is ALIVE, DISARM, and SNIPER
        # p1c is ALIVE, MEDIC
        self.team1 = Team(id="Team1", to_kill="Team2", target_of="Team3")
        self.p1a = Player(
            id="+1", realname="player1a", codename="p1a", team="Team1", state="ALIVE", role="DEMO", can_set_after=today
        )
        self.team1.demo = "+1"
        self.p1a.put()
        self.p1b = Player(
            id="+2",
            realname="player1b",
            codename="p1b",
            team="Team1",
            state="ALIVE",
            disarm=True,
            role="SNIPER",
            can_set_after=today,
        )
        self.team1.sniper = "+2"
        self.p1b.put()
        self.p1c = Player(
            id="+3", realname="player1c", codename="p1c", team="Team1", state="ALIVE", role="MEDIC", can_set_after=today
        )
        self.team1.medic = "+3"
        self.p1c.put()
        self.team1.put()

        # Make Team 2 and populate with player 2a, 2b, 2c.
        # p2a is ALIVE
        # p2b is DEAD
        # p2c is INVUL
        self.team2 = Team(id="Team2", to_kill="Team3", target_of="Team1")
        self.p2a = Player(
            id="+4", realname="player2a", codename="p2a", team="Team2", state="ALIVE", role="DEMO", can_set_after=today
        )
        self.team2.demo = "+4"
        self.p2a.put()
        self.p2b = Player(
            id="+5", realname="player2b", codename="p2b", team="Team2", state="DEAD", role="SNIPER", can_set_after=today
        )
        self.team2.sniper = "+5"
        self.p2b.put()
        self.p2c = Player(
            id="+6",
            realname="player2c",
            codename="p2c",
            team="Team2",
            state="ALIVE",
            invul=True,
            role="MEDIC",
            can_set_after=today,
        )
        self.team2.medic = "+6"
        self.p2c.put()
        self.team2.put()

        # Make Team 3 and populate with player 3a, 3b, 3c.
        self.team3 = Team(id="Team3", to_kill="Team1", target_of="Team2")
        self.p3a = Player(
            id="+7", realname="player3a", codename="p3a", team="Team3", state="ALIVE", role="DEMO", can_set_after=today
        )
        self.team3.demo = "+7"
        self.p3a.put()
        self.p3b = Player(
            id="+8", realname="player3b", codename="p3b", team="Team3", state="ALIVE", role="SPY", can_set_after=today
        )
        self.team3.sniper = "+8"
        self.p3b.put()
        self.p3c = Player(
            id="+9", realname="player3c", codename="p3c", team="Team3", state="ALIVE", role="MEDIC", can_set_after=today
        )
        self.team3.medic = "+9"
        self.p3c.put()
        self.team3.put()