public bool Block(ShieldDamages damages, Action <IShieldField, Vector3> onBlock) { try { var result = _elements .Where(e => e.Second != null) .First(e => e.First.Block(damages, e.Second.Value) >= damages.Damage); if (result.Second != null) { onBlock?.Invoke(result.First, result.Second.Value); return(true); } } catch (InvalidOperationException) {} return(false); }
public bool Block(Vector3 origin, Vector3 position, ShieldDamages damages) { try { foreach (var shield in Shields) { if (shield?.IsActive() == true && !ShouldPassThrough(shield, position) && !shield.Collision(origin) && shield.Collision(position) && shield.Block(damages, position) >= damages.Damage) { return(true); } } } catch (KeyNotFoundException) {} return(false); }
public Vector3?Block( Vector3 origin, Vector3 position, Vector3 end, ShieldDamages damages) { try { foreach (var shield in Shields) { if (shield == null || !shield.IsActive() || ShouldPassThrough(shield, position) || Mod.Settings.EnableShootingOut && shield.Collision(origin)) { continue; } var point = shield.Collision(position, end); if (point != null && shield.Block(damages, point.Value) >= damages.Damage) { return(point.Value); } } } catch (KeyNotFoundException) {} return(null); }