Exemplo n.º 1
0
        private Toil Upgrade()
        {
            var upgrade = new Toil();

            upgrade.tickAction = delegate
            {
                var actor = upgrade.actor;
                actor.skills.Learn(SkillDefOf.Construction, SkillTuning.XpPerTickConstruction);
                var constructionSpeed = actor.GetStatValue(StatDefOf.ConstructionSpeed);
                if (TargetThingA.def.MadeFromStuff)
                {
                    constructionSpeed *= TargetThingA.Stuff.GetStatValueAbstract(StatDefOf.ConstructionSpeedFactor);
                }
                var successChance = actor.GetStatValue(StatDefOf.ConstructSuccessChance) * UpgradableComp.Props.upgradeSuccessChanceFactor;
                if (Rand.Value < 1f - Mathf.Pow(successChance, constructionSpeed / UpgradableComp.upgradeWorkTotal) && UpgradableComp.Props.upgradeFailable)
                {
                    UpgradableComp.upgradeWorkDone = 0f;
                    FailUpgrade(actor, successChance, TargetThingA);
                    ReadyForNextToil();
                }

                UpgradableComp.upgradeWorkDone += constructionSpeed;
                if (!(UpgradableComp.upgradeWorkDone >= UpgradableComp.upgradeWorkTotal))
                {
                    return;
                }

                UpgradableComp.Upgrade();
                Map.designationManager.TryRemoveDesignationOn(TargetThingA, DesignationDefOf.UpgradeTurret);
                actor.records.Increment(RecordDefOf.TurretsUpgraded);
                actor.jobs.EndCurrentJob(JobCondition.Succeeded);
            };
            upgrade.FailOnThingMissingDesignation(TurretInd, DesignationDefOf.UpgradeTurret);
            upgrade.FailOnCannotTouch(TurretInd, PathEndMode.Touch);
            upgrade.WithEffect(UpgradableComp.Props.UpgradeEffect((Building)job.GetTarget(TurretInd).Thing), TurretInd);
            upgrade.WithProgressBar(TurretInd, () => UpgradableComp.upgradeWorkDone / UpgradableComp.upgradeWorkTotal);
            upgrade.defaultCompleteMode = ToilCompleteMode.Never;
            upgrade.activeSkill         = () => SkillDefOf.Construction;
            return(upgrade);
        }
Exemplo n.º 2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Init();
            yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A));

            Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (RequiredDesignation != null) ? ((Func <Thing, bool>)((Thing t) => base.Map.designationManager.DesignationOn(t, RequiredDesignation) != null)) : null);

            yield return(initExtractTargetFromQueue);

            yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A));

            yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A));

            Toil toil = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue);

            if (RequiredDesignation != null)
            {
                toil.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation);
            }
            yield return(toil);

            Toil cut = new Toil();

            cut.tickAction = delegate
            {
                Pawn actor = cut.actor;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Plants, xpPerTick);
                }
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed);
                Plant plant     = Plant;
                statValue *= Mathf.Lerp(3.3f, 1f, plant.Growth);
                workDone  += statValue;
                if (workDone >= plant.def.plant.harvestWork)
                {
                    if (plant.def.plant.harvestedThingDef != null)
                    {
                        if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && !plant.Blighted && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield))
                        {
                            MoteMaker.ThrowText((pawn.DrawPos + plant.DrawPos) / 2f, base.Map, "TextMote_HarvestFailed".Translate(), 3.65f);
                        }
                        else
                        {
                            int num = plant.YieldNow();
                            if (num > 0)
                            {
                                Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef);
                                thing.stackCount = num;
                                if (actor.Faction != Faction.OfPlayer)
                                {
                                    thing.SetForbidden(value: true);
                                }
                                Find.QuestManager.Notify_PlantHarvested(actor, thing);
                                GenPlace.TryPlaceThing(thing, actor.Position, base.Map, ThingPlaceMode.Near);
                                actor.records.Increment(RecordDefOf.PlantsHarvested);
                            }
                        }
                    }
                    plant.def.plant.soundHarvestFinish.PlayOneShot(actor);
                    plant.PlantCollected();
                    workDone = 0f;
                    ReadyForNextToil();
                }
            };
            cut.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            if (RequiredDesignation != null)
            {
                cut.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation);
            }
            cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            cut.defaultCompleteMode = ToilCompleteMode.Never;
            cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A);
            cut.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, interpolateBetweenActorAndTarget: true);
            cut.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting);
            cut.activeSkill = (() => SkillDefOf.Plants);
            yield return(cut);

            Toil toil2 = PlantWorkDoneToil();

            if (toil2 != null)
            {
                yield return(toil2);
            }
            yield return(Toils_Jump.Jump(initExtractTargetFromQueue));
        }
Exemplo n.º 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.Init();
            yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A));

            Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (this.RequiredDesignation == null) ? null : new Func <Thing, bool>((Thing t) => this.Map.designationManager.DesignationOn(t, this.RequiredDesignation) != null));

            yield return(initExtractTargetFromQueue);

            yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A));

            yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true));

            Toil gotoThing = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue);

            if (this.RequiredDesignation != null)
            {
                gotoThing.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation);
            }
            yield return(gotoThing);

            Toil cut = new Toil();

            cut.tickAction = delegate()
            {
                Pawn actor = cut.actor;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Plants, this.xpPerTick, false);
                }
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                float num       = statValue;
                Plant plant     = this.Plant;
                num           *= Mathf.Lerp(3.3f, 1f, plant.Growth);
                this.workDone += num;
                if (this.workDone >= plant.def.plant.harvestWork)
                {
                    if (plant.def.plant.harvestedThingDef != null)
                    {
                        if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield, true))
                        {
                            Vector3 loc = (this.pawn.DrawPos + plant.DrawPos) / 2f;
                            MoteMaker.ThrowText(loc, this.Map, "TextMote_HarvestFailed".Translate(), 3.65f);
                        }
                        else
                        {
                            int num2 = plant.YieldNow();
                            if (num2 > 0)
                            {
                                Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null);
                                thing.stackCount = num2;
                                if (actor.Faction != Faction.OfPlayer)
                                {
                                    thing.SetForbidden(true, true);
                                }
                                GenPlace.TryPlaceThing(thing, actor.Position, this.Map, ThingPlaceMode.Near, null, null);
                                actor.records.Increment(RecordDefOf.PlantsHarvested);
                            }
                        }
                    }
                    plant.def.plant.soundHarvestFinish.PlayOneShot(actor);
                    plant.PlantCollected();
                    this.workDone = 0f;
                    this.ReadyForNextToil();
                    return;
                }
            };
            cut.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            if (this.RequiredDesignation != null)
            {
                cut.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation);
            }
            cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            cut.defaultCompleteMode = ToilCompleteMode.Never;
            cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A);
            cut.WithProgressBar(TargetIndex.A, () => this.workDone / this.Plant.def.plant.harvestWork, true, -0.5f);
            cut.PlaySustainerOrSound(() => this.Plant.def.plant.soundHarvesting);
            cut.activeSkill = (() => SkillDefOf.Plants);
            yield return(cut);

            Toil plantWorkDoneToil = this.PlantWorkDoneToil();

            if (plantWorkDoneToil != null)
            {
                yield return(plantWorkDoneToil);
            }
            yield return(Toils_Jump.Jump(initExtractTargetFromQueue));

            yield break;
        }
Exemplo n.º 4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A));

            Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (RequiredDesignation == null) ? null : new Func <Thing, bool>((Thing t) => Map.designationManager.DesignationOn(t, RequiredDesignation) != null));

            yield return(initExtractTargetFromQueue);

            yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A));

            yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true));

            Toil gotoThing = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue);

            if (RequiredDesignation != null)
            {
                gotoThing.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation);
            }
            yield return(gotoThing);

            Toil cut = new Toil();

            cut.tickAction = delegate
            {
                Pawn actor  = cut.actor;
                Job  curJob = actor.jobs.curJob;
                curJob.expiryInterval = -1;
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                float num       = statValue;
                Plant plant     = Plant;
                num      *= Mathf.Lerp(3.3f, 1f, plant.Growth);
                workDone += num;
                if (workDone >= plant.def.plant.harvestWork)
                {
                    if (plant.def.plant.harvestedThingDef != null)
                    {
                        int num2 = plant.YieldNow();
                        if (num2 > 0)
                        {
                            Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null);
                            thing.stackCount = num2;
                            if (actor.Faction != Faction.OfPlayer)
                            {
                                thing.SetForbidden(true, true);
                            }
                            GenPlace.TryPlaceThing(thing, actor.Position, Map, ThingPlaceMode.Near, null, null);
                        }
                    }
                    plant.def.plant.soundHarvestFinish.PlayOneShot(actor);
                    plant.PlantCollected();
                    workDone = 0f;
                    ReadyForNextToil();
                    return;
                }
            };
            cut.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            if (RequiredDesignation != null)
            {
                cut.FailOnThingMissingDesignation(TargetIndex.A, RequiredDesignation);
            }
            cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            cut.defaultCompleteMode = ToilCompleteMode.Never;
            cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A);
            cut.WithProgressBar(TargetIndex.A, () => workDone / Plant.def.plant.harvestWork, true, -0.5f);
            cut.PlaySustainerOrSound(() => Plant.def.plant.soundHarvesting);
            cut.activeSkill = (() => SkillDefOf.Plants);
            yield return(cut);

            Toil plantWorkDoneToil = PlantWorkDoneToil();

            if (plantWorkDoneToil != null)
            {
                yield return(plantWorkDoneToil);
            }
            yield return(Toils_Jump.Jump(initExtractTargetFromQueue));
        }