mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-20 05:34:22 +00:00
fix: add range checks to npc combat skill behavior (#2003)
* fix: add range checks to npc combat skill behavior tested that all enemies now cast skills smartly based on range to targets, and do not cast skills if they are out of range. fixes an issue where the spider queen could attack you outside the normal range fixes an issue where entering happy flower caused you to need to restart the client fixes #965 * feedback
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "RenderComponent.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "eStateChangeType.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -48,10 +49,30 @@ void BossSpiderQueenEnemyServer::OnStartup(Entity* self) {
|
||||
combat->SetStunImmune(true);
|
||||
|
||||
m_CurrentBossStage = 1;
|
||||
|
||||
ToggleAttacking(*self, false);
|
||||
self->SetProximityRadius(65.0f, "AggroRadius");
|
||||
// Obtain faction and collision group to save for subsequent resets
|
||||
}
|
||||
|
||||
void BossSpiderQueenEnemyServer::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) {
|
||||
if (name != "AggroRadius" || !entering || !entering->IsPlayer()) return;
|
||||
|
||||
auto playerCount = self->GetVar<int32_t>(u"player_count");
|
||||
|
||||
if (status == "ENTER") {
|
||||
if (playerCount == 0) {
|
||||
ToggleAttacking(*self, true);
|
||||
}
|
||||
playerCount++;
|
||||
} else if (status == "LEAVE") {
|
||||
playerCount--;
|
||||
if (playerCount == 0) {
|
||||
ToggleAttacking(*self, false);
|
||||
}
|
||||
}
|
||||
self->SetVar<int32_t>(u"player_count", playerCount);
|
||||
}
|
||||
|
||||
void BossSpiderQueenEnemyServer::OnDie(Entity* self, Entity* killer) {
|
||||
if (Game::zoneManager->GetZoneID().GetMapID() == instanceZoneID && killer) {
|
||||
for (const auto& player : PlayerManager::GetAllPlayers()) {
|
||||
@@ -71,6 +92,7 @@ void BossSpiderQueenEnemyServer::OnDie(Entity* self, Entity* killer) {
|
||||
self->SetPosition({ 10000, 0, 10000 });
|
||||
|
||||
Game::entityManager->SerializeEntity(self);
|
||||
ToggleAttacking(*self, false);
|
||||
|
||||
controller->OnFireEventServerSide(self, "ClearProperty");
|
||||
}
|
||||
@@ -634,3 +656,19 @@ float BossSpiderQueenEnemyServer::PlayAnimAndReturnTime(Entity* self, const std:
|
||||
|
||||
return animTimer;
|
||||
}
|
||||
|
||||
void BossSpiderQueenEnemyServer::ToggleAttacking(Entity& self, bool on) {
|
||||
const auto stoppedFlag = self.GetVarAs<bool>(u"stoppedFlag");
|
||||
|
||||
if (!on) {
|
||||
if (stoppedFlag) return;
|
||||
|
||||
self.SetVar(u"stoppedFlag", true);
|
||||
combat->Stun(100000.0f, true); // forcibly stun so we stop attacking people trying to put on armor
|
||||
} else {
|
||||
if (!stoppedFlag) return;
|
||||
|
||||
self.SetVar(u"stoppedFlag", false);
|
||||
combat->Stun(0.0f, true); // forcibly turn off the stun we put on above
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user