Skip to content

Commit

Permalink
Each nameplate now has its own cast cooldown timer while casting test…
Browse files Browse the repository at this point in the history
… is enabled.
  • Loading branch information
Tercioo committed Jul 19, 2024
1 parent adc6e4f commit 930d89d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 67 deletions.
23 changes: 23 additions & 0 deletions Definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,29 @@
---@field RemoveForceBlizzardNameplateUnits fun(npcId: number)
---@field GetHealthCutoffValue fun() update the execute range by the class, spec and talents the player is using
---@field CheckRange fun(plateFrame: table, onAdded: boolean) check if the nameplate is in range and update the alpha
---@field PlayAudioForScript fun(canUseScriptAudio: boolean, audioFilePath: string, envTable: scriptenv) play an audio for a script

---@class scriptenv : table
---@field _SpellID number
---@field _UnitID string
---@field _SpellName string
---@field _Texture string
---@field _Caster string
---@field _StackCount number
---@field _Duration number
---@field _StartTime number
---@field _EndTime number
---@field _RemainingTime number
---@field _CastPercent number
---@field _CanInterrupt boolean
---@field _NpcID number
---@field _UnitName string
---@field _UnitGUID string
---@field _HealthPercent number
---@field _CanStealOrPurge boolean
---@field _AuraType string
---@field _AuraAmount number
---@field _CastBarHeight number

---@class scriptoption : table
---@field Type number
Expand Down
147 changes: 83 additions & 64 deletions Plater.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3779,6 +3779,12 @@ Plater.AnchorNamesByPhraseId = {

-- add private aura anchors
Plater.HandlePrivateAuraAnchors(plateFrame.unitFrame) -- requires namePlateUnitToken, PlaterOnScreen and IsSelf to be set

--check if the cast bar test is enabled
if (Plater.IsShowingCastBarTest) then
--start a castbar test for this unit
platerInternal.CastBar.StartTestCastBarForNameplate(plateFrame)
end
end,

-- ~removed
Expand Down Expand Up @@ -4734,97 +4740,110 @@ function Plater.OnInit() --private --~oninit ~init

Plater.IsTestRunning = true
end

function platerInternal.CastBar.StartTestCastBarForNameplate(plateFrame)
local castTime = Plater.CastBarTestFrame.castTime
---@cast plateFrame plateframe
if plateFrame.unitFrame.PlaterOnScreen then
local castBar = plateFrame.unitFrame.castBar

local spellName, _, spellIcon = GetSpellInfo(116)

castBar.Text:SetText(spellName)
castBar.Icon:SetTexture(spellIcon)
castBar.Icon:SetAlpha(1)
castBar.Icon:Show()
castBar.percentText:Show()
castBar:SetMinMaxValues(0, (castTime or 3))
castBar:SetValue(0)
castBar.Spark:Show()
castBar.casting = true
castBar.finished = false
castBar.value = 0
castBar.maxValue = (castTime or 3)
castBar.canInterrupt = castNoInterrupt or math.random (1, 2) == 1
--castBar.canInterrupt = true
--castBar.channeling = true
castBar:UpdateCastColor()

castBar.spellName = spellName
castBar.spellID = 116
castBar.spellTexture = spellIcon
castBar.spellStartTime = GetTime()
castBar.spellEndTime = GetTime() + (castTime or 3)

castBar.SpellStartTime = GetTime()
castBar.SpellEndTime = GetTime() + (castTime or 3)

castBar.playedFinishedTest = nil

castBar.flashTexture:Hide()
castBar:Animation_StopAllAnimations()

if (castBar.channeling) then
Plater.CastBarOnEvent_Hook(castBar, "UNIT_SPELLCAST_CHANNEL_START", plateFrame.unitFrame.unit, plateFrame.unitFrame.unit)
else
Plater.CastBarOnEvent_Hook(castBar, "UNIT_SPELLCAST_START", plateFrame.unitFrame.unit, plateFrame.unitFrame.unit)
end

platerInternal.Audio.PlaySoundForCastStart(castBar.spellID)

if (not castBar:IsShown()) then
castBar:Animation_FadeIn()
castBar:Show()
end

Plater.UpdateCastbarTargetText(castBar)
local textString = castBar.FrameOverlay.TargetName
textString:Show()
textString:SetText("Target Name")
end
end

function Plater.DoCastBarTest (castNoInterrupt, castTime)

Plater.CastBarTestFrame.castTime = castTime or 3

for _, plateFrame in ipairs (Plater.GetAllShownPlates()) do
---@cast plateFrame plateframe
if plateFrame.unitFrame.PlaterOnScreen then
local castBar = plateFrame.unitFrame.castBar

local spellName, _, spellIcon = GetSpellInfo(116)

castBar.Text:SetText(spellName)
castBar.Icon:SetTexture(spellIcon)
castBar.Icon:SetAlpha(1)
castBar.Icon:Show()
castBar.percentText:Show()
castBar:SetMinMaxValues(0, (castTime or 3))
castBar:SetValue(0)
castBar.Spark:Show()
castBar.casting = true
castBar.finished = false
castBar.value = 0
castBar.maxValue = (castTime or 3)
castBar.canInterrupt = castNoInterrupt or math.random (1, 2) == 1
--castBar.canInterrupt = true
--castBar.channeling = true
castBar:UpdateCastColor()

castBar.spellName = spellName
castBar.spellID = 116
castBar.spellTexture = spellIcon
castBar.spellStartTime = GetTime()
castBar.spellEndTime = GetTime() + (castTime or 3)

castBar.SpellStartTime = GetTime()
castBar.SpellEndTime = GetTime() + (castTime or 3)

castBar.playedFinishedTest = nil

castBar.flashTexture:Hide()
castBar:Animation_StopAllAnimations()

if (castBar.channeling) then
Plater.CastBarOnEvent_Hook(castBar, "UNIT_SPELLCAST_CHANNEL_START", plateFrame.unitFrame.unit, plateFrame.unitFrame.unit)
else
Plater.CastBarOnEvent_Hook(castBar, "UNIT_SPELLCAST_START", plateFrame.unitFrame.unit, plateFrame.unitFrame.unit)
end

if (not castBar:IsShown()) then
castBar:Animation_FadeIn()
castBar:Show()
end

Plater.UpdateCastbarTargetText(castBar)
local textString = castBar.FrameOverlay.TargetName
textString:Show()
textString:SetText("Target Name")
end
platerInternal.CastBar.StartTestCastBarForNameplate(plateFrame)
end

local totalTime = 0
local checkEachSeconds = 0.4 --0.4 default
local forward = true

Plater.CastBarTestFrame:SetScript ("OnUpdate", function (self, deltaTime)
if (totalTime >= (Plater.CastBarTestFrame.castTime + 0.1)) then
if (totalTime >= checkEachSeconds) then --(Plater.CastBarTestFrame.castTime + 0.1)
totalTime = 0

for _, plateFrame in ipairs (Plater.GetAllShownPlates()) do
---@cast plateFrame plateframe
if plateFrame.unitFrame.PlaterOnScreen then
local castBar = plateFrame.unitFrame.castBar
local textString = castBar.FrameOverlay.TargetName
textString:Show()
textString:SetText("Target Name")
--local textString = castBar.FrameOverlay.TargetName
--textString:Show()
--textString:SetText("Target Name")

if (castBar.finished and not castBar.playedFinishedTest) then
Plater.CastBarOnEvent_Hook (castBar, "UNIT_SPELLCAST_STOP", plateFrame.unitFrame.unit, plateFrame.unitFrame.unit)
--castBar:Hide()
castBar.playedFinishedTest = true
end
end
end

if (Plater.IsShowingCastBarTest) then
--run another cycle
Plater.CastBarTestFrame.ScheduleNewCycle = C_Timer.NewTimer(0.5, function()
if (Plater.IsShowingCastBarTest) then
Plater.StartCastBarTest(Plater.CastBarTestFrame.castNoInterrupt, Plater.CastBarTestFrame.castTime, true)
end
end)
if (not Plater.CastBarTestFrame.ScheduleNewCycle) then
Plater.CastBarTestFrame.ScheduleNewCycle = C_Timer.NewTimer(0.5, function()
if (Plater.IsShowingCastBarTest) then
for _, plateFrame in ipairs (Plater.GetAllShownPlates()) do
if (not plateFrame.unitFrame.castBar:IsShown()) then
platerInternal.CastBar.StartTestCastBarForNameplate(plateFrame)
end
end
end
Plater.CastBarTestFrame.ScheduleNewCycle = nil
end)
end
else
--don't run another cycle
Plater.CastBarTestFrame:SetScript("OnUpdate", nil)
Expand Down
6 changes: 3 additions & 3 deletions Plater_Audio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ function platerInternal.Audio.PlaySoundForCastStart(spellId, audioFilePath)
local audioCue = audioFilePath or platerInternal.Audio.GetAudioCueForSpell(spellId)
if (audioCue) then
if (((platerInternal.LatestTimeForAudioPlayedByID[spellId] or 0) + Plater.db.profile.cast_audiocue_cooldown) > GetTime()) then
return -- do not play, was played already within the last quarter of a second...
return -- do not play, was played already within the last x seconds, defined on Plater.db.profile.cast_audiocue_cooldown
end

if (platerInternal.LatestHandleForAudioPlayed) then
StopSound(platerInternal.LatestHandleForAudioPlayed, 500)
end

local channel = validChannels[Plater.db.cast_audiocues_channel] or defaultAudioChannel
local willPlay, soundHandle = PlaySoundFile(audioCue, channel)
local bWillPlay, soundHandle = PlaySoundFile(audioCue, channel)

if (willPlay) then
if (bWillPlay) then
platerInternal.LatestHandleForAudioPlayed = soundHandle
platerInternal.LatestTimeForAudioPlayedByID[spellId] = GetTime()
end
Expand Down
1 change: 1 addition & 0 deletions Plater_Data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local addonName, platerInternal = ...

--namespaces
platerInternal.Scripts = {}
platerInternal.CastBar = {}
platerInternal.Mods = {}
platerInternal.Events = {}
platerInternal.Comms = {}
Expand Down

0 comments on commit 930d89d

Please sign in to comment.