Skip to content

Commit

Permalink
feat: add command .q1v1 rated/unrated
Browse files Browse the repository at this point in the history
  • Loading branch information
Helias committed Sep 13, 2024
1 parent 273dd1f commit 8fe3eff
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
9 changes: 9 additions & 0 deletions conf/1v1arena.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,14 @@ Arena1v1.ForbiddenTalentsIDs = "0"

Arena1v1.ArenaSlotID = 3

#
# Arena1v1.EnableCommand
# Description: If enabled, it allows to run .q1v1 rated/unrated
# Default: true
# Value: true
# false

Arena1v1.EnableCommand = 1

#
###################################################################################################
9 changes: 8 additions & 1 deletion data/sql/db-world/base/1v1_Battlemaster.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entr
(999991, 0, 0, 0, 0, 0, 'Arena Battlemaster 1v1', '', '', 8218, 70, 70, 2, 35, 1048577, 1.1, 1.14286, 1, 0, 0, 1, 2000, 2000, 1, 768, 2048, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 'npc_1v1arena', 12340);

DELETE FROM `creature_template_model` WHERE `CreatureID` In (999991);
INSERT INTO `creature_template_model` (`CreatureID`, `Idx`, `CreatureDisplayID`, `DisplayScale`, `Probability`, `VerifiedBuild`) VALUES
INSERT INTO `creature_template_model` (`CreatureID`, `Idx`, `CreatureDisplayID`, `DisplayScale`, `Probability`, `VerifiedBuild`) VALUES
(999991, 0, 7110, 1, 1, 23766);

DELETE FROM `battlemaster_entry` WHERE `entry`=999991;
INSERT INTO `battlemaster_entry` (`entry`, `bg_template`) VALUES (999991, 6);

-- Command
DELETE FROM `command` WHERE `name` IN ('q1v1', 'q1v1 rated', 'q1v1 unrated');
INSERT INTO `command` (`name`, `security`, `help`) VALUES
('q1v1', 0, 'Syntax .q1v1 rated/unrate\nJoin arena 1v1 rated or unrated'),
('q1v1 rated', 0, 'Syntax .q1v1 rated\nJoin arena 1v1 rated'),
('q1v1 unrated', 0, 'Syntax .q1v1 unrated\nJoin arena 1v1 unrated');
4 changes: 3 additions & 1 deletion src/1v1_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
void AddSC_npc_1v1arena();
void AddSC_arena1v1_commandscript();

void Addmod_1v1_arenaScripts()
void Addmod_1v1_arenaScripts()
{
AddSC_npc_1v1arena();
AddSC_arena1v1_commandscript();
}
98 changes: 98 additions & 0 deletions src/cs_1v1arena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#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 "npc_1v1arena.h"

using namespace Acore::ChatCommands;

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

ChatCommandTable GetCommands() const override
{
static ChatCommandTable command1v1Table =
{
{ "rated", HandleQueueArena1v1Rated, SEC_PLAYER, Console::No },
{ "unrated", HandleQueueArena1v1UnRated, SEC_PLAYER, Console::No },
};

static ChatCommandTable commandTable =
{
{ "q1v1", command1v1Table },
};

return commandTable;
}

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

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

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

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

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

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

npc_1v1arena Command1v1;

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

if (!player->GetArenaTeamId(sConfigMgr->GetOption<uint32>("Arena1v1.ArenaSlotID", 3)))
{
// create 1v1 team if player doesn't have it
if (!Command1v1.CreateArenateam(player, nullptr))
return false;

handler->PSendSysMessage("Join again arena 1v1 rated!");
}
else
{
if (Command1v1.JoinQueueArena(player, nullptr, isRated))
handler->PSendSysMessage("You have joined the solo 1v1 arena queue {}.", isRated ? "Rated" : "UnRated");
}

return true;
}
};

void AddSC_arena1v1_commandscript()
{
new CommandJoin1v1();
}

0 comments on commit 8fe3eff

Please sign in to comment.