TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Trinity::XP Namespace Reference

Functions

uint8 GetGrayLevel (uint8 pl_level)
 
XPColorChar GetColorCode (uint8 pl_level, uint8 mob_level)
 
uint8 GetZeroDifference (uint8 pl_level)
 
uint32 BaseGain (uint8 pl_level, uint8 mob_level)
 
uint32 Gain (Player *player, Unit *u, bool isBattleGround=false)
 
float xp_in_group_rate (uint32 count, bool isRaid)
 

Function Documentation

uint32 Trinity::XP::BaseGain ( uint8  pl_level,
uint8  mob_level 
)
inline
120  {
121  uint32 baseGain;
122 
123  GtOCTLevelExperienceEntry const* BaseExpPlayer = sGtOCTLevelExperienceStore.EvaluateTable(pl_level - 1, 1);
124  GtOCTLevelExperienceEntry const* BaseExpMob = sGtOCTLevelExperienceStore.EvaluateTable(mob_level - 1, 1);
125 
126  GtOCTLevelExperienceEntry const* CoefPlayer = sGtOCTLevelExperienceStore.EvaluateTable(pl_level - 1, 4);
127  GtOCTLevelExperienceEntry const* CoefMob = sGtOCTLevelExperienceStore.EvaluateTable(mob_level - 1, 4);
128 
129  if (mob_level >= pl_level)
130  {
131  uint8 nLevelDiff = mob_level - pl_level;
132  if (nLevelDiff > 4)
133  nLevelDiff = 4;
134 
135  baseGain = uint32(round(BaseExpPlayer->Data * (1 + 0.05f * nLevelDiff)));
136  }
137  else
138  {
139  uint8 gray_level = GetGrayLevel(pl_level);
140  if (mob_level > gray_level)
141  {
142  uint8 ZD = GetZeroDifference(pl_level);
143  baseGain = uint32(round(BaseExpMob->Data * ((1 - ((pl_level - mob_level) / float(ZD))) * (CoefMob->Data / CoefPlayer->Data))));
144  }
145  else
146  baseGain = 0;
147  }
148 
149  sScriptMgr->OnBaseGainCalculation(baseGain, pl_level, mob_level);
150  return baseGain;
151  }
double round(double f)
Definition: g3dmath.h:214
float Data
Definition: DBCStructure.h:594
uint8 GetGrayLevel(uint8 pl_level)
Definition: Formulas.h:46
uint32_t uint32
Definition: Define.h:150
GameTable< GtOCTLevelExperienceEntry > sGtOCTLevelExperienceStore(GtOCTLevelExperiencefmt)
uint8 GetZeroDifference(uint8 pl_level)
Definition: Formulas.h:86
uint8_t uint8
Definition: Define.h:152
#define sScriptMgr
Definition: ScriptMgr.h:837
uint32_t uint32
Definition: g3dmath.h:168
Definition: DBCStructure.h:592

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 Trinity::XP::Gain ( Player *  player,
Unit u,
bool  isBattleGround = false 
)
inline
154  {
155  Creature* creature = u->ToCreature();
156  uint32 gain = 0;
157 
158  if (!creature || (!creature->IsTotem() && !creature->IsPet() && !creature->IsCritter() &&
160  {
161  float xpMod = 1.0f;
162 
163  gain = BaseGain(player->getLevel(), u->getLevel());
164 
165  if (gain && creature)
166  {
167  // Players get only 10% xp for killing creatures of lower expansion levels than himself
168  if ((uint32(creature->GetCreatureTemplate()->expansion) < GetExpansionForLevel(player->getLevel())))
169  gain = uint32(round(gain / 10.0f));
170 
171  if (creature->isElite())
172  {
173  // Elites in instances have a 2.75x XP bonus instead of the regular 2x world bonus.
174  if (u->GetMap()->IsDungeon())
175  xpMod *= 2.75f;
176  else
177  xpMod *= 2.0f;
178  }
179 
180  xpMod *= creature->GetCreatureTemplate()->ModExperience;
181  }
182 
183  xpMod *= isBattleGround ? sWorld->getRate(RATE_XP_BG_KILL) : sWorld->getRate(RATE_XP_KILL);
184  if (creature && creature->m_PlayerDamageReq) // if players dealt less than 50% of the damage and were credited anyway (due to CREATURE_FLAG_EXTRA_NO_PLAYER_DAMAGE_REQ), scale XP gained appropriately (linear scaling)
185  xpMod *= 1.0f - 2.0f*creature->m_PlayerDamageReq / creature->GetMaxHealth();
186 
187  gain = uint32(gain * xpMod);
188  }
189 
190  sScriptMgr->OnGainCalculation(gain, player, u);
191  return gain;
192  }
uint32 GetExpansionForLevel(uint32 level)
Definition: DBCStores.cpp:632
int32 expansion
Definition: Creature.h:95
uint32 GetMaxHealth() const
Definition: Unit.h:1427
Map * GetMap() const
Definition: Object.h:543
double round(double f)
Definition: g3dmath.h:214
float ModExperience
Definition: Creature.h:137
Definition: World.h:403
bool IsDungeon() const
Definition: Map.h:395
Definition: Creature.h:467
uint32 flags_extra
Definition: Creature.h:142
#define sWorld
Definition: World.h:887
uint8 getLevel() const
Definition: Unit.h:1408
uint32 m_PlayerDamageReq
Definition: Creature.h:697
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:558
Definition: World.h:402
uint32_t uint32
Definition: Define.h:150
bool IsPet() const
Definition: Unit.h:1403
Definition: Creature.h:48
bool IsTotem() const
Definition: Unit.h:1405
bool IsCritter() const
Definition: Unit.h:1580
Creature * ToCreature()
Definition: Object.h:194
bool isElite() const
Definition: Creature.cpp:1824
#define sScriptMgr
Definition: ScriptMgr.h:837
uint32_t uint32
Definition: g3dmath.h:168
uint32 BaseGain(uint8 pl_level, uint8 mob_level)
Definition: Formulas.h:119

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

XPColorChar Trinity::XP::GetColorCode ( uint8  pl_level,
uint8  mob_level 
)
inline
68  {
69  XPColorChar color;
70 
71  if (mob_level >= pl_level + 5)
72  color = XP_RED;
73  else if (mob_level >= pl_level + 3)
74  color = XP_ORANGE;
75  else if (mob_level >= pl_level - 2)
76  color = XP_YELLOW;
77  else if (mob_level > GetGrayLevel(pl_level))
78  color = XP_GREEN;
79  else
80  color = XP_GRAY;
81 
82  sScriptMgr->OnColorCodeCalculation(color, pl_level, mob_level);
83  return color;
84  }
Definition: SharedDefines.h:4682
Definition: SharedDefines.h:4679
Definition: SharedDefines.h:4681
XPColorChar
Definition: SharedDefines.h:4676
uint8 GetGrayLevel(uint8 pl_level)
Definition: Formulas.h:46
Definition: SharedDefines.h:4678
Definition: SharedDefines.h:4680
#define sScriptMgr
Definition: ScriptMgr.h:837

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint8 Trinity::XP::GetGrayLevel ( uint8  pl_level)
inline
47  {
48  uint8 level;
49 
50  if (pl_level < 7)
51  level = 0;
52  else if (pl_level < 35)
53  {
54  uint8 count = 0;
55  for (int i = 15; i <= pl_level; ++i)
56  if (i % 5 == 0) ++count;
57 
58  level = (pl_level - 7) - (count - 1);
59  }
60  else
61  level = pl_level - 10;
62 
63  sScriptMgr->OnGrayLevelCalculation(level, pl_level);
64  return level;
65  }
uint8_t uint8
Definition: Define.h:152
#define sScriptMgr
Definition: ScriptMgr.h:837

+ Here is the caller graph for this function:

uint8 Trinity::XP::GetZeroDifference ( uint8  pl_level)
inline
87  {
88  uint8 diff;
89 
90  if (pl_level < 4)
91  diff = 5;
92  else if (pl_level < 10)
93  diff = 6;
94  else if (pl_level < 12)
95  diff = 7;
96  else if (pl_level < 16)
97  diff = 8;
98  else if (pl_level < 20)
99  diff = 9;
100  else if (pl_level < 30)
101  diff = 11;
102  else if (pl_level < 40)
103  diff = 12;
104  else if (pl_level < 45)
105  diff = 13;
106  else if (pl_level < 50)
107  diff = 14;
108  else if (pl_level < 55)
109  diff = 15;
110  else if (pl_level < 60)
111  diff = 16;
112  else
113  diff = 17;
114 
115  sScriptMgr->OnZeroDifferenceCalculation(diff, pl_level);
116  return diff;
117  }
uint8_t uint8
Definition: Define.h:152
#define sScriptMgr
Definition: ScriptMgr.h:837

+ Here is the caller graph for this function:

float Trinity::XP::xp_in_group_rate ( uint32  count,
bool  isRaid 
)
inline
195  {
196  float rate;
197 
198  if (isRaid)
199  {
200  // FIXME: Must apply decrease modifiers depending on raid size.
201  // set to < 1 to, so client will display raid related strings
202  rate = 0.99f;
203  }
204  else
205  {
206  switch (count)
207  {
208  case 0:
209  case 1:
210  case 2:
211  rate = 1.0f;
212  break;
213  case 3:
214  rate = 1.166f;
215  break;
216  case 4:
217  rate = 1.3f;
218  break;
219  case 5:
220  default:
221  rate = 1.4f;
222  }
223  }
224 
225  sScriptMgr->OnGroupRateCalculation(rate, count, isRaid);
226  return rate;
227  }
#define sScriptMgr
Definition: ScriptMgr.h:837

+ Here is the caller graph for this function: