private static void AutoUndraftTick(AutoUndrafter __instance) { Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>(); if (Find.TickManager.TicksGame % 100 == 0) { if (pawn.jobs.curJob != null && pawn.jobs.curJob.def == JobDefOf.WaitCombat && pawn.stances != null && pawn.stances.curStance is Stance_Mobile) { //pawn.jobs.EndCurrentJob(JobCondition.Succeeded); WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, GoldfishModule.GetGoldfishForPawn(pawn)); } } }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (RestraintsUtility.InRestraints(pawn)) { return(null); } { //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax)); Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory); foreach (string wepName in pawnMemory.weapons) { ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName); if (def == null) { continue; } if (!pawn.hasWeaponSomewhere(wepName)) { float maxDist = 1000f; if (pawn.Faction != Faction.OfPlayer || inCombat) { maxDist = 30f; } List <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(def); Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, matchingWeapons, PathEndMode.OnCell, TraverseParms.For(pawn), maxDist, (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t), (Thing t) => SimpleSidearms.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0); if (thing == null) { continue; } if (!inCombat) { return(new Job(SidearmsDefOf.EquipSecondary, thing)); } else { return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position)); } } } return(null); } }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (RestraintsUtility.InRestraints(pawn)) { return(null); } { //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax)); Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory); foreach (string wepName in pawnMemory.weapons) { ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName); if (def == null) { continue; } if (!pawn.hasWeaponSomewhere(wepName)) { ThingRequest request = new ThingRequest(); request.singleDef = def; float maxDist = 1000f; if (pawn.Faction != Faction.OfPlayer || inCombat) { maxDist = 30f; } Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), maxDist, (Thing x) => (!x.IsForbidden(pawn)) && pawn.CanReserve(x, 1, -1, null, false)); if (thing == null) { continue; } if (!inCombat) { return(new Job(SidearmsDefOf.EquipSecondary, thing)); } else { return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position)); } } } return(null); } }
protected override Job TryGiveJob(Pawn pawn) { //Log.Message("retrieval precheck for " + pawn.LabelShort); if (pawn.Faction != Faction.OfPlayer) { return(null); } if (pawn.Drafted) { return(null); } /*if (Find.TickManager.TicksGame > GetNextTryTick(pawn)) * { * return null; * } * else*/ { //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax)); //Log.Message("retrieval check for " + pawn.LabelShort); Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory); foreach (string wepName in pawnMemory.weapons) { //Log.Message("checking "+wepName); ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName); if (def == null) { continue; } if (!pawn.hasWeaponSomewhere(wepName)) { //Log.Message("looking for"); ThingRequest request = new ThingRequest(); request.singleDef = def; Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 1000f, (Thing x) => (!x.IsForbidden(pawn)) && pawn.CanReserve(x, 1, -1, null, false)); if (thing == null) { continue; } return(new Job(SidearmsJobDefOf.EquipSecondary, thing)); } } return(null); } }