mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
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:
52
dScripts/ai/ACT/ActMine.cpp
Normal file
52
dScripts/ai/ACT/ActMine.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "ActMine.h"
|
||||
#include "SkillComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
#include "RebuildComponent.h"
|
||||
|
||||
void ActMine::OnStartup(Entity* self) {
|
||||
self->SetVar(u"RebuildComplete", false);
|
||||
self->SetProximityRadius(MINE_RADIUS, "mineRadius");
|
||||
}
|
||||
|
||||
void ActMine::OnRebuildNotifyState(Entity* self, eRebuildState state) {
|
||||
if (state == eRebuildState::REBUILD_COMPLETED) {
|
||||
auto* rebuild = self->GetComponent<RebuildComponent>();
|
||||
if (rebuild) {
|
||||
auto* builder = rebuild->GetBuilder();
|
||||
self->SetVar(u"Builder", builder->GetObjectID());
|
||||
}
|
||||
|
||||
self->SetVar(u"RebuildComplete", true);
|
||||
self->SetVar(u"NumWarnings", 0);
|
||||
self->AddToGroup("reset");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ActMine::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
|
||||
auto* detroyable = self->GetComponent<DestroyableComponent>();
|
||||
if (!detroyable) return;
|
||||
if (status == "ENTER" && self->GetVar<bool>(u"RebuildComplete") == true && detroyable->IsEnemy(entering)) {
|
||||
GameMessages::SendPlayFXEffect(self->GetObjectID(), 242, u"orange", "sirenlight_B");
|
||||
self->AddTimer("Tick", TICK_TIME);
|
||||
}
|
||||
}
|
||||
|
||||
void ActMine::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName == "Tick") {
|
||||
if (self->GetVar<int>(u"NumWarnings") >= MAX_WARNINGS) {
|
||||
auto* skill = self->GetComponent<SkillComponent>();
|
||||
if (!skill) return;
|
||||
skill->CalculateBehavior(SKILL_ID, BEHAVIOR_ID, LWOOBJID_EMPTY);
|
||||
self->AddTimer("BlowedUp", BLOWED_UP_TIME);
|
||||
} else {
|
||||
GameMessages::SendPlayFXEffect(self->GetObjectID(), 242, u"orange", "sirenlight_B");
|
||||
self->AddTimer("Tick", TICK_TIME);
|
||||
self->SetVar(u"NumWarnings", self->GetVar<int>(u"NumWarnings") + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (timerName == "BlowedUp") {
|
||||
self->Kill(self);
|
||||
}
|
||||
}
|
18
dScripts/ai/ACT/ActMine.h
Normal file
18
dScripts/ai/ACT/ActMine.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class ActMine : public CppScripts::Script {
|
||||
public:
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnRebuildNotifyState(Entity* self, eRebuildState state) override;
|
||||
void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
private:
|
||||
int MAX_WARNINGS = 3;
|
||||
float MINE_RADIUS = 10.0;
|
||||
float TICK_TIME = 0.25;
|
||||
float BLOWED_UP_TIME = 0.1;
|
||||
uint32_t SKILL_ID = 317;
|
||||
uint32_t BEHAVIOR_ID = 3719;
|
||||
};
|
||||
|
7
dScripts/ai/ACT/ActPlayerDeathTrigger.cpp
Normal file
7
dScripts/ai/ACT/ActPlayerDeathTrigger.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "ActPlayerDeathTrigger.h"
|
||||
|
||||
void ActPlayerDeathTrigger::OnCollisionPhantom(Entity* self, Entity* target) {
|
||||
if (!target->IsPlayer() || target->GetIsDead() || !target->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready
|
||||
|
||||
target->Smash(self->GetObjectID(), eKillType::SILENT);
|
||||
}
|
9
dScripts/ai/ACT/ActPlayerDeathTrigger.h
Normal file
9
dScripts/ai/ACT/ActPlayerDeathTrigger.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class ActPlayerDeathTrigger : public CppScripts::Script
|
||||
{
|
||||
public:
|
||||
void OnCollisionPhantom(Entity* self, Entity* target);
|
||||
};
|
||||
|
52
dScripts/ai/ACT/ActVehicleDeathTrigger.cpp
Normal file
52
dScripts/ai/ACT/ActVehicleDeathTrigger.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "ActVehicleDeathTrigger.h"
|
||||
#include "PossessableComponent.h"
|
||||
#include "GameMessages.h"
|
||||
#include "RacingControlComponent.h"
|
||||
#include "dZoneManager.h"
|
||||
#include "EntityManager.h"
|
||||
#include "PossessorComponent.h"
|
||||
|
||||
|
||||
void ActVehicleDeathTrigger::OnCollisionPhantom(Entity* self, Entity* target) {
|
||||
auto* possessableComponent = target->GetComponent<PossessableComponent>();
|
||||
|
||||
Entity* vehicle;
|
||||
Entity* player;
|
||||
|
||||
if (possessableComponent != nullptr) {
|
||||
auto* player = EntityManager::Instance()->GetEntity(possessableComponent->GetPossessor());
|
||||
|
||||
if (player == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
} else if (target->IsPlayer()) {
|
||||
auto* possessorComponent = target->GetComponent<PossessorComponent>();
|
||||
|
||||
if (possessorComponent == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
vehicle = EntityManager::Instance()->GetEntity(possessorComponent->GetPossessable());
|
||||
|
||||
if (vehicle == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
player = target;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
GameMessages::SendDie(vehicle, self->GetObjectID(), LWOOBJID_EMPTY, true, VIOLENT, u"", 0, 0, 0, true, false, 0);
|
||||
|
||||
auto* zoneController = dZoneManager::Instance()->GetZoneControlObject();
|
||||
|
||||
auto* racingControlComponent = zoneController->GetComponent<RacingControlComponent>();
|
||||
|
||||
if (racingControlComponent != nullptr) {
|
||||
racingControlComponent->OnRequestDie(player);
|
||||
}
|
||||
}
|
9
dScripts/ai/ACT/ActVehicleDeathTrigger.h
Normal file
9
dScripts/ai/ACT/ActVehicleDeathTrigger.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
class ActVehicleDeathTrigger : public CppScripts::Script
|
||||
{
|
||||
public:
|
||||
void OnCollisionPhantom(Entity* self, Entity* target) override;
|
||||
};
|
||||
|
12
dScripts/ai/ACT/CMakeLists.txt
Normal file
12
dScripts/ai/ACT/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
set(DSCRIPTS_SOURCES_AI_ACT
|
||||
"ActMine.cpp"
|
||||
"ActPlayerDeathTrigger.cpp"
|
||||
"ActVehicleDeathTrigger.cpp")
|
||||
|
||||
add_subdirectory(FootRace)
|
||||
|
||||
foreach(file ${DSCRIPTS_SOURCES_AI_ACT_FOOTRACE})
|
||||
set(DSCRIPTS_SOURCES_AI_ACT ${DSCRIPTS_SOURCES_AI_ACT} "FootRace/${file}")
|
||||
endforeach()
|
||||
|
||||
set(DSCRIPTS_SOURCES_AI_ACT ${DSCRIPTS_SOURCES_AI_ACT} PARENT_SCOPE)
|
48
dScripts/ai/ACT/FootRace/BaseFootRaceManager.cpp
Normal file
48
dScripts/ai/ACT/FootRace/BaseFootRaceManager.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "BaseFootRaceManager.h"
|
||||
#include "EntityManager.h"
|
||||
#include "Character.h"
|
||||
|
||||
void BaseFootRaceManager::OnStartup(Entity* self) {
|
||||
// TODO: Add to FootRaceStarter group
|
||||
}
|
||||
|
||||
void BaseFootRaceManager::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1,
|
||||
int32_t param2, int32_t param3) {
|
||||
const auto splitArguments = GeneralUtils::SplitString(args, '_');
|
||||
if (splitArguments.size() > 1) {
|
||||
|
||||
const auto eventName = splitArguments[0];
|
||||
const auto player = EntityManager::Instance()->GetEntity(std::stoull(splitArguments[1]));
|
||||
|
||||
if (player != nullptr) {
|
||||
if (eventName == "updatePlayer") {
|
||||
UpdatePlayer(self, player->GetObjectID());
|
||||
} else if (IsPlayerInActivity(self, player->GetObjectID())) {
|
||||
if (eventName == "initialActivityScore") {
|
||||
auto* character = player->GetCharacter();
|
||||
if (character != nullptr) {
|
||||
character->SetPlayerFlag(115, true);
|
||||
}
|
||||
|
||||
SetActivityScore(self, player->GetObjectID(), 1);
|
||||
} else if (eventName == "updatePlayerTrue") {
|
||||
auto* character = player->GetCharacter();
|
||||
if (character != nullptr) {
|
||||
character->SetPlayerFlag(115, false);
|
||||
}
|
||||
|
||||
UpdatePlayer(self, player->GetObjectID(), true);
|
||||
} else if (eventName == "PlayerWon") {
|
||||
auto* character = player->GetCharacter();
|
||||
if (character != nullptr) {
|
||||
character->SetPlayerFlag(115, false);
|
||||
if (param2 != -1) // Certain footraces set a flag
|
||||
character->SetPlayerFlag(param2, true);
|
||||
}
|
||||
|
||||
StopActivity(self, player->GetObjectID(), 0, param1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
dScripts/ai/ACT/FootRace/BaseFootRaceManager.h
Normal file
9
dScripts/ai/ACT/FootRace/BaseFootRaceManager.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "ActivityManager.h"
|
||||
#include "CppScripts.h"
|
||||
|
||||
class BaseFootRaceManager : public ActivityManager {
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2,
|
||||
int32_t param3) override;
|
||||
};
|
3
dScripts/ai/ACT/FootRace/CMakeLists.txt
Normal file
3
dScripts/ai/ACT/FootRace/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
set(DSCRIPTS_SOURCES_AI_ACT_FOOTRACE
|
||||
"BaseFootRaceManager.cpp"
|
||||
PARENT_SCOPE)
|
Reference in New Issue
Block a user