Buy buffmats & Buff players

This commit is contained in:
Roman Hergenreder 2017-11-22 21:31:32 +01:00
parent 7b345827c1
commit b9000b79da

@ -11,18 +11,44 @@ local RAID_MARK_SQUARE = 6
local RAID_MARK_CROSS = 7
local RAID_MARK_SKULL = 8
local SYMBOL_OF_KINGS_ID = 21177
local SDK_ID = 20217
local GSDK_ID = 25898
local GSDW_ID = 48938
local SDW_ID = 48936
local SDM_ID = 48932
local GSDM_ID = 48934
local CLASS_WARRIOR = 1
local CLASS_PALADIN = 2
local CLASS_HUNTER = 3
local CLASS_ROGUE = 4
local CLASS_PRIEST = 5
local CLASS_DEATHKNIGHT = 6
local CLASS_SHAMAN = 7
local CLASS_MAGE = 8
local CLASS_WARLOCK = 9
local QueuedMemberCount = QueuedMemberCount
local Enabled = Enabled
local AQ_Enabled = AQ_Enabled
local AB_Enabled = AB_Enabled
local Frame = Frame
local Tick = Tick
local hasJoined = hasJoined
local messageSent = messageSent
local aMerchants = { ["Drix Finsterzang"] = 39, ["Jeeves"] = 13 }
local function OnUpdate(self, elapsed)
local doUpdate = (floor(Tick + elapsed) > floor(Tick))
Tick = Tick + elapsed
if doUpdate and Enabled then
AutoQueueBG:OnUpdate()
if doUpdate then
if AQ_Enabled then
AutoQueueBG:OnUpdate()
end
if AB_Enabled then
AutoQueueBG:BuyBuffMats()
end
end
end
@ -42,8 +68,59 @@ function AutoQueueBG:CanConfirm()
return (GetBattlefieldStatus(RANDOM_BG_INDEX) == "confirm")
end
function AutoQueueBG:CheckNPC(npcName)
TargetUnit(npcName)
if UnitExists("target") == 1
and GetUnitName("target") == npcName
and UnitIsFriend("target","player") == 1
and UnitIsDeadOrGhost("target") == nil
and CheckInteractDistance("target", 3) == 1 then
return true
end
return false
end
function AutoQueueBG:CheckRaidMember(raidMember)
if UnitExists(raidMember) == 1
and GetUnitName(raidMember) == playerName
and UnitIsFriend(raidMember,"player") == 1
and UnitIsDeadOrGhost(raidMember) == nil
and UnitInRange(raidMember) == 1 then
return true
end
return false
end
function AutoQueueBG:BuyBuffMats()
if not AB_Enabled then
return
end
local buyAmount = 200 - GetItemCount(SYMBOL_OF_KINGS_ID)
if buyAmount > 0 then
for npcName, itemSlot in pairs(aMerchants) do
if AutoQueueBG:CheckNPC(npcName) then
InteractUnit("target")
name, texture, price, quantity = GetMerchantItemInfo(itemSlot)
buyAmount = ceil(buyAmount / quantity)
BuyMerchantItem(itemSlot, buyAmount)
CloseMerchant()
return
end
end
end
end
function AutoQueueBG:IsPreperationTime()
local time = GetBattlefieldInstanceRunTime()
return time > 0 and time < 120000
end
function AutoQueueBG:OnUpdate()
if (not Enabled) then
if (not AQ_Enabled) then
return
end
@ -57,6 +134,10 @@ function AutoQueueBG:OnUpdate()
elseif IsRaidLeader() == 1 then
AutoQueueBG:MarkPlayers()
end
if AutoQueueBG:IsPreperationTime() then
AutoQueueBG:BuffPlayers()
end
end
if AutoQueueBG:IsQueued() or AutoQueueBG:CanConfirm() then
@ -81,6 +162,45 @@ function AutoQueueBG:OnUpdate()
end
end
function AutoQueueBG:BuffDuration(unit, buffName)
name, rank, icon, count, debuffType, duration, expirationTime = UnitBuff(unit, buffName)
if expirationTime == nil then
return 0
else
return (GetTime() - expirationTime)
end
end
function AutoQueueBG:PlayerNeedsSDM(unit)
localizedClass, englishClass, classIndex = UnitClass(unit);
if classIndex == CLASS_WARRIOR or
classIndex == CLASS_DEATHKNIGHT or
classIndex == CLASS_ROGUE or
classIndex == CLASS_HUNTER then
return true
end
return false
end
function AutoQueueBG:BuffPlayer(unit, spellId)
TargetUnit(unit)
CastSpellByID(spellId)
TargetLastTarget()
end
function AutoQueueBG:BuffPlayers()
local aBuffs = {{GSDK,SDK},{GSDM,SDM},{GSDW,SDW}}
for i = 1, 40 do -- For each raid member
local unit = "raid" .. i
if AutoQueueBG:CheckRaidMember(unit) then
if AutoQueueBG:BuffDuration(unit, GetSpellInfo(GSDK)) < 15 then
BuffPlayer(unit, GSDK)
end
end
end
end
function AutoQueueBG:MarkPlayers()
if IsRaidLeader() == 1 then
@ -100,6 +220,7 @@ function AutoQueueBG:MarkPlayers()
["Zalaras"] = RAID_MARK_TRIANGLE,
["Leiana"] = RAID_MARK_TRIANGLE,
["Seyjóu"] = RAID_MARK_SQUARE,
["Morcsi"] = RAID_MARK_SQUARE,
["Ravenson"] = RAID_MARK_DIAMOND,
["Gurtogg"] = RAID_MARK_CONDOM
}
@ -158,35 +279,39 @@ function AutoQueueBG:OnCommand(input)
local arg1, arg2 = AutoQueueBG:GetArgs(input, 2)
ChatType = id
if arg1 == nil then
print("[AutoQueueBG] Usage: /autoqueue [start|stop|status]")
print("[AutoQueueBG] Usage: /autoqueue [start|stop|status|autobuy]")
return
end
if string.lower(arg1) == "start" then
if Enabled then
if AQ_Enabled then
print("AutoQueueBG ist bereits aktiv.")
else
Enabled = true
AQ_Enabled = true
Tick = 0
Frame:SetScript("OnUpdate", OnUpdate)
print("AutoQueueBG aktiviert.")
end
elseif string.lower(arg1) == "stop" then
if not Enabled then
if not AQ_Enabled then
print("AutoQueueBG ist nicht aktiv.")
else
Enabled = false
Frame:SetScript("OnUpdate", nil)
AQ_Enabled = false
-- Frame:SetScript("OnUpdate", nil)
print("AutoQueueBG deaktiviert.")
end
elseif string.lower(arg1) == "status" then
print("[AutoQueueBG] Status: " .. (Enabled and "Aktiviert" or "Deaktiviert"))
print("[AutoQueueBG] Status: " .. (AQ_Enabled and "Aktiviert" or "Deaktiviert"))
elseif string.lower(arg1) == "autobuy" then
AB_Enabled = not AB_Enabled
print("[AutoQueueBG] AutoBuy " .. (AB_Enabled and "Aktiviert" or "Deaktiviert"))
end
end
function AutoQueueBG:OnInitialize()
Enabled = false
AQ_Enabled = false
AB_Enabled = true
Frame = CreateFrame("frame")
Frame:SetScript("OnUpdate", OnUpdate)
Tick = 0
hasJoined = false
messageSent = 0