Пример #1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, job.def.joyMaxParticipants));

            if (TargetB != null)
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.B, 1));
            }

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell));

            var toil = new Toil();

            toil.PlaySustainerOrSound(TargetThingA?.def?.defName == "RimWriter_TableTypewriter"
                ? DefDatabase <SoundDef> .GetNamed("RimWriter_SoundManualTypewriter") : DefDatabase <SoundDef> .GetNamed(
                                          "RimWriter_SoundManualPencil"));
            toil.tickAction = delegate
            {
                pawn.rotationTracker.FaceCell(TargetA.Cell);
                pawn.GainComfortFromCellIfPossible();
                var statValue          = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor, true);
                var extraJoyGainFactor = statValue;
                JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.GoToNextToil, extraJoyGainFactor);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = job.def.joyDuration;
            toil.AddFinishAction(delegate
            {
                RimWriterUtility.TryGainLibraryThought(pawn);
            });
            yield return(toil);

            var finishedToil = new Toil
            {
                initAction = delegate
                {
                    if (RimWriterUtility.IsCosmicHorrorsLoaded() || RimWriterUtility.IsCultsLoaded())
                    {
                        try
                        {
                            if (RimWriterUtility.HasSanityLoss(pawn))
                            {
                                RimWriterUtility.ApplySanityLoss(pawn, -sanityRestoreRate, 1);
                                Messages.Message(pawn.ToString() + " has restored some sanity using the " + TargetA.Thing.def.label + ".", new TargetInfo(pawn.Position, pawn.Map), MessageTypeDefOf.NeutralEvent);// .Standard);
                            }
                        }
                        catch
                        {
                            Log.Message("Error loading Sanity Hediff.");
                        }
                    }
                }
            };

            yield return(finishedToil);

            yield break;
        }
Пример #2
0
        /// <summary>
        /// What happens while the game is being played. Make it return true if the player wins.
        /// </summary>
        /// <returns></returns>
        protected virtual bool WatchTickAction()
        {
            var extraJoyGainFactor = TargetThingA.GetStatValue(StatDefOf.EntertainmentStrengthFactor);

            JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.None, extraJoyGainFactor);

            return(false);
        }
        protected void ReadTickAction()
        {
            pawn.rotationTracker.FaceCell(TargetB.Cell);
            pawn.GainComfortFromCellIfPossible();
            var statValue = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor);
            var pawn1     = pawn;

            JoyUtility.JoyTickCheckEnd(pawn1, JoyTickFullJoyAction.EndJob, statValue);
        }
Пример #4
0
 protected Action WaitTickAction()
 {
     return(delegate
     {
         pawn.rotationTracker.FaceCell(TargetB.Cell);
         pawn.GainComfortFromCellIfPossible();
         var extraJoyGainFactor = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor);
         JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, extraJoyGainFactor);
     });
 }
Пример #5
0
        protected void ReadTickAction()
        {
            this.pawn.rotationTracker.FaceCell(TargetB.Cell);
            this.pawn.GainComfortFromCellIfPossible();
            var  statValue          = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor, true);
            Pawn pawn               = this.pawn;
            var  extraJoyGainFactor = statValue;

            if (TargetThingA is GuideBook gBook)
            {
                gBook.Teach(pawn);
            }
            JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.GoToNextToil, extraJoyGainFactor);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, job.def.joyMaxParticipants));

            if (TargetB != null)
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.B));
            }

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell));

            var toil     = new Toil();
            var soundDef = Find.World.GetComponent <WorldComponent_Tunes>().TuneDefCache
                           .FindAll(x => x.instrumentDefs.Contains(TargetThingA.def)).RandomElement();

            toil.PlaySustainerOrSound(soundDef);
            toil.tickAction = delegate
            {
                pawn.rotationTracker.FaceCell(TargetA.Cell);
                pawn.GainComfortFromCellIfPossible();
                var statValue = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor);
                JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, statValue);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = job.def.joyDuration;
            toil.AddFinishAction(delegate
            {
                if (Utility.IsCosmicHorrorsLoaded())
                {
                    try
                    {
                        if (Utility.HasSanityLoss(pawn))
                        {
                            Utility.ApplySanityLoss(pawn, -sanityRestoreRate);
                            Messages.Message(
                                pawn + " has restored some sanity using the " + TargetA.Thing.def.label + ".",
                                new TargetInfo(pawn.Position, pawn.Map), MessageTypeDefOf.NeutralEvent); // .Standard);
                        }
                    }
                    catch
                    {
                        Log.Message("Error loading Sanity Hediff.");
                    }
                }

                JoyUtility.TryGainRecRoomThought(pawn);
            });
            yield return(toil);
        }
Пример #7
0
        protected virtual void ListenTickAction()
        {
            if (!Gramophone.IsOn())
            {
                EndJobWith(JobCondition.Incompletable);
                return;
            }

            pawn.rotationTracker.FaceCell(TargetA.Cell);
            pawn.GainComfortFromCellIfPossible();
            var statValue = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor);

            JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, statValue);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(TargetIndex.A);
            yield return(Toils_Reserve.Reserve(TargetIndex.A, job.def.joyMaxParticipants));

            if (TargetB != null)
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.B));
            }

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell));

            var toil = new Toil();

            toil.PlaySustainerOrSound(DefDatabase <SoundDef> .GetNamed("Estate_SoundManualTypewriter"));
            toil.tickAction = delegate
            {
                pawn.rotationTracker.FaceCell(TargetA.Cell);
                pawn.GainComfortFromCellIfPossible();
                var statValue = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor);
                JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, statValue);
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = job.def.joyDuration;
//            toil.AddFinishAction(delegate
//            {
//                if (Cthulhu.Utility.IsCosmicHorrorsLoaded())
//                {
//                    try
//                    {
//                        if (Cthulhu.Utility.HasSanityLoss(this.pawn))
//                        {
//                            Cthulhu.Utility.ApplySanityLoss(this.pawn, -sanityRestoreRate, 1);
//                            Messages.Message(this.pawn.ToString() + " has restored some sanity using the " + this.TargetA.Thing.def.label + ".", new TargetInfo(this.pawn.Position, this.pawn.Map), MessageTypeDefOf.NeutralEvent);// .Standard);
//                        }
//                    }
//                    catch
//                    {
//                        Log.Message("Error loading Sanity Hediff.");
//                    }
//                }
//
//                JoyUtility.TryGainRecRoomThought(this.pawn);
//            });
            yield return(toil);
        }
Пример #9
0
        protected void RollForLuck()
        {
            var   extraLuckFromQuality      = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor, true);
            float extraLuckFromHobbitSmarts = pawn.skills.GetSkill(SkillDefOf.Intellectual).levelInt;

            var yourLuckyNumber = (1f + extraLuckFromHobbitSmarts) * extraLuckFromQuality / 100;

            Log.Message("lucky number is: " + yourLuckyNumber.ToString());

            if (Rand.Chance(yourLuckyNumber) || DebugSettings.godMode)
            {
                Thing reward = ThingMaker.MakeThing(ThingDefOf.Gold);
                reward.stackCount = Rand.RangeInclusive(10, 50);
                GenSpawn.Spawn(reward, pawn.Position, pawn.Map);
                PuzzleBox.Destroy();
                Letter letter = LetterMaker.MakeLetter("LotRH_PuzzleSolvedLabel".Translate(), "LotRH_PuzzleSolved".Translate(new object[] {
                    pawn.Label,
                    reward.Label,
                }), LetterDefOf.PositiveEvent);
                Find.LetterStack.ReceiveLetter(letter);
            }
        }
Пример #10
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Log.Message("Toil start:" + pawn + " is trying to learn " + project + ", globalFailConditions count:" + globalFailConditions.Count);
            Dictionary <ResearchProjectDef, float> expertise = pawn.TryGetComp <CompKnowledge>().expertise;

            AddEndCondition(delegate
            {
                if (!desk.Spawned)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });
            this.FailOnBurningImmobile(TargetIndex.A);
            this.FailOn(delegate()
            {
                IBillGiver billGiver = desk as IBillGiver;
                if (billGiver != null)
                {
                    if (job.bill.DeletedOrDereferenced)
                    {
                        return(true);
                    }
                    if (!billGiver.CurrentlyUsableForBills())
                    {
                        return(true);
                    }
                    if (project == null)
                    {
                        Log.Warning("[HumanResources] " + pawn + " tried to learn a null project.");
                        TryMakePreToilReservations(true);
                        return(true);
                    }
                    bool flag = IsResearch ? project.IsKnownBy(pawn) : !techComp.homework.Contains(project);
                    if (flag)
                    {
                        return(true);
                    }
                }
                return(false);
            });
            Toil gotoBillGiver = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell);

            yield return(gotoBillGiver);

            Toil acquireKnowledge = new Toil();

            acquireKnowledge.initAction = delegate()
            {
                Pawn actor = acquireKnowledge.actor;
                if (!expertise.ContainsKey(project))
                {
                    expertise.Add(project, 0f);
                }
            };
            acquireKnowledge.AddEndCondition(delegate
            {
                Pawn actor = acquireKnowledge.actor;
                if (expertise.ContainsKey(project) && expertise[project] > 1f)
                {
                    expertise[project] = 1f;
                    if (!IsResearch)
                    {
                        Notify_IterationCompleted(actor, job.bill as Bill_Production);
                        techComp.homework.Remove(project);
                    }
                    techComp.LearnCrops(project);
                    Messages.Message("MessageStudyComplete".Translate(actor, project.LabelCap), desk, MessageTypeDefOf.TaskCompletion, true);
                    project = null;
                    return(JobCondition.Succeeded);
                }
                return(JobCondition.Ongoing);
            });
            acquireKnowledge.tickAction = delegate()
            {
                Pawn  actor = acquireKnowledge.actor;
                float num   = actor.GetStatValue(StatDefOf.ResearchSpeed, true);
                num *= TargetThingA.GetStatValue(StatDefOf.ResearchSpeedFactor, true);
                float workAmount = IsResearch ? 1f : job.bill.recipe.workAmount;
                project.Learned(num, workAmount, actor, job.bill == null);
                actor.skills.Learn(SkillDefOf.Intellectual, 0.1f, false);
                actor.GainComfortFromCellIfPossible(true);
            };
            acquireKnowledge.AddFinishAction(delegate
            {
                Pawn actor = acquireKnowledge.actor;
                if (job.bill != null && job.RecipeDef.workSkill != null)
                {
                    float xp = ticksSpentDoingRecipeWork * 0.1f * job.RecipeDef.workSkillLearnFactor;
                    actor.skills.GetSkill(job.RecipeDef.workSkill).Learn(xp, false);
                }
            });
            acquireKnowledge.FailOn(() => project == null);
            //research.FailOn(() => !this.Project.CanBeResearchedAt(this.ResearchBench, false)); //need rework
            acquireKnowledge.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
            acquireKnowledge.FailOnDespawnedOrNull(TargetIndex.A);
            acquireKnowledge.WithEffect(EffecterDefOf.Research, TargetIndex.A);
            acquireKnowledge.WithProgressBar(TargetIndex.A, delegate
            {
                if (project == null)
                {
                    return(0f);
                }
                return(expertise[project]);
            }, false, -0.5f);
            acquireKnowledge.defaultCompleteMode = ToilCompleteMode.Delay;
            acquireKnowledge.defaultDuration     = 4000;
            acquireKnowledge.activeSkill         = () => SkillDefOf.Intellectual;
            yield return(acquireKnowledge);

            yield return(Toils_General.Wait(2, TargetIndex.None));

            yield break;
        }
Пример #11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(thingInd, JobCondition.Incompletable);             // thing
            this.FailOnForbidden(thingInd);

            yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell));            // cell

            CompPowerTrader compPowerTrader = (CompPowerTrader)thing.TryGetComp <CompPowerTrader>();
            float           statValue       = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor, true);
            Toil            sing            = new Toil();

            sing.tickAction = delegate
            {
                pawn.rotationTracker.FaceCell(TargetA.Cell);

                if (compPowerTrader != null)
                {
                    if (compPowerTrader.PowerNet.CurrentStoredEnergy() <= 0 || thing.IsBrokenDown() || !FlickUtility.WantsToBeOn(thing))
                    {
                        pawn.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    }
                }

                JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, statValue);

                if (pawn.IsHashIntervalTick(100))
                {
                    MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_Note);

                    // add thought to everyone in room

                    Room room = pawn.GetRoom(RegionType.Set_Passable);
                    if (room != null)
                    {
                        int         stage    = 0;
                        SkillRecord artSkill = pawn.skills.GetSkill(SkillDefOf.Artistic);
                        if (!artSkill.TotallyDisabled)
                        {
                            float stageFloat = GetSingThoughtState(artSkill.Level) * pawn.health.capacities.GetLevel(PawnCapacityDefOf.Talking) * pawn.health.capacities.GetLevel(PawnCapacityDefOf.Hearing);
                            stage = (int)stageFloat;
                            if (stage > 4)
                            {
                                stage = 4;
                            }
                        }

                        List <Thing> containedAndAdjacentThings = room.ContainedAndAdjacentThings;
                        for (int i = 0; i < containedAndAdjacentThings.Count; i++)
                        {
                            Pawn pawn2 = containedAndAdjacentThings[i] as Pawn;
                            if (pawn2 != null)
                            {
                                if (pawn2 != pawn && pawn2.RaceProps.Humanlike)
                                {
                                    //Log.Message("Singer: " + pawn + ". Stage: " + stage);
                                    //Log.Message("Listener: " + pawn2);
                                    if (pawn.health.hediffSet.HasHediff(HediffDefOf.AvaliBiology))                                     // Avali singer
                                    {
                                        if (pawn2.health.hediffSet.HasHediff(HediffDefOf.AvaliBiology))                                // Avali listener
                                        {
                                            if (stage < 2)
                                            {
                                                stage = 2;
                                            }
                                            stage = CheckSingerTraits(stage);
                                            pawn2.GiveThoughtWithStage(ThoughtDefOf.ListenerAvali, stage);
                                        }
                                        else                                         // non Avali listener
                                        {
                                            if (stage < 1)
                                            {
                                                stage = 1;
                                            }
                                            stage = CheckSingerTraits(stage);
                                            pawn2.GiveThoughtWithStage(ThoughtDefOf.ListenerAny, stage);
                                        }
                                    }
                                    else                                     // non Avali singer
                                    {
                                        stage = CheckSingerTraits(stage);
                                        if (pawn2.health.hediffSet.HasHediff(HediffDefOf.AvaliBiology))                                         // Avali listener
                                        {
                                            pawn2.GiveThoughtWithStage(ThoughtDefOf.ListenerAvali, stage);
                                        }
                                        else                                         // non Avali listener
                                        {
                                            pawn2.GiveThoughtWithStage(ThoughtDefOf.ListenerAny, stage);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            sing.handlingFacing      = true;
            sing.socialMode          = RandomSocialMode.Off;
            sing.defaultCompleteMode = ToilCompleteMode.Delay;
            sing.defaultDuration     = job.def.joyDuration;
            sing.AddFinishAction(delegate
            {
                JoyUtility.TryGainRecRoomThought(pawn);
            });

            yield return(sing);

            yield break;
        }
Пример #12
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
            this.EndOnDespawnedOrNull(TargetIndex.B, JobCondition.Incompletable);
            this.FailOnForbidden(TargetIndex.A);

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.OnCell));

            float    statValue = TargetThingA.GetStatValue(StatDefOf.JoyGainFactor, true);
            Building building  = (Building)pawn.CurJob.targetA.Thing;
            //CompRunningGenerator comp = (CompRunningGenerator)building.GetComp<CompRunningGenerator>();
            //int storedEnergy = 0;
            //int skipTick = 0;
            //int sameValueTimes = 0;

            Toil use = new Toil();

            use.tickAction = delegate
            {
                pawn.rotationTracker.FaceCell(TargetA.Cell);
                pawn.GainComfortFromCellIfPossible();

                building.GetComp <CompMannable>().ManForATick(pawn);

                if (TargetC.IsValid)
                {
                    JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.None, statValue);

                    //Log.Message(building + " current stored energy = " + (int)comp.PowerNet.CurrentStoredEnergy());

                    /*
                     * if (skipTick < 60)
                     * {
                     *      //Log.Message(building + " stored energy = " + storedEnergy);
                     *      if ((int)comp.PowerNet.CurrentStoredEnergy() == storedEnergy)
                     *      {
                     *              if (sameValueTimes < 60)
                     *              {
                     *                      sameValueTimes++;
                     *              }
                     *              else pawn.jobs.curDriver.EndJobWith(JobCondition.Succeeded);
                     *      }
                     *      else sameValueTimes = 0;
                     *
                     *      skipTick++;
                     * }
                     * else
                     * {
                     *      storedEnergy = (int)comp.PowerNet.CurrentStoredEnergy();
                     *      skipTick = 0;
                     * }
                     */
                }
                else
                {
                    JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.EndJob, statValue);
                }
            };

            if (!TargetC.IsValid)
            {
                use.defaultCompleteMode = ToilCompleteMode.Delay;
                use.defaultDuration     = job.def.joyDuration;
            }
            else
            {
                use.defaultCompleteMode = ToilCompleteMode.Never;
            }

            use.handlingFacing = true;
            use.AddFinishAction(delegate
            {
                JoyUtility.TryGainRecRoomThought(pawn);
            });

            yield return(use);

            yield break;
        }