void UpdateDamage() { foreach (var item in Objects.Where(obj => obj is IDamageControler)) { switch (item) { case Player player: player.Damage = null; break; case MapObject mapObject: mapObject.Damage = null; break; default: Logger.Error("Invalid Type"); break; } } foreach (IDamageControler item in Objects.Where(obj => obj is IDamageControler)) { while (item.DamageRequests.Count > 0) { Damages.Add(item.DamageRequests.Dequeue()); } while (item.DirectDamageRequests.Count > 0) { var damage = item.DirectDamageRequests.Dequeue(); if (item.Damage == null) { if (item is Player player) { player.Damage = new DamageInfo(damage.Damage, damage.KnockBack, damage.TakeDown, damage.Priority); } else if (item is MapObject mapObject) { mapObject.Damage = new DamageInfo(damage.Damage, damage.KnockBack, damage.TakeDown, damage.Priority); } } else if (Player.Damage is DamageInfo info) { info.RecieveDamage += damage.Damage; info.KnockBack = info.KnockBack < damage.KnockBack ? damage.KnockBack : info.KnockBack; info.TakeDown = info.TakeDown < damage.TakeDown ? damage.TakeDown : info.TakeDown; info.Priority = info.Priority < damage.Priority ? damage.Priority : info.Priority; } } } List <DamageRect> removeRect = new List <DamageRect>(); if (Player != null) { foreach (var item in Damages.Where(obj => obj.Group != Player.DamageGroup)) { if (Player.CollisionShape.GetIsCollidedWith(item)) { if (Player.Damage == null) { Player.Damage = new DamageInfo(item.Damage, item.KnockBack, item.TakeDown, item.Priority); } else if (Player.Damage is DamageInfo info) { info.RecieveDamage += item.Damage; info.KnockBack = info.KnockBack < item.KnockBack ? item.KnockBack : info.KnockBack; info.TakeDown = info.TakeDown < item.TakeDown ? item.TakeDown : info.TakeDown; info.Priority = info.Priority < item.Priority ? item.Priority : info.Priority; } if (!item.Sastainable) { removeRect.Add(item); } } } foreach (var item in Damages.Where(obj => obj.Group == Player.DamageGroup)) { foreach (IDamageControler item2 in Objects.Where(obj => obj is IDamageControler damageControler && damageControler.IsReceiveDamage && damageControler.DamageGroup != Player.DamageGroup && damageControler.CollisionShape.GetIsCollidedWith(item))) { if (item2 is MapObject mapObject && mapObject.Damage == null) { mapObject.Damage = new DamageInfo(item.Damage, item.KnockBack, item.TakeDown, item.Priority); } else if (item2 is MapObject mapObject2 && mapObject2.Damage is DamageInfo info) { info.RecieveDamage += item.Damage; info.KnockBack = info.KnockBack < item.KnockBack ? item.KnockBack : info.KnockBack; info.TakeDown = info.TakeDown < item.TakeDown ? item.TakeDown : info.TakeDown; info.Priority = info.Priority < item.Priority ? item.Priority : info.Priority; } if (!item.Sastainable) { removeRect.Add(item); } }