Example #1
0
            public static bool Prefix(Bill __instance, ref bool __result)
            {
                MeeseeksBillStorage billStorage = Current.Game.World.GetComponent <MeeseeksBillStorage>();

                if (billStorage.IsDuplicate(__instance))
                {
                    __result = __instance.deleted;
                    return(false);
                }

                return(true);
            }
        private Job GetMedicalBillJob(Pawn meeseeks, CompMeeseeksMemory memory, SavedJob savedJob, SavedTargetInfo jobTarget, ref JobAvailability jobAvailabilty)
        {
            Bill_Medical bill = jobTarget.bill as Bill_Medical;
            Job          job  = null;

            if (jobTarget != null && jobTarget.HasThing && !jobTarget.ThingDestroyed && jobTarget.Thing is Pawn && !(jobTarget.Thing as Pawn).Dead)
            {
                Pawn targetPawn = jobTarget.Thing as Pawn;
                if (targetPawn == null || targetPawn.Dead || !bill.CompletableEver)
                {
                    bill.deleted   = true;
                    jobAvailabilty = JobAvailability.Complete;
                }
                else
                {
                    MeeseeksBillStorage billStorage = Current.Game.World.GetComponent <MeeseeksBillStorage>();
                    BillStack           billStack   = targetPawn.BillStack;

                    jobAvailabilty = JobAvailability.Delayed;

                    if (targetPawn.UsableForBillsAfterFueling() && meeseeks.CanReserve(targetPawn, 1, -1, null, true))
                    {
                        List <ThingCount> chosenIngredients = new List <ThingCount>();
                        // Screw you I need this function
                        bool result = (bool)typeof(WorkGiver_DoBill).GetMethod("TryFindBestBillIngredients", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { bill, meeseeks, targetPawn, chosenIngredients });

                        if (result)
                        {
                            Job haulOffJob;
                            job = WorkGiver_DoBill.TryStartNewDoBillJob(meeseeks, bill, targetPawn, chosenIngredients, out haulOffJob);
                            bill.billStack.billGiver = targetPawn as IBillGiver;
                        }

                        if (job == null)
                        {
                            jobAvailabilty = JobAvailability.Delayed;
                        }
                        else
                        {
                            jobAvailabilty = JobAvailability.Available;
                        }
                    }
                }
            }
            else
            {
                bill.deleted   = true;
                jobAvailabilty = JobAvailability.Complete;
            }

            return(job);
        }
Example #3
0
            public static void Postfix(ref Bill_Production __instance, Pawn billDoer, List <Thing> ingredients)
            {
                if (recursing == true)
                {
                    return;// true;
                }
                MeeseeksBillStorage billStorage = Current.Game.World.GetComponent <MeeseeksBillStorage>();

                Bill_Production originalBill  = billStorage.GetOriginalBillFromDuplicate(__instance) as Bill_Production;
                Bill_Production duplicateBill = billStorage.GetDuplicateBillFromOriginal(__instance) as Bill_Production;

                if (originalBill == null && duplicateBill == null)
                {
                }
                // The finished iteration was on an original bill, doesn't matter who did it, mirror the result
                else if (duplicateBill != null)
                {
                    UpdateBill(duplicateBill);
                    return;// true;
                }
                // The finished iteration was on a duplicate bill, copy the result to the original, if it exists and make sure the duplicate is properly updated and check for deletion
                else if (billStorage.IsDuplicate(__instance))
                {
                    UpdateBill(__instance, false);

                    if (originalBill != null)
                    {
                        try
                        {
                            recursing = true;
                            originalBill.Notify_IterationCompleted(billDoer, ingredients);
                        }
                        finally
                        {
                            recursing = false;
                        }
                    }

                    //return false;
                }

                //return true;
            }
        public void AddJobTarget(SavedTargetInfo target, bool firstTarget = false)
        {
            if (jobTargets.Contains(target))
            {
                return;
            }

            if (target.HasThing && savedJob.bill != null)
            {
                MeeseeksBillStorage billStorage = Current.Game.World.GetComponent <MeeseeksBillStorage>();

                if (firstTarget)
                {
                    billStorage.SaveBill(savedJob.bill);
                    savedJob.bill = billStorage.GetDuplicateBillFromOriginal(savedJob.bill);
                    savedJob.bill.billStack.billGiver = target.Thing as IBillGiver;
                }

                WorkGiver_Scanner workGiverScanner = savedJob.workGiverDef.Worker as WorkGiver_Scanner;
                if (workGiverScanner != null)
                {
                    Job job = workGiverScanner.JobOnThing(Meeseeks, target.Thing, true);
                    if (job != null && job.bill != null)
                    {
                        billStorage.SaveBill(job.bill);
                        target.bill = billStorage.GetDuplicateBillFromOriginal(job.bill);
                        target.bill.billStack.billGiver = target.Thing as IBillGiver;
                    }
                }
            }
            else if (target.HasThing && savedJob.IsConstruction)
            {
                ThingDef   thingDefToBuild   = null;
                TerrainDef terrainDefToBuild = null;
                ThingDef   stuffDefToUse     = null;

                Blueprint_Build blueprint = target.Thing as Blueprint_Build;
                Frame           frame     = target.Thing as Frame;

                if (blueprint != null)
                {
                    thingDefToBuild   = blueprint.def.entityDefToBuild as ThingDef;
                    terrainDefToBuild = blueprint.def.entityDefToBuild as TerrainDef;
                    stuffDefToUse     = blueprint.stuffToUse;
                }
                else if (frame != null)
                {
                    thingDefToBuild   = frame.def.entityDefToBuild as ThingDef;
                    terrainDefToBuild = frame.def.entityDefToBuild as TerrainDef;
                    stuffDefToUse     = frame.Stuff;
                }

                if (thingDefToBuild != null)
                {
                    target.blueprintThingDef = thingDefToBuild;
                }
                else if (terrainDefToBuild != null)
                {
                    target.blueprintTerrainDef = terrainDefToBuild;
                }

                target.blueprintStuff    = stuffDefToUse;
                target.blueprintRotation = target.Thing.Rotation;

                // Redirect job to the cell so that we can continue various construction phases and replace blueprint if needed
                target.target = target.Cell;
            }
            else if (target.HasThing && savedJob.IsTraining)
            {
                target.trainable = (target.Thing as Pawn).training.NextTrainableToTrain();
            }

            jobTargets.Add(target);
        }