DarkflameServer/dScripts/02_server/Objects/StinkyFishTarget.cpp

46 lines
1.3 KiB
C++
Raw Permalink Normal View History

#include "StinkyFishTarget.h"
#include "EntityManager.h"
#include "EntityInfo.h"
#include "Entity.h"
2022-07-28 13:39:57 +00:00
void StinkyFishTarget::OnStartup(Entity* self) {
auto position = self->GetPosition();
position.SetY(position.GetY() - 0.5f);
self->SetPosition(position);
}
2022-07-28 13:39:57 +00:00
void StinkyFishTarget::OnSkillEventFired(Entity* self, Entity* caster, const std::string& message) {
if (message != "stinkfish" || self->GetVar<bool>(u"used"))
return;
2022-07-28 13:39:57 +00:00
self->SetVar<bool>(u"used", true);
self->SetVar<LWOOBJID>(u"player", caster->GetObjectID());
2022-07-28 13:39:57 +00:00
EntityInfo entityInfo{};
entityInfo.lot = SHARK_LOT;
2022-07-28 13:39:57 +00:00
entityInfo.pos = self->GetPosition();
entityInfo.rot = self->GetRotation();
entityInfo.spawnerID = self->GetObjectID();
entityInfo.settings = {
new LDFData<bool>(u"no_timed_spawn", true)
};
auto* fish = Game::entityManager->CreateEntity(entityInfo);
Game::entityManager->ConstructEntity(fish);
2022-07-28 13:39:57 +00:00
self->SetVar<LWOOBJID>(u"fish", fish->GetObjectID());
self->AddTimer("smash", 5.0f);
}
2022-07-28 13:39:57 +00:00
void StinkyFishTarget::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "smash") {
const auto playerID = self->GetVar<LWOOBJID>(u"player");
auto* fish = Game::entityManager->GetEntity(self->GetVar<LWOOBJID>(u"fish"));
if (fish) {
2022-07-28 13:39:57 +00:00
fish->Smash(playerID);
self->Smash(playerID);
}
}
}