public static ReplaceFrame PlaceReplaceFrame(Thing oldThing, ThingDef stuff) { ThingDef replaceFrameDef = ThingDefGenerator_ReplaceFrame.ReplaceFrameDefFor(oldThing.def); if (replaceFrameDef == null) { return(null); } if (oldThing.Position.GetFirstThing(oldThing.Map, replaceFrameDef) != null) { return(null); } ReplaceFrame replaceFrame = (ReplaceFrame)ThingMaker.MakeThing(replaceFrameDef, stuff); //QualityBuilder if (QBTypes.qbDesDef != null && replaceFrame.def.HasComp(QBTypes.compQBType)) { oldThing.Map.designationManager.AddDesignation(new Designation(replaceFrame, QBTypes.qbDesDef)); } replaceFrame.SetFactionDirect(Faction.OfPlayer); replaceFrame.oldThing = oldThing; replaceFrame.oldStuff = oldThing.Stuff; GenSpawn.Spawn(replaceFrame, oldThing.Position, oldThing.Map, oldThing.Rotation); return(replaceFrame); }
public static ReplaceFrame PlaceReplaceFrame(Thing oldThing, ThingDef stuff) { ThingDef replaceFrameDef = ThingDefGenerator_ReplaceFrame.ReplaceFrameDefFor(oldThing.def); if (replaceFrameDef == null) { return(null); } if (oldThing.Position.GetFirstThing(oldThing.Map, replaceFrameDef) != null) { return(null); } ReplaceFrame replaceFrame = (ReplaceFrame)ThingMaker.MakeThing(replaceFrameDef, stuff); //QualityBuilder if (DefDatabase <DesignationDef> .GetNamed("SkilledBuilder", false) is DesignationDef d && AccessTools.TypeByName("CompQualityBuilder") is Type qbType && replaceFrame.def.HasComp(qbType)) { oldThing.Map.designationManager.AddDesignation(new Designation(replaceFrame, d)); } replaceFrame.SetFactionDirect(Faction.OfPlayer); replaceFrame.oldThing = oldThing; replaceFrame.oldStuff = oldThing.Stuff; GenSpawn.Spawn(replaceFrame, oldThing.Position, oldThing.Map, oldThing.Rotation); return(replaceFrame); }
static ModStartup() { //Hugslibs-added defs will be queued up before this Static Constructor //So queue replace frame generation after that LongEventHandler.QueueLongEvent(() => ThingDefGenerator_ReplaceFrame.AddReplaceFrames(), null, true, null); LongEventHandler.QueueLongEvent(() => CoolersOverWalls.DesignatorBuildDropdownStuffFix.SanityCheck(), null, true, null); }
/* * public static void Postfix() * { * // would be nice but mods don't add defs early enough. * // I mean they assume blueprints/frames don't need to be implied from them * // But replace frames sure can! * AddReplaceFrames(false); * } */ public static void AddReplaceFrames(bool addShortHash = true) { IEnumerable <ThingDef> enumerable = ThingDefGenerator_ReplaceFrame.ImpliedReplaceFrameDefs(); foreach (ThingDef current in enumerable) { if (addShortHash) //Wouldn't need this if other mods added defs earlier. Oh well. { AccessTools.Method(typeof(ShortHashGiver), "GiveShortHash").Invoke(null, new object[] { current, typeof(ThingDef) }); } ; current.PostLoad(); DefDatabase <ThingDef> .Add(current); } }
public static ThingDef NewReplaceFrameDef_Thing(ThingDef def) { ThingDef thingDef = ThingDefGenerator_ReplaceFrame.BaseFrameDef(); thingDef.defName = def.defName + "_ReplaceStuff"; thingDef.label = def.label + "TD.ReplacingTag".Translate(); //Not entirely sure if this is needed since ReplaceFrame.Label doesn't use it, but, this is vanilla Frame code. thingDef.size = def.size; thingDef.SetStatBaseValue(StatDefOf.MaxHitPoints, (float)def.BaseMaxHitPoints * 0.25f); thingDef.SetStatBaseValue(StatDefOf.Beauty, -8f); thingDef.fillPercent = 0.2f; thingDef.pathCost = 10; thingDef.description = def.description; thingDef.passability = def.passability; thingDef.selectable = def.selectable; thingDef.constructEffect = def.constructEffect; thingDef.building.isEdifice = false; thingDef.constructionSkillPrerequisite = def.constructionSkillPrerequisite; thingDef.clearBuildingArea = false; thingDef.drawPlaceWorkersWhileSelected = def.drawPlaceWorkersWhileSelected; thingDef.stuffCategories = def.stuffCategories; //Support QualityBuilder if (QBTypes.compPropQBType != null) { if (def.HasComp(typeof(CompQuality)) && def.building != null) { thingDef.comps.Add((CompProperties)Activator.CreateInstance(QBTypes.compPropQBType)); } } thingDef.entityDefToBuild = def; //def.replaceFrameDef = thingDef; //Dictionary instead thingDef.modContentPack = LoadedModManager.GetMod <Mod>().Content; return(thingDef); }
static ModStartup() { //Hugslibs-added defs will be queued up before this Static Constructor //So queue replace frame generation after that LongEventHandler.QueueLongEvent(() => ThingDefGenerator_ReplaceFrame.AddReplaceFrames(), null, true, null); }