Beispiel #1
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);
                        }
                    }
                }
            }
        }
        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
        }
Beispiel #3
0
        //private long lastAutoCollect = 0;
        public override void TickLong()
        {
            if (this.Spawned && base.Map != null)
            {
                // Fix for an issue where apparel will appear on top of the dresser even though it's already stored inside
                this.HandleThingsOnTop();
            }

            if (!this.AreStorageSettingsEqual())
            {
                try
                {
                    this.AllowAdds = false;

                    WorldComp.SortDressersToUse();
                    this.UpdatePreviousStorageFilter();

                    List <Apparel> removed = this.StoredApparel.RemoveFilteredApparel(this.settings);
                    foreach (Apparel a in removed)
                    {
                        if (!WorldComp.AddApparel(a))
                        {
                            this.DropThing(a, false);
                        }
                    }
                }
                finally
                {
                    this.AllowAdds = true;
                }
            }

            if (this.forceAddedApparel != null && this.forceAddedApparel.Count > 0)
            {
                foreach (Thing t in this.forceAddedApparel)
                {
                    this.DropApparel(this.forceAddedApparel, false);
                }
                this.forceAddedApparel.Clear();
                this.forceAddedApparel = null;
            }

            /*long now = DateTime.Now.Millisecond;
             * if (now - this.lastAutoCollect > THIRTY_SECONDS)
             * {
             *  this.lastAutoCollect = now;
             *  this.ReclaimApparel();
             * }*/
        }
Beispiel #4
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
            }
        }
Beispiel #5
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);
                        }
                    }
                }
            }
        }
Beispiel #6
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
        }
Beispiel #7
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();
            }
        }
Beispiel #8
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
        }
        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
        }