2017-11-17 17:04:37 +01:00
|
|
|
AutoQueueBG = LibStub("AceAddon-3.0"):NewAddon("AutoQueueBG", "AceConsole-3.0","AceEvent-3.0", "AceTimer-3.0")
|
|
|
|
local AutoQueueBG = _G.AutoQueueBG
|
|
|
|
|
|
|
|
local RANDOM_BG_INDEX = 1
|
|
|
|
local RAID_MARK_STAR = 1
|
|
|
|
local RAID_MARK_CONDOM = 2
|
|
|
|
local RAID_MARK_DIAMOND = 3
|
|
|
|
local RAID_MARK_TRIANGLE = 4
|
|
|
|
local RAID_MARK_MOON = 5
|
|
|
|
local RAID_MARK_SQUARE = 6
|
|
|
|
local RAID_MARK_CROSS = 7
|
|
|
|
local RAID_MARK_SKULL = 8
|
|
|
|
|
2017-11-22 21:31:32 +01:00
|
|
|
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
|
|
|
|
|
2017-11-17 17:04:37 +01:00
|
|
|
local QueuedMemberCount = QueuedMemberCount
|
2017-11-22 21:31:32 +01:00
|
|
|
local AQ_Enabled = AQ_Enabled
|
|
|
|
local AB_Enabled = AB_Enabled
|
2017-11-17 17:04:37 +01:00
|
|
|
local Frame = Frame
|
|
|
|
local Tick = Tick
|
|
|
|
local hasJoined = hasJoined
|
|
|
|
local messageSent = messageSent
|
2017-11-22 21:31:32 +01:00
|
|
|
local aMerchants = { ["Drix Finsterzang"] = 39, ["Jeeves"] = 13 }
|
2017-11-17 17:04:37 +01:00
|
|
|
|
|
|
|
local function OnUpdate(self, elapsed)
|
|
|
|
local doUpdate = (floor(Tick + elapsed) > floor(Tick))
|
|
|
|
Tick = Tick + elapsed
|
2017-11-22 21:31:32 +01:00
|
|
|
if doUpdate then
|
|
|
|
if AQ_Enabled then
|
|
|
|
AutoQueueBG:OnUpdate()
|
|
|
|
end
|
|
|
|
|
|
|
|
if AB_Enabled then
|
|
|
|
AutoQueueBG:BuyBuffMats()
|
|
|
|
end
|
2017-11-17 17:04:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:CanQueue()
|
|
|
|
return (GetBattlefieldStatus(RANDOM_BG_INDEX) == "none")
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:IsQueued()
|
|
|
|
return (GetBattlefieldStatus(RANDOM_BG_INDEX) == "queued");
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:IsInBattleground()
|
|
|
|
return (GetBattlefieldStatus(RANDOM_BG_INDEX) == "active")
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:CanConfirm()
|
|
|
|
return (GetBattlefieldStatus(RANDOM_BG_INDEX) == "confirm")
|
|
|
|
end
|
|
|
|
|
2017-11-22 21:31:32 +01:00
|
|
|
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 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
|
|
|
|
|
2017-11-17 17:04:37 +01:00
|
|
|
function AutoQueueBG:OnUpdate()
|
2017-11-22 21:31:32 +01:00
|
|
|
if (not AQ_Enabled) then
|
2017-11-17 17:04:37 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if messageSent > 0 then
|
|
|
|
messageSent = messageSent - 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if (AutoQueueBG:IsInBattleground()) then
|
|
|
|
if (GetBattlefieldInstanceExpiration() > 0) then
|
|
|
|
AutoQueueBG:LeaveBG()
|
|
|
|
elseif IsRaidLeader() == 1 then
|
|
|
|
AutoQueueBG:MarkPlayers()
|
|
|
|
end
|
2017-11-22 21:31:32 +01:00
|
|
|
|
|
|
|
if AutoQueueBG:IsPreperationTime() then
|
|
|
|
AutoQueueBG:BuffPlayers()
|
|
|
|
end
|
2017-11-17 17:04:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if AutoQueueBG:IsQueued() or AutoQueueBG:CanConfirm() then
|
|
|
|
if AutoQueueBG:GetQueueMemberCount() > QueuedMemberCount then
|
|
|
|
AutoQueueBG:LeaveBG()
|
|
|
|
elseif AutoQueueBG:CanConfirm() then
|
|
|
|
RequestBattlegroundInstanceInfo(RANDOM_BG_INDEX)
|
|
|
|
AcceptBattlefieldPort(RANDOM_BG_INDEX, 1)
|
|
|
|
StaticPopup_Hide("CONFIRM_BATTLEFIELD_ENTRY")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if(AutoQueueBG:CanQueue()) then
|
|
|
|
if (QueuedMemberCount > 1 and hasJoined and messageSent == 0) then
|
|
|
|
SendChatMessage("[AutoQueueBG] Bitte das aktuelle BG verlassen, damit wir als Gruppe anmelden können!", "PARTY", nil)
|
|
|
|
messageSent = 30
|
|
|
|
end
|
|
|
|
AutoQueueBG:QueueBG()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-22 21:31:32 +01:00
|
|
|
function AutoQueueBG:BuffDuration(unit, buffName)
|
|
|
|
name, rank, icon, count, debuffType, duration, expirationTime = UnitBuff(unit, buffName)
|
|
|
|
if expirationTime == nil then
|
|
|
|
return 0
|
|
|
|
else
|
2017-11-22 22:39:42 +01:00
|
|
|
return -1 * (GetTime() - expirationTime)
|
2017-11-22 21:31:32 +01:00
|
|
|
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
|
2017-11-22 22:15:17 +01:00
|
|
|
local spellName = GetSpellInfo(GSDK_ID)
|
2017-11-22 22:39:42 +01:00
|
|
|
if AutoQueueBG:BuffDuration(unit, spellName) < 15000 then
|
2017-11-22 22:15:17 +01:00
|
|
|
AutoQueueBG:BuffPlayer(unit, GSDK_ID)
|
2017-11-22 22:09:22 +01:00
|
|
|
return;
|
2017-11-22 21:31:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-17 17:04:37 +01:00
|
|
|
function AutoQueueBG:MarkPlayers()
|
|
|
|
|
|
|
|
if IsRaidLeader() == 1 then
|
|
|
|
local aMarks = {
|
|
|
|
["Kulaf"] = RAID_MARK_STAR,
|
|
|
|
["Jasna"] = RAID_MARK_CONDOM,
|
|
|
|
["Masimi"] = RAID_MARK_CONDOM,
|
|
|
|
["Alconex"] = RAID_MARK_TRIANGLE,
|
|
|
|
["Ytraqpolbeci"] = RAID_MARK_DIAMOND,
|
|
|
|
["Icebloqparty"] = RAID_MARK_DIAMOND,
|
|
|
|
["Zars"] = RAID_MARK_MOON,
|
|
|
|
["Miemiemiee"] = RAID_MARK_SQUARE,
|
|
|
|
["Amandela"] = RAID_MARK_CROSS,
|
|
|
|
["Chugian"] = RAID_MARK_MOON,
|
|
|
|
["Mev"] = RAID_MARK_MOON,
|
|
|
|
["Naiguh"] = RAID_MARK_MOON,
|
|
|
|
["Zalaras"] = RAID_MARK_TRIANGLE,
|
|
|
|
["Leiana"] = RAID_MARK_TRIANGLE,
|
|
|
|
["Seyjóu"] = RAID_MARK_SQUARE,
|
2017-11-22 21:31:32 +01:00
|
|
|
["Morcsi"] = RAID_MARK_SQUARE,
|
2017-11-17 17:04:37 +01:00
|
|
|
["Ravenson"] = RAID_MARK_DIAMOND,
|
|
|
|
["Gurtogg"] = RAID_MARK_CONDOM
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, v in pairs(aMarks) do
|
|
|
|
AutoQueueBG:MarkPlayer(k, v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:IsMarkSet(mark)
|
|
|
|
for i = 1, 40 do -- For each raid member
|
|
|
|
local unit = "raid" .. i
|
|
|
|
if UnitExists(unit) then
|
|
|
|
if GetRaidTargetIndex(unit) == mark then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:MarkPlayer(name, mark)
|
|
|
|
if UnitExists(name) and not AutoQueueBG:IsMarkSet(mark) then
|
|
|
|
SetRaidTarget(name, mark)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:GetQueueMemberCount()
|
|
|
|
return (GetNumPartyMembers() + 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:LeaveBG()
|
|
|
|
hasJoined = false
|
|
|
|
messageSent = 0
|
|
|
|
|
|
|
|
if AutoQueueBG:IsInBattleground() then
|
|
|
|
LeaveBattlefield()
|
|
|
|
else
|
|
|
|
AcceptBattlefieldPort(RANDOM_BG_INDEX, nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:QueueBG()
|
|
|
|
if (IsPartyLeader() == nil or IsPartyLeader() == 1) then
|
|
|
|
RequestBattlegroundInstanceInfo(RANDOM_BG_INDEX)
|
|
|
|
QueuedMemberCount = AutoQueueBG:GetQueueMemberCount()
|
|
|
|
local joinAsGroup = (QueuedMemberCount == 1 and 0 or 1)
|
|
|
|
hasJoined = true
|
|
|
|
JoinBattlefield(RANDOM_BG_INDEX, joinAsGroup)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:OnCommand(input)
|
|
|
|
local arg1, arg2 = AutoQueueBG:GetArgs(input, 2)
|
|
|
|
ChatType = id
|
|
|
|
if arg1 == nil then
|
2017-11-22 21:31:32 +01:00
|
|
|
print("[AutoQueueBG] Usage: /autoqueue [start|stop|status|autobuy]")
|
2017-11-17 17:04:37 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if string.lower(arg1) == "start" then
|
2017-11-22 21:31:32 +01:00
|
|
|
if AQ_Enabled then
|
2017-11-17 17:04:37 +01:00
|
|
|
print("AutoQueueBG ist bereits aktiv.")
|
|
|
|
else
|
2017-11-22 21:31:32 +01:00
|
|
|
AQ_Enabled = true
|
2017-11-17 17:04:37 +01:00
|
|
|
Tick = 0
|
|
|
|
print("AutoQueueBG aktiviert.")
|
|
|
|
end
|
|
|
|
elseif string.lower(arg1) == "stop" then
|
2017-11-22 21:31:32 +01:00
|
|
|
if not AQ_Enabled then
|
2017-11-17 17:04:37 +01:00
|
|
|
print("AutoQueueBG ist nicht aktiv.")
|
|
|
|
else
|
2017-11-22 21:31:32 +01:00
|
|
|
AQ_Enabled = false
|
|
|
|
-- Frame:SetScript("OnUpdate", nil)
|
2017-11-17 17:04:37 +01:00
|
|
|
print("AutoQueueBG deaktiviert.")
|
|
|
|
end
|
|
|
|
elseif string.lower(arg1) == "status" then
|
2017-11-22 21:31:32 +01:00
|
|
|
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"))
|
2017-11-17 17:04:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:OnInitialize()
|
2017-11-22 21:31:32 +01:00
|
|
|
AQ_Enabled = false
|
|
|
|
AB_Enabled = true
|
2017-11-17 17:04:37 +01:00
|
|
|
Frame = CreateFrame("frame")
|
2017-11-22 21:31:32 +01:00
|
|
|
Frame:SetScript("OnUpdate", OnUpdate)
|
2017-11-17 17:04:37 +01:00
|
|
|
Tick = 0
|
|
|
|
hasJoined = false
|
|
|
|
messageSent = 0
|
|
|
|
QueuedMemberCount = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
function string.starts(String,Start)
|
|
|
|
return string.sub(String,1,string.len(Start))==Start
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:OnSystemMessage(type, msg)
|
|
|
|
if (string.starts(msg, "Spieler in Warteschlange: ") and QueuedMemberCount > 1) then
|
|
|
|
local queued = string.match(msg, "%d+")
|
|
|
|
SendChatMessage("[AutoQueueBG] Als Gruppe angemeldet. Spieler: " .. queued .. "/20", "PARTY", nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:OnEnable(first)
|
|
|
|
AutoQueueBG:RegisterEvent("CHAT_MSG_SYSTEM","OnSystemMessage")
|
|
|
|
AutoQueueBG:RegisterChatCommand("autoqueue", "OnCommand")
|
|
|
|
AutoQueueBG:RegisterChatCommand("aq", "OnCommand")
|
|
|
|
end
|
|
|
|
|
|
|
|
function AutoQueueBG:OnDisable()
|
|
|
|
AutoQueueBG:UnregisterAllEvents()
|
|
|
|
AutoQueueBG:UnregisterChatCommand("autoqueue")
|
|
|
|
AutoQueueBG:UnregisterChatCommand("aq")
|
|
|
|
end
|