Skip to content

Commit 8b5688c

Browse files
authored
Merge pull request #149 from Xian55/feature/castinghandler-cast-event-error
Feature - CastingHandler V2 / all profiles updated
2 parents 75dea7b + f060ea1 commit 8b5688c

File tree

117 files changed

+2567
-3554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+2567
-3554
lines changed

Addons/DataToColor/Constants.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ DataToColor.C.Totem = "Totem"
2121
-- Character's name
2222
DataToColor.C.CHARACTER_NAME = UnitName(DataToColor.C.unitPlayer)
2323
DataToColor.C.CHARACTER_GUID = UnitGUID(DataToColor.C.unitPlayer)
24-
_, DataToColor.C.CHARACTER_CLASS = UnitClass(DataToColor.C.unitPlayer)
24+
_, DataToColor.C.CHARACTER_CLASS, DataToColor.C.CHARACTER_CLASS_ID = UnitClass(DataToColor.C.unitPlayer)
25+
_, _, DataToColor.C.CHARACTER_RACE_ID = UnitRace(DataToColor.C.unitPlayer)
2526

2627
-- Actionbar power cost
2728
DataToColor.C.MAX_POWER_TYPE = 1000000

Addons/DataToColor/DataToColor.lua

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,23 @@ DataToColor.lastCombatCreatureDied = 0
4848

4949
DataToColor.lastAutoShot = 0
5050
DataToColor.lastMainHandMeleeSwing = 0
51+
DataToColor.lastCastEvent = 0
52+
DataToColor.lastCastSpellId = 0
53+
54+
DataToColor.lastCastStartTime = 0
55+
DataToColor.CastNum = 0
5156

5257
DataToColor.targetChanged = true
5358

5459
DataToColor.playerGUID = UnitGUID(DataToColor.C.unitPlayer)
5560
DataToColor.petGUID = UnitGUID(DataToColor.C.unitPet)
5661

62+
-- buff / debuff counters
63+
local playerDebuffCount = 0
64+
local playerBuffCount = 0
65+
local targetDebuffCount = 0
66+
local targetBuffCount = 0
67+
5768
-- Update Queue
5869
stack = {}
5970
DataToColor.stack = stack
@@ -169,6 +180,16 @@ function DataToColor:Reset()
169180

170181
DataToColor.lastAutoShot = 0
171182
DataToColor.lastMainHandMeleeSwing = 0
183+
DataToColor.lastCastEvent = 0
184+
DataToColor.lastCastSpellId = 0
185+
186+
DataToColor.lastCastStartTime = 0
187+
DataToColor.CastNum = 0
188+
189+
playerDebuffCount = 0
190+
playerBuffCount = 0
191+
targetDebuffCount = 0
192+
targetBuffCount = 0
172193
end
173194

174195
function DataToColor:Update()
@@ -336,10 +357,14 @@ function DataToColor:CreateFrames(n)
336357
-- 20
337358
bagNum = DataToColor.stack:pop(DataToColor.bagQueue)
338359
if bagNum then
339-
local freeSlots, bagType = GetContainerNumFreeSlots(bagNum) or 0, 0
360+
local freeSlots, bagType = GetContainerNumFreeSlots(bagNum)
361+
if not bagType then
362+
bagType = 0
363+
end
364+
340365
-- BagType + Index + FreeSpace + BagSlots
341366
MakePixelSquareArrI(bagType * 1000000 + bagNum * 100000 + freeSlots * 1000 + DataToColor:bagSlots(bagNum), 20)
342-
--DataToColor:Print("bagQueue "..bagType.." -> "..bagNum.." -> "..freeSlots.." -> "..DataToColor:bagSlots(bagNum))
367+
--DataToColor:Print("bagQueue bagType:"..bagType.." | bagNum: "..bagNum.." | freeSlots: "..freeSlots.." | BagSlots: "..DataToColor:bagSlots(bagNum))
343368
end
344369

345370
-- 21 22 23
@@ -425,7 +450,7 @@ function DataToColor:CreateFrames(n)
425450

426451
--MakePixelSquareArrI(DataToColor:GetGossipIcons(), 45) -- Returns which gossip icons are on display in dialogue box
427452

428-
MakePixelSquareArrI(DataToColor.S.PlayerClass, 46) -- Returns player class as an integer
453+
MakePixelSquareArrI(DataToColor.C.CHARACTER_RACE_ID * 100 + DataToColor.C.CHARACTER_CLASS_ID, 46)
429454
MakePixelSquareArrI(DataToColor:isUnskinnable(), 47) -- Returns 1 if creature is unskinnable
430455
MakePixelSquareArrI(DataToColor:shapeshiftForm(), 48) -- Shapeshift id https://wowwiki.fandom.com/wiki/API_GetShapeshiftForm
431456
MakePixelSquareArrI(DataToColor:getRange(), 49) -- 15 Represents if target is within 0-5 5-15 15-20, 20-30, 30-35, or greater than 35 yards
@@ -437,7 +462,25 @@ function DataToColor:CreateFrames(n)
437462

438463
MakePixelSquareArrI(DataToColor:CastingInfoSpellId(DataToColor.C.unitPlayer), 53) -- Spell being cast
439464
MakePixelSquareArrI(DataToColor:ComboPoints(), 54) -- Combo points for rogue / druid
440-
MakePixelSquareArrI(DataToColor:getAuraCount(UnitDebuff, DataToColor.C.unitPlayer), 55)
465+
466+
playerDebuffCount = DataToColor:getAuraCount(UnitDebuff, DataToColor.C.unitPlayer)
467+
playerBuffCount = DataToColor:getAuraCount(UnitBuff, DataToColor.C.unitPlayer)
468+
469+
if UnitExists(DataToColor.C.unitTarget) then
470+
targetDebuffCount = DataToColor:getAuraCount(UnitDebuff, DataToColor.C.unitTarget)
471+
targetBuffCount = DataToColor:getAuraCount(UnitBuff, DataToColor.C.unitTarget)
472+
else
473+
targetDebuffCount = 0
474+
targetBuffCount = 0
475+
end
476+
477+
if playerDebuffCount > 16 then
478+
playerDebuffCount = 16
479+
end
480+
481+
-- player/target buff and debuff counts
482+
-- formula playerDebuffCount + playerBuffCount + targetDebuffCount + targetBuffCount
483+
MakePixelSquareArrI(playerDebuffCount * 1000000 + playerBuffCount * 10000 + targetDebuffCount * 100 + targetBuffCount, 55)
441484

442485
if DataToColor.targetChanged then
443486
MakePixelSquareArrI(DataToColor:targetNpcId(), 56) -- target id
@@ -450,9 +493,8 @@ function DataToColor:CreateFrames(n)
450493

451494
MakePixelSquareArrI(DataToColor.lastAutoShot, 60)
452495
MakePixelSquareArrI(DataToColor.lastMainHandMeleeSwing, 61)
453-
-- 62 not used
454-
-- 63 not used
455-
-- 64 not used
496+
MakePixelSquareArrI(DataToColor.lastCastEvent, 62)
497+
MakePixelSquareArrI(DataToColor.lastCastSpellId, 63)
456498

457499
MakePixelSquareArrI(DataToColor.lastCombatCreature, 64) -- Combat message creature
458500
MakePixelSquareArrI(DataToColor.lastCombatDamageDoneCreature, 65) -- Last Combat damage done
@@ -461,10 +503,13 @@ function DataToColor:CreateFrames(n)
461503

462504
MakePixelSquareArrI(DataToColor:getGuid(DataToColor.C.unitPet), 68) -- pet guid
463505
MakePixelSquareArrI(DataToColor:getGuid(DataToColor.C.unitPetTarget), 69) -- pet target
506+
MakePixelSquareArrI(DataToColor.CastNum, 70)
464507

465508
-- Timers
466-
MakePixelSquareArrI(DataToColor.globalTime, 70)
467-
MakePixelSquareArrI(DataToColor.lastLoot, 71)
509+
MakePixelSquareArrI(DataToColor.lastLoot, 97)
510+
MakePixelSquareArrI(DataToColor.globalTime, 98)
511+
512+
-- 99 Reserved
468513

469514
DataToColor:ConsumeChanges()
470515

Addons/DataToColor/DataToColor.toc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Title: DataToColor
33
## Author: FreeHongKongMMO
44
## Notes: An addon that displays player position as color
5-
## Version: 1.1.26
5+
## Version: 1.1.35
66
## RequiredDeps:
77
## OptionalDeps: Ace3, LibDataBroker-1.1, LibCompress, LibRangeCheck
88
## SavedVariables:

Addons/DataToColor/EventHandlers.lua

Lines changed: 105 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
local Load = select(2, ...)
22
local DataToColor = unpack(Load)
33

4+
local CAST_START = 999998
5+
local CAST_SUCCESS = 999999
6+
47
local ignoreErrorList = {
58
"ERR_ABILITY_COOLDOWN",
69
"ERR_OUT_OF_RAGE",
@@ -23,6 +26,8 @@ local errorList = {
2326
"ERR_SPELL_COOLDOWN", --7 "Spell is not ready yet."
2427
"ERR_SPELL_FAILED_ANOTHER_IN_PROGRESS", --8 "Another action is in progress"
2528
"ERR_SPELL_FAILED_STUNNED", -- 9 "Can't do that while stunned"
29+
"SPELL_FAILED_INTERRUPTED", -- 10 "Interrupted"
30+
"SPELL_FAILED_ITEM_NOT_READY" -- 11 "Item is not ready yet"
2631
};
2732

2833
function DataToColor:RegisterEvents()
@@ -39,86 +44,144 @@ function DataToColor:RegisterEvents()
3944
end
4045

4146
function DataToColor:OnUIErrorMessage(event, messageType, message)
42-
local errorName = GetGameMessageInfo(messageType)
47+
local code, ignored, foundMessage, message = DataToColor:GetErrorCode(messageType, message)
48+
49+
if ignored then
50+
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey messasge
51+
elseif foundMessage and code ~= 0 then
52+
DataToColor.uiErrorMessage = code;
53+
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
54+
else
55+
UIErrorsFrame:AddMessage(message, 0, 0, 1) -- show as blue message (unknown message)
56+
end
57+
end
58+
59+
function DataToColor:GetErrorCode(messageType, message)
60+
61+
local errorName
62+
local foundMessage = false
63+
local ignored = false
64+
local code = 0
65+
66+
if messageType ~= nil then
67+
errorName = GetGameMessageInfo(messageType)
68+
end
4369

44-
local foundMessage=false;
4570
for i = 1, table.getn(ignoreErrorList), 1 do
46-
if ignoreErrorList[i]==errorName then
47-
foundMessage=true;
48-
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey messasge
71+
if ignoreErrorList[i] == errorName then
72+
foundMessage = true;
73+
ignored = true
4974
end
5075
end
5176

52-
if not foundMessage then
77+
if not ignored and not foundMessage then
5378
for i = 1, table.getn(errorList), 1 do
54-
if errorList[i]==errorName then
55-
DataToColor.uiErrorMessage = i;
56-
57-
if errorName==errorList[2] then -- ERR_SPELL_FAILED_S
58-
if message==SPELL_FAILED_UNIT_NOT_INFRONT then
59-
DataToColor.uiErrorMessage = 1
60-
message = message.." ("..ERR_BADATTACKFACING..")"
61-
elseif message==SPELL_FAILED_MOVING then
62-
DataToColor.uiErrorMessage = 6
63-
elseif message==SPELL_FAILED_STUNNED then
64-
DataToColor.uiErrorMessage = 9
65-
--message = message.." ("..SPELL_FAILED_STUNNED..")"
66-
--else
67-
-- message = message.." (Spell related)"
68-
end
69-
end
70-
71-
foundMessage=true;
72-
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
79+
if errorList[i] == errorName or
80+
(_G[errorList[i]] ~= nil and string.find(_G[errorList[i]], message)) then
81+
code = i;
82+
foundMessage = true;
7383
end
7484
end
7585
end
7686

77-
if not foundMessage then
78-
UIErrorsFrame:AddMessage(message, 0, 0, 1) -- show as blue message (unknown message)
87+
-- ERR_SPELL_FAILED_S
88+
-- find by message ex combatlog
89+
if not ignored and (not foundMessage or errorName == errorList[2]) then
90+
if string.find(message, SPELL_FAILED_UNIT_NOT_INFRONT) then
91+
code = 1
92+
foundMessage = true
93+
message = message.." ("..ERR_BADATTACKFACING..")"
94+
elseif string.find(message, SPELL_FAILED_MOVING) then
95+
foundMessage = true
96+
code = 6
97+
elseif string.find(message, SPELL_FAILED_STUNNED) then
98+
foundMessage = true
99+
code = 9
100+
end
79101
end
102+
103+
return code, ignored, foundMessage, message
80104
end
81105

82106
local watchedSpells = {
83107
[DataToColor.C.Spell.AutoShotId] = function ()
84108
--DataToColor:Print("Auto Shot detected")
85109
DataToColor.lastAutoShot = DataToColor.globalTime
86-
end
110+
end
87111
}
88112

113+
local swing_reset_spells = {
114+
--[[ Maul ]]
115+
[132136]=1,
116+
--[[ Raptor Strike ]]
117+
[132223]=1,
118+
--[[ Cleave ]]
119+
[132338]=1,
120+
--[[ Heroic Strike ]]
121+
[132282]=1,
122+
--[[ Slam ]]
123+
[132340]=1
124+
}
125+
89126
function DataToColor:OnCombatEvent(...)
90127
local _, eventType, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _, spellId, _, _ = CombatLogGetCurrentEventInfo();
91128
--print(CombatLogGetCurrentEventInfo())
92129
if eventType=="SPELL_PERIODIC_DAMAGE" then
93130
DataToColor.lastCombatCreature=0;
94131
elseif string.find(sourceGUID, "Creature") then
95132
DataToColor.lastCombatCreature = DataToColor:getGuidFromUUID(sourceGUID);
96-
--print(CombatLogGetCurrentEventInfo())
97133
else
98134
DataToColor.lastCombatCreature=0;
99-
--print("Other "..eventType);
100135
end
101136

102137
if string.find(sourceGUID, "Creature") and (destGUID == DataToColor.playerGUID or destGUID == DataToColor.petGUID) then
103138
DataToColor.lastCombatDamageTakenCreature = DataToColor:getGuidFromUUID(sourceGUID);
104-
--print(sourceGUID.." "..DataToColor.lastCombatDamageTakenCreature.." "..sourceName);
105139
end
106140

107-
if eventType=="SPELL_CAST_SUCCESS" and sourceGUID == DataToColor.playerGUID then
108-
if watchedSpells[spellId] then watchedSpells[spellId]() end
109-
end
141+
if sourceGUID == DataToColor.playerGUID then
142+
if eventType=="SPELL_CAST_SUCCESS" then
143+
if watchedSpells[spellId] then watchedSpells[spellId]() end
144+
145+
local _, _, icon = GetSpellInfo(spellId)
146+
if swing_reset_spells[icon] then
147+
--DataToColor:Print("Special Melee Swing detected")
148+
DataToColor.lastMainHandMeleeSwing = DataToColor.globalTime
149+
end
150+
end
110151

111-
if string.find(eventType, "_DAMAGE") then
112-
if sourceGUID == DataToColor.playerGUID or sourceGUID == DataToColor.petGUID then
152+
if string.find(eventType, "_CAST_START") then
153+
DataToColor.lastCastEvent = CAST_START
154+
DataToColor.lastCastSpellId = spellId
155+
--print(CombatLogGetCurrentEventInfo())
156+
--print("_CAST_START "..spellId)
157+
end
158+
159+
if string.find(eventType, "_CAST_SUCCESS") or string.find(eventType, "_CAST_FAILED") then
160+
--print(CombatLogGetCurrentEventInfo())
161+
DataToColor.lastCastSpellId = spellId
162+
163+
if string.find(eventType, "_CAST_FAILED") then
164+
--local lastCastEvent = DataToColor.lastCastEvent
165+
local failedType = select(15, CombatLogGetCurrentEventInfo())
166+
DataToColor.lastCastEvent = DataToColor:GetErrorCode(nil, failedType)
167+
--print(lastCastEvent.." -> "..DataToColor.lastCastEvent.." "..failedType.." "..spellId)
168+
else
169+
DataToColor.lastCastEvent = CAST_SUCCESS
170+
end
171+
end
172+
173+
-- matches SWING_ RANGE_ SPELL_ but not SPELL_PERIODIC
174+
if not string.find(eventType, "SPELL_PERIODIC") and
175+
(string.find(eventType, "_DAMAGE") or string.find(eventType, "_MISSED")) then
113176
DataToColor.lastCombatDamageDoneCreature = DataToColor:getGuidFromUUID(destGUID);
114177
end
115-
end
116178

117-
if sourceGUID == DataToColor.playerGUID and string.find(eventType, "SWING_") then
118-
local _, _, _, _, _, _, _, _, _, isOffHand = select(12, ...)
119-
if not isOffHand then
120-
--DataToColor:Print("Melee Swing detected")
121-
DataToColor.lastMainHandMeleeSwing = DataToColor.globalTime
179+
if string.find(eventType, "SWING_") then
180+
local _, _, _, _, _, _, _, _, _, isOffHand = select(12, ...)
181+
if not isOffHand then
182+
--DataToColor:Print("Normal Melee Swing detected")
183+
DataToColor.lastMainHandMeleeSwing = DataToColor.globalTime
184+
end
122185
end
123186
end
124187

Addons/DataToColor/Query.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,21 @@ function DataToColor:GetTargetName(partition)
9898
return 0
9999
end
100100

101-
function DataToColor:CastingInfoSpellId(target)
102-
local _, _, _, _, _, _, _, spellID = UnitCastingInfo(target)
101+
function DataToColor:CastingInfoSpellId(unitId)
102+
local _, _, _, _, startTime, _, _, spellID = UnitCastingInfo(unitId)
103103
if spellID ~= nil then
104+
if unitId == DataToColor.C.unitPlayer and startTime ~= DataToColor.lastCastStartTime then
105+
DataToColor.lastCastStartTime = startTime
106+
DataToColor.CastNum = DataToColor.CastNum + 1
107+
end
104108
return spellID
105109
end
106-
_, _, _, _, _, _, spellID = UnitChannelInfo(target)
110+
_, _, _, startTime, _, _, spellID = UnitChannelInfo(unitId)
107111
if spellID ~= nil then
112+
if unitId == DataToColor.C.unitPlayer and startTime ~= DataToColor.lastCastStartTime then
113+
DataToColor.lastCastStartTime = startTime
114+
DataToColor.CastNum = DataToColor.CastNum + 1
115+
end
108116
return spellID
109117
end
110118
return 0

0 commit comments

Comments
 (0)