using System.Collections.Generic; using UnityEngine; namespace DanroJump.Gameplay { public sealed class PlatformContentProfile : IPlatformContentSource { private readonly IReadOnlyList collectiblePrefabs; private readonly IReadOnlyList equipmentPrefabs; private readonly IReadOnlyList enemyPrefabs; private readonly float collectibleSpawnChance; private readonly float equipmentSpawnChance; private readonly float enemySpawnChance; public PlatformContentProfile( IReadOnlyList collectiblePrefabs, float collectibleSpawnChance, IReadOnlyList equipmentPrefabs, float equipmentSpawnChance, IReadOnlyList enemyPrefabs, float enemySpawnChance) { this.collectiblePrefabs = collectiblePrefabs; this.collectibleSpawnChance = Mathf.Clamp01(collectibleSpawnChance); this.equipmentPrefabs = equipmentPrefabs; this.equipmentSpawnChance = Mathf.Clamp01(equipmentSpawnChance); this.enemyPrefabs = enemyPrefabs; this.enemySpawnChance = Mathf.Clamp01(enemySpawnChance); } public bool ShouldSpawn(PlatformContentKind kind, System.Random random) { var chance = GetSpawnChance(kind); if (chance <= 0f) { return false; } if (chance >= 1f) { return true; } return (random != null ? random.NextDouble() : 0d) <= chance; } public bool TryGetPrefab(PlatformContentKind kind, System.Random random, out GameObject prefab) { if (WeightedPrefabOption.TrySelect(GetPrefabs(kind), random, out prefab)) { return true; } prefab = null; return false; } private float GetSpawnChance(PlatformContentKind kind) { switch (kind) { case PlatformContentKind.Collectible: return collectibleSpawnChance; case PlatformContentKind.Equipment: return equipmentSpawnChance; case PlatformContentKind.Enemy: return enemySpawnChance; default: return 0f; } } private IReadOnlyList GetPrefabs(PlatformContentKind kind) { switch (kind) { case PlatformContentKind.Collectible: return collectiblePrefabs; case PlatformContentKind.Equipment: return equipmentPrefabs; case PlatformContentKind.Enemy: return enemyPrefabs; default: return collectiblePrefabs; } } } }