2021-12-05 17:54:36 +00:00
|
|
|
#include "AgSpaceStuff.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "EntityInfo.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "GeneralUtils.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "EntityManager.h"
|
2023-03-20 13:10:52 +00:00
|
|
|
#include "RenderComponent.h"
|
|
|
|
#include "Entity.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void AgSpaceStuff::OnStartup(Entity* self) {
|
|
|
|
self->AddTimer("FloaterScale", 5.0f);
|
|
|
|
|
|
|
|
EntityInfo info{};
|
|
|
|
|
|
|
|
info.pos = { -418, 585, -30 };
|
|
|
|
info.lot = 33;
|
|
|
|
info.spawnerID = self->GetObjectID();
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* ref = Game::entityManager->CreateEntity(info);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->ConstructEntity(ref);
|
2021-12-08 02:14:15 +00:00
|
|
|
|
|
|
|
self->SetVar(u"ShakeObject", ref->GetObjectID());
|
|
|
|
|
2022-01-01 08:02:28 +00:00
|
|
|
self->AddTimer("ShipShakeIdle", 2.0f);
|
2021-12-08 02:14:15 +00:00
|
|
|
self->SetVar(u"RandomTime", 10);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AgSpaceStuff::OnTimerDone(Entity* self, std::string timerName) {
|
|
|
|
if (timerName == "FloaterScale") {
|
|
|
|
int scaleType = GeneralUtils::GenerateRandomNumber<int>(1, 5);
|
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(self, u"scale_0" + GeneralUtils::to_u16string(scaleType));
|
2021-12-05 17:54:36 +00:00
|
|
|
self->AddTimer("FloaterPath", 0.4);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else if (timerName == "FloaterPath") {
|
2021-12-05 17:54:36 +00:00
|
|
|
int pathType = GeneralUtils::GenerateRandomNumber<int>(1, 4);
|
|
|
|
int randTime = GeneralUtils::GenerateRandomNumber<int>(20, 25);
|
|
|
|
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(self, u"path_0" + (GeneralUtils::to_u16string(pathType)));
|
2021-12-05 17:54:36 +00:00
|
|
|
self->AddTimer("FloaterScale", randTime);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else if (timerName == "ShipShakeExplode") {
|
2021-12-08 02:14:15 +00:00
|
|
|
DoShake(self, true);
|
2022-07-28 13:39:57 +00:00
|
|
|
} else if (timerName == "ShipShakeIdle") {
|
2021-12-08 02:14:15 +00:00
|
|
|
DoShake(self, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AgSpaceStuff::DoShake(Entity* self, bool explodeIdle) {
|
|
|
|
|
|
|
|
if (!explodeIdle) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* ref = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"ShakeObject"));
|
2021-12-08 02:14:15 +00:00
|
|
|
|
|
|
|
const auto randomTime = self->GetVar<int>(u"RandomTime");
|
|
|
|
auto time = GeneralUtils::GenerateRandomNumber<int>(0, randomTime + 1);
|
|
|
|
|
|
|
|
if (time < randomTime / 2) {
|
|
|
|
time += randomTime / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->AddTimer("ShipShakeIdle", static_cast<float>(time));
|
|
|
|
|
|
|
|
if (ref)
|
|
|
|
GameMessages::SendPlayEmbeddedEffectOnAllClientsNearObject(ref, FXName, ref->GetObjectID(), 500.0f);
|
|
|
|
|
|
|
|
auto* debrisObject = GetEntityInGroup(DebrisFX);
|
|
|
|
|
|
|
|
if (debrisObject)
|
|
|
|
GameMessages::SendPlayFXEffect(debrisObject, -1, u"DebrisFall", "Debris", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
|
|
|
|
|
|
|
|
const auto randomFx = GeneralUtils::GenerateRandomNumber<int>(0, 3);
|
|
|
|
|
|
|
|
auto* shipFxObject = GetEntityInGroup(ShipFX);
|
|
|
|
if (shipFxObject) {
|
|
|
|
std::string effectType = "shipboom" + std::to_string(randomFx);
|
|
|
|
GameMessages::SendPlayFXEffect(shipFxObject, 559, GeneralUtils::ASCIIToUTF16(effectType), "FX", LWOOBJID_EMPTY, 1.0f, 1.0f, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
self->AddTimer("ShipShakeExplode", 5.0f);
|
|
|
|
|
|
|
|
auto* shipFxObject2 = GetEntityInGroup(ShipFX2);
|
|
|
|
if (shipFxObject2)
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(shipFxObject2, u"explosion");
|
2022-07-28 13:39:57 +00:00
|
|
|
} else {
|
2021-12-08 02:14:15 +00:00
|
|
|
auto* shipFxObject = GetEntityInGroup(ShipFX);
|
|
|
|
auto* shipFxObject2 = GetEntityInGroup(ShipFX2);
|
|
|
|
|
|
|
|
if (shipFxObject)
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(shipFxObject, u"idle");
|
2021-12-08 02:14:15 +00:00
|
|
|
|
|
|
|
if (shipFxObject2)
|
2023-03-20 13:10:52 +00:00
|
|
|
RenderComponent::PlayAnimation(shipFxObject2, u"idle");
|
2021-12-08 02:14:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Entity* AgSpaceStuff::GetEntityInGroup(const std::string& group) {
|
2023-07-15 20:56:33 +00:00
|
|
|
auto entities = Game::entityManager->GetEntitiesInGroup(group);
|
2021-12-08 02:14:15 +00:00
|
|
|
Entity* en = nullptr;
|
|
|
|
|
|
|
|
for (auto entity : entities) {
|
|
|
|
if (entity) {
|
|
|
|
en = entity;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return en;
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|