Example #1
0
        static void ChangeMeatAmountByAge(Thing __instance, float efficiency, ref IEnumerable <Thing> __result)
        {
            if (__instance.GetType() == typeof(Pawn))
            {
                var thingies = __result.ToList();
                var pawn     = (Pawn)__instance;

                if ((__instance.def.butcherProducts != null) && (__instance.def.defName == "GR_Manchicken"))
                {
                    int baseCalculation = 70;

                    ThingDefCountClass ta = __instance.def.butcherProducts[0];
                    float num             = pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(pawn.RaceProps.body.corePart);
                    int   count           = GenMath.RoundRandom((pawn.BodySize * baseCalculation * efficiency * num));
                    if (count > 0)
                    {
                        Thing t = ThingMaker.MakeThing(ta.thingDef, null);
                        t.stackCount = count;
                        thingies.Insert(1, t);

                        __result = thingies;
                    }
                }
            }
        }
Example #2
0
        public override void DrawPanelReadout(ref float curY, float width)
        {
            if (entDef.costStuffCount <= 0 && stuffDef != null)
            {
                stuffDef = null;
            }
            ThingDef thingDef = entDef as ThingDef;

            if (thingDef != null)
            {
                Widgets.InfoCardButton(width - 24f - 2f, 6f, thingDef, stuffDef);
            }
            else
            {
                Widgets.InfoCardButton(width - 24f - 2f, 6f, entDef);
            }
            Text.Font = GameFont.Small;
            List <ThingDefCountClass> list = entDef.CostListAdjusted(stuffDef, errorOnNullStuff: false);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass thingDefCountClass = list[i];
                Color color = GUI.color;
                Widgets.ThingIcon(new Rect(0f, curY, 20f, 20f), thingDefCountClass.thingDef);
                GUI.color = color;
                if (thingDefCountClass.thingDef != null && thingDefCountClass.thingDef.resourceReadoutPriority != 0 && base.Map.resourceCounter.GetCount(thingDefCountClass.thingDef) < thingDefCountClass.count)
                {
                    GUI.color = Color.red;
                }
                Widgets.Label(new Rect(26f, curY + 2f, 50f, 100f), thingDefCountClass.count.ToString());
                GUI.color = Color.white;
                string text   = (thingDefCountClass.thingDef != null) ? thingDefCountClass.thingDef.LabelCap : ("(" + "UnchosenStuff".Translate() + ")");
                float  width2 = width - 60f;
                float  num    = Text.CalcHeight(text, width2) - 5f;
                Widgets.Label(new Rect(60f, curY + 2f, width2, num + 5f), text);
                curY += num;
            }
            if (entDef.constructionSkillPrerequisite > 0)
            {
                Rect rect = new Rect(0f, curY + 2f, width, 24f);
                if (!AnyColonistWithConstructionSkill(entDef.constructionSkillPrerequisite, careIfDisabled: false))
                {
                    GUI.color = Color.red;
                    TooltipHandler.TipRegion(rect, "NoColonistWithConstructionSkillTip".Translate(Faction.OfPlayer.def.pawnsPlural));
                }
                else if (!AnyColonistWithConstructionSkill(entDef.constructionSkillPrerequisite, careIfDisabled: true))
                {
                    GUI.color = Color.yellow;
                    TooltipHandler.TipRegion(rect, "AllColonistsWithConstructionSkillHaveDisaledConstructingTip".Translate(Faction.OfPlayer.def.pawnsPlural, WorkTypeDefOf.Construction.gerundLabel));
                }
                else
                {
                    GUI.color = new Color(0.72f, 0.87f, 0.72f);
                }
                Widgets.Label(rect, string.Format("{0}: {1}", "ConstructionNeeded".Translate(), entDef.constructionSkillPrerequisite));
                GUI.color = Color.white;
                curY     += 18f;
            }
            curY += 4f;
        }
Example #3
0
        private static RecipeDef CreateMiningRecipe(ThingDefCountClass defCount, EffecterDef effecter)
        {
            RecipeDef r = new RecipeDef();

            r.defName   = "Recipe_AutoMachineTool_Mine_" + defCount.thingDef.defName;
            r.label     = "PRF.AutoMachineTool.AutoMiner.MineOre".Translate(defCount.thingDef.label);
            r.jobString = "PRF.AutoMachineTool.AutoMiner.MineOre".Translate(defCount.thingDef.label);

            r.workAmount     = Mathf.Max(10000f, StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(defCount.thingDef, null)) * defCount.count * 1000);
            r.workSpeedStat  = StatDefOf.WorkToMake;
            r.efficiencyStat = StatDefOf.WorkToMake;

            r.workSkill            = SkillDefOf.Mining;
            r.workSkillLearnFactor = 0;

            r.products = new List <ThingDefCountClass>().Append(defCount);
            r.defaultIngredientFilter = new ThingFilter();

            r.effectWorking = effecter;

            // ChunkStone が Recipe の WorkAmount 経由で価値を設定されてしまうため、BaseMarketValue に0を設定して、計算されないようにする。
            // <see cref="StatWorker_MarketValue.CalculatedBaseMarketValue(BuildableDef, ThingDef)"/>
            if (!defCount.thingDef.statBases.StatListContains(StatDefOf.MarketValue) && defCount.count == 1)
            {
                defCount.thingDef.BaseMarketValue = 0;
            }

            return(r);
        }
Example #4
0
 public Chapter(ThingDefCountClass thingDefCount, int size, Color color) : this()
 {
     label         = thingDefCount.thingDef.LabelCap;
     ThingDefCount = thingDefCount;
     this.size     = size;
     lineColor     = color;
 }
Example #5
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.GetInspectString());
            stringBuilder.AppendLine("ContainedResources".Translate() + ":");
            List <ThingDefCountClass> list = this.def.entityDefToBuild.CostListAdjusted(base.Stuff, true);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass need = list[i];
                int num = need.count;
                foreach (ThingDefCountClass current in from needed in this.MaterialsNeeded()
                         where needed.thingDef == need.thingDef
                         select needed)
                {
                    num -= current.count;
                }
                stringBuilder.AppendLine(string.Concat(new object[]
                {
                    need.thingDef.LabelCap,
                    ": ",
                    num,
                    " / ",
                    need.count
                }));
            }
            stringBuilder.Append("WorkLeft".Translate() + ": " + this.WorkLeft.ToStringWorkAmount());
            return(stringBuilder.ToString());
        }
        public static void DoLeavingsFor(TerrainDef terrain, IntVec3 cell, Map map)
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }
            ThingOwner <Thing>        thingOwner = new ThingOwner <Thing>();
            List <ThingDefCountClass> list       = terrain.CostListAdjusted(null);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass thingDefCountClass = list[i];
                int num = GenMath.RoundRandom((float)thingDefCountClass.count * terrain.resourcesFractionWhenDeconstructed);
                if (num > 0)
                {
                    Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef);
                    thing.stackCount = num;
                    thingOwner.TryAdd(thing);
                }
            }
            while (thingOwner.Count > 0)
            {
                if (!thingOwner.TryDrop(thingOwner[0], cell, map, ThingPlaceMode.Near, out var _))
                {
                    Log.Warning(string.Concat("Failed to place all leavings for removed terrain ", terrain, " at ", cell));
                    break;
                }
            }
        }
Example #7
0
        public bool ThingsAvailableAnywhere(ThingDefCountClass need, Pawn pawn)
        {
            int  key = Gen.HashCombine <Faction>(need.GetHashCode(), pawn.Faction);
            bool flag;

            if (!this.cachedResults.TryGetValue(key, out flag))
            {
                List <Thing> list = this.map.listerThings.ThingsOfDef(need.thingDef);
                int          num  = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    if (!list[i].IsForbidden(pawn))
                    {
                        num += list[i].stackCount;
                        if (num >= need.count)
                        {
                            break;
                        }
                    }
                }
                flag = (num >= need.count);
                this.cachedResults.Add(key, flag);
            }
            return(flag);
        }
Example #8
0
        private static void ChangeSteelToIron()
        {
            if (!ModStuff.Settings.LimitTechnology)
            {
                return;
            }

            steelDefs = 0;
            foreach (var tdd in DefDatabase <ThingDef> .AllDefs.Where(tt =>
                                                                      tt?.costList?.Any(y => y?.thingDef == ThingDefOf.Steel) ?? false))
            {
                var tempCost = tdd.costList.FirstOrDefault(z => z.thingDef == ThingDefOf.Steel);
                if (tempCost != null)
                {
                    var newTempCost = new ThingDefCountClass(ThingDef.Named("LotR_Iron"), tempCost.count);
                    tdd.costList.Remove(tempCost);
                    tdd.costList.Add(newTempCost);
                }

                steelDefs++;
            }


            Log.Message("Replaced " + steelDefs + " defs with Iron.");
        }
Example #9
0
        public override void DrawMouseAttachments()
        {
            base.DrawMouseAttachments();
            if (ArchitectCategoryTab.InfoRect.Contains(UI.MousePositionOnUIInverted))
            {
                return;
            }
            DesignationDragger dragger = Find.DesignatorManager.Dragger;
            int     num    = ((!dragger.Dragging) ? 1 : dragger.DragCells.Count());
            float   num2   = 0f;
            Vector2 vector = Event.current.mousePosition + DragPriceDrawOffset;
            List <ThingDefCountClass> list = entDef.CostListAdjusted(stuffDef);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass thingDefCountClass = list[i];
                float y = vector.y + num2;
                Widgets.ThingIcon(new Rect(vector.x, y, 27f, 27f), thingDefCountClass.thingDef);
                Rect   rect = new Rect(vector.x + 29f, y, 999f, 29f);
                int    num3 = num * thingDefCountClass.count;
                string text = num3.ToString();
                if (base.Map.resourceCounter.GetCount(thingDefCountClass.thingDef) < num3)
                {
                    GUI.color = Color.red;
                    text     += " (" + "NotEnoughStoredLower".Translate() + ")";
                }
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(rect, text);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
                num2       += 29f;
            }
        }
        static void ChangeMeatAmountByAge(Thing __instance, float efficiency, ref IEnumerable <Thing> __result)
        {
            if (__instance.GetType() == typeof(Pawn))
            {
                var thingies = __result.ToList();
                var pawn     = (Pawn)__instance;

                if ((__instance.def.butcherProducts != null) && ((__instance.def.defName == "AA_Aerofleet") || (__instance.def.defName == "AA_ColossalAerofleet") || (__instance.def.defName == "AA_Cactipine") || (__instance.def.defName == "AA_Needlepost") || (__instance.def.defName == "AA_Needleroll") || (__instance.def.defName == "AA_Wildpod") || (__instance.def.defName == "AA_Wildpawn") || (__instance.def.defName == "GR_Needlechicken") || (__instance.def.defName == "AA_OcularJelly") || (__instance.def.defName == "AA_Mantrap") || (__instance.def.defName == "AA_Agaripod") || (__instance.def.defName == "AA_MycoidColossus")))
                {
                    //Log.Message("Adding meat butcher products", false);

                    int baseCalculation = 90;
                    if ((__instance.def.defName == "AA_Wildpod") || (__instance.def.defName == "AA_Agaripod"))
                    {
                        baseCalculation = 30;
                    }
                    if (__instance.def.defName == "AA_MycoidColossus")
                    {
                        baseCalculation = 15;
                    }

                    ThingDefCountClass ta = __instance.def.butcherProducts[0];
                    float num             = pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(pawn.RaceProps.body.corePart);
                    int   count           = GenMath.RoundRandom((pawn.BodySize * baseCalculation * efficiency * num));
                    if (count > 0)
                    {
                        Thing t = ThingMaker.MakeThing(ta.thingDef, null);
                        t.stackCount = count;
                        thingies.Insert(1, t);

                        __result = thingies;
                    }
                }
            }
        }
        // Token: 0x06000078 RID: 120 RVA: 0x00004C7C File Offset: 0x00002E7C
        private HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingDefCountClass need, IConstructible c, int resTotalAvailable, bool canRemoveExistingFloorUnderNearbyNeeders, out int neededTotal, out Job jobToMakeNeederAvailable)
        {
            neededTotal = need.count;
            HashSet <Thing> hashSet = new HashSet <Thing>();
            Thing           thing   = (Thing)c;

            foreach (Thing thing2 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 8f, true))
            {
                bool flag = neededTotal >= resTotalAvailable;
                if (flag)
                {
                    break;
                }
                bool flag2 = this.IsNewValidNearbyNeeder(thing2, hashSet, c, pawn);
                if (flag2)
                {
                    Blueprint blueprint = thing2 as Blueprint;
                    bool      flag3     = blueprint == null || !WorkGiver_WPConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint);
                    if (flag3)
                    {
                        int  num   = GenConstruct.AmountNeededByOf((IConstructible)thing2, need.thingDef);
                        bool flag4 = num > 0;
                        if (flag4)
                        {
                            hashSet.Add(thing2);
                            neededTotal += num;
                        }
                    }
                }
            }
            Blueprint blueprint2 = c as Blueprint;
            bool      flag5      = blueprint2 != null && blueprint2.def.entityDefToBuild is TerrainDef && canRemoveExistingFloorUnderNearbyNeeders && neededTotal < resTotalAvailable;

            if (flag5)
            {
                foreach (Thing thing3 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 3f, false))
                {
                    bool flag6 = this.IsNewValidNearbyNeeder(thing3, hashSet, c, pawn);
                    if (flag6)
                    {
                        Blueprint blueprint3 = thing3 as Blueprint;
                        bool      flag7      = blueprint3 != null;
                        if (flag7)
                        {
                            Job  job   = this.RemoveExistingFloorJob(pawn, blueprint3);
                            bool flag8 = job != null;
                            if (flag8)
                            {
                                jobToMakeNeederAvailable = job;
                                return(hashSet);
                            }
                        }
                    }
                }
            }
            jobToMakeNeederAvailable = null;
            return(hashSet);
        }
Example #12
0
        public static List <ThingDefCountClass> CostListAdjusted(this BuildableDef entDef, ThingDef stuff, bool errorOnNullStuff = true)
        {
            CostListPair key = new CostListPair(entDef, stuff);

            if (!cachedCosts.TryGetValue(key, out List <ThingDefCountClass> value))
            {
                value = new List <ThingDefCountClass>();
                int num = 0;
                if (entDef.MadeFromStuff)
                {
                    if (errorOnNullStuff && stuff == null)
                    {
                        Log.Error("Cannot get AdjustedCostList for " + entDef + " with null Stuff.");
                        ThingDef thingDef = GenStuff.DefaultStuffFor(entDef);
                        return((thingDef == null) ? null : entDef.CostListAdjusted(GenStuff.DefaultStuffFor(entDef)));
                    }
                    if (stuff != null)
                    {
                        num = Mathf.RoundToInt((float)entDef.costStuffCount / stuff.VolumePerUnit);
                        if (num < 1)
                        {
                            num = 1;
                        }
                    }
                    else
                    {
                        num = entDef.costStuffCount;
                    }
                }
                else if (stuff != null)
                {
                    Log.Error("Got AdjustedCostList for " + entDef + " with stuff " + stuff + " but is not MadeFromStuff.");
                }
                bool flag = false;
                if (entDef.costList != null)
                {
                    for (int i = 0; i < entDef.costList.Count; i++)
                    {
                        ThingDefCountClass thingDefCountClass = entDef.costList[i];
                        if (thingDefCountClass.thingDef == stuff)
                        {
                            value.Add(new ThingDefCountClass(thingDefCountClass.thingDef, thingDefCountClass.count + num));
                            flag = true;
                        }
                        else
                        {
                            value.Add(thingDefCountClass);
                        }
                    }
                }
                if (!flag && num > 0)
                {
                    value.Add(new ThingDefCountClass(stuff, num));
                }
                cachedCosts.Add(key, value);
            }
            return(value);
        }
        //public bool ThingsAvailableAnywhere(ThingDefCountClass need, Pawn pawn)
        public static bool OrInInventory(ItemAvailability item, ThingDefCountClass need, Pawn pawn)
        {
            if (item.ThingsAvailableAnywhere(need, pawn))
            {
                return(true);
            }

            return(pawn.Map.GetComponent <ItemInvAvailabilityMapComp>().ThingsAvailableInventories(need.thingDef, pawn));
        }
Example #14
0
 //public bool ThingsAvailableAnywhere(ThingDefCountClass need, Pawn pawn)
 public static bool Prefix(ThingDefCountClass need, Pawn pawn, ref bool __result)
 {
     if (Settings.Get().ShareTheLoad_DeliverAsMuchAsYouCan)
     {
         List <Thing> list = pawn.Map.listerThings.ThingsOfDef(need.thingDef);
         __result = list.Any(t => !t.IsForbidden(pawn));
         return(false);
     }
     return(true);
 }
        //public bool ThingsAvailableAnywhere(ThingDefCountClass need, Pawn pawn)
        public static bool OrInInventory(ItemAvailability item, ThingDefCountClass need, Pawn pawn)
        {
            if (item.ThingsAvailableAnywhere(need, pawn))
            {
                return(true);
            }

            return
                (pawn.carryTracker.GetDirectlyHeldThings().Contains(need.thingDef) ||
                 pawn.Map.GetComponent <ItemInvAvailabilityMapComp>().ThingsAvailableInventories(need.thingDef, pawn.Faction));
        }
        private static HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingDefCountClass need, IConstructible c, int resTotalAvailable, bool canRemoveExistingFloorUnderNearbyNeeders, out int neededTotal, out Job jobToMakeNeederAvailable)
        {
            neededTotal = need.count;
            HashSet <Thing> hashSet = new HashSet <Thing>();
            Thing           thing   = (Thing)c;

            foreach (Thing item in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 8f, useCenter: true))
            {
                if (neededTotal >= resTotalAvailable)
                {
                    break;
                }

                if (IsNewValidNearbyNeeder(item, hashSet, c, pawn))
                {
                    Blueprint blueprint = item as Blueprint;
                    if (blueprint == null || !ShouldRemoveExistingFloorFirst(pawn, blueprint))
                    {
                        int num = GenConstruct.AmountNeededByOf((IConstructible)item, need.thingDef);
                        if (num > 0)
                        {
                            hashSet.Add(item);
                            neededTotal += num;
                        }
                    }
                }
            }

            Blueprint blueprint2 = c as Blueprint;

            if (((blueprint2 != null && blueprint2.def.entityDefToBuild is TerrainDef) & canRemoveExistingFloorUnderNearbyNeeders) && neededTotal < resTotalAvailable)
            {
                foreach (Thing item2 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 3f, useCenter: false))
                {
                    if (IsNewValidNearbyNeeder(item2, hashSet, c, pawn))
                    {
                        Blueprint blueprint3 = item2 as Blueprint;
                        if (blueprint3 != null)
                        {
                            Job job = RemoveExistingFloorJob(pawn, blueprint3);
                            if (job != null)
                            {
                                jobToMakeNeederAvailable = job;
                                return(hashSet);
                            }
                        }
                    }
                }
            }

            jobToMakeNeederAvailable = null;
            return(hashSet);
        }
        public static void SetThingComponentSpacerCost(string thingDefName, int newComponentSpacerCost)
        {
            ThingDef def = GetDefByDefName <ThingDef>(thingDefName);

            if (def != null)
            {
                ThingDefCountClass costDef = def.costList.FirstOrDefault(c => c.thingDef == ThingDefOf.ComponentSpacer);
                if (costDef != null)
                {
                    costDef.count = newComponentSpacerCost;
                }
            }
        }
Example #18
0
        public static float CalculatedMarketValue(BuildableDef def, ThingDef stuffDef)
        {
            float     num       = 0f;
            RecipeDef recipeDef = StatWorker_MarketValue.CalculableRecipe(def);
            float     num2;
            int       num3;

            if (recipeDef != null)
            {
                num2 = recipeDef.workAmount;
                num3 = recipeDef.products[0].count;
                if (recipeDef.ingredients != null)
                {
                    for (int i = 0; i < recipeDef.ingredients.Count; i++)
                    {
                        IngredientCount ingredientCount = recipeDef.ingredients[i];
                        int             num4            = ingredientCount.CountRequiredOfFor(ingredientCount.FixedIngredient, recipeDef);
                        num += (float)num4 * ingredientCount.FixedIngredient.BaseMarketValue;
                    }
                }
            }
            else
            {
                num2 = Mathf.Max(def.GetStatValueAbstract(StatDefOf.WorkToMake, stuffDef), def.GetStatValueAbstract(StatDefOf.WorkToBuild, stuffDef));
                num3 = 1;
                if (def.costList != null)
                {
                    for (int j = 0; j < def.costList.Count; j++)
                    {
                        ThingDefCountClass thingDefCountClass = def.costList[j];
                        num += (float)thingDefCountClass.count * thingDefCountClass.thingDef.BaseMarketValue;
                    }
                }
                if (def.costStuffCount > 0)
                {
                    if (stuffDef != null)
                    {
                        num += (float)def.costStuffCount / stuffDef.VolumePerUnit * stuffDef.GetStatValueAbstract(StatDefOf.MarketValue, null);
                    }
                    else
                    {
                        num += (float)def.costStuffCount * 2f;
                    }
                }
            }
            if (num2 > 2f)
            {
                num += num2 * 0.0036f;
            }
            return(num / (float)num3);
        }
Example #19
0
 private static void ChangeSteelToIron()
 {
     steelDefs = 0;
     foreach (ThingDef tdd in DefDatabase <ThingDef> .AllDefs.Where(tt =>
                                                                    tt?.costList?.Any(y => y?.thingDef == ThingDefOf.Steel) ?? false))
     {
         var tempCost    = tdd.costList.FirstOrDefault(z => z.thingDef == ThingDefOf.Steel);
         var newTempCost = new ThingDefCountClass(ThingDef.Named("LotR_Iron"), tempCost.count);
         tdd.costList.Remove(tempCost);
         tdd.costList.Add(newTempCost);
         steelDefs++;
     }
     Log.Message("Replaced " + steelDefs + " defs with Iron.");
 }
 private static bool ResourceValidator(Pawn pawn, ThingDefCountClass need, Thing th)
 {
     if (th.def != need.thingDef)
     {
         return(false);
     }
     if (th.IsForbidden(pawn))
     {
         return(false);
     }
     if (!pawn.CanReserve(th))
     {
         return(false);
     }
     return(true);
 }
Example #21
0
        public override void PostLoad()
        {
            base.PostLoad();

            if (this.products == null)
            {
                var thingCountClass = new ThingDefCountClass();
                DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(thingCountClass, "thingDef", "Mizu_NormalWater");
                thingCountClass.count = 1;

                this.products = new List <ThingDefCountClass>()
                {
                    thingCountClass,
                };
            }
        }
Example #22
0
        public List <ThingDefCountClass> MaterialsNeeded()
        {
            this.cachedMaterialsNeeded.Clear();
            List <ThingDefCountClass> list = this.def.entityDefToBuild.CostListAdjusted(base.Stuff, true);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass thingDefCountClass = list[i];
                int num  = this.resourceContainer.TotalStackCountOfDef(thingDefCountClass.thingDef);
                int num2 = thingDefCountClass.count - num;
                if (num2 > 0)
                {
                    this.cachedMaterialsNeeded.Add(new ThingDefCountClass(thingDefCountClass.thingDef, num2));
                }
            }
            return(this.cachedMaterialsNeeded);
        }
Example #23
0
        protected Job UpgradeNodeDeliverJob(Pawn pawn, VehiclePawn vehicle)
        {
            UpgradeNode u = vehicle.CompUpgradeTree.NodeUnlocking;
            List <ThingDefCountClass> materials = u.MaterialsRequired().ToList();
            int count = materials.Count;

            bool flag = false;
            ThingDefCountClass thingDefCountClass = null;
            var reservationManager = vehicle.Map.GetCachedMapComponent <VehicleReservationManager>();

            for (int i = 0; i < count; i++)
            {
                ThingDefCountClass materialRequired = materials[i];

                if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(materialRequired, pawn))
                {
                    flag = true;
                    thingDefCountClass = materialRequired;
                    break;
                }

                Thing foundResource = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(materialRequired.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn,
                                                                                                                                                                                            Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing t) => t.def == materialRequired.thingDef && !t.IsForbidden(pawn) && pawn.CanReserve(t, 1, -1, null, false));

                if (foundResource != null && pawn.Map.GetCachedMapComponent <VehicleReservationManager>().CanReserve <ThingDefCountClass, VehicleNodeReservation>(vehicle, pawn, null))
                {
                    FindAvailableNearbyResources(foundResource, pawn, out int resourceTotalAvailable);
                    Job job      = JobMaker.MakeJob(JobDefOf_Vehicles.LoadUpgradeMaterials, foundResource, vehicle);
                    int matCount = reservationManager.GetReservation <VehicleNodeReservation>(vehicle)?.MaterialsLeft().FirstOrDefault(m => m.thingDef == foundResource.def)?.count ?? int.MaxValue;
                    job.count = foundResource.stackCount > matCount ? matCount : foundResource.stackCount;
                    return(job);
                }
                else
                {
                    flag = true;
                    thingDefCountClass = materialRequired;
                }
            }

            if (flag)
            {
                JobFailReason.Is(string.Format($"{"MissingMaterials".Translate()}: {thingDefCountClass.thingDef.label}"), null);
            }
            return(null);
        }
        protected override Toil GiveAsMuchToShipAsPossible()
        {
            return(new Toil
            {
                initAction = delegate()
                {
                    if (Item is null)
                    {
                        pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                    }
                    else
                    {
                        ThingDefCountClass materialRequired = Vehicle.CompUpgradeTree.NodeUnlocking.MaterialsRequired().FirstOrDefault(x => x.thingDef == Item.def);

                        if (ThingDef is null || ThingDef.count <= 0)
                        {
                            pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                        }
        public static void DrawBridgeCost(Designator_Build designator, Vector2 drawPos, float curY, ThingDef stuff)
        {
            DesignationDragger dragger  = Find.DesignatorManager.Dragger;
            int bridgeCount             = 0;
            IEnumerable <IntVec3> cells = dragger.Dragging ? dragger.DragCells :
                                          GenAdj.OccupiedRect(UI.MouseCell(), designator.PlacingRot(), designator.PlacingDef.Size).Cells;

            foreach (IntVec3 dragPos in cells)
            {
                if (PlaceBridges.NeedsBridge(designator.PlacingDef, dragPos, designator.Map, stuff))
                {
                    bridgeCount++;
                }
            }

            if (bridgeCount == 0)
            {
                return;
            }

            //could just say wood here, this is still assuming it costs only one thing.
            ThingDefCountClass bridgeCost = TerrainDefOf.Bridge.costList.First();

            Widgets.ThingIcon(new Rect(drawPos.x, drawPos.y + curY, 27f, 27f), bridgeCost.thingDef);

            int totalCost = bridgeCost.count * bridgeCount;

            string label = $"{totalCost} ({TerrainDefOf.Bridge.LabelCap})";

            //This doesn't account for normal building cost + under bridge cost, but what can you do
            if (designator.Map.resourceCounter.GetCount(bridgeCost.thingDef) < totalCost)
            {
                GUI.color = Color.red;
                label     = label + " (" + "NotEnoughStoredLower".Translate() + ")";
            }
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(new Rect(drawPos.x + 29f, drawPos.y + curY, 999f, 29f), label);
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }
        public static List <ThingDefCountClass> FilterForExpected(List <ThingDefCountClass> materialsNeeded, Thing c)
        {
            List <ThingDefCountClass> needs = new List <ThingDefCountClass>(materialsNeeded.Count);

            foreach (var t in materialsNeeded)
            {
                needs.Add(new ThingDefCountClass(t.thingDef, t.count));
            }

            for (int i = 0; i < needs.Count; i++)
            {
                ThingDefCountClass thingNeeds = needs[i];
                thingNeeds.count -= ExpectingComp.ExpectedCount(c, thingNeeds.thingDef);
                if (thingNeeds.count <= 0)
                {
                    needs.Remove(thingNeeds);
                    i--;
                }
            }
            return(needs);
        }
Example #27
0
        private static RecipeDef CreateMiningRecipe(ThingDefCountClass defCount)
        {
            RecipeDef r = new RecipeDef();

            r.defName   = "Recipe_NR_AutoMachineTool_Mine_" + defCount.thingDef.defName;
            r.label     = "NR_AutoMachineTool.AutoMiner.MineOre".Translate(defCount.thingDef.label);
            r.jobString = "NR_AutoMachineTool.AutoMiner.MineOre".Translate(defCount.thingDef.label);

            r.workAmount     = Mathf.Max(10000f, StatDefOf.MarketValue.Worker.GetValue(StatRequest.For(defCount.thingDef, null)) * defCount.count * 1000);
            r.workSpeedStat  = StatDefOf.WorkToMake;
            r.efficiencyStat = StatDefOf.WorkToMake;

            r.workSkill            = SkillDefOf.Mining;
            r.workSkillLearnFactor = 0;

            r.products = new List <ThingDefCountClass>().Append(defCount);
            r.defaultIngredientFilter = new ThingFilter();

            r.effectWorking = EffecterDefOf.Drill;

            return(r);
        }
        // Token: 0x060000D9 RID: 217 RVA: 0x00006D5C File Offset: 0x00004F5C
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(this.GetInspectString());
            stringBuilder.AppendLine(Translator.Translate("ContainedResources") + ":");
            List <ThingDefCountClass> list = CostListCalculator.CostListAdjusted(base.def.entityDefToBuild, this.Stuff, true);

            for (int i = 0; i < list.Count; i++)
            {
                ThingDefCountClass need = list[i];
                int num = need.count;
                foreach (ThingDefCountClass item in from needed in MaterialsNeeded()
                         where needed.thingDef == need.thingDef
                         select needed)
                {
                    num -= item.count;
                }
                stringBuilder.AppendLine(need.thingDef.LabelCap + ": " + num + " / " + need.count);
            }
            stringBuilder.Append(Translator.Translate("WorkLeft") + ": " + GenText.ToStringWorkAmount(WorkLeft));
            return(stringBuilder.ToString());
        }
 // Token: 0x06000002 RID: 2 RVA: 0x00002090 File Offset: 0x00000290
 private static void MakeButcherProducts_PostFix(Thing __instance, ref IEnumerable <Thing> __result, Pawn butcher, float efficiency)
 {
     //    Log.Message(string.Format("{0}", __instance));
     if (__instance is Pawn pawn)
     {
         //    Log.Message(string.Format("{0} is Pawn pawn", __instance));
         if (XenomorphUtil.IsXenomorph(pawn))
         {
             //    Log.Message(string.Format("{0} Pawn pawn is Xenomorph", __instance));
             foreach (var item in pawn.health.hediffSet.GetNotMissingParts())
             {
                 if (item.def == XenomorphDefOf.RRY_Xeno_TailSpike)
                 {
                     ThingDefCountClass thingDefCountClass = new ThingDefCountClass
                     {
                         thingDef = XenomorphDefOf.RRY_Xenomorph_TailSpike,
                         count    = 1
                     };
                     Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                     thing.stackCount = thingDefCountClass.count;
                     __result         = __result.AddItem(thing);
                 }
                 if (item.def == XenomorphDefOf.RRY_Xeno_Shell)
                 {
                     ThingDefCountClass thingDefCountClass = new ThingDefCountClass
                     {
                         thingDef = XenomorphDefOf.RRY_Xenomorph_HeadShell,
                         count    = 1
                     };
                     Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                     thing.stackCount = thingDefCountClass.count;
                     __result         = __result.AddItem(thing);
                 }
             }
         }
     }
 }
Example #30
0
 public static void GenerateInventoryFor(Pawn p, PawnGenerationRequest request)
 {
     p.inventory.DestroyAll();
     for (int i = 0; i < p.kindDef.fixedInventory.Count; i++)
     {
         ThingDefCountClass thingDefCountClass = p.kindDef.fixedInventory[i];
         Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef);
         thing.stackCount = thingDefCountClass.count;
         p.inventory.innerContainer.TryAdd(thing);
     }
     if (p.kindDef.inventoryOptions != null)
     {
         foreach (Thing item in p.kindDef.inventoryOptions.GenerateThings())
         {
             p.inventory.innerContainer.TryAdd(item);
         }
     }
     if (request.AllowFood)
     {
         GiveRandomFood(p);
     }
     GiveDrugsIfAddicted(p);
     GiveCombatEnhancingDrugs(p);
 }