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

Revision 263, 6.7 kB (checked in by yumileroy, 17 years ago)

Some missing changes. This should fix the bug that loading char causes crash.
Please do not commit to the other tip (I do not know how to delete it).

Original author: megamage
Date: 2008-11-20 17:40:13-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21#ifndef TRINITY_FORMULAS_H
22#define TRINITY_FORMULAS_H
23
24#include "World.h"
25
26namespace Trinity
27{
28    namespace Honor
29    {
30        inline uint32 hk_honor_at_level(uint32 level, uint32 count=1)
31        {
32            return (uint32)ceil(count*(-0.53177f + 0.59357f * exp((level +23.54042f) / 26.07859f )));
33        }
34    }
35    namespace XP
36    {
37        typedef enum XPColorChar { RED, ORANGE, YELLOW, GREEN, GRAY };
38
39        inline uint32 GetGrayLevel(uint32 pl_level)
40        {
41            if( pl_level <= 5 )
42                return 0;
43            else if( pl_level <= 39 )
44                return pl_level - 5 - pl_level/10;
45            else if( pl_level <= 59 )
46                return pl_level - 1 - pl_level/5;
47            else
48                return pl_level - 9;
49        }
50
51        inline XPColorChar GetColorCode(uint32 pl_level, uint32 mob_level)
52        {
53            if( mob_level >= pl_level + 5 )
54                return RED;
55            else if( mob_level >= pl_level + 3 )
56                return ORANGE;
57            else if( mob_level >= pl_level - 2 )
58                return YELLOW;
59            else if( mob_level > GetGrayLevel(pl_level) )
60                return GREEN;
61            else
62                return GRAY;
63        }
64
65        inline uint32 GetZeroDifference(uint32 pl_level)
66        {
67            if( pl_level < 8 )  return 5;
68            if( pl_level < 10 ) return 6;
69            if( pl_level < 12 ) return 7;
70            if( pl_level < 16 ) return 8;
71            if( pl_level < 20 ) return 9;
72            if( pl_level < 30 ) return 11;
73            if( pl_level < 40 ) return 12;
74            if( pl_level < 45 ) return 13;
75            if( pl_level < 50 ) return 14;
76            if( pl_level < 55 ) return 15;
77            if( pl_level < 60 ) return 16;
78            return 17;
79        }
80
81        inline uint32 BaseGain(uint32 pl_level, uint32 mob_level, ContentLevels content)
82        {
83            //TODO: need modifier for CONTENT_71_80 different from CONTENT_61_70?
84            const uint32 nBaseExp = content == CONTENT_1_60 ? 45 : 235;
85            if( mob_level >= pl_level )
86            {
87                uint32 nLevelDiff = mob_level - pl_level;
88                if (nLevelDiff > 4)
89                    nLevelDiff = 4;
90                return ((pl_level*5 + nBaseExp) * (20 + nLevelDiff)/10 + 1)/2;
91            }
92            else
93            {
94                uint32 gray_level = GetGrayLevel(pl_level);
95                if( mob_level > gray_level )
96                {
97                    uint32 ZD = GetZeroDifference(pl_level);
98                    return (pl_level*5 + nBaseExp) * (ZD + mob_level - pl_level)/ZD;
99                }
100                return 0;
101            }
102        }
103
104        inline uint32 Gain(Player *pl, Unit *u)
105        {
106            if(u->GetTypeId()==TYPEID_UNIT && (
107                ((Creature*)u)->isTotem() || ((Creature*)u)->isPet() ||
108                (((Creature*)u)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL) ))
109                return 0;
110
111            uint32 xp_gain= BaseGain(pl->getLevel(), u->getLevel(), GetContentLevelsForMapAndZone(pl->GetMapId(),pl->GetZoneId()));
112            if( xp_gain == 0 )
113                return 0;
114
115            if(u->GetTypeId()==TYPEID_UNIT && ((Creature*)u)->isElite())
116                xp_gain *= 2;
117
118            return (uint32)(xp_gain*sWorld.getRate(RATE_XP_KILL));
119        }
120
121        inline uint32 xp_Diff(uint32 lvl)
122        {
123            if( lvl < 29 )
124                return 0;
125            if( lvl == 29 )
126                return 1;
127            if( lvl == 30 )
128                return 3;
129            if( lvl == 31 )
130                return 6;
131            else
132                return (5*(lvl-30));
133        }
134
135        inline uint32 mxp(uint32 lvl)
136        {
137            if (lvl < 60)
138            {
139                return (45 + (5*lvl));
140            }
141            else
142            {
143                return (235 + (5*lvl));
144            }
145        }
146
147        inline uint32 xp_to_level(uint32 lvl)
148        {
149            uint32 xp = 0;
150            if (lvl < 60)
151            {
152                xp = (8*lvl + xp_Diff(lvl)) * mxp(lvl);
153            }
154            else if (lvl == 60)
155            {
156                xp = (155 + mxp(lvl) * (1344 - 70 - ((69 - lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
157            }
158            else if (lvl < 70)
159            {
160                xp = (155 + mxp(lvl) * (1344 - ((69-lvl) * (7 + (69 - lvl) * 8 - 1)/2)));
161            }else
162            {
163                // level higher than 70 is not supported
164                xp = (uint32)(779700 * (pow(sWorld.getRate(RATE_XP_PAST_70), (int32)lvl - 69)));
165                return ((xp < 0x7fffffff) ? xp : 0x7fffffff);
166            }
167
168            // The XP to Level is always rounded to the nearest 100 points (50 rounded to high).
169            xp = ((xp + 50) / 100) * 100;                   // use additional () for prevent free association operations in C++
170
171            if ((lvl > 10) && (lvl < 60))                   // compute discount added in 2.3.x
172            {
173                uint32 discount = (lvl < 28) ? (lvl - 10) : 18;
174                xp = (xp * (100 - discount)) / 100;         // apply discount
175                xp = (xp / 100) * 100;                      // floor to hundreds
176            }
177
178            return xp;
179        }
180
181        inline float xp_in_group_rate(uint32 count, bool isRaid)
182        {
183            if(isRaid)
184            {
185                // FIX ME: must apply decrease modifiers dependent from raid size
186                return 1.0f;
187            }
188            else
189            {
190                switch(count)
191                {
192                    case 0:
193                    case 1:
194                    case 2:
195                        return 1.0f;
196                    case 3:
197                        return 1.166f;
198                    case 4:
199                        return 1.3f;
200                    case 5:
201                    default:
202                        return 1.4f;
203                }
204            }
205        }
206    }
207}
208#endif
Note: See TracBrowser for help on using the browser.