Class Relationship
- Namespace
- TinyLife
- Assembly
- TinyLife.dll
A relationship is a connection between two PersonLike objects. It should be noted that a relationship is not always the same between a person and the linked OtherPerson. What this means is that A can have a good relationship to B, but B can have a less good relationship to A.
[DataContract]
public class Relationship : JsonTypeSafeGenericDataHolder, IGenericDataHolder
- Inheritance
-
JsonTypeSafeGenericDataHolderRelationship
- Implements
-
IGenericDataHolder
- Inherited Members
-
JsonTypeSafeGenericDataHolder.GetDataKeys()
- Extension Methods
Fields
Dating
This value is set to true if this relationship is a romantic relationship
[DataMember]
public bool Dating
Field Value
KnownJobType
Stores the Types registry name of the job type that this relationship's person currently knows about the relationship's Partner. If this is null, no job type is known. If this value is set to None, the Partner has no job.
[DataMember]
public string KnownJobType
Field Value
KnownPersonalityTypes
A set of PersonalityType objects that are known about this relationship's OtherPerson. This collection is populated by AskAboutPersonality.
[DataMember]
public readonly HashSet<PersonalityType> KnownPersonalityTypes
Field Value
Max
The maximum value that a relationship level can have
public const float Max = 100000
Field Value
Migrations
A set of migrations that will be applied when a Relationship is validated, specifically in Validate(PersonLike, AppliedMigrations). Mods can add their own migrations to this list. Non-silent migrations, as well as Early and Late migration phases, are supported.
public static readonly List<Migration<Relationship>> Migrations
Field Value
PassiveFriendReduction
The amount of points (out of Max) that are removed from each relationship's FriendLevel each update frame
public const float PassiveFriendReduction = 0.01
Field Value
PassiveRomanceReduction
The amount of points (out of Max) that are removed from each relationship's RomanceLevel each update frame
public const float PassiveRomanceReduction = 0.015
Field Value
TryingForBaby
Stores whether the people involved in this relationship have agreed to try for a baby. If this is true, fooling around has a chance to lead to a pregnancy.
[DataMember(EmitDefaultValue = false)]
public bool TryingForBaby
Field Value
Properties
FriendDisplayString
An (unlocalized) string that represents a written version of this relationship's Type status.
public string FriendDisplayString { get; }
Property Value
FriendLevel
The current amount of friendship points (out of Max) that this relationship has. This value is automatically clamped between -Max and Max. To take skills, personalities and more into account, use ChangeFriendship(PersonLike, float, bool).
public float FriendLevel { get; set; }
Property Value
FriendPercentage
The FriendLevel of this relationship, divided by Max, yielding a percentage between -1 and 1 of how good this friendship is
public float FriendPercentage { get; }
Property Value
Genealogy
The GenealogyType of this relationship. Note that the genealogy's value works in the following direction: "I am the [Genealogy] of [OtherPerson]". Note that OtherPerson will always have the GenealogyType's GetOpposite(GenealogyType).
[DataMember]
public GenealogyType Genealogy { get; }
Property Value
OtherPerson
The Guid of the person that this relationship is linked to. To easily retrieve the matching PersonLike instance, see Partner or the more customizable GetPartner(bool).
[DataMember]
public Guid OtherPerson { get; }
Property Value
Partner
Returns an instance of the OtherPerson that this relationship is linked to.
Internally, this property calls the GetPartner(bool) method with the includeDeadPeople parameter set to false.
If a potentially dead partner that isn't currently on the map should be included, use GetPartner(bool).
public PersonLike Partner { get; }
Property Value
Person
The person that this relationship is linked to.
public PersonLike Person { get; }
Property Value
RomanceDisplayString
An (unlocalized) string that represents a written version of this relationship's RomanceType status.
public string RomanceDisplayString { get; }
Property Value
RomanceLevel
The current amount of romance points (out of Max) that this relationship has. This value is automatically clamped between 0 and Max. To take skills, personalities and more into account, use ChangeRomance(PersonLike, float, bool). Note that, for aromantic people, getting and setting this value always gets and sets FriendLevel instead.
public float RomanceLevel { get; set; }
Property Value
RomancePercentage
The RomanceLevel of this relationship, divided by Max, yielding a percentage between 0 and 1 of how good this relationship's romance level is
public float RomancePercentage { get; }
Property Value
RomanceType
The RomanceType that this relationship has, based on the current RomanceLevel.
public RomanceType RomanceType { get; set; }
Property Value
Type
The RelationshipType that this relationship has, based on the current FriendLevel.
public RelationshipType Type { get; set; }
Property Value
Methods
AddMemory<T>(MemoryType, bool, int, TimeSpan?)
Adds a Memory to this relationship's person's and OtherPerson's Memories list of this person.
public T AddMemory<T>(MemoryType type, bool addToBoth, int toKeep = 0, TimeSpan? timeOccured = null) where T : Memory
Parameters
typeMemoryTypeThe type of memory to add.
addToBothboolWhether the memory should be added to the OtherPerson as well.
toKeepintAn amount of memories of the given
typeto keep, also counting the newly added one. Oldest memories will be removed first.timeOccuredTimeSpan?
Returns
- T
The added memory.
Type Parameters
T
CreateBars(Anchor, PersonLike, Relationship, Vector2, float, bool)
Creates a MLEM.Ui.Elements.Group with two MLEM.Ui.Elements.ProgressBar elements in it that represent the friendship and romance levels of the given relationship.
public static Group CreateBars(Anchor anchor, PersonLike person, Relationship relationship, Vector2 size, float barHeight = 10, bool showText = true)
Parameters
anchorAnchorThe anchor to use.
personPersonLikeThe person who has the
relationship.relationshipRelationshipThe relationship. May be null.
sizeVector2The MLEM.Ui.Elements.Element.Size that the MLEM.Ui.Elements.Group should have.
barHeightfloatThe height of the bars.
showTextboolWhether the relationship type should be displayed as text in the bars.
Returns
- Group
The group containing the bars.
CreatePanel(PersonLike, PersonLike, Relationship, Vector2)
Creates a MLEM.Ui.Elements.Group with a MLEM.Ui.Elements.Panel in it that contains information about the given relationship.
This method also calls OnRelationshipPanel.
public static Group CreatePanel(PersonLike person, PersonLike otherPerson, Relationship relationship, Vector2 size)
Parameters
personPersonLikeThe person who has the
relationship.otherPersonPersonLikeThe partner of the
relationship.relationshipRelationshipThe relationship. May be null.
sizeVector2The MLEM.Ui.Elements.Element.Size that the MLEM.Ui.Elements.Panel should have.
Returns
- Group
A MLEM.Ui.Elements.Group that contains the MLEM.Ui.Elements.Panel created.
GetMemories<T>(MemoryType, bool)
Returns all Memory instances that this relationship's person and OtherPerson currently track that match the given MemoryType.
public IEnumerable<T> GetMemories<T>(MemoryType type, bool returnBoth) where T : Memory
Parameters
typeMemoryTypeThe memory type to match.
returnBothboolWhether the OtherPerson's memories should also be returned.
Returns
- IEnumerable<T>
The memories of the given type.
Type Parameters
T
GetPartner(bool)
Returns an instance of the OtherPerson that this relationship is linked to.
Note that the Partner property calls this method internally, with the includeDeadPeople parameter set to false.
public PersonLike GetPartner(bool includeDeadPeople)
Parameters
includeDeadPeopleboolWhether any dead people, that is, people returned as part of GetStoredDeadPeople(), should also be searched for a matching person.
Returns
- PersonLike
This relationship's partner, or null if they can't be found.
GetSocialEffectiveness(ActionType)
Returns the effectiveness percentage that the given ActionType has right now, based on the amount of times that it has been used previously. In TalkAction, this effectiveness is used to reduce the friendship and romance gain based on the "boringness" of an action. Note that, if this relationship's main person is younger than a Child, the social effectiveness will always be 1.
public float GetSocialEffectiveness(ActionType action)
Parameters
actionActionTypeThe action whose effectiveness to query
Returns
- float
The social effectiveness, which is a percentage between 0 and 1
GetTimeSinceMemory<T>(MemoryType, bool, Func<T, bool>)
Returns the time since a memory of the given MemoryType has occured in this relationship's main person or OtherPerson. If there are multiple memories of the given type, the minimum time is returned. If there is no memory of the given type, null is returned.
public TimeSpan? GetTimeSinceMemory<T>(MemoryType type, bool includeBoth, Func<T, bool> condition = null) where T : Memory
Parameters
typeMemoryTypeThe memory type to query.
includeBothboolWhether the OtherPerson's memories should be included in the search.
conditionFunc<T, bool>An additional condition to determine whether memories should be included in the search.
Returns
- TimeSpan?
The time since the given memory type.
Type Parameters
T
PopulateTooltip(PersonLike, PersonLike, Relationship, Tooltip)
Populates the given tooltip with information about the given relationship.
This method also takes the OnRelationshipTooltip event into account.
public static void PopulateTooltip(PersonLike person, PersonLike otherPerson, Relationship relationship, Tooltip tooltip)
Parameters
personPersonLikeThe person who has the
relationship.otherPersonPersonLikeThe partner of the
relationship.relationshipRelationshipThe relationship. May be null.
tooltipTooltipThe tooltip to populate.
RemoveMemory<T>(MemoryType, bool, int, Func<T, bool>)
Removes all Memory instances of the given type T and MemoryType from this relationship's person's and OtherPerson's Memories collections, and returns the amount of memories removed.
public int RemoveMemory<T>(MemoryType type, bool removeFromBoth, int toKeep = 0, Func<T, bool> condition = null) where T : Memory
Parameters
typeMemoryTypeThe memory type to match.
removeFromBothboolWether the OtherPerson's memories should also be removed.
toKeepintAn amount of memories of the given
typeto keep. Oldest memories will be removed first.conditionFunc<T, bool>An additional condition to determine whether memories should be included in the search.
Returns
- int
How many memories were removed.
Type Parameters
T
ResetToStatic(bool, bool)
Resets this relationship to a more basic, static version. This method is used when a map or household is exported, and by the ExportHousehold cheat.
public void ResetToStatic(bool thorough, bool sameHousehold)
Parameters
thoroughboolWhether the relationship should be reset thoroughly, causing the friendship level and romance level to be averaged out
sameHouseholdboolWhether the two people that are part of this relationship are in the same household
SetGenealogy(GenealogyType, bool, Action<PersonLike, Relationship, GenealogyType>, ICollection<PersonLike>)
Sets this relationship's Genealogy and this Partner's relationship's Genealogy, additionally updating all transitive relationships' genealogies using GetTransitive(GenealogyType, GenealogyType).
public void SetGenealogy(GenealogyType genealogy, bool overwriteExistingTransitive, Action<PersonLike, Relationship, GenealogyType> onGenealogyChanged = null, ICollection<PersonLike> possibleAdditionalPeople = null)
Parameters
genealogyGenealogyTypeThe genealogy to use for this relationship.
overwriteExistingTransitiveboolWhether the genealogies of existing transitive relationships should be updated, even if they are already set to a non-Unrelated relationship or have romantic involvement.
onGenealogyChangedAction<PersonLike, Relationship, GenealogyType>An action that is invoked when a genealogy is changed, which is additionally passed to recursive calls of this method.
possibleAdditionalPeopleICollection<PersonLike>A set of additional people that can optionally be considered as this relationship's or subsequent recursive calls' relationships' partners, in addition to the Partner and subsequent recursive calls' partners, which may not currently be present on the map.
Validate(PersonLike, AppliedMigrations)
Validates this relationship, setting its internal person reference to the given PersonLike. This method is automatically called for all of their relationships in Validate(AppliedMigrations).
public bool Validate(PersonLike person, AppliedMigrations appliedMigrations)
Parameters
personPersonLikeThe person that this relationship belongs to
appliedMigrationsAppliedMigrationsThe migrations to use when validating this relationship.
Returns
Events
OnRelationshipPanel
An event that is raised when a relationship panel is created in CreatePanel(PersonLike, PersonLike, Relationship, Vector2). Use this event to add custom information to a relationship panel.
public static event Action<(PersonLike Person, PersonLike Other, Relationship Relationship, Group Group)> OnRelationshipPanel
Event Type
- Action<(PersonLike Person, PersonLike Other, Relationship Relationship, Group Group)>
OnRelationshipTooltip
An event that is raised when a relationship tooltip is populated in PopulateTooltip(PersonLike, PersonLike, Relationship, Tooltip). Use this event to add custom information to a relationship tooltip.
public static event Action<(PersonLike Person, PersonLike Other, Relationship Relationship, Tooltip Tooltip)> OnRelationshipTooltip
Event Type
- Action<(PersonLike Person, PersonLike Other, Relationship Relationship, Tooltip Tooltip)>