예제 #1
0
 static void Postfix(Lord lord)
 {
     foreach (Building_WeaponStorage s in WorldComp.GetWeaponStorages(lord.Map))
     {
         s.ReclaimWeapons();
     }
 }
예제 #2
0
        public void UpdateFoundDefCache()
        {
            long now = DateTime.Now.Ticks;

            if (now - this.lastCacheUpdate > TimeSpan.TicksPerSecond)
            {
                this.lastCacheUpdate = now;

                this.foundDefCache.Clear();
                foreach (ThingDef def in this.AllowedDefs)
                {
                    if (CombatExtendedUtil.GetAmmoCount(def) > 0)
                    {
                        this.foundDefCache.Add(def);
                        continue;
                    }
                    foreach (Building_WeaponStorage s in WorldComp.GetWeaponStorages(null))
                    {
                        if (s.HasWeapon(this, def))
                        {
                            this.foundDefCache.Add(def);
                            break;
                        }
                    }
                }
            }
        }
            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.GetWeaponStorages(map), wealthItems);

                wealthItemsFI.SetValue(__instance, wealthItems);
            }
예제 #4
0
 public static void ReclaimWeapons()
 {
     foreach (Building_WeaponStorage ws in WorldComp.GetWeaponStorages(null))
     {
         if (ws.Map != null && ws.Spawned)
         {
             ws.ReclaimWeapons();
         }
     }
 }
예제 #5
0
 static void Prefix(IEnumerable <Pawn> pawns, Faction faction, int exitFromTile, int directionTile, int destinationTile, bool sendMessage)
 {
     if (faction == Faction.OfPlayer)
     {
         List <Pawn> p = new List <Pawn>(pawns);
         if (p.Count > 0)
         {
             foreach (Building_WeaponStorage s in WorldComp.GetWeaponStorages(null))
             {
                 s.ReclaimWeapons();
             }
         }
     }
 }
예제 #6
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_WeaponStorage s in WorldComp.GetWeaponStorages(map))
                {
                    s.Empty();
                }
            }
        }
예제 #7
0
        public static IEnumerable <Thing> EmptyWeaponStorages(Map map)
        {
            List <Thing> l = new List <Thing>();

            foreach (Building_WeaponStorage ws in WorldComp.GetWeaponStorages(map))
            {
                if (ws.Map == map && ws.Spawned && ws.IncludeInTradeDeals)
                {
                    foreach (ThingWithComps t in ws.GetWeapons(true))
                    {
                        l.Add(t);
                    }
                    ws.Empty();
                }
            }
            return(l);
        }
예제 #8
0
        static void Postfix(ref int __result, RecipeWorkerCounter __instance, Bill_Production bill)
        {
            List <ThingDefCountClass> products = __instance.recipe.products;
            var storages = WorldComp.GetWeaponStorages(bill?.Map);

            if (storages.Count() > 0 && products != null)
            {
                foreach (ThingDefCountClass product in products)
                {
                    ThingDef def = product.thingDef;
                    if (def.IsWeapon)
                    {
                        foreach (Building_WeaponStorage ws in WorldComp.GetWeaponStorages(bill.Map))
                        {
                            __result += ws.GetWeaponCount(def, bill.qualityRange, bill.hpRange, (bill.limitToAllowedStuff) ? bill.ingredientFilter : null);
                        }
                    }
                }
            }
        }
예제 #9
0
 public void UpdateDefCache(ThingDef def)
 {
     if (this.AllowedDefs.Contains(def))
     {
         if (CombatExtendedUtil.GetAmmoCount(def) > 0)
         {
             this.foundDefCache.Add(def);
             return;
         }
         foreach (Building_WeaponStorage s in WorldComp.GetWeaponStorages(null))
         {
             if (s.HasWeapon(this, def))
             {
                 this.foundDefCache.Add(def);
                 return;
             }
         }
     }
     this.foundDefCache.Remove(def);
 }
예제 #10
0
 static void Prefix()
 {
     try
     {
         foreach (Building_WeaponStorage s in WorldComp.GetWeaponStorages(null))
         {
             try
             {
                 s.ReclaimWeapons(true);
             }
             catch (Exception e)
             {
                 Log.Warning("Error while reclaiming weapon for storage\n" + e.Message);
             }
         }
     }
     catch (Exception e)
     {
         Log.Warning("Error while reclaiming weapons\n" + e.Message);
     }
 }
예제 #11
0
            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.HasStorages(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.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 <WeaponsToUse> weaponsToUse = new List <WeaponsToUse>();
                foreach (Building_WeaponStorage storage in WorldComp.GetWeaponStorages(bill.Map))
                {
                    if ((float)(storage.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;

                            List <ThingWithComps> gotten;
                            if (storage.TryGetFilteredWeapons(bill, neededIng.Filter, out gotten))
                            {
                                foreach (ThingWithComps got in gotten)
                                {
                                    neededIng.Add(new StoredWeapons(storage, got));
                                }
                                if (neededIng.CountReached())
                                {
                                    weaponsToUse.Add(new WeaponsToUse(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 (WeaponsToUse ttu in weaponsToUse)
                    {
                        int count = ttu.Count;
                        foreach (StoredWeapons sa in ttu.Weapons)
                        {
                            if (count <= 0)
                            {
                                break;
                            }

                            if (sa.Storage.Remove(sa.Weapon))
                            {
                                count -= sa.Weapon.stackCount;
                                chosen.Add(new ThingCount(sa.Weapon, sa.Weapon.stackCount));
                            }
                        }
                    }
                }

                weaponsToUse.Clear();
                foreach (NeededIngrediants n in neededIngs)
                {
                    n.Clear();
                }
                neededIngs.Clear();
                chosenAmounts.Clear();
            }