public AssignLink( int zone, Pawn colonist, Outfit outfit, DrugPolicy drugPolicy, HostilityResponseMode hostilityResponse, int loadoutId, int mapId) { this.zone = zone; this.colonist = colonist; this.outfit = outfit; this.drugPolicy = drugPolicy; this.hostilityResponse = hostilityResponse; this.loadoutId = loadoutId; this.mapId = mapId; }
private static bool VanillaModified_TryFindIngestibleToNurse(JoyGiver_SocialRelax __instance, IntVec3 center, Pawn ingester, out Thing ingestible) { if (ingester.IsTeetotaler()) { ingestible = null; return(false); } if (ingester.drugs == null) { ingestible = null; return(false); } AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").SetValue(__instance, new List <ThingDef>()); DrugPolicy currentPolicy = ingester.drugs.CurrentPolicy; for (int i = 0; i < currentPolicy.Count; i++) { if (currentPolicy[i].allowedForJoy && currentPolicy[i].drug.ingestible.nurseable) { ((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance)).Add(currentPolicy[i].drug); } } ((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance)).Shuffle(); for (int j = 0; j < ((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance)).Count; j++) { List <Thing> list = ingester.Map.listerThings.ThingsOfDef(((List <ThingDef>)AccessTools.Field(typeof(JoyGiver_SocialRelax), "nurseableDrugs").GetValue(__instance))[j]); if (list.Count > 0) { Predicate <Thing> validator = delegate(Thing t) { if (t.def?.graphicData?.texPath == "Things/Item/Resource/BloodWine") { return(false); } if (ingester.CanReserve(t)) { return(!t.IsForbidden(ingester)); } return(false); }; ingestible = GenClosest.ClosestThing_Global_Reachable(center, ingester.Map, list, PathEndMode.OnCell, TraverseParms.For(ingester), 40f, validator); if (ingestible != null) { return(true); } } } ingestible = null; return(false); }
public static void CheckValues(DrugPolicy DP, DrugPolicyEntry DPE, ThingDef drug, out DrugPolicyEntry DPEChecked) { DPEChecked = DPE; if (!DrugPolicyUtility.IsAddictive(drug)) { DPEChecked.allowedForAddiction = false; } if (!drug.IsPleasureDrug) { DPEChecked.allowedForJoy = false; } }
internal void TryStoreDrugPolicy() { if (!Settings.DrugPolicies) { return; } if (Parent.drugs?.CurrentPolicy == null) { return; } _lastDrugPolicy = Parent.drugs.CurrentPolicy; }
private static void TryTakeScheduledDrugs(Pawn pawn, Caravan caravan) { if (pawn.drugs != null) { DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy; for (int i = 0; i < currentPolicy.Count; i++) { if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug) && CaravanInventoryUtility.TryGetThingOfDef(caravan, currentPolicy[i].drug, out Thing thing, out Pawn owner)) { caravan.needs.IngestDrug(pawn, thing, owner); } } } }
// Token: 0x0600004D RID: 77 RVA: 0x00005358 File Offset: 0x00003558 public static bool DPExists(DrugPolicy policy, ThingDef drugDef) { if (policy.Count > 0) { for (int i = 0; i < policy.Count; i++) { DrugPolicyEntry drugPolicyEntry = policy[i]; if ((drugPolicyEntry?.drug) == drugDef) { return(true); } } } return(false); }
public static void Postfix(DrugPolicy __instance, ref DrugPolicyEntry __result, ThingDef drugDef) { var entriesInt = Traverse.Create(__instance).Field("entriesInt").GetValue <List <DrugPolicyEntry> >(); foreach (DrugPolicyEntry entry in entriesInt) { if (entry.drug == drugDef) { __result = entry; return; } } // Added: Missing def __result = AddDef(drugDef, entriesInt); }
private static void TryTakeScheduledDrugs(Pawn pawn, Caravan caravan) { if (pawn.drugs != null) { DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy; for (int i = 0; i < currentPolicy.Count; i++) { Thing drug = default(Thing); Pawn drugOwner = default(Pawn); if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug) && CaravanInventoryUtility.TryGetThingOfDef(caravan, currentPolicy[i].drug, out drug, out drugOwner)) { CaravanPawnsNeedsUtility.IngestDrug(pawn, drug, drugOwner, caravan); } } } }
private static void UpdateDrugManagement(Pawn pawn) { var restriction = Current.Game.drugPolicyDatabase.AllPolicies.FirstOrDefault(x => x.label == "Tenants".Translate()); if (restriction == null) { var uniqueId = !Current.Game.drugPolicyDatabase.AllPolicies.Any() ? 1 : Current.Game.drugPolicyDatabase.AllPolicies.Max(o => o.uniqueId) + 1; restriction = new DrugPolicy(uniqueId, "Tenants".Translate()); Current.Game.drugPolicyDatabase.AllPolicies.Add(restriction); } pawn.drugs.CurrentPolicy = restriction; }
protected override Thing BestIngestItem(Pawn pawn, Predicate <Thing> extraValidator) { if (pawn.drugs == null) { return(null); } Predicate <Thing> predicate = (Thing t) => CanIngestForJoy(pawn, t) && (extraValidator == null || extraValidator(t)) && t.def.ingestible != null && t.def.ingestible.drugCategory != DrugCategory.None; ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer; for (int i = 0; i < innerContainer.Count; i++) { if (predicate(innerContainer[i])) { return(innerContainer[i]); } } //bool flag = false; //if (pawn.story != null && (pawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire) > 0 || pawn.InMentalState)) //{ // flag = true; //} takeableDrugs.Clear(); DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy; for (int j = 0; j < currentPolicy.Count; j++) { if (/*flag ||*/ currentPolicy[j].allowedForJoy) { takeableDrugs.Add(currentPolicy[j].drug); } } // takeableDrugs.Shuffle(); for (int k = 0; k < takeableDrugs.Count; k++) { List <Thing> list = pawn.Map.listerThings.ThingsOfDef(takeableDrugs[k]); if (list.Count > 0) { Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, list, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false, false, false), 9999f, predicate, null); if (thing != null) { return(thing); } } } return(null); }
protected override Thing BestIngestItem(Pawn pawn, Predicate <Thing> extraValidator) { if (pawn.IsPrisoner || pawn.IsPrisonerOfColony) { //Log.Message("No drugs in prison mofo"); return(null); } Predicate <Thing> predicate = (Thing t) => this.CanIngestForJoy(pawn, t) && (extraValidator == null || extraValidator(t)); var innerContainer = pawn.inventory.innerContainer; for (int i = 0; i < innerContainer.Count; i++) { if (predicate(innerContainer[i])) { return(innerContainer[i]); } } takeableDrugs.Clear(); DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy; for (int j = 0; j < currentPolicy.Count; j++) { if (currentPolicy[j].allowedForJoy) { takeableDrugs.Add(currentPolicy[j].drug); } } takeableDrugs.Shuffle <ThingDef>(); for (int k = 0; k < takeableDrugs.Count; k++) { List <Thing> list = pawn.Map.listerThings.ThingsOfDef(takeableDrugs[k]); if (list.Count > 0) { Predicate <Thing> validator = predicate; Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, list, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, null); if (thing != null) { return(thing); } } } return(null); }
public void SavePawnFromHediff(Hediff_CorticalStack hediff) { this.name = hediff.name; this.origPawn = hediff.origPawn; this.hostilityMode = hediff.hostilityMode; this.areaRestriction = hediff.areaRestriction; this.ageChronologicalTicks = hediff.ageChronologicalTicks; this.medicalCareCategory = hediff.medicalCareCategory; this.selfTend = hediff.selfTend; this.foodRestriction = hediff.foodRestriction; this.outfit = hediff.outfit; this.drugPolicy = hediff.drugPolicy; this.times = hediff.times; this.thoughts = hediff.thoughts; this.faction = hediff.faction; this.isFactionLeader = hediff.isFactionLeader; this.traits = hediff.traits; this.relations = hediff.relations; this.relatedPawns = hediff.relatedPawns; this.skills = hediff.skills; this.childhood = hediff.childhood; this.adulthood = hediff.adulthood; this.priorities = hediff.priorities; this.hasPawn = true; if (this.gender == Gender.None) { this.gender = hediff.gender; } this.pawnID = hediff.pawnID; if (ModLister.RoyaltyInstalled) { this.royalTitles = hediff.royalTitles; this.favor = hediff.favor; this.heirs = hediff.heirs; this.bondedThings = hediff.bondedThings; } this.isCopied = hediff.isCopied; this.stackGroupID = hediff.stackGroupID; }
public void CopyFromOtherStack(CorticalStack otherStack) { this.name = otherStack.name; this.origPawn = otherStack.origPawn; this.hostilityMode = otherStack.hostilityMode; this.areaRestriction = otherStack.areaRestriction; this.ageChronologicalTicks = otherStack.ageChronologicalTicks; this.medicalCareCategory = otherStack.medicalCareCategory; this.selfTend = otherStack.selfTend; this.foodRestriction = otherStack.foodRestriction; this.outfit = otherStack.outfit; this.drugPolicy = otherStack.drugPolicy; this.times = otherStack.times; this.thoughts = otherStack.thoughts; this.faction = otherStack.faction; this.isFactionLeader = otherStack.isFactionLeader; this.traits = otherStack.traits; this.relations = otherStack.relations; this.relatedPawns = otherStack.relatedPawns; this.skills = otherStack.skills; this.childhood = otherStack.childhood; this.adulthood = otherStack.adulthood; this.priorities = otherStack.priorities; this.hasPawn = true; if (this.gender == Gender.None) { this.gender = otherStack.gender; } this.pawnID = otherStack.pawnID; if (ModLister.RoyaltyInstalled) { this.royalTitles = otherStack.royalTitles; this.favor = otherStack.favor; this.heirs = otherStack.heirs; this.bondedThings = otherStack.bondedThings; } this.isCopied = true; this.stackGroupID = otherStack.stackGroupID; }
private static void TryTakeScheduledDrugs(Pawn pawn, Caravan caravan) { if (pawn.drugs == null) { return; } DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy; for (int i = 0; i < currentPolicy.Count; i++) { if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug)) { Thing drug; Pawn drugOwner; if (CaravanInventoryUtility.TryGetThingOfDef(caravan, currentPolicy[i].drug, out drug, out drugOwner)) { caravan.needs.IngestDrug(pawn, drug, drugOwner); } } } }
private static bool TryFindIngestibleToNurse(IntVec3 center, Pawn ingester, out Thing ingestible) { if (ingester.IsTeetotaler()) { ingestible = null; return(false); } if (ingester.drugs == null) { ingestible = null; return(false); } JoyGiver_SocialRelaxAvali.nurseableDrugs.Clear(); DrugPolicy currentPolicy = ingester.drugs.CurrentPolicy; for (int i = 0; i < currentPolicy.Count; i++) { if (currentPolicy[i].allowedForJoy && currentPolicy[i].drug.ingestible.nurseable) { JoyGiver_SocialRelaxAvali.nurseableDrugs.Add(currentPolicy[i].drug); } } JoyGiver_SocialRelaxAvali.nurseableDrugs.Shuffle <ThingDef>(); for (int j = 0; j < JoyGiver_SocialRelaxAvali.nurseableDrugs.Count; j++) { List <Thing> list = ingester.Map.listerThings.ThingsOfDef(JoyGiver_SocialRelaxAvali.nurseableDrugs[j]); if (list.Count > 0) { Predicate <Thing> validator = (Thing t) => ingester.CanReserve(t, 1, -1, null, false) && !t.IsForbidden(ingester); ingestible = GenClosest.ClosestThing_Global_Reachable(center, ingester.Map, list, PathEndMode.OnCell, TraverseParms.For(ingester, Danger.Deadly, TraverseMode.ByPawn, false), 40f, validator, null); if (ingestible != null) { return(true); } } } ingestible = null; return(false); }
internal static void Prefix(DrugPolicy __instance, List <DrugPolicyEntry> ___entriesInt) { if (Scribe.mode != LoadSaveMode.PostLoadInit) { return; } var allDefsListForReading = DefDatabase <ThingDef> .AllDefsListForReading; foreach (var t in allDefsListForReading) { if (t.category == ThingCategory.Item && t.IsDrug && !___entriesInt.Exists(e => e.drug == t)) { DrugPolicyEntry drugPolicyEntry = new DrugPolicyEntry { drug = t, allowedForAddiction = true }; ___entriesInt.Add(drugPolicyEntry); Log.Message($"Added {t.label} to drug policy {__instance.label}."); } } ___entriesInt.SortBy(e => e.drug.GetCompProperties <CompProperties_Drug>().listOrder); }
public static void AddNewDrugToPolicy(DrugPolicy dp, ThingDef newdrug, DrugCategory DC) { var drugPolicyEntry = new DrugPolicyEntry { drug = newdrug, allowedForAddiction = false, allowedForJoy = false, allowScheduled = false }; if (dp.label == "SocialDrugs".Translate()) { if (DC == DrugCategory.Social) { drugPolicyEntry.allowedForJoy = true; } } else if (dp.label == "Unrestricted".Translate()) { if (newdrug.IsPleasureDrug) { drugPolicyEntry.allowedForJoy = true; } } else if (dp.label == "OneDrinkPerDay".Translate() && (DrugPolicyUtility.IsAlcohol(newdrug) || DrugPolicyUtility.IsSmokey(newdrug)) && newdrug.IsPleasureDrug) { drugPolicyEntry.allowedForJoy = true; } if (DrugPolicyUtility.IsAddictive(newdrug)) { drugPolicyEntry.allowedForAddiction = true; } var list = NonPublicFields.DrugPolicyEntryList(dp); list.AddDistinct(drugPolicyEntry); NonPublicFields.DrugPolicyEntryList(dp) = list; }
public static bool SavePolicySettings(DrugPolicy policy, FileInfo fi) { try { // Write Data using (FileStream fileStream = File.Open(fi.FullName, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fileStream)) { WriteField(sw, "Version", "1"); WriteField(sw, "name", policy.label); for (int i = 0; i < policy.Count; ++i) { DrugPolicyEntry e = policy[i]; WriteField(sw, "drug", i.ToString()); WriteField(sw, "defName", e.drug.defName); WriteField(sw, "allowedForAddiction", e.allowedForAddiction.ToString()); WriteField(sw, "allowedForJoy", e.allowedForJoy.ToString()); WriteField(sw, "allowScheduled", e.allowScheduled.ToString()); WriteField(sw, "daysFrequency", e.daysFrequency.ToString()); WriteField(sw, "onlyIfJoyBelow", e.onlyIfJoyBelow.ToString()); WriteField(sw, "onlyIfMoodBelow", e.onlyIfMoodBelow.ToString()); WriteField(sw, "takeToInventory", e.takeToInventory.ToString()); WriteField(sw, "takeToInventoryTempBuffer", e.takeToInventoryTempBuffer); WriteField(sw, BREAK, BREAK); } } } } catch (Exception e) { LogException("Problem saving storage settings file '" + fi.Name + "'.", e); return(false); } return(true); }
internal static void SaveCurrentState(List <Pawn> pawns) { int currentMap = Find.CurrentMap.uniqueID; //Save current state foreach (Pawn p in pawns) { //find colonist on the current zone in the current map AssignLink link = AssignManager.links.Find( x => p.Equals(x.colonist) && x.zone == AssignManager.GetActivePolicy().id&& x.mapId == currentMap); if (link != null) { //colonist found! save link.outfit = p.outfits.CurrentOutfit; link.drugPolicy = p.drugs.CurrentPolicy; link.hostilityResponse = p.playerSettings.hostilityResponse; link.foodPolicy = p.foodRestriction.CurrentFoodRestriction; if (Widget_CombatExtended.CombatExtendedAvailable) { link.loadoutId = Widget_CombatExtended.GetLoadoutId(p); } } else { //colonist not found. So add it to the AssignLink list int loadoutId = 0; if (Widget_CombatExtended.CombatExtendedAvailable) { loadoutId = Widget_CombatExtended.GetLoadoutId(p); } Outfit outfit = p.outfits.CurrentOutfit; if (outfit == Current.Game.outfitDatabase.DefaultOutfit()) { outfit = AssignManager.DefaultOutfit; } DrugPolicy drug = p.drugs.CurrentPolicy; if (drug == Current.Game.drugPolicyDatabase.DefaultDrugPolicy()) { drug = AssignManager.DefaultDrugPolicy; } FoodRestriction food = p.foodRestriction.CurrentFoodRestriction; if (food == Current.Game.foodRestrictionDatabase.DefaultFoodRestriction()) { food = AssignManager.DefaultFoodPolicy; } AssignManager.links.Add( new AssignLink( AssignManager.GetActivePolicy().id, p, outfit, food, drug, p.playerSettings.hostilityResponse, loadoutId, currentMap)); } } }
internal LoadPolicyDialog(string storageTypeName, DrugPolicy drugPolicy) : base(storageTypeName) { this.DrugPolicy = drugPolicy; this.interactButLabel = "LoadGameButton".Translate(); }
// Token: 0x0600004C RID: 76 RVA: 0x00005168 File Offset: 0x00003368 public static bool IsOKtoAdmin(Pawn pawn, HediffDef hdef, ThingDef def) { DrugPolicy drugPolicy; if (pawn == null) { drugPolicy = null; } else { Pawn_DrugPolicyTracker drugs = pawn.drugs; drugPolicy = (drugs?.CurrentPolicy); } DrugPolicy policy = drugPolicy; if (policy != null) { if (!MSDrugUtility.DPExists(policy, def)) { Messages.Message(TranslatorFormattedStringExtensions.Translate("MSPainless.ErrDrugPolicy", pawn?.LabelShort, def?.label), pawn, MessageTypeDefOf.NeutralEvent, false); return(false); } if (policy[def] != null) { DrugPolicyEntry entry = policy[def]; if (entry != null && entry.allowScheduled && entry != null && entry.daysFrequency > 0f) { return(false); } } } if (!DRSettings.DoIfImmune && MSDrugUtility.ImmuneNow(pawn, hdef)) { return(false); } if (hdef != null && hdef.defName == "Anesthetic") { HediffSet hediffSet; if (pawn == null) { hediffSet = null; } else { Pawn_HealthTracker health = pawn.health; hediffSet = (health?.hediffSet); } HediffSet set = hediffSet; if (set != null) { Hediff Anesthetic = set.GetFirstHediffOfDef(hdef, false); if (Anesthetic != null && Anesthetic.Severity >= 0.8f) { return(false); } } } if (def.IsIngestible) { List <IngestionOutcomeDoer> ODs = def.ingestible.outcomeDoers; if (ODs.Count > 0) { bool toohighsev = false; HediffSet hediffSet2; if (pawn == null) { hediffSet2 = null; } else { Pawn_HealthTracker health2 = pawn.health; hediffSet2 = (health2?.hediffSet); } HediffSet hediffset = hediffSet2; if (hediffset != null) { foreach (IngestionOutcomeDoer OD in ODs) { if (OD is IngestionOutcomeDoer_GiveHediff) { IngestionOutcomeDoer_GiveHediff ingestionOutcomeDoer_GiveHediff = OD as IngestionOutcomeDoer_GiveHediff; HediffDef ODhediffdef = ingestionOutcomeDoer_GiveHediff?.hediffDef; if (ODhediffdef != null) { float ODSev = (OD as IngestionOutcomeDoer_GiveHediff).severity; if (ODSev > 0f) { Hediff ODhediff = hediffset.GetFirstHediffOfDef(ODhediffdef, false); if (ODhediff != null && ODhediff.Severity / ODSev > 0.75f) { toohighsev = true; } } } } } if (toohighsev) { return(false); } } } return(true); } return(false); }
public void SavePawnToCorticalStack(Pawn pawn) { this.name = pawn.Name; this.origPawn = pawn; if (pawn.playerSettings != null) { this.hostilityMode = (int)pawn.playerSettings.hostilityResponse; this.areaRestriction = pawn.playerSettings.AreaRestriction; this.medicalCareCategory = pawn.playerSettings.medCare; this.selfTend = pawn.playerSettings.selfTend; } this.ageChronologicalTicks = pawn.ageTracker.AgeChronologicalTicks; this.foodRestriction = pawn.foodRestriction?.CurrentFoodRestriction; this.outfit = pawn.outfits?.CurrentOutfit; this.drugPolicy = pawn.drugs?.CurrentPolicy; this.times = pawn.timetable?.times; this.thoughts = pawn.needs?.mood?.thoughts?.memories?.Memories; this.faction = pawn.Faction; if (pawn.Faction.leader == pawn) { this.isFactionLeader = true; } this.traits = pawn.story?.traits?.allTraits; this.relations = pawn.relations?.DirectRelations; this.relatedPawns = pawn.relations.RelatedPawns.ToHashSet(); this.skills = pawn.skills?.skills; this.childhood = pawn.story?.childhood?.identifier; if (pawn.story?.adulthood != null) { this.adulthood = pawn.story.adulthood.identifier; } this.priorities = new Dictionary <WorkTypeDef, int>(); if (pawn.workSettings != null && Traverse.Create(pawn.workSettings).Field("priorities").GetValue <DefMap <WorkTypeDef, int> >() != null) { foreach (WorkTypeDef w in DefDatabase <WorkTypeDef> .AllDefs) { this.priorities[w] = pawn.workSettings.GetPriority(w); } } this.hasPawn = true; this.pawnID = pawn.ThingID; if (ModLister.RoyaltyInstalled) { this.royalTitles = pawn.royalty?.AllTitlesForReading; this.favor = Traverse.Create(pawn.royalty).Field("favor").GetValue <Dictionary <Faction, int> >(); this.heirs = Traverse.Create(pawn.royalty).Field("heirs").GetValue <Dictionary <Faction, Pawn> >(); foreach (var map in Find.Maps) { foreach (var thing in map.listerThings.AllThings) { var comp = thing.TryGetComp <CompBladelinkWeapon>(); if (comp != null) { } if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(thing); } } foreach (var gear in pawn.apparel.WornApparel) { var comp = gear.TryGetComp <CompBladelinkWeapon>(); if (comp != null) { } if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(gear); } } foreach (var gear in pawn.equipment.AllEquipmentListForReading) { var comp = gear.TryGetComp <CompBladelinkWeapon>(); if (comp != null) { } if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(gear); } } foreach (var gear in pawn.inventory.innerContainer) { var comp = gear.TryGetComp <CompBladelinkWeapon>(); if (comp != null) { } if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(gear); } } } } }
public SavePolicyDialog(string type, DrugPolicy drugPolicy) : base(type) { DrugPolicy = drugPolicy; }
public void SavePawnFromHediff(Hediff_CorticalStack hediff) { this.name = hediff.name; this.origPawn = hediff.origPawn; this.hostilityMode = hediff.hostilityMode; this.areaRestriction = hediff.areaRestriction; this.ageChronologicalTicks = hediff.ageChronologicalTicks; this.medicalCareCategory = hediff.medicalCareCategory; this.selfTend = hediff.selfTend; this.foodRestriction = hediff.foodRestriction; this.outfit = hediff.outfit; this.drugPolicy = hediff.drugPolicy; this.times = hediff.times; this.thoughts = hediff.thoughts; this.faction = hediff.faction; this.isFactionLeader = hediff.isFactionLeader; this.traits = hediff.traits; this.relations = hediff.relations; this.relatedPawns = hediff.relatedPawns; this.skills = hediff.skills; if (hediff.negativeSkillsOffsets != null) { foreach (var negativeOffset in hediff.negativeSkillsOffsets) { var skill = this.skills.Where(x => x.def == negativeOffset.skill).FirstOrDefault(); if (skill != null) { skill.Level += negativeOffset.offset; } } } if (hediff.negativeSkillPassionsOffsets != null) { foreach (var negativeOffset in hediff.negativeSkillPassionsOffsets) { var skill = this.skills.Where(x => x.def == negativeOffset.skill).FirstOrDefault(); if (skill != null) { var finalValue = (int)skill.passion + negativeOffset.offset + 1; //Log.Message("finalValue: " + finalValue, true); if (finalValue <= 2) { switch (finalValue) { case 0: skill.passion = Passion.None; //Log.Message(skill.def + " - finalValue: " + finalValue + " - skill.passion = Passion.None"); break; case 1: skill.passion = Passion.Minor; //Log.Message(skill.def + " - finalValue: " + finalValue + " - skill.passion = Passion.Minor"); break; case 2: skill.passion = Passion.Major; //Log.Message(skill.def + " - finalValue: " + finalValue + " - skill.passion = Passion.Major"); break; default: skill.passion = Passion.None; //Log.Message("default: " + skill.def + " - finalValue: " + finalValue + " - skill.passion = Passion.None"); break; } } else { skill.passion = Passion.None; //Log.Message("2 default: " + skill.def + " - finalValue: " + finalValue + " - skill.passion = Passion.None"); } } } } this.childhood = hediff.childhood; this.adulthood = hediff.adulthood; this.priorities = hediff.priorities; this.hasPawn = true; if (this.gender == Gender.None) { this.gender = hediff.gender; } if (this.race == null) { this.race = hediff.race; } this.pawnID = hediff.pawnID; if (ModLister.RoyaltyInstalled) { this.royalTitles = hediff.royalTitles; this.favor = hediff.favor; this.heirs = hediff.heirs; this.bondedThings = hediff.bondedThings; this.permitPoints = hediff.permitPoints; this.factionPermits = hediff.factionPermits; } this.isCopied = hediff.isCopied; this.stackGroupID = hediff.stackGroupID; this.sexuality = hediff.sexuality; this.romanceFactor = hediff.romanceFactor; this.psychologyData = hediff.psychologyData; }
public void SavePawnToCorticalStack(Pawn pawn) { this.name = pawn.Name; this.origPawn = pawn; if (pawn.playerSettings != null) { this.hostilityMode = (int)pawn.playerSettings.hostilityResponse; this.areaRestriction = pawn.playerSettings.AreaRestriction; this.medicalCareCategory = pawn.playerSettings.medCare; this.selfTend = pawn.playerSettings.selfTend; } if (pawn.ageTracker != null) { this.ageChronologicalTicks = pawn.ageTracker.AgeChronologicalTicks; } this.foodRestriction = pawn.foodRestriction?.CurrentFoodRestriction; this.outfit = pawn.outfits?.CurrentOutfit; this.drugPolicy = pawn.drugs?.CurrentPolicy; this.times = pawn.timetable?.times; this.thoughts = pawn.needs?.mood?.thoughts?.memories?.Memories; this.faction = pawn.Faction; if (pawn.Faction.leader == pawn) { this.isFactionLeader = true; } this.traits = pawn.story?.traits?.allTraits; this.relations = pawn.relations?.DirectRelations; this.relatedPawns = pawn.relations?.RelatedPawns?.ToHashSet(); foreach (var otherPawn in pawn.relations.RelatedPawns) { foreach (var rel2 in pawn.GetRelations(otherPawn)) { if (this.relations.Where(r => r.def == rel2 && r.otherPawn == otherPawn).Count() == 0) { //Log.Message("00000 Rel: " + otherPawn?.Name + " - " + rel2 + " - " + pawn.Name, true); if (!rel2.implied) { this.relations.Add(new DirectPawnRelation(rel2, otherPawn, 0)); } } } relatedPawns.Add(otherPawn); } this.skills = pawn.skills?.skills; this.childhood = pawn.story?.childhood?.identifier; if (pawn.story?.adulthood != null) { this.adulthood = pawn.story.adulthood.identifier; } this.priorities = new Dictionary <WorkTypeDef, int>(); if (pawn.workSettings != null && Traverse.Create(pawn.workSettings).Field("priorities").GetValue <DefMap <WorkTypeDef, int> >() != null) { foreach (WorkTypeDef w in DefDatabase <WorkTypeDef> .AllDefs) { this.priorities[w] = pawn.workSettings.GetPriority(w); } } this.hasPawn = true; this.pawnID = pawn.ThingID; if (ModLister.RoyaltyInstalled && pawn.royalty != null) { this.royalTitles = pawn.royalty?.AllTitlesForReading; this.favor = Traverse.Create(pawn.royalty).Field("favor").GetValue <Dictionary <Faction, int> >(); this.heirs = Traverse.Create(pawn.royalty).Field("heirs").GetValue <Dictionary <Faction, Pawn> >(); foreach (var map in Find.Maps) { foreach (var thing in map.listerThings.AllThings) { var comp = thing.TryGetComp <CompBladelinkWeapon>(); if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(thing); } } foreach (var gear in pawn.apparel?.WornApparel) { var comp = gear.TryGetComp <CompBladelinkWeapon>(); if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(gear); } } foreach (var gear in pawn.equipment?.AllEquipmentListForReading) { var comp = gear.TryGetComp <CompBladelinkWeapon>(); if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(gear); } } foreach (var gear in pawn.inventory?.innerContainer) { var comp = gear.TryGetComp <CompBladelinkWeapon>(); if (comp != null && comp.bondedPawn == pawn) { this.bondedThings.Add(gear); } } } this.factionPermits = Traverse.Create(pawn.royalty).Field("factionPermits").GetValue <List <FactionPermit> >(); this.permitPoints = Traverse.Create(pawn.royalty).Field("permitPoints").GetValue <Dictionary <Faction, int> >(); } if (ModCompatibility.IndividualityIsActive) { this.sexuality = ModCompatibility.GetSyrTraitsSexuality(pawn); this.romanceFactor = ModCompatibility.GetSyrTraitsRomanceFactor(pawn); } if (ModCompatibility.PsychologyIsActive) { this.psychologyData = ModCompatibility.GetPsychologyData(pawn); } }
static bool Prefix(Pawn_InventoryTracker __instance, ref ThingCount __result) { if (__instance.innerContainer.Count == 0) { __result = default(ThingCount); return(false); } tmpDrugsToKeep.Clear(); if (__instance.pawn.drugs != null && __instance.pawn.drugs.CurrentPolicy != null) { DrugPolicy currentPolicy = __instance.pawn.drugs.CurrentPolicy; for (int i = 0; i < currentPolicy.Count; i++) { if (currentPolicy[i].takeToInventory > 0) { tmpDrugsToKeep.Add(new ThingDefCount(currentPolicy[i].drug, currentPolicy[i].takeToInventory)); } } } Thing bestInstrument = null; if (!__instance.pawn.NonHumanlikeOrWildMan() && !__instance.pawn.WorkTagIsDisabled(WorkTags.Artistic)) { int artSkill = __instance.pawn.skills.GetSkill(SkillDefOf.Artistic).levelInt; IEnumerable <Thing> heldInstruments = __instance.innerContainer.Where(x => PerformanceManager.IsInstrument(x)) .Where(x => !x.TryGetComp <CompMusicalInstrument>().Props.isBuilding) .OrderByDescending(x => x.TryGetComp <CompMusicalInstrument>().WeightedSuitability(artSkill)); if (heldInstruments.Any()) { bestInstrument = heldInstruments.FirstOrDefault(); } } if (tmpDrugsToKeep.Any() || bestInstrument != null) { for (int j = 0; j < __instance.innerContainer.Count; j++) { if (__instance.innerContainer[j].def.IsDrug) { int num = -1; for (int k = 0; k < tmpDrugsToKeep.Count; k++) { if (__instance.innerContainer[j].def == tmpDrugsToKeep[k].ThingDef) { num = k; break; } } if (num < 0) { __result = new ThingCount(__instance.innerContainer[j], __instance.innerContainer[j].stackCount); return(false); } if (__instance.innerContainer[j].stackCount > tmpDrugsToKeep[num].Count) { __result = new ThingCount(__instance.innerContainer[j], __instance.innerContainer[j].stackCount - tmpDrugsToKeep[num].Count); return(false); } tmpDrugsToKeep[num] = new ThingDefCount(tmpDrugsToKeep[num].ThingDef, tmpDrugsToKeep[num].Count - __instance.innerContainer[j].stackCount); } else if (PerformanceManager.IsInstrument(__instance.innerContainer[j])) { if (bestInstrument == null) { __result = new ThingCount(__instance.innerContainer[j], __instance.innerContainer[j].stackCount); return(false); } if (bestInstrument.GetHashCode() != __instance.innerContainer[j].GetHashCode()) { __result = new ThingCount(__instance.innerContainer[j], __instance.innerContainer[j].stackCount); return(false); } } else { __result = new ThingCount(__instance.innerContainer[j], __instance.innerContainer[j].stackCount); return(false); } } __result = default(ThingCount); return(false); } else { __result = new ThingCount(__instance.innerContainer[0], __instance.innerContainer[0].stackCount); return(false); } }
private static void SetDrugPolicy(Dialog_ManageDrugPolicies dialog, DrugPolicy selectedPolicy) { typeof(Dialog_ManageDrugPolicies).GetProperty("SelectedPolicy", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty).SetValue(dialog, selectedPolicy, null); }
protected override void DrawPawnRow(Rect rect, Pawn p) { // available space for row Rect rowRect = new Rect(rect.x + 165f, rect.y, rect.width - 165f, rect.height); // response button rect Vector2 responsePos = new Vector2(rowRect.xMin, rowRect.yMin + (rowRect.height - 24f) / 2f); // offset rest of row for that button, so we don't have to mess with all the other rect calculations rowRect.xMin += 24f + _margin; // label + buttons for outfit Rect outfitRect = new Rect(rowRect.xMin, rowRect.yMin, rowRect.width * (1f / 4f) + (_margin + _buttonSize) / 2f, rowRect.height); Rect labelOutfitRect = new Rect(outfitRect.xMin, outfitRect.yMin, outfitRect.width - _margin * 3 - _buttonSize * 2, outfitRect.height) .ContractedBy(_margin / 2f); Rect editOutfitRect = new Rect(labelOutfitRect.xMax + _margin, outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2), _buttonSize, _buttonSize); Rect forcedOutfitRect = new Rect(labelOutfitRect.xMax + _buttonSize + _margin * 2, outfitRect.yMin + ((outfitRect.height - _buttonSize) / 2), _buttonSize, _buttonSize); // drucg policy Rect drugRect = new Rect(outfitRect.xMax, rowRect.yMin, rowRect.width * (1f / 4f) - (_margin + _buttonSize) / 2f, rowRect.height); Rect labelDrugRect = new Rect(drugRect.xMin, drugRect.yMin, drugRect.width - _margin * 2 - _buttonSize, drugRect.height) .ContractedBy(_margin / 2f); Rect editDrugRect = new Rect(labelDrugRect.xMax + _margin, drugRect.yMin + ((drugRect.height - _buttonSize) / 2), _buttonSize, _buttonSize); // label + button for loadout Rect loadoutRect = new Rect(drugRect.xMax, rowRect.yMin, rowRect.width * (1f / 4f) - (_margin + _buttonSize) / 2f, rowRect.height); Rect labelLoadoutRect = new Rect(loadoutRect.xMin, loadoutRect.yMin, loadoutRect.width - _margin * 2 - _buttonSize, loadoutRect.height) .ContractedBy(_margin / 2f); Rect editLoadoutRect = new Rect(labelLoadoutRect.xMax + _margin, loadoutRect.yMin + ((loadoutRect.height - _buttonSize) / 2), _buttonSize, _buttonSize); // fight or flight button HostilityResponseModeUtility.DrawResponseButton(responsePos, p); // weight + bulk indicators Rect weightRect = new Rect(loadoutRect.xMax, rowRect.yMin, rowRect.width * (1f / 8f) - _margin, rowRect.height).ContractedBy(_margin / 2f); Rect bulkRect = new Rect(weightRect.xMax + _margin, rowRect.yMin, rowRect.width * (1f / 8f) - _margin, rowRect.height).ContractedBy(_margin / 2f); // OUTFITS // main button if (Widgets.ButtonText(labelOutfitRect, p.outfits.CurrentOutfit.label, true, false)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (Outfit current in Current.Game.outfitDatabase.AllOutfits) { // need to create a local copy for delegate Outfit localOut = current; options.Add(new FloatMenuOption(localOut.label, delegate { p.outfits.CurrentOutfit = localOut; }, MenuOptionPriority.Default, null, null)); } Find.WindowStack.Add(new FloatMenu(options, optionalTitle, false)); } // edit button TooltipHandler.TipRegion(editOutfitRect, "CE_EditX".Translate("CE_outfit".Translate() + " " + p.outfits.CurrentOutfit.label)); if (Widgets.ButtonImage(editOutfitRect, _iconEdit)) { Text.Font = GameFont.Small; Find.WindowStack.Add(new Dialog_ManageOutfits(p.outfits.CurrentOutfit)); } // clear forced button if (p.outfits.forcedHandler.SomethingIsForced) { TooltipHandler.TipRegion(forcedOutfitRect, "ClearForcedApparel".Translate()); if (Widgets.ButtonImage(forcedOutfitRect, _iconClearForced)) { p.outfits.forcedHandler.Reset(); } TooltipHandler.TipRegion(forcedOutfitRect, new TipSignal(delegate { string text = "ForcedApparel".Translate() + ":\n"; foreach (Apparel current2 in p.outfits.forcedHandler.ForcedApparel) { text = text + "\n " + current2.LabelCap; } return(text); }, p.GetHashCode() * 612)); } // DRUG POLICY // main button string textDrug = p.drugs.CurrentPolicy.label; if (p.story != null && p.story.traits != null) { Trait trait = p.story.traits.GetTrait(TraitDefOf.DrugDesire); if (trait != null) { textDrug = textDrug + " (" + trait.Label + ")"; } } if (Widgets.ButtonText(labelDrugRect, textDrug, true, false, true)) { List <FloatMenuOption> list = new List <FloatMenuOption>(); foreach (DrugPolicy current in Current.Game.drugPolicyDatabase.AllPolicies) { DrugPolicy localAssignedDrugs = current; list.Add(new FloatMenuOption(current.label, delegate { p.drugs.CurrentPolicy = localAssignedDrugs; }, MenuOptionPriority.Default, null, null, 0f, null)); } Find.WindowStack.Add(new FloatMenu(list)); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.DrugPolicies, KnowledgeAmount.Total); } // edit button TooltipHandler.TipRegion(editDrugRect, "CE_EditX".Translate("CE_drugs".Translate() + " " + p.drugs.CurrentPolicy.label)); if (Widgets.ButtonImage(editDrugRect, _iconEdit)) { Text.Font = GameFont.Small; Find.WindowStack.Add(new Dialog_ManageDrugPolicies(p.drugs.CurrentPolicy)); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.DrugPolicies, KnowledgeAmount.Total); } // LOADOUTS // main button if (Widgets.ButtonText(labelLoadoutRect, p.GetLoadout().LabelCap, true, false)) { List <FloatMenuOption> options = new List <FloatMenuOption>(); foreach (Loadout loadout in LoadoutManager.Loadouts) { // need to create a local copy for delegate Loadout localLoadout = loadout; options.Add(new FloatMenuOption(localLoadout.LabelCap, delegate { p.SetLoadout(localLoadout); }, MenuOptionPriority.Default, null, null)); } Find.WindowStack.Add(new FloatMenu(options, optionalTitle, false)); } // edit button TooltipHandler.TipRegion(editLoadoutRect, "CE_EditX".Translate("CE_loadout".Translate() + " " + p.GetLoadout().LabelCap)); if (Widgets.ButtonImage(editLoadoutRect, _iconEdit)) { Find.WindowStack.Add(new Dialog_ManageLoadouts(p.GetLoadout())); } // STATUS BARS // fetch the comp CompInventory comp = p.TryGetComp <CompInventory>(); if (comp != null) { Utility_Loadouts.DrawBar(bulkRect, comp.currentBulk, comp.capacityBulk, "", p.GetBulkTip()); Utility_Loadouts.DrawBar(weightRect, comp.currentWeight, comp.capacityWeight, "", p.GetWeightTip()); } }
public static void Postfix(ref DrugPolicy __result) { DrugPolicySort.SortPolicy(__result); }
internal SavePolicyDialog(string type, DrugPolicy drugPolicy) : base(type) { this.DrugPolicy = drugPolicy; this.interactButLabel = "OverwriteButton".Translate(); }