mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
feat(scripts): the Assembly Engineer turret works as TURRET.lua
The turret (LOT 9303-9305, 12618) had no script: it fought as soon as it was spawned and lasted the generic 60 seconds. As TURRET.lua: its combat AI is off until it is built, it can't be stunned, interrupted, knocked back or pulled, and it dies 30 seconds after it was placed once nobody is building it. Kill credit going to the builder is not done. Check: summon the turret with Engineer gear: it doesn't shoot until built, then fights and goes away after about 30 seconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
set(DSCRIPTS_SOURCES_EQUIPMENTSCRIPTS
|
||||
"Sunflower.cpp"
|
||||
"Turret.cpp"
|
||||
"AnvilOfArmor.cpp"
|
||||
"FountainOfImagination.cpp"
|
||||
"CauldronOfLife.cpp"
|
||||
|
||||
52
dScripts/EquipmentScripts/Turret.cpp
Normal file
52
dScripts/EquipmentScripts/Turret.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "Turret.h"
|
||||
|
||||
#include "BaseCombatAIComponent.h"
|
||||
#include "ControllablePhysicsComponent.h"
|
||||
#include "DestroyableComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "eQuickBuildState.h"
|
||||
#include "eStateChangeType.h"
|
||||
|
||||
void Turret::SetCombatAI(Entity* self, bool enabled) {
|
||||
if (auto* combatAI = self->GetComponent<BaseCombatAIComponent>()) combatAI->SetDisabled(!enabled);
|
||||
}
|
||||
|
||||
void Turret::OnStartup(Entity* self) {
|
||||
SetCombatAI(self, false);
|
||||
self->SetVar<int32_t>(u"currentTime", 1);
|
||||
self->SetVar<bool>(u"building", false);
|
||||
self->AddTimer("TickTime", 1.0f);
|
||||
|
||||
// SetStunImmunity (attack, interrupt) and SetStatusImmunity (pull to point, knockback); DLU keeps interrupt with the status ones
|
||||
if (auto* controllablePhysics = self->GetComponent<ControllablePhysicsComponent>()) {
|
||||
controllablePhysics->SetStunImmunity(eStateChangeType::PUSH, self->GetObjectID(), true, false, false, false, false, false, false);
|
||||
}
|
||||
if (auto* destroyable = self->GetComponent<DestroyableComponent>()) {
|
||||
destroyable->SetStatusImmunity(eStateChangeType::PUSH, false, false, true, true, false, false, false, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
void Turret::OnQuickBuildStart(Entity* self, Entity* target) {
|
||||
self->SetVar<bool>(u"building", true);
|
||||
}
|
||||
|
||||
void Turret::OnQuickBuildNotifyState(Entity* self, eQuickBuildState state) {
|
||||
if (state != eQuickBuildState::COMPLETED) return;
|
||||
SetCombatAI(self, true);
|
||||
self->SetVar<bool>(u"building", false);
|
||||
self->CancelAllTimers();
|
||||
self->AddTimer("TickTime", 1.0f);
|
||||
}
|
||||
|
||||
void Turret::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName != "TickTime") return;
|
||||
const auto currentTime = self->GetVar<int32_t>(u"currentTime") + 1;
|
||||
self->SetVar<int32_t>(u"currentTime", currentTime);
|
||||
if (currentTime >= KILL_TIME && !self->GetVar<bool>(u"building")) {
|
||||
SetCombatAI(self, false);
|
||||
self->SetVar<int32_t>(u"currentTime", 0);
|
||||
self->Smash(self->GetObjectID());
|
||||
return;
|
||||
}
|
||||
self->AddTimer("TickTime", 1.0f);
|
||||
}
|
||||
15
dScripts/EquipmentScripts/Turret.h
Normal file
15
dScripts/EquipmentScripts/Turret.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
// TURRET.lua: the Assembly Engineer turret. Its combat AI is off until it is built; it can't be stunned, interrupted,
|
||||
// knocked back or pulled; it dies 30 seconds after it was placed, once nobody is building it.
|
||||
class Turret : public CppScripts::Script {
|
||||
public:
|
||||
void OnStartup(Entity* self) override;
|
||||
void OnQuickBuildStart(Entity* self, Entity* target) override;
|
||||
void OnQuickBuildNotifyState(Entity* self, eQuickBuildState state) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
private:
|
||||
static void SetCombatAI(Entity* self, bool enabled);
|
||||
static constexpr int32_t KILL_TIME = 30;
|
||||
};
|
||||
Reference in New Issue
Block a user