public static void AutoUndraftTick(AutoUndrafter __instance) { Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue <Pawn>(); int tick = Find.TickManager.TicksGame; if (tick % 100 == 0) { if (pawn.jobs.curJob != null && pawn.jobs.curJob.def == JobDefOf.Wait_Combat && pawn.stances != null && pawn.stances.curStance is Stance_Mobile) { //pawn.jobs.EndCurrentJob(JobCondition.Succeeded); WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, DroppingModeEnum.Combat); BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; FieldInfo field = (__instance.GetType()).GetField("lastNonWaitingTick", bindFlags); int lastNonWaitingTick = (int)field.GetValue(__instance); if (tick - lastNonWaitingTick > autoRetrieveDelay) { Job retrieval = JobGiver_RetrieveWeapon.TryGiveJobStatic(pawn, true); if (retrieval != null) { pawn.jobs.TryTakeOrderedJob(retrieval, JobTag.Misc); } } } } }
public static void SelfConsume(Verb_ShootOneUse __instance) { if (__instance.caster is Pawn) { Pawn pawn = (__instance.caster as Pawn); ThingDefStuffDefPair weapon = __instance.EquipmentSource.toThingDefStuffDefPair(); bool anotherFound = WeaponAssingment.equipSpecificWeaponTypeFromInventory(pawn, weapon, false, false); if (!anotherFound) { WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, DroppingModeEnum.UsedUp); } } }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (RestraintsUtility.InRestraints(pawn)) { return(null); } else { if (!pawn.IsValidSidearmsCarrier()) { return(null); } CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn); if (pawnMemory == null) { return(null); } if (pawnMemory.IsUsingAutotool(true, false)) { pawnMemory.currentJobWeaponReequipDelayed = true; return(null); } else { pawnMemory.currentJobWeaponReequipDelayed = false; } //Log.Message(pawn.Label+" considering switching weapons on the run"); WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, DroppingModeEnum.Calm); //yes, I realise that this never actually results in a job. //I might at some point in the future decide to make switching weapons non-instaneous, which will happen here. return(null); } }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (RestraintsUtility.InRestraints(pawn)) { return(null); } else { Pawn_EquipmentTracker equipment = pawn.equipment; if (equipment == null) { return(null); } GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawnMemory == null) { return(null); } if (SimpleSidearms.ToolAutoSwitch && ((Find.TickManager.TicksGame - pawnMemory.delayIdleSwitchTimestamp) < 60)) { return(null); } WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, Globals.DroppingModeEnum.Calm); if (pawnMemory.RememberedWeapons is null) { Log.Warning("pawnMemory of " + pawn.Label + " is missing remembered weapons"); } Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>(); foreach (ThingDefStuffDefPair weaponMemory in pawnMemory.RememberedWeapons) { if (!dupeCounters.ContainsKey(weaponMemory)) { dupeCounters[weaponMemory] = 0; } if (!pawn.hasWeaponSomewhere(weaponMemory, dupeCounters[weaponMemory])) { float maxDist = 1000f; if (pawn.Faction != Faction.OfPlayer) { maxDist = 30f; } if (inCombat) { maxDist = 12f; } IEnumerable <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(weaponMemory.thing).Where(t => t.Stuff == weaponMemory.stuff); 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); //this works properly because better ranged weapons also happen to be better at pistolwhipping //okay past me, WHAT? Why? if (thing == null) { continue; } if (!inCombat) { return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondary, thing)); } else { return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondaryCombat, thing, pawn.Position)); } } dupeCounters[weaponMemory]++; } return(null); } }