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