Use inline functions

This commit is contained in:
EmosewaMC 2023-04-14 01:32:52 -07:00
parent 41355cea58
commit ed2639ce4e
2 changed files with 63 additions and 15 deletions

View File

@ -10,19 +10,23 @@
#include "CDClientManager.h" #include "CDClientManager.h"
#include "GeneralUtils.h" #include "GeneralUtils.h"
#include "Entity.h" #include "Entity.h"
#include "LDFFormat.h"
#include <sstream> #include <sstream>
#include "CDActivitiesTable.h" #include "CDActivitiesTable.h"
#include "Metrics.hpp" #include "Metrics.hpp"
Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const Leaderboard::Type leaderboardType) { Leaderboard::Leaderboard(const GameID gameID, const Leaderboard::InfoType infoType, const bool weekly, const Leaderboard::Type leaderboardType) {
this->relatedPlayer = relatedPlayer;
this->gameID = gameID; this->gameID = gameID;
this->weekly = weekly; this->weekly = weekly;
this->infoType = infoType; this->infoType = infoType;
this->entries = entries;
this->leaderboardType = leaderboardType; this->leaderboardType = leaderboardType;
} }
template<class TypeToWrite>
void Leaderboard::WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, const std::string& key, const eLDFType& ldfType, const TypeToWrite& value) const {
leaderboard << "Result[0].Row[" << index << "]." << key << '=' << ldfType << ':' << value << '\n';
}
void Leaderboard::Serialize(RakNet::BitStream* bitStream) const { void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
std::ostringstream leaderboard; std::ostringstream leaderboard;
@ -33,20 +37,61 @@ void Leaderboard::Serialize(RakNet::BitStream* bitStream) const {
auto index = 0; auto index = 0;
for (const auto& entry : entries) { for (const auto& entry : entries) {
leaderboard << "Result[0].Row[" << index << "].LastPlayed=8:" << entry.lastPlayed << '\n'; WriteLeaderboardRow(leaderboard, index, "CharacterID", eLDFType::LDF_TYPE_U64, entry.playerID);
leaderboard << "Result[0].Row[" << index << "].CharacterID=8:" << entry.playerID << '\n'; WriteLeaderboardRow(leaderboard, index, "LastPlayed", eLDFType::LDF_TYPE_U64, entry.lastPlayed);
leaderboard << "Result[0].Row[" << index << "].NumPlayed=1:1\n"; // number of times the activity was played WriteLeaderboardRow(leaderboard, index, "NumPlayed", eLDFType::LDF_TYPE_S32, 1);
leaderboard << "Result[0].Row[" << index << "].RowNumber=8:" << entry.placement << '\n'; WriteLeaderboardRow(leaderboard, index, "name", eLDFType::LDF_TYPE_UTF_16, entry.playerName);
leaderboard << "Result[0].Row[" << index << "].Time=1:" << entry.time << '\n';
// Only these minigames have a points system // Each minigame has its own "points" system
if (leaderboardType == Survival || leaderboardType == ShootingGallery) { switch (leaderboardType) {
leaderboard << "Result[0].Row[" << index << "].Points=1:"<< entry.score << '\n'; case Type::ShootingGallery:
} else if (leaderboardType == SurvivalNS) { WriteLeaderboardRow(leaderboard, index, "HitPercentage", eLDFType::LDF_TYPE_FLOAT, 0.0f);
leaderboard << "Result[0].Row[" << index << "].Wave=1:"<< entry.score << '\n'; // HitPercentage:3 between 0 and 1
WriteLeaderboardRow(leaderboard, index, "RowNumber", eLDFType::LDF_TYPE_S32, entry.placement);
// RowNumber:1
WriteLeaderboardRow(leaderboard, index, "Score", eLDFType::LDF_TYPE_S32, entry.score);
// Score:1
case Type::Racing:
WriteLeaderboardRow(leaderboard, index, "BestLapTime", eLDFType::LDF_TYPE_FLOAT, 0.0f);
// BestLapTime:3
WriteLeaderboardRow(leaderboard, index, "BestTime", eLDFType::LDF_TYPE_FLOAT, 0.0f);
// BestTime:3
WriteLeaderboardRow(leaderboard, index, "License", eLDFType::LDF_TYPE_S32, 0);
// License:1
WriteLeaderboardRow(leaderboard, index, "NumWins", eLDFType::LDF_TYPE_S32, 0);
// NumWins:1
WriteLeaderboardRow(leaderboard, index, "RowNumber", eLDFType::LDF_TYPE_U64, entry.placement);
// RowNumber:8
case Type::MonumentRace:
WriteLeaderboardRow(leaderboard, index, "RowNumber", eLDFType::LDF_TYPE_S32, entry.placement);
// RowNumber:1
// Time:1(?)
case Type::FootRace:
WriteLeaderboardRow(leaderboard, index, "RowNumber", eLDFType::LDF_TYPE_S32, entry.placement);
// RowNumber:1
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, 0);
// Time:1
case Type::Survival:
WriteLeaderboardRow(leaderboard, index, "Points", eLDFType::LDF_TYPE_S32, entry.score);
// Points:1
WriteLeaderboardRow(leaderboard, index, "RowNumber", eLDFType::LDF_TYPE_S32, entry.placement);
// RowNumber:1
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, 0);
// Time:1
case Type::SurvivalNS:
WriteLeaderboardRow(leaderboard, index, "RowNumber", eLDFType::LDF_TYPE_U64, entry.placement);
// RowNumber:8
WriteLeaderboardRow(leaderboard, index, "Time", eLDFType::LDF_TYPE_S32, entry.time);
// Time:1
WriteLeaderboardRow(leaderboard, index, "Wave", eLDFType::LDF_TYPE_S32, entry.score);
// Wave:1
case Type::Donations:
// Something? idk yet.
case Type::None:
break;
default:
break;
} }
leaderboard << "Result[0].Row[" << index << "].name=0:" << entry.playerName << '\n';
index++; index++;
} }

View File

@ -5,6 +5,7 @@
#include "Singleton.h" #include "Singleton.h"
#include "dCommonVars.h" #include "dCommonVars.h"
#include "LDFFormat.h"
namespace RakNet{ namespace RakNet{
class BitStream; class BitStream;
@ -36,7 +37,7 @@ public:
Racing, Racing,
MonumentRace, MonumentRace,
FootRace, FootRace,
// There is no 4 // There is no 4 defined anywhere in the client or cdclient
Survival = 5, Survival = 5,
SurvivalNS, SurvivalNS,
Donations, Donations,
@ -77,6 +78,8 @@ public:
*/ */
void AddEntry(Entry entry) { entries.push_back(entry); } void AddEntry(Entry entry) { entries.push_back(entry); }
private: private:
template<class TypeToWrite>
inline void WriteLeaderboardRow(std::ostringstream& leaderboard, const uint32_t& index, const std::string& key, const eLDFType& ldfType, const TypeToWrite& value) const;
LeaderboardEntries entries; LeaderboardEntries entries;
LWOOBJID relatedPlayer; LWOOBJID relatedPlayer;
GameID gameID; GameID gameID;