Merge branch 'main' into fix/cmake-libs-2

This commit is contained in:
David Markowitz
2024-03-03 04:17:27 -08:00
committed by GitHub
475 changed files with 5755 additions and 6213 deletions

View File

@@ -0,0 +1,72 @@
#include "AchievementVendorComponent.h"
#include "MissionComponent.h"
#include "InventoryComponent.h"
#include "eMissionState.h"
#include "CDComponentsRegistryTable.h"
#include "CDItemComponentTable.h"
#include "eVendorTransactionResult.h"
#include "CheatDetection.h"
#include "UserManager.h"
#include "CDMissionsTable.h"
bool AchievementVendorComponent::SellsItem(Entity* buyer, const LOT lot) {
auto* missionComponent = buyer->GetComponent<MissionComponent>();
if (!missionComponent) return false;
if (m_PlayerPurchasableItems[buyer->GetObjectID()].contains(lot)){
return true;
}
CDMissionsTable* missionsTable = CDClientManager::GetTable<CDMissionsTable>();
const auto missions = missionsTable->GetMissionsForReward(lot);
for (const auto mission : missions) {
if (missionComponent->GetMissionState(mission) == eMissionState::COMPLETE) {
m_PlayerPurchasableItems[buyer->GetObjectID()].insert(lot);
return true;
}
}
return false;
}
void AchievementVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) {
// get the item Comp from the item LOT
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
int itemCompID = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::ITEM);
CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID);
uint32_t costLOT = itemComp.commendationLOT;
if (costLOT == -1 || !SellsItem(buyer, lot)) {
auto* user = UserManager::Instance()->GetUser(buyer->GetSystemAddress());
CheatDetection::ReportCheat(user, buyer->GetSystemAddress(), "Attempted to buy item %i from achievement vendor %i that is not purchasable", lot, m_Parent->GetLOT());
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
auto* inventoryComponent = buyer->GetComponent<InventoryComponent>();
if (!inventoryComponent) {
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
if (costLOT == 13763) { // Faction Token Proxy
auto* missionComponent = buyer->GetComponent<MissionComponent>();
if (!missionComponent) return;
if (missionComponent->GetMissionState(545) == eMissionState::COMPLETE) costLOT = 8318; // "Assembly Token"
if (missionComponent->GetMissionState(556) == eMissionState::COMPLETE) costLOT = 8321; // "Venture League Token"
if (missionComponent->GetMissionState(567) == eMissionState::COMPLETE) costLOT = 8319; // "Sentinels Token"
if (missionComponent->GetMissionState(578) == eMissionState::COMPLETE) costLOT = 8320; // "Paradox Token"
}
const uint32_t altCurrencyCost = itemComp.commendationCost * count;
if (inventoryComponent->GetLotCount(costLOT) < altCurrencyCost) {
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
inventoryComponent->RemoveItem(costLOT, altCurrencyCost);
inventoryComponent->AddItem(lot, count, eLootSourceType::VENDOR);
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_SUCCESS);
}

View File

@@ -0,0 +1,23 @@
#ifndef __ACHIEVEMENTVENDORCOMPONENT__H__
#define __ACHIEVEMENTVENDORCOMPONENT__H__
#include "VendorComponent.h"
#include "eReplicaComponentType.h"
#include <set>
#include <map>
class Entity;
class AchievementVendorComponent final : public VendorComponent {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::ACHIEVEMENT_VENDOR;
AchievementVendorComponent(Entity* parent) : VendorComponent(parent) {};
bool SellsItem(Entity* buyer, const LOT lot);
void Buy(Entity* buyer, LOT lot, uint32_t count);
private:
std::map<LWOOBJID,std::set<LOT>> m_PlayerPurchasableItems;
};
#endif //!__ACHIEVEMENTVENDORCOMPONENT__H__

View File

@@ -10,7 +10,6 @@
#include "WorldPackets.h"
#include "EntityManager.h"
#include "ChatPackets.h"
#include "Player.h"
#include "BitStreamUtils.h"
#include "dServer.h"
#include "GeneralUtils.h"
@@ -47,7 +46,7 @@ ActivityComponent::ActivityComponent(Entity* parent, int32_t activityID) : Compo
if (destroyableComponent) {
// First lookup the loot matrix id for this component id.
CDActivityRewardsTable* activityRewardsTable = CDClientManager::Instance().GetTable<CDActivityRewardsTable>();
CDActivityRewardsTable* activityRewardsTable = CDClientManager::GetTable<CDActivityRewardsTable>();
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([=](CDActivityRewards entry) {return (entry.LootMatrixIndex == destroyableComponent->GetLootMatrixID()); });
uint32_t startingLMI = 0;
@@ -71,7 +70,7 @@ ActivityComponent::ActivityComponent(Entity* parent, int32_t activityID) : Compo
}
}
void ActivityComponent::LoadActivityData(const int32_t activityId) {
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
CDActivitiesTable* activitiesTable = CDClientManager::GetTable<CDActivitiesTable>();
std::vector<CDActivities> activities = activitiesTable->Query([activityId](CDActivities entry) {return (entry.ActivityID == activityId); });
bool soloRacing = Game::config->GetValue("solo_racing") == "1";
@@ -84,21 +83,22 @@ void ActivityComponent::LoadActivityData(const int32_t activityId) {
if (m_ActivityInfo.instanceMapID == -1) {
const auto& transferOverride = m_Parent->GetVarAsString(u"transferZoneID");
if (!transferOverride.empty()) {
GeneralUtils::TryParse(transferOverride, m_ActivityInfo.instanceMapID);
m_ActivityInfo.instanceMapID =
GeneralUtils::TryParse<uint32_t>(transferOverride).value_or(m_ActivityInfo.instanceMapID);
}
}
}
}
void ActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_DirtyActivityInfo);
void ActivityComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_DirtyActivityInfo);
if (m_DirtyActivityInfo) {
outBitStream->Write<uint32_t>(m_ActivityPlayers.size());
outBitStream.Write<uint32_t>(m_ActivityPlayers.size());
if (!m_ActivityPlayers.empty()) {
for (const auto& activityPlayer : m_ActivityPlayers) {
outBitStream->Write<LWOOBJID>(activityPlayer->playerID);
outBitStream.Write<LWOOBJID>(activityPlayer->playerID);
for (const auto& activityValue : activityPlayer->values) {
outBitStream->Write<float_t>(activityValue);
outBitStream.Write<float_t>(activityValue);
}
}
}
@@ -107,7 +107,7 @@ void ActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsIniti
}
void ActivityComponent::ReloadConfig() {
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
CDActivitiesTable* activitiesTable = CDClientManager::GetTable<CDActivitiesTable>();
std::vector<CDActivities> activities = activitiesTable->Query([this](CDActivities entry) {return (entry.ActivityID == m_ActivityID); });
for (auto activity : activities) {
auto mapID = m_ActivityInfo.instanceMapID;
@@ -546,14 +546,14 @@ void ActivityInstance::RewardParticipant(Entity* participant) {
}
// First, get the activity data
auto* activityRewardsTable = CDClientManager::Instance().GetTable<CDActivityRewardsTable>();
auto* activityRewardsTable = CDClientManager::GetTable<CDActivityRewardsTable>();
std::vector<CDActivityRewards> activityRewards = activityRewardsTable->Query([this](CDActivityRewards entry) { return (entry.objectTemplate == m_ActivityInfo.ActivityID); });
if (!activityRewards.empty()) {
uint32_t minCoins = 0;
uint32_t maxCoins = 0;
auto* currencyTableTable = CDClientManager::Instance().GetTable<CDCurrencyTableTable>();
auto* currencyTableTable = CDClientManager::GetTable<CDCurrencyTableTable>();
std::vector<CDCurrencyTable> currencyTable = currencyTableTable->Query([=](CDCurrencyTable entry) { return (entry.currencyIndex == activityRewards[0].CurrencyIndex && entry.npcminlevel == 1); });
if (!currencyTable.empty()) {

View File

@@ -155,7 +155,7 @@ public:
void LoadActivityData(const int32_t activityId);
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Makes some entity join the minigame, if it's a lobbied one, the entity will be placed in the lobby

View File

@@ -107,10 +107,10 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id):
int32_t collisionGroup = (COLLISION_GROUP_DYNAMIC | COLLISION_GROUP_ENEMY);
CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
CDComponentsRegistryTable* componentRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
auto componentID = componentRegistryTable->GetByIDAndType(parent->GetLOT(), eReplicaComponentType::CONTROLLABLE_PHYSICS);
CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance().GetTable<CDPhysicsComponentTable>();
CDPhysicsComponentTable* physicsComponentTable = CDClientManager::GetTable<CDPhysicsComponentTable>();
if (physicsComponentTable != nullptr) {
auto* info = physicsComponentTable->GetByID(componentID);
@@ -185,7 +185,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
bool stunnedThisFrame = m_Stunned;
CalculateCombat(deltaTime); // Putting this here for now
if (m_StartPosition == NiPoint3::ZERO) {
if (m_StartPosition == NiPoint3Constant::ZERO) {
m_StartPosition = m_Parent->GetPosition();
}
@@ -520,11 +520,11 @@ bool BaseCombatAIComponent::IsMech() {
}
void BaseCombatAIComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_DirtyStateOrTarget || bIsInitialUpdate);
void BaseCombatAIComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_DirtyStateOrTarget || bIsInitialUpdate);
if (m_DirtyStateOrTarget || bIsInitialUpdate) {
outBitStream->Write(m_State);
outBitStream->Write(m_Target);
outBitStream.Write(m_State);
outBitStream.Write(m_Target);
m_DirtyStateOrTarget = false;
}
}

View File

@@ -53,7 +53,7 @@ public:
~BaseCombatAIComponent() override;
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Get the current behavioral state of the enemy

View File

@@ -22,10 +22,10 @@ BouncerComponent::BouncerComponent(Entity* parent) : Component(parent) {
BouncerComponent::~BouncerComponent() {
}
void BouncerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_PetEnabled);
void BouncerComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_PetEnabled);
if (m_PetEnabled) {
outBitStream->Write(m_PetBouncerEnabled);
outBitStream.Write(m_PetBouncerEnabled);
}
}

View File

@@ -17,7 +17,7 @@ public:
BouncerComponent(Entity* parentEntity);
~BouncerComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
Entity* GetParentEntity() const;

View File

@@ -32,24 +32,24 @@ BuffComponent::BuffComponent(Entity* parent) : Component(parent) {
BuffComponent::~BuffComponent() {
}
void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void BuffComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (!bIsInitialUpdate) return;
outBitStream->Write(!m_Buffs.empty());
outBitStream.Write(!m_Buffs.empty());
if (!m_Buffs.empty()) {
outBitStream->Write<uint32_t>(m_Buffs.size());
outBitStream.Write<uint32_t>(m_Buffs.size());
for (const auto& [id, buff] : m_Buffs) {
outBitStream->Write<uint32_t>(id);
outBitStream->Write(buff.time != 0.0f);
if (buff.time != 0.0f) outBitStream->Write<uint32_t>(buff.time * 1000.0f);
outBitStream->Write(buff.cancelOnDeath);
outBitStream->Write(buff.cancelOnZone);
outBitStream->Write(buff.cancelOnDamaged);
outBitStream->Write(buff.cancelOnRemoveBuff);
outBitStream->Write(buff.cancelOnUi);
outBitStream->Write(buff.cancelOnLogout);
outBitStream->Write(buff.cancelOnUnequip);
outBitStream->Write0(); // Cancel on Damage Absorb Ran Out. Generally false from what I can tell
outBitStream.Write<uint32_t>(id);
outBitStream.Write(buff.time != 0.0f);
if (buff.time != 0.0f) outBitStream.Write<uint32_t>(buff.time * 1000.0f);
outBitStream.Write(buff.cancelOnDeath);
outBitStream.Write(buff.cancelOnZone);
outBitStream.Write(buff.cancelOnDamaged);
outBitStream.Write(buff.cancelOnRemoveBuff);
outBitStream.Write(buff.cancelOnUi);
outBitStream.Write(buff.cancelOnLogout);
outBitStream.Write(buff.cancelOnUnequip);
outBitStream.Write0(); // Cancel on Damage Absorb Ran Out. Generally false from what I can tell
auto* team = TeamManager::Instance()->GetTeam(buff.source);
bool addedByTeammate = false;
@@ -57,15 +57,15 @@ void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUp
addedByTeammate = std::count(team->members.begin(), team->members.end(), m_Parent->GetObjectID()) > 0;
}
outBitStream->Write(addedByTeammate); // Added by teammate. If source is in the same team as the target, this is true. Otherwise, false.
outBitStream->Write(buff.applyOnTeammates);
if (addedByTeammate) outBitStream->Write(buff.source);
outBitStream.Write(addedByTeammate); // Added by teammate. If source is in the same team as the target, this is true. Otherwise, false.
outBitStream.Write(buff.applyOnTeammates);
if (addedByTeammate) outBitStream.Write(buff.source);
outBitStream->Write<uint32_t>(buff.refCount);
outBitStream.Write<uint32_t>(buff.refCount);
}
}
outBitStream->Write0(); // something to do with immunity buffs?
outBitStream.Write0(); // something to do with immunity buffs?
}
void BuffComponent::Update(float deltaTime) {
@@ -164,7 +164,7 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO
const auto& parameters = GetBuffParameters(id);
for (const auto& parameter : parameters) {
if (parameter.name == "overtime") {
auto* behaviorTemplateTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
auto* behaviorTemplateTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
behaviorID = behaviorTemplateTable->GetSkillByID(parameter.values[0]).behaviorID;
stacks = static_cast<int32_t>(parameter.values[1]);
@@ -208,9 +208,8 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO
void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity, bool ignoreRefCount) {
const auto& iter = m_Buffs.find(id);
if (iter == m_Buffs.end()) {
return;
}
// If the buff is already scheduled to be removed, don't do it again
if (iter == m_Buffs.end() || m_BuffsToRemove.contains(id)) return;
if (!ignoreRefCount && !iter->second.cancelOnRemoveBuff) {
iter->second.refCount--;
@@ -222,7 +221,7 @@ void BuffComponent::RemoveBuff(int32_t id, bool fromUnEquip, bool removeImmunity
GameMessages::SendRemoveBuff(m_Parent, fromUnEquip, removeImmunity, id);
m_BuffsToRemove.push_back(id);
m_BuffsToRemove.insert(id);
RemoveBuffEffect(id);
}

View File

@@ -61,7 +61,7 @@ public:
void UpdateXml(tinyxml2::XMLDocument* doc) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
@@ -141,7 +141,7 @@ private:
std::map<int32_t, Buff> m_Buffs;
// Buffs to remove at the end of the update frame.
std::vector<int32_t> m_BuffsToRemove;
std::set<int32_t> m_BuffsToRemove;
/**
* Parameters (=effects) for each buff

View File

@@ -56,7 +56,7 @@ void BuildBorderComponent::OnUse(Entity* originator) {
4,
0,
-1,
NiPoint3::ZERO,
NiPoint3Constant::ZERO,
0
);
} else {

View File

@@ -1,4 +1,5 @@
set(DGAME_DCOMPONENTS_SOURCES
"AchievementVendorComponent.cpp"
"ActivityComponent.cpp"
"BaseCombatAIComponent.cpp"
"BouncerComponent.cpp"
@@ -27,7 +28,6 @@ set(DGAME_DCOMPONENTS_SOURCES
"PlayerForcedMovementComponent.cpp"
"PossessableComponent.cpp"
"PossessorComponent.cpp"
"PropertyComponent.cpp"
"PropertyEntranceComponent.cpp"
"PropertyManagementComponent.cpp"
"PropertyVendorComponent.cpp"

View File

@@ -24,7 +24,7 @@
#include "WorldPackets.h"
#include <ctime>
CharacterComponent::CharacterComponent(Entity* parent, Character* character) : Component(parent) {
CharacterComponent::CharacterComponent(Entity* parent, Character* character, const SystemAddress& systemAddress) : Component(parent) {
m_Character = character;
m_IsRacing = false;
@@ -46,6 +46,7 @@ CharacterComponent::CharacterComponent(Entity* parent, Character* character) : C
m_CurrentActivity = eGameActivity::NONE;
m_CountryCode = 0;
m_LastUpdateTimestamp = std::time(nullptr);
m_SystemAddress = systemAddress;
}
bool CharacterComponent::LandingAnimDisabled(int zoneID) {
@@ -77,94 +78,94 @@ bool CharacterComponent::LandingAnimDisabled(int zoneID) {
CharacterComponent::~CharacterComponent() {
}
void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
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_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)
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.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);
outBitStream.Write0();
outBitStream.Write(m_IsLanding);
if (m_IsLanding) {
outBitStream->Write<uint16_t>(m_LastRocketConfig.size());
outBitStream.Write<uint16_t>(m_LastRocketConfig.size());
for (uint16_t character : m_LastRocketConfig) {
outBitStream->Write(character);
outBitStream.Write(character);
}
}
}
outBitStream->Write(m_DirtyGMInfo);
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_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_DirtyCurrentActivity);
if (m_DirtyCurrentActivity) outBitStream.Write(m_CurrentActivity);
outBitStream->Write(m_DirtySocialInfo);
outBitStream.Write(m_DirtySocialInfo);
if (m_DirtySocialInfo) {
outBitStream->Write(m_GuildID);
outBitStream->Write<unsigned char>(m_GuildName.size());
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.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);
outBitStream.Write(m_IsLEGOClubMember);
outBitStream.Write(m_CountryCode);
}
}
@@ -762,14 +763,14 @@ void CharacterComponent::UpdateClientMinimap(bool showFaction, std::string ventu
}
void CharacterComponent::AwardClaimCodes() {
if (!m_Parent) return;
auto* user = m_Parent->GetParentUser();
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::Instance().GetTable<CDRewardCodesTable>();
auto* cdrewardCodes = CDClientManager::GetTable<CDRewardCodesTable>();
for (auto const rewardCode : rewardCodes) {
LOG_DEBUG("Processing RewardCode %i", rewardCode);
const uint32_t rewardCodeIndex = rewardCode >> 6;
@@ -817,3 +818,20 @@ void CharacterComponent::SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId) const {
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;
}

View File

@@ -11,6 +11,7 @@
#include "tinyxml2.h"
#include "eReplicaComponentType.h"
#include <array>
#include "Loot.h"
enum class eGameActivity : uint32_t;
@@ -65,13 +66,13 @@ class CharacterComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::CHARACTER;
CharacterComponent(Entity* parent, Character* character);
CharacterComponent(Entity* parent, Character* character, const SystemAddress& systemAddress);
~CharacterComponent() override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Updates the rocket configuration using a LOT string separated by commas
@@ -289,6 +290,22 @@ public:
*/
void SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId = 0) const;
const SystemAddress& GetSystemAddress() const;
const NiPoint3& GetRespawnPosition() const { return m_respawnPos; };
void SetRespawnPos(const NiPoint3& position);
const NiQuaternion& GetRespawnRotation() const { return m_respawnRot; };
void SetRespawnRot(const NiQuaternion& rotation);
std::map<LWOOBJID, Loot::Info>& GetDroppedLoot() { return m_DroppedLoot; };
uint64_t GetDroppedCoins() const { return m_DroppedCoins; };
void SetDroppedCoins(const uint64_t value) { m_DroppedCoins = value; };
/**
* Character info regarding this character, including clothing styles, etc.
*/
@@ -579,6 +596,16 @@ private:
std::array<uint64_t, 4> m_ClaimCodes{};
void AwardClaimCodes();
SystemAddress m_SystemAddress;
NiPoint3 m_respawnPos;
NiQuaternion m_respawnRot;
std::map<LWOOBJID, Loot::Info> m_DroppedLoot;
uint64_t m_DroppedCoins = 0;
};
#endif // CHARACTERCOMPONENT_H

View File

@@ -1,5 +1,5 @@
#include "CollectibleComponent.h"
void CollectibleComponent::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) {
outBitStream->Write(GetCollectibleId());
void CollectibleComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
outBitStream.Write(GetCollectibleId());
}

View File

@@ -10,7 +10,7 @@ public:
CollectibleComponent(Entity* parentEntity, int32_t collectibleId) : Component(parentEntity), m_CollectibleId(collectibleId) {}
int16_t GetCollectibleId() const { return m_CollectibleId; }
void Serialize(RakNet::BitStream* outBitStream, bool isConstruction) override;
void Serialize(RakNet::BitStream& outBitStream, bool isConstruction) override;
private:
int16_t m_CollectibleId = 0;
};

View File

@@ -29,6 +29,6 @@ void Component::LoadFromXml(tinyxml2::XMLDocument* doc) {
}
void Component::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) {
void Component::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
}

View File

@@ -42,7 +42,7 @@ public:
*/
virtual void LoadFromXml(tinyxml2::XMLDocument* doc);
virtual void Serialize(RakNet::BitStream* outBitStream, bool isConstruction);
virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction);
protected:

View File

@@ -21,8 +21,6 @@ ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity) : Phy
m_InJetpackMode = false;
m_IsOnGround = true;
m_IsOnRail = false;
m_DirtyVelocity = true;
m_DirtyAngularVelocity = true;
m_dpEntity = nullptr;
m_Static = false;
m_SpeedMultiplier = 1;
@@ -71,90 +69,92 @@ void ControllablePhysicsComponent::Update(float deltaTime) {
}
void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void ControllablePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
//If this is a creation, then we assume the position is dirty, even when it isn't.
//This is because new clients will still need to receive the position.
//if (bIsInitialUpdate) m_DirtyPosition = true;
if (bIsInitialUpdate) {
outBitStream->Write(m_InJetpackMode);
outBitStream.Write(m_InJetpackMode);
if (m_InJetpackMode) {
outBitStream->Write(m_JetpackEffectID);
outBitStream->Write(m_JetpackFlying);
outBitStream->Write(m_JetpackBypassChecks);
outBitStream.Write(m_JetpackEffectID);
outBitStream.Write(m_JetpackFlying);
outBitStream.Write(m_JetpackBypassChecks);
}
outBitStream->Write1(); // always write these on construction
outBitStream->Write(m_ImmuneToStunMoveCount);
outBitStream->Write(m_ImmuneToStunJumpCount);
outBitStream->Write(m_ImmuneToStunTurnCount);
outBitStream->Write(m_ImmuneToStunAttackCount);
outBitStream->Write(m_ImmuneToStunUseItemCount);
outBitStream->Write(m_ImmuneToStunEquipCount);
outBitStream->Write(m_ImmuneToStunInteractCount);
outBitStream.Write1(); // always write these on construction
outBitStream.Write(m_ImmuneToStunMoveCount);
outBitStream.Write(m_ImmuneToStunJumpCount);
outBitStream.Write(m_ImmuneToStunTurnCount);
outBitStream.Write(m_ImmuneToStunAttackCount);
outBitStream.Write(m_ImmuneToStunUseItemCount);
outBitStream.Write(m_ImmuneToStunEquipCount);
outBitStream.Write(m_ImmuneToStunInteractCount);
}
if (m_IgnoreMultipliers) m_DirtyCheats = false;
outBitStream->Write(m_DirtyCheats);
outBitStream.Write(m_DirtyCheats);
if (m_DirtyCheats) {
outBitStream->Write(m_GravityScale);
outBitStream->Write(m_SpeedMultiplier);
outBitStream.Write(m_GravityScale);
outBitStream.Write(m_SpeedMultiplier);
m_DirtyCheats = false;
}
outBitStream->Write(m_DirtyEquippedItemInfo);
outBitStream.Write(m_DirtyEquippedItemInfo);
if (m_DirtyEquippedItemInfo) {
outBitStream->Write(m_PickupRadius);
outBitStream->Write(m_InJetpackMode);
outBitStream.Write(m_PickupRadius);
outBitStream.Write(m_InJetpackMode);
m_DirtyEquippedItemInfo = false;
}
outBitStream->Write(m_DirtyBubble);
outBitStream.Write(m_DirtyBubble);
if (m_DirtyBubble) {
outBitStream->Write(m_IsInBubble);
outBitStream.Write(m_IsInBubble);
if (m_IsInBubble) {
outBitStream->Write(m_BubbleType);
outBitStream->Write(m_SpecialAnims);
outBitStream.Write(m_BubbleType);
outBitStream.Write(m_SpecialAnims);
}
m_DirtyBubble = false;
}
outBitStream->Write(m_DirtyPosition || bIsInitialUpdate);
outBitStream.Write(m_DirtyPosition || bIsInitialUpdate);
if (m_DirtyPosition || bIsInitialUpdate) {
outBitStream->Write(m_Position.x);
outBitStream->Write(m_Position.y);
outBitStream->Write(m_Position.z);
outBitStream.Write(m_Position.x);
outBitStream.Write(m_Position.y);
outBitStream.Write(m_Position.z);
outBitStream->Write(m_Rotation.x);
outBitStream->Write(m_Rotation.y);
outBitStream->Write(m_Rotation.z);
outBitStream->Write(m_Rotation.w);
outBitStream.Write(m_Rotation.x);
outBitStream.Write(m_Rotation.y);
outBitStream.Write(m_Rotation.z);
outBitStream.Write(m_Rotation.w);
outBitStream->Write(m_IsOnGround);
outBitStream->Write(m_IsOnRail);
outBitStream.Write(m_IsOnGround);
outBitStream.Write(m_IsOnRail);
outBitStream->Write(m_DirtyVelocity);
if (m_DirtyVelocity) {
outBitStream->Write(m_Velocity.x);
outBitStream->Write(m_Velocity.y);
outBitStream->Write(m_Velocity.z);
bool isNotZero = m_Velocity != NiPoint3Constant::ZERO;
outBitStream.Write(isNotZero);
if (isNotZero) {
outBitStream.Write(m_Velocity.x);
outBitStream.Write(m_Velocity.y);
outBitStream.Write(m_Velocity.z);
}
outBitStream->Write(m_DirtyAngularVelocity);
if (m_DirtyAngularVelocity) {
outBitStream->Write(m_AngularVelocity.x);
outBitStream->Write(m_AngularVelocity.y);
outBitStream->Write(m_AngularVelocity.z);
isNotZero = m_AngularVelocity != NiPoint3Constant::ZERO;
outBitStream.Write(isNotZero);
if (isNotZero) {
outBitStream.Write(m_AngularVelocity.x);
outBitStream.Write(m_AngularVelocity.y);
outBitStream.Write(m_AngularVelocity.z);
}
outBitStream->Write0();
}
if (!bIsInitialUpdate) {
outBitStream->Write(m_IsTeleporting);
m_IsTeleporting = false;
outBitStream.Write0();
if (!bIsInitialUpdate) {
m_DirtyPosition = false;
outBitStream.Write(m_IsTeleporting);
m_IsTeleporting = false;
}
}
}
@@ -211,33 +211,29 @@ void ControllablePhysicsComponent::SetRotation(const NiQuaternion& rot) {
}
void ControllablePhysicsComponent::SetVelocity(const NiPoint3& vel) {
if (m_Static) {
return;
}
if (m_Static || m_Velocity == vel) return;
m_Velocity = vel;
m_DirtyPosition = true;
m_DirtyVelocity = true;
if (m_dpEntity) m_dpEntity->SetVelocity(vel);
}
void ControllablePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) {
if (m_Static) {
return;
}
if (m_Static || m_AngularVelocity == vel) return;
m_AngularVelocity = vel;
m_DirtyPosition = true;
m_DirtyAngularVelocity = true;
}
void ControllablePhysicsComponent::SetIsOnGround(bool val) {
if (m_IsOnGround == val) return;
m_DirtyPosition = true;
m_IsOnGround = val;
}
void ControllablePhysicsComponent::SetIsOnRail(bool val) {
if (m_IsOnRail == val) return;
m_DirtyPosition = true;
m_IsOnRail = val;
}
@@ -245,15 +241,6 @@ void ControllablePhysicsComponent::SetIsOnRail(bool val) {
void ControllablePhysicsComponent::SetDirtyPosition(bool val) {
m_DirtyPosition = val;
}
void ControllablePhysicsComponent::SetDirtyVelocity(bool val) {
m_DirtyVelocity = val;
}
void ControllablePhysicsComponent::SetDirtyAngularVelocity(bool val) {
m_DirtyAngularVelocity = val;
}
void ControllablePhysicsComponent::AddPickupRadiusScale(float value) {
m_ActivePickupRadiusScales.push_back(value);
if (value > m_PickupRadius) {
@@ -309,7 +296,7 @@ void ControllablePhysicsComponent::RemoveSpeedboost(float value) {
Game::entityManager->SerializeEntity(m_Parent);
}
void ControllablePhysicsComponent::ActivateBubbleBuff(eBubbleType bubbleType, bool specialAnims){
void ControllablePhysicsComponent::ActivateBubbleBuff(eBubbleType bubbleType, bool specialAnims) {
if (m_IsInBubble) {
LOG("Already in bubble");
return;
@@ -321,7 +308,7 @@ void ControllablePhysicsComponent::ActivateBubbleBuff(eBubbleType bubbleType, bo
Game::entityManager->SerializeEntity(m_Parent);
}
void ControllablePhysicsComponent::DeactivateBubbleBuff(){
void ControllablePhysicsComponent::DeactivateBubbleBuff() {
m_DirtyBubble = true;
m_IsInBubble = false;
Game::entityManager->SerializeEntity(m_Parent);
@@ -336,9 +323,9 @@ void ControllablePhysicsComponent::SetStunImmunity(
const bool bImmuneToStunJump,
const bool bImmuneToStunMove,
const bool bImmuneToStunTurn,
const bool bImmuneToStunUseItem){
const bool bImmuneToStunUseItem) {
if (state == eStateChangeType::POP){
if (state == eStateChangeType::POP) {
if (bImmuneToStunAttack && m_ImmuneToStunAttackCount > 0) m_ImmuneToStunAttackCount -= 1;
if (bImmuneToStunEquip && m_ImmuneToStunEquipCount > 0) m_ImmuneToStunEquipCount -= 1;
if (bImmuneToStunInteract && m_ImmuneToStunInteractCount > 0) m_ImmuneToStunInteractCount -= 1;

View File

@@ -27,7 +27,7 @@ public:
~ControllablePhysicsComponent() override;
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
@@ -104,18 +104,6 @@ public:
*/
void SetDirtyPosition(bool val);
/**
* Mark the velocity as dirty, forcing a serializtion update next tick
* @param val whether or not the velocity is dirty
*/
void SetDirtyVelocity(bool val);
/**
* Mark the angular velocity as dirty, forcing a serialization update next tick
* @param val whether or not the angular velocity is dirty
*/
void SetDirtyAngularVelocity(bool val);
/**
* Sets whether or not the entity is currently wearing a jetpack
* @param val whether or not the entity is currently wearing a jetpack
@@ -310,21 +298,11 @@ private:
*/
dpEntity* m_dpEntity;
/**
* Whether or not the velocity is dirty, forcing a serialization of the velocity
*/
bool m_DirtyVelocity;
/**
* The current velocity of the entity
*/
NiPoint3 m_Velocity;
/**
* Whether or not the angular velocity is dirty, forcing a serialization
*/
bool m_DirtyAngularVelocity;
/**
* The current angular velocity of the entity
*/

View File

@@ -81,7 +81,7 @@ DestroyableComponent::~DestroyableComponent() {
}
void DestroyableComponent::Reinitialize(LOT templateID) {
CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
int32_t buffComponentID = compRegistryTable->GetByIDAndType(templateID, eReplicaComponentType::BUFF);
int32_t collectibleComponentID = compRegistryTable->GetByIDAndType(templateID, eReplicaComponentType::COLLECTIBLE);
@@ -92,7 +92,7 @@ void DestroyableComponent::Reinitialize(LOT templateID) {
if (quickBuildComponentID > 0) componentID = quickBuildComponentID;
if (buffComponentID > 0) componentID = buffComponentID;
CDDestructibleComponentTable* destCompTable = CDClientManager::Instance().GetTable<CDDestructibleComponentTable>();
CDDestructibleComponentTable* destCompTable = CDClientManager::GetTable<CDDestructibleComponentTable>();
std::vector<CDDestructibleComponent> destCompData = destCompTable->Query([=](CDDestructibleComponent entry) { return (entry.id == componentID); });
if (componentID > 0) {
@@ -122,61 +122,61 @@ void DestroyableComponent::Reinitialize(LOT templateID) {
}
}
void DestroyableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void DestroyableComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) {
outBitStream->Write1(); // always write these on construction
outBitStream->Write(m_ImmuneToBasicAttackCount);
outBitStream->Write(m_ImmuneToDamageOverTimeCount);
outBitStream->Write(m_ImmuneToKnockbackCount);
outBitStream->Write(m_ImmuneToInterruptCount);
outBitStream->Write(m_ImmuneToSpeedCount);
outBitStream->Write(m_ImmuneToImaginationGainCount);
outBitStream->Write(m_ImmuneToImaginationLossCount);
outBitStream->Write(m_ImmuneToQuickbuildInterruptCount);
outBitStream->Write(m_ImmuneToPullToPointCount);
outBitStream.Write1(); // always write these on construction
outBitStream.Write(m_ImmuneToBasicAttackCount);
outBitStream.Write(m_ImmuneToDamageOverTimeCount);
outBitStream.Write(m_ImmuneToKnockbackCount);
outBitStream.Write(m_ImmuneToInterruptCount);
outBitStream.Write(m_ImmuneToSpeedCount);
outBitStream.Write(m_ImmuneToImaginationGainCount);
outBitStream.Write(m_ImmuneToImaginationLossCount);
outBitStream.Write(m_ImmuneToQuickbuildInterruptCount);
outBitStream.Write(m_ImmuneToPullToPointCount);
}
outBitStream->Write(m_DirtyHealth || bIsInitialUpdate);
outBitStream.Write(m_DirtyHealth || bIsInitialUpdate);
if (m_DirtyHealth || bIsInitialUpdate) {
outBitStream->Write(m_iHealth);
outBitStream->Write(m_fMaxHealth);
outBitStream->Write(m_iArmor);
outBitStream->Write(m_fMaxArmor);
outBitStream->Write(m_iImagination);
outBitStream->Write(m_fMaxImagination);
outBitStream.Write(m_iHealth);
outBitStream.Write(m_fMaxHealth);
outBitStream.Write(m_iArmor);
outBitStream.Write(m_fMaxArmor);
outBitStream.Write(m_iImagination);
outBitStream.Write(m_fMaxImagination);
outBitStream->Write(m_DamageToAbsorb);
outBitStream->Write(IsImmune());
outBitStream->Write(m_IsGMImmune);
outBitStream->Write(m_IsShielded);
outBitStream.Write(m_DamageToAbsorb);
outBitStream.Write(IsImmune());
outBitStream.Write(m_IsGMImmune);
outBitStream.Write(m_IsShielded);
outBitStream->Write(m_fMaxHealth);
outBitStream->Write(m_fMaxArmor);
outBitStream->Write(m_fMaxImagination);
outBitStream.Write(m_fMaxHealth);
outBitStream.Write(m_fMaxArmor);
outBitStream.Write(m_fMaxImagination);
outBitStream->Write<uint32_t>(m_FactionIDs.size());
outBitStream.Write<uint32_t>(m_FactionIDs.size());
for (size_t i = 0; i < m_FactionIDs.size(); ++i) {
outBitStream->Write(m_FactionIDs[i]);
outBitStream.Write(m_FactionIDs[i]);
}
outBitStream->Write(m_IsSmashable);
outBitStream.Write(m_IsSmashable);
if (bIsInitialUpdate) {
outBitStream->Write(m_IsDead);
outBitStream->Write(m_IsSmashed);
outBitStream.Write(m_IsDead);
outBitStream.Write(m_IsSmashed);
if (m_IsSmashable) {
outBitStream->Write(m_IsModuleAssembly);
outBitStream->Write(m_ExplodeFactor != 1.0f);
if (m_ExplodeFactor != 1.0f) outBitStream->Write(m_ExplodeFactor);
outBitStream.Write(m_IsModuleAssembly);
outBitStream.Write(m_ExplodeFactor != 1.0f);
if (m_ExplodeFactor != 1.0f) outBitStream.Write(m_ExplodeFactor);
}
}
m_DirtyHealth = false;
}
outBitStream->Write(m_DirtyThreatList || bIsInitialUpdate);
outBitStream.Write(m_DirtyThreatList || bIsInitialUpdate);
if (m_DirtyThreatList || bIsInitialUpdate) {
outBitStream->Write(m_HasThreats);
outBitStream.Write(m_HasThreats);
m_DirtyThreatList = false;
}
}
@@ -251,13 +251,14 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) {
if (playAnim) {
// Now update the player bar
if (!m_Parent->GetParentUser()) return;
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
if (!characterComponent) return;
AMFArrayValue args;
args.Insert("amount", std::to_string(difference));
args.Insert("type", "health");
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
}
Game::entityManager->SerializeEntity(m_Parent);
@@ -292,13 +293,14 @@ void DestroyableComponent::SetMaxArmor(float value, bool playAnim) {
if (playAnim) {
// Now update the player bar
if (!m_Parent->GetParentUser()) return;
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
if (!characterComponent) return;
AMFArrayValue args;
args.Insert("amount", std::to_string(value));
args.Insert("type", "armor");
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
}
Game::entityManager->SerializeEntity(m_Parent);
@@ -332,13 +334,14 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) {
if (playAnim) {
// Now update the player bar
if (!m_Parent->GetParentUser()) return;
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
if (!characterComponent) return;
AMFArrayValue args;
args.Insert("amount", std::to_string(difference));
args.Insert("type", "imagination");
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
GameMessages::SendUIMessageServerToSingleClient(m_Parent, characterComponent->GetSystemAddress(), "MaxPlayerBarUpdate", args);
}
Game::entityManager->SerializeEntity(m_Parent);
}

View File

@@ -25,7 +25,7 @@ public:
~DestroyableComponent() override;
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;

View File

@@ -36,13 +36,13 @@ void DonationVendorComponent::SubmitDonation(uint32_t count) {
m_DirtyDonationVendor = true;
}
void DonationVendorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void DonationVendorComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
VendorComponent::Serialize(outBitStream, bIsInitialUpdate);
outBitStream->Write(bIsInitialUpdate || m_DirtyDonationVendor);
outBitStream.Write(bIsInitialUpdate || m_DirtyDonationVendor);
if (bIsInitialUpdate || m_DirtyDonationVendor) {
outBitStream->Write(m_PercentComplete);
outBitStream->Write(m_TotalDonated);
outBitStream->Write(m_TotalRemaining);
outBitStream.Write(m_PercentComplete);
outBitStream.Write(m_TotalDonated);
outBitStream.Write(m_TotalRemaining);
if (!bIsInitialUpdate) m_DirtyDonationVendor = false;
}
}

View File

@@ -10,7 +10,7 @@ class DonationVendorComponent final : public VendorComponent {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::DONATION_VENDOR;
DonationVendorComponent(Entity* parent);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
uint32_t GetActivityID() {return m_ActivityId;};
void SubmitDonation(uint32_t count);

View File

@@ -1,14 +1,14 @@
#include "GhostComponent.h"
GhostComponent::GhostComponent(Entity* parent) : Component(parent) {
m_GhostReferencePoint = NiPoint3::ZERO;
m_GhostOverridePoint = NiPoint3::ZERO;
m_GhostReferencePoint = NiPoint3Constant::ZERO;
m_GhostOverridePoint = NiPoint3Constant::ZERO;
m_GhostOverride = false;
}
GhostComponent::~GhostComponent() {
for (auto& observedEntity : m_ObservedEntities) {
if (observedEntity == 0) continue;
if (observedEntity == LWOOBJID_EMPTY) continue;
auto* entity = Game::entityManager->GetGhostCandidate(observedEntity);
if (!entity) continue;
@@ -44,14 +44,14 @@ void GhostComponent::ConstructLimboEntities() {
m_LimboConstructions.clear();
}
void GhostComponent::ObserveEntity(int32_t id) {
void GhostComponent::ObserveEntity(LWOOBJID id) {
m_ObservedEntities.insert(id);
}
bool GhostComponent::IsObserved(int32_t id) {
bool GhostComponent::IsObserved(LWOOBJID id) {
return m_ObservedEntities.contains(id);
}
void GhostComponent::GhostEntity(int32_t id) {
void GhostComponent::GhostEntity(LWOOBJID id) {
m_ObservedEntities.erase(id);
}

View File

@@ -33,18 +33,18 @@ public:
void ConstructLimboEntities();
void ObserveEntity(const int32_t id);
void ObserveEntity(const LWOOBJID id);
bool IsObserved(const int32_t id);
bool IsObserved(const LWOOBJID id);
void GhostEntity(const int32_t id);
void GhostEntity(const LWOOBJID id);
private:
NiPoint3 m_GhostReferencePoint;
NiPoint3 m_GhostOverridePoint;
std::unordered_set<int32_t> m_ObservedEntities;
std::unordered_set<LWOOBJID> m_ObservedEntities;
std::unordered_set<LWOOBJID> m_LimboConstructions;

View File

@@ -2,13 +2,11 @@
#include "EntityManager.h"
HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent) : PhysicsComponent(parent) {
m_Velocity = NiPoint3::ZERO;
m_AngularVelocity = NiPoint3::ZERO;
m_Velocity = NiPoint3Constant::ZERO;
m_AngularVelocity = NiPoint3Constant::ZERO;
m_IsOnGround = true;
m_IsOnRail = false;
m_DirtyPosition = true;
m_DirtyVelocity = true;
m_DirtyAngularVelocity = true;
m_EndBehavior = GeneralUtils::GenerateRandomNumber<uint32_t>(0, 7);
}
@@ -37,85 +35,66 @@ void HavokVehiclePhysicsComponent::SetIsOnRail(bool val) {
}
void HavokVehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) {
if (m_RemoteInputInfo == remoteInputInfo) return;
if (remoteInputInfo == m_RemoteInputInfo) return;
this->m_RemoteInputInfo = remoteInputInfo;
m_DirtyRemoteInput = true;
m_DirtyPosition = true;
}
void HavokVehiclePhysicsComponent::SetDirtyVelocity(bool val) {
m_DirtyVelocity = val;
}
void HavokVehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) {
m_DirtyAngularVelocity = val;
}
void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(bIsInitialUpdate || m_DirtyPosition);
void HavokVehiclePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(bIsInitialUpdate || m_DirtyPosition);
if (bIsInitialUpdate || m_DirtyPosition) {
m_DirtyPosition = false;
outBitStream->Write(m_Position.x);
outBitStream->Write(m_Position.y);
outBitStream->Write(m_Position.z);
outBitStream.Write(m_Position.x);
outBitStream.Write(m_Position.y);
outBitStream.Write(m_Position.z);
outBitStream->Write(m_Rotation.x);
outBitStream->Write(m_Rotation.y);
outBitStream->Write(m_Rotation.z);
outBitStream->Write(m_Rotation.w);
outBitStream.Write(m_Rotation.x);
outBitStream.Write(m_Rotation.y);
outBitStream.Write(m_Rotation.z);
outBitStream.Write(m_Rotation.w);
outBitStream->Write(m_IsOnGround);
outBitStream->Write(m_IsOnRail);
outBitStream.Write(m_IsOnGround);
outBitStream.Write(m_IsOnRail);
outBitStream->Write(bIsInitialUpdate || m_DirtyVelocity);
if (bIsInitialUpdate || m_DirtyVelocity) {
outBitStream->Write(m_Velocity.x);
outBitStream->Write(m_Velocity.y);
outBitStream->Write(m_Velocity.z);
m_DirtyVelocity = false;
bool isNotZero = m_Velocity != NiPoint3Constant::ZERO;
outBitStream.Write(isNotZero);
if (isNotZero) {
outBitStream.Write(m_Velocity.x);
outBitStream.Write(m_Velocity.y);
outBitStream.Write(m_Velocity.z);
}
outBitStream->Write(bIsInitialUpdate || m_DirtyAngularVelocity);
if (bIsInitialUpdate || m_DirtyAngularVelocity) {
outBitStream->Write(m_AngularVelocity.x);
outBitStream->Write(m_AngularVelocity.y);
outBitStream->Write(m_AngularVelocity.z);
m_DirtyAngularVelocity = false;
isNotZero = m_AngularVelocity != NiPoint3Constant::ZERO;
outBitStream.Write(isNotZero);
if (isNotZero) {
outBitStream.Write(m_AngularVelocity.x);
outBitStream.Write(m_AngularVelocity.y);
outBitStream.Write(m_AngularVelocity.z);
}
outBitStream->Write0(); // local_space_info. TODO: Implement this
outBitStream.Write0(); // local_space_info. TODO: Implement this
outBitStream->Write(m_DirtyRemoteInput || bIsInitialUpdate); // remote_input_info
if (m_DirtyRemoteInput || bIsInitialUpdate) {
outBitStream->Write(m_RemoteInputInfo.m_RemoteInputX);
outBitStream->Write(m_RemoteInputInfo.m_RemoteInputY);
outBitStream->Write(m_RemoteInputInfo.m_IsPowersliding);
outBitStream->Write(m_RemoteInputInfo.m_IsModified);
m_DirtyRemoteInput = false;
}
// This structure only has this bool flag set to false if a ptr to the peVehicle is null, which we don't have
// therefore, this will always be 1, even if all the values in the structure are 0.
outBitStream.Write1(); // has remote_input_info
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputX);
outBitStream.Write(m_RemoteInputInfo.m_RemoteInputY);
outBitStream.Write(m_RemoteInputInfo.m_IsPowersliding);
outBitStream.Write(m_RemoteInputInfo.m_IsModified);
outBitStream->Write(125.0f); // remote_input_ping TODO: Figure out how this should be calculated as it seems to be constant through the whole race.
outBitStream.Write(125.0f); // remote_input_ping TODO: Figure out how this should be calculated as it seems to be constant through the whole race.
if (!bIsInitialUpdate) {
outBitStream->Write0();
outBitStream.Write0();
}
}
if (bIsInitialUpdate) {
outBitStream->Write<uint8_t>(m_EndBehavior);
outBitStream->Write1(); // is input locked?
outBitStream.Write<uint8_t>(m_EndBehavior);
outBitStream.Write1(); // is input locked?
}
outBitStream->Write0();
}
void HavokVehiclePhysicsComponent::Update(float deltaTime) {
if (m_SoftUpdate > 5) {
Game::entityManager->SerializeEntity(m_Parent);
m_SoftUpdate = 0;
} else {
m_SoftUpdate += deltaTime;
}
outBitStream.Write0();
}

View File

@@ -15,9 +15,7 @@ public:
HavokVehiclePhysicsComponent(Entity* parentEntity);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Sets the velocity
@@ -67,22 +65,16 @@ public:
*/
const bool GetIsOnRail() const { return m_IsOnRail; }
void SetDirtyPosition(bool val);
void SetDirtyVelocity(bool val);
void SetDirtyAngularVelocity(bool val);
void SetRemoteInputInfo(const RemoteInputInfo&);
private:
bool m_DirtyVelocity;
NiPoint3 m_Velocity;
bool m_DirtyAngularVelocity;
NiPoint3 m_AngularVelocity;
bool m_IsOnGround;
bool m_IsOnRail;
float m_SoftUpdate = 0;
uint32_t m_EndBehavior;
RemoteInputInfo m_RemoteInputInfo;
bool m_DirtyRemoteInput;
};

View File

@@ -14,7 +14,6 @@
#include "Character.h"
#include "EntityManager.h"
#include "ItemSet.h"
#include "Player.h"
#include "PetComponent.h"
#include "PossessorComponent.h"
#include "PossessableComponent.h"
@@ -56,10 +55,10 @@ InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* do
return;
}
auto* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
auto* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
const auto componentId = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::INVENTORY);
auto* inventoryComponentTable = CDClientManager::Instance().GetTable<CDInventoryComponentTable>();
auto* inventoryComponentTable = CDClientManager::GetTable<CDInventoryComponentTable>();
auto items = inventoryComponentTable->Query([=](const CDInventoryComponent entry) { return entry.id == componentId; });
auto slot = 0u;
@@ -695,11 +694,11 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
}
}
void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool bIsInitialUpdate) {
void InventoryComponent::Serialize(RakNet::BitStream& outBitStream, const bool bIsInitialUpdate) {
if (bIsInitialUpdate || m_Dirty) {
outBitStream->Write(true);
outBitStream.Write(true);
outBitStream->Write<uint32_t>(m_Equipped.size());
outBitStream.Write<uint32_t>(m_Equipped.size());
for (const auto& pair : m_Equipped) {
const auto item = pair.second;
@@ -708,21 +707,21 @@ void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool b
AddItemSkills(item.lot);
}
outBitStream->Write(item.id);
outBitStream->Write(item.lot);
outBitStream.Write(item.id);
outBitStream.Write(item.lot);
outBitStream->Write0();
outBitStream.Write0();
outBitStream->Write(item.count > 0);
if (item.count > 0) outBitStream->Write(item.count);
outBitStream.Write(item.count > 0);
if (item.count > 0) outBitStream.Write(item.count);
outBitStream->Write(item.slot != 0);
if (item.slot != 0) outBitStream->Write<uint16_t>(item.slot);
outBitStream.Write(item.slot != 0);
if (item.slot != 0) outBitStream.Write<uint16_t>(item.slot);
outBitStream->Write0();
outBitStream.Write0();
bool flag = !item.config.empty();
outBitStream->Write(flag);
outBitStream.Write(flag);
if (flag) {
RakNet::BitStream ldfStream;
ldfStream.Write<int32_t>(item.config.size()); // Key count
@@ -731,26 +730,26 @@ void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool b
std::string newRocketStr = data->GetValueAsString() + ";";
GeneralUtils::ReplaceInString(newRocketStr, "+", ";");
LDFData<std::u16string>* ldf_data = new LDFData<std::u16string>(u"assemblyPartLOTs", GeneralUtils::ASCIIToUTF16(newRocketStr));
ldf_data->WriteToPacket(&ldfStream);
ldf_data->WriteToPacket(ldfStream);
delete ldf_data;
} else {
data->WriteToPacket(&ldfStream);
data->WriteToPacket(ldfStream);
}
}
outBitStream->Write(ldfStream.GetNumberOfBytesUsed() + 1);
outBitStream->Write<uint8_t>(0); // Don't compress
outBitStream->Write(ldfStream);
outBitStream.Write(ldfStream.GetNumberOfBytesUsed() + 1);
outBitStream.Write<uint8_t>(0); // Don't compress
outBitStream.Write(ldfStream);
}
outBitStream->Write1();
outBitStream.Write1();
}
m_Dirty = false;
} else {
outBitStream->Write(false);
outBitStream.Write(false);
}
outBitStream->Write(false);
outBitStream.Write(false);
}
void InventoryComponent::Update(float deltaTime) {
@@ -910,11 +909,11 @@ void InventoryComponent::UnEquipItem(Item* item) {
void InventoryComponent::EquipScripts(Item* equippedItem) {
CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
if (!compRegistryTable) return;
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(equippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
if (scriptComponentID > -1) {
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
CDScriptComponentTable* scriptCompTable = CDClientManager::GetTable<CDScriptComponentTable>();
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
if (!itemScript) {
@@ -925,11 +924,11 @@ void InventoryComponent::EquipScripts(Item* equippedItem) {
}
void InventoryComponent::UnequipScripts(Item* unequippedItem) {
CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
if (!compRegistryTable) return;
int32_t scriptComponentID = compRegistryTable->GetByIDAndType(unequippedItem->GetLot(), eReplicaComponentType::SCRIPT, -1);
if (scriptComponentID > -1) {
CDScriptComponentTable* scriptCompTable = CDClientManager::Instance().GetTable<CDScriptComponentTable>();
CDScriptComponentTable* scriptCompTable = CDClientManager::GetTable<CDScriptComponentTable>();
CDScriptComponent scriptCompData = scriptCompTable->GetByID(scriptComponentID);
auto* itemScript = CppScripts::GetScript(m_Parent, scriptCompData.script_name);
if (!itemScript) {
@@ -1223,7 +1222,7 @@ void InventoryComponent::SpawnPet(Item* item) {
EntityInfo info{};
info.lot = item->GetLot();
info.pos = m_Parent->GetPosition();
info.rot = NiQuaternion::IDENTITY;
info.rot = NiQuaternionConstant::IDENTITY;
info.spawnerID = m_Parent->GetObjectID();
auto* pet = Game::entityManager->CreateEntity(info);
@@ -1281,7 +1280,7 @@ bool InventoryComponent::IsTransferInventory(eInventoryType type) {
}
uint32_t InventoryComponent::FindSkill(const LOT lot) {
auto* table = CDClientManager::Instance().GetTable<CDObjectSkillsTable>();
auto* table = CDClientManager::GetTable<CDObjectSkillsTable>();
const auto results = table->Query([=](const CDObjectSkills& entry) {
return entry.objectTemplate == static_cast<unsigned int>(lot);
@@ -1299,8 +1298,8 @@ uint32_t InventoryComponent::FindSkill(const LOT lot) {
std::vector<uint32_t> InventoryComponent::FindBuffs(Item* item, bool castOnEquip) const {
std::vector<uint32_t> buffs;
if (item == nullptr) return buffs;
auto* table = CDClientManager::Instance().GetTable<CDObjectSkillsTable>();
auto* behaviors = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
auto* table = CDClientManager::GetTable<CDObjectSkillsTable>();
auto* behaviors = CDClientManager::GetTable<CDSkillBehaviorTable>();
const auto results = table->Query([=](const CDObjectSkills& entry) {
return entry.objectTemplate == static_cast<unsigned int>(item->GetLot());

View File

@@ -41,7 +41,7 @@ public:
explicit InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document = nullptr);
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void LoadXml(tinyxml2::XMLDocument* document);
void UpdateXml(tinyxml2::XMLDocument* document) override;

View File

@@ -1,5 +1,5 @@
#include "ItemComponent.h"
void ItemComponent::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) {
outBitStream->Write0();
void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
outBitStream.Write0();
}

View File

@@ -10,7 +10,7 @@ public:
ItemComponent(Entity* entity) : Component(entity) {}
void Serialize(RakNet::BitStream* bitStream, bool isConstruction) override;
void Serialize(RakNet::BitStream& bitStream, bool isConstruction) override;
};
#endif //!__ITEMCOMPONENT__H__

View File

@@ -15,10 +15,10 @@ void LUPExhibitComponent::NextLUPExhibit() {
Game::entityManager->SerializeEntity(m_Parent);
}
void LUPExhibitComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_DirtyLUPExhibit);
void LUPExhibitComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_DirtyLUPExhibit);
if (m_DirtyLUPExhibit) {
outBitStream->Write(m_LUPExhibits[m_LUPExhibitIndex % m_LUPExhibits.size()]);
outBitStream.Write(m_LUPExhibits[m_LUPExhibitIndex % m_LUPExhibits.size()]);
if (!bIsInitialUpdate) m_DirtyLUPExhibit = false;
}
}

View File

@@ -18,7 +18,7 @@ public:
LUPExhibitComponent(Entity* parent) : Component(parent) {};
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void NextLUPExhibit();
private:
float m_UpdateTimer = 0.0f;

View File

@@ -37,14 +37,14 @@ void LevelProgressionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
m_CharacterVersion = static_cast<eCharacterVersion>(characterVersion);
}
void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(bIsInitialUpdate || m_DirtyLevelInfo);
if (bIsInitialUpdate || m_DirtyLevelInfo) outBitStream->Write(m_Level);
void LevelProgressionComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(bIsInitialUpdate || m_DirtyLevelInfo);
if (bIsInitialUpdate || m_DirtyLevelInfo) outBitStream.Write(m_Level);
m_DirtyLevelInfo = false;
}
void LevelProgressionComponent::HandleLevelUp() {
auto* rewardsTable = CDClientManager::Instance().GetTable<CDRewardsTable>();
auto* rewardsTable = CDClientManager::GetTable<CDRewardsTable>();
const auto& rewards = rewardsTable->GetByLevelID(m_Level);
bool rewardingItem = rewards.size() > 0;

View File

@@ -21,7 +21,7 @@ public:
*/
LevelProgressionComponent(Entity* parent);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Save data from this componennt to character XML

View File

@@ -1,5 +1,5 @@
#include "MiniGameControlComponent.h"
void MiniGameControlComponent::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) {
outBitStream->Write<uint32_t>(0x40000000);
void MiniGameControlComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
outBitStream.Write<uint32_t>(0x40000000);
}

View File

@@ -9,7 +9,7 @@ public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::MINI_GAME_CONTROL;
MiniGameControlComponent(Entity* parent) : Component(parent) {}
void Serialize(RakNet::BitStream* outBitStream, bool isConstruction);
void Serialize(RakNet::BitStream& outBitStream, bool isConstruction);
};
#endif //!__MINIGAMECONTROLCOMPONENT__H__

View File

@@ -1,5 +1,5 @@
#include "MinigameComponent.h"
void MinigameComponent::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) {
outBitStream->Write<uint32_t>(0x40000000);
void MinigameComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
outBitStream.Write<uint32_t>(0x40000000);
}

View File

@@ -266,7 +266,7 @@ void MissionComponent::ForceProgressValue(uint32_t missionId, uint32_t taskType,
}
bool MissionComponent::GetMissionInfo(uint32_t missionId, CDMissions& result) {
auto* missionsTable = CDClientManager::Instance().GetTable<CDMissionsTable>();
auto* missionsTable = CDClientManager::GetTable<CDMissionsTable>();
const auto missions = missionsTable->Query([=](const CDMissions& entry) {
return entry.id == static_cast<int>(missionId);
@@ -320,8 +320,8 @@ const std::vector<uint32_t> MissionComponent::LookForAchievements(eMissionTaskTy
return acceptedAchievements;
#else
auto* missionTasksTable = CDClientManager::Instance().GetTable<CDMissionTasksTable>();
auto* missionsTable = CDClientManager::Instance().GetTable<CDMissionsTable>();
auto* missionTasksTable = CDClientManager::GetTable<CDMissionTasksTable>();
auto* missionsTable = CDClientManager::GetTable<CDMissionsTable>();
auto tasks = missionTasksTable->Query([=](const CDMissionTasks& entry) {
return entry.taskType == static_cast<unsigned>(type);
@@ -407,8 +407,8 @@ const std::vector<uint32_t>& MissionComponent::QueryAchievements(eMissionTaskTyp
}
// Find relevent tables
auto* missionTasksTable = CDClientManager::Instance().GetTable<CDMissionTasksTable>();
auto* missionsTable = CDClientManager::Instance().GetTable<CDMissionsTable>();
auto* missionTasksTable = CDClientManager::GetTable<CDMissionTasksTable>();
auto* missionsTable = CDClientManager::GetTable<CDMissionsTable>();
std::vector<uint32_t> result;

View File

@@ -30,7 +30,7 @@ public:
explicit MissionComponent(Entity* parent);
~MissionComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;

View File

@@ -40,7 +40,7 @@ bool OfferedMission::GetAcceptsMission() const {
//------------------------ MissionOfferComponent below ------------------------
MissionOfferComponent::MissionOfferComponent(Entity* parent, const LOT parentLot) : Component(parent) {
auto* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
auto* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
auto value = compRegistryTable->GetByIDAndType(parentLot, eReplicaComponentType::MISSION_OFFER, -1);
@@ -48,7 +48,7 @@ MissionOfferComponent::MissionOfferComponent(Entity* parent, const LOT parentLot
const uint32_t componentId = value;
// Now lookup the missions in the MissionNPCComponent table
auto* missionNpcComponentTable = CDClientManager::Instance().GetTable<CDMissionNPCComponentTable>();
auto* missionNpcComponentTable = CDClientManager::GetTable<CDMissionNPCComponentTable>();
auto missions = missionNpcComponentTable->Query([=](const CDMissionNPCComponent& entry) {
return entry.id == static_cast<unsigned>(componentId);

View File

@@ -14,26 +14,26 @@ ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
}
void ModelComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void ModelComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
// ItemComponent Serialization. Pets do not get this serialization.
if (!m_Parent->HasComponent(eReplicaComponentType::PET)) {
outBitStream->Write1();
outBitStream->Write<LWOOBJID>(m_userModelID != LWOOBJID_EMPTY ? m_userModelID : m_Parent->GetObjectID());
outBitStream->Write<int>(0);
outBitStream->Write0();
outBitStream.Write1();
outBitStream.Write<LWOOBJID>(m_userModelID != LWOOBJID_EMPTY ? m_userModelID : m_Parent->GetObjectID());
outBitStream.Write<int>(0);
outBitStream.Write0();
}
//actual model component:
outBitStream->Write1(); // Yes we are writing model info
outBitStream->Write0(); // Is pickable
outBitStream->Write<uint32_t>(2); // Physics type
outBitStream->Write(m_OriginalPosition); // Original position
outBitStream->Write(m_OriginalRotation); // Original rotation
outBitStream.Write1(); // Yes we are writing model info
outBitStream.Write0(); // Is pickable
outBitStream.Write<uint32_t>(2); // Physics type
outBitStream.Write(m_OriginalPosition); // Original position
outBitStream.Write(m_OriginalRotation); // Original rotation
outBitStream->Write1(); // We are writing behavior info
outBitStream->Write<uint32_t>(0); // Number of behaviors
outBitStream->Write1(); // Is this model paused
if (bIsInitialUpdate) outBitStream->Write0(); // We are not writing model editing info
outBitStream.Write1(); // We are writing behavior info
outBitStream.Write<uint32_t>(0); // Number of behaviors
outBitStream.Write1(); // Is this model paused
if (bIsInitialUpdate) outBitStream.Write0(); // We are not writing model editing info
}
void ModelComponent::UpdatePendingBehaviorId(const int32_t newId) {

View File

@@ -28,7 +28,7 @@ public:
ModelComponent(Entity* parent);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Returns the original position of the model
@@ -61,7 +61,7 @@ public:
* @param args the arguments of the message to be deserialized
*/
template<typename Msg>
void HandleControlBehaviorsMsg(AMFArrayValue* args) {
void HandleControlBehaviorsMsg(const AMFArrayValue& args) {
static_assert(std::is_base_of_v<BehaviorMessageBase, Msg>, "Msg must be a BehaviorMessageBase");
Msg msg(args);
for (auto& behavior : m_Behaviors) {

View File

@@ -46,20 +46,20 @@ const std::u16string& ModuleAssemblyComponent::GetAssemblyPartsLOTs() const {
return m_AssemblyPartsLOTs;
}
void ModuleAssemblyComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void ModuleAssemblyComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) {
outBitStream->Write1();
outBitStream.Write1();
outBitStream->Write(m_SubKey != LWOOBJID_EMPTY);
outBitStream.Write(m_SubKey != LWOOBJID_EMPTY);
if (m_SubKey != LWOOBJID_EMPTY) {
outBitStream->Write(m_SubKey);
outBitStream.Write(m_SubKey);
}
outBitStream->Write(m_UseOptionalParts);
outBitStream.Write(m_UseOptionalParts);
outBitStream->Write<uint16_t>(m_AssemblyPartsLOTs.size());
outBitStream.Write<uint16_t>(m_AssemblyPartsLOTs.size());
for (char16_t character : m_AssemblyPartsLOTs) {
outBitStream->Write(character);
outBitStream.Write(character);
}
}
}

View File

@@ -17,7 +17,7 @@ public:
ModuleAssemblyComponent(Entity* parent);
~ModuleAssemblyComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
/**

View File

@@ -43,7 +43,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) :
m_NextWaypoint = m_Parent->GetPosition();
m_Acceleration = 0.4f;
m_PullingToPoint = false;
m_PullPoint = NiPoint3::ZERO;
m_PullPoint = NiPoint3Constant::ZERO;
m_HaltDistance = 0;
m_TimeToTravel = 0;
m_TimeTravelled = 0;
@@ -88,7 +88,7 @@ void MovementAIComponent::Update(const float deltaTime) {
SetPosition(source);
NiPoint3 velocity = NiPoint3::ZERO;
NiPoint3 velocity = NiPoint3Constant::ZERO;
if (m_Acceleration > 0 && m_BaseSpeed > 0 && AdvanceWaypointIndex()) // Do we have another waypoint to seek?
{
@@ -203,7 +203,7 @@ void MovementAIComponent::Stop() {
SetPosition(ApproximateLocation());
SetVelocity(NiPoint3::ZERO);
SetVelocity(NiPoint3Constant::ZERO);
m_TimeToTravel = 0;
m_TimeTravelled = 0;
@@ -244,8 +244,8 @@ float MovementAIComponent::GetBaseSpeed(LOT lot) {
return it->second;
}
CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance().GetTable<CDPhysicsComponentTable>();
CDComponentsRegistryTable* componentRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
CDPhysicsComponentTable* physicsComponentTable = CDClientManager::GetTable<CDPhysicsComponentTable>();
int32_t componentID;
CDPhysicsComponent* physicsComponent = nullptr;

View File

@@ -32,25 +32,25 @@ MoverSubComponent::MoverSubComponent(const NiPoint3& startPos) {
MoverSubComponent::~MoverSubComponent() = default;
void MoverSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write<bool>(true);
void MoverSubComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write<bool>(true);
outBitStream->Write(mState);
outBitStream->Write<int32_t>(mDesiredWaypointIndex);
outBitStream->Write(mShouldStopAtDesiredWaypoint);
outBitStream->Write(mInReverse);
outBitStream.Write(mState);
outBitStream.Write<int32_t>(mDesiredWaypointIndex);
outBitStream.Write(mShouldStopAtDesiredWaypoint);
outBitStream.Write(mInReverse);
outBitStream->Write<float_t>(mPercentBetweenPoints);
outBitStream.Write<float_t>(mPercentBetweenPoints);
outBitStream->Write<float_t>(mPosition.x);
outBitStream->Write<float_t>(mPosition.y);
outBitStream->Write<float_t>(mPosition.z);
outBitStream.Write<float_t>(mPosition.x);
outBitStream.Write<float_t>(mPosition.y);
outBitStream.Write<float_t>(mPosition.z);
outBitStream->Write<uint32_t>(mCurrentWaypointIndex);
outBitStream->Write<uint32_t>(mNextWaypointIndex);
outBitStream.Write<uint32_t>(mCurrentWaypointIndex);
outBitStream.Write<uint32_t>(mNextWaypointIndex);
outBitStream->Write<float_t>(mIdleTimeElapsed);
outBitStream->Write<float_t>(0.0f); // Move time elapsed
outBitStream.Write<float_t>(mIdleTimeElapsed);
outBitStream.Write<float_t>(0.0f); // Move time elapsed
}
//------------- MovingPlatformComponent below --------------
@@ -71,43 +71,43 @@ MovingPlatformComponent::~MovingPlatformComponent() {
delete static_cast<MoverSubComponent*>(m_MoverSubComponent);
}
void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void MovingPlatformComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
// Here we don't serialize the moving platform to let the client simulate the movement
if (!m_Serialize) {
outBitStream->Write<bool>(false);
outBitStream->Write<bool>(false);
outBitStream.Write<bool>(false);
outBitStream.Write<bool>(false);
return;
}
outBitStream->Write<bool>(true);
outBitStream.Write<bool>(true);
auto hasPath = !m_PathingStopped && !m_PathName.empty();
outBitStream->Write(hasPath);
outBitStream.Write(hasPath);
if (hasPath) {
// Is on rail
outBitStream->Write1();
outBitStream.Write1();
outBitStream->Write<uint16_t>(m_PathName.size());
outBitStream.Write<uint16_t>(m_PathName.size());
for (const auto& c : m_PathName) {
outBitStream->Write<uint16_t>(c);
outBitStream.Write<uint16_t>(c);
}
// Starting point
outBitStream->Write<uint32_t>(0);
outBitStream.Write<uint32_t>(0);
// Reverse
outBitStream->Write<bool>(false);
outBitStream.Write<bool>(false);
}
const auto hasPlatform = m_MoverSubComponent != nullptr;
outBitStream->Write<bool>(hasPlatform);
outBitStream.Write<bool>(hasPlatform);
if (hasPlatform) {
auto* mover = static_cast<MoverSubComponent*>(m_MoverSubComponent);
outBitStream->Write(m_MoverSubComponentType);
outBitStream.Write(m_MoverSubComponentType);
if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) {
// TODO
@@ -162,7 +162,7 @@ void MovingPlatformComponent::StartPathing() {
const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex];
subComponent->mPosition = currentWaypoint.position;
subComponent->mSpeed = currentWaypoint.movingPlatform.speed;
subComponent->mSpeed = currentWaypoint.speed;
subComponent->mWaitTime = currentWaypoint.movingPlatform.wait;
targetPosition = nextWaypoint.position;
@@ -213,7 +213,7 @@ void MovingPlatformComponent::ContinuePathing() {
const auto& nextWaypoint = m_Path->pathWaypoints[subComponent->mNextWaypointIndex];
subComponent->mPosition = currentWaypoint.position;
subComponent->mSpeed = currentWaypoint.movingPlatform.speed;
subComponent->mSpeed = currentWaypoint.speed;
subComponent->mWaitTime = currentWaypoint.movingPlatform.wait; // + 2;
pathSize = m_Path->pathWaypoints.size() - 1;

View File

@@ -38,7 +38,7 @@ public:
MoverSubComponent(const NiPoint3& startPos);
~MoverSubComponent();
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate);
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate);
/**
* The state the platform is currently in
@@ -111,7 +111,7 @@ public:
MovingPlatformComponent(Entity* parent, const std::string& pathName);
~MovingPlatformComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Stops all pathing, called when an entity starts a quick build associated with this platform

View File

@@ -71,7 +71,7 @@ std::map<LOT, int32_t> PetComponent::petFlags = {
};
PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Component{ parentEntity } {
m_PetInfo = CDClientManager::Instance().GetTable<CDPetComponentTable>()->GetByID(componentId); // TODO: Make reference when safe
m_PetInfo = CDClientManager::GetTable<CDPetComponentTable>()->GetByID(componentId); // TODO: Make reference when safe
m_ComponentId = componentId;
m_Interaction = LWOOBJID_EMPTY;
@@ -84,7 +84,7 @@ PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Compone
m_DatabaseId = LWOOBJID_EMPTY;
m_Status = 67108866; // Tamable
m_Ability = ePetAbilityType::Invalid;
m_StartPosition = NiPoint3::ZERO;
m_StartPosition = NiPoint3Constant::ZERO;
m_MovementAI = nullptr;
m_TresureTime = 0;
m_Preconditions = nullptr;
@@ -96,42 +96,42 @@ PetComponent::PetComponent(Entity* parentEntity, uint32_t componentId) : Compone
}
}
void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void PetComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
const bool tamed = m_Owner != LWOOBJID_EMPTY;
outBitStream->Write1(); // Always serialize as dirty for now
outBitStream.Write1(); // Always serialize as dirty for now
outBitStream->Write<uint32_t>(m_Status);
outBitStream->Write(tamed ? m_Ability : ePetAbilityType::Invalid); // Something with the overhead icon?
outBitStream.Write<uint32_t>(m_Status);
outBitStream.Write(tamed ? m_Ability : ePetAbilityType::Invalid); // Something with the overhead icon?
const bool interacting = m_Interaction != LWOOBJID_EMPTY;
outBitStream->Write(interacting);
outBitStream.Write(interacting);
if (interacting) {
outBitStream->Write(m_Interaction);
outBitStream.Write(m_Interaction);
}
outBitStream->Write(tamed);
outBitStream.Write(tamed);
if (tamed) {
outBitStream->Write(m_Owner);
outBitStream.Write(m_Owner);
}
if (bIsInitialUpdate) {
outBitStream->Write(tamed);
outBitStream.Write(tamed);
if (tamed) {
outBitStream->Write(m_ModerationStatus);
outBitStream.Write(m_ModerationStatus);
const auto nameData = GeneralUtils::UTF8ToUTF16(m_Name);
const auto ownerNameData = GeneralUtils::UTF8ToUTF16(m_OwnerName);
outBitStream->Write<uint8_t>(nameData.size());
outBitStream.Write<uint8_t>(nameData.size());
for (const auto c : nameData) {
outBitStream->Write(c);
outBitStream.Write(c);
}
outBitStream->Write<uint8_t>(ownerNameData.size());
outBitStream.Write<uint8_t>(ownerNameData.size());
for (const auto c : ownerNameData) {
outBitStream->Write(c);
outBitStream.Write(c);
}
}
}
@@ -312,7 +312,7 @@ void PetComponent::OnUse(Entity* originator) {
}
void PetComponent::Update(float deltaTime) {
if (m_StartPosition == NiPoint3::ZERO) {
if (m_StartPosition == NiPoint3Constant::ZERO) {
m_StartPosition = m_Parent->GetPosition();
}
@@ -447,7 +447,7 @@ void PetComponent::Update(float deltaTime) {
if (distance < 5 * 5) {
m_Interaction = closestTresure->GetObjectID();
Command(NiPoint3::ZERO, LWOOBJID_EMPTY, 1, 202, true);
Command(NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 1, 202, true);
m_TresureTime = 2;
} else if (distance < 10 * 10) {
@@ -531,7 +531,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
EntityInfo info{};
info.lot = cached->second.puzzleModelLot;
info.pos = position;
info.rot = NiQuaternion::IDENTITY;
info.rot = NiQuaternionConstant::IDENTITY;
info.spawnerID = tamer->GetObjectID();
auto* modelEntity = Game::entityManager->CreateEntity(info);
@@ -591,9 +591,9 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
LWOOBJID_EMPTY,
false,
ePetTamingNotifyType::NAMINGPET,
NiPoint3::ZERO,
NiPoint3::ZERO,
NiQuaternion::IDENTITY,
NiPoint3Constant::ZERO,
NiPoint3Constant::ZERO,
NiQuaternionConstant::IDENTITY,
UNASSIGNED_SYSTEM_ADDRESS
);
@@ -671,9 +671,9 @@ void PetComponent::RequestSetPetName(std::u16string name) {
m_Tamer,
false,
ePetTamingNotifyType::SUCCESS,
NiPoint3::ZERO,
NiPoint3::ZERO,
NiQuaternion::IDENTITY,
NiPoint3Constant::ZERO,
NiPoint3Constant::ZERO,
NiQuaternionConstant::IDENTITY,
UNASSIGNED_SYSTEM_ADDRESS
);
@@ -712,9 +712,9 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
m_Tamer,
false,
ePetTamingNotifyType::QUIT,
NiPoint3::ZERO,
NiPoint3::ZERO,
NiQuaternion::IDENTITY,
NiPoint3Constant::ZERO,
NiPoint3Constant::ZERO,
NiQuaternionConstant::IDENTITY,
UNASSIGNED_SYSTEM_ADDRESS
);
@@ -763,9 +763,9 @@ void PetComponent::ClientFailTamingMinigame() {
m_Tamer,
false,
ePetTamingNotifyType::FAILED,
NiPoint3::ZERO,
NiPoint3::ZERO,
NiQuaternion::IDENTITY,
NiPoint3Constant::ZERO,
NiPoint3Constant::ZERO,
NiQuaternionConstant::IDENTITY,
UNASSIGNED_SYSTEM_ADDRESS
);

View File

@@ -21,7 +21,7 @@ public:
explicit PetComponent(Entity* parentEntity, uint32_t componentId);
~PetComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
/**

View File

@@ -143,10 +143,10 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsCompon
*/
if (!m_HasCreatedPhysics) {
CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::PHANTOM_PHYSICS);
CDPhysicsComponentTable* physComp = CDClientManager::Instance().GetTable<CDPhysicsComponentTable>();
CDPhysicsComponentTable* physComp = CDClientManager::GetTable<CDPhysicsComponentTable>();
if (physComp == nullptr) return;
@@ -156,83 +156,42 @@ PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsCompon
//temp test
if (info->physicsAsset == "miscellaneous\\misc_phys_10x1x5.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 10.0f, 5.0f, 1.0f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
} else if (info->physicsAsset == "miscellaneous\\misc_phys_640x640.hkx") {
// Move this down by 13.521004 units so it is still effectively at the same height as before
m_Position = m_Position - NiPoint3::UNIT_Y * 13.521004f;
// TODO Fix physics simulation to do simulation at high velocities due to bullet through paper problem...
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 1638.4f, 13.521004f * 2.0f, 1638.4f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
// Move this down by 13.521004 units so it is still effectively at the same height as before
m_Position = m_Position - NiPoint3Constant::UNIT_Y * 13.521004f;
} else if (info->physicsAsset == "env\\trigger_wall_tall.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 10.0f, 25.0f, 1.0f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
} else if (info->physicsAsset == "env\\env_gen_placeholderphysics.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 20.0f, 20.0f, 20.0f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
} else if (info->physicsAsset == "env\\POI_trigger_wall.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 1.0f, 12.5f, 20.0f); // Not sure what the real size is
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
} else if (info->physicsAsset == "env\\NG_NinjaGo\\env_ng_gen_gate_chamber_puzzle_ceiling_tile_falling_phantom.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 18.0f, 5.0f, 15.0f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position + m_Rotation.GetForwardVector() * 7.5f);
dpWorld::AddEntity(m_dpEntity);
m_Position += m_Rotation.GetForwardVector() * 7.5f;
} else if (info->physicsAsset == "env\\NG_NinjaGo\\ng_flamejet_brick_phantom.HKX") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 1.0f, 1.0f, 12.0f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position + m_Rotation.GetForwardVector() * 6.0f);
dpWorld::AddEntity(m_dpEntity);
m_Position += m_Rotation.GetForwardVector() * 6.0f;
} else if (info->physicsAsset == "env\\Ring_Trigger.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 6.0f, 6.0f, 6.0f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
} else if (info->physicsAsset == "env\\vfx_propertyImaginationBall.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 4.5f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
} else if (info->physicsAsset == "env\\env_won_fv_gas-blocking-volume.hkx") {
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 390.496826f, 111.467964f, 600.821534f, true);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_Position.y -= (111.467964f * m_Scale) / 2;
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
} else {
//LOG("This one is supposed to have %s", info->physicsAsset.c_str());
// LOG_DEBUG("This one is supposed to have %s", info->physicsAsset.c_str());
//add fallback cube:
m_dpEntity = new dpEntity(m_Parent->GetObjectID(), 2.0f, 2.0f, 2.0f);
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
}
m_dpEntity->SetScale(m_Scale);
m_dpEntity->SetRotation(m_Rotation);
m_dpEntity->SetPosition(m_Position);
dpWorld::AddEntity(m_dpEntity);
}
}
@@ -260,10 +219,10 @@ void PhantomPhysicsComponent::CreatePhysics() {
y = m_Parent->GetVar<float>(u"primitiveModelValueY");
z = m_Parent->GetVar<float>(u"primitiveModelValueZ");
} else {
CDComponentsRegistryTable* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
auto componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::PHANTOM_PHYSICS);
CDPhysicsComponentTable* physComp = CDClientManager::Instance().GetTable<CDPhysicsComponentTable>();
CDPhysicsComponentTable* physComp = CDClientManager::GetTable<CDPhysicsComponentTable>();
if (physComp == nullptr) return;
@@ -305,30 +264,30 @@ void PhantomPhysicsComponent::CreatePhysics() {
m_HasCreatedPhysics = true;
}
void PhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void PhantomPhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
outBitStream->Write(m_EffectInfoDirty || bIsInitialUpdate);
outBitStream.Write(m_EffectInfoDirty || bIsInitialUpdate);
if (m_EffectInfoDirty || bIsInitialUpdate) {
outBitStream->Write(m_IsPhysicsEffectActive);
outBitStream.Write(m_IsPhysicsEffectActive);
if (m_IsPhysicsEffectActive) {
outBitStream->Write(m_EffectType);
outBitStream->Write(m_DirectionalMultiplier);
outBitStream.Write(m_EffectType);
outBitStream.Write(m_DirectionalMultiplier);
// forgive me father for i have sinned
outBitStream->Write0();
//outBitStream->Write(m_MinMax);
outBitStream.Write0();
//outBitStream.Write(m_MinMax);
//if (m_MinMax) {
//outBitStream->Write(m_Min);
//outBitStream->Write(m_Max);
//outBitStream.Write(m_Min);
//outBitStream.Write(m_Max);
//}
outBitStream->Write(m_IsDirectional);
outBitStream.Write(m_IsDirectional);
if (m_IsDirectional) {
outBitStream->Write(m_Direction.x);
outBitStream->Write(m_Direction.y);
outBitStream->Write(m_Direction.z);
outBitStream.Write(m_Direction.x);
outBitStream.Write(m_Direction.y);
outBitStream.Write(m_Direction.z);
}
}

View File

@@ -32,7 +32,7 @@ public:
PhantomPhysicsComponent(Entity* parent);
~PhantomPhysicsComponent() override;
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Creates the physics shape for this entity based on LDF data

View File

@@ -1,21 +1,21 @@
#include "PhysicsComponent.h"
PhysicsComponent::PhysicsComponent(Entity* parent) : Component(parent) {
m_Position = NiPoint3::ZERO;
m_Rotation = NiQuaternion::IDENTITY;
m_Position = NiPoint3Constant::ZERO;
m_Rotation = NiQuaternionConstant::IDENTITY;
m_DirtyPosition = false;
}
void PhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(bIsInitialUpdate || m_DirtyPosition);
void PhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(bIsInitialUpdate || m_DirtyPosition);
if (bIsInitialUpdate || m_DirtyPosition) {
outBitStream->Write(m_Position.x);
outBitStream->Write(m_Position.y);
outBitStream->Write(m_Position.z);
outBitStream->Write(m_Rotation.x);
outBitStream->Write(m_Rotation.y);
outBitStream->Write(m_Rotation.z);
outBitStream->Write(m_Rotation.w);
outBitStream.Write(m_Position.x);
outBitStream.Write(m_Position.y);
outBitStream.Write(m_Position.z);
outBitStream.Write(m_Rotation.x);
outBitStream.Write(m_Rotation.y);
outBitStream.Write(m_Rotation.z);
outBitStream.Write(m_Rotation.w);
if (!bIsInitialUpdate) m_DirtyPosition = false;
}
}

View File

@@ -14,7 +14,7 @@ public:
PhysicsComponent(Entity* parent);
virtual ~PhysicsComponent() = default;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
const NiPoint3& GetPosition() const { return m_Position; }
virtual void SetPosition(const NiPoint3& pos) { if (m_Position == pos) return; m_Position = pos; m_DirtyPosition = true; }

View File

@@ -6,11 +6,11 @@ PlayerForcedMovementComponent::PlayerForcedMovementComponent(Entity* parent) : C
PlayerForcedMovementComponent::~PlayerForcedMovementComponent() {}
void PlayerForcedMovementComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_DirtyInfo || bIsInitialUpdate);
void PlayerForcedMovementComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_DirtyInfo || bIsInitialUpdate);
if (m_DirtyInfo || bIsInitialUpdate) {
outBitStream->Write(m_PlayerOnRail);
outBitStream->Write(m_ShowBillboard);
outBitStream.Write(m_PlayerOnRail);
outBitStream.Write(m_ShowBillboard);
}
m_DirtyInfo = false;
}

View File

@@ -19,7 +19,7 @@ public:
PlayerForcedMovementComponent(Entity* parent);
~PlayerForcedMovementComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* @brief Set the Player On Rail object

View File

@@ -27,17 +27,17 @@ PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId)
result.finalize();
}
void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_DirtyPossessable || bIsInitialUpdate);
void PossessableComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_DirtyPossessable || bIsInitialUpdate);
if (m_DirtyPossessable || bIsInitialUpdate) {
m_DirtyPossessable = false; // reset flag
outBitStream->Write(m_Possessor != LWOOBJID_EMPTY);
if (m_Possessor != LWOOBJID_EMPTY) outBitStream->Write(m_Possessor);
outBitStream.Write(m_Possessor != LWOOBJID_EMPTY);
if (m_Possessor != LWOOBJID_EMPTY) outBitStream.Write(m_Possessor);
outBitStream->Write(m_AnimationFlag != eAnimationFlags::IDLE_NONE);
if (m_AnimationFlag != eAnimationFlags::IDLE_NONE) outBitStream->Write(m_AnimationFlag);
outBitStream.Write(m_AnimationFlag != eAnimationFlags::IDLE_NONE);
if (m_AnimationFlag != eAnimationFlags::IDLE_NONE) outBitStream.Write(m_AnimationFlag);
outBitStream->Write(m_ImmediatelyDepossess);
outBitStream.Write(m_ImmediatelyDepossess);
m_ImmediatelyDepossess = false; // reset flag
}
}

View File

@@ -18,7 +18,7 @@ public:
PossessableComponent(Entity* parentEntity, uint32_t componentId);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* @brief mounts the Entity

View File

@@ -26,15 +26,15 @@ PossessorComponent::~PossessorComponent() {
}
}
void PossessorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate);
void PossessorComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_DirtyPossesor || bIsInitialUpdate);
if (m_DirtyPossesor || bIsInitialUpdate) {
m_DirtyPossesor = false;
outBitStream->Write(m_Possessable != LWOOBJID_EMPTY);
outBitStream.Write(m_Possessable != LWOOBJID_EMPTY);
if (m_Possessable != LWOOBJID_EMPTY) {
outBitStream->Write(m_Possessable);
outBitStream.Write(m_Possessable);
}
outBitStream->Write(m_PossessableType);
outBitStream.Write(m_PossessableType);
}
}

View File

@@ -23,7 +23,7 @@ public:
PossessorComponent(Entity* parent);
~PossessorComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* @brief Mounts the entity

View File

@@ -1,11 +0,0 @@
#include "PropertyComponent.h"
#include "GameMessages.h"
#include "dZoneManager.h"
PropertyComponent::PropertyComponent(Entity* parent) : Component(parent) {
m_PropertyName = parent->GetVar<std::string>(u"propertyName");
m_PropertyState = new PropertyState();
}
PropertyComponent::~PropertyComponent() = default;

View File

@@ -1,34 +1,22 @@
/*
* Darkflame Universe
* Copyright 2018
* Copyright 2024
*/
#ifndef PROPERTYCOMPONENT_H
#define PROPERTYCOMPONENT_H
#include "BitStream.h"
#include "Entity.h"
#include "Component.h"
#include "eReplicaComponentType.h"
struct PropertyState {
LWOOBJID ownerID;
LWOOBJID propertyID;
bool rented;
};
/**
* This component is unused and has no functionality
*/
class PropertyComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PROPERTY;
explicit PropertyComponent(Entity* parentEntity);
~PropertyComponent() override;
[[nodiscard]] PropertyState* GetPropertyState() const { return m_PropertyState; };
private:
PropertyState* m_PropertyState;
std::string m_PropertyName;
explicit PropertyComponent(Entity* const parentEntity) noexcept : Component{ parentEntity } {}
};
#endif // PROPERTYCOMPONENT_H
#endif // !PROPERTYCOMPONENT_H

View File

@@ -18,7 +18,7 @@
PropertyEntranceComponent::PropertyEntranceComponent(Entity* parent, uint32_t componentID) : Component(parent) {
this->propertyQueries = {};
auto table = CDClientManager::Instance().GetTable<CDPropertyEntranceComponentTable>();
auto table = CDClientManager::GetTable<CDPropertyEntranceComponentTable>();
const auto& entry = table->GetByID(componentID);
this->m_MapID = entry.mapID;

View File

@@ -14,7 +14,6 @@
#include "Item.h"
#include "Database.h"
#include "ObjectIDManager.h"
#include "Player.h"
#include "RocketLaunchpadControlComponent.h"
#include "PropertyEntranceComponent.h"
#include "InventoryComponent.h"
@@ -177,8 +176,6 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
auto* entity = Game::entityManager->GetEntity(playerId);
auto* user = entity->GetParentUser();
auto character = entity->GetCharacter();
if (!character) return false;
@@ -297,7 +294,7 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
const auto modelLOT = item->GetLot();
if (rotation != NiQuaternion::IDENTITY) {
if (rotation != NiQuaternionConstant::IDENTITY) {
rotation = { rotation.w, rotation.z, rotation.y, rotation.x };
}
@@ -481,7 +478,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
GameMessages::SendGetModelsOnProperty(entity->GetObjectID(), GetModels(), UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3::ZERO, LWOOBJID_EMPTY, 16, NiQuaternion::IDENTITY);
GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, NiQuaternionConstant::IDENTITY);
if (spawner != nullptr) {
Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID);
@@ -534,7 +531,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
GameMessages::SendGetModelsOnProperty(entity->GetObjectID(), GetModels(), UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3::ZERO, LWOOBJID_EMPTY, 16, NiQuaternion::IDENTITY);
GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, NiQuaternionConstant::IDENTITY);
if (spawner != nullptr) {
Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID);

View File

@@ -23,7 +23,7 @@
#include "CppScripts.h"
QuickBuildComponent::QuickBuildComponent(Entity* entity) : Component(entity) {
QuickBuildComponent::QuickBuildComponent(Entity* const entity) : Component{ entity } {
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");
if (!checkPreconditions.empty()) {
@@ -33,10 +33,9 @@ QuickBuildComponent::QuickBuildComponent(Entity* entity) : Component(entity) {
// Should a setting that has the build activator position exist, fetch that setting here and parse it for position.
// It is assumed that the user who sets this setting uses the correct character delimiter (character 31 or in hex 0x1F)
auto positionAsVector = GeneralUtils::SplitString(m_Parent->GetVarAsString(u"rebuild_activators"), 0x1F);
if (positionAsVector.size() == 3 &&
GeneralUtils::TryParse(positionAsVector[0], m_ActivatorPosition.x) &&
GeneralUtils::TryParse(positionAsVector[1], m_ActivatorPosition.y) &&
GeneralUtils::TryParse(positionAsVector[2], m_ActivatorPosition.z)) {
const auto activatorPositionValid = GeneralUtils::TryParse<NiPoint3>(positionAsVector);
if (positionAsVector.size() == 3 && activatorPositionValid) {
m_ActivatorPosition = activatorPositionValid.value();
} else {
LOG("Failed to find activator position for lot %i. Defaulting to parents position.", m_Parent->GetLOT());
m_ActivatorPosition = m_Parent->GetPosition();
@@ -56,55 +55,55 @@ QuickBuildComponent::~QuickBuildComponent() {
DespawnActivator();
}
void QuickBuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void QuickBuildComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (m_Parent->GetComponent(eReplicaComponentType::DESTROYABLE) == nullptr) {
if (bIsInitialUpdate) {
outBitStream->Write(false);
outBitStream.Write(false);
}
outBitStream->Write(false);
outBitStream.Write(false);
outBitStream->Write(false);
outBitStream.Write(false);
}
// If build state is completed and we've already serialized once in the completed state,
// don't serializing this component anymore as this will cause the build to jump again.
// If state changes, serialization will begin again.
if (!m_StateDirty && m_State == eQuickBuildState::COMPLETED) {
outBitStream->Write0();
outBitStream->Write0();
outBitStream.Write0();
outBitStream.Write0();
return;
}
// BEGIN Scripted Activity
outBitStream->Write1();
outBitStream.Write1();
Entity* builder = GetBuilder();
if (builder) {
outBitStream->Write<uint32_t>(1);
outBitStream->Write(builder->GetObjectID());
outBitStream.Write<uint32_t>(1);
outBitStream.Write(builder->GetObjectID());
for (int i = 0; i < 10; i++) {
outBitStream->Write(0.0f);
outBitStream.Write(0.0f);
}
} else {
outBitStream->Write<uint32_t>(0);
outBitStream.Write<uint32_t>(0);
}
// END Scripted Activity
outBitStream->Write1();
outBitStream.Write1();
outBitStream->Write(m_State);
outBitStream.Write(m_State);
outBitStream->Write(m_ShowResetEffect);
outBitStream->Write(m_Activator != nullptr);
outBitStream.Write(m_ShowResetEffect);
outBitStream.Write(m_Activator != nullptr);
outBitStream->Write(m_Timer);
outBitStream->Write(m_TimerIncomplete);
outBitStream.Write(m_Timer);
outBitStream.Write(m_TimerIncomplete);
if (bIsInitialUpdate) {
outBitStream->Write(false);
outBitStream->Write(m_ActivatorPosition);
outBitStream->Write(m_RepositionPlayer);
outBitStream.Write(false);
outBitStream.Write(m_ActivatorPosition);
outBitStream.Write(m_RepositionPlayer);
}
m_StateDirty = false;
}
@@ -253,13 +252,13 @@ void QuickBuildComponent::OnUse(Entity* originator) {
}
void QuickBuildComponent::SpawnActivator() {
if (!m_SelfActivator || m_ActivatorPosition != NiPoint3::ZERO) {
if (!m_SelfActivator || m_ActivatorPosition != NiPoint3Constant::ZERO) {
if (!m_Activator) {
EntityInfo info;
info.lot = 6604;
info.spawnerID = m_Parent->GetObjectID();
info.pos = m_ActivatorPosition == NiPoint3::ZERO ? m_Parent->GetPosition() : m_ActivatorPosition;
info.pos = m_ActivatorPosition == NiPoint3Constant::ZERO ? m_Parent->GetPosition() : m_ActivatorPosition;
m_Activator = Game::entityManager->CreateEntity(info, nullptr, m_Parent);
if (m_Activator) {
@@ -284,73 +283,73 @@ void QuickBuildComponent::DespawnActivator() {
}
}
Entity* QuickBuildComponent::GetActivator() {
Entity* QuickBuildComponent::GetActivator() const {
return Game::entityManager->GetEntity(m_ActivatorId);
}
NiPoint3 QuickBuildComponent::GetActivatorPosition() {
NiPoint3 QuickBuildComponent::GetActivatorPosition() const noexcept {
return m_ActivatorPosition;
}
float QuickBuildComponent::GetResetTime() {
float QuickBuildComponent::GetResetTime() const noexcept {
return m_ResetTime;
}
float QuickBuildComponent::GetCompleteTime() {
float QuickBuildComponent::GetCompleteTime() const noexcept {
return m_CompleteTime;
}
int QuickBuildComponent::GetTakeImagination() {
int32_t QuickBuildComponent::GetTakeImagination() const noexcept {
return m_TakeImagination;
}
bool QuickBuildComponent::GetInterruptible() {
bool QuickBuildComponent::GetInterruptible() const noexcept {
return m_Interruptible;
}
bool QuickBuildComponent::GetSelfActivator() {
bool QuickBuildComponent::GetSelfActivator() const noexcept {
return m_SelfActivator;
}
std::vector<int> QuickBuildComponent::GetCustomModules() {
std::vector<int32_t> QuickBuildComponent::GetCustomModules() const noexcept {
return m_CustomModules;
}
int QuickBuildComponent::GetActivityId() {
int32_t QuickBuildComponent::GetActivityId() const noexcept {
return m_ActivityId;
}
int QuickBuildComponent::GetPostImaginationCost() {
int32_t QuickBuildComponent::GetPostImaginationCost() const noexcept {
return m_PostImaginationCost;
}
float QuickBuildComponent::GetTimeBeforeSmash() {
float QuickBuildComponent::GetTimeBeforeSmash() const noexcept {
return m_TimeBeforeSmash;
}
eQuickBuildState QuickBuildComponent::GetState() {
eQuickBuildState QuickBuildComponent::GetState() const noexcept {
return m_State;
}
Entity* QuickBuildComponent::GetBuilder() const {
auto* builder = Game::entityManager->GetEntity(m_Builder);
auto* const builder = Game::entityManager->GetEntity(m_Builder);
return builder;
}
bool QuickBuildComponent::GetRepositionPlayer() const {
bool QuickBuildComponent::GetRepositionPlayer() const noexcept {
return m_RepositionPlayer;
}
void QuickBuildComponent::SetActivatorPosition(NiPoint3 value) {
void QuickBuildComponent::SetActivatorPosition(const NiPoint3& value) noexcept {
m_ActivatorPosition = value;
}
void QuickBuildComponent::SetResetTime(float value) {
void QuickBuildComponent::SetResetTime(const float value) noexcept {
m_ResetTime = value;
}
void QuickBuildComponent::SetCompleteTime(float value) {
void QuickBuildComponent::SetCompleteTime(const float value) noexcept {
if (value < 0) {
m_CompleteTime = 4.5f;
} else {
@@ -358,31 +357,31 @@ void QuickBuildComponent::SetCompleteTime(float value) {
}
}
void QuickBuildComponent::SetTakeImagination(int value) {
void QuickBuildComponent::SetTakeImagination(const int32_t value) noexcept {
m_TakeImagination = value;
}
void QuickBuildComponent::SetInterruptible(bool value) {
void QuickBuildComponent::SetInterruptible(const bool value) noexcept {
m_Interruptible = value;
}
void QuickBuildComponent::SetSelfActivator(bool value) {
void QuickBuildComponent::SetSelfActivator(const bool value) noexcept {
m_SelfActivator = value;
}
void QuickBuildComponent::SetCustomModules(std::vector<int> value) {
void QuickBuildComponent::SetCustomModules(const std::vector<int32_t>& value) noexcept {
m_CustomModules = value;
}
void QuickBuildComponent::SetActivityId(int value) {
void QuickBuildComponent::SetActivityId(const int32_t value) noexcept {
m_ActivityId = value;
}
void QuickBuildComponent::SetPostImaginationCost(int value) {
void QuickBuildComponent::SetPostImaginationCost(const int32_t value) noexcept {
m_PostImaginationCost = value;
}
void QuickBuildComponent::SetTimeBeforeSmash(float value) {
void QuickBuildComponent::SetTimeBeforeSmash(const float value) noexcept {
if (value < 0) {
m_TimeBeforeSmash = 10.0f;
} else {
@@ -390,11 +389,11 @@ void QuickBuildComponent::SetTimeBeforeSmash(float value) {
}
}
void QuickBuildComponent::SetRepositionPlayer(bool value) {
void QuickBuildComponent::SetRepositionPlayer(const bool value) noexcept {
m_RepositionPlayer = value;
}
void QuickBuildComponent::StartQuickBuild(Entity* user) {
void QuickBuildComponent::StartQuickBuild(Entity* const user) {
if (m_State == eQuickBuildState::OPEN || m_State == eQuickBuildState::COMPLETED || m_State == eQuickBuildState::INCOMPLETE) {
m_Builder = user->GetObjectID();
@@ -427,10 +426,8 @@ void QuickBuildComponent::StartQuickBuild(Entity* user) {
}
}
void QuickBuildComponent::CompleteQuickBuild(Entity* user) {
if (user == nullptr) {
return;
}
void QuickBuildComponent::CompleteQuickBuild(Entity* const user) {
if (!user) return;
auto* characterComponent = user->GetComponent<CharacterComponent>();
if (characterComponent != nullptr) {
@@ -519,7 +516,7 @@ void QuickBuildComponent::CompleteQuickBuild(Entity* user) {
RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f);
}
void QuickBuildComponent::ResetQuickBuild(bool failed) {
void QuickBuildComponent::ResetQuickBuild(const bool failed) {
Entity* builder = GetBuilder();
if (m_State == eQuickBuildState::BUILDING && builder) {
@@ -554,7 +551,7 @@ void QuickBuildComponent::ResetQuickBuild(bool failed) {
}
}
void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason failReason, bool skipChecks) {
void QuickBuildComponent::CancelQuickBuild(Entity* const entity, const eQuickBuildFailReason failReason, const bool skipChecks) {
if (m_State != eQuickBuildState::COMPLETED || skipChecks) {
m_Builder = LWOOBJID_EMPTY;
@@ -582,9 +579,7 @@ void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason
Game::entityManager->SerializeEntity(m_Parent);
}
if (entity == nullptr) {
return;
}
if (!entity) return;
CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>();
if (characterComponent) {

View File

@@ -24,10 +24,10 @@ class QuickBuildComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
QuickBuildComponent(Entity* entity);
QuickBuildComponent(Entity* const entity);
~QuickBuildComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
/**
@@ -50,148 +50,148 @@ public:
* Returns the entity that acts as the activator for this quickbuild
* @return the entity that acts as the activator for this quickbuild
*/
Entity* GetActivator();
[[nodiscard]] Entity* GetActivator() const;
/**
* Returns the spawn position of the activator for this quickbuild, if any
* @return the spawn position of the activator for this quickbuild, if any
*/
NiPoint3 GetActivatorPosition();
[[nodiscard]] NiPoint3 GetActivatorPosition() const noexcept;
/**
* Sets the spawn position for the activator of this quickbuild
* @param value the spawn position to set for the activator
*/
void SetActivatorPosition(NiPoint3 value);
void SetActivatorPosition(const NiPoint3& value) noexcept;
/**
* Returns the time it takes for the quickbuild to reset after being built
* @return the time it takes for the quickbuild to reset after being built
*/
float GetResetTime();
[[nodiscard]] float GetResetTime() const noexcept;
/**
* Sets the time it takes for the quickbuild to reset after being built
* @param value the reset time to set
*/
void SetResetTime(float value);
void SetResetTime(const float value) noexcept;
/**
* Returns the time it takes to complete the quickbuild
* @return the time it takes to complete the quickbuild
*/
float GetCompleteTime();
[[nodiscard]] float GetCompleteTime() const noexcept;
/**
* Sets the time it takes to complete the quickbuild
* @param value the completion time to set
*/
void SetCompleteTime(float value);
void SetCompleteTime(const float value) noexcept;
/**
* Returns the imagination that's taken when completing the quickbuild
* @return the imagination that's taken when completing the quickbuild
*/
int GetTakeImagination();
[[nodiscard]] int32_t GetTakeImagination() const noexcept;
/**
* Sets the imagination that's taken when completing the quickbuild
* @param value the imagination deduction to set
*/
void SetTakeImagination(int value);
void SetTakeImagination(const int32_t value) noexcept;
/**
* Returns if the quickbuild can be interrupted, currently unused
* @return if the quickbuild can be interrupted
*/
bool GetInterruptible();
[[nodiscard]] bool GetInterruptible() const noexcept;
/**
* Sets whether or not the quickbuild can be interrupted, currently unused
* @param value true if the quickbuild may be interrupted, false otherwise
*/
void SetInterruptible(bool value);
void SetInterruptible(const bool value) noexcept;
/**
* Returns whether or not this entity contains a built-in activator
* @return whether or not this entity contains a built-in activator
*/
bool GetSelfActivator();
[[nodiscard]] bool GetSelfActivator() const noexcept;
/**
* Sets whether or not this entity contains a built-in activator. If set to false this will spawn activators on
* each new quickbuild.
* @param value whether or not this entity contains a built-in activator
*/
void SetSelfActivator(bool value);
void SetSelfActivator(const bool value) noexcept;
/**
* Currently unused
*/
std::vector<int> GetCustomModules();
[[nodiscard]] std::vector<int32_t> GetCustomModules() const noexcept;
/**
* Currently unused
*/
void SetCustomModules(std::vector<int> value);
void SetCustomModules(const std::vector<int32_t>& value) noexcept;
/**
* Returns the activity ID for participating in this quickbuild
* @return the activity ID for participating in this quickbuild
*/
int GetActivityId();
[[nodiscard]] int32_t GetActivityId() const noexcept;
/**
* Sets the activity ID for participating in this quickbuild
* @param value the activity ID to set
*/
void SetActivityId(int value);
void SetActivityId(const int32_t value) noexcept;
/**
* Currently unused
*/
int GetPostImaginationCost();
[[nodiscard]] int32_t GetPostImaginationCost() const noexcept;
/**
* Currently unused
*/
void SetPostImaginationCost(int value);
void SetPostImaginationCost(const int32_t value) noexcept;
/**
* Returns the time it takes for an incomplete quickbuild to be smashed automatically
* @return the time it takes for an incomplete quickbuild to be smashed automatically
*/
float GetTimeBeforeSmash();
[[nodiscard]] float GetTimeBeforeSmash() const noexcept;
/**
* Sets the time it takes for an incomplete quickbuild to be smashed automatically
* @param value the time to set
*/
void SetTimeBeforeSmash(float value);
void SetTimeBeforeSmash(const float value) noexcept;
/**
* Returns the current quickbuild state
* @return the current quickbuild state
*/
eQuickBuildState GetState();
[[nodiscard]] eQuickBuildState GetState() const noexcept;
/**
* Returns the player that is currently building this quickbuild
* @return the player that is currently building this quickbuild
*/
Entity* GetBuilder() const;
[[nodiscard]] Entity* GetBuilder() const;
/**
* Returns whether or not the player is repositioned when initiating the quickbuild
* @return whether or not the player is repositioned when initiating the quickbuild
*/
bool GetRepositionPlayer() const;
[[nodiscard]] bool GetRepositionPlayer() const noexcept;
/**
* Sets whether or not the player is repositioned when initiating the quickbuild
* @param value whether or not the player is repositioned when initiating the quickbuild
*/
void SetRepositionPlayer(bool value);
void SetRepositionPlayer(const bool value) noexcept;
/**
* Adds a callback that is called when the quickbuild is completed
@@ -209,7 +209,7 @@ public:
* Resets the quickbuild
* @param failed whether or not the player failed to complete the quickbuild, triggers an extra animation
*/
void ResetQuickBuild(bool failed);
void ResetQuickBuild(const bool failed);
/**
* Cancels the quickbuild if it wasn't completed
@@ -217,7 +217,7 @@ public:
* @param failReason the reason the quickbuild was cancelled
* @param skipChecks whether or not to skip the check for the quickbuild not being completed
*/
void CancelQuickBuild(Entity* builder, eQuickBuildFailReason failReason, bool skipChecks = false);
void CancelQuickBuild(Entity* const builder, const eQuickBuildFailReason failReason, const bool skipChecks = false);
private:
/**
* Whether or not the quickbuild state has been changed since we last serialized it.
@@ -242,7 +242,7 @@ private:
/**
* The position that the quickbuild activator is spawned at
*/
NiPoint3 m_ActivatorPosition = NiPoint3::ZERO;
NiPoint3 m_ActivatorPosition = NiPoint3Constant::ZERO;
/**
* The entity that represents the quickbuild activator
@@ -287,7 +287,7 @@ private:
/**
* The imagination that's deducted when completing the quickbuild
*/
int m_TakeImagination = 0;
int32_t m_TakeImagination = 0;
/**
* Currently unused
@@ -302,17 +302,17 @@ private:
/**
* Currently unused
*/
std::vector<int> m_CustomModules{};
std::vector<int32_t> m_CustomModules{};
/**
* The activity ID that players partake in when doing this quickbuild
*/
int m_ActivityId = 0;
int32_t m_ActivityId = 0;
/**
* Currently unused
*/
int m_PostImaginationCost = 0;
int32_t m_PostImaginationCost = 0;
/**
* The time it takes for the quickbuild to reset when it's not completed yet
@@ -327,7 +327,7 @@ private:
/**
* The amount of imagination that was drained when building this quickbuild
*/
int m_DrainedImagination = 0;
int32_t m_DrainedImagination = 0;
/**
* Whether to reposition the player or not when building
@@ -337,7 +337,7 @@ private:
/**
* Currently unused
*/
float m_SoftTimer = 0;
int32_t m_SoftTimer = 0;
/**
* The ID of the entity that's currently building the quickbuild
@@ -353,13 +353,13 @@ private:
* Starts the quickbuild for a certain entity
* @param user the entity to start the quickbuild
*/
void StartQuickBuild(Entity* user);
void StartQuickBuild(Entity* const user);
/**
* Completes the quickbuild for an entity, dropping loot and despawning the activator
* @param user the entity that completed the quickbuild
*/
void CompleteQuickBuild(Entity* user);
void CompleteQuickBuild(Entity* const user);
};
#endif // QUICKBUILDCOMPONENT_H

View File

@@ -12,7 +12,6 @@
#include "Item.h"
#include "MissionComponent.h"
#include "ModuleAssemblyComponent.h"
#include "Player.h"
#include "PossessableComponent.h"
#include "PossessorComponent.h"
#include "eRacingTaskParam.h"
@@ -54,7 +53,7 @@ RacingControlComponent::RacingControlComponent(Entity* parent)
if (Game::zoneManager->CheckIfAccessibleZone((worldID / 10) * 10)) m_MainWorld = (worldID / 10) * 10;
m_ActivityID = 42;
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
CDActivitiesTable* activitiesTable = CDClientManager::GetTable<CDActivitiesTable>();
std::vector<CDActivities> activities = activitiesTable->Query([=](CDActivities entry) {return (entry.instanceMapID == worldID); });
for (CDActivities activity : activities) m_ActivityID = activity.ActivityID;
}
@@ -119,8 +118,8 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
GeneralUtils::UTF16ToWTF8(m_PathName));
auto spawnPointEntities = Game::entityManager->GetEntitiesByLOT(4843);
auto startPosition = NiPoint3::ZERO;
auto startRotation = NiQuaternion::IDENTITY;
auto startPosition = NiPoint3Constant::ZERO;
auto startRotation = NiQuaternionConstant::IDENTITY;
const std::string placementAsString = std::to_string(positionNumber);
for (auto entity : spawnPointEntities) {
if (!entity) continue;
@@ -434,83 +433,83 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity* player, int32_t bu
}
}
void RacingControlComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void RacingControlComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
// BEGIN Scripted Activity
outBitStream->Write1();
outBitStream.Write1();
outBitStream->Write<uint32_t>(m_RacingPlayers.size());
outBitStream.Write<uint32_t>(m_RacingPlayers.size());
for (const auto& player : m_RacingPlayers) {
outBitStream->Write(player.playerID);
outBitStream.Write(player.playerID);
outBitStream->Write(player.data[0]);
if (player.finished != 0) outBitStream->Write<float>(player.raceTime);
else outBitStream->Write(player.data[1]);
if (player.finished != 0) outBitStream->Write<float>(player.bestLapTime);
else outBitStream->Write(player.data[2]);
if (player.finished == 1) outBitStream->Write<float>(1.0f);
else outBitStream->Write(player.data[3]);
outBitStream->Write(player.data[4]);
outBitStream->Write(player.data[5]);
outBitStream->Write(player.data[6]);
outBitStream->Write(player.data[7]);
outBitStream->Write(player.data[8]);
outBitStream->Write(player.data[9]);
outBitStream.Write(player.data[0]);
if (player.finished != 0) outBitStream.Write<float>(player.raceTime);
else outBitStream.Write(player.data[1]);
if (player.finished != 0) outBitStream.Write<float>(player.bestLapTime);
else outBitStream.Write(player.data[2]);
if (player.finished == 1) outBitStream.Write<float>(1.0f);
else outBitStream.Write(player.data[3]);
outBitStream.Write(player.data[4]);
outBitStream.Write(player.data[5]);
outBitStream.Write(player.data[6]);
outBitStream.Write(player.data[7]);
outBitStream.Write(player.data[8]);
outBitStream.Write(player.data[9]);
}
// END Scripted Activity
outBitStream->Write1();
outBitStream->Write<uint16_t>(m_RacingPlayers.size());
outBitStream.Write1();
outBitStream.Write<uint16_t>(m_RacingPlayers.size());
outBitStream->Write(!m_AllPlayersReady);
outBitStream.Write(!m_AllPlayersReady);
if (!m_AllPlayersReady) {
int32_t numReady = 0;
for (const auto& player : m_RacingPlayers) {
outBitStream->Write1(); // Has more player data
outBitStream->Write(player.playerID);
outBitStream->Write(player.vehicleID);
outBitStream->Write(player.playerIndex);
outBitStream->Write(player.playerLoaded);
outBitStream.Write1(); // Has more player data
outBitStream.Write(player.playerID);
outBitStream.Write(player.vehicleID);
outBitStream.Write(player.playerIndex);
outBitStream.Write(player.playerLoaded);
if (player.playerLoaded) numReady++;
}
outBitStream->Write0(); // No more data
outBitStream.Write0(); // No more data
if (numReady == m_RacingPlayers.size()) m_AllPlayersReady = true;
}
outBitStream->Write(!m_RacingPlayers.empty());
outBitStream.Write(!m_RacingPlayers.empty());
if (!m_RacingPlayers.empty()) {
for (const auto& player : m_RacingPlayers) {
if (player.finished == 0) continue;
outBitStream->Write1(); // Has more date
outBitStream.Write1(); // Has more date
outBitStream->Write(player.playerID);
outBitStream->Write(player.finished);
outBitStream.Write(player.playerID);
outBitStream.Write(player.finished);
}
outBitStream->Write0(); // No more data
outBitStream.Write0(); // No more data
}
outBitStream->Write(bIsInitialUpdate);
outBitStream.Write(bIsInitialUpdate);
if (bIsInitialUpdate) {
outBitStream->Write(m_RemainingLaps);
outBitStream->Write<uint16_t>(m_PathName.size());
outBitStream.Write(m_RemainingLaps);
outBitStream.Write<uint16_t>(m_PathName.size());
for (const auto character : m_PathName) {
outBitStream->Write(character);
outBitStream.Write(character);
}
}
outBitStream->Write(!m_RacingPlayers.empty());
outBitStream.Write(!m_RacingPlayers.empty());
if (!m_RacingPlayers.empty()) {
for (const auto& player : m_RacingPlayers) {
if (player.finished == 0) continue;
outBitStream->Write1(); // Has more data
outBitStream->Write(player.playerID);
outBitStream->Write<float>(player.bestLapTime);
outBitStream->Write<float>(player.raceTime);
outBitStream.Write1(); // Has more data
outBitStream.Write(player.playerID);
outBitStream.Write<float>(player.bestLapTime);
outBitStream.Write<float>(player.raceTime);
}
outBitStream->Write0(); // No more data
outBitStream.Write0(); // No more data
}
}
@@ -818,7 +817,7 @@ void RacingControlComponent::Update(float deltaTime) {
// Some offset up to make they don't fall through the terrain on a
// respawn, seems to fix itself to the track anyhow
player.respawnPosition = position + NiPoint3::UNIT_Y * 5;
player.respawnPosition = position + NiPoint3Constant::UNIT_Y * 5;
player.respawnRotation = vehicle->GetRotation();
player.respawnIndex = respawnIndex;

View File

@@ -110,7 +110,7 @@ public:
RacingControlComponent(Entity* parentEntity);
~RacingControlComponent();
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
/**

View File

@@ -13,7 +13,7 @@
RailActivatorComponent::RailActivatorComponent(Entity* parent, int32_t componentID) : Component(parent) {
m_ComponentID = componentID;
const auto tableData = CDClientManager::Instance().GetTable<CDRailActivatorComponentTable>()->GetEntryByID(componentID);;
const auto tableData = CDClientManager::GetTable<CDRailActivatorComponentTable>()->GetEntryByID(componentID);;
m_Path = parent->GetVar<std::u16string>(u"rail_path");
m_PathDirection = parent->GetVar<bool>(u"rail_path_direction");

View File

@@ -1,7 +1,9 @@
#include "RenderComponent.h"
#include <algorithm>
#include <sstream>
#include <string>
#include <utility>
#include <iomanip>
#include "Entity.h"
@@ -14,8 +16,7 @@
std::unordered_map<int32_t, float> RenderComponent::m_DurationCache{};
RenderComponent::RenderComponent(Entity* parent, int32_t componentId): Component(parent) {
m_Effects = std::vector<Effect*>();
RenderComponent::RenderComponent(Entity* const parentEntity, const int32_t componentId) : Component{ parentEntity } {
m_LastAnimationName = "";
if (componentId == -1) return;
@@ -26,116 +27,69 @@ RenderComponent::RenderComponent(Entity* parent, int32_t componentId): Component
if (!result.eof()) {
auto animationGroupIDs = std::string(result.getStringField("animationGroupIDs", ""));
if (!animationGroupIDs.empty()) {
auto* animationsTable = CDClientManager::Instance().GetTable<CDAnimationsTable>();
auto* animationsTable = CDClientManager::GetTable<CDAnimationsTable>();
auto groupIdsSplit = GeneralUtils::SplitString(animationGroupIDs, ',');
for (auto& groupId : groupIdsSplit) {
int32_t groupIdInt;
if (!GeneralUtils::TryParse(groupId, groupIdInt)) {
const auto groupIdInt = GeneralUtils::TryParse<int32_t>(groupId);
if (!groupIdInt) {
LOG("bad animation group Id %s", groupId.c_str());
continue;
}
m_animationGroupIds.push_back(groupIdInt);
animationsTable->CacheAnimationGroup(groupIdInt);
m_animationGroupIds.push_back(groupIdInt.value());
animationsTable->CacheAnimationGroup(groupIdInt.value());
}
}
}
result.finalize();
}
RenderComponent::~RenderComponent() {
for (Effect* eff : m_Effects) {
if (eff) {
delete eff;
eff = nullptr;
}
}
m_Effects.clear();
}
void RenderComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void RenderComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (!bIsInitialUpdate) return;
outBitStream->Write<uint32_t>(m_Effects.size());
outBitStream.Write<uint32_t>(m_Effects.size());
for (Effect* eff : m_Effects) {
// we still need to write 0 as the size for name if it is a nullptr
if (!eff) {
outBitStream->Write<uint8_t>(0);
continue;
}
outBitStream->Write<uint8_t>(eff->name.size());
for (auto& eff : m_Effects) {
outBitStream.Write<uint8_t>(eff.name.size());
// if there is no name, then we don't write anything else
if (eff->name.empty()) continue;
if (eff.name.empty()) continue;
for (const auto& value : eff->name) outBitStream->Write<uint8_t>(value);
for (const auto& value : eff.name) outBitStream.Write<uint8_t>(value);
outBitStream->Write(eff->effectID);
outBitStream.Write(eff.effectID);
outBitStream->Write<uint8_t>(eff->type.size());
for (const auto& value : eff->type) outBitStream->Write<uint16_t>(value);
outBitStream.Write<uint8_t>(eff.type.size());
for (const auto& value : eff.type) outBitStream.Write<uint16_t>(value);
outBitStream->Write<float_t>(eff->priority);
outBitStream->Write<int64_t>(eff->secondary);
outBitStream.Write<float_t>(eff.priority);
outBitStream.Write<int64_t>(eff.secondary);
}
}
Effect* RenderComponent::AddEffect(const int32_t effectId, const std::string& name, const std::u16string& type, const float priority) {
auto* eff = new Effect();
eff->effectID = effectId;
eff->name = name;
eff->type = type;
eff->priority = priority;
m_Effects.push_back(eff);
return eff;
Effect& RenderComponent::AddEffect(const int32_t effectId, const std::string& name, const std::u16string& type, const float priority) {
return m_Effects.emplace_back(effectId, name, type, priority);
}
void RenderComponent::RemoveEffect(const std::string& name) {
uint32_t index = -1;
if (m_Effects.empty()) return;
for (auto i = 0u; i < m_Effects.size(); ++i) {
auto* eff = m_Effects[i];
const auto effectToRemove = std::ranges::find_if(m_Effects, [&name](auto&& effect) { return effect.name == name; });
if (effectToRemove == m_Effects.end()) return; // Return early if effect is not present
if (eff->name == name) {
index = i;
delete eff;
break;
}
}
if (index == -1) {
return;
}
m_Effects.erase(m_Effects.begin() + index);
const auto lastEffect = m_Effects.rbegin();
*effectToRemove = std::move(*lastEffect); // Move-overwrite
m_Effects.pop_back();
}
void RenderComponent::Update(const float deltaTime) {
std::vector<Effect*> dead;
void RenderComponent::Update(const float deltaTime) {
for (auto& effect : m_Effects) {
if (effect.time == 0) continue; // Skip persistent effects
for (auto* effect : m_Effects) {
if (effect->time == 0) {
continue; // Skip persistent effects
}
const auto result = effect.time - deltaTime;
if (result <= 0) continue;
const auto result = effect->time - deltaTime;
if (result <= 0) {
dead.push_back(effect);
continue;
}
effect->time = result;
}
for (auto* effect : dead) {
// StopEffect(effect->name);
effect.time = result;
}
}
@@ -144,12 +98,12 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e
GameMessages::SendPlayFXEffect(m_Parent, effectId, effectType, name, secondary, priority, scale, serialize);
auto* effect = AddEffect(effectId, name, effectType, priority);
auto& effect = AddEffect(effectId, name, effectType, priority);
const auto& pair = m_DurationCache.find(effectId);
if (pair != m_DurationCache.end()) {
effect->time = pair->second;
effect.time = pair->second;
return;
}
@@ -168,16 +122,16 @@ void RenderComponent::PlayEffect(const int32_t effectId, const std::u16string& e
m_DurationCache[effectId] = 0;
effect->time = 0; // Persistent effect
effect.time = 0; // Persistent effect
return;
}
effect->time = static_cast<float>(result.getFloatField(0));
effect.time = static_cast<float>(result.getFloatField(0));
result.finalize();
m_DurationCache[effectId] = effect->time;
m_DurationCache[effectId] = effect.time;
}
void RenderComponent::StopEffect(const std::string& name, const bool killImmediate) {
@@ -186,11 +140,6 @@ void RenderComponent::StopEffect(const std::string& name, const bool killImmedia
RemoveEffect(name);
}
std::vector<Effect*>& RenderComponent::GetEffects() {
return m_Effects;
}
float RenderComponent::PlayAnimation(Entity* self, const std::u16string& animation, float priority, float scale) {
if (!self) return 0.0f;
return RenderComponent::PlayAnimation(self, GeneralUtils::UTF16ToWTF8(animation), priority, scale);
@@ -218,13 +167,12 @@ float RenderComponent::DoAnimation(Entity* self, const std::string& animation, b
auto* renderComponent = self->GetComponent<RenderComponent>();
if (!renderComponent) return returnlength;
auto* animationsTable = CDClientManager::Instance().GetTable<CDAnimationsTable>();
auto* animationsTable = CDClientManager::GetTable<CDAnimationsTable>();
for (auto& groupId : renderComponent->m_animationGroupIds) {
auto animationGroup = animationsTable->GetAnimation(animation, renderComponent->GetLastAnimationName(), groupId);
if (animationGroup.FoundData()) {
auto data = animationGroup.Data();
renderComponent->SetLastAnimationName(data.animation_name);
returnlength = data.animation_length;
if (animationGroup) {
renderComponent->SetLastAnimationName(animationGroup->animation_name);
returnlength = animationGroup->animation_length;
}
}
if (sendAnimation) GameMessages::SendPlayAnimation(self, GeneralUtils::ASCIIToUTF16(animation), priority, scale);

View File

@@ -17,7 +17,12 @@ class Entity;
* here.
*/
struct Effect {
Effect() { priority = 1.0f; }
explicit Effect(const int32_t effectID, const std::string& name, const std::u16string& type, const float priority = 1.0f) noexcept
: effectID{ effectID }
, name{ name }
, type{ type }
, priority{ priority } {
}
/**
* The ID of the effect
@@ -58,10 +63,9 @@ class RenderComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::RENDER;
RenderComponent(Entity* entity, int32_t componentId = -1);
~RenderComponent() override;
RenderComponent(Entity* const parentEntity, const int32_t componentId = -1);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void Update(float deltaTime) override;
/**
@@ -72,7 +76,7 @@ public:
* @param priority the priority of the effect
* @return if successful, the effect that was created
*/
Effect* AddEffect(int32_t effectId, const std::string& name, const std::u16string& type, const float priority);
[[maybe_unused]] Effect& AddEffect(const int32_t effectId, const std::string& name, const std::u16string& type, const float priority);
/**
* Removes an effect for this entity
@@ -99,12 +103,6 @@ public:
*/
void StopEffect(const std::string& name, bool killImmediate = true);
/**
* Returns the list of currently active effects
* @return
*/
std::vector<Effect*>& GetEffects();
/**
* Verifies that an animation can be played on this entity by checking
* if it has the animation assigned to its group. If it does, the animation is echo'd
@@ -125,10 +123,10 @@ public:
static float PlayAnimation(Entity* self, const std::u16string& animation, float priority = 0.0f, float scale = 1.0f);
static float PlayAnimation(Entity* self, const std::string& animation, float priority = 0.0f, float scale = 1.0f);
static float GetAnimationTime(Entity* self, const std::string& animation);
static float GetAnimationTime(Entity* self, const std::u16string& animation);
[[nodiscard]] static float GetAnimationTime(Entity* self, const std::string& animation);
[[nodiscard]] static float GetAnimationTime(Entity* self, const std::u16string& animation);
const std::string& GetLastAnimationName() const { return m_LastAnimationName; };
[[nodiscard]] const std::string& GetLastAnimationName() const { return m_LastAnimationName; };
void SetLastAnimationName(const std::string& name) { m_LastAnimationName = name; };
private:
@@ -136,7 +134,7 @@ private:
/**
* List of currently active effects
*/
std::vector<Effect*> m_Effects;
std::vector<Effect> m_Effects;
std::vector<int32_t> m_animationGroupIds;

View File

@@ -11,6 +11,6 @@ RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* paren
m_Rotation = m_Parent->GetDefaultRotation();
}
void RigidbodyPhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void RigidbodyPhantomPhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
}

View File

@@ -23,7 +23,7 @@ public:
RigidbodyPhantomPhysicsComponent(Entity* parent);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
};
#endif // __RIGIDBODYPHANTOMPHYSICS_H__

View File

@@ -139,7 +139,7 @@ void RocketLaunchpadControlComponent::TellMasterToPrepZone(int zoneID) {
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PREP_ZONE);
bitStream.Write(zoneID);
Game::server->SendToMaster(&bitStream);
Game::server->SendToMaster(bitStream);
}

View File

@@ -17,50 +17,50 @@ void ShootingGalleryComponent::SetDynamicParams(const DynamicShootingGalleryPara
Game::entityManager->SerializeEntity(m_Parent);
}
void ShootingGalleryComponent::Serialize(RakNet::BitStream* outBitStream, bool isInitialUpdate) {
void ShootingGalleryComponent::Serialize(RakNet::BitStream& outBitStream, bool isInitialUpdate) {
// Start ScriptedActivityComponent
outBitStream->Write<bool>(true);
outBitStream.Write<bool>(true);
if (m_CurrentPlayerID == LWOOBJID_EMPTY) {
outBitStream->Write<uint32_t>(0);
outBitStream.Write<uint32_t>(0);
} else {
outBitStream->Write<uint32_t>(1);
outBitStream->Write<LWOOBJID>(m_CurrentPlayerID);
outBitStream.Write<uint32_t>(1);
outBitStream.Write<LWOOBJID>(m_CurrentPlayerID);
for (size_t i = 0; i < 10; i++) {
outBitStream->Write<float_t>(0.0f);
outBitStream.Write<float_t>(0.0f);
}
}
// End ScriptedActivityComponent
if (isInitialUpdate) {
outBitStream->Write<float_t>(m_StaticParams.cameraPosition.GetX());
outBitStream->Write<float_t>(m_StaticParams.cameraPosition.GetY());
outBitStream->Write<float_t>(m_StaticParams.cameraPosition.GetZ());
outBitStream.Write<float_t>(m_StaticParams.cameraPosition.GetX());
outBitStream.Write<float_t>(m_StaticParams.cameraPosition.GetY());
outBitStream.Write<float_t>(m_StaticParams.cameraPosition.GetZ());
outBitStream->Write<float_t>(m_StaticParams.cameraLookatPosition.GetX());
outBitStream->Write<float_t>(m_StaticParams.cameraLookatPosition.GetY());
outBitStream->Write<float_t>(m_StaticParams.cameraLookatPosition.GetZ());
outBitStream.Write<float_t>(m_StaticParams.cameraLookatPosition.GetX());
outBitStream.Write<float_t>(m_StaticParams.cameraLookatPosition.GetY());
outBitStream.Write<float_t>(m_StaticParams.cameraLookatPosition.GetZ());
}
outBitStream->Write<bool>(m_Dirty || isInitialUpdate);
outBitStream.Write<bool>(m_Dirty || isInitialUpdate);
if (m_Dirty || isInitialUpdate) {
outBitStream->Write<double_t>(m_DynamicParams.cannonVelocity);
outBitStream->Write<double_t>(m_DynamicParams.cannonRefireRate);
outBitStream->Write<double_t>(m_DynamicParams.cannonMinDistance);
outBitStream.Write<double_t>(m_DynamicParams.cannonVelocity);
outBitStream.Write<double_t>(m_DynamicParams.cannonRefireRate);
outBitStream.Write<double_t>(m_DynamicParams.cannonMinDistance);
outBitStream->Write<float_t>(m_DynamicParams.cameraBarrelOffset.GetX());
outBitStream->Write<float_t>(m_DynamicParams.cameraBarrelOffset.GetY());
outBitStream->Write<float_t>(m_DynamicParams.cameraBarrelOffset.GetZ());
outBitStream.Write<float_t>(m_DynamicParams.cameraBarrelOffset.GetX());
outBitStream.Write<float_t>(m_DynamicParams.cameraBarrelOffset.GetY());
outBitStream.Write<float_t>(m_DynamicParams.cameraBarrelOffset.GetZ());
outBitStream->Write<float_t>(m_DynamicParams.cannonAngle);
outBitStream.Write<float_t>(m_DynamicParams.cannonAngle);
outBitStream->Write<float_t>(m_DynamicParams.facing.GetX());
outBitStream->Write<float_t>(m_DynamicParams.facing.GetY());
outBitStream->Write<float_t>(m_DynamicParams.facing.GetZ());
outBitStream.Write<float_t>(m_DynamicParams.facing.GetX());
outBitStream.Write<float_t>(m_DynamicParams.facing.GetY());
outBitStream.Write<float_t>(m_DynamicParams.facing.GetZ());
outBitStream->Write<LWOOBJID>(m_CurrentPlayerID);
outBitStream->Write<float_t>(m_DynamicParams.cannonTimeout);
outBitStream->Write<float_t>(m_DynamicParams.cannonFOV);
outBitStream.Write<LWOOBJID>(m_CurrentPlayerID);
outBitStream.Write<float_t>(m_DynamicParams.cannonTimeout);
outBitStream.Write<float_t>(m_DynamicParams.cannonFOV);
if (!isInitialUpdate) m_Dirty = false;
}
}

View File

@@ -77,7 +77,7 @@ public:
explicit ShootingGalleryComponent(Entity* parent);
~ShootingGalleryComponent();
void Serialize(RakNet::BitStream* outBitStream, bool isInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool isInitialUpdate) override;
/**
* Returns the static params for the shooting gallery

View File

@@ -32,26 +32,26 @@ SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, uint32_t componen
SimplePhysicsComponent::~SimplePhysicsComponent() {
}
void SimplePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
void SimplePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) {
outBitStream->Write(m_ClimbableType != eClimbableType::CLIMBABLE_TYPE_NOT);
outBitStream->Write(m_ClimbableType);
outBitStream.Write(m_ClimbableType != eClimbableType::CLIMBABLE_TYPE_NOT);
outBitStream.Write(m_ClimbableType);
}
outBitStream->Write(m_DirtyVelocity || bIsInitialUpdate);
outBitStream.Write(m_DirtyVelocity || bIsInitialUpdate);
if (m_DirtyVelocity || bIsInitialUpdate) {
outBitStream->Write(m_Velocity);
outBitStream->Write(m_AngularVelocity);
outBitStream.Write(m_Velocity);
outBitStream.Write(m_AngularVelocity);
m_DirtyVelocity = false;
}
// Physics motion state
if (m_PhysicsMotionState != 0) {
outBitStream->Write1();
outBitStream->Write<uint32_t>(m_PhysicsMotionState);
outBitStream.Write1();
outBitStream.Write<uint32_t>(m_PhysicsMotionState);
} else {
outBitStream->Write0();
outBitStream.Write0();
}
PhysicsComponent::Serialize(outBitStream, bIsInitialUpdate);
}

View File

@@ -33,7 +33,7 @@ public:
SimplePhysicsComponent(Entity* parent, uint32_t componentID);
~SimplePhysicsComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Returns the velocity of this entity
@@ -87,12 +87,12 @@ private:
/**
* The current velocity of the entity
*/
NiPoint3 m_Velocity = NiPoint3::ZERO;
NiPoint3 m_Velocity = NiPoint3Constant::ZERO;
/**
* The current angular velocity of the entity
*/
NiPoint3 m_AngularVelocity = NiPoint3::ZERO;
NiPoint3 m_AngularVelocity = NiPoint3Constant::ZERO;
/**
* Whether or not the velocity has changed

View File

@@ -31,7 +31,7 @@ ProjectileSyncEntry::ProjectileSyncEntry() {
std::unordered_map<uint32_t, uint32_t> SkillComponent::m_skillBehaviorCache = {};
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream* bitStream, const LWOOBJID target, uint32_t skillID) {
bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t skillUid, RakNet::BitStream& bitStream, const LWOOBJID target, uint32_t skillID) {
auto* context = new BehaviorContext(this->m_Parent->GetObjectID());
context->caster = m_Parent->GetObjectID();
@@ -51,7 +51,7 @@ bool SkillComponent::CastPlayerSkill(const uint32_t behaviorId, const uint32_t s
return !context->failed;
}
void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syncId, RakNet::BitStream* bitStream) {
void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syncId, RakNet::BitStream& bitStream) {
const auto index = this->m_managedBehaviors.find(skillUid);
if (index == this->m_managedBehaviors.end()) {
@@ -66,7 +66,7 @@ void SkillComponent::SyncPlayerSkill(const uint32_t skillUid, const uint32_t syn
}
void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::BitStream* bitStream, const LWOOBJID target) {
void SkillComponent::SyncPlayerProjectile(const LWOOBJID projectileId, RakNet::BitStream& bitStream, const LWOOBJID target) {
auto index = -1;
for (auto i = 0u; i < this->m_managedProjectiles.size(); ++i) {
@@ -234,7 +234,7 @@ bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LW
// if it's not in the cache look it up and cache it
if (pair == m_skillBehaviorCache.end()) {
auto skillTable = CDClientManager::Instance().GetTable<CDSkillBehaviorTable>();
auto skillTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
behaviorId = skillTable->GetSkillByID(skillId).behaviorID;
m_skillBehaviorCache.insert_or_assign(skillId, behaviorId);
} else {
@@ -252,7 +252,7 @@ bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LW
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride) {
auto* bitStream = new RakNet::BitStream();
RakNet::BitStream bitStream{};
auto* behavior = Behavior::CreateBehavior(behaviorId);
@@ -273,7 +273,6 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
}
if (!context->foundTarget) {
delete bitStream;
delete context;
// Invalid attack
@@ -299,22 +298,20 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
}
//start.optionalTargetID = target;
start.sBitStream.assign(reinterpret_cast<char*>(bitStream->GetData()), bitStream->GetNumberOfBytesUsed());
start.sBitStream.assign(reinterpret_cast<char*>(bitStream.GetData()), bitStream.GetNumberOfBytesUsed());
// Write message
RakNet::BitStream message;
BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
message.Write(this->m_Parent->GetObjectID());
start.Serialize(&message);
start.Serialize(message);
Game::server->Send(&message, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(message, UNASSIGNED_SYSTEM_ADDRESS, true);
}
context->ExecuteUpdates();
delete bitStream;
// Valid attack
return { true, context->skillTime };
}
@@ -424,13 +421,13 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
auto* behavior = Behavior::CreateBehavior(behaviorId);
auto* bitStream = new RakNet::BitStream();
RakNet::BitStream bitStream{};
behavior->Calculate(entry.context, bitStream, entry.branchContext);
DoClientProjectileImpact projectileImpact;
projectileImpact.sBitStream.assign(reinterpret_cast<char*>(bitStream->GetData()), bitStream->GetNumberOfBytesUsed());
projectileImpact.sBitStream.assign(reinterpret_cast<char*>(bitStream.GetData()), bitStream.GetNumberOfBytesUsed());
projectileImpact.i64OwnerID = this->m_Parent->GetObjectID();
projectileImpact.i64OrgID = entry.id;
projectileImpact.i64TargetID = entry.branchContext.target;
@@ -439,42 +436,34 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
message.Write(this->m_Parent->GetObjectID());
projectileImpact.Serialize(&message);
projectileImpact.Serialize(message);
Game::server->Send(&message, UNASSIGNED_SYSTEM_ADDRESS, true);
Game::server->Send(message, UNASSIGNED_SYSTEM_ADDRESS, true);
entry.context->ExecuteUpdates();
delete bitStream;
}
void SkillComponent::HandleUnmanaged(const uint32_t behaviorId, const LWOOBJID target, LWOOBJID source) {
auto* context = new BehaviorContext(source);
BehaviorContext context{ source };
context->unmanaged = true;
context->caster = target;
context.unmanaged = true;
context.caster = target;
auto* behavior = Behavior::CreateBehavior(behaviorId);
auto* bitStream = new RakNet::BitStream();
RakNet::BitStream bitStream{};
behavior->Handle(context, bitStream, { target });
delete bitStream;
delete context;
behavior->Handle(&context, bitStream, { target });
}
void SkillComponent::HandleUnCast(const uint32_t behaviorId, const LWOOBJID target) {
auto* context = new BehaviorContext(target);
BehaviorContext context{ target };
context->caster = target;
context.caster = target;
auto* behavior = Behavior::CreateBehavior(behaviorId);
behavior->UnCast(context, { target });
delete context;
behavior->UnCast(&context, { target });
}
SkillComponent::SkillComponent(Entity* parent): Component(parent) {
@@ -485,8 +474,8 @@ SkillComponent::~SkillComponent() {
Reset();
}
void SkillComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) outBitStream->Write0();
void SkillComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) outBitStream.Write0();
}
/// <summary>

View File

@@ -64,7 +64,7 @@ public:
explicit SkillComponent(Entity* parent);
~SkillComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Computes skill updates. Invokes CalculateUpdate.
@@ -93,7 +93,7 @@ public:
* @param bitStream the bitSteam given by the client to determine the behavior path
* @param target the explicit target of the skill
*/
bool CastPlayerSkill(uint32_t behaviorId, uint32_t skillUid, RakNet::BitStream* bitStream, LWOOBJID target, uint32_t skillID = 0);
bool CastPlayerSkill(uint32_t behaviorId, uint32_t skillUid, RakNet::BitStream& bitStream, LWOOBJID target, uint32_t skillID = 0);
/**
* Continues a player skill. Should only be called when the server receives a sync message from the client.
@@ -101,7 +101,7 @@ public:
* @param syncId the unique sync ID of the skill given by the client
* @param bitStream the bitSteam given by the client to determine the behavior path
*/
void SyncPlayerSkill(uint32_t skillUid, uint32_t syncId, RakNet::BitStream* bitStream);
void SyncPlayerSkill(uint32_t skillUid, uint32_t syncId, RakNet::BitStream& bitStream);
/**
* Continues a player projectile calculation. Should only be called when the server receives a projectile sync message from the client.
@@ -109,7 +109,7 @@ public:
* @param bitStream the bitSteam given by the client to determine the behavior path
* @param target the explicit target of the target
*/
void SyncPlayerProjectile(LWOOBJID projectileId, RakNet::BitStream* bitStream, LWOOBJID target);
void SyncPlayerProjectile(LWOOBJID projectileId, RakNet::BitStream& bitStream, LWOOBJID target);
/**
* Registers a player projectile. Should only be called when the server is computing a player projectile.

View File

@@ -2,28 +2,28 @@
#include "Game.h"
#include "Logger.h"
void MusicCue::Serialize(RakNet::BitStream* outBitStream){
outBitStream->Write<uint8_t>(name.size());
outBitStream->Write(name.c_str(), name.size());
outBitStream->Write(result);
outBitStream->Write(boredomTime);
void MusicCue::Serialize(RakNet::BitStream& outBitStream){
outBitStream.Write<uint8_t>(name.size());
outBitStream.Write(name.c_str(), name.size());
outBitStream.Write(result);
outBitStream.Write(boredomTime);
}
void MusicParameter::Serialize(RakNet::BitStream* outBitStream){
outBitStream->Write<uint8_t>(name.size());
outBitStream->Write(name.c_str(), name.size());
outBitStream->Write(value);
void MusicParameter::Serialize(RakNet::BitStream& outBitStream){
outBitStream.Write<uint8_t>(name.size());
outBitStream.Write(name.c_str(), name.size());
outBitStream.Write(value);
}
void GUIDResults::Serialize(RakNet::BitStream* outBitStream){
void GUIDResults::Serialize(RakNet::BitStream& outBitStream){
guid.Serialize(outBitStream);
outBitStream->Write(result);
outBitStream.Write(result);
}
void MixerProgram::Serialize(RakNet::BitStream* outBitStream){
outBitStream->Write<uint8_t>(name.size());
outBitStream->Write(name.c_str(), name.size());
outBitStream->Write(result);
void MixerProgram::Serialize(RakNet::BitStream& outBitStream){
outBitStream.Write<uint8_t>(name.size());
outBitStream.Write(name.c_str(), name.size());
outBitStream.Write(result);
}
SoundTriggerComponent::SoundTriggerComponent(Entity* parent) : Component(parent) {
@@ -55,30 +55,30 @@ SoundTriggerComponent::SoundTriggerComponent(Entity* parent) : Component(parent)
if (!mixerName.empty()) this->m_MixerPrograms.push_back(MixerProgram(mixerName));
}
void SoundTriggerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(this->m_Dirty || bIsInitialUpdate);
void SoundTriggerComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(this->m_Dirty || bIsInitialUpdate);
if (this->m_Dirty || bIsInitialUpdate) {
outBitStream->Write<uint8_t>(this->m_MusicCues.size());
outBitStream.Write<uint8_t>(this->m_MusicCues.size());
for (auto& musicCue : this->m_MusicCues) {
musicCue.Serialize(outBitStream);
}
outBitStream->Write<uint8_t>(this->m_MusicParameters.size());
outBitStream.Write<uint8_t>(this->m_MusicParameters.size());
for (auto& musicParam : this->m_MusicParameters) {
musicParam.Serialize(outBitStream);
}
outBitStream->Write<uint8_t>(this->m_2DAmbientSounds.size());
outBitStream.Write<uint8_t>(this->m_2DAmbientSounds.size());
for (auto twoDAmbientSound : this->m_2DAmbientSounds) {
twoDAmbientSound.Serialize(outBitStream);
}
outBitStream->Write<uint8_t>(this->m_3DAmbientSounds.size());
outBitStream.Write<uint8_t>(this->m_3DAmbientSounds.size());
for (auto threeDAmbientSound : this->m_3DAmbientSounds) {
threeDAmbientSound.Serialize(outBitStream);
}
outBitStream->Write<uint8_t>(this->m_MixerPrograms.size());
outBitStream.Write<uint8_t>(this->m_MixerPrograms.size());
for (auto& mixerProgram : this->m_MixerPrograms) {
mixerProgram.Serialize(outBitStream);
}

View File

@@ -17,7 +17,7 @@ struct MusicCue {
this->boredomTime = boredomTime;
};
void Serialize(RakNet::BitStream* outBitStream);
void Serialize(RakNet::BitStream& outBitStream);
};
struct MusicParameter {
@@ -29,7 +29,7 @@ struct MusicParameter {
this->value = value;
}
void Serialize(RakNet::BitStream* outBitStream);
void Serialize(RakNet::BitStream& outBitStream);
};
struct GUIDResults{
@@ -41,7 +41,7 @@ struct GUIDResults{
this->result = result;
}
void Serialize(RakNet::BitStream* outBitStream);
void Serialize(RakNet::BitStream& outBitStream);
};
struct MixerProgram {
@@ -53,7 +53,7 @@ struct MixerProgram {
this->result = result;
}
void Serialize(RakNet::BitStream* outBitStream);
void Serialize(RakNet::BitStream& outBitStream);
};
@@ -61,7 +61,7 @@ class SoundTriggerComponent : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_TRIGGER;
explicit SoundTriggerComponent(Entity* parent);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void ActivateMusicCue(const std::string& name, float bordemTime = -1.0);
void DeactivateMusicCue(const std::string& name);

View File

@@ -21,8 +21,8 @@ SwitchComponent::~SwitchComponent() {
}
}
void SwitchComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(m_Active);
void SwitchComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(m_Active);
}
void SwitchComponent::SetActive(bool active) {

View File

@@ -25,7 +25,7 @@ public:
Entity* GetParentEntity() const;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Sets whether the switch is on or off.

View File

@@ -9,7 +9,6 @@
#include "ControllablePhysicsComponent.h"
#include "MissionComponent.h"
#include "PhantomPhysicsComponent.h"
#include "Player.h"
#include "QuickBuildComponent.h"
#include "SkillComponent.h"
#include "eEndBehavior.h"
@@ -22,10 +21,8 @@ TriggerComponent::TriggerComponent(Entity* parent, const std::string triggerInfo
std::vector<std::string> tokens = GeneralUtils::SplitString(triggerInfo, ':');
uint32_t sceneID;
GeneralUtils::TryParse<uint32_t>(tokens.at(0), sceneID);
uint32_t triggerID;
GeneralUtils::TryParse<uint32_t>(tokens.at(1), triggerID);
const auto sceneID = GeneralUtils::TryParse<uint32_t>(tokens.at(0)).value_or(0);
const auto triggerID = GeneralUtils::TryParse<uint32_t>(tokens.at(1)).value_or(0);
m_Trigger = Game::zoneManager->GetZone()->GetTrigger(sceneID, triggerID);
@@ -191,9 +188,8 @@ void TriggerComponent::HandleFireEvent(Entity* targetEntity, std::string args) {
}
void TriggerComponent::HandleDestroyObject(Entity* targetEntity, std::string args){
uint32_t killType;
GeneralUtils::TryParse<uint32_t>(args, killType);
targetEntity->Smash(m_Parent->GetObjectID(), static_cast<eKillType>(killType));
const eKillType killType = GeneralUtils::TryParse<eKillType>(args).value_or(eKillType::VIOLENT);
targetEntity->Smash(m_Parent->GetObjectID(), killType);
}
void TriggerComponent::HandleToggleTrigger(Entity* targetEntity, std::string args){
@@ -217,9 +213,8 @@ void TriggerComponent::HandleResetRebuild(Entity* targetEntity, std::string args
void TriggerComponent::HandleMoveObject(Entity* targetEntity, std::vector<std::string> argArray){
if (argArray.size() <= 2) return;
auto position = targetEntity->GetPosition();
NiPoint3 offset = NiPoint3::ZERO;
GeneralUtils::TryParse(argArray.at(0), argArray.at(1), argArray.at(2), offset);
NiPoint3 position = targetEntity->GetPosition();
const NiPoint3 offset = GeneralUtils::TryParse<NiPoint3>(argArray).value_or(NiPoint3Constant::ZERO);
position += offset;
targetEntity->SetPosition(position);
@@ -228,8 +223,7 @@ void TriggerComponent::HandleMoveObject(Entity* targetEntity, std::vector<std::s
void TriggerComponent::HandleRotateObject(Entity* targetEntity, std::vector<std::string> argArray){
if (argArray.size() <= 2) return;
NiPoint3 vector = NiPoint3::ZERO;
GeneralUtils::TryParse(argArray.at(0), argArray.at(1), argArray.at(2), vector);
const NiPoint3 vector = GeneralUtils::TryParse<NiPoint3>(argArray).value_or(NiPoint3Constant::ZERO);
NiQuaternion rotation = NiQuaternion::FromEulerAngles(vector);
targetEntity->SetRotation(rotation);
@@ -246,8 +240,7 @@ void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vector<std::s
phantomPhysicsComponent->SetPhysicsEffectActive(true);
phantomPhysicsComponent->SetEffectType(ePhysicsEffectType::PUSH);
phantomPhysicsComponent->SetDirectionalMultiplier(1);
NiPoint3 direction = NiPoint3::ZERO;
GeneralUtils::TryParse(argArray.at(0), argArray.at(1), argArray.at(2), direction);
const NiPoint3 direction = GeneralUtils::TryParse<NiPoint3>(argArray).value_or(NiPoint3Constant::ZERO);
phantomPhysicsComponent->SetDirection(direction);
Game::entityManager->SerializeEntity(m_Parent);
@@ -260,8 +253,8 @@ void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args)
LOG_DEBUG("Phantom Physics component not found!");
return;
}
float forceMultiplier;
GeneralUtils::TryParse<float>(args, forceMultiplier);
const float forceMultiplier = GeneralUtils::TryParse<float>(args).value_or(1.0f);
phantomPhysicsComponent->SetPhysicsEffectActive(true);
phantomPhysicsComponent->SetEffectType(ePhysicsEffectType::REPULSE);
phantomPhysicsComponent->SetDirectionalMultiplier(forceMultiplier);
@@ -280,11 +273,10 @@ void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args)
void TriggerComponent::HandleSetTimer(Entity* targetEntity, std::vector<std::string> argArray){
if (argArray.size() != 2) {
LOG_DEBUG("Not ehought variables!");
LOG_DEBUG("Not enough variables!");
return;
}
float time = 0.0;
GeneralUtils::TryParse<float>(argArray.at(1), time);
const float time = GeneralUtils::TryParse<float>(argArray.at(1)).value_or(0.0f);
m_Parent->AddTimer(argArray.at(0), time);
}
@@ -300,7 +292,7 @@ void TriggerComponent::HandlePlayCinematic(Entity* targetEntity, std::vector<std
bool hidePlayer = false;
if (argArray.size() >= 2) {
GeneralUtils::TryParse<float>(argArray.at(1), leadIn);
leadIn = GeneralUtils::TryParse<float>(argArray.at(1)).value_or(leadIn);
if (argArray.size() >= 3 && argArray.at(2) == "wait") {
wait = eEndBehavior::WAIT;
if (argArray.size() >= 4 && argArray.at(3) == "unlock") {
@@ -345,12 +337,16 @@ void TriggerComponent::HandleUpdateMission(Entity* targetEntity, std::vector<std
void TriggerComponent::HandlePlayEffect(Entity* targetEntity, std::vector<std::string> argArray) {
if (argArray.size() < 3) return;
int32_t effectID = 0;
if (!GeneralUtils::TryParse<int32_t>(argArray.at(1), effectID)) return;
const auto effectID = GeneralUtils::TryParse<int32_t>(argArray.at(1));
if (!effectID) return;
std::u16string effectType = GeneralUtils::UTF8ToUTF16(argArray.at(2));
float priority = 1;
if (argArray.size() == 4) GeneralUtils::TryParse<float>(argArray.at(3), priority);
GameMessages::SendPlayFXEffect(targetEntity, effectID, effectType, argArray.at(0), LWOOBJID_EMPTY, priority);
if (argArray.size() == 4) {
priority = GeneralUtils::TryParse<float>(argArray.at(3)).value_or(priority);
}
GameMessages::SendPlayFXEffect(targetEntity, effectID.value(), effectType, argArray.at(0), LWOOBJID_EMPTY, priority);
}
void TriggerComponent::HandleCastSkill(Entity* targetEntity, std::string args){
@@ -359,8 +355,7 @@ void TriggerComponent::HandleCastSkill(Entity* targetEntity, std::string args){
LOG_DEBUG("Skill component not found!");
return;
}
uint32_t skillId;
GeneralUtils::TryParse<uint32_t>(args, skillId);
const uint32_t skillId = GeneralUtils::TryParse<uint32_t>(args).value_or(0);
skillComponent->CastSkill(skillId, targetEntity->GetObjectID());
}
@@ -382,17 +377,16 @@ void TriggerComponent::HandleSetPhysicsVolumeEffect(Entity* targetEntity, std::v
phantomPhysicsComponent->SetEffectType(effectType);
phantomPhysicsComponent->SetDirectionalMultiplier(std::stof(argArray.at(1)));
if (argArray.size() > 4) {
NiPoint3 direction = NiPoint3::ZERO;
GeneralUtils::TryParse(argArray.at(2), argArray.at(3), argArray.at(4), direction);
const NiPoint3 direction =
GeneralUtils::TryParse<NiPoint3>(argArray.at(2), argArray.at(3), argArray.at(4)).value_or(NiPoint3Constant::ZERO);
phantomPhysicsComponent->SetDirection(direction);
}
if (argArray.size() > 5) {
uint32_t min;
GeneralUtils::TryParse<uint32_t>(argArray.at(6), min);
const uint32_t min = GeneralUtils::TryParse<uint32_t>(argArray.at(6)).value_or(0);
phantomPhysicsComponent->SetMin(min);
uint32_t max;
GeneralUtils::TryParse<uint32_t>(argArray.at(7), max);
const uint32_t max = GeneralUtils::TryParse<uint32_t>(argArray.at(7)).value_or(0);
phantomPhysicsComponent->SetMax(max);
}

View File

@@ -8,6 +8,11 @@
#include "CDLootMatrixTable.h"
#include "CDLootTableTable.h"
#include "CDItemComponentTable.h"
#include "InventoryComponent.h"
#include "Character.h"
#include "eVendorTransactionResult.h"
#include "UserManager.h"
#include "CheatDetection.h"
VendorComponent::VendorComponent(Entity* parent) : Component(parent) {
m_HasStandardCostItems = false;
@@ -16,11 +21,11 @@ VendorComponent::VendorComponent(Entity* parent) : Component(parent) {
RefreshInventory(true);
}
void VendorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
outBitStream->Write(bIsInitialUpdate || m_DirtyVendor);
void VendorComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
outBitStream.Write(bIsInitialUpdate || m_DirtyVendor);
if (bIsInitialUpdate || m_DirtyVendor) {
outBitStream->Write(m_HasStandardCostItems);
outBitStream->Write(m_HasMultiCostItems);
outBitStream.Write(m_HasStandardCostItems);
outBitStream.Write(m_HasMultiCostItems);
if (!bIsInitialUpdate) m_DirtyVendor = false;
}
}
@@ -35,36 +40,34 @@ void VendorComponent::RefreshInventory(bool isCreation) {
SetHasMultiCostItems(false);
m_Inventory.clear();
// Custom code for Max vanity NPC and Mr.Ree cameras
if(isCreation && m_Parent->GetLOT() == 9749 && Game::server->GetZoneID() == 1201) {
SetupMaxCustomVendor();
// Custom code for Vanity Vendor Invetory Override
if(m_Parent->HasVar(u"vendorInvOverride")) {
std::vector<std::string> items = GeneralUtils::SplitString(m_Parent->GetVarAsString(u"vendorInvOverride"), ',');
uint32_t sortPriority = -1;
for (auto& itemString : items) {
itemString.erase(remove_if(itemString.begin(), itemString.end(), isspace), itemString.end());
auto item = GeneralUtils::TryParse<uint32_t>(itemString);
if (!item) continue;
if (SetupItem(item.value())) {
sortPriority++;
m_Inventory.push_back(SoldItem(item.value(), sortPriority));
}
}
return;
}
auto* lootMatrixTable = CDClientManager::Instance().GetTable<CDLootMatrixTable>();
auto* lootMatrixTable = CDClientManager::GetTable<CDLootMatrixTable>();
const auto& lootMatrices = lootMatrixTable->GetMatrix(m_LootMatrixID);
if (lootMatrices.empty()) return;
auto* lootTableTable = CDClientManager::Instance().GetTable<CDLootTableTable>();
auto* itemComponentTable = CDClientManager::Instance().GetTable<CDItemComponentTable>();
auto* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
auto* lootTableTable = CDClientManager::GetTable<CDLootTableTable>();
for (const auto& lootMatrix : lootMatrices) {
auto vendorItems = lootTableTable->GetTable(lootMatrix.LootTableIndex);
if (lootMatrix.maxToDrop == 0 || lootMatrix.minToDrop == 0) {
for (const auto& item : vendorItems) {
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
auto itemComponentID = compRegistryTable->GetByIDAndType(item.itemid, eReplicaComponentType::ITEM, -1);
if (itemComponentID == -1) {
LOG("Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT());
continue;
}
auto itemComponent = itemComponentTable->GetItemComponentByID(itemComponentID);
if (!m_HasStandardCostItems && itemComponent.baseValue != -1) SetHasStandardCostItems(true);
if (!m_HasMultiCostItems && !itemComponent.currencyCosts.empty()) SetHasMultiCostItems(true);
}
m_Inventory.push_back(SoldItem(item.itemid, item.sortPriority));
if (SetupItem(item.itemid)) m_Inventory.push_back(SoldItem(item.itemid, item.sortPriority));
}
} else {
auto randomCount = GeneralUtils::GenerateRandomNumber<int32_t>(lootMatrix.minToDrop, lootMatrix.maxToDrop);
@@ -74,17 +77,7 @@ void VendorComponent::RefreshInventory(bool isCreation) {
auto randomItemIndex = GeneralUtils::GenerateRandomNumber<int32_t>(0, vendorItems.size() - 1);
const auto& randomItem = vendorItems.at(randomItemIndex);
vendorItems.erase(vendorItems.begin() + randomItemIndex);
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
auto itemComponentID = compRegistryTable->GetByIDAndType(randomItem.itemid, eReplicaComponentType::ITEM, -1);
if (itemComponentID == -1) {
LOG("Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT());
continue;
}
auto itemComponent = itemComponentTable->GetItemComponentByID(itemComponentID);
if (!m_HasStandardCostItems && itemComponent.baseValue != -1) SetHasStandardCostItems(true);
if (!m_HasMultiCostItems && !itemComponent.currencyCosts.empty()) SetHasMultiCostItems(true);
}
m_Inventory.push_back(SoldItem(randomItem.itemid, randomItem.sortPriority));
if (SetupItem(randomItem.itemid)) m_Inventory.push_back(SoldItem(randomItem.itemid, randomItem.sortPriority));
}
}
}
@@ -101,10 +94,10 @@ void VendorComponent::RefreshInventory(bool isCreation) {
}
void VendorComponent::SetupConstants() {
auto* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
auto* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
int componentID = compRegistryTable->GetByIDAndType(m_Parent->GetLOT(), eReplicaComponentType::VENDOR);
auto* vendorComponentTable = CDClientManager::Instance().GetTable<CDVendorComponentTable>();
auto* vendorComponentTable = CDClientManager::GetTable<CDVendorComponentTable>();
std::vector<CDVendorComponent> vendorComps = vendorComponentTable->Query([=](CDVendorComponent entry) { return (entry.id == componentID); });
if (vendorComps.empty()) return;
auto vendorData = vendorComps.at(0);
@@ -121,15 +114,6 @@ bool VendorComponent::SellsItem(const LOT item) const {
}) > 0;
}
void VendorComponent::SetupMaxCustomVendor(){
SetHasStandardCostItems(true);
m_Inventory.push_back(SoldItem(11909, 0)); // Top hat w frog
m_Inventory.push_back(SoldItem(7785, 0)); // Flash bulb
m_Inventory.push_back(SoldItem(12764, 0)); // Big fountain soda
m_Inventory.push_back(SoldItem(12241, 0)); // Hot cocoa (from fb)
}
void VendorComponent::HandleMrReeCameras(){
if (m_Parent->GetLOT() == 13569) {
SetHasStandardCostItems(true);
@@ -151,3 +135,80 @@ void VendorComponent::HandleMrReeCameras(){
m_Inventory.push_back(SoldItem(camera, 0));
}
}
void VendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) {
if (!SellsItem(lot)) {
auto* user = UserManager::Instance()->GetUser(buyer->GetSystemAddress());
CheatDetection::ReportCheat(user, buyer->GetSystemAddress(), "Attempted to buy item %i from achievement vendor %i that is not purchasable", lot, m_Parent->GetLOT());
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
auto* inventoryComponent = buyer->GetComponent<InventoryComponent>();
if (!inventoryComponent) {
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
int itemCompID = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::ITEM);
CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID);
// Extra currency that needs to be deducted in case of crafting
auto craftingCurrencies = CDItemComponentTable::ParseCraftingCurrencies(itemComp);
for (const auto& [crafintCurrencyLOT, crafintCurrencyCount]: craftingCurrencies) {
if (inventoryComponent->GetLotCount(crafintCurrencyLOT) < (crafintCurrencyCount * count)) {
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
}
for (const auto& [crafintCurrencyLOT, crafintCurrencyCount]: craftingCurrencies) {
inventoryComponent->RemoveItem(crafintCurrencyLOT, crafintCurrencyCount * count);
}
float buyScalar = GetBuyScalar();
const auto coinCost = static_cast<uint32_t>(std::floor((itemComp.baseValue * buyScalar) * count));
Character* character = buyer->GetCharacter();
if (!character || character->GetCoins() < coinCost) {
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
if (Inventory::IsValidItem(itemComp.currencyLOT)) {
const uint32_t altCurrencyCost = std::floor(itemComp.altCurrencyCost * buyScalar) * count;
if (inventoryComponent->GetLotCount(itemComp.currencyLOT) < altCurrencyCost) {
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
return;
}
inventoryComponent->RemoveItem(itemComp.currencyLOT, altCurrencyCost);
}
character->SetCoins(character->GetCoins() - (coinCost), eLootSourceType::VENDOR);
inventoryComponent->AddItem(lot, count, eLootSourceType::VENDOR);
GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_SUCCESS);
}
bool VendorComponent::SetupItem(LOT item) {
auto* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
auto* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
auto itemComponentID = compRegistryTable->GetByIDAndType(item, eReplicaComponentType::ITEM, -1);
if (itemComponentID == -1) {
LOG("Attempted to add item %i with ItemComponent ID -1 to vendor %i inventory. Not adding item!", itemComponentID, m_Parent->GetLOT());
return false;
}
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
auto itemComponent = itemComponentTable->GetItemComponentByID(itemComponentID);
if (!m_HasStandardCostItems && itemComponent.baseValue != -1) SetHasStandardCostItems(true);
if (!m_HasMultiCostItems && !itemComponent.currencyCosts.empty()) SetHasMultiCostItems(true);
}
return true;
}

View File

@@ -23,7 +23,7 @@ public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
VendorComponent(Entity* parent);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void OnUse(Entity* originator) override;
void RefreshInventory(bool isCreation = false);
@@ -47,10 +47,11 @@ public:
m_DirtyVendor = true;
}
void Buy(Entity* buyer, LOT lot, uint32_t count);
private:
void SetupMaxCustomVendor();
void HandleMrReeCameras();
bool SetupItem(LOT item);
float m_BuyScalar = 0.0f;
float m_SellScalar = 0.0f;
float m_RefreshTimeSeconds = 0.0f;