2021-12-05 17:54:36 +00:00
|
|
|
#include "CrabServer.h"
|
|
|
|
#include "PetComponent.h"
|
2023-05-02 22:39:21 +00:00
|
|
|
#include "ePetTamingNotifyType.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void CrabServer::OnStartup(Entity* self) {
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* petComponent = self->GetComponent<PetComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
if (petComponent == nullptr || petComponent->GetOwner() != nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Triggers the local crab script for taming etc.
|
|
|
|
auto tamer = self->GetVar<LWOOBJID>(u"tamer");
|
|
|
|
// Client compares this with player:GetID() which is a string, so we'll have to give it a string
|
|
|
|
self->SetNetworkVar(u"crabtamer", std::to_string(tamer));
|
|
|
|
|
|
|
|
// Kill if the player decides that the crab is not worthy
|
|
|
|
self->AddTimer("killself", 45.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrabServer::OnTimerDone(Entity* self, std::string timerName) {
|
|
|
|
if (timerName == "killself") {
|
|
|
|
|
|
|
|
// Don't accidentally kill a pet that is already owned
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* petComponent = self->GetComponent<PetComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
if (petComponent == nullptr || petComponent->GetOwner() != nullptr)
|
|
|
|
return;
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
self->Smash(self->GetObjectID(), eKillType::SILENT);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 22:39:21 +00:00
|
|
|
void CrabServer::OnNotifyPetTamingMinigame(Entity* self, Entity* tamer, ePetTamingNotifyType type) {
|
|
|
|
if (type == ePetTamingNotifyType::BEGIN) {
|
2021-12-05 17:54:36 +00:00
|
|
|
self->CancelTimer("killself");
|
2023-05-02 22:39:21 +00:00
|
|
|
} else if (type == ePetTamingNotifyType::QUIT || type == ePetTamingNotifyType::FAILED) {
|
|
|
|
self->Smash(self->GetObjectID(), eKillType::SILENT);
|
|
|
|
} else if (type == ePetTamingNotifyType::SUCCESS) {
|
2023-06-09 08:27:05 +00:00
|
|
|
auto* petComponent = self->GetComponent<PetComponent>();
|
2021-12-05 17:54:36 +00:00
|
|
|
if (petComponent == nullptr)
|
|
|
|
return;
|
|
|
|
// TODO: Remove custom group?
|
|
|
|
// Command the pet to the player as it may otherwise go to its spawn point which is non existant
|
|
|
|
// petComponent->Command(NiPoint3::ZERO, LWOOBJID_EMPTY, 6, 202, true);
|
|
|
|
}
|
|
|
|
}
|