//PawnApparelGenerator public static void GenerateStartingApparelFor(Pawn pawn, PawnGenerationRequest request) { var swappables = pawn?.apparel?.WornApparel?.FindAll(x => x.def.HasModExtension <ApparelExtension>()); if (swappables == null || swappables?.Count <= 0) { return; } var destroyables = new HashSet <Apparel>(); foreach (var swap in swappables) { if (swap.def?.GetModExtension <ApparelExtension>()?.swapCondition is SwapCondition sc && sc?.swapWhenGender is Gender gen && gen != Gender.None && gen == pawn.gender) { Apparel apparel = (Apparel)ThingMaker.MakeThing(sc.swapTo, swap.Stuff); PawnGenerator.PostProcessGeneratedGear(apparel, pawn); if (ApparelUtility.HasPartsToWear(pawn, apparel.def)) { pawn.apparel.Wear(apparel, false); } destroyables.Add(swap); } } if (destroyables == null || destroyables?.Count <= 0) { return; } while (destroyables?.Count > 0) { var first = destroyables.First(); first.Destroy(); destroyables.Remove(first); } }
public static void TryGenerateWeaponFor(Pawn pawn, PawnGenerationRequest request) { workingWeapons.Clear(); if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0 || !pawn.RaceProps.ToolUser || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || pawn.WorkTagIsDisabled(WorkTags.Violent)) { return; } float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; for (int i = 0; i < allWeaponPairs.Count; i++) { ThingStuffPair w2 = allWeaponPairs[i]; if (!(w2.Price > randomInRange) && (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Any((string tag) => w2.thing.weaponTags.Contains(tag))) && (!(w2.thing.generateAllowChance < 1f) || Rand.ChanceSeeded(w2.thing.generateAllowChance, pawn.thingIDNumber ^ w2.thing.shortHash ^ 0x1B3B648))) { workingWeapons.Add(w2); } } if (workingWeapons.Count == 0) { return; } pawn.equipment.DestroyAllEquipment(); if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out var result)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(result.thing, result.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); float num = ((request.BiocodeWeaponChance > 0f) ? request.BiocodeWeaponChance : pawn.kindDef.biocodeWeaponChance); if (Rand.Value < num) { thingWithComps.TryGetComp <CompBiocodableWeapon>()?.CodeFor(pawn); } pawn.equipment.AddEquipment(thingWithComps); } workingWeapons.Clear(); }
public void GiveToPawn(Pawn pawn) { for (int i = 0; i < this.aps.Count; i++) { Apparel apparel = (Apparel)ThingMaker.MakeThing(this.aps[i].thing, this.aps[i].stuff); PawnGenerator.PostProcessGeneratedGear(apparel, pawn); if (ApparelUtility.HasPartsToWear(pawn, apparel.def)) { pawn.apparel.Wear(apparel, false); } } for (int j = 0; j < this.aps.Count; j++) { for (int k = 0; k < this.aps.Count; k++) { if (j != k && !ApparelUtility.CanWearTogether(this.aps[j].thing, this.aps[k].thing, pawn.RaceProps.body)) { Log.Error(string.Concat(new object[] { pawn, " generated with apparel that cannot be worn together: ", this.aps[j], ", ", this.aps[k] }), false); return; } } } }
public void GiveToPawn(Pawn pawn) { for (int i = 0; i < aps.Count; i++) { ThingStuffPair thingStuffPair = aps[i]; ThingDef thing = thingStuffPair.thing; ThingStuffPair thingStuffPair2 = aps[i]; Apparel apparel = (Apparel)ThingMaker.MakeThing(thing, thingStuffPair2.stuff); PawnGenerator.PostProcessGeneratedGear(apparel, pawn); if (ApparelUtility.HasPartsToWear(pawn, apparel.def)) { pawn.apparel.Wear(apparel, dropReplacedApparel: false); } } for (int j = 0; j < aps.Count; j++) { for (int k = 0; k < aps.Count; k++) { if (j != k) { ThingStuffPair thingStuffPair3 = aps[j]; ThingDef thing2 = thingStuffPair3.thing; ThingStuffPair thingStuffPair4 = aps[k]; if (!ApparelUtility.CanWearTogether(thing2, thingStuffPair4.thing, pawn.RaceProps.body)) { Log.Error(pawn + " generated with apparel that cannot be worn together: " + aps[j] + ", " + aps[k]); return; } } } } }
public static void TryGenerateWeaponFor(Pawn pawn) { PawnWeaponGenerator.workingWeapons.Clear(); if (pawn.kindDef.weaponTags != null && pawn.kindDef.weaponTags.Count != 0 && pawn.RaceProps.ToolUser && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && (pawn.story == null || !pawn.story.WorkTagIsDisabled(WorkTags.Violent))) { float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; for (int i = 0; i < PawnWeaponGenerator.allWeaponPairs.Count; i++) { ThingStuffPair w2 = PawnWeaponGenerator.allWeaponPairs[i]; if (!(w2.Price > randomInRange) && pawn.kindDef.weaponTags.Any((string tag) => w2.thing.weaponTags.Contains(tag)) && (!(w2.thing.generateAllowChance < 1.0) || !(Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) > w2.thing.generateAllowChance))) { PawnWeaponGenerator.workingWeapons.Add(w2); } } if (PawnWeaponGenerator.workingWeapons.Count != 0) { pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish); ThingStuffPair thingStuffPair = default(ThingStuffPair); if (((IEnumerable <ThingStuffPair>)PawnWeaponGenerator.workingWeapons).TryRandomElementByWeight <ThingStuffPair>((Func <ThingStuffPair, float>)((ThingStuffPair w) => w.Commonality * w.Price), out thingStuffPair)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.equipment.AddEquipment(thingWithComps); } PawnWeaponGenerator.workingWeapons.Clear(); } } }
public static void TryGenerateWeaponFor(Pawn pawn) { workingWeapons.Clear(); if (pawn.kindDef.weaponTags != null && pawn.kindDef.weaponTags.Count != 0 && pawn.RaceProps.ToolUser && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && (pawn.story == null || !pawn.story.WorkTagIsDisabled(WorkTags.Violent))) { float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; for (int i = 0; i < allWeaponPairs.Count; i++) { ThingStuffPair w2 = allWeaponPairs[i]; if (!(w2.Price > randomInRange) && (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Any((string tag) => w2.thing.weaponTags.Contains(tag))) && (!(w2.thing.generateAllowChance < 1f) || Rand.ChanceSeeded(w2.thing.generateAllowChance, pawn.thingIDNumber ^ w2.thing.shortHash ^ 0x1B3B648))) { workingWeapons.Add(w2); } } if (workingWeapons.Count != 0) { pawn.equipment.DestroyAllEquipment(); if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out ThingStuffPair result)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(result.thing, result.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.equipment.AddEquipment(thingWithComps); } workingWeapons.Clear(); } } }
protected override Thing GenerateLoadoutThing(int max) { Thing thing = base.GenerateLoadoutThing(max); Pawn pawn = compInvInt.parent as Pawn; if (pawn != null) { PawnGenerator.PostProcessGeneratedGear(thing, compInvInt.parent as Pawn); } return(thing); }
// Token: 0x0600000A RID: 10 RVA: 0x000022B0 File Offset: 0x000004B0 public static void PawnWeaponGenerator_TryGenerateWeaponFor_PostFix(Pawn pawn) { HugsLib.Settings.SettingHandle <int> chance = Traverse.Create(typeof(DualWield.Base)).Field("NPCDualWieldChance").GetValue <HugsLib.Settings.SettingHandle <int> >(); bool alwaysDW = (pawn.kindDef.weaponTags != null && pawn.kindDef.weaponTags.Contains("AlwaysDualWield")); Rand.PushState(); bool flag = !pawn.RaceProps.Humanlike && pawn.RaceProps.ToolUser && pawn.RaceProps.FleshType != FleshTypeDefOf.Mechanoid && pawn.equipment != null && (Rand.Chance((float)chance / 100f) || alwaysDW); Rand.PopState(); if (flag) { float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; List <ThingStuffPair> allWeaponPairs = Traverse.Create(typeof(PawnWeaponGenerator)).Field("allWeaponPairs").GetValue <List <ThingStuffPair> >(); List <ThingStuffPair> workingWeapons = Traverse.Create(typeof(PawnWeaponGenerator)).Field("workingWeapons").GetValue <List <ThingStuffPair> >(); if (pawn.equipment != null && pawn.equipment.Primary != null && pawn.equipment.Primary.def.IsTwoHand()) { return; } if (pawn.equipment == null || pawn.equipment.Primary == null) { return; } for (int i = 0; i < allWeaponPairs.Count; i++) { ThingStuffPair w = allWeaponPairs[i]; if (w.Price <= randomInRange) { if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag))) { Rand.PushState(); if (w.thing.generateAllowChance >= 1f || Rand.ChanceSeeded(w.thing.generateAllowChance, pawn.thingIDNumber ^ (int)w.thing.shortHash ^ 28554824)) { workingWeapons.Add(w); } Rand.PopState(); } } } if (workingWeapons.Count == 0) { return; } IEnumerable <ThingStuffPair> matchingWeapons = workingWeapons.Where((ThingStuffPair tsp) => tsp.thing.CanBeOffHand() && !tsp.thing.IsTwoHand()); if (matchingWeapons != null && matchingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out ThingStuffPair thingStuffPair)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); AddOffHandEquipment(pawn.equipment, thingWithComps); } } }
// Token: 0x0600005A RID: 90 RVA: 0x000045A8 File Offset: 0x000027A8 public static void TryGenerateWeaponFor_Prefix(Pawn pawn) { List <ThingStuffPair> value = Traverse.Create(typeof(PawnWeaponGenerator)).Field("workingWeapons").GetValue <List <ThingStuffPair> >(); List <ThingStuffPair> value2 = Traverse.Create(typeof(PawnWeaponGenerator)).Field("allWeaponPairs").GetValue <List <ThingStuffPair> >(); value.Clear(); bool flag = pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0; if (!flag) { bool flag2 = !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); if (!flag2) { bool flag3 = pawn.story != null && pawn.WorkTagIsDisabled(WorkTags.Violent); if (!flag3) { float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; for (int i = 0; i < value2.Count; i++) { ThingStuffPair w = value2[i]; bool flag4 = w.Price <= randomInRange; if (flag4) { bool flag5 = pawn.kindDef.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag)); if (flag5) { bool flag6 = w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance; if (flag6) { value.Add(w); } } } } bool flag7 = value.Count == 0; if (!flag7) { pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish); ThingStuffPair thingStuffPair; bool flag8 = value.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair); if (flag8) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.equipment.AddEquipment(thingWithComps); } value.Clear(); } } } } }
public static void TryGenerateWeaponFor(Pawn pawn) { PawnWeaponGenerator.workingWeapons.Clear(); if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0) { return; } if (!pawn.RaceProps.ToolUser) { return; } if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { return; } if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { return; } float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; for (int i = 0; i < PawnWeaponGenerator.allWeaponPairs.Count; i++) { ThingStuffPair w = PawnWeaponGenerator.allWeaponPairs[i]; if (w.Price <= randomInRange) { if (pawn.kindDef.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag))) { if (w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance) { PawnWeaponGenerator.workingWeapons.Add(w); } } } } if (PawnWeaponGenerator.workingWeapons.Count == 0) { return; } pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish); ThingStuffPair thingStuffPair; if (PawnWeaponGenerator.workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.equipment.AddEquipment(thingWithComps); } PawnWeaponGenerator.workingWeapons.Clear(); }
private void TryGenerateWeaponWithAmmoFor(Pawn pawn, CompInventory inventory, SidearmOption option) { if (option.weaponTags.NullOrEmpty() || !Rand.Chance(option.generateChance)) { return; } // Generate weapon - mostly based on PawnWeaponGenerator.TryGenerateWeaponFor() // START 1:1 COPY float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; for (int i = 0; i < allWeaponPairs.Count; i++) { ThingStuffPair w = allWeaponPairs[i]; if (w.Price <= randomInRange) { if (option.weaponTags == null || option.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag))) { if (w.thing.generateAllowChance >= 1f || Rand.ChanceSeeded(w.thing.generateAllowChance, pawn.thingIDNumber ^ (int)w.thing.shortHash ^ 28554824)) { workingWeapons.Add(w); } } } } if (workingWeapons.Count == 0) { return; } // END 1:1 COPY // pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish); --removed compared to sourcecode // Some 1:1 COPY below ThingStuffPair thingStuffPair; if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair)) { // Create the actual weapon and put it into inventory ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); LoadWeaponWithRandAmmo(thingWithComps); //Custom int count; //Custom if (inventory.CanFitInInventory(thingWithComps, out count)) //Custom { PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); if (inventory.container.TryAdd(thingWithComps)) //Custom { TryGenerateAmmoFor(thingWithComps, inventory, Mathf.RoundToInt(option.magazineCount.RandomInRange)); //Custom } } } workingWeapons.Clear(); }
static void Postfix(Pawn pawn) { if (pawn.RaceProps.Humanlike && Rand.Chance(((float)Base.NPCDualWieldChance) / 100f)) { float randomInRange = pawn.kindDef.weaponMoney.RandomInRange; List <ThingStuffPair> allWeaponPairs = Traverse.Create(typeof(PawnWeaponGenerator)).Field("allWeaponPairs").GetValue <List <ThingStuffPair> >(); List <ThingStuffPair> workingWeapons = Traverse.Create(typeof(PawnWeaponGenerator)).Field("workingWeapons").GetValue <List <ThingStuffPair> >(); if (pawn.equipment != null && pawn.equipment.Primary != null && pawn.equipment.Primary.def.IsTwoHand()) { return; } if (pawn.equipment == null || pawn.equipment.Primary == null) { return; } for (int i = 0; i < allWeaponPairs.Count; i++) { ThingStuffPair w = allWeaponPairs[i]; if (w.Price <= randomInRange) { if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag))) { if (w.thing.generateAllowChance >= 1f || Rand.ChanceSeeded(w.thing.generateAllowChance, pawn.thingIDNumber ^ (int)w.thing.shortHash ^ 28554824)) { workingWeapons.Add(w); } } } } if (workingWeapons.Count == 0) { return; } ThingStuffPair thingStuffPair; IEnumerable <ThingStuffPair> matchingWeapons = workingWeapons.Where((ThingStuffPair tsp) => tsp.thing.CanBeOffHand() && !tsp.thing.IsTwoHand()); if (matchingWeapons != null && matchingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.equipment.AddOffHandEquipment(thingWithComps); } } }
public static IEnumerator GenerateStartingApparelFor(Zombie zombie) { var possibleApparel = AllApparelPairs().Where(pair => CanWear(zombie, pair)).ToList(); yield return(null); if (possibleApparel.Count > 0) { for (var i = 0; i < Rand.Range(0, 4); i++) { var pair = possibleApparel.RandomElement(); yield return(null); var apparel = (Apparel)ThingMaker.MakeThing(pair.thing, pair.stuff); yield return(null); PawnGenerator.PostProcessGeneratedGear(apparel, zombie); yield return(null); if (ApparelUtility.HasPartsToWear(zombie, apparel.def)) { if (zombie.apparel.WornApparel.All(pa => ApparelUtility.CanWearTogether(pair.thing, pa.def, zombie.RaceProps.body))) { apparel.SetColor(Zombie.zombieColors[Rand.Range(0, Zombie.zombieColors.Length)].SaturationChanged(0.25f)); Graphic_Multi_Init_Patch.suppressError = true; Graphic_Multi_Init_Patch.textureError = false; try { zombie.apparel.Wear(apparel, false); } catch (Exception) { } if (Graphic_Multi_Init_Patch.textureError) { zombie.apparel.Remove(apparel); } Graphic_Multi_Init_Patch.suppressError = false; } } yield return(null); } } }
public override void Generate() { foreach (Pawn pawn in MapInitData.colonists) { Log.Message("generating a tool"); var tool = (Tool)ThingMaker.MakeThing(ThingDef.Named("Tool_LaserTool"), ThingDefOf.Plasteel); PawnGenerator.PostProcessGeneratedGear(tool, pawn); Log.Message("adding to equipment"); pawn.equipment.AddEquipment(tool); var foundtool = pawn.equipment.AllEquipment.First(eq => eq is Tool); if (foundtool == null) { // this happens if the equipment type isn't Primary, in Alpha 9 Log.Error("tool wasn't found in equipment after tool added to equipment"); } } }
private void TryGenerateWeaponWithAmmoFor(Pawn pawn, CompInventory inventory, SidearmOption option) { if (option.weaponTags.NullOrEmpty() || !Rand.Chance(option.generateChance)) { return; } // Generate weapon - mostly based on PawnWeaponGenerator.TryGenerateWeaponFor() float money = option.sidearmMoney.RandomInRange; foreach (ThingStuffPair cur in allWeaponPairs) { if (cur.Price <= money && option.weaponTags.Any(t => cur.thing.weaponTags.Contains(t)) && (cur.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554635) <= cur.thing.generateAllowChance)) { workingWeapons.Add(cur); } } if (workingWeapons.Count == 0) { return; } ThingStuffPair pair; if (workingWeapons.TryRandomElementByWeight(p => p.Commonality * p.Price, out pair)) { // Create the actual weapon and put it into inventory var eq = (ThingWithComps)ThingMaker.MakeThing(pair.thing, pair.stuff); LoadWeaponWithRandAmmo(eq); int count; if (inventory.CanFitInInventory(eq, out count)) { PawnGenerator.PostProcessGeneratedGear(eq, pawn); if (inventory.container.TryAdd(eq)) { TryGenerateAmmoFor(eq, inventory, Mathf.RoundToInt(option.magazineCount.RandomInRange)); } } } workingWeapons.Clear(); }
public void AddApparel(Pawn targetPawn, int layer) { if (acceptedApparel[layer] != null) { Apparel a; if (selectedApparel[layer].MadeFromStuff) { a = (Apparel)ThingMaker.MakeThing(selectedApparel[layer], selectedStuff[layer]); a.DrawColor = colors[layer] * GetStuffColor(layer); } else { a = (Apparel)ThingMaker.MakeThing(selectedApparel[layer], null); a.DrawColor = colors[layer]; } PawnGenerator.PostProcessGeneratedGear(a, targetPawn); if (ApparelUtility.HasPartsToWear(targetPawn, a.def)) { targetPawn.apparel.Wear(a, false); } } }
public static void GenerateAdditionalAmmo(Pawn p, PawnGenerationRequest request) { foreach (var thingDefCountRange in from comp in p.AllReloadComps() let gen = comp.GenerateAmmo where gen != null from tdcr in gen select tdcr) { } foreach (var reloadable in p.AllReloadComps()) { if (reloadable.GenerateAmmo != null) { foreach (var thingDefCountRange in reloadable.GenerateAmmo) { var ammo = ThingMaker.MakeThing(thingDefCountRange.thingDef); ammo.stackCount = thingDefCountRange.countRange.RandomInRange; p.inventory?.innerContainer.TryAdd(ammo); } } if (reloadable.GenerateBackupWeapon) { var weaponPairs = Traverse.Create(typeof(PawnWeaponGenerator)).Field("allWeaponPairs").GetValue <List <ThingStuffPair> >().Where(w => !w.thing.IsRangedWeapon || !p.WorkTagIsDisabled(WorkTags.Shooting)); if (p.kindDef.weaponMoney.Span > 0f) { var money = p.kindDef.weaponMoney.RandomInRange / 5f; weaponPairs = weaponPairs.Where(w => w.Price <= money); } if (p.kindDef.weaponStuffOverride != null) { weaponPairs = weaponPairs.Where(w => w.stuff == p.kindDef.weaponStuffOverride); } weaponPairs = weaponPairs.Where(w => w.thing.weaponClasses == null || w.thing.weaponClasses.Contains(ReloadingDefOf.RangedLight) && w.thing.weaponClasses.Contains(ReloadingDefOf.ShortShots) || w.thing.weaponTags.Contains("MedievalMeleeBasic") || w.thing.weaponTags.Contains("SimpleGun")); if (weaponPairs.TryRandomElementByWeight(w => w.Price * w.Commonality, out var weaponPair)) { var weapon = (ThingWithComps)ThingMaker.MakeThing(weaponPair.thing, weaponPair.stuff); PawnGenerator.PostProcessGeneratedGear(weapon, p); var num = request.BiocodeWeaponChance > 0f ? request.BiocodeWeaponChance : p.kindDef.biocodeWeaponChance; if (Rand.Chance(num)) { weapon.TryGetComp <CompBiocodable>()?.CodeFor(p); } var compEquippable = weapon.TryGetComp <CompEquippable>(); if (compEquippable != null) { if (p.kindDef.weaponStyleDef != null) { compEquippable.parent.StyleDef = p.kindDef.weaponStyleDef; } else if (p.Ideo != null) { compEquippable.parent.StyleDef = p.Ideo.GetStyleFor(weapon.def); } } p.inventory?.innerContainer.TryAdd(weapon, false); } } } }
//static PawnShieldGenerator() //{ // //Initialise all shields. // Reset(); //} /// <summary> /// Tries to generate a shield for the pawn. /// </summary> /// <param name="pawn"></param> /// <param name="request"></param> public static void TryGenerateShieldFor(Pawn pawn, PawnGenerationRequest request) { workingShields.Clear(); // Same conditions as weapon generation, except using PawnKindDef ShieldPawnGeneratorProperties.shieldTags instead of pawn.kindDef.weaponTags var generatorProps = request.KindDef.GetShieldPawnGeneratorProperties(); if (generatorProps == null || generatorProps.shieldTags.NullOrEmpty()) { return; } if (!pawn.RaceProps.ToolUser || !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || pawn.WorkTagIsDisabled(WorkTags.Violent)) { return; } var generatorPropsShieldMoney = generatorProps.shieldMoney; var randomInRange = generatorPropsShieldMoney.RandomInRange; foreach (var w in allShieldPairs) { if (w.Price <= randomInRange && !w.thing.weaponTags.NullOrEmpty() && generatorProps.shieldTags.Any(tag => w.thing.weaponTags.Contains(tag)) && (!w.thing.IsRangedWeapon || !pawn.WorkTagIsDisabled(WorkTags.Shooting)) && (w.thing.generateAllowChance >= 1f || Rand.ChanceSeeded(w.thing.generateAllowChance, pawn.thingIDNumber ^ w.thing.shortHash ^ 0x1B3B648))) { workingShields.Add(w); } } if (workingShields.Count == 0) { //Log.Warning("No working shields found for " + pawn.Label + "::" + pawn.KindLabel); return; } if (workingShields.TryRandomElementByWeight(w => w.Commonality * w.Price * GetWeaponCommonalityFromIdeo(pawn, w), out var thingStuffPair)) { var thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); var compEquippable = thingWithComps.GetCompShield(); if (compEquippable != null) { if (pawn.Ideo != null) { compEquippable.parent.StyleDef = pawn.Ideo.GetStyleFor(thingWithComps.def); } } var biocodeWeaponChance = (request.BiocodeWeaponChance > 0f) ? request.BiocodeWeaponChance : pawn.kindDef.biocodeWeaponChance; if (Rand.Value < biocodeWeaponChance) { BiocodeForPawn(pawn, thingWithComps); } pawn.equipment.AddEquipment(thingWithComps); } workingShields.Clear(); }
//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); } }
public static void PawnFinaliser(Pawn pawn) { int meleeSkill = pawn.skills.GetSkill(skillDef: Defs_Rimworld.MeleeSkill).Level; if (meleeSkill < 10) { pawn.skills.GetSkill(skillDef: Defs_Rimworld.MeleeSkill).Level += Rand.RangeInclusive(min: 10 - meleeSkill, max: 10 - meleeSkill + 5); } float[] choiceArray = { 10 - NVGameComponent.Evilness, 5 + NVGameComponent.Evilness, 5 + NVGameComponent.Evilness }; var indexes = new[] { 0, 1, 2 }; int choice = indexes.RandomElementByWeight(weightSelector: ind => choiceArray[ind]); switch (choice) { case 1: if (PawnGenUtility.AnyPSHediffsExist.IsNotFalse()) { foreach (BodyPartRecord bodyPartRecord in pawn.RaceProps.body.GetPartsWithTag(tag: Defs_Rimworld.EyeTag)) { HediffDef hediff = PawnGenUtility.GetRandomPhotosensitiveHediffDef(); if (hediff != null) { pawn.health.AddHediff(def: hediff, part: bodyPartRecord); } } if (ApparelGenUtility.GetNullPSApparelDefByTag(tagsList: pawn.kindDef.apparelTags) is ThingDef appDef) { if (ApparelUtility.HasPartsToWear(p: pawn, apparel: appDef)) { Thing apparel = ThingMaker.MakeThing( def: appDef, stuff: appDef.MadeFromStuff ? GenStuff.RandomStuffByCommonalityFor(td: appDef) : null ); pawn.apparel.Wear(newApparel: (Apparel)apparel, dropReplacedApparel: false); } } break; } else { goto case 2; } case 2: if (ApparelGenUtility.GetGiveNVApparelDefByTag(tagsList: pawn.kindDef.apparelTags) is ThingDef nvAppDef) { if (ApparelUtility.HasPartsToWear(p: pawn, apparel: nvAppDef)) { Thing apparel = ThingMaker.MakeThing( def: nvAppDef, stuff: nvAppDef.MadeFromStuff ? GenStuff.RandomStuffByCommonalityFor(td: nvAppDef) : null ); PawnGenerator.PostProcessGeneratedGear(apparel, pawn); pawn.apparel.Wear(newApparel: (Apparel)apparel, dropReplacedApparel: false); } } break; } if (Rand.Chance(chance: NVGameComponent.Evilness / 8f)) { ThingDef shield = Defs_Rimworld.ShieldDef; if (ApparelUtility.HasPartsToWear(p: pawn, apparel: shield)) { Thing shieldBelt = ThingMaker.MakeThing(def: shield, stuff: shield.MadeFromStuff ? GenStuff.RandomStuffFor(td: shield) : null); PawnGenerator.PostProcessGeneratedGear(shieldBelt, pawn); pawn.apparel.Wear(newApparel: (Apparel)shieldBelt, dropReplacedApparel: false); } } }
/*static PawnShieldGenerator() * { * //Initialise all shields. * Reset(); * }*/ /// <summary> /// Tries to generate a shield for the pawn. /// </summary> /// <param name="pawn"></param> /// <param name="request"></param> public static void TryGenerateShieldFor(Pawn pawn, PawnGenerationRequest request) { //Shield stuff. ShieldPawnGeneratorProperties generatorProps = request.KindDef?.GetModExtension <ShieldPawnGeneratorProperties>(); //Abort early if there is no mention at all of shield properties. if (generatorProps == null) { return; } workingShields = new List <ThingStuffPair>(); //Initial filtering if (generatorProps.shieldTags == null || generatorProps.shieldTags?.Count == 0) { Log.Warning("PawnShields :: XML element shieldTags is null or empty for " + request.KindDef.defName); return; } if (!(pawn?.RaceProps?.ToolUser ?? false)) { Log.Warning("PawnShields :: " + request.KindDef.defName + " is not a ToolUser or Humanlike in RaceProps."); return; } if (!(pawn.health?.capacities?.CapableOf(PawnCapacityDefOf.Manipulation) ?? false)) { Log.Warning("PawnShields :: " + request.KindDef.defName + " is not capable of manipulation."); return; } if (pawn.story != null && ((bool)pawn.story?.WorkTagIsDisabled(WorkTags.Violent))) { return; } var generatorPropsShieldMoney = generatorProps.shieldMoney; float randomInRange = generatorPropsShieldMoney.RandomInRange; if (allShieldPairs != null && allShieldPairs?.Count > 0) { foreach (var w in allShieldPairs) { if (w.Price <= randomInRange) { if (!w.thing.weaponTags.NullOrEmpty()) { if (generatorProps.shieldTags.Any(tag => (w.thing.weaponTags.Contains(tag)))) { if (w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance) { workingShields.Add(w); } } } } } } if (workingShields == null || workingShields?.Count == 0) { Log.Warning("No working shields found for " + pawn.Label + "::" + pawn.KindLabel); return; } if (workingShields.TryRandomElementByWeight(w => w.Commonality * w.Price, out var thingStuffPair)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.equipment?.AddEquipment(thingWithComps); //Log.Message(pawn.Label + " added shield " + thingWithComps.Label); } }
public static void TryGenerateShieldFor(Pawn pawn) { workingShields.Clear(); var kindDefExtension = PawnKindDefExtension.Get(pawn.kindDef); // No shieldTags if (kindDefExtension.shieldTags.NullOrEmpty()) { return; } // Not a tool user if (!pawn.RaceProps.ToolUser) { return; } // Primary unusable with shields if (pawn.equipment.Primary is ThingWithComps primary && !primary.def.UsableWithShields()) { return; } // Has multiple weapons if (pawn.equipment.AllEquipmentListForReading.Count(t => t.def.equipmentType == EquipmentType.Primary) > 1) { return; } // Not enough manipulation if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) || !pawn.CanUseShields()) { return; } // Pacifist if (pawn.story != null && pawn.WorkTagIsDisabled(WorkTags.Violent)) { return; } float randomInRange = kindDefExtension.shieldMoney.RandomInRange; for (int i = 0; i < allShieldPairs.Count; i++) { ThingStuffPair w = allShieldPairs[i]; if (w.Price <= randomInRange) { var shieldProps = w.thing.GetCompProperties <CompProperties_Shield>(); if (kindDefExtension.shieldTags == null || kindDefExtension.shieldTags.Any((string tag) => shieldProps.shieldTags.Contains(tag))) { if (w.thing.generateAllowChance >= 1f || Rand.ChanceSeeded(w.thing.generateAllowChance, pawn.thingIDNumber ^ (int)w.thing.shortHash ^ 28554824)) { workingShields.Add(w); } } } } if (workingShields.Count == 0) { return; } //pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish); ThingStuffPair thingStuffPair; if (workingShields.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair)) { var shield = (Apparel)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(shield, pawn); // Colour the shield if (pawn.Faction != null) { var thingDefExtension = ThingDefExtension.Get(thingStuffPair.thing); if (!thingDefExtension.useFactionColourForPawnKinds.NullOrEmpty() && thingDefExtension.useFactionColourForPawnKinds.Contains(pawn.kindDef)) { shield.SetColor(pawn.Faction.Color); } } pawn.AddShield(shield); } workingShields.Clear(); }
public static void TryGenerateSidearmsFor(Pawn pawn) { if (SimpleSidearms.SidearmSpawnChance.Value < 0.01f) { return; } if (!hasBeenReset) { Reset(); } if (Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) >= SimpleSidearms.SidearmSpawnChance.Value) { return; } if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0) { return; } if (!pawn.RaceProps.ToolUser) { return; } if (!pawn.RaceProps.Humanlike) { return; } if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { return; } if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { return; } if (pawn.equipment.Primary == null) { return; } bool meleeOnly = pawn.equipment.Primary.def.IsMeleeWeapon || (pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler)); bool neolithic = true; foreach (string wepTag in pawn.kindDef.weaponTags) { if (wepTag.Contains("Neolithic")) { neolithic = false; break; } } List <string> sidearmTags = GettersFilters.weaponTagsToSidearmTags(pawn.kindDef.weaponTags); float money = pawn.kindDef.weaponMoney.min; money /= 5f; for (int i = 0; i < allWeaponPairs.Count; i++) { ThingStuffPair w = allWeaponPairs[i]; if (!StatCalculator.canCarrySidearm(w.thing, pawn)) { continue; } if (w.Price > money) { continue; } if (meleeOnly && w.thing.IsRangedWeapon) { continue; } if (neolithic) { bool isNeolithic = true; #region nestedMonstrosity foreach (string wepTag in pawn.kindDef.weaponTags) { if (!wepTag.Contains("Neolithic")) { //check if the weapon is allowed despite not being neolithic bool getsAPass = false; foreach (string weapon in SimpleSidearms.SidearmsNeolithicExtension.Value.InnerList) { if (weapon.Equals(w.thing.defName)) { getsAPass = true; break; } } if (!getsAPass) { isNeolithic = false; } } if (!isNeolithic) { break; } } #endregion if (!isNeolithic) { continue; } } if (sidearmTags.Any((string tag) => w.thing.weaponTags.Contains(tag))) { if (w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance) { workingWeapons.Add(w); } } } if (workingWeapons.Count == 0) { return; } ThingStuffPair thingStuffPair; if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price / w.thing.BaseMass, out thingStuffPair)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.inventory.innerContainer.TryAdd(thingWithComps); //pawn.equipment.AddEquipment(thingWithComps); } workingWeapons.Clear(); }
/*static PawnShieldGenerator() * { * //Initialise all shields. * Reset(); * }*/ /// <summary> /// Tries to generate a shield for the pawn. /// </summary> /// <param name="pawn"></param> /// <param name="request"></param> public static void TryGenerateShieldFor(Pawn pawn, PawnGenerationRequest request) { //Shield stuff. ShieldPawnGeneratorProperties generatorProps = request.KindDef.GetModExtension <ShieldPawnGeneratorProperties>(); //Abort early if there is no mention at all of shield properties. if (generatorProps == null) { return; } workingShields.Clear(); //Initial filtering if (generatorProps.shieldTags == null || generatorProps.shieldTags.Count == 0) { return; } if (!pawn.RaceProps.ToolUser) { return; } if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { return; } if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) { return; } float randomInRange = generatorProps.shieldMoney.RandomInRange; for (int i = 0; i < allShieldPairs.Count; i++) { ThingStuffPair w = allShieldPairs[i]; if (w.Price <= randomInRange) { if (generatorProps.shieldTags.Any(tag => w.thing.weaponTags.Contains(tag))) { if (w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance) { workingShields.Add(w); } } } } if (workingShields.Count == 0) { return; } ThingStuffPair thingStuffPair; if (workingShields.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair)) { ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff); PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn); pawn.equipment.AddEquipment(thingWithComps); } workingShields.Clear(); }