TrinityCore
Loading...
Searching...
No Matches
cs_honor.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/* ScriptData
19Name: honor_commandscript
20%Complete: 100
21Comment: All honor related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "Chat.h"
27#include "Language.h"
28#include "Player.h"
29#include "RBAC.h"
30#include "WorldSession.h"
31
32using namespace Trinity::ChatCommands;
33
35{
36public:
37 honor_commandscript() : CommandScript("honor_commandscript") { }
38
40 {
41 static ChatCommandTable honorAddCommandTable =
42 {
45 };
46
47 static ChatCommandTable honorCommandTable =
48 {
49 { "add", honorAddCommandTable },
51 };
52
53 static ChatCommandTable commandTable =
54 {
55 { "honor", honorCommandTable },
56 };
57 return commandTable;
58 }
59
60 static bool HandleHonorAddCommand(ChatHandler* handler, uint32 amount)
61 {
62 Player* target = handler->getSelectedPlayer();
63 if (!target)
64 {
66 handler->SetSentErrorMessage(true);
67 return false;
68 }
69
70 // check online security
71 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
72 return false;
73
74 target->RewardHonor(nullptr, 1, amount);
75 return true;
76 }
77
79 {
80 Unit* target = handler->getSelectedUnit();
81 if (!target)
82 {
84 handler->SetSentErrorMessage(true);
85 return false;
86 }
87
88 // check online security
89 if (Player* player = target->ToPlayer())
90 if (handler->HasLowerSecurity(player, ObjectGuid::Empty))
91 return false;
92
93 handler->GetSession()->GetPlayer()->RewardHonor(target, 1);
94 return true;
95 }
96
98 {
99 Player* target = handler->getSelectedPlayer();
100 if (!target)
101 {
103 handler->SetSentErrorMessage(true);
104 return false;
105 }
106
107 // check online security
108 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
109 return false;
110
111 target->UpdateHonorFields();
112 return true;
113 }
114};
115
uint32_t uint32
Definition Define.h:133
@ LANG_PLAYER_NOT_FOUND
Definition Language.h:570
Role Based Access Control related classes definition.
Unit * getSelectedUnit()
Definition Chat.cpp:314
Player * getSelectedPlayer()
Definition Chat.cpp:302
WorldSession * GetSession()
Definition Chat.h:46
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition Chat.cpp:51
void SetSentErrorMessage(bool val)
Definition Chat.h:134
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:101
static ObjectGuid const Empty
Definition ObjectGuid.h:140
static Player * ToPlayer(Object *o)
Definition Object.h:180
bool RewardHonor(Unit *victim, uint32 groupsize, int32 honor=-1, bool pvptoken=false)
Definition Player.cpp:6524
void UpdateHonorFields()
Definition Player.cpp:6489
Definition Unit.h:769
Player * GetPlayer() const
static bool HandleHonorAddCommand(ChatHandler *handler, uint32 amount)
Definition cs_honor.cpp:60
static bool HandleHonorUpdateCommand(ChatHandler *handler)
Definition cs_honor.cpp:97
ChatCommandTable GetCommands() const override
Definition cs_honor.cpp:39
static bool HandleHonorAddKillCommand(ChatHandler *handler)
Definition cs_honor.cpp:78
void AddSC_honor_commandscript()
Definition cs_honor.cpp:116
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:50
@ RBAC_PERM_COMMAND_HONOR_UPDATE
Definition RBAC.h:281
@ RBAC_PERM_COMMAND_HONOR_ADD
Definition RBAC.h:279
@ RBAC_PERM_COMMAND_HONOR_ADD_KILL
Definition RBAC.h:280