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(); } } } }
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 }
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(); }
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(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; } }