AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
KillRewarder Class Reference

#include "KillRewarder.h"

Public Member Functions

 KillRewarder (Player *killer, Unit *victim, bool isBattleGround)
 
void Reward ()
 
UnitGetVictim ()
 
PlayerGetKiller ()
 

Private Member Functions

void _InitXP (Player *player)
 
void _InitGroupData ()
 
void _RewardHonor (Player *player)
 
void _RewardXP (Player *player, float rate)
 
void _RewardReputation (Player *player)
 
void _RewardKillCredit (Player *player)
 
void _RewardPlayer (Player *player, bool isDungeon)
 
void _RewardGroup ()
 

Private Attributes

Player_killer
 
Unit_victim
 
Group_group
 
float _groupRate
 
Player_maxNotGrayMember
 
uint32 _count
 
uint32 _aliveSumLevel
 
uint32 _sumLevel
 
uint32 _xp
 
bool _isFullXP
 
uint8 _maxLevel
 
bool _isBattleGround
 
bool _isPvP
 

Detailed Description

Constructor & Destructor Documentation

◆ KillRewarder()

KillRewarder::KillRewarder ( Player killer,
Unit victim,
bool  isBattleGround 
)
66 :
67// 1. Initialize internal variables to default values.
68 _killer(killer), _victim(victim), _group(killer->GetGroup()),
69 _groupRate(1.0f), _maxNotGrayMember(nullptr), _count(0), _aliveSumLevel(0), _sumLevel(0), _xp(0),
70 _isFullXP(false), _maxLevel(0), _isBattleGround(isBattleGround), _isPvP(false)
71{
72 // mark the credit as pvp if victim is player
73 if (victim->IsPlayer())
74 _isPvP = true;
75 // or if its owned by player and its not a vehicle
76 else if (victim->GetCharmerOrOwnerGUID().IsPlayer())
77 _isPvP = !victim->IsVehicle();
78
80}
bool IsPlayer() const
Definition: Object.h:197
bool IsPlayer() const
Definition: ObjectGuid.h:168
uint8 _maxLevel
Definition: KillRewarder.h:57
uint32 _count
Definition: KillRewarder.h:52
float _groupRate
Definition: KillRewarder.h:50
uint32 _xp
Definition: KillRewarder.h:55
uint32 _aliveSumLevel
Definition: KillRewarder.h:53
uint32 _sumLevel
Definition: KillRewarder.h:54
Player * _maxNotGrayMember
Definition: KillRewarder.h:51
Unit * _victim
Definition: KillRewarder.h:48
Player * _killer
Definition: KillRewarder.h:47
bool _isBattleGround
Definition: KillRewarder.h:58
Group * _group
Definition: KillRewarder.h:49
void _InitGroupData()
Definition: KillRewarder.cpp:82
bool _isFullXP
Definition: KillRewarder.h:56
bool _isPvP
Definition: KillRewarder.h:59
Group * GetGroup()
Definition: Player.h:2448
bool IsVehicle() const
Definition: Unit.h:713
ObjectGuid GetCharmerOrOwnerGUID() const
Definition: Unit.h:1226

References _InitGroupData(), _isPvP, Unit::GetCharmerOrOwnerGUID(), Object::IsPlayer(), ObjectGuid::IsPlayer(), and Unit::IsVehicle().

Member Function Documentation

◆ _InitGroupData()

void KillRewarder::_InitGroupData ( )
private
83{
84 if (_group)
85 {
86 // 2. In case when player is in group, initialize variables necessary for group calculations:
87 for (GroupReference* itr = _group->GetFirstMember(); itr != nullptr; itr = itr->next())
88 if (Player* member = itr->GetSource())
89 if ((_killer == member || member->IsAtGroupRewardDistance(_victim)))
90 {
91 const uint8 lvl = member->GetLevel();
92 if (member->IsAlive())
93 {
94 // 2.1. _count - number of alive group members within reward distance;
95 ++_count;
96 // 2.2. _aliveSumLevel - sum of levels of alive group members within reward distance;
97 _aliveSumLevel += lvl;
98 // 2.3. _maxLevel - maximum level of alive group member within reward distance;
99 if (_maxLevel < lvl)
100 {
101 _maxLevel = lvl;
102 }
103 // 2.4. _maxNotGrayMember - maximum level of alive group member within reward distance,
104 // for whom victim is not gray;
105 uint32 grayLevel = Acore::XP::GetGrayLevel(lvl);
106 if (_victim->GetLevel() > grayLevel && (!_maxNotGrayMember || _maxNotGrayMember->GetLevel() < lvl))
107 {
108 _maxNotGrayMember = member;
109 }
110 }
111 // 2.5. _sumLevel - sum of levels of group members within reward distance;
112 _sumLevel += lvl;
113 }
114 // 2.6. _isFullXP - flag identifying that for all group members victim is not gray,
115 // so 100% XP will be rewarded (50% otherwise).
117 }
118 else
119 _count = 1;
120}
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
uint8 GetGrayLevel(uint8 pl_level)
Definition: Formulas.h:46
Definition: Player.h:1064
bool IsAtGroupRewardDistance(WorldObject const *pRewardSource) const
Definition: Player.cpp:12761
uint8 GetLevel() const
Definition: Unit.h:855
GroupReference * GetFirstMember()
Definition: Group.h:243
Definition: GroupReference.h:27
GroupReference * next()
Definition: GroupReference.h:36

References _aliveSumLevel, _count, _group, _isFullXP, _killer, _maxLevel, _maxNotGrayMember, _sumLevel, _victim, Group::GetFirstMember(), Acore::XP::GetGrayLevel(), Unit::GetLevel(), Player::IsAtGroupRewardDistance(), and GroupReference::next().

Referenced by KillRewarder().

◆ _InitXP()

void KillRewarder::_InitXP ( Player player)
private
123{
124 // Get initial value of XP for kill.
125 // XP is given:
126 // * on battlegrounds;
127 // * otherwise, not in PvP;
128 // * not if killer is on vehicle.
129 if (_victim && (_isBattleGround || (!_isPvP && !_killer->GetVehicle())))
131
132 if (_xp && !_isBattleGround && _victim) // pussywizard: npcs with relatively low hp give lower exp
133 if (_victim->IsCreature())
135 if (ct->ModHealth <= 0.75f && ct->ModHealth >= 0.0f)
136 _xp = uint32(_xp * ct->ModHealth);
137}
uint32 Gain(Player *player, Unit *unit, bool isBattleGround=false)
Definition: Formulas.cpp:71
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:206
Definition: CreatureData.h:189
bool IsCreature() const
Definition: Object.h:201
Creature * ToCreature()
Definition: Object.h:202
Vehicle * GetVehicle() const
Definition: Unit.h:1673

References _isBattleGround, _isPvP, _killer, _victim, _xp, Acore::XP::Gain(), Creature::GetCreatureTemplate(), Unit::GetVehicle(), Object::IsCreature(), and Object::ToCreature().

Referenced by _RewardGroup(), and Reward().

◆ _RewardGroup()

void KillRewarder::_RewardGroup ( )
private
230{
231 if (_maxLevel)
232 {
234 // 3.1.1. Initialize initial XP amount based on maximum level of group member,
235 // for whom victim is not gray.
237 // To avoid unnecessary calculations and calls,
238 // proceed only if XP is not ZERO or player is not on battleground
239 // (battleground rewards only XP, that's why).
240 if (!_isBattleGround || _xp)
241 {
242 const bool isDungeon = !_isPvP && sMapStore.LookupEntry(_killer->GetMapId())->IsDungeon();
243 if (!_isBattleGround)
244 {
245 // 3.1.2. Alter group rate if group is in raid (not for battlegrounds).
246 const bool isRaid = !_isPvP && sMapStore.LookupEntry(_killer->GetMapId())->IsRaid() && _group->isRaidGroup();
248 }
249
250 // 3.1.3. Reward each group member (even dead or corpse) within reward distance.
251 for (GroupReference* itr = _group->GetFirstMember(); itr != nullptr; itr = itr->next())
252 {
253 if (Player* member = itr->GetSource())
254 {
255 if (_killer == member || member->IsAtGroupRewardDistance(_victim))
256 {
257 _RewardPlayer(member, isDungeon);
258 // Xinef: only count players
259 //if (_victim->IsPlayer())
260 // member->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL, 1, 0, _victim);
261 }
262 }
263 }
264 }
265 }
266}
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
float xp_in_group_rate(uint32 count, bool isRaid)
Definition: Formulas.h:119
uint32 GetMapId() const
Definition: Position.h:276
void _RewardPlayer(Player *player, bool isDungeon)
Definition: KillRewarder.cpp:196
void _InitXP(Player *player)
Definition: KillRewarder.cpp:122
bool isRaidGroup() const
Definition: Group.cpp:2271

References _count, _group, _groupRate, _InitXP(), _isBattleGround, _isPvP, _killer, _maxLevel, _maxNotGrayMember, _RewardPlayer(), _victim, _xp, Group::GetFirstMember(), WorldLocation::GetMapId(), Player::IsAtGroupRewardDistance(), Group::isRaidGroup(), GroupReference::next(), sMapStore, and Acore::XP::xp_in_group_rate().

Referenced by Reward().

◆ _RewardHonor()

void KillRewarder::_RewardHonor ( Player player)
private
140{
141 // Rewarded player must be alive.
142 if (player->IsAlive())
143 player->RewardHonor(_victim, _count, -1);
144}
bool RewardHonor(Unit *victim, uint32 groupsize, int32 honor=-1, bool awardXP=true)
Definition: Player.cpp:6064
bool IsAlive() const
Definition: Unit.h:1204

References _count, _victim, Unit::IsAlive(), and Player::RewardHonor().

Referenced by _RewardPlayer().

◆ _RewardKillCredit()

void KillRewarder::_RewardKillCredit ( Player player)
private
186{
187 // 4.4. Give kill credit (player must not be in group, or he must be alive or without corpse).
188 if (!_group || player->IsAlive() || !player->GetCorpse())
189 if (Creature* target = _victim->ToCreature())
190 {
191 player->KilledMonster(target->GetCreatureTemplate(), target->GetGUID());
192 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE, target->GetCreatureType(), 1, target);
193 }
194}
@ ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE
Definition: DBCEnums.h:188
Definition: Creature.h:46
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, Unit *unit=nullptr)
Definition: PlayerUpdates.cpp:2127
void KilledMonster(CreatureTemplate const *cInfo, ObjectGuid guid)
Definition: PlayerQuest.cpp:1909
Corpse * GetCorpse() const
Definition: Player.cpp:4692

References _group, _victim, ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE, Player::GetCorpse(), Unit::IsAlive(), Player::KilledMonster(), Object::ToCreature(), and Player::UpdateAchievementCriteria().

Referenced by _RewardPlayer().

◆ _RewardPlayer()

void KillRewarder::_RewardPlayer ( Player player,
bool  isDungeon 
)
private
197{
198 // 4. Reward player.
199 if (!_isBattleGround)
200 {
201 // 4.1. Give honor (player must be alive and not on BG).
202 _RewardHonor(player);
203 // 4.1.1 Send player killcredit for quests with PlayerSlain
204 if (_victim->IsPlayer())
205 player->KilledPlayerCredit();
206 }
207
208 // Give XP only in PvE or in battlegrounds.
209 // Give reputation and kill credit only in PvE.
210 if (!_isPvP || _isBattleGround)
211 {
212 float xpRate = _group ? _groupRate * float(player->GetLevel()) / _aliveSumLevel : /*Personal rate is 100%.*/ 1.0f; // Group rate depends on the sum of levels.
213 sScriptMgr->OnRewardKillRewarder(player, this, isDungeon, xpRate); // Personal rate is 100%.
214
215 if (_xp)
216 {
217 // 4.2. Give XP.
218 _RewardXP(player, xpRate);
219 }
220 if (!_isBattleGround)
221 {
222 // If killer is in dungeon then all members receive full reputation at kill.
223 _RewardReputation(player);
224 _RewardKillCredit(player);
225 }
226 }
227}
#define sScriptMgr
Definition: ScriptMgr.h:708
void _RewardReputation(Player *player)
Definition: KillRewarder.cpp:178
void _RewardHonor(Player *player)
Definition: KillRewarder.cpp:139
void _RewardXP(Player *player, float rate)
Definition: KillRewarder.cpp:146
void _RewardKillCredit(Player *player)
Definition: KillRewarder.cpp:185
void KilledPlayerCredit(uint16 count=1)
Definition: PlayerQuest.cpp:1989

References _aliveSumLevel, _group, _groupRate, _isBattleGround, _isPvP, _RewardHonor(), _RewardKillCredit(), _RewardReputation(), _RewardXP(), _victim, _xp, Unit::GetLevel(), Object::IsPlayer(), Player::KilledPlayerCredit(), and sScriptMgr.

Referenced by _RewardGroup(), and Reward().

◆ _RewardReputation()

void KillRewarder::_RewardReputation ( Player player)
private
179{
180 // 4.3. Give reputation (player must not be on BG).
181 // Even dead players and corpses are rewarded.
182 player->RewardReputation(_victim);
183}
void RewardReputation(Unit *victim)
Definition: Player.cpp:5949

References _victim, and Player::RewardReputation().

Referenced by _RewardPlayer().

◆ _RewardXP()

void KillRewarder::_RewardXP ( Player player,
float  rate 
)
private
147{
148 uint32 xp(_xp);
149 if (_group)
150 {
151 // 4.2.1. If player is in group, adjust XP:
152 // * set to 0 if player's level is more than maximum level of not gray member;
153 // * cut XP in half if _isFullXP is false.
154 if (_maxNotGrayMember && player->IsAlive() &&
155 _maxNotGrayMember->GetLevel() >= player->GetLevel())
156 xp = _isFullXP ?
157 uint32(xp * rate) : // Reward FULL XP if all group members are not gray.
158 uint32(xp * rate / 2) + 1; // Reward only HALF of XP if some of group members are gray.
159 else
160 xp = 0;
161 }
162 if (xp)
163 {
164 // 4.2.2. Apply auras modifying rewarded XP (SPELL_AURA_MOD_XP_PCT).
166 for (Unit::AuraEffectList::const_iterator i = auras.begin(); i != auras.end(); ++i)
167 AddPct(xp, (*i)->GetAmount());
168
169 // 4.2.3. Give XP to player.
170 sScriptMgr->OnGivePlayerXP(player, xp, _victim, PlayerXPSource::XPSOURCE_KILL);
171 player->GiveXP(xp, _victim, _groupRate);
172 if (Pet* pet = player->GetPet())
173 // 4.2.4. If player has pet, reward pet with XP (100% for single player, 50% for group case).
174 pet->GivePetXP(_group ? xp / 2 : xp);
175 }
176}
T AddPct(T &base, U pct)
Definition: Util.h:67
@ SPELL_AURA_MOD_XP_PCT
Definition: SpellAuraDefines.h:263
Definition: Pet.h:41
Pet * GetPet() const
Definition: Player.cpp:8906
void GiveXP(uint32 xp, Unit *victim, float group_rate=1.0f, bool isLFGReward=false)
Definition: Player.cpp:2371
AuraEffectList const & GetAuraEffectsByType(AuraType type) const
Definition: Unit.h:1362
std::list< AuraEffect * > AuraEffectList
Definition: Unit.h:646

References _group, _groupRate, _isFullXP, _maxNotGrayMember, _victim, _xp, AddPct(), Unit::GetAuraEffectsByType(), Unit::GetLevel(), Player::GetPet(), Player::GiveXP(), Unit::IsAlive(), SPELL_AURA_MOD_XP_PCT, and sScriptMgr.

Referenced by _RewardPlayer().

◆ GetKiller()

Player * KillRewarder::GetKiller ( )
301{
302 return _killer;
303}

References _killer.

◆ GetVictim()

Unit * KillRewarder::GetVictim ( )
296{
297 return _victim;
298}

References _victim.

◆ Reward()

void KillRewarder::Reward ( )
269{
270 // 3. Reward killer (and group, if necessary).
271 if (_group)
272 // 3.1. If killer is in group, reward group.
273 _RewardGroup();
274 else
275 {
276 // 3.2. Reward single killer (not group case).
277 // 3.2.1. Initialize initial XP amount based on killer's level.
279 // To avoid unnecessary calculations and calls,
280 // proceed only if XP is not ZERO or player is not on battleground
281 // (battleground rewards only XP, that's why).
282 if (!_isBattleGround || _xp)
283 // 3.2.2. Reward killer.
284 if (_killer->IsInMap(_victim)) // pussywizard: killer may be on other map (crashfix), when killing in a group same map is required, so its not a problem
285 _RewardPlayer(_killer, false);
286 }
287
288 // 5. Credit instance encounter.
289 if (Creature* victim = _victim->ToCreature())
290 if (victim->IsDungeonBoss())
291 if (Map* map = _victim->FindMap())
292 map->UpdateEncounterState(ENCOUNTER_CREDIT_KILL_CREATURE, _victim->GetEntry(), _victim);
293}
@ ENCOUNTER_CREDIT_KILL_CREATURE
Definition: Map.h:308
uint32 GetEntry() const
Definition: Object.h:112
Map * FindMap() const
Definition: Object.h:532
bool IsInMap(WorldObject const *obj) const
Definition: Object.cpp:1285
void _RewardGroup()
Definition: KillRewarder.cpp:229
Definition: Map.h:313

References _group, _InitXP(), _isBattleGround, _killer, _RewardGroup(), _RewardPlayer(), _victim, _xp, ENCOUNTER_CREDIT_KILL_CREATURE, WorldObject::FindMap(), Object::GetEntry(), WorldObject::IsInMap(), and Object::ToCreature().

Referenced by Player::RewardPlayerAndGroupAtKill().

Member Data Documentation

◆ _aliveSumLevel

uint32 KillRewarder::_aliveSumLevel
private

Referenced by _InitGroupData(), and _RewardPlayer().

◆ _count

uint32 KillRewarder::_count
private

◆ _group

Group* KillRewarder::_group
private

◆ _groupRate

float KillRewarder::_groupRate
private

◆ _isBattleGround

bool KillRewarder::_isBattleGround
private

◆ _isFullXP

bool KillRewarder::_isFullXP
private

Referenced by _InitGroupData(), and _RewardXP().

◆ _isPvP

bool KillRewarder::_isPvP
private

◆ _killer

Player* KillRewarder::_killer
private

◆ _maxLevel

uint8 KillRewarder::_maxLevel
private

Referenced by _InitGroupData(), and _RewardGroup().

◆ _maxNotGrayMember

Player* KillRewarder::_maxNotGrayMember
private

◆ _sumLevel

uint32 KillRewarder::_sumLevel
private

Referenced by _InitGroupData().

◆ _victim

◆ _xp

uint32 KillRewarder::_xp
private