Skip to content

Commit

Permalink
feat: add command .qsolo unrated/rated
Browse files Browse the repository at this point in the history
  • Loading branch information
Helias committed Sep 21, 2024
1 parent 05a9667 commit f687038
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 175 deletions.
6 changes: 4 additions & 2 deletions data/sql/db-world/as_2024_03_17_00.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ DELETE FROM `npc_text` WHERE `ID` = @entryNpcText2;
INSERT INTO `npc_text` (`ID`, `text0_0`) VALUES (@entryNpcText2, @text2);

-- Command
DELETE FROM `command` WHERE `name` IN ('qsolo', 'testqsolo');
DELETE FROM `command` WHERE `name` IN ('qsolo', 'qsolo rated', 'qsolo unrated', 'testqsolo');
INSERT INTO `command` (`name`, `security`, `help`) VALUES
('qsolo', 0, '.qsolo -> join arena 3v3soloQ'),
('qsolo', 0, '.qsolo rated/unrated\nJoin arena 3v3soloQ rated or unrated'),
('qsolo rated', 0, 'Syntax .qsolo rated\nJoin arena 3v3soloQ rated'),
('qsolo unrated', 0, 'Syntax .qsolo unrated\nJoin arena 3v3soloQ unrated'),
('testqsolo', 4, '.testqsolo -> join arena 3v3soloQ for testing');
178 changes: 178 additions & 0 deletions src/cs_solo3v3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
#include "Chat.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Tokenize.h"
#include "DatabaseEnv.h"
#include "Config.h"
#include "BattlegroundMgr.h"
#include "CommandScript.h"
#include "solo3v3_sc.h"

using namespace Acore::ChatCommands;

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

ChatCommandTable GetCommands() const override
{
static ChatCommandTable command3v3Table =
{
{ "rated", HandleQueueArena3v3Rated, SEC_PLAYER, Console::No },
{ "unrated", HandleQueueArena3v3UnRated, SEC_PLAYER, Console::No },
};

static ChatCommandTable SoloCommandTable =
{
{ "qsolo", command3v3Table },
{ "testqsolo", HandleQueueSoloArenaTesting, SEC_ADMINISTRATOR, Console::No }
};

return SoloCommandTable;
}

static bool HandleQueueArena3v3Rated(ChatHandler* handler, const char* args)
{
return HandleQueueSoloArena(handler, args, true);
}

static bool HandleQueueArena3v3UnRated(ChatHandler* handler, const char* args)
{
return HandleQueueSoloArena(handler, args, false);
}

static bool HandleQueueSoloArena(ChatHandler* handler, const char* /*args*/, bool isRated)
{
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) && isRated)
{
// create solo3v3 team if player doesn't have it
if (!SoloCommand.CreateArenateam(player, nullptr))
return false;

handler->PSendSysMessage("Join again arena 3v3soloQ rated!");
}
else
{
if (!SoloCommand.ArenaCheckFullEquipAndTalents(player))
return false;

if (SoloCommand.JoinQueueArena(player, nullptr, isRated))
handler->PSendSysMessage("You have joined the solo 3v3 arena queue {}.", isRated ? "rated" : "unrated");
}

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_commandscript()
{
new CommandJoinSolo();
}
3 changes: 3 additions & 0 deletions src/solo3v3_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
*/

void AddSC_Solo_3v3_Arena();
void AddSC_Solo_3v3_commandscript();


void Addmod_arena_3v3_solo_queueScripts()
{
AddSC_Solo_3v3_Arena();
AddSC_Solo_3v3_commandscript();
}
25 changes: 25 additions & 0 deletions src/solo3v3_sc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,3 +747,28 @@ bool PlayerScript3v3Arena::CanBattleFieldPort(Player* player, uint8 arenaType, B
// return true;
// }
// }

void AddSC_Solo_3v3_Arena()
{
if (!ArenaTeam::ArenaSlotByType.count(ARENA_TEAM_SOLO_3v3))
ArenaTeam::ArenaSlotByType[ARENA_TEAM_SOLO_3v3] = ARENA_SLOT_SOLO_3v3;

if (!ArenaTeam::ArenaReqPlayersForType.count(ARENA_TYPE_3v3_SOLO))
ArenaTeam::ArenaReqPlayersForType[ARENA_TYPE_3v3_SOLO] = 6;

if (!BattlegroundMgr::queueToBg.count(BATTLEGROUND_QUEUE_3v3_SOLO))
BattlegroundMgr::queueToBg[BATTLEGROUND_QUEUE_3v3_SOLO] = BATTLEGROUND_AA;

if (!BattlegroundMgr::ArenaTypeToQueue.count(ARENA_TYPE_3v3_SOLO))
BattlegroundMgr::ArenaTypeToQueue[ARENA_TYPE_3v3_SOLO] = (BattlegroundQueueTypeId)BATTLEGROUND_QUEUE_3v3_SOLO;

if (!BattlegroundMgr::QueueToArenaType.count(BATTLEGROUND_QUEUE_3v3_SOLO))
BattlegroundMgr::QueueToArenaType[BATTLEGROUND_QUEUE_3v3_SOLO] = (ArenaType)ARENA_TYPE_3v3_SOLO;

new NpcSolo3v3();
new Solo3v3BG();
new Team3v3arena();
new ConfigLoader3v3Arena();
new PlayerScript3v3Arena();
new Arena_SC();
}
Loading

0 comments on commit f687038

Please sign in to comment.