2022-08-06 03:01:59 +00:00
|
|
|
#include "GfBanana.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "DestroyableComponent.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "EntityInfo.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
#include "EntityManager.h"
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void GfBanana::SpawnBanana(Entity* self) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto position = self->GetPosition();
|
|
|
|
const auto rotation = self->GetRotation();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
position.y += 12;
|
|
|
|
position.x -= rotation.GetRightVector().x * 5;
|
|
|
|
position.z -= rotation.GetRightVector().z * 5;
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
EntityInfo info{};
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
info.pos = position;
|
|
|
|
info.rot = rotation;
|
|
|
|
info.lot = 6909;
|
|
|
|
info.spawnerID = self->GetObjectID();
|
|
|
|
|
|
|
|
auto* entity = EntityManager::Instance()->CreateEntity(info);
|
|
|
|
|
|
|
|
EntityManager::Instance()->ConstructEntity(entity);
|
|
|
|
|
|
|
|
self->SetVar(u"banana", entity->GetObjectID());
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
entity->AddDieCallback([self]() {
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetVar(u"banana", LWOOBJID_EMPTY);
|
|
|
|
|
|
|
|
self->AddTimer("bananaTimer", 30);
|
2022-07-28 13:39:57 +00:00
|
|
|
});
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void GfBanana::OnStartup(Entity* self) {
|
2021-12-05 17:54:36 +00:00
|
|
|
SpawnBanana(self);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void GfBanana::OnHit(Entity* self, Entity* attacker) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* destroyable = self->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
destroyable->SetHealth(9999);
|
|
|
|
|
|
|
|
const auto bananaId = self->GetVar<LWOOBJID>(u"banana");
|
|
|
|
|
|
|
|
if (bananaId == LWOOBJID_EMPTY) return;
|
|
|
|
|
|
|
|
auto* bananaEntity = EntityManager::Instance()->GetEntity(bananaId);
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
if (bananaEntity == nullptr) {
|
2021-12-05 17:54:36 +00:00
|
|
|
self->SetVar(u"banana", LWOOBJID_EMPTY);
|
|
|
|
|
|
|
|
self->AddTimer("bananaTimer", 30);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2022-01-16 03:12:07 +00:00
|
|
|
bananaEntity->SetPosition(bananaEntity->GetPosition() - NiPoint3::UNIT_Y * 8);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
auto* bananaDestroyable = bananaEntity->GetComponent<DestroyableComponent>();
|
|
|
|
|
|
|
|
bananaDestroyable->SetHealth(0);
|
|
|
|
|
|
|
|
bananaDestroyable->Smash(attacker->GetObjectID());
|
|
|
|
|
|
|
|
/*
|
|
|
|
auto position = self->GetPosition();
|
|
|
|
const auto rotation = self->GetRotation();
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
position.y += 12;
|
|
|
|
position.x -= rotation.GetRightVector().x * 5;
|
|
|
|
position.z -= rotation.GetRightVector().z * 5;
|
|
|
|
|
|
|
|
EntityInfo info {};
|
|
|
|
|
|
|
|
info.pos = position;
|
|
|
|
info.rot = rotation;
|
|
|
|
info.lot = 6718;
|
|
|
|
info.spawnerID = self->GetObjectID();
|
|
|
|
|
|
|
|
auto* entity = EntityManager::Instance()->CreateEntity(info);
|
|
|
|
|
|
|
|
EntityManager::Instance()->ConstructEntity(entity, UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
*/
|
|
|
|
|
|
|
|
EntityManager::Instance()->SerializeEntity(self);
|
|
|
|
}
|
|
|
|
|
2022-07-28 13:39:57 +00:00
|
|
|
void GfBanana::OnTimerDone(Entity* self, std::string timerName) {
|
|
|
|
if (timerName == "bananaTimer") {
|
2021-12-05 17:54:36 +00:00
|
|
|
SpawnBanana(self);
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|