Untitled diff

Created Diff never expires
11 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
85 lines
31 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
105 lines
void Player::addExperience(Creature* source, uint64_t exp, bool sendText/* = false*/)
void Player::addExperience(Creature* source, uint64_t exp, bool sendText/* = false*/)
{
{
uint16_t prevPassiveDamageBonus = passiveDamageBonus;
uint64_t currLevelExp = Player::getExpForLevel(level);
uint64_t currLevelExp = Player::getExpForLevel(level);
uint64_t nextLevelExp = Player::getExpForLevel(level + 1);
uint64_t nextLevelExp = Player::getExpForLevel(level + 1);
uint64_t rawExp = exp;
uint64_t rawExp = exp;
if (currLevelExp >= nextLevelExp) {
if (currLevelExp >= nextLevelExp) {
//player has reached max level
//player has reached max level
levelPercent = 0;
levelPercent = 0;
sendStats();
sendStats();
return;
return;
}
}


g_events->eventPlayerOnGainExperience(this, source, exp, rawExp);
g_events->eventPlayerOnGainExperience(this, source, exp, rawExp);
if (exp == 0) {
if (exp == 0) {
return;
return;
}
}


experience += exp;
experience += exp;


if (sendText) {
if (sendText) {
std::string expString = std::to_string(exp) + (exp != 1 ? " experience points." : " experience point.");
std::string expString = std::to_string(exp) + (exp != 1 ? " experience points." : " experience point.");


TextMessage message(MESSAGE_EXPERIENCE, "You gained " + expString);
TextMessage message(MESSAGE_EXPERIENCE, "You gained " + expString);
message.position = position;
message.position = position;
message.primary.value = exp;
message.primary.value = exp;
message.primary.color = TEXTCOLOR_WHITE_EXP;
message.primary.color = TEXTCOLOR_WHITE_EXP;
sendTextMessage(message);
sendTextMessage(message);


SpectatorHashSet spectators;
SpectatorHashSet spectators;
g_game.map.getSpectators(spectators, position, false, true);
g_game.map.getSpectators(spectators, position, false, true);
spectators.erase(this);
spectators.erase(this);
if (!spectators.empty()) {
if (!spectators.empty()) {
message.type = MESSAGE_EXPERIENCE_OTHERS;
message.type = MESSAGE_EXPERIENCE_OTHERS;
message.text = getName() + " gained " + expString;
message.text = getName() + " gained " + expString;
for (Creature* spectator : spectators) {
for (Creature* spectator : spectators) {
spectator->getPlayer()->sendTextMessage(message);
spectator->getPlayer()->sendTextMessage(message);
}
}
}
}
}
}


uint32_t prevLevel = level;
uint32_t prevLevel = level;
while (experience >= nextLevelExp) {
while (experience >= nextLevelExp) {
++level;
++level;
healthMax += vocation->getHPGain();
//custom edit: max level / passiveDamageBonus
health += vocation->getHPGain();
if (level > (uint32_t)g_config.getNumber(ConfigManager::MAX_LEVEL))
manaMax += vocation->getManaGain();
{
mana += vocation->getManaGain();
if (passiveDamageBonus < g_config.getNumber(ConfigManager::MAX_PASSIVE_DAMAGE_BONUS))
capacity += vocation->getCapGain();
{

passiveDamageBonus++;
currLevelExp = nextLevelExp;
}
nextLevelExp = Player::getExpForLevel(level + 1);
level = g_config.getNumber(ConfigManager::MAX_LEVEL);
if (currLevelExp >= nextLevelExp) {
// reduzir a exp equivalente a um level.. caso ele upe dois ou mais, vai executar o loop 2x
//player has reached max level
experience -= getExpForLevel(g_config.getNumber(ConfigManager::MAX_LEVEL)+1) - getExpForLevel(g_config.getNumber(ConfigManager::MAX_LEVEL));
break;
}
else
{
healthMax += vocation->getHPGain();
health += vocation->getHPGain();
manaMax += vocation->getManaGain();
mana += vocation->getManaGain();
capacity += vocation->getCapGain();
currLevelExp = nextLevelExp;
nextLevelExp = Player::getExpForLevel(level + 1);
if (currLevelExp >= nextLevelExp) {
//player has reached max level
break;
}
}
}
}
}


if (prevLevel != level) {
if (prevLevel != level) {
health = healthMax;
health = healthMax;
mana = manaMax;
mana = manaMax;


updateBaseSpeed();
updateBaseSpeed();
setBaseSpeed(getBaseSpeed());
setBaseSpeed(getBaseSpeed());


g_game.changeSpeed(this, 0);
g_game.changeSpeed(this, 0);
g_game.addCreatureHealth(this);
g_game.addCreatureHealth(this);


if (party) {
if (party) {
party->updateSharedExperience();
party->updateSharedExperience();
}
}


g_creatureEvents->playerAdvance(this, SKILL_LEVEL, prevLevel, level);
g_creatureEvents->playerAdvance(this, SKILL_LEVEL, prevLevel, level);


std::ostringstream ss;
std::ostringstream ss;
ss << "You advanced from Level " << prevLevel << " to Level " << level << '.';
ss << "You advanced from Level " << prevLevel << " to Level " << level << '.';
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
sendTextMessage(MESSAGE_EVENT_ADVANCE, ss.str());
}
}
else if (prevPassiveDamageBonus != passiveDamageBonus)
{
std::ostringstream msgDamageBonus;
msgDamageBonus << "You are currently on maximum level. Your passive damage bonus advanced from " << prevPassiveDamageBonus << "% to " << passiveDamageBonus << "%.";
sendTextMessage(MESSAGE_EVENT_ADVANCE, msgDamageBonus.str());
}


if (nextLevelExp > currLevelExp) {
if (nextLevelExp > currLevelExp) {
levelPercent = Player::getPercentLevel(experience - currLevelExp, nextLevelExp - currLevelExp);
levelPercent = Player::getPercentLevel(experience - currLevelExp, nextLevelExp - currLevelExp);
} else {
} else {
levelPercent = 0;
levelPercent = 0;
}
}
sendStats();
sendStats();
}
}