CODE:elseif (event == "UNIT_HEALTH") then if (GB_CURRENT_HEAL[1] and arg1 == GB_CURRENT_HEAL[3]) then if (GB_Settings[GB_INDEX].cancelHealThreshold) then if (not GB_Get_PastThreshold("cancelHealThreshold", GB_CURRENT_HEAL[3])) then local text = GB_TEXT.HealCancelledMessage; text = string.gsub(text, ’$s’, GB_CURRENT_HEAL[1]); text = string.gsub(text, ’$r’, GB_CURRENT_HEAL[2]); GB_Feedback(text); GB_CURRENT_HEAL = {}; SpellStopCasting(); end end end
CODE: function GB_Get_PastThreshold(threshold, target, thresholdnum) if ((not thresholdnum) or thresholdnum == "mana") then threshold = GB_Settings[GB_INDEX][threshold]; --把threshold从设置中读出来 else threshold = GB_Settings[GB_INDEX][threshold][thresholdnum]; end --这时的threshold就是你设置的那个字符串,可能在你看来就是一个数字。
if ((not threshold) or threshold == "") then return true; end
local damage = UnitHealthMax(target) - UnitHealth(target); --计算伤害量 --下面是计算百分比 --注意看,是100-[当前血量]/[最大血量] *100 = 伤害量占总血量的百分比 local percent = 100 - UnitHealth(target) / UnitHealthMax(target) * 100; if (thresholdnum == "mana") then --这个是对应魔法 damage = UnitManaMax(target) - UnitMana(target); percent = 100 - UnitMana(target) / UnitManaMax(target) * 100; end if (threshold) then if (string.find(threshold, "%%")) then--检查阈值字符串中间有没有%, _,_,threshold = string.find(threshold, "(%d*)%%"); threshold = tonumber(threshold); --看下面,有%的话就比较百分比 if (threshold and percent < threshold) then return false; end else threshold = tonumber(threshold); if (UnitHealthMax(target) == 100 or (not threshold)) then return 0; end --没有%就比较绝对值 if (damage < threshold) then return false; end end end return true; end
CODE: elseif (event == "UNIT_AURA") then if (arg1 == "target") then if (this.targetauras) then GB_Update_Auras(arg1); end else GB_Update_Auras(arg1); end
CODE: function GB_Update_Auras(unit) --如果目标不存在,就不管他了 if (not UnitName(unit)) then return; end --GB_BUFFS和GB_DEBUFFS是用来保存单位光环信息的表,由单位编号来检索 --既然是光环变化了,而魔兽世界也没有提供到底是什么buff变化了,是消失还是获得, --因此在这里清空对应单位的状态 GB_BUFFS[unit] = {nil}; GB_DEBUFFS[unit] = {nil}; --开始重新检索buff和debuff,总共16个buff和8个debuff for i = 1, 16 do if (UnitBuff(unit, i)) then GBTooltip:SetUnitBuff(unit, i); if (GBTooltipTextLeft1:IsVisible()) then GB_BUFFS[unit][GBTooltipTextLeft1:GetText()] = true; if (string.find(GBTooltipTextLeft1:GetText(), "-", 1, true)) then GB_BUFFS[unit][UnitBuff(unit, i)] = true; end end end end for i = 1, 8 do if (UnitDebuff(unit, i)) then GBTooltip:SetUnitDebuff(unit, i); if (GBTooltipTextLeft1:IsVisible()) then GB_DEBUFFS[unit][GBTooltipTextLeft1:GetText()] = true; end if (GBTooltipTextRight1:IsVisible()) then GB_DEBUFFS[unit][GBTooltipTextRight1:GetText()] = true; end end end end
CODE: elseif (event == "TRAINER_CLOSED") then GB_Spellbook_Initialize(); if (GB_SPELLS_UPDATED) then GB_SPELLS_UPDATED = nil; else GB_Update_SpellRanks(); end