示例#1
0
	def test_buff_stack_with_expiry_all_at_once(self):
		buffable = Buffable()

		buff = BuffSpec()
		buff.activation_triggers = []  # no triggers
		buff.conditions = []  # no conditions
		buff.max_stack = 3    # 3 stacks max#
		buff.duration_seconds = 10
		buff.modifiers = [Modifier("+", 10, Attributes.DEF)]

		with FixedTime(get_timestamp()):

			expiry_time = get_timestamp() + buff.duration_seconds

			# Add the buff for full 3 stacks
			add_buff(buffable, buff, CompleteBuildingEvent())
			add_buff(buffable, buff, CompleteBuildingEvent())
			add_buff(buffable, buff, CompleteBuildingEvent())

			assert buffable.attributes[Attributes.DEF] == 30
			assert buffable.active_buffs[buff.buff_id].stack == 3
			assert len(buffable.expiry_times) == 3

			with FixedTime(expiry_time):

				assert buffable.attributes[Attributes.DEF] == 0
				assert len(buffable.expiry_times) == 0
				assert buff.buff_id not in buffable.active_buffs
示例#2
0
	def test_next_to_expire(self):
		buffable = Buffable()

		buff = BuffSpec()
		buff.activation_triggers = []  # no triggers
		buff.conditions = []  # no conditions
		buff.duration_seconds = 10  # Only lasts for 10 seconds
		buff.max_stack = 3
		buff.modifiers = [Modifier("+", 50, Attributes.DEF)]

		with FixedTime(get_timestamp()):

			expiry_time = get_timestamp() + buff.duration_seconds

			# Add the buff 3 stacks
			add_buff(buffable, buff, CompleteBuildingEvent())
			add_buff(buffable, buff, CompleteBuildingEvent())
			add_buff(buffable, buff, CompleteBuildingEvent())

			with FixedTime(expiry_time):

				expired_buffs = list(get_expired_buffs(buffable))
				assert len(expired_buffs) == 3

				# Calling expired buffs should have removed them from expiry list
				assert len(buffable.expiry_times) == 0
示例#3
0
    def test_expiring_stacks(self):
        buffable = Buffable()

        buff = BuffSpec(1)
        buff.activation_triggers = []  # no triggers
        buff.conditions = []  # no conditions
        buff.duration_seconds = 10  # Only lasts for 10 seconds
        buff.max_stack = 2
        buff.modifiers = [Modifier("+", 50, Attributes.DEF)]

        # Add the buff 2 times, one in the future
        add_buff(buffable, buff, CompleteBuildingEvent())
        with FixedTime(get_timestamp() + 5):
            add_buff(buffable, buff, CompleteBuildingEvent())

        expiry_time_1 = get_timestamp() + buff.duration_seconds
        expiry_time_2 = expiry_time_1 + 5

        assert buffable.attributes[Attributes.DEF] == 100
        assert buffable.active_buffs[buff.buff_id].stack == 2
        assert len(buffable.expiry_times) == 2

        with FixedTime(expiry_time_1):
            assert buffable.attributes[Attributes.DEF] == 50
            assert buffable.active_buffs[buff.buff_id].stack == 1
            assert len(buffable.expiry_times) == 1

        with FixedTime(expiry_time_2):
            assert buffable.attributes[Attributes.DEF] == 0
            assert buff.buff_id not in buffable.active_buffs
            assert len(buffable.expiry_times) == 0
示例#4
0
    def test_getting_expired_buffs(self):
        register_expiry_time(self.buffable, self.buff_spec)

        assert len(list(get_expired_buffs(self.buffable))) == 0

        with FixedTime(get_timestamp() + self.buff_spec.duration_seconds):
            assert len(list(get_expired_buffs(self.buffable))) == 1
示例#5
0
    def test_registering_expiries(self):
        register_expiry_time(self.buffable, self.buff_spec)

        next_expiry_time, buff_id = self.buffable.expiry_times[0]

        assert next_expiry_time == get_timestamp(
        ) + self.buff_spec.duration_seconds
        assert buff_id == self.buff_spec.buff_id
示例#6
0
    def test_getting_expired_buffs_removing_from_expired_list(self):
        register_expiry_time(self.buffable, self.buff_spec)

        assert len(self.buffable.expiry_times) == 1

        with FixedTime(get_timestamp() + self.buff_spec.duration_seconds):

            # Run the generator
            list(get_expired_buffs(self.buffable))

            assert len(self.buffable.expiry_times) == 0
示例#7
0
    def test_adding_buff(self):
        buffable = Buffable()

        buff = BuffSpec(1)
        buff.activation_triggers = []  # no triggers
        buff.conditions = []  # no conditions
        buff.duration_seconds = 10  # Only lasts for 10 seconds
        buff.modifiers = [Modifier("+", 50, Attributes.DEF)]

        with FixedTime(get_timestamp()):
            # Add the buff
            expiry_time = get_timestamp() + 10

            add_buff(buffable, buff, CompleteBuildingEvent())

            # Since it has no triggers or conditions, it was added automatically
            assert buffable.attributes[Attributes.DEF] == 50
            assert buff.buff_id in buffable.active_buffs

            # Check the expiry time was registered
            registered_expiry_time, buff_id = buffable.expiry_times[0]
            assert registered_expiry_time == expiry_time
            assert buff_id == buff.buff_id
示例#8
0
    def test_buff_expiring(self):
        buffable = Buffable()

        buff = BuffSpec(1)
        buff.activation_triggers = []  # no triggers
        buff.conditions = []  # no conditions
        buff.duration_seconds = 10  # Only lasts for 10 seconds
        buff.modifiers = [Modifier("+", 50, Attributes.DEF)]

        expiry_time = get_timestamp() + buff.duration_seconds

        # Add the buff
        add_buff(buffable, buff, CompleteBuildingEvent())

        assert buffable.attributes[Attributes.DEF] == 50

        with FixedTime(expiry_time):
            # Simply by reading the attribute we will expire that buff
            assert buffable.attributes[Attributes.DEF] == 0
            # Should not be an active buff anymore
            assert buff.buff_id not in buffable.active_buffs
            # Expiry time
            assert len(buffable.expiry_times) == 0