Example #1
0
    def collect(self):
        if g.user is not None and g.user.current_player is not None:
            player = g.user.current_player
        else:
            # FIXME throw proper error
            return None

        # Check if the player is in range
        if self.distance_max is not None:
            if self.distance_max < self.distance_to(player):
                return send_action("notice", self, "You are too far away!")

        # Check if the player already has the maximum amount of items of a class
        if self.owned_max is not None:
            if player.has_item(self.__class__) >= self.owned_max:
                return send_action("notice", self, "You have already collected enough of this!")

        # Check if the collection is allowed
        if self.collectible and self.isonmap and self.may_collect(player):
            # Change owner
            self.owner = player
            self.on_collected()
            DB.session.add(self)
            DB.session.commit()
            return redirect(url_for(self.__class__, resource_id=self.id))
        else:
            return send_action("notice", self, "You cannot collect this!")
Example #2
0
    def talk(self):
        if g.user is not None and g.user.current_player is not None:
            player = g.user.current_player
        else:
            # FIXME throw proper error
            return None

        if self.distance_max is not None:
            if self.distance_max < self.distance_to(player):
                return send_action("notice", self, "You are too far away!")

        if self.talkable and self.isonmap and self.may_talk(player):
            return self.on_talk()
        else:
            return send_action("notice", self, "You cannot tolk to this character!")
Example #3
0
    def talk(self):
        if g.user is not None and g.user.current_player is not None:
            player = g.user.current_player
        else:
            # FIXME throw proper error
            return None

        # Check if the player is in range for talking to the NPC
        if self.distance_max is not None:
            if self.distance_max < self.distance_to(player):
                return send_action("notice", self, "You are too far away!")

        # Check if talking to the NPC is allowed
        if self.talkable and self.isonmap and self.may_talk(player):
            # Run talk logic
            return self.on_talk()
        else:
            return send_action("notice", self, "You cannot talk to this character!")
Example #4
0
 def handover(self, target_player):
     if self.owner is not None and self.handoverable and self.may_handover(target_player) and target_player.may_accept_handover(self):
         self.owner = target_player
         self.on_handedover()
         DB.session.add(self)
         DB.session.commit()
         return redirect("/api/gameobject_item/%i" % self.id)
     else:
         return send_action("notice", self, "You cannot hand this over.")
Example #5
0
 def handover(self, target_player):
     # Check if the handover is allowed
     if self.owner is not None and self.handoverable and self.may_handover(target_player) and target_player.may_accept_handover(self):
         # Change owner
         self.owner = target_player
         self.on_handedover()
         DB.session.add(self)
         DB.session.commit()
         return redirect(url_for(self.__class__, resource_id=self.id))
     else:
         return send_action("notice", self, "You cannot hand this over.")
Example #6
0
    def collect(self):
        if g.user is not None and g.user.current_player is not None:
            player = g.user.current_player
        else:
            # FIXME throw proper error
            return None

        if self.distance_max is not None:
            if self.distance_max < self.distance_to(player):
                return send_action("notice", self, "You are too far away!")

        if self.owned_max is not None:
            if player.has_item(self.__class__) >= self.owned_max:
                return send_action("notice", self, "You have already collected enough of this!")

        if self.collectible and self.isonmap and self.may_collect(player):
            self.owner = player
            self.isonmap = False
            self.on_collected()
            DB.session.add(self)
            DB.session.commit()
            return redirect("/api/gameobject_item/%i" % self.id)
        else:
            return send_action("notice", self, "You cannot collect this!")
Example #7
0
 def say(self, message):
     return send_action("say", self, message)
Example #8
0
 def say(self, message):
     return send_action("say", self, message)