can now pause infinite duration buffs
This commit is contained in:
parent
87a990616f
commit
8397b9205b
1 changed files with 24 additions and 18 deletions
|
|
@ -877,23 +877,25 @@ class BuffHandler:
|
||||||
start = buff["start"] # Start
|
start = buff["start"] # Start
|
||||||
duration = buff["duration"] # Duration
|
duration = buff["duration"] # Duration
|
||||||
prevtick = buff["prevtick"] # Previous tick timestamp
|
prevtick = buff["prevtick"] # Previous tick timestamp
|
||||||
tickrate = buff["ref"].tickrate # Buff's tick rate
|
tickrate = buff["tickrate"] # Buff's tick rate
|
||||||
|
|
||||||
# Original buff ending, and new duration
|
|
||||||
end = start + duration # End
|
end = start + duration # End
|
||||||
newduration = end - current # New duration
|
|
||||||
|
|
||||||
# Apply the new duration
|
# Setting "tickleft"
|
||||||
if newduration > 0:
|
if buff["ref"].ticking:
|
||||||
buff["duration"] = newduration
|
buff["tickleft"] = max(1, tickrate - (current - prevtick))
|
||||||
if buff["ref"].ticking:
|
|
||||||
buff["tickleft"] = max(1, tickrate - (current - prevtick))
|
# Setting the new duration (if applicable)
|
||||||
self.buffcache[key] = buff
|
if duration > -1:
|
||||||
instance: BaseBuff = buff["ref"](self, key, buff)
|
newduration = end - current # New duration
|
||||||
instance.at_pause(**context)
|
if newduration > 0:
|
||||||
else:
|
buff["duration"] = newduration
|
||||||
self.remove(key)
|
else:
|
||||||
return
|
self.remove(key)
|
||||||
|
|
||||||
|
# Apply new cache info, call pause hook
|
||||||
|
self.buffcache[key] = buff
|
||||||
|
instance: BaseBuff = buff["ref"](self, key, buff)
|
||||||
|
instance.at_pause(**context)
|
||||||
|
|
||||||
def unpause(self, key: str, context=None):
|
def unpause(self, key: str, context=None):
|
||||||
"""Unpauses a buff. This makes it visible to the various buff systems again.
|
"""Unpauses a buff. This makes it visible to the various buff systems again.
|
||||||
|
|
@ -920,15 +922,19 @@ class BuffHandler:
|
||||||
buff["start"] = current
|
buff["start"] = current
|
||||||
if buff["ref"].ticking:
|
if buff["ref"].ticking:
|
||||||
buff["prevtick"] = current - (tickrate - tickleft)
|
buff["prevtick"] = current - (tickrate - tickleft)
|
||||||
|
|
||||||
|
# Apply new cache info, call hook
|
||||||
self.buffcache[key] = buff
|
self.buffcache[key] = buff
|
||||||
instance: BaseBuff = buff["ref"](self, key, buff)
|
instance: BaseBuff = buff["ref"](self, key, buff)
|
||||||
instance.at_unpause(**context)
|
instance.at_unpause(**context)
|
||||||
utils.delay(buff["duration"], cleanup_buffs, self, persistent=True)
|
|
||||||
|
# Set up typical delays (cleanup/ticking)
|
||||||
|
if instance.duration > -1:
|
||||||
|
utils.delay(buff["duration"], cleanup_buffs, self, persistent=True)
|
||||||
if instance.ticking:
|
if instance.ticking:
|
||||||
utils.delay(
|
utils.delay(
|
||||||
tickrate, tick_buff, handler=self, buffkey=key, initial=False, persistent=True
|
tickrate, tick_buff, handler=self, buffkey=key, initial=False, persistent=True
|
||||||
)
|
)
|
||||||
return
|
|
||||||
|
|
||||||
def view(self, to_filter=None) -> dict:
|
def view(self, to_filter=None) -> dict:
|
||||||
"""Returns a buff flavor text as a dictionary of tuples in the format {key: (name, flavor)}. Common use for this is a buff readout of some kind.
|
"""Returns a buff flavor text as a dictionary of tuples in the format {key: (name, flavor)}. Common use for this is a buff readout of some kind.
|
||||||
|
|
@ -1157,7 +1163,7 @@ def tick_buff(handler: BuffHandler, buffkey: str, context=None, initial=True):
|
||||||
tr = max(1, buff.tickrate)
|
tr = max(1, buff.tickrate)
|
||||||
|
|
||||||
# This stops the old ticking process if you refresh/stack the buff
|
# This stops the old ticking process if you refresh/stack the buff
|
||||||
if tr > time.time() - buff.prevtick and initial != True:
|
if (tr > time.time() - buff.prevtick and initial != True) or buff.paused:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Only fire the at_tick methods if the conditional is truthy
|
# Only fire the at_tick methods if the conditional is truthy
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue