コード例 #1
0
 public override Job JobOnThing(Pawn pawn, Thing targetThing, bool forced = true)
 {
     if ((targetThing == null) || (pawn == targetThing))
     {
         return(null);
     }
     else
     {
         Pawn targetPawn = (Pawn)targetThing;
         if (targetPawn.RaceProps.Humanlike && targetPawn.InMentalState)
         {
             if (SnapCheck.CompatCheck(targetPawn.MentalState.def.ToString()))
             {
                 bool recent = Find.TickManager.TicksGame < targetPawn.mindState.lastAssignedInteractTime + SOMod.Settings.Cooldown;
                 if (pawn.CurJobDef != SnapDefOf.CalmDownJob)
                 {
                     if (SnapCheck.CanDo(targetPawn) && SnapCheck.IsCapable(pawn) && !recent && pawn.CanReserve(targetPawn))
                     {
                         SnapUtils.DebugLog(string.Format("{0} given calm job with {1} as target", pawn.Name.ToStringShort, targetPawn.Name.ToStringShort));
                         return(new Job(SnapDefOf.CalmDownJob, targetPawn));
                     }
                 }
                 SnapUtils.DebugLog(string.Format("{0} has been considered but conditions were not fulfilled", targetPawn.Name.ToStringShort));
                 return(null);
             }
             else
             {
                 SnapUtils.DebugLog(string.Format("{0} mental state def has failed compatability check", targetPawn.MentalState.def.ToString()));
                 return(null);
             }
         }
     }
     return(null);
 }
コード例 #2
0
        public static float DoFormula(Pawn doer, Pawn subjectee)
        {
            float baseValue      = SOMod.Settings.BaseValue;
            float negotiationCap = SOMod.Settings.NegotiationCap;

            float negotiationSkill = doer.GetStatValue(StatDefOf.NegotiationAbility, true) * 100;

            if (negotiationSkill > negotiationCap)
            {
                negotiationSkill = negotiationCap;
            }

            float opinion = (float)subjectee.relations.OpinionOf(doer);

            float dipWeight = SOMod.Settings.NegMult / 100;
            float opnWeight = SOMod.Settings.OpnMult / 100;

            float badOpnPenalty = 0f;
            float opinionCopy   = opinion;

            while (opinionCopy < 0)
            {
                badOpnPenalty -= 0.25f;
                opinionCopy++;
            }

            float chance = (baseValue + badOpnPenalty) + (negotiationSkill * dipWeight) + (opinion * opnWeight);

            SnapUtils.DebugLog($"({baseValue} + {badOpnPenalty}) + ({negotiationSkill} * {dipWeight}) + ({opinion} * {opnWeight}) = {chance / 100}");

            return(chance / 100);
        }
コード例 #3
0
        public override void DoSettingsWindowContents(Rect inRect)
        {
            Listing_Standard listing_Standard = new Listing_Standard();

            listing_Standard.Begin(inRect);
            listing_Standard.AddLabeledCheckbox("MessagesEnabledLabel".Translate() + " ", ref Settings.MessagesEnabled);
            listing_Standard.AddLabeledCheckbox("AggroCalmEnabledLabel".Translate() + " ", ref Settings.AggroCalmEnabled);
            listing_Standard.AddLabeledCheckbox("OpinionOnlyEnabledLabel".Translate() + " ", ref Settings.OpinionOnly);
            listing_Standard.AddLabeledCheckbox("NonFactionEnabledLabel".Translate() + " ", ref Settings.NonFaction);
            listing_Standard.AddLabeledCheckbox("TraderCalmEnabledLabel".Translate() + " ", ref Settings.TraderCalm);
            listing_Standard.AddLabeledCheckbox("AdvancedMenu".Translate() + "  ", ref Settings.AdvancedMenu);
            if (SOMod.Settings.AdvancedMenu)
            {
                listing_Standard.AddLabelLine("Formula = diplomacy skill * social multiplier + opinion * opinion multiplier");
                if (SOMod.Settings.OpinionOnly)
                {
                    listing_Standard.AddLabeledNumericalTextField("OOMultLabel".Translate(), ref Settings.OOpnWeight, (float)0.5, 0, 1);
                }
                else
                {
                    listing_Standard.AddLabeledNumericalTextField("SMultLabel".Translate(), ref Settings.DipWeight, (float)0.5, 0, 1);
                    listing_Standard.AddLabeledNumericalTextField("OMultLabel".Translate(), ref Settings.OpnWeight, (float)0.5, 0, 1);
                }

                listing_Standard.AddLabeledNumericalTextField("StunWeight".Translate(), ref Settings.StunWeight, (float)0.5, 0, 1);

                listing_Standard.AddLabeledNumericalTextField("CalmDuration".Translate(), ref SOMod.Settings.CalmDuration);
                listing_Standard.AddLabeledNumericalTextField("Cooldown".Translate(), ref SOMod.Settings.Cooldown);
                listing_Standard.AddLabeledCheckbox("DebugChanceSetting".Translate() + " ", ref Settings.Debug);
                listing_Standard.AddLabeledCheckbox("LaunchCounterSetting".Translate() + " ", ref Settings.LaunchCounter);
                listing_Standard.AddLabeledCheckbox("AlwaysSucceedSetting".Translate() + " ", ref Settings.AlwaysSucceed);
                if (listing_Standard.ButtonText("Default"))
                {
                    SnapUtils.DebugLog("Reset advanced settings to defaults");
                    SOMod.Settings.DipWeight     = 0.2f;
                    SOMod.Settings.OpnWeight     = 0.0014f;
                    SOMod.Settings.OOpnWeight    = 0.006f;
                    SOMod.Settings.StunWeight    = 0.55f;
                    SOMod.Settings.CalmDuration  = 1250;
                    SOMod.Settings.Debug         = false;
                    SOMod.Settings.LaunchCounter = true;
                    SOMod.Settings.Cooldown      = 15000;
                }
            }

            listing_Standard.End();
            Settings.Write();
        }
コード例 #4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Pawn pieceofs = (Pawn)this.pawn.CurJob.targetA.Thing;
            var  cdown    = CalmDown(PieceOfShit, SOMod.Settings.CalmDuration);

            this.FailOnDowned(PieceOfShit);
            this.FailOnDespawnedOrNull(PieceOfShit);
            this.FailOnNotAwake(PieceOfShit);

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

            yield return(Toils_Interpersonal.WaitToBeAbleToInteract(this.pawn));

            yield return(Toils_Interpersonal.GotoInteractablePosition(PieceOfShit));

            yield return(Toils_General.Do(delegate
            {
                pieceofs.rotationTracker.FaceCell(pawn.PositionHeld);
                if (pieceofs.InAggroMentalState)
                {
                    float rand = Rand.RangeSeeded(0f, 0.85f, Find.TickManager.TicksAbs);
                    float socialImpact = pawn.GetStatValue(StatDefOf.SocialImpact, true);
                    socialImpact *= SOMod.Settings.StunWeight;
                    SnapUtils.DebugLog(string.Format("Aggressive stun success chance was {0} opposed to a failure chance of {1}", socialImpact.ToString(), rand.ToString()));
                    if (rand > socialImpact)
                    {
                        SnapUtils.DoStatusMessage(3, pawn, pieceofs);
                        pieceofs.TryStartAttack(pawn);
                        pieceofs.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame;
                        EndJobWith(JobCondition.Incompletable);
                    }
                    else
                    {
                        pieceofs.stances.stunner.StunFor(SOMod.Settings.CalmDuration, pawn);
                    }
                }
            }));

            yield return(Toils_Interpersonal.GotoInteractablePosition(PieceOfShit));

            yield return(Toils_General.WaitWith(PieceOfShit, SOMod.Settings.CalmDuration, true, true));

            yield return(cdown);

            yield return(Toils_Interpersonal.SetLastInteractTime(PieceOfShit));
        }
コード例 #5
0
        public static void AttemptSendSafety(Pawn subjectee)
        {
            Job goToSafetyJob = new Job(SnapDefOf.GoToSafetyJob);

            if (subjectee.ownership.OwnedRoom != null)
            {
                int srand = Rand.RangeSeeded(0, 100, Find.TickManager.TicksAbs);
                SnapUtils.DebugLog(subjectee.Name.ToStringShort + " has a bedroom. Chance to get sent to safety.. " + srand);
                if (srand <= 65) // 65% chance
                {
                    SnapUtils.DebugLog(subjectee.Name.ToStringShort + " has been sent to safety!");
                    goToSafetyJob.playerForced      = true;
                    goToSafetyJob.locomotionUrgency = LocomotionUrgency.Jog;
                    subjectee.jobs.EndCurrentJob(JobCondition.Succeeded);
                    subjectee.jobs.StartJob(goToSafetyJob, JobCondition.Succeeded);
                }
                else
                {
                    SnapUtils.DebugLog(subjectee.Name.ToStringShort + " has not been sent to safety!");
                }
            }
        }
コード例 #6
0
        protected Toil CalmDown(TargetIndex ctrg, int dur)
        {
            Pawn pieceofs = (Pawn)this.pawn.CurJob.targetA.Thing;
            var  toil     = new Toil
            {
                initAction = () =>
                {
                    if (pieceofs == null)
                    {
                        return;
                    }

                    pieceofs.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    this.TargetThingB = this.pawn; // Defining our initiator pawn
                    float rand = Rand.RangeSeeded(0f, 0.70f, Find.TickManager.TicksAbs);
                    pawn.interactions.TryInteractWith(pieceofs, SnapDefOf.CalmDownInteraction);
                    float num = SnapUtils.DoFormula(pawn, pieceofs);

                    if (SOMod.Settings.AlwaysSucceed)
                    {
                        rand = 0f;
                        num  = 1f;
                    }
                    SnapUtils.DebugLog(string.Format("Success chance of {0} opposed to failure chance of {1}", num.ToString(), rand.ToString()));
                    if (rand > num)
                    {
                        if (SOMod.Settings.MessagesEnabled)
                        {
                            MoteMaker.ThrowText(this.pawn.DrawPos + this.pawn.Drawer.renderer.BaseHeadOffsetAt(this.pawn.Rotation), this.pawn.Map, SnapUtils.GetCalmingMessage(), Color.red, 3.85f);
                        }

                        if (pieceofs.InAggroMentalState)
                        {
                            pieceofs.TryStartAttack(pawn);
                            SnapUtils.DoStatusMessage(3, pawn, pieceofs);
                            pieceofs.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame;
                            return;
                        }

                        SnapUtils.DoStatusMessage(2, pawn, pieceofs);
                        pieceofs.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame;
                        Room bedroom = pieceofs.ownership.OwnedRoom;
                        if (bedroom != null)
                        {
                            int srand = Rand.RangeSeeded(0, 100, Find.TickManager.TicksAbs);
                            SnapUtils.DebugLog(pieceofs.Name.ToStringShort + " has a bedroom. Chance to get job is.. " + srand);
                            if (srand <= 65) // 65% chance
                            {
                                SnapUtils.DebugLog(pieceofs.Name.ToStringShort + " received gotosafety job!");
                                gotosafetyjob.playerForced      = true;
                                gotosafetyjob.locomotionUrgency = LocomotionUrgency.Jog;
                                pieceofs.jobs.EndCurrentJob(JobCondition.Succeeded);
                                pieceofs.jobs.StartJob(gotosafetyjob, JobCondition.Succeeded);
                            }
                            else
                            {
                                SnapUtils.DebugLog(pieceofs.Name.ToStringShort + " didnt receive gotosafety job!");
                            }
                        }

                        return;
                    }

                    if (SOMod.Settings.MessagesEnabled)
                    {
                        MoteMaker.ThrowText(this.pawn.DrawPos + this.pawn.Drawer.renderer.BaseHeadOffsetAt(this.pawn.Rotation), this.pawn.Map, SnapUtils.GetCalmingMessage(), Color.green, 3.85f);
                    }

                    pawn.needs.mood.thoughts.memories.TryGainMemory(SnapDefOf.HelpedThought, null);
                    pawn.skills.Learn(SkillDefOf.Social, Rand.RangeSeeded(50, 125, Find.TickManager.TicksAbs));
                    SnapUtils.DoStatusMessage(1, pawn, pieceofs);
                    if (pieceofs.InAggroMentalState)
                    {
                        pieceofs.MentalState.RecoverFromState();
                        pieceofs.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Wander_Sad);
                    }

                    recoverjob.playerForced = true;
                    pieceofs.jobs.EndCurrentJob(JobCondition.Succeeded);
                    pieceofs.jobs.StartJob(recoverjob, JobCondition.Succeeded);
                    pieceofs.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame;
                },
                socialMode          = RandomSocialMode.Off,
                defaultCompleteMode = ToilCompleteMode.Instant,
                defaultDuration     = SOMod.Settings.CalmDuration
            };

            return(toil.WithProgressBarToilDelay(TargetIndex.B));
        }
コード例 #7
0
        protected Toil AttemptCalm(TargetIndex ctrg)
        {
            Pawn subjectee = (Pawn)this.pawn.CurJob.targetA.Thing;
            var  toil      = new Toil
            {
                initAction = () =>
                {
                    if (subjectee == null)
                    {
                        return;
                    }

                    subjectee.jobs.EndCurrentJob(JobCondition.InterruptForced);
                    this.TargetThingB = this.pawn; // Defining our initiator pawn
                    float rand = Rand.RangeSeeded(0f, 0.70f, Find.TickManager.TicksAbs);
                    pawn.interactions.TryInteractWith(subjectee, SnapDefOf.CalmDownInteraction);
                    float num = SnapUtils.DoFormula(pawn, subjectee);

                    if (SOMod.Settings.AlwaysSucceed)
                    {
                        rand = 0f;
                    }

                    SnapUtils.DebugLog(string.Format("Success chance of {0} opposed to failure chance of {1}", num.ToString(), rand.ToString()));
                    if (rand > num)
                    {
                        if (SOMod.Settings.MessagesEnabled)
                        {
                            SnapUtils.CalmText(this.pawn, Color.red);
                        }

                        if (subjectee.InAggroMentalState)
                        {
                            subjectee.TryStartAttack(pawn);
                            SnapUtils.DoStatusMessage(3, pawn, subjectee);
                            subjectee.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame;
                            return;
                        }

                        SnapUtils.DoStatusMessage(2, pawn, subjectee);
                        subjectee.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame;
                        SnapUtils.AttemptSendSafety(subjectee);
                        return;
                    }

                    if (SOMod.Settings.MessagesEnabled)
                    {
                        SnapUtils.CalmText(this.pawn, Color.green);
                    }

                    if (subjectee.InAggroMentalState)
                    {
                        subjectee.MentalState.RecoverFromState();
                        subjectee.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Wander_Sad);
                    }

                    SnapUtils.DoStatusMessage(1, pawn, subjectee);

                    pawn.needs.mood.thoughts.memories.TryGainMemory(SnapDefOf.HelpedThought, null);
                    pawn.skills.Learn(SkillDefOf.Social, Rand.RangeSeeded(50, 125, Find.TickManager.TicksAbs));
                    subjectee.jobs.EndCurrentJob(JobCondition.Succeeded);
                    recoverjob.playerForced = true;
                    subjectee.jobs.StartJob(recoverjob, JobCondition.Succeeded);
                    subjectee.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame;
                },
                socialMode          = RandomSocialMode.Off,
                defaultCompleteMode = ToilCompleteMode.Instant,
                defaultDuration     = SOMod.Settings.CalmDuration
            };

            return(toil.WithProgressBarToilDelay(TargetIndex.B));
        }