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:
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);
|
||||
}
|
||||
Reference in New Issue
Block a user