From 9621a951f4f7a4467769fc1fa13b989030e0db9b Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 2 Jun 2021 22:16:15 -0400 Subject: [PATCH] Core/Pools: Fixed spawning in pools with both explicitly and equally chanced entries Port From (https://github.com/TrinityCore/TrinityCore/commit/5e774fc7f1941484ec86c1c5abe5bbb14f4e4090) --- Source/Game/Pools/PoolManager.cs | 39 ++++++++++---------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/Source/Game/Pools/PoolManager.cs b/Source/Game/Pools/PoolManager.cs index 6c8ad558f..0df3b63e1 100644 --- a/Source/Game/Pools/PoolManager.cs +++ b/Source/Game/Pools/PoolManager.cs @@ -765,45 +765,30 @@ namespace Game // roll objects to be spawned if (!ExplicitlyChanced.Empty()) { - while (count != 0 && ExplicitlyChanced.Count > rolledObjects.Count) - { - --count; - float roll = (float)RandomHelper.randChance(); + float roll = (float)RandomHelper.randChance(); - foreach (PoolObject obj in ExplicitlyChanced) + foreach (PoolObject obj in ExplicitlyChanced) + { + roll -= obj.chance; + // Triggering object is marked as spawned at this time and can be also rolled (respawn case) + // so this need explicit check for this case + if (roll < 0 && (obj.guid == triggerFrom || !spawns.IsActiveObject(obj.guid))) { - roll -= obj.chance; - // Triggering object is marked as spawned at this time and can be also rolled (respawn case) - // so this need explicit check for this case - if (roll < 0 && (obj.guid == triggerFrom || !spawns.IsActiveObject(obj.guid))) - { - rolledObjects.Add(obj); - break; - } + rolledObjects.Add(obj); + break; } } } - else if (!EqualChanced.Empty()) + + if (!EqualChanced.Empty() && rolledObjects.Empty()) { - rolledObjects = EqualChanced; - - for (var i =0; i < rolledObjects.Count; ++i) - { - var obj = rolledObjects[i]; - // remove most of the active objects so there is higher chance inactive ones are spawned - if (spawns.IsActiveObject(obj.guid) && RandomHelper.URand(1, 4) != 1) - rolledObjects.Remove(obj); - } - + rolledObjects.AddRange(EqualChanced.Where(obj => obj.guid == triggerFrom || !spawns.IsActiveObject(obj.guid))); rolledObjects.RandomResize((uint)count); } // try to spawn rolled objects foreach (PoolObject obj in rolledObjects) { - if (spawns.IsActiveObject(obj.guid)) - continue; - if (obj.guid == triggerFrom) { ReSpawn1Object(obj);