Files
Arena-Fight-Script/AIO/FighterGuildServer.lua
2025-12-13 17:31:34 -05:00

306 lines
15 KiB
Lua

local AIO = AIO or require("AIO")
local FighterGuildHandlers = AIO.AddHandlers("FighterGuildServer", {})
-- Define bosses directly (with difficulty levels, points, and spawn info)
local bosses = {
-- Custom Bosses
{id = 700800, name = "Arian - The Demon", level = 80, points = 25, difficulty = "Easy"},
{id = 700801, name = "Lord Cyran", level = 80, points = 75, difficulty = "Challenging"},
{id = 700802, name = "Tiger Boss", level = 80, points = 25, difficulty = "Easy"},
{id = 700803, name = "Spellmaster", level = 80, points = 75, difficulty = "Challenging"},
{id = 700804, name = "Bogdan - The Shadow Lord", level = 80, points = 75, difficulty = "Challenging"},
{id = 700805, name = "Cow Lord", level = 80, points = 25, difficulty = "Easy"},
{id = 700806, name = "Diablo", level = 80, points = 250, difficulty = "Hard"},
{id = 700807, name = "Naroxius Death Guard", level = 80, points = 75, difficulty = "Challenging"},
{id = 700817, name = "Gioran the Corrupted Paladin", level = 80, points = 75, difficulty = "Challenging"},
-- Vanilla Bosses
{id = 700837, name = "Bazzalan", level = 80, points = 25, difficulty = "Easy"},
{id = 700838, name = "Mutanus the Devourer", level = 80, points = 25, difficulty = "Easy"},
{id = 700839, name = "Princess Theradras", level = 80, points = 25, difficulty = "Easy"},
{id = 700840, name = "Kel'Thuzad", level = 83, points = 250, difficulty = "Hard"},
{id = 700841, name = "Patchwerk", level = 83, points = 250, difficulty = "Hard"},
{id = 700842, name = "Viscidus", level = 80, points = 75, difficulty = "Challenging"},
{id = 700843, name = "Gothik the Harvester", level = 83, points = 75, difficulty = "Challenging"},
{id = 700844, name = "Shazzrah", level = 80, points = 250, difficulty = "Hard"},
{id = 700845, name = "Baron Geddon", level = 80, points = 75, difficulty = "Challenging"},
{id = 700846, name = "Broodlord Lashlayer", level = 80, points = 75, difficulty = "Challenging"},
{id = 700847, name = "Majordomo Executus", level = 80, points = 75, difficulty = "Challenging"},
{id = 700848, name = "King Gordok", level = 80, points = 250, difficulty = "Challenging"},
-- BC Bosses
{id = 700849, name = "Leotheras the Blind", level = 80, points = 250, difficulty = "Hard"},
{id = 700850, name = "Selin Fireheart", level = 80, points = 25, difficulty = "Easy"},
{id = 700851, name = "Omor the Unscarred", level = 80, points = 25, difficulty = "Easy"},
{id = 700852, name = "Hydromancer Thespia", level = 80, points = 25, difficulty = "Easy"},
{id = 700853, name = "Warbringer O'mrogg", level = 80, points = 25, difficulty = "Easy"},
{id = 700854, name = "Grand Warlock Nethekurse", level = 80, points = 75, difficulty = "Challenging"},
{id = 700855, name = "Warp Splinter", level = 80, points = 75, difficulty = "Challenging"},
{id = 700856, name = "Hex Lord Malacrass", level = 80, points = 75, difficulty = "Challenging"},
{id = 700857, name = "High Astromancer Solarian", level = 80, points = 75, difficulty = "Challenging"},
{id = 700858, name = "Teron Gorefiend", level = 80, points = 250, difficulty = "Hard"},
{id = 700859, name = "Kaz'rogal", level = 80, points = 250, difficulty = "Hard"},
{id = 700860, name = "Illidan Stormrage", level = 82, points = 250, difficulty = "Hard"},
-- WOTLK Bosses
{id = 700861, name = "Varos Cloudstrider", level = 81, points = 75, difficulty = "Challenging"},
{id = 700862, name = "Bronjahm", level = 82, points = 75, difficulty = "Challenging"},
{id = 700863, name = "Elder Nadox", level = 80, points = 25, difficulty = "Easy"},
{id = 700864, name = "Trollgore", level = 82, points = 75, difficulty = "Challenging"},
{id = 700865, name = "Jedoga Shadowseeker", level = 82, points = 75, difficulty = "Challenging"},
{id = 700866, name = "Meathook", level = 82, points = 75, difficulty = "Challenging"},
{id = 700867, name = "Hodir", level = 83, points = 250, difficulty = "Hard"},
{id = 700868, name = "Freya", level = 83, points = 250, difficulty = "Hard"},
{id = 700869, name = "Slad'ran", level = 80, points = 25, difficulty = "Easy"},
{id = 700870, name = "Moorabi", level = 80, points = 25, difficulty = "Easy"},
{id = 700871, name = "Toravon the Ice Watcher", level = 83, points = 250, difficulty = "Hard"},
{id = 700809, name = "The Lich King", level = 83, points = 250, difficulty = "Hard"},
-- CATA Bosses
{id = 700808, name = "Al'Akir", level = 84, points = 250, difficulty = "Hard"},
{id = 700810, name = "Cho'gall", level = 80, points = 250, difficulty = "Hard"},
{id = 700811, name = "Forgemaster Throngus", level = 82, points = 25, difficulty = "Easy"},
{id = 700812, name = "Ozruk", level = 80, points = 75, difficulty = "Challenging"},
{id = 700813, name = "Argaloth", level = 80, points = 250, difficulty = "Hard"},
{id = 700814, name = "Setesh", level = 80, points = 25, difficulty = "Easy"},
{id = 700815, name = "Therazane", level = 80, points = 75, difficulty = "Challenging"},
--MOP BOSSES
{id = 700816, name = "Elegon", level = 80, points = 250, difficulty = "Hard"},
{id = 700818, name = "Amber-Shaper Un'Sok", level = 83, points = 250, difficulty = "Hard"},
{id = 700819, name = "Imperial Vizier Zor'lok", level = 82, points = 250, difficulty = "Hard"},
{id = 700820, name = "Garrosh Hellscream", level = 85, points = 250, difficulty = "Hard"},
{id = 700821, name = "Thok the Bloodthirsty", level = 83, points = 75, difficulty = "Challenging"},
{id = 700822, name = "General Pa'valak", level = 82, points = 75, difficulty = "Easy"},
{id = 700823, name = "Gekkan", level = 84, points = 75, difficulty = "Easy"},
-- WoD Bosses
{id = 700824, name = "Blackhand", level = 85, points = 75, difficulty = "Challenging"},
{id = 700825, name = "Kargath Bladefist", level = 85, points = 250, difficulty = "Hard"},
{id = 700826, name = "High Sage Viryx", level = 83, points = 75, difficulty = "Easy"},
{id = 700827, name = "The Butcher", level = 85, points = 75, difficulty = "Challenging"},
{id = 700828, name = "Brackenspore", level = 83, points = 250, difficulty = "Hard"},
{id = 700829, name = "Mannoroth", level = 85, points = 250, difficulty = "Hard"},
{id = 700830, name = "Lady Temptessa", level = 85, points = 75, difficulty = "Easy"},
-- Legion Bosses
{id = 700831, name = "Kil'Jaeden", level = 85, points = 250, difficulty = "Hard"},
{id = 700832, name = "Gul'dan", level = 85, points = 250, difficulty = "Hard"},
{id = 700833, name = "Tichondrius", level = 85, points = 250, difficulty = "Hard"},
{id = 700834, name = "Xavius", level = 85, points = 250, difficulty = "Hard"},
{id = 700835, name = "Varimathras", level = 85, points = 75, difficulty = "Challenging"},
{id = 700836, name = "Imonar the Soulhunter", level = 85, points = 75, difficulty = "Challenging"},
}
-- Arena coordinates (using YOUR new location)
local mapId = 1
local playerSpawnX, playerSpawnY, playerSpawnZ, playerOrientation = 2172.05, -4789.88, 55, 1.32696
local bossSpawnX, bossSpawnY, bossSpawnZ, bossOrientation = 2176, -4766, 55, 1.3
local rewardX, rewardY, rewardZ, rewardOrientation = 2204.453125, -4794.402344, 64.998360, 1.033404
-- BRAWL SYSTEM INTEGRATION: Queue and timer variables
local queue = {} -- Queue of waiting players
local maxTime = 120000 -- 2 minutes in milliseconds
local timerAura = 707474 -- Timer visual aura
local currentFighter = nil -- Currently fighting player
local currentBoss = nil -- Currently spawned boss
local PlayerDeathEvent = nil -- Event ID for tracking
-- Function to get the next player in queue
local function StartNextInQueue()
if #queue > 0 then
local nextInQueue = table.remove(queue, 1)
FighterGuildHandlers.StartFight(nextInQueue.player, nextInQueue.bossId)
-- Update queue positions for remaining players
for i, entry in ipairs(queue) do
if entry.player and entry.player:IsInWorld() then
entry.player:SendBroadcastMessage("|TInterface/ICONS/exclam:35:35|t Your place in line is: " .. i)
entry.player:SendAreaTriggerMessage("|TInterface/ICONS/exclam:35:35|t Your place in line is: " .. i)
end
end
else
-- Arena is now free
currentFighter = nil
currentBoss = nil
end
end
-- BRAWL SYSTEM: Player took too long (timeout)
local function TookTooLong(eventId, delay, calls, player)
if player and player:IsInWorld() then
player:SendBroadcastMessage("Time's up! You took too long to defeat the boss.")
player:Teleport(mapId, rewardX, rewardY, rewardZ, rewardOrientation)
player:RemoveAura(timerAura)
-- Clean up boss if still alive
if currentBoss and currentBoss:IsInWorld() then
currentBoss:DespawnOrUnsummon(1000)
end
-- Move to next player
player:RegisterEvent(StartNextInQueue, 10000, 1)
end
end
-- Modified StartFight function with queue and timer system
function FighterGuildHandlers.StartFight(player, bossId)
-- Check if arena is occupied
if currentFighter ~= nil and currentFighter:IsInWorld() then
-- Arena is occupied, add player to queue
table.insert(queue, {player = player, bossId = bossId})
local position = #queue
player:SendBroadcastMessage("Arena is currently occupied. You are #" .. position .. " in the queue.")
player:SendAreaTriggerMessage("|TInterface/ICONS/exclam:35:35|t Queue Position: " .. position)
return
end
-- Arena is free, start fight immediately
currentFighter = player
player:Teleport(mapId, playerSpawnX, playerSpawnY, playerSpawnZ, playerOrientation)
-- Apply timer aura
player:AddAura(timerAura, player)
player:SendBroadcastMessage("|TInterface/ICONS/Exc:35:35|t You're up! Fight begins now!|TInterface/ICONS/Exc:35:35|t")
player:SendAreaTriggerMessage("|TInterface/ICONS/Exc:35:35|t You're up!|TInterface/ICONS/Exc:35:35|t")
local bossInfo
for _, boss in ipairs(bosses) do
if boss.id == bossId then
bossInfo = boss
break
end
end
-- Spawn the boss at the designated location
if bossInfo then
currentBoss = player:SpawnCreature(bossInfo.id, bossSpawnX, bossSpawnY, bossSpawnZ, bossOrientation, 2, maxTime)
if currentBoss then
currentBoss:SetLevel(bossInfo.level or 80)
player:SendBroadcastMessage("Boss spawned: " .. bossInfo.name .. " - You have 2 minutes!")
-- Register timeout event (2 minutes)
PlayerDeathEvent = player:RegisterEvent(TookTooLong, maxTime, 1)
else
player:SendBroadcastMessage("Failed to spawn boss. NPC ID: " .. bossInfo.id)
currentFighter = nil
StartNextInQueue()
end
else
player:SendBroadcastMessage("Invalid boss selected.")
currentFighter = nil
StartNextInQueue()
end
end
-- Function to handle PLAYER death (player lost)
local function OnPlayerDeath(event, creature, victim)
if victim and victim:IsPlayer() and victim == currentFighter then
-- Remove timeout event
if PlayerDeathEvent then
victim:RemoveEventById(PlayerDeathEvent)
PlayerDeathEvent = nil
end
victim:RemoveAura(timerAura)
victim:SendBroadcastMessage("You were defeated! Better luck next time.")
-- Despawn boss
if currentBoss and currentBoss:IsInWorld() then
currentBoss:DespawnOrUnsummon(3000)
end
-- Teleport to reward area (no rewards though)
victim:Teleport(mapId, rewardX, rewardY, rewardZ, rewardOrientation)
-- Move to next player after delay
victim:RegisterEvent(StartNextInQueue, 10000, 1)
end
end
-- Function to handle BOSS defeat and reward arena points
local function OnBossDefeated(event, creature, killer)
if killer and killer:IsPlayer() and killer == currentFighter then
local bossName = creature:GetName()
-- Find the boss info by its ID
local bossInfo
for _, boss in ipairs(bosses) do
if boss.id == creature:GetEntry() then
bossInfo = boss
break
end
end
-- Remove timeout event
if PlayerDeathEvent then
killer:RemoveEventById(PlayerDeathEvent)
PlayerDeathEvent = nil
end
killer:RemoveAura(timerAura)
-- Teleport the player back to the reward location
if bossInfo then
killer:Teleport(mapId, rewardX, rewardY, rewardZ, rewardOrientation)
-- Announce the winner
creature:SendUnitYell("And our winner is " .. killer:GetName() .. "! They have beaten " .. bossName .. ". Look at all that carnage!", 0)
-- Award arena points
local points = bossInfo.points or 0
killer:ModifyArenaPoints(points)
killer:SendBroadcastMessage("You earned " .. points .. " Arena Points for defeating " .. bossName .. "!")
else
killer:SendBroadcastMessage("Could not find boss information after defeat.")
end
-- Move to next player after delay
killer:RegisterEvent(StartNextInQueue, 15000, 1)
end
end
-- Function to handle player logout/disconnect during fight
local function OnPlayerLogout(event, player)
if player == currentFighter then
if PlayerDeathEvent then
player:RemoveEventById(PlayerDeathEvent)
PlayerDeathEvent = nil
end
-- Clean up boss
if currentBoss and currentBoss:IsInWorld() then
currentBoss:DespawnOrUnsummon(1000)
end
-- Update character position in database to prevent getting stuck
local guid = tostring(player:GetGUID())
CharDBQuery("UPDATE `characters` SET `position_x` = (" .. rewardX .. ") WHERE `guid` = " .. guid .. ";")
CharDBQuery("UPDATE `characters` SET `position_y` = (" .. rewardY .. ") WHERE `guid` = " .. guid .. ";")
CharDBQuery("UPDATE `characters` SET `position_z` = (" .. rewardZ .. ") WHERE `guid` = " .. guid .. ";")
CharDBQuery("UPDATE `characters` SET `map` = (" .. mapId .. ") WHERE `guid` = " .. guid .. ";")
-- Start next player
CreateLuaEvent(StartNextInQueue, 5000, 1)
end
end
-- Register death events for all bosses
for _, boss in ipairs(bosses) do
RegisterCreatureEvent(boss.id, 4, OnBossDefeated) -- Boss death
RegisterCreatureEvent(boss.id, 3, OnPlayerDeath) -- Player death by boss
end
-- Register player logout event
RegisterPlayerEvent(4, OnPlayerLogout)
-- NPC Interaction Logic: Show the AIO Boss Selection Frame
local function ArenaMaster_OnGossipHello(event, player, creature)
AIO.Handle(player, "FighterGuildClient", "ShowBossSelectionFrame")
player:GossipComplete()
end
-- Register the NPC gossip event (NPC ID: 18268)
RegisterCreatureGossipEvent(18268, 1, ArenaMaster_OnGossipHello)