public static bool PreFix(ref Toil __result, TargetIndex ind, PathEndMode peMode) { Toil toil = new Toil(); toil.initAction = delegate() { Pawn actor = toil.actor; actor.pather.StartPath(actor.jobs.curJob.GetTarget(ind), peMode); }; toil.AddPreTickAction(delegate() { Pawn actor = toil.actor; if (Gen.IsHashIntervalTick(actor, 240) && actor.jobs.curJob.GetTarget(ind).HasThing) { Thing thing = actor.jobs.curJob.GetTarget(ind).Thing; if (thing is Pawn && GenHostility.HostileTo(actor, thing as Pawn)) { CamoAIUtility.JobFailIfHid(actor, thing as Pawn, actor.jobs.curJob); } } }); toil.defaultCompleteMode = ToilCompleteMode.PatherArrival; __result = toil; return(false); }
public override void WarmupComplete() { base.WarmupComplete(); SoundStarter.PlayOneShot(Verb_ShootMini.M134Shoot, (SoundInfo)this.caster.Position); if (!this.CasterIsPawn || this.CasterPawn.skills == null) { return; } float xp = 10f; if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn) { xp = !GenHostility.HostileTo(this.currentTarget.Thing, this.caster) ? 50f : 200f; } this.CasterPawn.skills.Learn(SkillDefOf.Shooting, xp); }
public override void PawnDied(Corpse corpse) { //Fancy death effect. MoteMaker.MakePowerBeamMote(corpse.Position, corpse.Map); //Hurt all nearby enemy pawns. foreach (IntVec3 cell in GenRadial.RadialCellsAround(corpse.Position, 3f, true)) { List <Thing> thingList = new List <Thing>(cell.GetThingList(corpse.Map)); foreach (Thing thing in thingList) { if (GenHostility.HostileTo(thing, corpse.InnerPawn.Faction)) { //Damage. thing.TakeDamage(new DamageInfo(DamageDefOf.Burn, 40)); } } } }
/// <summary> /// Grab all viable target candidates. /// </summary> /// <param name="abilityDef">Ability Def to take in account.</param> /// <param name="pawn">Caster Pawn.</param> /// <param name="customPredicate">If set it overrides the default predicate.</param> /// <param name="pawnsToTest">How many pawns to test at max before stopping. Default is 30.</param> /// <returns>Things that are viable.</returns> public virtual IEnumerable <Thing> GrabTargets(AbilityAIDef abilityDef, Pawn pawn, Predicate <Thing> customPredicate = null, int pawnsToTest = 30) { //Make a list of candidates. List <Thing> potentionalTargets = new List <Thing>(); Predicate <Thing> pawnPredicate = null; if (customPredicate != null) { pawnPredicate = customPredicate; } else if (abilityDef.canTargetAlly) { pawnPredicate = delegate(Thing thing) { //Count own faction and faction whose goodwill they got above 50% as allies. if (AbilityUtility.AreAllies(pawn, thing)) { return(true); } return(false); } } ; else { pawnPredicate = delegate(Thing thing) { Pawn thingPawn = thing as Pawn; //Count anything hostile as a target. if (thingPawn != null) { if (!thingPawn.Downed && GenHostility.HostileTo(thing, pawn)) { return(true); } else if (GenHostility.HostileTo(thing, pawn)) { return(true); } } return(false); } }; //Max 'pawnsToTest' shall we grab. for (int i = 0; i < pawnsToTest; i++) { Thing grabResult = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.Pawn), Verse.AI.PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors), abilityDef.maxRange, thing => pawn != thing && !potentionalTargets.Contains(thing) && (thing.Position - pawn.Position).LengthHorizontal >= abilityDef.minRange && pawnPredicate(thing)); //If found nothing, then break. if (grabResult == null) { break; } potentionalTargets.Add(grabResult); yield return(grabResult); } } }
public bool TryExecute(Pawn p) { return((p.RaceProps.Humanlike && !GenHostility.HostileTo(p, Faction.OfPlayer) && !p.IsColonist) || p.IsPrisonerOfColony); }
/// <summary> /// Check if the target is hostile /// </summary> /// <param name="baseThing">Source Thing</param> /// <param name="targetFaction">Target Faction</param> /// <returns></returns> public static bool IsHostile(Thing baseThing, Faction targetFaction) { return(GenHostility.HostileTo(baseThing, targetFaction)); }
// Token: 0x06000021 RID: 33 RVA: 0x00003600 File Offset: 0x00001800 internal static void DoCamoMote(Thing thing, Thing ghost, bool hidden, int chance, float camoEff, float scaler) { bool flag = true; bool flag2 = false; if (CamoUtility.IsDebugMode() && Controller.Settings.ShowMoteMsgs && thing != null && (thing?.Map) != null && thing.Spawned) { if (flag) { if (thing is Pawn) { flag2 = (ghost is Pawn && GenHostility.HostileTo(thing, ghost) && (!(thing.Position == ghost.Position) && !thing.Position.InHorDistOf(ghost.Position, CamoUtility.NotPossibleMinDist))); } } else { flag2 = true; } if (flag2 && CamoUtility.IsValidThingForCamo(thing)) { Vector3 vector = thing.Position.ToVector3(); _ = Color.cyan; string text; Color color; if (hidden) { text = TranslatorFormattedStringExtensions.Translate("CompCamo.CannotSee", chance.ToString(), GenText.ToStringPercent(camoEff), GenText.ToStringPercent(scaler)); color = Color.green; } else { text = TranslatorFormattedStringExtensions.Translate("CompCamo.CanSee", chance.ToString(), GenText.ToStringPercent(camoEff), GenText.ToStringPercent(scaler)); color = Color.red; } MoteMaker.ThrowText(vector, thing.Map, text, color, -1f); if (CamoUtility.IsDebugMode()) { string text2 = text; bool flag3; if (!(thing is Pawn pawn)) { flag3 = (null != null); } else { Pawn_JobTracker jobs = pawn.jobs; flag3 = ((jobs?.curJob) != null); } if (flag3) { text2 = text2 + ", CJ: " + (thing as Pawn).jobs.curJob.def.defName; string str = text2; string str2 = ", ET:"; bool flag4; if (!(thing is Pawn pawn2)) { flag4 = (null != null); } else { Pawn_MindState mindState = pawn2.mindState; flag4 = ((mindState?.enemyTarget) != null); } string str3; if (!flag4) { str3 = "null"; } else { Thing enemyTarget = (thing as Pawn).mindState.enemyTarget; str3 = (enemyTarget?.LabelShortCap); } text2 = str + str2 + str3; string str4 = text2; string str5 = ", MT:"; bool flag5; if (!(thing is Pawn pawn3)) { flag5 = (null != null); } else { Pawn_MindState mindState2 = pawn3.mindState; flag5 = ((mindState2?.meleeThreat) != null); } string str6; if (!flag5) { str6 = "null"; } else { Pawn meleeThreat = (thing as Pawn).mindState.meleeThreat; str6 = (meleeThreat?.LabelShortCap); } text2 = str4 + str5 + str6; } Log.Message(text2, false); }