ProjectDDD/Assets/_DDD/_Scripts/RestaurantState/Customer/RandomSpawnScheduleBuilder.cs
2025-08-12 20:46:30 +09:00

53 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using static DDD.SpawnScheduleUtils;
namespace DDD
{
public class RandomSpawnScheduleBuilder : ISpawnScheduleBuilder
{
public SpawnSchedule Build(SpawnScheduleBuildArgs args)
{
var randomGenerator = new Random(args.Seed);
int normalQuota = Math.Max(0, args.NormalQuota);
int specialQuota = Math.Max(0, args.SpecialQuota);
if (args.NormalIds == null || args.NormalIds.Count == 0) normalQuota = 0;
if (args.SpecialIds == null || args.SpecialIds.Count == 0) specialQuota = 0;
int total = normalQuota + specialQuota;
if (total == 0) return new SpawnSchedule(Array.Empty<string>());
// 스페셜 위치만 무작위 고정(정확히 specialQuota개)
var specialPositions = new HashSet<int>();
PickUniqueIndices(total, specialQuota, randomGenerator, specialPositions);
int normalIndex = 0;
int specialIndex = 0;
var result = new List<string>(total);
for (int i = 0; i < total; i++)
{
bool isSpecial = specialPositions.Contains(i);
if (isSpecial)
{
var id = NextRoundRobin(args.SpecialIds, ref specialIndex);
if (string.IsNullOrEmpty(id) == false)
{
result.Add(id);
}
}
else
{
var id = NextRoundRobin(args.NormalIds, ref normalIndex);
if (string.IsNullOrEmpty(id) == false)
{
result.Add(id);
}
}
}
return new SpawnSchedule(result);
}
}
}