private static void Initialize <D>(DefStat <D> s, StringBuilder sb) where D : Def, new() { if (s != null) { try { Log.Message($"Initialize {s.defName} and IParentStat? {s is IParentStat}"); if (s.Initialize() && s is IParentStat p) { Log.Message($"Auto Apply? {Defs.ApplyStatsAutoDefs.Contains(s.Def)}"); if (Defs.ApplyStatsAutoDefs.Contains(s.Def)) { try { p.ApplyStats(s.Def); sb.AppendLine($"- Def: {s.defName}"); } catch (Exception e) { Log.Error($"Failed to apply settings to Def [{s.defName}] due to {e.Message}"); } } } else { Log.Warning($"Unable to initialize Def {s.defName}\n{s.ToString()}"); } } catch (Exception e) { Log.Error($"Failed to load Def [{s.defName}] due to {e.Message}\n{s.ToString()}"); } } }
public ExtraDamageStats(ExtraDamage d) { this.damageDefStat = Util.AssignDefStat(d.def); this.amount = d.amount; this.armorPenetration = d.armorPenetration; this.chance = d.chance; }
public static D AssignDef <D>(DefStat <D> from) where D : Def, new() { if (from == null) { return(null); } return(from.Def); }
public static void AssignDef <D>(DefStat <D> from, out D def) where D : Def, new() { if (from == null) { def = null; } else { def = from.Def; } }
public static void AssignDefStat <D>(D def, out DefStat <D> stat) where D : Def, new() { if (def == null) { stat = null; } else { stat = new DefStat <D>(def); } }
public StoryTellerDefStats(StorytellerDef d) : base(d) { this.listOrder = d.listOrder; this.listVisible = d.listVisible; this.tutorialMode = d.tutorialMode; this.disableAdaptiveTraining = d.disableAdaptiveTraining; this.disableAlerts = d.disableAlerts; this.disablePermadeath = d.disablePermadeath; this.adaptDaysMin = d.adaptDaysMin; this.adaptDaysMax = d.adaptDaysMax; this.adaptDaysGameStartGraceDays = d.adaptDaysGameStartGraceDays; this.populationIntentFactorFromPopCurve = Util.Assign(d.populationIntentFactorFromPopCurve, v => new SimpleCurveStats(v)); this.populationIntentFactorFromPopAdaptDaysCurve = Util.Assign(d.populationIntentFactorFromPopAdaptDaysCurve, v => new SimpleCurveStats(v)); this.pointsFactorFromDaysPassed = Util.Assign(d.pointsFactorFromDaysPassed, v => new SimpleCurveStats(v)); this.pointsFactorFromAdaptDays = Util.Assign(d.pointsFactorFromAdaptDays, v => new SimpleCurveStats(v)); this.adaptDaysLossFromColonistLostByPostPopulation = Util.Assign(d.adaptDaysLossFromColonistLostByPostPopulation, v => new SimpleCurveStats(v)); this.adaptDaysLossFromColonistViolentlyDownedByPopulation = Util.Assign(d.adaptDaysLossFromColonistViolentlyDownedByPopulation, v => new SimpleCurveStats(v)); this.adaptDaysGrowthRateCurve = Util.Assign(d.adaptDaysGrowthRateCurve, v => new SimpleCurveStats(v)); this.forcedDifficulty = Util.AssignDefStat(d.forcedDifficulty); Util.Populate(out this.comps, d.comps, v => new StorytellerCompPropertiesStats(v)); }
public BiomeDefStats(BiomeDef d) : base(d) { this.canBuildBase = d.canBuildBase; this.canAutoChoose = d.canAutoChoose; this.allowRoads = d.allowRoads; this.allowRivers = d.allowRivers; this.animalDensity = d.animalDensity; this.plantDensity = d.plantDensity; this.diseaseMtbDays = d.diseaseMtbDays; this.settlementSelectionWeight = d.settlementSelectionWeight; this.impassable = d.impassable; this.hasVirtualPlants = d.hasVirtualPlants; this.forageability = d.forageability; if (d.foragedFood != null) { this.foragedFood = new DefStat <ThingDef>(d.foragedFood); } this.wildPlantsCareAboutLocalFertility = d.wildPlantsCareAboutLocalFertility; this.wildPlantRegrowDays = d.wildPlantRegrowDays; this.movementDifficulty = d.movementDifficulty; this.hasBedrock = d.hasBedrock; if (d.baseWeatherCommonalities != null) { this.weatherCommonalities = new List <FloatValueDefStat <WeatherDef> >(d.baseWeatherCommonalities.Count); foreach (var v in d.baseWeatherCommonalities) { this.weatherCommonalities.Add(new FloatValueDefStat <WeatherDef>(v.weather) { value = v.commonality }); } } if (d.terrainsByFertility != null) { this.terrainsByFertility = new List <MinMaxFloatDefStat <TerrainDef> >(d.terrainsByFertility.Count); foreach (var v in d.terrainsByFertility) { this.terrainsByFertility.Add(new MinMaxFloatDefStat <TerrainDef>(v.terrain) { Min = v.min, Max = v.max }); } } if (d.soundsAmbient != null) { this.soundsAmbient = new List <DefStat <SoundDef> >(d.soundsAmbient.Count); foreach (var v in d.soundsAmbient) { this.soundsAmbient.Add(new DefStat <SoundDef>(v)); } } if (d.terrainPatchMakers != null) { this.terrainPatchMakers = new List <TerrainPatchMakerStats>(d.terrainPatchMakers.Count); foreach (var v in d.terrainPatchMakers) { this.terrainPatchMakers.Add(new TerrainPatchMakerStats(v)); } } List <BiomePlantRecord> plants = GetWildPlants(base.Def); if (plants != null) { this.wildPlants = new List <FloatValueDefStat <ThingDef> >(plants.Count); foreach (var v in plants) { this.wildPlants.Add(new FloatValueDefStat <ThingDef>(v.plant) { value = v.commonality }); } } List <BiomeAnimalRecord> animals = GetWildAnimals(base.Def); if (animals != null) { this.wildAnimals = new List <FloatValueDefStat <PawnKindDef> >(animals.Count); foreach (var v in animals) { this.wildAnimals.Add(new FloatValueDefStat <PawnKindDef>(v.animal) { value = v.commonality }); } } List <BiomeDiseaseRecord> diseases = GetDiseases(base.Def); if (diseases != null) { this.diseases = new List <FloatValueDoubleDefStat <IncidentDef, BiomeDef> >(diseases.Count); foreach (var v in diseases) { this.diseases.Add(new FloatValueDoubleDefStat <IncidentDef, BiomeDef>(v.diseaseInc, v.biome) { value = v.commonality }); } } List <ThingDef> allowedPackAnimals = GetAllowedPackAnimals(base.Def); if (d != null) { this.allowedPackAnimals = new List <DefStat <PawnKindDef> >(allowedPackAnimals.Count); foreach (var v in allowedPackAnimals) { this.allowedPackAnimals.Add(new DefStat <PawnKindDef>(v.race.AnyPawnKind)); } } }
public StorytellerCompPropertiesStats(StorytellerCompProperties p) { this.compClass = p.compClass.FullName; this.minDaysPassed = p.minDaysPassed; this.minIncChancePopulationIntentFactor = p.minIncChancePopulationIntentFactor; Util.Populate(out allowedTargetTags, p.allowedTargetTags, d => new DefStat <IncidentTargetTagDef>(d)); Util.Populate(out disallowedTargetTags, p.disallowedTargetTags, d => new DefStat <IncidentTargetTagDef>(d)); switch (this.compClass) { case "RimWorld.StorytellerComp_CategoryIndividualMTBByBiome": if (p is StorytellerCompProperties_CategoryIndividualMTBByBiome cb) { this.category = Util.AssignDefStat(cb.category); this.applyCaravanVisibility = cb.applyCaravanVisibility; } break; case "RimWorld.StorytellerComp_CategoryMTB": if (p is StorytellerCompProperties_CategoryMTB cm) { this.category = Util.AssignDefStat(cm.category); this.mtbDays = cm.mtbDays; this.mtbDaysFactorByDaysPassedCurve = Util.Assign(cm.mtbDaysFactorByDaysPassedCurve, v => new SimpleCurveStats(v)); } break; case "RimWorld.StorytellerComp_DeepDrillInfestation": if (p is StorytellerCompProperties_DeepDrillInfestation cd) { this.baseMtbDaysPerDrill = cd.baseMtbDaysPerDrill; } break; case "RimWorld.StorytellerComp_Disease": if (p is StorytellerCompProperties_Disease d) { this.category = Util.AssignDefStat(d.category); } break; case "RimWorld.StorytellerComp_FactionInteraction": if (p is StorytellerCompProperties_FactionInteraction fi) { this.incident = Util.AssignDefStat(fi.incident); this.baseIncidentsPerYear = fi.baseIncidentsPerYear; this.minSpacingDays = fi.minSpacingDays; this.minDanger = fi.minDanger; this.fullAlliesOnly = fi.fullAlliesOnly; } break; case "RimWorld.StorytellerComp_OnOffCycle": if (p is StorytellerCompProperties_OnOffCycle ooc) { this.category = Util.AssignDefStat(GetCategory(ooc)); this.onDays = ooc.onDays; this.offDays = ooc.offDays; this.minSpacingDays = ooc.minDaysPassed; this.numIncidentsRange = Util.Assign(ooc.numIncidentsRange, v => new MinMaxFloatStats(v)); this.acceptFractionByDaysPassedCurve = Util.Assign(ooc.acceptFractionByDaysPassedCurve, v => new SimpleCurveStats(v)); this.acceptPercentFactorPerThreatPointsCurve = Util.Assign(ooc.acceptPercentFactorPerThreatPointsCurve, v => new SimpleCurveStats(v)); this.incident = Util.AssignDefStat(ooc.incident); // TODO this.applyRaidBeaconThreatMtbFactor = ooc.applyRaidBeaconThreatMtbFactor; this.forceRaidEnemyBeforeDaysPassed = ooc.forceRaidEnemyBeforeDaysPassed; } break; case "RimWorld.StorytellerComp_RandomMain": if (p is StorytellerCompProperties_RandomMain rm) { this.mtbDays = rm.mtbDays; Util.Populate(out this.categoryWeights, rm.categoryWeights, v => new FloatValueDefStat <IncidentCategoryDef>(v.category, v.weight)); this.maxThreatBigIntervalDays = rm.maxThreatBigIntervalDays; this.randomPointsFactorRange = Util.Assign(rm.randomPointsFactorRange, v => new MinMaxFloatStats(v)); this.skipThreatBigIfRaidBeacon = rm.skipThreatBigIfRaidBeacon; } break; case "RimWorld.StorytellerComp_SingleMTB": if (p is StorytellerCompProperties_SingleMTB smtb) { this.incident = Util.AssignDefStat(smtb.incident); this.mtbDays = smtb.mtbDays; } break; case "RimWorld.StorytellerComp_Triggered": if (p is StorytellerCompProperties_Triggered t) { this.incident = Util.AssignDefStat(t.incident); this.delayTicks = t.delayTicks; } break; case "RimWorld.StorytellerCompProperties_RefiringUniqueQuest": if (p is StorytellerCompProperties_RefiringUniqueQuest ruq) { this.incident = Util.AssignDefStat(ruq.incident); this.refireEveryDays = ruq.refireEveryDays; } break; case "RimWorld.StorytellerCompProperties_SingleOnceFixed": if (p is StorytellerCompProperties_SingleOnceFixed sof) { this.incident = Util.AssignDefStat(sof.incident); this.fireAfterDaysPassed = sof.fireAfterDaysPassed; } break; case "RimWorld.StorytellerComp_ClassicIntro": case "RimWorld.StorytellerComp_ShipChunkDrop": case "RimWorld.StorytellerCompProperties_RandomQuest": case "RimWorld.StorytellerComp_SingleOnceFixed": case "RimWorld.StorytellerComp_RefiringUniqueQuest": case "RimWorld.StorytellerComp_ThreatsGenerator": case "RimWorld.StorytellerComp_RandomQuest": // Do nothing break; default: Log.Warning("Unknown StorytellerProperty type of " + this.compClass); break; } }
public static bool AreEqual <T>(DefStat <T> l, DefStat <T> r) where T : Def, new() { return (l == null && r == null || (l != null && r != null && l.Equals(r))); }
public PawnKindDefStats(PawnKindDef d) : base(d) { if (d.race != null) { this.race = new DefStat <ThingDef>(d.race); } if (d.defaultFactionType != null) { this.defaultFactionType = new DefStat <FactionDef>(d.defaultFactionType); } if (d.forcedTraits?.Count > 0) { this.forcedTraits = new List <TraitRequirementStat>(d.forcedTraits.Count); foreach (var t in d.forcedTraits) { this.forcedTraits.Add(new TraitRequirementStat(t)); } } if (d.disallowedTraits?.Count > 0) { this.disallowedTraits = new List <DefStat <TraitDef> >(d.disallowedTraits.Count); foreach (var t in d.disallowedTraits) { this.disallowedTraits.Add(new DefStat <TraitDef>(t)); } } this.minGenerationAge = d.minGenerationAge; this.maxGenerationAge = d.maxGenerationAge; if (d.fixedGender != null) { this.fixedGender = d.fixedGender.Value; } this.allowOldAgeInjuries = d.allowOldAgeInjuries; this.destroyGearOnDrop = d.destroyGearOnDrop; this.defendPointRadius = d.defendPointRadius; this.factionHostileOnKill = d.factionHostileOnKill; this.factionHostileOnDeath = d.factionHostileOnDeath; if (d.initialResistanceRange != null) { this.initialResistanceRange = d.initialResistanceRange.Value; } if (d.initialWillRange != null) { this.initialWillRange = d.initialWillRange.Value; } //this.allowRoyalRoomRequirements = true; //this.allowRoyalApparelRequirements = true; this.isFighter = d.isFighter; this.combatPower = d.combatPower; this.canArriveManhunter = d.canArriveManhunter; this.canBeSapper = d.canBeSapper; this.isGoodBreacher = d.isGoodBreacher; this.baseRecruitDifficulty = d.baseRecruitDifficulty; this.aiAvoidCover = d.aiAvoidCover; this.fleeHealthThresholdRange = new FloatRange(d.fleeHealthThresholdRange.min, d.fleeHealthThresholdRange.max); this.acceptArrestChanceFactor = d.acceptArrestChanceFactor; this.gearHealthRange = new FloatRange(d.gearHealthRange.min, d.gearHealthRange.max); this.weaponMoney = new FloatRange(d.weaponMoney.min, d.weaponMoney.max); if (d.weaponTags != null) { this.weaponTags = new List <string>(d.weaponTags.Count); foreach (var s in d.weaponTags) { this.weaponTags.Add(s); } } if (d.weaponStuffOverride != null) { this.weaponStuffOverride = new DefStat <ThingDef>(d.weaponStuffOverride); } if (d.weaponStyleDef != null) { this.weaponStyleDef = new DefStat <ThingStyleDef>(d.weaponStyleDef); } this.apparelMoney = new FloatRange(d.apparelMoney.min, d.apparelMoney.max); if (d.apparelRequired != null) { this.apparelRequired = new List <DefStat <ThingDef> >(d.apparelRequired.Count); foreach (var a in d.apparelRequired) { this.apparelRequired.Add(new DefStat <ThingDef>(a)); } } if (d.apparelTags != null) { this.apparelTags = new List <string>(d.apparelTags.Count); foreach (var s in d.apparelTags) { this.apparelTags.Add(s); } } if (d.apparelDisallowTags != null) { this.apparelDisallowTags = new List <string>(d.apparelDisallowTags.Count); foreach (var s in d.apparelDisallowTags) { this.apparelDisallowTags.Add(s); } } this.apparelAllowHeadgearChance = d.apparelAllowHeadgearChance; this.apparelIgnoreSeasons = d.apparelIgnoreSeasons; this.ignoreFactionApparelStuffRequirements = d.ignoreFactionApparelStuffRequirements; if (d.techHediffsRequired != null) { this.techHediffsRequired = new List <DefStat <ThingDef> >(d.techHediffsRequired.Count); foreach (var a in d.techHediffsRequired) { this.techHediffsRequired.Add(new DefStat <ThingDef>(a)); } } this.techHediffsMoney = new FloatRange(d.techHediffsMoney.min, d.techHediffsMoney.max); if (d.techHediffsTags != null) { this.techHediffsTags = new List <string>(d.techHediffsTags.Count); foreach (var s in d.techHediffsTags) { this.techHediffsTags.Add(s); } } if (d.techHediffsDisallowTags != null) { this.techHediffsDisallowTags = new List <string>(d.techHediffsDisallowTags.Count); foreach (var s in d.techHediffsDisallowTags) { this.techHediffsDisallowTags.Add(s); } } this.techHediffsChance = d.techHediffsChance; this.techHediffsMaxAmount = d.techHediffsMaxAmount; this.biocodeWeaponChance = d.biocodeWeaponChance; this.chemicalAddictionChance = d.chemicalAddictionChance; this.combatEnhancingDrugsChance = d.combatEnhancingDrugsChance; this.combatEnhancingDrugsCount = new IntRange(d.combatEnhancingDrugsCount.min, d.combatEnhancingDrugsCount.max); if (d.forcedAddictions != null) { this.forcedAddictions = new List <DefStat <ChemicalDef> >(d.forcedAddictions.Count); foreach (var a in d.forcedAddictions) { this.forcedAddictions.Add(new DefStat <ChemicalDef>(a)); } } this.trader = d.trader; this.extraSkillLevels = d.extraSkillLevels; this.minTotalSkillLevels = d.minTotalSkillLevels; this.minBestSkillLevel = d.minBestSkillLevel; this.wildGroupSize = new IntRange(d.wildGroupSize.min, d.wildGroupSize.max); this.ecoSystemWeight = d.ecoSystemWeight; }
public ThingDefCountClassStats(ThingDefCountClass t) { this.ThingDef = new DefStat <ThingDef>(t.thingDef); this.Count = t.count; }