TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
KillRewarder Class Reference

#include <KillRewarder.h>

Public Member Functions

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

Private Member Functions

void _InitXP (Player *player)
 
void _InitGroupData ()
 
void _RewardHonor (Player *player)
 
void _RewardXP (Player *player, float rate)
 
void _RewardReputation (Player *player, float rate)
 
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 _sumLevel
 
uint32 _xp
 
bool _isFullXP
 
uint8 _maxLevel
 
bool _isBattleGround
 
bool _isPvP
 

Constructor & Destructor Documentation

KillRewarder::KillRewarder ( Player killer,
Unit victim,
bool  isBattleGround 
)
71  :
72  // 1. Initialize internal variables to default values.
73  _killer(killer), _victim(victim), _group(killer->GetGroup()),
74  _groupRate(1.0f), _maxNotGrayMember(nullptr), _count(0), _sumLevel(0), _xp(0),
75  _isFullXP(false), _maxLevel(0), _isBattleGround(isBattleGround), _isPvP(false)
76 {
77  // mark the credit as pvp if victim is player
78  if (victim->GetTypeId() == TYPEID_PLAYER)
79  _isPvP = true;
80  // or if its owned by player and its not a vehicle
81  else if (victim->GetCharmerOrOwnerGUID().IsPlayer())
82  _isPvP = !victim->IsVehicle();
83 
85 }
uint32 _xp
Definition: KillRewarder.h:52
Player * _killer
Definition: KillRewarder.h:45
uint8 _maxLevel
Definition: KillRewarder.h:54
bool IsPlayer() const
Definition: ObjectGuid.h:249
bool _isFullXP
Definition: KillRewarder.h:53
bool IsVehicle() const
Definition: Unit.h:1406
bool _isBattleGround
Definition: KillRewarder.h:55
float _groupRate
Definition: KillRewarder.h:48
Unit * _victim
Definition: KillRewarder.h:46
uint32 _sumLevel
Definition: KillRewarder.h:51
void _InitGroupData()
Definition: KillRewarder.cpp:87
TypeID GetTypeId() const
Definition: Object.h:113
Player * _maxNotGrayMember
Definition: KillRewarder.h:49
bool _isPvP
Definition: KillRewarder.h:56
ObjectGuid GetCharmerOrOwnerGUID() const
Definition: Unit.cpp:12677
uint32 _count
Definition: KillRewarder.h:50
Definition: ObjectGuid.h:33
Group * _group
Definition: KillRewarder.h:47

+ Here is the call graph for this function:

Member Function Documentation

void KillRewarder::_InitGroupData ( )
inlineprivate
88 {
89  if (_group)
90  {
91  // 2. In case when player is in group, initialize variables necessary for group calculations:
92  for (GroupReference* itr = _group->GetFirstMember(); itr != nullptr; itr = itr->next())
93  if (Player* member = itr->GetSource())
94  if (member->IsAlive() && member->IsAtGroupRewardDistance(_victim))
95  {
96  const uint8 lvl = member->getLevel();
97  // 2.1. _count - number of alive group members within reward distance;
98  ++_count;
99  // 2.2. _sumLevel - sum of levels of alive group members within reward distance;
100  _sumLevel += lvl;
101  // 2.3. _maxLevel - maximum level of alive group member within reward distance;
102  if (_maxLevel < lvl)
103  _maxLevel = lvl;
104  // 2.4. _maxNotGrayMember - maximum level of alive group member within reward distance,
105  // for whom victim is not gray;
106  uint32 grayLevel = Trinity::XP::GetGrayLevel(lvl);
107  if (_victim->getLevel() > grayLevel && (!_maxNotGrayMember || _maxNotGrayMember->getLevel() < lvl))
108  _maxNotGrayMember = member;
109  }
110  // 2.5. _isFullXP - flag identifying that for all group members victim is not gray,
111  // so 100% XP will be rewarded (50% otherwise).
113  }
114  else
115  _count = 1;
116 }
uint8 _maxLevel
Definition: KillRewarder.h:54
bool _isFullXP
Definition: KillRewarder.h:53
Unit * _victim
Definition: KillRewarder.h:46
uint8 GetGrayLevel(uint8 pl_level)
Definition: Formulas.h:46
uint8 getLevel() const
Definition: Unit.h:1408
uint32 _sumLevel
Definition: KillRewarder.h:51
Player * _maxNotGrayMember
Definition: KillRewarder.h:49
uint32_t uint32
Definition: Define.h:150
GroupReference * GetFirstMember()
Definition: Group.h:295
GroupReference * next()
Definition: GroupReference.h:37
uint32 _count
Definition: KillRewarder.h:50
Group * _group
Definition: KillRewarder.h:47
uint8_t uint8
Definition: Define.h:152
Definition: GroupReference.h:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KillRewarder::_InitXP ( Player player)
inlineprivate
119 {
120  // Get initial value of XP for kill.
121  // XP is given:
122  // * on battlegrounds;
123  // * otherwise, not in PvP;
124  // * not if killer is on vehicle.
125  if (_isBattleGround || (!_isPvP && !_killer->GetVehicle()))
127 }
uint32 _xp
Definition: KillRewarder.h:52
Player * _killer
Definition: KillRewarder.h:45
uint32 Gain(Player *player, Unit *u, bool isBattleGround=false)
Definition: Formulas.h:153
bool _isBattleGround
Definition: KillRewarder.h:55
Unit * _victim
Definition: KillRewarder.h:46
bool _isPvP
Definition: KillRewarder.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KillRewarder::_RewardGroup ( )
private
215 {
216  if (_maxLevel)
217  {
218  if (_maxNotGrayMember)
219  // 3.1.1. Initialize initial XP amount based on maximum level of group member,
220  // for whom victim is not gray.
222  // To avoid unnecessary calculations and calls,
223  // proceed only if XP is not ZERO or player is not on battleground
224  // (battleground rewards only XP, that's why).
225  if (!_isBattleGround || _xp)
226  {
227  bool const isDungeon = !_isPvP && sMapStore.LookupEntry(_killer->GetMapId())->IsDungeon();
228  if (!_isBattleGround)
229  {
230  // 3.1.2. Alter group rate if group is in raid (not for battlegrounds).
231  bool const isRaid = !_isPvP && sMapStore.LookupEntry(_killer->GetMapId())->IsRaid() && _group->isRaidGroup();
233  }
234 
235  // 3.1.3. Reward each group member (even dead or corpse) within reward distance.
236  for (GroupReference* itr = _group->GetFirstMember(); itr != nullptr; itr = itr->next())
237  {
238  if (Player* member = itr->GetSource())
239  {
240  if (member->IsAtGroupRewardDistance(_victim))
241  {
242  _RewardPlayer(member, isDungeon);
243  member->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL, 1, 0, 0, _victim);
244  }
245  }
246  }
247  }
248  }
249 }
uint32 _xp
Definition: KillRewarder.h:52
Player * _killer
Definition: KillRewarder.h:45
uint8 _maxLevel
Definition: KillRewarder.h:54
bool _isBattleGround
Definition: KillRewarder.h:55
float _groupRate
Definition: KillRewarder.h:48
bool isRaidGroup() const
Definition: Group.cpp:2509
Unit * _victim
Definition: KillRewarder.h:46
void _InitXP(Player *player)
Definition: KillRewarder.cpp:118
Player * _maxNotGrayMember
Definition: KillRewarder.h:49
bool _isPvP
Definition: KillRewarder.h:56
GroupReference * GetFirstMember()
Definition: Group.h:295
void _RewardPlayer(Player *player, bool isDungeon)
Definition: KillRewarder.cpp:184
GroupReference * next()
Definition: GroupReference.h:37
uint32 _count
Definition: KillRewarder.h:50
DBCStorage< MapEntry > sMapStore(Mapfmt)
Group * _group
Definition: KillRewarder.h:47
float xp_in_group_rate(uint32 count, bool isRaid)
Definition: Formulas.h:194
Definition: GroupReference.h:27

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KillRewarder::_RewardHonor ( Player player)
inlineprivate
130 {
131  // Rewarded player must be alive.
132  if (player->IsAlive())
133  player->RewardHonor(_victim, _count, -1, true);
134 }
Unit * _victim
Definition: KillRewarder.h:46
uint32 _count
Definition: KillRewarder.h:50

+ Here is the caller graph for this function:

void KillRewarder::_RewardKillCredit ( Player player)
inlineprivate
174 {
175  // 4.4. Give kill credit (player must not be in group, or he must be alive or without corpse).
176  if (!_group || player->IsAlive() || !player->GetCorpse())
177  if (Creature* target = _victim->ToCreature())
178  {
179  player->KilledMonster(target->GetCreatureTemplate(), target->GetGUID());
180  player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE, target->GetCreatureType(), 1, 0, target);
181  }
182 }
Unit * _victim
Definition: KillRewarder.h:46
Definition: Creature.h:467
Creature * ToCreature()
Definition: Object.h:194
Group * _group
Definition: KillRewarder.h:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KillRewarder::_RewardPlayer ( Player player,
bool  isDungeon 
)
private
185 {
186  // 4. Reward player.
187  if (!_isBattleGround)
188  {
189  // 4.1. Give honor (player must be alive and not on BG).
190  _RewardHonor(player);
191  // 4.1.1 Send player killcredit for quests with PlayerSlain
192  if (_victim->GetTypeId() == TYPEID_PLAYER)
193  player->KilledPlayerCredit();
194  }
195  // Give XP only in PvE or in battlegrounds.
196  // Give reputation and kill credit only in PvE.
197  if (!_isPvP || _isBattleGround)
198  {
199  float const rate = _group ?
200  _groupRate * float(player->getLevel()) / _sumLevel : // Group rate depends on summary level.
201  1.0f; // Personal rate is 100%.
202  if (_xp)
203  // 4.2. Give XP.
204  _RewardXP(player, rate);
205  if (!_isBattleGround)
206  {
207  // If killer is in dungeon then all members receive full reputation at kill.
208  _RewardReputation(player, isDungeon ? 1.0f : rate);
209  _RewardKillCredit(player);
210  }
211  }
212 }
uint32 _xp
Definition: KillRewarder.h:52
bool _isBattleGround
Definition: KillRewarder.h:55
float _groupRate
Definition: KillRewarder.h:48
void _RewardHonor(Player *player)
Definition: KillRewarder.cpp:129
Unit * _victim
Definition: KillRewarder.h:46
uint32 _sumLevel
Definition: KillRewarder.h:51
TypeID GetTypeId() const
Definition: Object.h:113
void _RewardKillCredit(Player *player)
Definition: KillRewarder.cpp:173
bool _isPvP
Definition: KillRewarder.h:56
void _RewardXP(Player *player, float rate)
Definition: KillRewarder.cpp:136
Definition: ObjectGuid.h:33
Group * _group
Definition: KillRewarder.h:47
void _RewardReputation(Player *player, float rate)
Definition: KillRewarder.cpp:166

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KillRewarder::_RewardReputation ( Player player,
float  rate 
)
inlineprivate
167 {
168  // 4.3. Give reputation (player must not be on BG).
169  // Even dead players and corpses are rewarded.
170  player->RewardReputation(_victim, rate);
171 }
Unit * _victim
Definition: KillRewarder.h:46

+ Here is the caller graph for this function:

void KillRewarder::_RewardXP ( Player player,
float  rate 
)
inlineprivate
137 {
138  uint32 xp(_xp);
139  if (_group)
140  {
141  // 4.2.1. If player is in group, adjust XP:
142  // * set to 0 if player's level is more than maximum level of not gray member;
143  // * cut XP in half if _isFullXP is false.
144  if (_maxNotGrayMember && player->IsAlive() &&
145  _maxNotGrayMember->getLevel() >= player->getLevel())
146  xp = _isFullXP ?
147  uint32(xp * rate) : // Reward FULL XP if all group members are not gray.
148  uint32(xp * rate / 2) + 1; // Reward only HALF of XP if some of group members are gray.
149  else
150  xp = 0;
151  }
152  if (xp)
153  {
154  // 4.2.2. Apply auras modifying rewarded XP (SPELL_AURA_MOD_XP_PCT).
155  for (auto const& aura : player->GetAuraEffectsByType(SPELL_AURA_MOD_XP_PCT))
156  AddPct(xp, aura->GetAmount());
157 
158  // 4.2.3. Give XP to player.
159  player->GiveXP(xp, _victim, _groupRate);
160  if (Pet* pet = player->GetPet())
161  // 4.2.4. If player has pet, reward pet with XP (100% for single player, 50% for group case).
162  pet->GivePetXP(_group ? xp / 2 : xp);
163  }
164 }
uint32 _xp
Definition: KillRewarder.h:52
bool _isFullXP
Definition: KillRewarder.h:53
float _groupRate
Definition: KillRewarder.h:48
Unit * _victim
Definition: KillRewarder.h:46
Player * _maxNotGrayMember
Definition: KillRewarder.h:49
uint32_t uint32
Definition: Define.h:150
Definition: SpellAuraDefines.h:260
T AddPct(T &base, U pct)
Definition: Util.h:98
Group * _group
Definition: KillRewarder.h:47
uint32_t uint32
Definition: g3dmath.h:168
Definition: Pet.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void KillRewarder::Reward ( )
252 {
253  // 3. Reward killer (and group, if necessary).
254  if (_group)
255  // 3.1. If killer is in group, reward group.
256  _RewardGroup();
257  else
258  {
259  // 3.2. Reward single killer (not group case).
260  // 3.2.1. Initialize initial XP amount based on killer's level.
261  _InitXP(_killer);
262  // To avoid unnecessary calculations and calls,
263  // proceed only if XP is not ZERO or player is not on battleground
264  // (battleground rewards only XP, that's why).
265  if (!_isBattleGround || _xp)
266  // 3.2.2. Reward killer.
267  _RewardPlayer(_killer, false);
268  }
269 
270  // 5. Credit instance encounter.
271  // 6. Update guild achievements.
272  if (Creature* victim = _victim->ToCreature())
273  {
274  if (victim->IsDungeonBoss())
275  if (InstanceScript* instance = _victim->GetInstanceScript())
276  instance->UpdateEncounterState(ENCOUNTER_CREDIT_KILL_CREATURE, _victim->GetEntry(), _victim);
277 
278  if (ObjectGuid::LowType guildId = victim->GetMap()->GetOwnerGuildId())
279  if (Guild* guild = sGuildMgr->GetGuildById(guildId))
280  guild->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE, victim->GetEntry(), 1, 0, victim, _killer);
281  }
282 
283 }
uint32 _xp
Definition: KillRewarder.h:52
Player * _killer
Definition: KillRewarder.h:45
bool _isBattleGround
Definition: KillRewarder.h:55
InstanceScript * GetInstanceScript()
Definition: Object.cpp:1540
Unit * _victim
Definition: KillRewarder.h:46
#define sGuildMgr
Definition: GuildMgr.h:61
void _InitXP(Player *player)
Definition: KillRewarder.cpp:118
Definition: DBCEnums.h:198
Definition: Creature.h:467
uint64 LowType
Definition: ObjectGuid.h:199
Definition: ObjectMgr.h:672
void _RewardPlayer(Player *player, bool isDungeon)
Definition: KillRewarder.cpp:184
Creature * ToCreature()
Definition: Object.h:194
Group * _group
Definition: KillRewarder.h:47
Definition: InstanceScript.h:141
uint32 GetEntry() const
Definition: Object.h:107
Definition: Guild.h:320
void _RewardGroup()
Definition: KillRewarder.cpp:214

+ Here is the call graph for this function:

Member Data Documentation

uint32 KillRewarder::_count
private
Group* KillRewarder::_group
private
float KillRewarder::_groupRate
private
bool KillRewarder::_isBattleGround
private
bool KillRewarder::_isFullXP
private
bool KillRewarder::_isPvP
private
Player* KillRewarder::_killer
private
uint8 KillRewarder::_maxLevel
private
Player* KillRewarder::_maxNotGrayMember
private
uint32 KillRewarder::_sumLevel
private
Unit* KillRewarder::_victim
private
uint32 KillRewarder::_xp
private

The documentation for this class was generated from the following files: