format codebase

This commit is contained in:
aronwk-aaron
2022-07-28 08:39:57 -05:00
parent 4f7aa11067
commit 19e77a38d8
881 changed files with 34700 additions and 38689 deletions

View File

@@ -5,241 +5,211 @@
#include "Character.h"
#include "dZoneManager.h"
void CavePrisonCage::OnStartup(Entity *self)
{
const auto& myNum = self->GetVar<std::u16string>(u"myNumber");
void CavePrisonCage::OnStartup(Entity* self) {
const auto& myNum = self->GetVar<std::u16string>(u"myNumber");
if (myNum.empty())
{
return;
}
if (myNum.empty()) {
return;
}
auto* spawner = dZoneManager::Instance()->GetSpawnersByName("PrisonCounterweight_0" + GeneralUtils::UTF16ToWTF8(myNum))[0];
auto* spawner = dZoneManager::Instance()->GetSpawnersByName("PrisonCounterweight_0" + GeneralUtils::UTF16ToWTF8(myNum))[0];
self->SetVar<Spawner*>(u"CWSpawner", spawner);
self->SetVar<Spawner*>(u"CWSpawner", spawner);
Setup(self, spawner);
Setup(self, spawner);
}
void CavePrisonCage::Setup(Entity *self, Spawner* spawner)
{
SpawnCounterweight(self, spawner);
void CavePrisonCage::Setup(Entity* self, Spawner* spawner) {
SpawnCounterweight(self, spawner);
NiPoint3 mypos = self->GetPosition();
NiQuaternion myrot = self->GetRotation();
NiPoint3 mypos = self->GetPosition();
NiQuaternion myrot = self->GetRotation();
mypos.y += 1.5;
mypos.z -= 0.5;
mypos.y += 1.5;
mypos.z -= 0.5;
EntityInfo info {};
info.lot = m_Villagers[self->GetVarAs<int32_t>(u"myNumber") - 1];
info.pos = mypos;
info.rot = myrot;
info.spawnerID = self->GetObjectID();
EntityInfo info{};
info.lot = m_Villagers[self->GetVarAs<int32_t>(u"myNumber") - 1];
info.pos = mypos;
info.rot = myrot;
info.spawnerID = self->GetObjectID();
// Spawn the villager inside the jail
auto* entity = EntityManager::Instance()->CreateEntity(info);
// Spawn the villager inside the jail
auto* entity = EntityManager::Instance()->CreateEntity(info);
// Save the villeger ID
self->SetVar<LWOOBJID>(u"villager", entity->GetObjectID());
// Save the villeger ID
self->SetVar<LWOOBJID>(u"villager", entity->GetObjectID());
// Construct the entity
EntityManager::Instance()->ConstructEntity(entity);
// Construct the entity
EntityManager::Instance()->ConstructEntity(entity);
}
void CavePrisonCage::OnRebuildNotifyState(Entity* self, eRebuildState state)
{
if (state != eRebuildState::REBUILD_RESETTING)
{
return;
}
void CavePrisonCage::OnRebuildNotifyState(Entity* self, eRebuildState state) {
if (state != eRebuildState::REBUILD_RESETTING) {
return;
}
auto* spawner = self->GetVar<Spawner*>(u"CWSpawner");
auto* spawner = self->GetVar<Spawner*>(u"CWSpawner");
if (spawner == nullptr)
{
return;
}
if (spawner == nullptr) {
return;
}
spawner->Reset();
spawner->Reset();
SpawnCounterweight(self, spawner);
SpawnCounterweight(self, spawner);
}
void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner)
{
spawner->Reset();
void CavePrisonCage::SpawnCounterweight(Entity* self, Spawner* spawner) {
spawner->Reset();
auto* counterweight = spawner->Spawn();
auto* counterweight = spawner->Spawn();
self->SetVar<LWOOBJID>(u"Counterweight", counterweight->GetObjectID());
self->SetVar<LWOOBJID>(u"Counterweight", counterweight->GetObjectID());
auto* rebuildComponent = counterweight->GetComponent<RebuildComponent>();
auto* rebuildComponent = counterweight->GetComponent<RebuildComponent>();
if (rebuildComponent != nullptr)
{
rebuildComponent->AddRebuildStateCallback([this, self] (eRebuildState state) {
OnRebuildNotifyState(self, state);
});
if (rebuildComponent != nullptr) {
rebuildComponent->AddRebuildStateCallback([this, self](eRebuildState state) {
OnRebuildNotifyState(self, state);
});
rebuildComponent->AddRebuildCompleteCallback([this, self] (Entity* user) {
// The counterweight is a simple mover, which is not implemented, so we'll just set it's position
auto* counterweight = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
rebuildComponent->AddRebuildCompleteCallback([this, self](Entity* user) {
// The counterweight is a simple mover, which is not implemented, so we'll just set it's position
auto* counterweight = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
if (counterweight == nullptr)
{
return;
}
if (counterweight == nullptr) {
return;
}
// Move the counterweight down 2 units
counterweight->SetPosition(counterweight->GetPosition() + NiPoint3(0, -2, 0));
// Move the counterweight down 2 units
counterweight->SetPosition(counterweight->GetPosition() + NiPoint3(0, -2, 0));
// Serialize the counterweight
EntityManager::Instance()->SerializeEntity(counterweight);
// Serialize the counterweight
EntityManager::Instance()->SerializeEntity(counterweight);
// notifyPlatformAtLastWaypoint
// Save the userID as Builder
self->SetVar<LWOOBJID>(u"Builder", user->GetObjectID());
// notifyPlatformAtLastWaypoint
// Get the button and make sure it still exists
auto* button = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
// Save the userID as Builder
self->SetVar<LWOOBJID>(u"Builder", user->GetObjectID());
if (button == nullptr)
{
return;
}
// Get the button and make sure it still exists
auto* button = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
// Play the 'down' animation on the button
GameMessages::SendPlayAnimation(button, u"down");
if (button == nullptr) {
return;
}
// Setup a timer named 'buttonGoingDown' to be triggered in 5 seconds
self->AddTimer("buttonGoingDown", 5.0f);
});
}
// Play the 'down' animation on the button
GameMessages::SendPlayAnimation(button, u"down");
if (self->GetVar<LWOOBJID>(u"Button"))
{
return;
}
// Setup a timer named 'buttonGoingDown' to be triggered in 5 seconds
self->AddTimer("buttonGoingDown", 5.0f);
});
}
GetButton(self);
if (self->GetVar<LWOOBJID>(u"Button")) {
return;
}
GetButton(self);
}
void CavePrisonCage::GetButton(Entity* self)
{
const auto buttons = EntityManager::Instance()->GetEntitiesInGroup("PrisonButton_0" + std::to_string(self->GetVarAs<int32_t>(u"myNumber")));
void CavePrisonCage::GetButton(Entity* self) {
const auto buttons = EntityManager::Instance()->GetEntitiesInGroup("PrisonButton_0" + std::to_string(self->GetVarAs<int32_t>(u"myNumber")));
if (buttons.size() == 0)
{
// Try again in 0.5 seconds
self->AddCallbackTimer(0.5, [this, self] () {
GetButton(self);
});
if (buttons.size() == 0) {
// Try again in 0.5 seconds
self->AddCallbackTimer(0.5, [this, self]() {
GetButton(self);
});
return;
}
return;
}
auto* button = buttons[0];
auto* button = buttons[0];
self->SetVar<LWOOBJID>(u"Button", button->GetObjectID());
self->SetVar<LWOOBJID>(u"Button", button->GetObjectID());
}
void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName)
{
// the anim of the button down is over
if (timerName == "buttonGoingDown")
{
// Play the 'up' animation
GameMessages::SendPlayAnimation(self, u"up");
void CavePrisonCage::OnTimerDone(Entity* self, std::string timerName) {
// the anim of the button down is over
if (timerName == "buttonGoingDown") {
// Play the 'up' animation
GameMessages::SendPlayAnimation(self, u"up");
// Setup a timer named 'CageOpen' to be triggered in 1 second
self->AddTimer("CageOpen", 1.0f);
}
else if (timerName == "CageOpen")
{
// play the idle open anim
GameMessages::SendPlayAnimation(self, u"idle-up");
// Setup a timer named 'CageOpen' to be triggered in 1 second
self->AddTimer("CageOpen", 1.0f);
} else if (timerName == "CageOpen") {
// play the idle open anim
GameMessages::SendPlayAnimation(self, u"idle-up");
// Get the villeger
auto* villager = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
// Get the villeger
auto* villager = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
if (villager == nullptr)
{
return;
}
if (villager == nullptr) {
return;
}
GameMessages::SendNotifyClientObject(villager->GetObjectID(), u"TimeToChat", 0, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::SendNotifyClientObject(villager->GetObjectID(), u"TimeToChat", 0, 0, LWOOBJID_EMPTY, "", UNASSIGNED_SYSTEM_ADDRESS);
// Get the builder and make sure it still exists
auto* builder = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Builder"));
// Get the builder and make sure it still exists
auto* builder = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Builder"));
if (builder == nullptr)
{
return;
}
if (builder == nullptr) {
return;
}
const auto flagNum = 2020 + self->GetVarAs<int32_t>(u"myNumber");
const auto flagNum = 2020 + self->GetVarAs<int32_t>(u"myNumber");
// Set the flag on the builder character
builder->GetCharacter()->SetPlayerFlag(flagNum, true);
// Set the flag on the builder character
builder->GetCharacter()->SetPlayerFlag(flagNum, true);
// Setup a timer named 'VillagerEscape' to be triggered in 5 seconds
self->AddTimer("VillagerEscape", 5.0f);
}
else if (timerName == "VillagerEscape")
{
// Get the villeger and make sure it still exists
auto* villager = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
if (villager == nullptr)
{
return;
}
// Setup a timer named 'VillagerEscape' to be triggered in 5 seconds
self->AddTimer("VillagerEscape", 5.0f);
} else if (timerName == "VillagerEscape") {
// Get the villeger and make sure it still exists
auto* villager = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"villager"));
// Kill the villager
villager->Kill();
if (villager == nullptr) {
return;
}
// Setup a timer named 'SmashCounterweight' to be triggered in 2 seconds
self->AddTimer("SmashCounterweight", 2.0f);
}
else if (timerName == "SmashCounterweight")
{
// Get the counterweight and make sure it still exists
auto* counterweight = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
// Kill the villager
villager->Kill();
if (counterweight == nullptr)
{
return;
}
// Setup a timer named 'SmashCounterweight' to be triggered in 2 seconds
self->AddTimer("SmashCounterweight", 2.0f);
} else if (timerName == "SmashCounterweight") {
// Get the counterweight and make sure it still exists
auto* counterweight = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Counterweight"));
// Smash the counterweight
counterweight->Smash();
if (counterweight == nullptr) {
return;
}
// Get the button and make sure it still exists
auto* button = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
// Smash the counterweight
counterweight->Smash();
if (button == nullptr)
{
return;
}
// Get the button and make sure it still exists
auto* button = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"Button"));
// Play the 'up' animation on the button
GameMessages::SendPlayAnimation(button, u"up");
if (button == nullptr) {
return;
}
// Setup a timer named 'CageClosed' to be triggered in 1 second
self->AddTimer("CageClosed", 1.0f);
}
else if (timerName == "CageClosed")
{
// play the idle closed anim
GameMessages::SendPlayAnimation(self, u"idle");
// Play the 'up' animation on the button
GameMessages::SendPlayAnimation(button, u"up");
// Setup a timer named 'ResetPrison' to be triggered in 10 seconds
self->AddTimer("ResetPrison", 10.0f);
}
else if (timerName == "ResetPrison")
{
Setup(self, self->GetVar<Spawner*>(u"CWSpawner"));
}
// Setup a timer named 'CageClosed' to be triggered in 1 second
self->AddTimer("CageClosed", 1.0f);
} else if (timerName == "CageClosed") {
// play the idle closed anim
GameMessages::SendPlayAnimation(self, u"idle");
// Setup a timer named 'ResetPrison' to be triggered in 10 seconds
self->AddTimer("ResetPrison", 10.0f);
} else if (timerName == "ResetPrison") {
Setup(self, self->GetVar<Spawner*>(u"CWSpawner"));
}
}