refactor: removed hardcoded ag laser logic (#1079)

* Removed hardcoded laser logic

* Address feedback
This commit is contained in:
Aaron Kimbrell
2023-05-13 18:21:17 -05:00
committed by GitHub
parent 2117a18d62
commit 9708ea28dc
4 changed files with 30 additions and 65 deletions

View File

@@ -2,56 +2,27 @@
#include "PhantomPhysicsComponent.h"
#include "SkillComponent.h"
#include "EntityManager.h"
#include "AgMonumentLaserServer.h"
#include "EntityManager.h"
#include "ePhysicsEffectType.h"
#include "eReplicaComponentType.h"
void AgLaserSensorServer::OnStartup(Entity* self) {
PhantomPhysicsComponent* physComp = static_cast<PhantomPhysicsComponent*>(self->GetComponent(eReplicaComponentType::PHANTOM_PHYSICS));
physComp->SetPhysicsEffectActive(true);
physComp->SetEffectType(ePhysicsEffectType::REPULSE);
physComp->SetDirectionalMultiplier(static_cast<float>(m_RepelForce));
physComp->SetDirection(NiPoint3::UNIT_Y);
m_Skill = self->GetComponent<SkillComponent>();
self->SetBoolean(u"active", true);
auto repelForce = self->GetVarAs<float>(u"repelForce");
if (!repelForce) repelForce = m_RepelForce;
auto* phantomPhysicsComponent = self->GetComponent<PhantomPhysicsComponent>();
if (!phantomPhysicsComponent) return;
phantomPhysicsComponent->SetPhysicsEffectActive(true);
phantomPhysicsComponent->SetEffectType(ePhysicsEffectType::REPULSE);
phantomPhysicsComponent->SetDirectionalMultiplier(repelForce);
phantomPhysicsComponent->SetDirection(NiPoint3::UNIT_Y);
}
void AgLaserSensorServer::OnCollisionPhantom(Entity* self, Entity* target) {
if (!m_Skill) return;
Entity* laser = nullptr;
for (auto script : EntityManager::Instance()->GetEntitiesByComponent(eReplicaComponentType::SCRIPT)) {
AgMonumentLaserServer* hasLaser = (AgMonumentLaserServer*)script;
if (hasLaser) {
const auto source = script->GetPosition();
const auto obj = self->GetObjectID();
if (obj == 76690936093053 && Vector3::DistanceSquared(source, NiPoint3(149.007f, 417.083f, 218.346f)) <= 1.0f) {
laser = script;
break;
} else if (obj == 75866302318824 && Vector3::DistanceSquared(source, NiPoint3(48.6403f, 403.803f, 196.711f)) <= 1.0f) {
laser = script;
break;
} else if (obj == 75866302318822 && Vector3::DistanceSquared(source, NiPoint3(19.2155f, 420.083f, 249.226f)) <= 1.0f) {
laser = script;
break;
} else if (obj == 75866302318823 && Vector3::DistanceSquared(source, NiPoint3(-6.61596f, 404.633f, 274.323f)) <= 1.0f) {
laser = script;
break;
}
}
}
if (laser != nullptr) {
m_Skill->CalculateBehavior(m_SkillCastID, 15714, target->GetObjectID());
}
auto active = self->GetVar<bool>(u"active");
if (!active) return;
auto skillCastID = self->GetVarAs<float>(u"skillCastID");
if (skillCastID == 0) skillCastID = m_SkillCastID;
auto* skillComponent = self->GetComponent<SkillComponent>();
if (!skillComponent) return;
skillComponent->CastSkill(m_SkillCastID, target->GetObjectID());
}