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,134 @@
#include "BaseEnemyApe.h"
#include "BaseCombatAIComponent.h"
#include "DestroyableComponent.h"
#include "GameMessages.h"
#include "EntityManager.h"
#include "SkillComponent.h"
void BaseEnemyApe::OnStartup(Entity* self) {
self->SetVar<uint32_t>(u"timesStunned", 2);
self->SetVar<bool>(u"knockedOut", false);
}
void BaseEnemyApe::OnDie(Entity* self, Entity* killer) {
auto* anchor = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"QB"));
if (anchor != nullptr && !anchor->GetIsDead()) {
anchor->Smash(self->GetObjectID(), SILENT);
}
}
void BaseEnemyApe::OnSkillCast(Entity* self, uint32_t skillID) {
const auto groundPoundSkill = self->GetVar<uint32_t>(u"GroundPoundSkill") != 0 ? self->GetVar<uint32_t>(u"GroundPoundSkill") : 725;
const auto spawnQuickBuildTime = self->GetVar<float_t>(u"spawnQBTime") != 0.0f ? self->GetVar<float_t>(u"spawnQBTime") : 5.0f;
if (skillID == groundPoundSkill && self->GetVar<LWOOBJID>(u"QB") == LWOOBJID_EMPTY) {
self->AddTimer("spawnQBTime", spawnQuickBuildTime);
}
}
void BaseEnemyApe::OnHit(Entity* self, Entity* attacker) {
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
if (destroyableComponent != nullptr && destroyableComponent->GetArmor() < 1 && !self->GetBoolean(u"knockedOut")) {
StunApe(self, true);
self->CancelTimer("spawnQBTime");
GameMessages::SendPlayAnimation(self, u"disable", 1.7f);
const auto reviveTime = self->GetVar<float_t>(u"reviveTime") != 0.0f
? self->GetVar<float_t>(u"reviveTime") : 12.0f;
self->AddTimer("reviveTime", reviveTime);
}
}
void BaseEnemyApe::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "reviveTime") {
// Revives the ape, giving it back some armor
const auto timesStunned = self->GetVar<uint32_t>(u"timesStunned");
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
if (destroyableComponent != nullptr) {
destroyableComponent->SetArmor(destroyableComponent->GetMaxArmor() / timesStunned);
}
EntityManager::Instance()->SerializeEntity(self);
self->SetVar<uint32_t>(u"timesStunned", timesStunned + 1);
StunApe(self, false);
} else if (timerName == "spawnQBTime" && self->GetVar<LWOOBJID>(u"QB") == LWOOBJID_EMPTY) {
// Spawn QB in front of ape.
const auto position = self->GetPosition();
const auto rotation = self->GetRotation();
const auto backwardVector = rotation.GetForwardVector() * -1;
const auto objectPosition = NiPoint3(
position.GetX() - (backwardVector.GetX() * 8),
position.GetY(),
position.GetZ() - (backwardVector.GetZ() * 8)
);
EntityInfo entityInfo{};
entityInfo.pos = position;
entityInfo.rot = rotation;
entityInfo.pos.SetY(entityInfo.pos.GetY() + 13.0f);
entityInfo.spawnerID = self->GetObjectID();
entityInfo.lot = self->GetVar<LOT>(u"QuickbuildAnchorLOT") != 0
? self->GetVar<LOT>(u"QuickbuildAnchorLOT") : 7549;
entityInfo.settings = {
new LDFData<std::string>(u"rebuild_activators",
std::to_string(objectPosition.GetX()) + "\x1f" +
std::to_string(objectPosition.GetY()) + "\x1f" +
std::to_string(objectPosition.GetZ())
),
new LDFData<bool>(u"no_timed_spawn", true),
new LDFData<LWOOBJID>(u"ape", self->GetObjectID())
};
auto* anchor = EntityManager::Instance()->CreateEntity(entityInfo);
EntityManager::Instance()->ConstructEntity(anchor);
self->SetVar<LWOOBJID>(u"QB", anchor->GetObjectID());
} else if (timerName == "anchorDamageTimer") {
// Attacks the ape with some god skill
const auto* player = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"smasher"));
if (player == nullptr) {
return;
}
auto* skillComponent = self->GetComponent<SkillComponent>();
if (skillComponent != nullptr) {
skillComponent->CalculateBehavior(1273, 29446, self->GetObjectID(), true, false, player->GetObjectID());
}
self->SetVar<LWOOBJID>(u"QB", LWOOBJID_EMPTY);
}
}
void BaseEnemyApe::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) {
if (args == "rebuildDone" && sender != nullptr) {
self->SetVar<LWOOBJID>(u"smasher", sender->GetObjectID());
const auto anchorDamageDelayTime = self->GetVar<float_t>(u"AnchorDamageDelayTime") != 0.0f ? self->GetVar<float_t>(u"AnchorDamageDelayTime") : 0.5f;
self->AddTimer("anchorDamageTimer", anchorDamageDelayTime);
}
}
void BaseEnemyApe::StunApe(Entity* self, bool stunState) {
auto* combatAIComponent = self->GetComponent<BaseCombatAIComponent>();
if (combatAIComponent != nullptr) {
combatAIComponent->SetDisabled(stunState);
combatAIComponent->SetStunned(stunState);
auto* skillComponent = self->GetComponent<SkillComponent>();
if (skillComponent != nullptr) {
skillComponent->Interrupt();
}
GameMessages::SendSetStunned(self->GetObjectID(), stunState ? PUSH : POP, UNASSIGNED_SYSTEM_ADDRESS, self->GetObjectID(),
true, true, true, true, true,
true, true, true, true);
self->SetBoolean(u"knockedOut", stunState);
}
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "CppScripts.h"
class BaseEnemyApe : public CppScripts::Script {
public:
void OnStartup(Entity* self) override;
void OnDie(Entity* self, Entity* killer) override;
void OnSkillCast(Entity* self, uint32_t skillID) override;
void OnHit(Entity* self, Entity* attacker) override;
void OnTimerDone(Entity* self, std::string timerName) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
int32_t param3) override;
private:
static void StunApe(Entity* self, bool stunState);
};

View File

@@ -0,0 +1,43 @@
#include "BaseEnemyMech.h"
#include "Entity.h"
#include "ControllablePhysicsComponent.h"
#include "EntityManager.h"
#include "dpWorld.h"
#include "GeneralUtils.h"
#include "DestroyableComponent.h"
void BaseEnemyMech::OnStartup(Entity* self) {
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
if (destroyableComponent != nullptr) {
destroyableComponent->SetFaction(4);
}
}
void BaseEnemyMech::OnDie(Entity* self, Entity* killer) {
ControllablePhysicsComponent* controlPhys = static_cast<ControllablePhysicsComponent*>(self->GetComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS));
if (!controlPhys) return;
NiPoint3 newLoc = { controlPhys->GetPosition().x, dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(controlPhys->GetPosition()), controlPhys->GetPosition().z };
EntityInfo info = EntityInfo();
std::vector<LDFBaseData*> cfg;
std::u16string activatorPosStr;
activatorPosStr += (GeneralUtils::to_u16string(controlPhys->GetPosition().x));
activatorPosStr.push_back(0x1f);
activatorPosStr += (GeneralUtils::to_u16string(controlPhys->GetPosition().y));
activatorPosStr.push_back(0x1f);
activatorPosStr += (GeneralUtils::to_u16string(controlPhys->GetPosition().z));
LDFBaseData* activatorPos = new LDFData<std::u16string>(u"rebuild_activators", activatorPosStr);
cfg.push_back(activatorPos);
info.lot = qbTurretLOT;
info.pos = newLoc;
info.rot = controlPhys->GetRotation();
info.spawnerID = self->GetObjectID();
info.settings = cfg;
Entity* turret = EntityManager::Instance()->CreateEntity(info, nullptr);
if (turret) {
EntityManager::Instance()->ConstructEntity(turret);
}
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "CppScripts.h"
class BaseEnemyMech : public CppScripts::Script
{
public:
void OnStartup(Entity* self) override;
void OnDie(Entity* self, Entity* killer) override;
protected:
LOT qbTurretLOT = 6254;
};

View File

@@ -0,0 +1,7 @@
set(DSCRIPTS_SOURCES_02_SERVER_ENEMY_GENERAL
"BaseEnemyMech.cpp"
"BaseEnemyApe.cpp"
"GfApeSmashingQB.cpp"
"TreasureChestDragonServer.cpp"
"EnemyNjBuff.cpp"
PARENT_SCOPE)

View File

@@ -0,0 +1,12 @@
#include "EnemyNjBuff.h"
#include "SkillComponent.h"
void EnemyNjBuff::OnStartup(Entity* self) {
auto* skillComponent = self->GetComponent<SkillComponent>();
if (skillComponent == nullptr) {
return;
}
skillComponent->CalculateBehavior(1127, 24812, self->GetObjectID(), true);
}

View File

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

View File

@@ -0,0 +1,22 @@
#include "GfApeSmashingQB.h"
#include "EntityManager.h"
#include "GameMessages.h"
void GfApeSmashingQB::OnStartup(Entity* self) {
self->SetNetworkVar<LWOOBJID>(u"lootTagOwner", self->GetVar<LWOOBJID>(u"lootTagOwner"));
}
void GfApeSmashingQB::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "anchorBreakTime") {
self->Smash();
}
}
void GfApeSmashingQB::OnRebuildComplete(Entity* self, Entity* target) {
auto* ape = EntityManager::Instance()->GetEntity(self->GetVar<LWOOBJID>(u"ape"));
if (ape != nullptr) {
ape->OnFireEventServerSide(target, "rebuildDone");
GameMessages::SendPlayAnimation(self, u"smash", 1.7f);
self->AddTimer("anchorBreakTime", 1.0f);
}
}

View File

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

View File

@@ -0,0 +1,42 @@
#include "TreasureChestDragonServer.h"
#include "ScriptedActivityComponent.h"
#include "TeamManager.h"
#include "EntityManager.h"
void TreasureChestDragonServer::OnStartup(Entity* self) {
}
void TreasureChestDragonServer::OnUse(Entity* self, Entity* user) {
if (self->GetVar<bool>(u"bUsed")) {
return;
}
self->SetVar<bool>(u"bUsed", true);
auto* scriptedActivityComponent = self->GetComponent<ScriptedActivityComponent>();
if (scriptedActivityComponent == nullptr) {
return;
}
auto rating = 1;
auto* team = TeamManager::Instance()->GetTeam(user->GetObjectID());
if (team != nullptr) {
rating = team->members.size();
for (const auto member : team->members) {
auto* memberObject = EntityManager::Instance()->GetEntity(member);
if (memberObject == nullptr) continue;
LootGenerator::Instance().DropActivityLoot(memberObject, self, scriptedActivityComponent->GetActivityID(), rating);
}
} else {
LootGenerator::Instance().DropActivityLoot(user, self, scriptedActivityComponent->GetActivityID(), rating);
}
self->Smash(self->GetObjectID());
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "CppScripts.h"
class TreasureChestDragonServer : public CppScripts::Script
{
public:
void OnStartup(Entity* self) override;
void OnUse(Entity* self, Entity* user) override;
};