QoL: DragonSoul Timer Refactored
This commit is contained in:
@@ -670,6 +670,8 @@ class DragonSoulWindow(ui.ScriptWindow):
|
|||||||
def DeactivateDragonSoul(self):
|
def DeactivateDragonSoul(self):
|
||||||
self.isActivated = False
|
self.isActivated = False
|
||||||
self.activateButton.SetUp()
|
self.activateButton.SetUp()
|
||||||
|
if self.tooltipItem:
|
||||||
|
self.tooltipItem.ClearDragonSoulTimeCache()
|
||||||
|
|
||||||
# MR-3: Keyboard-enabled deck toggling
|
# MR-3: Keyboard-enabled deck toggling
|
||||||
def ActivateButtonClick(self, deckIndex = None):
|
def ActivateButtonClick(self, deckIndex = None):
|
||||||
|
|||||||
@@ -499,17 +499,20 @@ class ItemToolTip(ToolTip):
|
|||||||
# When displaying item tooltip, if the current character cannot equip the item, force it to use Disable Color (already works this way but needed ability to turn it off)
|
# When displaying item tooltip, if the current character cannot equip the item, force it to use Disable Color (already works this way but needed ability to turn it off)
|
||||||
self.bCannotUseItemForceSetDisableColor = True
|
self.bCannotUseItemForceSetDisableColor = True
|
||||||
|
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = -1
|
self.itemSlotIndex = -1
|
||||||
self._wearTimerCache = {}
|
self.wndDragonSoul = None
|
||||||
self._dragonSoulWindow = None
|
self.dsActivatedTimeCache = {}
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
ToolTip.__del__(self)
|
ToolTip.__del__(self)
|
||||||
self.metinSlot = None
|
self.metinSlot = None
|
||||||
|
|
||||||
def SetDragonSoulWindow(self, wnd):
|
def SetDragonSoulWindow(self, wnd):
|
||||||
self._dragonSoulWindow = wnd
|
self.wndDragonSoul = wnd
|
||||||
|
|
||||||
|
def ClearDragonSoulTimeCache(self):
|
||||||
|
self.dsActivatedTimeCache = {}
|
||||||
|
|
||||||
def SetCannotUseItemForceSetDisableColor(self, enable):
|
def SetCannotUseItemForceSetDisableColor(self, enable):
|
||||||
self.bCannotUseItemForceSetDisableColor = enable
|
self.bCannotUseItemForceSetDisableColor = enable
|
||||||
@@ -576,10 +579,8 @@ class ItemToolTip(ToolTip):
|
|||||||
def ClearToolTip(self):
|
def ClearToolTip(self):
|
||||||
self.isShopItem = False
|
self.isShopItem = False
|
||||||
self.toolTipWidth = self.TOOL_TIP_WIDTH
|
self.toolTipWidth = self.TOOL_TIP_WIDTH
|
||||||
|
self.itemWindowType = None
|
||||||
self._curItemWindowType = None
|
self.itemSlotIndex = -1
|
||||||
self._curItemSlotIndex = -1
|
|
||||||
|
|
||||||
ToolTip.ClearToolTip(self)
|
ToolTip.ClearToolTip(self)
|
||||||
|
|
||||||
def SetInventoryItem(self, slotIndex, window_type = player.INVENTORY):
|
def SetInventoryItem(self, slotIndex, window_type = player.INVENTORY):
|
||||||
@@ -596,8 +597,8 @@ class ItemToolTip(ToolTip):
|
|||||||
metinSlot = [player.GetItemMetinSocket(window_type, slotIndex, i) for i in xrange(player.METIN_SOCKET_MAX_NUM)]
|
metinSlot = [player.GetItemMetinSocket(window_type, slotIndex, i) for i in xrange(player.METIN_SOCKET_MAX_NUM)]
|
||||||
attrSlot = [player.GetItemAttribute(window_type, slotIndex, i) for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM)]
|
attrSlot = [player.GetItemAttribute(window_type, slotIndex, i) for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM)]
|
||||||
|
|
||||||
self._curItemWindowType = window_type
|
self.itemWindowType = window_type
|
||||||
self._curItemSlotIndex = slotIndex
|
self.itemSlotIndex = slotIndex
|
||||||
self.AddItemData(itemVnum, metinSlot, attrSlot)
|
self.AddItemData(itemVnum, metinSlot, attrSlot)
|
||||||
|
|
||||||
def SetShopItem(self, slotIndex):
|
def SetShopItem(self, slotIndex):
|
||||||
@@ -607,8 +608,8 @@ class ItemToolTip(ToolTip):
|
|||||||
|
|
||||||
price = shop.GetItemPrice(slotIndex)
|
price = shop.GetItemPrice(slotIndex)
|
||||||
self.ClearToolTip()
|
self.ClearToolTip()
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = slotIndex
|
self.itemSlotIndex = slotIndex
|
||||||
self.isShopItem = True
|
self.isShopItem = True
|
||||||
|
|
||||||
metinSlot = []
|
metinSlot = []
|
||||||
@@ -628,8 +629,8 @@ class ItemToolTip(ToolTip):
|
|||||||
|
|
||||||
price = shop.GetItemPrice(slotIndex)
|
price = shop.GetItemPrice(slotIndex)
|
||||||
self.ClearToolTip()
|
self.ClearToolTip()
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = slotIndex
|
self.itemSlotIndex = slotIndex
|
||||||
self.isShopItem = True
|
self.isShopItem = True
|
||||||
|
|
||||||
metinSlot = []
|
metinSlot = []
|
||||||
@@ -648,8 +649,8 @@ class ItemToolTip(ToolTip):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.ClearToolTip()
|
self.ClearToolTip()
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = slotIndex
|
self.itemSlotIndex = slotIndex
|
||||||
|
|
||||||
metinSlot = []
|
metinSlot = []
|
||||||
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
||||||
@@ -665,8 +666,8 @@ class ItemToolTip(ToolTip):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.ClearToolTip()
|
self.ClearToolTip()
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = slotIndex
|
self.itemSlotIndex = slotIndex
|
||||||
|
|
||||||
metinSlot = []
|
metinSlot = []
|
||||||
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
||||||
@@ -683,8 +684,8 @@ class ItemToolTip(ToolTip):
|
|||||||
|
|
||||||
item.SelectItem(itemVnum)
|
item.SelectItem(itemVnum)
|
||||||
self.ClearToolTip()
|
self.ClearToolTip()
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = privateShopSlotIndex
|
self.itemSlotIndex = privateShopSlotIndex
|
||||||
self.AppendSellingPrice(shop.GetPrivateShopItemPrice(invenType, invenPos))
|
self.AppendSellingPrice(shop.GetPrivateShopItemPrice(invenType, invenPos))
|
||||||
|
|
||||||
metinSlot = []
|
metinSlot = []
|
||||||
@@ -702,8 +703,8 @@ class ItemToolTip(ToolTip):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.ClearToolTip()
|
self.ClearToolTip()
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = slotIndex
|
self.itemSlotIndex = slotIndex
|
||||||
metinSlot = []
|
metinSlot = []
|
||||||
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
||||||
metinSlot.append(safebox.GetItemMetinSocket(slotIndex, i))
|
metinSlot.append(safebox.GetItemMetinSocket(slotIndex, i))
|
||||||
@@ -719,8 +720,8 @@ class ItemToolTip(ToolTip):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.ClearToolTip()
|
self.ClearToolTip()
|
||||||
self._curItemWindowType = None
|
self.itemWindowType = None
|
||||||
self._curItemSlotIndex = slotIndex
|
self.itemSlotIndex = slotIndex
|
||||||
metinSlot = []
|
metinSlot = []
|
||||||
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
for i in xrange(player.METIN_SOCKET_MAX_NUM):
|
||||||
metinSlot.append(safebox.GetMallItemMetinSocket(slotIndex, i))
|
metinSlot.append(safebox.GetMallItemMetinSocket(slotIndex, i))
|
||||||
@@ -1917,50 +1918,42 @@ class ItemToolTip(ToolTip):
|
|||||||
def AppendTimerBasedOnWearLastTime(self, metinSlot, getLimit):
|
def AppendTimerBasedOnWearLastTime(self, metinSlot, getLimit):
|
||||||
remainSec = metinSlot[0]
|
remainSec = metinSlot[0]
|
||||||
|
|
||||||
if 0 == remainSec:
|
if remainSec <= 0:
|
||||||
self.AppendSpace(5)
|
self.AppendSpace(5)
|
||||||
self.AppendTextLine(localeInfo.CANNOT_USE, self.DISABLE_COLOR)
|
self.AppendTextLine(localeInfo.CANNOT_USE, self.DISABLE_COLOR)
|
||||||
return
|
return
|
||||||
|
|
||||||
# For Dragon Soul items, the timer only ticks when:
|
isTimerActive = self.__IsTimerBasedOnWearActive()
|
||||||
# 1. The item is EQUIPPED on a deck (window_type == player.INVENTORY for DS equip slots)
|
|
||||||
# 2. AND the deck is ACTIVATED
|
|
||||||
# Items in DS inventory bag (window_type == player.DRAGON_SOUL_INVENTORY) never tick.
|
|
||||||
item.SelectItem(self.itemVnum)
|
|
||||||
isDragonSoulItem = item.GetItemType() == item.ITEM_TYPE_DS
|
|
||||||
|
|
||||||
if isDragonSoulItem:
|
|
||||||
isTimerActive = False
|
|
||||||
windowType = getattr(self, "_curItemWindowType", None)
|
|
||||||
# Only equipped DS items (in INVENTORY window, not DRAGON_SOUL_INVENTORY) can have active timers
|
|
||||||
isEquippedOnDeck = (windowType == player.INVENTORY)
|
|
||||||
if isEquippedOnDeck and self._dragonSoulWindow and getattr(self._dragonSoulWindow, "isActivated", False):
|
|
||||||
isTimerActive = True
|
|
||||||
else:
|
|
||||||
# Non-dragon soul items with LIMIT_TIMER_BASED_ON_WEAR
|
|
||||||
# Timer is active when equipped (this function is only called for such items)
|
|
||||||
isTimerActive = True
|
|
||||||
|
|
||||||
# Not active -> show STATIC remaining time (no ticking)
|
|
||||||
if not isTimerActive:
|
if not isTimerActive:
|
||||||
self.AppendSpace(5)
|
self.AppendSpace(5)
|
||||||
self.AppendTextLine(localeInfo.LEFT_TIME + ": " + localeInfo.RTSecondToDHMS(remainSec), self.NORMAL_COLOR)
|
self.AppendTextLine(localeInfo.LEFT_TIME + ": " + localeInfo.RTSecondToDHMS(remainSec), self.NORMAL_COLOR)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Active -> show real-time countdown
|
endTime = self.__GetOrCreateCachedEndTime(remainSec)
|
||||||
# Cache maintains stable display across re-hovers (server updates remainSec periodically)
|
|
||||||
now = app.GetGlobalTimeStamp()
|
|
||||||
slotIndex = getattr(self, "_curItemSlotIndex", -1)
|
|
||||||
key = (self.itemVnum, slotIndex)
|
|
||||||
|
|
||||||
cache = self._wearTimerCache.get(key)
|
|
||||||
if cache and cache.get("remainSec") == remainSec:
|
|
||||||
endTime = cache["endTime"]
|
|
||||||
else:
|
|
||||||
endTime = now + remainSec
|
|
||||||
self._wearTimerCache[key] = {"remainSec": remainSec, "endTime": endTime}
|
|
||||||
|
|
||||||
self.AppendMallItemLastTime(endTime, getLimit)
|
self.AppendMallItemLastTime(endTime, getLimit)
|
||||||
|
|
||||||
|
def __IsTimerBasedOnWearActive(self):
|
||||||
|
item.SelectItem(self.itemVnum)
|
||||||
|
|
||||||
|
if item.GetItemType() == item.ITEM_TYPE_DS:
|
||||||
|
isEquippedOnDeck = (self.itemWindowType == player.INVENTORY)
|
||||||
|
isDeckActivated = self.wndDragonSoul and self.wndDragonSoul.isActivated
|
||||||
|
return isEquippedOnDeck and isDeckActivated
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def __GetOrCreateCachedEndTime(self, remainSec):
|
||||||
|
key = (self.itemVnum, self.itemSlotIndex)
|
||||||
|
cache = self.dsActivatedTimeCache.get(key)
|
||||||
|
|
||||||
|
if cache and cache["remainSec"] == remainSec:
|
||||||
|
return cache["endTime"]
|
||||||
|
|
||||||
|
now = app.GetGlobalTimeStamp()
|
||||||
|
endTime = now + remainSec
|
||||||
|
self.dsActivatedTimeCache[key] = {"remainSec": remainSec, "endTime": endTime}
|
||||||
|
return endTime
|
||||||
|
|
||||||
def AppendRealTimeStartFirstUseLastTime(self, item, metinSlot, limitIndex, getLimit):
|
def AppendRealTimeStartFirstUseLastTime(self, item, metinSlot, limitIndex, getLimit):
|
||||||
useCount = metinSlot[1]
|
useCount = metinSlot[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user