Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Addons/DataToColor/DataToColor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-- Trigger between emitting game data and frame location data
local SETUP_SEQUENCE = false
-- Total number of data frames generated
local NUMBER_OF_FRAMES = 118
local NUMBER_OF_FRAMES = 119
-- Set number of pixel rows
local FRAME_ROWS = 1
-- Size of data squares in px. Varies based on rounding errors as well as dimension size. Use as a guideline, but not 100% accurate.
Expand Down Expand Up @@ -1197,6 +1197,9 @@ function DataToColor:CreateFrames()
Pixel(int, DataToColor:CastingInfoSpellId(DataToColor.C.unitPlayer), 53) -- SpellId being cast
Pixel(int, DataToColor:getAvgEquipmentDurabilityCached() * 100 + ((DataToColor.C.CHARACTER_CLASS_ID == 2 and UnitPower(DataToColor.C.unitPlayer, PowerType.HolyPower) or GetComboPoints(DataToColor.C.unitPlayer, DataToColor.C.unitTarget)) or 0), 54) -- for paladin holy power or combo points

-- mainHand * 10000 + offHand * 100 + ranged, each 0-99 (99 = slot empty or item has no durability)
Pixel(int, DataToColor:getWeaponDurabilityCached(), 116)

local playerBuffCount = DataToColor:populateAuraTimer(UnitBuff, DataToColor.C.unitPlayer, DataToColor.playerBuffTime)
local playerDebuffCount = DataToColor:populateAuraTimer(UnitDebuff, DataToColor.C.unitPlayer, DataToColor.playerDebuffTime)
local targetDebuffCount = DataToColor:populateAuraTimer(UnitDebuff, DataToColor.C.unitTarget, DataToColor.targetDebuffTime)
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Legacy Cataclysm 4.3.0)
## Version: 1.12.1
## Version: 1.13.0
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, cTimerBackport
## SavedVariables:
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor_Classic.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Classic)
## Version: 1.12.1
## Version: 1.13.0
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor_TBC.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Classic TBC)
## Version: 1.12.1
## Version: 1.13.0
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor_Wrath.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors (Classic Wrath)
## Version: 1.12.1
## Version: 1.13.0
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
4 changes: 4 additions & 0 deletions Addons/DataToColor/EventHandlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ end

function DataToColor:OnPlayerEquipmentChanged(event, equipmentSlot, hasCurrent)
DataToColor.equipmentQueue:push(equipmentSlot)

-- Swapping gear changes durability without raising UPDATE_INVENTORY_DURABILITY,
-- so cells 54 and 116 have to be recomputed from here.
DataToColor:InvalidateDurabilityCache()
--local c = hasCurrent and 1 or 0
--DataToColor:Print("OnPlayerEquipmentChanged "..equipmentSlot.." -> "..c)
end
Expand Down
57 changes: 47 additions & 10 deletions Addons/DataToColor/Query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -862,29 +862,66 @@ function DataToColor:getUnitRangedDamage(unit)
return floor((speed or 0) * 100)
end

function DataToColor:getAvgEquipmentDurability()
-- Equipment durability caches: cell 54 carries the all-slot average, cell 116 the
-- per weapon slot breakdown. Both are filled by one pass over the inventory and
-- share the dirty flag, so a single invalidate refreshes them together.
-- Mainhand = 16, Offhand = 17, Ranged = 18 - see Core/Equipments/InventorySlotId.cs
local FIRST_WEAPON_SLOT = 16
local WEAPON_SLOT_MUL = { [16] = 10000, [17] = 100, [18] = 1 }

-- 0-99. The +1 bias makes an empty slot - or an equipped item that has no
-- durability at all, such as a thrown weapon or an off hand tome - report 99,
-- while a genuinely broken item reports 0.
local function durabilityPercent(current, maxValue)
local p = floor((current + 1) * 100 / (maxValue + 1)) - 1
if p < 0 then
return 0
end
return p
end

local cachedDurability = 0
local cachedWeaponDurability = 0
local durabilityDirty = true

local function refreshDurability()
local current = 0
local max = 0
local weapon = 0

for i = 1, 18 do
local c, m = GetInventoryItemDurability(i)
current = current + (c or 0)
max = max + (m or 0)
c = c or 0
m = m or 0

current = current + c
max = max + m

if i >= FIRST_WEAPON_SLOT then
weapon = weapon + durabilityPercent(c, m) * WEAPON_SLOT_MUL[i]
end
end
return math.max(0, floor((current + 1) * 100 / (max + 1)) - 1) -- 0-99
end

-- Equipment durability cache (cell 54)
local cachedDurability = 0
local durabilityDirty = true
cachedDurability = durabilityPercent(current, max)
cachedWeaponDurability = weapon
durabilityDirty = false
end

function DataToColor:getAvgEquipmentDurabilityCached()
if durabilityDirty then
cachedDurability = DataToColor:getAvgEquipmentDurability()
durabilityDirty = false
refreshDurability()
end
return cachedDurability
end

-- mainHand * 10000 + offHand * 100 + ranged, each 0-99
function DataToColor:getWeaponDurabilityCached()
if durabilityDirty then
refreshDurability()
end
return cachedWeaponDurability
end

function DataToColor:InvalidateDurabilityCache()
durabilityDirty = true
end
Expand Down
14 changes: 14 additions & 0 deletions Core/Addon/PlayerReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using SharedLib;

using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Numerics;
Expand Down Expand Up @@ -160,6 +161,19 @@ public Vector3 TargetMapPos
public int ComboPoints() => reader.GetInt(54) % 100;
public int AvgEquipDurability() => reader.GetInt(54) / 100; // 0-99

public const int WeaponDurabilityCell = 116;

// mainHandDurability * 10000 + offHandDurability * 100 + rangedDurability
// Each is 0-99, where 99 also covers an empty slot or an equipped item that
// has no durability - a thrown weapon, an off hand tome, a relic.
public int MainHandDurability() => reader.GetInt(WeaponDurabilityCell) / 10000;
public int OffHandDurability() => reader.GetInt(WeaponDurabilityCell) / 100 % 100;
public int RangedDurability() => reader.GetInt(WeaponDurabilityCell) % 100;

// The weapon closest to breaking. 99 = nothing equipped that can break.
public int MinWeaponDurability() =>
Math.Min(MainHandDurability(), Math.Min(OffHandDurability(), RangedDurability()));

public AuraCount AuraCount => new(reader, 55);

public int TargetId => reader.GetInt(56);
Expand Down
4 changes: 4 additions & 0 deletions Core/Requirement/RequirementFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ bool CannibalizeCorpseNearby() =>
{ "Combo Point", playerReader.ComboPoints },
{ "Holy Power", playerReader.ComboPoints },
{ "Durability%", playerReader.AvgEquipDurability },
{ "MainHandDurability%", playerReader.MainHandDurability },
{ "OffHandDurability%", playerReader.OffHandDurability },
{ "RangedDurability%", playerReader.RangedDurability },
{ "WeaponDurability%", playerReader.MinWeaponDurability },
{ "BagCount", bagReader.BagItemCount },
{ "FoodCount", bagReader.FoodItemCount },
{ "DrinkCount", bagReader.DrinkItemCount },
Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,12 @@ examples of full automatic npc detection or multiple whitelisted names:
}
```

**Note:** `Durability%` is the average across all 18 equipped slots, so it is dominated by
armour and lags well behind a weapon that is about to break. Use
[`WeaponDurability%`](#value-base-requirements) - the lowest of main hand, off hand and
ranged - when the repair trip is really about the weapon:
`"Requirement": "Durability% < 35 || WeaponDurability% < 30"`.

#### Class Trainer

A `ClassTrainer` entry walks to the trainer and **learns spells**, instead of opening a
Expand Down Expand Up @@ -2502,7 +2508,11 @@ Arithmetic operators can be used to build complex expressions:
| `TotalRune` | Player current runes (blood+frost+unholy+death) |
| `Combo Point` | Player current combo points on the target |
| `Holy Power` | Player current Holy Power points on the target |
| `Durability%` | Player worn equipment average durability. **0-99** value range. |
| `Durability%` | Player worn equipment average durability across **all 18** slots. Dominated by armour, since 15 of the 18 slots are armour. **0-99** value range. |
| `MainHandDurability%` | Main hand weapon durability. **0-99** value range. |
| `OffHandDurability%` | Off hand weapon or shield durability. **0-99** value range. |
| `RangedDurability%` | Ranged weapon (bow / gun / crossbow / wand) durability. **0-99** value range. |
| `WeaponDurability%` | Lowest of the three weapon slots above - the "is any weapon about to break" check. **0-99** value range. |
| `BagCount` | How many items in the player inventory |
| `FoodCount` | Returns the highest amount of food type, item count |
| `DrinkCount` | Returns the highest amount of drink type, item count |
Expand Down Expand Up @@ -2549,6 +2559,16 @@ Arithmetic operators can be used to build complex expressions:
| `PathDist` | Returns the context [PathSettings](#pathsettings) of closest distance (in yards) from the player location to the Path. |
| `PathDist_{PathSettings.Id}` | Returns the closest distance (in yards) from the player location to the Path. |

The durability keywords all report **0-99**, where **0** means broken and **99** means fully repaired.

**99 is also what an empty slot reports**, along with an equipped item that has no durability at all - a thrown weapon, an off hand tome, a Wrath relic. That is deliberate: it keeps `WeaponDurability%` (the lowest of the three weapon slots) meaningful for any spec. A caster with an empty off hand and no ranged weapon gets `WeaponDurability% == MainHandDurability%`, a dual wielder gets the worse of the two, a hunter gets the worst of all three - and a slot that cannot break never drags the value down.

Weapons wear out several times faster than armour, so the all-slot `Durability%` average is late to notice a weapon about to break. Prefer `WeaponDurability%` for a repair gate, on its own or next to `Durability%`:

```json
"Requirement": "Durability% < 35 || WeaponDurability% < 30"
```

For the `MinRange` and `MaxRange` gives an approximation range distance between the player and target.

**Note:** _Every class has its own unique way to find these values by using different in game items/spells/interact._
Expand All @@ -2572,6 +2592,8 @@ e.g. Single Requirement
"Requirement": "Rage > 90"
"Requirement": "BagCount > 80"
"Requirement": "MobCount > 1"
"Requirement": "WeaponDurability% < 30" // The most worn of main hand / off hand / ranged is below 30%
"Requirement": "MainHandDurability% < 25" // Only the main hand weapon
"Requirement": "MinRange < 5"
"Requirement": "MinRange > 15"
"Requirement": "MaxRange > 20"
Expand Down
Loading