2018-10-11 22:57:05 +00:00
|
|
|
#include "CEyeball.hpp"
|
2018-11-21 00:02:20 +00:00
|
|
|
#include "Weapon/CBeamInfo.hpp"
|
|
|
|
#include "Weapon/CGameProjectile.hpp"
|
|
|
|
#include "Weapon/CPlasmaProjectile.hpp"
|
|
|
|
#include "World/CPlayer.hpp"
|
2018-12-02 02:32:26 +00:00
|
|
|
#include "World/CWorld.hpp"
|
|
|
|
#include "World/CGameArea.hpp"
|
2018-11-21 00:02:20 +00:00
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "TCastTo.hpp"
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde::MP1 {
|
2018-10-11 22:57:05 +00:00
|
|
|
CEyeball::CEyeball(TUniqueId uid, std::string_view name, CPatterned::EFlavorType flavor, const CEntityInfo& info,
|
2019-01-16 04:22:44 +00:00
|
|
|
const zeus::CTransform& xf, CModelData&& mData, const CPatternedInfo& pInfo, float attackDelay,
|
|
|
|
float attackStartTime, CAssetId wpscId, const CDamageInfo& dInfo, CAssetId beamContactFxId,
|
|
|
|
CAssetId beamPulseFxId, CAssetId beamTextureId, CAssetId beamGlowTextureId, u32 anim0, u32 anim1,
|
|
|
|
u32 anim2, u32 anim3, u32 beamSfx, bool attackDisabled, const CActorParameters& actParms)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CPatterned(ECharacter::EyeBall, uid, name, flavor, info, xf, std::move(mData), pInfo, EMovementType::Flyer,
|
|
|
|
EColliderType::Zero, EBodyType::Restricted, actParms, EKnockBackVariant::Medium)
|
2019-01-16 04:22:44 +00:00
|
|
|
, x568_attackDelay(attackDelay)
|
|
|
|
, x56c_attackStartTime(attackStartTime)
|
2019-04-03 04:32:31 +00:00
|
|
|
, x570_boneTracking(*GetModelData()->GetAnimationData(), "Eye"sv, zeus::degToRad(45.f), zeus::degToRad(180.f),
|
|
|
|
EBoneTrackingFlags::NoParent)
|
2019-01-16 04:22:44 +00:00
|
|
|
, x5b4_projectileInfo(wpscId, dInfo)
|
|
|
|
, x5dc_beamContactFxId(beamContactFxId)
|
|
|
|
, x5e0_beamPulseFxId(beamPulseFxId)
|
|
|
|
, x5e4_beamTextureId(beamTextureId)
|
|
|
|
, x5e8_beamGlowTextureId(beamGlowTextureId)
|
|
|
|
, x604_beamSfxId(CSfxManager::TranslateSFXID(beamSfx))
|
2018-12-08 05:30:43 +00:00
|
|
|
, x60c_24_canAttack(false)
|
|
|
|
, x60c_25_playerInRange(false)
|
|
|
|
, x60c_26_alert(false)
|
2019-01-16 04:22:44 +00:00
|
|
|
, x60c_27_attackDisabled(attackDisabled)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x60c_28_firingBeam(false) {
|
2019-01-16 04:22:44 +00:00
|
|
|
x5f4_animIdxs[0] = anim0;
|
|
|
|
x5f4_animIdxs[1] = anim1;
|
|
|
|
x5f4_animIdxs[2] = anim2;
|
|
|
|
x5f4_animIdxs[3] = anim3;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
x460_knockBackController.SetAutoResetImpulse(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEyeball::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
|
|
|
void CEyeball::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::ProjectileCollide:
|
|
|
|
case EScriptObjectMessage::InvulnDamage: {
|
|
|
|
if (TCastToConstPtr<CGameProjectile> proj = mgr.GetObjectById(uid)) {
|
|
|
|
if (proj->GetOwnerId() == mgr.GetPlayer().GetUniqueId())
|
|
|
|
if (GetDamageVulnerability()->GetVulnerability(proj->GetDamageInfo().GetWeaponMode(), false) !=
|
|
|
|
EVulnerability::Deflect)
|
|
|
|
x400_24_hitByPlayerProjectile = true;
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Alert:
|
|
|
|
x60c_26_alert = true;
|
|
|
|
break;
|
|
|
|
case EScriptObjectMessage::Registered: {
|
|
|
|
RemoveMaterial(EMaterialTypes::Orbit, EMaterialTypes::Target, mgr);
|
|
|
|
x450_bodyController->Activate(mgr);
|
|
|
|
x330_stateMachineState.SetDelay(0.f);
|
|
|
|
CreateShadow(false);
|
|
|
|
CreateBeam(mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EScriptObjectMessage::Deleted: {
|
|
|
|
if (x5ec_projectileId != kInvalidUniqueId) {
|
|
|
|
mgr.FreeScriptObject(x5ec_projectileId);
|
|
|
|
if (x608_beamSfx) {
|
|
|
|
CSfxManager::RemoveEmitter(x608_beamSfx);
|
|
|
|
x608_beamSfx.reset();
|
|
|
|
}
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
x5ec_projectileId = kInvalidUniqueId;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CPatterned::AcceptScriptMsg(msg, uid, mgr);
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 02:32:26 +00:00
|
|
|
static float kMinAngle = std::cos(zeus::degToRad(45.f));
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::Think(float dt, CStateManager& mgr) {
|
|
|
|
CPatterned::Think(dt, mgr);
|
|
|
|
if (!GetActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CPlayer& player = mgr.GetPlayer();
|
|
|
|
zeus::CVector3f direction = (player.GetTranslation() - GetTranslation()).normalized();
|
|
|
|
|
|
|
|
x60c_25_playerInRange = (player.GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Morphed &&
|
|
|
|
direction.dot(GetTransform().frontVector()) > kMinAngle);
|
|
|
|
|
|
|
|
if (x60c_25_playerInRange) {
|
|
|
|
x570_boneTracking.SetActive(true);
|
|
|
|
x5a8_targetPosition = player.GetTranslation() - (0.5f * player.GetVelocity());
|
|
|
|
x570_boneTracking.SetTargetPosition(x5a8_targetPosition);
|
|
|
|
x570_boneTracking.Update(dt);
|
|
|
|
ModelData()->AnimationData()->PreRender();
|
|
|
|
x570_boneTracking.PreRender(mgr, *ModelData()->AnimationData(), GetTransform(), GetModelData()->GetScale(),
|
|
|
|
*x450_bodyController.get());
|
|
|
|
} else
|
|
|
|
x570_boneTracking.SetActive(false);
|
2018-12-02 02:32:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (GetActive()) {
|
|
|
|
CPlasmaProjectile* projectile = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x5ec_projectileId));
|
|
|
|
if (projectile && projectile->GetActive())
|
2019-01-03 03:47:28 +00:00
|
|
|
projectile->UpdateFx(GetLctrTransform(skEyeLocator), dt, mgr);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-12-02 02:32:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x60c_28_firingBeam) {
|
|
|
|
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(GetAreaIdAlways());
|
|
|
|
if (area->GetActive() && area->IsPostConstructed() &&
|
|
|
|
area->GetPostConstructed()->x10dc_occlusionState == CGameArea::EOcclusionState::Occluded)
|
|
|
|
ResetBeamState(mgr);
|
|
|
|
}
|
2018-12-02 02:32:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::CreateBeam(CStateManager& mgr) {
|
|
|
|
if (x5ec_projectileId != kInvalidUniqueId)
|
|
|
|
return;
|
2018-11-21 00:02:20 +00:00
|
|
|
|
2019-01-31 20:44:05 +00:00
|
|
|
CBeamInfo beamInfo(3, x5dc_beamContactFxId, x5e0_beamPulseFxId, x5e4_beamTextureId, x5e8_beamGlowTextureId, 50, 0.05f,
|
|
|
|
1.f, 2.f, 20.f, 1.f, 1.f, 2.f, zeus::CColor(1.f, 1.f, 1.f, 0.f), zeus::CColor(0.f, 1.f, 0.5f, 0.f),
|
|
|
|
150.f);
|
2018-12-08 05:30:43 +00:00
|
|
|
x5ec_projectileId = mgr.AllocateUniqueId();
|
|
|
|
mgr.AddObject(new CPlasmaProjectile(x5b4_projectileInfo.Token(), "EyeBall_Beam"sv, EWeaponType::AI, beamInfo,
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CTransform(), EMaterialTypes::Immovable,
|
2018-12-08 05:30:43 +00:00
|
|
|
x5b4_projectileInfo.GetDamage(), x5ec_projectileId, GetAreaIdAlways(),
|
2019-01-03 03:47:28 +00:00
|
|
|
GetUniqueId(), {}, false, EProjectileAttrib::KeepInCinematic));
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::InActive(CStateManager&, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Activate)
|
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Relaxed);
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::Cover(CStateManager&, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Lurk);
|
|
|
|
x60c_24_canAttack = false;
|
|
|
|
x330_stateMachineState.SetDelay(x568_attackDelay);
|
|
|
|
}
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
2018-10-11 22:57:05 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::Flinch(CStateManager& mgr, EStateMsg msg, float arg) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
2018-12-13 07:39:16 +00:00
|
|
|
x32c_animState = EAnimState::Ready;
|
2018-12-08 05:30:43 +00:00
|
|
|
x330_stateMachineState.SetDelay(x568_attackDelay);
|
|
|
|
} else if (msg == EStateMsg::Update)
|
|
|
|
TryCommand(mgr, pas::EAnimationState::KnockBack, CPatternedTryFunc(&CEyeball::TryFlinch), 0);
|
|
|
|
else if (msg == EStateMsg::Deactivate)
|
2018-12-13 07:39:16 +00:00
|
|
|
x32c_animState = EAnimState::NotReady;
|
2018-10-11 22:57:05 +00:00
|
|
|
}
|
2018-11-21 00:02:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::TryFlinch(CStateManager&, int arg) {
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCKnockBackCmd(GetTransform().basis[0], pas::ESeverity(arg)));
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::Active(CStateManager& mgr, EStateMsg msg, float) {
|
|
|
|
if (msg == EStateMsg::Activate) {
|
|
|
|
x400_24_hitByPlayerProjectile = 0;
|
|
|
|
x450_bodyController->SetLocomotionType(pas::ELocomotionType::Combat);
|
|
|
|
x60c_24_canAttack = false;
|
|
|
|
} else if (msg == EStateMsg::Update) {
|
2019-01-16 04:22:44 +00:00
|
|
|
if (x330_stateMachineState.GetTime() > x56c_attackStartTime)
|
2018-12-08 05:30:43 +00:00
|
|
|
x60c_24_canAttack = true;
|
2018-11-21 00:02:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateAnimation();
|
|
|
|
} else if (msg == EStateMsg::Deactivate) {
|
|
|
|
x330_stateMachineState.SetDelay(x568_attackDelay);
|
|
|
|
if (CPlasmaProjectile* proj = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x5ec_projectileId)))
|
|
|
|
proj->ResetBeam(mgr, true);
|
2018-12-02 02:32:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x60c_24_canAttack = false;
|
2018-11-21 00:02:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CSfxManager::RemoveEmitter(x608_beamSfx);
|
|
|
|
x608_beamSfx.reset();
|
|
|
|
}
|
2018-11-21 00:02:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::UpdateAnimation() {
|
|
|
|
if (std::fabs(GetModelData()->GetAnimationData()->GetAnimTimeRemaining("Whole Body"sv) - 0.f) >= 0.00001f)
|
|
|
|
return;
|
2018-11-21 00:02:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x5f0_currentAnim = (x5f0_currentAnim + 1) & 3;
|
|
|
|
for (u32 i = 0; i < 4; ++i) {
|
|
|
|
if (x5f4_animIdxs[x5f0_currentAnim] != -1)
|
|
|
|
break;
|
2018-11-21 00:02:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x5f0_currentAnim = (x5f0_currentAnim + 1) & 3;
|
|
|
|
}
|
|
|
|
s32 animIdx = x5f4_animIdxs[x5f0_currentAnim];
|
|
|
|
if (animIdx != -1)
|
|
|
|
x450_bodyController->GetCommandMgr().DeliverCmd(CBCScriptedCmd(animIdx, false, false, 0.f));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEyeball::ResetBeamState(CStateManager& mgr) {
|
|
|
|
if (CPlasmaProjectile* projectile = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x5ec_projectileId)))
|
|
|
|
projectile->ResetBeam(mgr, true);
|
|
|
|
|
|
|
|
x60c_28_firingBeam = false;
|
|
|
|
if (x608_beamSfx) {
|
|
|
|
CSfxManager::RemoveEmitter(x608_beamSfx);
|
|
|
|
x608_beamSfx.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEyeball::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node, EUserEventType type, float dt) {
|
|
|
|
if (type == EUserEventType::DamageOff)
|
|
|
|
ResetBeamState(mgr);
|
|
|
|
else if (type == EUserEventType::DamageOn && x60c_24_canAttack)
|
|
|
|
FireBeam(mgr, GetLctrTransform(node.GetLocatorName()));
|
|
|
|
else
|
|
|
|
CPatterned::DoUserAnimEvent(mgr, node, type, dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CEyeball::FireBeam(CStateManager& mgr, const zeus::CTransform& xf) {
|
|
|
|
if (CPlasmaProjectile* projectile = static_cast<CPlasmaProjectile*>(mgr.ObjectById(x5ec_projectileId))) {
|
|
|
|
if (!projectile->GetActive()) {
|
|
|
|
projectile->Fire(xf, mgr, false);
|
|
|
|
x60c_28_firingBeam = true;
|
|
|
|
if (!x608_beamSfx) {
|
|
|
|
CAudioSys::C3DEmitterParmData parmData{
|
|
|
|
GetTranslation(), {}, 50.f, 0.1f, 0x1, x604_beamSfxId, 1.f /* 127 */, 0.15f /* 20 / 127 */, false, 127};
|
|
|
|
x608_beamSfx = CSfxManager::AddEmitter(parmData, true, 127, true, GetAreaIdAlways());
|
|
|
|
}
|
2018-12-02 02:32:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-12-02 02:32:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
|
|
|
|
CPatterned::PreRender(mgr, frustum);
|
|
|
|
x570_boneTracking.PreRender(mgr, *ModelData()->AnimationData(), GetTransform(), GetModelData()->GetScale(),
|
|
|
|
*x450_bodyController);
|
2018-12-02 02:32:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CEyeball::Death(CStateManager& mgr, const zeus::CVector3f& pos, EScriptObjectState state) {
|
|
|
|
zeus::CTransform oldXf = GetTransform();
|
|
|
|
CPatterned::Death(mgr, pos, state);
|
|
|
|
SetTransform(oldXf);
|
2018-12-02 02:32:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde::MP1
|