218 lines
6.0 KiB
Lua
218 lines
6.0 KiB
Lua
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
|
|
|
|
local QueuedMemberCount = QueuedMemberCount
|
|
local Enabled = Enabled
|
|
local Frame = Frame
|
|
local Tick = Tick
|
|
local hasJoined = hasJoined
|
|
local messageSent = messageSent
|
|
|
|
local function OnUpdate(self, elapsed)
|
|
local doUpdate = (floor(Tick + elapsed) > floor(Tick))
|
|
Tick = Tick + elapsed
|
|
if doUpdate and Enabled then
|
|
AutoQueueBG:OnUpdate()
|
|
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
|
|
|
|
function AutoQueueBG:OnUpdate()
|
|
if (not Enabled) then
|
|
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
|
|
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
|
|
|
|
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,
|
|
["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
|
|
print("[AutoQueueBG] Usage: /autoqueue [start|stop|status]")
|
|
return
|
|
end
|
|
|
|
if string.lower(arg1) == "start" then
|
|
if Enabled then
|
|
print("AutoQueueBG ist bereits aktiv.")
|
|
else
|
|
Enabled = true
|
|
Tick = 0
|
|
Frame:SetScript("OnUpdate", OnUpdate)
|
|
print("AutoQueueBG aktiviert.")
|
|
end
|
|
elseif string.lower(arg1) == "stop" then
|
|
if not Enabled then
|
|
print("AutoQueueBG ist nicht aktiv.")
|
|
else
|
|
Enabled = false
|
|
Frame:SetScript("OnUpdate", nil)
|
|
print("AutoQueueBG deaktiviert.")
|
|
end
|
|
elseif string.lower(arg1) == "status" then
|
|
print("[AutoQueueBG] Status: " .. (Enabled and "Aktiviert" or "Deaktiviert"))
|
|
end
|
|
end
|
|
|
|
function AutoQueueBG:OnInitialize()
|
|
Enabled = false
|
|
Frame = CreateFrame("frame")
|
|
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
|