diff --git a/CMakeLists.txt b/CMakeLists.txt index 41d4219f..4675dbfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,7 +305,7 @@ file( file( GLOB HEADERS_DGAME LIST_DIRECTORIES false - ${PROJECT_SOURCE_DIR}/dGame/Entity.h + ${PROJECT_SOURCE_DIR}/dGame/dEntity/Entity.h ${PROJECT_SOURCE_DIR}/dGame/dGameMessages/GameMessages.h ${PROJECT_SOURCE_DIR}/dGame/EntityManager.h ${PROJECT_SOURCE_DIR}/dScripts/CppScripts.h diff --git a/dGame/CMakeLists.txt b/dGame/CMakeLists.txt index 80f16042..c7b5e82c 100644 --- a/dGame/CMakeLists.txt +++ b/dGame/CMakeLists.txt @@ -1,5 +1,4 @@ set(DGAME_SOURCES "Character.cpp" - "Entity.cpp" "EntityManager.cpp" "LeaderboardManager.cpp" "Player.cpp" diff --git a/dGame/Player.cpp b/dGame/Player.cpp index 98ddb1ca..0db57ce9 100644 --- a/dGame/Player.cpp +++ b/dGame/Player.cpp @@ -247,7 +247,7 @@ const std::vector& Player::GetAllPlayers() { return m_Players; } -uint64_t Player::GetDroppedCoins() { +uint64_t Player::GetDroppedCoins() const { return m_DroppedCoins; } diff --git a/dGame/Player.h b/dGame/Player.h index 1ae41b9c..591b298e 100644 --- a/dGame/Player.h +++ b/dGame/Player.h @@ -36,7 +36,7 @@ public: std::map& GetDroppedLoot(); - uint64_t GetDroppedCoins(); + uint64_t GetDroppedCoins() const; /** * Setters diff --git a/dGame/dEntity/CMakeLists.txt b/dGame/dEntity/CMakeLists.txt index 4bb49799..e1f28ee4 100644 --- a/dGame/dEntity/CMakeLists.txt +++ b/dGame/dEntity/CMakeLists.txt @@ -1,2 +1,5 @@ -set(DGAME_DENTITY_SOURCES "EntityCallbackTimer.cpp" - "EntityTimer.cpp" PARENT_SCOPE) +set(DGAME_DENTITY_SOURCES + "Entity.cpp" + "EntityCallbackTimer.cpp" + "EntityTimer.cpp" + PARENT_SCOPE) diff --git a/dGame/Entity.cpp b/dGame/dEntity/Entity.cpp similarity index 92% rename from dGame/Entity.cpp rename to dGame/dEntity/Entity.cpp index 62278163..9d51c702 100644 --- a/dGame/Entity.cpp +++ b/dGame/dEntity/Entity.cpp @@ -905,8 +905,12 @@ void Entity::OnCinematicUpdate(Entity* self, Entity* sender, eCinematicEvent eve GetScript()->OnCinematicUpdate(self, sender, event, pathName, pathTime, totalTime, waypoint); } -void Entity::NotifyObject(Entity* sender, const std::string& name, int32_t param1, int32_t param2) { - GameMessages::SendNotifyObject(GetObjectID(), sender->GetObjectID(), GeneralUtils::ASCIIToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS); +void Entity::CancelCallbackTimers() { + m_CallbackTimers.clear(); +} + +void Entity::NotifyObject(Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { + GameMessages::SendNotifyObject(GetObjectID(), sender->GetObjectID(), name, UNASSIGNED_SYSTEM_ADDRESS, param1, param2); GetScript()->OnNotifyObject(this, sender, name, param1, param2); } @@ -1037,22 +1041,13 @@ void Entity::Kill(Entity* murderer) { } // Track a player smashing something else - if (murderer) { - auto* murdererCharacterComponent = murderer->GetComponent(); - if (murdererCharacterComponent) { - murdererCharacterComponent->UpdatePlayerStatistic(SmashablesSmashed); - } + if (!murderer) return; + auto* murdererCharacterComponent = murderer->GetComponent(); + if (murdererCharacterComponent) { + murdererCharacterComponent->UpdatePlayerStatistic(SmashablesSmashed); } } -void Entity::AddDieCallback(const std::function& callback) { - m_DieCallbacks.push_back(callback); -} - -void Entity::AddCollisionPhantomCallback(const std::function& callback) { - m_PhantomCollisionCallbacks.push_back(callback); -} - void Entity::AddRebuildCompleteCallback(const std::function& callback) const { auto* quickBuildComponent = GetComponent(); if (quickBuildComponent) quickBuildComponent->AddRebuildCompleteCallback(callback); @@ -1063,11 +1058,10 @@ bool Entity::GetIsDead() const { return dest && dest->GetArmor() == 0 && dest->GetHealth() == 0; } -// Replace static_cast with dynamic_cast void Entity::AddLootItem(const Loot::Info& info) { if (!IsPlayer()) return; - auto& droppedLoot = static_cast(this)->GetDroppedLoot(); - droppedLoot.insert(std::make_pair(info.id, info)); + auto* player = dynamic_cast(this); + if (player) player->GetDroppedLoot().insert(std::make_pair(info.id, info)); // Move this to Player } // Replace static_cast with dynamic_cast @@ -1079,73 +1073,80 @@ void Entity::PickupItem(const LWOOBJID& objectID) { auto* objectsTable = CDClientManager::Instance().GetTable(); auto* skillsTable = CDClientManager::Instance().GetTable(); - auto& droppedLoot = static_cast(this)->GetDroppedLoot(); + auto* player = dynamic_cast(this); + if (!player) return; + auto& droppedLoot = player->GetDroppedLoot(); - // See if there is some faster way to do this. - for (const auto& [lootObjId, loot] : droppedLoot) { - if (lootObjId != objectID) continue; - auto* characterComponent = GetComponent(); - if (characterComponent) characterComponent->TrackLOTCollection(loot.lot); + auto lootIterator = droppedLoot.find(objectID); + if (lootIterator == droppedLoot.end()) return; + const auto& [objId, loot] = *lootIterator; - const CDObjects& object = objectsTable->GetByID(loot.lot); - if (object.id != 0 && object.type == "Powerup") { - const auto lootLot = loot.lot; - auto skills = skillsTable->Query([lootLot](CDObjectSkills entry) {return (entry.objectTemplate == lootLot); }); - for (const auto& skill : skills) { - auto* skillBehaviorTable = CDClientManager::Instance().GetTable(); - auto behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID); - // This should take a skillID, not a behaviorID. - SkillComponent::HandleUnmanaged(behaviorData.behaviorID, GetObjectID()); + auto* characterComponent = GetComponent(); + if (characterComponent) characterComponent->TrackLOTCollection(loot.lot); - auto* missionComponent = GetComponent(); + const CDObjects& object = objectsTable->GetByID(loot.lot); + if (object.id != 0 && object.type == "Powerup") { + const auto lootLot = loot.lot; + auto skills = skillsTable->Query([lootLot](CDObjectSkills entry) { return (entry.objectTemplate == lootLot); }); + auto* skillBehaviorTable = CDClientManager::Instance().GetTable(); + for (const auto& skill : skills) { + auto behaviorData = skillBehaviorTable->GetSkillByID(skill.skillID); + // This should take a skillID, not a behaviorID. + SkillComponent::HandleUnmanaged(behaviorData.behaviorID, GetObjectID()); - if (missionComponent) missionComponent->Progress(eMissionTaskType::POWERUP, skill.skillID); - } - } else { - inventoryComponent->AddItem(loot.lot, loot.count, eLootSourceType::PICKUP, eInventoryType::INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, eInventoryType::INVALID, 1); + auto* missionComponent = GetComponent(); + + if (missionComponent) missionComponent->Progress(eMissionTaskType::POWERUP, skill.skillID); } + } else { + inventoryComponent->AddItem(loot.lot, loot.count, eLootSourceType::PICKUP, eInventoryType::INVALID, {}, LWOOBJID_EMPTY, true, false, LWOOBJID_EMPTY, eInventoryType::INVALID, 1); } - droppedLoot.erase(objectID); + droppedLoot.erase(lootIterator); } // This functions name is misleading and should not modify the number of dropped coins. // A separate function, PickupCoins should modify that. // Replace static_cast with dynamic_cast -bool Entity::CanPickupCoins(const uint64_t& count) { +bool Entity::CanPickupCoins(const uint64_t& count) const { if (!IsPlayer()) return false; - auto* player = static_cast(this); - auto droppedCoins = player->GetDroppedCoins(); - if (count > droppedCoins) { - return false; - } else { - player->SetDroppedCoins(droppedCoins - count); - return true; - } + const auto* player = dynamic_cast(this); + return count <= player->GetDroppedCoins(); +} + +void Entity::PickupCoins(const uint64_t& count) { + if (!IsPlayer()) return; + auto* player = dynamic_cast(this); + if (!player) return; + const auto droppedCoins = player->GetDroppedCoins(); + if (count <= droppedCoins) player->SetDroppedCoins(droppedCoins - count); } -// Replace static_cast with dynamic_cast void Entity::RegisterCoinDrop(const uint64_t& coinsDropped) { if (!IsPlayer()) return; - auto* player = static_cast(this); + auto* player = dynamic_cast(this); + if (!player) return; player->SetDroppedCoins(player->GetDroppedCoins() + coinsDropped); } void Entity::AddChild(Entity* child) { m_IsParentChildDirty = true; - if (std::find(m_ChildEntities.begin(), m_ChildEntities.end(), child) == m_ChildEntities.end()) m_ChildEntities.push_back(child); + if (std::find(m_ChildEntities.begin(), m_ChildEntities.end(), child) != m_ChildEntities.end()) return; + m_ChildEntities.push_back(child); } void Entity::RemoveChild(Entity* child) { if (!child) return; uint32_t entityPosition = 0; auto toRemove = std::remove(m_ChildEntities.begin(), m_ChildEntities.end(), child); - if (toRemove != m_ChildEntities.end()) m_IsParentChildDirty = true; - m_ChildEntities.erase(toRemove, m_ChildEntities.end()); + if (toRemove != m_ChildEntities.end()) { + m_ChildEntities.erase(toRemove, m_ChildEntities.end()); + m_IsParentChildDirty = true; + } } void Entity::RemoveParent() { if (m_ParentEntity) m_IsParentChildDirty = true; - else Game::logger->Log("Entity", "Attempted to remove parent from(objid:lot) (%llu:%i) when no parent existed", GetObjectID(), GetLOT()); + else Game::logger->Log("Entity", "WARNING: Attempted to remove parent from(objid:lot) (%llu:%i) when no parent existed", GetObjectID(), GetLOT()); this->m_ParentEntity = nullptr; } @@ -1164,13 +1165,8 @@ bool Entity::HasTimer(const std::string& name) { return possibleTimer != m_Timers.end(); } -void Entity::CancelCallbackTimers() { - m_CallbackTimers.clear(); -} - void Entity::ScheduleKillAfterUpdate(Entity* murderer) { EntityManager::Instance()->ScheduleForKill(this); - if (murderer) m_ScheduleKiller = murderer; } @@ -1180,10 +1176,10 @@ void Entity::CancelTimer(const std::string& name) { }); m_Timers.erase(m_Timers.begin(), toErase); } -// ### LEFT OFF HERE ### + void Entity::CancelAllTimers() { m_Timers.clear(); - m_CallbackTimers.clear(); + CancelCallbackTimers(); } bool Entity::IsPlayer() const { @@ -1207,22 +1203,8 @@ Entity* Entity::GetOwner() const { return const_cast(this); } -const NiPoint3& Entity::GetDefaultPosition() const { - return m_DefaultPosition; -} - -const NiQuaternion& Entity::GetDefaultRotation() const { - return m_DefaultRotation; -} - -void Entity::SetOwnerOverride(const LWOOBJID& value) { - m_OwnerOverride = value; -} - void Entity::SetObservers(int8_t value) { - if (value < 0) { - value = 0; - } + if (value < 0) value = 0; m_Observers = value; } @@ -1241,7 +1223,7 @@ bool Entity::IsSleeping() const { return m_IsGhostingCandidate && m_Observers == 0; } - +// The following 3 should share a base component class so we can else if it. const NiPoint3& Entity::GetPosition() const { auto* controllablePhysicsComponent = GetComponent(); @@ -1354,36 +1336,6 @@ void Entity::SetRotation(const NiQuaternion& rotation) { EntityManager::Instance()->SerializeEntity(this); } -// Move to header -bool Entity::GetBoolean(const std::u16string& name) const { - return GetVar(name); -} - -// Move to header -int32_t Entity::GetI32(const std::u16string& name) const { - return GetVar(name); -} - -// Move to header -int64_t Entity::GetI64(const std::u16string& name) const { - return GetVar(name); -} - -// Move to header -void Entity::SetBoolean(const std::u16string& name, const bool value) { - SetVar(name, value); -} - -// Move to header -void Entity::SetI32(const std::u16string& name, const int32_t value) { - SetVar(name, value); -} - -// Move to header -void Entity::SetI64(const std::u16string& name, const int64_t value) { - SetVar(name, value); -} - bool Entity::HasVar(const std::u16string& name) const { auto hasVar = std::find_if(m_Settings.begin(), m_Settings.end(), [&name](const LDFBaseData* data) { return data->GetKey() == name; @@ -1391,11 +1343,6 @@ bool Entity::HasVar(const std::u16string& name) const { return hasVar != m_Settings.end(); } -// Move to header -void Entity::SetNetworkId(const uint16_t id) { - m_NetworkID = id; -} - std::vector& Entity::GetTargetsInPhantom() { auto toRemove = std::remove_if(m_TargetsInPhantom.begin(), m_TargetsInPhantom.end(), [this](const LWOOBJID& id) { return EntityManager::Instance()->GetEntity(id) == nullptr; diff --git a/dGame/Entity.h b/dGame/dEntity/Entity.h similarity index 90% rename from dGame/Entity.h rename to dGame/dEntity/Entity.h index c4444d97..0b905730 100644 --- a/dGame/Entity.h +++ b/dGame/dEntity/Entity.h @@ -2,6 +2,7 @@ #define __ENTITY__H__ #include +#include #include #include @@ -110,14 +111,14 @@ public: void SetObservers(const int8_t value); const uint16_t GetNetworkId() const { return m_NetworkID; } - void SetNetworkId(const uint16_t id); + void SetNetworkId(const uint16_t id) { m_NetworkID = id; } Entity* GetOwner() const; - void SetOwnerOverride(const LWOOBJID& value); + void SetOwnerOverride(const LWOOBJID& value) { m_OwnerOverride = value; }; - const NiPoint3& GetDefaultPosition() const; + const NiPoint3& GetDefaultPosition() const { return m_DefaultPosition; }; - const NiQuaternion& GetDefaultRotation() const; + const NiQuaternion& GetDefaultRotation() const { return m_DefaultRotation; }; const float GetDefaultScale() const { return m_Scale; } @@ -178,7 +179,7 @@ public: void OnCinematicUpdate(Entity* self, Entity* sender, const eCinematicEvent event, const std::u16string& pathName, const float pathTime, const float totalTime, const int32_t waypoint); - void NotifyObject(Entity* sender, const std::string& name, const int32_t param1 = 0, const int32_t param2 = 0); + void NotifyObject(Entity* sender, const std::u16string& name, const int32_t param1 = 0, const int32_t param2 = 0); void OnEmoteReceived(const int32_t emote, Entity* target); void OnUse(Entity* originator); @@ -202,14 +203,15 @@ public: void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u""); void Kill(Entity* murderer = nullptr); void AddRebuildCompleteCallback(const std::function& callback) const; - void AddCollisionPhantomCallback(const std::function& callback); - void AddDieCallback(const std::function& callback); + void AddCollisionPhantomCallback(const std::function& callback) { m_PhantomCollisionCallbacks.push_back(callback); }; + void AddDieCallback(const std::function& callback) { m_DieCallbacks.push_back(callback); }; void Resurrect(); void AddLootItem(const Loot::Info& info); void PickupItem(const LWOOBJID& objectID); - bool CanPickupCoins(const uint64_t& count); + bool CanPickupCoins(const uint64_t& count) const; + void PickupCoins(const uint64_t& count); void RegisterCoinDrop(const uint64_t& count); void ScheduleKillAfterUpdate(Entity* murderer = nullptr); @@ -230,13 +232,13 @@ public: //Retroactively corrects the model vault size due to incorrect initialization in a previous patch. void RetroactiveVaultSize(); - bool GetBoolean(const std::u16string& name) const; - int32_t GetI32(const std::u16string& name) const; - int64_t GetI64(const std::u16string& name) const; + bool GetBoolean(const std::u16string& name) const { return GetVar(name); }; + int32_t GetI32(const std::u16string& name) const { return GetVar(name); }; + int64_t GetI64(const std::u16string& name) const { return GetVar(name); }; - void SetBoolean(const std::u16string& name, bool value); - void SetI32(const std::u16string& name, int32_t value); - void SetI64(const std::u16string& name, int64_t value); + void SetBoolean(const std::u16string& name, bool value) { SetVar(name, value); } + void SetI32(const std::u16string& name, int32_t value) { SetVar(name, value); }; + void SetI64(const std::u16string& name, int64_t value) { SetVar(name, value); }; bool HasVar(const std::u16string& name) const; diff --git a/dGame/Entity.tcc b/dGame/dEntity/Entity.tcc similarity index 100% rename from dGame/Entity.tcc rename to dGame/dEntity/Entity.tcc diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index dfda8be6..55d6ed73 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5318,6 +5318,7 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent auto* ch = entity->GetCharacter(); if (entity->CanPickupCoins(currency)) { + entity->PickupCoins(currency); ch->SetCoins(ch->GetCoins() + currency, eLootSourceType::PICKUP); } } diff --git a/dScripts/02_server/Map/AM/AmBridge.cpp b/dScripts/02_server/Map/AM/AmBridge.cpp index 719ca058..c0c0a926 100644 --- a/dScripts/02_server/Map/AM/AmBridge.cpp +++ b/dScripts/02_server/Map/AM/AmBridge.cpp @@ -1,5 +1,6 @@ #include "AmBridge.h" #include "EntityManager.h" +#include "Entity.h" void AmBridge::OnStartup(Entity* self) { @@ -14,7 +15,7 @@ void AmBridge::OnRebuildComplete(Entity* self, Entity* target) { auto* console = consoles[0]; - console->NotifyObject(self, "BridgeBuilt"); + console->NotifyObject(self, u"BridgeBuilt"); self->AddTimer("SmashBridge", 50); } diff --git a/dScripts/02_server/Map/AM/AmDrawBridge.cpp b/dScripts/02_server/Map/AM/AmDrawBridge.cpp index 3c4dcce6..ccbd9a6f 100644 --- a/dScripts/02_server/Map/AM/AmDrawBridge.cpp +++ b/dScripts/02_server/Map/AM/AmDrawBridge.cpp @@ -3,6 +3,7 @@ #include "GameMessages.h" #include "SimplePhysicsComponent.h" #include "eTerminateType.h" +#include "Entity.h" void AmDrawBridge::OnStartup(Entity* self) { self->SetNetworkVar(u"InUse", false); @@ -72,8 +73,8 @@ void AmDrawBridge::OnTimerDone(Entity* self, std::string timerName) { } } -void AmDrawBridge::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { - if (name == "BridgeBuilt") { +void AmDrawBridge::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { + if (name == u"BridgeBuilt") { self->SetVar(u"BridgeID", sender->GetObjectID()); self->AddTimer("SmashEffectBridge", 45); diff --git a/dScripts/02_server/Map/AM/AmDrawBridge.h b/dScripts/02_server/Map/AM/AmDrawBridge.h index 86237b7f..b61786f5 100644 --- a/dScripts/02_server/Map/AM/AmDrawBridge.h +++ b/dScripts/02_server/Map/AM/AmDrawBridge.h @@ -7,7 +7,7 @@ public: void OnStartup(Entity* self) override; void OnUse(Entity* self, Entity* user) override; void OnTimerDone(Entity* self, std::string timerName) override; - void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1 = 0, int32_t param2 = 0) override; void MoveBridgeDown(Entity* self, Entity* bridge, bool down); void NotifyDie(Entity* self, Entity* other); diff --git a/dScripts/02_server/Map/AM/AmSkullkinDrillStand.cpp b/dScripts/02_server/Map/AM/AmSkullkinDrillStand.cpp index 5493dc24..1961f1c8 100644 --- a/dScripts/02_server/Map/AM/AmSkullkinDrillStand.cpp +++ b/dScripts/02_server/Map/AM/AmSkullkinDrillStand.cpp @@ -10,7 +10,7 @@ void AmSkullkinDrillStand::OnStartup(Entity* self) { self->SetProximityRadius(new dpEntity(self->GetObjectID(), { 6, 14, 6 }), "knockback"); } -void AmSkullkinDrillStand::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { +void AmSkullkinDrillStand::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { } diff --git a/dScripts/02_server/Map/AM/AmSkullkinDrillStand.h b/dScripts/02_server/Map/AM/AmSkullkinDrillStand.h index 673dee05..61ddade8 100644 --- a/dScripts/02_server/Map/AM/AmSkullkinDrillStand.h +++ b/dScripts/02_server/Map/AM/AmSkullkinDrillStand.h @@ -6,7 +6,7 @@ class AmSkullkinDrillStand : public CppScripts::Script public: void OnStartup(Entity* self) override; - void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1 = 0, int32_t param2 = 0) override; void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) override; }; diff --git a/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.cpp b/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.cpp index a4c29d2a..752faf7b 100644 --- a/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.cpp +++ b/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.cpp @@ -1,6 +1,7 @@ #include "NjRailPostServer.h" #include "QuickBuildComponent.h" #include "EntityManager.h" +#include "Entity.h" void NjRailPostServer::OnStartup(Entity* self) { auto* quickBuildComponent = self->GetComponent(); @@ -9,11 +10,11 @@ void NjRailPostServer::OnStartup(Entity* self) { } } -void NjRailPostServer::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, +void NjRailPostServer::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { - if (name == "PostRebuilt") { + if (name == u"PostRebuilt") { self->SetNetworkVar(NetworkNotActiveVariable, false); - } else if (name == "PostDied") { + } else if (name == u"PostDied") { self->SetNetworkVar(NetworkNotActiveVariable, true); } } @@ -24,7 +25,7 @@ void NjRailPostServer::OnRebuildNotifyState(Entity* self, eRebuildState state) { if (relatedRail == nullptr) return; - relatedRail->NotifyObject(self, "PostRebuilt"); + relatedRail->NotifyObject(self, u"PostRebuilt"); if (self->GetVar(NotActiveVariable)) return; @@ -35,7 +36,7 @@ void NjRailPostServer::OnRebuildNotifyState(Entity* self, eRebuildState state) { if (relatedRail == nullptr) return; - relatedRail->NotifyObject(self, "PostDied"); + relatedRail->NotifyObject(self, u"PostDied"); } } diff --git a/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.h b/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.h index 3486db87..87f1e234 100644 --- a/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.h +++ b/dScripts/02_server/Map/General/Ninjago/NjRailPostServer.h @@ -3,7 +3,7 @@ class NjRailPostServer : public CppScripts::Script { void OnStartup(Entity* self) override; - void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) override; void OnRebuildNotifyState(Entity* self, eRebuildState state) override; private: Entity* GetRelatedRail(Entity* self); diff --git a/dScripts/02_server/Map/njhub/CatapultBaseServer.cpp b/dScripts/02_server/Map/njhub/CatapultBaseServer.cpp index 270e7f40..051f265c 100644 --- a/dScripts/02_server/Map/njhub/CatapultBaseServer.cpp +++ b/dScripts/02_server/Map/njhub/CatapultBaseServer.cpp @@ -4,8 +4,8 @@ #include "Entity.h" #include "RenderComponent.h" -void CatapultBaseServer::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { - if (name == "BouncerBuilt") { +void CatapultBaseServer::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { + if (name == u"BouncerBuilt") { // start a timer for the arm to player the with bouncer animation self->AddTimer("PlatAnim", .75); @@ -46,7 +46,7 @@ void CatapultBaseServer::OnTimerDone(Entity* self, std::string timerName) { if (bouncer == nullptr) return; // bounce all players - bouncer->NotifyObject(bouncer, "bounceAllInProximity"); // Likely to trigger server side bounce, bodging this + bouncer->NotifyObject(bouncer, u"bounceAllInProximity"); // Likely to trigger server side bounce, bodging this // add a delay to play the animation self->AddTimer("launchAnim", .3); } else if (timerName == "resetArm") { diff --git a/dScripts/02_server/Map/njhub/CatapultBaseServer.h b/dScripts/02_server/Map/njhub/CatapultBaseServer.h index cc5a1907..471805d1 100644 --- a/dScripts/02_server/Map/njhub/CatapultBaseServer.h +++ b/dScripts/02_server/Map/njhub/CatapultBaseServer.h @@ -3,7 +3,7 @@ class CatapultBaseServer : public CppScripts::Script { public: - void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1 = 0, int32_t param2 = 0) override; void OnTimerDone(Entity* self, std::string timerName) override; }; diff --git a/dScripts/02_server/Map/njhub/CatapultBouncerServer.cpp b/dScripts/02_server/Map/njhub/CatapultBouncerServer.cpp index 89faf001..f9cb5d12 100644 --- a/dScripts/02_server/Map/njhub/CatapultBouncerServer.cpp +++ b/dScripts/02_server/Map/njhub/CatapultBouncerServer.cpp @@ -1,6 +1,7 @@ #include "CatapultBouncerServer.h" #include "GameMessages.h" #include "EntityManager.h" +#include "Entity.h" void CatapultBouncerServer::OnRebuildComplete(Entity* self, Entity* target) { GameMessages::SendNotifyClientObject(self->GetObjectID(), u"Built", 0, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS); @@ -10,6 +11,6 @@ void CatapultBouncerServer::OnRebuildComplete(Entity* self, Entity* target) { const auto base = EntityManager::Instance()->GetEntitiesInGroup(self->GetVarAsString(u"BaseGroup")); for (auto* obj : base) { - obj->NotifyObject(self, "BouncerBuilt"); + obj->NotifyObject(self, u"BouncerBuilt"); } } diff --git a/dScripts/CppScripts.h b/dScripts/CppScripts.h index 6bfff464..d5c398c1 100644 --- a/dScripts/CppScripts.h +++ b/dScripts/CppScripts.h @@ -12,11 +12,9 @@ class InvalidScript; enum class eMissionState : int32_t; enum class ePetTamingNotifyType : uint32_t; enum class eRebuildState : uint32_t; +enum class eCinematicEvent : uint32_t; namespace CppScripts { - - extern std::unique_ptr invalidScript; - extern std::map m_Scripts; /** * Base class for all scripts. Includes virtual methods to be overridden to handle LUA equivelent events. * @@ -76,7 +74,7 @@ namespace CppScripts { * * Equivalent to 'function onNotifyObject(self, msg)' */ - virtual void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) {}; + virtual void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1 = 0, int32_t param2 = 0) {}; /** * Invoked upon a player exiting the modular build minigame. @@ -363,6 +361,8 @@ namespace CppScripts { */ virtual void OnRequestActivityExit(Entity* sender, LWOOBJID player, bool canceled) {}; }; - Script* GetScript(Entity* parent, const std::string& scriptName); + + extern std::unique_ptr invalidScript; + extern std::map m_Scripts; }; diff --git a/dScripts/ai/FV/FvConsoleLeftQuickbuild.cpp b/dScripts/ai/FV/FvConsoleLeftQuickbuild.cpp index 3f495ed7..08804287 100644 --- a/dScripts/ai/FV/FvConsoleLeftQuickbuild.cpp +++ b/dScripts/ai/FV/FvConsoleLeftQuickbuild.cpp @@ -3,6 +3,7 @@ #include "GameMessages.h" #include "eTerminateType.h" #include "eRebuildState.h" +#include "Entity.h" void FvConsoleLeftQuickbuild::OnStartup(Entity* self) { self->SetVar(u"IAmBuilt", false); @@ -16,7 +17,7 @@ void FvConsoleLeftQuickbuild::OnRebuildNotifyState(Entity* self, eRebuildState s const auto objects = EntityManager::Instance()->GetEntitiesInGroup("Facility"); if (!objects.empty()) { - objects[0]->NotifyObject(self, "ConsoleLeftUp"); + objects[0]->NotifyObject(self, u"ConsoleLeftUp"); } } else if (state == eRebuildState::RESETTING) { self->SetVar(u"IAmBuilt", false); @@ -25,7 +26,7 @@ void FvConsoleLeftQuickbuild::OnRebuildNotifyState(Entity* self, eRebuildState s const auto objects = EntityManager::Instance()->GetEntitiesInGroup("Facility"); if (!objects.empty()) { - objects[0]->NotifyObject(self, "ConsoleLeftDown"); + objects[0]->NotifyObject(self, u"ConsoleLeftDown"); } } } @@ -41,7 +42,7 @@ void FvConsoleLeftQuickbuild::OnUse(Entity* self, Entity* user) { const auto objects = EntityManager::Instance()->GetEntitiesInGroup("Facility"); if (!objects.empty()) { - objects[0]->NotifyObject(self, "ConsoleLeftActive"); + objects[0]->NotifyObject(self, u"ConsoleLeftActive"); } } diff --git a/dScripts/ai/FV/FvConsoleRightQuickbuild.cpp b/dScripts/ai/FV/FvConsoleRightQuickbuild.cpp index e03e4135..7d42a702 100644 --- a/dScripts/ai/FV/FvConsoleRightQuickbuild.cpp +++ b/dScripts/ai/FV/FvConsoleRightQuickbuild.cpp @@ -3,6 +3,7 @@ #include "GameMessages.h" #include "eTerminateType.h" #include "eRebuildState.h" +#include "Entity.h" void FvConsoleRightQuickbuild::OnStartup(Entity* self) { self->SetVar(u"IAmBuilt", false); @@ -16,7 +17,7 @@ void FvConsoleRightQuickbuild::OnRebuildNotifyState(Entity* self, eRebuildState const auto objects = EntityManager::Instance()->GetEntitiesInGroup("Facility"); if (!objects.empty()) { - objects[0]->NotifyObject(self, "ConsoleRightUp"); + objects[0]->NotifyObject(self, u"ConsoleRightUp"); } } else if (state == eRebuildState::RESETTING) { self->SetVar(u"IAmBuilt", false); @@ -25,7 +26,7 @@ void FvConsoleRightQuickbuild::OnRebuildNotifyState(Entity* self, eRebuildState const auto objects = EntityManager::Instance()->GetEntitiesInGroup("Facility"); if (!objects.empty()) { - objects[0]->NotifyObject(self, "ConsoleRightDown"); + objects[0]->NotifyObject(self, u"ConsoleRightDown"); } } } @@ -41,7 +42,7 @@ void FvConsoleRightQuickbuild::OnUse(Entity* self, Entity* user) { const auto objects = EntityManager::Instance()->GetEntitiesInGroup("Facility"); if (!objects.empty()) { - objects[0]->NotifyObject(self, "ConsoleRightActive"); + objects[0]->NotifyObject(self, u"ConsoleRightActive"); } } diff --git a/dScripts/ai/FV/FvFacilityBrick.cpp b/dScripts/ai/FV/FvFacilityBrick.cpp index 6ff12750..43bd8a70 100644 --- a/dScripts/ai/FV/FvFacilityBrick.cpp +++ b/dScripts/ai/FV/FvFacilityBrick.cpp @@ -8,37 +8,37 @@ void FvFacilityBrick::OnStartup(Entity* self) { self->SetVar(u"ConsoleRIGHTtActive", false); } -void FvFacilityBrick::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { +void FvFacilityBrick::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { auto* brickSpawner = dZoneManager::Instance()->GetSpawnersByName("ImaginationBrick")[0]; auto* bugSpawner = dZoneManager::Instance()->GetSpawnersByName("MaelstromBug")[0]; auto* canisterSpawner = dZoneManager::Instance()->GetSpawnersByName("BrickCanister")[0]; - if (name == "ConsoleLeftUp") { + if (name == u"ConsoleLeftUp") { GameMessages::SendStopFXEffect(self, true, "LeftPipeOff"); GameMessages::SendPlayFXEffect(self->GetObjectID(), 2775, u"create", "LeftPipeEnergy"); - } else if (name == "ConsoleLeftDown") { + } else if (name == u"ConsoleLeftDown") { self->SetVar(u"ConsoleLEFTActive", false); GameMessages::SendStopFXEffect(self, true, "LeftPipeEnergy"); GameMessages::SendStopFXEffect(self, true, "LeftPipeOn"); GameMessages::SendPlayFXEffect(self->GetObjectID(), 2774, u"create", "LeftPipeOff"); - } else if (name == "ConsoleLeftActive") { + } else if (name == u"ConsoleLeftActive") { self->SetVar(u"ConsoleLEFTActive", true); GameMessages::SendStopFXEffect(self, true, "LeftPipeEnergy"); GameMessages::SendPlayFXEffect(self->GetObjectID(), 2776, u"create", "LeftPipeOn"); } - else if (name == "ConsoleRightUp") { + else if (name == u"ConsoleRightUp") { GameMessages::SendStopFXEffect(self, true, "RightPipeOff"); GameMessages::SendPlayFXEffect(self->GetObjectID(), 2778, u"create", "RightPipeEnergy"); - } else if (name == "ConsoleRightDown") { + } else if (name == u"ConsoleRightDown") { self->SetVar(u"ConsoleRIGHTActive", false); GameMessages::SendStopFXEffect(self, true, "RightPipeEnergy"); GameMessages::SendStopFXEffect(self, true, "RightPipeOn"); GameMessages::SendPlayFXEffect(self->GetObjectID(), 2777, u"create", "RightPipeOff"); - } else if (name == "ConsoleRightActive") { + } else if (name == u"ConsoleRightActive") { self->SetVar(u"ConsoleRIGHTActive", true); GameMessages::SendStopFXEffect(self, true, "RightPipeOff"); diff --git a/dScripts/ai/FV/FvFacilityBrick.h b/dScripts/ai/FV/FvFacilityBrick.h index c7580c25..834d51ed 100644 --- a/dScripts/ai/FV/FvFacilityBrick.h +++ b/dScripts/ai/FV/FvFacilityBrick.h @@ -5,7 +5,7 @@ class FvFacilityBrick : public CppScripts::Script { public: void OnStartup(Entity* self) override; - void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1 = 0, int32_t param2 = 0) override; void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override; }; diff --git a/dScripts/ai/WILD/WildNinjaBricks.cpp b/dScripts/ai/WILD/WildNinjaBricks.cpp index 243aceea..702b2f38 100644 --- a/dScripts/ai/WILD/WildNinjaBricks.cpp +++ b/dScripts/ai/WILD/WildNinjaBricks.cpp @@ -5,9 +5,9 @@ void WildNinjaBricks::OnStartup(Entity* self) { self->AddToGroups("Ninjastuff"); } -void WildNinjaBricks::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { - if (name == "Crane") GameMessages::SendPlayAnimation(self, u"crane"); - else if (name == "Tiger") GameMessages::SendPlayAnimation(self, u"tiger"); - else if (name == "Mantis") GameMessages::SendPlayAnimation(self, u"mantis"); +void WildNinjaBricks::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { + if (name == u"Crane") GameMessages::SendPlayAnimation(self, u"crane"); + else if (name == u"Tiger") GameMessages::SendPlayAnimation(self, u"tiger"); + else if (name == u"Mantis") GameMessages::SendPlayAnimation(self, u"mantis"); } diff --git a/dScripts/ai/WILD/WildNinjaBricks.h b/dScripts/ai/WILD/WildNinjaBricks.h index 9578e37a..81cda4a4 100644 --- a/dScripts/ai/WILD/WildNinjaBricks.h +++ b/dScripts/ai/WILD/WildNinjaBricks.h @@ -4,6 +4,6 @@ class WildNinjaBricks : public CppScripts::Script { public: void OnStartup(Entity* self) override; - void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1 = 0, int32_t param2 = 0) override; }; diff --git a/dScripts/ai/WILD/WildNinjaSensei.cpp b/dScripts/ai/WILD/WildNinjaSensei.cpp index 42ddfa21..15ceb4d3 100644 --- a/dScripts/ai/WILD/WildNinjaSensei.cpp +++ b/dScripts/ai/WILD/WildNinjaSensei.cpp @@ -9,27 +9,27 @@ void WildNinjaSensei::OnStartup(Entity* self) { void WildNinjaSensei::OnTimerDone(Entity* self, std::string timerName) { if (timerName == "CraneStart") { auto ninjas = EntityManager::Instance()->GetEntitiesInGroup("Ninjastuff"); - for (auto ninja : ninjas) ninja->NotifyObject(self, "Crane"); + for (auto ninja : ninjas) ninja->NotifyObject(self, u"Crane"); self->AddTimer("Bow", 15.5f); self->AddTimer("TigerStart", 25); GameMessages::SendPlayAnimation(self, u"crane"); } else if (timerName == "TigerStart") { auto ninjas = EntityManager::Instance()->GetEntitiesInGroup("Ninjastuff"); GameMessages::SendPlayAnimation(self, u"bow"); - for (auto ninja : ninjas) ninja->NotifyObject(self, "Tiger"); + for (auto ninja : ninjas) ninja->NotifyObject(self, u"Tiger"); self->AddTimer("Bow", 15.5f); self->AddTimer("MantisStart", 25); GameMessages::SendPlayAnimation(self, u"tiger"); } else if (timerName == "MantisStart") { auto ninjas = EntityManager::Instance()->GetEntitiesInGroup("Ninjastuff"); GameMessages::SendPlayAnimation(self, u"tiger"); - for (auto ninja : ninjas) ninja->NotifyObject(self, "Mantis"); + for (auto ninja : ninjas) ninja->NotifyObject(self, u"Mantis"); self->AddTimer("Bow", 15.5f); self->AddTimer("CraneStart", 25); GameMessages::SendPlayAnimation(self, u"mantis"); } else if (timerName == "Bow") { auto ninjas = EntityManager::Instance()->GetEntitiesInGroup("Ninjastuff"); - for (auto ninja : ninjas) ninja->NotifyObject(self, "Bow"); + for (auto ninja : ninjas) ninja->NotifyObject(self, u"Bow"); GameMessages::SendPlayAnimation(self, u"bow"); } } diff --git a/dScripts/ai/WILD/WildNinjaStudent.cpp b/dScripts/ai/WILD/WildNinjaStudent.cpp index 57ac18b1..36115ea6 100644 --- a/dScripts/ai/WILD/WildNinjaStudent.cpp +++ b/dScripts/ai/WILD/WildNinjaStudent.cpp @@ -1,14 +1,15 @@ #include "WildNinjaStudent.h" #include "GameMessages.h" +#include "Entity.h" void WildNinjaStudent::OnStartup(Entity* self) { self->AddToGroups("Ninjastuff"); GameMessages::SendPlayAnimation(self, u"bow"); } -void WildNinjaStudent::OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1, int32_t param2) { - if (name == "Crane") GameMessages::SendPlayAnimation(self, u"crane"); - else if (name == "Tiger") GameMessages::SendPlayAnimation(self, u"tiger"); - else if (name == "Mantis") GameMessages::SendPlayAnimation(self, u"mantis"); - else if (name == "Bow") GameMessages::SendPlayAnimation(self, u"bow"); +void WildNinjaStudent::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { + if (name == u"Crane") GameMessages::SendPlayAnimation(self, u"crane"); + else if (name == u"Tiger") GameMessages::SendPlayAnimation(self, u"tiger"); + else if (name == u"Mantis") GameMessages::SendPlayAnimation(self, u"mantis"); + else if (name == u"Bow") GameMessages::SendPlayAnimation(self, u"bow"); } diff --git a/dScripts/ai/WILD/WildNinjaStudent.h b/dScripts/ai/WILD/WildNinjaStudent.h index b76e5fa5..09ae3318 100644 --- a/dScripts/ai/WILD/WildNinjaStudent.h +++ b/dScripts/ai/WILD/WildNinjaStudent.h @@ -4,6 +4,6 @@ class WildNinjaStudent : public CppScripts::Script { public: void OnStartup(Entity* self) override; - void OnNotifyObject(Entity* self, Entity* sender, const std::string& name, int32_t param1 = 0, int32_t param2 = 0) override; + void OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1 = 0, int32_t param2 = 0) override; };