DarkflameServer/dScripts/AmDarklingDragon.cpp

153 lines
4.5 KiB
C++
Raw Permalink Normal View History

#include "AmDarklingDragon.h"
#include "BaseCombatAIComponent.h"
#include "DestroyableComponent.h"
#include "EntityManager.h"
#include "GameMessages.h"
#include "SkillComponent.h"
#include "BaseCombatAIComponent.h"
void AmDarklingDragon::OnStartup(Entity* self) {
2022-07-28 13:39:57 +00:00
self->SetVar<int32_t>(u"weakspot", 0);
2022-07-28 13:39:57 +00:00
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>();
2022-07-28 13:39:57 +00:00
if (baseCombatAIComponent != nullptr) {
baseCombatAIComponent->SetStunImmune(true);
}
}
void AmDarklingDragon::OnDie(Entity* self, Entity* killer) {
2022-07-28 13:39:57 +00:00
if (self->GetVar<bool>(u"bDied")) {
return;
}
2022-07-28 13:39:57 +00:00
self->SetVar<bool>(u"bDied", true);
2022-07-28 13:39:57 +00:00
auto golemId = self->GetVar<LWOOBJID>(u"Golem");
2022-07-28 13:39:57 +00:00
auto* golem = EntityManager::Instance()->GetEntity(golemId);
if (golem != nullptr) {
golem->Smash(self->GetObjectID());
}
}
void AmDarklingDragon::OnHitOrHealResult(Entity* self, Entity* attacker, int32_t damage) {
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayFXEffect(self, -1, u"gothit", "", LWOOBJID_EMPTY, 1, 1, true);
2022-07-28 13:39:57 +00:00
if (true) {
auto weakpoint = self->GetVar<int32_t>(u"weakspot");
2022-07-28 13:39:57 +00:00
if (weakpoint == 1) {
self->Smash(attacker->GetObjectID());
}
}
2022-07-28 13:39:57 +00:00
auto* destroyableComponent = self->GetComponent<DestroyableComponent>();
2022-07-28 13:39:57 +00:00
if (destroyableComponent != nullptr) {
if (destroyableComponent->GetArmor() > 0) return;
2022-07-28 13:39:57 +00:00
auto weakpoint = self->GetVar<int32_t>(u"weakpoint");
2022-07-28 13:39:57 +00:00
if (weakpoint == 0) {
self->AddTimer("ReviveTimer", 12);
2022-07-28 13:39:57 +00:00
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>();
auto* skillComponent = self->GetComponent<SkillComponent>();
2022-07-28 13:39:57 +00:00
if (baseCombatAIComponent != nullptr) {
baseCombatAIComponent->SetDisabled(true);
baseCombatAIComponent->SetStunned(true);
}
2022-07-28 13:39:57 +00:00
if (skillComponent != nullptr) {
skillComponent->Interrupt();
}
2022-07-28 13:39:57 +00:00
self->SetVar<int32_t>(u"weakpoint", 2);
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayAnimation(self, u"stunstart", 1.7f);
2022-07-28 13:39:57 +00:00
self->AddTimer("timeToStunLoop", 1);
2022-07-28 13:39:57 +00:00
auto position = self->GetPosition();
auto forward = self->GetRotation().GetForwardVector();
auto backwards = forward * -1;
2022-07-28 13:39:57 +00:00
forward.x *= 10;
forward.z *= 10;
2022-07-28 13:39:57 +00:00
auto rotation = self->GetRotation();
2022-07-28 13:39:57 +00:00
auto objectPosition = NiPoint3();
2022-07-28 13:39:57 +00:00
objectPosition.y = position.y;
objectPosition.x = position.x - (backwards.x * 8);
objectPosition.z = position.z - (backwards.z * 8);
2022-07-28 13:39:57 +00:00
auto golem = self->GetVar<int32_t>(u"DragonSmashingGolem");
2022-07-28 13:39:57 +00:00
EntityInfo info{};
info.lot = golem != 0 ? golem : 8340;
info.pos = objectPosition;
info.rot = rotation;
info.spawnerID = self->GetObjectID();
info.settings = {
new LDFData<std::string>(u"rebuild_activators",
std::to_string(objectPosition.x + forward.x) + "\x1f" +
std::to_string(objectPosition.y) + "\x1f" +
std::to_string(objectPosition.z + forward.z)
),
new LDFData<int32_t>(u"respawn", 100000),
new LDFData<float>(u"rebuild_reset_time", 15),
new LDFData<bool>(u"no_timed_spawn", true),
new LDFData<LWOOBJID>(u"Dragon", self->GetObjectID())
};
2022-07-28 13:39:57 +00:00
auto* golemObject = EntityManager::Instance()->CreateEntity(info);
2022-07-28 13:39:57 +00:00
EntityManager::Instance()->ConstructEntity(golemObject);
}
}
}
2022-07-28 13:39:57 +00:00
void AmDarklingDragon::OnTimerDone(Entity* self, std::string timerName) {
if (timerName == "ReviveHeldTimer") {
self->AddTimer("backToAttack", 2.5);
} else if (timerName == "ExposeWeakSpotTimer") {
self->SetVar<int32_t>(u"weakspot", 1);
} else if (timerName == "timeToStunLoop") {
GameMessages::SendPlayAnimation(self, u"stunloop", 1.8f);
} else if (timerName == "ReviveTimer") {
GameMessages::SendPlayAnimation(self, u"stunend", 2.0f);
self->AddTimer("backToAttack", 1);
} else if (timerName == "backToAttack") {
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>();
auto* skillComponent = self->GetComponent<SkillComponent>();
if (baseCombatAIComponent != nullptr) {
baseCombatAIComponent->SetDisabled(false);
baseCombatAIComponent->SetStunned(false);
}
if (skillComponent != nullptr) {
skillComponent->Interrupt();
}
self->SetVar<int32_t>(u"weakspot", -1);
GameMessages::SendNotifyObject(self->GetObjectID(), self->GetObjectID(), u"DragonRevive", UNASSIGNED_SYSTEM_ADDRESS);
}
}
2022-07-28 13:39:57 +00:00
void AmDarklingDragon::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) {
if (args != "rebuildDone") return;
2022-07-28 13:39:57 +00:00
self->AddTimer("ExposeWeakSpotTimer", 3.8f);
2022-07-28 13:39:57 +00:00
self->CancelTimer("ReviveTimer");
2022-07-28 13:39:57 +00:00
self->AddTimer("ReviveHeldTimer", 10.5f);
2022-07-28 13:39:57 +00:00
self->SetVar<LWOOBJID>(u"Golem", sender->GetObjectID());
2022-07-28 13:39:57 +00:00
GameMessages::SendPlayAnimation(self, u"quickbuildhold", 1.9f);
}