Skip to content

Commit

Permalink
command
Browse files Browse the repository at this point in the history
  • Loading branch information
laasker committed Sep 13, 2024
1 parent 7ea2c18 commit f7c275a
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 8 deletions.
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


Solo.3v3.FilterTalents = 0
Expand Down
6 changes: 5 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,8 @@ 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
INSERT INTO `command` (`name`, `security`, `help`) VALUES ('qsolo', 0, '');
INSERT INTO `command` (`name`, `security`, `help`) VALUES ('testqsolo', 4, '');
11 changes: 7 additions & 4 deletions src/solo3v3_sc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ bool NpcSolo3v3::ArenaCheckFullEquipAndTalents(Player* player)

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

if (sConfigMgr->GetOption<uint32>("Solo.3v3.MinLevel", 80) > player->GetLevel())
Expand All @@ -259,8 +259,11 @@ 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))
return false;

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

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

// Check if player is already in an arena team
Expand Down
154 changes: 151 additions & 3 deletions src/solo3v3_sc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,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 @@ -145,6 +144,154 @@ 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 +315,5 @@ void AddSC_Solo_3v3_Arena()
new ConfigLoader3v3Arena();
new PlayerScript3v3Arena();
new Arena_SC();
new CommandJoinSolo();
}

0 comments on commit f7c275a

Please sign in to comment.