Character fixes - get it compiling again

- Pass componentID to activity component constructor
- use int componentid so -1 can denote no component
This commit is contained in:
David Markowitz 2023-06-26 22:39:15 -07:00
parent d9a3bea6d5
commit 2abcb142ad
20 changed files with 96 additions and 103 deletions

View File

@ -29,8 +29,8 @@
#include "CDActivitiesTable.h"
#include "LeaderboardManager.h"
ActivityComponent::ActivityComponent(Entity* parent) : Component(parent) {
m_ActivityID = activityID;
ActivityComponent::ActivityComponent(Entity* parent, int32_t componentId) : Component(parent) {
m_ActivityID = componentId;
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
std::vector<CDActivities> activities = activitiesTable->Query([=](CDActivities entry) {return (entry.ActivityID == m_ActivityID); });

View File

@ -156,7 +156,7 @@ struct ActivityPlayer {
*/
class ActivityComponent : public Component {
public:
ActivityComponent(Entity* parent);
ActivityComponent(Entity* parent, int32_t componentId);
~ActivityComponent() override;
void Update(float deltaTime) override;

View File

@ -12,7 +12,7 @@
/**
* Component for the build border, allowing the user to start building when interacting with it
*/
class BuildBorderComponent : public Component {
class BuildBorderComponent final : public Component {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::BUILD_BORDER;

View File

@ -66,16 +66,12 @@ bool CharacterComponent::LandingAnimDisabled(int zoneID) {
return false;
}
CharacterComponent::~CharacterComponent() {
}
void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
if (bIsInitialUpdate) {
outBitStream->Write0();
outBitStream->Write0();
outBitStream->Write0();
outBitStream->Write0();
outBitStream->Write0(); // Claim codes. Dont't belive these have an effect.
outBitStream->Write0(); // Claim codes. Dont't belive these have an effect.
outBitStream->Write0(); // Claim codes. Dont't belive these have an effect.
outBitStream->Write0(); // Claim codes. Dont't belive these have an effect.
outBitStream->Write(m_Character->GetHairColor());
outBitStream->Write(m_Character->GetHairStyle());
@ -122,6 +118,8 @@ void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInit
outBitStream->Write(m_RacesFinished);
outBitStream->Write(m_FirstPlaceRaceFinishes);
// This is a really weird bit of serialization. This is serialized as a two bit integer, but the first bit written is always zero.
// If the 2 bit integer is exactly 1, we write the rocket configuration.
outBitStream->Write0();
outBitStream->Write(m_IsLanding);
if (m_IsLanding) {
@ -132,20 +130,24 @@ void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInit
}
}
outBitStream->Write(m_DirtyGMInfo);
if (m_DirtyGMInfo) {
outBitStream->Write(bIsInitialUpdate || m_DirtyGMInfo);
if (bIsInitialUpdate || m_DirtyGMInfo) {
outBitStream->Write(m_PvpEnabled);
outBitStream->Write(m_IsGM);
outBitStream->Write(m_GMLevel);
outBitStream->Write(m_EditorEnabled);
outBitStream->Write(m_EditorLevel);
if (!bIsInitialUpdate) m_DirtyGMInfo = false;
}
outBitStream->Write(m_DirtyCurrentActivity);
if (m_DirtyCurrentActivity) outBitStream->Write(m_CurrentActivity);
outBitStream->Write(bIsInitialUpdate || m_DirtyCurrentActivity);
if (bIsInitialUpdate || m_DirtyCurrentActivity) {
outBitStream->Write(m_CurrentActivity);
if (!bIsInitialUpdate) m_DirtyCurrentActivity = false;
}
outBitStream->Write(m_DirtySocialInfo);
if (m_DirtySocialInfo) {
outBitStream->Write(bIsInitialUpdate || m_DirtySocialInfo);
if (bIsInitialUpdate || m_DirtySocialInfo) {
outBitStream->Write(m_GuildID);
outBitStream->Write<unsigned char>(static_cast<unsigned char>(m_GuildName.size()));
if (!m_GuildName.empty())
@ -153,6 +155,7 @@ void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInit
outBitStream->Write(m_IsLEGOClubMember);
outBitStream->Write(m_CountryCode);
if (!bIsInitialUpdate) m_DirtySocialInfo = false;
}
}
@ -161,21 +164,21 @@ bool CharacterComponent::GetPvpEnabled() const {
}
void CharacterComponent::SetPvpEnabled(const bool value) {
if (m_PvpEnabled == value) return;
m_DirtyGMInfo = true;
m_PvpEnabled = value;
}
void CharacterComponent::SetGMLevel(eGameMasterLevel gmlevel) {
if (m_GMLevel == gmlevel) return;
m_DirtyGMInfo = true;
if (gmlevel > eGameMasterLevel::CIVILIAN) m_IsGM = true;
else m_IsGM = false;
m_IsGM = gmlevel > eGameMasterLevel::CIVILIAN;
m_GMLevel = gmlevel;
}
void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
auto* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
Game::logger->Log("CharacterComponent", "Failed to find char tag while loading XML!");
return;
@ -195,7 +198,7 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
}
// Load the zone statistics
m_ZoneStatistics = {};
m_ZoneStatistics.clear();
auto zoneStatistics = character->FirstChildElement("zs");
if (zoneStatistics) {
@ -218,20 +221,16 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
}
}
const tinyxml2::XMLAttribute* rocketConfig = character->FindAttribute("lcbp");
const auto* rocketConfig = character->FindAttribute("lcbp");
if (rocketConfig) {
m_LastRocketConfig = GeneralUtils::ASCIIToUTF16(rocketConfig->Value());
} else {
m_LastRocketConfig = u"";
}
m_LastRocketConfig = rocketConfig ? GeneralUtils::ASCIIToUTF16(rocketConfig->Value()) : u"";
//
// Begin custom attributes
//
// Load the last rocket item ID
const tinyxml2::XMLAttribute* lastRocketItemID = character->FindAttribute("lrid");
const auto* lastRocketItemID = character->FindAttribute("lrid");
if (lastRocketItemID) {
m_LastRocketItemID = lastRocketItemID->Int64Value();
}
@ -248,7 +247,7 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
}
//Annoying guild bs:
const tinyxml2::XMLAttribute* guildName = character->FindAttribute("gn");
const auto* guildName = character->FindAttribute("gn");
if (guildName) {
const char* gn = guildName->Value();
int64_t gid = 0;
@ -269,10 +268,8 @@ void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
if (!m_Character) return;
//Check to see if we're landing:
if (m_Character->GetZoneID() != Game::server->GetZoneID()) {
m_IsLanding = true;
}
// If the loaded zoneID is different from the current zoneID, we are landing
m_IsLanding = m_Character->GetZoneID() != Game::server->GetZoneID();
if (LandingAnimDisabled(m_Character->GetZoneID()) || LandingAnimDisabled(Game::server->GetZoneID()) || m_LastRocketConfig.empty()) {
m_IsLanding = false; //Don't make us land on VE/minigames lol
@ -300,7 +297,7 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
// done with minifig
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
auto* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
Game::logger->Log("CharacterComponent", "Failed to find char tag while updating XML!");
return;
@ -316,15 +313,15 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
if (!zoneStatistics) zoneStatistics = doc->NewElement("zs");
zoneStatistics->DeleteChildren();
for (auto pair : m_ZoneStatistics) {
for (const auto&[mapId, zoneStatisticToSave] : m_ZoneStatistics) {
auto zoneStatistic = doc->NewElement("s");
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);
zoneStatistic->SetAttribute("map", mapId);
zoneStatistic->SetAttribute("ac", zoneStatisticToSave.m_AchievementsCollected);
zoneStatistic->SetAttribute("bc", zoneStatisticToSave.m_BricksCollected);
zoneStatistic->SetAttribute("cc", zoneStatisticToSave.m_CoinsCollected);
zoneStatistic->SetAttribute("es", zoneStatisticToSave.m_EnemiesSmashed);
zoneStatistic->SetAttribute("qbc", zoneStatisticToSave.m_QuickBuildsCompleted);
zoneStatistics->LinkEndChild(zoneStatistic);
}
@ -350,7 +347,7 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
//
auto newUpdateTimestamp = std::time(nullptr);
Game::logger->Log("TotalTimePlayed", "Time since last save: %d", newUpdateTimestamp - m_LastUpdateTimestamp);
Game::logger->Log("TotalTimePlayed", "Time since %i last saved: %d", m_Character->GetID(), newUpdateTimestamp - m_LastUpdateTimestamp);
m_TotalTimePlayed += newUpdateTimestamp - m_LastUpdateTimestamp;
character->SetAttribute("time", m_TotalTimePlayed);
@ -391,7 +388,7 @@ Item* CharacterComponent::RocketEquip(Entity* player) {
if (!rocket) return rocket;
// build and define the rocket config
for (LDFBaseData* data : rocket->GetConfig()) {
for (auto* data : rocket->GetConfig()) {
if (data->GetKey() == u"assemblyPartLOTs") {
std::string newRocketStr = data->GetValueAsString() + ";";
GeneralUtils::ReplaceInString(newRocketStr, "+", ";");
@ -471,9 +468,7 @@ void CharacterComponent::TrackImaginationDelta(int32_t imagination) {
}
void CharacterComponent::TrackArmorDelta(int32_t armor) {
if (armor > 0) {
UpdatePlayerStatistic(TotalArmorRepaired, armor);
}
if (armor > 0) UpdatePlayerStatistic(TotalArmorRepaired, armor);
}
void CharacterComponent::TrackRebuildComplete() {
@ -485,17 +480,16 @@ void CharacterComponent::TrackRebuildComplete() {
void CharacterComponent::TrackRaceCompleted(bool won) {
m_RacesFinished++;
if (won)
m_FirstPlaceRaceFinishes++;
if (won) m_FirstPlaceRaceFinishes++;
}
void CharacterComponent::TrackPositionUpdate(const NiPoint3& newPosition) {
const auto distance = NiPoint3::Distance(newPosition, m_ParentEntity->GetPosition());
if (m_IsRacing) {
UpdatePlayerStatistic(DistanceDriven, (uint64_t)distance);
UpdatePlayerStatistic(DistanceDriven, static_cast<uint64_t>(distance));
} else {
UpdatePlayerStatistic(MetersTraveled, (uint64_t)distance);
UpdatePlayerStatistic(MetersTraveled, static_cast<uint64_t>(distance));
}
}
@ -666,45 +660,45 @@ void CharacterComponent::InitializeEmptyStatistics() {
std::string CharacterComponent::StatisticsToString() const {
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) << ';';
result
<< m_CurrencyCollected << ';'
<< m_BricksCollected << ';'
<< m_SmashablesSmashed << ';'
<< m_QuickBuildsCompleted << ';'
<< m_EnemiesSmashed << ';'
<< m_RocketsUsed << ';'
<< m_MissionsCompleted << ';'
<< m_PetsTamed << ';'
<< m_ImaginationPowerUpsCollected << ';'
<< m_LifePowerUpsCollected << ';'
<< m_ArmorPowerUpsCollected << ';'
<< m_MetersTraveled << ';'
<< m_TimesSmashed << ';'
<< m_TotalDamageTaken << ';'
<< m_TotalDamageHealed << ';'
<< m_TotalArmorRepaired << ';'
<< m_TotalImaginationRestored << ';'
<< m_TotalImaginationUsed << ';'
<< m_DistanceDriven << ';'
<< m_TimeAirborneInCar << ';'
<< m_RacingImaginationPowerUpsCollected << ';'
<< m_RacingImaginationCratesSmashed << ';'
<< m_RacingCarBoostsActivated << ';'
<< m_RacingTimesWrecked << ';'
<< m_RacingSmashablesSmashed << ';'
<< m_RacesFinished << ';'
<< m_FirstPlaceRaceFinishes << ';';
return result.str();
}
uint64_t CharacterComponent::GetStatisticFromSplit(std::vector<std::string> split, uint32_t index) {
return split.size() > index ? std::stoul(split.at(index)) : 0;
return index < split.size() ? std::stoul(split.at(index)) : 0;
}
ZoneStatistics& CharacterComponent::GetZoneStatisticsForMap(LWOMAPID mapID) {
auto stats = m_ZoneStatistics.find(mapID);
if (stats == m_ZoneStatistics.end())
m_ZoneStatistics.insert({ mapID, {0, 0, 0, 0, 0 } });
if (stats == m_ZoneStatistics.end()) m_ZoneStatistics.insert({ mapID, {0, 0, 0, 0, 0 } });
return m_ZoneStatistics.at(mapID);
}

View File

@ -60,12 +60,11 @@ enum StatisticID {
/**
* Represents a character, including their rockets and stats
*/
class CharacterComponent : public Component {
class CharacterComponent final : public Component {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::CHARACTER;
CharacterComponent(Entity* parent, Character* character);
~CharacterComponent() override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;

View File

@ -1,5 +1,5 @@
#include "GateRushComponent.h"
GateRushComponent::GateRushComponent(Entity* parent) : RacingControlComponent(parent) {
GateRushComponent::GateRushComponent(Entity* parent, int32_t componentId) : RacingControlComponent(parent, componentId) {
}

View File

@ -9,7 +9,7 @@ class Entity;
class GateRushComponent : public RacingControlComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::GATE_RUSH_CONTROL;
GateRushComponent(Entity* parent);
GateRushComponent(Entity* parent, int32_t componentId);
};
#endif //!__GATERUSHCONTROLCOMPONENT__H__

View File

@ -2,6 +2,6 @@
#include "Entity.h"
#include "MinigameControlComponent.h"
MinigameControlComponent::MinigameControlComponent(Entity* parent) : ActivityComponent(parent) {
MinigameControlComponent::MinigameControlComponent(Entity* parent, int32_t componentId) : ActivityComponent(parent, componentId) {
}

View File

@ -9,7 +9,7 @@ class Entity;
class MinigameControlComponent : public ActivityComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MINIGAME_CONTROL;
MinigameControlComponent(Entity* parent);
MinigameControlComponent(Entity* parent, int32_t componentId);
};
#endif //!__MINIGAMECONTROLCOMPONENT__H__

View File

@ -25,7 +25,7 @@
#include "CppScripts.h"
QuickBuildComponent::QuickBuildComponent(Entity* entity) : ActivityComponent(entity) {
QuickBuildComponent::QuickBuildComponent(Entity* entity, int32_t componentId) : ActivityComponent(entity, componentId) {
m_ComponentId = componentId;
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");

View File

@ -24,7 +24,7 @@ class QuickBuildComponent : public ActivityComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
QuickBuildComponent(Entity* entity, uint32_t componentId = 0);
QuickBuildComponent(Entity* entity, int32_t componentId = 0);
~QuickBuildComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
@ -351,7 +351,7 @@ private:
*/
PreconditionExpression* m_Precondition = nullptr;
uint32_t m_ComponentId = 0;
int32_t m_ComponentId = 0;
/**
* Starts the rebuild for a certain entity

View File

@ -1,5 +1,5 @@
#include "RacingComponent.h"
RacingComponent::RacingComponent(Entity* parent) : RacingControlComponent(parent) {
RacingComponent::RacingComponent(Entity* parent, int32_t componentId) : RacingControlComponent(parent, componentId) {
}

View File

@ -9,7 +9,7 @@ class Entity;
class RacingComponent : public RacingControlComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
RacingComponent(Entity* parent);
RacingComponent(Entity* parent, int32_t componentId);
};

View File

@ -29,7 +29,7 @@
#define M_PI 3.14159265358979323846264338327950288
#endif
RacingControlComponent::RacingControlComponent(Entity* parent) : ScriptedActivityComponent(parent) {
RacingControlComponent::RacingControlComponent(Entity* parent, int32_t componentId) : ScriptedActivityComponent(parent, componentId) {
m_PathName = u"MainPath";
m_RemainingLaps = 3;
m_LeadingPlayer = LWOOBJID_EMPTY;

View File

@ -107,7 +107,7 @@ class RacingControlComponent : public ScriptedActivityComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
RacingControlComponent(Entity* parentEntity);
RacingControlComponent(Entity* parentEntity, int32_t componentId);
~RacingControlComponent();
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);

View File

@ -1,5 +1,5 @@
#include "ScriptedActivityComponent.h"
ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent) : ActivityComponent(parent) {
ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int32_t componentId) : ActivityComponent(parent, componentId) {
}

View File

@ -10,7 +10,7 @@ class Entity;
class ScriptedActivityComponent : public ActivityComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SCRIPTED_ACTIVITY;
ScriptedActivityComponent(Entity* parent);
ScriptedActivityComponent(Entity* parent, int32_t componentId);
};
#endif //!__SCRIPTEDACTIVITYCOMPONENT__H__

View File

@ -2,7 +2,7 @@
#include "EntityManager.h"
#include "ScriptedActivityComponent.h"
ShootingGalleryComponent::ShootingGalleryComponent(Entity* parent) : ActivityComponent(parent) {
ShootingGalleryComponent::ShootingGalleryComponent(Entity* parent, int32_t componentId) : ActivityComponent(parent, componentId) {
}
ShootingGalleryComponent::~ShootingGalleryComponent() = default;

View File

@ -75,7 +75,7 @@ class ShootingGalleryComponent : public ActivityComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::SHOOTING_GALLERY;
explicit ShootingGalleryComponent(Entity* parent);
explicit ShootingGalleryComponent(Entity* parent, int32_t componentId);
~ShootingGalleryComponent();
void Serialize(RakNet::BitStream* outBitStream, bool isInitialUpdate, uint32_t& flags) const;

View File

@ -305,7 +305,7 @@ void Entity::Initialize() {
AddComponent<InventoryComponent>();
break;
case eReplicaComponentType::SHOOTING_GALLERY:
AddComponent<ShootingGalleryComponent>();
AddComponent<ShootingGalleryComponent>(componentId);
break;
case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS:
if (hasPhysicsComponent) continue;
@ -402,7 +402,7 @@ void Entity::Initialize() {
AddComponent<SwitchComponent>();
break;
case eReplicaComponentType::MINIGAME_CONTROL:
AddComponent<MinigameControlComponent>();
AddComponent<MinigameControlComponent>(componentId);
break;
case eReplicaComponentType::BASE_COMBAT_AI: {
auto* baseCombatAiComponent = AddComponent<BaseCombatAIComponent>(componentId);
@ -556,7 +556,7 @@ void Entity::Initialize() {
case eReplicaComponentType::PLAYER_FORCED_MOVEMENT:
case eReplicaComponentType::CRAFTING:
case eReplicaComponentType::LEVEL_PROGRESSION:
case eReplicaComponentType::POSSESSOR:
case eReplicaComponentType::POSSESSION:
case eReplicaComponentType::MOUNT_CONTROL:
case eReplicaComponentType::UNKNOWN_112:
case eReplicaComponentType::PROPERTY_PLAQUE: