From 4d1af075cb6feab20d54f4443b5c8fe4f5998b64 Mon Sep 17 00:00:00 2001 From: Walter Pagani Date: Wed, 19 Jul 2023 00:36:17 -0300 Subject: [PATCH] feat. Misc fixs (#47) * feat. Misc fixs * fix build --- .git_commit_template | 49 ------ .gitattributes | 10 +- .github/README.md | 13 +- conf/1v1arena.conf.dist | 14 +- data/sql/db-world/base/1v1_Battlemaster.sql | 3 +- data/sql/delete/1v1_delete.sql | 2 + setup_git_commit_template.sh | 4 - src/npc_arena1v1.cpp | 174 +++++++++++--------- 8 files changed, 123 insertions(+), 146 deletions(-) delete mode 100644 .git_commit_template create mode 100644 data/sql/delete/1v1_delete.sql delete mode 100644 setup_git_commit_template.sh diff --git a/.git_commit_template b/.git_commit_template deleted file mode 100644 index 708b551..0000000 --- a/.git_commit_template +++ /dev/null @@ -1,49 +0,0 @@ -### TITLE -## Type(Scope/Subscope): Commit ultra short explanation -## |---- Write below the examples with a maximum of 50 characters ----| -## Example 1: fix(DB/SAI): Missing spell to NPC Hogger -## Example 2: fix(CORE/Raid): Phase 2 of Ragnaros -## Example 3: feat(CORE/Commands): New GM command to do something - - -### DESCRIPTION -## Explain why this change is being made, what does it fix etc... -## |---- Write below the examples with a maximum of 72 characters per lines ----| -## Example: Hogger (id: 492) was not charging player when being engaged. - - -## Provide links to any issue, commit, pull request or other resource -## Example 1: Closes issue #23 -## Example 2: Ported from other project's commit (link) -## Example 3: References taken from wowpedia / wowhead / wowwiki / https://wowgaming.altervista.org/aowow/ - - - -## ======================================================= -## EXTRA INFOS -## ======================================================= -## "Type" can be: -## feat (new feature) -## fix (bug fix) -## refactor (refactoring production code) -## style (formatting, missing semi colons, etc; no code change) -## docs (changes to documentation) -## test (adding or refactoring tests; no production code change) -## chore (updating bash scripts, git files etc; no production code change) -## -------------------- -## Remember to -## Capitalize the subject line -## Use the imperative mood in the subject line -## Do not end the subject line with a period -## Separate subject from body with a blank line -## Use the body to explain what and why rather than how -## Can use multiple lines with "-" for bullet points in body -## -------------------- -## More info here https://www.conventionalcommits.org/en/v1.0.0-beta.2/ -## ======================================================= -## "Scope" can be: -## CORE (core related, c++) -## DB (database related, sql) -## ======================================================= -## "Subscope" is optional and depends on the nature of the commit. -## ======================================================= diff --git a/.gitattributes b/.gitattributes index 7ef9001..a20e449 100644 --- a/.gitattributes +++ b/.gitattributes @@ -32,16 +32,16 @@ ## For documentation # Documents -*.doc diff=astextplain -*.DOC diff=astextplain +*.doc diff=astextplain +*.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain *.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain ## DOCUMENTATION *.markdown text diff --git a/.github/README.md b/.github/README.md index a86c0b2..d6cd9a4 100644 --- a/.github/README.md +++ b/.github/README.md @@ -11,26 +11,33 @@ ![icon](https://github.com/azerothcore/mod-1v1-arena/assets/2810187/ba375f70-71c7-4c71-aa3f-d3ab6c6fdda7) #### Features: + - 1v1 Rated Arena Games - 1v1 Unrated Arena Games ### This module currently requires: + - AzerothCore v1.0.1+ ### How to install + 1. Simply place the module under the `modules` folder of your AzerothCore source folder. 2. Re-run cmake and launch a clean build of AzerothCore 3. Run the Sql file into your database. 4. Ready. ### Usage -- Enable the module and join 1 v 1 with 2 characters at the BattleMaster Npc. + +- Enable the module and join 1v1 with 2 characters at the BattleMaster Npc. ### Info -This module runs over the 5v5.You can configure it to run over 4v4/3v3..etc As you desire. + +This module runs over the 5v5. You can configure it to run over 4v4/3v3..etc As you desire. + +If you leave the default value at 3, you can have 1v1, 2v2, 3v3 and 5v5. Unless you want to replace it with one of the existing ones. ## Credits -* [XDev](https://github.com/XdevTLKWoW): +* [XDev](https://github.com/XdevTLKWoW) * Adjusted by fr4z3n for azerothcore * Written by Teiby diff --git a/conf/1v1arena.conf.dist b/conf/1v1arena.conf.dist index 2953943..9eb269f 100644 --- a/conf/1v1arena.conf.dist +++ b/conf/1v1arena.conf.dist @@ -64,16 +64,22 @@ Arena1v1.BlockForbiddenTalents = 1 # # Arena1v1.ForbiddenTalentsIDs # Description: List to block specific talents id in arena. See TalentTab.dbc for available talents (you will need an DBC-Editor). The list is coma(,) separated and should have no spaces -# Default: "0" - (no talent blocked) -# Example: "201,202,382,362,282,383,163" +# Default: "0" - (no talent blocked) +# Example: "201,202,382,362,282,383,163" Arena1v1.ForbiddenTalentsIDs = "0" # # Arena1v1.ArenaSlotID -# Description: The slot the 1v1 will be working over. Needs to be bigger or equals then 3 otherwise it will overwrite the 2v2,3v3 or 5v5 data -# Default: 3 +# Description: The slot the 1v1 will be working over. Needs to be bigger or equals then 3 otherwise it will overwrite the 2v2, 3v3 or 5v5 data +# Default: 3 +# Value: +# 2v2 = 0 +# 3v3 = 1 +# 5v5 = 2 +# 1v1 = 3 +# Arena1v1.ArenaSlotID = 3 diff --git a/data/sql/db-world/base/1v1_Battlemaster.sql b/data/sql/db-world/base/1v1_Battlemaster.sql index 6f835cf..0721116 100644 --- a/data/sql/db-world/base/1v1_Battlemaster.sql +++ b/data/sql/db-world/base/1v1_Battlemaster.sql @@ -1,7 +1,6 @@ DELETE FROM `creature_template` WHERE `entry`=999991; INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES -(999991, 0, 0, 0, 0, 0, 23766, 0, 0, 0, 'Arena Battlemaster 1v1', '', '', 8218, 70, 70, 2, 35, 1048577, 1.1, 1.14286, 3, 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); +(999991, 0, 0, 0, 0, 0, 23766, 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 `battlemaster_entry` WHERE `entry`=999991; - INSERT INTO `battlemaster_entry` (`entry`, `bg_template`) VALUES (999991, 6); diff --git a/data/sql/delete/1v1_delete.sql b/data/sql/delete/1v1_delete.sql new file mode 100644 index 0000000..adc7dd0 --- /dev/null +++ b/data/sql/delete/1v1_delete.sql @@ -0,0 +1,2 @@ +DELETE FROM `creature_template` WHERE `entry`=999991; +DELETE FROM `battlemaster_entry` WHERE `entry`=999991; diff --git a/setup_git_commit_template.sh b/setup_git_commit_template.sh deleted file mode 100644 index 7b52062..0000000 --- a/setup_git_commit_template.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -## Set a local git commit template -git config --local commit.template ".git_commit_template.txt" ; diff --git a/src/npc_arena1v1.cpp b/src/npc_arena1v1.cpp index 9c08f54..7b6ec04 100644 --- a/src/npc_arena1v1.cpp +++ b/src/npc_arena1v1.cpp @@ -32,6 +32,32 @@ uint32 ARENA_SLOT_1V1 = 3; //Config std::vector forbiddenTalents; +bool teamExistForPlayerGuid(Player* player) +{ + QueryResult queryPlayerTeam = CharacterDatabase.Query("SELECT * FROM `arena_team` WHERE `captainGuid`={} AND `type`=1", player->GetGUID().GetCounter()); + if (queryPlayerTeam) + return true; + return false; +} + +uint32 playerArenaTeam(Player* player) +{ + QueryResult queryPlayerTeam = CharacterDatabase.Query("SELECT `arenaTeamId` FROM `arena_team` WHERE `captainGuid`={} AND `type`=1", player->GetGUID().GetCounter()); + if (queryPlayerTeam) + return (*queryPlayerTeam)[0].Get(); + return 0; +} + +void deleteTeamArenaForPlayer(Player* player) +{ + QueryResult queryPlayerTeam = CharacterDatabase.Query("SELECT `arenaTeamId` FROM `arena_team` WHERE `captainGuid`={} AND `type`=1", player->GetGUID().GetCounter()); + if (queryPlayerTeam) + { + CharacterDatabase.Execute("DELETE FROM `arena_team` WHERE `captainGuid`={} AND `type`=1", player->GetGUID().GetCounter()); + CharacterDatabase.Execute("DELETE FROM `arena_team_member` WHERE `guid`={}", player->GetGUID().GetCounter()); + } +} + class configloader_1v1arena : public WorldScript { public: @@ -45,8 +71,8 @@ class configloader_1v1arena : public WorldScript for (std::string blockedTalentsStr; std::getline(ss, blockedTalentsStr, ',');) { forbiddenTalents.push_back(stoi(blockedTalentsStr)); - } - + } + ARENA_SLOT_1V1 = sConfigMgr->GetOption("Arena1v1.ArenaSlotID", 3); ArenaTeam::ArenaSlotByType.emplace(ARENA_TEAM_1V1, ARENA_SLOT_1V1); @@ -70,7 +96,6 @@ class playerscript_1v1arena : public PlayerScript ChatHandler(pPlayer->GetSession()).SendSysMessage("This server is running the |cff4CFF00Arena 1v1 |rmodule."); } - void GetCustomGetArenaTeamId(const Player* player, uint8 slot, uint32& id) const override { if (slot == sConfigMgr->GetOption("Arena1v1.ArenaSlotID", 3)) @@ -82,7 +107,6 @@ class playerscript_1v1arena : public PlayerScript } } - void GetCustomArenaPersonalRating(const Player* player, uint8 slot, uint32& rating) const override { if (slot == sConfigMgr->GetOption("Arena1v1.ArenaSlotID", 3)) @@ -94,7 +118,6 @@ class playerscript_1v1arena : public PlayerScript } } - void OnGetMaxPersonalArenaRatingRequirement(const Player* player, uint32 minslot, uint32& maxArenaRating) const override { if (sConfigMgr->GetOption("Arena1v1.VendorRating", false) && minslot < (uint32)sConfigMgr->GetOption("Arena1v1.ArenaSlotID", 3)) @@ -132,7 +155,7 @@ class npc_1v1arena : public CreatureScript AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Queue enter 1v1 Arena (UnRated)", GOSSIP_SENDER_MAIN, 20); } - if (!player->GetArenaTeamId(ArenaTeam::GetSlotByType(ARENA_TEAM_1V1))) + if (!teamExistForPlayerGuid(player)) { AddGossipItemFor(player, GOSSIP_ICON_CHAT, "Create new 1v1 Arena Team", GOSSIP_SENDER_MAIN, 1, "Are you sure?", sConfigMgr->GetOption("Arena1v1.Costs", 400000), false); } @@ -162,88 +185,88 @@ class npc_1v1arena : public CreatureScript switch (action) { - case 1: // Create new Arenateam - { - if (sConfigMgr->GetOption("Arena1v1.MinLevel", 80) <= player->getLevel()) + case 1: // Create new Arenateam { - if (player->GetMoney() >= uint32(sConfigMgr->GetOption("Arena1v1.Costs", 400000)) && CreateArenateam(player, creature)) - player->ModifyMoney(sConfigMgr->GetOption("Arena1v1.Costs", 400000) * -1); + if (sConfigMgr->GetOption("Arena1v1.MinLevel", 80) <= player->getLevel()) + { + if (player->GetMoney() >= uint32(sConfigMgr->GetOption("Arena1v1.Costs", 400000)) && CreateArenateam(player, creature)) + player->ModifyMoney(sConfigMgr->GetOption("Arena1v1.Costs", 400000) * -1); + } + else + { + handler.PSendSysMessage("You have to be level %u + to create a 1v1 arena team.", sConfigMgr->GetOption("Arena1v1.MinLevel", 70)); + return true; + } + CloseGossipMenuFor(player); } - else + break; + + case 2: // Join Queue Arena (rated) { - handler.PSendSysMessage("You have to be level %u + to create a 1v1 arena team.", sConfigMgr->GetOption("Arena1v1.MinLevel", 70)); + if (Arena1v1CheckTalents(player) && !JoinQueueArena(player, creature, true)) + handler.SendSysMessage("Something went wrong when joining the queue."); + CloseGossipMenuFor(player); return true; } - } - break; + break; - case 2: // Join Queue Arena (rated) - { - if (Arena1v1CheckTalents(player) && !JoinQueueArena(player, creature, true)) - handler.SendSysMessage("Something went wrong when joining the queue."); - - CloseGossipMenuFor(player); - return true; - } - break; + case 20: // Join Queue Arena (unrated) + { + if (Arena1v1CheckTalents(player) && !JoinQueueArena(player, creature, false)) + handler.SendSysMessage("Something went wrong when joining the queue."); - case 20: // Join Queue Arena (unrated) - { - if (Arena1v1CheckTalents(player) && !JoinQueueArena(player, creature, false)) - handler.SendSysMessage("Something went wrong when joining the queue."); + CloseGossipMenuFor(player); + return true; + } + break; - CloseGossipMenuFor(player); - return true; - } - break; + case 3: // Leave Queue + { + uint8 arenaType = ARENA_TYPE_1V1; - case 3: // Leave Queue - { - uint8 arenaType = ARENA_TYPE_1V1; + if (!player->InBattlegroundQueueForBattlegroundQueueType(bgQueueTypeId)) + return true; - if (!player->InBattlegroundQueueForBattlegroundQueueType(bgQueueTypeId)) + WorldPacket data; + data << arenaType << (uint8)0x0 << (uint32)BATTLEGROUND_AA << (uint16)0x0 << (uint8)0x0; + player->GetSession()->HandleBattleFieldPortOpcode(data); + CloseGossipMenuFor(player); return true; + } + break; - WorldPacket data; - data << arenaType << (uint8)0x0 << (uint32)BATTLEGROUND_AA << (uint16)0x0 << (uint8)0x0; - player->GetSession()->HandleBattleFieldPortOpcode(data); - CloseGossipMenuFor(player); - return true; - } - break; - - case 4: // get statistics - { - ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(player->GetArenaTeamId(ArenaTeam::GetSlotByType(ARENA_TEAM_1V1))); - if (at) + case 4: // get statistics { - std::stringstream s; - s << "Rating: " << at->GetStats().Rating; - s << "\nRank: " << at->GetStats().Rank; - s << "\nSeason Games: " << at->GetStats().SeasonGames; - s << "\nSeason Wins: " << at->GetStats().SeasonWins; - s << "\nWeek Games: " << at->GetStats().WeekGames; - s << "\nWeek Wins: " << at->GetStats().WeekWins; - - ChatHandler(player->GetSession()).PSendSysMessage(SERVER_MSG_STRING, s.str().c_str()); + ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(playerArenaTeam(player)); + if (at) + { + std::stringstream s; + s << "\nRating: " << at->GetStats().Rating; + s << "\nRank: " << at->GetStats().Rank; + s << "\nSeason Games: " << at->GetStats().SeasonGames; + s << "\nSeason Wins: " << at->GetStats().SeasonWins; + s << "\nWeek Games: " << at->GetStats().WeekGames; + s << "\nWeek Wins: " << at->GetStats().WeekWins; + + ChatHandler(player->GetSession()).PSendSysMessage(SERVER_MSG_STRING, s.str().c_str()); + } + CloseGossipMenuFor(player); } - } - break; + break; - case 5: // Disband arenateam - { - WorldPacket Data; - Data << player->GetArenaTeamId(ArenaTeam::GetSlotByType(ARENA_TEAM_1V1)); - player->GetSession()->HandleArenaTeamLeaveOpcode(Data); - handler.SendSysMessage("Arenateam deleted!"); - CloseGossipMenuFor(player); - return true; - } - break; + case 5: // Disband arenateam + { + deleteTeamArenaForPlayer(player); + WorldPacket Data; + Data << player->GetArenaTeamId(ArenaTeam::GetSlotByType(ARENA_TEAM_1V1)); + player->GetSession()->HandleArenaTeamLeaveOpcode(Data); + handler.SendSysMessage("Arenateam deleted!"); + CloseGossipMenuFor(player); + return true; + } + break; } - - OnGossipHello(player, creature); return true; } @@ -256,7 +279,6 @@ class npc_1v1arena : public CreatureScript if (sConfigMgr->GetOption("Arena1v1.MinLevel", 80) > player->getLevel()) return false; - uint8 arenaslot = ArenaTeam::GetSlotByType(ARENA_TEAM_1V1); uint8 arenatype = ARENA_TYPE_1V1; uint32 arenaRating = 0; uint32 matchmakerRating = 0; @@ -295,7 +317,7 @@ class npc_1v1arena : public CreatureScript if (isRated) { - ateamId = player->GetArenaTeamId(arenaslot); + ateamId = playerArenaTeam(player); ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(ateamId); if (!at) { @@ -424,7 +446,6 @@ class team_1v1arena : public ArenaTeamScript public: team_1v1arena() : ArenaTeamScript("team_1v1arena") {} - void OnGetSlotByType(const uint32 type, uint8& slot) override { if (type == ARENA_TEAM_1V1) @@ -433,7 +454,6 @@ class team_1v1arena : public ArenaTeamScript } } - void OnGetArenaPoints(ArenaTeam* at, float& points) override { if (at->GetType() == ARENA_TEAM_1V1) @@ -442,7 +462,6 @@ class team_1v1arena : public ArenaTeamScript } } - void OnTypeIDToQueueID(const BattlegroundTypeId, const uint8 arenaType, uint32& _bgQueueTypeId) override { if (arenaType == ARENA_TYPE_1V1) @@ -451,7 +470,6 @@ class team_1v1arena : public ArenaTeamScript } } - void OnQueueIdToArenaType(const BattlegroundQueueTypeId _bgQueueTypeId, uint8& arenaType) override { if (_bgQueueTypeId == bgQueueTypeId) @@ -460,7 +478,6 @@ class team_1v1arena : public ArenaTeamScript } } - void OnSetArenaMaxPlayersPerTeam(const uint8 type, uint32& maxPlayersPerTeam) override { if (type == ARENA_TYPE_1V1) @@ -468,7 +485,6 @@ class team_1v1arena : public ArenaTeamScript maxPlayersPerTeam = 1; } } - }; void AddSC_npc_1v1arena()