metaforce/Runtime/MP1/World/CJellyZap.cpp

266 lines
10 KiB
C++
Raw Normal View History

#include "Runtime/MP1/World/CJellyZap.hpp"
#include "Runtime/CStateManager.hpp"
2020-03-16 02:00:52 +00:00
#include "Runtime/World/CFishCloud.hpp"
#include "Runtime/World/CPlayer.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2019-02-12 01:58:12 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce::MP1 {
constexpr CMaterialFilter kPlayerFilter = CMaterialFilter::MakeInclude({EMaterialTypes::Player});
2019-02-12 01:58:12 +00:00
CJellyZap::CJellyZap(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
2021-04-26 03:16:16 +00:00
CModelData&& mData, const CDamageInfo& attackDamage, bool b1, float attackRadius, float f2,
float f3, float f4, float attackDelay, float f6, float f7, float f8, float priority,
float repulseRadius, float attractRadius, float f12, const CPatternedInfo& pInfo,
const CActorParameters& actParms)
2019-02-12 01:58:12 +00:00
: CPatterned(ECharacter::JellyZap, uid, name, EFlavorType::Zero, info, xf, std::move(mData), pInfo,
EMovementType::Flyer, EColliderType::One, EBodyType::BiPedal, actParms, EKnockBackVariant::Medium)
2021-04-26 03:16:16 +00:00
, x56c_attackDamage(attackDamage)
, x588_attackRadius(attackRadius)
2019-02-12 01:58:12 +00:00
, x58c_(f2)
, x590_(f4)
, x594_(f3)
, x598_(f8)
2021-04-26 03:16:16 +00:00
, x59c_priority(priority)
, x5a0_repulseRadius(repulseRadius)
, x5a4_attractRadius(attractRadius)
, x5a8_attackDelay(attackDelay)
2019-02-12 01:58:12 +00:00
, x5ac_(f6)
, x5b0_(f7)
, x5b4_(f12)
, x5b8_26_(b1) {
UpdateThermalFrozenState(true);
x50c_baseDamageMag = 0.f;
}
void CJellyZap::Accept(IVisitor& visitor) { visitor.Visit(this); }
void CJellyZap::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
CPatterned::AcceptScriptMsg(msg, uid, mgr);
if (msg == EScriptObjectMessage::Registered) {
x450_bodyController->Activate(mgr);
} else if (msg == EScriptObjectMessage::Activate) {
AddAttractor(mgr);
} else if (msg == EScriptObjectMessage::Deleted || msg == EScriptObjectMessage::Deactivate) {
RemoveAllAttractors(mgr);
}
}
void CJellyZap::Think(float dt, CStateManager& mgr) {
CPatterned::Think(dt, mgr);
2021-04-26 03:16:16 +00:00
if (!GetActive()) {
2019-02-12 01:58:12 +00:00
return;
2021-04-26 03:16:16 +00:00
}
if (x5b8_24_) {
x450_bodyController->FaceDirection(mgr.GetPlayer().GetTranslation() - GetTranslation(), dt);
2021-04-26 03:16:16 +00:00
}
float damage = x50c_baseDamageMag;
2019-02-12 01:58:12 +00:00
2021-04-26 03:16:16 +00:00
if (x5b8_25_ || GetBodyController()->GetPercentageFrozen() != 0.f) {
damage -= dt / 0.75f;
} else {
damage += dt / 0.3f;
}
2020-03-16 02:00:52 +00:00
x50c_baseDamageMag = zeus::clamp(0.f, damage, 1.f);
2019-02-12 01:58:12 +00:00
}
void CJellyZap::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) {
if (type == EUserEventType::DamageOn) {
mgr.ApplyDamageToWorld(GetUniqueId(), *this, GetTranslation(), x56c_attackDamage, kPlayerFilter);
return;
}
CPatterned::DoUserAnimEvent(mgr, node, type, dt);
}
2020-03-16 02:00:52 +00:00
void CJellyZap::KnockBack(const zeus::CVector3f& pos, CStateManager& mgr, const CDamageInfo& info, EKnockBackType type,
bool inDeferred, float magnitude) {
if (info.GetWeaponMode().GetType() == EWeaponType::Ice) {
2021-04-26 03:16:16 +00:00
Freeze(mgr, {}, GetTransform().transposeRotate(pos), x4fc_freezeDur);
2020-03-16 02:00:52 +00:00
}
}
2019-02-12 01:58:12 +00:00
void CJellyZap::Attack(CStateManager& mgr, EStateMsg msg, float arg) {
if (msg == EStateMsg::Activate) {
x32c_animState = EAnimState::Ready;
AddRepulsor(mgr);
x5b8_25_ = true;
2021-04-26 03:16:16 +00:00
float dist = (mgr.GetPlayer().GetTranslation() - GetTranslation()).magnitude();
2019-02-12 01:58:12 +00:00
if (dist < x56c_attackDamage.GetRadius()) {
2021-04-26 03:16:16 +00:00
float staticTimer = 3.f * (1.f - dist / x56c_attackDamage.GetRadius()) + 2.f;
2019-02-12 01:58:12 +00:00
if (staticTimer > mgr.GetPlayer().GetStaticTimer()) {
mgr.GetPlayer().SetHudDisable(staticTimer, 0.5f, 2.5f);
mgr.GetPlayer().SetOrbitRequestForTarget(mgr.GetPlayer().GetOrbitTargetId(),
CPlayer::EPlayerOrbitRequest::ActivateOrbitSource, mgr);
}
mgr.GetPlayerState()->GetStaticInterference().AddSource(GetUniqueId(), 0.5f, 0.5f);
}
x330_stateMachineState.SetDelay(x5ac_);
} else if (msg == EStateMsg::Update) {
TryCommand(mgr, pas::EAnimationState::MeleeAttack, &CPatterned::TryMeleeAttack, 1);
} else if (msg == EStateMsg::Deactivate) {
RemoveAllAttractors(mgr);
x32c_animState = EAnimState::NotReady;
x5b8_25_ = false;
}
}
void CJellyZap::Suck(CStateManager& mgr, EStateMsg msg, float arg) {
if (msg == EStateMsg::Activate) {
x32c_animState = EAnimState::Ready;
RemoveAllAttractors(mgr);
2021-04-26 03:16:16 +00:00
x568_ = 1;
x400_24_hitByPlayerProjectile = false;
x5b8_24_ = true;
x5b8_25_ = true;
2019-02-12 01:58:12 +00:00
} else if (msg == EStateMsg::Update) {
2021-04-26 03:16:16 +00:00
auto curSuit = mgr.GetPlayerState()->GetCurrentSuit();
TryCommand(mgr, pas::EAnimationState::LoopReaction, &CPatterned::TryLoopReaction, 0);
2020-03-13 20:22:39 +00:00
x450_bodyController->GetCommandMgr().DeliverTargetVector(
(mgr.GetPlayer().GetTranslation() + zeus::CVector3f(0.f, 0.f, 1.f)) - GetTranslation());
2020-03-16 02:00:52 +00:00
float intensity = mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit) ? 0.1f : 1.f;
zeus::CVector3f posDiff = (mgr.GetPlayer().GetTranslation() - GetTranslation());
float mag = 1.f / posDiff.magnitude();
2021-04-26 03:16:16 +00:00
float massScale = mgr.GetPlayer().GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed ? x594_
: curSuit == CPlayerState::EPlayerSuit::Gravity ? x590_
: x58c_;
mgr.GetPlayer().ApplyImpulseWR(
arg * ((5.f * massScale * mgr.GetPlayer().GetMass()) * (intensity * (mag * -posDiff))), {});
2020-03-16 02:00:52 +00:00
mgr.GetPlayer().UseCollisionImpulses();
2021-04-26 03:16:16 +00:00
mgr.GetPlayer().SetAccelerationChangeTimer(2.f * arg);
2020-03-16 02:00:52 +00:00
mgr.GetPlayerState()->GetStaticInterference().AddSource(GetUniqueId(), 0.1f, 0.1f);
2019-02-12 01:58:12 +00:00
} else if (msg == EStateMsg::Deactivate) {
2020-03-16 02:00:52 +00:00
x450_bodyController->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState));
mgr.GetPlayerState()->GetStaticInterference().RemoveSource(GetUniqueId());
2021-04-26 03:16:16 +00:00
x32c_animState = EAnimState::NotReady;
2020-03-16 02:00:52 +00:00
x5b8_24_ = false;
x5b8_25_ = false;
2019-02-12 01:58:12 +00:00
}
}
void CJellyZap::Active(CStateManager& mgr, EStateMsg msg, float arg) {
if (msg == EStateMsg::Activate) {
x5b8_24_ = true;
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Lurk);
x568_ = 0;
x330_stateMachineState.SetDelay(x3d0_playerLeashTime);
} else if (msg == EStateMsg::Update) {
zeus::CVector3f targetVector =
GetTranslation() - (zeus::CVector3f(0.f, 0.f, 1.f) + mgr.GetPlayer().GetTranslation());
2020-03-13 20:22:39 +00:00
x450_bodyController->GetCommandMgr().DeliverTargetVector(targetVector);
2019-02-12 01:58:12 +00:00
if (x5b8_26_) {
zeus::CVector3f moveToImpulse =
GetMoveToORImpulseWR(GetTransform().transposeRotate(arg * (zeus::CVector3f(0.f, 1.f, 0.f) * x598_)), arg);
ApplyImpulseOR(moveToImpulse, zeus::CAxisAngle());
2019-02-12 01:58:12 +00:00
}
} else if (msg == EStateMsg::Deactivate) {
x5b8_24_ = false;
}
}
2021-04-26 03:16:16 +00:00
void CJellyZap::InActive(CStateManager& mgr, EStateMsg msg, float arg) {
if (msg != EStateMsg::Activate) {
return;
2019-02-12 01:58:12 +00:00
}
2021-04-26 03:16:16 +00:00
x400_24_hitByPlayerProjectile = false;
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed);
AddAttractor(mgr);
x568_ = 0;
2019-02-12 01:58:12 +00:00
}
void CJellyZap::Flinch(CStateManager& mgr, EStateMsg msg, float arg) {
if (msg == EStateMsg::Activate) {
x400_24_hitByPlayerProjectile = false;
2021-04-26 03:16:16 +00:00
x32c_animState = EAnimState::Ready;
2019-02-12 01:58:12 +00:00
x330_stateMachineState.SetDelay(x5b0_);
} else if (msg == EStateMsg::Update) {
TryCommand(mgr, pas::EAnimationState::KnockBack, &CPatterned::TryKnockBack, 0);
} else if (msg == EStateMsg::Deactivate) {
x32c_animState = EAnimState::NotReady;
}
}
2021-04-26 03:16:16 +00:00
bool CJellyZap::InAttackPosition(CStateManager& mgr, float arg) {
if (mgr.GetPlayer().GetFluidCounter() == 0) {
2019-02-12 01:58:12 +00:00
return false;
2021-04-26 03:16:16 +00:00
}
2019-02-12 01:58:12 +00:00
2021-04-26 03:16:16 +00:00
return (mgr.GetPlayer().GetTranslation() - GetTranslation()).magSquared() < x588_attackRadius * x588_attackRadius;
2019-02-12 01:58:12 +00:00
}
bool CJellyZap::InDetectionRange(CStateManager& mgr, float arg) {
return (mgr.GetPlayer().GetFluidCounter() != 0 ? CPatterned::InDetectionRange(mgr, arg) : false);
}
2020-03-16 02:00:52 +00:00
void CJellyZap::AddSelfToFishCloud(CStateManager& mgr, float radius, float priority, bool repulsor) {
for (const SConnection& conn : x20_conns) {
2021-04-26 03:16:16 +00:00
if (conn.x0_state != EScriptObjectState::ScanStart || conn.x4_msg != EScriptObjectMessage::Follow) {
2020-03-16 02:00:52 +00:00
continue;
2021-04-26 03:16:16 +00:00
}
2020-03-16 02:00:52 +00:00
if (TCastToPtr<CFishCloud> cloud = mgr.ObjectById(mgr.GetIdForScript(conn.x8_objId))) {
if (repulsor) {
cloud->AddRepulsor(GetUniqueId(), false, radius, priority);
} else {
cloud->AddAttractor(GetUniqueId(), false, radius, priority);
}
}
}
}
2019-02-12 01:58:12 +00:00
2020-03-16 02:00:52 +00:00
void CJellyZap::AddRepulsor(CStateManager& mgr) { AddSelfToFishCloud(mgr, x5a0_repulseRadius, x59c_priority, true); }
2019-02-12 01:58:12 +00:00
2020-03-16 02:00:52 +00:00
void CJellyZap::AddAttractor(CStateManager& mgr) {
AddSelfToFishCloud(mgr, x5a0_repulseRadius, x59c_priority, true);
AddSelfToFishCloud(mgr, x5a4_attractRadius, x59c_priority, false);
}
2019-02-12 01:58:12 +00:00
2020-03-16 02:00:52 +00:00
void CJellyZap::RemoveSelfFromFishCloud(CStateManager& mgr) {
for (const SConnection& conn : x20_conns) {
2021-04-26 03:16:16 +00:00
if (conn.x0_state != EScriptObjectState::ScanStart || conn.x4_msg != EScriptObjectMessage::Follow) {
2020-03-16 02:00:52 +00:00
continue;
2021-04-26 03:16:16 +00:00
}
2020-03-16 02:00:52 +00:00
if (TCastToPtr<CFishCloud> cloud = mgr.ObjectById(mgr.GetIdForScript(conn.x8_objId))) {
cloud->RemoveAttractor(GetUniqueId());
cloud->RemoveRepulsor(GetUniqueId());
}
}
}
2019-02-12 01:58:12 +00:00
void CJellyZap::RemoveAllAttractors(CStateManager& mgr) { RemoveSelfFromFishCloud(mgr); }
bool CJellyZap::ClosestToPlayer(const CStateManager& mgr) const {
const zeus::CVector3f playerPos = mgr.GetPlayer().GetTranslation();
const float ourDistance = (playerPos - GetTranslation()).magnitude();
2019-02-12 01:58:12 +00:00
float closestDistance = ourDistance;
for (CEntity* ent : mgr.GetPhysicsActorObjectList()) {
2021-04-26 03:16:16 +00:00
if (auto* zap = CPatterned::CastTo<CJellyZap>(ent)) {
if (zap->GetAreaIdAlways() != GetAreaIdAlways() || zap == this) {
2019-02-12 01:58:12 +00:00
continue;
2021-04-26 03:16:16 +00:00
}
2019-02-12 01:58:12 +00:00
const float tmpDist = (playerPos - zap->GetTranslation()).magnitude();
2021-04-26 03:16:16 +00:00
if (tmpDist < closestDistance) {
2019-02-12 01:58:12 +00:00
closestDistance = tmpDist;
2021-04-26 03:16:16 +00:00
}
2019-02-12 01:58:12 +00:00
2021-04-26 03:16:16 +00:00
if (zap->x5b8_25_) {
2019-02-12 01:58:12 +00:00
return false;
2021-04-26 03:16:16 +00:00
}
2019-02-12 01:58:12 +00:00
}
}
return zeus::close_enough(closestDistance, ourDistance);
}
2020-03-16 02:00:52 +00:00
const CDamageVulnerability* CJellyZap::GetDamageVulnerability(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const CDamageInfo& info) const {
2021-04-26 03:16:16 +00:00
if (!sub801d8190()) {
return GetDamageVulnerability();
}
return &CDamageVulnerability::ReflectVulnerabilty();
2020-03-16 02:00:52 +00:00
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce::MP1