2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_FORMULAS_H
20 #define MANGOS_FORMULAS_H
23 #include "Database/DatabaseEnv.h"
29 typedef enum XPColorChar
{ RED
, ORANGE
, YELLOW
, GREEN
, GRAY
};
31 inline uint32
GetGrayLevel(uint32 pl_level
)
35 else if( pl_level
<= 39 )
36 return pl_level
- 5 - pl_level
/10;
37 else if( pl_level
<= 59 )
38 return pl_level
- 1 - pl_level
/5;
43 inline XPColorChar
GetColorCode(uint32 pl_level
, uint32 mob_level
)
45 if( mob_level
>= pl_level
+ 5 )
47 else if( mob_level
>= pl_level
+ 3 )
49 else if( mob_level
>= pl_level
- 2 )
51 else if( mob_level
> GetGrayLevel(pl_level
) )
57 inline uint32
GetZeroDifference(uint32 pl_level
)
59 if( pl_level
< 8 ) return 5;
60 if( pl_level
< 10 ) return 6;
61 if( pl_level
< 12 ) return 7;
62 if( pl_level
< 16 ) return 8;
63 if( pl_level
< 20 ) return 9;
64 if( pl_level
< 30 ) return 11;
65 if( pl_level
< 40 ) return 12;
66 if( pl_level
< 45 ) return 13;
67 if( pl_level
< 50 ) return 14;
68 if( pl_level
< 55 ) return 15;
69 if( pl_level
< 60 ) return 16;
73 inline uint32
BaseGain(uint32 pl_level
, uint32 mob_level
)
75 if( mob_level
>= pl_level
)
76 return ((pl_level
*5 + 45) * (20 + mob_level
- pl_level
)/10 + 1)/2;
79 uint32 gray_level
= GetGrayLevel(pl_level
);
80 if( mob_level
> gray_level
)
82 uint32 ZD
= GetZeroDifference(pl_level
);
83 return (pl_level
*5 + 45) * (ZD
+ mob_level
- pl_level
)/ZD
;
89 inline uint32
Gain(Player
*pl
, Unit
*u
)
91 if(u
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)u
)->isTotem() || ((Creature
*)u
)->isPet())
94 uint32 xp_gain
= BaseGain(pl
->getLevel(), u
->getLevel());
98 if(u
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)u
)->isElite())
101 return (uint32
)(xp_gain
*sWorld
.getRate(RATE_XP_KILL
));
104 inline uint32
xp_Diff(uint32 lvl
)
118 inline uint32
mxp(uint32 lvl
)
122 return (45 + (5*lvl
));
126 return (235 + (5*lvl
));
130 inline uint32
xp_to_level(uint32 lvl
)
135 xp
= (8*lvl
+ xp_Diff(lvl
)) * mxp(lvl
);
139 xp
= (155 + mxp(lvl
) * (1344 - 69 - ((69 - lvl
) * (7 + (69 - lvl
) * 8 - 1)/2)));
143 xp
= (155 + mxp(lvl
) * (1344 - ((69-lvl
) * (7 + (69 - lvl
) * 8 - 1)/2)));
145 // The XP to Level is always rounded to the nearest 100 points (50 rounded to low).
146 return ((xp
+ 49) / 100) * 100; // use additional () for prevent free association operations in C++
149 inline uint32
xp_to_money(uint32 rewXP
, uint32 qlevel
)
155 else if (qlevel
== 14)
157 else if (qlevel
== 13)
159 else if (qlevel
== 12)
161 else if (qlevel
== 11)
163 else if (qlevel
> 0 && qlevel
<= 10)