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 #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
 static void Prefix()
 {
     foreach (Building_Dresser d in WorldComp.GetDressers(null))
     {
         d.ReclaimApparel();
     }
 }
            static void Postfix(WealthWatcher __instance)
            {
                Map       map           = (Map)__instance.GetType().GetField("map", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
                FieldInfo wealthItemsFI = __instance.GetType().GetField("wealthItems", BindingFlags.NonPublic | BindingFlags.Instance);
                float     wealthItems   = (float)wealthItemsFI.GetValue(__instance);

                wealthItems = TallyWealth(WorldComp.GetDressers(map), wealthItems);

                wealthItemsFI.SetValue(__instance, wealthItems);
            }
Exemple #5
0
        static void Prefix(Window __instance)
        {
            Type type = __instance.GetType();

            if (type == typeof(Dialog_FormCaravan))
            {
                Map map = __instance.GetType().GetField("map", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance) as Map;

                foreach (Building_Dresser d in WorldComp.GetDressers(map))
                {
                    d.Empty <Thing>();
                }
            }
        }
Exemple #6
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();
             * }*/
        }
Exemple #7
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 #8
0
 static void Postfix(Pawn_DraftController __instance)
 {
     if (WorldComp.HasDressers())
     {
         Pawn pawn = __instance.pawn;
         if (WorldComp.PawnOutfits.TryGetValue(pawn, out PawnOutfitTracker outfits))
         {
             if (pawn.Drafted)
             {
                 outfits.ChangeToBattleOutfit();
             }
             else
             {
                 outfits.ChangeToCivilianOutfit();
             }
         }
     }
 }
Exemple #9
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 #10
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 #11
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 #12
0
 static void Prefix()
 {
     try
     {
         foreach (Building_Dresser d in WorldComp.GetDressers(null))
         {
             try
             {
                 d.ReclaimApparel(true);
             }
             catch (Exception e)
             {
                 Log.Warning("Error while reclaiming apparel for change dresser\n" + e.Message);
             }
         }
     }
     catch (Exception e)
     {
         Log.Warning("Error while reclaiming apparel\n" + e.Message);
     }
 }
Exemple #13
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 #14
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 #15
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 #16
0
 static void Prefix(MapParent settlement)
 {
     WorldComp.RemoveDressers(settlement.Map);
 }
Exemple #17
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            IEnumerable <Gizmo> enumerables = base.GetGizmos();

            List <Gizmo> l;

            if (enumerables != null)
            {
                l = new List <Gizmo>(enumerables);
            }
            else
            {
                l = new List <Gizmo>(1);
            }

            int groupKey = this.GetType().Name.GetHashCode();

            Command_Action a = new Command_Action();

            a.icon          = WidgetUtil.manageapparelTexture;
            a.defaultDesc   = "ChangeDresser.ManageApparelDesc".Translate();
            a.defaultLabel  = "ChangeDresser.ManageApparel".Translate();
            a.activateSound = SoundDef.Named("Click");
            a.action        = delegate { Find.WindowStack.Add(new UI.StorageUI(this, null)); };
            a.groupKey      = groupKey;
            ++groupKey;
            l.Add(a);

            a               = new Command_Action();
            a.icon          = WidgetUtil.assignweaponsTexture;
            a.defaultDesc   = "ChangeDresser.AssignOutfitsDesc".Translate();
            a.defaultLabel  = "ChangeDresser.AssignOutfits".Translate();
            a.activateSound = SoundDef.Named("Click");
            a.action        = delegate { Find.WindowStack.Add(new UI.AssignOutfitUI(this)); };
            a.groupKey      = groupKey;
            ++groupKey;
            l.Add(a);

            a               = new Command_Action();
            a.icon          = WidgetUtil.customapparelTexture;
            a.defaultDesc   = "ChangeDresser.CustomOutfitsDesc".Translate();
            a.defaultLabel  = "ChangeDresser.CustomOutfits".Translate();
            a.activateSound = SoundDef.Named("Click");
            a.action        = delegate { Find.WindowStack.Add(new UI.CustomOutfitUI(this)); };
            a.groupKey      = groupKey;
            ++groupKey;
            l.Add(a);

            a               = new Command_Action();
            a.icon          = WidgetUtil.emptyTexture;
            a.defaultDesc   = "ChangeDresser.EmptyDesc".Translate();
            a.defaultLabel  = "ChangeDresser.Empty".Translate();
            a.activateSound = SoundDef.Named("Click");
            a.action        =
                delegate
            {
                this.Empty <Apparel>();
            };
            a.groupKey = groupKey;
            ++groupKey;
            l.Add(a);

            a               = new Command_Action();
            a.icon          = WidgetUtil.collectTexture;
            a.defaultDesc   = "ChangeDresser.CollectDesc".Translate();
            a.defaultLabel  = "ChangeDresser.Collect".Translate();
            a.activateSound = SoundDef.Named("Click");
            a.action        =
                delegate
            {
                this.ReclaimApparel();
            };
            a.groupKey = groupKey;
            ++groupKey;
            l.Add(a);

            a = new Command_Action();
            if (this.includeInTradeDeals)
            {
                a.icon = WidgetUtil.yesSellTexture;
            }
            else
            {
                a.icon = WidgetUtil.noSellTexture;
            }
            a.defaultDesc   = "ChangeDresser.IncludeInTradeDealsDesc".Translate();
            a.defaultLabel  = "ChangeDresser.IncludeInTradeDeals".Translate();
            a.activateSound = SoundDef.Named("Click");
            a.action        =
                delegate
            {
                this.includeInTradeDeals = !this.includeInTradeDeals;
            };
            a.groupKey = groupKey;
            ++groupKey;
            l.Add(a);

            a = new Command_Action();
            if (this.UseDresserToDressFrom)
            {
                a.icon = WidgetUtil.yesDressFromTexture;
            }
            else
            {
                a.icon = WidgetUtil.noDressFromTexture;
            }
            a.defaultDesc   = "ChangeDresser.UseDresserToDressFromDesc".Translate();
            a.defaultLabel  = "ChangeDresser.UseDresserToDressFrom".Translate();
            a.activateSound = SoundDef.Named("Click");
            a.action        =
                delegate
            {
                this.UseDresserToDressFrom = !this.UseDresserToDressFrom;
                if (this.UseDresserToDressFrom)
                {
                    WorldComp.AddDresser(this);
                }
                else
                {
                    WorldComp.RemoveDesser(this);
                }
            };
            a.groupKey = groupKey;
            ++groupKey;
            l.Add(a);

            return(SaveStorageSettingsGizmoUtil.AddSaveLoadGizmos(l, SaveTypeEnum.Apparel_Management, this.settings.filter));
        }
        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
        }
Exemple #19
0
        static void Postfix(Pawn __instance, ref IEnumerable <Gizmo> __result)
        {
            List <Gizmo> l = new List <Gizmo>();

            if ((__instance.IsPrisoner || (Settings.ShowDresserButtonForPawns && __instance.Faction == Faction.OfPlayer && __instance.def.race.Humanlike)) && WorldComp.HasDressers())
            {
                bool isAlien = AlienRaceUtil.IsAlien(__instance);
                l.Add(new Command_Action
                {
                    icon          = WidgetUtil.yesDressFromTexture,
                    defaultLabel  = "ChangeDresser.UseDresser".Translate(),
                    activateSound = SoundDef.Named("Click"),
                    action        = delegate
                    {
                        List <FloatMenuOption> options = new List <FloatMenuOption>(6)
                        {
                            new FloatMenuOption("ChangeDresser.Wearing".Translate(), delegate() {
                                Find.WindowStack.Add(new StorageUI(__instance));
                            }),
                            new FloatMenuOption("ChangeDresser.ChangeApparelColors".Translate(), delegate() {
                                Find.WindowStack.Add(new DresserUI(DresserDtoFactory.Create(__instance, null, CurrentEditorEnum.ChangeDresserApparelColor)));
                            })
                        };
                        if (Settings.IncludeColorByLayer)
                        {
                            options.Add(new FloatMenuOption("ChangeDresser.ChangeApparelColorsByLayer".Translate(), delegate()
                            {
                                Find.WindowStack.Add(new DresserUI(DresserDtoFactory.Create(__instance, null, CurrentEditorEnum.ChangeDresserApparelLayerColor)));
                            }));
                        }
                        if (!isAlien || AlienRaceUtil.HasHair(__instance))
                        {
                            options.Add(new FloatMenuOption("ChangeDresser.ChangeHair".Translate(), delegate()
                            {
                                Find.WindowStack.Add(new DresserUI(DresserDtoFactory.Create(__instance, null, CurrentEditorEnum.ChangeDresserHair)));
                            }));
                        }
                        if (Settings.ShowBodyChange)
                        {
                            options.Add(new FloatMenuOption("ChangeDresser.ChangeBody".Translate(), delegate()
                            {
                                Find.WindowStack.Add(new DresserUI(DresserDtoFactory.Create(__instance, null, CurrentEditorEnum.ChangeDresserBody)));
                            }));
                            if (isAlien)
                            {
                                options.Add(new FloatMenuOption("ChangeDresser.ChangeAlienBodyColor".Translate(), delegate()
                                {
                                    Find.WindowStack.Add(new DresserUI(DresserDtoFactory.Create(__instance, null, CurrentEditorEnum.ChangeDresserAlienSkinColor)));
                                }));
                            }
                        }
                        Find.WindowStack.Add(new FloatMenu(options));
                    }
                });
                l.AddRange(__result);
            }

            if (!__instance.Drafted && WorldComp.HasDressers())
            {
#if DEBUG
                ++i;
                if (i == WAIT)
                {
                    Log.Warning("DraftController.Postfix: Pawn is Drafted");
                }
#endif
                if (WorldComp.PawnOutfits.TryGetValue(__instance, out PawnOutfitTracker outfits))
                {
                    if (l.Count == 0)
                    {
                        l.AddRange(__result);
                    }
#if DEBUG
                    if (i == WAIT)
                    {
                        Log.Warning("DraftController.Postfix: Sets found! Pre Gizmo Count: " + l.Count);
                    }
#endif
                    foreach (IDresserOutfit o in outfits.CivilianOutfits)
                    {
                        if (o == null || !o.IsValid())
                        {
                            continue;
                        }
#if DEBUG && DRESSER_OUTFIT
                        string msg = "Patch_Pawn_GetGizmos Outfit: " + o.Label;
                        Log.ErrorOnce(msg, msg.GetHashCode());
#endif
                        Command_Action a    = new Command_Action();
                        ThingDef       icon = o.Icon;
                        if (icon != null)
                        {
                            a.icon = HarmonyPatches.GetIcon(icon);
                        }
                        else
                        {
                            a.icon = WidgetUtil.noneTexture;
                        }
                        StringBuilder sb = new StringBuilder();
                        if (!o.IsBeingWorn)
                        {
                            sb.Append("ChangeDresser.ChangeTo".Translate());
                            a.defaultDesc = "ChangeDresser.ChangeToDesc".Translate();
                        }
                        else
                        {
                            sb.Append("ChangeDresser.Wearing".Translate());
                            a.defaultDesc = "ChangeDresser.WearingDesc".Translate();
                        }
                        sb.Append(" ");
                        sb.Append(o.Label);
                        a.defaultLabel  = sb.ToString();
                        a.activateSound = SoundDef.Named("Click");
                        a.action        = delegate
                        {
#if DRESSER_OUTFIT
                            Log.Warning("Patch_Pawn_GetGizmos click for " + o.Label);
#endif
                            outfits.ChangeTo(o);
                            //HarmonyPatches.SwapApparel(pawn, o);
                            //outfits.ColorApparel(__instance);
                        };
                        l.Add(a);
                    }
#if DEBUG
                    if (i == WAIT)
                    {
                        Log.Warning("Post Gizmo Count: " + l.Count);
                    }
#endif
                }
            }
#if DEBUG
            else
            {
                if (i == WAIT)
                {
                    Log.Warning("Pawn is not Drafted, could gizmo");
                }
            }
#endif
#if DEBUG
            if (i == WAIT)
            {
                i = 0;
            }
#endif
            if (l.Count > 0)
            {
                __result = l;
            }
        }
Exemple #20
0
        public static void OptimizeApparel(Pawn pawn)
        {
            if (!WorldComp.HasDressers(pawn.Map))
            {
                // When pawns are not on the home map they will not get dressed using the game's normal method

                // This logic works but pawns will run back to the dresser to change cloths
                foreach (ThingDef def in pawn.outfits.CurrentOutfit.filter.AllowedThingDefs)
                {
#if TRACE && SWAP_APPAREL
                    Log.Warning("        Try Find Def " + def.label);
#endif
                    if (pawn.apparel.CanWearWithoutDroppingAnything(def))
                    {
#if TRACE && SWAP_APPAREL
                        Log.Warning("        Can Wear. Check Dressers for apparel:");
#endif
                        foreach (Building_Dresser d in WorldComp.DressersToUse)
                        {
#if TRACE && SWAP_APPAREL
                            Log.Warning("            " + d.Label);
#endif
                            Apparel apparel;
                            if (d.TryRemoveBestApparel(def, pawn.outfits.CurrentOutfit.filter, out apparel))
                            {
                                WorldComp.ApparelColorTracker.RemoveApparel(apparel);
#if TRACE && SWAP_APPAREL
                                Log.Warning("            Found : " + apparel.Label);
#endif
                                pawn.apparel.Wear(apparel);
                                break;
                            }
#if TRACE && SWAP_APPAREL
                            else
                            {
                                Log.Warning("            No matching apparel found");
                            }
#endif
                        }
                    }
#if TRACE && SWAP_APPAREL
                    else
                    {
                        Log.Warning("        Can't wear");
                    }
#endif
                }
                return;
            }

#if DRESSER_OUTFIT
            Log.Warning("Begin OptimizeApparelUtil.OptimizeApparel(Pawn: " + pawn.Name + ")");
#endif
            MethodInfo mi = typeof(JobGiver_OptimizeApparel).GetMethod("TryGiveJob", BindingFlags.Instance | BindingFlags.NonPublic);
            JobGiver_OptimizeApparel apparelOptimizer = new JobGiver_OptimizeApparel();
            object[] param = new object[] { pawn };

            for (int i = 0; i < 10; ++i)
            {
#if TRACE && DRESSER_OUTFIT
                Log.Message(i + " start equip for loop");
#endif
                Job job = mi.Invoke(apparelOptimizer, param) as Job;
#if TRACE && DRESSER_OUTFIT
                Log.Message(i + " job is null: " + (string)((job == null) ? "yes" : "no"));
#endif
                if (job == null)
                {
                    break;
                }
#if TRACE && DRESSER_OUTFIT
                Log.Message(job.def.defName);
#endif
                if (job.def == JobDefOf.Wear)
                {
                    Apparel a = ((job.targetB != null) ? job.targetB.Thing : null) as Apparel;
                    if (a == null)
                    {
                        Log.Warning("ChangeDresser: OptimizeApparelUtil.OptimizeApparel: Problem equiping pawn. Apparel is null.");
                        break;
                    }
#if TRACE && DRESSER_OUTFIT
                    Log.Message("Wear from ground " + a.Label);
#endif
                    pawn.apparel.Wear(a);
                }
                else if (job.def == Building_Dresser.WEAR_APPAREL_FROM_DRESSER_JOB_DEF)
                {
                    Building_Dresser d = ((job.targetA != null) ? job.targetA.Thing : null) as Building_Dresser;
                    Apparel          a = ((job.targetB != null) ? job.targetB.Thing : null) as Apparel;

                    if (d == null || a == null)
                    {
                        Log.Warning("ChangeDresser: OptimizeApparelUtil.OptimizeApparel: Problem equiping pawn. Dresser or Apparel is null.");
                        break;
                    }
#if TRACE && DRESSER_OUTFIT
                    Log.Message("Wear from dresser " + d.Label + " " + a.Label);
#endif
                    d.RemoveNoDrop(a);
                    pawn.apparel.Wear(a);
                }
#if TRACE && DRESSER_OUTFIT
                Log.Message(i + " end equip for loop");
#endif
            }
#if DRESSER_OUTFIT
            Log.Warning("End OptimizeApparelUtil.OptimizeApparel");
#endif
        }
Exemple #21
0
        static void Postfix(Pawn_DraftController __instance, ref IEnumerable <Gizmo> __result)
        {
            Pawn pawn = __instance.pawn;

            if (pawn.Drafted && WorldComp.HasDressers())
            {
#if DEBUG
                ++i;
                if (i == WAIT)
                {
                    Log.Warning("DraftController.Postfix: Pawn is Drafted");
                }
#endif
                if (WorldComp.PawnOutfits.TryGetValue(pawn, out PawnOutfitTracker outfits))
                {
                    List <Gizmo> l = new List <Gizmo>(__result);
#if DEBUG
                    if (i == WAIT)
                    {
                        Log.Warning("DraftController.Postfix: Sets found! Pre Gizmo Count: " + l.Count);
                    }
#endif
                    foreach (IDresserOutfit o in outfits.BattleOutfits)
                    {
                        if (o == null || !o.IsValid())
                        {
                            continue;
                        }
#if DEBUG && DRESSER_OUTFIT
                        string msg = "Patch_Pawn_DraftController_GetGizmos Outfit: " + o.Label;
                        Log.ErrorOnce(msg, msg.GetHashCode());
#endif
#if DEBUG
                        if (i == WAIT)
                        {
                            Log.Warning("DraftController.Postfix: Set: " + o.Label + ", Current Oufit: " + pawn.outfits.CurrentOutfit.label);
                        }
#endif
                        Command_Action a    = new Command_Action();
                        ThingDef       icon = o.Icon;
                        if (icon != null)
                        {
                            a.icon = HarmonyPatches.GetIcon(icon);
                        }
                        else
                        {
                            a.icon = WidgetUtil.noneTexture;
                        }
                        StringBuilder sb = new StringBuilder();
                        if (!pawn.outfits.CurrentOutfit.Equals(o))
                        {
                            sb.Append("ChangeDresser.ChangeTo".Translate());
                            a.defaultDesc = "ChangeDresser.ChangeToDesc".Translate();
                        }
                        else
                        {
                            sb.Append("ChangeDresser.Wearing".Translate());
                            a.defaultDesc = "ChangeDresser.WearingDesc".Translate();
                        }
                        sb.Append(" ");
                        sb.Append(o.Label);
                        a.defaultLabel  = sb.ToString();
                        a.activateSound = SoundDef.Named("Click");
                        a.action        = delegate
                        {
#if DRESSER_OUTFIT
                            Log.Warning("Patch_Pawn_DraftController_GetGizmos click for " + o.Label);
#endif
                            outfits.ChangeTo(o);
                            //HarmonyPatches.SwapApparel(pawn, o);
                            //outfits.ColorApparel(pawn);
                        };
                        l.Add(a);
                    }
#if DEBUG
                    if (i == WAIT)
                    {
                        Log.Warning("Post Gizmo Count: " + l.Count);
                    }
#endif
                    __result = l;
                }
            }
#if DEBUG
            else
            {
                if (i == WAIT)
                {
                    Log.Warning("Pawn is not Drafted, could gizmo");
                }
            }
#endif
#if DEBUG
            if (i == WAIT)
            {
                i = 0;
            }
#endif
        }
            static void Postfix(ref bool __result, Bill bill, Pawn pawn, Thing billGiver, List <ThingCount> chosen)
            {
                if (bill.Map == null)
                {
                    Log.Error("Bill's map is null");
                    return;
                }

                if (__result == true || !WorldComp.HasDressers(bill.Map) || bill.Map != pawn.Map)
                {
                    return;
                }

#if DEBUG && (DROP_DEBUG || BILL_DEBUG)
                Log.Warning("TryFindBestBillIngredients.Postfix __result: " + __result);
#endif
                Dictionary <ThingDef, int> chosenAmounts = new Dictionary <ThingDef, int>();
                foreach (ThingCount c in chosen)
                {
                    int count;
                    if (chosenAmounts.TryGetValue(c.Thing.def, out count))
                    {
                        count += c.Count;
                    }
                    else
                    {
                        count = c.Count;
                    }
                    chosenAmounts[c.Thing.def] = count;
                }

#if DEBUG && (DROP_DEBUG || BILL_DEBUG)
                Log.Warning("    ChosenAmounts:");
                foreach (KeyValuePair <ThingLookup, int> kv in chosenAmounts)
                {
                    Log.Warning("        " + kv.Key.Def.label + " - " + kv.Value);
                }
#endif

                LinkedList <NeededIngrediants> neededIngs = new LinkedList <NeededIngrediants>();
                foreach (IngredientCount ing in bill.recipe.ingredients)
                {
                    bool found = false;
                    foreach (KeyValuePair <ThingDef, int> kv in chosenAmounts)
                    {
                        if ((int)ing.GetBaseCount() == kv.Value)
                        {
#if DEBUG && (DROP_DEBUG || BILL_DEBUG)
                            Log.Warning("    Needed Ing population count is the same");
#endif
                            if (ing.filter.Allows(kv.Key))
                            {
#if DEBUG && (DROP_DEBUG || BILL_DEBUG)
                                Log.Warning("    Needed Ing population found: " + kv.Key.Def.label + " count: " + kv.Value);
#endif
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found)
                    {
#if DEBUG && (DROP_DEBUG || BILL_DEBUG)
                        Log.Warning("    Needed Ing population not found");
#endif
                        neededIngs.AddLast(new NeededIngrediants(ing.filter, (int)ing.GetBaseCount()));
                    }
                }

#if DEBUG && (DROP_DEBUG || BILL_DEBUG)
                Log.Warning("    Needed Ings:");
                foreach (NeededIngrediants ings in neededIngs)
                {
                    Log.Warning("        " + ings.Count);
                }
#endif

                List <ApparelToUse> apparelToUse = new List <ApparelToUse>();
                foreach (Building_Dresser dresser in WorldComp.GetDressers(bill.Map))
                {
                    if ((float)(dresser.Position - billGiver.Position).LengthHorizontalSquared < Math.Pow(bill.ingredientSearchRadius, 2))
                    {
                        LinkedListNode <NeededIngrediants> n = neededIngs.First;
                        while (n != null)
                        {
                            var next = n.Next;
                            NeededIngrediants neededIng = n.Value;

                            if (dresser.TryGetFilteredApparel(bill, neededIng.Filter, out List <Apparel> gotten))
                            {
                                foreach (Apparel got in gotten)
                                {
                                    neededIng.Add(new StoredApparel(dresser, got));
                                }
                                if (neededIng.CountReached())
                                {
                                    apparelToUse.Add(new ApparelToUse(neededIng.GetFoundThings(), neededIng.Count));
                                    neededIng.Clear();
                                    neededIngs.Remove(n);
                                }
                            }
                            n = next;
                        }
                    }
                }

#if DEBUG && (DROP_DEBUG || BILL_DEBUG)
                Log.Warning("    neededIngs.count: " + neededIngs.Count);
#endif

                if (neededIngs.Count == 0)
                {
                    __result = true;
                    foreach (ApparelToUse ttu in apparelToUse)
                    {
                        int count = ttu.Count;
                        foreach (StoredApparel sa in ttu.Apparel)
                        {
                            if (count <= 0)
                            {
                                break;
                            }

                            if (sa.Dresser.TryRemove(sa.Apparel, false))
                            {
                                count -= sa.Apparel.stackCount;
                                chosen.Add(new ThingCount(sa.Apparel, sa.Apparel.stackCount));
                            }
                        }
                    }
                }

                apparelToUse.Clear();
                foreach (NeededIngrediants n in neededIngs)
                {
                    n.Clear();
                }
                neededIngs.Clear();
                chosenAmounts.Clear();
            }
Exemple #23
0
        public override void ExposeData()
        {
#if DEBUG
            Log.Warning(Environment.NewLine + "Start Building_Dresser.ExposeData mode: " + Scribe.mode);
#endif
            base.ExposeData();

            //bool useInLookup = this.UseInApparelLookup;
            //Scribe_Values.Look(ref useInLookup, "useInApparelLookup", false, false);
            //this.UseInApparelLookup = useInLookup;

            if (Scribe.mode == LoadSaveMode.Saving)
            {
                this.tempApparelList = new List <Apparel>(this.StoredApparel.Apparel);
                if (this.forceAddedApparel == null)
                {
                    this.forceAddedApparel = new List <Thing>();
                }
            }

#if DEBUG
            Log.Warning(" Scribe_Collections.Look tempApparelList");
#endif
            Scribe_Collections.Look(ref this.tempApparelList, false, "apparel", LookMode.Deep, new object[0]);
            Scribe_Values.Look(ref this.includeInTradeDeals, "includeInTradeDeals", true);
            Scribe_Collections.Look(ref this.forceAddedApparel, false, "forceAddedApparel", LookMode.Deep, new object[0]);
            Scribe_Values.Look(ref this.UseDresserToDressFrom, "useDresserToDressFrom", true, false);
#if DEBUG
            if (this.tempApparelList != null)
            {
                Log.Warning(" tempApparelList Count: " + this.tempApparelList.Count);
            }
            else
            {
                Log.Warning(" StempApparelList is null");
            }
#endif
            if (this.tempApparelList != null &&
                Scribe.mode == LoadSaveMode.PostLoadInit)
            {
#if DEBUG
                Log.Warning(" tempApparelList != null && PostLoadInit");
#endif
                foreach (Apparel apparel in this.tempApparelList)
                {
                    if (apparel != null && !apparel.Destroyed && apparel.HitPoints > 0.01)
                    {
                        this.StoredApparel.AddApparel(apparel);
                    }
                }
            }

            if (this.tempApparelList != null &&
                (Scribe.mode == LoadSaveMode.Saving ||
                 Scribe.mode == LoadSaveMode.PostLoadInit))
            {
#if DEBUG
                StringBuilder sb = new StringBuilder(" Saving or PostLoadInit - Count: " + this.StoredApparel.Count);
                foreach (Apparel a in this.StoredApparel.Apparel)
                {
                    sb.Append(", ");
                    sb.Append(a.LabelShort);
                }
                Log.Warning(sb.ToString());
#endif
                this.tempApparelList.Clear();
                this.tempApparelList = null;

                if (this.forceAddedApparel != null && this.forceAddedApparel.Count == 0)
                {
                    this.forceAddedApparel = null;
                }
            }

            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                if (!this.UseDresserToDressFrom)
                {
                    WorldComp.RemoveDesser(this);
                }
            }

#if DEBUG
            Log.Message("End Building_Dresser.ExposeData" + Environment.NewLine);
#endif
        }