public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.compPowerTrader             = base.GetComp <CompPowerTrader>();
            this.compPowerTrader.PowerOutput = -LOW_POWER_COST;

            this.CurrentMap = map;

            foreach (Building_Dresser d in BuildingUtil.FindThingsOfTypeNextTo <Building_Dresser>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
                this.AddDresser(d);
            }

#if DEBUG_REPAIR
            Log.Warning(this.Label + " adding attached dressers:");
            foreach (Building_Dresser d in this.AttachedDressers)
            {
                Log.Warning(" " + d.Label);
            }
#endif

            this.compPowerTrader.powerStartedAction = new Action(delegate()
            {
                this.compPowerTrader.PowerOutput = LOW_POWER_COST;
            });

            this.compPowerTrader.powerStoppedAction = new Action(delegate()
            {
                this.StopRepairing();
                this.compPowerTrader.PowerOutput = 0;
            });
        }
Exemple #2
0
        public void AddApparel(Apparel a)
        {
#if DEBUG
            Log.Warning("AddApparel " + a.Label + " Spawned: " + a.Spawned + " IsForbidden: " + a.IsForbidden(Faction.OfPlayer));
#endif
            if (a != null)
            {
                if (this.settings.AllowedToAccept(a))
                {
                    if (a.Spawned)
                    {
                        a.DeSpawn();
                    }
                    this.StoredApparel.AddApparel(a);
                }
                else // Not Allowed
                {
                    if (!WorldComp.AddApparel(a))
                    {
                        if (!a.Spawned)
                        {
                            BuildingUtil.DropThing(a, this, this.CurrentMap, false);
                        }
                    }
                }
            }
        }
Exemple #3
0
        public void Empty <T>(List <T> removed = null) where T : Thing
        {
            try
            {
                this.AllowAdds = false;

                foreach (LinkedList <Apparel> ll in this.StoredApparel.StoredApparelLookup.Values)
                {
                    foreach (Apparel a in ll)
                    {
                        BuildingUtil.DropThing(a, this, this.CurrentMap, false);
                        if (removed != null)
                        {
                            removed.Add(a as T);
                        }
                    }
                    ll.Clear();
                }
                this.StoredApparel.StoredApparelLookup.Clear();
                WorldComp.ApparelColorTracker.Clear();
            }
            finally
            {
                this.AllowAdds = true;
            }
        }
        public void Undress(Pawn pawn, List <Apparel> customApparel)
        {
#if DRESSER_OUTFIT
            Log.Warning("Begin DefinedOutfit.Undress(Pawn: " + pawn.Name.ToStringShort + ")");
#endif
            List <Apparel> wornApparel = new List <Apparel>(pawn.apparel.WornApparel);
            pawn.outfits.forcedHandler.ForcedApparel.Clear();
#if DRESSER_OUTFIT
            Log.Warning("    Remove Apparel:");
#endif
            foreach (Apparel a in wornApparel)
            {
#if DRESSER_OUTFIT
                Log.Warning("        " + a.Label);
#endif
                pawn.apparel.Remove(a);
                if (!customApparel.Contains(a))
                {
#if DRESSER_OUTFIT
                    Log.Warning("            -- Not a custom piece of apparel. Storing in Dresser.");
#endif
                    if (!WorldComp.AddApparel(a))
                    {
                        BuildingUtil.DropThing(a, pawn.Position, pawn.Map, false);
                    }
                }
            }
            this.isBeingWorn = false;
#if DRESSER_OUTFIT
            Log.Warning("End DefinedOutfit.Undress");
#endif
        }
Exemple #5
0
        internal void ReclaimApparel(bool force = false)
        {
            if (base.Map == null)
            {
                return;
            }
#if DEBUG
            List <Apparel> ll = new List <Apparel>(BuildingUtil.FindThingsOfTypeNextTo <Apparel>(base.Map, base.Position, 1));
            Log.Warning("Apparel found: " + ll.Count);
#endif
            try
            {
                List <Thing> l = BuildingUtil.FindThingsNextTo(base.Map, base.Position, 1);
                if (l.Count > 0)
                {
                    foreach (Thing t in l)
                    {
                        try
                        {
                            if (t is Apparel)
                            {
                                if (!WorldComp.AddApparel((Apparel)t) &&
                                    force &&
                                    t.Spawned)
                                {
                                    t.DeSpawn();
                                    if (this.forceAddedApparel == null)
                                    {
                                        this.forceAddedApparel = new List <Thing>();
                                    }
                                    this.forceAddedApparel.Add(t);
                                }
                            }
                        }
                        catch
                        {
                            // Ignore
                        }
                    }
                    l.Clear();
                    l = null;
                }
            }
            catch
            {
                // Ignore
            }
        }
Exemple #6
0
        static void Postfix(Pawn __instance)
        {
            if (__instance.Dead && __instance.apparel?.LockedApparel?.Count == 0)
            {
                if (WorldComp.PawnOutfits.TryGetValue(__instance, out PawnOutfitTracker po))
                {
                    WorldComp.PawnOutfits.Remove(__instance);

                    foreach (Apparel a in po.CustomApparel)
                    {
                        if (!WorldComp.AddApparel(a))
                        {
                            BuildingUtil.DropThing(a, __instance.Position, map, true);
                        }
                    }
                }
            }
        }
Exemple #7
0
        public void UpdateCustomApparel(Building_Dresser dresser)
        {
#if DRESSER_OUTFIT
            Log.Warning("Begin PawnOutfitTracker.UpdateCustomApparel(Dresser: " + ((dresser == null) ? "<null>" : dresser.Label) + ")");
#endif
            List <Apparel> stored = new List <Apparel>(this.customApparel);
            this.customApparel.Clear();

            foreach (CustomOutfit o in this.CustomOutfits)
            {
                foreach (Apparel a in o.Apparel)
                {
                    if (!this.customApparel.Contains(a))
                    {
#if DRESSER_OUTFIT
                        Log.Message("    Add CustomApparel: " + a.Label);
#endif
                        this.customApparel.Add(a);
                    }
                    stored.Remove(a);
                }
            }

            foreach (Apparel a in stored)
            {
#if DRESSER_OUTFIT
                Log.Message("    No Longer Used: " + a.Label);
#endif
                if (!WorldComp.AddApparel(a))
                {
                    if (dresser == null)
                    {
                        Log.Error("Unable to drop " + a.Label + " on ground.");
                    }
                    else
                    {
                        BuildingUtil.DropThing(a, dresser, dresser.Map, false);
                    }
                }
            }
#if DRESSER_OUTFIT
            Log.Warning("End PawnOutfitTracker.UpdateCustomApparel");
#endif
        }
Exemple #8
0
        internal void ReclaimApparel()
        {
#if DEBUG
            List <Apparel> ll = new List <Apparel>(BuildingUtil.FindThingsOfTypeNextTo <Apparel>(base.Map, base.Position, 1));
            Log.Warning("Apparel found: " + ll.Count);
#endif
            List <Thing> l = BuildingUtil.FindThingsNextTo(base.Map, base.Position, 1);
            if (l.Count > 0)
            {
                foreach (Thing t in l)
                {
                    if (t is Apparel)
                    {
                        WorldComp.AddApparel((Apparel)t);
                    }
                }
                l.Clear();
            }
        }
Exemple #9
0
        private void Dispose()
        {
            try
            {
                this.Empty <Apparel>();
            }
            catch (Exception e)
            {
                Log.Error(
                    "ChangeDresser:Building_Dresser.Dispose\n" +
                    e.GetType().Name + " " + e.Message + "\n" +
                    e.StackTrace);
            }

            WorldComp.RemoveDesser(this);
            foreach (Building_RepairChangeDresser r in BuildingUtil.FindThingsOfTypeNextTo <Building_RepairChangeDresser>(this.CurrentMap, base.Position, Settings.RepairAttachmentDistance))
            {
#if DEBUG_REPAIR
                Log.Warning("Removing Dresser " + this.Label + " to " + r.Label);
#endif
                r.RemoveDresser(this);
            }
        }
Exemple #10
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.CurrentMap = map;
            WorldComp.AddDresser(this);

            if (settings == null)
            {
                base.settings = new StorageSettings(this);
                base.settings.CopyFrom(this.def.building.defaultStorageSettings);
                base.settings.filter.SetDisallowAll();
            }

            foreach (Building_RepairChangeDresser r in BuildingUtil.FindThingsOfTypeNextTo <Building_RepairChangeDresser>(base.Map, base.Position, Settings.RepairAttachmentDistance))
            {
#if DEBUG_REPAIR
                Log.Warning("Adding Dresser " + this.Label + " to " + r.Label);
#endif
                r.AddDresser(this);
            }

            this.UpdatePreviousStorageFilter();
        }
Exemple #11
0
        public static void StoreApparelInWorldDresser(List <Apparel> apparel, Pawn pawn)
        {
#if DRESSER_OUTFIT
            Log.Warning("Begin ApparelUtil.StoreApparelInWorldDresser(Pawn: " + pawn.Name.ToStringShort + ")");
            Log.Message("    Store Apparel in World Dressers:");
#endif
            foreach (Apparel a in apparel)
            {
#if DRESSER_OUTFIT
                Log.Message("        " + a.Label);
#endif
                if (!WorldComp.AddApparel(a))
                {
#if DRESSER_OUTFIT
                    Log.Warning("            Unable to place apparel in dresser, dropping to floor");
#endif
                    BuildingUtil.DropThing(a, pawn.Position, pawn.Map, false);
                }
            }
#if DRESSER_OUTFIT
            Log.Warning("End ApparelUtil.StoreApparelInWorldDresser");
#endif
        }
Exemple #12
0
 private bool DropThing(Thing t, bool makeForbidden = true)
 {
     WorldComp.ApparelColorTracker.RemoveApparel(t as Apparel);
     return(BuildingUtil.DropThing(t, this, this.CurrentMap, makeForbidden));
 }
        public void Undress(Pawn pawn, List <Apparel> customApparel)
        {
#if DRESSER_OUTFIT
            Log.Warning("Begin CustomOutfit.Undress(Pawn: " + pawn.Name.ToStringShort + ")");
#endif
            List <Apparel> wornApparel = new List <Apparel>(pawn.apparel.WornApparel);
            pawn.outfits.forcedHandler.ForcedApparel.Clear();
#if DRESSER_OUTFIT
            Log.Warning("    Remove Apparel:");
#endif
            foreach (Apparel a in wornApparel)
            {
#if DRESSER_OUTFIT
                Log.Warning("        " + a.Label);
#endif
                pawn.apparel.Remove(a);
                if (!customApparel.Contains(a))
                {
#if DRESSER_OUTFIT
                    Log.Warning("            -- Not a custom piece of apparel. Storing in Dresser.");
#endif
                    if (!WorldComp.AddApparel(a))
                    {
                        BuildingUtil.DropThing(a, pawn.Position, pawn.Map, false);
                    }
                }
            }
            this.isBeingWorn = false;

            /*#if DRESSER_OUTFIT
             *          Log.Warning("Begin CustomOutfit.Undress(Pawn: " + pawn.Name.ToStringShort + ")");
             #endif
             #if DRESSER_OUTFIT
             *          Log.Warning("    Find any changes in Custom Outfit:");
             #endif
             *          LinkedList<Apparel> noLongerWearing = new LinkedList<Apparel>(this.Apparel);
             *          foreach (Apparel a in pawn.apparel.WornApparel)
             *          {
             *              if (!noLongerWearing.Remove(a))
             *              {
             #if DRESSER_OUTFIT
             *                  Log.Warning("        No longer wearing: " + a.Label);
             #endif
             *              }
             #if DRESSER_OUTFIT
             *              else
             *                  Log.Message("        Is still wearing: " + a.Label);
             #endif
             *          }
             *
             #if DRESSER_OUTFIT
             *          if (noLongerWearing.Count > 0)
             *              Log.Message("    Remove Apparel from Custom Outfit:");
             #endif
             *
             #if DRESSER_OUTFIT
             *          System.Text.StringBuilder sb = new System.Text.StringBuilder("    Tracker-CustomApparel: ");
             *          foreach(Apparel a in customApparel)
             *          {
             *              sb.Append("[" + a.Label + "]  ");
             *          }
             #endif
             *
             *          // Remove any apparel that's no longer being worn
             *          foreach (Apparel a in noLongerWearing)
             *          {
             #if DRESSER_OUTFIT
             *              Log.Message("        " + a.Label);
             #endif
             *              this.Apparel.Remove(a);
             *              if (!customApparel.Contains(a))
             *              {
             #if DRESSER_OUTFIT
             *                  Log.Message("        " + a.Label + " NOT custom apparel, going back to dresser");
             #endif
             *                  WorldComp.AddApparel(a);
             *              }
             *          }
             *          pawn.outfits.forcedHandler.ForcedApparel.Clear();*/

            /*foreach (Apparel a in this.Apparel)
             * {
             *  tracker.AddCustomApparel(a);
             * }*/

#if DRESSER_OUTFIT
            Log.Warning("End CustomOutfit.Undress");
#endif
        }
 private bool DropThing(Thing t, bool makeForbidden = true)
 {
     return(BuildingUtil.DropThing(t, this, this.CurrentMap, makeForbidden));
 }