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:
David Markowitz
2026-06-18 23:27:49 -07:00
committed by GitHub
parent ce9d4e823c
commit 56504d9447
7 changed files with 74 additions and 10 deletions

View File

@@ -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
}
}

View File

@@ -46,7 +46,10 @@ public:
void OnTimerDone(Entity* self, std::string timerName) override;
void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status);
private:
void ToggleAttacking(Entity& self, bool on);
//Regular variables:
DestroyableComponent* destroyable = nullptr;
ControllablePhysicsComponent* controllable = nullptr;