TrinityCore
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 "ChatCommand.h"
28#include "Language.h"
29#include "Player.h"
30#include "RBAC.h"
31#include "WorldSession.h"
32
33using namespace Trinity::ChatCommands;
34
36{
37public:
38 honor_commandscript() : CommandScript("honor_commandscript") { }
39
41 {
42 static ChatCommandTable honorAddCommandTable =
43 {
46 };
47
48 static ChatCommandTable honorCommandTable =
49 {
50 { "add", honorAddCommandTable },
52 };
53
54 static ChatCommandTable commandTable =
55 {
56 { "honor", honorCommandTable },
57 };
58 return commandTable;
59 }
60
61 static bool HandleHonorAddCommand(ChatHandler* handler, int32 amount)
62 {
63 Player* target = handler->getSelectedPlayer();
64 if (!target)
65 {
67 handler->SetSentErrorMessage(true);
68 return false;
69 }
70
71 // check online security
72 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
73 return false;
74
75 target->RewardHonor(nullptr, 1, amount);
76 return true;
77 }
78
80 {
81 Unit* target = handler->getSelectedUnit();
82 if (!target)
83 {
85 handler->SetSentErrorMessage(true);
86 return false;
87 }
88
89 // check online security
90 if (Player* player = target->ToPlayer())
91 if (handler->HasLowerSecurity(player, ObjectGuid::Empty))
92 return false;
93
94 handler->GetSession()->GetPlayer()->RewardHonor(target, 1);
95 return true;
96 }
97
99 {
100 Player* target = handler->getSelectedPlayer();
101 if (!target)
102 {
104 handler->SetSentErrorMessage(true);
105 return false;
106 }
107
108 // check online security
109 if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
110 return false;
111
112 target->UpdateHonorFields();
113 return true;
114 }
115};
116
118{
120}
int32_t int32
Definition: Define.h:138
@ LANG_PLAYER_NOT_FOUND
Definition: Language.h:567
Role Based Access Control related classes definition.
Unit * getSelectedUnit()
Definition: Chat.cpp:212
Player * getSelectedPlayer()
Definition: Chat.cpp:200
WorldSession * GetSession()
Definition: Chat.h:42
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition: Chat.cpp:63
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
static ObjectGuid const Empty
Definition: ObjectGuid.h:274
static Player * ToPlayer(Object *o)
Definition: Object.h:213
bool RewardHonor(Unit *victim, uint32 groupsize, int32 honor=-1, bool pvptoken=false)
Definition: Player.cpp:6726
void UpdateHonorFields()
Definition: Player.cpp:6695
Definition: Unit.h:627
Player * GetPlayer() const
static bool HandleHonorUpdateCommand(ChatHandler *handler)
Definition: cs_honor.cpp:98
static bool HandleHonorAddCommand(ChatHandler *handler, int32 amount)
Definition: cs_honor.cpp:61
ChatCommandTable GetCommands() const override
Definition: cs_honor.cpp:40
static bool HandleHonorAddKillCommand(ChatHandler *handler)
Definition: cs_honor.cpp:79
void AddSC_honor_commandscript()
Definition: cs_honor.cpp:117
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
@ RBAC_PERM_COMMAND_HONOR_UPDATE
Definition: RBAC.h:283
@ RBAC_PERM_COMMAND_HONOR_ADD
Definition: RBAC.h:281
@ RBAC_PERM_COMMAND_HONOR_ADD_KILL
Definition: RBAC.h:282