From fdd98ab8255f4297f19e079acee071f788692c01 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 13 Jun 2023 22:01:51 -0500 Subject: [PATCH] fix other script calls --- dGame/Entity.cpp | 96 +++++-------------- dGame/Player.cpp | 8 +- dGame/dBehaviors/SkillEventBehavior.cpp | 8 +- dGame/dComponents/DestroyableComponent.cpp | 8 +- dGame/dComponents/MovingPlatformComponent.cpp | 8 +- dGame/dComponents/PetComponent.cpp | 20 ++-- .../PropertyManagementComponent.cpp | 4 +- dGame/dComponents/QuickBuildComponent.cpp | 28 ++---- dGame/dComponents/SkillComponent.cpp | 4 +- dGame/dComponents/TriggerComponent.cpp | 4 +- 10 files changed, 52 insertions(+), 136 deletions(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 96b89e53..ee9b863f 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -832,9 +832,7 @@ void Entity::Update(const float deltaTime) { Wake(); } - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnUpdate(this); - } + GetScript()->OnUpdate(this); for (const auto& pair : m_Components) { if (pair.second == nullptr) continue; @@ -851,9 +849,7 @@ void Entity::OnCollisionProximity(LWOOBJID otherEntity, const std::string& proxN Entity* other = EntityManager::Instance()->GetEntity(otherEntity); if (!other) return; - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnProximityUpdate(this, other, proxName, status); - } + GetScript()->OnProximityUpdate(this, other, proxName, status); auto* rocketComp = GetComponent(); if (!rocketComp) return; @@ -865,9 +861,7 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) { auto* other = EntityManager::Instance()->GetEntity(otherEntity); if (!other) return; - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnCollisionPhantom(this, other); - } + GetScript()->OnCollisionPhantom(this, other); for (const auto& callback : m_PhantomCollisionCallbacks) { callback(other); @@ -912,9 +906,7 @@ void Entity::OnCollisionLeavePhantom(const LWOOBJID otherEntity) { auto* other = EntityManager::Instance()->GetEntity(otherEntity); if (!other) return; - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnOffCollisionPhantom(this, other); - } + GetScript()->OnOffCollisionPhantom(this, other); TriggerEvent(eTriggerEventType::EXIT, other); @@ -931,44 +923,32 @@ void Entity::OnCollisionLeavePhantom(const LWOOBJID otherEntity) { } void Entity::OnFireEventServerSide(Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnFireEventServerSide(this, sender, args, param1, param2, param3); - } + GetScript()->OnFireEventServerSide(this, sender, args, param1, param2, param3); } void Entity::OnActivityStateChangeRequest(LWOOBJID senderID, int32_t value1, int32_t value2, const std::u16string& stringValue) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnActivityStateChangeRequest(this, senderID, value1, value2, stringValue); - } + GetScript()->OnActivityStateChangeRequest(this, senderID, value1, value2, stringValue); } void Entity::OnCinematicUpdate(Entity* self, Entity* sender, eCinematicEvent event, const std::u16string& pathName, float_t pathTime, float_t totalTime, int32_t waypoint) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnCinematicUpdate(self, sender, event, pathName, pathTime, totalTime, waypoint); - } + 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); - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnNotifyObject(this, sender, name, param1, param2); - } + GetScript()->OnNotifyObject(this, sender, name, param1, param2); } void Entity::OnEmoteReceived(const int32_t emote, Entity* target) { - for (auto* script : CppScripts::GetEntityScripts(this)) { - script->OnEmoteReceived(this, emote, target); - } + GetScript()->OnEmoteReceived(this, emote, target); } void Entity::OnUse(Entity* originator) { TriggerEvent(eTriggerEventType::INTERACT, originator); - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnUse(this, originator); - } + GetScript()->OnUse(this, originator); // component base class when @@ -980,82 +960,56 @@ void Entity::OnUse(Entity* originator) { } void Entity::OnHitOrHealResult(Entity* attacker, int32_t damage) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnHitOrHealResult(this, attacker, damage); - } + GetScript()->OnHitOrHealResult(this, attacker, damage); } void Entity::OnHit(Entity* attacker) { TriggerEvent(eTriggerEventType::HIT, attacker); - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnHit(this, attacker); - } + GetScript()->OnHit(this, attacker); } void Entity::OnZonePropertyEditBegin() { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyEditBegin(this); - } + GetScript()->OnZonePropertyEditBegin(this); } void Entity::OnZonePropertyEditEnd() { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyEditEnd(this); - } + GetScript()->OnZonePropertyEditEnd(this); } void Entity::OnZonePropertyModelEquipped() { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyModelEquipped(this); - } + GetScript()->OnZonePropertyModelEquipped(this); } void Entity::OnZonePropertyModelPlaced(Entity* player) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyModelPlaced(this, player); - } + GetScript()->OnZonePropertyModelPlaced(this, player); } void Entity::OnZonePropertyModelPickedUp(Entity* player) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyModelPickedUp(this, player); - } + GetScript()->OnZonePropertyModelPickedUp(this, player); } void Entity::OnZonePropertyModelRemoved(Entity* player) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyModelRemoved(this, player); - } + GetScript()->OnZonePropertyModelRemoved(this, player); } void Entity::OnZonePropertyModelRemovedWhileEquipped(Entity* player) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyModelRemovedWhileEquipped(this, player); - } + GetScript()->OnZonePropertyModelRemovedWhileEquipped(this, player); } void Entity::OnZonePropertyModelRotated(Entity* player) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnZonePropertyModelRotated(this, player); - } + GetScript()->OnZonePropertyModelRotated(this, player); } void Entity::OnMessageBoxResponse(Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnMessageBoxResponse(this, sender, button, identifier, userData); - } + GetScript()->OnMessageBoxResponse(this, sender, button, identifier, userData); } void Entity::OnChoiceBoxResponse(Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnChoiceBoxResponse(this, sender, button, buttonIdentifier, identifier); - } + GetScript()->OnChoiceBoxResponse(this, sender, button, buttonIdentifier, identifier); } void Entity::RequestActivityExit(Entity* sender, const LWOOBJID& player, const bool canceled) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnRequestActivityExit(sender, player, canceled); - } + GetScript()->OnRequestActivityExit(sender, player, canceled); } void Entity::Smash(const LWOOBJID source, const eKillType killType, const std::u16string& deathType) { @@ -1088,9 +1042,7 @@ void Entity::Kill(Entity* murderer) { //OMAI WA MOU, SHINDERIU - for (CppScripts::Script* script : CppScripts::GetEntityScripts(this)) { - script->OnDie(this, murderer); - } + GetScript()->OnDie(this, murderer); if (m_Spawner != nullptr) { m_Spawner->NotifyOfEntityDeath(m_ObjectID); diff --git a/dGame/Player.cpp b/dGame/Player.cpp index 77b96b43..98ddb1ca 100644 --- a/dGame/Player.cpp +++ b/dGame/Player.cpp @@ -282,16 +282,12 @@ Player::~Player() { if (IsPlayer()) { Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity(); - for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) { - script->OnPlayerExit(zoneControl, this); - } + zoneControl->GetScript()->OnPlayerExit(zoneControl, this); std::vector scriptedActs = EntityManager::Instance()->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)) { - script->OnPlayerExit(scriptEntity, this); - } + scriptEntity->GetScript()->OnPlayerExit(scriptEntity, this); } } } diff --git a/dGame/dBehaviors/SkillEventBehavior.cpp b/dGame/dBehaviors/SkillEventBehavior.cpp index 837d70c9..77efbf2f 100644 --- a/dGame/dBehaviors/SkillEventBehavior.cpp +++ b/dGame/dBehaviors/SkillEventBehavior.cpp @@ -9,9 +9,7 @@ void SkillEventBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bit auto* caster = EntityManager::Instance()->GetEntity(context->originator); if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) { - script->OnSkillEventFired(target, caster, *this->m_effectHandle); - } + target->GetScript()->OnSkillEventFired(target, caster, *this->m_effectHandle); } } @@ -21,8 +19,6 @@ SkillEventBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitSt auto* caster = EntityManager::Instance()->GetEntity(context->originator); if (caster != nullptr && target != nullptr && this->m_effectHandle != nullptr && !this->m_effectHandle->empty()) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(target)) { - script->OnSkillEventFired(target, caster, *this->m_effectHandle); - } + target->GetScript()->OnSkillEventFired(target, caster, *this->m_effectHandle); } } diff --git a/dGame/dComponents/DestroyableComponent.cpp b/dGame/dComponents/DestroyableComponent.cpp index b35057e6..5e16cde1 100644 --- a/dGame/dComponents/DestroyableComponent.cpp +++ b/dGame/dComponents/DestroyableComponent.cpp @@ -822,16 +822,12 @@ void DestroyableComponent::Smash(const LWOOBJID source, const eKillType killType } Entity* zoneControl = EntityManager::Instance()->GetZoneControlEntity(); - for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControl)) { - script->OnPlayerDied(zoneControl, m_ParentEntity); - } + zoneControl->GetScript()->OnPlayerDied(zoneControl, m_ParentEntity); std::vector scriptedActs = EntityManager::Instance()->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)) { - script->OnPlayerDied(scriptEntity, m_ParentEntity); - } + scriptEntity->GetScript()->OnPlayerDied(scriptEntity, m_ParentEntity); } } } diff --git a/dGame/dComponents/MovingPlatformComponent.cpp b/dGame/dComponents/MovingPlatformComponent.cpp index cf69f816..f7c0cd56 100644 --- a/dGame/dComponents/MovingPlatformComponent.cpp +++ b/dGame/dComponents/MovingPlatformComponent.cpp @@ -183,9 +183,7 @@ void MovingPlatformComponent::StartPathing() { const auto travelNext = subComponent->mWaitTime + travelTime; m_ParentEntity->AddCallbackTimer(travelTime, [subComponent, this] { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnWaypointReached(m_ParentEntity, subComponent->mNextWaypointIndex); - } + m_ParentEntity>GetScript()->OnWaypointReached(m_ParentEntity, subComponent->mNextWaypointIndex); }); m_ParentEntity->AddCallbackTimer(travelNext, [this] { @@ -295,9 +293,7 @@ void MovingPlatformComponent::ContinuePathing() { const auto travelNext = subComponent->mWaitTime + travelTime; m_ParentEntity->AddCallbackTimer(travelTime, [subComponent, this] { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnWaypointReached(m_ParentEntity, subComponent->mNextWaypointIndex); - } + m_ParentEntity->GetScript()->OnWaypointReached(m_ParentEntity, subComponent->mNextWaypointIndex); }); m_ParentEntity->AddCallbackTimer(travelNext, [this] { diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index ea34741a..ba71e8d1 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -317,9 +317,8 @@ void PetComponent::OnUse(Entity* originator) { currentActivities.insert_or_assign(m_Tamer, m_ParentEntity->GetObjectID()); // Notify the start of a pet taming minigame - for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnNotifyPetTamingMinigame(m_ParentEntity, originator, ePetTamingNotifyType::BEGIN); - } + m_ParentEntity->GetScript()->OnNotifyPetTamingMinigame(m_ParentEntity, originator, ePetTamingNotifyType::BEGIN); + } void PetComponent::Update(float deltaTime) { @@ -694,9 +693,8 @@ void PetComponent::RequestSetPetName(std::u16string name) { m_Tamer = LWOOBJID_EMPTY; // Notify the end of a pet taming minigame - for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnNotifyPetTamingMinigame(m_ParentEntity, tamer, ePetTamingNotifyType::SUCCESS); - } + m_ParentEntity->GetScript()->OnNotifyPetTamingMinigame(m_ParentEntity, tamer, ePetTamingNotifyType::SUCCESS); + } void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) { @@ -735,9 +733,8 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) { EntityManager::Instance()->SerializeEntity(m_ParentEntity); // Notify the end of a pet taming minigame - for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnNotifyPetTamingMinigame(m_ParentEntity, tamer, ePetTamingNotifyType::QUIT); - } + m_ParentEntity->GetScript()->OnNotifyPetTamingMinigame(m_ParentEntity, tamer, ePetTamingNotifyType::QUIT); + } void PetComponent::StartTimer() { @@ -786,9 +783,8 @@ void PetComponent::ClientFailTamingMinigame() { EntityManager::Instance()->SerializeEntity(m_ParentEntity); // Notify the end of a pet taming minigame - for (CppScripts::Script* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnNotifyPetTamingMinigame(m_ParentEntity, tamer, ePetTamingNotifyType::FAILED); - } + m_ParentEntity->GetScript()->OnNotifyPetTamingMinigame(m_ParentEntity, tamer, ePetTamingNotifyType::FAILED); + } void PetComponent::Wander() { diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index 99fcc8d9..a8981451 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -241,9 +241,7 @@ bool PropertyManagementComponent::Claim(const LWOOBJID playerId) { } auto* zoneControlObject = dZoneManager::Instance()->GetZoneControlObject(); - for (CppScripts::Script* script : CppScripts::GetEntityScripts(zoneControlObject)) { - script->OnZonePropertyRented(zoneControlObject, entity); - } + zoneControlObject->GetScript()->OnZonePropertyRented(zoneControlObject, entity); return true; } diff --git a/dGame/dComponents/QuickBuildComponent.cpp b/dGame/dComponents/QuickBuildComponent.cpp index aae29e43..f10c62d1 100644 --- a/dGame/dComponents/QuickBuildComponent.cpp +++ b/dGame/dComponents/QuickBuildComponent.cpp @@ -452,15 +452,11 @@ void QuickBuildComponent::StartRebuild(Entity* user) { movingPlatform->OnRebuildInitilized(); } - for (auto* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnRebuildStart(m_ParentEntity, user); - } + m_ParentEntity->GetScript()->OnRebuildStart(m_ParentEntity, user); // Notify scripts and possible subscribers - for (auto* script : CppScripts::GetEntityScripts(m_ParentEntity)) - script->OnRebuildNotifyState(m_ParentEntity, m_State); - for (const auto& cb : m_RebuildStateCallbacks) - cb(m_State); + m_ParentEntity->GetScript()->OnRebuildNotifyState(m_ParentEntity, m_State); + for (const auto& cb : m_RebuildStateCallbacks) cb(m_State); } } @@ -525,10 +521,8 @@ void QuickBuildComponent::CompleteRebuild(Entity* user) { } // Notify scripts - for (auto* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnRebuildComplete(m_ParentEntity, user); - script->OnRebuildNotifyState(m_ParentEntity, m_State); - } + m_ParentEntity->GetScript()->OnRebuildComplete(m_ParentEntity, user); + m_ParentEntity->GetScript()->OnRebuildNotifyState(m_ParentEntity, m_State); // Notify subscribers for (const auto& callback : m_RebuildStateCallbacks) @@ -579,10 +573,8 @@ void QuickBuildComponent::ResetRebuild(bool failed) { EntityManager::Instance()->SerializeEntity(m_ParentEntity); // Notify scripts and possible subscribers - for (auto* script : CppScripts::GetEntityScripts(m_ParentEntity)) - script->OnRebuildNotifyState(m_ParentEntity, m_State); - for (const auto& cb : m_RebuildStateCallbacks) - cb(m_State); + m_ParentEntity->GetScript()->OnRebuildNotifyState(m_ParentEntity, m_State); + for (const auto& cb : m_RebuildStateCallbacks) cb(m_State); m_ParentEntity->ScheduleKillAfterUpdate(); @@ -611,10 +603,8 @@ void QuickBuildComponent::CancelRebuild(Entity* entity, eQuickBuildFailReason fa m_StateDirty = true; // Notify scripts and possible subscribers - for (auto* script : CppScripts::GetEntityScripts(m_ParentEntity)) - script->OnRebuildNotifyState(m_ParentEntity, m_State); - for (const auto& cb : m_RebuildStateCallbacks) - cb(m_State); + m_ParentEntity->GetScript()->OnRebuildNotifyState(m_ParentEntity, m_State); + for (const auto& cb : m_RebuildStateCallbacks) cb(m_State); EntityManager::Instance()->SerializeEntity(m_ParentEntity); } diff --git a/dGame/dComponents/SkillComponent.cpp b/dGame/dComponents/SkillComponent.cpp index 36dca7d1..5f06c770 100644 --- a/dGame/dComponents/SkillComponent.cpp +++ b/dGame/dComponents/SkillComponent.cpp @@ -268,9 +268,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, c behavior->Calculate(context, bitStream, { target, 0 }); - for (auto* script : CppScripts::GetEntityScripts(m_ParentEntity)) { - script->OnSkillCast(m_ParentEntity, skillId); - } + m_ParentEntity->GetScript()->OnSkillCast(m_ParentEntity, skillId); if (!context->foundTarget) { delete bitStream; diff --git a/dGame/dComponents/TriggerComponent.cpp b/dGame/dComponents/TriggerComponent.cpp index d41803f4..ee5900a1 100644 --- a/dGame/dComponents/TriggerComponent.cpp +++ b/dGame/dComponents/TriggerComponent.cpp @@ -184,9 +184,7 @@ std::vector TriggerComponent::GatherTargets(LUTriggers::Command* comman } void TriggerComponent::HandleFireEvent(Entity* targetEntity, std::string args) { - for (CppScripts::Script* script : CppScripts::GetEntityScripts(targetEntity)) { - script->OnFireEventServerSide(targetEntity, m_ParentEntity, args, 0, 0, 0); - } + targetEntity->GetScript()->OnFireEventServerSide(targetEntity, m_ParentEntity, args, 0, 0, 0); } void TriggerComponent::HandleDestroyObject(Entity* targetEntity, std::string args){