2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/MP1/World/CBloodFlower.hpp"
|
|
|
|
|
2020-02-03 15:14:15 +00:00
|
|
|
#include <array>
|
|
|
|
|
2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/CSimplePool.hpp"
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Particle/CElementGen.hpp"
|
|
|
|
#include "Runtime/Particle/CGenDescription.hpp"
|
|
|
|
#include "Runtime/Weapon/CProjectileWeapon.hpp"
|
|
|
|
#include "Runtime/Weapon/CTargetableProjectile.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CScriptTrigger.hpp"
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde::MP1 {
|
2018-10-11 22:57:05 +00:00
|
|
|
CBloodFlower::CBloodFlower(TUniqueId uid, std::string_view name, const CEntityInfo& info, const zeus::CTransform& xf,
|
|
|
|
CModelData&& mData, const CPatternedInfo& pInfo, CAssetId partId1, CAssetId wpscId1,
|
|
|
|
const CActorParameters& actParms, CAssetId wpscId2, const CDamageInfo& dInfo1,
|
|
|
|
const CDamageInfo& dInfo2, const CDamageInfo& dInfo3, CAssetId partId2, CAssetId partId3,
|
|
|
|
CAssetId partId4, float f1, CAssetId partId5, u32 soundId)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CPatterned(ECharacter::BloodFlower, uid, name, EFlavorType::Zero, info, xf, std::move(mData), pInfo,
|
2019-03-23 00:36:10 +00:00
|
|
|
EMovementType::Ground, EColliderType::One, EBodyType::Restricted, actParms, EKnockBackVariant::Medium)
|
|
|
|
, x568_podEffectDesc(g_SimplePool->GetObj({FOURCC('PART'), partId1}))
|
2019-09-12 03:50:38 +00:00
|
|
|
, x574_podEffect(std::make_unique<CElementGen>(x568_podEffectDesc))
|
2019-03-24 05:45:47 +00:00
|
|
|
, x578_projectileDesc(g_SimplePool->GetObj({FOURCC('WPSC'), wpscId1}))
|
2019-03-23 00:36:10 +00:00
|
|
|
, x590_projectileInfo(wpscId2, dInfo1)
|
2019-03-24 05:45:47 +00:00
|
|
|
, x5d4_visorSfx(CSfxManager::TranslateSFXID(soundId))
|
|
|
|
, x5dc_projectileDamage(dInfo2)
|
2019-03-23 00:36:10 +00:00
|
|
|
, x5f8_podDamage(dInfo3)
|
|
|
|
, x614_(f1)
|
|
|
|
, x618_(partId2)
|
|
|
|
, x61c_(partId3)
|
|
|
|
, x620_(partId4) {
|
|
|
|
x588_projectileOffset = GetModelData()->GetScale().z() * GetLocatorTransform("LCTR_FLOFLOWER"sv).origin.z();
|
|
|
|
x574_podEffect->SetParticleEmission(false);
|
|
|
|
x574_podEffect->SetOrientation(xf.getRotation());
|
|
|
|
x574_podEffect->SetGlobalTranslation(xf.origin);
|
|
|
|
x574_podEffect->SetGlobalScale(GetModelData()->GetScale());
|
|
|
|
x590_projectileInfo.Token().Lock();
|
|
|
|
x460_knockBackController.SetAutoResetImpulse(false);
|
|
|
|
if (partId5.IsValid()) {
|
2019-03-24 05:45:47 +00:00
|
|
|
x5c4_visorParticle = g_SimplePool->GetObj({FOURCC('PART'), partId5});
|
2019-03-23 00:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
CPatterned::AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
if (msg == EScriptObjectMessage::Registered) {
|
|
|
|
x450_bodyController->Activate(mgr);
|
|
|
|
x5b8_ = GetHealthInfo(mgr)->GetHP();
|
|
|
|
} else if (msg == EScriptObjectMessage::Damage) {
|
|
|
|
if (x450_bodyController->IsFrozen()) {
|
|
|
|
x450_bodyController->FrozenBreakout();
|
|
|
|
}
|
2019-05-14 22:30:15 +00:00
|
|
|
CalculateAttackTime(mgr);
|
2019-03-23 00:36:10 +00:00
|
|
|
UpdateFire(mgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 22:30:15 +00:00
|
|
|
void CBloodFlower::CalculateAttackTime(CStateManager& mgr) {
|
2019-03-23 00:36:10 +00:00
|
|
|
x584_curAttackTime = x308_attackTimeVariation * -mgr.GetActiveRandom()->Float();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::UpdateFire(CStateManager& mgr) {
|
|
|
|
if (x5d8_effectState == 0) {
|
|
|
|
TurnEffectsOn(0, mgr);
|
2019-03-24 05:45:47 +00:00
|
|
|
} else if (x5d8_effectState == 1) {
|
2019-03-23 00:36:10 +00:00
|
|
|
TurnEffectsOff(0, mgr);
|
|
|
|
TurnEffectsOn(1, mgr);
|
2019-03-24 05:45:47 +00:00
|
|
|
} else if (x5d8_effectState == 2) {
|
2019-03-23 00:36:10 +00:00
|
|
|
TurnEffectsOff(1, mgr);
|
|
|
|
TurnEffectsOn(2, mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
++x5d8_effectState;
|
|
|
|
}
|
|
|
|
|
2020-02-03 15:14:15 +00:00
|
|
|
constexpr std::array sFireEffects{
|
2019-03-24 05:45:47 +00:00
|
|
|
"Fire1"sv,
|
|
|
|
"Fire2"sv,
|
|
|
|
"Fire3"sv,
|
2019-03-23 00:36:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void CBloodFlower::TurnEffectsOn(u32 effect, CStateManager& mgr) {
|
2019-08-14 14:58:54 +00:00
|
|
|
GetModelData()->GetAnimationData()->SetParticleEffectState(sFireEffects[effect], true, mgr);
|
2019-03-23 00:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::TurnEffectsOff(u32 effect, CStateManager& mgr) {
|
2019-08-14 14:58:54 +00:00
|
|
|
GetModelData()->GetAnimationData()->SetParticleEffectState(sFireEffects[effect], false, mgr);
|
2019-03-23 00:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::Think(float dt, CStateManager& mgr) {
|
|
|
|
if (!GetActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CPatterned::Think(dt, mgr);
|
|
|
|
x574_podEffect->Update(dt);
|
|
|
|
if (x5bc_projectileDelay > 0.f)
|
|
|
|
x5bc_projectileDelay -= dt;
|
|
|
|
|
|
|
|
x5c0_ += dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) {
|
|
|
|
if (type == EUserEventType::Projectile) {
|
|
|
|
if (x58c_projectileState == 1 && x5bc_projectileDelay <= 0.f) {
|
|
|
|
LaunchPollenProjectile(GetLocatorTransform(node.GetLocatorName()), mgr, x614_, 5);
|
|
|
|
x58c_projectileState = 0;
|
|
|
|
x5bc_projectileDelay = 0.5f;
|
|
|
|
}
|
2019-03-24 05:45:47 +00:00
|
|
|
return;
|
|
|
|
} else if (type == EUserEventType::Delete) {
|
2019-03-23 00:36:10 +00:00
|
|
|
if (x5d8_effectState > 0)
|
|
|
|
TurnEffectsOff((x5d8_effectState > 3 ? x5d8_effectState - 1 : 2), mgr);
|
|
|
|
}
|
|
|
|
CPatterned::DoUserAnimEvent(mgr, node, type, dt);
|
|
|
|
}
|
|
|
|
|
2019-03-24 05:45:47 +00:00
|
|
|
void CBloodFlower::LaunchPollenProjectile(const zeus::CTransform& xf, CStateManager& mgr, float var_f1, s32 w1) {
|
|
|
|
CProjectileInfo* proj = GetProjectileInfo();
|
|
|
|
TLockedToken<CWeaponDescription> projToken = proj->Token();
|
|
|
|
|
|
|
|
if (!projToken)
|
|
|
|
return;
|
|
|
|
|
|
|
|
zeus::CVector3f aimPos = mgr.GetPlayer().GetAimPosition(mgr, 0.f);
|
|
|
|
|
|
|
|
float zDiff = xf.origin.z() - aimPos.z();
|
|
|
|
float f2 = (zDiff > 0.f ? var_f1 : -zDiff + var_f1);
|
|
|
|
if (zDiff > 0.f)
|
|
|
|
var_f1 = zDiff + var_f1;
|
|
|
|
float f7 = std::sqrt(2.f * f2 / 4.9050002f) + std::sqrt(2.f * var_f1 / 4.9050002f);
|
|
|
|
float f4 = 1.f / f7;
|
|
|
|
zeus::CVector3f vel{f4 * (aimPos.x() - xf.origin.x()), f4 * (aimPos.y() - xf.origin.y()),
|
|
|
|
2.4525001f * f7 + (-zDiff / f7)};
|
|
|
|
if (CTargetableProjectile* targProj =
|
|
|
|
CreateArcProjectile(mgr, GetProjectileInfo()->Token(), zeus::CTransform::Translate(xf.origin),
|
|
|
|
GetProjectileInfo()->GetDamage(), kInvalidUniqueId)) {
|
|
|
|
targProj->ProjectileWeapon().SetVelocity(CProjectileWeapon::GetTickPeriod() * vel);
|
|
|
|
targProj->ProjectileWeapon().SetGravity(CProjectileWeapon::GetTickPeriod() *
|
|
|
|
zeus::CVector3f(0.f, 0.f, -4.9050002f));
|
|
|
|
mgr.AddObject(targProj);
|
|
|
|
}
|
2019-03-23 00:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::Render(const CStateManager& mgr) const {
|
|
|
|
CPatterned::Render(mgr);
|
|
|
|
x574_podEffect->Render(GetActorLights());
|
|
|
|
}
|
|
|
|
|
2020-02-03 15:35:49 +00:00
|
|
|
EWeaponCollisionResponseTypes CBloodFlower::GetCollisionResponseType(const zeus::CVector3f&, const zeus::CVector3f&,
|
|
|
|
const CWeaponMode& weaponMode, EProjectileAttrib) const {
|
|
|
|
const auto* const damageVulnerability = GetDamageVulnerability();
|
|
|
|
|
|
|
|
if (damageVulnerability->WeaponHurts(weaponMode, false)) {
|
|
|
|
return EWeaponCollisionResponseTypes::Unknown28;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EWeaponCollisionResponseTypes::Unknown78;
|
|
|
|
}
|
|
|
|
|
2019-03-23 00:36:10 +00:00
|
|
|
bool CBloodFlower::ShouldAttack(CStateManager& mgr, float arg) {
|
|
|
|
if (TooClose(mgr, 0.f))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (x584_curAttackTime <= x304_averageAttackTime)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (mgr.GetPlayer().GetTranslation().z() + mgr.GetPlayer().GetEyeHeight() <
|
|
|
|
x588_projectileOffset + x614_ + GetTranslation().z());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CBloodFlower::ShouldTurn(CStateManager& mgr, float) {
|
|
|
|
if (TooClose(mgr, 0.f))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
zeus::CVector3f frontVec = GetTransform().basis[1];
|
|
|
|
frontVec.z() = 0.f;
|
|
|
|
frontVec.normalize();
|
|
|
|
zeus::CVector3f posDiff = mgr.GetPlayer().GetTranslation() - GetTranslation();
|
|
|
|
posDiff.z() = 0.f;
|
|
|
|
posDiff.normalize();
|
|
|
|
|
|
|
|
return posDiff.dot(frontVec) < 0.99599999f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::Active(CStateManager& mgr, EStateMsg msg, float arg) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x32c_animState = EAnimState::Ready;
|
2019-05-14 22:30:15 +00:00
|
|
|
CalculateAttackTime(mgr);
|
2019-03-23 00:36:10 +00:00
|
|
|
} else if (msg == EStateMsg::Update) {
|
|
|
|
TryCommand(mgr, pas::EAnimationState::LoopReaction, &CPatterned::TryLoopReaction, 0);
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCAdditiveAimCmd());
|
|
|
|
x584_curAttackTime += arg;
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverAdditiveTargetVector(
|
2019-03-24 05:45:47 +00:00
|
|
|
GetTransform().transposeRotate(mgr.GetPlayer().GetTranslation() - GetTranslation()));
|
2019-03-23 00:36:10 +00:00
|
|
|
} else if (msg == EStateMsg::Deactivate) {
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::ExitState));
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBodyStateCmd(EBodyStateCmd::AdditiveIdle));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::InActive(CStateManager& mgr, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed);
|
|
|
|
x400_24_hitByPlayerProjectile = false;
|
|
|
|
} else if (msg == EStateMsg::Deactivate) {
|
|
|
|
x5c0_ = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::BulbAttack(CStateManager& mgr, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
2019-03-24 05:45:47 +00:00
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(
|
|
|
|
CBCProjectileAttackCmd(pas::ESeverity::Zero, mgr.GetPlayer().GetTranslation(), true));
|
2019-03-23 00:36:10 +00:00
|
|
|
x58c_projectileState = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::PodAttack(CStateManager& mgr, EStateMsg msg, float arg) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCMeleeAttackCmd(pas::ESeverity::Zero));
|
|
|
|
x574_podEffect->SetParticleEmission(true);
|
|
|
|
ActivateTriggers(mgr, true);
|
|
|
|
} else if (msg == EStateMsg::Update) {
|
|
|
|
if (TooClose(mgr, 0.f))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), x5f8_podDamage,
|
|
|
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
|
|
|
|
} else if (msg == EStateMsg::Deactivate) {
|
|
|
|
x574_podEffect->SetParticleEmission(false);
|
|
|
|
ActivateTriggers(mgr, false);
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCKnockBackCmd({}, pas::ESeverity::One));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CBloodFlower::ActivateTriggers(CStateManager& mgr, bool activate) {
|
|
|
|
for (const SConnection& conn : GetConnectionList()) {
|
|
|
|
auto search = mgr.GetIdListForScript(conn.x8_objId);
|
|
|
|
for (auto it = search.first; it != search.second; ++it) {
|
|
|
|
if (TCastToPtr<CScriptTrigger> trigger = mgr.ObjectById(it->second)) {
|
|
|
|
mgr.SendScriptMsg(trigger, GetUniqueId(),
|
|
|
|
(activate ? EScriptObjectMessage::Activate : EScriptObjectMessage::Deactivate));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 05:45:47 +00:00
|
|
|
CTargetableProjectile* CBloodFlower::CreateArcProjectile(CStateManager& mgr, const TToken<CWeaponDescription>& desc,
|
|
|
|
const zeus::CTransform& xf, const CDamageInfo& damage,
|
|
|
|
TUniqueId uid) {
|
|
|
|
|
|
|
|
if (!x578_projectileDesc)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
TUniqueId projId = mgr.AllocateUniqueId();
|
|
|
|
CTargetableProjectile* targProj = new CTargetableProjectile(
|
|
|
|
desc, EWeaponType::AI, xf, EMaterialTypes::Character, damage, x5dc_projectileDamage, projId, GetAreaIdAlways(),
|
|
|
|
GetUniqueId(), x578_projectileDesc, uid, EProjectileAttrib::None, {x5c4_visorParticle}, x5d4_visorSfx, false);
|
|
|
|
if (mgr.GetPlayer().GetOrbitTargetId() == GetUniqueId()) {
|
|
|
|
mgr.GetPlayer().ResetAimTargetPrediction(projId);
|
|
|
|
mgr.GetPlayer().SetOrbitTargetId(projId, mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return targProj;
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde::MP1
|