root/trunk/src/game/Formulas.h @ 19

Revision 2, 6.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef MANGOS_FORMULAS_H
20#define MANGOS_FORMULAS_H
21
22#include "World.h"
23
24namespace MaNGOS
25{
26    namespace XP
27    {
28        typedef enum XPColorChar { RED, ORANGE, YELLOW, GREEN, GRAY };
29
30        inline uint32 GetGrayLevel(uint32 pl_level)
31        {
32            if( pl_level <= 5 )
33                return 0;
34            else if( pl_level <= 39 )
35                return pl_level - 5 - pl_level/10;
36            else if( pl_level <= 59 )
37                return pl_level - 1 - pl_level/5;
38            else
39                return pl_level - 9;
40        }
41
42        inline XPColorChar GetColorCode(uint32 pl_level, uint32 mob_level)
43        {
44            if( mob_level >= pl_level + 5 )
45                return RED;
46            else if( mob_level >= pl_level + 3 )
47                return ORANGE;
48            else if( mob_level >= pl_level - 2 )
49                return YELLOW;
50            else if( mob_level > GetGrayLevel(pl_level) )
51                return GREEN;
52            else
53                return GRAY;
54        }
55
56        inline uint32 GetZeroDifference(uint32 pl_level)
57        {
58            if( pl_level < 8 )  return 5;
59            if( pl_level < 10 ) return 6;
60            if( pl_level < 12 ) return 7;
61            if( pl_level < 16 ) return 8;
62            if( pl_level < 20 ) return 9;
63            if( pl_level < 30 ) return 11;
64            if( pl_level < 40 ) return 12;
65            if( pl_level < 45 ) return 13;
66            if( pl_level < 50 ) return 14;
67            if( pl_level < 55 ) return 15;
68            if( pl_level < 60 ) return 16;
69            return 17;
70        }
71
72        inline uint32 BaseGain(uint32 pl_level, uint32 mob_level, ContentLevels content)
73        {
74            const uint32 nBaseExp = content == CONTENT_1_60 ? 45 : 235;
75            if( mob_level >= pl_level )
76            {
77                uint32 nLevelDiff = mob_level - pl_level;
78                if (nLevelDiff > 4)
79                    nLevelDiff = 4;
80                return ((pl_level*5 + nBaseExp) * (20 + nLevelDiff)/10 + 1)/2;
81            }
82            else
83            {
84                uint32 gray_level = GetGrayLevel(pl_level);
85                if( mob_level > gray_level )
86                {
87                    uint32 ZD = GetZeroDifference(pl_level);
88                    return (pl_level*5 + nBaseExp) * (ZD + mob_level - pl_level)/ZD;
89                }
90                return 0;
91            }
92        }
93
94        inline uint32 Gain(Player *pl, Unit *u)
95        {
96            if(u->GetTypeId()==TYPEID_UNIT && (
97                ((Creature*)u)->isTotem() || ((Creature*)u)->isPet() ||
98                (((Creature*)u)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL) ))
99                return 0;
100
101            uint32 xp_gain= BaseGain(pl->getLevel(), u->getLevel(), GetContentLevelsForMapAndZone(pl->GetMapId(),pl->GetZoneId()));
102            if( xp_gain == 0 )
103                return 0;
104
105            if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isElite())
106                xp_gain *= 2;
107
108            return (uint32)(xp_gain*sWorld.getRate(RATE_XP_KILL));
109        }
110
111        inline uint32 xp_Diff(uint32 lvl)
112        {
113            if( lvl < 29 )
114                return 0;
115            if( lvl == 29 )
116                return 1;
117            if( lvl == 30 )
118                return 3;
119            if( lvl == 31 )
120                return 6;
121            else
122                return (5*(lvl-30));
123        }
124
125        inline uint32 mxp(uint32 lvl)
126        {
127            if (lvl < 60)
128            {
129                return (45 + (5*lvl));
130            }
131            else
132            {
133                return (235 + (5*lvl));
134            }
135        }
136
137        inline uint32 xp_to_level(uint32 lvl)
138        {
139            uint32 xp = 0;
140            if (lvl < 60)
141            {
142                xp = (8*lvl + xp_Diff(lvl)) * mxp(lvl);
143            }
144            else if (lvl == 60)
145            {
146                xp = (155 + mxp(lvl) * (1344 - 70 - ((69 - lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
147            }
148            else if (lvl < 70)
149            {
150                xp = (155 + mxp(lvl) * (1344 - ((69-lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
151            }else
152            {
153                // level higher than 70 is not supported
154                xp = (uint32)(779700 * (pow(sWorld.getRate(RATE_XP_PAST_70), (int32)lvl - 69)));
155                return ((xp < 0x7fffffff) ? xp : 0x7fffffff);
156            }
157
158            // The XP to Level is always rounded to the nearest 100 points (50 rounded to high).
159            xp = ((xp + 50) / 100) * 100;                   // use additional () for prevent free association operations in C++
160
161            if ((lvl > 10) && (lvl < 60))                   // compute discount added in 2.3.x
162            {
163                uint32 discount = (lvl < 28) ? (lvl - 10) : 18;
164                xp = (xp * (100 - discount)) / 100;         // apply discount
165                xp = (xp / 100) * 100;                      // floor to hundreds
166            }
167
168            return xp;
169        }
170
171        inline float xp_in_group_rate(uint32 count, bool isRaid)
172        {
173            if(isRaid)
174            {
175                // FIX ME: must apply decrease modifiers dependent from raid size
176                return 1.0f;
177            }
178            else
179            {
180                switch(count)
181                {
182                    case 0:
183                    case 1:
184                    case 2:
185                        return 1.0f;
186                    case 3:
187                        return 1.166f;
188                    case 4:
189                        return 1.3f;
190                    case 5:
191                    default:
192                        return 1.4f;
193                }
194            }
195        }
196    }
197}
198#endif
Note: See TracBrowser for help on using the browser.