From f3c4d191af121fc93f2c09e434ca8f585a7055d4 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Tue, 15 Oct 2013 01:25:51 +0000 Subject: [PATCH] Split "actions" from "functions", where actions are Spell/Item/Macro, etc. Actions are final actions to be suggested, while functions return booleans or values. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1055 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleBestAction.lua | 180 ++++++++++++++++++++++++++------------------------- OvaleCompile.lua | 8 ++- 2 files changed, 98 insertions(+), 90 deletions(-) diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua index 371d1cf..9f4d8c9 100644 --- a/OvaleBestAction.lua +++ b/OvaleBestAction.lua @@ -69,6 +69,81 @@ local function PutValue(element, value, origin, rate) return result end +local function ComputeAction(element, atTime) + local self = OvaleBestAction + local actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration, + actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId = self:GetActionInfo(element) + + if not actionTexture then + Ovale:Logf("Action %s not found", element.params[1]) + return nil + end + if not (actionEnable and actionEnable > 0) then + Ovale:Logf("Action %s not enabled", element.params[1]) + return nil + end + if element.params.usable == 1 and not actionUsable then + Ovale:Logf("Action %s not usable", element.params[1]) + return nil + end + + if spellId then + local si = spellId and OvaleData.spellInfo[spellId] + if si and si.casttime then + element.castTime = si.casttime + else + local castTime = select(7, API_GetSpellInfo(spellId)) + if castTime then + element.castTime = castTime / 1000 + else + element.castTime = nil + end + end + if si and si.toggle and actionIsCurrent then + Ovale:Logf("Action %s (toggle) is the current action", element.params[1]) + return nil + end + else + element.castTime = 0 + end + + local start, ending = 0, math.huge + local priority = element.params.priority or OVALE_DEFAULT_PRIORITY + + -- If the action is not on cooldown, then treat it like it's immediately ready. + if actionCooldownDuration and actionCooldownStart and actionCooldownStart > 0 then + start = actionCooldownDuration + actionCooldownStart + else + start = atTime + end + + Ovale:Logf("start=%f attenteFinCast=%s [%d]", start, OvaleState.attenteFinCast, element.nodeId) + if start < OvaleState.attenteFinCast then + local si = OvaleState.currentSpellId and OvaleData.spellInfo[OvaleState.currentSpellId] + if not (si and si.canStopChannelling) then + -- not a channelled spell, or a channelled spell that cannot be interrupted + start = OvaleState.attenteFinCast + else + --TODO: pas exact, parce que si ce sort est reporté de par exemple 0,5s par un debuff + --ça tombera entre deux ticks + local numTicks = floor(OvalePaperDoll:GetSpellHasteMultiplier() * si.canStopChannelling + 0.5) + local tick = (OvaleState.attenteFinCast - OvaleState.startCast) / numTicks + local tickTime = OvaleState.startCast + tick + Ovale:Logf("%s start=%f", spellId, start) + for i = 1, numTicks do + if start <= tickTime then + start = tickTime + break + end + tickTime = tickTime + tick + end + Ovale:Logf("%s start=%f, numTicks=%d, tick=%f, tickTime=%f", spellId, start, numTicks, tick, tickTime) + end + end + Ovale:Logf("Action %s can start at %f", element.params[1], start) + return start, ending, priority, element +end + local function ComputeAnd(element, atTime) Ovale:Logf("%s [%d]", element.type, element.nodeId) local self = OvaleBestAction @@ -260,98 +335,26 @@ end local function ComputeFunction(element, atTime) local self = OvaleBestAction - if element.func == "spell" or element.func == "macro" or element.func == "item" or element.func == "texture" then - local actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration, - actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId = self:GetActionInfo(element) - - if not actionTexture then - Ovale:Logf("Action %s not found", element.params[1]) - return nil - end - if element.params.usable == 1 and not actionUsable then - Ovale:Logf("Action %s not usable", element.params[1]) - return nil - end + local condition = OvaleCondition.conditions[element.func] + if not condition then + Ovale:Errorf("Condition %s not found", element.func) + return nil + end + local start, ending, value, origin, rate = condition(element.params, atTime) - if spellId then - local si = spellId and OvaleData.spellInfo[spellId] - if si and si.casttime then - element.castTime = si.casttime - else - local castTime = select(7, API_GetSpellInfo(spellId)) - if castTime then - element.castTime = castTime / 1000 - else - element.castTime = nil - end - end - if si and si.toggle and actionIsCurrent then - Ovale:Logf("Action %s (toggle) is the current action", element.params[1]) - return nil - end - else - element.castTime = 0 + if Ovale.trace then + local conditionCall = element.func .. "(" + for k, v in pairs(element.params) do + conditionCall = conditionCall .. k .. "=" .. v .. "," end + conditionCall = conditionCall .. ")" + Ovale:FormatPrint("Condition %s returned %s, %s, %s, %s, %s", conditionCall, start, ending, value, origin, rate) + end - if actionEnable and actionEnable > 0 then - local start, ending = 0, math.huge - local priority = element.params.priority or OVALE_DEFAULT_PRIORITY - - if actionCooldownDuration and actionCooldownStart and actionCooldownStart > 0 then - start = actionCooldownDuration + actionCooldownStart - else - start = atTime - end - Ovale:Logf("start=%f attenteFinCast=%s [%d]", start, OvaleState.attenteFinCast, element.nodeId) - if start < OvaleState.attenteFinCast then - local si = OvaleState.currentSpellId and OvaleData.spellInfo[OvaleState.currentSpellId] - if not (si and si.canStopChannelling) then - -- not a channelled spell, or a channelled spell that cannot be interrupted - start = OvaleState.attenteFinCast - else - --TODO: pas exact, parce que si ce sort est reporté de par exemple 0,5s par un debuff - --ça tombera entre deux ticks - local numTicks = floor(OvalePaperDoll:GetSpellHasteMultiplier() * si.canStopChannelling + 0.5) - local tick = (OvaleState.attenteFinCast - OvaleState.startCast) / numTicks - local tickTime = OvaleState.startCast + tick - Ovale:Logf("%s start=%f", spellId, start) - for i = 1, numTicks do - if start <= tickTime then - start = tickTime - break - end - tickTime = tickTime + tick - end - Ovale:Logf("%s start=%f, numTicks=%d, tick=%f, tickTime=%f", spellId, start, numTicks, tick, tickTime) - end - end - Ovale:Logf("Action %s can start at %f", element.params[1], start) - return start, ending, priority, element - else - Ovale:Logf("Action %s not enabled", element.params[1]) - end + if value then + return start, ending, OVALE_DEFAULT_PRIORITY, PutValue(element, value, origin, rate) else - local condition = OvaleCondition.conditions[element.func] - if not condition then - Ovale:Errorf("Condition %s not found", element.func) - return nil - end - local start, ending, value, origin, rate = condition(element.params, atTime) - - if Ovale.trace then - local conditionCall = element.func .. "(" - for k, v in pairs(element.params) do - conditionCall = conditionCall .. k .. "=" .. v .. "," - end - conditionCall = conditionCall .. ")" - Ovale:FormatPrint("Condition %s returned %s, %s, %s, %s, %s", conditionCall, start, ending, value, origin, rate) - end - - if value then - return start, ending, OVALE_DEFAULT_PRIORITY, PutValue(element, value, origin, rate) - else - return start, ending - end + return start, ending end end @@ -522,6 +525,7 @@ end -- local OVALE_COMPUTE_VISITOR = { + ["action"] = ComputeAction, ["and"] = ComputeAnd, ["arithmetic"] = ComputeArithmetic, ["compare"] = ComputeCompare, diff --git a/OvaleCompile.lua b/OvaleCompile.lua index ba48388..1b47032 100644 --- a/OvaleCompile.lua +++ b/OvaleCompile.lua @@ -217,7 +217,11 @@ local function ParseFunction(prefix, func, params) end local node = self_pool:Get() - node.type = "function" + if func == "spell" or func == "macro" or func == "item" or func == "texture" then + node.type = "action" + else + node.type = "function" + end node.func = func node.params = paramList local nodeName = AddNode(node) @@ -835,7 +839,7 @@ function OvaleCompile:DebugNode(node) text = text .. self:DebugNode(n) .. " " end text = text .. "}\n" - elseif (node.type == "function") then + elseif (node.type == "action" or node.type == "function") then text = node.func.."(" for k,p in pairs(node.params) do text = text .. k.."=" .. p .. " " -- 1.7.9.5