public static bool TryRangeInclusiveWhere(int from, int to, Predicate <int> predicate, out int value) { int num = to - from + 1; if (num <= 0) { value = 0; return(false); } int num2 = Mathf.Max(Mathf.RoundToInt(Mathf.Sqrt((float)num)), 5); for (int i = 0; i < num2; i++) { int num3 = Rand.RangeInclusive(from, to); if (predicate(num3)) { value = num3; return(true); } } Rand.tmpRange.Clear(); for (int j = from; j <= to; j++) { Rand.tmpRange.Add(j); } Rand.tmpRange.Shuffle(); int k = 0; int count = Rand.tmpRange.Count; for (; k < count; k++) { if (predicate(Rand.tmpRange[k])) { value = Rand.tmpRange[k]; return(true); } } value = 0; return(false); }
public static void DamageUntilDead(Pawn p) { HediffSet hediffSet = p.health.hediffSet; int num = 0; while (!p.Dead && num < 200 && HealthUtility.HittablePartsViolence(hediffSet).Any()) { num++; BodyPartRecord bodyPartRecord = HealthUtility.HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Rand.RangeInclusive(8, 25); DamageDef damageDef = (bodyPartRecord.depth != BodyPartDepth.Outside) ? DamageDefOf.Blunt : HealthUtility.RandomViolenceDamageType(); DamageDef def = damageDef; int amount = num2; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown); p.TakeDamage(dinfo); } if (!p.Dead) { Log.Error(p + " not killed during GiveInjuriesToKill"); } }
private static int FinalLevelOfSkill(Pawn pawn, SkillDef sk) { float num; if (sk.usuallyDefinedInBackstories) { num = (float)Rand.RangeInclusive(0, 4); } else { num = Rand.ByCurve(PawnGenerator.LevelRandomCurve, 100); } foreach (Backstory current in from bs in pawn.story.AllBackstories where bs != null select bs) { foreach (KeyValuePair <SkillDef, int> current2 in current.skillGainsResolved) { if (current2.Key == sk) { num += (float)current2.Value * Rand.Range(1f, 1.4f); } } } for (int i = 0; i < pawn.story.traits.allTraits.Count; i++) { int num2 = 0; if (pawn.story.traits.allTraits[i].CurrentData.skillGains.TryGetValue(sk, out num2)) { num += (float)num2; } } float num3 = Rand.Range(1f, PawnGenerator.AgeSkillMaxFactorCurve.Evaluate((float)pawn.ageTracker.AgeBiologicalYears)); num *= num3; num = PawnGenerator.LevelFinalAdjustmentCurve.Evaluate(num); return(Mathf.Clamp(Mathf.RoundToInt(num), 0, 20)); }
public static DamageDef RandomViolenceDamageType() { switch (Rand.RangeInclusive(0, 4)) { case 0: return(DamageDefOf.Bullet); case 1: return(DamageDefOf.Blunt); case 2: return(DamageDefOf.Stab); case 3: return(DamageDefOf.Scratch); case 4: return(DamageDefOf.Cut); default: return(null); } }
public DamageInfo(DamageDef def, int amount, float angle = -1f, Thing instigator = null, BodyPartRecord hitPart = null, ThingDef weapon = null, SourceCategory category = SourceCategory.ThingOrUnknown) { this.defInt = def; this.amountInt = amount; if (angle < 0.0) { this.angleInt = (float)Rand.RangeInclusive(0, 359); } else { this.angleInt = angle; } this.instigatorInt = instigator; this.categoryInt = category; this.hitPartInt = hitPart; this.heightInt = BodyPartHeight.Undefined; this.depthInt = BodyPartDepth.Undefined; this.weaponInt = weapon; this.weaponBodyPartGroupInt = null; this.weaponHediffInt = null; this.instantOldInjuryInt = false; this.allowDamagePropagationInt = true; }
public static void DamageUntilDead(Pawn p) { HediffSet hediffSet = p.health.hediffSet; int num = 0; while (!p.Dead && num < 200 && HittablePartsViolence(hediffSet).Any()) { num++; BodyPartRecord bodyPartRecord = HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Rand.RangeInclusive(8, 25); DamageDef damageDef = (bodyPartRecord.depth != BodyPartDepth.Outside) ? DamageDefOf.Blunt : RandomViolenceDamageType(); DamageDef def = damageDef; float amount = (float)num2; float armorPenetration = 999f; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart); p.TakeDamage(dinfo); } if (!p.Dead) { Log.Error(p + " not killed during GiveInjuriesToKill"); } }
public override void Init(GraphicRequest req) { this.data = req.graphicData; if (req.path.NullOrEmpty()) { throw new ArgumentNullException("folderPath"); } if (req.shader == null) { throw new ArgumentNullException("shader"); } this.path = req.path; this.color = req.color; this.colorTwo = req.colorTwo; this.drawSize = req.drawSize; List <Texture2D> list = (from x in ContentFinder <Texture2D> .GetAllInFolder(req.path) where !x.name.EndsWith(Graphic_Single.MaskSuffix) && !x.name.EndsWith("Glow") orderby x.name select x).ToList <Texture2D>(); if (list.NullOrEmpty <Texture2D>()) { Log.Error("Collection cannot init: No textures found at path " + req.path, false); this.subGraphics = new Graphic[] { BaseContent.BadGraphic }; return; } this.subGraphics = new Graphic[list.Count]; for (int i = 0; i < list.Count; i++) { string path = req.path + "/" + list[i].name; this.subGraphics[i] = GraphicDatabase.Get(typeof(Graphic_Single), path, req.shader, this.drawSize, this.color, this.colorTwo, null, req.shaderParameters); } ind = Rand.RangeInclusive(0, subGraphics.Length - 1); }
public static void DamageLegsUntilIncapableOfMoving(Pawn p, bool allowBleedingWounds = true) { int num = 0; p.health.forceIncap = true; while (p.health.capacities.CapableOf(PawnCapacityDefOf.Moving) && num < 300) { num++; IEnumerable <BodyPartRecord> source = from x in p.health.hediffSet.GetNotMissingParts() where x.def.tags.Contains(BodyPartTagDefOf.MovingLimbCore) && p.health.hediffSet.GetPartHealth(x) >= 2f select x; if (!source.Any()) { break; } BodyPartRecord bodyPartRecord = source.RandomElement(); float maxHealth = bodyPartRecord.def.GetMaxHealth(p); float partHealth = p.health.hediffSet.GetPartHealth(bodyPartRecord); int min = Mathf.Clamp(Mathf.RoundToInt(maxHealth * 0.12f), 1, (int)partHealth - 1); int max = Mathf.Clamp(Mathf.RoundToInt(maxHealth * 0.27f), 1, (int)partHealth - 1); int num2 = Rand.RangeInclusive(min, max); DamageDef damageDef = (allowBleedingWounds || !(bodyPartRecord.def.bleedRate > 0f)) ? RandomViolenceDamageType() : DamageDefOf.Blunt; HediffDef hediffDefFromDamage = GetHediffDefFromDamage(damageDef, p, bodyPartRecord); if (p.health.WouldDieAfterAddingHediff(hediffDefFromDamage, bodyPartRecord, (float)num2)) { break; } DamageDef def = damageDef; float amount = (float)num2; float armorPenetration = 999f; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart); dinfo.SetAllowDamagePropagation(val: false); p.TakeDamage(dinfo); } p.health.forceIncap = false; }
public static bool TryFindRandomCellNear(IntVec3 root, Map map, int squareRadius, Predicate <IntVec3> validator, out IntVec3 result) { int num = root.x - squareRadius; int num2 = root.x + squareRadius; int num3 = root.z - squareRadius; int num4 = root.z + squareRadius; if (num < 0) { num = 0; } if (num3 < 0) { num3 = 0; } int num5 = num2; IntVec3 size = map.Size; if (num5 > size.x) { IntVec3 size2 = map.Size; num2 = size2.x; } int num6 = num4; IntVec3 size3 = map.Size; if (num6 > size3.z) { IntVec3 size4 = map.Size; num4 = size4.z; } int num7 = 0; while (true) { IntVec3 intVec = new IntVec3(Rand.RangeInclusive(num, num2), 0, Rand.RangeInclusive(num3, num4)); if (validator != null && !validator(intVec)) { if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0f, "inv", 50); } num7++; if (num7 > 20) { break; } continue; } if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0.5f, "found", 50); } result = intVec; return(true); } CellFinder.workingListX.Clear(); CellFinder.workingListZ.Clear(); for (int i = num; i <= num2; i++) { CellFinder.workingListX.Add(i); } for (int j = num3; j <= num4; j++) { CellFinder.workingListZ.Add(j); } CellFinder.workingListX.Shuffle(); CellFinder.workingListZ.Shuffle(); for (int k = 0; k < CellFinder.workingListX.Count; k++) { for (int l = 0; l < CellFinder.workingListZ.Count; l++) { IntVec3 intVec = new IntVec3(CellFinder.workingListX[k], 0, CellFinder.workingListZ[l]); if (validator(intVec)) { if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0.6f, "found2", 50); } result = intVec; return(true); } if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0.25f, "inv2", 50); } } } result = root; return(false); }
private DamageWorker.DamageResult ApplyToPawn(DamageInfo dinfo, Pawn pawn) { DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult(); if (dinfo.Amount <= 0f) { return(damageResult); } if (!DebugSettings.enablePlayerDamage && pawn.Faction == Faction.OfPlayer) { return(damageResult); } Map mapHeld = pawn.MapHeld; bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned; if (dinfo.AllowDamagePropagation && dinfo.Amount >= (float)dinfo.Def.minDamageToFragment) { int num = Rand.RangeInclusive(2, 4); for (int i = 0; i < num; i++) { DamageInfo dinfo2 = dinfo; dinfo2.SetAmount(dinfo.Amount / (float)num); this.ApplyDamageToPart(dinfo2, pawn, damageResult); } } else { this.ApplyDamageToPart(dinfo, pawn, damageResult); this.ApplySmallPawnDamagePropagation(dinfo, pawn, damageResult); } if (damageResult.wounded) { DamageWorker_AddInjury.PlayWoundedVoiceSound(dinfo, pawn); pawn.Drawer.Notify_DamageApplied(dinfo); } if (damageResult.headshot && pawn.Spawned) { MoteMaker.ThrowText(new Vector3((float)pawn.Position.x + 1f, (float)pawn.Position.y, (float)pawn.Position.z + 1f), pawn.Map, "Headshot".Translate(), Color.white, -1f); if (dinfo.Instigator != null) { Pawn pawn2 = dinfo.Instigator as Pawn; if (pawn2 != null) { pawn2.records.Increment(RecordDefOf.Headshots); } } } if ((damageResult.deflected || damageResult.diminished) && spawnedOrAnyParentSpawned) { EffecterDef effecterDef; if (damageResult.deflected) { if (damageResult.deflectedByMetalArmor && dinfo.Def.canUseDeflectMetalEffect) { if (dinfo.Def == DamageDefOf.Bullet) { effecterDef = EffecterDefOf.Deflect_Metal_Bullet; } else { effecterDef = EffecterDefOf.Deflect_Metal; } } else if (dinfo.Def == DamageDefOf.Bullet) { effecterDef = EffecterDefOf.Deflect_General_Bullet; } else { effecterDef = EffecterDefOf.Deflect_General; } } else if (damageResult.diminishedByMetalArmor) { effecterDef = EffecterDefOf.DamageDiminished_Metal; } else { effecterDef = EffecterDefOf.DamageDiminished_General; } if (pawn.health.deflectionEffecter == null || pawn.health.deflectionEffecter.def != effecterDef) { if (pawn.health.deflectionEffecter != null) { pawn.health.deflectionEffecter.Cleanup(); pawn.health.deflectionEffecter = null; } pawn.health.deflectionEffecter = effecterDef.Spawn(); } pawn.health.deflectionEffecter.Trigger(pawn, dinfo.Instigator ?? pawn); if (damageResult.deflected) { pawn.Drawer.Notify_DamageDeflected(dinfo); } } if (!damageResult.deflected && spawnedOrAnyParentSpawned) { ImpactSoundUtility.PlayImpactSound(pawn, dinfo.Def.impactSoundType, mapHeld); } return(damageResult); }
public static void DamageUntilDowned(Pawn p, bool allowBleedingWounds = true) { if (p.health.Downed) { return; } HediffSet hediffSet = p.health.hediffSet; p.health.forceIncap = true; IEnumerable <BodyPartRecord> source = from x in HealthUtility.HittablePartsViolence(hediffSet) where !p.health.hediffSet.hediffs.Any((Hediff y) => y.Part == x && y.CurStage != null && y.CurStage.partEfficiencyOffset < 0f) select x; int num = 0; while (num < 300 && !p.Downed && source.Any <BodyPartRecord>()) { num++; BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Mathf.RoundToInt(hediffSet.GetPartHealth(bodyPartRecord)) - 3; if (num2 >= 8) { DamageDef damageDef; if (bodyPartRecord.depth == BodyPartDepth.Outside) { if (!allowBleedingWounds && bodyPartRecord.def.bleedRate > 0f) { damageDef = DamageDefOf.Blunt; } else { damageDef = HealthUtility.RandomViolenceDamageType(); } } else { damageDef = DamageDefOf.Blunt; } int num3 = Rand.RangeInclusive(Mathf.RoundToInt((float)num2 * 0.65f), num2); HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(damageDef, p, bodyPartRecord); if (!p.health.WouldDieAfterAddingHediff(hediffDefFromDamage, bodyPartRecord, (float)num3)) { DamageDef def = damageDef; float amount = (float)num3; float armorPenetration = 999f; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null); dinfo.SetAllowDamagePropagation(false); p.TakeDamage(dinfo); } } } if (p.Dead) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(p + " died during GiveInjuriesToForceDowned"); for (int i = 0; i < p.health.hediffSet.hediffs.Count; i++) { stringBuilder.AppendLine(" -" + p.health.hediffSet.hediffs[i].ToString()); } Log.Error(stringBuilder.ToString(), false); } p.health.forceIncap = false; }
private static object RandInt(object[] args) { CultureInfo invariantCulture = CultureInfo.InvariantCulture; return((double)Rand.RangeInclusive(Convert.ToInt32(args[0], invariantCulture), Convert.ToInt32(args[1], invariantCulture))); }
protected virtual void ExplosionDamageThing(Explosion explosion, Thing t, List <Thing> damagedThings, IntVec3 cell) { if (t.def.category != ThingCategory.Mote && t.def.category != ThingCategory.Ethereal && !damagedThings.Contains(t)) { damagedThings.Add(t); if (def == DamageDefOf.Bomb && t.def == ThingDefOf.Fire && !t.Destroyed) { t.Destroy(); } else { float num = (!(t.Position == explosion.Position)) ? (t.Position - explosion.Position).AngleFlat : ((float)Rand.RangeInclusive(0, 359)); DamageDef damageDef = def; float amount = (float)explosion.GetDamageAmountAt(cell); float armorPenetrationAt = explosion.GetArmorPenetrationAt(cell); float angle = num; Thing instigator = explosion.instigator; ThingDef weapon = explosion.weapon; DamageInfo dinfo = new DamageInfo(damageDef, amount, armorPenetrationAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown, explosion.intendedTarget); if (def.explosionAffectOutsidePartsOnly) { dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); } BattleLogEntry_ExplosionImpact battleLogEntry_ExplosionImpact = null; Pawn pawn = t as Pawn; if (pawn != null) { battleLogEntry_ExplosionImpact = new BattleLogEntry_ExplosionImpact(explosion.instigator, t, explosion.weapon, explosion.projectile, def); Find.BattleLog.Add(battleLogEntry_ExplosionImpact); } DamageResult damageResult = t.TakeDamage(dinfo); damageResult.AssociateWithLog(battleLogEntry_ExplosionImpact); if (pawn != null && damageResult.wounded && pawn.stances != null) { pawn.stances.StaggerFor(95); } } } }
protected virtual void ExplosionDamageThing(Explosion explosion, Thing t, List <Thing> damagedThings, IntVec3 cell) { if (t.def.category == ThingCategory.Mote || t.def.category == ThingCategory.Ethereal) { return; } if (damagedThings.Contains(t)) { return; } damagedThings.Add(t); if (this.def == DamageDefOf.Bomb && t.def == ThingDefOf.Fire && !t.Destroyed) { t.Destroy(DestroyMode.Vanish); return; } float num; if (t.Position == explosion.Position) { num = (float)Rand.RangeInclusive(0, 359); } else { num = (t.Position - explosion.Position).AngleFlat; } DamageDef damageDef = this.def; float amount = (float)explosion.GetDamageAmountAt(cell); float armorPenetrationAt = explosion.GetArmorPenetrationAt(cell); float angle = num; Thing instigator = explosion.instigator; ThingDef weapon = explosion.weapon; DamageInfo dinfo = new DamageInfo(damageDef, amount, armorPenetrationAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown, explosion.intendedTarget); if (this.def.explosionAffectOutsidePartsOnly) { dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); } if (t.def.category == ThingCategory.Building) { int num2 = Mathf.RoundToInt(dinfo.Amount * this.def.explosionBuildingDamageFactor); dinfo.SetAmount((float)num2); } else if (t.def.category == ThingCategory.Plant) { int num3 = Mathf.RoundToInt(dinfo.Amount * this.def.explosionPlantDamageFactor); dinfo.SetAmount((float)num3); } BattleLogEntry_ExplosionImpact battleLogEntry_ExplosionImpact = null; Pawn pawn = t as Pawn; if (pawn != null) { battleLogEntry_ExplosionImpact = new BattleLogEntry_ExplosionImpact(explosion.instigator, t, explosion.weapon, explosion.projectile, this.def); Find.BattleLog.Add(battleLogEntry_ExplosionImpact); } DamageWorker.DamageResult damageResult = t.TakeDamage(dinfo); damageResult.AssociateWithLog(battleLogEntry_ExplosionImpact); if (pawn != null && damageResult.wounded && pawn.stances != null) { pawn.stances.StaggerFor(95); } }
protected virtual void ExplosionDamageThing(Explosion explosion, Thing t, List <Thing> damagedThings, IntVec3 cell) { if (t.def.category != ThingCategory.Mote && !damagedThings.Contains(t)) { damagedThings.Add(t); if (this.def == DamageDefOf.Bomb && t.def == ThingDefOf.Fire && !t.Destroyed) { t.Destroy(DestroyMode.Vanish); } else { float num = (!(t.Position == explosion.Position)) ? (t.Position - explosion.Position).AngleFlat : ((float)Rand.RangeInclusive(0, 359)); DamageDef damageDef = this.def; int damageAmountAt = explosion.GetDamageAmountAt(cell); float angle = num; Thing instigator = explosion.instigator; ThingDef weapon = explosion.weapon; DamageInfo dinfo = new DamageInfo(damageDef, damageAmountAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown); if (this.def.explosionAffectOutsidePartsOnly) { dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); } if (t.def.category == ThingCategory.Building) { int num2 = Mathf.RoundToInt((float)dinfo.Amount * this.def.explosionBuildingDamageFactor); damageDef = this.def; damageAmountAt = num2; angle = dinfo.Angle; instigator = explosion.instigator; weapon = dinfo.Weapon; dinfo = new DamageInfo(damageDef, damageAmountAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown); } BattleLogEntry_ExplosionImpact battleLogEntry_ExplosionImpact = null; if (t is Pawn) { battleLogEntry_ExplosionImpact = new BattleLogEntry_ExplosionImpact(explosion.instigator, t, explosion.weapon, explosion.projectile, this.def); Find.BattleLog.Add(battleLogEntry_ExplosionImpact); } t.TakeDamage(dinfo).InsertIntoLog(battleLogEntry_ExplosionImpact); } } }
public static IntVec3 RandomAdjacentCell8Way(this IntVec3 root) { return(root + GenAdj.AdjacentCells[Rand.RangeInclusive(0, 7)]); }
private static void GenerateTraits(Pawn pawn, PawnGenerationRequest request) { if (pawn.story == null) { return; } if (request.ForcedTraits != null) { foreach (TraitDef forcedTrait in request.ForcedTraits) { if (forcedTrait != null) { pawn.story.traits.GainTrait(new Trait(forcedTrait, 0, forced: true)); } } } if (pawn.story.childhood.forcedTraits != null) { List <TraitEntry> forcedTraits = pawn.story.childhood.forcedTraits; for (int i = 0; i < forcedTraits.Count; i++) { TraitEntry traitEntry = forcedTraits[i]; if (traitEntry.def == null) { Log.Error("Null forced trait def on " + pawn.story.childhood); } else if ((request.KindDef.disallowedTraits == null || !request.KindDef.disallowedTraits.Contains(traitEntry.def)) && !pawn.story.traits.HasTrait(traitEntry.def) && (request.ProhibitedTraits == null || !request.ProhibitedTraits.Contains(traitEntry.def))) { pawn.story.traits.GainTrait(new Trait(traitEntry.def, traitEntry.degree)); } } } if (pawn.story.adulthood != null && pawn.story.adulthood.forcedTraits != null) { List <TraitEntry> forcedTraits2 = pawn.story.adulthood.forcedTraits; for (int j = 0; j < forcedTraits2.Count; j++) { TraitEntry traitEntry2 = forcedTraits2[j]; if (traitEntry2.def == null) { Log.Error("Null forced trait def on " + pawn.story.adulthood); } else if ((request.KindDef.disallowedTraits == null || !request.KindDef.disallowedTraits.Contains(traitEntry2.def)) && !pawn.story.traits.HasTrait(traitEntry2.def) && (request.ProhibitedTraits == null || !request.ProhibitedTraits.Contains(traitEntry2.def))) { pawn.story.traits.GainTrait(new Trait(traitEntry2.def, traitEntry2.degree)); } } } int num = Rand.RangeInclusive(2, 3); if (request.AllowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn))) { Trait trait = new Trait(TraitDefOf.Gay, RandomTraitDegree(TraitDefOf.Gay)); pawn.story.traits.GainTrait(trait); } while (pawn.story.traits.allTraits.Count < num) { TraitDef newTraitDef = DefDatabase <TraitDef> .AllDefsListForReading.RandomElementByWeight((TraitDef tr) => tr.GetGenderSpecificCommonality(pawn.gender)); if (pawn.story.traits.HasTrait(newTraitDef) || (request.KindDef.disallowedTraits != null && request.KindDef.disallowedTraits.Contains(newTraitDef)) || (request.KindDef.requiredWorkTags != 0 && (newTraitDef.disabledWorkTags & request.KindDef.requiredWorkTags) != 0) || (newTraitDef == TraitDefOf.Gay && (!request.AllowGay || LovePartnerRelationUtility.HasAnyLovePartnerOfTheOppositeGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheOppositeGender(pawn))) || (request.ProhibitedTraits != null && request.ProhibitedTraits.Contains(newTraitDef)) || (request.Faction != null && Faction.OfPlayerSilentFail != null && request.Faction.HostileTo(Faction.OfPlayer) && !newTraitDef.allowOnHostileSpawn) || pawn.story.traits.allTraits.Any((Trait tr) => newTraitDef.ConflictsWith(tr)) || (newTraitDef.requiredWorkTypes != null && pawn.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes)) || pawn.WorkTagIsDisabled(newTraitDef.requiredWorkTags) || (newTraitDef.forcedPassions != null && pawn.workSettings != null && newTraitDef.forcedPassions.Any((SkillDef p) => p.IsDisabled(pawn.story.DisabledWorkTagsBackstoryAndTraits, pawn.GetDisabledWorkTypes(permanentOnly: true))))) { continue; } int degree = RandomTraitDegree(newTraitDef); if (!pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && (pawn.story.adulthood == null || !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree))) { Trait trait2 = new Trait(newTraitDef, degree); if (pawn.mindState == null || pawn.mindState.mentalBreaker == null || !((pawn.mindState.mentalBreaker.BreakThresholdMinor + trait2.OffsetOfStat(StatDefOf.MentalBreakThreshold)) * trait2.MultiplierOfStat(StatDefOf.MentalBreakThreshold) > 0.5f)) { pawn.story.traits.GainTrait(trait2); } } } }
private static void GenerateTraits(Pawn pawn, PawnGenerationRequest request) { if (pawn.story == null) { return; } if (pawn.story.childhood.forcedTraits != null) { List <TraitEntry> forcedTraits = pawn.story.childhood.forcedTraits; for (int i = 0; i < forcedTraits.Count; i++) { TraitEntry traitEntry = forcedTraits[i]; if (traitEntry.def == null) { Log.Error("Null forced trait def on " + pawn.story.childhood); } else if (!pawn.story.traits.HasTrait(traitEntry.def)) { pawn.story.traits.GainTrait(new Trait(traitEntry.def, traitEntry.degree, false)); } } } if (pawn.story.adulthood != null && pawn.story.adulthood.forcedTraits != null) { List <TraitEntry> forcedTraits2 = pawn.story.adulthood.forcedTraits; for (int j = 0; j < forcedTraits2.Count; j++) { TraitEntry traitEntry2 = forcedTraits2[j]; if (traitEntry2.def == null) { Log.Error("Null forced trait def on " + pawn.story.adulthood); } else if (!pawn.story.traits.HasTrait(traitEntry2.def)) { pawn.story.traits.GainTrait(new Trait(traitEntry2.def, traitEntry2.degree, false)); } } } int num = Rand.RangeInclusive(2, 3); if (request.AllowGay && (LovePartnerRelationUtility.HasAnyLovePartnerOfTheSameGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheSameGender(pawn))) { Trait trait = new Trait(TraitDefOf.Gay, PawnGenerator.RandomTraitDegree(TraitDefOf.Gay), false); pawn.story.traits.GainTrait(trait); } while (pawn.story.traits.allTraits.Count < num) { TraitDef newTraitDef = DefDatabase <TraitDef> .AllDefsListForReading.RandomElementByWeight((TraitDef tr) => tr.GetGenderSpecificCommonality(pawn)); if (!pawn.story.traits.HasTrait(newTraitDef)) { if (newTraitDef == TraitDefOf.Gay) { if (!request.AllowGay) { continue; } if (LovePartnerRelationUtility.HasAnyLovePartnerOfTheOppositeGender(pawn) || LovePartnerRelationUtility.HasAnyExLovePartnerOfTheOppositeGender(pawn)) { continue; } } if (request.Faction == null || Faction.OfPlayerSilentFail == null || !request.Faction.HostileTo(Faction.OfPlayer) || newTraitDef.allowOnHostileSpawn) { if (!pawn.story.traits.allTraits.Any((Trait tr) => newTraitDef.ConflictsWith(tr)) && (newTraitDef.conflictingTraits == null || !newTraitDef.conflictingTraits.Any((TraitDef tr) => pawn.story.traits.HasTrait(tr)))) { if (newTraitDef.requiredWorkTypes == null || !pawn.story.OneOfWorkTypesIsDisabled(newTraitDef.requiredWorkTypes)) { if (!pawn.story.WorkTagIsDisabled(newTraitDef.requiredWorkTags)) { int degree = PawnGenerator.RandomTraitDegree(newTraitDef); if (!pawn.story.childhood.DisallowsTrait(newTraitDef, degree) && (pawn.story.adulthood == null || !pawn.story.adulthood.DisallowsTrait(newTraitDef, degree))) { Trait trait2 = new Trait(newTraitDef, degree, false); if (pawn.mindState != null && pawn.mindState.mentalBreaker != null) { float num2 = pawn.mindState.mentalBreaker.BreakThresholdExtreme; num2 += trait2.OffsetOfStat(StatDefOf.MentalBreakThreshold); num2 *= trait2.MultiplierOfStat(StatDefOf.MentalBreakThreshold); if (num2 > 0.4f) { continue; } } pawn.story.traits.GainTrait(trait2); } } } } } } } }
public static bool TryFindRandomCellNear(IntVec3 root, Map map, int squareRadius, Predicate <IntVec3> validator, out IntVec3 result, int maxTries = -1) { int num = root.x - squareRadius; int num2 = root.x + squareRadius; int num3 = root.z - squareRadius; int num4 = root.z + squareRadius; int num5 = (num2 - num + 1) * (num4 - num3 + 1); if (num < 0) { num = 0; } if (num3 < 0) { num3 = 0; } if (num2 > map.Size.x) { num2 = map.Size.x; } if (num4 > map.Size.z) { num4 = map.Size.z; } int num6; bool flag; if (maxTries < 0 || maxTries >= num5) { num6 = 20; flag = false; } else { num6 = maxTries; flag = true; } for (int i = 0; i < num6; i++) { IntVec3 intVec = new IntVec3(Rand.RangeInclusive(num, num2), 0, Rand.RangeInclusive(num3, num4)); if (validator == null || validator(intVec)) { if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0.5f, "found"); } result = intVec; return(true); } if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0f, "inv"); } } if (flag) { result = root; return(false); } workingListX.Clear(); workingListZ.Clear(); for (int j = num; j <= num2; j++) { workingListX.Add(j); } for (int k = num3; k <= num4; k++) { workingListZ.Add(k); } workingListX.Shuffle(); workingListZ.Shuffle(); for (int l = 0; l < workingListX.Count; l++) { for (int m = 0; m < workingListZ.Count; m++) { IntVec3 intVec = new IntVec3(workingListX[l], 0, workingListZ[m]); if (validator(intVec)) { if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0.6f, "found2"); } result = intVec; return(true); } if (DebugViewSettings.drawDestSearch) { map.debugDrawer.FlashCell(intVec, 0.25f, "inv2"); } } } result = root; return(false); }
private DamageResult ApplyToPawn(DamageInfo dinfo, Pawn pawn) { DamageResult result = DamageResult.MakeNew(); if (dinfo.Amount <= 0) { return(result); } if (!DebugSettings.enablePlayerDamage && pawn.Faction == Faction.OfPlayer) { return(result); } Map mapHeld = pawn.MapHeld; bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned; if (dinfo.Def.spreadOut) { if (pawn.apparel != null) { List <Apparel> wornApparel = pawn.apparel.WornApparel; for (int num = wornApparel.Count - 1; num >= 0; num--) { this.CheckApplySpreadDamage(dinfo, wornApparel[num]); } } if (pawn.equipment != null && pawn.equipment.Primary != null) { this.CheckApplySpreadDamage(dinfo, pawn.equipment.Primary); } if (pawn.inventory != null) { ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer; for (int num2 = innerContainer.Count - 1; num2 >= 0; num2--) { this.CheckApplySpreadDamage(dinfo, innerContainer[num2]); } } } if (this.ShouldFragmentDamageForDamageType(dinfo)) { int num3 = Rand.RangeInclusive(3, 4); for (int i = 0; i < num3; i++) { DamageInfo dinfo2 = dinfo; dinfo2.SetAmount(dinfo.Amount / num3); this.ApplyDamageToPart(dinfo2, pawn, ref result); } } else { this.ApplyDamageToPart(dinfo, pawn, ref result); this.CheckDuplicateSmallPawnDamageToPartParent(dinfo, pawn, ref result); } if (result.wounded) { DamageWorker_AddInjury.PlayWoundedVoiceSound(dinfo, pawn); pawn.Drawer.Notify_DamageApplied(dinfo); DamageWorker_AddInjury.InformPsychology(dinfo, pawn); } if (result.headshot && pawn.Spawned) { IntVec3 position = pawn.Position; double x = (float)position.x + 1.0; IntVec3 position2 = pawn.Position; float y = (float)position2.y; IntVec3 position3 = pawn.Position; MoteMaker.ThrowText(new Vector3((float)x, y, (float)((float)position3.z + 1.0)), pawn.Map, "Headshot".Translate(), Color.white, -1f); if (dinfo.Instigator != null) { Pawn pawn2 = dinfo.Instigator as Pawn; if (pawn2 != null) { pawn2.records.Increment(RecordDefOf.Headshots); } } } if (result.deflected) { if (pawn.health.deflectionEffecter == null) { pawn.health.deflectionEffecter = EffecterDefOf.ArmorDeflect.Spawn(); } pawn.health.deflectionEffecter.Trigger(pawn, pawn); } else if (spawnedOrAnyParentSpawned) { ImpactSoundUtility.PlayImpactSound(pawn, dinfo.Def.impactSoundType, mapHeld); } return(result); }
public static IntVec3 RandomAdjacentCellCardinal(this IntVec3 root) { return(root + GenAdj.CardinalDirections[Rand.RangeInclusive(0, 3)]); }
private static int FinalLevelOfSkill(Pawn pawn, SkillDef sk) { float num = (!sk.usuallyDefinedInBackstories) ? Rand.ByCurve(LevelRandomCurve) : ((float)Rand.RangeInclusive(0, 4)); foreach (Backstory item in from bs in pawn.story.AllBackstories where bs != null select bs) { foreach (KeyValuePair <SkillDef, int> item2 in item.skillGainsResolved) { if (item2.Key == sk) { num += (float)item2.Value * Rand.Range(1f, 1.4f); } } } for (int i = 0; i < pawn.story.traits.allTraits.Count; i++) { int value = 0; if (pawn.story.traits.allTraits[i].CurrentData.skillGains.TryGetValue(sk, out value)) { num += (float)value; } } float num2 = Rand.Range(1f, AgeSkillMaxFactorCurve.Evaluate((float)pawn.ageTracker.AgeBiologicalYears)); num *= num2; num = LevelFinalAdjustmentCurve.Evaluate(num); return(Mathf.Clamp(Mathf.RoundToInt(num), 0, 20)); }