fix(spawner): Fixes spawners infinitely spawning (#346)

Bumps release version
This commit is contained in:
Kamron Batman 2020-12-11 22:04:49 -08:00 committed by GitHub
parent 5b7a4151c7
commit 3acb1414dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 45 deletions

View file

@ -323,12 +323,11 @@ namespace Server.Engines.Spawners
{
list.Add(1060742); // active
list.Add(1060656, m_Count.ToString()); // amount to make: ~1_val~
list.Add(1061169, m_HomeRange.ToString()); // range ~1_val~
list.Add(1060656, m_Count.ToString()); // amount to make: ~1_val~
list.Add(1061169, m_HomeRange.ToString()); // range ~1_val~
list.Add(1050039, "walking range:\t{0}", m_WalkingRange); // ~1_NUMBER~ ~2_ITEMNAME~
list.Add(1053099, "group:\t{0}", m_Group); // ~1_oretype~: ~2_armortype~
list.Add(1060847, "team:\t{0}", m_Team); // ~1_val~ ~2_val~
list.Add(1053099, "group:\t{0}", m_Group); // ~1_oretype~: ~2_armortype~
list.Add(1060847, "team:\t{0}", m_Team); // ~1_val~ ~2_val~
list.Add(1063483, "delay:\t{0} to {1}", m_MinDelay, m_MaxDelay); // ~1_MATERIAL~: ~2_ITEMNAME~
GetSpawnerProperties(list);
@ -439,7 +438,15 @@ namespace Server.Engines.Spawners
return;
}
var probsum = Entries.Where(t => !t.IsFull).Sum(t => t.SpawnedProbability);
var probsum = 0;
foreach (var spawnerEntry in Entries)
{
if (!spawnerEntry.IsFull)
{
probsum += spawnerEntry.SpawnedProbability;
}
}
if (probsum <= 0)
{
@ -572,10 +579,8 @@ namespace Server.Engines.Spawners
try
{
IEntity entity = null;
string[] paramargs;
string[] propargs;
propargs = string.IsNullOrEmpty(entry.Properties)
var propargs = string.IsNullOrEmpty(entry.Properties)
? Array.Empty<string>()
: CommandSystem.Split(entry.Properties.Trim());
@ -589,7 +594,7 @@ namespace Server.Engines.Spawners
return false;
}
paramargs = string.IsNullOrEmpty(entry.Parameters)
var paramargs = string.IsNullOrEmpty(entry.Parameters)
? Array.Empty<string>()
: entry.Parameters.Trim().Split(' ');
@ -666,8 +671,6 @@ namespace Server.Engines.Spawners
var loc = m is BaseVendor ? Location : GetSpawnPosition(m, map);
m.OnBeforeSpawn(loc, map);
InvalidateProperties();
m.MoveToWorld(loc, map);
if (m is BaseCreature c)
@ -717,7 +720,7 @@ namespace Server.Engines.Spawners
return false;
}
InvalidateProperties();
ClearProperties();
return true;
}
@ -748,9 +751,16 @@ namespace Server.Engines.Spawners
End = DateTime.UtcNow + delay;
m_Timer?.Stop();
if (m_Timer == null)
{
m_Timer = new InternalTimer(this, delay);
}
else
{
m_Timer?.Stop();
m_Timer.Delay = delay;
}
m_Timer = new InternalTimer(this, delay);
if (!IsFull)
{
m_Timer.Start();
@ -803,7 +813,6 @@ namespace Server.Engines.Spawners
{
entry.Spawned.RemoveAt(i);
Spawned.Remove(e);
e.Delete();
}
}
@ -1071,26 +1080,16 @@ namespace Server.Engines.Spawners
public InternalTimer(BaseSpawner spawner, TimeSpan delay) : base(delay)
{
if (spawner.IsFull)
{
Priority = TimerPriority.FiveSeconds;
}
else
{
Priority = TimerPriority.OneSecond;
}
Priority = spawner.IsFull ? TimerPriority.FiveSeconds : TimerPriority.OneSecond;
m_Spawner = spawner;
}
protected override void OnTick()
{
if (m_Spawner != null)
if (m_Spawner?.Deleted == false)
{
if (!m_Spawner.Deleted)
{
m_Spawner.OnTick();
}
m_Spawner.OnTick();
}
}
}

View file

@ -31,8 +31,6 @@ namespace Server.Engines.Spawners
Spawned = new List<ISpawnable>(count);
for (var i = 0; i < count; ++i)
// IEntity e = World.FindEntity( reader.ReadInt() );
{
if (reader.ReadEntity() is ISpawnable e)
{
@ -49,19 +47,26 @@ namespace Server.Engines.Spawners
}
}
[JsonPropertyName("probability")] public int SpawnedProbability { get; set; }
[JsonPropertyName("probability")]
public int SpawnedProbability { get; set; }
[JsonPropertyName("maxCount")] public int SpawnedMaxCount { get; set; }
[JsonPropertyName("maxCount")]
public int SpawnedMaxCount { get; set; }
[JsonPropertyName("name")] public string SpawnedName { get; set; }
[JsonPropertyName("name")]
public string SpawnedName { get; set; }
[JsonPropertyName("properties")] public string Properties { get; set; }
[JsonPropertyName("properties")]
public string Properties { get; set; }
[JsonPropertyName("parameters")] public string Parameters { get; set; }
[JsonPropertyName("parameters")]
public string Parameters { get; set; }
[JsonIgnore] public EntryFlags Valid { get; set; }
[JsonIgnore]
public EntryFlags Valid { get; set; }
[JsonIgnore] public List<ISpawnable> Spawned { get; }
[JsonIgnore]
public List<ISpawnable> Spawned { get; }
public bool IsFull => Spawned.Count >= SpawnedMaxCount;
@ -106,7 +111,6 @@ namespace Server.Engines.Spawners
if (parent.OnDefragSpawn(spawned, false))
{
Spawned.RemoveAt(i--);
parent.Spawned.Remove(spawned);
}
}
}

View file

@ -53,9 +53,7 @@ namespace Server.Items
public void Unlink()
{
var se = Spawner;
if (se != null)
if (Spawner != null)
{
Spawner.Remove(this);
Spawner = null;

View file

@ -3459,8 +3459,7 @@ namespace Server.Mobiles
}
else
{
var se = Spawner;
if (se?.UnlinkOnTaming == true)
if (Spawner?.UnlinkOnTaming == true)
{
Spawner.Remove(this);
Spawner = null;
@ -3882,7 +3881,7 @@ namespace Server.Mobiles
private bool IsSpawnerBound() =>
Map != null && Map != Map.Internal &&
FightMode != FightMode.None && RangeHome >= 0 &&
!Controlled && !Summoned && Spawner is Spawner spawner && spawner.Map == Map;
!Controlled && !Summoned && (Spawner as Spawner)?.Map == Map;
public override void OnSectorDeactivate()
{