static bool IsBiocodedOrLinked(Pawn pawn, Thing thing, bool inventory) { if (pawn.IsQuestLodger()) { if (inventory) { return(true); } else { CompBiocodable compBiocodable = thing.TryGetComp <CompBiocodable>(); if (compBiocodable != null && compBiocodable.Biocoded) { return(true); } else { CompBladelinkWeapon compBladelinkWeapon = thing.TryGetComp <CompBladelinkWeapon>(); return(compBladelinkWeapon != null && compBladelinkWeapon.bondedPawn == pawn); } } } else { return(false); } }
public static bool canCarrySidearmInstance(ThingWithComps sidearmThing, Pawn pawn, out string errString) { //nicked from EquipmentUtility.CanEquip CompBladelinkWeapon compBladelinkWeapon = sidearmThing.TryGetComp <CompBladelinkWeapon>(); if (compBladelinkWeapon != null && compBladelinkWeapon.Biocodable && compBladelinkWeapon.CodedPawn != null && compBladelinkWeapon.CodedPawn != pawn) { errString = "BladelinkBondedToSomeoneElse".Translate(); return(false); } if (CompBiocodable.IsBiocoded(sidearmThing) && !CompBiocodable.IsBiocodedFor(sidearmThing, pawn)) { errString = "BiocodedCodedForSomeoneElse".Translate(); return(false); } if (EquipmentUtility.AlreadyBondedToWeapon(sidearmThing, pawn)) { errString = "BladelinkAlreadyBondedMessage".Translate(pawn.Named("PAWN"), pawn.equipment.bondedWeapon.Named("BONDEDWEAPON")); return(false); } if (compBladelinkWeapon != null && !compBladelinkWeapon.Biocoded && !compBladelinkWeapon.TraitsListForReading.Any(t => t.neverBond == true)) { errString = "SidearmPickupFail_NotYetBladelinkBonded".Translate(); return(false); } if (EquipmentUtility.RolePreventsFromUsing(pawn, sidearmThing, out string roleReason)) { errString = roleReason; return(false); } ThingDefStuffDefPair sidearm = sidearmThing.toThingDefStuffDefPair(); return(canCarrySidearmType(sidearm, pawn, out errString)); }
public static void SubvertBiocodedGear(Pawn target, Pawn subverter) { Pawn_EquipmentTracker eqTracker = target.equipment; foreach (Thing eq in eqTracker.AllEquipmentListForReading) { // if biocodable and biocoded, code to subverter CompBiocodable biocode = eq.TryGetComp <CompBiocodable>(); if (biocode != null && biocode.Biocoded) { biocode.CodeFor(subverter); eqTracker.TryDropEquipment(eqTracker.Primary, out ThingWithComps dontcare, target.Position); } } Pawn_ApparelTracker apTracker = target.apparel; foreach (Apparel ap in apTracker.WornApparel) { CompBiocodable biocode = ap.TryGetComp <CompBiocodable>(); if (biocode != null && biocode.Biocoded) { biocode.CodeFor(subverter); apTracker.TryDrop(ap); } } }
public override void Tick() { base.Tick(); if (base.Wearer == null) { return; } if (this.Wearer.kindDef == PawnKindDefOf.WildMan) { this.Destroy(DestroyMode.Vanish); return; } if (this.Wearer.Faction == null) { this.Destroy(DestroyMode.Vanish); return; } if (this.Wearer.kindDef.defaultFactionType != PSFDefOf.Polaribloc_SecuirityForce) { this.Destroy(DestroyMode.Vanish); return; } if (this.Wearer != null) { if (ModLister.GetActiveModWithIdentifier("Vanya.Polarisbloc.CoreLab") != null) { this.Wearer.health.AddHediff(HediffDef.Named("PolarisCombatChip_Currency"), this.Wearer.health.hediffSet.GetBrain(), null); } BodyPartRecord eye = this.GetEye(); if (eye != null) { this.Wearer.health.AddHediff(HediffDef.Named("BionicEye"), eye, null); } BodyPartRecord leg = this.GetLeg(); if (leg != null) { this.Wearer.health.AddHediff(HediffDef.Named("BionicLeg"), leg, null); } if (this.Wearer.health.hediffSet.hediffs.Find(x => x.TryGetComp <HediffComp_Cartridge>() != null) == null) { Hediff hediff = HediffMaker.MakeHediff(PolarisblocDefOf.Hediff_PloarisCartridge, this.Wearer, null); this.Wearer.health.AddHediff(hediff); } CombatEnhancingDrugsApply(this.Wearer); foreach (Apparel ap in this.Wearer.apparel.WornApparel) { CompBiocodable compBiocodable = ap.TryGetComp <CompBiocodable>(); if (compBiocodable != null && !compBiocodable.Biocoded) { compBiocodable.CodeFor(this.Wearer); } } this.Wearer.apparel.Remove(this); this.Destroy(DestroyMode.Vanish); return; } }
private static void DecodeBiocoded() { foreach (Thing thing in Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell()).ToList <Thing>()) { CompBiocodable compBiocodable = thing.TryGetComp <CompBiocodable>(); if (compBiocodable != null && compBiocodable.Biocoded) { compBiocodable.UnCode(); } DebugActionsUtility.DustPuffFrom(thing); } }
public static Thing PickBestArmorFor(Pawn pawn) { if (pawn.outfits == null) { return(null); } if (pawn.Faction != Faction.OfPlayer) { return(null); } if (pawn.IsQuestLodger()) { return(null); } Outfit currentOutfit = pawn.outfits.CurrentOutfit; Thing thing = null; float num2 = 0f; List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel); if (list.Count == 0) { return(null); } neededWarmth = PawnApparelGenerator.CalculateNeededWarmth(pawn, pawn.Map.Tile, GenLocalDate.Twelfth(pawn)); wornApparelScores = new List <float>(); List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int i = 0; i < wornApparel.Count; i++) { wornApparelScores.Add(ApparelScoreRaw(pawn, wornApparel[i])); } for (int j = 0; j < list.Count; j++) { Apparel apparel = (Apparel)list[j]; // && apparel.IsInAnyStorage() if (!apparel.IsBurning() && currentOutfit.filter.Allows(apparel) && !apparel.IsForbidden(pawn) && (apparel.def.apparel.gender == Gender.None || apparel.def.apparel.gender == pawn.gender)) { float num3 = ApparelScoreGain_NewTmp(pawn, apparel, wornApparelScores); if (!(num3 < 0.05f) && !(num3 < num2) && (!CompBiocodable.IsBiocoded(apparel) || CompBiocodable.IsBiocodedFor(apparel, pawn)) && ApparelUtility.HasPartsToWear(pawn, apparel.def) && pawn.CanReserveAndReach(apparel, PathEndMode.OnCell, pawn.NormalMaxDanger())) { thing = apparel; num2 = num3; } } } return(thing); }
/// <summary> /// METHOD SIGNATURE CANNOT BE CHANGED AS MENDING PATCH USES THIS METHOD /// </summary> public bool Remove(ThingWithComps weapon) { if (weapon == null) { return(true); } if (!CompBiocodable.IsBiocoded(weapon)) { //Log.Warning("Remove non-biocoded"); return(this.RemoveFrom(weapon, this.StoredWeapons)); } //Log.Warning("Remove biocoded"); //foreach (var l in this.StoredBioEncodedWeapons.Values) // foreach (var w in l) // Log.Warning(" - " + w.Label); return(this.RemoveFrom(weapon, this.StoredBioEncodedWeapons)); }
/*internal void AddWeapons(IEnumerable<ThingWithComps> weapons) * { * if (weapons == null) * return; * * foreach (ThingWithComps w in weapons) * { * this.AddWeapon(w); * } * }*/ internal bool AddWeapon(ThingWithComps weapon) { if (this.CanAdd(weapon)) { if (weapon.Spawned) { weapon.DeSpawn(); } if (CombatExtendedUtil.AddAmmo(weapon)) { return(true); } this.AddToSortedList(weapon, (CompBiocodable.IsBiocoded(weapon)) ? this.StoredBioEncodedWeapons : this.StoredWeapons); return(true); } return(false); }
static void DropDownThingMenu(object tab, Thing thing) { Pawn SelPawnForGear = (Pawn)LSelPawnForGear.GetValue(tab); Pawn SelPawn = (Pawn)LSelPawn.GetValue(tab); bool canControl = (bool)LCanControl.GetValue(tab); List <FloatMenuOption> list = new List <FloatMenuOption>(); list.Add(new FloatMenuOption("ThingInfo".Translate(), delegate() { Find.WindowStack.Add(new Dialog_InfoCard(thing)); }, MenuOptionPriority.Default, null, null, 0f, null, null)); //bool canControl = this.CanControl; if (canControl) { ThingWithComps eq = thing as ThingWithComps; bool flag10 = eq != null && eq.TryGetComp <CompEquippable>() != null; if (flag10) { object comp = SelPawnForGear.getCompInventory(); CompBiocodable compBiocodable = eq.TryGetComp <CompBiocodable>(); bool flag11 = comp != null; if (flag11) { string value = GenLabel.ThingLabel(eq.def, eq.Stuff, 1); bool flag12 = compBiocodable != null && compBiocodable.Biocoded && compBiocodable.CodedPawn != SelPawnForGear; FloatMenuOption item; if (flag12) { item = new FloatMenuOption("CannotEquip".Translate(value) + ": " + "BiocodedCodedForSomeoneElse".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { bool flag13 = SelPawnForGear.IsQuestLodger() && !EquipmentUtility.QuestLodgerCanEquip(eq, SelPawnForGear); if (flag13) { TaggedString t = SelPawnForGear.equipment.AllEquipmentListForReading.Contains(eq) ? "CE_CannotPutAway".Translate(value) : "CannotEquip".Translate(value); item = new FloatMenuOption(t + ": " + "CE_CannotChangeEquipment".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { bool flag14 = SelPawnForGear.equipment.AllEquipmentListForReading.Contains(eq) && SelPawnForGear.inventory != null; if (flag14) { item = new FloatMenuOption("CE_PutAway".Translate(value), delegate() { SelPawnForGear.equipment.TryTransferEquipmentToContainer(SelPawnForGear.equipment.Primary, SelPawnForGear.inventory.innerContainer); }, MenuOptionPriority.Default, null, null, 0f, null, null); } else { bool flag15 = !SelPawnForGear.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); if (flag15) { item = new FloatMenuOption("CannotEquip".Translate(value), null, MenuOptionPriority.Default, null, null, 0f, null, null); } else { string text4 = "Equip".Translate(value); bool flag16 = eq.def.IsRangedWeapon && SelPawnForGear.story != null && SelPawnForGear.story.traits.HasTrait(TraitDefOf.Brawler); if (flag16) { text4 = text4 + " " + "EquipWarningBrawler".Translate(); } item = new FloatMenuOption(text4, (SelPawnForGear.story != null && SelPawnForGear.WorkTagIsDisabled(WorkTags.Violent)) ? null : new Action(delegate() { CEAccess.trySwitchToWeapon(comp, eq); }), MenuOptionPriority.Default, null, null, 0f, null, null); } } } } list.Add(item); } } //Pawn selPawnForGear = SelPawnForGear; //?? List <Apparel> list2; if (SelPawnForGear == null) { list2 = null; } else { Pawn_ApparelTracker apparel2 = SelPawnForGear.apparel; list2 = ((apparel2 != null) ? apparel2.WornApparel : null); } List <Apparel> list3 = list2; using (List <Apparel> .Enumerator enumerator = list3.GetEnumerator()) { while (enumerator.MoveNext()) { Apparel apparel = enumerator.Current; CompReloadable compReloadable = apparel.TryGetComp <CompReloadable>(); bool flag17 = compReloadable != null && compReloadable.AmmoDef == thing.def && compReloadable.NeedsReload(true); if (flag17) { bool flag18 = !SelPawnForGear.Drafted; if (flag18) { FloatMenuOption item2 = new FloatMenuOption("CE_ReloadApparel".Translate(apparel.Label, thing.Label), delegate() { SelPawnForGear.jobs.TryTakeOrderedJob(JobMaker.MakeJob(JobDefOf.Reload, apparel, thing), JobTag.Misc); }, MenuOptionPriority.Default, null, null, 0f, null, null); list.Add(item2); } } } } bool flag19 = canControl && thing.IngestibleNow && SelPawn.RaceProps.CanEverEat(thing); if (flag19) { Action action = delegate() { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); LInterfaceIngest.Invoke(tab, new object[] { thing }); }; string text5 = thing.def.ingestible.ingestCommandString.NullOrEmpty() ? (string)"ConsumeThing".Translate(thing.LabelShort, thing) : string.Format(thing.def.ingestible.ingestCommandString, thing.LabelShort); bool flag20 = SelPawnForGear.IsTeetotaler() && thing.def.IsNonMedicalDrug; if (flag20) { List <FloatMenuOption> list4 = list; string str = text5; string str2 = ": "; TraitDegreeData traitDegreeData = (from x in TraitDefOf.DrugDesire.degreeDatas where x.degree == -1 select x).First <TraitDegreeData>(); list4.Add(new FloatMenuOption(str + str2 + ((traitDegreeData != null) ? traitDegreeData.label : null), null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { list.Add(new FloatMenuOption(text5, action, MenuOptionPriority.Default, null, null, 0f, null, null)); } } bool flag21 = SelPawnForGear.isItemQuestLocked(eq); if (flag21) { list.Add(new FloatMenuOption("CE_CannotDropThing".Translate() + ": " + "DropThingLocked".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null)); list.Add(new FloatMenuOption("CE_CannotDropThingHaul".Translate() + ": " + "DropThingLocked".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null)); } else { list.Add(new FloatMenuOption("DropThing".Translate(), delegate() { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); LInterfaceDrop.Invoke(tab, new object[] { thing }); }, MenuOptionPriority.Default, null, null, 0f, null, null)); list.Add(new FloatMenuOption("CE_DropThingHaul".Translate(), delegate() { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); InterfaceDropHaul(SelPawnForGear, thing, SelPawn); }, MenuOptionPriority.Default, null, null, 0f, null, null)); } bool flag22 = canControl && (bool)LHoldTrackerIsHeld.Invoke(null, new object[] { SelPawnForGear, thing }); //SelPawnForGear.HoldTrackerIsHeld(thing); if (flag22) { Action action2 = delegate() { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); LHoldTrackerForget.Invoke(null, new object[] { SelPawnForGear, thing }); //SelPawnForGear.HoldTrackerForget(thing); }; list.Add(new FloatMenuOption("CE_HoldTrackerForget".Translate(), action2, MenuOptionPriority.Default, null, null, 0f, null, null)); } } FloatMenu window = new FloatMenu(list, thing.LabelCap, false); Find.WindowStack.Add(window); }
private void DrawThingRow(ref float y, float width, Thing thing, bool showDropButtonIfPrisoner = false) { Rect rect = new Rect(0f, y, width, _thingRowHeight); Widgets.InfoCardButton(rect.width - 24f, y, thing); rect.width -= 24f; if (CanControl || (SelPawnForGear.Faction == Faction.OfPlayer && SelPawnForGear.RaceProps.packAnimal) || (showDropButtonIfPrisoner && SelPawnForGear.IsPrisonerOfColony)) { Rect dropRect = new Rect(rect.width - 24f, y, 24f, 24f); TooltipHandler.TipRegion(dropRect, "DropThing".Translate()); if (Widgets.ButtonImage(dropRect, TexButton.Drop)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceDrop(thing); } rect.width -= 24f; } if (CanControlColonist) { if ((thing.def.IsNutritionGivingIngestible || thing.def.IsNonMedicalDrug) && thing.IngestibleNow && base.SelPawn.WillEat(thing, null) && (!SelPawnForGear.IsTeetotaler() || !thing.def.IsNonMedicalDrug)) { Rect rect3 = new Rect(rect.width - 24f, y, 24f, 24f); TooltipHandler.TipRegion(rect3, "ConsumeThing".Translate(thing.LabelNoCount, thing)); if (Widgets.ButtonImage(rect3, TexButton.Ingest)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); InterfaceIngest(thing); } } rect.width -= 24f; } Rect rect4 = rect; rect4.xMin = rect4.xMax - 60f; CaravanThingsTabUtility.DrawMass(thing, rect4); rect.width -= 60f; if (Mouse.IsOver(rect)) { GUI.color = _highlightColor; GUI.DrawTexture(rect, TexUI.HighlightTex); } if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null) { Widgets.ThingIcon(new Rect(4f, y, _thingIconSize, _thingIconSize), thing, 1f); } Text.Anchor = TextAnchor.MiddleLeft; GUI.color = ThingLabelColor; Rect thingLabelRect = new Rect(_thingLeftX, y, rect.width - _thingLeftX, _thingRowHeight); string thingLabel = thing.LabelCap; if ((thing is Apparel && SelPawnForGear.outfits != null && SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing)) || (SelPawnForGear.inventory != null && SelPawnForGear.HoldTrackerIsHeld(thing))) { thingLabel = thingLabel + ", " + "ApparelForcedLower".Translate(); } Text.WordWrap = false; Widgets.Label(thingLabelRect, thingLabel.Truncate(thingLabelRect.width, null)); Text.WordWrap = true; string text2 = string.Concat(new object[] { thing.LabelCap, "\n", thing.DescriptionDetailed, "\n", thing.GetWeightAndBulkTip() }); if (thing.def.useHitPoints) { string text3 = text2; text2 = string.Concat(new object[] { text3, "\n", "HitPointsBasic".Translate().CapitalizeFirst(), ": ", thing.HitPoints, " / ", thing.MaxHitPoints }); } TooltipHandler.TipRegion(thingLabelRect, text2); y += 28f; // RMB menu if (Widgets.ButtonInvisible(thingLabelRect) && Event.current.button == 1) { List <FloatMenuOption> floatOptionList = new List <FloatMenuOption>(); floatOptionList.Add(new FloatMenuOption("ThingInfo".Translate(), delegate { Find.WindowStack.Add(new Dialog_InfoCard(thing)); }, MenuOptionPriority.Default, null, null)); if (CanControl) { // Equip option ThingWithComps eq = thing as ThingWithComps; if (eq != null && eq.TryGetComp <CompEquippable>() != null) { CompInventory compInventory = SelPawnForGear.TryGetComp <CompInventory>(); CompBiocodable compBiocoded = eq.TryGetComp <CompBiocodable>(); if (compInventory != null) { FloatMenuOption equipOption; string eqLabel = GenLabel.ThingLabel(eq.def, eq.Stuff, 1); if (compBiocoded != null && compBiocoded.Biocoded && compBiocoded.CodedPawn != SelPawnForGear) { equipOption = new FloatMenuOption("CannotEquip".Translate(eqLabel) + ": " + "BiocodedCodedForSomeoneElse".Translate(), null); } else if (SelPawnForGear.equipment.AllEquipmentListForReading.Contains(eq) && SelPawnForGear.inventory != null) { equipOption = new FloatMenuOption("CE_PutAway".Translate(eqLabel), new Action(delegate { SelPawnForGear.equipment.TryTransferEquipmentToContainer(SelPawnForGear.equipment.Primary, SelPawnForGear.inventory.innerContainer); })); } else if (!SelPawnForGear.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { equipOption = new FloatMenuOption("CannotEquip".Translate(eqLabel), null); } else { string equipOptionLabel = "Equip".Translate(eqLabel); if (eq.def.IsRangedWeapon && SelPawnForGear.story != null && SelPawnForGear.story.traits.HasTrait(TraitDefOf.Brawler)) { equipOptionLabel = equipOptionLabel + " " + "EquipWarningBrawler".Translate(); } equipOption = new FloatMenuOption( equipOptionLabel, (SelPawnForGear.story != null && SelPawnForGear.WorkTagIsDisabled(WorkTags.Violent)) ? null : new Action(delegate { compInventory.TrySwitchToWeapon(eq); })); } floatOptionList.Add(equipOption); } } // Drop option Action dropApparel = delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceDrop(thing); }; Action dropApparelHaul = delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceDropHaul(thing); }; if (CanControl && thing.IngestibleNow && base.SelPawn.RaceProps.CanEverEat(thing)) { Action eatFood = delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceIngest(thing); }; string label = thing.def.ingestible.ingestCommandString.NullOrEmpty() ? (string)"ConsumeThing".Translate(thing.LabelShort, thing) : string.Format(thing.def.ingestible.ingestCommandString, thing.LabelShort); if (SelPawnForGear.IsTeetotaler() && thing.def.IsNonMedicalDrug) { floatOptionList.Add(new FloatMenuOption(label + ": " + TraitDefOf.DrugDesire.degreeDatas.Where(x => x.degree == -1).First()?.label, null)); } else { floatOptionList.Add(new FloatMenuOption(label, eatFood)); } } floatOptionList.Add(new FloatMenuOption("DropThing".Translate(), dropApparel)); floatOptionList.Add(new FloatMenuOption("CE_DropThingHaul".Translate(), dropApparelHaul)); if (CanControl && SelPawnForGear.HoldTrackerIsHeld(thing)) { Action forgetHoldTracker = delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); SelPawnForGear.HoldTrackerForget(thing); }; floatOptionList.Add(new FloatMenuOption("CE_HoldTrackerForget".Translate(), forgetHoldTracker)); } } FloatMenu window = new FloatMenu(floatOptionList, thing.LabelCap, false); Find.WindowStack.Add(window); } // end menu }
public override void ExposeData() { base.ExposeData(); if (Scribe.mode == LoadSaveMode.Saving) { this.temp = new List <ThingWithComps>(); foreach (IEnumerable <ThingWithComps> l in this.StoredWeapons.Values) { this.temp.AddRange(l); } foreach (IEnumerable <ThingWithComps> l in this.StoredBioEncodedWeapons.Values) { this.temp.AddRange(l); } if (this.forceAddedWeapons == null) { this.forceAddedWeapons = new List <Thing>(0); } } Scribe_Collections.Look(ref this.temp, false, "storedWeapons", LookMode.Deep, new object[0]); Scribe_Values.Look <bool>(ref this.includeInTradeDeals, "includeInTradeDeals", true, false); Scribe_Values.Look <bool>(ref this.IncludeInSharedWeapons, "includeInSharedWeapons", true, false); Scribe_Collections.Look(ref this.forceAddedWeapons, false, "forceAddedWeapons", LookMode.Deep, new object[0]); Scribe_Values.Look(ref this.Name, "name", "", false); if (Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { this.StoredWeapons.Clear(); this.StoredBioEncodedWeapons.Clear(); if (this.temp != null) { foreach (ThingWithComps t in this.temp) { if (CompBiocodable.IsBiocoded(t)) { this.AddToSortedList(t, this.StoredBioEncodedWeapons); } else { this.AddToSortedList(t, this.StoredWeapons); } } } } if (Scribe.mode == LoadSaveMode.Saving || Scribe.mode == LoadSaveMode.ResolvingCrossRefs) { if (this.temp != null) { this.temp.Clear(); this.temp = null; } if (this.forceAddedWeapons != null && this.forceAddedWeapons.Count == 0) { this.forceAddedWeapons = null; } } }
private bool Contains(ThingWithComps t) { return(this.Contains(t, (CompBiocodable.IsBiocoded(t)) ? this.StoredBioEncodedWeapons : this.StoredWeapons)); }
//reworked to use my own code instead of generator code nicked from vanilla Rimworld public static bool TryGenerateSidearmFor(Pawn pawn, float chance, float budgetMultiplier, PawnGenerationRequest request) { if ( !(Current.ProgramState == ProgramState.Playing) || !pawn.IsValidSidearmsCarrier() || chance < 0.01f || pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0 || pawn.equipment.Primary == null || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || (pawn.story != null && ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0)) ) { /* * Log.Message("sidearm viability conditions not met"); * * if (pawn is null) * Log.Message("pawn is null"); * if (SimpleSidearms.configData is null) * Log.Message("configData null"); * if (chance < 0.01f) * Log.Message("chance < 0.01"); * if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0) * Log.Message("weapon tags null or empty"); * if (pawn.equipment == null || pawn.equipment.Primary == null) * Log.Message("equipment null or no primary"); * if (!pawn.RaceProps.ToolUser) * Log.Message("not a toolUser"); * if (!pawn.RaceProps.Humanlike) * Log.Message("not humanlike"); * if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) * Log.Message("not capable of manipulation"); * if ((pawn.story != null && ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0))) * Log.Message("disabled violent work tags, tags:"+pawn.CombinedDisabledWorkTags); */ return(false); } else { //bool primarySingleUse = pawn.equipment.Primary.GetComp<CompEquippable>().PrimaryVerb is Verb_ShootOneUse; ThingDefStuffDefPair primaryBase = new ThingDefStuffDefPair(pawn.equipment.Primary.def, pawn.equipment.Primary.Stuff); var sidearmChanceRoll = Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824); if (sidearmChanceRoll >= chance) { return(false); //rolled no sidearm } IEnumerable <ThingDefStuffDefPair> validSidearms = GettersFilters.getValidSidearms(); IEnumerable <string> weaponTags = generateWeaponTags(pawn.kindDef.weaponTags); validSidearms = validSidearms.Where(t => { foreach (string tag in t.thing.weaponTags) { if (t == null || t.thing == null || t.thing.weaponTags == null) { continue; } if (weaponTags.Contains(tag)) { return(true); } } return(false); }); //filter out nonsensical material weapons validSidearms = validSidearms.Where(w => w.stuff == null || (w.stuff != ThingDefOf.Gold && w.stuff != ThingDefOf.Silver && w.stuff != ThingDefOf.Uranium)); //filter out weapons the pawn cant carry validSidearms = validSidearms.Where(w => StatCalculator.canCarrySidearmType(w, pawn, out _)); bool onlyMelee = (pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler)); bool onlyRanged = (pawn.story != null && pawn.story.traits.HasTrait(TraitDef.Named("Wimp"))); //wimp has no defOf if (onlyMelee) { validSidearms = validSidearms.Where(w => w.thing.IsMeleeWeapon); } if (onlyRanged) { validSidearms = validSidearms.Where(w => w.thing.IsRangedWeapon); } //listWeapons("budget " + pawn.kindDef.weaponMoney.max* budgetMultiplier + " to " + pawn.kindDef.weaponMoney.min* budgetMultiplier + ", main "+ pawn.equipment.Primary.MarketValue +" selecting from:", validSidearms); //use the value of primary to limit budget maximum (but of the base to match pre-degradation value) to prevent sidearms being better than the primary weapon float budget = Math.Min(pawn.kindDef.weaponMoney.RandomInRange, primaryBase.Price) * budgetMultiplier; validSidearms = validSidearms.Where(t => t.Price <= budget); //listWeapons("post select:", validSidearms); if (validSidearms.Count() == 0) { return(false); } ThingDefStuffDefPair rolledWeaponThingDefStuffDefPair; validSidearms.TryRandomElementByWeight(t => { return(t.Commonality * t.Price); }, out rolledWeaponThingDefStuffDefPair); ThingWithComps rolledWeaponFinal = (ThingWithComps)ThingMaker.MakeThing(rolledWeaponThingDefStuffDefPair.thing, rolledWeaponThingDefStuffDefPair.stuff); PawnGenerator.PostProcessGeneratedGear(rolledWeaponFinal, pawn); float num = (request.BiocodeWeaponChance > 0f) ? request.BiocodeWeaponChance : pawn.kindDef.biocodeWeaponChance; if (Rand.Value < num) { CompBiocodable compBiocodableWeapon = rolledWeaponFinal.TryGetComp <CompBiocodable>(); if (compBiocodableWeapon != null) { compBiocodableWeapon.CodeFor(pawn); } } bool success = pawn.inventory.innerContainer.TryAdd(rolledWeaponFinal); if (success) { CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn); if (pawnMemory != null) { pawnMemory.InformOfAddedSidearm(rolledWeaponFinal); } } else { Log.Warning("Failed to add generated sidearm to inventory"); } return(true); } }
private void Recode() { //CompBiocodableWeapon biocodableWeapon = this.CodableThing.TryGetComp<CompBiocodableWeapon>(); CompBiocodable biocodableThing = this.CodableThing.TryGetComp <CompBiocodable>(); CompBladelinkWeapon bladelinkWeapon = this.CodableThing.TryGetComp <CompBladelinkWeapon>(); bool selfDestory = false; /*if (Rand.Value > this.SuccessChance) * { * Messages.Message("PolarisDecoderFailedUsedForPawn".Translate(this.pawn.NameShortColored, this.CodableThing.Label), MessageTypeDefOf.NegativeEvent, true); * if (Rand.Value < this.Configs.selfDestoryOnFailed) * { * Messages.Message("PolarisDecoderSelfDestroyed".Translate(), MessageTypeDefOf.NegativeEvent, true); * this.Item.SplitOff(1).Destroy(DestroyMode.Vanish); * } * return; * } * Messages.Message("PolarisDecoderSuccessedUsedForPawn".Translate(this.pawn.NameShortColored, this.CodableThing.Label), this.pawn, MessageTypeDefOf.PositiveEvent, true);*/ /*if (biocodableWeapon != null) * { * if (biocodableWeapon.Biocoded) * { * biocodableWeapon.CodeFor(this.pawn); * if (Rand.Value < this.Configs.selfDestoryOnSuccessed) * { * selfDestory = true; * } * } * else * { * biocodableWeapon.CodeFor(this.pawn); * * } * }*/ if (biocodableThing != null) { if (biocodableThing.Biocoded) { if (this.CheckSuccessOnUsed()) { biocodableThing.CodeFor(this.pawn); if (Rand.Value < this.Configs.selfDestoryOnSuccessed) { selfDestory = true; } } } else { biocodableThing.CodeFor(this.pawn); Messages.Message("PolarisDecoderSuccessedUsedForPawn".Translate(this.pawn.NameShortColored, this.CodableThing.Label), this.pawn, MessageTypeDefOf.PositiveEvent, true); } } if (bladelinkWeapon != null) { if (bladelinkWeapon.bondedPawn != this.pawn) { if (this.CheckSuccessOnUsed()) { bladelinkWeapon.bondedPawn = null; bladelinkWeapon.Notify_Equipped(this.pawn); if (Rand.Value < this.Configs.selfDestoryOnSuccessed) { selfDestory = true; } } } } if (biocodableThing == null && bladelinkWeapon == null) { throw new ArgumentOutOfRangeException(); } if (selfDestory) { this.Item.SplitOff(1).Destroy(DestroyMode.Vanish); Messages.Message("PolarisDecoderSelfDestroyed".Translate(), MessageTypeDefOf.NegativeEvent, true); } }
private static bool AllowedByBiocode(Thing thing, Pawn pawn) { CompBiocodable compBiocoded = thing.TryGetComp <CompBiocodable>(); return(compBiocoded == null || !compBiocoded.Biocoded || compBiocoded.CodedPawn == pawn); }
public static Thing PickBestWeaponFor(Pawn pawn) { if (pawn.Map == null || pawn.equipment == null || pawn.Faction != Faction.OfPlayer || pawn.IsQuestLodger() || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || pawn.WorkTagIsDisabled(WorkTags.Violent)) { return(null); } bool isBrawler = pawn.story?.traits?.HasTrait(TraitDefOf.Brawler) ?? false; bool preferRanged = !isBrawler && (!pawn.equipment.Primary?.def.IsMeleeWeapon ?? false || pawn.equipment.Primary == null); Predicate <Thing> validator = delegate(Thing t) { if (!t.def.IsWeapon) { return(false); } if (t.IsForbidden(pawn)) { return(false); } if (isBrawler && t.def.IsRangedWeapon) { return(false); } if (preferRanged && t.def.IsMeleeWeapon) { return(false); } if (!preferRanged && t.def.IsRangedWeapon) { return(false); } if (t.def.weaponTags != null && t.def.weaponTags.Where(x => x.ToLower().Contains("grenade")).Any()) { return(false); } if (t.def.IsRangedWeapon && t.def.Verbs.Where(x => x.verbClass == typeof(Verb_ShootOneUse)).Any()) { return(false); } return(true); }; Thing thing = null; float maxValue = 0f; List <Thing> list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Weapon).Where(x => validator(x)).ToList(); List <Thing> weapons = pawn.inventory.innerContainer.InnerListForReading.Where(x => validator(x)).ToList(); list.AddRange(weapons); if (pawn.equipment.Primary != null) { list.Add(pawn.equipment.Primary); } for (int j = 0; j < list.Count; j++) { Thing weapon = list[j]; if (!weapon.IsBurning()) { float weaponScore = WeaponScoreGain(weapon, StatDefOf.AccuracyMedium); if (!(weaponScore < 0.05f) && !(weaponScore < maxValue) && (!CompBiocodable.IsBiocoded(weapon) || CompBiocodable.IsBiocodedFor(weapon, pawn)) && EquipmentUtility.CanEquip(weapon, pawn) && pawn.CanReserveAndReach(weapon, PathEndMode.OnCell, pawn.NormalMaxDanger())) { thing = weapon; maxValue = weaponScore; } } } return(thing); }
private void DrawThingRow(ref float y, float width, Thing thing, bool showDropButtonIfPrisoner = false) { Rect rect = new Rect(0f, y, width, _thingRowHeight); Widgets.InfoCardButton(rect.width - 24f, y, thing); rect.width -= 24f; if (CanControl || (SelPawnForGear.Faction == Faction.OfPlayer && SelPawnForGear.RaceProps.packAnimal) || (showDropButtonIfPrisoner && SelPawnForGear.IsPrisonerOfColony)) { var dropForbidden = IsItemDropForbidden(thing); Color color = dropForbidden ? Color.grey : Color.white; Color mouseoverColor = dropForbidden ? Color.grey : GenUI.MouseoverColor; Rect dropRect = new Rect(rect.width - 24f, y, 24f, 24f); TooltipHandler.TipRegion(dropRect, dropForbidden ? "DropThingLocked".Translate() : "DropThing".Translate()); if (Widgets.ButtonImage(dropRect, TexButton.Drop, color, mouseoverColor) && !dropForbidden) { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceDrop(thing); } rect.width -= 24f; } if (CanControlColonist) { if ((thing.def.IsNutritionGivingIngestible || thing.def.IsNonMedicalDrug) && thing.IngestibleNow && base.SelPawn.WillEat(thing, null) && (!SelPawnForGear.IsTeetotaler() || !thing.def.IsNonMedicalDrug)) { Rect rect3 = new Rect(rect.width - 24f, y, 24f, 24f); TooltipHandler.TipRegion(rect3, "ConsumeThing".Translate(thing.LabelNoCount, thing)); if (Widgets.ButtonImage(rect3, TexButton.Ingest)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); InterfaceIngest(thing); } } rect.width -= 24f; } Rect rect4 = rect; rect4.xMin = rect4.xMax - 60f; CaravanThingsTabUtility.DrawMass(thing, rect4); rect.width -= 60f; if (Mouse.IsOver(rect)) { GUI.color = _highlightColor; GUI.DrawTexture(rect, TexUI.HighlightTex); } if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null) { Widgets.ThingIcon(new Rect(4f, y, _thingIconSize, _thingIconSize), thing, 1f); } Text.Anchor = TextAnchor.MiddleLeft; GUI.color = ThingLabelColor; Rect thingLabelRect = new Rect(_thingLeftX, y, rect.width - _thingLeftX, _thingRowHeight); string thingLabel = thing.LabelCap; if ((thing is Apparel && SelPawnForGear.outfits != null && SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing)) || (SelPawnForGear.inventory != null && SelPawnForGear.HoldTrackerIsHeld(thing))) { thingLabel = thingLabel + ", " + "ApparelForcedLower".Translate(); } Text.WordWrap = false; Widgets.Label(thingLabelRect, thingLabel.Truncate(thingLabelRect.width, null)); Text.WordWrap = true; string text2 = string.Concat(new object[] { thing.LabelCap, "\n", thing.DescriptionDetailed, "\n", thing.GetWeightAndBulkTip() }); if (thing.def.useHitPoints) { string text3 = text2; text2 = string.Concat(new object[] { text3, "\n", "HitPointsBasic".Translate().CapitalizeFirst(), ": ", thing.HitPoints, " / ", thing.MaxHitPoints }); } TooltipHandler.TipRegion(thingLabelRect, text2); y += 28f; // RMB menu if (Widgets.ButtonInvisible(thingLabelRect) && Event.current.button == 1) { List <FloatMenuOption> floatOptionList = new List <FloatMenuOption>(); floatOptionList.Add(new FloatMenuOption("ThingInfo".Translate(), delegate { Find.WindowStack.Add(new Dialog_InfoCard(thing)); }, MenuOptionPriority.Default, null, null)); if (CanControl) { // Equip option ThingWithComps eq = thing as ThingWithComps; if (eq != null && eq.TryGetComp <CompEquippable>() != null) { CompInventory compInventory = SelPawnForGear.TryGetComp <CompInventory>(); CompBiocodable compBiocoded = eq.TryGetComp <CompBiocodable>(); if (compInventory != null) { FloatMenuOption equipOption; string eqLabel = GenLabel.ThingLabel(eq.def, eq.Stuff, 1); if (compBiocoded != null && compBiocoded.Biocoded && compBiocoded.CodedPawn != SelPawnForGear) { equipOption = new FloatMenuOption("CannotEquip".Translate(eqLabel) + ": " + "BiocodedCodedForSomeoneElse".Translate(), null); } else if (SelPawnForGear.IsQuestLodger() && !EquipmentUtility.QuestLodgerCanEquip(eq, SelPawnForGear)) { var forbiddenEquipOrPutAway = SelPawnForGear.equipment.AllEquipmentListForReading.Contains(eq) ? "CE_CannotPutAway".Translate(eqLabel) : "CannotEquip".Translate(eqLabel); equipOption = new FloatMenuOption(forbiddenEquipOrPutAway + ": " + "CE_CannotChangeEquipment".Translate(), null); } else if (SelPawnForGear.equipment.AllEquipmentListForReading.Contains(eq) && SelPawnForGear.inventory != null) { equipOption = new FloatMenuOption("CE_PutAway".Translate(eqLabel), new Action(delegate { SelPawnForGear.equipment.TryTransferEquipmentToContainer(SelPawnForGear.equipment.Primary, SelPawnForGear.inventory.innerContainer); })); } else if (!SelPawnForGear.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { equipOption = new FloatMenuOption("CannotEquip".Translate(eqLabel), null); } else { string equipOptionLabel = "Equip".Translate(eqLabel); if (eq.def.IsRangedWeapon && SelPawnForGear.story != null && SelPawnForGear.story.traits.HasTrait(TraitDefOf.Brawler)) { equipOptionLabel = equipOptionLabel + " " + "EquipWarningBrawler".Translate(); } equipOption = new FloatMenuOption( equipOptionLabel, (SelPawnForGear.story != null && SelPawnForGear.WorkTagIsDisabled(WorkTags.Violent)) ? null : new Action(delegate { compInventory.TrySwitchToWeapon(eq); })); } floatOptionList.Add(equipOption); } } //Reload apparel option IEnumerable <Apparel> worn_apparel = SelPawnForGear?.apparel?.WornApparel ?? Enumerable.Empty <Apparel>(); foreach (var apparel in worn_apparel) { var compReloadable = apparel.TryGetComp <CompReloadable>(); if (compReloadable != null && compReloadable.AmmoDef == thing.def && compReloadable.NeedsReload(true)) { if (!SelPawnForGear.Drafted) //TODO-1.2 This should be doable for drafted pawns as well, but the job does nothing. Figure out what's wrong and remove this condition. { FloatMenuOption reloadApparelOption = new FloatMenuOption( "CE_ReloadApparel".Translate(apparel.Label, thing.Label), new Action(delegate { //var reloadJob = JobMaker.MakeJob(JobDefOf.Reload, apparel, thing); //SelPawnForGear.jobs.StartJob(reloadJob, JobCondition.InterruptForced, null, SelPawnForGear.CurJob?.def != reloadJob.def, true); SelPawnForGear.jobs.TryTakeOrderedJob(JobMaker.MakeJob(JobDefOf.Reload, apparel, thing)); }) ); floatOptionList.Add(reloadApparelOption); } } } // Consume option if (CanControl && thing.IngestibleNow && base.SelPawn.RaceProps.CanEverEat(thing)) { Action eatFood = delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceIngest(thing); }; string label = thing.def.ingestible.ingestCommandString.NullOrEmpty() ? (string)"ConsumeThing".Translate(thing.LabelShort, thing) : string.Format(thing.def.ingestible.ingestCommandString, thing.LabelShort); if (SelPawnForGear.IsTeetotaler() && thing.def.IsNonMedicalDrug) { floatOptionList.Add(new FloatMenuOption(label + ": " + TraitDefOf.DrugDesire.degreeDatas.Where(x => x.degree == -1).First()?.label, null)); } else { floatOptionList.Add(new FloatMenuOption(label, eatFood)); } } // Drop, and drop&haul options if (IsItemDropForbidden(eq)) { floatOptionList.Add(new FloatMenuOption("CE_CannotDropThing".Translate() + ": " + "DropThingLocked".Translate(), null)); floatOptionList.Add(new FloatMenuOption("CE_CannotDropThingHaul".Translate() + ": " + "DropThingLocked".Translate(), null)); } else { floatOptionList.Add(new FloatMenuOption("DropThing".Translate(), new Action(delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceDrop(thing); }))); floatOptionList.Add(new FloatMenuOption("CE_DropThingHaul".Translate(), new Action(delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); InterfaceDropHaul(thing); }))); } // Stop holding in inventory option if (CanControl && SelPawnForGear.HoldTrackerIsHeld(thing)) { Action forgetHoldTracker = delegate { SoundDefOf.Tick_High.PlayOneShotOnCamera(); SelPawnForGear.HoldTrackerForget(thing); }; floatOptionList.Add(new FloatMenuOption("CE_HoldTrackerForget".Translate(), forgetHoldTracker)); } } FloatMenu window = new FloatMenu(floatOptionList, thing.LabelCap, false); Find.WindowStack.Add(window); } // end menu }
public static bool DrawThingRow(Pawn SelPawn, bool CanControl, ref float y, ref float width, Thing thing, bool inventory) { Color hColor = new Color(1f, 0.8f, 0.8f, 1f); bool IsBiocodedOrLinked(Pawn pawn, Thing athing, bool ainventory) { if (pawn.IsQuestLodger()) { if (ainventory) { return(true); } else { CompBiocodable compBiocodable = athing.TryGetComp <CompBiocodable>(); if (compBiocodable != null && compBiocodable.Biocoded) { return(true); } else { CompBladelinkWeapon compBladelinkWeapon = athing.TryGetComp <CompBladelinkWeapon>(); return(compBladelinkWeapon != null && compBladelinkWeapon.bondedPawn == pawn); } } } else { return(false); } } bool IsLocked(Pawn pawn, Thing athing) { Apparel apparel; return((apparel = (athing as Apparel)) != null && pawn.apparel != null && pawn.apparel.IsLocked(apparel)); } if (!Settings.gui_manual_unload) { return(true); } Rect rect = new Rect(0f, y, width, 28f); if (CanControl && (SelPawn.IsColonistPlayerControlled || SelPawn.Spawned && !SelPawn.Map.IsPlayerHome) && (thing is ThingWithComps) && !IsBiocodedOrLinked(SelPawn, thing, inventory) && !IsLocked(SelPawn, thing)) { Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f); CompUnloadChecker c = CompUnloadChecker.GetChecker(thing, false, true); if (c.ShouldUnload) { TooltipHandler.TipRegion(rect2, "UnloadThingCancel".Translate()); //weird shenanigans with colors var cl = GUI.color; if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing_Cancel"), hColor)) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = false; if (MassUtility.Capacity(SelPawn, null) < MassUtility.GearAndInventoryMass(SelPawn) && thing.stackCount * thing.GetStatValue(StatDefOf.Mass, true) > 0 && !thing.def.destroyOnDrop) { Thing t; SelPawn.inventory.innerContainer.TryDrop(thing, SelPawn.Position, SelPawn.Map, ThingPlaceMode.Near, out t, null, null); } } GUI.color = cl; } else { TooltipHandler.TipRegion(rect2, "UnloadThing".Translate()); if (Widgets.ButtonImage(rect2, ContentFinder <Texture2D> .Get("UI/Icons/Unload_Thing"))) { SoundDefOf.Tick_High.PlayOneShotOnCamera(null); c.ShouldUnload = true; } } width -= 24f; } return(true); }
public static Job TryGiveJobStatic(Pawn pawn, bool inCombat) { if (!Settings.ReEquipOutOfCombat) { return(null); } if (!Settings.ReEquipInCombat && inCombat) { return(null); } 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)) // 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.hasWeaponType(weaponMemory, dupeCounters[weaponMemory])) { float maxDist = 1000f; if (pawn.Faction != Faction.OfPlayer) { maxDist = 30f; } if (inCombat) { maxDist = 12f; } bool bladelinkable = weaponMemory.thing.HasComp(typeof(CompBladelinkWeapon)); bool biocodeable = weaponMemory.thing.HasComp(typeof(CompBiocodable)); IEnumerable <ThingWithComps> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(weaponMemory.thing).OfType <ThingWithComps>().Where(t => t.Stuff == weaponMemory.stuff); if (bladelinkable) { matchingWeapons = matchingWeapons.Where(t => { CompBladelinkWeapon bladelink = t.GetComp <CompBladelinkWeapon>(); return(bladelink != null && bladelink.Biocoded && bladelink.CodedPawn == pawn); }); } if (biocodeable) { matchingWeapons = matchingWeapons.Where(t => { CompBiocodable biocode = t.GetComp <CompBiocodable>(); if (biocode == null) { return(true); //not sure how this could ever happen... } if (biocode.Biocoded && biocode.CodedPawn != pawn) { return(false); } return(true); }); } 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) => Settings.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); } }