diff --git a/Assets/_2_0Script/Mgr/BattleMgr.cs b/Assets/_2_0Script/Mgr/BattleMgr.cs index b0d9af529..664fc1633 100644 --- a/Assets/_2_0Script/Mgr/BattleMgr.cs +++ b/Assets/_2_0Script/Mgr/BattleMgr.cs @@ -1499,6 +1499,8 @@ public class BattleMgr : Singleton hpBarEnemies[i].HideHpBar(); } } + + UnregistBattleEntities(ivMonsters); iMonsterCount = 0; } @@ -1943,34 +1945,38 @@ public class BattleMgr : Singleton indexlist.RemoveAt(irand); v3pos.z = v3pos.y * 0.1f; + var monster = ivMonsters[index]; if (iWave == iTotalWave) { - if(ivMonsters[index].GetCreatureClass() == eCreatureClass.elite) + if(monster.GetCreatureClass() == eCreatureClass.elite) { - ivMonsters[index].ResetDebuff(); - ivMonsters[index].SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); - hpBarEnemies[i].ReSetoffsetY(ivMonsters[index].GetMonType()); - ivMonsters[index].Summon(v3pos, trfChar.position.x > v3pos.x); + monster.ResetDebuff(); + monster.SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); + hpBarEnemies[i].ReSetoffsetY(monster.GetMonType()); + monster.Summon(v3pos, trfChar.position.x > v3pos.x); iMonsterCount++; } - if (ivMonsters[index].GetCreatureClass() == eCreatureClass.boss) + if (monster.GetCreatureClass() == eCreatureClass.boss) { - ivMonsters[index].ResetDebuff(); - ivMonsters[index].SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); - hpBarEnemies[i].ReSetoffsetY(ivMonsters[index].GetMonType()); - ivMonsters[index].Summon(v3pos, trfChar.position.x > v3pos.x); + monster.ResetDebuff(); + monster.SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); + hpBarEnemies[i].ReSetoffsetY(monster.GetMonType()); + monster.Summon(v3pos, trfChar.position.x > v3pos.x); iMonsterCount++; } + } else { - ivMonsters[index].ResetDebuff(); - ivMonsters[index].SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); - hpBarEnemies[i].ReSetoffsetY(ivMonsters[index].GetMonType()); - ivMonsters[index].Summon(v3pos, trfChar.position.x > v3pos.x); + monster.ResetDebuff(); + monster.SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); + hpBarEnemies[i].ReSetoffsetY(monster.GetMonType()); + monster.Summon(v3pos, trfChar.position.x > v3pos.x); iMonsterCount++; } + RegistBattleEntities(monster); + if (indexlist.Count == 0) break; } @@ -2287,17 +2293,21 @@ public class BattleMgr : Singleton v3pos.y += Random.Range(-0.7f, 0.7f); v3pos.z = v3pos.y * 2f; - ivMonsters[index].ResetDebuff(); - ivMonsters[index].SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); + var monster = ivMonsters[index]; + + monster.ResetDebuff(); + monster.SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, igroup: igroup); if (CurrentBattleType == BattleType.AwakenDungeon) { if(index == GetAvailDgMonsterIndex(CreatureBase.eDgCreatureClass.DgN3)) { - ivMonsters[index].SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, false, false, igroup: igroup); + monster.SetStatus(biatk, fhp, dConst.RateMaxFloat, 0, dConst.RateMaxFloat * 0.1f * fspeed, dConst.RateMax, frange, false, false, igroup: igroup); } } - hpBarEnemies[index].ReSetoffsetY(ivMonsters[index].GetMonType()); - ivMonsters[index].Summon(v3pos, trfChar.position.x > v3pos.x); + hpBarEnemies[index].ReSetoffsetY(monster.GetMonType()); + monster.Summon(v3pos, trfChar.position.x > v3pos.x); + RegistBattleEntities(monster); + iMonsterCount++; if (indexlist.Count == 0) @@ -2481,6 +2491,7 @@ public class BattleMgr : Singleton public void DieEnemy(eCreatureClass cls, int index) { iMonsterCount--; + UnregistBattleEntities(ivMonsters[index]); if (CurrentBattleType == BattleType.Pvp) { @@ -3208,16 +3219,25 @@ public class BattleMgr : Singleton #endregion Heal #region BattleEntities + private HashSet addRegisterSet = new(); + private HashSet removeRegisterSet = new(); + public void RegistBattleEntities(params IBattleEntity[] entities) { - for (int i = 0; i < entities.Length; i++) - battleEntities.Add(entities[i]); + for(int i = 0; i < entities.Length; i++) + { + removeRegisterSet.Remove(entities[i]); + addRegisterSet.Add(entities[i]); + } } public void UnregistBattleEntities(params IBattleEntity[] entities) { - for (int i = 0; i < entities.Length; i++) - battleEntities.Remove(entities[i]); + for(int i = 0; i < entities.Length; i++) + { + addRegisterSet.Remove(entities[i]); + removeRegisterSet.Add(entities[i]); + } } /// @@ -3228,10 +3248,17 @@ public class BattleMgr : Singleton if (ivChar.IsBattleAvail() && !func(ivChar)) return; if (CurrentBattleType == BattleType.Pvp && ivCharEnemy.IsBattleAvail() && !func(ivCharEnemy)) return; - for (int i = 0; i < ivMonsters.Length; i++) + foreach (var entity in addRegisterSet) + { + battleEntities.Add(entity); + } + addRegisterSet.Clear(); + + foreach (var entity in removeRegisterSet) { - if (ivMonsters[i].IsBattleAvail() && !func(ivMonsters[i])) return; + battleEntities.Remove(entity); } + removeRegisterSet.Clear(); foreach (var bEntity in battleEntities) {