OregonCore  revision 3611e8a-git
Your Favourite TBC server
Formulas.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 #ifndef OREGON_FORMULAS_H
19 #define OREGON_FORMULAS_H
20 
21 #include "World.h"
22 
23 namespace Oregon
24 {
25 namespace Honor
26 {
27 inline uint32 hk_honor_at_level(uint32 level, uint32 count = 1)
28 {
29  return (uint32)ceil(count * (-0.53177f + 0.59357f * exp((level + 23.54042f) / 26.07859f)));
30 }
31 }
32 namespace XP
33 {
35 
36 inline uint32 GetGrayLevel(uint32 pl_level)
37 {
38  if (pl_level <= 5)
39  return 0;
40  else if (pl_level <= 39)
41  return pl_level - 5 - pl_level / 10;
42  else if (pl_level <= 59)
43  return pl_level - 1 - pl_level / 5;
44  else
45  return pl_level - 9;
46 }
47 
48 inline XPColorChar GetColorCode(uint32 pl_level, uint32 mob_level)
49 {
50  if (mob_level >= pl_level + 5)
51  return RED;
52  else if (mob_level >= pl_level + 3)
53  return ORANGE;
54  else if (mob_level >= pl_level - 2)
55  return YELLOW;
56  else if (mob_level > GetGrayLevel(pl_level))
57  return GREEN;
58  else
59  return GRAY;
60 }
61 
63 {
64  if (pl_level < 8) return 5;
65  if (pl_level < 10) return 6;
66  if (pl_level < 12) return 7;
67  if (pl_level < 16) return 8;
68  if (pl_level < 20) return 9;
69  if (pl_level < 30) return 11;
70  if (pl_level < 40) return 12;
71  if (pl_level < 45) return 13;
72  if (pl_level < 50) return 14;
73  if (pl_level < 55) return 15;
74  if (pl_level < 60) return 16;
75  return 17;
76 }
77 
78 inline uint32 BaseGain(uint32 pl_level, uint32 mob_level, ContentLevels content)
79 {
80  const uint32 nBaseExp = content == CONTENT_1_60 ? 45 : 235;
81  if (mob_level >= pl_level)
82  {
83  uint32 nLevelDiff = mob_level - pl_level;
84  if (nLevelDiff > 4)
85  nLevelDiff = 4;
86  return ((pl_level * 5 + nBaseExp) * (20 + nLevelDiff) / 10 + 1) / 2;
87  }
88  else
89  {
90  uint32 gray_level = GetGrayLevel(pl_level);
91  if (mob_level > gray_level)
92  {
93  uint32 ZD = GetZeroDifference(pl_level);
94  return (pl_level * 5 + nBaseExp) * (ZD + mob_level - pl_level) / ZD;
95  }
96  return 0;
97  }
98 }
99 
100 inline uint32 Gain(Player* pl, Unit* u)
101 {
102  if (u->GetTypeId() == TYPEID_UNIT && (
103  ((Creature*)u)->IsTotem() || ((Creature*)u)->IsPet() ||
104  (((Creature*)u)->GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL) ||
106  return 0;
107 
108  uint32 xp_gain = BaseGain(pl->getLevel(), u->getLevel(), GetContentLevelsForMapAndZone(u->GetMapId(), u->GetZoneId()));
109  if (xp_gain == 0)
110  return 0;
111 
112  if (u->GetTypeId() == TYPEID_UNIT && ((Creature*)u)->isElite())
113  xp_gain *= 2;
114 
115  return (uint32)(xp_gain * sWorld.getRate(RATE_XP_KILL));
116 }
117 
118 inline uint32 Gain(Pet* pet, Unit* u)
119 {
120  if (u->GetTypeId() == TYPEID_UNIT && (
121  ((Creature*)u)->IsTotem() || ((Creature*)u)->IsPet() ||
122  (((Creature*)u)->GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL)))
123  return 0;
124 
125  uint32 xp_gain = BaseGain(pet->getLevel(), u->getLevel(), GetContentLevelsForMapAndZone(u->GetMapId(), u->GetZoneId()));
126  if (xp_gain == 0)
127  return 0;
128 
129  if (u->GetTypeId() == TYPEID_UNIT && ((Creature*)u)->isElite())
130  xp_gain *= 2;
131 
132  return (uint32)(xp_gain * sWorld.getRate(RATE_XP_KILL));
133 }
134 
135 inline uint32 xp_Diff(uint32 lvl)
136 {
137  if (lvl < 29)
138  return 0;
139  if (lvl == 29)
140  return 1;
141  if (lvl == 30)
142  return 3;
143  if (lvl == 31)
144  return 6;
145  else
146  return (5 * (lvl - 30));
147 }
148 
149 inline uint32 mxp(uint32 lvl)
150 {
151  if (lvl < 60)
152  return (45 + (5 * lvl));
153  else
154  return (235 + (5 * lvl));
155 }
156 
158 {
159  uint32 xp = 0;
160  if (lvl < 60)
161  xp = (8 * lvl + xp_Diff(lvl)) * mxp(lvl);
162  else if (lvl == 60)
163  xp = (155 + mxp(lvl) * (1344 - 70 - ((69 - lvl) * (7 + (69 - lvl) * 8 - 1) / 2)));
164  else if (lvl < 70)
165  xp = (155 + mxp(lvl) * (1344 - ((69 - lvl) * (7 + (69 - lvl) * 8 - 1) / 2)));
166  else
167  {
168  // level higher than 70 is not supported
169  xp = (uint32)(779700 * (pow(sWorld.getRate(RATE_XP_PAST_70), (int32)lvl - 69)));
170  return ((xp < 0x7fffffff) ? xp : 0x7fffffff);
171  }
172 
173  // The XP to Level is always rounded to the nearest 100 points (50 rounded to high).
174  xp = ((xp + 50) / 100) * 100; // use additional () for prevent free association operations in C++
175 
176  if ((lvl > 10) && (lvl < 60)) // compute discount added in 2.3.x
177  {
178  uint32 discount = (lvl < 28) ? (lvl - 10) : 18;
179  xp = (xp * (100 - discount)) / 100; // apply discount
180  xp = (xp / 100) * 100; // floor to hundreds
181  }
182 
183  return xp;
184 }
185 
186 inline float xp_in_group_rate(uint32 count, bool isRaid)
187 {
188  if (isRaid)
189  {
190  // FIX ME: must apply decrease modifiers dependent from raid size
191  return 1.0f;
192  }
193  else
194  {
195  switch (count)
196  {
197  case 0:
198  case 1:
199  case 2:
200  return 1.0f;
201  case 3:
202  return 1.166f;
203  case 4:
204  return 1.3f;
205  case 5:
206  default:
207  return 1.4f;
208  }
209  }
210 }
211 }
212 }
213 #endif
214 
CreatureInfo const * GetCreatureTemplate(uint32 id)
Definition: ObjectMgr.cpp:7615
float xp_in_group_rate(uint32 count, bool isRaid)
Definition: Formulas.h:186
uint32 mxp(uint32 lvl)
Definition: Formulas.h:149
uint32 Gain(Pet *pet, Unit *u)
Definition: Formulas.h:118
XPColorChar GetColorCode(uint32 pl_level, uint32 mob_level)
Definition: Formulas.h:48
uint32 GetGrayLevel(uint32 pl_level)
Definition: Formulas.h:36
Definition: Log.h:71
ACE_INT32 int32
Definition: Define.h:67
uint8 GetTypeId() const
Definition: Object.h:204
Definition: Log.h:80
uint32 type
Definition: Creature.h:173
uint32 xp_to_level(uint32 lvl)
Definition: Formulas.h:157
uint32 xp_Diff(uint32 lvl)
Definition: Formulas.h:135
uint32 BaseGain(uint32 pl_level, uint32 mob_level, ContentLevels content)
Definition: Formulas.h:78
Definition: Log.h:70
uint32 hk_honor_at_level(uint32 level, uint32 count=1)
Definition: Formulas.h:27
#define sWorld
Definition: World.h:860
uint32 GetZeroDifference(uint32 pl_level)
Definition: Formulas.h:62
ACE_UINT32 uint32
Definition: Define.h:71
ContentLevels
Definition: DBCStores.h:46
Definition: Unit.h:884
uint32 getLevel() const
Definition: Unit.h:1029
Definition: Player.h:922
Definition: Pet.h:146
ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId)
Definition: DBCStores.cpp:663