/*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); } }
/*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(); }