protected static bool ShouldStopHighDamage(IntVec3 center, Map map) { return(new FieldQuery(map) .IsActive() .Intersects(PositionUtility.ToVector3(center)) .Block(Mod.Settings.SkyfallerDamage)); }
protected static bool ShouldStopLowDamage(IntVec3 center, Map map) { return(new FieldQuery(map) .IsActive() .Intersects(PositionUtility.ToVector3(center)) .Block(Mod.Settings.DropPodDamage / 8f)); }
private static float CalculateShieldPreference(float score, Map map, IntVec3 start, IntVec3 end) { if (!Mod.Settings.EnableAICastPositionFinder) { return(score); } var shieldManager = map.GetComponent <ShieldManager>(); var startAdjusted = PositionUtility.ToVector3(start); var endAdjusted = PositionUtility.ToVector3(end); var targetProtected = shieldManager.WhichShielded(startAdjusted, endAdjusted).ToList(); var shooterProtected = shieldManager.WhichShielded(endAdjusted, startAdjusted).ToList(); var shooterUnderShield = shieldManager.WhichShielded(startAdjusted).ToList(); if (shooterProtected.Any()) { score *= 1 + shooterProtected.Count; } if (shooterUnderShield.Any()) { score *= 1 + shooterUnderShield.Count; } if (targetProtected.Any()) { score /= 1 + targetProtected.Count; } return(score); }
protected static bool ShieldBlocks(Thing caster, Verb verb, IntVec3 source, LocalTargetInfo target) { if (caster.Faction == null) { return(false); } if (!Mod.Settings.EnableAIVerbFindShotLine) { return(false); } if (!verb.verbProps.requireLineOfSight) { return(false); } if (UncheckedTypes.Exists(a => a.IsInstanceOfType(verb))) { return(false); } var friendlyShieldBlocks = new FieldQuery(caster.Map) .IsActive() .FriendlyTo(caster.Faction) .Intersects( PositionUtility.ToVector3(source), PositionUtility.ToVector3(target.Cell)) .Get() .Any(); return(friendlyShieldBlocks); }
private static float CalculateShieldPreference(float score, Map map, IntVec3 start, IntVec3 end) { if (!Mod.Settings.EnableAICastPositionFinder) { return(score); } var shieldManager = ShieldManager.For(map); var startAdjusted = PositionUtility.ToVector3(start); var endAdjusted = PositionUtility.ToVector3(end); var targetProtected = shieldManager.Query(map).IsActive().Intersects(startAdjusted, endAdjusted).Get().ToList(); var shooterProtected = shieldManager.Query(map).IsActive().Intersects(endAdjusted, startAdjusted).Get().ToList(); var shooterUnderShield = shieldManager.Query(map).IsActive().Intersects(startAdjusted).Get().ToList(); if (shooterProtected.Any()) { score *= 1 + shooterProtected.Count; } if (shooterUnderShield.Any()) { score *= 1 + shooterUnderShield.Count; } if (targetProtected.Any()) { score /= 1 + targetProtected.Count; } return(score); }
protected static bool IsShielded(IntVec3 position, Map map) { return(new FieldQuery(map) .IsActive() .Intersects(PositionUtility.ToVector3(position)) .Get() .Any()); }
private static bool CanPhysicallyDropIntoShielded(Map map, IntVec3 c) { var shieldProtected = new FieldQuery(map) .Intersects(PositionUtility.ToVector3(c)) .Get() .Any(); return !shieldProtected; }
static float Postfix(float __result, IAttackTarget target, IAttackTargetSearcher searcher, Verb verb) { if (searcher.Thing.Map.GetComponent <ShieldManager>().Shielded(PositionUtility.ToVector3(searcher.Thing.Position), PositionUtility.ToVector3(target.Thing.Position))) { return(__result / 2); } return(__result); }
private static bool IsShieldedFrom(Map map, IntVec3 cell, Thing threat) { return(new FieldQuery(map) .IsActive() .Intersects( PositionUtility.ToVector3(threat.Position).Yto0(), PositionUtility.ToVector3(cell).Yto0()) .Get() .Any()); }
private static bool TryBlock(Thing explosion, DamageDef damType, int damAmount, IntVec3 position) { if (damType?.defName == null) { return(false); } var damages = new ShieldDamages(new ShieldDamage(damType, damAmount)); return(explosion.Map.GetComponent <ShieldManager>().Block( explosion.TrueCenter(), PositionUtility.ToVector3(position), damages)); }
protected static bool TryBlock(Map map, Vector3 origin, DamageDef damType, int damAmount, Vector3 position) { if (damType?.defName == null) { return(false); } var damages = new ShieldDamages(new ShieldDamage(damType, damAmount)); var blocked = new FieldQuery(map) .IsActive() .Intersects(origin, PositionUtility.ToVector3(position).Yto0()) .Block(damages); return(blocked); }
private static bool TryBlockOverheadProjectileCE( ProjectileCE projectile, Vector3 currentPosition, int ticksToImpact, Vector2 origin) { return(TryBlock( projectile, currentPosition, ticksToImpact, PositionUtility.ToVector3(origin), // TODO might be able to calculate the exact path with 3d CE projectiles projectile.def.projectile.flyOverhead, CalculateDamages(projectile)) != null); }
protected static Vector3?TryBlock( Thing projectile, Vector3 currentPosition, Vector3 nextPosition, int ticksToImpact, Vector3 origin, bool flyOverhead, ShieldDamages damages) { var shieldManager = projectile.Map.GetComponent <ShieldManager>(); if (IsBlacklisted(projectile)) { return(null); } if (flyOverhead) { if (ticksToImpact <= 1) { // fix for fire foam projectiles having 99999 damage if (projectile.def.defName == "Bullet_Shell_Firefoam") { damages.OverrideDamage = 10; } if (shieldManager.Block( PositionUtility.ToVector3(origin), PositionUtility.ToVector3(currentPosition), // TODO calculate mortar damage better damages)) { return(currentPosition); } return(null); } } else { return(shieldManager.Block( PositionUtility.ToVector3(origin), PositionUtility.ToVector3(currentPosition), PositionUtility.ToVector3(nextPosition), damages)); } return(null); }
protected static bool ShieldBlocks(Thing caster, Verb verb, IntVec3 source, LocalTargetInfo target) { if (Mod.Settings.EnableShootingIn) { return(false); } if (!verb.verbProps.requireLineOfSight) { return(false); } if (UncheckedTypes.Exists(a => a.IsInstanceOfType(verb))) { return(false); } return(caster.Map.GetComponent <ShieldManager>().Shielded(PositionUtility.ToVector3(source), PositionUtility.ToVector3(target.Cell), caster.Faction)); }
private static bool TryBlockProjectileCE( ProjectileCE projectile, Vector3 currentPosition, Vector3 nextPosition, int ticksToImpact, Vector2 origin, Action <IShieldField, Vector3> onBlock = null) { return(TryBlock( projectile, currentPosition, nextPosition, ticksToImpact, PositionUtility.ToVector3(origin), false, // not needed since CE mortars are calculated in 3D CalculateDamages(projectile.def), onBlock)); }
static float AdjustScoreForShieldedTargets(float __result, IAttackTarget target, IAttackTargetSearcher searcher, Verb verb) { if (!Mod.Settings.EnableAIAttackTargetFinder) { return(__result); } var targetShielded = new FieldQuery(searcher.Thing.Map) .IsActive() .Intersects( PositionUtility.ToVector3(searcher.Thing.Position), PositionUtility.ToVector3(target.Thing.Position)) .Get() .Any(); if (targetShielded) { return(__result / 2); } return(__result); }
protected static bool ShieldBlocks(Thing caster, Verb verb, IntVec3 source, LocalTargetInfo target) { if (verb.GetType() == typeof(Verb_CastPsycast)) { return(false); } if (!Mod.Settings.EnableAIVerbFindShotLine) { return(false); } if (!verb.verbProps.requireLineOfSight) { return(false); } if (UncheckedTypes.Exists(a => a.IsInstanceOfType(verb))) { return(false); } if (caster.Faction == null) //additional check for casters without faction { return(new FieldQuery(caster.Map) .IsActive() .Intersects( PositionUtility.ToVector3(source), PositionUtility.ToVector3(target.Cell)) .Get() .Any()); } else { return(new FieldQuery(caster.Map) .IsActive() .FriendlyTo(caster.Faction) .Intersects( PositionUtility.ToVector3(source), PositionUtility.ToVector3(target.Cell)) .Get() .Any()); } }
static bool CanShootAtShieldFromCurrentPosition(bool __result, IAttackTarget target, IAttackTargetSearcher searcher, Verb verb) { if (!Mod.Settings.EnableAIAttackTargetFinder) { return(__result); } if (__result == false) { try { var result = new FieldQuery(searcher.Thing.Map) .IsActive() .HostileTo(searcher.Thing.Faction) .Intersects( PositionUtility.ToVector3(searcher.Thing.Position), PositionUtility.ToVector3(target.Thing.Position)) .GetWithIntersects() .First(); if (result.Second == null) { return(false); } var distance = Vector3.Distance(searcher.Thing.TrueCenter(), result.Second.Value); var range = verb.verbProps.range; var isTarget = result.First.Emitters .Select(emitter => emitter.Thing) .Any(thing => thing == target.Thing); if (distance <= range && isTarget) { return(true); } } catch (InvalidOperationException) { } } return(__result); }
public TargetingParameters ForShip(Faction faction) => new TargetingParameters() { canTargetLocations = true, canTargetSelf = false, canTargetPawns = false, canTargetFires = false, canTargetBuildings = false, canTargetItems = false, validator = targetInfo => { Mod.SetDropCellCheckEnabled(false); var goodDropSpot = DropCellFinder.IsGoodDropSpot(targetInfo.Cell, targetInfo.Map, false, true); Mod.SetDropCellCheckEnabled(true); var shielded = new FieldQuery(targetInfo.Map) .FriendlyTo(faction, true) .Intersects(PositionUtility.ToVector3(targetInfo.Cell)) .Get() .Any(); return(!shielded && goodDropSpot); } };
private static bool ShouldStop(Map map, IntVec3 center) { return(map.GetComponent <ShieldManager>().Block(PositionUtility.ToVector3(center), Mod.Settings.SkyfallerDamage)); }
// Runs ahead of the standard check of cells to affect // Finds cells that are protected from the outermost edge first protected static void HandleProtected <T>( ICollection <IntVec3> cellsToAffect, T explosion, Vector3 origin, int startTick, Func <T, IntVec3, int> getDamage) where T : Explosion { var ticksGame = Find.TickManager.TicksGame; cellsToAffect .Where(cell => ticksGame >= GetCellAffectTickReversed(explosion, startTick, cell)) .OrderByDescending(cell => cell.DistanceTo(explosion.Position)) .Where(cell => TryBlock(explosion.Map, origin, explosion.damType, getDamage(explosion, cell), PositionUtility.ToVector3(cell).Yto0())) .Do(blocked => cellsToAffect.Remove(blocked)); }
private static bool CanPhysicallyDropIntoShielded(Map map, IntVec3 c) { return(!map.GetComponent <ShieldManager>().Shielded(PositionUtility.ToVector3(c), false)); }
static bool CheckCellShielded(ExplosionCE __instance, IntVec3 c) { return(!TryBlock(__instance.Map, __instance.TrueCenter(), __instance.damType, GetDamage(__instance, c), PositionUtility.ToVector3(c))); }
private static bool IsShielded(Map map, IntVec3 position) { return(map.GetComponent <ShieldManager>().Shielded(PositionUtility.ToVector3(position))); }