示例#1
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);
            }
示例#3
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>();
                }
            }
        }
示例#4
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);
     }
 }
            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();
            }