Merge pull request #508 from aronwk-aaron/Frostburgh

Frostburgh Server fixes
This commit is contained in:
David Markowitz 2022-04-18 22:58:02 -07:00 committed by GitHub
commit 80a09881c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 199 additions and 34 deletions

View File

@ -53,6 +53,11 @@ RacingControlComponent::RacingControlComponent(Entity *parent)
m_MainWorld = 1200;
break;
case 1261:
m_ActivityID = 60;
m_MainWorld = 1260;
break;
case 1303:
m_ActivityID = 39;
m_MainWorld = 1300;

View File

@ -7,10 +7,16 @@
class AgFans : public CppScripts::Script
{
public:
void OnStartup(Entity* self);
void OnDie(Entity* self, Entity* killer);
void OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2,
int32_t param3);
void OnStartup(Entity* self) override;
void OnDie(Entity* self, Entity* killer) override;
void OnFireEventServerSide(
Entity *self,
Entity *sender,
std::string args,
int32_t param1,
int32_t param2,
int32_t param3
) override;
private:
void ToggleFX(Entity* self, bool hit);
};

View File

@ -1,4 +1,4 @@
//I can feel my soul being torn apart with every script added to this monstrosity.
//I can feel my soul being torn apart with every script added to this monstrosity.
// skate fast eat trash
// do you think god stays in heaven because he too lives in fear of what he's created?
@ -274,6 +274,10 @@
#include "AgSurvivalMech.h"
#include "AgSurvivalSpiderling.h"
// Frostburgh Scripts
#include "RockHydrantBroken.h"
#include "WhFans.h"
//Big bad global bc this is a namespace and not a class:
InvalidScript* invalidToReturn = new InvalidScript();
std::map<std::string, CppScripts::Script*> m_Scripts;
@ -795,6 +799,12 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
else if (scriptName == "scripts\\EquipmentScripts\\BuccaneerValiantShip.lua")
script = new BuccaneerValiantShip();
// FB
else if (scriptName == "scripts\\ai\\NS\\WH\\L_ROCKHYDRANT_BROKEN.lua")
script = new RockHydrantBroken();
else if (scriptName == "scripts\\ai\\NS\\L_NS_WH_FANS.lua")
script = new WhFans();
//Ignore these scripts:
else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua")
script = invalidToReturn;

View File

@ -2,7 +2,7 @@
#include "EntityManager.h"
#include "GameMessages.h"
void HydrantBroken::OnStartup(Entity* self)
void HydrantBroken::OnStartup(Entity* self)
{
self->AddTimer("playEffect", 1);
@ -10,8 +10,6 @@ void HydrantBroken::OnStartup(Entity* self)
const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant);
Game::logger->Log("HydrantBroken", "Broken Hydrant spawned (%s)\n", hydrant.c_str());
for (auto* bouncer : bouncers)
{
self->SetVar<LWOOBJID>(u"bouncer", bouncer->GetObjectID());
@ -20,11 +18,11 @@ void HydrantBroken::OnStartup(Entity* self)
GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"enableCollision", UNASSIGNED_SYSTEM_ADDRESS);
}
self->AddTimer("KillBroken", 25);
}
void HydrantBroken::OnTimerDone(Entity* self, std::string timerName)
void HydrantBroken::OnTimerDone(Entity* self, std::string timerName)
{
if (timerName == "KillBroken")
{

View File

@ -2,20 +2,18 @@
#include "EntityManager.h"
#include "GeneralUtils.h"
void HydrantSmashable::OnDie(Entity* self, Entity* killer)
void HydrantSmashable::OnDie(Entity* self, Entity* killer)
{
const auto hydrantName = self->GetVar<std::u16string>(u"hydrant");
LDFBaseData* data = new LDFData<std::string>(u"hydrant", GeneralUtils::UTF16ToWTF8(hydrantName));
EntityInfo info {};
info.lot = 7328;
info.lot = HYDRANT_BROKEN;
info.pos = self->GetPosition();
info.rot = self->GetRotation();
info.settings = {data};
info.spawnerID = self->GetSpawnerID();
Game::logger->Log("HydrantBroken", "Hydrant spawned (%s)\n", data->GetString().c_str());
auto* hydrant = EntityManager::Instance()->CreateEntity(info);

View File

@ -1,8 +1,10 @@
#pragma once
#include "CppScripts.h"
class HydrantSmashable : public CppScripts::Script
class HydrantSmashable : public CppScripts::Script
{
public:
void OnDie(Entity* self, Entity* killer) override;
void OnDie(Entity* self, Entity* killer) override;
private:
LOT HYDRANT_BROKEN = 7328;
};

View File

@ -0,0 +1,45 @@
#include "RockHydrantBroken.h"
#include "EntityManager.h"
#include "GameMessages.h"
void RockHydrantBroken::OnStartup(Entity* self)
{
self->AddTimer("playEffect", 1);
const auto hydrant = "hydrant" + self->GetVar<std::string>(u"hydrant");
const auto bouncers = EntityManager::Instance()->GetEntitiesInGroup(hydrant);
for (auto* bouncer : bouncers)
{
self->SetVar<LWOOBJID>(u"bouncer", bouncer->GetObjectID());
GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"enableCollision", UNASSIGNED_SYSTEM_ADDRESS);
}
self->AddTimer("KillBroken", 10);
}
void RockHydrantBroken::OnTimerDone(Entity* self, std::string timerName)
{
if (timerName == "KillBroken")
{
auto* bouncer = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"bouncer"));
if (bouncer != nullptr)
{
GameMessages::SendBouncerActiveStatus(bouncer->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS);
GameMessages::SendNotifyObject(bouncer->GetObjectID(), self->GetObjectID(), u"disableCollision", UNASSIGNED_SYSTEM_ADDRESS);
}
self->Kill();
}
else if (timerName == "playEffect")
{
GameMessages::SendPlayFXEffect(self->GetObjectID(), 4737, u"water", "water", LWOOBJID_EMPTY, 1, 1, true);
}
}

View File

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

View File

@ -1,24 +1,21 @@
#include "RockHydrantSmashable.h"
#include "EntityManager.h"
#include "SimplePhysicsComponent.h"
#include "Entity.h"
#include "GameMessages.h"
#include "Game.h"
#include "dLogger.h"
#include "GeneralUtils.h"
void RockHydrantSmashable::OnDie(Entity* self, Entity* killer) {
SimplePhysicsComponent* physics = self->GetComponent<SimplePhysicsComponent>();
NiPoint3 pos = physics->GetPosition();
void RockHydrantSmashable::OnDie(Entity* self, Entity* killer)
{
const auto hydrantName = self->GetVar<std::u16string>(u"hydrant");
EntityInfo info;
info.lot = 12293;
info.pos = pos;
info.spawner = nullptr;
LDFBaseData* data = new LDFData<std::string>(u"hydrant", GeneralUtils::UTF16ToWTF8(hydrantName));
EntityInfo info {};
info.lot = ROCK_HYDRANT_BROKEN;
info.pos = self->GetPosition();
info.rot = self->GetRotation();
info.settings = {data};
info.spawnerID = self->GetSpawnerID();
info.spawnerNodeID = 0;
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
if (newEntity) {
EntityManager::Instance()->ConstructEntity(newEntity);
}
}
auto* hydrant = EntityManager::Instance()->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(hydrant);
}

View File

@ -5,5 +5,7 @@ class RockHydrantSmashable : public CppScripts::Script
{
public:
void OnDie(Entity* self, Entity* killer);
private:
LOT ROCK_HYDRANT_BROKEN = 12293;
};

69
dScripts/WhFans.cpp Normal file
View File

@ -0,0 +1,69 @@
#include "WhFans.h"
#include "RenderComponent.h"
void WhFans::OnStartup(Entity* self) {
self->SetVar<bool>(u"alive", true);
self->SetVar<bool>(u"on", false);
ToggleFX(self, false);
}
void WhFans::ToggleFX(Entity* self, bool hit) {
std::string fanGroup;
const auto& groups = self->GetGroups();
if (!groups.empty()) {
fanGroup = groups[0];
} else {
fanGroup = "";
}
std::vector<Entity*> fanVolumes = EntityManager::Instance()->GetEntitiesInGroup(fanGroup);
auto* renderComponent = self->GetComponent<RenderComponent>();
if (renderComponent == nullptr) return;
if (fanVolumes.size() == 0 || !self->GetVar<bool>(u"alive")) return;
if (self->GetVar<bool>(u"on")) {
GameMessages::SendPlayAnimation(self, u"fan-off");
renderComponent->StopEffect("fanOn");
self->SetVar<bool>(u"on", false);
for (Entity* volume : fanVolumes) {
auto volumePhys = volume->GetComponent<PhantomPhysicsComponent>();
if (!volumePhys) continue;
volumePhys->SetPhysicsEffectActive(false);
EntityManager::Instance()->SerializeEntity(volume);
}
}
else if (!self->GetVar<bool>(u"on") && self->GetVar<bool>(u"alive")) {
GameMessages::SendPlayAnimation(self, u"fan-on");
self->SetVar<bool>(u"on", true);
for (Entity* volume : fanVolumes) {
auto volumePhys = volume->GetComponent<PhantomPhysicsComponent>();
if (!volumePhys) continue;
volumePhys->SetPhysicsEffectActive(true);
EntityManager::Instance()->SerializeEntity(volume);
}
}
}
void WhFans::OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) {
if (args.length() == 0 || !self->GetVar<bool>(u"alive")) return;
if ((args == "turnOn" && self->GetVar<bool>(u"on")) || (args == "turnOff" && !self->GetVar<bool>(u"on"))) return;
ToggleFX(self, false);
}
void WhFans::OnDie(Entity* self, Entity* killer) {
if (self->GetVar<bool>(u"on")) {
ToggleFX(self, true);
}
self->SetVar<bool>(u"alive", false);
}

23
dScripts/WhFans.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include "CppScripts.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "PhantomPhysicsComponent.h"
class WhFans : public CppScripts::Script
{
public:
void OnStartup(Entity* self) override;
void OnDie(Entity* self, Entity* killer) override;
void OnFireEventServerSide(
Entity *self,
Entity *sender,
std::string args,
int32_t param1,
int32_t param2,
int32_t param3
) override;
private:
void ToggleFX(Entity* self, bool hit);
};