DarkflameServer/dGame/dComponents/CharacterComponent.cpp

838 lines
26 KiB
C++
Raw Permalink Normal View History

#include "CharacterComponent.h"
#include "BitStream.h"
#include "tinyxml2.h"
#include "Game.h"
#include "Logger.h"
#include "GeneralUtils.h"
#include "dServer.h"
#include "dZoneManager.h"
#include "CDClientManager.h"
#include "InventoryComponent.h"
#include "ControllablePhysicsComponent.h"
#include "EntityManager.h"
#include "HavokVehiclePhysicsComponent.h"
2022-02-13 05:03:04 +00:00
#include "GameMessages.h"
#include "Item.h"
#include "Amf3.h"
#include "eGameMasterLevel.h"
#include "eGameActivity.h"
#include "User.h"
#include "Database.h"
#include "CDRewardCodesTable.h"
#include "Mail.h"
#include "ZoneInstanceManager.h"
#include "WorldPackets.h"
#include <ctime>
CharacterComponent::CharacterComponent(Entity* parent, Character* character, const SystemAddress& systemAddress) : Component(parent) {
m_Character = character;
m_IsRacing = false;
m_IsGM = false;
m_IsLanding = false;
m_IsLEGOClubMember = true;
m_DirtyCurrentActivity = false;
m_DirtyGMInfo = false;
m_DirtySocialInfo = false;
m_PvpEnabled = false;
m_GMLevel = character->GetGMLevel();
m_EditorEnabled = false;
m_EditorLevel = m_GMLevel;
2022-07-28 13:39:57 +00:00
m_Reputation = 0;
m_CurrentActivity = eGameActivity::NONE;
m_CountryCode = 0;
m_LastUpdateTimestamp = std::time(nullptr);
m_SystemAddress = systemAddress;
}
bool CharacterComponent::LandingAnimDisabled(int zoneID) {
switch (zoneID) {
case 0:
case 556:
case 1101:
case 1202:
case 1203:
case 1204:
case 1261:
case 1301:
case 1302:
case 1303:
case 1401:
case 1402:
case 1403:
case 1603:
case 2001:
return true;
default:
return false;
}
return false;
}
CharacterComponent::~CharacterComponent() {
}
void CharacterComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) {
outBitStream.Write(m_ClaimCodes[0] != 0);
if (m_ClaimCodes[0] != 0) outBitStream.Write(m_ClaimCodes[0]);
outBitStream.Write(m_ClaimCodes[1] != 0);
if (m_ClaimCodes[1] != 0) outBitStream.Write(m_ClaimCodes[1]);
outBitStream.Write(m_ClaimCodes[2] != 0);
if (m_ClaimCodes[2] != 0) outBitStream.Write(m_ClaimCodes[2]);
outBitStream.Write(m_ClaimCodes[3] != 0);
if (m_ClaimCodes[3] != 0) outBitStream.Write(m_ClaimCodes[3]);
outBitStream.Write(m_Character->GetHairColor());
outBitStream.Write(m_Character->GetHairStyle());
outBitStream.Write<uint32_t>(0); //Default "head"
outBitStream.Write(m_Character->GetShirtColor());
outBitStream.Write(m_Character->GetPantsColor());
outBitStream.Write(m_Character->GetShirtStyle());
outBitStream.Write<uint32_t>(0); //Default "head color"
outBitStream.Write(m_Character->GetEyebrows());
outBitStream.Write(m_Character->GetEyes());
outBitStream.Write(m_Character->GetMouth());
outBitStream.Write<uint64_t>(0); //AccountID, trying out if 0 works.
outBitStream.Write(m_Character->GetLastLogin()); //Last login
outBitStream.Write<uint64_t>(0); //"prop mod last display time"
outBitStream.Write<uint64_t>(m_Uscore); //u-score
outBitStream.Write0(); //Not free-to-play (disabled in DLU)
//Stats:
outBitStream.Write(m_CurrencyCollected);
outBitStream.Write(m_BricksCollected);
outBitStream.Write(m_SmashablesSmashed);
outBitStream.Write(m_QuickBuildsCompleted);
outBitStream.Write(m_EnemiesSmashed);
outBitStream.Write(m_RocketsUsed);
outBitStream.Write(m_MissionsCompleted);
outBitStream.Write(m_PetsTamed);
outBitStream.Write(m_ImaginationPowerUpsCollected);
outBitStream.Write(m_LifePowerUpsCollected);
outBitStream.Write(m_ArmorPowerUpsCollected);
outBitStream.Write(m_MetersTraveled);
outBitStream.Write(m_TimesSmashed);
outBitStream.Write(m_TotalDamageTaken);
outBitStream.Write(m_TotalDamageHealed);
outBitStream.Write(m_TotalArmorRepaired);
outBitStream.Write(m_TotalImaginationRestored);
outBitStream.Write(m_TotalImaginationUsed);
outBitStream.Write(m_DistanceDriven);
outBitStream.Write(m_TimeAirborneInCar);
outBitStream.Write(m_RacingImaginationPowerUpsCollected);
outBitStream.Write(m_RacingImaginationCratesSmashed);
outBitStream.Write(m_RacingCarBoostsActivated);
outBitStream.Write(m_RacingTimesWrecked);
outBitStream.Write(m_RacingSmashablesSmashed);
outBitStream.Write(m_RacesFinished);
outBitStream.Write(m_FirstPlaceRaceFinishes);
outBitStream.Write0();
outBitStream.Write(m_IsLanding);
if (m_IsLanding) {
outBitStream.Write<uint16_t>(m_LastRocketConfig.size());
for (uint16_t character : m_LastRocketConfig) {
outBitStream.Write(character);
}
}
}
outBitStream.Write(m_DirtyGMInfo);
if (m_DirtyGMInfo) {
outBitStream.Write(m_PvpEnabled);
outBitStream.Write(m_IsGM);
outBitStream.Write(m_GMLevel);
outBitStream.Write(m_EditorEnabled);
outBitStream.Write(m_EditorLevel);
}
outBitStream.Write(m_DirtyCurrentActivity);
if (m_DirtyCurrentActivity) outBitStream.Write(m_CurrentActivity);
outBitStream.Write(m_DirtySocialInfo);
if (m_DirtySocialInfo) {
outBitStream.Write(m_GuildID);
outBitStream.Write<unsigned char>(m_GuildName.size());
if (!m_GuildName.empty())
outBitStream.WriteBits(reinterpret_cast<const unsigned char*>(m_GuildName.c_str()), static_cast<unsigned char>(m_GuildName.size()) * sizeof(wchar_t) * 8);
outBitStream.Write(m_IsLEGOClubMember);
outBitStream.Write(m_CountryCode);
}
}
2022-07-28 13:39:57 +00:00
bool CharacterComponent::GetPvpEnabled() const {
return m_PvpEnabled;
}
2022-07-28 13:39:57 +00:00
void CharacterComponent::SetPvpEnabled(const bool value) {
m_DirtyGMInfo = true;
m_PvpEnabled = value;
}
void CharacterComponent::SetGMLevel(eGameMasterLevel gmlevel) {
m_DirtyGMInfo = true;
if (gmlevel > eGameMasterLevel::CIVILIAN) m_IsGM = true;
else m_IsGM = false;
m_GMLevel = gmlevel;
}
void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
LOG("Failed to find char tag while loading XML!");
return;
}
2022-07-28 13:39:57 +00:00
if (character->QueryAttribute("rpt", &m_Reputation) == tinyxml2::XML_NO_ATTRIBUTE) {
SetReputation(0);
}
character->QueryUnsigned64Attribute("co", &m_ClaimCodes[0]);
character->QueryUnsigned64Attribute("co1", &m_ClaimCodes[1]);
character->QueryUnsigned64Attribute("co2", &m_ClaimCodes[2]);
character->QueryUnsigned64Attribute("co3", &m_ClaimCodes[3]);
AwardClaimCodes();
character->QueryInt64Attribute("ls", &m_Uscore);
// Load the statistics
2022-07-28 13:39:57 +00:00
const auto* statisticsAttribute = character->FindAttribute("stt");
if (statisticsAttribute) {
InitializeStatisticsFromString(std::string(statisticsAttribute->Value()));
} else {
InitializeEmptyStatistics();
}
// Load the zone statistics
m_ZoneStatistics = {};
auto zoneStatistics = character->FirstChildElement("zs");
if (zoneStatistics) {
auto child = zoneStatistics->FirstChildElement();
while (child) {
ZoneStatistics statistics = {};
child->QueryUnsigned64Attribute("ac", &statistics.m_AchievementsCollected);
child->QueryInt64Attribute("bc", &statistics.m_BricksCollected);
2022-07-28 13:39:57 +00:00
child->QueryUnsigned64Attribute("cc", &statistics.m_CoinsCollected);
child->QueryUnsigned64Attribute("es", &statistics.m_EnemiesSmashed);
child->QueryUnsigned64Attribute("qbc", &statistics.m_QuickBuildsCompleted);
uint32_t mapID;
child->QueryAttribute("map", &mapID);
m_ZoneStatistics.insert({ static_cast<LWOMAPID>(mapID), statistics });
2022-07-28 13:39:57 +00:00
child = child->NextSiblingElement();
}
}
const tinyxml2::XMLAttribute* rocketConfig = character->FindAttribute("lcbp");
if (rocketConfig) {
2022-08-02 13:56:20 +00:00
m_LastRocketConfig = GeneralUtils::ASCIIToUTF16(rocketConfig->Value());
2022-07-28 13:39:57 +00:00
} else {
m_LastRocketConfig = u"";
}
2022-07-28 13:39:57 +00:00
//
// Begin custom attributes
//
2022-07-28 13:39:57 +00:00
// Load the last rocket item ID
const tinyxml2::XMLAttribute* lastRocketItemID = character->FindAttribute("lrid");
if (lastRocketItemID) {
m_LastRocketItemID = lastRocketItemID->Int64Value();
}
2022-07-28 13:39:57 +00:00
//
// End custom attributes
//
if (m_GMLevel > eGameMasterLevel::CIVILIAN) {
m_IsGM = true;
m_DirtyGMInfo = true;
m_EditorLevel = m_GMLevel;
m_EditorEnabled = false; //We're not currently in HF if we're loading in
}
//Annoying guild bs:
2022-07-28 13:39:57 +00:00
const tinyxml2::XMLAttribute* guildName = character->FindAttribute("gn");
if (guildName) {
const char* gn = guildName->Value();
int64_t gid = 0;
character->QueryInt64Attribute("gid", &gid);
if (gid != 0) {
std::string guildname(gn);
2022-08-02 13:56:20 +00:00
m_GuildName = GeneralUtils::UTF8ToUTF16(guildname);
m_GuildID = gid;
m_DirtySocialInfo = true;
}
}
if (character->FindAttribute("time")) {
2022-07-28 13:39:57 +00:00
character->QueryUnsigned64Attribute("time", &m_TotalTimePlayed);
} else {
2022-07-28 13:39:57 +00:00
m_TotalTimePlayed = 0;
}
2022-08-08 14:34:33 +00:00
if (!m_Character) return;
//Check to see if we're landing:
if (m_Character->GetZoneID() != Game::server->GetZoneID()) {
m_IsLanding = true;
}
if (LandingAnimDisabled(m_Character->GetZoneID()) || LandingAnimDisabled(Game::server->GetZoneID()) || m_LastRocketConfig.empty()) {
m_IsLanding = false; //Don't make us land on VE/minigames lol
}
}
void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
2022-07-28 13:39:57 +00:00
tinyxml2::XMLElement* minifig = doc->FirstChildElement("obj")->FirstChildElement("mf");
2021-12-11 02:02:02 +00:00
if (!minifig) {
LOG("Failed to find mf tag while updating XML!");
2021-12-11 02:02:02 +00:00
return;
}
2022-07-28 13:39:57 +00:00
// write minifig information that might have been changed by commands
2021-12-11 02:02:02 +00:00
2022-07-28 13:39:57 +00:00
minifig->SetAttribute("es", m_Character->GetEyebrows());
minifig->SetAttribute("ess", m_Character->GetEyes());
minifig->SetAttribute("hc", m_Character->GetHairColor());
minifig->SetAttribute("hs", m_Character->GetHairStyle());
minifig->SetAttribute("l", m_Character->GetPantsColor());
minifig->SetAttribute("lh", m_Character->GetLeftHand());
minifig->SetAttribute("ms", m_Character->GetMouth());
minifig->SetAttribute("rh", m_Character->GetRightHand());
minifig->SetAttribute("t", m_Character->GetShirtColor());
2021-12-11 02:02:02 +00:00
2022-07-28 13:39:57 +00:00
// done with minifig
2021-12-11 02:02:02 +00:00
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
LOG("Failed to find char tag while updating XML!");
return;
}
if (m_ClaimCodes[0] != 0) character->SetAttribute("co", m_ClaimCodes[0]);
if (m_ClaimCodes[1] != 0) character->SetAttribute("co1", m_ClaimCodes[1]);
if (m_ClaimCodes[2] != 0) character->SetAttribute("co2", m_ClaimCodes[2]);
if (m_ClaimCodes[3] != 0) character->SetAttribute("co3", m_ClaimCodes[3]);
character->SetAttribute("ls", m_Uscore);
2022-07-28 13:39:57 +00:00
// Custom attribute to keep track of reputation.
character->SetAttribute("rpt", GetReputation());
character->SetAttribute("stt", StatisticsToString().c_str());
// Set the zone statistics of the form <zs><s/> ... <s/></zs>
auto zoneStatistics = character->FirstChildElement("zs");
if (!zoneStatistics) zoneStatistics = doc->NewElement("zs");
zoneStatistics->DeleteChildren();
for (auto pair : m_ZoneStatistics) {
2022-07-28 13:39:57 +00:00
auto zoneStatistic = doc->NewElement("s");
2022-07-28 13:39:57 +00:00
zoneStatistic->SetAttribute("map", pair.first);
zoneStatistic->SetAttribute("ac", pair.second.m_AchievementsCollected);
zoneStatistic->SetAttribute("bc", pair.second.m_BricksCollected);
zoneStatistic->SetAttribute("cc", pair.second.m_CoinsCollected);
zoneStatistic->SetAttribute("es", pair.second.m_EnemiesSmashed);
zoneStatistic->SetAttribute("qbc", pair.second.m_QuickBuildsCompleted);
2022-07-28 13:39:57 +00:00
zoneStatistics->LinkEndChild(zoneStatistic);
}
character->LinkEndChild(zoneStatistics);
if (!m_LastRocketConfig.empty()) {
std::string config = GeneralUtils::UTF16ToWTF8(m_LastRocketConfig);
character->SetAttribute("lcbp", config.c_str());
2022-07-28 13:39:57 +00:00
} else {
character->DeleteAttribute("lcbp");
}
2022-07-28 13:39:57 +00:00
//
// Begin custom attributes
//
2022-07-28 13:39:57 +00:00
// Store last rocket item ID
character->SetAttribute("lrid", m_LastRocketItemID);
2022-07-28 13:39:57 +00:00
//
// End custom attributes
//
auto newUpdateTimestamp = std::time(nullptr);
LOG("Time since last save: %d", newUpdateTimestamp - m_LastUpdateTimestamp);
m_TotalTimePlayed += newUpdateTimestamp - m_LastUpdateTimestamp;
character->SetAttribute("time", m_TotalTimePlayed);
m_LastUpdateTimestamp = newUpdateTimestamp;
}
void CharacterComponent::SetLastRocketConfig(std::u16string config) {
m_IsLanding = !config.empty();
m_LastRocketConfig = config;
}
Item* CharacterComponent::GetRocket(Entity* player) {
Item* rocket = nullptr;
auto* inventoryComponent = player->GetComponent<InventoryComponent>();
if (!inventoryComponent) return rocket;
// Select the rocket
2022-07-28 13:39:57 +00:00
if (!rocket) {
rocket = inventoryComponent->FindItemById(GetLastRocketItemID());
}
if (!rocket) {
rocket = inventoryComponent->FindItemByLot(6416);
}
if (!rocket) {
LOG("Unable to find rocket to equip!");
return rocket;
}
return rocket;
}
Item* CharacterComponent::RocketEquip(Entity* player) {
Item* rocket = GetRocket(player);
if (!rocket) return rocket;
// build and define the rocket config
for (LDFBaseData* data : rocket->GetConfig()) {
if (data->GetKey() == u"assemblyPartLOTs") {
std::string newRocketStr = data->GetValueAsString() + ";";
GeneralUtils::ReplaceInString(newRocketStr, "+", ";");
SetLastRocketConfig(GeneralUtils::ASCIIToUTF16(newRocketStr));
}
}
// Store the last used rocket item's ID
SetLastRocketItemID(rocket->GetId());
// carry the rocket
rocket->Equip(true);
return rocket;
}
void CharacterComponent::RocketUnEquip(Entity* player) {
Item* rocket = GetRocket(player);
if (!rocket) return;
// We don't want to carry it anymore
rocket->UnEquip();
}
void CharacterComponent::TrackMissionCompletion(bool isAchievement) {
2022-07-28 13:39:57 +00:00
UpdatePlayerStatistic(MissionsCompleted);
2022-07-28 13:39:57 +00:00
// Achievements are tracked separately for the zone
if (isAchievement) {
const auto mapID = Game::zoneManager->GetZoneID().GetMapID();
2022-07-28 13:39:57 +00:00
GetZoneStatisticsForMap(mapID).m_AchievementsCollected++;
}
}
void CharacterComponent::TrackLOTCollection(LOT lot) {
2022-07-28 13:39:57 +00:00
switch (lot) {
// Handle all the imagination powerup lots
case 935: // 1 point
case 4035: // 2 points
case 11910: // 3 points
case 11911: // 5 points
case 11918: // 10 points
UpdatePlayerStatistic(ImaginationPowerUpsCollected);
break;
// Handle all the armor powerup lots
case 6431: // 1 point
case 11912: // 2 points
case 11913: // 3 points
case 11914: // 5 points
case 11919: // 10 points
UpdatePlayerStatistic(ArmorPowerUpsCollected);
break;
// Handle all the life powerup lots
case 177: // 1 point
case 11915: // 2 points
case 11916: // 3 points
case 11917: // 5 points
case 11920: // 10 points
UpdatePlayerStatistic(LifePowerUpsCollected);
break;
default:
break;
}
}
void CharacterComponent::TrackHealthDelta(int32_t health) {
2022-07-28 13:39:57 +00:00
if (health > 0) {
UpdatePlayerStatistic(TotalDamageHealed, health);
} else {
UpdatePlayerStatistic(TotalDamageTaken, -health);
}
}
void CharacterComponent::TrackImaginationDelta(int32_t imagination) {
2022-07-28 13:39:57 +00:00
if (imagination > 0) {
UpdatePlayerStatistic(TotalImaginationRestored, imagination);
} else {
UpdatePlayerStatistic(TotalImaginationUsed, -imagination);
}
}
void CharacterComponent::TrackArmorDelta(int32_t armor) {
2022-07-28 13:39:57 +00:00
if (armor > 0) {
UpdatePlayerStatistic(TotalArmorRepaired, armor);
}
}
void CharacterComponent::TrackQuickBuildComplete() {
2022-07-28 13:39:57 +00:00
UpdatePlayerStatistic(QuickBuildsCompleted);
const auto mapID = Game::zoneManager->GetZoneID().GetMapID();
2022-07-28 13:39:57 +00:00
GetZoneStatisticsForMap(mapID).m_QuickBuildsCompleted++;
}
void CharacterComponent::TrackRaceCompleted(bool won) {
2022-07-28 13:39:57 +00:00
m_RacesFinished++;
if (won)
m_FirstPlaceRaceFinishes++;
}
void CharacterComponent::TrackPositionUpdate(const NiPoint3& newPosition) {
2022-07-28 13:39:57 +00:00
const auto distance = NiPoint3::Distance(newPosition, m_Parent->GetPosition());
2022-07-28 13:39:57 +00:00
if (m_IsRacing) {
UpdatePlayerStatistic(DistanceDriven, static_cast<uint64_t>(distance));
2022-07-28 13:39:57 +00:00
} else {
UpdatePlayerStatistic(MetersTraveled, static_cast<uint64_t>(distance));
2022-07-28 13:39:57 +00:00
}
}
2022-07-28 13:39:57 +00:00
void CharacterComponent::HandleZoneStatisticsUpdate(LWOMAPID zoneID, const std::u16string& name, int32_t value) {
auto zoneStatistics = &GetZoneStatisticsForMap(zoneID);
if (name == u"BricksCollected") {
m_BricksCollected += value;
zoneStatistics->m_BricksCollected += value;
} else if (name == u"CoinsCollected") {
m_CurrencyCollected += value;
zoneStatistics->m_CoinsCollected += value;
} else if (name == u"EnemiesSmashed") {
m_EnemiesSmashed += value;
zoneStatistics->m_EnemiesSmashed += value;
}
}
void CharacterComponent::UpdatePlayerStatistic(StatisticID updateID, uint64_t updateValue) {
2022-07-28 13:39:57 +00:00
switch (updateID) {
case CurrencyCollected:
m_CurrencyCollected += updateValue;
break;
case BricksCollected:
m_BricksCollected += updateValue;
break;
case SmashablesSmashed:
m_SmashablesSmashed += updateValue;
break;
case QuickBuildsCompleted:
m_QuickBuildsCompleted += updateValue;
break;
case EnemiesSmashed:
m_EnemiesSmashed += updateValue;
break;
case RocketsUsed:
m_RocketsUsed += updateValue;
break;
case MissionsCompleted:
m_MissionsCompleted += updateValue;
break;
case PetsTamed:
m_PetsTamed += updateValue;
break;
case ImaginationPowerUpsCollected:
m_ImaginationPowerUpsCollected += updateValue;
break;
case LifePowerUpsCollected:
m_LifePowerUpsCollected += updateValue;
break;
case ArmorPowerUpsCollected:
m_ArmorPowerUpsCollected += updateValue;
break;
case MetersTraveled:
m_MetersTraveled += updateValue;
break;
case TimesSmashed:
m_TimesSmashed += updateValue;
break;
case TotalDamageTaken:
m_TotalDamageTaken += updateValue;
break;
case TotalDamageHealed:
m_TotalDamageHealed += updateValue;
break;
case TotalArmorRepaired:
m_TotalArmorRepaired += updateValue;
break;
case TotalImaginationRestored:
m_TotalImaginationRestored += updateValue;
break;
case TotalImaginationUsed:
m_TotalImaginationUsed += updateValue;
break;
case DistanceDriven:
m_DistanceDriven += updateValue;
break;
case TimeAirborneInCar:
m_TimeAirborneInCar += updateValue;
break;
case RacingImaginationPowerUpsCollected:
m_RacingImaginationPowerUpsCollected += updateValue;
break;
case RacingImaginationCratesSmashed:
m_RacingImaginationCratesSmashed += updateValue;
break;
case RacingCarBoostsActivated:
m_RacingCarBoostsActivated += updateValue;
break;
case RacingTimesWrecked:
m_RacingTimesWrecked += updateValue;
break;
case RacingSmashablesSmashed:
m_RacingSmashablesSmashed += updateValue;
break;
case RacesFinished:
m_RacesFinished += updateValue;
break;
case FirstPlaceRaceFinishes:
m_FirstPlaceRaceFinishes += updateValue;
break;
default:
break;
}
}
2022-07-28 13:39:57 +00:00
void CharacterComponent::InitializeStatisticsFromString(const std::string& statisticsString) {
auto split = GeneralUtils::SplitString(statisticsString, ';');
m_CurrencyCollected = GetStatisticFromSplit(split, 0);
m_BricksCollected = GetStatisticFromSplit(split, 1);
m_SmashablesSmashed = GetStatisticFromSplit(split, 2);
m_QuickBuildsCompleted = GetStatisticFromSplit(split, 3);
m_EnemiesSmashed = GetStatisticFromSplit(split, 4);
m_RocketsUsed = GetStatisticFromSplit(split, 5);
m_MissionsCompleted = GetStatisticFromSplit(split, 6);
m_PetsTamed = GetStatisticFromSplit(split, 7);
m_ImaginationPowerUpsCollected = GetStatisticFromSplit(split, 8);
m_LifePowerUpsCollected = GetStatisticFromSplit(split, 9);
m_ArmorPowerUpsCollected = GetStatisticFromSplit(split, 10);
m_MetersTraveled = GetStatisticFromSplit(split, 11);
m_TimesSmashed = GetStatisticFromSplit(split, 12);
m_TotalDamageTaken = GetStatisticFromSplit(split, 13);
m_TotalDamageHealed = GetStatisticFromSplit(split, 14);
m_TotalArmorRepaired = GetStatisticFromSplit(split, 15);
m_TotalImaginationRestored = GetStatisticFromSplit(split, 16);
m_TotalImaginationUsed = GetStatisticFromSplit(split, 17);
m_DistanceDriven = GetStatisticFromSplit(split, 18);
m_TimeAirborneInCar = GetStatisticFromSplit(split, 19); // WONTFIX
m_RacingImaginationPowerUpsCollected = GetStatisticFromSplit(split, 20);
m_RacingImaginationCratesSmashed = GetStatisticFromSplit(split, 21);
m_RacingCarBoostsActivated = GetStatisticFromSplit(split, 22);
m_RacingTimesWrecked = GetStatisticFromSplit(split, 23);
m_RacingSmashablesSmashed = GetStatisticFromSplit(split, 24);
m_RacesFinished = GetStatisticFromSplit(split, 25);
m_FirstPlaceRaceFinishes = GetStatisticFromSplit(split, 26);
}
void CharacterComponent::InitializeEmptyStatistics() {
2022-07-28 13:39:57 +00:00
m_CurrencyCollected = 0;
m_BricksCollected = 0;
m_SmashablesSmashed = 0;
m_QuickBuildsCompleted = 0;
m_EnemiesSmashed = 0;
m_RocketsUsed = 0;
m_MissionsCompleted = 0;
m_PetsTamed = 0;
m_ImaginationPowerUpsCollected = 0;
m_LifePowerUpsCollected = 0;
m_ArmorPowerUpsCollected = 0;
m_MetersTraveled = 0;
m_TimesSmashed = 0;
m_TotalDamageTaken = 0;
m_TotalDamageHealed = 0;
m_TotalArmorRepaired = 0;
m_TotalImaginationRestored = 0;
m_TotalImaginationUsed = 0;
m_DistanceDriven = 0;
m_TimeAirborneInCar = 0;
m_RacingImaginationPowerUpsCollected = 0;
m_RacingImaginationCratesSmashed = 0;
m_RacingCarBoostsActivated = 0;
m_RacingTimesWrecked = 0;
m_RacingSmashablesSmashed = 0;
m_RacesFinished = 0;
m_FirstPlaceRaceFinishes = 0;
}
std::string CharacterComponent::StatisticsToString() const {
2022-07-28 13:39:57 +00:00
std::stringstream result;
result << std::to_string(m_CurrencyCollected) << ';'
<< std::to_string(m_BricksCollected) << ';'
<< std::to_string(m_SmashablesSmashed) << ';'
<< std::to_string(m_QuickBuildsCompleted) << ';'
<< std::to_string(m_EnemiesSmashed) << ';'
<< std::to_string(m_RocketsUsed) << ';'
<< std::to_string(m_MissionsCompleted) << ';'
<< std::to_string(m_PetsTamed) << ';'
<< std::to_string(m_ImaginationPowerUpsCollected) << ';'
<< std::to_string(m_LifePowerUpsCollected) << ';'
<< std::to_string(m_ArmorPowerUpsCollected) << ';'
<< std::to_string(m_MetersTraveled) << ';'
<< std::to_string(m_TimesSmashed) << ';'
<< std::to_string(m_TotalDamageTaken) << ';'
<< std::to_string(m_TotalDamageHealed) << ';'
<< std::to_string(m_TotalArmorRepaired) << ';'
<< std::to_string(m_TotalImaginationRestored) << ';'
<< std::to_string(m_TotalImaginationUsed) << ';'
<< std::to_string(m_DistanceDriven) << ';'
<< std::to_string(m_TimeAirborneInCar) << ';'
<< std::to_string(m_RacingImaginationPowerUpsCollected) << ';'
<< std::to_string(m_RacingImaginationCratesSmashed) << ';'
<< std::to_string(m_RacingCarBoostsActivated) << ';'
<< std::to_string(m_RacingTimesWrecked) << ';'
<< std::to_string(m_RacingSmashablesSmashed) << ';'
<< std::to_string(m_RacesFinished) << ';'
<< std::to_string(m_FirstPlaceRaceFinishes) << ';';
return result.str();
}
uint64_t CharacterComponent::GetStatisticFromSplit(std::vector<std::string> split, uint32_t index) {
refactor: Database abstraction and organization of files (#1274) * Database: Convert to proper namespace * Database: Use base class and getter * Database: Move files around * Database: Add property Management query Database: Move over user queries Tested at gm 0 that pre-approved names are pre-approved, unapproved need moderator approval deleting characters deletes the selcted one refreshing the character page shows the last character you logged in as tested all my characters show up when i login tested that you can delete all 4 characters and the correct character is selected each time tested renaming, approving names as gm0 Database: Add ugc model getter Hey it works, look I got around the mariadb issue. Database: Add queries Database: consolidate name query Database: Add friends list query Update name of approved names query Documentation Database: Add name check Database: Add BFF Query Database: Move BFF Setter Database: Move new friend query Database: Add remove friend queries Database: Add activity log Database: Add ugc & prop content removal Database: Add model update Database: Add migration queries Database: Add character and xml queries Database: Add user queries Untested, but compiling code Need to test that new character names are properly assigned in the following scenarios gm 0 and pre-approved name gm 0 and unapproved name gm 9 and pre-approved name gm 9 and unapproved name Database: constify function arguments Database: Add pet queries * Database: Move property model queries Untested. Need to test placing a new model moving existing one removing ugc model placing ugc model moving ugc model(?) changing privacy option variously change description and name approve property can properly travel to property * Property: Move stale reference deletion * Database: Move performance update query * Database: Add bug report query * Database: Add cheat detection query * Database: Add mail send query * Untested code need to test mailing from slash command, from all users of SendMail, getting bbb of a property and sending messages to bffs * Update CDComponentsRegistryTable.h Database: Rename and add further comments Datavbase: Add comments Add some comments Build: Fix PCH directories Database: Fix time thanks apple Database: Fix compiler warnings Overload destructor Define specialty for time_t Use string instead of string_view for temp empty string Update CDTable.h Property: Update queries to use mapId Database: Reorganize Reorganize into CDClient folder and GameDatabase folder for clearer meanings and file structure Folders: Rename to GameDatabase MySQL: Remove MySQL Specifier from table Database: Move Tables to Interfaces Database: Reorder functions in header Database: Simplify property queries Database: Remove unused queries Remove extra query definitions as well Database: Consolidate User getters Database: Comment logs Update MySQLDatabase.cpp Database: Use generic code Playkey: Fix bad optional access Database: Move stuff around WorldServer: Update queries Ugc reduced by many scopes use new queries very fast tested that ugc still loads Database: Add auth queries I tested that only the correct password can sign into an account. Tested that disabled playkeys do not allow the user to play the game Database: Add donation query Database: add objectId queries Database: Add master queries Database: Fix mis-named function Database: Add slash command queries Mail: Fix itemId type CharFilter: Use new query ObjectID: Remove duplicate code SlashCommand: Update query with function Database: Add mail queries Ugc: Fix issues with saving models Resolve large scope blocks as well * Database: Add debug try catch rethrow macro * General fixes * fix play key not working * Further fixes --------- Co-authored-by: Aaron Kimbre <aronwk.aaron@gmail.com>
2023-11-18 00:47:18 +00:00
return split.size() > index ? std::stoull(split.at(index)) : 0;
}
ZoneStatistics& CharacterComponent::GetZoneStatisticsForMap(LWOMAPID mapID) {
2022-07-28 13:39:57 +00:00
auto stats = m_ZoneStatistics.find(mapID);
if (stats == m_ZoneStatistics.end())
m_ZoneStatistics.insert({ mapID, {0, 0, 0, 0, 0 } });
return m_ZoneStatistics.at(mapID);
}
void CharacterComponent::AddVentureVisionEffect(std::string ventureVisionType) {
2022-07-28 13:39:57 +00:00
const auto ventureVisionTypeIterator = m_ActiveVentureVisionEffects.find(ventureVisionType);
2022-07-28 13:39:57 +00:00
if (ventureVisionTypeIterator != m_ActiveVentureVisionEffects.end()) {
ventureVisionTypeIterator->second = ++ventureVisionTypeIterator->second;
} else {
// If the effect it not found, insert it into the active effects.
m_ActiveVentureVisionEffects.insert(std::make_pair(ventureVisionType, 1U));
}
2022-07-28 13:39:57 +00:00
UpdateClientMinimap(true, ventureVisionType);
}
void CharacterComponent::RemoveVentureVisionEffect(std::string ventureVisionType) {
2022-07-28 13:39:57 +00:00
const auto ventureVisionTypeIterator = m_ActiveVentureVisionEffects.find(ventureVisionType);
2022-07-28 13:39:57 +00:00
if (ventureVisionTypeIterator != m_ActiveVentureVisionEffects.end()) {
ventureVisionTypeIterator->second = --ventureVisionTypeIterator->second;
UpdateClientMinimap(ventureVisionTypeIterator->second != 0U, ventureVisionType);
}
}
void CharacterComponent::UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const {
2022-07-28 13:39:57 +00:00
if (!m_Parent) return;
AMFArrayValue arrayToSend;
arrayToSend.Insert(ventureVisionType, showFaction);
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent ? m_Parent->GetSystemAddress() : UNASSIGNED_SYSTEM_ADDRESS, "SetFactionVisibility", arrayToSend);
}
void CharacterComponent::AwardClaimCodes() {
if (!m_Parent || !m_Parent->GetCharacter()) return;
auto* user = m_Parent->GetCharacter()->GetParentUser();
if (!user) return;
auto rewardCodes = Database::Get()->GetRewardCodesByAccountID(user->GetAccountID());
if (rewardCodes.empty()) return;
auto* cdrewardCodes = CDClientManager::GetTable<CDRewardCodesTable>();
for (auto const rewardCode : rewardCodes) {
LOG_DEBUG("Processing RewardCode %i", rewardCode);
const uint32_t rewardCodeIndex = rewardCode >> 6;
const uint32_t bitIndex = rewardCode % 64;
if (GeneralUtils::CheckBit(m_ClaimCodes[rewardCodeIndex], bitIndex)) continue;
m_ClaimCodes[rewardCodeIndex] = GeneralUtils::SetBit(m_ClaimCodes[rewardCodeIndex], bitIndex);
// Don't send it on this one since it's default and the mail doesn't make sense
if (rewardCode == 30) continue;
auto attachmentLOT = cdrewardCodes->GetAttachmentLOT(rewardCode);
std::ostringstream subject;
subject << "%[RewardCodes_" << rewardCode << "_subjectText]";
std::ostringstream body;
body << "%[RewardCodes_" << rewardCode << "_bodyText]";
Mail::SendMail(LWOOBJID_EMPTY, "%[MAIL_SYSTEM_NOTIFICATION]", m_Parent, subject.str(), body.str(), attachmentLOT, 1);
}
}
void CharacterComponent::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) const {
const auto objid = m_Parent->GetObjectID();
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, zoneId, cloneId, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
auto* entity = Game::entityManager->GetEntity(objid);
if (!entity) return;
const auto sysAddr = entity->GetSystemAddress();
auto* character = entity->GetCharacter();
auto* characterComponent = entity->GetComponent<CharacterComponent>();
if (character && characterComponent) {
character->SetZoneID(zoneID);
character->SetZoneInstance(zoneInstance);
character->SetZoneClone(zoneClone);
characterComponent->SetLastRocketConfig(u"");
character->SaveXMLToDatabase();
}
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
Game::entityManager->DestructEntity(entity);
});
}
const SystemAddress& CharacterComponent::GetSystemAddress() const {
return m_SystemAddress;
}
void CharacterComponent::SetRespawnPos(const NiPoint3& position) {
if (!m_Character) return;
m_respawnPos = position;
m_Character->SetRespawnPoint(Game::zoneManager->GetZone()->GetWorldID(), position);
}
void CharacterComponent::SetRespawnRot(const NiQuaternion& rotation) {
m_respawnRot = rotation;
}