public BossPawnThingDef(ThingDef def, float points, Dictionary <BuffCat, float> buffMultipliers) { // Define if bugs are reported //public List<StatModifier> equippedStatOffsets; //startingHpRange //public List<CompProperties> comps; foreach (FieldInfo field in def.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)) { field.SetValue(this, field.GetValue(def)); } defName = "Level" + points + "Boss" + def.defName; label = "Boss " + label; statBases = new List <StatModifier>(); size = new IntVec2( def.size.x * (int)Math.Max((buffMultipliers[BuffCat.Size] * BossFightSettings.SizeFinalScalar), 1), def.size.z * (int)Math.Max((buffMultipliers[BuffCat.Size] * BossFightSettings.SizeFinalScalar), 1) ); BossifyTools(def, buffMultipliers); BossifyStats(def, buffMultipliers); BossifyRace(def, buffMultipliers); ResolveReferences(); }
private static ThingDef BaseSlimeDef(SlimeGeneratorDef slimeGenerator) { var thingDef = new ThingDef(); foreach (var fieldInfo in typeof(ThingDef).GetFields()) { try { var newField = thingDef.GetType().GetField(fieldInfo.Name); newField.SetValue(thingDef, fieldInfo.GetValue(slimeGenerator.slimeTypeDef.originThingDef)); } catch { } } thingDef.defName = slimeGenerator.defName; thingDef.label = slimeGenerator.label; if (slimeGenerator.description?.Length > 0) { thingDef.description = slimeGenerator.description; } else { thingDef.description = slimeGenerator.slimeTypeDef.originThingDef.description; } AssignNewVariables(ref thingDef, slimeGenerator.slimeTypeDef.originThingDef); AdjustStatBases(ref thingDef, slimeGenerator.statModifiers); if (slimeGenerator.butcherThings.butcherBasic != null) { thingDef.butcherProducts = slimeGenerator.butcherThings.butcherBasic; } if (slimeGenerator.butcherThings.butcherSpecialized != null) { var compProperties = new CompProperties_ExtraButcherProducts { butcherSpecialized = slimeGenerator.butcherThings.butcherSpecialized }; thingDef.comps.Add(compProperties); } if (slimeGenerator.slimeTypeDef.growthStages != null) { var compProperties = new CompProperties_ExtraGraphics { growthStages = slimeGenerator.slimeTypeDef.growthStages, totalAbsorbableMass = slimeGenerator.slimeTypeDef.totalAbsorbableMass }; thingDef.comps.Add(compProperties); } return(thingDef); }
internal static ThingDef CreateNanoBedDefFromSupportedBed(this ThingDef bed, Action <ThingDef> fnAdditionalProcessing, List <ThingDef> linkableBuildings, List <CompProperties_Facility> facilities) { Type typeRimworldBed = typeof(Building_Bed); Type bedToClone = bed.GetType(); if (typeRimworldBed.IsAssignableFrom(bedToClone)) { throw new Exception("Type [" + bedToClone.Name + "] is not supported."); } FieldInfo[] fields = typeof(ThingDef).GetFields(BindingFlags.Public | BindingFlags.Instance); ThingDef nBed = new ThingDef(); foreach (FieldInfo field in fields) { field.SetValue(nBed, field.GetValue(bed)); } nBed.comps = new List <CompProperties>(); for (int i = 0; i < bed.comps.Count; i++) { ConstructorInfo constructor = bed.comps[i].GetType().GetConstructor(Type.EmptyTypes); CompProperties comp = (CompProperties)constructor.Invoke(null); fields = comp.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo field in fields) { field.SetValue(comp, field.GetValue(bed.comps[i])); } nBed.comps.Add(comp); } nBed.statBases.Add(new StatModifier() { stat = StatDef.Named("Ogre_NanoApparelRate"), value = 0 }); nBed.statBases.Add(new StatModifier() { stat = StatDef.Named("Ogre_NanoWeaponsRate"), value = 0 }); CompProperties_Power power = new CompProperties_Power(); power.compClass = typeof(CompPowerTrader); power.basePowerConsumption = 60f; power.shortCircuitInRain = false; nBed.comps.Add(power); CompProperties_Flickable flick = new CompProperties_Flickable(); flick.compClass = typeof(CompFlickable); nBed.comps.Add(flick); CompProperties_Refuelable fuel = new CompProperties_Refuelable(); fuel.fuelConsumptionRate = 0; fuel.fuelCapacity = 25.0f * bed.size.x; // same way it calculates in BedUtility fuel.consumeFuelOnlyWhenUsed = true; fuel.fuelFilter = new ThingFilter(); fuel.fuelFilter.SetAllow(ThingDef.Named("Ogre_NanoTechFuel"), true); nBed.comps.Add(fuel); Dictionary <string, int> cost = new Dictionary <string, int>() { { "ComponentIndustrial", 1 }, { "Steel", 5 } }; if (nBed.costList == null) { nBed.costList = new List <ThingDefCountClass>(); } Dictionary <string, ThingDefCountClass> current = nBed.costList.ToDictionary(x => x.thingDef.defName, y => y); foreach (string item in cost.Keys) { ThingDefCountClass count = null; if (!current.TryGetValue(item, out count)) { count = new ThingDefCountClass(ThingDef.Named(item), (cost[item] * nBed.size.x)); nBed.costList.Add(count); } else { count.count += (cost[item] * nBed.size.x); } } bool found = false; nBed.researchPrerequisites = new List <ResearchProjectDef>(); if (bed.researchPrerequisites != null && bed.researchPrerequisites.Count > 0) { foreach (ResearchProjectDef d in bed.researchPrerequisites) { if (d.defName == "Ogre_NanoTech") { found = true; } nBed.researchPrerequisites.Add(d); } } if (!found) { nBed.researchPrerequisites.Add(ResearchProjectDef.Named("Ogre_NanoTech")); } nBed.defName += "_NanoBed"; nBed.description += "\n\n" + TranslatorFormattedStringExtensions.Translate("NanoTech.Description.Short"); nBed.label = TranslatorFormattedStringExtensions.Translate("NanoTech.ModName.Short") + " " + nBed.label; nBed.thingClass = typeof(NanoBed); nBed.tradeability = Tradeability.None; nBed.scatterableOnMapGen = false; nBed.tickerType = TickerType.Rare; nBed.constructionSkillPrerequisite = bed.constructionSkillPrerequisite < 2 ? 2 : bed.constructionSkillPrerequisite; nBed.uiIconScale = 0.9f; nBed.techLevel = TechLevel.Industrial; nBed.shortHash = 0; // as of 1.3 without this, it wont // show the out of fuel icon nBed.drawerType = DrawerType.RealtimeOnly; nBed.designationCategory = DefDatabase <DesignationCategoryDef> .AllDefsListForReading.Find(x => x.defName == "Ogre_NanoRepairTech_DesignationCategory"); MethodInfo newBluePrintDef = typeof(RimWorld.ThingDefGenerator_Buildings).GetMethod("NewBlueprintDef_Thing", BindingFlags.Static | BindingFlags.NonPublic); nBed.blueprintDef = (ThingDef)newBluePrintDef.Invoke(null, new object[] { nBed, false, null }); MethodInfo newFrameDef = typeof(RimWorld.ThingDefGenerator_Buildings).GetMethod("NewFrameDef_Thing", BindingFlags.Static | BindingFlags.NonPublic); nBed.frameDef = (ThingDef)newFrameDef.Invoke(null, new object[] { nBed }); if (bed.building.bed_humanlike) { CompProperties_AffectedByFacilities abf = nBed.GetCompProperties <CompProperties_AffectedByFacilities>(); if (abf == null) { abf = new CompProperties_AffectedByFacilities(); nBed.comps.Add(abf); } if (abf.linkableFacilities == null) { abf.linkableFacilities = new List <ThingDef>(); } abf.linkableFacilities.AddRange(linkableBuildings); foreach (CompProperties_Facility f in facilities) { f.linkableBuildings.Add(nBed); } } if (fnAdditionalProcessing != null) { fnAdditionalProcessing.Invoke(nBed); } typeof(ShortHashGiver).GetMethod("GiveShortHash", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { nBed, typeof(ThingDef) }); return(nBed); }
public static bool IsAlienRace(ThingDef raceDef) { FieldInfo alienRaceField = raceDef.GetType().GetField("alienRace", BindingFlags.Public | BindingFlags.Instance); return(alienRaceField != null); }
private static void BattleLogEntry_WeaponDefGrammarPrefix(Thing initiator, ref ThingDef weaponDef) { MethodInfo MI_GiveShortHash = AccessTools.Method(type: typeof(ShortHashGiver), name: "GiveShortHash", parameters: new Type[] { typeof(Def), typeof(Type) }); if (initiator is Pawn pawn) { Verb usedVerb = pawn.GetComp <VEF_Comp_Pawn_RangedVerbs>().CurRangedVerb; if (usedVerb == null) { usedVerb = pawn.GetComp <VEF_Comp_Pawn_RangedVerbs>().TryGetRangedVerb((pawn.mindState == null) ? null : pawn.mindState.enemyTarget); } if (usedVerb == null) { ThingDef tempThingDef = new ThingDef() { defName = "tempThingDef :: " + pawn.Label, label = "VerbError".Translate(), thingClass = typeof(ThingWithComps), category = ThingCategory.Item }; MI_GiveShortHash.Invoke(null, new object[] { tempThingDef, tempThingDef.GetType() }); // Traverse.Create(tempThingDef).Field("verbs").SetValue(new List<VerbProperties>() { usedVerb.verbProps }); weaponDef = tempThingDef; return; } else if (pawn.equipment != null && pawn.equipment.Primary != null && usedVerb.EquipmentSource != null && usedVerb.EquipmentSource.def == pawn.equipment.Primary.def) { return; } else if (usedVerb.EquipmentSource != null) { weaponDef = usedVerb.EquipmentSource.def; } else if (usedVerb.HediffSource != null) { ThingDef tempThingDef = new ThingDef() { defName = "tempThingDef :: " + usedVerb.HediffSource.def.label, label = (usedVerb.verbProps.label == usedVerb.HediffSource.def.label) ? usedVerb.HediffSource.def.label : usedVerb.verbProps.label, thingClass = typeof(ThingWithComps), category = ThingCategory.Item }; MI_GiveShortHash.Invoke(null, new object[] { tempThingDef, tempThingDef.GetType() }); Traverse.Create(tempThingDef).Field("verbs").SetValue(new List <VerbProperties>() { usedVerb.verbProps }); weaponDef = tempThingDef; } else { if (usedVerb.verbProps.label == pawn.def.label) { weaponDef = pawn.def; } else { ThingDef tempThingDef = new ThingDef() { defName = "tempThingDef :: " + pawn.Label, label = usedVerb.verbProps.label, thingClass = typeof(ThingWithComps), category = ThingCategory.Item }; MI_GiveShortHash.Invoke(null, new object[] { tempThingDef, tempThingDef.GetType() }); Traverse.Create(tempThingDef).Field("verbs").SetValue(new List <VerbProperties>() { usedVerb.verbProps }); weaponDef = tempThingDef; } } } return; }