Scripts for the AG sentinel camp QB wall (#761)

* Scripts for the AG sentinel camp QB wall

* use lookat

* Address feedback

* Fix stromling spawner

* fix aggro and remove logs

Co-authored-by: Jett <55758076+Jettford@users.noreply.github.com>
This commit is contained in:
Aaron Kimbrell 2022-09-01 21:44:26 -05:00 committed by GitHub
parent e3077aa410
commit 1af3e59348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 183 additions and 0 deletions

15
dScripts/AgQbWall.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "AgQbWall.h"
void AgQbWall::OnRebuildComplete(Entity* self, Entity* player) {
self->SetVar(u"player", player->GetObjectID());
auto targetWallSpawners = GeneralUtils::UTF16ToWTF8(self->GetVar<std::u16string>(u"spawner"));
if (targetWallSpawners != "") {
auto groupObjs = EntityManager::Instance()->GetEntitiesInGroup(targetWallSpawners);
for (auto* obj : groupObjs) {
if (obj) {
obj->SetVar(u"player", player->GetObjectID());
obj->OnFireEventServerSide(self, "spawnMobs");
}
}
}
}

7
dScripts/AgQbWall.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include "CppScripts.h"
class AgQbWall : public CppScripts::Script {
public:
void OnRebuildComplete(Entity* self, Entity* player) override;
};

View File

@ -21,6 +21,7 @@ set(DSCRIPT_SOURCES "ActivityManager.cpp"
"AgPropGuard.cpp" "AgPropGuard.cpp"
"AgPropguards.cpp" "AgPropguards.cpp"
"AgQbElevator.cpp" "AgQbElevator.cpp"
"AgQbWall.cpp"
"AgSalutingNpcs.cpp" "AgSalutingNpcs.cpp"
"AgShipPlayerDeathTrigger.cpp" "AgShipPlayerDeathTrigger.cpp"
"AgShipPlayerShockServer.cpp" "AgShipPlayerShockServer.cpp"
@ -206,6 +207,7 @@ set(DSCRIPT_SOURCES "ActivityManager.cpp"
"PrSeagullFly.cpp" "PrSeagullFly.cpp"
"PrWhistle.cpp" "PrWhistle.cpp"
"QbEnemyStunner.cpp" "QbEnemyStunner.cpp"
"QbSpawner.cpp"
"RaceImagineCrateServer.cpp" "RaceImagineCrateServer.cpp"
"RaceImaginePowerup.cpp" "RaceImaginePowerup.cpp"
"RaceMaelstromGeiser.cpp" "RaceMaelstromGeiser.cpp"

View File

@ -61,6 +61,8 @@
#include "VeMissionConsole.h" #include "VeMissionConsole.h"
#include "VeEpsilonServer.h" #include "VeEpsilonServer.h"
#include "AgSurvivalBuffStation.h" #include "AgSurvivalBuffStation.h"
#include "QbSpawner.h"
#include "AgQbWall.h"
// NS Scripts // NS Scripts
#include "NsModularBuild.h" #include "NsModularBuild.h"
@ -466,6 +468,10 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
script = new WildAmbients(); script = new WildAmbients();
else if (scriptName == "scripts\\ai\\NS\\NS_PP_01\\L_NS_PP_01_TELEPORT.lua") else if (scriptName == "scripts\\ai\\NS\\NS_PP_01\\L_NS_PP_01_TELEPORT.lua")
script = new PropertyDeathPlane(); script = new PropertyDeathPlane();
else if (scriptName == "scripts\\02_server\\Map\\General\\L_QB_SPAWNER.lua")
script = new QbSpawner();
else if (scriptName == "scripts\\ai\\AG\\L_AG_QB_Wall.lua")
script = new AgQbWall();
//GF: //GF:
else if (scriptName == "scripts\\02_server\\Map\\GF\\L_GF_TORCH.lua") else if (scriptName == "scripts\\02_server\\Map\\GF\\L_GF_TORCH.lua")

136
dScripts/QbSpawner.cpp Normal file
View File

@ -0,0 +1,136 @@
#include "QbSpawner.h"
#include "BaseCombatAIComponent.h"
#include "MovementAIComponent.h"
void QbSpawner::OnStartup(Entity* self) {
auto mobNum = self->GetVar<int>(u"mobNum");
auto spawnDist = self->GetVar<float>(u"spawnDist");
auto mobTemplate = self->GetVar<LWOOBJID>(u"mobTemplate");
auto spawnTime = self->GetVar<float>(u"spawnTime");
if (!mobNum) self->SetVar<int>(u"mobNum", m_DefaultMobNum);
if (!spawnDist) self->SetVar<float>(u"spawnDist", m_DefaultSpawnDist);
if (!mobTemplate) self->SetVar<LWOOBJID>(u"mobTemplate", m_DefaultMobTemplate);
if (!spawnTime) self->SetVar<float>(u"spawnTime", m_DefaultSpawnTime);
// go ahead and setup the mob table here
std::vector<LWOOBJID> mobTable;
mobTable.assign(self->GetVar<int>(u"mobNum"), LWOOBJID_EMPTY);
self->SetVar<std::vector<LWOOBJID>>(u"mobTable", mobTable);
}
void QbSpawner::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
auto gateObjID = sender->GetObjectID();
if (!gateObjID) return;
if (args == "spawnMobs") {
self->SetVar(u"gateObj", gateObjID);
auto spawnTime = self->GetVar<float>(u"spawnTime");
self->AddTimer("SpawnMobEnemies", spawnTime);
}
}
void QbSpawner::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "SpawnMobEnemies") {
auto mobTable = self->GetVar<std::vector<LWOOBJID>>(u"mobTable");
auto spawnDist = self->GetVar<float>(u"spawnDist");
auto mobTemplate = self->GetVar<LWOOBJID>(u"mobTemplate");
auto gateObjID = self->GetVar<LWOOBJID>(u"gateObj");
if (!gateObjID) return;
auto* gate = EntityManager::Instance()->GetEntity(gateObjID);
if (!gate) return;
auto oPos = gate->GetPosition();
auto oDir = gate->GetRotation().GetForwardVector();
NiPoint3 newPos(
oPos.x + (oDir.x * spawnDist),
oPos.y,
oPos.z + (oDir.z * spawnDist)
);
auto newRot = NiQuaternion::LookAt(newPos, oPos);
for (int i = 0; i < mobTable.size(); i++) {
int posOffset = -10;
if (mobTable[i] == LWOOBJID_EMPTY) {
posOffset = posOffset + 5 * i;
auto newOffset = newPos;
newOffset.z = newOffset.z + posOffset;
EntityInfo info{};
info.lot = mobTemplate;
info.pos = newOffset;
info.rot = newRot;
info.spawnerID = self->GetObjectID();
info.spawnerNodeID = 0;
info.settings = {
new LDFData<bool>(u"no_timed_spawn", true),
new LDFData<float>(u"aggroRadius", 70),
new LDFData<float>(u"softtetherRadius", 80),
new LDFData<float>(u"tetherRadius", 90),
new LDFData<float>(u"wanderRadius", 5),
new LDFData<int>(u"mobTableLoc", i)
};
auto* child = EntityManager::Instance()->CreateEntity(info, nullptr, self);
EntityManager::Instance()->ConstructEntity(child);
OnChildLoaded(self, child);
} else {
auto* mob = EntityManager::Instance()->GetEntity(mobTable[i]);
AggroTargetObject(self, mob);
}
}
}
}
void QbSpawner::OnChildLoaded(Entity* self, Entity* child) {
auto mobTable = self->GetVar<std::vector<LWOOBJID>>(u"mobTable");
auto tableLoc = child->GetVar<int>(u"mobTableLoc");
mobTable[tableLoc] = child->GetObjectID();
self->SetVar<std::vector<LWOOBJID>>(u"mobTable", mobTable);
AggroTargetObject(self, child);
const auto selfID = self->GetObjectID();
child->AddDieCallback([this, selfID, child]() {
auto* self = EntityManager::Instance()->GetEntity(selfID);
OnChildRemoved(self, child);
}
);
}
void QbSpawner::OnChildRemoved(Entity* self, Entity* child) {
auto mobTable = self->GetVar<std::vector<LWOOBJID>>(u"mobTable");
auto tableLoc = child->GetVar<int>(u"mobTableLoc");
mobTable[tableLoc] = LWOOBJID_EMPTY;
self->SetVar<std::vector<LWOOBJID>>(u"mobTable", mobTable);
}
void QbSpawner::AggroTargetObject(Entity* self, Entity* enemy) {
auto* baseCombatAIComponent = enemy->GetComponent<BaseCombatAIComponent>();
if (!baseCombatAIComponent) return;
auto gateObjID = self->GetVar<LWOOBJID>(u"gateObj");
if (gateObjID) {
auto* gate = EntityManager::Instance()->GetEntity(gateObjID);
if (gate) {
auto* movementAIComponent = enemy->GetComponent<MovementAIComponent>();
if (movementAIComponent) movementAIComponent->SetDestination(gate->GetPosition());
baseCombatAIComponent->Taunt(gateObjID, 1000);
}
}
auto playerObjID = self->GetVar<LWOOBJID>(u"player");
if (playerObjID) {
baseCombatAIComponent->Taunt(playerObjID, 100);
}
}

17
dScripts/QbSpawner.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include "CppScripts.h"
class QbSpawner : public CppScripts::Script {
public:
void OnStartup(Entity* self) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override;
void OnTimerDone(Entity* self, std::string timerName) override;
void OnChildLoaded(Entity* self, Entity* child);
void OnChildRemoved(Entity* self, Entity* child);
void AggroTargetObject(Entity* self, Entity* enemy);
private:
const int m_DefaultMobNum = 3;
const float m_DefaultSpawnDist = 25.0;
const LWOOBJID m_DefaultMobTemplate = 4712;
const float m_DefaultSpawnTime = 2.0;
};