Skip to content

Commit

Permalink
feat: exp tracker (otland#3999)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturKnopik committed Mar 10, 2022
1 parent 904abe6 commit bdf8fa1
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ forceMonsterTypesOnLoad = true
cleanProtectionZones = false
luaItemDesc = false
showPlayerLogInConsole = true
analyserSendTrueRawExp = false

-- VIP and Depot limits
-- NOTE: you can set custom limits per group in data/XML/groups.xml
Expand Down
1 change: 1 addition & 0 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ bool ConfigManager::load()
boolean[REMOVE_ON_DESPAWN] = getGlobalBoolean(L, "removeOnDespawn", true);
boolean[PLAYER_CONSOLE_LOGS] = getGlobalBoolean(L, "showPlayerLogInConsole", true);
boolean[TWO_FACTOR_AUTH] = getGlobalBoolean(L, "enableTwoFactorAuth", true);
boolean[EXP_ANALYSER_SEND_TRUE_RAW_EXP] = getGlobalBoolean(L, "analyserSendTrueRawExp", false);

string[DEFAULT_PRIORITY] = getGlobalString(L, "defaultPriority", "high");
string[SERVER_NAME] = getGlobalString(L, "serverName", "");
Expand Down
1 change: 1 addition & 0 deletions src/configmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ConfigManager
REMOVE_ON_DESPAWN,
PLAYER_CONSOLE_LOGS,
TWO_FACTOR_AUTH,
EXP_ANALYSER_SEND_TRUE_RAW_EXP,

LAST_BOOLEAN_CONFIG /* this must be the last one */
};
Expand Down
1 change: 1 addition & 0 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@ void LuaScriptInterface::registerFunctions()
registerEnumIn("configKeys", ConfigManager::MAX_PACKETS_PER_SECOND)
registerEnumIn("configKeys", ConfigManager::PLAYER_CONSOLE_LOGS)
registerEnumIn("configKeys", ConfigManager::TWO_FACTOR_AUTH)
registerEnumIn("configKeys", ConfigManager::EXP_ANALYSER_SEND_TRUE_RAW_EXP)

// os
registerMethod("os", "mtime", LuaScriptInterface::luaSystemTime);
Expand Down
7 changes: 7 additions & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,11 @@ void Player::addExperience(Creature* source, uint64_t exp, bool sendText/* = fal
levelPercent = 0;
}
sendStats();
if (g_config.getBoolean(ConfigManager::EXP_ANALYSER_SEND_TRUE_RAW_EXP)) {
sendExperienceTracker(rawExp, exp);
} else {
sendExperienceTracker(rawExp * g_config.getExperienceStage(getLevel()), exp);
}
}

void Player::removeExperience(uint64_t exp, bool sendText/* = false*/)
Expand Down Expand Up @@ -1904,6 +1909,8 @@ void Player::removeExperience(uint64_t exp, bool sendText/* = false*/)
levelPercent = 0;
}
sendStats();

sendExperienceTracker(0, -static_cast<int64_t>(exp));
}

uint8_t Player::getPercentLevel(uint64_t count, uint64_t nextLevelCount)
Expand Down
7 changes: 7 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,13 @@ class Player final : public Creature, public Cylinder
}
}
void sendStats();

void sendExperienceTracker(int64_t rawExp, int64_t finalExp) const {
if (client) {
client->sendExperienceTracker(rawExp, finalExp);
}
}

void sendBasicData() const {
if (client) {
client->sendBasicData();
Expand Down
9 changes: 9 additions & 0 deletions src/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,15 @@ void ProtocolGame::sendStats()
writeToOutputBuffer(msg);
}

void ProtocolGame::sendExperienceTracker(int64_t rawExp, int64_t finalExp)
{
NetworkMessage msg;
msg.addByte(0xAF);
msg.add<int64_t>(rawExp);
msg.add<int64_t>(finalExp);
writeToOutputBuffer(msg);
}

void ProtocolGame::sendClientFeatures()
{
NetworkMessage msg;
Expand Down
1 change: 1 addition & 0 deletions src/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class ProtocolGame final : public Protocol
void sendCancelTarget();
void sendCreatureOutfit(const Creature* creature, const Outfit_t& outfit);
void sendStats();
void sendExperienceTracker(int64_t rawExp, int64_t finalExp);
void sendClientFeatures();
void sendBasicData();
void sendTextMessage(const TextMessage& message);
Expand Down

0 comments on commit bdf8fa1

Please sign in to comment.