Organize dScripts (#814)

* Organize dScripts

whitespace

Remove parent scope

Remove parent scope from initial setter

Remove debug

Remove helper programs

* Fix NtImagimeterVisibility script

Co-authored-by: aronwk-aaron <aronwk.aaron@gmail.com>
This commit is contained in:
David Markowitz
2022-11-03 10:57:54 -07:00
committed by GitHub
parent b974eed8f5
commit 8d37d9b681
567 changed files with 886 additions and 252 deletions

View File

@@ -0,0 +1,9 @@
set(DSCRIPTS_SOURCES_CLIENT)
add_subdirectory(ai)
foreach(file ${DSCRIPTS_SOURCES_CLIENT_AI})
set(DSCRIPTS_SOURCES_CLIENT ${DSCRIPTS_SOURCES_CLIENT} "ai/${file}")
endforeach()
set(DSCRIPTS_SOURCES_CLIENT ${DSCRIPTS_SOURCES_CLIENT} PARENT_SCOPE)

View File

@@ -0,0 +1,9 @@
set(DSCRIPTS_SOURCES_CLIENT_AI)
add_subdirectory(PR)
foreach(file ${DSCRIPTS_SOURCES_CLIENT_AI_PR})
set(DSCRIPTS_SOURCES_CLIENT_AI ${DSCRIPTS_SOURCES_CLIENT_AI} "PR/${file}")
endforeach()
set(DSCRIPTS_SOURCES_CLIENT_AI ${DSCRIPTS_SOURCES_CLIENT_AI} PARENT_SCOPE)

View File

@@ -0,0 +1,4 @@
set(DSCRIPTS_SOURCES_CLIENT_AI_PR
"PrWhistle.cpp"
"CrabServer.cpp"
PARENT_SCOPE)

View File

@@ -0,0 +1,43 @@
#include "CrabServer.h"
#include "PetComponent.h"
void CrabServer::OnStartup(Entity* self) {
auto* petComponent = self->GetComponent<PetComponent>();
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
auto* petComponent = self->GetComponent<PetComponent>();
if (petComponent == nullptr || petComponent->GetOwner() != nullptr)
return;
self->Smash(self->GetObjectID(), SILENT);
}
}
void CrabServer::OnNotifyPetTamingMinigame(Entity* self, Entity* tamer, eNotifyType type) {
if (type == NOTIFY_TYPE_BEGIN) {
self->CancelTimer("killself");
} else if (type == NOTIFY_TYPE_QUIT || type == NOTIFY_TYPE_FAILED) {
self->Smash(self->GetObjectID(), SILENT);
} else if (type == NOTIFY_TYPE_SUCCESS) {
auto* petComponent = self->GetComponent<PetComponent>();
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);
}
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "CppScripts.h"
class CrabServer : public CppScripts::Script
{
public:
void OnStartup(Entity* self) override;
void OnTimerDone(Entity* self, std::string timerName) override;
void OnNotifyPetTamingMinigame(Entity* self, Entity* tamer, eNotifyType type) override;
};

View File

@@ -0,0 +1,14 @@
#include "PrWhistle.h"
#include "Character.h"
#include "Entity.h"
void PrWhistle::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) {
if (args == "unlockEmote") {
auto* character = sender->GetCharacter();
if (character != nullptr) {
character->UnlockEmote(115);
}
}
}

View File

@@ -0,0 +1,10 @@
#pragma once
#include "CppScripts.h"
class PrWhistle : public CppScripts::Script
{
public:
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) override;
};