fix: implement enemy clear threat script (#1678)

* brother

* use some better logic
This commit is contained in:
David Markowitz
2024-12-15 21:44:57 -08:00
committed by GitHub
parent 53242ad5d5
commit 0f8c5b436d
20 changed files with 197 additions and 64 deletions

View File

@@ -2,6 +2,7 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL
"BankInteractServer.cpp"
"BaseInteractDropLootServer.cpp"
"Binoculars.cpp"
"EnemyClearThreat.cpp"
"ExplodingAsset.cpp"
"FrictionVolumeServer.cpp"
"ForceVolumeServer.cpp"

View File

@@ -0,0 +1,25 @@
#include "EnemyClearThreat.h"
#include "BaseCombatAIComponent.h"
#include "PhysicsComponent.h"
void EnemyClearThreat::OnCollisionPhantom(Entity* self, Entity* target) {
if (!target) return;
const auto colGroup = target->GetCollisionGroup();
if (colGroup == 12) { // enemy
auto* const baseCombatAiComponent = target->GetComponent<BaseCombatAIComponent>();
if (!baseCombatAiComponent) return;
baseCombatAiComponent->ClearThreat();
baseCombatAiComponent->ForceTether();
} else if (colGroup == 10) { // player
const auto enemies = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::BASE_COMBAT_AI);
for (const auto& enemy : enemies) {
auto* const baseCombatAiComponent = enemy->GetComponent<BaseCombatAIComponent>();
if (!baseCombatAiComponent) continue;
baseCombatAiComponent->IgnoreThreat(target->GetObjectID(), 3.0f);
}
}
}

View File

@@ -0,0 +1,11 @@
#ifndef ENEMYCLEARTHREAT_H
#define ENEMYCLEARTHREAT_H
#include "CppScripts.h"
class EnemyClearThreat : public CppScripts::Script {
public:
void OnCollisionPhantom(Entity* self, Entity* target) override;
};
#endif //!ENEMYCLEARTHREAT_H

View File

@@ -327,6 +327,7 @@
#include "VisToggleNotifierServer.h"
#include "LupGenericInteract.h"
#include "WblRobotCitizen.h"
#include "EnemyClearThreat.h"
#include <map>
#include <string>
@@ -686,8 +687,21 @@ namespace {
{"scripts\\zone\\LUPs\\RobotCity Intro\\WBL_RCIntro_RobotCitizenOrange.lua", []() {return new WblRobotCitizen();}},
{"scripts\\zone\\LUPs\\RobotCity Intro\\WBL_RCIntro_RobotCitizenRed.lua", []() {return new WblRobotCitizen();}},
{"scripts\\zone\\LUPs\\RobotCity Intro\\WBL_RCIntro_RobotCitizenYellow.lua", []() {return new WblRobotCitizen();}},
{"scripts\\02_server\\Map\\General\\L_ENEMY_CLEAR_THREAT.lua", []() {return new EnemyClearThreat();}},
};
std::set<std::string> g_ExcludedScripts = {
"scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua",
"scripts\\02_server\\Enemy\\General\\L_BASE_ENEMY_SPIDERLING.lua",
"scripts\\ai\\AG\\L_AG_SENTINEL_GUARD.lua",
"scripts\\ai\\FV\\L_ACT_NINJA_STUDENT.lua",
"scripts\\ai\\WILD\\L_WILD_GF_FROG.lua",
"scripts\\empty.lua",
"scripts\\zone\\AG\\L_ZONE_AG.lua",
"scripts\\zone\\NS\\L_ZONE_NS.lua",
"scripts\\zone\\GF\\L_ZONE_GF.lua",
};
};
CppScripts::Script* const CppScripts::GetScript(Entity* parent, const std::string& scriptName) {
@@ -699,14 +713,8 @@ CppScripts::Script* const CppScripts::GetScript(Entity* parent, const std::strin
const auto itrTernary = scriptLoader.find(scriptName);
Script* script = itrTernary != scriptLoader.cend() ? itrTernary->second() : &InvalidToReturn;
if (script == &InvalidToReturn) {
if ((scriptName.length() > 0) && !((scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") ||
(scriptName == "scripts\\02_server\\Enemy\\General\\L_BASE_ENEMY_SPIDERLING.lua") ||
(scriptName == "scripts\\ai\\FV\\L_ACT_NINJA_STUDENT.lua") ||
(scriptName == "scripts\\ai\\WILD\\L_WILD_GF_FROG.lua") ||
(scriptName == "scripts\\empty.lua") ||
(scriptName == "scripts\\ai\\AG\\L_AG_SENTINEL_GUARD.lua")
)) LOG_DEBUG("LOT %i attempted to load CppScript for '%s', but returned InvalidScript.", parent->GetLOT(), scriptName.c_str());
if (script == &InvalidToReturn && !scriptName.empty() && !g_ExcludedScripts.contains(scriptName)) {
LOG_DEBUG("LOT %i attempted to load CppScript for '%s', but returned InvalidScript.", parent->GetLOT(), scriptName.c_str());
}
g_Scripts[scriptName] = script;