2021-12-05 17:54:36 +00:00
|
|
|
#include "AmSkullkinDrill.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "MovingPlatformComponent.h"
|
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
#include "ProximityMonitorComponent.h"
|
|
|
|
#include "MissionComponent.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "EntityInfo.h"
|
2023-03-20 13:10:52 +00:00
|
|
|
#include "RenderComponent.h"
|
2023-05-02 22:39:21 +00:00
|
|
|
#include "eStateChangeType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void AmSkullkinDrill::OnStartup(Entity* self) {
|
|
|
|
self->SetNetworkVar(u"bIsInUse", false);
|
|
|
|
self->SetVar(u"bActive", true);
|
|
|
|
|
|
|
|
GameMessages::SendPlayFXEffect(self->GetObjectID(), -1, u"spin", "active");
|
|
|
|
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* movingPlatformComponent = self->GetComponent<MovingPlatformComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (movingPlatformComponent == nullptr) {
|
|
|
|
return;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
movingPlatformComponent->SetSerialized(true);
|
|
|
|
|
|
|
|
movingPlatformComponent->GotoWaypoint(0);
|
|
|
|
|
|
|
|
auto* standObj = GetStandObj(self);
|
|
|
|
|
|
|
|
if (standObj != nullptr) {
|
|
|
|
standObj->SetVar(u"bActive", true);
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetProximityRadius(5, "spin_distance");
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity* AmSkullkinDrill::GetStandObj(Entity* self) {
|
|
|
|
const auto& myGroup = self->GetGroups();
|
|
|
|
|
|
|
|
if (myGroup.empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string groupName = "Drill_Stand_";
|
|
|
|
|
|
|
|
groupName.push_back(myGroup[0][myGroup[0].size() - 1]);
|
|
|
|
|
|
|
|
const auto standObjs = EntityManager::Instance()->GetEntitiesInGroup(groupName);
|
|
|
|
|
|
|
|
if (standObjs.empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return standObjs[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) {
|
|
|
|
if (message != "NinjagoSpinEvent" || self->GetNetworkVar<bool>(u"bIsInUse")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* proximityMonitorComponent = self->GetComponent<ProximityMonitorComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (proximityMonitorComponent == nullptr || !proximityMonitorComponent->IsInProximity("spin_distance", caster->GetObjectID())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->SetVar(u"activaterID", caster->GetObjectID());
|
|
|
|
|
|
|
|
self->SetNetworkVar(u"bIsInUse", true);
|
|
|
|
|
|
|
|
TriggerDrill(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::TriggerDrill(Entity* self) {
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(self, u"slowdown");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
self->AddTimer("killDrill", 10.0f);
|
|
|
|
|
|
|
|
auto* standObj = GetStandObj(self);
|
|
|
|
|
|
|
|
if (standObj != nullptr) {
|
|
|
|
standObj->SetVar(u"bActive", false);
|
|
|
|
}
|
|
|
|
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* movingPlatformComponent = self->GetComponent<MovingPlatformComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (movingPlatformComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
movingPlatformComponent->GotoWaypoint(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::OnWaypointReached(Entity* self, uint32_t waypointIndex) {
|
|
|
|
if (waypointIndex == 1) {
|
|
|
|
auto myPos = self->GetPosition();
|
|
|
|
auto myRot = self->GetRotation();
|
|
|
|
|
|
|
|
myPos.y -= 21;
|
|
|
|
|
|
|
|
EntityInfo info = {};
|
|
|
|
info.lot = 12346;
|
|
|
|
info.pos = myPos;
|
|
|
|
info.rot = myRot;
|
|
|
|
info.scale = 3; // Needs the scale, otherwise attacks fail
|
|
|
|
info.spawnerID = self->GetObjectID();
|
|
|
|
|
|
|
|
auto* child = EntityManager::Instance()->CreateEntity(info);
|
|
|
|
|
|
|
|
EntityManager::Instance()->ConstructEntity(child);
|
|
|
|
|
|
|
|
self->SetVar(u"ChildSmash", child->GetObjectID());
|
|
|
|
|
|
|
|
child->AddDieCallback([this, self]() {
|
|
|
|
const auto& userID = self->GetVar<LWOOBJID>(u"activaterID");
|
|
|
|
|
|
|
|
auto* player = EntityManager::Instance()->GetEntity(userID);
|
|
|
|
|
|
|
|
if (player == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OnHitOrHealResult(self, player, 1);
|
|
|
|
});
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
OnArrived(self, waypointIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::OnUse(Entity* self, Entity* user) {
|
|
|
|
if (self->GetNetworkVar<bool>(u"bIsInUse")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->SetNetworkVar(u"bIsInUse", true);
|
|
|
|
|
|
|
|
GameMessages::SendPlayFXEffect(user->GetObjectID(), 5499, u"on-anim", "tornado");
|
|
|
|
GameMessages::SendPlayFXEffect(user->GetObjectID(), 5502, u"on-anim", "staff");
|
|
|
|
|
|
|
|
const auto userID = user->GetObjectID();
|
|
|
|
|
|
|
|
self->SetVar(u"userID", userID);
|
|
|
|
self->SetVar(u"activaterID", userID);
|
|
|
|
|
|
|
|
PlayAnim(self, user, "spinjitzu-staff-windup");
|
|
|
|
PlayCinematic(self);
|
|
|
|
|
|
|
|
FreezePlayer(self, user, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::FreezePlayer(Entity* self, Entity* player, bool bFreeze) {
|
2023-01-07 05:59:19 +00:00
|
|
|
auto StateChangeType = eStateChangeType::POP;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (bFreeze) {
|
|
|
|
if (player->GetIsDead()) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-01-07 05:59:19 +00:00
|
|
|
StateChangeType = eStateChangeType::PUSH;
|
2021-12-05 17:54:36 +00:00
|
|
|
} else {
|
|
|
|
if (player->GetIsDead()) {
|
|
|
|
//
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2023-01-07 05:59:19 +00:00
|
|
|
GameMessages::SendSetStunned(player->GetObjectID(), StateChangeType, player->GetSystemAddress(), self->GetObjectID(),
|
2021-12-05 17:54:36 +00:00
|
|
|
true, false, true, false, true, false, true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::OnArrived(Entity* self, uint32_t waypointIndex) {
|
|
|
|
auto* standObj = GetStandObj(self);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (waypointIndex == 1) {
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(self, u"no-spin");
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendStopFXEffect(self, true, "active");
|
|
|
|
GameMessages::SendPlayFXEffect(self->GetObjectID(), -1, u"indicator", "indicator");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetVar(u"bActive", false);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
const auto playerID = self->GetVar<LWOOBJID>(u"userID");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* player = EntityManager::Instance()->GetEntity(playerID);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (player != nullptr) {
|
|
|
|
PlayAnim(self, player, "spinjitzu-staff-end");
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (standObj != nullptr) {
|
|
|
|
standObj->SetVar(u"bActive", false);
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(self, u"idle");
|
2021-12-05 17:54:36 +00:00
|
|
|
GameMessages::SendPlayFXEffect(self->GetObjectID(), -1, u"spin", "active");
|
|
|
|
GameMessages::SendStopFXEffect(self, true, "indicator");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::PlayCinematic(Entity* self) {
|
|
|
|
auto* player = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"userID"));
|
|
|
|
|
|
|
|
if (player == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& cine = self->GetVar<std::u16string>(u"cinematic");
|
|
|
|
|
|
|
|
if (cine.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameMessages::SendPlayCinematic(player->GetObjectID(), cine, player->GetSystemAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::PlayAnim(Entity* self, Entity* player, const std::string& animName) {
|
|
|
|
const auto animTime = animName == "spinjitzu-staff-end" ? 0.5f : 1.0f;
|
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(player, animName);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
self->AddTimer("AnimDone_" + animName, animTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::OnHitOrHealResult(Entity* self, Entity* attacker, int32_t damage) {
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (destroyableComponent == nullptr || !attacker->IsPlayer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->GetVar<bool>(u"bActive")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto activaterID = self->GetVar<LWOOBJID>(u"activaterID");
|
|
|
|
|
|
|
|
auto* activator = EntityManager::Instance()->GetEntity(activaterID);
|
|
|
|
|
|
|
|
// TODO: Missions
|
|
|
|
if (activator != nullptr) {
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* missionComponent = activator->GetComponent<MissionComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (missionComponent != nullptr) {
|
|
|
|
for (const auto missionID : m_MissionsToUpdate) {
|
|
|
|
missionComponent->ForceProgressValue(missionID, 1, self->GetLOT());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
self->Smash(attacker->GetObjectID(), eKillType::SILENT);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
self->CancelAllTimers();
|
|
|
|
|
|
|
|
auto* standObj = GetStandObj(self);
|
|
|
|
|
|
|
|
if (standObj != nullptr) {
|
|
|
|
GameMessages::SendPlayFXEffect(standObj->GetObjectID(), 4946, u"explode", "explode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AmSkullkinDrill::OnTimerDone(Entity* self, std::string timerName) {
|
|
|
|
if (timerName == "killDrill") {
|
|
|
|
const auto childID = self->GetVar<LWOOBJID>(u"ChildSmash");
|
|
|
|
|
|
|
|
auto* child = EntityManager::Instance()->GetEntity(childID);
|
|
|
|
|
|
|
|
if (child != nullptr) {
|
2023-05-02 22:39:21 +00:00
|
|
|
child->Smash(self->GetObjectID(), eKillType::SILENT);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self->SetNetworkVar(u"bIsInUse", false);
|
|
|
|
self->SetVar(u"bActive", true);
|
|
|
|
self->SetVar(u"activaterID", LWOOBJID_EMPTY);
|
|
|
|
|
|
|
|
auto* standObj = GetStandObj(self);
|
|
|
|
|
|
|
|
if (standObj != nullptr) {
|
|
|
|
standObj->SetVar(u"bActive", true);
|
|
|
|
}
|
|
|
|
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* movingPlatformComponent = self->GetComponent<MovingPlatformComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
if (movingPlatformComponent == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
movingPlatformComponent->GotoWaypoint(0);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& data = GeneralUtils::SplitString(timerName, '_');
|
|
|
|
|
|
|
|
if (data.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data[0] == "AnimDone") {
|
|
|
|
const auto& animName = data[1];
|
|
|
|
|
|
|
|
const auto playerID = self->GetVar<LWOOBJID>(u"userID");
|
|
|
|
|
|
|
|
auto* player = EntityManager::Instance()->GetEntity(playerID);
|
|
|
|
|
|
|
|
if (player == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animName == "spinjitzu-staff-windup") {
|
|
|
|
TriggerDrill(self);
|
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(player, u"spinjitzu-staff-loop");
|
2021-12-05 17:54:36 +00:00
|
|
|
} else if (animName == "spinjitzu-staff-end") {
|
|
|
|
FreezePlayer(self, player, false);
|
|
|
|
|
|
|
|
self->SetVar(u"userID", LWOOBJID_EMPTY);
|
|
|
|
|
|
|
|
GameMessages::SendStopFXEffect(player, true, "tornado");
|
|
|
|
GameMessages::SendStopFXEffect(player, true, "staff");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (data[0] == "TryUnFreezeAgain") {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|