//Main thing #region jobonthing public override Job JobOnThing(Pawn pawn, Thing thang, bool forced = true) { Pawn pawn2 = (Pawn)thang; if (pawn2.RaceProps.Humanlike) { if (pawn2.InMentalState) { if (SnapUtils.breakCompatCheck(pawn2.MentalState.def.ToString())) { SnapUtils.logThis(pawn2.MentalState.def.ToString()); SnapUtils.logThis(pawn2.Name.ToStringShort + " has met HumanLike and InMentalState conditions."); bool recent = Find.TickManager.TicksGame < pawn2.mindState.lastAssignedInteractTime + 15000; if (SnapUtils.canDo(pawn2) && SnapUtils.IsCapableOf(pawn) && !recent && pawn.CanReserve(pawn2)) //Only on non-aggressive mental state pawns { SnapUtils.logThis("Calming job initiated on " + pawn2.Name.ToStringShort + " by " + pawn.Name.ToStringShort); return(new Job(SnapDefOf.CalmDownJob, pawn2)); } } return(null); } return(null); } return(null); }
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); }
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); }
//Toil stuffs (DONE) #region toilstuffs protected override IEnumerable <Toil> MakeNewToils() { Pawn pieceofs = (Pawn)this.pawn.CurJob.targetA.Thing; var cdown = CalmDown(pieceofshit, SOMod.settings.SOCalmDuration); 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 { SnapUtils.modCompatDoer(pieceofs.MentalState.def.ToString(), pawn, pieceofs); pieceofs.rotationTracker.FaceCell(pawn.PositionHeld); if (pieceofs.InAggroMentalState) { float randa = UnityEngine.Random.Range(0f, 0.85f); float numba = pawn.GetStatValue(StatDefOf.SocialImpact, true); numba = numba * SOMod.settings.SOStunWeight; SnapUtils.logThis("Aggressive stun chance was " + numba.ToString() + " versus random of " + randa.ToString()); if (randa > numba) { SnapUtils.doStatusMessage(3, pawn, pieceofs); pieceofs.TryStartAttack(pawn); pieceofs.mindState.lastAssignedInteractTime = Find.TickManager.TicksGame; EndJobWith(JobCondition.Incompletable); } if (numba > randa) { pieceofs.stances.stunner.StunFor(SOMod.settings.SOCalmDuration, pawn); } } })); yield return(Toils_Interpersonal.GotoInteractablePosition(pieceofshit)); yield return(Toils_General.WaitWith(pieceofshit, SOMod.settings.SOCalmDuration, true, true)); yield return(cdown); yield return(Toils_Interpersonal.SetLastInteractTime(pieceofshit)); }
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(); }
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)); }
//Main window thing public override void DoSettingsWindowContents(Rect inRect) { Listing_Standard listing_Standard = new Listing_Standard(); listing_Standard.Begin(inRect); listing_Standard.AddLabeledCheckbox("MessagesEnabledLabel".Translate() + " ", ref settings.SOmessagesEnabled); listing_Standard.AddLabeledCheckbox("AggroCalmEnabledLabel".Translate() + " ", ref settings.SOAggroCalmEnabled); listing_Standard.AddLabeledCheckbox("OpinionOnlyEnabledLabel".Translate() + " ", ref settings.SOOpnOnly); listing_Standard.AddLabeledCheckbox("NonFactionEnabledLabel".Translate() + " ", ref settings.SONonFaction); listing_Standard.AddLabeledCheckbox("TraderCalmEnabledLabel".Translate() + " ", ref settings.SOTraderCalm); listing_Standard.AddLabeledCheckbox("AdvancedMenu".Translate() + " ", ref settings.SOAdvanced); if (SOMod.settings.SOAdvanced) { listing_Standard.AddLabelLine("Formula = diplomacy skill * social multiplier + opinion * opinion multiplier"); //listing_Standard.AddLabeledSlider("SMultLabel".Translate() + " - " + SOMod.settings.SODipWeight, ref settings.SODipWeight, 0f, 1f); done //listing_Standard.AddLabeledSlider("OMultLabel".Translate() + " - " + SOMod.settings.SOOpnWeight, ref settings.SOOpnWeight, 0f, 1f); done //listing_Standard.AddLabeledSlider("OOMultLabel".Translate() + " - " + SOMod.settings.SOOOpnWeight, ref settings.SOOOpnWeight, 0f, 1f); done //listing_Standard.AddLabeledSlider("StunWeight".Translate() + " - " + SOMod.settings.SOStunWeight, ref settings.SOStunWeight, 0f, 1f); done listing_Standard.AddLabeledNumericalTextField("SMultLabel".Translate(), ref settings.SODipWeight, (float)0.5, 0, 1); listing_Standard.AddLabeledNumericalTextField("OMultLabel".Translate(), ref settings.SOOpnWeight, (float)0.5, 0, 1); listing_Standard.AddLabeledNumericalTextField("OOMultLabel".Translate().Translate(), ref settings.SOOOpnWeight, (float)0.5, 0, 1); listing_Standard.AddLabeledNumericalTextField("StunWeight".Translate(), ref settings.SOStunWeight, (float)0.5, 0, 1); listing_Standard.AddLabeledNumericalTextField("CalmDuration".Translate(), ref SOMod.settings.SOCalmDuration); listing_Standard.AddLabeledNumericalTextField("Cooldown".Translate(), ref SOMod.settings.SOCooldown); listing_Standard.AddLabeledCheckbox("DebugChanceSetting".Translate() + " ", ref settings.SODebug); if (listing_Standard.ButtonText("Default")) { SnapUtils.logThis("Reset advanced settings to defaults"); SOMod.settings.SODipWeight = 0.2f; SOMod.settings.SOOpnWeight = 0.0014f; SOMod.settings.SOOOpnWeight = 0.006f; SOMod.settings.SOStunWeight = 0.55f; SOMod.settings.SOCalmDuration = 1250; SOMod.settings.SODebug = false; SOMod.settings.SOCooldown = 15000; } } listing_Standard.End(); settings.Write(); }
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!"); } } }
//Our main toil that does the calculations and stuff like that (DONE) #region MainToil protected Toil CalmDown(TargetIndex CTrg, int dur) { Pawn pieceofs = (Pawn)this.pawn.CurJob.targetA.Thing; var toil = new Toil { initAction = () => { pieceofs.jobs.EndCurrentJob(JobCondition.InterruptForced); this.TargetThingB = this.pawn; //Defining our initiator pawn float rand = UnityEngine.Random.Range(0f, 0.70f); pawn.interactions.TryInteractWith(pieceofs, SnapDefOf.CalmDownInteraction); float num = SnapUtils.doFormula(pawn, pieceofs); SnapUtils.logThis("Calm chance was " + num.ToString() + " versus random of " + rand.ToString()); if (rand > num) { #region failcondition if (SOMod.settings.SOmessagesEnabled) { 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 = Random.Range(0, 100); SnapUtils.logThis(pieceofs.Name.ToStringShort + " has a bedroom. Chance to get job is.. " + srand); if (srand <= 65) //65% chance { SnapUtils.logThis(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.logThis(pieceofs.Name.ToStringShort + " didnt receive gotosafety job!"); } } return; #endregion } #region successcondition if (SOMod.settings.SOmessagesEnabled) { 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.Range(50, 125)); 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; #endregion }, socialMode = RandomSocialMode.Off, defaultCompleteMode = ToilCompleteMode.Instant, defaultDuration = SOMod.settings.SOCalmDuration }; return(toil.WithProgressBarToilDelay(TargetIndex.B)); }
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)); }