private void BreakLoverAndFianceRelations(Pawn pawn, out List <Pawn> oldLoversAndFiances) { oldLoversAndFiances = new List <Pawn> { }; List <PawnRelationDef> relationsToBreak = RelationshipUtility.ListOfBreakupRelationships(); for (int i = 0; i < relationsToBreak.Count(); i++) { PawnRelationDef relation = relationsToBreak[i]; List <Pawn> pawns = RelationshipUtility.GetAllPawnsWithGivenRelationshipTo(pawn, relation); for (int i2 = 1; i2 < pawns.Count(); i2++) { Pawn other = pawns[i2]; if (!RelationshipUtility.IsPolygamist(pawn) || !RelationshipUtility.IsPolygamist(other)) { if (!relation.GetModExtension <RomanticRelationExtension>().isFormalRelationship&& !BreakupUtility.ShouldImplicitlyEndInformalRelationship(pawn, other, relation)) { continue; } BreakupUtility.ResolveBreakup(pawn, other, relation); oldLoversAndFiances.Add(other); } } } }
public void AddThought(ThoughtDef thought, PawnRelationDef relationDef, Pawn pawn) { if (RimValiUtility.GetPackSize(pawn, relationDef) == 1 && packLossEnabled) { RimValiUtility.AddThought(pawn, thought); } }
public static void CollectPackmates(Pawn pawn, Pawn pawn2, PawnRelationDef relationDef) { //Grab a list of all of their pack relations. IEnumerable <Pawn> firstRelatedPawns = pawn.relations.RelatedPawns.Where(x => x.relations.DirectRelationExists(relationDef, pawn)); IEnumerable <Pawn> secondRelatedPawns = pawn2.relations.RelatedPawns.Where(x => x.relations.DirectRelationExists(relationDef, pawn2)); foreach (Pawn pawnFound in firstRelatedPawns) { //if a packmate relation exists between pawn and firstRelatedPawns[relatedItem] if (pawn.relations.DirectRelationExists(relationDef, pawnFound)) { //and the other pawn does not have it if (!pawn2.relations.DirectRelationExists(relationDef, pawnFound) && !(pawn2 == pawnFound)) { //add the relation to both pawn2.relations.AddDirectRelation(relationDef, pawnFound); } } } //same thing, except pawn2 is in place of pawn, and secondRelatedPawns replaces firstRelated foreach (Pawn foundPawn in secondRelatedPawns) { if (pawn2.relations.DirectRelationExists(relationDef, foundPawn)) { if (!pawn.relations.DirectRelationExists(relationDef, foundPawn) && !(pawn == foundPawn)) { pawn.relations.AddDirectRelation(relationDef, foundPawn); } } } }
private static void ApplyQueenRelation(Pawn queen) { PawnRelationDef relation = DefDatabase <PawnRelationDef> .GetNamed("Ant_QueenRelation"); // all free colonists on map List <Pawn> colonists = new List <Pawn>(); colonists = queen.Map.mapPawns.FreeColonists.ToList(); foreach (Pawn c in colonists.Where(p => p.RaceProps.Humanlike && p != queen)) { if (c.relations.GetDirectRelation(relation, queen) == null) { // remove any old Q relations List <DirectPawnRelation> others = new List <DirectPawnRelation>(); others = c.relations.DirectRelations.Where(r => r.def == relation).ToList(); if (others.Count != 0) { foreach (DirectPawnRelation r in others) { c.relations.RemoveDirectRelation(r); } } // add new Q relation c.relations.AddDirectRelation(relation, queen); } } }
public CustomRelationship(PawnRelationDef def, CustomPawn source, CustomPawn target, bool removeable) { this.def = def; this.source = source; this.target = target; this.removeable = removeable; }
public static void TryAddDirectRelation(this Pawn pawn1, Pawn pawn2, PawnRelationDef relation) { if (!pawn1.relations.DirectRelationExists(relation, pawn2)) { pawn1.relations.AddDirectRelation(relation, pawn2); } }
public void UpdatePawns(Map map) { IEnumerable <Pawn> pawns = RimValiUtility.CheckAllPawnsInMapAndFaction(map, Faction.OfPlayer).Where(x => x.def == AvaliDefs.RimVali); foreach (Pawn pawn in pawns) { AvaliThoughtDriver avaliThoughtDriver = pawn.TryGetComp <AvaliThoughtDriver>(); PackComp packComp = pawn.TryGetComp <PackComp>(); if (!(avaliThoughtDriver == null)) { if (pawn.def == AvaliDefs.RimVali) { if (RimValiUtility.GetPackSize(pawn, avaliThoughtDriver.Props.relationDef) > 1) { PawnRelationDef relationDef = avaliThoughtDriver.Props.relationDef; UpdateSharedRoomThought(pawn, relationDef, avaliThoughtDriver.Props.inSameRoomThought); UpdateBedRoomThought(pawn, relationDef, avaliThoughtDriver.Props.sharedBedroomThought, avaliThoughtDriver.Props.sleptApartThought); } } } if (!(packComp == null)) { if (packComp.Props.canHaveAloneThought) { UpdateThought(pawn, packComp.Props.relation, packComp.Props.aloneThought); } } } }
public static void TrimPack(Pawn pawn, Pawn pawn2, PawnRelationDef relationDef, Faction faction = null, int limit = 5) { if (faction == null) { faction = pawn.Faction; } IEnumerable <Pawn> firstRelatedPawns = pawn.relations.RelatedPawns.Where(x => x.relations.DirectRelationExists(relationDef, pawn)); IEnumerable <Pawn> secondRelatedPawns = pawn2.relations.RelatedPawns.Where(x => x.relations.DirectRelationExists(relationDef, pawn2)); foreach (Pawn pawnFound in firstRelatedPawns) { //if a packmate relation exists between pawn and firstRelatedPawns[relatedItem] if (pawn.relations.DirectRelationExists(relationDef, pawnFound) && GetPackSize(pawn, relationDef) > limit) { //and the other pawn does not have it if (pawn2.relations.DirectRelationExists(relationDef, pawnFound)) { //remove the relation from both pawn2.relations.TryRemoveDirectRelation(relationDef, pawnFound); } } } //same thing, except pawn2 is in place of pawn, and secondRelatedPawns replaces firstRelated foreach (Pawn foundPawn in secondRelatedPawns) { if (pawn2.relations.DirectRelationExists(relationDef, foundPawn) && GetPackSize(pawn2, relationDef) > limit) { if (pawn.relations.DirectRelationExists(relationDef, foundPawn)) { pawn.relations.TryRemoveDirectRelation(relationDef, foundPawn); } } } }
public static Pawn PawnWithMostAdvancedRelationship(Pawn pawn, out PawnRelationDef relation, bool mostLikedLover = true) { List <PawnRelationDef> listOfRomanceStages = ListOfRomanceStages(); Pawn lover = null; relation = null; for (int i = 0; i < listOfRomanceStages.Count(); i++) { relation = listOfRomanceStages[i]; List <Pawn> lovers = GetAllPawnsWithGivenRelationshipTo(pawn, listOfRomanceStages[i]); if (lovers.Count() > 0) { for (int i2 = 0; i < lovers.Count(); i++) { if (lover == null) { lover = lovers[i2]; } else if (mostLikedLover == false && lover.relations.OpinionOf(pawn) < lovers[i2].relations.OpinionOf(pawn)) { lover = lovers[i2]; } else if (mostLikedLover == true && pawn.relations.OpinionOf(lover) < pawn.relations.OpinionOf(lovers[i2])) { lover = lovers[i2]; } } break; } } return(lover); }
//returns the most logical romance stage for the given romance stage. public static PawnRelationDef NextRomanceStage(PawnRelationDef currentStage) { if (currentStage == PawnRelationDefOf.Fiance) { return(PawnRelationDefOf.Spouse); } else if (currentStage == PawnRelationDefOf.Lover) { return(PawnRelationDefOf.Fiance); } else if (currentStage == PawnRelationDefOfGR.Lovefriend) { return(PawnRelationDefOf.Lover); } else if (currentStage == PawnRelationDefOfGR.Sweetheart) { return(PawnRelationDefOfGR.Lovefriend); } else if (currentStage == PawnRelationDefOfGR.Lovebuddy) { return(PawnRelationDefOfGR.Lovefriend); } else { return(null); } }
/// <summary> /// Gives out relationship-based Thoughts, such as My Relative Died, and Killer Killed My Relative/Friend/Rival. /// <para/> /// Most thoughts given out here are all social thoughts. The very few excptions to this are the Bonded Animal Died thought /// </summary> private void GiveOutRelationshipBasedThoughts(Pawn recipient) { PawnRelationDef mostImportantRelation = recipient.GetMostImportantRelation(Victim); if (mostImportantRelation != null) { // Step 2.0: News is shocking because relative died. recipient.GetNewsKnowledgeTracker().AttemptToObtainExistingReference(this).FlagAsShockingNews(); // Step 2.1: My relative died ThoughtDef genderSpecificDiedThought = mostImportantRelation.GetGenderSpecificDiedThought(Victim); if (genderSpecificDiedThought != null) { new IndividualThoughtToAdd(genderSpecificDiedThought, recipient, Victim, 1f, 1f).Add(); } // Step 2.2: Hatred towards killer; does not allow self-hating if (Killer != null && Killer != Victim && Killer != recipient) { // This killer killed my relatives GiveOutHatredTowardsKiller_ForRelatives(mostImportantRelation, recipient); // This killer killed my friend/rival if (recipient.RaceProps.IsFlesh) { GiveOutHatredTowardsKiller_ForFriendsOrRivals(recipient); } } } }
public static bool IsSingle(Pawn pawn) { try { Pawn_RelationsTracker pawn_relations_tracker = pawn.relations; PawnRelationDef relationship_lover = PawnRelationDefOf.Lover; Predicate <Pawn> isNotDead = (Pawn p) => { return(!p.Dead); }; if (pawn_relations_tracker.GetFirstDirectRelationPawn(relationship_lover, isNotDead) == null) { PawnRelationDef relationship_fiance = PawnRelationDefOf.Fiance; if (pawn_relations_tracker.GetFirstDirectRelationPawn(relationship_fiance, isNotDead) == null) { PawnRelationDef relationship_spouse = PawnRelationDefOf.Spouse; return(pawn_relations_tracker.GetFirstDirectRelationPawn(relationship_spouse, isNotDead) == null); } } return(false); } catch (NullReferenceException e) { // I don't know man, wave a magic wand? } catch { // I don't know man, wave a magic wand? } finally { // I don't know man, wave a magic wand? } return(false); }
// Plundered and adapted from Psychology public override float RandomSelectionWeight(Pawn initiator, Pawn recipient) { if (!RelationshipUtility.HasInformalRelationship(initiator, recipient) && !LovePartnerRelationUtility.LovePartnerRelationExists(initiator, recipient)) { return(0f); } else if (initiator.story.traits.HasTrait(TraitDefOfPsychology.Codependent)) { return(0f); } float chance = 0.02f * GradualRomanceMod.BaseBreakupChance; float romanticFactor = 1f; if (PsycheHelper.PsychologyEnabled(initiator)) { chance = 0.05f * GradualRomanceMod.BaseBreakupChance; romanticFactor = Mathf.InverseLerp(1.05f, 0f, PsycheHelper.Comp(initiator).Psyche.GetPersonalityRating(PersonalityNodeDefOf.Romantic)); } float opinionFactor = Mathf.InverseLerp(100f, -100f, (float)initiator.relations.OpinionOf(recipient)); float spouseFactor = 1f; PawnRelationDef relation = RelationshipUtility.MostAdvancedRelationshipBetween(initiator, recipient); spouseFactor = relation.GetModExtension <RomanticRelationExtension>().baseAffairReluctance; float justificationFactor = 0.75f; if (BreakupUtility.HasReasonForBreakup(initiator, recipient)) { justificationFactor = 2f; } return(chance * romanticFactor * opinionFactor * spouseFactor * justificationFactor); }
private void SetVars(Slate slate) { if (pawn.GetValue(slate) == null || otherPawns.GetValue(slate) == null) { return; } tmpRelations.Clear(); int num = 0; foreach (Pawn item in otherPawns.GetValue(slate)) { PawnRelationDef mostImportantRelation = pawn.GetValue(slate).GetMostImportantRelation(item); if (mostImportantRelation != null) { tmpRelations.Add(mostImportantRelation.GetGenderSpecificLabel(item)); } else { num++; } } if (num == 1) { tmpRelations.Add(nonRelatedLabel.GetValue(slate)); } else if (num >= 2) { tmpRelations.Add(num + " " + nonRelatedLabelPlural.GetValue(slate)); } if (tmpRelations.Any()) { slate.Set(storeAs.GetValue(slate), tmpRelations.ToCommaList(useAnd: true)); tmpRelations.Clear(); } }
public CustomRelationship(PawnRelationDef def, PawnRelationDef inverseDef, CustomPawn source, CustomPawn target) { this.def = def; this.inverseDef = inverseDef; this.source = source; this.target = target; }
public override void Notify_GeneratedByQuestGen(SitePart part, Slate slate, List <Rule> outExtraDescriptionRules, Dictionary <string, string> outExtraDescriptionConstants) { base.Notify_GeneratedByQuestGen(part, slate, outExtraDescriptionRules, outExtraDescriptionConstants); Pawn pawn = DownedRefugeeQuestUtility.GenerateRefugee(part.site.Tile); part.things = new ThingOwner <Pawn>(part, oneStackOnly: true); part.things.TryAdd(pawn); if (pawn.relations != null) { pawn.relations.everSeenByPlayer = true; } Pawn mostImportantColonyRelative = PawnRelationUtility.GetMostImportantColonyRelative(pawn); if (mostImportantColonyRelative != null) { PawnRelationDef mostImportantRelation = mostImportantColonyRelative.GetMostImportantRelation(pawn); TaggedString text = ""; if (mostImportantRelation != null && mostImportantRelation.opinionOffset > 0) { pawn.relations.relativeInvolvedInRescueQuest = mostImportantColonyRelative; text = "\n\n" + "RelatedPawnInvolvedInQuest".Translate(mostImportantColonyRelative.LabelShort, mostImportantRelation.GetGenderSpecificLabel(pawn), mostImportantColonyRelative.Named("RELATIVE"), pawn.Named("PAWN")).AdjustedFor(pawn); } else { PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, pawn); } outExtraDescriptionRules.Add(new Rule_String("pawnInvolvedInQuestInfo", text)); } slate.Set("refugee", pawn); }
public static bool HasReasonForBreakup(Pawn pawn, Pawn other) { PawnRelationDef relation = RelationshipUtility.MostAdvancedRelationshipBetween(pawn, other); if (relation == null) { return(false); } if (AttractionUtility.GetRelationshipUnmodifiedOpinion(pawn, other) < unmodifiedRelationshipBreakupThreshold) { return(true); } if (pawn.needs.mood.thoughts.memories.Memories.Any <Thought_Memory>(x => x.def.defName == "CheatedOnMe" && x.otherPawn == other)) { return(true); } if (pawn.needs.mood.thoughts.memories.Memories.Any <Thought_Memory>(x => x.def.defName == "CaughtFlirting" && x.otherPawn == other)) { return(true); } if (ThoughtDetector.HasSocialSituationalThought(pawn, other, ThoughtDefOfGR.FeelingNeglected)) { return(true); } return(false); }
public override void Notify_RelationAdded(Pawn otherPawn, PawnRelationDef relationDef) { if (otherPawn == target && (relationDef == PawnRelationDefOf.Lover || relationDef == PawnRelationDefOf.Fiance || relationDef == PawnRelationDefOf.Spouse)) { pawn.health.RemoveHediff(this); } }
public static void AdvanceInformalRelationship(Pawn pawn, Pawn other, out PawnRelationDef newRelation, float sweetheartChance = 0.5f) { PawnRelationDef oldRelation = MostAdvancedRelationshipBetween(pawn, other); //if (!IsInformalRelationship(oldRelation)) newRelation = null; int targetLevel = 1; if (oldRelation != null && IsInformalRelationship(oldRelation)) { targetLevel = (oldRelation.GetModExtension <RomanticRelationExtension>().relationshipLevel + 1); } IEnumerable <PawnRelationDef> candidateRelations = from relation in DefDatabase <PawnRelationDef> .AllDefsListForReading where GetRelationLevel(relation) == targetLevel select relation; if (candidateRelations.Count() > 0) { foreach (PawnRelationDef relation in candidateRelations) { Log.Message("Testing " + relation.defName); if (RelationshipCanEvolveTo(pawn, other, relation)) { if (oldRelation != null) { pawn.relations.TryRemoveDirectRelation(oldRelation, other); } pawn.relations.AddDirectRelation(relation, other); newRelation = relation; break; } } } }
public void UpdatePacks() { IEnumerable <Pawn> pawnsOnMap = RimValiUtility.AllPawnsOfRaceOnMap(AvaliDefs.RimVali, map).Where(x => (RimValiUtility.GetPackSize(x, x.TryGetComp <PackComp>().Props.relation) < maxSize) & racesInPacks.Contains(x.def)); foreach (Pawn pawn in pawnsOnMap) { PackComp comp = pawn.TryGetComp <PackComp>(); if (!(comp == null)) { //Pull the comp info from the pawn PawnRelationDef relationDef = comp.Props.relation; SimpleCurve ageCurve = comp.Props.packGenChanceOverAge; if (RimValiUtility.GetPackSize(pawn, relationDef) == 1) { //Tells us that this pawn has had a pack if (enableDebug) { Log.Message("Attempting to make pack.. [Base pack]"); } //Makes the pack. RimValiUtility.KeoBuildMakePack(pawn, relationDef, racesInPacks, maxSize); } } } }
public static void KeoBuildMakeBasePack(Pawn pawn, PawnRelationDef relationDef, IEnumerable <ThingDef> racesInPacks, int packLimit) { //Get all pawns in the allowed list. IEnumerable <Pawn> packMates = PawnsFinder.AllMaps_SpawnedPawnsInFaction(pawn.Faction).Where <Pawn>(x => racesInPacks.Contains(x.def)); foreach (Pawn packmate in packMates) { //check that neither's pack size is too big, and that they aren't the same if (GetPackSize(packmate, relationDef) == 1 && GetPackSize(pawn, relationDef) == 1 && !(pawn == packmate)) { // adds the relation and evens out the pack. pawn.relations.AddDirectRelation(relationDef, packmate); CollectPackmates(packmate, pawn, relationDef); TrimPack(pawn, packmate, relationDef, packmate.Faction, packLimit); } else { //break if the pawn has reached the max pack limit. if (GetPackSize(pawn, relationDef) == packLimit) { break; } } } }
public CustomRelationship(PawnRelationDef def, CustomPawn source, CustomPawn target) { this.def = def; this.inverseDef = null; this.source = source; this.target = target; this.removeable = true; }
public static void DecayRelationship(Pawn pawn, Pawn other, PawnRelationDef relation) { pawn.relations.TryRemoveDirectRelation(relation, other); if ((PawnUtility.ShouldSendNotificationAbout(pawn) || PawnUtility.ShouldSendNotificationAbout(other)) && GradualRomanceMod.informalRomanceLetters) { //Finish Current.Game.letterStack.ReceiveLetter("RelationshipDecays_label", "RelationshipDecays_text".Translate(pawn, other, relation.label), LetterDefOf.NeutralEvent); } }
public void AddRelationship(PawnRelationDef def, CustomPawn source, CustomPawn target) { if (def.workerClass.GetMethod("CreateRelation", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) == null) { return; } this.relationships.Add(new CustomRelationship(def, FindInverseRelationship(def), source, target)); dirty = true; }
public static Color GetRelationColor(PawnRelationDef def, float opinion) { if (def != null && def.VisibleInTab()) { return(def.ColorInTab()); } return(GetRelationColor(opinion)); }
private void GiveOutHatredTowardsKiller_ForRelatives(PawnRelationDef mostImportantRelation, Pawn recipient) { ThoughtDef genderSpecificKilledThought = mostImportantRelation.GetGenderSpecificKilledThought(Victim); if (genderSpecificKilledThought != null) { new IndividualThoughtToAdd(genderSpecificKilledThought, recipient, Killer, 1f, 1f).Add(); } }
public float DrawRelationship(float cursor, PawnRelationDef def, CustomPawn source, CustomPawn target, bool removeable) { cursor += ContentPadding.y; Vector2 relationshipBoxSize = SizeRelation; if (scrollView.ScrollbarsVisible) { relationshipBoxSize.x -= ScrollView.ScrollbarSize; } Rect relationshipBox = new Rect(ContentPadding.x, cursor, relationshipBoxSize.x, relationshipBoxSize.y); // Draw background box. GUI.color = BackgroundBoxColor; GUI.DrawTexture(relationshipBox, BaseContent.WhiteTex); GUI.BeginGroup(relationshipBox); // Draw pawn name. GUI.color = Page_ConfigureStartingPawnsCarefully.TextColor; Widgets.Label(new Rect(8, 6, relationshipBoxSize.x - 16, 24), target.Pawn.NameStringShort); // Draw relationship field. Rect fieldRect = new Rect(16, 30, relationshipBoxSize.x - 32, 28); GUI.color = Color.white; Widgets.DrawAtlas(fieldRect, Textures.TextureFieldAtlas); // TODO: Move this color to another file like we did with the textures. GUI.color = Page_ConfigureStartingPawnsCarefully.TextColor; if (def != null) { Widgets.Label(new Rect(fieldRect.x, fieldRect.y + 1, fieldRect.width, fieldRect.height), def.GetGenderSpecificLabelCap(target.Pawn)); } // Delete relation Rect buttonRect = new Rect(relationshipBoxSize.x - 21, 3, 18, 18); GUI.color = buttonRect.Contains(Event.current.mousePosition) ? Page_ConfigureStartingPawnsCarefully.ButtonHighlightColor : Page_ConfigureStartingPawnsCarefully.ButtonColor; if (removeable) { GUI.DrawTexture(buttonRect, Textures.TextureButtonDelete); if (Widgets.ButtonInvisible(buttonRect, false)) { SoundDefOf.TickTiny.PlayOneShotOnCamera(); PrepareCarefully.Instance.RelationshipManager.DeleteRelationship(def, source, target); } } else { GUI.DrawTexture(buttonRect, Textures.TextureDerivedRelationship); TooltipHandler.TipRegion(buttonRect, "EdB.PrepareCarefully.CannotDeleteRelationship".Translate()); } GUI.color = Color.white; GUI.EndGroup(); return(cursor + relationshipBoxSize.y); }
public void DeleteRelationship(PawnRelationDef def, CustomPawn source, CustomPawn target) { CustomRelationship toRemove = relationships.Find(def, source, target); if (toRemove != null) { deletionList.Add(toRemove); } dirty = true; }
public static bool VisibleInTab(this PawnRelationDef relation) { if (relation == null) { return(false); } return(relation.opinionOffset > OPINION_THRESHOLD_POS / 2f || relation.opinionOffset < OPINION_THRESHOLD_NEG / 2f); }
public static void GRIsExLovePartnerRelation(ref bool __result, PawnRelationDef relation) { if (__result != true) { if (relation == PawnRelationDefOfGR.ExLovefriend) { __result = true; } } }