private Thing FindIngredient(Pawn pawn, string thirdItem, Building_ItemProcessor building_processor)
        {
            if (building_processor.compItemProcessor.Props.isCategoryBuilding)
            {
                Predicate <Thing> predicate = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false);
                IntVec3           position  = pawn.Position;
                Map          map            = pawn.Map;
                List <Thing> searchSet      = new List <Thing>();
                foreach (ThingDef thingDef in ThingCategoryDef.Named(thirdItem).childThingDefs)
                {
                    if (!(DefDatabase <CombinationDef> .GetNamed(building_processor.thisRecipe).disallowedThingDefs != null &&
                          DefDatabase <CombinationDef> .GetNamed(building_processor.thisRecipe).disallowedThingDefs.Contains(thingDef.defName)))
                    {
                        searchSet.AddRange(pawn.Map.listerThings.ThingsOfDef(thingDef));
                    }
                }

                TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = predicate;
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                return(GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, searchSet, peMode, traverseParams, 9999f, validator, null));
            }
            else
            {
                Predicate <Thing> predicate      = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false);
                IntVec3           position       = pawn.Position;
                Map               map            = pawn.Map;
                ThingRequest      thingReq       = ThingRequest.ForDef(ThingDef.Named(thirdItem));
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = predicate;
                return(GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
            }
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_ItemProcessor building_processor = t as Building_ItemProcessor;

            if (building_processor == null || building_processor.GetComp <CompItemProcessor>().Props.isCompletelyAutoMachine || building_processor.processorStage != ProcessorStage.ExpectingIngredients || building_processor.thirdIngredientComplete || building_processor.thirdItem == "")
            {
                return(false);
            }

            if (!t.IsForbidden(pawn))
            {
                LocalTargetInfo target = t;
                if (pawn.CanReserve(target, 1, 1, null, forced))
                {
                    if (pawn.Map.designationManager.DesignationOn(t, DesignationDefOf.Deconstruct) != null)
                    {
                        return(false);
                    }
                    if (this.FindIngredient(pawn, building_processor.thirdItem, building_processor) == null)
                    {
                        JobFailReason.Is(WorkGiver_InsertProcessorThird.NoIngredientFound, null);
                        return(false);
                    }
                    return(!t.IsBurning());
                }
            }
            return(false);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_ItemProcessor building_processor = (Building_ItemProcessor)t;
            Thing t2 = this.FindIngredient(pawn, building_processor.thirdItem, building_processor);

            return(new Job(DefDatabase <JobDef> .GetNamed("IP_InsertThirdIngredient", true), t, t2));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Log.Message("I am inside the job now, with "+pawn.ToString(), false);
            Building_ItemProcessor building_processor = (Building_ItemProcessor)this.job.GetTarget(TargetIndex.A).Thing;

            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_General.DoAtomic(delegate
            {
                if (building_processor.ExpectedAmountSecondIngredient != 0)
                {
                    this.job.count = building_processor.ExpectedAmountSecondIngredient - building_processor.CurrentAmountSecondIngredient;
                }
                else
                {
                    this.job.count = 1;
                }
            }));

            Toil reserveIngredient = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null);

            yield return(reserveIngredient);

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnSomeonePhysicallyInteracting(TargetIndex.B));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, true, false).FailOnDestroyedNullOrForbidden(TargetIndex.B));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveIngredient, TargetIndex.B, TargetIndex.None, true, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(200, TargetIndex.None).FailOnDestroyedNullOrForbidden(TargetIndex.B).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    if (building_processor.processorStage != ProcessorStage.Inactive)
                    {
                        if (building_processor.compItemProcessor.Props.transfersIngredientLists)
                        {
                            if (this.job.targetB.Thing.TryGetComp <CompIngredients>() is CompIngredients ingredientComp)
                            {
                                building_processor.ingredients.AddRange(ingredientComp.ingredients);
                            }
                        }

                        building_processor.CurrentAmountSecondIngredient += this.job.targetB.Thing.stackCount;
                        if (building_processor.ExpectedAmountSecondIngredient != 0)
                        {
                            if (building_processor.CurrentAmountSecondIngredient >= building_processor.ExpectedAmountSecondIngredient)
                            {
                                building_processor.secondIngredientComplete = true;
                            }
                        }
                        building_processor.TryAcceptSecond(this.job.targetB.Thing, 0, true);
                        building_processor.Notify_StartProcessing();
                        //this.job.targetB.Thing.Destroy();
                    }
                },
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_ItemProcessor building_processor = t as Building_ItemProcessor;
            bool result;

            if (building_processor == null || building_processor.processorStage != ProcessorStage.Finished)
            {
                return(false);
            }

            else
            {
                if (!t.IsForbidden(pawn))
                {
                    LocalTargetInfo target = t;
                    if (pawn.CanReserve(target, 1, -1, null, forced))
                    {
                        result = true;
                        return(result);
                    }
                }
                result = false;
            }
            return(result);
        }
예제 #6
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Log.Message("I am inside the job now, with "+pawn.ToString(), false);
            Building_ItemProcessor building_processor = (Building_ItemProcessor)this.job.GetTarget(TargetIndex.A).Thing;

            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_General.DoAtomic(delegate
            {
                this.job.count = 1;
            }));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(240).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing newProduct;
                    if (building_processor.productsToTurnInto != null && building_processor.productsToTurnInto.Count > 0)
                    {
                        newProduct = ThingMaker.MakeThing(ThingDef.Named(building_processor.productsToTurnInto[(int)building_processor.qualityNow]));
                    }
                    else
                    {
                        newProduct = ThingMaker.MakeThing(ThingDef.Named(building_processor.productToTurnInto));
                    }

                    newProduct.stackCount = building_processor.amount;

                    if ((newProduct.TryGetComp <CompIngredients>() is CompIngredients ingredientComp) && !building_processor.compItemProcessor.Props.ignoresIngredientLists)
                    {
                        ingredientComp.ingredients = building_processor.ingredients;
                    }
                    if (building_processor.usingQualityIncreasing && newProduct.TryGetComp <CompQuality>() is CompQuality qualityComp)
                    {
                        qualityComp.SetQuality(building_processor.qualityNow, ArtGenerationContext.Colony);
                    }

                    GenSpawn.Spawn(newProduct, building_processor.InteractionCell, building_processor.Map);
                    building_processor.processorStage = ProcessorStage.ProductRemoved;
                    building_processor.ResetEverything();
                    building_processor.DestroyIngredients();

                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(newProduct);
                    IntVec3 c;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(newProduct, this.pawn, this.Map, currentPriority, this.pawn.Faction, out c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, newProduct);
                        this.job.count = newProduct.stackCount;
                    }
                    else
                    {
                        this.EndJobWith(JobCondition.Incompletable);
                    }
                },
예제 #7
0
        public override void Notify_PatherFailed()
        {
            Building_ItemProcessor building_processor = (Building_ItemProcessor)this.job.GetTarget(TargetIndex.A).Thing;

            building_processor.processorStage = ProcessorStage.IngredientsChosen;

            this.EndJobWith(JobCondition.ErroredPather);
        }
        public Command_SetFirstItemList()
        {
            //Loops through all things selected right now to see if it finds an item processor building
            //Just in case, item processors disable its Gizmos (buttons) if there are more things selected
            foreach (object obj in Find.Selector.SelectedObjects)
            {
                building = obj as Building_ItemProcessor;
                if (building != null)
                {
                    if (building.firstItem == "")
                    {
                        //If a first ingredient hasn't been chosen yet, show an empty "choose ingredient" button. This is configurable in each building
                        icon = ContentFinder <Texture2D> .Get(building.compItemProcessor.Props.chooseIngredientsIcon, true);

                        defaultLabel = "IP_ChooseIngredient".Translate();
                    }
                    foreach (ItemAcceptedDef element in DefDatabase <ItemAcceptedDef> .AllDefs.Where(element => (element.building == building.def.defName) && (element.slot == 1)))
                    {
                        foreach (string item in element.items)
                        {
                            //If a first ingredient has been chosen, then show the graphic of that ingredient

                            if (building.firstItem == item)
                            {
                                if (building.compItemProcessor.Props.isCategoryBuilding)
                                {
                                    icon = ContentFinder <Texture2D> .Get(ThingCategoryDef.Named(item).iconPath, true);

                                    defaultLabel = "IP_InsertVariable".Translate(ThingCategoryDef.Named(item).LabelCap);
                                }
                                else
                                {
                                    if (ThingDef.Named(item).graphicData.graphicClass == typeof(Graphic_StackCount))
                                    {
                                        icon = ContentFinder <Texture2D> .Get(ThingDef.Named(item).graphic.path + "/" + ThingDef.Named(item).defName + "_b", false);

                                        if (icon == null)
                                        {
                                            icon = ContentFinder <Texture2D> .Get(ThingDef.Named(item).graphic.path + "/" + ThingDef.Named(item).defName, false);
                                        }
                                    }
                                    else
                                    {
                                        icon = ContentFinder <Texture2D> .Get(ThingDef.Named(item).graphic.path, false);
                                    }

                                    defaultLabel = "IP_InsertVariable".Translate(ThingDef.Named(item).LabelCap);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #9
0
        private Thing FindIngredient(Pawn pawn, string thirdItem, Building_ItemProcessor building_processor)
        {
            Predicate <Thing> predicate      = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false);
            IntVec3           position       = pawn.Position;
            Map               map            = pawn.Map;
            ThingRequest      thingReq       = ThingRequest.ForDef(ThingDef.Named(thirdItem));
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
            Predicate <Thing> validator      = predicate;

            return(GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
        }
        public Command_SetFourthItemList()
        {
            foreach (object obj in Find.Selector.SelectedObjects)
            {
                building = obj as Building_ItemProcessor;
                if (building != null)
                {
                    if (building.fourthItem == "")
                    {
                        icon = ContentFinder <Texture2D> .Get(building.compItemProcessor.Props.chooseIngredientsIcon, true);

                        defaultLabel = "IP_ChooseIngredientFourth".Translate();
                    }
                    foreach (ItemAcceptedDef element in DefDatabase <ItemAcceptedDef> .AllDefs.Where(element => (element.building == building.def.defName) && (element.slot == 4)))
                    {
                        foreach (string item in element.items)
                        {
                            if (building.fourthItem == item)
                            {
                                if (building.compItemProcessor.Props.isCategoryBuilding)
                                {
                                    icon = ContentFinder <Texture2D> .Get(ThingCategoryDef.Named(item).iconPath, true);

                                    defaultLabel = "IP_InsertVariable".Translate(ThingCategoryDef.Named(item).LabelCap);
                                }
                                else
                                {
                                    if (ThingDef.Named(item).graphicData.graphicClass == typeof(Graphic_StackCount))
                                    {
                                        icon = ContentFinder <Texture2D> .Get(ThingDef.Named(item).graphic.path + "/" + ThingDef.Named(item).defName + "_b", false);

                                        if (icon == null)
                                        {
                                            icon = ContentFinder <Texture2D> .Get(ThingDef.Named(item).graphic.path + "/" + ThingDef.Named(item).defName, false);
                                        }
                                    }
                                    else
                                    {
                                        icon = ContentFinder <Texture2D> .Get(ThingDef.Named(item).graphic.path, false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public Command_SetQualityList()
        {
            foreach (object obj in Find.Selector.SelectedObjects)
            {
                building = obj as Building_ItemProcessor;
                if (building != null)
                {
                    if (!building.qualityEstablished)
                    {
                        icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityAuto", true);

                        defaultLabel = "IP_ChooseQualityAuto".Translate();
                    }


                    else
                    {
                        switch (building.qualityRequested)
                        {
                        case QualityCategory.Awful:
                            icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityAwful", true);

                            defaultLabel = "IP_QualityAutoIs".Translate(QualityCategory.Awful.ToString());
                            break;

                        case QualityCategory.Poor:
                            icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityPoor", true);

                            defaultLabel = "IP_QualityAutoIs".Translate(QualityCategory.Poor.ToString());
                            break;

                        case QualityCategory.Normal:
                            icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityNormal", true);

                            defaultLabel = "IP_QualityAutoIs".Translate(QualityCategory.Normal.ToString());
                            break;

                        case QualityCategory.Good:
                            icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityGood", true);

                            defaultLabel = "IP_QualityAutoIs".Translate(QualityCategory.Good.ToString());
                            break;

                        case QualityCategory.Excellent:
                            icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityExcellent", true);

                            defaultLabel = "IP_QualityAutoIs".Translate(QualityCategory.Excellent.ToString());
                            break;

                        case QualityCategory.Masterwork:
                            icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityMasterwork", true);

                            defaultLabel = "IP_QualityAutoIs".Translate(QualityCategory.Masterwork.ToString());
                            break;

                        case QualityCategory.Legendary:
                            icon = ContentFinder <Texture2D> .Get("UI/QualitySelectors/IP_QualityLegendary", true);

                            defaultLabel = "IP_QualityAutoIs".Translate(QualityCategory.Legendary.ToString());
                            break;
                        }
                    }
                }
            }
        }
        public Command_SetOutputList()
        {
            //Loops through all things selected right now to see if it finds an item processor building
            //Just in case, item processors disable its Gizmos (buttons) if there are more things selected
            foreach (object obj in Find.Selector.SelectedObjects)
            {
                building = obj as Building_ItemProcessor;
                if (building != null)
                {
                    if (building.firstItem == "")
                    {
                        //If a first ingredient hasn't been chosen yet, show an empty "choose ingredient" button. This is configurable in each building
                        icon = ContentFinder <Texture2D> .Get(building.compItemProcessor.Props.chooseIngredientsIcon, true);

                        defaultLabel = "IP_ChooseOutput".Translate();
                    }
                    foreach (CombinationDef element in DefDatabase <CombinationDef> .AllDefs.Where(element => (element.building == building.def.defName && building.firstItem == element.items[0])))
                    {
                        //If an output has been chosen, then show the graphic of that ingredient

                        if (building.productToTurnInto == element.result)
                        {
                            if (element.resultUsesSpecialIcon)
                            {
                                icon = ContentFinder <Texture2D> .Get(element.resultSpecialIcon, false);
                            }
                            else if (ThingDef.Named(element.result).graphicData.graphicClass == typeof(Graphic_StackCount))
                            {
                                icon = ContentFinder <Texture2D> .Get(ThingDef.Named(element.result).graphic.path + "/" + ThingDef.Named(element.result).defName + "_b", false);

                                if (icon == null)
                                {
                                    icon = ContentFinder <Texture2D> .Get(ThingDef.Named(element.result).graphic.path + "/" + ThingDef.Named(element.result).defName, false);
                                }
                                if (icon == null)
                                {
                                    icon = ContentFinder <Texture2D> .Get(ThingDef.Named(element.result).graphic.path, false);
                                }
                            }
                            else
                            {
                                if (ThingDef.Named(element.result).graphic.path != null)
                                {
                                    icon = ContentFinder <Texture2D> .Get(ThingDef.Named(element.result).graphic.path, false);
                                }
                                else
                                {
                                    icon = ContentFinder <Texture2D> .Get(ThingDef.Named(element.result).graphicData.texPath, false);
                                }
                            }

                            defaultLabel = "IP_Output".Translate(ThingDef.Named(element.result).LabelCap);
                            if (element.isCategoryRecipe)
                            {
                                string categorytwoLabel   = "";
                                string categorythreeLabel = "";
                                string categoryfourLabel  = "";
                                if (element.secondItems != null)
                                {
                                    ThingCategoryDef categorytwo = DefDatabase <ThingCategoryDef> .GetNamedSilentFail(element.secondItems[0]);

                                    if (categorytwo != null)
                                    {
                                        categorytwoLabel = ", " + categorytwo.LabelCap;
                                    }
                                }
                                if (element.thirdItems != null)
                                {
                                    ThingCategoryDef categorythree = DefDatabase <ThingCategoryDef> .GetNamedSilentFail(element.thirdItems[0]);

                                    if (categorythree != null)
                                    {
                                        categorythreeLabel = ", " + categorythree.LabelCap;
                                    }
                                }
                                if (element.fourthItems != null)
                                {
                                    ThingCategoryDef categoryfour = DefDatabase <ThingCategoryDef> .GetNamedSilentFail(element.fourthItems[0]);

                                    if (categoryfour != null)
                                    {
                                        categoryfourLabel = ", " + categoryfour.LabelCap;
                                    }
                                }
                                defaultDesc = "IP_OutputDesc".Translate(ThingDef.Named(element.result).LabelCap, DefDatabase <ThingCategoryDef> .GetNamedSilentFail(building.firstItem).LabelCap
                                                                        + categorytwoLabel + categorythreeLabel + categoryfourLabel);
                            }
                            else
                            {
                                string itemtwoLabel   = "";
                                string itemthreeLabel = "";
                                string itemfourLabel  = "";
                                if (element.secondItems != null)
                                {
                                    ThingDef itemtwo = DefDatabase <ThingDef> .GetNamedSilentFail(element.secondItems[0]);

                                    if (itemtwo != null)
                                    {
                                        itemtwoLabel = ", " + itemtwo.LabelCap;
                                    }
                                }
                                if (element.thirdItems != null)
                                {
                                    ThingDef itemthree = DefDatabase <ThingDef> .GetNamedSilentFail(element.thirdItems[0]);

                                    if (itemthree != null)
                                    {
                                        itemthreeLabel = ", " + itemthree.LabelCap;
                                    }
                                }
                                if (element.fourthItems != null)
                                {
                                    ThingDef itemfour = DefDatabase <ThingDef> .GetNamedSilentFail(element.fourthItems[0]);

                                    if (itemfour != null)
                                    {
                                        itemfourLabel = ", " + itemfour.LabelCap;
                                    }
                                }
                                defaultDesc = "IP_OutputDesc".Translate(ThingDef.Named(element.result).LabelCap, DefDatabase <ThingDef> .GetNamedSilentFail(building.firstItem).LabelCap
                                                                        + itemtwoLabel + itemthreeLabel + itemfourLabel);
                            }
                        }
                    }
                }
            }
        }