mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-22 14:44:22 +00:00
feat: implement ronin script
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
set(DSCRIPTS_SOURCES_02_SERVER_ENEMY_GENERAL
|
||||
"BaseEnemyMech.cpp"
|
||||
"BaseEnemyApe.cpp"
|
||||
"CountdownDestroyAI.cpp"
|
||||
"GfApeSmashingQB.cpp"
|
||||
"TreasureChestDragonServer.cpp"
|
||||
"EnemyNjBuff.cpp"
|
||||
|
||||
50
dScripts/02_server/Enemy/General/CountdownDestroyAI.cpp
Normal file
50
dScripts/02_server/Enemy/General/CountdownDestroyAI.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "CountdownDestroyAI.h"
|
||||
|
||||
#include "BaseCombatAIComponent.h"
|
||||
#include "ScriptComponent.h"
|
||||
|
||||
void CountdownDestroyAI::OnStartup(Entity* self) {
|
||||
CountdownStartup(*self);
|
||||
auto* scriptComp = self->GetComponent<ScriptComponent>();
|
||||
if (scriptComp) scriptComp->RegisterMsg(this, &CountdownDestroyAI::OnNotifyCombatAIStateChange);
|
||||
}
|
||||
|
||||
void CountdownDestroyAI::CountdownStartup(Entity& self) {
|
||||
auto suicideTimer = self.GetVar<float>(u"suicideTimer");
|
||||
if (suicideTimer == 0.0f) suicideTimer = 60;
|
||||
self.AddTimer("Dead", suicideTimer);
|
||||
}
|
||||
|
||||
void CountdownDestroyAI::OnHit(Entity* self, Entity* attacker) {
|
||||
if (!self->GetVar<bool>(u"ShouldBeDead")) return;
|
||||
self->CancelTimer("IsBeingAttacked");
|
||||
self->AddTimer("Dead", 5.0f);
|
||||
}
|
||||
|
||||
void CountdownDestroyAI::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName == "Dead") {
|
||||
self->SetVar<bool>(u"ShouldBeDead", true);
|
||||
if (self->GetVar<bool>(u"Busy")) {
|
||||
self->AddTimer("IsBeingAttacked", 5.0f);
|
||||
} else {
|
||||
self->Smash();
|
||||
}
|
||||
} else if (timerName == "IsBeingAttacked") {
|
||||
self->Smash();
|
||||
}
|
||||
}
|
||||
|
||||
bool CountdownDestroyAI::OnNotifyCombatAIStateChange(Entity& self, GameMessages::NotifyCombatAIStateChange& notifyMsg) {
|
||||
const auto curState = notifyMsg.newState;
|
||||
if (curState == AiState::dead) return true;
|
||||
|
||||
if (curState == AiState::aggro) {
|
||||
self.SetVar(u"Busy", true);
|
||||
} else {
|
||||
self.SetVar(u"Busy", false);
|
||||
if (self.GetVar<bool>(u"ShouldBeDead")) {
|
||||
self.Smash();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
13
dScripts/02_server/Enemy/General/CountdownDestroyAI.h
Normal file
13
dScripts/02_server/Enemy/General/CountdownDestroyAI.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "CppScripts.h"
|
||||
|
||||
#include "GameMessages.h"
|
||||
|
||||
class CountdownDestroyAI : public CppScripts::Script {
|
||||
public:
|
||||
void OnStartup(Entity* self) override;
|
||||
void CountdownStartup(Entity& self);
|
||||
void OnHit(Entity* self, Entity* attacker) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
bool OnNotifyCombatAIStateChange(Entity& self, GameMessages::NotifyCombatAIStateChange& msg);
|
||||
};
|
||||
Reference in New Issue
Block a user