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,4 @@
set(DSCRIPTS_SOURCES_AI_GENERAL
"InstanceExitTransferPlayerToLastNonInstance.cpp"
"LegoDieRoll.cpp"
PARENT_SCOPE)

View File

@@ -0,0 +1,56 @@
#include "InstanceExitTransferPlayerToLastNonInstance.h"
#include "GameMessages.h"
#include "Player.h"
#include "Character.h"
#include "dServer.h"
void InstanceExitTransferPlayerToLastNonInstance::OnUse(Entity* self, Entity* user) {
auto transferText = self->GetVar<std::u16string>(u"transferText");
if (transferText.empty())
transferText = u"DRAGON_EXIT_QUESTION";
GameMessages::SendDisplayMessageBox(
user->GetObjectID(),
true,
self->GetObjectID(),
u"Instance_Exit",
1,
transferText,
u"",
user->GetSystemAddress()
);
}
void InstanceExitTransferPlayerToLastNonInstance::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) {
auto* player = dynamic_cast<Player*>(sender);
if (player == nullptr)
return;
auto* character = sender->GetCharacter();
if (character != nullptr) {
if (identifier == u"Instance_Exit" && button == 1) {
auto lastInstance = character->GetLastNonInstanceZoneID();
// Sanity check
if (lastInstance == 0) {
switch (Game::server->GetZoneID()) {
case 2001:
lastInstance = 2000;
break;
case 1402:
lastInstance = 1400;
break;
default:
lastInstance = 1100;
break;
}
}
player->SendToZone(lastInstance);
}
}
GameMessages::SendTerminateInteraction(sender->GetObjectID(), eTerminateType::FROM_INTERACTION, self->GetObjectID());
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "CppScripts.h"
class InstanceExitTransferPlayerToLastNonInstance : public CppScripts::Script
{
public:
void OnUse(Entity* self, Entity* user) override;
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override;
};

View File

@@ -0,0 +1,52 @@
#include "LegoDieRoll.h"
#include "Entity.h"
#include "GameMessages.h"
#include "MissionComponent.h"
void LegoDieRoll::OnStartup(Entity* self) {
self->AddTimer("DoneRolling", 10.0f);
self->AddTimer("ThrowDice", LegoDieRoll::animTime);
}
void LegoDieRoll::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "DoneRolling") {
self->Smash(self->GetObjectID(), SILENT);
} else if (timerName == "ThrowDice") {
int dieRoll = GeneralUtils::GenerateRandomNumber<int>(1, 6);
switch (dieRoll) {
case 1:
GameMessages::SendPlayAnimation(self, u"roll-die-1");
break;
case 2:
GameMessages::SendPlayAnimation(self, u"roll-die-2");
break;
case 3:
GameMessages::SendPlayAnimation(self, u"roll-die-3");
break;
case 4:
GameMessages::SendPlayAnimation(self, u"roll-die-4");
break;
case 5:
GameMessages::SendPlayAnimation(self, u"roll-die-5");
break;
case 6:
{
GameMessages::SendPlayAnimation(self, u"roll-die-6");
// tracking the It's Truly Random Achievement
auto* owner = self->GetOwner();
auto* missionComponent = owner->GetComponent<MissionComponent>();
if (missionComponent != nullptr) {
const auto rollMissionState = missionComponent->GetMissionState(756);
if (rollMissionState == MissionState::MISSION_STATE_ACTIVE) {
missionComponent->ForceProgress(756, 1103, 1);
}
}
break;
}
default:
break;
}
}
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "CppScripts.h"
class LegoDieRoll : public CppScripts::Script {
public:
void OnStartup(Entity* self);
void OnTimerDone(Entity* self, std::string timerName);
private:
constexpr static const float animTime = 2.0f;
};