Skip to content

Commit

Permalink
Rewrite on the Painsmith's Spikeball handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Jul 15, 2021
1 parent 38c61cd commit 37b7687
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 161 deletions.
9 changes: 7 additions & 2 deletions classes/class_damage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,6 @@ function atributo_damage:RefreshWindow (instancia, tabela_do_combate, forcar, ex
else
--/run Details:Dump(Details:GetCurrentCombat():GetActor(1, "Injured Steelspine 1"))
if (keyName == "enemies") then
--amount, total = Details:ContainerSortEnemies (conteudo, amount, "total")
amount, total = Details:ContainerSortEnemies (conteudo, amount, "damage_taken")

--remove actors with zero damage taken
Expand All @@ -2039,7 +2038,13 @@ function atributo_damage:RefreshWindow (instancia, tabela_do_combate, forcar, ex
break
end
end
amount = newAmount

--if all units shown are enemies and all have damage taken, check if newAmount is zero and #conteudo has value bigger than 0
if (newAmount == 0 and #conteudo > 0) then
amount = amount
else
amount = newAmount
end

--keyName = "damage_taken"
--result of the first actor
Expand Down
223 changes: 68 additions & 155 deletions core/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,13 @@
[315197] = true, --> Thing From Beyond --REMOVE ON 9.0
}

local NPCID_SPIKEDBALL = 176581 --remove on 10.0
local NPCID_SPIKEDBALL = 176581 --remove on 10.0 --spikeball npcId
--local NPCID_SPIKEDBALL = 161881 --remove on 10.0 - debug npc
local spikeball_cache = {}
spikeball_cache.name_cache = {}
spikeball_cache.winners_cache = {}
spikeball_cache.spike_counter = 0
spikeball_cache.winner_spikeball = false
spikeball_cache.ignore_spikeballs = false
--spikeball cache
local spikeball_damage_cache = {
npc_cache = {},
ignore_spikeballs = 0,
}

local NPCID_KELTHUZAD_FROSTBOUNDDEVOTED = 176703
local NPCID_KELTHUZAD_ADDMIMICPLAYERS = 176605
Expand Down Expand Up @@ -640,142 +639,79 @@
end

if (npcId == NPCID_SPIKEDBALL) then --remove on 10.0, all this IF block
if (spikeball_cache.ignore_spikeballs) then
if (spikeball_cache.ignore_spikeballs > GetTime()) then
if (spikeball_damage_cache.ignore_spikeballs) then
if (spikeball_damage_cache.ignore_spikeballs > GetTime()) then
return
end
end

--actor name
local spikeName = spikeball_cache.name_cache[alvo_serial]
if (not spikeName) then
spikeball_cache.spike_counter = spikeball_cache.spike_counter + 1
spikeName = alvo_name .. " " .. spikeball_cache.spike_counter
spikeball_cache.name_cache[alvo_serial] = spikeName
local npcDamage = spikeball_damage_cache.npc_cache[alvo_serial]
if (not npcDamage) then
npcDamage = {}
spikeball_damage_cache.npc_cache[alvo_serial] = npcDamage
end

alvo_name = spikeName
amount = (amount-overkill)

local damageTable = npcDamage[who_serial]
if (not damageTable) then
damageTable = {total = 0, spells = {}}
npcDamage[who_serial] = damageTable
end

damageTable.total = damageTable.total + amount
damageTable.spells[spellid] = (damageTable.spells[spellid] or 0) + amount

--check if this spike ball is a winner
if (overkill > -1) then
--ignore new spike balls for 20 seconds
spikeball_cache.ignore_spikeballs = GetTime()+20

--merge winner spike balls
if (not spikeball_cache.winner_spikeball) then
local spikeBallObject = damage_cache[alvo_serial]
if (spikeBallObject) then
--spikeBallObject.displayName = originalName
spikeball_cache.winner_spikeball = spikeBallObject
else
print(6, "Details! winner spike ball doesn't exists. Nice coding bro!")
end
--cooldown to kill another spikeball again
spikeball_damage_cache.ignore_spikeballs = GetTime()+20

amount = (amount-overkill)
local playerNames = {}
local totalDamageTaken = 0

local playerObject = damage_cache[who_serial]
if (playerObject) then
playerObject.total = playerObject.total + amount
playerObject.targets[alvo_name] = (playerObject.targets[alvo_name] or 0) + amount
local spellTable = playerObject.spells._ActorTable[spellid]
if (spellTable) then
spellTable.total = spellTable.total + amount
spellTable.targets[alvo_name] = (spellTable.targets[alvo_name] or 0) + amount
end
end
spikeball_cache.winner_spikeball.damage_taken = spikeball_cache.winner_spikeball.damage_taken + amount
--award the damage of the spikeball dead to all players which have done damage to it
for playerSerial, damageTable in pairs(npcDamage) do
local actorObject = damage_cache[playerSerial]
if (actorObject) then
playerNames[actorObject.nome] = true
totalDamageTaken = totalDamageTaken + damageTable.total

else
amount = (amount-overkill)

local playerObject = damage_cache[who_serial]
if (playerObject) then
playerObject.total = playerObject.total + amount
playerObject.targets[alvo_name] = (playerObject.targets[alvo_name] or 0) + amount
local spellTable = playerObject.spells._ActorTable[spellid]
if (spellTable) then
spellTable.total = spellTable.total + amount
spellTable.targets[alvo_name] = (spellTable.targets[alvo_name] or 0) + amount
end
end
spikeball_cache.winner_spikeball.damage_taken = spikeball_cache.winner_spikeball.damage_taken + amount

--there's a second winner ball, merge both
local thisRoundWinnerSpikeBall = damage_cache[alvo_serial]
local firstWinnerName = spikeball_cache.winner_spikeball.nome
local thisRoundWinnerName = thisRoundWinnerSpikeBall.nome

--copy damage from
for damageFromName in pairs(thisRoundWinnerSpikeBall.damage_from) do
--the first winner ball get the "damage from" from this winner
spikeball_cache.winner_spikeball.damage_from[damageFromName] = true

local actorObject = _current_combat[1]:GetActor(damageFromName)
if (actorObject) then
--get the damage done on the winner ball of this round and transfer the damage done into the first winner
local damageDone = actorObject.targets[thisRoundWinnerName] or 0
actorObject.targets[firstWinnerName] = (actorObject.targets[firstWinnerName] or 0) + damageDone
actorObject.targets[thisRoundWinnerName] = nil

--spells
for _, spellTable in pairs(actorObject.spells._ActorTable) do
local damageDone = spellTable.targets[thisRoundWinnerName] or 0
spellTable.targets[thisRoundWinnerName] = nil
spellTable.targets[firstWinnerName] = (spellTable.targets[firstWinnerName] or 0) + damageDone
end
end
end
actorObject.total = actorObject.total + damageTable.total
actorObject.targets[alvo_name] = (actorObject.targets[alvo_name] or 0) + damageTable.total

spikeball_cache.winner_spikeball.damage_taken = spikeball_cache.winner_spikeball.damage_taken + thisRoundWinnerSpikeBall.damage_taken
for spellid, damageDone in pairs(damageTable.spells) do
local spellObject = actorObject.spells._ActorTable[spellid]

thisRoundWinnerSpikeBall.total = 0
thisRoundWinnerSpikeBall.damage_taken = 0
spikeball_cache.winners_cache[thisRoundWinnerSpikeBall] = true
end

--/run GameTooltip:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -13, 250) to remove the tooltip above details!

--delete loser spike balls
local container = _current_combat[1]._ActorTable
for i = #container, 1, -1 do
local spikeBall = container[i]
if (spikeBall) then
--check if the actor is a spike ball
if (tonumber(spikeBall.aID) == npcId) then
if (spikeball_cache.winner_spikeball ~= spikeBall and not spikeball_cache.winners_cache[spikeBall]) then

for actorName in pairs(spikeBall.damage_from) do
local actorObject = _current_combat[1]:GetActor(actorName)
if (actorObject) then
--remove from the damage from
spikeBall.damage_from[actorName] = nil

--remove from targets
local damageDone = actorObject.targets[spikeBall.nome] or 0
actorObject.targets[spikeBall.nome] = nil

--remove from damage done
actorObject.total = actorObject.total - damageDone

--reduce from spells
for _, spellTable in pairs(actorObject.spells._ActorTable) do
local damageDone = spellTable[spikeBall.nome] or 0
spellTable.total = spellTable.total - damageDone
end
end
end
if (not spellObject) then
spellObject = actorObject.spells:PegaHabilidade(spellid, true, token)
end

--reset the damage taken amount
spikeBall.damage_taken = 0
spikeBall.total = 0
if (spellObject) then
spellObject.total = spellObject.total + damageDone
spellObject.targets[alvo_name] = (spellObject.targets[alvo_name] or 0) + damageDone
end
end
end
end

--get or create the spikeball object; add the damage_from and damage taken
local spikeBall = damage_cache[alvo_serial]
if (not spikeBall) then
spikeBall = _current_damage_container:PegarCombatente(alvo_serial, alvo_name, alvo_flags, true)
damage_cache[alvo_serial] = spikeBall
end
if (spikeBall) then
spikeBall.damage_taken = spikeBall.damage_taken + totalDamageTaken
for playerName in pairs(playerNames) do
spikeBall.damage_from[playerName] = true
end
end

Details:RefreshMainWindow(-1, true)
return
end

return
end

--source
Expand All @@ -795,17 +731,6 @@
who_name = "Tank Add"
end

if (npcId == NPCID_SPIKEDBALL) then --remove on 10.0
--actor name
local spikeName = spikeball_cache.name_cache[who_serial]
if (not spikeName) then
spikeball_cache.spike_counter = spikeball_cache.spike_counter + 1
spikeName = who_name .. " " .. spikeball_cache.spike_counter
spikeball_cache.name_cache[who_serial] = spikeName
end
who_name = spikeName
end

--> avoid doing spellID checks on each iteration
if (special_damage_spells [spellid]) then
--> stagger
Expand Down Expand Up @@ -4853,12 +4778,10 @@ local SPELL_POWER_PAIN = SPELL_POWER_PAIN or (PowerEnum and PowerEnum.Pain) or 1

--remove on 10.0
--if (encounterID == 2430) then --Painsmith Raznal
_table_wipe(spikeball_cache)
spikeball_cache.name_cache = {}
spikeball_cache.winners_cache = {}
spikeball_cache.spike_counter = 0
spikeball_cache.winner_spikeball = false
spikeball_cache.ignore_spikeballs = false
spikeball_damage_cache = {
npc_cache = {},
ignore_spikeballs = 0,
}
--end
--

Expand Down Expand Up @@ -4958,13 +4881,13 @@ local SPELL_POWER_PAIN = SPELL_POWER_PAIN or (PowerEnum and PowerEnum.Pain) or 1
_table_wipe (bargastBuffs) --remove on 10.0
_table_wipe (necro_cheat_deaths) --remove on 10.0

_table_wipe(spikeball_cache) --remove on 10.0 spikeball from painsmith
spikeball_cache.name_cache = {}
spikeball_cache.winners_cache = {}
spikeball_cache.spike_counter = 0
spikeball_cache.winner_spikeball = false
spikeball_cache.ignore_spikeballs = false
--remove on 10.0 spikeball from painsmith
spikeball_damage_cache = {
npc_cache = {},
ignore_spikeballs = 0,
}
--

return true
end

Expand Down Expand Up @@ -5048,16 +4971,6 @@ local SPELL_POWER_PAIN = SPELL_POWER_PAIN or (PowerEnum and PowerEnum.Pain) or 1
if (_detalhes.debug) then
_detalhes:Msg ("(debug) running scheduled events after combat end.")
end

--remove on 10.0 spikeball from painsmith
--[=[
_table_wipe(spikeball_cache)
spikeball_cache.name_cache = {}
spikeball_cache.winners_cache = {}
spikeball_cache.spike_counter = 0
spikeball_cache.winner_spikeball = false
spikeball_cache.ignore_spikeballs = false
--]=]

--when the user requested data from the storage but is in combat lockdown
if (_detalhes.schedule_storage_load) then
Expand Down
8 changes: 4 additions & 4 deletions frames/window_playerbreakdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,8 @@ local elvui_skin = function()
window.bg1:SetHorizTile (true)
window.bg1:SetSize (PLAYER_DETAILS_WINDOW_WIDTH, PLAYER_DETAILS_WINDOW_HEIGHT)

window:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1})
window:SetBackdropColor (1, 1, 1, 1)
window:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\AddOns\Details\images\background]]})
window:SetBackdropColor (1, 1, 1, 0.3)
window:SetBackdropBorderColor (0, 0, 0, 1)
window.bg_icone_bg:Hide()
window.bg_icone:Hide()
Expand Down Expand Up @@ -5743,7 +5743,7 @@ function gump:CriaNovaBarraInfo1 (instancia, index)
esta_barra.targets.texture:SetAllPoints()
esta_barra.targets.texture:SetDesaturated (true)
esta_barra.targets:SetAlpha (.7)
esta_barra.targets.texture:SetAlpha (.7)
esta_barra.targets.texture:SetAlpha (1)
esta_barra.targets:SetScript ("OnEnter", target_on_enter)
esta_barra.targets:SetScript ("OnLeave", target_on_leave)

Expand All @@ -5762,7 +5762,7 @@ function gump:CriaNovaBarraInfo1 (instancia, index)
esta_barra.icone:SetHeight (CONST_BAR_HEIGHT)
esta_barra.icone:SetPoint ("RIGHT", esta_barra.textura, "LEFT", CONST_BAR_HEIGHT + 2, 0)

esta_barra:SetAlpha(0.9)
esta_barra:SetAlpha(1)
esta_barra.icone:SetAlpha (1)

esta_barra.isMain = true
Expand Down

0 comments on commit 37b7687

Please sign in to comment.