mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-07-26 17:21:57 +00:00
Merge remote-tracking branch 'origin/main' into grim-lu
This commit is contained in:
@@ -179,7 +179,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
|
||||
}
|
||||
|
||||
if (m_SoftTimer <= 0.0f) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
m_SoftTimer = 5.0f;
|
||||
} else {
|
||||
@@ -311,7 +311,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
}
|
||||
|
||||
if (serilizationRequired) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
GameMessages::SendPlayFXEffect(m_Parent->GetObjectID(), 6270, u"tether", "tether");
|
||||
@@ -324,7 +324,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
// Speed towards start position
|
||||
if (m_MovementAI != nullptr) {
|
||||
m_MovementAI->SetHaltDistance(0);
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
}
|
||||
|
||||
@@ -388,8 +388,6 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
}
|
||||
|
||||
LWOOBJID BaseCombatAIComponent::FindTarget() {
|
||||
//const auto reference = m_MovementAI == nullptr ? m_StartPosition : m_MovementAI->ApproximateLocation();
|
||||
|
||||
NiPoint3 reference = m_StartPosition;
|
||||
|
||||
if (m_MovementAI) reference = m_MovementAI->ApproximateLocation();
|
||||
@@ -418,7 +416,7 @@ LWOOBJID BaseCombatAIComponent::FindTarget() {
|
||||
float biggestThreat = 0;
|
||||
|
||||
for (const auto& entry : possibleTargets) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(entry);
|
||||
auto* entity = Game::entityManager->GetEntity(entry);
|
||||
|
||||
if (entity == nullptr) {
|
||||
continue;
|
||||
@@ -464,7 +462,7 @@ LWOOBJID BaseCombatAIComponent::FindTarget() {
|
||||
std::vector<LWOOBJID> deadThreats{};
|
||||
|
||||
for (const auto& threatTarget : m_ThreatEntries) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(threatTarget.first);
|
||||
auto* entity = Game::entityManager->GetEntity(threatTarget.first);
|
||||
|
||||
if (entity == nullptr) {
|
||||
deadThreats.push_back(threatTarget.first);
|
||||
@@ -503,7 +501,7 @@ std::vector<LWOOBJID> BaseCombatAIComponent::GetTargetWithinAggroRange() const {
|
||||
std::vector<LWOOBJID> targets;
|
||||
|
||||
for (auto id : m_Parent->GetTargetsInPhantom()) {
|
||||
auto* other = EntityManager::Instance()->GetEntity(id);
|
||||
auto* other = Game::entityManager->GetEntity(id);
|
||||
|
||||
const auto distance = Vector3::DistanceSquared(m_Parent->GetPosition(), other->GetPosition());
|
||||
|
||||
@@ -528,7 +526,7 @@ bool BaseCombatAIComponent::IsMech() {
|
||||
}
|
||||
|
||||
|
||||
void BaseCombatAIComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void BaseCombatAIComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_DirtyStateOrTarget || bIsInitialUpdate);
|
||||
if (m_DirtyStateOrTarget || bIsInitialUpdate) {
|
||||
outBitStream->Write(uint32_t(m_State));
|
||||
@@ -541,11 +539,11 @@ void BaseCombatAIComponent::SetAiState(AiState newState) {
|
||||
if (newState == this->m_State) return;
|
||||
this->m_State = newState;
|
||||
m_DirtyStateOrTarget = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
bool BaseCombatAIComponent::IsEnemy(LWOOBJID target) const {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* entity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (entity == nullptr) {
|
||||
Game::logger->Log("BaseCombatAIComponent", "Invalid entity for checking validity (%llu)!", target);
|
||||
@@ -594,11 +592,11 @@ void BaseCombatAIComponent::SetTarget(const LWOOBJID target) {
|
||||
if (this->m_Target == target) return;
|
||||
m_Target = target;
|
||||
m_DirtyStateOrTarget = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
Entity* BaseCombatAIComponent::GetTargetEntity() const {
|
||||
return EntityManager::Instance()->GetEntity(m_Target);
|
||||
return Game::entityManager->GetEntity(m_Target);
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::Taunt(LWOOBJID offender, float threat) {
|
||||
@@ -666,17 +664,17 @@ void BaseCombatAIComponent::Wander() {
|
||||
destination.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(destination);
|
||||
}
|
||||
|
||||
if (Vector3::DistanceSquared(destination, m_MovementAI->GetCurrentPosition()) < 2 * 2) {
|
||||
if (Vector3::DistanceSquared(destination, m_MovementAI->GetParent()->GetPosition()) < 2 * 2) {
|
||||
m_MovementAI->Stop();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_MovementAI->SetSpeed(m_TetherSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_TetherSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(destination);
|
||||
|
||||
m_Timer += (m_MovementAI->GetCurrentPosition().x - destination.x) / m_TetherSpeed;
|
||||
m_Timer += (m_MovementAI->GetParent()->GetPosition().x - destination.x) / m_TetherSpeed;
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::OnAggro() {
|
||||
@@ -691,21 +689,21 @@ void BaseCombatAIComponent::OnAggro() {
|
||||
m_MovementAI->SetHaltDistance(m_AttackRadius);
|
||||
|
||||
NiPoint3 targetPos = target->GetPosition();
|
||||
NiPoint3 currentPos = m_MovementAI->GetCurrentPosition();
|
||||
NiPoint3 currentPos = m_MovementAI->GetParent()->GetPosition();
|
||||
|
||||
// If the player's position is within range, attack
|
||||
if (Vector3::DistanceSquared(currentPos, targetPos) <= m_AttackRadius * m_AttackRadius) {
|
||||
m_MovementAI->Stop();
|
||||
} else if (Vector3::DistanceSquared(m_StartPosition, targetPos) > m_HardTetherRadius * m_HardTetherRadius) //Return to spawn if we're too far
|
||||
{
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
} else //Chase the player's new position
|
||||
{
|
||||
if (IsMech() && Vector3::DistanceSquared(targetPos, currentPos) > m_AttackRadius * m_AttackRadius * 3 * 3) return;
|
||||
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(targetPos);
|
||||
|
||||
@@ -731,7 +729,7 @@ void BaseCombatAIComponent::OnTether() {
|
||||
m_MovementAI->Stop();
|
||||
} else if (Vector3::DistanceSquared(m_StartPosition, targetPos) > m_HardTetherRadius * m_HardTetherRadius) //Return to spawn if we're too far
|
||||
{
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
|
||||
@@ -739,7 +737,7 @@ void BaseCombatAIComponent::OnTether() {
|
||||
} else {
|
||||
if (IsMech() && Vector3::DistanceSquared(targetPos, currentPos) > m_AttackRadius * m_AttackRadius * 3 * 3) return;
|
||||
|
||||
m_MovementAI->SetSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(targetPos);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
~BaseCombatAIComponent() override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Get the current behavioral state of the enemy
|
||||
|
||||
@@ -22,7 +22,7 @@ BouncerComponent::BouncerComponent(Entity* parent) : Component(parent) {
|
||||
BouncerComponent::~BouncerComponent() {
|
||||
}
|
||||
|
||||
void BouncerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void BouncerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_PetEnabled);
|
||||
if (m_PetEnabled) {
|
||||
outBitStream->Write(m_PetBouncerEnabled);
|
||||
@@ -36,7 +36,7 @@ Entity* BouncerComponent::GetParentEntity() const {
|
||||
void BouncerComponent::SetPetEnabled(bool value) {
|
||||
m_PetEnabled = value;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
||||
@@ -44,7 +44,7 @@ void BouncerComponent::SetPetBouncerEnabled(bool value) {
|
||||
|
||||
GameMessages::SendBouncerActiveStatus(m_Parent->GetObjectID(), value, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
if (value) {
|
||||
m_Parent->TriggerEvent(eTriggerEventType::PET_ON_SWITCH, m_Parent);
|
||||
@@ -68,7 +68,7 @@ void BouncerComponent::LookupPetSwitch() {
|
||||
const auto& groups = m_Parent->GetGroups();
|
||||
|
||||
for (const auto& group : groups) {
|
||||
const auto& entities = EntityManager::Instance()->GetEntitiesInGroup(group);
|
||||
const auto& entities = Game::entityManager->GetEntitiesInGroup(group);
|
||||
|
||||
for (auto* entity : entities) {
|
||||
auto* switchComponent = entity->GetComponent<SwitchComponent>();
|
||||
@@ -79,7 +79,7 @@ void BouncerComponent::LookupPetSwitch() {
|
||||
m_PetSwitchLoaded = true;
|
||||
m_PetEnabled = true;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
Game::logger->Log("BouncerComponent", "Loaded pet bouncer");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
BouncerComponent(Entity* parentEntity);
|
||||
~BouncerComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
Entity* GetParentEntity() const;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ BuffComponent::BuffComponent(Entity* parent) : Component(parent) {
|
||||
BuffComponent::~BuffComponent() {
|
||||
}
|
||||
|
||||
void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void BuffComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
if (!bIsInitialUpdate) return;
|
||||
if (m_Buffs.empty()) {
|
||||
outBitStream->Write0();
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ BuildBorderComponent::~BuildBorderComponent() {
|
||||
|
||||
void BuildBorderComponent::OnUse(Entity* originator) {
|
||||
if (originator->GetCharacter()) {
|
||||
const auto& entities = EntityManager::Instance()->GetEntitiesInGroup("PropertyPlaque");
|
||||
const auto& entities = Game::entityManager->GetEntitiesInGroup("PropertyPlaque");
|
||||
|
||||
auto buildArea = m_Parent->GetObjectID();
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
|
||||
"Component.cpp"
|
||||
"ControllablePhysicsComponent.cpp"
|
||||
"DestroyableComponent.cpp"
|
||||
"DonationVendorComponent.cpp"
|
||||
"InventoryComponent.cpp"
|
||||
"LevelProgressionComponent.cpp"
|
||||
"LUPExhibitComponent.cpp"
|
||||
@@ -30,7 +31,7 @@ set(DGAME_DCOMPONENTS_SOURCES "BaseCombatAIComponent.cpp"
|
||||
"RebuildComponent.cpp"
|
||||
"RenderComponent.cpp"
|
||||
"RigidbodyPhantomPhysicsComponent.cpp"
|
||||
"RocketLaunchLupComponent.cpp"
|
||||
"MultiZoneEntranceComponent.cpp"
|
||||
"RocketLaunchpadControlComponent.cpp"
|
||||
"ScriptedActivityComponent.cpp"
|
||||
"ShootingGalleryComponent.cpp"
|
||||
|
||||
@@ -70,7 +70,7 @@ bool CharacterComponent::LandingAnimDisabled(int zoneID) {
|
||||
CharacterComponent::~CharacterComponent() {
|
||||
}
|
||||
|
||||
void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write0();
|
||||
@@ -419,7 +419,7 @@ void CharacterComponent::TrackMissionCompletion(bool isAchievement) {
|
||||
|
||||
// Achievements are tracked separately for the zone
|
||||
if (isAchievement) {
|
||||
const auto mapID = dZoneManager::Instance()->GetZoneID().GetMapID();
|
||||
const auto mapID = Game::zoneManager->GetZoneID().GetMapID();
|
||||
GetZoneStatisticsForMap(mapID).m_AchievementsCollected++;
|
||||
}
|
||||
}
|
||||
@@ -480,7 +480,7 @@ void CharacterComponent::TrackArmorDelta(int32_t armor) {
|
||||
void CharacterComponent::TrackRebuildComplete() {
|
||||
UpdatePlayerStatistic(QuickBuildsCompleted);
|
||||
|
||||
const auto mapID = dZoneManager::Instance()->GetZoneID().GetMapID();
|
||||
const auto mapID = Game::zoneManager->GetZoneID().GetMapID();
|
||||
GetZoneStatisticsForMap(mapID).m_QuickBuildsCompleted++;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Updates the rocket configuration using a LOT string separated by commas
|
||||
@@ -276,6 +276,10 @@ public:
|
||||
*/
|
||||
void UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const;
|
||||
|
||||
void SetCurrentInteracting(LWOOBJID objectID) {m_CurrentInteracting = objectID;};
|
||||
|
||||
LWOOBJID GetCurrentInteracting() {return m_CurrentInteracting;};
|
||||
|
||||
/**
|
||||
* Character info regarding this character, including clothing styles, etc.
|
||||
*/
|
||||
@@ -560,6 +564,8 @@ private:
|
||||
* ID of the last rocket used
|
||||
*/
|
||||
LWOOBJID m_LastRocketItemID = LWOOBJID_EMPTY;
|
||||
|
||||
LWOOBJID m_CurrentInteracting = LWOOBJID_EMPTY;
|
||||
};
|
||||
|
||||
#endif // CHARACTERCOMPONENT_H
|
||||
|
||||
@@ -28,3 +28,7 @@ void Component::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
void Component::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
|
||||
}
|
||||
|
||||
void Component::Serialize(RakNet::BitStream* outBitStream, bool isConstruction) {
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
*/
|
||||
virtual void LoadFromXml(tinyxml2::XMLDocument* doc);
|
||||
|
||||
virtual void Serialize(RakNet::BitStream* outBitStream, bool isConstruction);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,7 +74,7 @@ void ControllablePhysicsComponent::Update(float deltaTime) {
|
||||
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
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;
|
||||
@@ -181,12 +181,6 @@ void ControllablePhysicsComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
m_DirtyPosition = true;
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::ResetFlags() {
|
||||
m_DirtyAngularVelocity = false;
|
||||
m_DirtyPosition = false;
|
||||
m_DirtyVelocity = false;
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
|
||||
if (!character) {
|
||||
@@ -194,7 +188,7 @@ void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto zoneInfo = dZoneManager::Instance()->GetZone()->GetZoneID();
|
||||
auto zoneInfo = Game::zoneManager->GetZone()->GetZoneID();
|
||||
|
||||
if (zoneInfo.GetMapID() != 0 && zoneInfo.GetCloneID() == 0) {
|
||||
character->SetAttribute("lzx", m_Position.x);
|
||||
@@ -300,7 +294,7 @@ void ControllablePhysicsComponent::RemovePickupRadiusScale(float value) {
|
||||
auto candidateRadius = m_ActivePickupRadiusScales[i];
|
||||
if (m_PickupRadius < candidateRadius) m_PickupRadius = candidateRadius;
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::AddSpeedboost(float value) {
|
||||
@@ -327,7 +321,7 @@ void ControllablePhysicsComponent::RemoveSpeedboost(float value) {
|
||||
m_SpeedBoost = m_ActiveSpeedBoosts.back();
|
||||
}
|
||||
SetSpeedMultiplier(m_SpeedBoost / 500.0f); // 500 being the base speed
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::ActivateBubbleBuff(eBubbleType bubbleType, bool specialAnims){
|
||||
@@ -339,13 +333,13 @@ void ControllablePhysicsComponent::ActivateBubbleBuff(eBubbleType bubbleType, bo
|
||||
m_IsInBubble = true;
|
||||
m_DirtyBubble = true;
|
||||
m_SpecialAnims = specialAnims;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ControllablePhysicsComponent::DeactivateBubbleBuff(){
|
||||
m_DirtyBubble = true;
|
||||
m_IsInBubble = false;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
};
|
||||
|
||||
void ControllablePhysicsComponent::SetStunImmunity(
|
||||
|
||||
@@ -27,9 +27,8 @@ public:
|
||||
~ControllablePhysicsComponent() override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void ResetFlags();
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,7 +141,7 @@ void DestroyableComponent::Reinitialize(LOT templateID) {
|
||||
}
|
||||
}
|
||||
|
||||
void DestroyableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags) {
|
||||
void DestroyableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write1(); // always write these on construction
|
||||
outBitStream->Write(m_ImmuneToBasicAttackCount);
|
||||
@@ -275,7 +275,7 @@ void DestroyableComponent::SetMaxHealth(float value, bool playAnim) {
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetArmor(int32_t value) {
|
||||
@@ -316,7 +316,7 @@ void DestroyableComponent::SetMaxArmor(float value, bool playAnim) {
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetImagination(int32_t value) {
|
||||
@@ -355,7 +355,7 @@ void DestroyableComponent::SetMaxImagination(float value, bool playAnim) {
|
||||
|
||||
GameMessages::SendUIMessageServerToSingleClient(m_Parent, m_Parent->GetParentUser()->GetSystemAddress(), "MaxPlayerBarUpdate", args);
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void DestroyableComponent::SetDamageToAbsorb(int32_t value) {
|
||||
@@ -504,11 +504,11 @@ LWOOBJID DestroyableComponent::GetKillerID() const {
|
||||
}
|
||||
|
||||
Entity* DestroyableComponent::GetKiller() const {
|
||||
return EntityManager::Instance()->GetEntity(m_KillerID);
|
||||
return Game::entityManager->GetEntity(m_KillerID);
|
||||
}
|
||||
|
||||
bool DestroyableComponent::CheckValidity(const LWOOBJID target, const bool ignoreFactions, const bool targetEnemy, const bool targetFriend) const {
|
||||
auto* targetEntity = EntityManager::Instance()->GetEntity(target);
|
||||
auto* targetEntity = Game::entityManager->GetEntity(target);
|
||||
|
||||
if (targetEntity == nullptr) {
|
||||
Game::logger->Log("DestroyableComponent", "Invalid entity for checking validity (%llu)!", target);
|
||||
@@ -554,7 +554,7 @@ void DestroyableComponent::Heal(const uint32_t health) {
|
||||
|
||||
SetHealth(current);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -572,7 +572,7 @@ void DestroyableComponent::Imagine(const int32_t deltaImagination) {
|
||||
|
||||
SetImagination(current);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -586,7 +586,7 @@ void DestroyableComponent::Repair(const uint32_t armor) {
|
||||
|
||||
SetArmor(current);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -648,7 +648,7 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
if (possessor) {
|
||||
auto possessableId = possessor->GetPossessable();
|
||||
if (possessableId != LWOOBJID_EMPTY) {
|
||||
auto possessable = EntityManager::Instance()->GetEntity(possessableId);
|
||||
auto possessable = Game::entityManager->GetEntity(possessableId);
|
||||
if (possessable) {
|
||||
possessor->Dismount(possessable);
|
||||
}
|
||||
@@ -660,10 +660,10 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
}
|
||||
|
||||
if (echo) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
auto* attacker = EntityManager::Instance()->GetEntity(source);
|
||||
auto* attacker = Game::entityManager->GetEntity(source);
|
||||
m_Parent->OnHit(attacker);
|
||||
m_Parent->OnHitOrHealResult(attacker, sourceDamage);
|
||||
NotifySubscribers(attacker, sourceDamage);
|
||||
@@ -683,7 +683,7 @@ void DestroyableComponent::Damage(uint32_t damage, const LWOOBJID source, uint32
|
||||
}
|
||||
|
||||
//check if hardcore mode is enabled
|
||||
if (EntityManager::Instance()->GetHardcoreMode()) {
|
||||
if (Game::entityManager->GetHardcoreMode()) {
|
||||
DoHardcoreModeDrops(source);
|
||||
}
|
||||
|
||||
@@ -718,12 +718,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
SetArmor(0);
|
||||
SetHealth(0);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
m_KillerID = source;
|
||||
|
||||
auto* owner = EntityManager::Instance()->GetEntity(source);
|
||||
auto* owner = Game::entityManager->GetEntity(source);
|
||||
|
||||
if (owner != nullptr) {
|
||||
owner = owner->GetOwner(); // If the owner is overwritten, we collect that here
|
||||
@@ -743,7 +743,7 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
if (missions != nullptr) {
|
||||
if (team != nullptr) {
|
||||
for (const auto memberId : team->members) {
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
|
||||
@@ -783,12 +783,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
if (team->lootOption == 0) { // Round robin
|
||||
specificOwner = TeamManager::Instance()->GetNextLootOwner(team);
|
||||
|
||||
auto* member = EntityManager::Instance()->GetEntity(specificOwner);
|
||||
auto* member = Game::entityManager->GetEntity(specificOwner);
|
||||
|
||||
if (member) LootGenerator::Instance().DropLoot(member, m_Parent, lootMatrixId, GetMinCoins(), GetMaxCoins());
|
||||
} else {
|
||||
for (const auto memberId : team->members) { // Free for all
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
|
||||
if (member == nullptr) continue;
|
||||
|
||||
@@ -801,13 +801,13 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
}
|
||||
} else {
|
||||
//Check if this zone allows coin drops
|
||||
if (dZoneManager::Instance()->GetPlayerLoseCoinOnDeath()) {
|
||||
if (Game::zoneManager->GetPlayerLoseCoinOnDeath()) {
|
||||
auto* character = m_Parent->GetCharacter();
|
||||
uint64_t coinsTotal = character->GetCoins();
|
||||
const uint64_t minCoinsToLose = dZoneManager::Instance()->GetWorldConfig()->coinsLostOnDeathMin;
|
||||
const uint64_t minCoinsToLose = Game::zoneManager->GetWorldConfig()->coinsLostOnDeathMin;
|
||||
if (coinsTotal >= minCoinsToLose) {
|
||||
const uint64_t maxCoinsToLose = dZoneManager::Instance()->GetWorldConfig()->coinsLostOnDeathMax;
|
||||
const float coinPercentageToLose = dZoneManager::Instance()->GetWorldConfig()->coinsLostOnDeathPercent;
|
||||
const uint64_t maxCoinsToLose = Game::zoneManager->GetWorldConfig()->coinsLostOnDeathMax;
|
||||
const float coinPercentageToLose = Game::zoneManager->GetWorldConfig()->coinsLostOnDeathPercent;
|
||||
|
||||
uint64_t coinsToLose = std::max(static_cast<uint64_t>(coinsTotal * coinPercentageToLose), minCoinsToLose);
|
||||
coinsToLose = std::min(maxCoinsToLose, coinsToLose);
|
||||
@@ -819,12 +819,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType
|
||||
}
|
||||
}
|
||||
|
||||
Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity();
|
||||
Entity* zoneControl = Game::entityManager->GetZoneControlEntity();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) {
|
||||
script->OnPlayerDied(zoneControl, m_Parent);
|
||||
}
|
||||
|
||||
std::vector<Entity*> scriptedActs = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
std::vector<Entity*> scriptedActs = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::SCRIPTED_ACTIVITY);
|
||||
for (Entity* scriptEntity : scriptedActs) {
|
||||
if (scriptEntity->GetObjectID() != zoneControl->GetObjectID()) { // Don't want to trigger twice on instance worlds
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(scriptEntity)) {
|
||||
@@ -1001,7 +1001,7 @@ void DestroyableComponent::FixStats() {
|
||||
destroyableComponent->SetImagination(currentImagination);
|
||||
|
||||
// Serialize the entity
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
|
||||
void DestroyableComponent::AddStat(const StatProperty& stat) {
|
||||
@@ -1334,12 +1334,12 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source){
|
||||
auto* character = m_Parent->GetComponent<CharacterComponent>();
|
||||
auto uscore = character->GetUScore();
|
||||
|
||||
auto uscoreToLose = uscore * (EntityManager::Instance()->GetHardcoreLoseUscoreOnDeathPercent() / 100);
|
||||
auto uscoreToLose = uscore * (Game::entityManager->GetHardcoreLoseUscoreOnDeathPercent() / 100);
|
||||
character->SetUScore(uscore - uscoreToLose);
|
||||
|
||||
GameMessages::SendModifyLEGOScore(m_Parent, m_Parent->GetSystemAddress(), -uscoreToLose, eLootSourceType::MISSION);
|
||||
|
||||
if (EntityManager::Instance()->GetHardcoreDropinventoryOnDeath()) {
|
||||
if (Game::entityManager->GetHardcoreDropinventoryOnDeath()) {
|
||||
//drop all items from inventory:
|
||||
auto* inventory = m_Parent->GetComponent<InventoryComponent>();
|
||||
if (inventory) {
|
||||
@@ -1356,7 +1356,7 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source){
|
||||
GameMessages::SendDropClientLoot(m_Parent, source, item.second->GetLot(), 0, m_Parent->GetPosition(), item.second->GetCount());
|
||||
item.second->SetCount(0, false, false);
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1376,25 +1376,25 @@ void DestroyableComponent::DoHardcoreModeDrops(const LWOOBJID source){
|
||||
|
||||
// Reload the player since we can't normally reduce uscore from the server and we want the UI to update
|
||||
// do this last so we don't get killed.... again
|
||||
EntityManager::Instance()->DestructEntity(m_Parent);
|
||||
EntityManager::Instance()->ConstructEntity(m_Parent);
|
||||
Game::entityManager->DestructEntity(m_Parent);
|
||||
Game::entityManager->ConstructEntity(m_Parent);
|
||||
return;
|
||||
}
|
||||
|
||||
//award the player some u-score:
|
||||
auto* player = EntityManager::Instance()->GetEntity(source);
|
||||
auto* player = Game::entityManager->GetEntity(source);
|
||||
if (player && player->IsPlayer()) {
|
||||
auto* playerStats = player->GetComponent<CharacterComponent>();
|
||||
if (playerStats) {
|
||||
//get the maximum health from this enemy:
|
||||
auto maxHealth = GetMaxHealth();
|
||||
|
||||
int uscore = maxHealth * EntityManager::Instance()->GetHardcoreUscoreEnemiesMultiplier();
|
||||
int uscore = maxHealth * Game::entityManager->GetHardcoreUscoreEnemiesMultiplier();
|
||||
|
||||
playerStats->SetUScore(playerStats->GetUScore() + uscore);
|
||||
GameMessages::SendModifyLEGOScore(player, player->GetSystemAddress(), uscore, eLootSourceType::MISSION);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
DestroyableComponent(Entity* parentEntity);
|
||||
~DestroyableComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
|
||||
void UpdateXml(tinyxml2::XMLDocument* doc) override;
|
||||
|
||||
|
||||
50
dGame/dComponents/DonationVendorComponent.cpp
Normal file
50
dGame/dComponents/DonationVendorComponent.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "DonationVendorComponent.h"
|
||||
#include "Database.h"
|
||||
|
||||
DonationVendorComponent::DonationVendorComponent(Entity* parent) : VendorComponent(parent) {
|
||||
//LoadConfigData
|
||||
m_PercentComplete = 0.0;
|
||||
m_TotalDonated = 0;
|
||||
m_TotalRemaining = 0;
|
||||
|
||||
// custom attribute to calculate other values
|
||||
m_Goal = m_Parent->GetVar<int32_t>(u"donationGoal");
|
||||
if (m_Goal == 0) m_Goal = INT32_MAX;
|
||||
|
||||
// Default to the nexus tower jawbox activity and setup settings
|
||||
m_ActivityId = m_Parent->GetVar<uint32_t>(u"activityID");
|
||||
if ((m_ActivityId == 0) || (m_ActivityId == 117)) {
|
||||
m_ActivityId = 117;
|
||||
m_PercentComplete = 1.0;
|
||||
m_TotalDonated = INT32_MAX;
|
||||
m_TotalRemaining = 0;
|
||||
m_Goal = INT32_MAX;
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> query(Database::CreatePreppedStmt("SELECT SUM(primaryScore) as donation_total FROM leaderboard WHERE game_id = ?;"));
|
||||
query->setInt(1, m_ActivityId);
|
||||
std::unique_ptr<sql::ResultSet> donation_total(query->executeQuery());
|
||||
if (donation_total->next()) m_TotalDonated = donation_total->getInt("donation_total");
|
||||
m_TotalRemaining = m_Goal - m_TotalDonated;
|
||||
m_PercentComplete = m_TotalDonated/static_cast<float>(m_Goal);
|
||||
}
|
||||
|
||||
void DonationVendorComponent::SubmitDonation(uint32_t count) {
|
||||
if (count <= 0 && ((m_TotalDonated + count) > 0)) return;
|
||||
m_TotalDonated += count;
|
||||
m_TotalRemaining = m_Goal - m_TotalDonated;
|
||||
m_PercentComplete = m_TotalDonated/static_cast<float>(m_Goal);
|
||||
m_DirtyDonationVendor = true;
|
||||
}
|
||||
|
||||
void DonationVendorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
VendorComponent::Serialize(outBitStream, bIsInitialUpdate);
|
||||
outBitStream->Write(bIsInitialUpdate || m_DirtyDonationVendor);
|
||||
if (bIsInitialUpdate || m_DirtyDonationVendor) {
|
||||
outBitStream->Write(m_PercentComplete);
|
||||
outBitStream->Write(m_TotalDonated);
|
||||
outBitStream->Write(m_TotalRemaining);
|
||||
if (!bIsInitialUpdate) m_DirtyDonationVendor = false;
|
||||
}
|
||||
}
|
||||
27
dGame/dComponents/DonationVendorComponent.h
Normal file
27
dGame/dComponents/DonationVendorComponent.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef __DONATIONVENDORCOMPONENT__H__
|
||||
#define __DONATIONVENDORCOMPONENT__H__
|
||||
|
||||
#include "VendorComponent.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class Entity;
|
||||
|
||||
class DonationVendorComponent final : public VendorComponent {
|
||||
public:
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::DONATION_VENDOR;
|
||||
DonationVendorComponent(Entity* parent);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
uint32_t GetActivityID() {return m_ActivityId;};
|
||||
void SubmitDonation(uint32_t count);
|
||||
|
||||
private:
|
||||
bool m_DirtyDonationVendor = false;
|
||||
float m_PercentComplete = 0.0;
|
||||
int32_t m_TotalDonated = 0;
|
||||
int32_t m_TotalRemaining = 0;
|
||||
uint32_t m_ActivityId = 0;
|
||||
int32_t m_Goal = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif //!__DONATIONVENDORCOMPONENT__H__
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "CDObjectSkillsTable.h"
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
|
||||
InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document): Component(parent) {
|
||||
InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document) : Component(parent) {
|
||||
this->m_Dirty = true;
|
||||
this->m_Equipped = {};
|
||||
this->m_Pushed = {};
|
||||
@@ -116,6 +116,9 @@ Inventory* InventoryComponent::GetInventory(const eInventoryType type) {
|
||||
case eInventoryType::VENDOR_BUYBACK:
|
||||
size = 27u;
|
||||
break;
|
||||
case eInventoryType::DONATION:
|
||||
size = 24u;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -797,7 +800,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool bIsInitialUpdate, unsigned& flags) {
|
||||
void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool bIsInitialUpdate) {
|
||||
if (bIsInitialUpdate || m_Dirty) {
|
||||
outBitStream->Write(true);
|
||||
|
||||
@@ -855,10 +858,6 @@ void InventoryComponent::Serialize(RakNet::BitStream* outBitStream, const bool b
|
||||
outBitStream->Write(false);
|
||||
}
|
||||
|
||||
void InventoryComponent::ResetFlags() {
|
||||
m_Dirty = false;
|
||||
}
|
||||
|
||||
void InventoryComponent::Update(float deltaTime) {
|
||||
for (auto* set : m_Itemsets) {
|
||||
set->Update(deltaTime);
|
||||
@@ -914,18 +913,26 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks) {
|
||||
if (character != nullptr && !skipChecks) {
|
||||
// Hacky proximity rocket
|
||||
if (item->GetLot() == 6416) {
|
||||
const auto rocketLauchPads = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::ROCKET_LAUNCH);
|
||||
const auto rocketLauchPads = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::ROCKET_LAUNCH);
|
||||
|
||||
const auto position = m_Parent->GetPosition();
|
||||
|
||||
for (auto* lauchPad : rocketLauchPads) {
|
||||
if (Vector3::DistanceSquared(lauchPad->GetPosition(), position) > 13 * 13) continue;
|
||||
for (auto* launchPad : rocketLauchPads) {
|
||||
if (!launchPad) continue;
|
||||
|
||||
auto prereq = launchPad->GetVarAsString(u"rocketLaunchPreCondition");
|
||||
if (!prereq.empty()) {
|
||||
PreconditionExpression expression(prereq);
|
||||
if (!expression.Check(m_Parent)) continue;
|
||||
}
|
||||
|
||||
if (Vector3::DistanceSquared(launchPad->GetPosition(), position) > 13 * 13) continue;
|
||||
|
||||
auto* characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
|
||||
if (characterComponent != nullptr) characterComponent->SetLastRocketItemID(item->GetId());
|
||||
|
||||
lauchPad->OnUse(m_Parent);
|
||||
launchPad->OnUse(m_Parent);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -967,7 +974,7 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks) {
|
||||
|
||||
EquipScripts(item);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void InventoryComponent::UnEquipItem(Item* item) {
|
||||
@@ -997,12 +1004,12 @@ void InventoryComponent::UnEquipItem(Item* item) {
|
||||
|
||||
UnequipScripts(item);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Trigger property event
|
||||
if (PropertyManagementComponent::Instance() != nullptr && item->GetCount() > 0 && Inventory::FindInventoryTypeForLot(item->GetLot()) == MODELS) {
|
||||
PropertyManagementComponent::Instance()->GetParent()->OnZonePropertyModelRemovedWhileEquipped(m_Parent);
|
||||
dZoneManager::Instance()->GetZoneControlObject()->OnZonePropertyModelRemovedWhileEquipped(m_Parent);
|
||||
Game::zoneManager->GetZoneControlObject()->OnZonePropertyModelRemovedWhileEquipped(m_Parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,7 +1055,7 @@ void InventoryComponent::HandlePossession(Item* item) {
|
||||
if (possessorComponent->GetIsDismounting()) return;
|
||||
|
||||
// Check to see if we are already mounting something
|
||||
auto* currentlyPossessedEntity = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
|
||||
auto* currentlyPossessedEntity = Game::entityManager->GetEntity(possessorComponent->GetPossessable());
|
||||
auto currentlyPossessedItem = possessorComponent->GetMountItemID();
|
||||
|
||||
if (currentlyPossessedItem) {
|
||||
@@ -1071,21 +1078,11 @@ void InventoryComponent::HandlePossession(Item* item) {
|
||||
info.rot = startRotation;
|
||||
info.spawnerID = m_Parent->GetObjectID();
|
||||
|
||||
auto* mount = EntityManager::Instance()->CreateEntity(info, nullptr, m_Parent);
|
||||
auto* mount = Game::entityManager->CreateEntity(info, nullptr, m_Parent);
|
||||
|
||||
// Check to see if the mount is a vehicle, if so, flip it
|
||||
auto* vehicleComponent = mount->GetComponent<VehiclePhysicsComponent>();
|
||||
if (vehicleComponent) {
|
||||
auto angles = startRotation.GetEulerAngles();
|
||||
// Make it right side up
|
||||
angles.x -= PI;
|
||||
// Make it going in the direction of the player
|
||||
angles.y -= PI;
|
||||
startRotation = NiQuaternion::FromEulerAngles(angles);
|
||||
mount->SetRotation(startRotation);
|
||||
// We're pod racing now
|
||||
characterComponent->SetIsRacing(true);
|
||||
}
|
||||
if (vehicleComponent) characterComponent->SetIsRacing(true);
|
||||
|
||||
// Setup the destroyable stats
|
||||
auto* destroyableComponent = mount->GetComponent<DestroyableComponent>();
|
||||
@@ -1106,9 +1103,9 @@ void InventoryComponent::HandlePossession(Item* item) {
|
||||
GameMessages::SendSetJetPackMode(m_Parent, false);
|
||||
|
||||
// Make it go to the client
|
||||
EntityManager::Instance()->ConstructEntity(mount);
|
||||
Game::entityManager->ConstructEntity(mount);
|
||||
// Update the possessor
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// have to unlock the input so it vehicle can be driven
|
||||
if (vehicleComponent) GameMessages::SendVehicleUnlockInput(mount->GetObjectID(), false, m_Parent->GetSystemAddress());
|
||||
@@ -1190,7 +1187,7 @@ void InventoryComponent::PopEquippedItems() {
|
||||
destroyableComponent->SetHealth(static_cast<int32_t>(destroyableComponent->GetMaxHealth()));
|
||||
destroyableComponent->SetArmor(static_cast<int32_t>(destroyableComponent->GetMaxArmor()));
|
||||
destroyableComponent->SetImagination(static_cast<int32_t>(destroyableComponent->GetMaxImagination()));
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
m_Dirty = true;
|
||||
@@ -1510,7 +1507,7 @@ void InventoryComponent::SpawnPet(Item* item) {
|
||||
info.rot = NiQuaternion::IDENTITY;
|
||||
info.spawnerID = m_Parent->GetObjectID();
|
||||
|
||||
auto* pet = EntityManager::Instance()->CreateEntity(info);
|
||||
auto* pet = Game::entityManager->CreateEntity(info);
|
||||
|
||||
auto* petComponent = pet->GetComponent<PetComponent>();
|
||||
|
||||
@@ -1518,7 +1515,7 @@ void InventoryComponent::SpawnPet(Item* item) {
|
||||
petComponent->Activate(item);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(pet);
|
||||
Game::entityManager->ConstructEntity(pet);
|
||||
}
|
||||
|
||||
void InventoryComponent::SetDatabasePet(LWOOBJID id, const DatabasePet& data) {
|
||||
@@ -1627,7 +1624,7 @@ void InventoryComponent::SetNPCItems(const std::vector<LOT>& items) {
|
||||
UpdateSlot(info.equipLocation, { id, static_cast<LOT>(item), 1, slot++ }, true);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
InventoryComponent::~InventoryComponent() {
|
||||
|
||||
@@ -43,10 +43,9 @@ public:
|
||||
explicit InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document = nullptr);
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void LoadXml(tinyxml2::XMLDocument* document);
|
||||
void UpdateXml(tinyxml2::XMLDocument* document) override;
|
||||
void ResetFlags();
|
||||
|
||||
/**
|
||||
* Returns an inventory of the specified type, if it exists
|
||||
|
||||
@@ -35,10 +35,10 @@ void LUPExhibitComponent::NextExhibit() {
|
||||
|
||||
m_Exhibit = m_Exhibits[m_ExhibitIndex];
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void LUPExhibitComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags) {
|
||||
void LUPExhibitComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write1(); // Dirty flag?
|
||||
outBitStream->Write(m_Exhibit);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
LUPExhibitComponent(Entity* parent);
|
||||
~LUPExhibitComponent();
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, uint32_t& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* After the timer runs out, this changes the currently exhibited LOT to the next one
|
||||
|
||||
@@ -37,7 +37,7 @@ void LevelProgressionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
|
||||
m_CharacterVersion = static_cast<eCharacterVersion>(characterVersion);
|
||||
}
|
||||
|
||||
void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void LevelProgressionComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(bIsInitialUpdate || m_DirtyLevelInfo);
|
||||
if (bIsInitialUpdate || m_DirtyLevelInfo) outBitStream->Write(m_Level);
|
||||
m_DirtyLevelInfo = false;
|
||||
@@ -56,19 +56,19 @@ void LevelProgressionComponent::HandleLevelUp() {
|
||||
// Tell the client we beginning to send level rewards.
|
||||
if (rewardingItem) GameMessages::NotifyLevelRewards(m_Parent->GetObjectID(), m_Parent->GetSystemAddress(), m_Level, rewardingItem);
|
||||
|
||||
for (auto* reward : rewards) {
|
||||
switch (reward->rewardType) {
|
||||
for (const auto& reward : rewards) {
|
||||
switch (reward.rewardType) {
|
||||
case 0:
|
||||
inventoryComponent->AddItem(reward->value, reward->count, eLootSourceType::LEVEL_REWARD);
|
||||
inventoryComponent->AddItem(reward.value, reward.count, eLootSourceType::LEVEL_REWARD);
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
auto* items = inventoryComponent->GetInventory(eInventoryType::ITEMS);
|
||||
items->SetSize(items->GetSize() + reward->value);
|
||||
items->SetSize(items->GetSize() + reward.value);
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
SetSpeedBase(static_cast<float>(reward->value) );
|
||||
SetSpeedBase(static_cast<float>(reward.value) );
|
||||
controllablePhysicsComponent->SetSpeedMultiplier(GetSpeedBase() / 500.0f);
|
||||
break;
|
||||
case 11:
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
*/
|
||||
LevelProgressionComponent(Entity* parent);
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Save data from this componennt to character XML
|
||||
|
||||
@@ -26,7 +26,7 @@ std::unordered_map<AchievementCacheKey, std::vector<uint32_t>> MissionComponent:
|
||||
|
||||
//! Initializer
|
||||
MissionComponent::MissionComponent(Entity* parent) : Component(parent) {
|
||||
m_LastUsedMissionOrderUID = dZoneManager::Instance()->GetUniqueMissionIdStartingValue();
|
||||
m_LastUsedMissionOrderUID = Game::zoneManager->GetUniqueMissionIdStartingValue();
|
||||
}
|
||||
|
||||
//! Destructor
|
||||
|
||||
@@ -8,7 +8,7 @@ ModelComponent::ModelComponent(Entity* parent) : Component(parent) {
|
||||
m_userModelID = m_Parent->GetVarAs<LWOOBJID>(u"userModelID");
|
||||
}
|
||||
|
||||
void ModelComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void ModelComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
// ItemComponent Serialization. Pets do not get this serialization.
|
||||
if (!m_Parent->HasComponent(eReplicaComponentType::PET)) {
|
||||
outBitStream->Write1();
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
ModelComponent(Entity* parent);
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Returns the original position of the model
|
||||
|
||||
@@ -46,7 +46,7 @@ const std::u16string& ModuleAssemblyComponent::GetAssemblyPartsLOTs() const {
|
||||
return m_AssemblyPartsLOTs;
|
||||
}
|
||||
|
||||
void ModuleAssemblyComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void ModuleAssemblyComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write1();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
ModuleAssemblyComponent(Entity* parent);
|
||||
~ModuleAssemblyComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,85 +10,77 @@
|
||||
#include "EntityManager.h"
|
||||
#include "SimplePhysicsComponent.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "Game.h"
|
||||
#include "dZoneManager.h"
|
||||
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDPhysicsComponentTable.h"
|
||||
|
||||
std::map<LOT, float> MovementAIComponent::m_PhysicsSpeedCache = {};
|
||||
namespace {
|
||||
/**
|
||||
* Cache of all lots and their respective speeds
|
||||
*/
|
||||
std::map<LOT, float> m_PhysicsSpeedCache;
|
||||
}
|
||||
|
||||
MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : Component(parent) {
|
||||
m_Info = std::move(info);
|
||||
m_Done = true;
|
||||
m_Info = info;
|
||||
m_AtFinalWaypoint = true;
|
||||
|
||||
m_BaseCombatAI = nullptr;
|
||||
|
||||
m_BaseCombatAI = reinterpret_cast<BaseCombatAIComponent*>(m_Parent->GetComponent(eReplicaComponentType::BASE_COMBAT_AI));
|
||||
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
|
||||
|
||||
//Try and fix the insane values:
|
||||
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius = m_Info.wanderRadius * 0.5f;
|
||||
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius *= 0.5f;
|
||||
if (m_Info.wanderRadius > 8.0f) m_Info.wanderRadius = 8.0f;
|
||||
if (m_Info.wanderSpeed > 0.5f) m_Info.wanderSpeed = m_Info.wanderSpeed * 0.5f;
|
||||
if (m_Info.wanderSpeed > 0.5f) m_Info.wanderSpeed *= 0.5f;
|
||||
|
||||
m_BaseSpeed = GetBaseSpeed(m_Parent->GetLOT());
|
||||
|
||||
m_NextWaypoint = GetCurrentPosition();
|
||||
m_NextWaypoint = m_Parent->GetPosition();
|
||||
m_Acceleration = 0.4f;
|
||||
m_Interrupted = false;
|
||||
m_PullPoint = {};
|
||||
m_PullingToPoint = false;
|
||||
m_PullPoint = NiPoint3::ZERO;
|
||||
m_HaltDistance = 0;
|
||||
m_Timer = 0;
|
||||
m_TimeToTravel = 0;
|
||||
m_TimeTravelled = 0;
|
||||
m_CurrentSpeed = 0;
|
||||
m_Speed = 0;
|
||||
m_TotalTime = 0;
|
||||
m_MaxSpeed = 0;
|
||||
m_LockRotation = false;
|
||||
}
|
||||
|
||||
MovementAIComponent::~MovementAIComponent() = default;
|
||||
|
||||
void MovementAIComponent::Update(const float deltaTime) {
|
||||
if (m_Interrupted) {
|
||||
if (m_PullingToPoint) {
|
||||
const auto source = GetCurrentWaypoint();
|
||||
|
||||
const auto speed = deltaTime * 2.5f;
|
||||
|
||||
NiPoint3 velocity;
|
||||
|
||||
velocity.x = (m_PullPoint.x - source.x) * speed;
|
||||
velocity.y = (m_PullPoint.y - source.y) * speed;
|
||||
velocity.z = (m_PullPoint.z - source.z) * speed;
|
||||
NiPoint3 velocity = (m_PullPoint - source) * speed;
|
||||
|
||||
SetPosition(source + velocity);
|
||||
|
||||
if (Vector3::DistanceSquared(GetCurrentPosition(), m_PullPoint) < 2 * 2) {
|
||||
m_Interrupted = false;
|
||||
if (Vector3::DistanceSquared(m_Parent->GetPosition(), m_PullPoint) < std::pow(2, 2)) {
|
||||
m_PullingToPoint = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (AtFinalWaypoint()) // Are we done?
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Are we done?
|
||||
if (AtFinalWaypoint()) return;
|
||||
|
||||
if (m_HaltDistance > 0) {
|
||||
if (Vector3::DistanceSquared(ApproximateLocation(), GetDestination()) < m_HaltDistance * m_HaltDistance) // Prevent us from hugging the target
|
||||
{
|
||||
// Prevent us from hugging the target
|
||||
if (Vector3::DistanceSquared(ApproximateLocation(), GetDestination()) < std::pow(m_HaltDistance, 2)) {
|
||||
Stop();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Timer > 0) {
|
||||
m_Timer -= deltaTime;
|
||||
|
||||
if (m_Timer > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_Timer = 0;
|
||||
}
|
||||
m_TimeTravelled += deltaTime;
|
||||
if (m_TimeTravelled < m_TimeToTravel) return;
|
||||
m_TimeTravelled = 0.0f;
|
||||
|
||||
const auto source = GetCurrentWaypoint();
|
||||
|
||||
@@ -101,55 +93,51 @@ void MovementAIComponent::Update(const float deltaTime) {
|
||||
m_NextWaypoint = GetCurrentWaypoint();
|
||||
|
||||
if (m_NextWaypoint == source) {
|
||||
m_Timer = 0;
|
||||
m_TimeToTravel = 0.0f;
|
||||
|
||||
goto nextAction;
|
||||
}
|
||||
|
||||
if (m_CurrentSpeed < m_Speed) {
|
||||
if (m_CurrentSpeed < m_MaxSpeed) {
|
||||
m_CurrentSpeed += m_Acceleration;
|
||||
}
|
||||
|
||||
if (m_CurrentSpeed > m_Speed) {
|
||||
m_CurrentSpeed = m_Speed;
|
||||
if (m_CurrentSpeed > m_MaxSpeed) {
|
||||
m_CurrentSpeed = m_MaxSpeed;
|
||||
}
|
||||
|
||||
const auto speed = m_CurrentSpeed * m_BaseSpeed;
|
||||
const auto speed = m_CurrentSpeed * m_BaseSpeed; // scale speed based on base speed
|
||||
|
||||
const auto delta = m_NextWaypoint - source;
|
||||
|
||||
// Normalize the vector
|
||||
const auto length = sqrtf(delta.x * delta.x + delta.y * delta.y + delta.z * delta.z);
|
||||
|
||||
const auto length = delta.Length();
|
||||
if (length > 0) {
|
||||
velocity.x = (delta.x / length) * speed;
|
||||
velocity.y = (delta.y / length) * speed;
|
||||
velocity.z = (delta.z / length) * speed;
|
||||
velocity = (delta / length) * speed;
|
||||
}
|
||||
|
||||
// Calclute the time it will take to reach the next waypoint with the current speed
|
||||
m_TotalTime = m_Timer = length / speed;
|
||||
m_TimeTravelled = 0.0f;
|
||||
m_TimeToTravel = length / speed;
|
||||
|
||||
SetRotation(NiQuaternion::LookAt(source, m_NextWaypoint));
|
||||
} else {
|
||||
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
|
||||
if (!m_Queue.empty()) {
|
||||
SetDestination(m_Queue.top());
|
||||
|
||||
m_Queue.pop();
|
||||
} else {
|
||||
// We have reached our final waypoint
|
||||
if (m_CurrentPath.empty()) {
|
||||
Stop();
|
||||
|
||||
return;
|
||||
}
|
||||
SetDestination(m_CurrentPath.top());
|
||||
|
||||
m_CurrentPath.pop();
|
||||
}
|
||||
|
||||
nextAction:
|
||||
|
||||
SetVelocity(velocity);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
const MovementAIInfo& MovementAIComponent::GetInfo() const {
|
||||
@@ -157,7 +145,7 @@ const MovementAIInfo& MovementAIComponent::GetInfo() const {
|
||||
}
|
||||
|
||||
bool MovementAIComponent::AdvanceWaypointIndex() {
|
||||
if (m_PathIndex >= m_CurrentPath.size()) {
|
||||
if (m_PathIndex >= m_InterpolatedWaypoints.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -167,37 +155,19 @@ bool MovementAIComponent::AdvanceWaypointIndex() {
|
||||
}
|
||||
|
||||
NiPoint3 MovementAIComponent::GetCurrentWaypoint() const {
|
||||
if (m_PathIndex >= m_CurrentPath.size()) {
|
||||
return GetCurrentPosition();
|
||||
}
|
||||
|
||||
return m_CurrentPath[m_PathIndex];
|
||||
}
|
||||
|
||||
NiPoint3 MovementAIComponent::GetNextWaypoint() const {
|
||||
return m_NextWaypoint;
|
||||
}
|
||||
|
||||
NiPoint3 MovementAIComponent::GetCurrentPosition() const {
|
||||
return m_Parent->GetPosition();
|
||||
return m_PathIndex >= m_InterpolatedWaypoints.size() ? m_Parent->GetPosition() : m_InterpolatedWaypoints[m_PathIndex];
|
||||
}
|
||||
|
||||
NiPoint3 MovementAIComponent::ApproximateLocation() const {
|
||||
auto source = GetCurrentPosition();
|
||||
auto source = m_Parent->GetPosition();
|
||||
|
||||
if (m_Done) {
|
||||
return source;
|
||||
}
|
||||
if (AtFinalWaypoint()) return source;
|
||||
|
||||
auto destination = m_NextWaypoint;
|
||||
|
||||
auto factor = m_TotalTime > 0 ? (m_TotalTime - m_Timer) / m_TotalTime : 0;
|
||||
auto percentageToWaypoint = m_TimeToTravel > 0 ? m_TimeTravelled / m_TimeToTravel : 0;
|
||||
|
||||
auto x = source.x + factor * (destination.x - source.x);
|
||||
auto y = source.y + factor * (destination.y - source.y);
|
||||
auto z = source.z + factor * (destination.z - source.z);
|
||||
|
||||
NiPoint3 approximation = NiPoint3(x, y, z);
|
||||
auto approximation = source + ((destination - source) * percentageToWaypoint);
|
||||
|
||||
if (dpWorld::Instance().IsLoaded()) {
|
||||
approximation.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(approximation);
|
||||
@@ -221,58 +191,47 @@ bool MovementAIComponent::Warp(const NiPoint3& point) {
|
||||
|
||||
SetPosition(destination);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
float MovementAIComponent::GetTimer() const {
|
||||
return m_Timer;
|
||||
}
|
||||
|
||||
bool MovementAIComponent::AtFinalWaypoint() const {
|
||||
return m_Done;
|
||||
}
|
||||
|
||||
void MovementAIComponent::Stop() {
|
||||
if (m_Done) {
|
||||
return;
|
||||
}
|
||||
if (AtFinalWaypoint()) return;
|
||||
|
||||
SetPosition(ApproximateLocation());
|
||||
|
||||
SetVelocity(NiPoint3::ZERO);
|
||||
|
||||
m_TotalTime = m_Timer = 0;
|
||||
m_TimeToTravel = 0;
|
||||
m_TimeTravelled = 0;
|
||||
|
||||
m_Done = true;
|
||||
m_AtFinalWaypoint = true;
|
||||
|
||||
m_CurrentPath = {};
|
||||
m_InterpolatedWaypoints.clear();
|
||||
while (!m_CurrentPath.empty()) m_CurrentPath.pop();
|
||||
|
||||
m_PathIndex = 0;
|
||||
|
||||
m_CurrentSpeed = 0;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void MovementAIComponent::PullToPoint(const NiPoint3& point) {
|
||||
Stop();
|
||||
|
||||
m_Interrupted = true;
|
||||
m_PullingToPoint = true;
|
||||
m_PullPoint = point;
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetPath(std::vector<NiPoint3> path) {
|
||||
std::reverse(path.begin(), path.end());
|
||||
if (path.empty()) return;
|
||||
std::for_each(path.rbegin(), path.rend() - 1, [this](const NiPoint3& point) {
|
||||
this->m_CurrentPath.push(point);
|
||||
});
|
||||
|
||||
for (const auto& point : path) {
|
||||
m_Queue.push(point);
|
||||
}
|
||||
|
||||
SetDestination(m_Queue.top());
|
||||
|
||||
m_Queue.pop();
|
||||
SetDestination(path.front());
|
||||
}
|
||||
|
||||
float MovementAIComponent::GetBaseSpeed(LOT lot) {
|
||||
@@ -291,26 +250,14 @@ float MovementAIComponent::GetBaseSpeed(LOT lot) {
|
||||
|
||||
componentID = componentRegistryTable->GetByIDAndType(lot, eReplicaComponentType::CONTROLLABLE_PHYSICS, -1);
|
||||
|
||||
if (componentID != -1) {
|
||||
physicsComponent = physicsComponentTable->GetByID(componentID);
|
||||
|
||||
goto foundComponent;
|
||||
if (componentID == -1) {
|
||||
componentID = componentRegistryTable->GetByIDAndType(lot, eReplicaComponentType::SIMPLE_PHYSICS, -1);
|
||||
}
|
||||
|
||||
componentID = componentRegistryTable->GetByIDAndType(lot, eReplicaComponentType::SIMPLE_PHYSICS, -1);
|
||||
|
||||
if (componentID != -1) {
|
||||
physicsComponent = physicsComponentTable->GetByID(componentID);
|
||||
|
||||
goto foundComponent;
|
||||
}
|
||||
|
||||
foundComponent:
|
||||
physicsComponent = physicsComponentTable->GetByID(componentID);
|
||||
|
||||
// Client defaults speed to 10 and if the speed is also null in the table, it defaults to 10.
|
||||
float speed = 10.0f;
|
||||
|
||||
if (physicsComponent) speed = physicsComponent->speed;
|
||||
float speed = physicsComponent != nullptr ? physicsComponent->speed : 10.0f;
|
||||
|
||||
float delta = fabs(speed) - 1.0f;
|
||||
|
||||
@@ -322,39 +269,11 @@ foundComponent:
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetPosition(const NiPoint3& value) {
|
||||
auto* controllablePhysicsComponent = m_Parent->GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
controllablePhysicsComponent->SetPosition(value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto* simplePhysicsComponent = m_Parent->GetComponent<SimplePhysicsComponent>();
|
||||
|
||||
if (simplePhysicsComponent != nullptr) {
|
||||
simplePhysicsComponent->SetPosition(value);
|
||||
}
|
||||
m_Parent->SetPosition(value);
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetRotation(const NiQuaternion& value) {
|
||||
if (m_LockRotation) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* controllablePhysicsComponent = m_Parent->GetComponent<ControllablePhysicsComponent>();
|
||||
|
||||
if (controllablePhysicsComponent != nullptr) {
|
||||
controllablePhysicsComponent->SetRotation(value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
auto* simplePhysicsComponent = m_Parent->GetComponent<SimplePhysicsComponent>();
|
||||
|
||||
if (simplePhysicsComponent != nullptr) {
|
||||
simplePhysicsComponent->SetRotation(value);
|
||||
}
|
||||
if (!m_LockRotation) m_Parent->SetRotation(value);
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetVelocity(const NiPoint3& value) {
|
||||
@@ -373,15 +292,8 @@ void MovementAIComponent::SetVelocity(const NiPoint3& value) {
|
||||
}
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetDestination(const NiPoint3& value) {
|
||||
if (m_Interrupted) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*if (Vector3::DistanceSquared(value, GetDestination()) < 2 * 2)
|
||||
{
|
||||
return;
|
||||
}*/
|
||||
void MovementAIComponent::SetDestination(const NiPoint3& destination) {
|
||||
if (m_PullingToPoint) return;
|
||||
|
||||
const auto location = ApproximateLocation();
|
||||
|
||||
@@ -390,97 +302,53 @@ void MovementAIComponent::SetDestination(const NiPoint3& value) {
|
||||
}
|
||||
|
||||
std::vector<NiPoint3> computedPath;
|
||||
|
||||
if (dpWorld::Instance().IsLoaded()) {
|
||||
computedPath = dpWorld::Instance().GetNavMesh()->GetPath(GetCurrentPosition(), value, m_Info.wanderSpeed);
|
||||
} else {
|
||||
computedPath = dpWorld::Instance().GetNavMesh()->GetPath(m_Parent->GetPosition(), destination, m_Info.wanderSpeed);
|
||||
}
|
||||
|
||||
// Somehow failed
|
||||
if (computedPath.empty()) {
|
||||
// Than take 10 points between the current position and the destination and make that the path
|
||||
|
||||
auto point = location;
|
||||
auto start = location;
|
||||
|
||||
auto delta = value - point;
|
||||
auto delta = destination - start;
|
||||
|
||||
auto step = delta / 10;
|
||||
auto step = delta / 10.0f;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
point = point + step;
|
||||
// TODO: Replace this with += when the NiPoint3::operator+= is fixed
|
||||
start = start + step;
|
||||
|
||||
computedPath.push_back(point);
|
||||
computedPath.push_back(start);
|
||||
}
|
||||
}
|
||||
|
||||
if (computedPath.empty()) // Somehow failed
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_CurrentPath.clear();
|
||||
|
||||
m_CurrentPath.push_back(location);
|
||||
m_InterpolatedWaypoints.clear();
|
||||
|
||||
// Simply path
|
||||
for (auto point : computedPath) {
|
||||
for (auto& point : computedPath) {
|
||||
if (dpWorld::Instance().IsLoaded()) {
|
||||
point.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(point);
|
||||
}
|
||||
|
||||
m_CurrentPath.push_back(point);
|
||||
m_InterpolatedWaypoints.push_back(point);
|
||||
}
|
||||
|
||||
m_CurrentPath.push_back(computedPath[computedPath.size() - 1]);
|
||||
|
||||
m_PathIndex = 0;
|
||||
|
||||
m_TotalTime = m_Timer = 0;
|
||||
m_TimeTravelled = 0;
|
||||
m_TimeToTravel = 0;
|
||||
|
||||
m_Done = false;
|
||||
m_AtFinalWaypoint = false;
|
||||
}
|
||||
|
||||
NiPoint3 MovementAIComponent::GetDestination() const {
|
||||
if (m_CurrentPath.empty()) {
|
||||
return GetCurrentPosition();
|
||||
}
|
||||
|
||||
return m_CurrentPath[m_CurrentPath.size() - 1];
|
||||
return m_InterpolatedWaypoints.empty() ? m_Parent->GetPosition() : m_InterpolatedWaypoints.back();
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetSpeed(const float value) {
|
||||
m_Speed = value;
|
||||
void MovementAIComponent::SetMaxSpeed(const float value) {
|
||||
if (value == m_MaxSpeed) return;
|
||||
m_MaxSpeed = value;
|
||||
m_Acceleration = value / 5;
|
||||
}
|
||||
|
||||
float MovementAIComponent::GetSpeed() const {
|
||||
return m_Speed;
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetAcceleration(const float value) {
|
||||
m_Acceleration = value;
|
||||
}
|
||||
|
||||
float MovementAIComponent::GetAcceleration() const {
|
||||
return m_Acceleration;
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetHaltDistance(const float value) {
|
||||
m_HaltDistance = value;
|
||||
}
|
||||
|
||||
float MovementAIComponent::GetHaltDistance() const {
|
||||
return m_HaltDistance;
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetCurrentSpeed(float value) {
|
||||
m_CurrentSpeed = value;
|
||||
}
|
||||
|
||||
float MovementAIComponent::GetCurrentSpeed() const {
|
||||
return m_CurrentSpeed;
|
||||
}
|
||||
|
||||
void MovementAIComponent::SetLockRotation(bool value) {
|
||||
m_LockRotation = value;
|
||||
}
|
||||
|
||||
bool MovementAIComponent::GetLockRotation() const {
|
||||
return m_LockRotation;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Darkflame Universe
|
||||
* Copyright 2018
|
||||
* Copyright 2023
|
||||
*/
|
||||
|
||||
#ifndef MOVEMENTAICOMPONENT_H
|
||||
@@ -60,7 +60,6 @@ public:
|
||||
static const eReplicaComponentType ComponentType = eReplicaComponentType::MOVEMENT_AI;
|
||||
|
||||
MovementAIComponent(Entity* parentEntity, MovementAIInfo info);
|
||||
~MovementAIComponent() override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
@@ -86,61 +85,55 @@ public:
|
||||
* Sets the max speed at which this entity may run
|
||||
* @param value the speed value to set
|
||||
*/
|
||||
void SetSpeed(float value);
|
||||
|
||||
/**
|
||||
* Returns the max speed at which this entity may run
|
||||
* @return the max speed at which this entity may run
|
||||
*/
|
||||
float GetSpeed() const;
|
||||
void SetMaxSpeed(float value);
|
||||
|
||||
/**
|
||||
* Sets how fast the entity will accelerate when not running at full speed
|
||||
* @param value the acceleration to set
|
||||
*/
|
||||
void SetAcceleration(float value);
|
||||
void SetAcceleration(float value) { m_Acceleration = value; };
|
||||
|
||||
/**
|
||||
* Returns the current speed at which this entity accelerates when not running at full speed
|
||||
* @return the current speed at which this entity accelerates when not running at full speed
|
||||
*/
|
||||
float GetAcceleration() const;
|
||||
float GetAcceleration() const { return m_Acceleration; };
|
||||
|
||||
/**
|
||||
* Sets the halting distance (the distance at which we consider the target to be reached)
|
||||
* @param value the halting distance to set
|
||||
*/
|
||||
void SetHaltDistance(float value);
|
||||
void SetHaltDistance(float value) { m_HaltDistance = value; }
|
||||
|
||||
/**
|
||||
* Returns the current halting distance (the distance at which we consider the target to be reached)
|
||||
* @return the current halting distance
|
||||
*/
|
||||
float GetHaltDistance() const;
|
||||
float GetHaltDistance() const { return m_HaltDistance; }
|
||||
|
||||
/**
|
||||
* Sets the speed the entity is currently running at
|
||||
* @param value the speed value to set
|
||||
*/
|
||||
void SetCurrentSpeed(float value);
|
||||
void SetCurrentSpeed(float value) { m_CurrentSpeed = value; }
|
||||
|
||||
/**
|
||||
* Returns the speed the entity is currently running at
|
||||
* @return the speed the entity is currently running at
|
||||
*/
|
||||
float GetCurrentSpeed() const;
|
||||
float GetCurrentSpeed() const { return m_CurrentSpeed; }
|
||||
|
||||
/**
|
||||
* Locks the rotation of this entity in place, depending on the argument
|
||||
* @param value if true, the entity will be rotationally locked
|
||||
*/
|
||||
void SetLockRotation(bool value);
|
||||
void SetLockRotation(bool value) { m_LockRotation = value; }
|
||||
|
||||
/**
|
||||
* Returns whether this entity is currently rotationally locked
|
||||
* @return true if the entity is rotationally locked, false otherwise
|
||||
*/
|
||||
bool GetLockRotation() const;
|
||||
bool GetLockRotation() const { return m_LockRotation; };
|
||||
|
||||
/**
|
||||
* Attempts to update the waypoint index, making the entity move to the next waypoint
|
||||
@@ -158,13 +151,7 @@ public:
|
||||
* Returns the waypoint this entity is supposed to move towards next
|
||||
* @return the waypoint this entity is supposed to move towards next
|
||||
*/
|
||||
NiPoint3 GetNextWaypoint() const;
|
||||
|
||||
/**
|
||||
* Returns the current position of this entity
|
||||
* @return the current position of this entity
|
||||
*/
|
||||
NiPoint3 GetCurrentPosition() const;
|
||||
NiPoint3 GetNextWaypoint() const { return m_NextWaypoint; }
|
||||
|
||||
/**
|
||||
* Returns the approximate current location of the entity, including y coordinates
|
||||
@@ -180,17 +167,11 @@ public:
|
||||
*/
|
||||
bool Warp(const NiPoint3& point);
|
||||
|
||||
/**
|
||||
* Returns the time it will take to reach the final waypoint according to the current speed
|
||||
* @return the time it will take to reach the final waypoint according to the current speed
|
||||
*/
|
||||
float GetTimer() const;
|
||||
|
||||
/**
|
||||
* Returns if the entity is at its final waypoint
|
||||
* @return if the entity is at its final waypoint
|
||||
*/
|
||||
bool AtFinalWaypoint() const;
|
||||
bool AtFinalWaypoint() const { return m_AtFinalWaypoint; }
|
||||
|
||||
/**
|
||||
* Renders the entity stationary
|
||||
@@ -250,17 +231,12 @@ private:
|
||||
/**
|
||||
* The max speed this entity may move at
|
||||
*/
|
||||
float m_Speed;
|
||||
float m_MaxSpeed;
|
||||
|
||||
/**
|
||||
* The time it will take to reach the next waypoint using the current speed
|
||||
*/
|
||||
float m_Timer;
|
||||
|
||||
/**
|
||||
* The total time it will take to reach the waypoint form its starting point
|
||||
*/
|
||||
float m_TotalTime;
|
||||
float m_TimeTravelled;
|
||||
|
||||
/**
|
||||
* The path this entity is currently traversing
|
||||
@@ -270,7 +246,7 @@ private:
|
||||
/**
|
||||
* If the entity has reached it last waypoint
|
||||
*/
|
||||
bool m_Done;
|
||||
bool m_AtFinalWaypoint;
|
||||
|
||||
/**
|
||||
* The speed the entity is currently moving at
|
||||
@@ -287,6 +263,11 @@ private:
|
||||
*/
|
||||
float m_HaltDistance;
|
||||
|
||||
/**
|
||||
* The total time it will take to reach the waypoint form its starting point
|
||||
*/
|
||||
float m_TimeToTravel;
|
||||
|
||||
/**
|
||||
* The base speed this entity has
|
||||
*/
|
||||
@@ -295,7 +276,7 @@ private:
|
||||
/**
|
||||
* If the AI is currently turned of (e.g. when teleporting to some location)
|
||||
*/
|
||||
bool m_Interrupted;
|
||||
bool m_PullingToPoint;
|
||||
|
||||
/**
|
||||
* A position that the entity is currently moving towards while being interrupted
|
||||
@@ -315,17 +296,12 @@ private:
|
||||
/**
|
||||
* The path the entity is currently following
|
||||
*/
|
||||
std::vector<NiPoint3> m_CurrentPath;
|
||||
std::vector<NiPoint3> m_InterpolatedWaypoints;
|
||||
|
||||
/**
|
||||
* Queue of positions to traverse
|
||||
* The path from the current position to the destination.
|
||||
*/
|
||||
std::stack<NiPoint3> m_Queue;
|
||||
|
||||
/**
|
||||
* Cache of all lots and their respective speeds
|
||||
*/
|
||||
static std::map<LOT, float> m_PhysicsSpeedCache;
|
||||
std::stack<NiPoint3> m_CurrentPath;
|
||||
};
|
||||
|
||||
#endif // MOVEMENTAICOMPONENT_H
|
||||
|
||||
@@ -32,7 +32,7 @@ MoverSubComponent::MoverSubComponent(const NiPoint3& startPos) {
|
||||
|
||||
MoverSubComponent::~MoverSubComponent() = default;
|
||||
|
||||
void MoverSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) const {
|
||||
void MoverSubComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write<bool>(true);
|
||||
|
||||
outBitStream->Write<uint32_t>(static_cast<uint32_t>(mState));
|
||||
@@ -59,7 +59,7 @@ MovingPlatformComponent::MovingPlatformComponent(Entity* parent, const std::stri
|
||||
m_MoverSubComponentType = eMoverSubComponentType::mover;
|
||||
m_MoverSubComponent = new MoverSubComponent(m_Parent->GetDefaultPosition());
|
||||
m_PathName = GeneralUtils::ASCIIToUTF16(pathName);
|
||||
m_Path = dZoneManager::Instance()->GetZone()->GetPath(pathName);
|
||||
m_Path = Game::zoneManager->GetZone()->GetPath(pathName);
|
||||
m_NoAutoStart = false;
|
||||
|
||||
if (m_Path == nullptr) {
|
||||
@@ -71,7 +71,7 @@ MovingPlatformComponent::~MovingPlatformComponent() {
|
||||
delete static_cast<MoverSubComponent*>(m_MoverSubComponent);
|
||||
}
|
||||
|
||||
void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
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) {
|
||||
@@ -112,7 +112,7 @@ void MovingPlatformComponent::Serialize(RakNet::BitStream* outBitStream, bool bI
|
||||
if (m_MoverSubComponentType == eMoverSubComponentType::simpleMover) {
|
||||
// TODO
|
||||
} else {
|
||||
mover->Serialize(outBitStream, bIsInitialUpdate, flags);
|
||||
mover->Serialize(outBitStream, bIsInitialUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ void MovingPlatformComponent::SetMovementState(eMovementPlatformState value) {
|
||||
|
||||
subComponent->mState = value;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void MovingPlatformComponent::GotoWaypoint(uint32_t index, bool stopAtWaypoint) {
|
||||
@@ -194,7 +194,7 @@ void MovingPlatformComponent::StartPathing() {
|
||||
|
||||
//GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void MovingPlatformComponent::ContinuePathing() {
|
||||
@@ -242,7 +242,7 @@ void MovingPlatformComponent::ContinuePathing() {
|
||||
subComponent->mCurrentWaypointIndex = pathSize;
|
||||
switch (behavior) {
|
||||
case PathBehavior::Once:
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
return;
|
||||
|
||||
case PathBehavior::Bounce:
|
||||
@@ -304,7 +304,7 @@ void MovingPlatformComponent::ContinuePathing() {
|
||||
ContinuePathing();
|
||||
});
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void MovingPlatformComponent::StopPathing() {
|
||||
@@ -318,7 +318,7 @@ void MovingPlatformComponent::StopPathing() {
|
||||
subComponent->mDesiredWaypointIndex = -1;
|
||||
subComponent->mShouldStopAtDesiredWaypoint = false;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
//GameMessages::SendPlatformResync(m_Parent, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
@@ -341,7 +341,7 @@ void MovingPlatformComponent::WarpToWaypoint(size_t index) {
|
||||
m_Parent->SetPosition(waypoint.position);
|
||||
m_Parent->SetRotation(waypoint.rotation);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
size_t MovingPlatformComponent::GetLastWaypointIndex() const {
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
MoverSubComponent(const NiPoint3& startPos);
|
||||
~MoverSubComponent();
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) const;
|
||||
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, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Stops all pathing, called when an entity starts a quick build associated with this platform
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "RocketLaunchLupComponent.h"
|
||||
#include "MultiZoneEntranceComponent.h"
|
||||
#include "RocketLaunchpadControlComponent.h"
|
||||
#include "InventoryComponent.h"
|
||||
#include "CharacterComponent.h"
|
||||
|
||||
RocketLaunchLupComponent::RocketLaunchLupComponent(Entity* parent) : Component(parent) {
|
||||
MultiZoneEntranceComponent::MultiZoneEntranceComponent(Entity* parent) : Component(parent) {
|
||||
m_Parent = parent;
|
||||
std::string zoneString = GeneralUtils::UTF16ToWTF8(m_Parent->GetVar<std::u16string>(u"MultiZoneIDs"));
|
||||
std::stringstream ss(zoneString);
|
||||
@@ -14,17 +14,17 @@ RocketLaunchLupComponent::RocketLaunchLupComponent(Entity* parent) : Component(p
|
||||
}
|
||||
}
|
||||
|
||||
RocketLaunchLupComponent::~RocketLaunchLupComponent() {}
|
||||
MultiZoneEntranceComponent::~MultiZoneEntranceComponent() {}
|
||||
|
||||
void RocketLaunchLupComponent::OnUse(Entity* originator) {
|
||||
void MultiZoneEntranceComponent::OnUse(Entity* originator) {
|
||||
auto* rocket = originator->GetComponent<CharacterComponent>()->RocketEquip(originator);
|
||||
if (!rocket) return;
|
||||
|
||||
// the LUP world menu is just the property menu, the client knows how to handle it
|
||||
GameMessages::SendPropertyEntranceBegin(m_Parent->GetObjectID(), m_Parent->GetSystemAddress());
|
||||
GameMessages::SendPropertyEntranceBegin(m_Parent->GetObjectID(), originator->GetSystemAddress());
|
||||
}
|
||||
|
||||
void RocketLaunchLupComponent::OnSelectWorld(Entity* originator, uint32_t index) {
|
||||
void MultiZoneEntranceComponent::OnSelectWorld(Entity* originator, uint32_t index) {
|
||||
auto* rocketLaunchpadControlComponent = m_Parent->GetComponent<RocketLaunchpadControlComponent>();
|
||||
if (!rocketLaunchpadControlComponent) return;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Entity.h"
|
||||
#include "GameMessages.h"
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
@@ -9,16 +8,16 @@
|
||||
* Component that handles the LUP/WBL rocket launchpad that can be interacted with to travel to WBL worlds.
|
||||
*
|
||||
*/
|
||||
class RocketLaunchLupComponent : public Component {
|
||||
class MultiZoneEntranceComponent : public Component {
|
||||
public:
|
||||
static const eReplicaComponentType ComponentType = eReplicaComponentType::ROCKET_LAUNCH_LUP;
|
||||
static const eReplicaComponentType ComponentType = eReplicaComponentType::MULTI_ZONE_ENTRANCE;
|
||||
|
||||
/**
|
||||
* Constructor for this component, builds the m_LUPWorlds vector
|
||||
* @param parent parent that contains this component
|
||||
*/
|
||||
RocketLaunchLupComponent(Entity* parent);
|
||||
~RocketLaunchLupComponent() override;
|
||||
MultiZoneEntranceComponent(Entity* parent);
|
||||
~MultiZoneEntranceComponent() override;
|
||||
|
||||
/**
|
||||
* Handles an OnUse event from some entity, preparing it for launch to some other world
|
||||
@@ -107,7 +107,7 @@ PetComponent::PetComponent(Entity* parent, uint32_t componentId): Component(pare
|
||||
result.finalize();
|
||||
}
|
||||
|
||||
void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void PetComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
const bool tamed = m_Owner != LWOOBJID_EMPTY;
|
||||
|
||||
outBitStream->Write1(); // Always serialize as dirty for now
|
||||
@@ -154,7 +154,7 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
}
|
||||
|
||||
if (m_Tamer != LWOOBJID_EMPTY) {
|
||||
auto* tamer = EntityManager::Instance()->GetEntity(m_Tamer);
|
||||
auto* tamer = Game::entityManager->GetEntity(m_Tamer);
|
||||
|
||||
if (tamer != nullptr) {
|
||||
return;
|
||||
@@ -236,7 +236,7 @@ void PetComponent::OnUse(Entity* originator) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& bricks = BrickDatabase::Instance()->GetBricks(buildFile);
|
||||
const auto& bricks = BrickDatabase::GetBricks(buildFile);
|
||||
|
||||
if (bricks.empty()) {
|
||||
ChatPackets::SendSystemMessage(originator->GetSystemAddress(), u"Failed to load the puzzle minigame for this pet.");
|
||||
@@ -344,7 +344,7 @@ void PetComponent::Update(float deltaTime) {
|
||||
|
||||
if (m_Timer <= 0) {
|
||||
Wander();
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
} else {
|
||||
m_Timer = 5;
|
||||
@@ -369,7 +369,7 @@ void PetComponent::Update(float deltaTime) {
|
||||
}
|
||||
|
||||
if (m_TresureTime > 0) {
|
||||
auto* tresure = EntityManager::Instance()->GetEntity(m_Interaction);
|
||||
auto* tresure = Game::entityManager->GetEntity(m_Interaction);
|
||||
|
||||
if (tresure == nullptr) {
|
||||
m_TresureTime = 0;
|
||||
@@ -395,7 +395,7 @@ void PetComponent::Update(float deltaTime) {
|
||||
}
|
||||
|
||||
auto destination = owner->GetPosition();
|
||||
NiPoint3 position = m_MovementAI->GetCurrentPosition();
|
||||
NiPoint3 position = m_MovementAI->GetParent()->GetPosition();
|
||||
|
||||
float distanceToOwner = Vector3::DistanceSquared(position, destination);
|
||||
|
||||
@@ -449,7 +449,7 @@ void PetComponent::Update(float deltaTime) {
|
||||
|
||||
NiPoint3 tresurePosition = closestTresure->GetPosition();
|
||||
float distance = Vector3::DistanceSquared(position, tresurePosition);
|
||||
if (distance < 3 * 3) {
|
||||
if (distance < 5 * 5) {
|
||||
m_Interaction = closestTresure->GetObjectID();
|
||||
|
||||
Command(NiPoint3::ZERO, LWOOBJID_EMPTY, 1, 202, true);
|
||||
@@ -466,7 +466,7 @@ skipTresure:
|
||||
|
||||
m_MovementAI->SetHaltDistance(haltDistance);
|
||||
|
||||
m_MovementAI->SetSpeed(2.5f);
|
||||
m_MovementAI->SetMaxSpeed(2.5f);
|
||||
|
||||
m_MovementAI->SetDestination(destination);
|
||||
|
||||
@@ -476,7 +476,7 @@ skipTresure:
|
||||
void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
|
||||
if (m_Tamer == LWOOBJID_EMPTY) return;
|
||||
|
||||
auto* tamer = EntityManager::Instance()->GetEntity(m_Tamer);
|
||||
auto* tamer = Game::entityManager->GetEntity(m_Tamer);
|
||||
|
||||
if (tamer == nullptr) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
@@ -498,7 +498,7 @@ void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
|
||||
|
||||
destroyableComponent->SetImagination(imagination);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(tamer);
|
||||
Game::entityManager->SerializeEntity(tamer);
|
||||
|
||||
if (clientFailed) {
|
||||
if (imagination < cached->second.imaginationCost) {
|
||||
@@ -516,7 +516,7 @@ void PetComponent::TryBuild(uint32_t numBricks, bool clientFailed) {
|
||||
void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
|
||||
if (m_Tamer == LWOOBJID_EMPTY) return;
|
||||
|
||||
auto* tamer = EntityManager::Instance()->GetEntity(m_Tamer);
|
||||
auto* tamer = Game::entityManager->GetEntity(m_Tamer);
|
||||
|
||||
if (tamer == nullptr) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
@@ -539,11 +539,11 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) {
|
||||
info.rot = NiQuaternion::IDENTITY;
|
||||
info.spawnerID = tamer->GetObjectID();
|
||||
|
||||
auto* modelEntity = EntityManager::Instance()->CreateEntity(info);
|
||||
auto* modelEntity = Game::entityManager->CreateEntity(info);
|
||||
|
||||
m_ModelId = modelEntity->GetObjectID();
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(modelEntity);
|
||||
Game::entityManager->ConstructEntity(modelEntity);
|
||||
|
||||
GameMessages::SendNotifyTamingModelLoadedOnServer(m_Tamer, tamer->GetSystemAddress());
|
||||
|
||||
@@ -639,7 +639,7 @@ void PetComponent::RequestSetPetName(std::u16string name) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* tamer = EntityManager::Instance()->GetEntity(m_Tamer);
|
||||
auto* tamer = Game::entityManager->GetEntity(m_Tamer);
|
||||
|
||||
if (tamer == nullptr) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
@@ -661,7 +661,7 @@ void PetComponent::RequestSetPetName(std::u16string name) {
|
||||
//Save our pet's new name to the db:
|
||||
SetPetNameForModeration(GeneralUtils::UTF16ToWTF8(name));
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
std::u16string u16name = GeneralUtils::UTF8ToUTF16(m_Name);
|
||||
std::u16string u16ownerName = GeneralUtils::UTF8ToUTF16(m_OwnerName);
|
||||
@@ -684,7 +684,7 @@ void PetComponent::RequestSetPetName(std::u16string name) {
|
||||
|
||||
GameMessages::SendTerminateInteraction(m_Tamer, eTerminateType::FROM_INTERACTION, m_Parent->GetObjectID());
|
||||
|
||||
auto* modelEntity = EntityManager::Instance()->GetEntity(m_ModelId);
|
||||
auto* modelEntity = Game::entityManager->GetEntity(m_ModelId);
|
||||
|
||||
if (modelEntity != nullptr) {
|
||||
modelEntity->Smash(m_Tamer);
|
||||
@@ -703,7 +703,7 @@ void PetComponent::RequestSetPetName(std::u16string name) {
|
||||
void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
|
||||
if (m_Tamer == LWOOBJID_EMPTY) return;
|
||||
|
||||
auto* tamer = EntityManager::Instance()->GetEntity(m_Tamer);
|
||||
auto* tamer = Game::entityManager->GetEntity(m_Tamer);
|
||||
|
||||
if (tamer == nullptr) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
@@ -733,7 +733,7 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
m_Timer = 0;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Notify the end of a pet taming minigame
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
@@ -754,7 +754,7 @@ void PetComponent::StartTimer() {
|
||||
void PetComponent::ClientFailTamingMinigame() {
|
||||
if (m_Tamer == LWOOBJID_EMPTY) return;
|
||||
|
||||
auto* tamer = EntityManager::Instance()->GetEntity(m_Tamer);
|
||||
auto* tamer = Game::entityManager->GetEntity(m_Tamer);
|
||||
|
||||
if (tamer == nullptr) {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
@@ -784,7 +784,7 @@ void PetComponent::ClientFailTamingMinigame() {
|
||||
m_Tamer = LWOOBJID_EMPTY;
|
||||
m_Timer = 0;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Notify the end of a pet taming minigame
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_Parent)) {
|
||||
@@ -822,17 +822,17 @@ void PetComponent::Wander() {
|
||||
destination.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(destination);
|
||||
}
|
||||
|
||||
if (Vector3::DistanceSquared(destination, m_MovementAI->GetCurrentPosition()) < 2 * 2) {
|
||||
if (Vector3::DistanceSquared(destination, m_MovementAI->GetParent()->GetPosition()) < 2 * 2) {
|
||||
m_MovementAI->Stop();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_MovementAI->SetSpeed(info.wanderSpeed);
|
||||
m_MovementAI->SetMaxSpeed(info.wanderSpeed);
|
||||
|
||||
m_MovementAI->SetDestination(destination);
|
||||
|
||||
m_Timer += (m_MovementAI->GetCurrentPosition().x - destination.x) / info.wanderSpeed;
|
||||
m_Timer += (m_MovementAI->GetParent()->GetPosition().x - destination.x) / info.wanderSpeed;
|
||||
}
|
||||
|
||||
void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) {
|
||||
@@ -887,7 +887,7 @@ void PetComponent::Activate(Item* item, bool registerPet, bool fromTaming) {
|
||||
|
||||
m_Timer = 3;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
owner->GetCharacter()->SetPlayerFlag(ePlayerFlag::FIRST_MANUAL_PET_HIBERNATE, true);
|
||||
|
||||
@@ -1004,7 +1004,7 @@ LWOOBJID PetComponent::GetOwnerId() const {
|
||||
}
|
||||
|
||||
Entity* PetComponent::GetOwner() const {
|
||||
return EntityManager::Instance()->GetEntity(m_Owner);
|
||||
return Game::entityManager->GetEntity(m_Owner);
|
||||
}
|
||||
|
||||
LWOOBJID PetComponent::GetDatabaseId() const {
|
||||
@@ -1046,7 +1046,7 @@ PetComponent* PetComponent::GetTamingPet(LWOOBJID tamer) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(pair->second);
|
||||
auto* entity = Game::entityManager->GetEntity(pair->second);
|
||||
|
||||
if (entity == nullptr) {
|
||||
currentActivities.erase(tamer);
|
||||
@@ -1064,7 +1064,7 @@ PetComponent* PetComponent::GetActivePet(LWOOBJID owner) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(pair->second);
|
||||
auto* entity = Game::entityManager->GetEntity(pair->second);
|
||||
|
||||
if (entity == nullptr) {
|
||||
activePets.erase(owner);
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
explicit PetComponent(Entity* parentEntity, uint32_t componentId);
|
||||
~PetComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
/**
|
||||
|
||||
@@ -306,7 +306,7 @@ void PhantomPhysicsComponent::CreatePhysics() {
|
||||
m_HasCreatedPhysics = true;
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void PhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_PositionInfoDirty || bIsInitialUpdate);
|
||||
if (m_PositionInfoDirty || bIsInitialUpdate) {
|
||||
outBitStream->Write(m_Position.x);
|
||||
@@ -348,11 +348,6 @@ void PhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bI
|
||||
}
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::ResetFlags() {
|
||||
m_EffectInfoDirty = false;
|
||||
m_PositionInfoDirty = false;
|
||||
}
|
||||
|
||||
void PhantomPhysicsComponent::Update(float deltaTime) {
|
||||
if (!m_dpEntity) return;
|
||||
|
||||
@@ -362,7 +357,7 @@ void PhantomPhysicsComponent::Update(float deltaTime) {
|
||||
|
||||
//If we are a respawn volume, inform the client:
|
||||
if (m_IsRespawnVolume) {
|
||||
auto entity = EntityManager::Instance()->GetEntity(en->GetObjectID());
|
||||
auto entity = Game::entityManager->GetEntity(en->GetObjectID());
|
||||
|
||||
if (entity) {
|
||||
GameMessages::SendPlayerReachedRespawnCheckpoint(entity, m_RespawnPos, m_RespawnRot);
|
||||
@@ -403,8 +398,8 @@ void PhantomPhysicsComponent::SpawnVertices() {
|
||||
info.spawnerID = m_Parent->GetObjectID();
|
||||
info.spawnerNodeID = 0;
|
||||
|
||||
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
|
||||
EntityManager::Instance()->ConstructEntity(newEntity);
|
||||
Entity* newEntity = Game::entityManager->CreateEntity(info, nullptr);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ public:
|
||||
PhantomPhysicsComponent(Entity* parent);
|
||||
~PhantomPhysicsComponent() override;
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void ResetFlags();
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Creates the physics shape for this entity based on LDF data
|
||||
|
||||
@@ -6,7 +6,7 @@ PlayerForcedMovementComponent::PlayerForcedMovementComponent(Entity* parent) : C
|
||||
|
||||
PlayerForcedMovementComponent::~PlayerForcedMovementComponent() {}
|
||||
|
||||
void PlayerForcedMovementComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void PlayerForcedMovementComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_DirtyInfo || bIsInitialUpdate);
|
||||
if (m_DirtyInfo || bIsInitialUpdate) {
|
||||
outBitStream->Write(m_PlayerOnRail);
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
PlayerForcedMovementComponent(Entity* parent);
|
||||
~PlayerForcedMovementComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* @brief Set the Player On Rail object
|
||||
|
||||
@@ -27,7 +27,7 @@ PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId)
|
||||
result.finalize();
|
||||
}
|
||||
|
||||
void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_DirtyPossessable || bIsInitialUpdate);
|
||||
if (m_DirtyPossessable || bIsInitialUpdate) {
|
||||
m_DirtyPossessable = false; // reset flag
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
PossessableComponent(Entity* parentEntity, uint32_t componentId);
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* @brief mounts the Entity
|
||||
|
||||
@@ -13,7 +13,7 @@ PossessorComponent::PossessorComponent(Entity* parent) : Component(parent) {
|
||||
|
||||
PossessorComponent::~PossessorComponent() {
|
||||
if (m_Possessable != LWOOBJID_EMPTY) {
|
||||
auto* mount = EntityManager::Instance()->GetEntity(m_Possessable);
|
||||
auto* mount = Game::entityManager->GetEntity(m_Possessable);
|
||||
if (mount) {
|
||||
auto* possessable = mount->GetComponent<PossessableComponent>();
|
||||
if (possessable) {
|
||||
@@ -26,7 +26,7 @@ PossessorComponent::~PossessorComponent() {
|
||||
}
|
||||
}
|
||||
|
||||
void PossessorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void PossessorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate);
|
||||
if (m_DirtyPossesor || bIsInitialUpdate) {
|
||||
m_DirtyPossesor = false;
|
||||
@@ -58,8 +58,8 @@ void PossessorComponent::Mount(Entity* mount) {
|
||||
GameMessages::SendVehicleUnlockInput(mount->GetObjectID(), false, m_Parent->GetSystemAddress());
|
||||
GameMessages::SendSetStunned(m_Parent->GetObjectID(), eStateChangeType::PUSH, m_Parent->GetSystemAddress(), LWOOBJID_EMPTY, true, false, true, false, false, false, false, true, true, true, true, true, true, true, true, true);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
EntityManager::Instance()->SerializeEntity(mount);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(mount);
|
||||
}
|
||||
|
||||
void PossessorComponent::Dismount(Entity* mount, bool forceDismount) {
|
||||
@@ -73,8 +73,8 @@ void PossessorComponent::Dismount(Entity* mount, bool forceDismount) {
|
||||
possessableComponent->SetPossessor(LWOOBJID_EMPTY);
|
||||
if (forceDismount) possessableComponent->ForceDepossess();
|
||||
}
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
EntityManager::Instance()->SerializeEntity(mount);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(mount);
|
||||
|
||||
auto characterComponent = m_Parent->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SetIsRacing(false);
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
PossessorComponent(Entity* parent);
|
||||
~PossessorComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* @brief Mounts the entity
|
||||
|
||||
@@ -38,7 +38,7 @@ PropertyManagementComponent::PropertyManagementComponent(Entity* parent) : Compo
|
||||
|
||||
instance = this;
|
||||
|
||||
const auto& worldId = dZoneManager::Instance()->GetZone()->GetZoneID();
|
||||
const auto& worldId = Game::zoneManager->GetZone()->GetZoneID();
|
||||
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
@@ -90,7 +90,7 @@ LWOOBJID PropertyManagementComponent::GetOwnerId() const {
|
||||
}
|
||||
|
||||
Entity* PropertyManagementComponent::GetOwner() const {
|
||||
return EntityManager::Instance()->GetEntity(owner);
|
||||
return Game::entityManager->GetEntity(owner);
|
||||
}
|
||||
|
||||
void PropertyManagementComponent::SetOwner(Entity* value) {
|
||||
@@ -98,7 +98,7 @@ void PropertyManagementComponent::SetOwner(Entity* value) {
|
||||
}
|
||||
|
||||
std::vector<NiPoint3> PropertyManagementComponent::GetPaths() const {
|
||||
const auto zoneId = dZoneManager::Instance()->GetZone()->GetWorldID();
|
||||
const auto zoneId = Game::zoneManager->GetZone()->GetWorldID();
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT path FROM PropertyTemplate WHERE mapID = ?;");
|
||||
@@ -185,14 +185,14 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(playerId);
|
||||
auto* entity = Game::entityManager->GetEntity(playerId);
|
||||
|
||||
auto* user = entity->GetParentUser();
|
||||
|
||||
auto character = entity->GetCharacter();
|
||||
if (!character) return false;
|
||||
|
||||
auto* zone = dZoneManager::Instance()->GetZone();
|
||||
auto* zone = Game::zoneManager->GetZone();
|
||||
|
||||
const auto& worldId = zone->GetZoneID();
|
||||
const auto propertyZoneId = worldId.GetMapID();
|
||||
@@ -240,7 +240,7 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto* zoneControlObject = dZoneManager::Instance()->GetZoneControlObject();
|
||||
auto* zoneControlObject = Game::zoneManager->GetZoneControlObject();
|
||||
for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControlObject)) {
|
||||
script->OnZonePropertyRented(zoneControlObject, entity);
|
||||
}
|
||||
@@ -256,7 +256,7 @@ void PropertyManagementComponent::OnStartBuilding() {
|
||||
|
||||
LWOMAPID zoneId = 1100;
|
||||
|
||||
const auto entrance = EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::PROPERTY_ENTRANCE);
|
||||
const auto entrance = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::PROPERTY_ENTRANCE);
|
||||
|
||||
originalPrivacyOption = privacyOption;
|
||||
|
||||
@@ -339,9 +339,9 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
info.settings.push_back(setting->Copy());
|
||||
}
|
||||
|
||||
Entity* newEntity = EntityManager::Instance()->CreateEntity(info);
|
||||
Entity* newEntity = Game::entityManager->CreateEntity(info);
|
||||
if (newEntity != nullptr) {
|
||||
EntityManager::Instance()->ConstructEntity(newEntity);
|
||||
Game::entityManager->ConstructEntity(newEntity);
|
||||
|
||||
// Make sure the propMgmt doesn't delete our model after the server dies
|
||||
// Trying to do this after the entity is constructed. Shouldn't really change anything but
|
||||
@@ -371,14 +371,14 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
info.respawnTime = 10;
|
||||
|
||||
info.emulated = true;
|
||||
info.emulator = EntityManager::Instance()->GetZoneControlEntity()->GetObjectID();
|
||||
info.emulator = Game::entityManager->GetZoneControlEntity()->GetObjectID();
|
||||
|
||||
info.spawnerID = persistentId;
|
||||
GeneralUtils::SetBit(info.spawnerID, eObjectBits::CLIENT);
|
||||
|
||||
const auto spawnerId = dZoneManager::Instance()->MakeSpawner(info);
|
||||
const auto spawnerId = Game::zoneManager->MakeSpawner(info);
|
||||
|
||||
auto* spawner = dZoneManager::Instance()->GetSpawner(spawnerId);
|
||||
auto* spawner = Game::zoneManager->GetSpawner(spawnerId);
|
||||
|
||||
auto ldfModelBehavior = new LDFData<LWOOBJID>(u"modelBehaviors", 0);
|
||||
auto userModelID = new LDFData<LWOOBJID>(u"userModelID", info.spawnerID);
|
||||
@@ -401,7 +401,7 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N
|
||||
|
||||
GameMessages::SendGetModelsOnProperty(entity->GetObjectID(), GetModels(), UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
EntityManager::Instance()->GetZoneControlEntity()->OnZonePropertyModelPlaced(entity);
|
||||
Game::entityManager->GetZoneControlEntity()->OnZonePropertyModelPlaced(entity);
|
||||
});
|
||||
// Progress place model missions
|
||||
auto missionComponent = entity->GetComponent<MissionComponent>();
|
||||
@@ -433,7 +433,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
|
||||
const auto spawnerId = index->second;
|
||||
|
||||
auto* spawner = dZoneManager::Instance()->GetSpawner(spawnerId);
|
||||
auto* spawner = Game::zoneManager->GetSpawner(spawnerId);
|
||||
|
||||
models.erase(id);
|
||||
|
||||
@@ -441,7 +441,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
Game::logger->Log("PropertyManagementComponent", "Failed to find spawner");
|
||||
}
|
||||
|
||||
auto* model = EntityManager::Instance()->GetEntity(id);
|
||||
auto* model = Game::entityManager->GetEntity(id);
|
||||
|
||||
if (model == nullptr) {
|
||||
Game::logger->Log("PropertyManagementComponent", "Failed to find model entity");
|
||||
@@ -449,7 +449,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager::Instance()->DestructEntity(model);
|
||||
Game::entityManager->DestructEntity(model);
|
||||
|
||||
Game::logger->Log("PropertyManagementComponent", "Deleting model LOT %i", model->GetLOT());
|
||||
|
||||
@@ -496,7 +496,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3::ZERO, LWOOBJID_EMPTY, 16, NiQuaternion::IDENTITY);
|
||||
|
||||
if (spawner != nullptr) {
|
||||
dZoneManager::Instance()->RemoveSpawner(spawner->m_Info.spawnerID);
|
||||
Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID);
|
||||
} else {
|
||||
model->Smash(LWOOBJID_EMPTY, eKillType::SILENT);
|
||||
}
|
||||
@@ -520,13 +520,13 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
item->Equip();
|
||||
|
||||
GameMessages::SendUGCEquipPostDeleteBasedOnEditMode(entity->GetObjectID(), entity->GetSystemAddress(), item->GetId(), item->GetCount());
|
||||
EntityManager::Instance()->GetZoneControlEntity()->OnZonePropertyModelPickedUp(entity);
|
||||
Game::entityManager->GetZoneControlEntity()->OnZonePropertyModelPickedUp(entity);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: // Return to inv
|
||||
{
|
||||
EntityManager::Instance()->GetZoneControlEntity()->OnZonePropertyModelRemoved(entity);
|
||||
Game::entityManager->GetZoneControlEntity()->OnZonePropertyModelRemoved(entity);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -549,7 +549,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet
|
||||
GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3::ZERO, LWOOBJID_EMPTY, 16, NiQuaternion::IDENTITY);
|
||||
|
||||
if (spawner != nullptr) {
|
||||
dZoneManager::Instance()->RemoveSpawner(spawner->m_Info.spawnerID);
|
||||
Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID);
|
||||
} else {
|
||||
model->Smash(LWOOBJID_EMPTY, eKillType::SILENT);
|
||||
}
|
||||
@@ -613,7 +613,7 @@ void PropertyManagementComponent::Load() {
|
||||
info.respawnTime = 10;
|
||||
|
||||
//info.emulated = true;
|
||||
//info.emulator = EntityManager::Instance()->GetZoneControlEntity()->GetObjectID();
|
||||
//info.emulator = Game::entityManager->GetZoneControlEntity()->GetObjectID();
|
||||
|
||||
info.spawnerID = id;
|
||||
|
||||
@@ -652,9 +652,9 @@ void PropertyManagementComponent::Load() {
|
||||
|
||||
node->config = settings;
|
||||
|
||||
const auto spawnerId = dZoneManager::Instance()->MakeSpawner(info);
|
||||
const auto spawnerId = Game::zoneManager->MakeSpawner(info);
|
||||
|
||||
auto* spawner = dZoneManager::Instance()->GetSpawner(spawnerId);
|
||||
auto* spawner = Game::zoneManager->GetSpawner(spawnerId);
|
||||
|
||||
auto* model = spawner->Spawn();
|
||||
|
||||
@@ -698,7 +698,7 @@ void PropertyManagementComponent::Save() {
|
||||
|
||||
modelIds.push_back(id);
|
||||
|
||||
auto* entity = EntityManager::Instance()->GetEntity(pair.first);
|
||||
auto* entity = Game::entityManager->GetEntity(pair.first);
|
||||
|
||||
if (entity == nullptr) {
|
||||
continue;
|
||||
@@ -786,7 +786,7 @@ void PropertyManagementComponent::OnQueryPropertyData(Entity* originator, const
|
||||
author = m_Parent->GetObjectID();
|
||||
}
|
||||
|
||||
const auto& worldId = dZoneManager::Instance()->GetZone()->GetZoneID();
|
||||
const auto& worldId = Game::zoneManager->GetZone()->GetZoneID();
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
|
||||
Game::logger->Log("Properties", "Getting property info for %d", zoneId);
|
||||
|
||||
@@ -43,7 +43,7 @@ void PropertyVendorComponent::OnBuyFromVendor(Entity* originator, const bool con
|
||||
|
||||
GameMessages::SendPropertyRentalResponse(m_Parent->GetObjectID(), 0, 0, 0, 0, originator->GetSystemAddress());
|
||||
|
||||
auto* controller = dZoneManager::Instance()->GetZoneControlObject();
|
||||
auto* controller = Game::zoneManager->GetZoneControlObject();
|
||||
|
||||
controller->OnFireEventServerSide(m_Parent, "propertyRented");
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "dConfig.h"
|
||||
#include "Loot.h"
|
||||
#include "eMissionTaskType.h"
|
||||
#include "LeaderboardManager.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "CDActivitiesTable.h"
|
||||
|
||||
@@ -49,7 +50,7 @@ RacingControlComponent::RacingControlComponent(Entity* parent)
|
||||
|
||||
m_MainWorld = 1200;
|
||||
const auto worldID = Game::server->GetZoneID();
|
||||
if (dZoneManager::Instance()->CheckIfAccessibleZone((worldID/10)*10)) m_MainWorld = (worldID/10)*10;
|
||||
if (Game::zoneManager->CheckIfAccessibleZone((worldID/10)*10)) m_MainWorld = (worldID/10)*10;
|
||||
|
||||
m_ActivityID = 42;
|
||||
CDActivitiesTable* activitiesTable = CDClientManager::Instance().GetTable<CDActivitiesTable>();
|
||||
@@ -105,10 +106,10 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
|
||||
|
||||
// Calculate the vehicle's starting position.
|
||||
|
||||
auto* path = dZoneManager::Instance()->GetZone()->GetPath(
|
||||
auto* path = Game::zoneManager->GetZone()->GetPath(
|
||||
GeneralUtils::UTF16ToWTF8(m_PathName));
|
||||
|
||||
auto spawnPointEntities = EntityManager::Instance()->GetEntitiesByLOT(4843);
|
||||
auto spawnPointEntities = Game::entityManager->GetEntitiesByLOT(4843);
|
||||
auto startPosition = NiPoint3::ZERO;
|
||||
auto startRotation = NiQuaternion::IDENTITY;
|
||||
const std::string placementAsString = std::to_string(positionNumber);
|
||||
@@ -124,8 +125,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
|
||||
// Make sure the player is at the correct position.
|
||||
|
||||
GameMessages::SendTeleport(player->GetObjectID(), startPosition,
|
||||
startRotation, player->GetSystemAddress(), true,
|
||||
true);
|
||||
startRotation, player->GetSystemAddress(), true);
|
||||
|
||||
// Spawn the vehicle entity.
|
||||
|
||||
@@ -136,7 +136,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
|
||||
info.spawnerID = m_Parent->GetObjectID();
|
||||
|
||||
auto* carEntity =
|
||||
EntityManager::Instance()->CreateEntity(info, nullptr, m_Parent);
|
||||
Game::entityManager->CreateEntity(info, nullptr, m_Parent);
|
||||
|
||||
// Make the vehicle a child of the racing controller.
|
||||
m_Parent->AddChild(carEntity);
|
||||
@@ -207,9 +207,9 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
|
||||
|
||||
// Construct and serialize everything when done.
|
||||
|
||||
EntityManager::Instance()->ConstructEntity(carEntity);
|
||||
EntityManager::Instance()->SerializeEntity(player);
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->ConstructEntity(carEntity);
|
||||
Game::entityManager->SerializeEntity(player);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
GameMessages::SendRacingSetPlayerResetInfo(
|
||||
m_Parent->GetObjectID(), 0, 0, player->GetObjectID(), startPosition, 1,
|
||||
@@ -220,7 +220,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
|
||||
// Reset the player to the start position during downtime, in case something
|
||||
// went wrong.
|
||||
m_Parent->AddCallbackTimer(1, [this, playerID]() {
|
||||
auto* player = EntityManager::Instance()->GetEntity(playerID);
|
||||
auto* player = Game::entityManager->GetEntity(playerID);
|
||||
|
||||
if (player == nullptr) {
|
||||
return;
|
||||
@@ -243,11 +243,9 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player,
|
||||
|
||||
// Make sure everything has the correct position.
|
||||
GameMessages::SendTeleport(player->GetObjectID(), startPosition,
|
||||
startRotation, player->GetSystemAddress(), true,
|
||||
true);
|
||||
startRotation, player->GetSystemAddress(), true);
|
||||
GameMessages::SendTeleport(carEntity->GetObjectID(), startPosition,
|
||||
startRotation, player->GetSystemAddress(), true,
|
||||
true);
|
||||
startRotation, player->GetSystemAddress(), true);
|
||||
}
|
||||
|
||||
void RacingControlComponent::OnRacingClientReady(Entity* player) {
|
||||
@@ -271,7 +269,7 @@ void RacingControlComponent::OnRacingClientReady(Entity* player) {
|
||||
racingPlayer.vehicleID, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void RacingControlComponent::OnRequestDie(Entity* player) {
|
||||
@@ -284,7 +282,7 @@ void RacingControlComponent::OnRequestDie(Entity* player) {
|
||||
}
|
||||
|
||||
auto* vehicle =
|
||||
EntityManager::Instance()->GetEntity(racingPlayer.vehicleID);
|
||||
Game::entityManager->GetEntity(racingPlayer.vehicleID);
|
||||
|
||||
if (!vehicle) return;
|
||||
|
||||
@@ -321,7 +319,7 @@ void RacingControlComponent::OnRequestDie(Entity* player) {
|
||||
auto* destroyableComponent = vehicle->GetComponent<DestroyableComponent>();
|
||||
// Reset imagination to half its current value, rounded up to the nearest value divisible by 10, as it was done in live.
|
||||
if (destroyableComponent) destroyableComponent->SetImagination(respawnImagination);
|
||||
EntityManager::Instance()->SerializeEntity(vehicle);
|
||||
Game::entityManager->SerializeEntity(vehicle);
|
||||
});
|
||||
|
||||
auto* characterComponent = player->GetComponent<CharacterComponent>();
|
||||
@@ -350,7 +348,7 @@ void RacingControlComponent::OnRacingPlayerInfoResetFinished(Entity* player) {
|
||||
}
|
||||
|
||||
auto* vehicle =
|
||||
EntityManager::Instance()->GetEntity(racingPlayer.vehicleID);
|
||||
Game::entityManager->GetEntity(racingPlayer.vehicleID);
|
||||
|
||||
if (vehicle == nullptr) {
|
||||
return;
|
||||
@@ -370,15 +368,17 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity* player, int32_t bu
|
||||
}
|
||||
|
||||
if (id == "rewardButton") {
|
||||
if (data->collectedRewards) {
|
||||
return;
|
||||
}
|
||||
if (data->collectedRewards) return;
|
||||
|
||||
data->collectedRewards = true;
|
||||
|
||||
// Calculate the score, different loot depending on player count
|
||||
const auto score = m_LoadedPlayers * 10 + data->finished;
|
||||
auto playersRating = m_LoadedPlayers;
|
||||
if(m_LoadedPlayers == 1 && m_SoloRacing) {
|
||||
playersRating *= 2;
|
||||
}
|
||||
|
||||
const auto score = playersRating * 10 + data->finished;
|
||||
LootGenerator::Instance().GiveActivityLoot(player, m_Parent, m_ActivityID, score);
|
||||
|
||||
// Giving rewards
|
||||
@@ -397,15 +397,15 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity* player, int32_t bu
|
||||
if (m_SoloRacing || m_LoadedPlayers > 2) {
|
||||
missionComponent->Progress(eMissionTaskType::RACING, data->finished, (LWOOBJID)eRacingTaskParam::FINISH_WITH_PLACEMENT); // Finish in 1st place on a race
|
||||
if (data->finished == 1) {
|
||||
missionComponent->Progress(eMissionTaskType::RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::FIRST_PLACE_MULTIPLE_TRACKS); // Finish in 1st place on multiple tracks.
|
||||
missionComponent->Progress(eMissionTaskType::RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::WIN_RACE_IN_WORLD); // Finished first place in specific world.
|
||||
missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::FIRST_PLACE_MULTIPLE_TRACKS); // Finish in 1st place on multiple tracks.
|
||||
missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::WIN_RACE_IN_WORLD); // Finished first place in specific world.
|
||||
}
|
||||
if (data->finished == m_LoadedPlayers) {
|
||||
missionComponent->Progress(eMissionTaskType::RACING, dZoneManager::Instance()->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::LAST_PLACE_FINISH); // Finished first place in specific world.
|
||||
missionComponent->Progress(eMissionTaskType::RACING, Game::zoneManager->GetZone()->GetWorldID(), (LWOOBJID)eRacingTaskParam::LAST_PLACE_FINISH); // Finished first place in specific world.
|
||||
}
|
||||
}
|
||||
} else if ((id == "ACT_RACE_EXIT_THE_RACE?" || id == "Exit") && button == m_ActivityExitConfirm) {
|
||||
auto* vehicle = EntityManager::Instance()->GetEntity(data->vehicleID);
|
||||
auto* vehicle = Game::entityManager->GetEntity(data->vehicleID);
|
||||
|
||||
if (vehicle == nullptr) {
|
||||
return;
|
||||
@@ -424,9 +424,7 @@ void RacingControlComponent::HandleMessageBoxResponse(Entity* player, int32_t bu
|
||||
}
|
||||
}
|
||||
|
||||
void RacingControlComponent::Serialize(RakNet::BitStream* outBitStream,
|
||||
bool bIsInitialUpdate,
|
||||
unsigned int& flags) {
|
||||
void RacingControlComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
// BEGIN Scripted Activity
|
||||
|
||||
outBitStream->Write1();
|
||||
@@ -506,7 +504,7 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
// Check if any players has disconnected before loading in
|
||||
for (size_t i = 0; i < m_LobbyPlayers.size(); i++) {
|
||||
auto* playerEntity =
|
||||
EntityManager::Instance()->GetEntity(m_LobbyPlayers[i]);
|
||||
Game::entityManager->GetEntity(m_LobbyPlayers[i]);
|
||||
|
||||
if (playerEntity == nullptr) {
|
||||
--m_LoadedPlayers;
|
||||
@@ -528,7 +526,7 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
if (m_EmptyTimer >= 30) {
|
||||
for (const auto player : m_LobbyPlayers) {
|
||||
auto* playerEntity =
|
||||
EntityManager::Instance()->GetEntity(player);
|
||||
Game::entityManager->GetEntity(player);
|
||||
|
||||
if (playerEntity == nullptr) {
|
||||
continue;
|
||||
@@ -553,7 +551,7 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
"Loading player now!");
|
||||
|
||||
auto* player =
|
||||
EntityManager::Instance()->GetEntity(m_LobbyPlayers[positionNumber]);
|
||||
Game::entityManager->GetEntity(m_LobbyPlayers[positionNumber]);
|
||||
|
||||
if (player == nullptr) {
|
||||
return;
|
||||
@@ -577,7 +575,7 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
if (!m_Started) {
|
||||
// Check if anyone has disconnected during this period
|
||||
for (size_t i = 0; i < m_RacingPlayers.size(); i++) {
|
||||
auto* playerEntity = EntityManager::Instance()->GetEntity(
|
||||
auto* playerEntity = Game::entityManager->GetEntity(
|
||||
m_RacingPlayers[i].playerID);
|
||||
|
||||
if (playerEntity == nullptr) {
|
||||
@@ -593,7 +591,7 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
if (m_LoadedPlayers < 2 && !(m_LoadedPlayers == 1 && m_SoloRacing)) {
|
||||
for (const auto player : m_LobbyPlayers) {
|
||||
auto* playerEntity =
|
||||
EntityManager::Instance()->GetEntity(player);
|
||||
Game::entityManager->GetEntity(player);
|
||||
|
||||
if (playerEntity == nullptr) {
|
||||
continue;
|
||||
@@ -626,15 +624,15 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
|
||||
for (const auto& player : m_RacingPlayers) {
|
||||
auto* vehicle =
|
||||
EntityManager::Instance()->GetEntity(player.vehicleID);
|
||||
Game::entityManager->GetEntity(player.vehicleID);
|
||||
auto* playerEntity =
|
||||
EntityManager::Instance()->GetEntity(player.playerID);
|
||||
Game::entityManager->GetEntity(player.playerID);
|
||||
|
||||
if (vehicle != nullptr && playerEntity != nullptr) {
|
||||
GameMessages::SendTeleport(
|
||||
player.playerID, player.respawnPosition,
|
||||
player.respawnRotation,
|
||||
playerEntity->GetSystemAddress(), true, true);
|
||||
playerEntity->GetSystemAddress(), true);
|
||||
|
||||
vehicle->SetPosition(player.respawnPosition);
|
||||
vehicle->SetRotation(player.respawnRotation);
|
||||
@@ -646,18 +644,18 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
destroyableComponent->SetImagination(0);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(vehicle);
|
||||
EntityManager::Instance()->SerializeEntity(
|
||||
Game::entityManager->SerializeEntity(vehicle);
|
||||
Game::entityManager->SerializeEntity(
|
||||
playerEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn imagination pickups
|
||||
auto* minSpawner = dZoneManager::Instance()->GetSpawnersByName(
|
||||
auto* minSpawner = Game::zoneManager->GetSpawnersByName(
|
||||
"ImaginationSpawn_Min")[0];
|
||||
auto* medSpawner = dZoneManager::Instance()->GetSpawnersByName(
|
||||
auto* medSpawner = Game::zoneManager->GetSpawnersByName(
|
||||
"ImaginationSpawn_Med")[0];
|
||||
auto* maxSpawner = dZoneManager::Instance()->GetSpawnersByName(
|
||||
auto* maxSpawner = Game::zoneManager->GetSpawnersByName(
|
||||
"ImaginationSpawn_Max")[0];
|
||||
|
||||
minSpawner->Activate();
|
||||
@@ -673,9 +671,9 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
// Reset players to their start location, without smashing them
|
||||
for (auto& player : m_RacingPlayers) {
|
||||
auto* vehicleEntity =
|
||||
EntityManager::Instance()->GetEntity(player.vehicleID);
|
||||
Game::entityManager->GetEntity(player.vehicleID);
|
||||
auto* playerEntity =
|
||||
EntityManager::Instance()->GetEntity(player.playerID);
|
||||
Game::entityManager->GetEntity(player.playerID);
|
||||
|
||||
if (vehicleEntity == nullptr || playerEntity == nullptr) {
|
||||
continue;
|
||||
@@ -692,9 +690,9 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
// Activate the players movement
|
||||
for (auto& player : m_RacingPlayers) {
|
||||
auto* vehicleEntity =
|
||||
EntityManager::Instance()->GetEntity(player.vehicleID);
|
||||
Game::entityManager->GetEntity(player.vehicleID);
|
||||
auto* playerEntity =
|
||||
EntityManager::Instance()->GetEntity(player.playerID);
|
||||
Game::entityManager->GetEntity(player.playerID);
|
||||
|
||||
if (vehicleEntity == nullptr || playerEntity == nullptr) {
|
||||
continue;
|
||||
@@ -712,7 +710,7 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
|
||||
Game::logger->Log("RacingControlComponent", "Starting race");
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
m_StartTime = std::time(nullptr);
|
||||
}
|
||||
@@ -726,13 +724,13 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
}
|
||||
|
||||
// Race routines
|
||||
auto* path = dZoneManager::Instance()->GetZone()->GetPath(
|
||||
auto* path = Game::zoneManager->GetZone()->GetPath(
|
||||
GeneralUtils::UTF16ToWTF8(m_PathName));
|
||||
|
||||
for (auto& player : m_RacingPlayers) {
|
||||
auto* vehicle = EntityManager::Instance()->GetEntity(player.vehicleID);
|
||||
auto* vehicle = Game::entityManager->GetEntity(player.vehicleID);
|
||||
auto* playerEntity =
|
||||
EntityManager::Instance()->GetEntity(player.playerID);
|
||||
Game::entityManager->GetEntity(player.playerID);
|
||||
|
||||
if (vehicle == nullptr || playerEntity == nullptr) {
|
||||
continue;
|
||||
@@ -838,6 +836,7 @@ void RacingControlComponent::Update(float deltaTime) {
|
||||
"Completed time %llu, %llu",
|
||||
raceTime, raceTime * 1000);
|
||||
|
||||
LeaderboardManager::SaveScore(playerEntity->GetObjectID(), m_ActivityID, static_cast<float>(player.raceTime), static_cast<float>(player.bestLapTime), static_cast<float>(player.finished == 1));
|
||||
// Entire race time
|
||||
missionComponent->Progress(eMissionTaskType::RACING, (raceTime) * 1000, (LWOOBJID)eRacingTaskParam::TOTAL_TRACK_TIME);
|
||||
|
||||
|
||||
@@ -110,8 +110,8 @@ public:
|
||||
RacingControlComponent(Entity* parentEntity);
|
||||
~RacingControlComponent();
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Update(float deltaTime);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
/**
|
||||
* Invoked when a player loads into the zone.
|
||||
|
||||
15
dGame/dComponents/RacingSoundTriggerComponent.h
Normal file
15
dGame/dComponents/RacingSoundTriggerComponent.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __RACINGSOUNDTRIGGERCOMPONENT__H__
|
||||
#define __RACINGSOUNDTRIGGERCOMPONENT__H__
|
||||
|
||||
#include "SoundTriggerComponent.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class Entity;
|
||||
|
||||
class RacingSoundTriggerComponent : public SoundTriggerComponent {
|
||||
public:
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_SOUND_TRIGGER;
|
||||
RacingSoundTriggerComponent(Entity* parent) : SoundTriggerComponent(parent){};
|
||||
};
|
||||
|
||||
#endif //!__RACINGSOUNDTRIGGERCOMPONENT__H__
|
||||
@@ -68,7 +68,7 @@ void RailActivatorComponent::OnUse(Entity* originator) {
|
||||
const auto originatorID = originator->GetObjectID();
|
||||
|
||||
m_Parent->AddCallbackTimer(animationLength, [originatorID, this]() {
|
||||
auto* originator = EntityManager::Instance()->GetEntity(originatorID);
|
||||
auto* originator = Game::entityManager->GetEntity(originatorID);
|
||||
|
||||
if (originator == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -57,7 +57,7 @@ RebuildComponent::~RebuildComponent() {
|
||||
DespawnActivator();
|
||||
}
|
||||
|
||||
void RebuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void RebuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
if (m_Parent->GetComponent(eReplicaComponentType::DESTROYABLE) == nullptr) {
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write(false);
|
||||
@@ -120,7 +120,7 @@ void RebuildComponent::Update(float deltaTime) {
|
||||
else {
|
||||
m_SoftTimer = 5.0f;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}*/
|
||||
|
||||
switch (m_State) {
|
||||
@@ -139,7 +139,7 @@ void RebuildComponent::Update(float deltaTime) {
|
||||
if (m_TimerIncomplete >= m_TimeBeforeSmash - 4.0f) {
|
||||
m_ShowResetEffect = true;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
if (m_TimerIncomplete >= m_TimeBeforeSmash) {
|
||||
@@ -163,7 +163,7 @@ void RebuildComponent::Update(float deltaTime) {
|
||||
if (!m_ShowResetEffect) {
|
||||
m_ShowResetEffect = true;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ void RebuildComponent::Update(float deltaTime) {
|
||||
{
|
||||
Entity* builder = GetBuilder();
|
||||
|
||||
if (builder == nullptr) {
|
||||
if (!builder) {
|
||||
ResetRebuild(false);
|
||||
|
||||
return;
|
||||
@@ -198,16 +198,16 @@ void RebuildComponent::Update(float deltaTime) {
|
||||
if (!destComp) break;
|
||||
|
||||
int newImagination = destComp->GetImagination();
|
||||
if (newImagination <= 0) {
|
||||
CancelRebuild(builder, eQuickBuildFailReason::OUT_OF_IMAGINATION, true);
|
||||
break;
|
||||
}
|
||||
|
||||
++m_DrainedImagination;
|
||||
--newImagination;
|
||||
destComp->SetImagination(newImagination);
|
||||
EntityManager::Instance()->SerializeEntity(builder);
|
||||
Game::entityManager->SerializeEntity(builder);
|
||||
|
||||
if (newImagination <= 0) {
|
||||
CancelRebuild(builder, eQuickBuildFailReason::OUT_OF_IMAGINATION, true);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ void RebuildComponent::Update(float deltaTime) {
|
||||
if (m_TimerIncomplete >= m_TimeBeforeSmash - 4.0f) {
|
||||
m_ShowResetEffect = true;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
if (m_TimerIncomplete >= m_TimeBeforeSmash) {
|
||||
@@ -263,20 +263,20 @@ void RebuildComponent::SpawnActivator() {
|
||||
info.spawnerID = m_Parent->GetObjectID();
|
||||
info.pos = m_ActivatorPosition == NiPoint3::ZERO ? m_Parent->GetPosition() : m_ActivatorPosition;
|
||||
|
||||
m_Activator = EntityManager::Instance()->CreateEntity(info, nullptr, m_Parent);
|
||||
m_Activator = Game::entityManager->CreateEntity(info, nullptr, m_Parent);
|
||||
if (m_Activator) {
|
||||
m_ActivatorId = m_Activator->GetObjectID();
|
||||
EntityManager::Instance()->ConstructEntity(m_Activator);
|
||||
Game::entityManager->ConstructEntity(m_Activator);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RebuildComponent::DespawnActivator() {
|
||||
if (m_Activator) {
|
||||
EntityManager::Instance()->DestructEntity(m_Activator);
|
||||
Game::entityManager->DestructEntity(m_Activator);
|
||||
|
||||
m_Activator->ScheduleKillAfterUpdate();
|
||||
|
||||
@@ -287,7 +287,7 @@ void RebuildComponent::DespawnActivator() {
|
||||
}
|
||||
|
||||
Entity* RebuildComponent::GetActivator() {
|
||||
return EntityManager::Instance()->GetEntity(m_ActivatorId);
|
||||
return Game::entityManager->GetEntity(m_ActivatorId);
|
||||
}
|
||||
|
||||
NiPoint3 RebuildComponent::GetActivatorPosition() {
|
||||
@@ -335,7 +335,7 @@ eRebuildState RebuildComponent::GetState() {
|
||||
}
|
||||
|
||||
Entity* RebuildComponent::GetBuilder() const {
|
||||
auto* builder = EntityManager::Instance()->GetEntity(m_Builder);
|
||||
auto* builder = Game::entityManager->GetEntity(m_Builder);
|
||||
|
||||
return builder;
|
||||
}
|
||||
@@ -403,14 +403,14 @@ void RebuildComponent::StartRebuild(Entity* user) {
|
||||
auto* character = user->GetComponent<CharacterComponent>();
|
||||
character->SetCurrentActivity(eGameActivity::QUICKBUILDING);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(user);
|
||||
Game::entityManager->SerializeEntity(user);
|
||||
|
||||
GameMessages::SendRebuildNotifyState(m_Parent, m_State, eRebuildState::BUILDING, user->GetObjectID());
|
||||
GameMessages::SendEnableRebuild(m_Parent, true, false, false, eQuickBuildFailReason::NOT_GIVEN, 0.0f, user->GetObjectID());
|
||||
|
||||
m_State = eRebuildState::BUILDING;
|
||||
m_StateDirty = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
auto* movingPlatform = m_Parent->GetComponent<MovingPlatformComponent>();
|
||||
if (movingPlatform != nullptr) {
|
||||
@@ -443,7 +443,7 @@ void RebuildComponent::CompleteRebuild(Entity* user) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(user);
|
||||
Game::entityManager->SerializeEntity(user);
|
||||
|
||||
GameMessages::SendRebuildNotifyState(m_Parent, m_State, eRebuildState::COMPLETED, user->GetObjectID());
|
||||
GameMessages::SendPlayFXEffect(m_Parent, 507, u"create", "BrickFadeUpVisCompleteEffect", LWOOBJID_EMPTY, 0.4f, 1.0f, true);
|
||||
@@ -456,7 +456,7 @@ void RebuildComponent::CompleteRebuild(Entity* user) {
|
||||
m_Timer = 0.0f;
|
||||
m_DrainedImagination = 0;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Removes extra item requirements, isn't live accurate.
|
||||
// In live, all items were removed at the start of the quickbuild, then returned if it was cancelled.
|
||||
@@ -476,13 +476,13 @@ void RebuildComponent::CompleteRebuild(Entity* user) {
|
||||
auto* team = TeamManager::Instance()->GetTeam(builder->GetObjectID());
|
||||
if (team) {
|
||||
for (const auto memberId : team->members) { // progress missions for all team members
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
if (member) {
|
||||
auto* missionComponent = member->GetComponent<MissionComponent>();
|
||||
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
||||
}
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
auto* missionComponent = builder->GetComponent<MissionComponent>();
|
||||
if (missionComponent) missionComponent->Progress(eMissionTaskType::ACTIVITY, m_ActivityId);
|
||||
}
|
||||
@@ -541,7 +541,7 @@ void RebuildComponent::ResetRebuild(bool failed) {
|
||||
m_ShowResetEffect = false;
|
||||
m_DrainedImagination = 0;
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
// Notify scripts and possible subscribers
|
||||
for (auto* script : CppScripts::GetEntityScripts(m_Parent))
|
||||
@@ -581,7 +581,7 @@ void RebuildComponent::CancelRebuild(Entity* entity, eQuickBuildFailReason failR
|
||||
for (const auto& cb : m_RebuildStateCallbacks)
|
||||
cb(m_State);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
if (entity == nullptr) {
|
||||
@@ -591,7 +591,7 @@ void RebuildComponent::CancelRebuild(Entity* entity, eQuickBuildFailReason failR
|
||||
CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>();
|
||||
if (characterComponent) {
|
||||
characterComponent->SetCurrentActivity(eGameActivity::NONE);
|
||||
EntityManager::Instance()->SerializeEntity(entity);
|
||||
Game::entityManager->SerializeEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
RebuildComponent(Entity* entity);
|
||||
~RebuildComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,7 @@ RenderComponent::~RenderComponent() {
|
||||
m_Effects.clear();
|
||||
}
|
||||
|
||||
void RenderComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void RenderComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
if (!bIsInitialUpdate) return;
|
||||
|
||||
outBitStream->Write<uint32_t>(m_Effects.size());
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
RenderComponent(Entity* entity, int32_t componentId = -1);
|
||||
~RenderComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* paren
|
||||
RigidbodyPhantomPhysicsComponent::~RigidbodyPhantomPhysicsComponent() {
|
||||
}
|
||||
|
||||
void RigidbodyPhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void RigidbodyPhantomPhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_IsDirty || bIsInitialUpdate);
|
||||
if (m_IsDirty || bIsInitialUpdate) {
|
||||
outBitStream->Write(m_Position.x);
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
RigidbodyPhantomPhysicsComponent(Entity* parent);
|
||||
~RigidbodyPhantomPhysicsComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Returns the position of this entity
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
#include "ChatPackets.h"
|
||||
#include "MissionComponent.h"
|
||||
#include "PropertyEntranceComponent.h"
|
||||
#include "RocketLaunchLupComponent.h"
|
||||
#include "MultiZoneEntranceComponent.h"
|
||||
#include "dServer.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "eObjectWorldState.h"
|
||||
#include "eConnectionType.h"
|
||||
#include "eMasterMessageType.h"
|
||||
@@ -81,7 +81,7 @@ void RocketLaunchpadControlComponent::Launch(Entity* originator, LWOMAPID mapId,
|
||||
|
||||
GameMessages::SendChangeObjectWorldState(rocket->GetId(), eObjectWorldState::ATTACHED, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(originator);
|
||||
Game::entityManager->SerializeEntity(originator);
|
||||
}
|
||||
|
||||
void RocketLaunchpadControlComponent::OnUse(Entity* originator) {
|
||||
@@ -94,7 +94,7 @@ void RocketLaunchpadControlComponent::OnUse(Entity* originator) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* rocketLaunchLUP = m_Parent->GetComponent<RocketLaunchLupComponent>();
|
||||
auto* rocketLaunchLUP = m_Parent->GetComponent<MultiZoneEntranceComponent>();
|
||||
if (rocketLaunchLUP) {
|
||||
return;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ LWOCLONEID RocketLaunchpadControlComponent::GetSelectedCloneId(LWOOBJID player)
|
||||
|
||||
void RocketLaunchpadControlComponent::TellMasterToPrepZone(int zoneID) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PREP_ZONE);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, eMasterMessageType::PREP_ZONE);
|
||||
bitStream.Write(zoneID);
|
||||
Game::server->SendToMaster(&bitStream);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "EntityManager.h"
|
||||
#include "ChatPackets.h"
|
||||
#include "Player.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "dServer.h"
|
||||
#include "GeneralUtils.h"
|
||||
#include "dZoneManager.h"
|
||||
@@ -36,7 +36,7 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit
|
||||
|
||||
for (CDActivities activity : activities) {
|
||||
m_ActivityInfo = activity;
|
||||
if (static_cast<LeaderboardType>(activity.leaderboardType) == LeaderboardType::Racing && Game::config->GetValue("solo_racing") == "1") {
|
||||
if (static_cast<Leaderboard::Type>(activity.leaderboardType) == Leaderboard::Type::Racing && Game::config->GetValue("solo_racing") == "1") {
|
||||
m_ActivityInfo.minTeamSize = 1;
|
||||
m_ActivityInfo.minTeams = 1;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ ScriptedActivityComponent::ScriptedActivityComponent(Entity* parent, int activit
|
||||
ScriptedActivityComponent::~ScriptedActivityComponent()
|
||||
= default;
|
||||
|
||||
void ScriptedActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) const {
|
||||
void ScriptedActivityComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(true);
|
||||
outBitStream->Write<uint32_t>(m_ActivityPlayers.size());
|
||||
|
||||
@@ -137,7 +137,7 @@ void ScriptedActivityComponent::PlayerJoin(Entity* player) {
|
||||
instance->AddParticipant(player);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ScriptedActivityComponent::PlayerJoinLobby(Entity* player) {
|
||||
@@ -149,7 +149,7 @@ void ScriptedActivityComponent::PlayerJoinLobby(Entity* player) {
|
||||
|
||||
auto* character = player->GetCharacter();
|
||||
if (character != nullptr)
|
||||
character->SetLastNonInstanceZoneID(dZoneManager::Instance()->GetZone()->GetWorldID());
|
||||
character->SetLastNonInstanceZoneID(Game::zoneManager->GetZone()->GetWorldID());
|
||||
|
||||
for (Lobby* lobby : m_Queue) {
|
||||
if (lobby->players.size() < m_ActivityInfo.maxTeamSize || m_ActivityInfo.maxTeamSize == 1 && lobby->players.size() < m_ActivityInfo.maxTeams) {
|
||||
@@ -310,7 +310,7 @@ bool ScriptedActivityComponent::IsValidActivity(Entity* player) {
|
||||
}
|
||||
|
||||
ChatPackets::SendSystemMessage(player->GetSystemAddress(), u"Sorry, this activity is not ready.");
|
||||
static_cast<Player*>(player)->SendToZone(dZoneManager::Instance()->GetZone()->GetWorldID()); // Gets them out of this stuck state
|
||||
static_cast<Player*>(player)->SendToZone(Game::zoneManager->GetZone()->GetWorldID()); // Gets them out of this stuck state
|
||||
|
||||
return false;
|
||||
}*/
|
||||
@@ -445,7 +445,7 @@ void ScriptedActivityComponent::RemoveActivityPlayerData(LWOOBJID playerID) {
|
||||
m_ActivityPlayers[i] = nullptr;
|
||||
|
||||
m_ActivityPlayers.erase(m_ActivityPlayers.begin() + i);
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -458,7 +458,7 @@ ActivityPlayer* ScriptedActivityComponent::AddActivityPlayerData(LWOOBJID player
|
||||
return data;
|
||||
|
||||
m_ActivityPlayers.push_back(new ActivityPlayer{ playerID, {} });
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
|
||||
return GetActivityPlayerData(playerID);
|
||||
}
|
||||
@@ -480,7 +480,7 @@ void ScriptedActivityComponent::SetActivityValue(LWOOBJID playerID, uint32_t ind
|
||||
data->values[std::min(index, (uint32_t)9)] = value;
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ScriptedActivityComponent::PlayerRemove(LWOOBJID playerID) {
|
||||
@@ -516,7 +516,7 @@ void ActivityInstance::StartZone() {
|
||||
// only make a team if we have more than one participant
|
||||
if (participants.size() > 1) {
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::CREATE_TEAM);
|
||||
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT_INTERNAL, eChatInternalMessageType::CREATE_TEAM);
|
||||
|
||||
bitStream.Write(leader->GetObjectID());
|
||||
bitStream.Write(m_Participants.size());
|
||||
@@ -535,7 +535,7 @@ void ActivityInstance::StartZone() {
|
||||
const auto objid = player->GetObjectID();
|
||||
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, m_ActivityInfo.instanceMapID, cloneId, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
|
||||
|
||||
auto* player = EntityManager::Instance()->GetEntity(objid);
|
||||
auto* player = Game::entityManager->GetEntity(objid);
|
||||
if (player == nullptr)
|
||||
return;
|
||||
|
||||
@@ -585,7 +585,7 @@ std::vector<Entity*> ActivityInstance::GetParticipants() const {
|
||||
entities.reserve(m_Participants.size());
|
||||
|
||||
for (const auto& id : m_Participants) {
|
||||
auto* entity = EntityManager::Instance()->GetEntity(id);
|
||||
auto* entity = Game::entityManager->GetEntity(id);
|
||||
if (entity != nullptr)
|
||||
entities.push_back(entity);
|
||||
}
|
||||
@@ -617,5 +617,5 @@ void ActivityInstance::SetScore(uint32_t score) {
|
||||
}
|
||||
|
||||
Entity* LobbyPlayer::GetEntity() const {
|
||||
return EntityManager::Instance()->GetEntity(entityID);
|
||||
return Game::entityManager->GetEntity(entityID);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
~ScriptedActivityComponent() override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) const;
|
||||
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
|
||||
|
||||
@@ -14,10 +14,10 @@ void ShootingGalleryComponent::SetStaticParams(const StaticShootingGalleryParams
|
||||
void ShootingGalleryComponent::SetDynamicParams(const DynamicShootingGalleryParams& params) {
|
||||
m_DynamicParams = params;
|
||||
m_Dirty = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void ShootingGalleryComponent::Serialize(RakNet::BitStream* outBitStream, bool isInitialUpdate, uint32_t& flags) const {
|
||||
void ShootingGalleryComponent::Serialize(RakNet::BitStream* outBitStream, bool isInitialUpdate) {
|
||||
// Start ScriptedActivityComponent
|
||||
outBitStream->Write<bool>(true);
|
||||
if (m_CurrentPlayerID == LWOOBJID_EMPTY) {
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
|
||||
explicit ShootingGalleryComponent(Entity* parent);
|
||||
~ShootingGalleryComponent();
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool isInitialUpdate, uint32_t& flags) const;
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool isInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Returns the static params for the shooting gallery
|
||||
|
||||
@@ -33,7 +33,7 @@ SimplePhysicsComponent::SimplePhysicsComponent(uint32_t componentID, Entity* par
|
||||
SimplePhysicsComponent::~SimplePhysicsComponent() {
|
||||
}
|
||||
|
||||
void SimplePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void SimplePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write(m_ClimbableType != eClimbableType::CLIMBABLE_TYPE_NOT);
|
||||
outBitStream->Write(m_ClimbableType);
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
SimplePhysicsComponent(uint32_t componentID, Entity* parent);
|
||||
~SimplePhysicsComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Returns the position of this entity
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "dServer.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Game.h"
|
||||
#include "PacketUtils.h"
|
||||
#include "BitStreamUtils.h"
|
||||
#include "BaseCombatAIComponent.h"
|
||||
#include "ScriptComponent.h"
|
||||
#include "BuffComponent.h"
|
||||
@@ -292,7 +292,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
start.optionalOriginatorID = context->originator;
|
||||
start.optionalTargetID = target;
|
||||
|
||||
auto* originator = EntityManager::Instance()->GetEntity(context->originator);
|
||||
auto* originator = Game::entityManager->GetEntity(context->originator);
|
||||
|
||||
if (originator != nullptr) {
|
||||
start.originatorRot = originator->GetRotation();
|
||||
@@ -304,7 +304,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c
|
||||
// Write message
|
||||
RakNet::BitStream message;
|
||||
|
||||
PacketUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
message.Write(this->m_Parent->GetObjectID());
|
||||
start.Serialize(&message);
|
||||
|
||||
@@ -338,7 +338,7 @@ void SkillComponent::CalculateUpdate(const float deltaTime) {
|
||||
|
||||
entry.time += deltaTime;
|
||||
|
||||
auto* origin = EntityManager::Instance()->GetEntity(entry.context->originator);
|
||||
auto* origin = Game::entityManager->GetEntity(entry.context->originator);
|
||||
|
||||
if (origin == nullptr) {
|
||||
continue;
|
||||
@@ -349,7 +349,7 @@ void SkillComponent::CalculateUpdate(const float deltaTime) {
|
||||
const auto position = entry.startPosition + (entry.velocity * entry.time);
|
||||
|
||||
for (const auto& targetId : targets) {
|
||||
auto* target = EntityManager::Instance()->GetEntity(targetId);
|
||||
auto* target = Game::entityManager->GetEntity(targetId);
|
||||
|
||||
const auto targetPosition = target->GetPosition();
|
||||
|
||||
@@ -397,7 +397,7 @@ void SkillComponent::CalculateUpdate(const float deltaTime) {
|
||||
|
||||
|
||||
void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry) const {
|
||||
auto* other = EntityManager::Instance()->GetEntity(entry.branchContext.target);
|
||||
auto* other = Game::entityManager->GetEntity(entry.branchContext.target);
|
||||
|
||||
if (other == nullptr) {
|
||||
if (entry.branchContext.target != LWOOBJID_EMPTY) {
|
||||
@@ -437,7 +437,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry)
|
||||
|
||||
RakNet::BitStream message;
|
||||
|
||||
PacketUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, eClientMessageType::GAME_MSG);
|
||||
message.Write(this->m_Parent->GetObjectID());
|
||||
projectileImpact.Serialize(&message);
|
||||
|
||||
@@ -486,7 +486,7 @@ SkillComponent::~SkillComponent() {
|
||||
Reset();
|
||||
}
|
||||
|
||||
void SkillComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void SkillComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
if (bIsInitialUpdate) outBitStream->Write0();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
explicit SkillComponent(Entity* parent);
|
||||
~SkillComponent() override;
|
||||
|
||||
static void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Computes skill updates. Invokes CalculateUpdate.
|
||||
|
||||
@@ -1,93 +1,114 @@
|
||||
#include "SoundTriggerComponent.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Game.h"
|
||||
#include "dLogger.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 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){
|
||||
guid.Serialize(outBitStream);
|
||||
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) {
|
||||
|
||||
const auto musicCueName = parent->GetVar<std::string>(u"NDAudioMusicCue_Name");
|
||||
const auto musicCueBoredomTime = parent->GetVar<float>(u"NDAudioMusicCue_BoredomTime");
|
||||
if (!musicCueName.empty()) {
|
||||
auto newCue = MusicCue(musicCueName);
|
||||
const auto musicCueBoredomTime = parent->GetVar<float>(u"NDAudioMusicCue_BoredomTime");
|
||||
if (musicCueBoredomTime) newCue.boredomTime = musicCueBoredomTime;
|
||||
this->m_MusicCues.push_back(newCue);
|
||||
}
|
||||
|
||||
this->musicCues.push_back({
|
||||
musicCueName,
|
||||
1,
|
||||
musicCueBoredomTime
|
||||
});
|
||||
const auto musicParameterName = parent->GetVar<std::string>(u"NDAudioMusicParameter_Name");
|
||||
if (!musicParameterName.empty()) {
|
||||
auto newParams = MusicParameter(musicParameterName);
|
||||
const auto musicParameterValue = parent->GetVar<float>(u"NDAudioMusicParameter_Value");
|
||||
if (musicParameterValue) newParams.value = musicParameterValue;
|
||||
this->m_MusicParameters.push_back(newParams);
|
||||
}
|
||||
|
||||
const auto mixerName = parent->GetVar<std::string>(u"NDAudioMixerProgram_Name");
|
||||
this->mixerPrograms.push_back(mixerName);
|
||||
const auto guidString = parent->GetVar<std::string>(u"NDAudioEventGUID");
|
||||
if (!guidString.empty())
|
||||
this->m_2DAmbientSounds.push_back(GUIDResults(guidString));
|
||||
|
||||
const auto guid2String = parent->GetVar<std::string>(u"NDAudioEventGUID2");
|
||||
if (!guid2String.empty()) {
|
||||
this->guids.emplace_back(guid2String);
|
||||
if (!guid2String.empty())
|
||||
this->m_3DAmbientSounds.push_back(GUIDResults(guid2String));
|
||||
|
||||
const auto mixerName = parent->GetVar<std::string>(u"NDAudioMixerProgram_Name");
|
||||
if (!mixerName.empty()) this->m_MixerPrograms.push_back(MixerProgram(mixerName));
|
||||
}
|
||||
|
||||
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());
|
||||
for (auto& musicCue : this->m_MusicCues) {
|
||||
musicCue.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
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());
|
||||
for (auto twoDAmbientSound : this->m_2DAmbientSounds) {
|
||||
twoDAmbientSound.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
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());
|
||||
for (auto& mixerProgram : this->m_MixerPrograms) {
|
||||
mixerProgram.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
if (!bIsInitialUpdate) this->m_Dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
SoundTriggerComponent::~SoundTriggerComponent() = default;
|
||||
|
||||
void SoundTriggerComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
if (bIsInitialUpdate)
|
||||
dirty = true;
|
||||
|
||||
outBitStream->Write(dirty);
|
||||
|
||||
if (dirty) {
|
||||
outBitStream->Write<uint8_t>(this->musicCues.size());
|
||||
for (const auto& musicCue : this->musicCues) {
|
||||
outBitStream->Write<uint8_t>(musicCue.name.size());
|
||||
outBitStream->Write(musicCue.name.c_str(), musicCue.name.size());
|
||||
outBitStream->Write<uint32_t>(musicCue.result);
|
||||
outBitStream->Write<float_t>(musicCue.boredomTime);
|
||||
}
|
||||
|
||||
// Unknown part
|
||||
outBitStream->Write<uint16_t>(0);
|
||||
|
||||
// GUID part
|
||||
outBitStream->Write<uint8_t>(this->guids.size());
|
||||
|
||||
for (const auto guid : this->guids) {
|
||||
outBitStream->Write<uint32_t>(guid.GetData1());
|
||||
outBitStream->Write<uint16_t>(guid.GetData2());
|
||||
outBitStream->Write<uint16_t>(guid.GetData3());
|
||||
for (const auto& guidSubPart : guid.GetData4()) {
|
||||
outBitStream->Write<uint8_t>(guidSubPart);
|
||||
}
|
||||
outBitStream->Write<uint32_t>(1); // Unknown
|
||||
}
|
||||
|
||||
// Mixer program part
|
||||
outBitStream->Write<uint8_t>(this->mixerPrograms.size());
|
||||
for (const auto& mixerProgram : mixerPrograms) {
|
||||
outBitStream->Write<uint8_t>(mixerProgram.size());
|
||||
outBitStream->Write(mixerProgram.c_str(), mixerProgram.size());
|
||||
outBitStream->Write<uint32_t>(1); // Unknown
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundTriggerComponent::ActivateMusicCue(const std::string& name) {
|
||||
if (std::find_if(this->musicCues.begin(), this->musicCues.end(), [name](const MusicCue& musicCue) {
|
||||
void SoundTriggerComponent::ActivateMusicCue(const std::string& name, float bordemTime) {
|
||||
const auto musicCue = std::find_if(this->m_MusicCues.begin(), this->m_MusicCues.end(), [name](const MusicCue& musicCue) {
|
||||
return musicCue.name == name;
|
||||
}) == this->musicCues.end()) {
|
||||
this->musicCues.push_back({
|
||||
name,
|
||||
1,
|
||||
-1.0f
|
||||
});
|
||||
dirty = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
}
|
||||
);
|
||||
|
||||
if (musicCue == this->m_MusicCues.end()) {
|
||||
this->m_MusicCues.push_back(MusicCue(name, bordemTime));
|
||||
this->m_Dirty = true;
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
|
||||
void SoundTriggerComponent::DeactivateMusicCue(const std::string& name) {
|
||||
const auto musicCue = std::find_if(this->musicCues.begin(), this->musicCues.end(), [name](const MusicCue& musicCue) {
|
||||
const auto musicCue = std::find_if(this->m_MusicCues.begin(), this->m_MusicCues.end(), [name](const MusicCue& musicCue) {
|
||||
return musicCue.name == name;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (musicCue != this->musicCues.end()) {
|
||||
this->musicCues.erase(musicCue);
|
||||
dirty = true;
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
if (musicCue != this->m_MusicCues.end()) {
|
||||
this->m_MusicCues.erase(musicCue);
|
||||
this->m_Dirty = true;
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,55 +5,72 @@
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* Music that should be played by the client
|
||||
*/
|
||||
struct MusicCue {
|
||||
std::string name;
|
||||
uint32_t result;
|
||||
float boredomTime;
|
||||
|
||||
MusicCue(std::string name, float boredomTime = -1.0, uint32_t result = 1){
|
||||
this->name = name;
|
||||
this->result = result;
|
||||
this->boredomTime = boredomTime;
|
||||
};
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles specific music triggers like the instruments in Red Block
|
||||
* Credits to https://github.com/SimonNitzsche/OpCrux-Server/blob/master/src/Entity/Components/SoundTriggerComponent.hpp
|
||||
*/
|
||||
struct MusicParameter {
|
||||
std::string name;
|
||||
float value;
|
||||
|
||||
MusicParameter(std::string name, float value = 0.0){
|
||||
this->name = name;
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream);
|
||||
};
|
||||
|
||||
struct GUIDResults{
|
||||
GUID guid;
|
||||
uint32_t result;
|
||||
|
||||
GUIDResults(std::string guidString, uint32_t result = 1){
|
||||
this->guid = GUID(guidString);
|
||||
this->result = result;
|
||||
}
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream);
|
||||
};
|
||||
|
||||
struct MixerProgram{
|
||||
std::string name;
|
||||
uint32_t result;
|
||||
|
||||
MixerProgram(std::string name, uint32_t result = 0){
|
||||
this->name = name;
|
||||
this->result = result;
|
||||
}
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream);
|
||||
};
|
||||
|
||||
|
||||
class SoundTriggerComponent : public Component {
|
||||
public:
|
||||
static const eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_TRIGGER;
|
||||
|
||||
explicit SoundTriggerComponent(Entity* parent);
|
||||
~SoundTriggerComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
|
||||
/**
|
||||
* Activates a music cue, making it played by any client in range
|
||||
* @param name the name of the music to play
|
||||
*/
|
||||
void ActivateMusicCue(const std::string& name);
|
||||
|
||||
/**
|
||||
* Deactivates a music cue (if active)
|
||||
* @param name name of the music to deactivate
|
||||
*/
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
void ActivateMusicCue(const std::string& name, float bordemTime = -1.0);
|
||||
void DeactivateMusicCue(const std::string& name);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Currently active cues
|
||||
*/
|
||||
std::vector<MusicCue> musicCues = {};
|
||||
std::vector<MusicCue> m_MusicCues = {};
|
||||
std::vector<MusicParameter> m_MusicParameters = {};
|
||||
std::vector<GUIDResults> m_2DAmbientSounds = {};
|
||||
std::vector<GUIDResults> m_3DAmbientSounds = {};
|
||||
std::vector<MixerProgram> m_MixerPrograms = {};
|
||||
|
||||
/**
|
||||
* Currently active mixer programs
|
||||
*/
|
||||
std::vector<std::string> mixerPrograms = {};
|
||||
|
||||
/**
|
||||
* GUID found in the LDF
|
||||
*/
|
||||
std::vector<GUID> guids = {};
|
||||
bool dirty = false;
|
||||
bool m_Dirty = false;
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ SwitchComponent::~SwitchComponent() {
|
||||
}
|
||||
}
|
||||
|
||||
void SwitchComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void SwitchComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(m_Active);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ void SwitchComponent::EntityEnter(Entity* entity) {
|
||||
const auto grpName = m_Parent->GetVarAsString(u"grp_name");
|
||||
|
||||
if (!grpName.empty()) {
|
||||
const auto entities = EntityManager::Instance()->GetEntitiesInGroup(grpName);
|
||||
const auto entities = Game::entityManager->GetEntitiesInGroup(grpName);
|
||||
|
||||
for (auto* entity : entities) {
|
||||
entity->OnFireEventServerSide(entity, "OnActivated");
|
||||
@@ -63,7 +63,7 @@ void SwitchComponent::EntityEnter(Entity* entity) {
|
||||
RenderComponent::PlayAnimation(m_Parent, u"engaged");
|
||||
m_PetBouncer->SetPetBouncerEnabled(true);
|
||||
} else {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,7 +85,7 @@ void SwitchComponent::Update(float deltaTime) {
|
||||
const auto grpName = m_Parent->GetVarAsString(u"grp_name");
|
||||
|
||||
if (!grpName.empty()) {
|
||||
const auto entities = EntityManager::Instance()->GetEntitiesInGroup(grpName);
|
||||
const auto entities = Game::entityManager->GetEntitiesInGroup(grpName);
|
||||
|
||||
for (auto* entity : entities) {
|
||||
entity->OnFireEventServerSide(entity, "OnDectivated");
|
||||
@@ -95,7 +95,7 @@ void SwitchComponent::Update(float deltaTime) {
|
||||
if (m_PetBouncer != nullptr) {
|
||||
m_PetBouncer->SetPetBouncerEnabled(false);
|
||||
} else {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
Entity* GetParentEntity() const;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
/**
|
||||
* Sets whether the switch is on or off.
|
||||
|
||||
@@ -26,7 +26,7 @@ TriggerComponent::TriggerComponent(Entity* parent, const std::string triggerInfo
|
||||
uint32_t triggerID;
|
||||
GeneralUtils::TryParse<uint32_t>(tokens.at(1), triggerID);
|
||||
|
||||
m_Trigger = dZoneManager::Instance()->GetZone()->GetTrigger(sceneID, triggerID);
|
||||
m_Trigger = Game::zoneManager->GetZone()->GetTrigger(sceneID, triggerID);
|
||||
|
||||
if (!m_Trigger) m_Trigger = new LUTriggers::Trigger();
|
||||
}
|
||||
@@ -170,10 +170,10 @@ std::vector<Entity*> TriggerComponent::GatherTargets(LUTriggers::Command* comman
|
||||
else if (command->target == "targetTeam" && optionalTarget) {
|
||||
auto* team = TeamManager::Instance()->GetTeam(optionalTarget->GetObjectID());
|
||||
for (const auto memberId : team->members) {
|
||||
auto* member = EntityManager::Instance()->GetEntity(memberId);
|
||||
auto* member = Game::entityManager->GetEntity(memberId);
|
||||
if (member) entities.push_back(member);
|
||||
}
|
||||
} else if (command->target == "objGroup") entities = EntityManager::Instance()->GetEntitiesInGroup(command->targetName);
|
||||
} else if (command->target == "objGroup") entities = Game::entityManager->GetEntitiesInGroup(command->targetName);
|
||||
else if (command->target == "allPlayers") {
|
||||
for (auto* player : Player::GetAllPlayers()) {
|
||||
entities.push_back(player);
|
||||
@@ -249,7 +249,7 @@ void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vector<std::s
|
||||
GeneralUtils::TryParse(argArray.at(0), argArray.at(1), argArray.at(2), direction);
|
||||
phantomPhysicsComponent->SetDirection(direction);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ void TriggerComponent::HandleRepelObject(Entity* targetEntity, std::string args)
|
||||
NiPoint3 direction = delta / length;
|
||||
phantomPhysicsComponent->SetDirection(direction);
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleSetTimer(Entity* targetEntity, std::vector<std::string> argArray){
|
||||
@@ -395,7 +395,7 @@ void TriggerComponent::HandleSetPhysicsVolumeEffect(Entity* targetEntity, std::v
|
||||
phantomPhysicsComponent->SetMax(max);
|
||||
}
|
||||
|
||||
EntityManager::Instance()->SerializeEntity(targetEntity);
|
||||
Game::entityManager->SerializeEntity(targetEntity);
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleSetPhysicsVolumeStatus(Entity* targetEntity, std::string args) {
|
||||
@@ -405,29 +405,29 @@ void TriggerComponent::HandleSetPhysicsVolumeStatus(Entity* targetEntity, std::s
|
||||
return;
|
||||
}
|
||||
phantomPhysicsComponent->SetPhysicsEffectActive(args == "On");
|
||||
EntityManager::Instance()->SerializeEntity(targetEntity);
|
||||
Game::entityManager->SerializeEntity(targetEntity);
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleActivateSpawnerNetwork(std::string args){
|
||||
for (auto* spawner : dZoneManager::Instance()->GetSpawnersByName(args)) {
|
||||
for (auto* spawner : Game::zoneManager->GetSpawnersByName(args)) {
|
||||
if (spawner) spawner->Activate();
|
||||
}
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleDeactivateSpawnerNetwork(std::string args){
|
||||
for (auto* spawner : dZoneManager::Instance()->GetSpawnersByName(args)) {
|
||||
for (auto* spawner : Game::zoneManager->GetSpawnersByName(args)) {
|
||||
if (spawner) spawner->Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleResetSpawnerNetwork(std::string args){
|
||||
for (auto* spawner : dZoneManager::Instance()->GetSpawnersByName(args)) {
|
||||
for (auto* spawner : Game::zoneManager->GetSpawnersByName(args)) {
|
||||
if (spawner) spawner->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void TriggerComponent::HandleDestroySpawnerNetworkObjects(std::string args){
|
||||
for (auto* spawner : dZoneManager::Instance()->GetSpawnersByName(args)) {
|
||||
for (auto* spawner : Game::zoneManager->GetSpawnersByName(args)) {
|
||||
if (spawner) spawner->DestroyAllEntities();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,34 +19,47 @@ VehiclePhysicsComponent::~VehiclePhysicsComponent() {
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetPosition(const NiPoint3& pos) {
|
||||
if (pos == m_Position) return;
|
||||
m_DirtyPosition = true;
|
||||
m_Position = pos;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetRotation(const NiQuaternion& rot) {
|
||||
if (rot == m_Rotation) return;
|
||||
m_DirtyPosition = true;
|
||||
m_Rotation = rot;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetVelocity(const NiPoint3& vel) {
|
||||
if (vel == m_Velocity) return;
|
||||
m_DirtyPosition = true;
|
||||
m_Velocity = vel;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetAngularVelocity(const NiPoint3& vel) {
|
||||
if (vel == m_AngularVelocity) return;
|
||||
m_DirtyPosition = true;
|
||||
m_AngularVelocity = vel;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetIsOnGround(bool val) {
|
||||
if (val == m_IsOnGround) return;
|
||||
m_DirtyPosition = true;
|
||||
m_IsOnGround = val;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetIsOnRail(bool val) {
|
||||
if (val == m_IsOnRail) return;
|
||||
m_DirtyPosition = true;
|
||||
m_IsOnRail = val;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetRemoteInputInfo(const RemoteInputInfo& remoteInputInfo) {
|
||||
if (m_RemoteInputInfo == remoteInputInfo) return;
|
||||
this->m_RemoteInputInfo = remoteInputInfo;
|
||||
m_DirtyRemoteInput = true;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::SetDirtyPosition(bool val) {
|
||||
m_DirtyPosition = val;
|
||||
}
|
||||
@@ -59,13 +72,19 @@ void VehiclePhysicsComponent::SetDirtyAngularVelocity(bool val) {
|
||||
m_DirtyAngularVelocity = val;
|
||||
}
|
||||
|
||||
void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream->Write(bIsInitialUpdate || m_DirtyPosition);
|
||||
|
||||
if (bIsInitialUpdate || m_DirtyPosition) {
|
||||
outBitStream->Write(m_Position);
|
||||
m_DirtyPosition = false;
|
||||
outBitStream->Write(m_Position.x);
|
||||
outBitStream->Write(m_Position.y);
|
||||
outBitStream->Write(m_Position.z);
|
||||
|
||||
outBitStream->Write(m_Rotation);
|
||||
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);
|
||||
@@ -73,20 +92,33 @@ void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bI
|
||||
outBitStream->Write(bIsInitialUpdate || m_DirtyVelocity);
|
||||
|
||||
if (bIsInitialUpdate || m_DirtyVelocity) {
|
||||
outBitStream->Write(m_Velocity);
|
||||
outBitStream->Write(m_Velocity.x);
|
||||
outBitStream->Write(m_Velocity.y);
|
||||
outBitStream->Write(m_Velocity.z);
|
||||
m_DirtyVelocity = false;
|
||||
}
|
||||
|
||||
outBitStream->Write(bIsInitialUpdate || m_DirtyAngularVelocity);
|
||||
|
||||
if (bIsInitialUpdate || m_DirtyAngularVelocity) {
|
||||
outBitStream->Write(m_AngularVelocity);
|
||||
outBitStream->Write(m_AngularVelocity.x);
|
||||
outBitStream->Write(m_AngularVelocity.y);
|
||||
outBitStream->Write(m_AngularVelocity.z);
|
||||
m_DirtyAngularVelocity = false;
|
||||
}
|
||||
|
||||
outBitStream->Write0();
|
||||
outBitStream->Write0(); // local_space_info. TODO: Implement this
|
||||
|
||||
outBitStream->Write0();
|
||||
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;
|
||||
}
|
||||
|
||||
outBitStream->Write(0.0f);
|
||||
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();
|
||||
@@ -95,7 +127,7 @@ void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bI
|
||||
|
||||
if (bIsInitialUpdate) {
|
||||
outBitStream->Write<uint8_t>(m_EndBehavior);
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write1(); // is input locked?
|
||||
}
|
||||
|
||||
outBitStream->Write0();
|
||||
@@ -103,8 +135,7 @@ void VehiclePhysicsComponent::Serialize(RakNet::BitStream* outBitStream, bool bI
|
||||
|
||||
void VehiclePhysicsComponent::Update(float deltaTime) {
|
||||
if (m_SoftUpdate > 5) {
|
||||
EntityManager::Instance()->SerializeEntity(m_Parent);
|
||||
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
m_SoftUpdate = 0;
|
||||
} else {
|
||||
m_SoftUpdate += deltaTime;
|
||||
|
||||
@@ -5,6 +5,24 @@
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
struct RemoteInputInfo {
|
||||
void operator=(const RemoteInputInfo& other) {
|
||||
m_RemoteInputX = other.m_RemoteInputX;
|
||||
m_RemoteInputY = other.m_RemoteInputY;
|
||||
m_IsPowersliding = other.m_IsPowersliding;
|
||||
m_IsModified = other.m_IsModified;
|
||||
}
|
||||
|
||||
bool operator==(const RemoteInputInfo& other) {
|
||||
return m_RemoteInputX == other.m_RemoteInputX && m_RemoteInputY == other.m_RemoteInputY && m_IsPowersliding == other.m_IsPowersliding && m_IsModified == other.m_IsModified;
|
||||
}
|
||||
|
||||
float m_RemoteInputX;
|
||||
float m_RemoteInputY;
|
||||
bool m_IsPowersliding;
|
||||
bool m_IsModified;
|
||||
};
|
||||
|
||||
/**
|
||||
* Physics component for vehicles.
|
||||
*/
|
||||
@@ -15,7 +33,7 @@ public:
|
||||
VehiclePhysicsComponent(Entity* parentEntity);
|
||||
~VehiclePhysicsComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
@@ -94,6 +112,7 @@ public:
|
||||
void SetDirtyPosition(bool val);
|
||||
void SetDirtyVelocity(bool val);
|
||||
void SetDirtyAngularVelocity(bool val);
|
||||
void SetRemoteInputInfo(const RemoteInputInfo&);
|
||||
|
||||
private:
|
||||
bool m_DirtyPosition;
|
||||
@@ -110,4 +129,6 @@ private:
|
||||
|
||||
float m_SoftUpdate = 0;
|
||||
uint32_t m_EndBehavior;
|
||||
RemoteInputInfo m_RemoteInputInfo;
|
||||
bool m_DirtyRemoteInput;
|
||||
};
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
#include "VendorComponent.h"
|
||||
|
||||
#include <BitStream.h>
|
||||
|
||||
#include "Game.h"
|
||||
#include "BitStream.h"
|
||||
#include "dServer.h"
|
||||
|
||||
#include "dZoneManager.h"
|
||||
#include "WorldConfig.h"
|
||||
#include "CDComponentsRegistryTable.h"
|
||||
#include "CDVendorComponentTable.h"
|
||||
#include "CDLootMatrixTable.h"
|
||||
#include "CDLootTableTable.h"
|
||||
#include "CDItemComponentTable.h"
|
||||
|
||||
VendorComponent::VendorComponent(Entity* parent) : Component(parent) {
|
||||
m_HasStandardCostItems = false;
|
||||
m_HasMultiCostItems = false;
|
||||
SetupConstants();
|
||||
RefreshInventory(true);
|
||||
}
|
||||
|
||||
VendorComponent::~VendorComponent() = default;
|
||||
|
||||
void VendorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
|
||||
outBitStream->Write1();
|
||||
outBitStream->Write1(); // Has standard items (Required for vendors with missions.)
|
||||
outBitStream->Write1();
|
||||
//outBitStream->Write(HasCraftingStation()); // Has multi use items
|
||||
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);
|
||||
if (!bIsInitialUpdate) m_DirtyVendor = false;
|
||||
}
|
||||
}
|
||||
|
||||
void VendorComponent::OnUse(Entity* originator) {
|
||||
@@ -29,97 +30,74 @@ void VendorComponent::OnUse(Entity* originator) {
|
||||
GameMessages::SendVendorStatusUpdate(m_Parent, originator->GetSystemAddress());
|
||||
}
|
||||
|
||||
float VendorComponent::GetBuyScalar() const {
|
||||
return m_BuyScalar;
|
||||
}
|
||||
|
||||
float VendorComponent::GetSellScalar() const {
|
||||
return m_SellScalar;
|
||||
}
|
||||
|
||||
void VendorComponent::SetBuyScalar(float value) {
|
||||
m_BuyScalar = value;
|
||||
}
|
||||
|
||||
void VendorComponent::SetSellScalar(float value) {
|
||||
m_SellScalar = value;
|
||||
}
|
||||
|
||||
std::map<LOT, int>& VendorComponent::GetInventory() {
|
||||
return m_Inventory;
|
||||
}
|
||||
|
||||
bool VendorComponent::HasCraftingStation() {
|
||||
// As far as we know, only Umami has a crafting station
|
||||
return m_Parent->GetLOT() == 13800;
|
||||
}
|
||||
|
||||
void VendorComponent::RefreshInventory(bool isCreation) {
|
||||
//Custom code for Max vanity NPC
|
||||
if (m_Parent->GetLOT() == 9749 && Game::server->GetZoneID() == 1201) {
|
||||
if (!isCreation) return;
|
||||
m_Inventory.insert({ 11909, 0 }); //Top hat w frog
|
||||
m_Inventory.insert({ 7785, 0 }); //Flash bulb
|
||||
m_Inventory.insert({ 12764, 0 }); //Big fountain soda
|
||||
m_Inventory.insert({ 12241, 0 }); //Hot cocoa (from fb)
|
||||
SetHasStandardCostItems(false);
|
||||
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();
|
||||
return;
|
||||
}
|
||||
m_Inventory.clear();
|
||||
|
||||
auto* lootMatrixTable = CDClientManager::Instance().GetTable<CDLootMatrixTable>();
|
||||
std::vector<CDLootMatrix> lootMatrices = lootMatrixTable->Query([=](CDLootMatrix entry) { return (entry.LootMatrixIndex == m_LootMatrixID); });
|
||||
const auto lootMatrices = lootMatrixTable->Query([=](CDLootMatrix entry) { return (entry.LootMatrixIndex == m_LootMatrixID); });
|
||||
|
||||
if (lootMatrices.empty()) return;
|
||||
// Done with lootMatrix table
|
||||
|
||||
auto* lootTableTable = CDClientManager::Instance().GetTable<CDLootTableTable>();
|
||||
auto* itemComponentTable = CDClientManager::Instance().GetTable<CDItemComponentTable>();
|
||||
auto* compRegistryTable = CDClientManager::Instance().GetTable<CDComponentsRegistryTable>();
|
||||
|
||||
for (const auto& lootMatrix : lootMatrices) {
|
||||
int lootTableID = lootMatrix.LootTableIndex;
|
||||
std::vector<CDLootTable> vendorItems = lootTableTable->Query([=](CDLootTable entry) { return (entry.LootTableIndex == lootTableID); });
|
||||
auto vendorItems = lootTableTable->Query([=](CDLootTable entry) { return (entry.LootTableIndex == lootTableID); });
|
||||
if (lootMatrix.maxToDrop == 0 || lootMatrix.minToDrop == 0) {
|
||||
for (CDLootTable item : vendorItems) {
|
||||
m_Inventory.insert({ item.itemid, item.sortPriority });
|
||||
for (const auto& item : vendorItems) {
|
||||
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
|
||||
auto itemComponentID = compRegistryTable->GetByIDAndType(item.itemid, eReplicaComponentType::ITEM, -1);
|
||||
if (itemComponentID == -1) {
|
||||
Game::logger->Log("VendorComponent", "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));
|
||||
}
|
||||
} else {
|
||||
auto randomCount = GeneralUtils::GenerateRandomNumber<int32_t>(lootMatrix.minToDrop, lootMatrix.maxToDrop);
|
||||
|
||||
for (size_t i = 0; i < randomCount; i++) {
|
||||
if (vendorItems.empty()) break;
|
||||
|
||||
auto randomItemIndex = GeneralUtils::GenerateRandomNumber<int32_t>(0, vendorItems.size() - 1);
|
||||
|
||||
const auto& randomItem = vendorItems[randomItemIndex];
|
||||
|
||||
const auto& randomItem = vendorItems.at(randomItemIndex);
|
||||
vendorItems.erase(vendorItems.begin() + randomItemIndex);
|
||||
|
||||
m_Inventory.insert({ randomItem.itemid, randomItem.sortPriority });
|
||||
if (!m_HasStandardCostItems || !m_HasMultiCostItems) {
|
||||
auto itemComponentID = compRegistryTable->GetByIDAndType(randomItem.itemid, eReplicaComponentType::ITEM, -1);
|
||||
if (itemComponentID == -1) {
|
||||
Game::logger->Log("VendorComponent", "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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Because I want a vendor to sell these cameras
|
||||
if (m_Parent->GetLOT() == 13569) {
|
||||
auto randomCamera = GeneralUtils::GenerateRandomNumber<int32_t>(0, 2);
|
||||
|
||||
switch (randomCamera) {
|
||||
case 0:
|
||||
m_Inventory.insert({ 16253, 0 }); //Grungagroid
|
||||
break;
|
||||
case 1:
|
||||
m_Inventory.insert({ 16254, 0 }); //Hipstabrick
|
||||
break;
|
||||
case 2:
|
||||
m_Inventory.insert({ 16204, 0 }); //Megabrixel snapshot
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
HandleMrReeCameras();
|
||||
|
||||
// Callback timer to refresh this inventory.
|
||||
m_Parent->AddCallbackTimer(m_RefreshTimeSeconds, [this]() {
|
||||
RefreshInventory();
|
||||
if (m_RefreshTimeSeconds > 0.0) {
|
||||
m_Parent->AddCallbackTimer(m_RefreshTimeSeconds, [this]() {
|
||||
RefreshInventory();
|
||||
});
|
||||
}
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
GameMessages::SendVendorStatusUpdate(m_Parent, UNASSIGNED_SYSTEM_ADDRESS);
|
||||
}
|
||||
|
||||
@@ -130,12 +108,47 @@ void VendorComponent::SetupConstants() {
|
||||
auto* vendorComponentTable = CDClientManager::Instance().GetTable<CDVendorComponentTable>();
|
||||
std::vector<CDVendorComponent> vendorComps = vendorComponentTable->Query([=](CDVendorComponent entry) { return (entry.id == componentID); });
|
||||
if (vendorComps.empty()) return;
|
||||
m_BuyScalar = vendorComps[0].buyScalar;
|
||||
m_SellScalar = vendorComps[0].sellScalar;
|
||||
m_RefreshTimeSeconds = vendorComps[0].refreshTimeSeconds;
|
||||
m_LootMatrixID = vendorComps[0].LootMatrixIndex;
|
||||
auto vendorData = vendorComps.at(0);
|
||||
if (vendorData.buyScalar == 0.0) m_BuyScalar = Game::zoneManager->GetWorldConfig()->vendorBuyMultiplier;
|
||||
else m_BuyScalar = vendorData.buyScalar;
|
||||
m_SellScalar = vendorData.sellScalar;
|
||||
m_RefreshTimeSeconds = vendorData.refreshTimeSeconds;
|
||||
m_LootMatrixID = vendorData.LootMatrixIndex;
|
||||
}
|
||||
|
||||
bool VendorComponent::SellsItem(const LOT item) const {
|
||||
return m_Inventory.find(item) != m_Inventory.end();
|
||||
return std::count_if(m_Inventory.begin(), m_Inventory.end(), [item](const SoldItem& lhs) {
|
||||
return lhs.lot == item;
|
||||
}) > 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);
|
||||
auto randomCamera = GeneralUtils::GenerateRandomNumber<int32_t>(0, 2);
|
||||
|
||||
LOT camera = 0;
|
||||
DluAssert(randomCamera >= 0 && randomCamera <= 2);
|
||||
switch (randomCamera) {
|
||||
case 0:
|
||||
camera = 16253; // Grungagroid
|
||||
break;
|
||||
case 1:
|
||||
camera = 16254; // Hipstabrick
|
||||
break;
|
||||
case 2:
|
||||
camera = 16204; // Megabrixel snapshot
|
||||
break;
|
||||
}
|
||||
m_Inventory.push_back(SoldItem(camera, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,91 +9,56 @@
|
||||
#include "RakNetTypes.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* A component for vendor NPCs. A vendor sells items to the player.
|
||||
*/
|
||||
struct SoldItem {
|
||||
SoldItem(const LOT lot, const int32_t sortPriority) {
|
||||
this->lot = lot;
|
||||
this->sortPriority = sortPriority;
|
||||
};
|
||||
LOT lot = 0;
|
||||
int32_t sortPriority = 0;
|
||||
};
|
||||
|
||||
class VendorComponent : public Component {
|
||||
public:
|
||||
static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
|
||||
|
||||
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::VENDOR;
|
||||
VendorComponent(Entity* parent);
|
||||
~VendorComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
|
||||
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
void OnUse(Entity* originator) override;
|
||||
|
||||
/**
|
||||
* Gets the buy scaler
|
||||
* @return the buy scaler
|
||||
*/
|
||||
float GetBuyScalar() const;
|
||||
|
||||
/**
|
||||
* Sets the buy scalar.
|
||||
* @param value the new value.
|
||||
*/
|
||||
void SetBuyScalar(float value);
|
||||
|
||||
/**
|
||||
* Gets the buy scaler
|
||||
* @return the buy scaler
|
||||
*/
|
||||
float GetSellScalar() const;
|
||||
|
||||
/**
|
||||
* Sets the sell scalar.
|
||||
* @param value the new value.
|
||||
*/
|
||||
void SetSellScalar(float value);
|
||||
|
||||
/**
|
||||
* True if the NPC LOT is 13800, the only NPC with a crafting station.
|
||||
*/
|
||||
bool HasCraftingStation();
|
||||
|
||||
/**
|
||||
* Gets the list if items the vendor sells.
|
||||
* @return the list of items.
|
||||
*/
|
||||
std::map<LOT, int>& GetInventory();
|
||||
|
||||
/**
|
||||
* Refresh the inventory of this vendor.
|
||||
*/
|
||||
void RefreshInventory(bool isCreation = false);
|
||||
|
||||
/**
|
||||
* Called on startup of vendor to setup the variables for the component.
|
||||
*/
|
||||
void SetupConstants();
|
||||
|
||||
bool SellsItem(const LOT item) const;
|
||||
float GetBuyScalar() const { return m_BuyScalar; }
|
||||
float GetSellScalar() const { return m_SellScalar; }
|
||||
void SetBuyScalar(const float value) { m_BuyScalar = value; }
|
||||
void SetSellScalar(const float value) { m_SellScalar = value; }
|
||||
const std::vector<SoldItem>& GetInventory() { return m_Inventory; }
|
||||
|
||||
void SetHasMultiCostItems(const bool hasMultiCostItems) {
|
||||
if (m_HasMultiCostItems == hasMultiCostItems) return;
|
||||
m_HasMultiCostItems = hasMultiCostItems;
|
||||
m_DirtyVendor = true;
|
||||
}
|
||||
|
||||
void SetHasStandardCostItems(const bool hasStandardCostItems) {
|
||||
if (m_HasStandardCostItems == hasStandardCostItems) return;
|
||||
m_HasStandardCostItems = hasStandardCostItems;
|
||||
m_DirtyVendor = true;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* The buy scalar.
|
||||
*/
|
||||
float m_BuyScalar;
|
||||
|
||||
/**
|
||||
* The sell scalar.
|
||||
*/
|
||||
float m_SellScalar;
|
||||
|
||||
/**
|
||||
* The refresh time of this vendors' inventory.
|
||||
*/
|
||||
float m_RefreshTimeSeconds;
|
||||
|
||||
/**
|
||||
* Loot matrix id of this vendor.
|
||||
*/
|
||||
uint32_t m_LootMatrixID;
|
||||
|
||||
/**
|
||||
* The list of items the vendor sells.
|
||||
*/
|
||||
std::map<LOT, int> m_Inventory;
|
||||
void SetupMaxCustomVendor();
|
||||
void HandleMrReeCameras();
|
||||
float m_BuyScalar = 0.0f;
|
||||
float m_SellScalar = 0.0f;
|
||||
float m_RefreshTimeSeconds = 0.0f;
|
||||
uint32_t m_LootMatrixID = 0;
|
||||
std::vector<SoldItem> m_Inventory;
|
||||
bool m_DirtyVendor = false;
|
||||
bool m_HasStandardCostItems = false;
|
||||
bool m_HasMultiCostItems = false;
|
||||
};
|
||||
|
||||
#endif // VENDORCOMPONENT_H
|
||||
|
||||
Reference in New Issue
Block a user