DarkflameServer/dScripts/02_server/Pets/PetFromObjectServer.cpp

36 lines
1.1 KiB
C++
Raw Permalink Normal View History

#include "PetFromObjectServer.h"
#include "PetComponent.h"
#include "ePetTamingNotifyType.h"
2022-07-28 13:39:57 +00:00
void PetFromObjectServer::OnStartup(Entity* self) {
self->SetNetworkVar(u"pettamer", std::to_string(self->GetVar<LWOOBJID>(u"tamer")));
self->AddTimer("killSelf", 45.0f);
}
2022-07-28 13:39:57 +00:00
void PetFromObjectServer::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "killSelf") {
const auto* petComponent = self->GetComponent<PetComponent>();
if (petComponent == nullptr || petComponent->GetOwner() != nullptr)
return;
self->Smash(self->GetObjectID(), eKillType::SILENT);
2022-07-28 13:39:57 +00:00
}
}
void PetFromObjectServer::OnNotifyPetTamingMinigame(Entity* self, Entity* tamer, ePetTamingNotifyType type) {
2022-07-28 13:39:57 +00:00
switch (type) {
case ePetTamingNotifyType::BEGIN:
2022-07-28 13:39:57 +00:00
self->CancelAllTimers();
break;
case ePetTamingNotifyType::QUIT:
case ePetTamingNotifyType::FAILED:
self->Smash(self->GetObjectID(), eKillType::SILENT);
2022-07-28 13:39:57 +00:00
break;
case ePetTamingNotifyType::SUCCESS:
2022-07-28 13:39:57 +00:00
// TODO: Remove from groups?
GameMessages::SendNotifyClientObject(self->GetObjectID(), u"UpdateSuccessPicking", 0,
0, tamer->GetObjectID(), "", UNASSIGNED_SYSTEM_ADDRESS);
default:
break;
}
}