feat: Changes Spawner HomeRange to SpawnBounds (#2290)

### Summary

This PR transitions the spawner system from a simple radius-based model to a flexible 3D boundary system.

### Core Changes

* **Replaced `HomeRange` with `SpawnBounds`**: Spawners now use a `Rectangle3D` to define spawn areas instead of a circular integer range.
* **Backward Compatibility**:
* The `HomeRange` property remains as a helper that generates square `SpawnBounds` centered on the spawner.
* Included a migration path (v10 to v11) that automatically converts old range data into new bounds during deserialization.


* **Dynamic Bounds Shifting**: If a spawner is moved, its `SpawnBounds` will automatically shift with it, provided the bounds are currently configured as a centered square.
* **New Spawn Logic**: Added `SpawnLocationIsHome` toggle. If enabled, spawned mobiles treat their exact spawn coordinates as their "Home" rather than the spawner's location.

### Implementation Details

* **Interface Updates**: Updated `ISpawner` to include `WalkingRange`, `SpawnBounds`, and `IsInSpawnBounds()`.
* **UI Enhancements**: The Spawner Controller Gump now displays "Custom" for complex bounds and allows copying of the new boundary properties between spawners.
* **Refactored Constructors**: Streamlined `BaseSpawner`, `ProximitySpawner`, and `RegionSpawner` constructors to support the new data types.
This commit is contained in:
Quick 2025-12-26 20:07:26 -06:00 • committed by GitHub
parent bde072f81c
commit 0b34cc4417
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 502 additions and 196 deletions

View file

@ -879,15 +879,15 @@ public abstract partial class BaseAI
_timer.Stop();
}
if (ShouldReturnToHome(Mobile.Spawner as Spawner))
if (ShouldReturnToHome(Mobile.Spawner))
{
Timer.StartTimer(ReturnToHome);
}
}
private bool ShouldReturnToHome(Spawner spawner) =>
private bool ShouldReturnToHome(ISpawner spawner) =>
spawner?.ReturnOnDeactivate == true && !Mobile.Controlled &&
(spawner.HomeLocation == Point3D.Zero || !Mobile.InRange(spawner.HomeLocation, spawner.HomeRange));
!spawner.IsInSpawnBounds(Mobile.Location);
private void ReturnToHome()
{

View file

@ -13,6 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
************************************************************************/
using Server.Engines.Spawners;
namespace Server.Mobiles;
public abstract partial class BaseAI
@ -326,7 +328,7 @@ public abstract partial class BaseAI
return true;
}
private bool IsInvalidControlTarget(Mobile target) => target?.Deleted != false || target.Map != Mobile.Map
private bool IsInvalidControlTarget(Mobile target) => target?.Deleted != false || target.Map != Mobile.Map
|| !target.Alive || target.IsDeadBondedPet;
private void HandleInvalidControlTarget()
@ -344,7 +346,7 @@ public abstract partial class BaseAI
private void FindCombatant()
{
var controlMaster = Mobile.ControlMaster;
foreach (var aggr in Mobile.GetMobilesInRange(Mobile.RangePerception))
{
if (!Mobile.CanSee(aggr) || aggr.IsDeadBondedPet || !aggr.Alive)
@ -354,7 +356,7 @@ public abstract partial class BaseAI
bool isAttackingPet = aggr.Combatant == Mobile;
bool isAttackingMaster = controlMaster != null && aggr.Combatant == controlMaster;
if (isAttackingPet || isAttackingMaster)
{
if (Mobile.InLOS(aggr))
@ -377,12 +379,12 @@ public abstract partial class BaseAI
for (var i = 0; i < controlMaster.Aggressors.Count; i++)
{
var aggressor = controlMaster.Aggressors[i].Attacker;
if (aggressor?.Deleted != false || !aggressor.Alive || aggressor.IsDeadBondedPet)
{
continue;
}
if (Mobile.InRange(aggressor, Mobile.RangePerception) && Mobile.CanSee(aggressor) && Mobile.InLOS(aggressor))
{
Mobile.ControlTarget = aggressor;
@ -404,10 +406,10 @@ public abstract partial class BaseAI
var spawner = Mobile.Spawner;
if (spawner != null && spawner.HomeLocation != Point3D.Zero)
if (spawner != null)
{
Mobile.Home = spawner.HomeLocation;
Mobile.RangeHome = spawner.HomeRange;
Mobile.Home = spawner.GetSpawnPosition(Mobile, spawner.Map);
Mobile.RangeHome = spawner.WalkingRange;
}
else
{