using System.Collections.Generic; using Entitas; using Sog; namespace CoreGame.Render { public enum WaveSpawnState { None = 0, TryStart = 1, Spawning = 2, Spawned = 3, End = 4, } public enum LevelSpawnState { None = 0, Start = 1, Spawning = 2, End = 3, Stop = 2, } public class WaveParam { // 大波次 // public LevelWaveGroupConfigData waveData; public ChapterBattleStageDesc waveData; public Fixed64 accTime = 0; public Fixed64 jumpTimeSpanAcc = 0; // 跳时间的累计值 public int jumpIdx; public int[] spawnedIdx; // 小波次内的索引 public int lastSpawnCount; // 小波次数量总和 public Fixed64[] newRuleTimeSpanAcc; // 新规则增量 public WaveSpawnState state; public List eids; } [Combat] public class LevelWaveComponent : IComponent, IReset { public Dictionary lifeEid2WaveIdx; public List waveParams; public LevelSpawnState state; public float totalTime; public int battleId; internal float totalTimeAcc; internal int curStageId; public bool CanStart(int predictedIdx) { if (predictedIdx < 0 || predictedIdx >= waveParams.Count) return false; if (predictedIdx == 0) return true; var waveData = waveParams[predictedIdx].waveData; var lastParam = waveParams[predictedIdx - 1]; if (waveData.stageStartType == WaveBeginType.AllWaveEntDeath) return lifeEid2WaveIdx.Count == 0 && lastParam.state == WaveSpawnState.Spawned; // if (waveData.stageStartType == WaveBeginType.LastWaveEnd && // lastParam.state == WaveSpawnState.End) // { // if (lastParam.waveData.mWaveEndType == WaveEndType.WaveMonsterDead) // return lastParam.eids.Count == 0; // return true; // } if (waveData.stageStartType == WaveBeginType.TimeCountOrWaveMonsterDead) { // 到达时间 if (lastParam.state == WaveSpawnState.End) return true; // 怪物生成完毕,且全死 if (lastParam.state == WaveSpawnState.Spawned) return lastParam.eids.Count == 0; } return false; } public void RemoveLifeEnt(int eid) { if (lifeEid2WaveIdx.Remove(eid, out var waveIdx)) { waveParams[waveIdx].eids.Remove(eid); } } public void AddLifeEnt(int eid, int waveIdx) { if (!lifeEid2WaveIdx.TryAdd(eid, waveIdx)) return; waveParams[waveIdx].eids.Add(eid); } public void Reset() { totalTimeAcc = 0; DictionaryPool.Push(ref lifeEid2WaveIdx); for (int i = 0; i < waveParams.Count; i++) { ListPool.Push(ref waveParams[i].eids); } ListPool.Push(ref waveParams); } } }