2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/MP1/World/CFlaahgraTentacle.hpp"
|
|
|
|
|
2020-04-09 21:38:03 +00:00
|
|
|
#include <array>
|
|
|
|
|
2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/Collision/CCollisionActor.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CScriptTrigger.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2019-06-10 00:09:07 +00:00
|
|
|
|
|
|
|
namespace urde::MP1 {
|
2020-04-09 21:38:03 +00:00
|
|
|
namespace {
|
|
|
|
constexpr std::string_view skpTentacleTip = "Arm_12"sv;
|
|
|
|
constexpr std::array<SSphereJointInfo, 3> skJointList{{
|
|
|
|
{"Arm_8", 2.f},
|
|
|
|
{"Arm_10", 1.2f},
|
|
|
|
{"Arm_12", 1.2f},
|
|
|
|
}};
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2019-06-10 00:09:07 +00:00
|
|
|
CFlaahgraTentacle::CFlaahgraTentacle(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
|
|
|
const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo,
|
|
|
|
const CActorParameters& actParms)
|
|
|
|
: CPatterned(ECharacter::FlaahgraTentacle, uid, name, EFlavorType::Zero, info, xf, std::move(mData), pInfo,
|
|
|
|
EMovementType::Flyer, EColliderType::One, EBodyType::Restricted, actParms, EKnockBackVariant::Large) {
|
|
|
|
x58e_24_ = false;
|
2019-08-14 14:58:54 +00:00
|
|
|
GetActorLights()->SetCastShadows(false);
|
2019-06-10 00:09:07 +00:00
|
|
|
x460_knockBackController.SetAutoResetImpulse(false);
|
2019-06-10 00:13:19 +00:00
|
|
|
CreateShadow(false);
|
2019-06-10 00:09:07 +00:00
|
|
|
}
|
|
|
|
void CFlaahgraTentacle::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::Registered: {
|
|
|
|
x450_bodyController->Activate(mgr);
|
|
|
|
SetupCollisionManager(mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Deleted: {
|
|
|
|
x56c_collisionManager->Destroy(mgr);
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToPtr<CScriptTrigger> trigger = mgr.ObjectById(x58c_triggerId)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
trigger->SetForceVector(x580_forceVector);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Touched: {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToConstPtr<CCollisionActor> colAct = mgr.GetObjectById(uid)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
if (colAct->GetLastTouchedObject() == mgr.GetPlayer().GetUniqueId() && x420_curDamageRemTime <= 0.f) {
|
2019-06-18 01:39:56 +00:00
|
|
|
mgr.ApplyDamage(GetUniqueId(), mgr.GetPlayer().GetUniqueId(), GetUniqueId(), GetContactDamage(),
|
2019-06-10 00:09:07 +00:00
|
|
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), {});
|
|
|
|
x420_curDamageRemTime = x424_damageWaitTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Play: {
|
2020-02-29 10:54:36 +00:00
|
|
|
x578_ = 0.04f;
|
2019-06-10 00:09:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Deactivate: {
|
|
|
|
DeathDelete(mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Open: {
|
|
|
|
ExtractTentacle(mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Close: {
|
|
|
|
RetractTentacle(mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::InitializedInArea: {
|
|
|
|
SaveBombSlotInfo(mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CPatterned::AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlaahgraTentacle::Think(float dt, CStateManager& mgr) {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (!GetActive()) {
|
2019-06-10 00:09:07 +00:00
|
|
|
return;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
|
|
|
CPatterned::Think(dt, mgr);
|
|
|
|
x56c_collisionManager->Update(dt, mgr, CCollisionActorManager::EUpdateOptions::ObjectSpace);
|
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (x574_ > 0.f) {
|
2019-06-10 00:09:07 +00:00
|
|
|
x574_ -= dt;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (x578_ > 0.f) {
|
2019-06-10 00:09:07 +00:00
|
|
|
x578_ -= dt;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-09 21:38:03 +00:00
|
|
|
void CFlaahgraTentacle::AddSphereCollisionList(const SSphereJointInfo* sphereJoints, size_t jointCount,
|
2019-06-10 00:09:07 +00:00
|
|
|
std::vector<CJointCollisionDescription>& outJoints) {
|
|
|
|
const CAnimData* animData = GetModelData()->GetAnimationData();
|
|
|
|
|
2020-04-09 21:38:03 +00:00
|
|
|
for (size_t i = 0; i < jointCount; ++i) {
|
2019-09-06 13:40:14 +00:00
|
|
|
const SSphereJointInfo& sphereJoint = sphereJoints[i];
|
|
|
|
const CSegId segId = animData->GetLocatorSegId(sphereJoint.name);
|
|
|
|
|
2019-10-27 01:53:11 +00:00
|
|
|
if (segId.IsInvalid()) {
|
2019-06-10 00:09:07 +00:00
|
|
|
continue;
|
2019-09-06 13:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
outJoints.push_back(CJointCollisionDescription::SphereCollision(segId, sphereJoint.radius, sphereJoint.name, 10.f));
|
2019-06-10 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlaahgraTentacle::SetupCollisionManager(CStateManager& mgr) {
|
|
|
|
std::vector<CJointCollisionDescription> jointList;
|
2020-04-09 21:38:03 +00:00
|
|
|
AddSphereCollisionList(skJointList.data(), skJointList.size(), jointList);
|
2019-09-12 03:50:38 +00:00
|
|
|
x56c_collisionManager =
|
|
|
|
std::make_unique<CCollisionActorManager>(mgr, GetUniqueId(), GetAreaIdAlways(), jointList, true);
|
2019-06-10 00:09:07 +00:00
|
|
|
|
|
|
|
for (u32 i = 0; i < x56c_collisionManager->GetNumCollisionActors(); ++i) {
|
|
|
|
const CJointCollisionDescription& desc = x56c_collisionManager->GetCollisionDescFromIndex(i);
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToPtr<CCollisionActor> colAct = mgr.ObjectById(desc.GetCollisionActorId())) {
|
2019-06-10 00:09:07 +00:00
|
|
|
colAct->SetMaterialFilter(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Player},
|
|
|
|
{EMaterialTypes::Character,
|
|
|
|
EMaterialTypes::CollisionActor,
|
|
|
|
EMaterialTypes::NoStaticCollision,
|
|
|
|
EMaterialTypes::NoPlatformCollision}));
|
|
|
|
colAct->AddMaterial(EMaterialTypes::ScanPassthrough);
|
|
|
|
colAct->SetDamageVulnerability(*GetDamageVulnerability());
|
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (x57c_tentacleTipAct == kInvalidUniqueId && desc.GetName() == skpTentacleTip) {
|
2019-06-10 00:09:07 +00:00
|
|
|
x57c_tentacleTipAct = desc.GetCollisionActorId();
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveMaterial(EMaterialTypes::Solid, EMaterialTypes::Target, EMaterialTypes::Orbit, mgr);
|
|
|
|
AddMaterial(EMaterialTypes::Scannable, mgr);
|
|
|
|
|
|
|
|
}
|
|
|
|
zeus::CVector3f CFlaahgraTentacle::GetAimPosition(const CStateManager& mgr, float dt) const {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToConstPtr<CCollisionActor> colAct = mgr.GetObjectById(x57c_tentacleTipAct)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
return colAct->GetTranslation();
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
|
|
|
return CPatterned::GetAimPosition(mgr, dt);
|
|
|
|
}
|
|
|
|
void CFlaahgraTentacle::ExtractTentacle(CStateManager& mgr) {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (!Inside(mgr, 0.f)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
return;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
|
|
|
x58e_24_ = true;
|
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToPtr<CScriptTrigger> trigger = mgr.ObjectById(x58c_triggerId)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
trigger->SetForceVector(x580_forceVector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlaahgraTentacle::RetractTentacle(CStateManager& mgr) {
|
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Crouch);
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToPtr<CScriptTrigger> trigger = mgr.ObjectById(x58c_triggerId)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
trigger->SetForceVector({});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void CFlaahgraTentacle::SaveBombSlotInfo(CStateManager& mgr) {
|
|
|
|
for (const SConnection& conn : GetConnectionList()) {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (conn.x0_state != EScriptObjectState::Modify || conn.x4_msg != EScriptObjectMessage::ToggleActive) {
|
2019-06-10 00:09:07 +00:00
|
|
|
continue;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
const TUniqueId uid = mgr.GetIdForScript(conn.x8_objId);
|
|
|
|
if (const TCastToConstPtr<CScriptTrigger> trigger = mgr.GetObjectById(uid)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
x58c_triggerId = uid;
|
|
|
|
x580_forceVector = trigger->GetForceVector();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CFlaahgraTentacle::ShouldAttack(CStateManager& mgr, float) {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (x578_ > 0.f) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (x574_ > 0.f || mgr.GetPlayer().IsInWaterMovement()) {
|
2019-06-10 00:09:07 +00:00
|
|
|
return false;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToConstPtr<CCollisionActor> colAct = mgr.GetObjectById(x57c_tentacleTipAct)) {
|
|
|
|
const float mag = (colAct->GetTranslation().toVec2f() - mgr.GetPlayer().GetTranslation().toVec2f()).magSquared();
|
2019-06-10 00:09:07 +00:00
|
|
|
return mag >= (x2fc_minAttackRange * x2fc_minAttackRange) && mag <= (x300_maxAttackRange * x300_maxAttackRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFlaahgraTentacle::Attack(CStateManager& mgr, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x568_ = 0;
|
|
|
|
} else if (msg == EStateMsg::Update) {
|
|
|
|
if (x568_ == 0) {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (x450_bodyController->GetBodyStateInfo().GetCurrentStateId() == pas::EAnimationState::MeleeAttack) {
|
2019-06-10 00:09:07 +00:00
|
|
|
x568_ = 2;
|
2020-04-09 21:43:13 +00:00
|
|
|
} else {
|
2019-06-10 00:09:07 +00:00
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(
|
|
|
|
CBCMeleeAttackCmd((x578_ > 0.f ? pas::ESeverity::Zero : pas::ESeverity::One), {}));
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
|
|
|
} else if (x568_ == 2 && x450_bodyController->GetBodyStateInfo().GetCurrentStateId() != pas::EAnimationState::MeleeAttack) {
|
|
|
|
x568_ = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (msg == EStateMsg::Deactivate) {
|
|
|
|
x574_ = (x308_attackTimeVariation * mgr.GetActiveRandom()->Float()) + x304_averageAttackTime;
|
|
|
|
x578_ = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void CFlaahgraTentacle::Retreat(CStateManager& mgr, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Update) {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (!x58e_24_) {
|
2019-06-10 00:09:07 +00:00
|
|
|
return;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (x330_stateMachineState.GetTime() <= 1.f) {
|
2019-06-10 00:09:07 +00:00
|
|
|
return;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToConstPtr<CScriptTrigger> trigger = mgr.ObjectById(x58c_triggerId)) {
|
|
|
|
if (trigger->IsPlayerTriggerProc()) {
|
2019-06-10 00:09:07 +00:00
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed);
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
}
|
|
|
|
} else if (msg == EStateMsg::Deactivate) {
|
|
|
|
x58e_24_ = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void CFlaahgraTentacle::InActive(CStateManager& mgr, EStateMsg msg, float arg) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x570_ = 0.f;
|
|
|
|
} else if (msg == EStateMsg::Update) {
|
2020-04-09 21:43:13 +00:00
|
|
|
if (Inside(mgr, 0.f)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
return;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
|
2020-04-09 21:43:13 +00:00
|
|
|
if (const TCastToConstPtr<CScriptTrigger> trigger = mgr.ObjectById(x58c_triggerId)) {
|
2019-06-10 00:09:07 +00:00
|
|
|
if (trigger->IsPlayerTriggerProc()) {
|
|
|
|
if (x570_ > 1.f) {
|
|
|
|
RetractTentacle(mgr);
|
|
|
|
ExtractTentacle(mgr);
|
2020-04-09 21:43:13 +00:00
|
|
|
} else {
|
2019-06-10 00:09:07 +00:00
|
|
|
x570_ += arg;
|
2020-04-09 21:43:13 +00:00
|
|
|
}
|
2019-06-10 00:09:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|