Class Person
Represents a human person, known in the game as a Tiny. This class extends PersonLike, but stores additional human-specific information, like Projects, Jobs, Pronouns, and more.
public class Person : PersonLike, IGenericDataHolder, IUpdatingObject
- Inheritance
-
JsonTypeSafeGenericDataHolderPerson
- Implements
-
IGenericDataHolder
- Inherited Members
-
JsonTypeSafeGenericDataHolder.GetDataKeys()
- Extension Methods
Constructors
Person(Map, Vector2, float)
Creates a new person with the given settings. To create a new person externally, use Create(Map, Random, AgeGroup, bool, bool, bool, bool, PersonLike[]).
[JsonConstructor]
protected Person(Map map, Vector2 position, float floor)
Parameters
Fields
AgeTextures
The textures that are used for each AgeGroup. The key is the AgeGroup, and the value is the texture name.
public static readonly Dictionary<AgeGroup, string> AgeTextures
Field Value
DiaperDirty
Whether this person's diaper is dirty.
[DataMember(EmitDefaultValue = false)]
public bool DiaperDirty
Field Value
Jobs
The jobs that this person currently has. Currently, multiple jobs are supported in-game, but not properly enforced, meaning if a person has multiple jobs whose work hours overlap, unexpected behaviors might occur. To modify this collection, please use AddJob(JobType, int) and RemoveJob(JobType) to raise the proper events.
[DataMember]
public readonly List<Job> Jobs
Field Value
LastBedSleptIn
[DataMember(EmitDefaultValue = false)]
public Guid LastBedSleptIn
Field Value
LotEmployment
The LotEmployment.Instance that this person works in. If this value is non-null, it implicitly means that this person does not have a HomeLot or Household that they are a part of.
[DataMember(EmitDefaultValue = false)]
public LotEmployment.Instance LotEmployment
Field Value
PhoneColors
This person's mobile phone colors.
[DataMember]
public int[] PhoneColors
Field Value
- int[]
Projects
The Project instances that this person currently has. Use StartProject(Project), GetProject(string, string), GetProjects(string) and Remove() to modify this collection effectively.
[DataMember]
public readonly List<Project> Projects
Field Value
Pronouns
This person's pronouns.
[DataMember]
public string Pronouns
Field Value
Properties
CurrentRoomDecorativeRating
The decorative rating of the CurrentRoom, resulting from the DecorativeRating of the contained furniture
public int CurrentRoomDecorativeRating { get; }
Property Value
DrawSize
The size, in draw space pixels, that a person's texture takes up.
public override Point DrawSize { get; }
Property Value
- Point
FullNamePronouns
This person's full name and pronouns, which is a concatenation of their FullName, and their pronouns in parentheses for Person types.
public override string FullNamePronouns { get; }
Property Value
IsRegularVisitor
A property that computes whether this person is a regular visitor. A person is considered a regular visitor if they have no Household, but also have no LotEmployment, and are not dead (IsDead).
public override bool IsRegularVisitor { get; }
Property Value
LifeGoal
This person's current LifeGoal.Instance
public LifeGoal.Instance LifeGoal { get; set; }
Property Value
Methods
AddJob(JobType, int)
Adds an instance of the given JobType to this person's list of Jobs and raises the OnJobChanged event.
public virtual bool AddJob(JobType type, int level = 0)
Parameters
Returns
- bool
Whether the job could be added. If this is false, then this person already has a job of the given
type
.
CanExecuteAction(ActionType, ActionInfo, bool)
Returns the given action type
's CanExecute delegate's result and also checks additional conditions like RequiredSkill, RequiredEmotion, CanExecuteAction and CanExecuteAction(ActionType, ActionInfo, bool, bool).
This method additionally catches and handles any exceptions by printing them out as a Notifications notification to the player.
public override CanExecuteResult CanExecuteAction(ActionType type, ActionInfo info, bool automatic)
Parameters
type
ActionTypeThe action to execute.
info
ActionInfoThe action info
automatic
boolWhether the action is automatically executed
Returns
- CanExecuteResult
A CanExecuteResult that represents whether the action can be executed right now
Create(Map, Random, AgeGroup, bool, bool, bool, bool, PersonLike[])
Creates a new person with the given settings, optionally randomly generating the returned person's FirstName, LastName, Age, Outfits and more.
public static Person Create(Map map, Random random, AgeGroup allowedAges = (AgeGroup)-1, bool markRandomlyGenerated = true, bool initializeName = true, bool initializePersonality = true, bool generateOutfits = true, PersonLike[] geneticInfluences = null)
Parameters
map
MapThe map to create the person for.
random
RandomThe Random instance to use for generating the person.
allowedAges
AgeGroupA set of AgeGroup flags that the person is allowed to have.
markRandomlyGenerated
boolWhether to mark the person as RandomlyGenerated.
initializeName
boolWhether to initialize the person's FirstName, LastName and Pronouns.
initializePersonality
boolWhether to initialize the person's PersonalityTypes.
generateOutfits
boolWhether to generate fitting outfits beyond the required default everyday one.
geneticInfluences
PersonLike[]A set of people that count as genetic influences, from which hair, eye and skin colors will randomly be chosen.
Returns
- Person
The generated person.
DrawIcon(Element, GameTime, SpriteBatch)
Draws this object as an icon in UI space. This method is called by the action queue as well as for notifications. By default, people draw their Portrait, and Furniture draws itself in ui space.
public override bool DrawIcon(Element element, GameTime time, SpriteBatch batch)
Parameters
element
ElementThe element to draw the object in.
time
GameTimeThe game time.
batch
SpriteBatchThe sprite batch to use for drawing.
Returns
- bool
Whether the object was actually drawn as an icon. If false is returned, a replacement icon can be drawn by the caller instead.
DrawLooksLayer(SpriteBatch, SpriteAnimation, TextureRegion, WornClothes, int, Vector2, Vector2, float, ParentInfo, Color, float, float)
Draws the given layer of this person's looks in the world. This method is invoked several times in DrawLooks(SpriteBatch, Vector2, Vector2, float, ParentInfo, Color?, float).
protected override void DrawLooksLayer(SpriteBatch batch, SpriteAnimation animation, TextureRegion region, WornClothes clothes, int layerIndex, Vector2 drawPos, Vector2 depthPos, float floor, ParentInfo parent, Color color, float scale, float depthOffset)
Parameters
batch
SpriteBatchThe sprite batch to use for drawing.
animation
SpriteAnimationThe animation to draw.
region
TextureRegionThe texture region of the
animation
to draw.clothes
WornClothesThe clothes to draw.
layerIndex
intThe index that this layer is on.
drawPos
Vector2The draw position in screen space.
depthPos
Vector2The position to use for calculating depth.
floor
floatThe floor to draw on.
parent
ParentInfoThis person's parent info.
color
ColorThe color to draw with.
scale
floatThe scale to draw with.
depthOffset
floatThe depth offset to draw with.
DrawUi(SpriteBatch, Vector2, float, Direction2, Outfit, Pose?, AgeGroup?)
Renders this person on a ui level rather than a world level
public override void DrawUi(SpriteBatch batch, Vector2 pos, float scale, Direction2 rotation = Direction2.Right, Outfit outfit = null, Pose? pose = null, AgeGroup? age = null)
Parameters
batch
SpriteBatchThe sprite batch to use for drawing
pos
Vector2The position, in screen space, to draw at
scale
floatThe scale to draw with
rotation
Direction2The rotation that this person should be drawn with. Defaults to MLEM.Maths.Direction2.Right.
outfit
OutfitThe outfit to draw with, which defaults to this person's CurrentOutfit.
pose
Pose?The pose to draw with, which defaults to this person's CurrentPose.
age
AgeGroup?The age to draw with, which defaults to this person's Age.
GenerateAnimationGroup(ClothesLayer, int, IReadOnlyDictionary<Point, TextureRegion>, Point)
Generates a MLEM.Animations.SpriteAnimationGroup for the given settings. This method is called when a person's Animations are generated, for each clothes layer.
protected override SpriteAnimationGroup GenerateAnimationGroup(ClothesLayer clothesLayer, int layerAmount, IReadOnlyDictionary<Point, TextureRegion> textures, Point textureRegion)
Parameters
clothesLayer
ClothesLayerThe clothes layer.
layerAmount
intThe amount of layers the clothing item has.
textures
IReadOnlyDictionary<Point, TextureRegion>The textures to use.
textureRegion
PointThe initial texture region to use.
Returns
- SpriteAnimationGroup
The generated MLEM.Animations.SpriteAnimationGroup.
GenerateShadowAnimation()
Generates a MLEM.Animations.SpriteAnimationGroup for this person's shadow. This method is called when a person's Animations are generated.
protected override SpriteAnimationGroup GenerateShadowAnimation()
Returns
- SpriteAnimationGroup
The generated MLEM.Animations.SpriteAnimationGroup.
GetAiPriorityForObject(MapObject, ObjectCategory)
Returns the AI priority for the given obj
and the given categories
.
This method checks the GetAiPriority(PersonLike, ObjectCategory) method, as well as any LotEmployment-speciifc AI priorities, and invokes the OnGetAiPriorityForObject event.
public override float GetAiPriorityForObject(MapObject obj, ObjectCategory categories)
Parameters
obj
MapObjectThe object.
categories
ObjectCategoryThe categories.
Returns
- float
The AI priority for the object.
GetCurrentGoals()
Returns a set of GoalSet objects that this person is currently working on. To add more current goals, use OnGetCurrentGoals.
public override List<IGoalTriggerable> GetCurrentGoals()
Returns
- List<IGoalTriggerable>
This person's current goals
GetHeldItemDrawOffset(bool)
Returns this person's held item's draw offset, which is used by ParentInfo for drawing.
public override Vector2 GetHeldItemDrawOffset(bool includeItemOffsets)
Parameters
includeItemOffsets
bool
Returns
- Vector2
This person's held item's draw offset.
GetHoverInfo(Tooltip)
Allows adding a set of paragraphs and other ui elements to the given tooltip
, which is then displayed when this object is hovered over using the cursor in the world.
By default, this method raises OnGetHoverInfo for MapObject, and adds additional information for Furniture and PersonLike.
public override void GetHoverInfo(Tooltip tooltip)
Parameters
tooltip
TooltipThe tooltip that will be displayed.
GetPassiveActionPriority(ActionType)
Returns the passive priority for the given ActionType. This method evaluates the action's own PassivePriority and adds additional factors like Extroverted and Introverted modifiers for social actions. You can use OnGetPassiveActionPriority to change the return value of this method.
public override float GetPassiveActionPriority(ActionType type)
Parameters
type
ActionTypeThe type of action to get the passive priority for
Returns
- float
The action's passive priority
GetPassiveNeedReduction(NeedType)
Returns the given need's current passive reduction for this person. The return value is a combination of PassiveReduction and the OnGetPassiveNeedReduction event, as well as PersonalityType modifiers and the like.
public override float GetPassiveNeedReduction(NeedType need)
Parameters
need
NeedTypeThe need.
Returns
- float
The passive need reduction.
GetPivot()
Returns this person's screen-space pivot position, based on the current animation frame.
public override Vector2 GetPivot()
Returns
- Vector2
This person's screen-space pivot position.
GetProject(string, string)
public Project GetProject(string type, string name)
Parameters
Returns
- Project
The matching project, or null if there is none
GetProjects(string)
Returns all of the projects of the given Type that this person has. To access all projects regardless of type, iterate the Projects list instead.
public IEnumerable<Project> GetProjects(string type)
Parameters
Returns
- IEnumerable<Project>
A set of projects that match the given type
GoToExitRoad(Vector2)
Teleports this person to the nearest exit road using GetClosestFreeExitPoint(Vector2).
public override void GoToExitRoad(Vector2 closestPosition)
Parameters
closestPosition
Vector2
OnAgeChanged(AgeGroup)
A method that is called by Age.set when this person's Age has just changed. Their previous age is stored in lastAge
.
protected override void OnAgeChanged(AgeGroup lastAge)
Parameters
lastAge
AgeGroupThis person's previous age.
OnRoomCheck()
A method that is invoked in Update(GameTime, TimeSpan, float) when the timer to check information about the CurrentRoom has elapsed in Update(GameTime, TimeSpan, float). By default, various emotion modifiers are applied based on various conditions.
protected override void OnRoomCheck()
RemoveJob(JobType)
Removes instances of the given JobType from this person's list of Jobs and raises the OnJobChanged event.
public virtual bool RemoveJob(JobType type)
Parameters
type
JobTypeThe type to remove.
Returns
- bool
Whether this person has a job of the given type.
ResetToStatic(bool, bool)
Resets this map object to a static state when the Map that is on is exported.
public override bool ResetToStatic(bool thorough, bool custom)
Parameters
thorough
boolWhether a more thorough reset is expected, which usually involves normalizing additional data and cleaning up player data entirely.
custom
boolWhether the static reset is happening in a custom context, that is, a Household being exported normally rather than through cheats, or a custom Map being exported.
Returns
- bool
Whether this object should stay on the map after the static reset. If false is returned, this object is removed.
StartProject(Project)
Starts a new project, adding it to the Projects list of this person
public virtual Project StartProject(Project project)
Parameters
project
ProjectThe project to start
Returns
- Project
The project that was passed, for chaining
Update(GameTime, TimeSpan, float)
The update method, which is called every update frame by the underlying Map, as well as additional places like the FurnitureStorage. Because of this, some actions might only want to be invoked if an object IsInWorld. To call this method while invoking all required events, use DoUpdate(GameTime, TimeSpan, float).
public override void Update(GameTime time, TimeSpan passedInGame, float speedMultiplier)
Parameters
time
GameTimeThe game's time
passedInGame
TimeSpanThe amount of time that has passed since the last call
speedMultiplier
floatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
UpdateAdditionalVisuals()
A method invoked in Update(GameTime, TimeSpan, float) near the end to update additional visuals, like spawning particles and changing the person's Tint.
protected virtual void UpdateAdditionalVisuals()
UpdateJobs(TimeSpan)
A method invoked in Update(GameTime, TimeSpan, float) to update this person's Jobs.
protected virtual void UpdateJobs(TimeSpan passedInGame)
Parameters
passedInGame
TimeSpanThe amount of time that has passed since the last call
UpdatePose()
A method invoked in Update(GameTime, TimeSpan, float) that updates this person's CurrentPose based on their held object or person.
protected override void UpdatePose()
Validate(AppliedMigrations)
This method is called when this object is loaded from disk. Returning false on this method causes the object to be removed from the map. By default, this method invokes OnValidated and OnEventsAttachable.
public override bool Validate(AppliedMigrations appliedMigrations)
Parameters
appliedMigrations
AppliedMigrations
Returns
- bool
false if the object is not valid, true otherwise
Events
OnCreate
An event that is invoked in Create(Map, Random, AgeGroup, bool, bool, bool, bool, PersonLike[]), which allows modifying the random generation of a new person.
public static event Action<(Person Person, Random Random, AgeGroup AllowedAges, bool InitializeName, bool InitializePersonality, bool GenerateOutfits, PersonLike[] GeneticInfluences, StylePreference Style, EventPhase Phase)> OnCreate
Event Type
- Action<(Person Person, Random Random, AgeGroup AllowedAges, bool InitializeName, bool InitializePersonality, bool GenerateOutfits, PersonLike[] GeneticInfluences, StylePreference Style, EventPhase Phase)>
OnDrawUi
An event that is invoked when this person is drawn in UI space using DrawUi(SpriteBatch, Vector2, float, Direction2, Outfit, Pose?, AgeGroup?). This event can be subscribed to using OnEventsAttachable.
public event Action<(SpriteBatch Batch, Vector2 Pos, float Scale, Direction2 Rotation, Outfit Outfit, Pose Pose, AgeGroup Age, EventPhase Phase)> OnDrawUi
Event Type
- Action<(SpriteBatch Batch, Vector2 Pos, float Scale, Direction2 Rotation, Outfit Outfit, Pose Pose, AgeGroup Age, EventPhase Phase)>
OnGenerateAnimationGroup
An event that is invoked when an animation group is created for this person in GenerateAnimationGroup(ClothesLayer, int, IReadOnlyDictionary<Point, TextureRegion>, Point). This event can be subscribed to using OnEventsAttachable.
public event Action<(ClothesLayer ClothesLayer, int LayerAmount, IReadOnlyDictionary<Point, TextureRegion> Textures, Point TextureRegion, SpriteAnimationGroup Group, EventPhase Phase)> OnGenerateAnimationGroup
Event Type
- Action<(ClothesLayer ClothesLayer, int LayerAmount, IReadOnlyDictionary<Point, TextureRegion> Textures, Point TextureRegion, SpriteAnimationGroup Group, EventPhase Phase)>
OnJobChanged
An event that is invoked when the Jobs collection changes. This event can be subscribed to using OnEventsAttachable.
public event Action<PersonLike> OnJobChanged
Event Type
OnLifeGoalChanged
An event that is invoked when a person's current LifeGoal is changed. This event can be subscribed to using OnEventsAttachable.
public event Action<LifeGoal.Instance> OnLifeGoalChanged