Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to join solo 3v3 rated #17

Merged
merged 12 commits into from
Sep 13, 2024
2 changes: 2 additions & 0 deletions conf/arena_3v3_solo_queue.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#

Solo.3v3.Enable = 1
Solo.3v3.EnableCommand = 1
Solo.3v3.EnableTestingCommand = 1
Helias marked this conversation as resolved.
Show resolved Hide resolved


Solo.3v3.FilterTalents = 0
Expand Down
8 changes: 7 additions & 1 deletion data/sql/db-world/as_2024_03_17_00.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ INSERT INTO `npc_text` (`ID`, `text0_0`) VALUES (@entryNpcText1, @text1);
SET @entryNpcText2 := 1000004;
SET @text2 := ' |TInterface/ICONS/achievement_bg_killXEnemies_generalsroom:25|t$B Solo 3v3 Arena$B$B Melee Caster Healer [|cffff0000off|r]';
DELETE FROM `npc_text` WHERE `ID` = @entryNpcText;
INSERT INTO `npc_text` (`ID`, `text0_0`) VALUES (@entryNpcText2, @text2);
INSERT INTO `npc_text` (`ID`, `text0_0`) VALUES (@entryNpcText2, @text2);

-- Command
DELETE FROM `command` WHERE `name` IN ('qsolo', 'testqsolo');
INSERT INTO `command` (`name`, `security`, `help`) VALUES
('qsolo', 0, ''),
('testqsolo', 4, '');
14 changes: 9 additions & 5 deletions src/solo3v3_sc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ bool NpcSolo3v3::ArenaCheckFullEquipAndTalents(Player* player)
return true;
}

bool NpcSolo3v3::JoinQueueArena(Player* player, Creature* creature, bool isRated)
bool NpcSolo3v3::JoinQueueArena(Player* player, Creature* /*creature*/, bool isRated)
{
if (!player || !creature)
if (!player)
return false;

if (sConfigMgr->GetOption<uint32>("Solo.3v3.MinLevel", 80) > player->GetLevel())
Expand All @@ -259,8 +259,12 @@ bool NpcSolo3v3::JoinQueueArena(Player* player, Creature* creature, bool isRated
uint32 arenaRating = 0;
uint32 matchmakerRating = 0;

// ignore if we already in BG or BG queue
if (player->InBattleground())
// ignore if we already in BG, Arena or Arena queue
if (player->InBattleground() || player->InArena() || player->InBattlegroundQueueForBattlegroundQueueType((BattlegroundQueueTypeId)BATTLEGROUND_QUEUE_2v2) ||
player->InBattlegroundQueueForBattlegroundQueueType((BattlegroundQueueTypeId)BATTLEGROUND_QUEUE_3v3) ||
player->InBattlegroundQueueForBattlegroundQueueType((BattlegroundQueueTypeId)BATTLEGROUND_QUEUE_5v5) ||
player->InBattlegroundQueueForBattlegroundQueueType((BattlegroundQueueTypeId)BATTLEGROUND_QUEUE_3v3_SOLO) ||
player->InBattlegroundQueueForBattlegroundQueueType((BattlegroundQueueTypeId)BATTLEGROUND_QUEUE_1v1))
return false;

//check existance
Expand Down Expand Up @@ -333,7 +337,7 @@ bool NpcSolo3v3::JoinQueueArena(Player* player, Creature* creature, bool isRated

bool NpcSolo3v3::CreateArenateam(Player* player, Creature* creature)
Helias marked this conversation as resolved.
Show resolved Hide resolved
{
if (!player || !creature)
if (!player)
return false;

// Check if player is already in an arena team
Expand Down
154 changes: 148 additions & 6 deletions src/solo3v3_sc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "Battleground.h"
#include "solo3v3.h"


enum Npc3v3Actions {
NPC_3v3_ACTION_CREATE_ARENA_TEAM = 1,
NPC_3v3_ACTION_JOIN_QUEUE_ARENA_RATED = 2,
Expand All @@ -37,7 +36,6 @@ enum Npc3v3Actions {
NPC_3v3_ACTION_SCRIPT_INFO = 8
};


class NpcSolo3v3 : public CreatureScript
{
public:
Expand All @@ -49,13 +47,12 @@ class NpcSolo3v3 : public CreatureScript
void Initialize();
bool OnGossipHello(Player* player, Creature* creature) override;
bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action) override;

private:
bool ArenaCheckFullEquipAndTalents(Player* player);
bool JoinQueueArena(Player* player, Creature* creature, bool isRated);
bool CreateArenateam(Player* player, Creature* creature);
void fetchQueueList();

private:
void fetchQueueList();
int cache3v3Queue[MAX_TALENT_CAT];
uint32 lastFetchQueueList;
};
Expand Down Expand Up @@ -107,7 +104,6 @@ class PlayerScript3v3Arena : public PlayerScript
bool CanBattleFieldPort(Player* player, uint8 arenaType, BattlegroundTypeId BGTypeID, uint8 action) override;
};


class Arena_SC : public ArenaScript
{
public:
Expand Down Expand Up @@ -145,6 +141,151 @@ class Arena_SC : public ArenaScript
}
};

using namespace Acore::ChatCommands;

class CommandJoinSolo : public CommandScript
{
public:
CommandJoinSolo() : CommandScript("CommandJoinSolo") { }

ChatCommandTable GetCommands() const override
{
static ChatCommandTable SoloCommandTable =
{
{ "qsolo", HandleQueueSoloArena, SEC_PLAYER, Console::No },
{ "testqsolo", HandleQueueSoloArenaTesting, SEC_ADMINISTRATOR, Console::No }
};

return SoloCommandTable;
}

static bool HandleQueueSoloArena(ChatHandler* handler, const char* /*args*/)
{
Player* player = handler->GetSession()->GetPlayer();
if (!player)
return false;

if (!sConfigMgr->GetOption<bool>("Solo.3v3.EnableCommand", true))
{
ChatHandler(player->GetSession()).SendSysMessage("Solo 3v3 Arena command is disabled.");
return false;
}

if (!sConfigMgr->GetOption<bool>("Solo.3v3.Enable", true))
{
ChatHandler(player->GetSession()).SendSysMessage("Solo 3v3 Arena is disabled.");
return false;
}

if (player->IsInCombat())
{
ChatHandler(player->GetSession()).SendSysMessage("Can't be in combat.");
return false;
}

NpcSolo3v3 SoloCommand;
if (player->HasAura(26013) && (sConfigMgr->GetOption<bool>("Solo.3v3.CastDeserterOnAfk", true) || sConfigMgr->GetOption<bool>("Solo.3v3.CastDeserterOnLeave", true)))
{
WorldPacket data;
sBattlegroundMgr->BuildGroupJoinedBattlegroundPacket(&data, ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS);
player->GetSession()->SendPacket(&data);
return false;
}

uint32 minLevel = sConfigMgr->GetOption<uint32>("Solo.3v3.MinLevel", 80);
if (player->GetLevel() < minLevel)
{
ChatHandler(player->GetSession()).PSendSysMessage("You need level {}+ to join solo arena.", minLevel);
return false;
}

if (!player->GetArenaTeamId(ARENA_SLOT_SOLO_3v3))
{
// create solo3v3 team if player don't have it
if (!SoloCommand.CreateArenateam(player, nullptr))
return false;
}
else
{
if (!SoloCommand.ArenaCheckFullEquipAndTalents(player))
return false;

if (SoloCommand.JoinQueueArena(player, nullptr, true))
handler->PSendSysMessage("You have joined the solo 3v3 arena queue.");
}

return true;
}

// USED IN TESTING ONLY!!! (time saving when alt tabbing) Will join solo 3v3 on all players!
// also use macros: /run AcceptBattlefieldPort(1,1); to accept queue and /afk to leave arena
static bool HandleQueueSoloArenaTesting(ChatHandler* handler, const char* /*args*/)
{
Player* player = handler->GetSession()->GetPlayer();
if (!player)
return false;

if (!sConfigMgr->GetOption<bool>("Solo.3v3.EnableTestingCommand", true))
{
ChatHandler(player->GetSession()).SendSysMessage("Solo 3v3 Arena testing command is disabled.");
return false;
}

if (!sConfigMgr->GetOption<bool>("Solo.3v3.Enable", true))
{
ChatHandler(player->GetSession()).SendSysMessage("Solo 3v3 Arena is disabled.");
return false;
}

NpcSolo3v3 SoloCommand;
for (auto& pair : ObjectAccessor::GetPlayers())
{
Player* currentPlayer = pair.second;
if (currentPlayer)
{
if (currentPlayer->IsInCombat())
{
handler->PSendSysMessage("Player {} can't be in combat.", currentPlayer->GetName().c_str());
continue;
}

if (currentPlayer->HasAura(26013) && (sConfigMgr->GetOption<bool>("Solo.3v3.CastDeserterOnAfk", true) || sConfigMgr->GetOption<bool>("Solo.3v3.CastDeserterOnLeave", true)))
{
WorldPacket data;
sBattlegroundMgr->BuildGroupJoinedBattlegroundPacket(&data, ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS);
currentPlayer->GetSession()->SendPacket(&data);
continue;
}

uint32 minLevel = sConfigMgr->GetOption<uint32>("Solo.3v3.MinLevel", 80);
if (currentPlayer->GetLevel() < minLevel)
{
handler->PSendSysMessage("Player {} needs level {}+ to join solo arena.", player->GetName().c_str(), minLevel);
continue;
}

if (!currentPlayer->GetArenaTeamId(ARENA_SLOT_SOLO_3v3)) // ARENA_SLOT_SOLO_3v3 | ARENA_TEAM_SOLO_3v3
{
if (!SoloCommand.CreateArenateam(currentPlayer, nullptr))
continue;
}
else
{
if (!SoloCommand.ArenaCheckFullEquipAndTalents(currentPlayer))
continue;

if (SoloCommand.JoinQueueArena(currentPlayer, nullptr, true))
handler->PSendSysMessage("Player {} has joined the solo 3v3 arena queue.", currentPlayer->GetName().c_str());
else
handler->PSendSysMessage("Failed to join queue for player {}.", currentPlayer->GetName().c_str());
}
}
}

return true;
}
};

void AddSC_Solo_3v3_Arena()
{
if (!ArenaTeam::ArenaSlotByType.count(ARENA_TEAM_SOLO_3v3))
Expand All @@ -168,4 +309,5 @@ void AddSC_Solo_3v3_Arena()
new ConfigLoader3v3Arena();
new PlayerScript3v3Arena();
new Arena_SC();
new CommandJoinSolo();
}
Loading