Skip to content

Commit

Permalink
Merge pull request #149 from Xian55/feature/castinghandler-cast-event…
Browse files Browse the repository at this point in the history
…-error

Feature - CastingHandler V2 / all profiles updated
  • Loading branch information
Xian55 authored Oct 19, 2021
2 parents 75dea7b + f060ea1 commit 8b5688c
Show file tree
Hide file tree
Showing 117 changed files with 2,567 additions and 3,554 deletions.
3 changes: 2 additions & 1 deletion Addons/DataToColor/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ DataToColor.C.Totem = "Totem"
-- Character's name
DataToColor.C.CHARACTER_NAME = UnitName(DataToColor.C.unitPlayer)
DataToColor.C.CHARACTER_GUID = UnitGUID(DataToColor.C.unitPlayer)
_, DataToColor.C.CHARACTER_CLASS = UnitClass(DataToColor.C.unitPlayer)
_, DataToColor.C.CHARACTER_CLASS, DataToColor.C.CHARACTER_CLASS_ID = UnitClass(DataToColor.C.unitPlayer)
_, _, DataToColor.C.CHARACTER_RACE_ID = UnitRace(DataToColor.C.unitPlayer)

-- Actionbar power cost
DataToColor.C.MAX_POWER_TYPE = 1000000
Expand Down
63 changes: 54 additions & 9 deletions Addons/DataToColor/DataToColor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,23 @@ DataToColor.lastCombatCreatureDied = 0

DataToColor.lastAutoShot = 0
DataToColor.lastMainHandMeleeSwing = 0
DataToColor.lastCastEvent = 0
DataToColor.lastCastSpellId = 0

DataToColor.lastCastStartTime = 0
DataToColor.CastNum = 0

DataToColor.targetChanged = true

DataToColor.playerGUID = UnitGUID(DataToColor.C.unitPlayer)
DataToColor.petGUID = UnitGUID(DataToColor.C.unitPet)

-- buff / debuff counters
local playerDebuffCount = 0
local playerBuffCount = 0
local targetDebuffCount = 0
local targetBuffCount = 0

-- Update Queue
stack = {}
DataToColor.stack = stack
Expand Down Expand Up @@ -169,6 +180,16 @@ function DataToColor:Reset()

DataToColor.lastAutoShot = 0
DataToColor.lastMainHandMeleeSwing = 0
DataToColor.lastCastEvent = 0
DataToColor.lastCastSpellId = 0

DataToColor.lastCastStartTime = 0
DataToColor.CastNum = 0

playerDebuffCount = 0
playerBuffCount = 0
targetDebuffCount = 0
targetBuffCount = 0
end

function DataToColor:Update()
Expand Down Expand Up @@ -336,10 +357,14 @@ function DataToColor:CreateFrames(n)
-- 20
bagNum = DataToColor.stack:pop(DataToColor.bagQueue)
if bagNum then
local freeSlots, bagType = GetContainerNumFreeSlots(bagNum) or 0, 0
local freeSlots, bagType = GetContainerNumFreeSlots(bagNum)
if not bagType then
bagType = 0
end

-- BagType + Index + FreeSpace + BagSlots
MakePixelSquareArrI(bagType * 1000000 + bagNum * 100000 + freeSlots * 1000 + DataToColor:bagSlots(bagNum), 20)
--DataToColor:Print("bagQueue "..bagType.." -> "..bagNum.." -> "..freeSlots.." -> "..DataToColor:bagSlots(bagNum))
--DataToColor:Print("bagQueue bagType:"..bagType.." | bagNum: "..bagNum.." | freeSlots: "..freeSlots.." | BagSlots: "..DataToColor:bagSlots(bagNum))
end

-- 21 22 23
Expand Down Expand Up @@ -425,7 +450,7 @@ function DataToColor:CreateFrames(n)

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

MakePixelSquareArrI(DataToColor.S.PlayerClass, 46) -- Returns player class as an integer
MakePixelSquareArrI(DataToColor.C.CHARACTER_RACE_ID * 100 + DataToColor.C.CHARACTER_CLASS_ID, 46)
MakePixelSquareArrI(DataToColor:isUnskinnable(), 47) -- Returns 1 if creature is unskinnable
MakePixelSquareArrI(DataToColor:shapeshiftForm(), 48) -- Shapeshift id https://wowwiki.fandom.com/wiki/API_GetShapeshiftForm
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
Expand All @@ -437,7 +462,25 @@ function DataToColor:CreateFrames(n)

MakePixelSquareArrI(DataToColor:CastingInfoSpellId(DataToColor.C.unitPlayer), 53) -- Spell being cast
MakePixelSquareArrI(DataToColor:ComboPoints(), 54) -- Combo points for rogue / druid
MakePixelSquareArrI(DataToColor:getAuraCount(UnitDebuff, DataToColor.C.unitPlayer), 55)

playerDebuffCount = DataToColor:getAuraCount(UnitDebuff, DataToColor.C.unitPlayer)
playerBuffCount = DataToColor:getAuraCount(UnitBuff, DataToColor.C.unitPlayer)

if UnitExists(DataToColor.C.unitTarget) then
targetDebuffCount = DataToColor:getAuraCount(UnitDebuff, DataToColor.C.unitTarget)
targetBuffCount = DataToColor:getAuraCount(UnitBuff, DataToColor.C.unitTarget)
else
targetDebuffCount = 0
targetBuffCount = 0
end

if playerDebuffCount > 16 then
playerDebuffCount = 16
end

-- player/target buff and debuff counts
-- formula playerDebuffCount + playerBuffCount + targetDebuffCount + targetBuffCount
MakePixelSquareArrI(playerDebuffCount * 1000000 + playerBuffCount * 10000 + targetDebuffCount * 100 + targetBuffCount, 55)

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

MakePixelSquareArrI(DataToColor.lastAutoShot, 60)
MakePixelSquareArrI(DataToColor.lastMainHandMeleeSwing, 61)
-- 62 not used
-- 63 not used
-- 64 not used
MakePixelSquareArrI(DataToColor.lastCastEvent, 62)
MakePixelSquareArrI(DataToColor.lastCastSpellId, 63)

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

MakePixelSquareArrI(DataToColor:getGuid(DataToColor.C.unitPet), 68) -- pet guid
MakePixelSquareArrI(DataToColor:getGuid(DataToColor.C.unitPetTarget), 69) -- pet target
MakePixelSquareArrI(DataToColor.CastNum, 70)

-- Timers
MakePixelSquareArrI(DataToColor.globalTime, 70)
MakePixelSquareArrI(DataToColor.lastLoot, 71)
MakePixelSquareArrI(DataToColor.lastLoot, 97)
MakePixelSquareArrI(DataToColor.globalTime, 98)

-- 99 Reserved

DataToColor:ConsumeChanges()

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: An addon that displays player position as color
## Version: 1.1.26
## Version: 1.1.35
## RequiredDeps:
## OptionalDeps: Ace3, LibDataBroker-1.1, LibCompress, LibRangeCheck
## SavedVariables:
Expand Down
147 changes: 105 additions & 42 deletions Addons/DataToColor/EventHandlers.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local Load = select(2, ...)
local DataToColor = unpack(Load)

local CAST_START = 999998
local CAST_SUCCESS = 999999

local ignoreErrorList = {
"ERR_ABILITY_COOLDOWN",
"ERR_OUT_OF_RAGE",
Expand All @@ -23,6 +26,8 @@ local errorList = {
"ERR_SPELL_COOLDOWN", --7 "Spell is not ready yet."
"ERR_SPELL_FAILED_ANOTHER_IN_PROGRESS", --8 "Another action is in progress"
"ERR_SPELL_FAILED_STUNNED", -- 9 "Can't do that while stunned"
"SPELL_FAILED_INTERRUPTED", -- 10 "Interrupted"
"SPELL_FAILED_ITEM_NOT_READY" -- 11 "Item is not ready yet"
};

function DataToColor:RegisterEvents()
Expand All @@ -39,86 +44,144 @@ function DataToColor:RegisterEvents()
end

function DataToColor:OnUIErrorMessage(event, messageType, message)
local errorName = GetGameMessageInfo(messageType)
local code, ignored, foundMessage, message = DataToColor:GetErrorCode(messageType, message)

if ignored then
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey messasge
elseif foundMessage and code ~= 0 then
DataToColor.uiErrorMessage = code;
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
else
UIErrorsFrame:AddMessage(message, 0, 0, 1) -- show as blue message (unknown message)
end
end

function DataToColor:GetErrorCode(messageType, message)

local errorName
local foundMessage = false
local ignored = false
local code = 0

if messageType ~= nil then
errorName = GetGameMessageInfo(messageType)
end

local foundMessage=false;
for i = 1, table.getn(ignoreErrorList), 1 do
if ignoreErrorList[i]==errorName then
foundMessage=true;
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey messasge
if ignoreErrorList[i] == errorName then
foundMessage = true;
ignored = true
end
end

if not foundMessage then
if not ignored and not foundMessage then
for i = 1, table.getn(errorList), 1 do
if errorList[i]==errorName then
DataToColor.uiErrorMessage = i;

if errorName==errorList[2] then -- ERR_SPELL_FAILED_S
if message==SPELL_FAILED_UNIT_NOT_INFRONT then
DataToColor.uiErrorMessage = 1
message = message.." ("..ERR_BADATTACKFACING..")"
elseif message==SPELL_FAILED_MOVING then
DataToColor.uiErrorMessage = 6
elseif message==SPELL_FAILED_STUNNED then
DataToColor.uiErrorMessage = 9
--message = message.." ("..SPELL_FAILED_STUNNED..")"
--else
-- message = message.." (Spell related)"
end
end

foundMessage=true;
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
if errorList[i] == errorName or
(_G[errorList[i]] ~= nil and string.find(_G[errorList[i]], message)) then
code = i;
foundMessage = true;
end
end
end

if not foundMessage then
UIErrorsFrame:AddMessage(message, 0, 0, 1) -- show as blue message (unknown message)
-- ERR_SPELL_FAILED_S
-- find by message ex combatlog
if not ignored and (not foundMessage or errorName == errorList[2]) then
if string.find(message, SPELL_FAILED_UNIT_NOT_INFRONT) then
code = 1
foundMessage = true
message = message.." ("..ERR_BADATTACKFACING..")"
elseif string.find(message, SPELL_FAILED_MOVING) then
foundMessage = true
code = 6
elseif string.find(message, SPELL_FAILED_STUNNED) then
foundMessage = true
code = 9
end
end

return code, ignored, foundMessage, message
end

local watchedSpells = {
[DataToColor.C.Spell.AutoShotId] = function ()
--DataToColor:Print("Auto Shot detected")
DataToColor.lastAutoShot = DataToColor.globalTime
end
end
}

local swing_reset_spells = {
--[[ Maul ]]
[132136]=1,
--[[ Raptor Strike ]]
[132223]=1,
--[[ Cleave ]]
[132338]=1,
--[[ Heroic Strike ]]
[132282]=1,
--[[ Slam ]]
[132340]=1
}

function DataToColor:OnCombatEvent(...)
local _, eventType, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _, spellId, _, _ = CombatLogGetCurrentEventInfo();
--print(CombatLogGetCurrentEventInfo())
if eventType=="SPELL_PERIODIC_DAMAGE" then
DataToColor.lastCombatCreature=0;
elseif string.find(sourceGUID, "Creature") then
DataToColor.lastCombatCreature = DataToColor:getGuidFromUUID(sourceGUID);
--print(CombatLogGetCurrentEventInfo())
else
DataToColor.lastCombatCreature=0;
--print("Other "..eventType);
end

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

if eventType=="SPELL_CAST_SUCCESS" and sourceGUID == DataToColor.playerGUID then
if watchedSpells[spellId] then watchedSpells[spellId]() end
end
if sourceGUID == DataToColor.playerGUID then
if eventType=="SPELL_CAST_SUCCESS" then
if watchedSpells[spellId] then watchedSpells[spellId]() end

local _, _, icon = GetSpellInfo(spellId)
if swing_reset_spells[icon] then
--DataToColor:Print("Special Melee Swing detected")
DataToColor.lastMainHandMeleeSwing = DataToColor.globalTime
end
end

if string.find(eventType, "_DAMAGE") then
if sourceGUID == DataToColor.playerGUID or sourceGUID == DataToColor.petGUID then
if string.find(eventType, "_CAST_START") then
DataToColor.lastCastEvent = CAST_START
DataToColor.lastCastSpellId = spellId
--print(CombatLogGetCurrentEventInfo())
--print("_CAST_START "..spellId)
end

if string.find(eventType, "_CAST_SUCCESS") or string.find(eventType, "_CAST_FAILED") then
--print(CombatLogGetCurrentEventInfo())
DataToColor.lastCastSpellId = spellId

if string.find(eventType, "_CAST_FAILED") then
--local lastCastEvent = DataToColor.lastCastEvent
local failedType = select(15, CombatLogGetCurrentEventInfo())
DataToColor.lastCastEvent = DataToColor:GetErrorCode(nil, failedType)
--print(lastCastEvent.." -> "..DataToColor.lastCastEvent.." "..failedType.." "..spellId)
else
DataToColor.lastCastEvent = CAST_SUCCESS
end
end

-- matches SWING_ RANGE_ SPELL_ but not SPELL_PERIODIC
if not string.find(eventType, "SPELL_PERIODIC") and
(string.find(eventType, "_DAMAGE") or string.find(eventType, "_MISSED")) then
DataToColor.lastCombatDamageDoneCreature = DataToColor:getGuidFromUUID(destGUID);
end
end

if sourceGUID == DataToColor.playerGUID and string.find(eventType, "SWING_") then
local _, _, _, _, _, _, _, _, _, isOffHand = select(12, ...)
if not isOffHand then
--DataToColor:Print("Melee Swing detected")
DataToColor.lastMainHandMeleeSwing = DataToColor.globalTime
if string.find(eventType, "SWING_") then
local _, _, _, _, _, _, _, _, _, isOffHand = select(12, ...)
if not isOffHand then
--DataToColor:Print("Normal Melee Swing detected")
DataToColor.lastMainHandMeleeSwing = DataToColor.globalTime
end
end
end

Expand Down
14 changes: 11 additions & 3 deletions Addons/DataToColor/Query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,21 @@ function DataToColor:GetTargetName(partition)
return 0
end

function DataToColor:CastingInfoSpellId(target)
local _, _, _, _, _, _, _, spellID = UnitCastingInfo(target)
function DataToColor:CastingInfoSpellId(unitId)
local _, _, _, _, startTime, _, _, spellID = UnitCastingInfo(unitId)
if spellID ~= nil then
if unitId == DataToColor.C.unitPlayer and startTime ~= DataToColor.lastCastStartTime then
DataToColor.lastCastStartTime = startTime
DataToColor.CastNum = DataToColor.CastNum + 1
end
return spellID
end
_, _, _, _, _, _, spellID = UnitChannelInfo(target)
_, _, _, startTime, _, _, spellID = UnitChannelInfo(unitId)
if spellID ~= nil then
if unitId == DataToColor.C.unitPlayer and startTime ~= DataToColor.lastCastStartTime then
DataToColor.lastCastStartTime = startTime
DataToColor.CastNum = DataToColor.CastNum + 1
end
return spellID
end
return 0
Expand Down
Loading

0 comments on commit 8b5688c

Please sign in to comment.