diff --git a/README.md b/README.md index ee8f7c4b..580e0ae8 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Full per-function reference: **[docs/API.md](docs/API.md)**. | [Talent](docs/API.md#talent) | `GetTalentIDByIndex`, `GetTalentSpellID` | | [TaxiMap](docs/API.md#taximap) | `C_TaxiMap.GetTaxiNodesForMap`, `C_TaxiMap.GetAllTaxiNodes` | | [Time](docs/API.md#time) | `C_DateAndTime.AdjustTimeByDays`, `C_DateAndTime.AdjustTimeByMinutes`, `C_DateAndTime.CompareCalendarTime`, `C_DateAndTime.GetCalendarTimeFromEpoch`, `C_DateAndTime.GetCurrentCalendarTime`, `C_DateAndTime.GetSecondsUntilDailyReset`, `C_DateAndTime.GetServerTimeLocal`, `C_Timer.After`, `C_Timer.NewTicker`, `C_Timer.NewTimer`, `GetServerTime` | -| [Totem](docs/API.md#totem) | `GetTotemInfo`, `GetTotemTimeLeft`, `TargetTotem` | +| [Totem](docs/API.md#totem) | `GetTotemInfo`, `GetTotemTimeLeft`, `GetTotemDuration`, `TargetTotem` | | [TradeSkillUI](docs/API.md#tradeskillui) | `C_TradeSkillUI.GetTradeSkillListLink`, `C_TradeSkillUI.GetCraftListLink`, `C_TradeSkillUI.GetTradeSkillListRecipes` | | [UIColor](docs/API.md#uicolor) | `C_UIColor.GetColors` | | [Unit](docs/API.md#unit) | `ClosestUnitPosition`, `GetUnitSpeed`, `UnitClassBase`, `UnitCreatureFamilyID`, `UnitCreatureTypeID`, `UnitDistanceSquared`, `UnitGUID`, `UnitInLineOfSight`, `UnitInRange`, `UnitIsAFK`, `UnitIsDND`, `UnitIsFeignDeath`, `UnitIsInMyGuild`, `UnitIsMinion`, `UnitIsOtherPlayersPet`, `UnitIsPet`, `UnitIsPossessed`, `UnitOwnerGUID`, `UnitPower`, `UnitPowerMax`, `UnitPowerType`, `UnitRaceBase`, `UnitStandState`, `UnitSubName`, `UnitTokenFromGUID` | diff --git a/docs/API.md b/docs/API.md index f0b5d91d..f18cc286 100644 --- a/docs/API.md +++ b/docs/API.md @@ -465,6 +465,7 @@ build instructions. - [Totem](#totem) - [`GetTotemInfo(slot)`](#gettoteminfoslot) - [`GetTotemTimeLeft(slot)`](#gettotemtimeleftslot) + - [`GetTotemDuration(slot)`](#gettotemdurationslot) - [`TargetTotem(slot)`](#targettotemslot) - [TradeSkillUI](#tradeskillui) @@ -11292,6 +11293,18 @@ notably it reflects the totem's *full* duration from cast, unaffected by any server-side early expiry the client isn't told about (the WorldTick scan still clears the slot when the totem creature actually disappears). +### `GetTotemDuration(slot)` + +Returns the slot's active totem's **total** duration in seconds (its full +lifetime from cast), or `0` when no totem is active. The companion to +[`GetTotemTimeLeft`](#gettotemtimeleftslot) (remaining time) — same value +as `GetTotemInfo`'s 4th return. + +```lua +local total = GetTotemDuration(1) -- e.g. 60 +local frac = GetTotemTimeLeft(1) / GetTotemDuration(1) -- bar fill +``` + ### `TargetTotem(slot)` Targets the player's totem in the given slot (`1` Fire, `2` Earth, `3` diff --git a/src/totem/Tracker.cpp b/src/totem/Tracker.cpp index a7bf35b2..4911d71b 100644 --- a/src/totem/Tracker.cpp +++ b/src/totem/Tracker.cpp @@ -454,6 +454,26 @@ int __fastcall Script_GetTotemTimeLeft(void *L) { return 1; } +// `GetTotemDuration(slot)` → the total duration (seconds) of the slot's +// active totem, or `0` when none. This is the totem's full lifetime from +// cast (the 4th value of GetTotemInfo); see GetTotemTimeLeft for the +// remaining time. +int __fastcall Script_GetTotemDuration(void *L) { + if (!Game::Lua::IsNumber(L, 1)) { + Game::Lua::Error(L, "Usage: GetTotemDuration(slot)"); + return 0; + } + const int slot = static_cast(Game::Lua::ToNumber(L, 1)); + double seconds = 0.0; + if (slot >= 1 && slot <= kSlots) { + const Slot &t = g_slots[slot - 1]; + if (t.active) + seconds = static_cast(t.durationMs) / 1000.0; + } + Game::Lua::PushNumber(L, seconds); + return 1; +} + // `TargetTotem(slot)` — target the player's totem in the given slot // (1 Fire, 2 Earth, 3 Water, 4 Air). No-op when the slot has no active // totem or the totem creature isn't currently visible. Finds the totem @@ -483,6 +503,8 @@ void RegisterLuaFunctions() { Game::Lua::RegisterGlobalFunction("GetTotemInfo", &Script_GetTotemInfo); Game::Lua::RegisterGlobalFunction("GetTotemTimeLeft", &Script_GetTotemTimeLeft); + Game::Lua::RegisterGlobalFunction("GetTotemDuration", + &Script_GetTotemDuration); Game::Lua::RegisterGlobalFunction("TargetTotem", &Script_TargetTotem); }