Esempio n. 1
0
    def at_repeat(self):
        """
        Trigger events.
        """
        if not self.obj.location:
            # The character's location is empty (maybe just login).
            return

        if self.obj.location != self.db.room:
            # The character has left the room.
            self.obj.scripts.delete(self)
            return

        # Do actions.
        func = EVENT_ACTION_SET.func(self.db.action)
        if func:
            func(self.db.event_key, self.obj, self.db.room)
Esempio n. 2
0
    def at_repeat(self):
        """
        Trigger events.
        """
        if not self.obj.location:
            # The character's location is empty (maybe just login).
            return

        if self.obj.location != self.db.room:
            # The character has left the room.
            self.obj.scripts.delete(self)
            return

        # Do actions.
        if self.db.offline:
            self.db.last_trigger_time = time.time()
        func = EVENT_ACTION_SET.func(self.db.action)
        if func:
            func(self.db.event_key, self.obj, self.db.room)
Esempio n. 3
0
    def trigger(self, event_type, character, obj):
        """
        Trigger an event.

        Args:
            event_type: (string) event's type.
            character: (object) the character who trigger this event.
            obj: (object) the event object.

        Return:
            triggered: (boolean) if an event is triggered.
        """
        if not character:
            return False

        if self.can_bypass(character):
            return False

        if event_type not in self.events:
            return False

        # Get all event's of this type.
        event_list = self.events[event_type]

        candidates = [
            e for e in event_list
            if not character.is_event_closed(e["key"]) and
            STATEMENT_HANDLER.match_condition(e["condition"], character, obj)
        ]

        rand = random.random()
        for event in candidates:
            if rand < event["odds"]:
                func = EVENT_ACTION_SET.func(event["action"])
                if func:
                    func(event["key"], character, obj)
                return True
            rand -= event["odds"]
Esempio n. 4
0
    def trigger(self, event_type, character, obj):
        """
        Trigger an event.

        Args:
            event_type: (string) event's type.
            character: (object) the character who trigger this event.
            obj: (object) the event object.

        Return:
            triggered: (boolean) if an event is triggered.
        """
        if not character:
            return False

        if self.can_bypass(character):
            return False

        if event_type not in self.events:
            return False

        # Get all event's of this type.
        event_list = self.events[event_type]

        candidates = [e for e in event_list
                         if not character.is_event_closed(e["key"]) and
                             STATEMENT_HANDLER.match_condition(e["condition"], character, obj)]

        rand = random.random()
        for event in candidates:
            if rand < event["odds"]:
                func = EVENT_ACTION_SET.func(event["action"])
                if func:
                    func(event["key"], character, obj)
                return True
            rand -= event["odds"]