Ejemplo n.º 1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(LoreCompIndex);

            Building_LoreComputer lorecomp = this.job.GetTarget(TargetIndex.A).Thing as Building_LoreComputer;

            _loreDataDisk = lorecomp.GetLocationOfOwnedThing("LockedDatadisk");
            this.job.SetTarget(DataDiskIndex, _loreDataDisk);

            //haul the locked datadisk to the analyzer
            yield return(Toils_Goto.GotoThing(DataDiskIndex, PathEndMode.Touch));

            this.pawn.CurJob.count    = 1;
            this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;
            yield return(Toils_Haul.StartCarryThing(DataDiskIndex, false, false));

            var GetHeldDisk = new Toil();

            GetHeldDisk.initAction = delegate
            {
                this.job.SetTarget(HeldDiskIndex, this.pawn.carryTracker.CarriedThing);
                _heldDataDisk = this.job.GetTarget(HeldDiskIndex).Thing;
            };

            yield return(GetHeldDisk);

            yield return(Toils_Goto.GotoThing(LoreCompIndex, PathEndMode.Touch));

            yield return(Toils_Haul.PlaceHauledThingInCell(LoreCompIndex, Toils_Goto.GotoThing(LoreCompIndex, PathEndMode.Touch), false));

            // perform work toil (decode the datadisk)
            var decodeTheData = new Toil();

            decodeTheData.initAction = delegate
            {
                _heldDataDisk.Destroy();
                //make a new unlocked datadisk based on weighting
                // show alert when complete
                Thing temp = ThingMaker.MakeThing(LoreComputerHarmonyPatches.ChooseDataDiskTypeOnDecrypt().def);

                GenSpawn.Spawn(temp.def, _loreComp.Position, _loreComp.Map);

                Find.LetterStack.ReceiveLetter("Datadisk decoded", "A datadisk has been decoded.", LetterDefOf.PositiveEvent);
            };

            yield return(decodeTheData);

            yield break;
        }
Ejemplo n.º 2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(LoreCompIndex);

            Building_LoreComputer lorecomp = this.job.GetTarget(TargetIndex.A).Thing as Building_LoreComputer;

            _researchDisk = lorecomp.GetLocationOfOwnedThing("ResearchDatadisk");
            this.job.SetTarget(DataDiskIndex, _researchDisk);

            yield return(Toils_Goto.GotoThing(DataDiskIndex, PathEndMode.Touch));

            this.pawn.CurJob.count    = 1; // this controls the num of times the pawn will do the toils, e.g count of 50 will make pawn do the entire job 50 times
            this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;

            yield return(Toils_Haul.StartCarryThing(DataDiskIndex, false, false));

            var GetHeldDisk = new Toil();

            GetHeldDisk.initAction = delegate
            {
                this.job.SetTarget(HeldDiskIndex, this.pawn.carryTracker.CarriedThing);
                _heldDataDisk = this.job.GetTarget(HeldDiskIndex).Thing;
            };
            yield return(GetHeldDisk);

            yield return(Toils_Goto.GotoThing(LoreCompIndex, PathEndMode.Touch));

            yield return(Toils_Haul.PlaceHauledThingInCell(LoreCompIndex, Toils_Goto.GotoThing(LoreCompIndex, PathEndMode.Touch), false));

            // perform work toil
            var loadResearchDisk = new Toil();

            loadResearchDisk.initAction = delegate
            {
                _heldDataDisk.Destroy();
                // get a random research from entire list
                string result = LoreComputerHarmonyPatches.SelectResearchByUniformCumulativeProb(LoreComputerHarmonyPatches.UndiscoveredResearchList.MainResearchDict.Values.ToList());
                LoreComputerHarmonyPatches.AddNewResearch(result);

                Find.LetterStack.ReceiveLetter("Research Disk Loaded", "A Research disk has been loaded, and it's research data is now usable.", LetterDefOf.PositiveEvent);
            };

            yield return(loadResearchDisk);

            yield break;
        }
Ejemplo n.º 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(CabinetIndex);

            Building_ExperimentFilingCabinet cabinet = this.job.GetTarget(TargetIndex.A).Thing as Building_ExperimentFilingCabinet;

            var thingList = LoreComputerHarmonyPatches.GetAllOfThingsOnMap("FinishedExperiment");

            if (thingList.Count == 0)
            {
                yield break;
            }

            var curExp = thingList[thingList.Count - 1] as Thing_FinishedExperiment;

            if (thingList.Count > 0)
            {// this appears to be only way to enqueue new custom jobs without using work/jobgiver
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] == curExp)
                    {
                        break;
                    }
                    var newJob = JobMaker.MakeJob(AddExperimentJobDefOf.CabinetAddExperiment, cabinet);
                    newJob.count = 1;
                    pawn.jobs.jobQueue.EnqueueFirst(newJob);
                }
            }


            _currentFinishedExperiment = curExp;
            this.job.SetTarget(ExperimentIndex, _currentFinishedExperiment);

            yield return(Toils_Goto.GotoThing(ExperimentIndex, PathEndMode.Touch));

            this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;

            yield return(Toils_Haul.StartCarryThing(ExperimentIndex, false, false));

            var GetHeldThing = new Toil();

            GetHeldThing.initAction = delegate
            {
                this.job.SetTarget(HeldExperimentIndex, this.pawn.carryTracker.CarriedThing);
                _heldThing = this.job.GetTarget(HeldExperimentIndex).Thing;
            };
            yield return(GetHeldThing);

            yield return(Toils_Goto.GotoThing(CabinetIndex, PathEndMode.Touch));

            yield return(Toils_Haul.PlaceHauledThingInCell(CabinetIndex, Toils_Goto.GotoThing(CabinetIndex, PathEndMode.Touch), false));

            // perform work toil
            var AddExperiment = new Toil();

            AddExperiment.initAction = delegate
            {
                cabinet.AddExperimentToCabinet(_heldThing);
                _heldThing.Destroy();
            };

            yield return(AddExperiment);
        }
        public override void DoWindowContents(Rect inRect)
        {
            string selectedExp          = "";
            string selectedExpType      = "";
            string recipeDescription    = "Invalid Recipe Combination.";
            bool   isExperimentSelected = false;

            //title
            Rect rect1 = new Rect(inRect.center.x - 80f, inRect.yMin + 35f, 200f, 74f);

            Text.Font = GameFont.Medium;
            Widgets.Label(rect1, "Experiment Setup");

            // Exit button
            Rect exitRect = new Rect(inRect.xMax - 50f, inRect.yMin + 5f, 50f, 30f);

            if (Widgets.ButtonText(exitRect, "Exit"))
            {
                this.Close();
            }

            // explain text
            Rect rect2 = new Rect(inRect);

            rect2.yMin  = rect1.yMax;
            rect2.yMax -= 38f;
            Text.Font   = GameFont.Small;
            Widgets.Label(rect2, "You can perform different types and sizes of experiments here, determining what kind of research you can unlock. The size of the research helps increase your chances of obtaining better research.");

            // 'select experiment' list
            Rect AddExpRect = new Rect(rect2);

            AddExpRect.width   = 550f;//275f;
            AddExpRect.height /= 2;
            AddExpRect.y      += 70f;
            AddExpRect.x      += 370f;

            //ExpList.DrawTextList(AddExpRect, _experimentNames, "Experiment Types");
            selectedExp = ExpList.SelectedEntry != null ? ExpList.SelectedEntry.EntryLabel : "None Selected";
            ExpList.DrawImageList(AddExpRect, "Experiment Types");

            // 'select type' list
            Rect AddExpTypeRect = new Rect(AddExpRect);

            AddExpTypeRect.x -= 310f;
            //AddExpTypeRect.ContractedBy(20f);
            AddExpTypeRect.width = 550f;//275f;
            //AddExpTypeRect.y += 20f;

            //ExpTypeList.DrawTextList(AddExpTypeRect, _experimentTypes, "Experiment Sizes");
            selectedExpType = ExpTypeList.SelectedEntry != null ? ExpTypeList.SelectedEntry.EntryLabel : "";
            ExpTypeList.DrawImageList(AddExpTypeRect, "Experiment Sizes");

            // need to get defName of recipe from this point
            _selectedExperimentDefName = selectedExpType + selectedExp;

            if (!(from t in DefDatabase <RecipeDef> .AllDefsListForReading where t.defName == _selectedExperimentDefName select t).TryRandomElement(out RecipeDef finalDef))
            {
                //Log.Error("Def not found");
                isExperimentSelected = false;
            }
            else
            {
                isExperimentSelected = true;
                _selectedRecipe      = finalDef;
                recipeDescription    = _selectedRecipe.description;
            }

            // text explaining selection, e.g. 'Small Biological Research Project - will help unlock biological research'
            Rect rect3 = new Rect(inRect.position, rect2.size);

            rect3.x   = inRect.center.x - 150f;
            rect3.y   = inRect.yMax - 100f;
            Text.Font = GameFont.Medium;
            Widgets.Label(rect3, _selectedExperimentDefName);

            Text.Font = GameFont.Small;
            Rect rect4 = rect3;

            rect4.x = inRect.x;
            rect4.y = inRect.yMax - 210f;
            Widgets.Label(rect4, recipeDescription);

            Rect rect5 = rect4;

            rect5.x = inRect.x;
            rect5.y = inRect.yMax - 160f;
            if (_selectedRecipe.HasModExtension <ResearchDefModExtension>())
            {
                Widgets.Label(rect5, "Potential Research Projects left to discover: " + LoreComputerHarmonyPatches.GetNumOfUnfoundProjsByRecipe(_selectedRecipe));
            }

            // confirm button
            Rect rect6 = new Rect(inRect.center.x - 100f, inRect.yMax - 35f, 150f, 29f);

            if (Widgets.ButtonText(rect6, "Confirm Experiment"))
            {
                if (isExperimentSelected == true)
                {
                    // TODO: change the assumption above to something less naive
                    Bill       newExpBill = (Bill_ProductionWithUft)_selectedRecipe.MakeNewBill();
                    Experiment newExp     = MakeNewExperiment();
                    _selectedTable.ExpStack.AddExperiment(newExp);
                    _selectedTable.ExpStack.AddExperimentWithBill(newExpBill);
                    isExperimentSelected = false;
                    this.Close();
                }
                else
                {
                    Dialog_MessageBox window = Dialog_MessageBox.CreateConfirmation("No Experiment Selected", delegate
                    {
                    }, destructive: true);
                    Find.WindowStack.Add(window);
                }
            }
            // exit button?
        }