public float Ingested(Pawn ingester, float nutritionWanted) { if (this.Destroyed) { Log.Error(ingester + " ingested destroyed thing " + this, false); return(0f); } if (!this.IngestibleNow) { Log.Error(ingester + " ingested IngestibleNow=false thing " + this, false); return(0f); } ingester.mindState.lastIngestTick = Find.TickManager.TicksGame; if (this.def.ingestible.outcomeDoers != null) { for (int i = 0; i < this.def.ingestible.outcomeDoers.Count; i++) { this.def.ingestible.outcomeDoers[i].DoIngestionOutcome(ingester, this); } } if (ingester.needs.mood != null) { List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(ingester, this, this.def); for (int j = 0; j < list.Count; j++) { ingester.needs.mood.thoughts.memories.TryGainMemory(list[j], null); } } if (ingester.IsColonist && FoodUtility.IsHumanlikeMeatOrHumanlikeCorpse(this)) { TaleRecorder.RecordTale(TaleDefOf.AteRawHumanlikeMeat, new object[] { ingester }); } int num; float result; this.IngestedCalculateAmounts(ingester, nutritionWanted, out num, out result); if (!ingester.Dead && ingester.needs.joy != null && Mathf.Abs(this.def.ingestible.joy) > 0.0001f && num > 0) { JoyKindDef joyKind = (this.def.ingestible.joyKind == null) ? JoyKindDefOf.Gluttonous : this.def.ingestible.joyKind; ingester.needs.joy.GainJoy((float)num * this.def.ingestible.joy, joyKind); } if (ingester.RaceProps.Humanlike && Rand.Chance(this.GetStatValue(StatDefOf.FoodPoisonChanceFixedHuman, true) * Find.Storyteller.difficulty.foodPoisonChanceFactor)) { FoodUtility.AddFoodPoisoningHediff(ingester, this, FoodPoisonCause.DangerousFoodType); } if (num > 0) { if (num == this.stackCount) { this.Destroy(DestroyMode.Vanish); } else { this.SplitOff(num); } } this.PostIngested(ingester); return(result); }
private void ImpactSomething() { if (def.projectile.flyOverhead) { RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position); if (roofDef != null) { if (roofDef.isThickRoof) { ThrowDebugText("hit-thick-roof", base.Position); def.projectile.soundHitThickRoof.PlayOneShot(new TargetInfo(base.Position, base.Map)); Destroy(); return; } if (base.Position.GetEdifice(base.Map) == null || base.Position.GetEdifice(base.Map).def.Fillage != FillCategory.Full) { RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map); } } } if (usedTarget.HasThing && CanHit(usedTarget.Thing)) { Pawn pawn = usedTarget.Thing as Pawn; if (pawn != null && pawn.GetPosture() != 0 && (origin - destination).MagnitudeHorizontalSquared() >= 20.25f && !Rand.Chance(0.2f)) { ThrowDebugText("miss-laying", base.Position); Impact(null); } else { Impact(usedTarget.Thing); } return; } cellThingsFiltered.Clear(); List <Thing> thingList = base.Position.GetThingList(base.Map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if ((thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && CanHit(thing)) { cellThingsFiltered.Add(thing); } } cellThingsFiltered.Shuffle(); for (int j = 0; j < cellThingsFiltered.Count; j++) { Thing thing2 = cellThingsFiltered[j]; Pawn pawn2 = thing2 as Pawn; float num; if (pawn2 != null) { num = 0.5f * Mathf.Clamp(pawn2.BodySize, 0.1f, 2f); if (pawn2.GetPosture() != 0 && (origin - destination).MagnitudeHorizontalSquared() >= 20.25f) { num *= 0.2f; } if (launcher != null && pawn2.Faction != null && launcher.Faction != null && !pawn2.Faction.HostileTo(launcher.Faction)) { num *= VerbUtility.InterceptChanceFactorFromDistance(origin, base.Position); } } else { num = 1.5f * thing2.def.fillPercent; } if (Rand.Chance(num)) { ThrowDebugText("hit-" + num.ToStringPercent(), base.Position); Impact(cellThingsFiltered.RandomElement()); return; } ThrowDebugText("miss-" + num.ToStringPercent(), base.Position); } Impact(null); }
protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result) { bool flag = Rand.Chance(this.def.bluntInnerHitChance); float num = (!flag) ? 0f : this.def.bluntInnerHitDamageFractionToConvert.RandomInRange; float num2 = totalDamage * (1f - num); DamageInfo lastInfo = dinfo; for (;;) { num2 -= base.FinalizeAndAddInjury(pawn, num2, lastInfo, result); if (!pawn.health.hediffSet.PartIsMissing(lastInfo.HitPart)) { break; } if (num2 <= 1f) { break; } BodyPartRecord parent = lastInfo.HitPart.parent; if (parent == null) { break; } lastInfo.SetHitPart(parent); } if (flag && !lastInfo.HitPart.def.IsSolid(lastInfo.HitPart, pawn.health.hediffSet.hediffs) && lastInfo.HitPart.depth == BodyPartDepth.Outside) { IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null) where x.parent == lastInfo.HitPart && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside select x; BodyPartRecord hitPart; if (source.TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out hitPart)) { DamageInfo lastInfo2 = lastInfo; lastInfo2.SetHitPart(hitPart); float totalDamage2 = totalDamage * num + totalDamage * this.def.bluntInnerHitDamageFractionToAdd.RandomInRange; base.FinalizeAndAddInjury(pawn, totalDamage2, lastInfo2, result); } } if (!pawn.Dead) { SimpleCurve simpleCurve = null; if (lastInfo.HitPart.parent == null) { simpleCurve = this.def.bluntStunChancePerDamagePctOfCorePartToBodyCurve; } else { foreach (BodyPartRecord lhs in pawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource)) { if (this.InSameBranch(lhs, lastInfo.HitPart)) { simpleCurve = this.def.bluntStunChancePerDamagePctOfCorePartToHeadCurve; break; } } } if (simpleCurve != null) { float x2 = totalDamage / pawn.def.race.body.corePart.def.GetMaxHealth(pawn); if (Rand.Chance(simpleCurve.Evaluate(x2))) { DamageInfo dinfo2 = dinfo; dinfo2.Def = DamageDefOf.Stun; dinfo2.SetAmount((float)this.def.bluntStunDuration.SecondsToTicks() / 30f); pawn.TakeDamage(dinfo2); } } } }
public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver) { float efficiency = ((recipeDef.efficiencyStat != null) ? worker.GetStatValue(recipeDef.efficiencyStat) : 1f); if (recipeDef.workTableEfficiencyStat != null) { Building_WorkTable building_WorkTable = billGiver as Building_WorkTable; if (building_WorkTable != null) { efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat); } } if (recipeDef.products != null) { for (int j = 0; j < recipeDef.products.Count; j++) { ThingDefCountClass thingDefCountClass = recipeDef.products[j]; Thing thing = ThingMaker.MakeThing(stuff: (!thingDefCountClass.thingDef.MadeFromStuff) ? null : dominantIngredient.def, def: thingDefCountClass.thingDef); thing.stackCount = Mathf.CeilToInt((float)thingDefCountClass.count * efficiency); if (dominantIngredient != null && recipeDef.useIngredientsForColor) { thing.SetColor(dominantIngredient.DrawColor, reportFailure: false); } CompIngredients compIngredients = thing.TryGetComp <CompIngredients>(); if (compIngredients != null) { for (int l = 0; l < ingredients.Count; l++) { compIngredients.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable compFoodPoisonable = thing.TryGetComp <CompFoodPoisonable>(); if (compFoodPoisonable != null) { if (Rand.Chance(worker.GetRoom()?.GetStat(RoomStatDefOf.FoodPoisonChance) ?? RoomStatDefOf.FoodPoisonChance.roomlessScore)) { compFoodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else if (Rand.Chance(worker.GetStatValue(StatDefOf.FoodPoisonChance))) { compFoodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } yield return(PostProcessProduct(thing, recipeDef, worker)); } } if (recipeDef.specialProducts == null) { yield break; } for (int j = 0; j < recipeDef.specialProducts.Count; j++) { for (int k = 0; k < ingredients.Count; k++) { Thing thing2 = ingredients[k]; switch (recipeDef.specialProducts[j]) { case SpecialProductType.Butchery: foreach (Thing item in thing2.ButcherProducts(worker, efficiency)) { yield return(PostProcessProduct(item, recipeDef, worker)); } break; case SpecialProductType.Smelted: foreach (Thing item2 in thing2.SmeltProducts(efficiency)) { yield return(PostProcessProduct(item2, recipeDef, worker)); } break; } } } }
private bool CheckForFreeIntercept(IntVec3 c) { if (destination.ToIntVec3() == c) { return(false); } float num = VerbUtility.InterceptChanceFactorFromDistance(origin, c); if (num <= 0f) { return(false); } bool flag = false; List <Thing> thingList = c.GetThingList(base.Map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (!CanHit(thing)) { continue; } bool flag2 = false; if (thing.def.Fillage == FillCategory.Full) { Building_Door building_Door = thing as Building_Door; if (building_Door == null || !building_Door.Open) { ThrowDebugText("int-wall", c); Impact(thing); return(true); } flag2 = true; } float num2 = 0f; Pawn pawn = thing as Pawn; if (pawn != null) { num2 = 0.4f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f); if (pawn.GetPosture() != 0) { num2 *= 0.1f; } if (launcher != null && pawn.Faction != null && launcher.Faction != null && !pawn.Faction.HostileTo(launcher.Faction)) { num2 *= 0.4f; } } else if (thing.def.fillPercent > 0.2f) { num2 = (flag2 ? 0.05f : ((!DestinationCell.AdjacentTo8Way(c)) ? (thing.def.fillPercent * 0.15f) : (thing.def.fillPercent * 1f))); } num2 *= num; if (num2 > 1E-05f) { if (Rand.Chance(num2)) { ThrowDebugText("int-" + num2.ToStringPercent(), c); Impact(thing); return(true); } flag = true; ThrowDebugText(num2.ToStringPercent(), c); } } if (!flag) { ThrowDebugText("o", c); } return(false); }
public static void FlavorfulCombatTest() { List <DebugMenuOption> list = new List <DebugMenuOption>(); IEnumerable <ManeuverDef> maneuvers = DefDatabase <ManeuverDef> .AllDefsListForReading; Func <ManeuverDef, RulePackDef>[] results = new Func <ManeuverDef, RulePackDef>[5] { (ManeuverDef m) => new RulePackDef[4] { m.combatLogRulesHit, m.combatLogRulesDeflect, m.combatLogRulesMiss, m.combatLogRulesDodge }.RandomElement(), (ManeuverDef m) => m.combatLogRulesHit, (ManeuverDef m) => m.combatLogRulesDeflect, (ManeuverDef m) => m.combatLogRulesMiss, (ManeuverDef m) => m.combatLogRulesDodge }; string[] array = new string[5] { "(random)", "Hit", "Deflect", "Miss", "Dodge" }; foreach (Pair <ManeuverDef, int> maneuverresult in maneuvers.Concat(null).Cross(Enumerable.Range(0, array.Length))) { DebugMenuOption item = new DebugMenuOption(string.Format("{0}/{1}", (maneuverresult.First == null) ? "(random)" : maneuverresult.First.defName, array[maneuverresult.Second]), DebugMenuOptionMode.Action, delegate { CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator) { StringBuilder stringBuilder7 = new StringBuilder(); ManeuverDef maneuver = default(ManeuverDef); for (int num3 = 0; num3 < 100; num3++) { maneuver = maneuverresult.First; if (maneuver == null) { maneuver = maneuvers.RandomElement(); } RulePackDef rulePackDef = results[maneuverresult.Second](maneuver); List <BodyPartRecord> list8 = null; List <bool> list9 = null; if (rulePackDef == maneuver.combatLogRulesHit) { list8 = new List <BodyPartRecord>(); list9 = new List <bool>(); bodyPartCreator(list8, list9); } ImplementOwnerTypeDef implementOwnerTypeDef; string toolLabel; if (!(from ttp in DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsMeleeWeapon && !td.tools.NullOrEmpty()).SelectMany((ThingDef td) => td.tools.Select((Tool tool) => new Pair <ThingDef, Tool>(td, tool))) where ttp.Second.capacities.Contains(maneuver.requiredCapacity) select ttp).TryRandomElement(out Pair <ThingDef, Tool> result)) { Log.Warning("Melee weapon with tool with capacity " + maneuver.requiredCapacity + " not found."); implementOwnerTypeDef = ImplementOwnerTypeDefOf.Bodypart; toolLabel = "(" + implementOwnerTypeDef.defName + ")"; } else { implementOwnerTypeDef = ((result.Second == null) ? ImplementOwnerTypeDefOf.Bodypart : ImplementOwnerTypeDefOf.Weapon); toolLabel = ((result.Second != null) ? result.Second.label : ("(" + implementOwnerTypeDef.defName + ")")); } BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = new BattleLogEntry_MeleeCombat(rulePackDef, alwaysShowInCompact: false, RandomPawnForCombat(), RandomPawnForCombat(), implementOwnerTypeDef, toolLabel, result.First); battleLogEntry_MeleeCombat.FillTargets(list8, list9, battleLogEntry_MeleeCombat.RuleDef.defName.Contains("Deflect")); battleLogEntry_MeleeCombat.Debug_OverrideTicks(Rand.Int); stringBuilder7.AppendLine(battleLogEntry_MeleeCombat.ToGameStringFromPOV(null)); } Log.Message(stringBuilder7.ToString()); }); }); list.Add(item); } int rf = 0; while (rf < 2) { list.Add(new DebugMenuOption((rf == 0) ? "Ranged fire singleshot" : "Ranged fire burst", DebugMenuOptionMode.Action, delegate { StringBuilder stringBuilder6 = new StringBuilder(); for (int num2 = 0; num2 < 100; num2++) { ThingDef thingDef = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement(); bool flag = Rand.Value < 0.2f; bool flag2 = !flag && Rand.Value < 0.95f; BattleLogEntry_RangedFire battleLogEntry_RangedFire = new BattleLogEntry_RangedFire(RandomPawnForCombat(), flag ? null : RandomPawnForCombat(), flag2 ? null : thingDef, null, rf != 0); battleLogEntry_RangedFire.Debug_OverrideTicks(Rand.Int); stringBuilder6.AppendLine(battleLogEntry_RangedFire.ToGameStringFromPOV(null)); } Log.Message(stringBuilder6.ToString()); })); int num = ++rf; } list.Add(new DebugMenuOption("Ranged impact hit", DebugMenuOptionMode.Action, delegate { CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator) { StringBuilder stringBuilder5 = new StringBuilder(); for (int n = 0; n < 100; n++) { ThingDef weaponDef3 = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement(); List <BodyPartRecord> list6 = new List <BodyPartRecord>(); List <bool> list7 = new List <bool>(); bodyPartCreator(list6, list7); Pawn pawn2 = RandomPawnForCombat(); BattleLogEntry_RangedImpact battleLogEntry_RangedImpact3 = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), pawn2, pawn2, weaponDef3, null, ThingDefOf.Wall); battleLogEntry_RangedImpact3.FillTargets(list6, list7, Rand.Chance(0.5f)); battleLogEntry_RangedImpact3.Debug_OverrideTicks(Rand.Int); stringBuilder5.AppendLine(battleLogEntry_RangedImpact3.ToGameStringFromPOV(null)); } Log.Message(stringBuilder5.ToString()); }); })); list.Add(new DebugMenuOption("Ranged impact miss", DebugMenuOptionMode.Action, delegate { StringBuilder stringBuilder4 = new StringBuilder(); for (int l = 0; l < 100; l++) { ThingDef weaponDef2 = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement(); BattleLogEntry_RangedImpact battleLogEntry_RangedImpact2 = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), null, RandomPawnForCombat(), weaponDef2, null, ThingDefOf.Wall); battleLogEntry_RangedImpact2.Debug_OverrideTicks(Rand.Int); stringBuilder4.AppendLine(battleLogEntry_RangedImpact2.ToGameStringFromPOV(null)); } Log.Message(stringBuilder4.ToString()); })); list.Add(new DebugMenuOption("Ranged impact hit incorrect", DebugMenuOptionMode.Action, delegate { CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator) { StringBuilder stringBuilder3 = new StringBuilder(); for (int k = 0; k < 100; k++) { ThingDef weaponDef = DefDatabase <ThingDef> .AllDefsListForReading.Where((ThingDef td) => td.IsRangedWeapon && td.IsWeaponUsingProjectiles && !td.menuHidden).RandomElement(); List <BodyPartRecord> list4 = new List <BodyPartRecord>(); List <bool> list5 = new List <bool>(); bodyPartCreator(list4, list5); BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(RandomPawnForCombat(), RandomPawnForCombat(), RandomPawnForCombat(), weaponDef, null, ThingDefOf.Wall); battleLogEntry_RangedImpact.FillTargets(list4, list5, Rand.Chance(0.5f)); battleLogEntry_RangedImpact.Debug_OverrideTicks(Rand.Int); stringBuilder3.AppendLine(battleLogEntry_RangedImpact.ToGameStringFromPOV(null)); } Log.Message(stringBuilder3.ToString()); }); })); foreach (RulePackDef transition in DefDatabase <RulePackDef> .AllDefsListForReading.Where((RulePackDef def) => def.defName.Contains("Transition") && !def.defName.Contains("Include"))) { list.Add(new DebugMenuOption(transition.defName, DebugMenuOptionMode.Action, delegate { StringBuilder stringBuilder2 = new StringBuilder(); for (int j = 0; j < 100; j++) { Pawn pawn = RandomPawnForCombat(); Pawn initiator = RandomPawnForCombat(); BodyPartRecord partRecord = pawn.health.hediffSet.GetNotMissingParts().RandomElement(); BattleLogEntry_StateTransition battleLogEntry_StateTransition = new BattleLogEntry_StateTransition(pawn, transition, initiator, HediffMaker.MakeHediff(DefDatabase <HediffDef> .AllDefsListForReading.RandomElement(), pawn, partRecord), pawn.RaceProps.body.AllParts.RandomElement()); battleLogEntry_StateTransition.Debug_OverrideTicks(Rand.Int); stringBuilder2.AppendLine(battleLogEntry_StateTransition.ToGameStringFromPOV(null)); } Log.Message(stringBuilder2.ToString()); })); } foreach (RulePackDef damageEvent in DefDatabase <RulePackDef> .AllDefsListForReading.Where((RulePackDef def) => def.defName.Contains("DamageEvent") && !def.defName.Contains("Include"))) { list.Add(new DebugMenuOption(damageEvent.defName, DebugMenuOptionMode.Action, delegate { CreateDamagedDestroyedMenu(delegate(Action <List <BodyPartRecord>, List <bool> > bodyPartCreator) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < 100; i++) { List <BodyPartRecord> list2 = new List <BodyPartRecord>(); List <bool> list3 = new List <bool>(); bodyPartCreator(list2, list3); BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(RandomPawnForCombat(), damageEvent); battleLogEntry_DamageTaken.FillTargets(list2, list3, deflected: false); battleLogEntry_DamageTaken.Debug_OverrideTicks(Rand.Int); stringBuilder.AppendLine(battleLogEntry_DamageTaken.ToGameStringFromPOV(null)); } Log.Message(stringBuilder.ToString()); }); })); } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list)); }
protected override void ApplySpecialEffectsToPart(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageResult result) { bool flag = Rand.Chance(def.bluntInnerHitChance); float num = (flag ? def.bluntInnerHitDamageFractionToConvert.RandomInRange : 0f); float num2 = totalDamage * (1f - num); DamageInfo lastInfo = dinfo; while (true) { num2 -= FinalizeAndAddInjury(pawn, num2, lastInfo, result); if (!pawn.health.hediffSet.PartIsMissing(lastInfo.HitPart) || num2 <= 1f) { break; } BodyPartRecord parent = lastInfo.HitPart.parent; if (parent == null) { break; } lastInfo.SetHitPart(parent); } if (flag && !lastInfo.HitPart.def.IsSolid(lastInfo.HitPart, pawn.health.hediffSet.hediffs) && lastInfo.HitPart.depth == BodyPartDepth.Outside && (from x in pawn.health.hediffSet.GetNotMissingParts() where x.parent == lastInfo.HitPart && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside select x).TryRandomElementByWeight((BodyPartRecord x) => x.coverageAbs, out var result2)) { DamageInfo dinfo2 = lastInfo; dinfo2.SetHitPart(result2); float totalDamage2 = totalDamage * num + totalDamage * def.bluntInnerHitDamageFractionToAdd.RandomInRange; FinalizeAndAddInjury(pawn, totalDamage2, dinfo2, result); } if (pawn.Dead) { return; } SimpleCurve simpleCurve = null; if (lastInfo.HitPart.parent == null) { simpleCurve = def.bluntStunChancePerDamagePctOfCorePartToBodyCurve; } else { foreach (BodyPartRecord item in pawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.ConsciousnessSource)) { if (InSameBranch(item, lastInfo.HitPart)) { simpleCurve = def.bluntStunChancePerDamagePctOfCorePartToHeadCurve; break; } } } if (simpleCurve != null) { float x2 = totalDamage / pawn.def.race.body.corePart.def.GetMaxHealth(pawn); if (Rand.Chance(simpleCurve.Evaluate(x2))) { DamageInfo dinfo3 = dinfo; dinfo3.Def = DamageDefOf.Stun; dinfo3.SetAmount((float)def.bluntStunDuration.SecondsToTicks() / 30f); pawn.TakeDamage(dinfo3); } } }
private static Pawn GeneratePawnInternal(PawnGenerationRequest request) { request.EnsureNonNullFaction(); Pawn pawn = null; if (!request.Newborn && !request.ForceGenerateNewPawn) { if (request.ForceRedressWorldPawnIfFormerColonist) { IEnumerable <Pawn> validCandidatesToRedress = PawnGenerator.GetValidCandidatesToRedress(request); if (validCandidatesToRedress.Where(PawnUtility.EverBeenColonistOrTameAnimal).TryRandomElementByWeight <Pawn>((Func <Pawn, float>)PawnGenerator.WorldPawnSelectionWeight, out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } if (pawn == null && request.Inhabitant && request.Tile != -1) { Settlement settlement = Find.WorldObjects.WorldObjectAt <Settlement>(request.Tile); if (settlement != null && settlement.previouslyGeneratedInhabitants.Any()) { IEnumerable <Pawn> validCandidatesToRedress2 = PawnGenerator.GetValidCandidatesToRedress(request); if ((from x in validCandidatesToRedress2 where settlement.previouslyGeneratedInhabitants.Contains(x) select x).TryRandomElementByWeight <Pawn>((Func <Pawn, float>)PawnGenerator.WorldPawnSelectionWeight, out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } } if (pawn == null && Rand.Chance(PawnGenerator.ChanceToRedressAnyWorldPawn(request))) { IEnumerable <Pawn> validCandidatesToRedress3 = PawnGenerator.GetValidCandidatesToRedress(request); if (validCandidatesToRedress3.TryRandomElementByWeight <Pawn>((Func <Pawn, float>)PawnGenerator.WorldPawnSelectionWeight, out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } } if (pawn == null) { pawn = PawnGenerator.GenerateNewNakedPawn(ref request); if (pawn == null) { return(null); } if (!request.Newborn) { PawnGenerator.GenerateGearFor(pawn, request); } if (request.Inhabitant && request.Tile != -1) { Settlement settlement2 = Find.WorldObjects.WorldObjectAt <Settlement>(request.Tile); if (settlement2 != null) { settlement2.previouslyGeneratedInhabitants.Add(pawn); } } } if (Find.Scenario != null) { Find.Scenario.Notify_PawnGenerated(pawn, request.Context); } return(pawn); }
public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver) { float efficiency; if (recipeDef.efficiencyStat == null) { efficiency = 1f; } else { efficiency = worker.GetStatValue(recipeDef.efficiencyStat, true); } if (recipeDef.workTableEfficiencyStat != null) { Building_WorkTable building_WorkTable = billGiver as Building_WorkTable; if (building_WorkTable != null) { efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat, true); } } if (recipeDef.products != null) { for (int i = 0; i < recipeDef.products.Count; i++) { ThingDefCountClass prod = recipeDef.products[i]; ThingDef stuffDef; if (prod.thingDef.MadeFromStuff) { stuffDef = dominantIngredient.def; } else { stuffDef = null; } Thing product = ThingMaker.MakeThing(prod.thingDef, stuffDef); product.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); if (dominantIngredient != null) { product.SetColor(dominantIngredient.DrawColor, false); } CompIngredients ingredientsComp = product.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { for (int l = 0; l < ingredients.Count; l++) { ingredientsComp.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable foodPoisonable = product.TryGetComp <CompFoodPoisonable>(); if (foodPoisonable != null) { Room room = worker.GetRoom(RegionType.Set_Passable); float chance = (room == null) ? RoomStatDefOf.FoodPoisonChance.roomlessScore : room.GetStat(RoomStatDefOf.FoodPoisonChance); if (Rand.Chance(chance)) { foodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else { float statValue = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); if (Rand.Chance(statValue)) { foodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } } yield return(GenRecipe.PostProcessProduct(product, recipeDef, worker)); } } if (recipeDef.specialProducts != null) { for (int j = 0; j < recipeDef.specialProducts.Count; j++) { for (int k = 0; k < ingredients.Count; k++) { Thing ing = ingredients[k]; SpecialProductType specialProductType = recipeDef.specialProducts[j]; if (specialProductType != SpecialProductType.Butchery) { if (specialProductType == SpecialProductType.Smelted) { foreach (Thing product2 in ing.SmeltProducts(efficiency)) { yield return(GenRecipe.PostProcessProduct(product2, recipeDef, worker)); } } } else { foreach (Thing product3 in ing.ButcherProducts(worker, efficiency)) { yield return(GenRecipe.PostProcessProduct(product3, recipeDef, worker)); } } } } } yield break; }
private static Pawn GenerateOrRedressPawnInternal(PawnGenerationRequest request) { Pawn pawn = null; if (!request.Newborn && !request.ForceGenerateNewPawn) { if (request.ForceRedressWorldPawnIfFormerColonist) { IEnumerable <Pawn> validCandidatesToRedress = PawnGenerator.GetValidCandidatesToRedress(request); if (validCandidatesToRedress.Where(new Func <Pawn, bool>(PawnUtility.EverBeenColonistOrTameAnimal)).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } if (pawn == null && request.Inhabitant && request.Tile != -1) { SettlementBase settlement = Find.WorldObjects.WorldObjectAt <SettlementBase>(request.Tile); if (settlement != null && settlement.previouslyGeneratedInhabitants.Any <Pawn>()) { IEnumerable <Pawn> validCandidatesToRedress2 = PawnGenerator.GetValidCandidatesToRedress(request); if ((from x in validCandidatesToRedress2 where settlement.previouslyGeneratedInhabitants.Contains(x) select x).TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } } if (pawn == null && Rand.Chance(PawnGenerator.ChanceToRedressAnyWorldPawn(request))) { IEnumerable <Pawn> validCandidatesToRedress3 = PawnGenerator.GetValidCandidatesToRedress(request); if (validCandidatesToRedress3.TryRandomElementByWeight(new Func <Pawn, float>(PawnGenerator.WorldPawnSelectionWeight), out pawn)) { PawnGenerator.RedressPawn(pawn, request); Find.WorldPawns.RemovePawn(pawn); } } } bool redressed; if (pawn == null) { redressed = false; pawn = PawnGenerator.GenerateNewPawnInternal(ref request); if (pawn == null) { return(null); } if (request.Inhabitant && request.Tile != -1) { SettlementBase settlementBase = Find.WorldObjects.WorldObjectAt <SettlementBase>(request.Tile); if (settlementBase != null) { settlementBase.previouslyGeneratedInhabitants.Add(pawn); } } } else { redressed = true; } if (Find.Scenario != null) { Find.Scenario.Notify_PawnGenerated(pawn, request.Context, redressed); } return(pawn); }
public void CheckForStateChange(DamageInfo?dinfo, Hediff hediff) { if (Dead) { return; } if (ShouldBeDead()) { if (!pawn.Destroyed) { pawn.Kill(dinfo, hediff); } } else if (!Downed) { if (ShouldBeDowned()) { if (!forceIncap && dinfo.HasValue && dinfo.Value.Def.ExternalViolenceFor(pawn) && !pawn.IsWildMan() && (pawn.Faction == null || !pawn.Faction.IsPlayer) && (pawn.HostFaction == null || !pawn.HostFaction.IsPlayer)) { float chance = pawn.RaceProps.Animal ? 0.5f : ((!pawn.RaceProps.IsMechanoid) ? (HealthTuning.DeathOnDownedChance_NonColonyHumanlikeFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent) * Find.Storyteller.difficulty.enemyDeathOnDownedChanceFactor) : 1f); if (Rand.Chance(chance)) { pawn.Kill(dinfo); return; } } forceIncap = false; MakeDowned(dinfo, hediff); } else { if (capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { return; } if (pawn.carryTracker != null && pawn.carryTracker.CarriedThing != null && pawn.jobs != null && pawn.CurJob != null) { pawn.jobs.EndCurrentJob(JobCondition.InterruptForced); } if (pawn.equipment == null || pawn.equipment.Primary == null) { return; } if (pawn.kindDef.destroyGearOnDrop) { pawn.equipment.DestroyEquipment(pawn.equipment.Primary); } else if (pawn.InContainerEnclosed) { pawn.equipment.TryTransferEquipmentToContainer(pawn.equipment.Primary, pawn.holdingOwner); } else if (pawn.SpawnedOrAnyParentSpawned) { pawn.equipment.TryDropEquipment(pawn.equipment.Primary, out ThingWithComps _, pawn.PositionHeld); } else if (pawn.IsCaravanMember()) { ThingWithComps primary = pawn.equipment.Primary; pawn.equipment.Remove(primary); if (!pawn.inventory.innerContainer.TryAdd(primary)) { primary.Destroy(); } } else { pawn.equipment.DestroyEquipment(pawn.equipment.Primary); } } } else if (!ShouldBeDowned()) { MakeUndowned(); } }
public void CheckForStateChange(DamageInfo?dinfo, Hediff hediff) { if (!this.Dead) { if (this.ShouldBeDead()) { if (!this.pawn.Destroyed) { this.pawn.Kill(dinfo, hediff); } return; } if (!this.Downed) { if (this.ShouldBeDowned()) { if (!this.forceIncap && dinfo.HasValue && dinfo.Value.Def.ExternalViolenceFor(this.pawn) && !this.pawn.IsWildMan() && (this.pawn.Faction == null || !this.pawn.Faction.IsPlayer) && (this.pawn.HostFaction == null || !this.pawn.HostFaction.IsPlayer)) { float chance; if (this.pawn.RaceProps.Animal) { chance = 0.5f; } else if (this.pawn.RaceProps.IsMechanoid) { chance = 1f; } else { chance = HealthTuning.DeathOnDownedChance_NonColonyHumanlikeFromPopulationIntentCurve.Evaluate(StorytellerUtilityPopulation.PopulationIntent) * Find.Storyteller.difficulty.enemyDeathOnDownedChanceFactor; } if (Rand.Chance(chance)) { this.pawn.Kill(dinfo, null); return; } } this.forceIncap = false; this.MakeDowned(dinfo, hediff); return; } if (!this.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { if (this.pawn.carryTracker != null && this.pawn.carryTracker.CarriedThing != null && this.pawn.jobs != null && this.pawn.CurJob != null) { this.pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true); } if (this.pawn.equipment != null && this.pawn.equipment.Primary != null) { if (this.pawn.kindDef.destroyGearOnDrop) { this.pawn.equipment.DestroyEquipment(this.pawn.equipment.Primary); } else if (this.pawn.InContainerEnclosed) { this.pawn.equipment.TryTransferEquipmentToContainer(this.pawn.equipment.Primary, this.pawn.holdingOwner); } else if (this.pawn.SpawnedOrAnyParentSpawned) { ThingWithComps thingWithComps; this.pawn.equipment.TryDropEquipment(this.pawn.equipment.Primary, out thingWithComps, this.pawn.PositionHeld, true); } else { this.pawn.equipment.DestroyEquipment(this.pawn.equipment.Primary); } } } } else if (!this.ShouldBeDowned()) { this.MakeUndowned(); return; } } }
// Token: 0x06000017 RID: 23 RVA: 0x00003205 File Offset: 0x00001405 public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient) { Log.Message(string.Concat(new string[] { "init WPGenRecipe: recipeDef ", (recipeDef != null) ? recipeDef.ToString() : null, " worker ", (worker != null) ? worker.ToString() : null, " ingredients ", (ingredients != null) ? ingredients.ToString() : null, " dominantIngredient ", (dominantIngredient != null) ? dominantIngredient.ToString() : null }), false); bool flag = recipeDef.efficiencyStat == null; float efficiency; if (flag) { efficiency = 1f; } else { efficiency = worker.GetStatValue(recipeDef.efficiencyStat, true); } bool flag2 = recipeDef.products != null; if (flag2) { int num2; for (int i = 0; i < recipeDef.products.Count; i = num2 + 1) { ThingDefCountClass prod = recipeDef.products[i]; bool madeFromStuff = prod.thingDef.MadeFromStuff; ThingDef stuffDef; if (madeFromStuff) { stuffDef = dominantIngredient.def; } else { stuffDef = null; } Thing product = ThingMaker.MakeThing(prod.thingDef, stuffDef); product.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); bool flag3 = dominantIngredient != null; if (flag3) { product.SetColor(dominantIngredient.DrawColor, false); } CompIngredients ingredientsComp = product.TryGetComp <CompIngredients>(); bool flag4 = ingredientsComp != null; if (flag4) { for (int j = 0; j < ingredients.Count; j = num2 + 1) { ingredientsComp.RegisterIngredient(ingredients[j].def); num2 = j; } } CompFoodPoisonable foodPoisonable = product.TryGetComp <CompFoodPoisonable>(); bool flag5 = foodPoisonable != null; if (flag5) { float num = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); Room room = worker.GetRoom(RegionType.Set_Passable); float chance = (room == null) ? RoomStatDefOf.FoodPoisonChance.roomlessScore : room.GetStat(RoomStatDefOf.FoodPoisonChance); bool flag6 = Rand.Chance(chance); if (flag6) { foodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else { float statValue = worker.GetStatValue(StatDefOf.FoodPoisonChance, true); bool flag7 = Rand.Chance(statValue); if (flag7) { foodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } room = null; } yield return(WPGenRecipe.PostProcessProduct(product, recipeDef, worker)); prod = null; stuffDef = null; product = null; ingredientsComp = null; foodPoisonable = null; num2 = i; } } bool flag8 = recipeDef.specialProducts != null; if (flag8) { string str = "special recipedef not null"; List <SpecialProductType> specialProducts = recipeDef.specialProducts; Log.Message(str + ((specialProducts != null) ? specialProducts.ToString() : null), false); Log.Message("recipeDef.specialProducts.Count " + recipeDef.specialProducts.Count.ToString(), false); int num2; for (int k = 0; k < recipeDef.specialProducts.Count; k = num2 + 1) { Log.Message("recipeDef.specialProducts[j] " + recipeDef.specialProducts[k].ToString(), false); Log.Message("ingredients.Count " + ingredients.Count.ToString(), false); string str2 = "recipeDef.ingredients "; List <IngredientCount> ingredients2 = recipeDef.ingredients; Log.Message(str2 + ((ingredients2 != null) ? ingredients2.ToString() : null), false); for (int l = 0; l < ingredients.Count; l = num2 + 1) { Thing ing = ingredients[l]; string str3 = "ingredients[k] "; Thing thing = ingredients[l]; Log.Message(str3 + ((thing != null) ? thing.ToString() : null), false); string str4 = "ing "; Thing thing2 = ing; Log.Message(str4 + ((thing2 != null) ? thing2.ToString() : null), false); SpecialProductType specialProductType = recipeDef.specialProducts[k]; bool flag9 = specialProductType > SpecialProductType.Butchery; if (flag9) { Log.Message("not butchery", false); bool flag10 = specialProductType == SpecialProductType.Smelted; if (flag10) { foreach (Thing product2 in ing.SmeltProducts(efficiency)) { yield return(WPGenRecipe.PostProcessProduct(product2, recipeDef, worker)); } } } else { Log.Message("butchery", false); foreach (Thing product3 in ing.ButcherProducts(worker, efficiency)) { string[] array = new string[8]; array[0] = "recipeDef.specialProducts[k] "; array[1] = recipeDef.specialProducts[l].ToString(); array[2] = "product3 "; int num3 = 3; Thing thing3 = product3; array[num3] = ((thing3 != null) ? thing3.ToString() : null); array[4] = " recipeDef "; array[5] = ((recipeDef != null) ? recipeDef.ToString() : null); array[6] = " worker "; array[7] = ((worker != null) ? worker.ToString() : null); Log.Message(string.Concat(array), false); yield return(WPGenRecipe.PostProcessProduct(product3, recipeDef, worker)); } } ing = null; num2 = l; } num2 = k; } } Log.Message("yield break", false); yield break; }
private static Pawn TryGenerateNewPawnInternal(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements, bool ignoreValidator) { error = null; Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race); pawnsBeingGenerated.Add(new PawnGenerationStatus(pawn, null)); try { pawn.kindDef = request.KindDef; pawn.SetFactionDirect(request.Faction); PawnComponentsUtility.CreateInitialComponents(pawn); if (request.FixedGender.HasValue) { pawn.gender = request.FixedGender.Value; } else if (pawn.RaceProps.hasGenders) { if (Rand.Value < 0.5f) { pawn.gender = Gender.Male; } else { pawn.gender = Gender.Female; } } else { pawn.gender = Gender.None; } GenerateRandomAge(pawn, request); pawn.needs.SetInitialLevels(); if (!request.Newborn && request.CanGeneratePawnRelations) { GeneratePawnRelations(pawn, ref request); } if (pawn.RaceProps.Humanlike) { Faction faction; FactionDef factionType = ((request.Faction != null) ? request.Faction.def : ((!Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction_NewTemp(out faction, tryMedievalOrBetter: false, allowDefeated: true)) ? Faction.OfAncients.def : faction.def)); pawn.story.melanin = (request.FixedMelanin.HasValue ? request.FixedMelanin.Value : PawnSkinColors.RandomMelanin(request.Faction)); pawn.story.crownType = ((Rand.Value < 0.5f) ? CrownType.Average : CrownType.Narrow); pawn.story.hairColor = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears); PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName, factionType); if (pawn.story != null) { if (request.FixedBirthName != null) { pawn.story.birthLastName = request.FixedBirthName; } else if (pawn.Name is NameTriple) { pawn.story.birthLastName = ((NameTriple)pawn.Name).Last; } } pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, factionType); GenerateTraits(pawn, request); GenerateBodyType_NewTemp(pawn, request); GenerateSkills(pawn); } if (pawn.RaceProps.Animal && request.Faction != null && request.Faction.IsPlayer) { pawn.training.SetWantedRecursive(TrainableDefOf.Tameness, checkOn: true); pawn.training.Train(TrainableDefOf.Tameness, null, complete: true); } GenerateInitialHediffs(pawn, request); if (!request.ForbidAnyTitle) { RoyalTitleDef royalTitleDef = request.FixedTitle; if (royalTitleDef == null) { if (request.KindDef.titleRequired != null) { royalTitleDef = request.KindDef.titleRequired; } else if (!request.KindDef.titleSelectOne.NullOrEmpty() && Rand.Chance(request.KindDef.royalTitleChance)) { royalTitleDef = request.KindDef.titleSelectOne.RandomElementByWeight((RoyalTitleDef t) => t.commonality); } } if (request.KindDef.minTitleRequired != null && (royalTitleDef == null || royalTitleDef.seniority < request.KindDef.minTitleRequired.seniority)) { royalTitleDef = request.KindDef.minTitleRequired; } if (royalTitleDef != null) { Faction faction2 = ((request.Faction != null && request.Faction.def.HasRoyalTitles) ? request.Faction : Find.FactionManager.RandomRoyalFaction()); pawn.royalty.SetTitle(faction2, royalTitleDef, grantRewards: false); if (request.Faction != null && !request.Faction.IsPlayer) { PurchasePermits(pawn, faction2); } int amount = 0; if (royalTitleDef.GetNextTitle(faction2) != null) { amount = Rand.Range(0, royalTitleDef.GetNextTitle(faction2).favorCost - 1); } pawn.royalty.SetFavor_NewTemp(faction2, amount); if (royalTitleDef.maxPsylinkLevel > 0) { Hediff_ImplantWithLevel hediff_ImplantWithLevel = HediffMaker.MakeHediff(HediffDefOf.PsychicAmplifier, pawn, pawn.health.hediffSet.GetBrain()) as Hediff_ImplantWithLevel; pawn.health.AddHediff(hediff_ImplantWithLevel); hediff_ImplantWithLevel.SetLevelTo(royalTitleDef.maxPsylinkLevel); } } } if (pawn.royalty != null) { pawn.royalty.allowRoomRequirements = request.KindDef.allowRoyalRoomRequirements; pawn.royalty.allowApparelRequirements = request.KindDef.allowRoyalApparelRequirements; } if (pawn.workSettings != null && request.Faction != null && request.Faction.IsPlayer) { pawn.workSettings.EnableAndInitialize(); } if (request.Faction != null && pawn.RaceProps.Animal) { pawn.GenerateNecessaryName(); } if (Find.Scenario != null) { Find.Scenario.Notify_NewPawnGenerating(pawn, request.Context); } if (!request.AllowDead && (pawn.Dead || pawn.Destroyed)) { DiscardGeneratedPawn(pawn); error = "Generated dead pawn."; return(null); } if (!request.AllowDowned && pawn.Downed) { DiscardGeneratedPawn(pawn); error = "Generated downed pawn."; return(null); } if (request.MustBeCapableOfViolence && ((pawn.story != null && pawn.WorkTagIsDisabled(WorkTags.Violent)) || (pawn.RaceProps.ToolUser && !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)))) { DiscardGeneratedPawn(pawn); error = "Generated pawn incapable of violence."; return(null); } if (request.KindDef != null && !request.KindDef.skills.NullOrEmpty()) { List <SkillRange> skills = request.KindDef.skills; for (int i = 0; i < skills.Count; i++) { if (pawn.skills.GetSkill(skills[i].Skill).TotallyDisabled) { error = "Generated pawn incapable of required skill: " + skills[i].Skill.defName; return(null); } } } if (request.KindDef.requiredWorkTags != 0 && (pawn.CombinedDisabledWorkTags & request.KindDef.requiredWorkTags) != 0) { DiscardGeneratedPawn(pawn); error = "Generated pawn with disabled requiredWorkTags."; return(null); } if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && Find.Scenario != null && !Find.Scenario.AllowPlayerStartingPawn(pawn, tryingToRedress: false, request)) { DiscardGeneratedPawn(pawn); error = "Generated pawn doesn't meet scenario requirements."; return(null); } if (!ignoreValidator && request.ValidatorPreGear != null && !request.ValidatorPreGear(pawn)) { DiscardGeneratedPawn(pawn); error = "Generated pawn didn't pass validator check (pre-gear)."; return(null); } if (!request.Newborn) { GenerateGearFor(pawn, request); } if (!ignoreValidator && request.ValidatorPostGear != null && !request.ValidatorPostGear(pawn)) { DiscardGeneratedPawn(pawn); error = "Generated pawn didn't pass validator check (post-gear)."; return(null); } for (int j = 0; j < pawnsBeingGenerated.Count - 1; j++) { if (pawnsBeingGenerated[j].PawnsGeneratedInTheMeantime == null) { pawnsBeingGenerated[j] = new PawnGenerationStatus(pawnsBeingGenerated[j].Pawn, new List <Pawn>()); } pawnsBeingGenerated[j].PawnsGeneratedInTheMeantime.Add(pawn); } return(pawn); } finally { pawnsBeingGenerated.RemoveLast(); } }
private bool CheckForFreeIntercept(IntVec3 c) { bool result; if (this.destination.ToIntVec3() == c) { result = false; } else { float num = VerbUtility.DistanceInterceptChance(this.origin, c, this.intendedTarget.Cell); if (num <= 0f) { result = false; } else { bool flag = false; List <Thing> thingList = c.GetThingList(base.Map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (this.CanHit(thing)) { bool flag2 = false; if (thing.def.Fillage == FillCategory.Full) { Building_Door building_Door = thing as Building_Door; if (building_Door == null || !building_Door.Open) { this.ThrowDebugText("int-wall", c); this.Impact(thing); return(true); } flag2 = true; } float num2 = 0f; Pawn pawn = thing as Pawn; if (pawn != null) { num2 = 0.4f; num2 *= Mathf.Clamp(pawn.BodySize, 0.1f, 2f); if (pawn.GetPosture() != PawnPosture.Standing) { num2 *= 0.1f; } if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !pawn.Faction.HostileTo(this.launcher.Faction)) { num2 *= 0.4f; } } else if (thing.def.fillPercent > 0.2f) { if (flag2) { num2 = 0.05f; } else if (this.DestinationCell.AdjacentTo8Way(c)) { num2 = thing.def.fillPercent * 1f; } else { num2 = thing.def.fillPercent * 0.15f; } } num2 *= num; if (num2 > 1E-05f) { if (Rand.Chance(num2)) { this.ThrowDebugText("int-" + num2.ToStringPercent(), c); this.Impact(thing); return(true); } flag = true; this.ThrowDebugText(num2.ToStringPercent(), c); } } } if (!flag) { this.ThrowDebugText("o", c); } result = false; } } return(result); }
protected override bool TryCastShot() { if (currentTarget.HasThing && currentTarget.Thing.Map != caster.Map) { return(false); } ThingDef projectile = Projectile; if (projectile == null) { return(false); } ShootLine resultingLine; bool flag = TryFindShootLineFromTo(caster.Position, currentTarget, out resultingLine); if (verbProps.stopBurstWithoutLos && !flag) { return(false); } if (base.EquipmentSource != null) { base.EquipmentSource.GetComp <CompChangeableProjectile>()?.Notify_ProjectileLaunched(); } Thing launcher = caster; Thing equipment = base.EquipmentSource; CompMannable compMannable = caster.TryGetComp <CompMannable>(); if (compMannable != null && compMannable.ManningPawn != null) { launcher = compMannable.ManningPawn; equipment = caster; } Vector3 drawPos = caster.DrawPos; Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, resultingLine.Source, caster.Map); if (verbProps.forcedMissRadius > 0.5f) { float num = VerbUtility.CalculateAdjustedForcedMiss(verbProps.forcedMissRadius, currentTarget.Cell - caster.Position); if (num > 0.5f) { int max = GenRadial.NumCellsInRadius(num); int num2 = Rand.Range(0, max); if (num2 > 0) { IntVec3 c = currentTarget.Cell + GenRadial.RadialPattern[num2]; ThrowDebugText("ToRadius"); ThrowDebugText("Rad\nDest", c); ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld; if (Rand.Chance(0.5f)) { projectileHitFlags = ProjectileHitFlags.All; } if (!canHitNonTargetPawnsNow) { projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns; } projectile2.Launch(launcher, drawPos, c, currentTarget, projectileHitFlags, equipment); return(true); } } } ShotReport shotReport = ShotReport.HitReportFor(caster, this, currentTarget); Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto(); ThingDef targetCoverDef = randomCoverToMissInto?.def; if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture)) { resultingLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget); ThrowDebugText("ToWild" + (canHitNonTargetPawnsNow ? "\nchntp" : "")); ThrowDebugText("Wild\nDest", resultingLine.Dest); ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld; if (Rand.Chance(0.5f) && canHitNonTargetPawnsNow) { projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns; } projectile2.Launch(launcher, drawPos, resultingLine.Dest, currentTarget, projectileHitFlags2, equipment, targetCoverDef); return(true); } if (currentTarget.Thing != null && currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance)) { ThrowDebugText("ToCover" + (canHitNonTargetPawnsNow ? "\nchntp" : "")); ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position); ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld; if (canHitNonTargetPawnsNow) { projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns; } projectile2.Launch(launcher, drawPos, randomCoverToMissInto, currentTarget, projectileHitFlags3, equipment, targetCoverDef); return(true); } ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget; if (canHitNonTargetPawnsNow) { projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns; } if (!currentTarget.HasThing || currentTarget.Thing.def.Fillage == FillCategory.Full) { projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld; } ThrowDebugText("ToHit" + (canHitNonTargetPawnsNow ? "\nchntp" : "")); if (currentTarget.Thing != null) { projectile2.Launch(launcher, drawPos, currentTarget, currentTarget, projectileHitFlags4, equipment, targetCoverDef); ThrowDebugText("Hit\nDest", currentTarget.Cell); } else { projectile2.Launch(launcher, drawPos, resultingLine.Dest, currentTarget, projectileHitFlags4, equipment, targetCoverDef); ThrowDebugText("Hit\nDest", resultingLine.Dest); } return(true); }
private void ImpactSomething() { if (this.def.projectile.flyOverhead) { RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position); if (roofDef != null) { if (roofDef.isThickRoof) { this.ThrowDebugText("hit-thick-roof", base.Position); this.def.projectile.soundHitThickRoof.PlayOneShot(new TargetInfo(base.Position, base.Map, false)); this.Destroy(DestroyMode.Vanish); return; } if (base.Position.GetEdifice(base.Map) == null || base.Position.GetEdifice(base.Map).def.Fillage != FillCategory.Full) { RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null); } } } if (this.usedTarget.HasThing && this.CanHit(this.usedTarget.Thing)) { Pawn pawn = this.usedTarget.Thing as Pawn; if (pawn != null && pawn.GetPosture() != PawnPosture.Standing && (this.origin - this.destination).MagnitudeHorizontalSquared() >= 20.25f) { if (!Rand.Chance(0.2f)) { this.ThrowDebugText("miss-laying", base.Position); this.Impact(null); return; } } this.Impact(this.usedTarget.Thing); } else { Projectile.cellThingsFiltered.Clear(); List <Thing> thingList = base.Position.GetThingList(base.Map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) { if (this.CanHit(thing)) { Projectile.cellThingsFiltered.Add(thing); } } } Projectile.cellThingsFiltered.Shuffle <Thing>(); for (int j = 0; j < Projectile.cellThingsFiltered.Count; j++) { Thing thing2 = Projectile.cellThingsFiltered[j]; Pawn pawn2 = thing2 as Pawn; float num; if (pawn2 != null) { num = 0.5f * Mathf.Clamp(pawn2.BodySize, 0.1f, 2f); } else { num = 1.5f * thing2.def.fillPercent; } if (Rand.Chance(num)) { this.ThrowDebugText("hit-" + num.ToStringPercent(), base.Position); this.Impact(Projectile.cellThingsFiltered.RandomElement <Thing>()); return; } this.ThrowDebugText("miss-" + num.ToStringPercent(), base.Position); } this.Impact(null); } }
public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver) { float efficiency = (recipeDef.efficiencyStat != null) ? worker.GetStatValue(recipeDef.efficiencyStat) : 1f; if (recipeDef.workTableEfficiencyStat != null) { Building_WorkTable building_WorkTable = billGiver as Building_WorkTable; if (building_WorkTable != null) { efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat); } } if (recipeDef.products != null) { int k = 0; if (k < recipeDef.products.Count) { ThingDefCountClass prod = recipeDef.products[k]; Thing product3 = ThingMaker.MakeThing(stuff: (!prod.thingDef.MadeFromStuff) ? null : dominantIngredient.def, def: prod.thingDef); product3.stackCount = Mathf.CeilToInt((float)prod.count * efficiency); if (dominantIngredient != null) { product3.SetColor(dominantIngredient.DrawColor, reportFailure: false); } CompIngredients ingredientsComp = product3.TryGetComp <CompIngredients>(); if (ingredientsComp != null) { for (int l = 0; l < ingredients.Count; l++) { ingredientsComp.RegisterIngredient(ingredients[l].def); } } CompFoodPoisonable foodPoisonable = product3.TryGetComp <CompFoodPoisonable>(); if (foodPoisonable != null) { float chance = worker.GetRoom()?.GetStat(RoomStatDefOf.FoodPoisonChance) ?? RoomStatDefOf.FoodPoisonChance.roomlessScore; if (Rand.Chance(chance)) { foodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen); } else { float statValue = worker.GetStatValue(StatDefOf.FoodPoisonChance); if (Rand.Chance(statValue)) { foodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook); } } } yield return(PostProcessProduct(product3, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } if (recipeDef.specialProducts != null) { for (int j = 0; j < recipeDef.specialProducts.Count; j++) { for (int i = 0; i < ingredients.Count; i++) { Thing ing = ingredients[i]; switch (recipeDef.specialProducts[j]) { case SpecialProductType.Butchery: using (IEnumerator <Thing> enumerator2 = ing.ButcherProducts(worker, efficiency).GetEnumerator()) { if (enumerator2.MoveNext()) { Thing product = enumerator2.Current; yield return(PostProcessProduct(product, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } break; case SpecialProductType.Smelted: using (IEnumerator <Thing> enumerator = ing.SmeltProducts(efficiency).GetEnumerator()) { if (enumerator.MoveNext()) { Thing product2 = enumerator.Current; yield return(PostProcessProduct(product2, recipeDef, worker)); /*Error: Unable to find new state assignment for yield return*/; } } break; } } } } yield break; IL_04dd: /*Error near IL_04de: Unexpected return in MoveNext()*/; }