示例#1
0
文件: Monster.py 项目: hathcox/Arthur
 def get_monster(cls, user):
     ''' Based on the users quest and level this will choose an appropriate monster '''
     quest = Quest.by_id(user.quest_level)
     #If we are still on quests
     if quest != None:
         #Get all valid monsters
         all = dbsession.query(cls).filter(cls.level<=quest.max_monster_level).filter(cls.level>=quest.min_monster_level).all()
         return choice(all)
     return choice(cls.get_all())
示例#2
0
文件: Battle.py 项目: hathcox/Arthur
    def check_ended(self):
        """ This checks wether a user or monster is dead """
        valid_user = User.by_id(self.user.id)
        # check is the user died
        if self.monster.health <= 0:
            # update the user
            valid_user.experience += self.monster.experience
            valid_user.gold += self.monster.gold

            # Grab the quest
            quest = Quest.by_id(valid_user.quest_level)
            if quest != None:
                # If we still have battles left in our quest
                if valid_user.current_quest_battle < quest.number_of_battles:
                    valid_user.current_quest_battle += 1
                # If not, give us the next quest
                else:
                    valid_user.current_quest_battle = 0
                    valid_user.quest_level += 1
            dbsession.add(valid_user)
            dbsession.flush()

            # set variable for the client
            self.victor = self.user
            self.text = self.user.name + " has defeated " + self.monster.name + " !"
            self.exp = self.monster.experience
            self.gold = self.monster.gold
            return True

        elif self.user.health <= 0:
            # decrement experience
            valid_user.lost_battle()
            dbsession.add(valid_user)
            dbsession.flush()

            # set variable for the client
            self.victor = self.monster
            self.text = self.monster.name + " has defeated " + self.user.name + " !"
            self.exp = self.user.experience - valid_user.experience
            self.gold = 0
            return True

        # Both user and monster are alive
        return False