public void SaveMemory() { if (pawn.workSettings == null) // Caused by an issue in Prison Labor, see https://github.com/Aviuz/PrisonLabor/issues/137 { pawn.workSettings = new Pawn_WorkSettings(pawn); pawn.workSettings.EnableAndInitialize(); } foreach (WorkTypeDef work in DefDatabase <WorkTypeDef> .AllDefs) { if (!savedWorkPriorities.ContainsKey(work)) { savedWorkPriorities.Add(work, pawn.workSettings.GetPriority(work)); } else { savedWorkPriorities[work] = pawn.workSettings.GetPriority(work); } } if (pawn.playerSettings != null && pawn.playerSettings.AreaRestriction != null) { savedRestrictedArea = pawn.playerSettings.AreaRestriction; } savedMedicalCare = (sbyte)pawn.playerSettings.medCare; if (SlaveUtility.GetEnslavedHediff(pawn) != null) { savedWillpower = SlaveUtility.GetEnslavedHediff(pawn).SlaveWillpower; } }
public static void ShouldShowRestraintsInfo_Patch(ref Pawn pawn, ref bool __result) { if (RestraintsUtility.InRestraints(pawn) && SlaveUtility.IsPawnColonySlave(pawn)) { __result = true; } }
public static void Postfix(ref Thought_Memory newThought, ref Pawn otherPawn) { Pawn pawn = newThought.pawn; ThoughtDef knowColonistDied = ThoughtDefOf.KnowColonistDied; ThoughtDef thoughtToGet = SS_ThoughtDefOf.KnowSlaveDied; if (newThought.def == knowColonistDied) { // Remove colonist death thoughts if (SlaveUtility.IsPawnColonySlave(otherPawn) || (SlaveUtility.IsPawnColonySlave(pawn) && !SlaveUtility.IsPawnColonySlave(otherPawn))) { pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDefWhereOtherPawnIs(knowColonistDied, otherPawn); } // Add slave death thoughts if (SlaveUtility.IsPawnColonySlave(otherPawn) && pawn.MapHeld == otherPawn.MapHeld) { //string thoughtToGet = "KnowSlaveDied"; if (SlaveUtility.IsPawnColonySlave(pawn)) { thoughtToGet = SS_ThoughtDefOf.KnowFellowSlaveDied; } pawn.needs.mood.thoughts.memories.TryGainMemory(thoughtToGet, otherPawn); } } }
public override IEnumerable <Gizmo> CompGetGizmosExtra() { if (parent == null) { yield break; } var pawn = parent as Pawn; if (SlaveUtility.IsPawnColonySlave(pawn)) { var hediff = SlaveUtility.GetEnslavedHediff(pawn); var freeSlave = new Command_Toggle(); freeSlave.isActive = () => hediff.toBeFreed; freeSlave.defaultLabel = "LabelWordEmancipate".Translate(); freeSlave.defaultDesc = "CommandDescriptionEmancipate".Translate(pawn.Name.ToStringShort); freeSlave.toggleAction = () => hediff.toBeFreed = !hediff.toBeFreed; freeSlave.alsoClickIfOtherInGroupClicked = true; freeSlave.activateSound = SoundDefOf.Click; freeSlave.icon = ContentFinder <Texture2D> .Get("UI/Commands/Emancipate", true); yield return(freeSlave); var shackleSlave = new Command_Toggle(); shackleSlave.isActive = () => hediff.shackledGoal; shackleSlave.defaultLabel = "LabelWordShackle".Translate(); shackleSlave.defaultDesc = "CommandDescriptionShackle".Translate(pawn.Name.ToStringShort); shackleSlave.toggleAction = () => hediff.shackledGoal = !hediff.shackledGoal; shackleSlave.alsoClickIfOtherInGroupClicked = true; shackleSlave.activateSound = SoundDefOf.Click; shackleSlave.icon = ContentFinder <Texture2D> .Get("UI/Commands/Shackle", true); yield return(shackleSlave); } }
protected override ThoughtState CurrentStateInternal(Pawn p) { if (p.health.hediffSet.HasHediff(HediffDef.Named("Enslaved"))) { Hediff_Enslaved enslaved_def = SlaveUtility.GetEnslavedHediff(p); if (enslaved_def.ageTicks < 2500 * 3.5f && enslaved_def.SlaveWillpower > 0) // Gets some flavour text just after being enslaved { return(ThoughtState.ActiveAtStage(0)); } if (enslaved_def.SlaveWillpower > 75) { return(ThoughtState.ActiveAtStage(1)); } else if (enslaved_def.SlaveWillpower > 50) { return(ThoughtState.ActiveAtStage(2)); } else if (enslaved_def.SlaveWillpower > 25 || (enslaved_def.SlaveWillpower <= 50 && IsSteadfast(p))) { return(ThoughtState.ActiveAtStage(3)); } else if (Math.Round(enslaved_def.SlaveWillpower) <= 1) { return(ThoughtState.ActiveAtStage(4)); } } return(ThoughtState.Inactive); }
public static void BestKindLabel_Patch(ref string __result, ref Pawn pawn, ref bool mustNoteGender) { if (mustNoteGender && pawn.gender != Gender.None && SlaveUtility.IsPawnColonySlave(pawn)) { __result = "PawnMainDescGendered".Translate(pawn.Named("PAWN"), "LabelWordSlave".Translate()); //Z- ( new object[] { pawn.gender.GetLabel() ->(pawn.Named("PAWN") } }
public static void InRestraints_Patch(ref Pawn pawn, ref bool __result) { // Pawn is a shackled slave if (SlaveUtility.IsPawnColonySlave(pawn)) { __result = SlaveUtility.GetEnslavedHediff(pawn).shackled; } }
public static void GeneratePawn_Patch(ref PawnGenerationRequest request, ref Pawn pawn) { //Z- Uses defName.Contains for Alien Race compatibilty if (request.KindDef.defName.Contains("Slave") && pawn.apparel.WornApparel.Find(SlaveUtility.IsSlaveCollar) == null) { SlaveUtility.GiveSlaveCollar(pawn); } }
private void UpdateSlaveHediffs(Pawn pawn) { var hediff = SlaveUtility.GetEnslavedHediff(pawn); hediff?.SetWillpowerDirect(hediff.SlaveWillpower / 100f); var memoryHediff = SlaveUtility.GetSlaveMemoryHediff(pawn); if (memoryHediff != null) { memoryHediff.savedWillpower /= 100f; } }
protected override ThoughtState CurrentStateInternal(Pawn p) { Pawn pawn = p; if (pawn.story.traits.HasTrait(TraitDef.Named("Kind")) && pawn.Map.mapPawns.FreeColonistsAndPrisonersSpawned.ToList().Find( x => SlaveUtility.IsPawnColonySlave(x) && x.Faction == pawn.Faction) != null) { return(ThoughtState.ActiveDefault); } return(ThoughtState.Inactive); }
public static void TryGiveJob_Patch(ref Pawn pawn, ref Job __result) { if (__result == null) { return; } if ((SlaveUtility.IsPawnColonySlave(pawn) && __result.targetA.Thing != null && SlaveUtility.IsSlaveCollar(__result.targetA.Thing as Apparel) && SlaveUtility.HasSlaveCollar(pawn)) || (!SlaveUtility.IsPawnColonySlave(pawn) && pawn.IsColonist && __result.targetA.Thing != null && SlaveUtility.IsSlaveCollar(__result.targetA.Thing as Apparel))) { __result = null; } }
public override void ExposeData() { base.ExposeData(); Scribe_Values.Look <float>(ref savedWillpower, "savedWillpower"); Scribe_Collections.Look <WorkTypeDef, int>(ref savedWorkPriorities, "savedWorkPriorities"); Scribe_References.Look <Area>(ref savedRestrictedArea, "savedRestrictedArea"); Scribe_Values.Look <sbyte>(ref savedMedicalCare, "savedMedicalCare"); Scribe_Values.Look(ref wasColonySlave, "wasColonySlave"); if (pawn != null && SlaveUtility.IsPawnColonySlave(pawn)) { wasColonySlave = true; } }
protected override ThoughtState CurrentStateInternal(Pawn p) { Pawn pawn = p; if (SlaveUtility.HasSlaveCollar(pawn) && SlaveUtility.GetSlaveCollar(pawn).def.thingClass == typeof(SlaveCollar_Explosive)) { if ((SlaveUtility.GetSlaveCollar(pawn) as SlaveCollar_Explosive).armed) { return(ThoughtState.ActiveAtStage(1)); } return(SlaveUtility.IsPawnColonySlave(pawn) ? ThoughtState.ActiveAtStage(0) : ThoughtState.ActiveAtStage(2)); } return(ThoughtState.Inactive); }
static IEnumerable <Pawn> sellableSlaves(Map map, IEnumerable <Pawn> previous) { foreach (Pawn pawn in map.mapPawns.FreeColonistsSpawned) { if (SlaveUtility.IsPawnColonySlave(pawn) && !previous.Contains(pawn)) { yield return(pawn); } } foreach (Pawn pawn in previous) { yield return(pawn); } }
public static float ArrestChance(Pawn pawn) { if (pawn.mindState.mentalStateHandler.CurStateDef == SS_MentalStateDefOf.CryptoStasis) { return(1f); } if (SlaveUtility.IsPawnColonySlave(pawn)) { return(1f - SlaveUtility.GetEnslavedHediff(pawn).SlaveWillpower); } else { return(0.6f); } }
public static void Beaten(Pawn __instance, ref DamageInfo dinfo) { // Check if the pawn is enslaved if (SlaveUtility.IsPawnColonySlave(__instance)) { Hediff_Enslaved enslaved_def = (Hediff_Enslaved)__instance.health.hediffSet.GetFirstHediffOfDef(SS_HediffDefOf.Enslaved); // Is the beating coming from the faction owning the slave? if (dinfo.Instigator != null) { if (dinfo.Instigator.Faction == enslaved_def.slaverFaction) { enslaved_def.TakeWillpowerHit(dinfo.Amount / 100f); } } } }
public static void PreTraded_Patch(ref Pawn __instance, ref TradeAction action) { // Slave wearing a slave collar if (action == TradeAction.PlayerBuys && __instance.RaceProps.Humanlike && __instance.apparel.WornApparel.Find(SlaveUtility.IsSlaveCollar) != null) { // Add the enslaved tracker __instance.health.AddHediff(SS_HediffDefOf.Enslaved); // Set willpower to zero SlaveUtility.GetEnslavedHediff(__instance).SetWillpowerDirect(0f); // Re-force wearing of the collar so the new slave does not drop it, freeing themselves __instance.outfits.forcedHandler.SetForced(__instance.apparel.WornApparel.Find(SlaveUtility.IsSlaveCollar), true); } else if (action == TradeAction.PlayerSells && SlaveUtility.IsPawnColonySlave(__instance)) { SlaveUtility.GetSlaveMemoryHediff(__instance).wasColonySlave = false; // Make sold slaves not count as previously being controlled by the colony } }
static IEnumerable <Thing> sellableThingsAndSlaves(Pawn playerNegotiator, IEnumerable <Thing> previous) { foreach (Thing thing in previous) { yield return(thing); } Caravan caravan = playerNegotiator.GetCaravan(); List <Pawn> caravanPawns = caravan.PawnsListForReading; foreach (Pawn pawn in caravanPawns) { if (SlaveUtility.IsPawnColonySlave(pawn) && !previous.Contains(pawn)) { yield return(pawn); } } }
public static void IsVisible_Patch(ref ITab_Pawn_Prisoner __instance, ref bool __result) { var pawn = Find.Selector.SingleSelectedThing; if (pawn == null || pawn.GetType() != typeof(Pawn)) { return; } if (__result == true) { if (SlaveUtility.IsPawnColonySlave(pawn as Pawn)) { __result = false; } } }
public override void PostMake() { base.PostMake(); actualFaction = pawn.Faction; slaverFaction = (Faction.OfPlayer); if (pawn.Faction == slaverFaction) { pawn.guest.SetGuestStatus(null); } else { pawn.SetFaction(Faction.OfPlayer); } // If the hediff was added without equipping a slave collar, ensure they get one if (pawn.apparel.WornApparel.Find(SlaveUtility.IsSlaveCollar) == null) { SlaveUtility.GiveSlaveCollar(pawn); } // Certain backstories begin with no willpower if (pawn.story.childhood.title == "Vatgrown slavegirl") //Z- Title -> title { willpower = 0; } if (pawn.story.adulthood != null) { if (pawn.story.adulthood.title == "Urbworld sex slave") //Z- Title - title { willpower = 0; } } // We were freed, but then enslaved AGAIN if (pawn.health.hediffSet.HasHediff(SS_HediffDefOf.SlaveMemory)) { SlaveAgain(); // Take a willpower hit, but only if we were free for a while if (pawn.health.hediffSet.GetFirstHediffOfDef(SS_HediffDefOf.SlaveMemory).ageTicks > 10000) { TakeWillpowerHit(0.5f); } } SaveMemory(); }
public static bool DoesMapHaveSlaves(Map map) { if (map == null) { return(false); } bool slaveExists = false; foreach (Pawn pawn in map.mapPawns.FreeColonists) { if (SlaveUtility.IsPawnColonySlave(pawn)) { slaveExists = true; break; } } return(slaveExists); }
public void Zap() { var zap = new DamageInfo(DamageDefOf.Burn, 1f, 100f, -1f, this, Wearer.RaceProps.body.AllParts.Find(part => part.def == BodyPartDefOf.Neck)); var zap2 = new DamageInfo(DamageDefOf.Stun, 1f, 100f, -1f, this, Wearer.RaceProps.body.AllParts.Find(part => part.def == BodyPartDefOf.Neck)); if (Wearer.Downed || !Wearer.Spawned) { armed = false; return; } SoundInfo info = SoundInfo.InMap(new TargetInfo(Wearer.PositionHeld, Wearer.MapHeld)); SoundDefOf.Power_OffSmall.PlayOneShot(info); Wearer.TakeDamage(zap); Wearer.TakeDamage(zap2); Wearer.health.AddHediff(SS_HediffDefOf.Electrocuted); SlaveUtility.TryHeartAttack(Wearer); }
public static List <Pawn> ClearOutSlavesFromColonistBar(List <Pawn> pawns) { if (SimpleSlavery.ShowSlavesInColonistBar) { return(pawns); } var newList = new List <Pawn> { }; foreach (Pawn pawn in pawns) { if (!SlaveUtility.IsPawnColonySlave(pawn)) { newList.Add(pawn); } } return(newList); }
public static void EnslavePawn(Pawn pawn, Apparel collar = null) { if (pawn == null) { Log.Error("[SimpleSlavery] Error: Tried to enslave null pawn."); return; } if (!pawn.RaceProps.Humanlike) { Log.Error("[SimpleSlavery] Error: Tried to enslave a non-humanlike pawn."); return; } if (!SlaveUtility.IsPawnColonySlave(pawn)) { SlaveUtility.GiveSlaveCollar(pawn, collar); pawn.health.AddHediff(SS_HediffDefOf.Enslaved); } }
public override TaggedString GetExplanation() { var slaves = SlaveUtility.GetSlavesInTimeout(); string text = ""; if (slaves.Count > 1) { StringBuilder stringBuilder = new StringBuilder(); foreach (var slave in slaves) { stringBuilder.AppendLine(" - " + slave.NameShortColored.Resolve()); } text = "Desc_TimeoutPlural".Translate(stringBuilder).Resolve(); } else { text = "Desc_Timeout".Translate(slaves[0].NameShortColored.Resolve()).Resolve(); } return(text); }
public override IEnumerable <Gizmo> SlaveGizmos() { // 1. Arm the collar var armCollar = new Command_Toggle(); Func <bool> isArmed = () => armed; armCollar.isActive = isArmed; armCollar.defaultLabel = "Label_CollarExplosive_Arm".Translate(); armCollar.defaultDesc = "Desc_CollarExplosive_Arm".Translate(); armCollar.toggleAction = delegate { armed = !armed; if (armed) { if (arm_cooldown == 0) { // Doesn't matter if pawn is slave or not when armed SlaveUtility.TryInstantBreak(Wearer, Rand.Range(0.25f, 0.33f)); arm_cooldown = 2500; } } }; armCollar.activateSound = SoundDefOf.Click; armCollar.icon = ContentFinder <Texture2D> .Get("UI/Commands/ArmCollar", true); yield return(armCollar); // 2. Detonate the collar if (armed) { var detonate = new Command_Action(); detonate.defaultLabel = "Label_CollarExplosive_Detonate".Translate(); detonate.defaultDesc = "Desc_CollarExplosive_Detonate".Translate(); detonate.action = delegate { GoBoom(); }; detonate.activateSound = SoundDefOf.Click; detonate.icon = ContentFinder <Texture2D> .Get("UI/Commands/DetonateCollar", true); yield return(detonate); } }
public override TaggedString GetExplanation() { var miserable = SlaveUtility.GetSlavesMiserable(); int num = miserable.Count; string text = ""; if (num > 1) { StringBuilder stringBuilder = new StringBuilder(); foreach (var slave in miserable) { stringBuilder.AppendLine(" - " + slave.NameShortColored.Resolve()); } text = "Desc_MiserableSlavesPlural".Translate(stringBuilder).Resolve(); } else if (num == 1) { text = "Desc_MiserableSlaves".Translate(miserable[0].NameShortColored.Resolve()).Resolve(); } return(text); }
internal static IEnumerable <Gizmo> SlaveGizmos(Pawn pawn) { var slaveMemory = SlaveUtility.GetSlaveMemoryHediff(pawn); if (slaveMemory == null || !slaveMemory.wasColonySlave) // Only display the apparel gizmos if the pawn was previously a colony slave { yield break; } if (SlaveUtility.IsPawnColonySlave(pawn)) { var hediff = SlaveUtility.GetEnslavedHediff(pawn); if (hediff.waitingInJail) { var timeout = new Command_Action(); timeout.defaultLabel = "Label_Timeout".Translate(); timeout.defaultDesc = "Desc_Timeout".Translate(); timeout.icon = ContentFinder <Texture2D> .Get("UI/Commands/DetonateCollar", true); timeout.disabled = true; yield return(timeout); } } if (pawn.apparel != null) { foreach (var apparel in pawn.apparel.WornApparel) { var slaveApparel = apparel as SlaveApparel; if (slaveApparel != null) { foreach (var g in slaveApparel.SlaveGizmos()) { yield return(g); } } } } }
public static void RenderPortrait_Patch(ref PawnRenderer __instance) { Pawn pawn = __instance.graphics.pawn; if (!SlaveUtility.IsPawnColonySlave(pawn)) { return; } Apparel collar = pawn.apparel.WornApparel.Find(SlaveUtility.IsSlaveCollar); var chainColour = new Color(0.5f, 0.5f, 0.5f, 0.5f); if (collar != null) { chainColour = collar.DrawColor; } Mesh mesh = MeshPool.humanlikeHeadSet.MeshAt(Rot4.South); Material mat = GraphicDatabase.Get <Graphic_Single>("Things/Pawn/Humanlike/Apparel/SlaveCollar/Chain", ShaderDatabase.CutoutComplex, new Vector2(1, 1), chainColour).MatAt(Rot4.South); mat.mainTexture.wrapMode = TextureWrapMode.Clamp; mat.mainTextureScale = new Vector2(1.75f, 1.75f); mat.mainTextureOffset = new Vector2(-0.37f, -0.10f); GenDraw.DrawMeshNowOrLater(mesh, new Vector3(0, 0.85f, 0), Quaternion.identity, mat, true); }
public override AlertReport GetReport() { return(AlertReport.CulpritsAre(SlaveUtility.GetSlavesMiserable())); }