Exemple #1
0
 public static T RequireComponent <T>(this ThingWithComps thing, T component)
 {
     if (component == null)
     {
         Log.Error($"{thing.GetType().Name} requires {nameof(T)} in def {thing.def.defName}");
     }
     return(component);
 }
 public static T RequireComponent <T>(this ThingWithComps thing, T component)
 {
     if (component == null)
     {
         RemoteTechController.Instance.Logger.Error($"{thing.GetType().Name} requires {nameof(T)} in def {thing.def.defName}");
     }
     return(component);
 }
        public static Thing ReplacedThing(ThingWithComps original)
        {
            bool actionRequired = original.GetType() != original.def.thingClass;

            if (actionRequired)
            {
                //    Log.Message("original.GetType("+ original.GetType()+ ") != original.def.thingClass("+ original.def.thingClass+")");
                bool act = original.def.modContentPack != null && original.def.modContentPack.Name.Contains("Adeptus Mechanicus");
                if (act)
                {
                    try
                    {
                        //    Log.Message("act");
                        //    Log.Warning(original.LabelCap + "'s ThingClass doesnt match its Defs ThingClass, trying to fix");
                        Thing thing = ThingMaker.MakeThing(original.def, original.Stuff);
                        thing.Position = original.Position;
                        CompQuality quality = original.TryGetCompFast <CompQuality>();
                        if (quality != null)
                        {
                            quality.parent = thing as ThingWithComps;
                        }
                        CompArt art = original.TryGetCompFast <CompArt>();
                        if (art != null)
                        {
                            art.parent = thing as ThingWithComps;
                        }
                        thing.thingIDNumber = original.thingIDNumber;
                        IThingHolder   holder     = original.ParentHolder;
                        CompEquippable equippable = original.TryGetCompFast <CompEquippable>();
                        if (equippable != null)
                        {
                            Thing user = equippable.VerbTracker.PrimaryVerb.Caster;
                            Pawn  p    = user as Pawn;
                            if (p != null)
                            {
                                p.equipment.Remove(original);
                                p.equipment.AddEquipment(thing as ThingWithComps);
                            }
                        }
                        else
                        if (holder != null)
                        {
                            holder.GetDirectlyHeldThings().Remove(original);
                            holder.GetDirectlyHeldThings().TryAdd(thing);
                        }
                        return(thing);
                    }
                    catch (Exception)
                    {
                        Log.Warning("Something went wrong trying to replace " + original.LabelCap + "'s ThingClass from " + original.GetType().Name + " to " + original.def.thingClass.Name);
                        return(original);
                    }
                }
            }
            return(original);
        }
Exemple #4
0
        public static T RequireComp <T>(this ThingWithComps thing) where T : ThingComp
        {
            var c = thing.GetComp <T>();

            if (c == null)
            {
                Log.Error($"{thing.GetType().Name} requires ThingComp of type {nameof(T)} in def {thing.def.defName}");
            }
            return(c);
        }
        public static Thing ReplacedThing(ThingWithComps original)
        {
            Type oldType = original.GetType();
            Type newType = original.def.thingClass;

            try
            {
                //   if (AMAMod.Dev) Log.Warning(original.LabelCap + "'s ThingClass(" + oldType + ") doesnt match its Defs ThingClass(" + newType + "), trying to fix");
                Thing thing = ThingMaker.MakeThing(original.def, original.Stuff);
                thing.Position = original.Position;
                CompQuality quality = original.TryGetCompFast <CompQuality>();
                if (quality != null)
                {
                    quality.parent = thing as ThingWithComps;
                }
                CompArt art = original.TryGetCompFast <CompArt>();
                if (art != null)
                {
                    art.parent = thing as ThingWithComps;
                }
                thing.thingIDNumber = original.thingIDNumber;
                IThingHolder   holder     = original.ParentHolder;
                CompEquippable equippable = original.TryGetCompFast <CompEquippable>();
                if (equippable != null)
                {
                    Thing user = equippable.VerbTracker.PrimaryVerb.Caster;
                    Pawn  p    = user as Pawn;
                    if (p != null)
                    {
                        p.equipment.Remove(original);
                        p.equipment.AddEquipment(thing as ThingWithComps);
                    }
                }
                else
                if (holder != null)
                {
                    holder.GetDirectlyHeldThings().Remove(original);
                    holder.GetDirectlyHeldThings().TryAdd(thing);
                }
                if (AMAMod.Dev)
                {
                    Log.Message(original.LabelCap + "'s ThingClass(" + thing.GetType() + ") " + (thing.GetType() == newType ? "now matches" : "doesnt match") + "its Defs ThingClass(" + newType + ")");
                }
                return(thing);
            }
            catch (Exception)
            {
                Log.Warning("Something went wrong trying to replace " + original.LabelCap + "'s ThingClass from " + oldType.Name + " to " + newType.Name);
                return(original);
            }
        }
 public static void GetInspectString(ThingWithComps __instance, ref string __result)
 {
     if (__instance.GetType() == typeof(Building_ResearchBench))
     {
         StringBuilder sb = new StringBuilder();
         sb.Append(_util.InspectStringInfo(__instance));
         sb.AppendInNewLine(__result);
         __result = sb.ToString();
     }
     if (ResearchInfo.ModHumanResources && (__instance.def.defName == "StudyDesk" || __instance.def.defName == "NetworkTerminal"))
     {
         StringBuilder sb = new StringBuilder();
         sb.Append(_util.InspectStringInfo(__instance, study: true));
         sb.AppendInNewLine(__result);
         __result = sb.ToString();
     }
 }