Table of Contents

Class MapObject

Namespace
TinyLife.Objects
Assembly
Tiny Life.dll

An instance of this class represents an object that can be, or is, part of a Map.

[DataContract]
public class MapObject : JsonTypeSafeGenericDataHolder, IGenericDataHolder
Inheritance
JsonTypeSafeGenericDataHolder
MapObject
Implements
IGenericDataHolder
Derived
Inherited Members
JsonTypeSafeGenericDataHolder.GetDataKeys()
Extension Methods

Constructors

MapObject(Guid, Map, Vector2, float)

Creates a new map object with the given settings

public MapObject(Guid id, Map map, Vector2 position, float floor)

Parameters

id Guid

The object's id

map Map

The map the object should be on

position Vector2

The position that the object should have

floor float

The floor that this map object is on.

Fields

PersonRotationOrder

The order of MLEM.Misc.Direction2 that the texture atlas for Person has for its textures, from left to right

public static readonly Direction2[] PersonRotationOrder

Field Value

Direction2[]

Properties

CurrentLot

A property that returns the Lot that this object is currently on, or null if there is none.

public Lot CurrentLot { get; }

Property Value

Lot

CurrentRoom

A property that returns the Room that this object is currently in, or null if there is none.

public Room CurrentRoom { get; }

Property Value

Room

Floor

The floor that this map object is on.

[DataMember]
public float Floor { get; set; }

Property Value

float

HoldingPerson

The person that is currently holding this object. If no person is currently holding this object, this property returns null.

public Person HoldingPerson { get; }

Property Value

Person

Id

The Guid of this object instance

[DataMember]
public Guid Id { get; protected set; }

Property Value

Guid

IsInWorld

A property that returns true if this object is currently present on a Map

public bool IsInWorld { get; }

Property Value

bool

Map

The map that this object is currently on. If this is null, the object is not currently on a map.

public Map Map { get; }

Property Value

Map

ParentInfo

Returns a ParentInfo for this object in its current context. By default, this method returns default, and Furniture returns a ParentInfo based on its current attachments.

public virtual ParentInfo ParentInfo { get; }

Property Value

ParentInfo

Position

The position on the Map of this object.

[DataMember]
public Vector2 Position { get; set; }

Property Value

Vector2

Visibility

Returns the visibility settings of this object. By default, WhenVisible is returned. For Furniture, its Visibility is returned instead.

public virtual Visibility Visibility { get; }

Property Value

Visibility

This object's visibility settings

Methods

ActionUpdate(Action, GameTime, TimeSpan, float, bool)

This method is called when an Action that this object is involved in updates, which is every Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime) frame. Note that this includes actions that are underlying (see Parent) and actions that aren't fully in progress yet (FullyInProgress). This object counts as involved in the action if its ActionInfo's GetInvolvedObjects<T>(ObjectCategory, bool, bool) includes this object. In general, the base method should be called for Furniture objects, since it sets deals with Dirty objects.

public virtual void ActionUpdate(Action action, GameTime time, TimeSpan passedInGame, float speedMultiplier, bool isAuxiliary)

Parameters

action Action

The action

time GameTime

The current game time

passedInGame TimeSpan

The amount of time that has passed, in game time

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

isAuxiliary bool

Whether this object counts as an auxiliary object. If this value is false, the object is th eGetActionObject<T>(bool)

CanCrossBetween(Point, Point)

Returns whether a Person should be allowed to cross between the given currPos and onto the adjacent or diagonally adjacent nextPos, with this map object presupposed to be in the way, ie covering one or two of the given positions. By default, this method returns true for all objects.

public virtual bool CanCrossBetween(Point currPos, Point nextPos)

Parameters

currPos Point

The current position.

nextPos Point

The next position.

Returns

bool

Whether crossing between the two positions is possible.

CanExecuteAction(ActionType, ActionInfo, bool, bool)

Returns whether the given action can be executed at this map object. By default, this method returns Valid for all actions, but Furniture additionally returns custom results based on whether the furniture is Broken or based on AreUtilitiesDisabled.

public virtual CanExecuteResult CanExecuteAction(ActionType action, ActionInfo info, bool automatic, bool isAuxiliary)

Parameters

action ActionType

The action that is querying whether it can be executed.

info ActionInfo

The action info.

automatic bool

Whether the action was started automatically.

isAuxiliary bool

Whether this object is auxiliary (or the main action object).

Returns

CanExecuteResult

Whether this object allows the action to be executed at it.

DoDraw(GameTime, object, Color?, bool, List<Item>)

Draws this map object, additionally invoking all required events and checking the Visibility.

public void DoDraw(GameTime time, object batch, Color? color, bool ignoreVisibility, List<StaticSpriteBatch.Item> items)

Parameters

time GameTime

The current time

batch object

The sprite batch to use for drawing, which is either a Microsoft.Xna.Framework.Graphics.SpriteBatch or MLEM.Graphics.StaticSpriteBatch.

color Color?

The color that should be used instead of this object's actual color. If null, the object's regular color should be used.

ignoreVisibility bool

Whether this object's Visibility should be ignored.

items List<StaticSpriteBatch.Item>

A list of sprite batch items that items should be added to if the batch is a MLEM.Graphics.StaticSpriteBatch.

DoUpdate(GameTime, TimeSpan, float)

Updates this map object if it is an IUpdatingObject, additionally invoking all required events.

public bool DoUpdate(GameTime time, TimeSpan passedInGame, float speedMultiplier)

Parameters

time GameTime

The game's time

passedInGame TimeSpan

The amount of time that has passed since the last call

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

Returns

bool

Draw(GameTime, object, Vector2, Color?, List<Item>)

Draws this object on the current Map, at the current Position. To draw a map object while invoking all the required events, use DoDraw(GameTime, object, Color?, bool, List<Item>).

public virtual void Draw(GameTime time, object batch, Vector2 drawPos, Color? overrideColor, List<StaticSpriteBatch.Item> items)

Parameters

time GameTime

The current time

batch object

The sprite batch to use for drawing, which is either a Microsoft.Xna.Framework.Graphics.SpriteBatch or MLEM.Graphics.StaticSpriteBatch.

drawPos Vector2

The position, in draw space, to draw this furniture at

overrideColor Color?

The color that should be used instead of this object's actual color. If null, the object's regular color should be used.

items List<StaticSpriteBatch.Item>

A list of sprite batch items that items should be added to if the batch is a MLEM.Graphics.StaticSpriteBatch.

DrawColumns(Map, Vector2, float, object, Vector2, TextureRegion, Color, float, Point, List<Item>, bool, ParentInfo, float, SpriteEffects, bool)

Draws the given texture region in multiple rows and columns based on their parent's ParentInfo.AttachmentType, which allows for depth calculation in isometric view to be possible. Bigger objects, including all furniture, are drawn in this matter. When drawing a furniture item, DrawColumns(Map, Vector2, float, object, Vector2, Direction2, TextureRegion, Color, float, List<Item>, bool, ParentInfo, float, SpriteEffects) should be used instead, which automatically supplies various values based on HasCategory(ObjectCategory).

public static void DrawColumns(Map map, Vector2 position, float floor, object batch, Vector2 drawPos, TextureRegion texture, Color color, float scale, Point size, List<StaticSpriteBatch.Item> items, bool pivot = true, ParentInfo parent = default, float depthOffset = 0, SpriteEffects effects = SpriteEffects.None, bool editDrawPos = true)

Parameters

map Map

The map that the object is on

position Vector2

The position that the object is on, in world space

floor float

The floor to draw on.

batch object

The sprite batch to draw with, which is either a Microsoft.Xna.Framework.Graphics.SpriteBatch or MLEM.Graphics.StaticSpriteBatch.

drawPos Vector2

The position to draw at, in draw space

texture TextureRegion

The texture region to draw

color Color

The color to draw with

scale float

The scale to draw at

size Point

The size, in tiles, that this object has

items List<StaticSpriteBatch.Item>

A list of sprite batch items that items should be added to if the batch is a MLEM.Graphics.StaticSpriteBatch.

pivot bool

The texture's pivot point, in texture-space pixels

parent ParentInfo

The object's parent object

depthOffset float

A value that is added to the calculated object's depth

effects SpriteEffects

The sprite effects to use when rendering

editDrawPos bool

Whether this object's drawPos should be changed based on this object's circumstances, especially based on its parent

GetAiPriority(Person, ObjectCategory)

Returns an integer that represents a priority for the PersonAi's interaction with this object. A higher priority means that this object will be picked over other objects (with lower priority). The default return value is 0, meaning that no special priority is assigned to this object. For any Furniture with the SingleBed or DoubleBed category that is the person's LastBedSleptIn, 10 is returned. This is invoked by a person in GetAiPriorityForObject(MapObject, ObjectCategory) with additional events being invoked.

public virtual float GetAiPriority(Person person, ObjectCategory categories)

Parameters

person Person

The person whose AI is attempting to interact with this object

categories ObjectCategory

The categories that are relevant for the ai interaction

Returns

float

This object's priority

GetCategories(Person)

Returns a set of ObjectCategory flags that this object has, based on the given Person.

public virtual ObjectCategory GetCategories(Person person)

Parameters

person Person

The person to query categories for

Returns

ObjectCategory

A set of categories that this object has

GetDebugLines(GameImpl, List<string>)

Returns the debug lines that should be displayed in Debug when hovering over this object. By default, OnGetDebugLines is invoked, and the id and position of this object are appended to the list of lines.

public virtual void GetDebugLines(GameImpl game, List<string> lines)

Parameters

game GameImpl

The game.

lines List<string>

The list of lines to append debug lines to.

GetEfficiencyModifier(Person, ActionInfo, bool, SkillType, float)

Returns the efficiency modifier that this object multiplies the person's productivity with. This method is automatically called in GetEfficiencyModifier(float, ActionInfo, SkillType, float). This action is invoked for all GetInvolvedObjects<T>(ObjectCategory, bool, bool) of the passed ActionInfo. By default, this method returns 1, meaning the person's efficiency will not be influenced.

public virtual float GetEfficiencyModifier(Person person, ActionInfo info, bool isAuxiliary, SkillType skill, float levelModifier)

Parameters

person Person

The person whose efficiency should be influenced

info ActionInfo

The action info

isAuxiliary bool

Whether this object is auxiliary (or the main action object)

skill SkillType

The skill that should influence the efficiency

levelModifier float

The level modifier for the skill

Returns

float

The efficiency modifier for this object

GetFreeActionSpotInfo(Person, ObjectCategory)

Returns the first free action spot, packed into an ActionInfo.

public virtual ActionInfo GetFreeActionSpotInfo(Person person, ObjectCategory context = null)

Parameters

person Person

The person to query free action spots for

context ObjectCategory

The object category that this action spot needs to have

Returns

ActionInfo

The first free action spot as an ActionInfo

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 Person.

public virtual void GetHoverInfo(Tooltip tooltip)

Parameters

tooltip Tooltip

The tooltip that will be displayed.

GetModCategory(string)

Adds and returns a custom ObjectCategory with the given name. The returned category is guaranteed to be unique and mapped to the given name. Additionally, it can be used in combined flags, as it is not a combined flag itself.

public static ObjectCategory GetModCategory(string name)

Parameters

name string

The name that the category should have

Returns

ObjectCategory

A new object category

GetPathCostModifier(Point)

Returns a modifier that indicates the "cost" for pathfinding over this object. If this object is a Furniture object, it has to have the NonColliding category for the returned value to have an effect. Note that, if this object moves, MarkDirtyForPathfinding(Point, int) should be invoked for its previous and resulting Position. By default, this method returns 0, meaning no additional pathfinding cost is added.

public virtual float GetPathCostModifier(Point position)

Parameters

position Point

The position whose path cost modifier is being calculated.

Returns

float

This object's path cost modifier for the given position

GetRestoreNeedModifier(Person, ActionInfo, bool, NeedType)

Returns the modifier that this object multiplies the person's restored need with. This method is automatically called in RestoreNeed(NeedType, float, ActionInfo, float). This action is invoked for all GetInvolvedObjects<T>(ObjectCategory, bool, bool) of the passed ActionInfo. By default, this method returns 1, meaning the need restoration modifier will not be influenced.

public virtual float GetRestoreNeedModifier(Person person, ActionInfo info, bool isAuxiliary, NeedType type)

Parameters

person Person

The person whose need restoration should be influenced.

info ActionInfo

The action info.

isAuxiliary bool

Whether this object is auxiliary (or the main action object).

type NeedType

The type of need that is being restored.

Returns

float

The need restoration modifier for this object.

HasCategory(Person, ObjectCategory)

A shorthand that checks whether GetCategories(Person) overlaps with the given category flags

public bool HasCategory(Person person, ObjectCategory category)

Parameters

person Person

The person to query categories for

category ObjectCategory

A set of categories, one of which this object needs to match

Returns

bool

Whether this object contains at least one of the given categories

Intersects(RectangleF)

Returns whether this map object intersects with the given rectangle. This is used for GetObjects<T>(RectangleF)

public virtual bool Intersects(RectangleF rectangle)

Parameters

rectangle RectangleF

The area that should be checked for

Returns

bool

true if this object intersects with the given rectangle

IsFreeSpot(Point)

Returns whether a Person should be allowed to occupy or pass the given position, which is contained in this object's intersection area (Intersects(RectangleF)). By default, Furniture objects return whether they have the NonColliding category, and all other objects return true. Note that, if this object moves, MarkDirtyForPathfinding(Point, int) should be invoked for its previous and resulting Position.

public virtual bool IsFreeSpot(Point position)

Parameters

position Point

The position whose path cost modifier is being calculated.

Returns

bool

Whether a Person can occupy the given position.

ModifyActionCategories(ActionType, ActionInfo, bool, List<string>)

A method that allows changing the Categories of an action when displaying it in the ring menu. This is used by objects like the LandlinePhone to remove the "Phone..." category if the action is not invoked on Self.

public virtual void ModifyActionCategories(ActionType type, ActionInfo info, bool isAuxiliary, List<string> categories)

Parameters

type ActionType

The action type.

info ActionInfo

The action info.

isAuxiliary bool

Whether this object is auxiliary.

categories List<string>

The categories.

MoveToMap(Map, Vector2, float)

Moves this object to the given map, changing the current Map in the process.

public virtual bool MoveToMap(Map map, Vector2 position, float floor)

Parameters

map Map

The map to move to.

position Vector2

The position on the new map to move to.

floor float

The floor to move to.

Returns

bool

Whether moving to the map was successful, which is false if this object is already on the map.

OnActionCompleted(Action, CompletionType, bool)

This method is called when an Action that this object is involved in is completed. Note that this includes actions that are underlying (see Parent). This object counts as involved in the action if its ActionInfo's GetInvolvedObjects<T>(ObjectCategory, bool, bool) includes this object. In general, the base method should be called for Furniture objects, since it sets DevaluedThroughUse.

public virtual void OnActionCompleted(Action action, CompletionType type, bool isAuxiliary)

Parameters

action Action

The action

type CompletionType

The type of the action's completion

isAuxiliary bool

Whether this object counts as an auxiliary object. If this value is false, the object is th eGetActionObject<T>(bool)

OnAdded()

This method is called when this object is added to a Map. By default, it does nothing.

public virtual void OnAdded()

OnCameraRotationChanged(Direction2, Direction2)

This method is invoked when the game's camera rotation changes. Additionally, the old and new rotations are passed.

public virtual void OnCameraRotationChanged(Direction2 oldRotation, Direction2 newRotation)

Parameters

oldRotation Direction2

The old camera rotation

newRotation Direction2

The new camera rotation

OnCurrentGameMapChanged(Map, Map)

This method is invoked when the game's CurrentMap is changed, ie when the camera is moved to a different map. For a method that is invoked when this object's Map is changed, see MoveToMap(Map, Vector2, float).

public virtual void OnCurrentGameMapChanged(Map oldMap, Map newMap)

Parameters

oldMap Map

The previous map.

newMap Map

The new map.

OnPositionChanged(Vector2, float)

A method that is automatically called when this object's Position changes. By default, this method is overriden in Furniture to call MarkDirtyForPathfinding(Vector2, float). Note that this method is also called if this object is not in the world (IsInWorld).

protected virtual void OnPositionChanged(Vector2 lastPosition, float lastFloor)

Parameters

lastPosition Vector2

This object's previous position.

lastFloor float

This object's previous floor.

OnRandomQuality(Person, ActionInfo, bool, SkillType, Random, bool, Dictionary<Quality, float>)

A method that is invoked when a random quality is determined based on an action and skill in GetRandomQuality(Person, Random, ActionInfo, bool, IEmotionSource, bool). This method is invoked for all GetInvolvedObjects<T>(ObjectCategory, bool, bool) of the passed ActionInfo.

public virtual void OnRandomQuality(Person person, ActionInfo info, bool isAuxiliary, SkillType skill, Random random, bool alwaysAllowAverage, Dictionary<Quality, float> weights)

Parameters

person Person

The person.

info ActionInfo

The action info.

isAuxiliary bool

Whether this object is auxiliary (or the main action object).

skill SkillType

The skill.

random Random

The Random instance used for determining the quality.

alwaysAllowAverage bool

Whether the Average quality should always be available as an option.

weights Dictionary<Quality, float>

The weights for each quality. This collection contains keys for all Quality values, and entries should not be removed, only modified.

OnRemoved()

This method is called when this object is removed from a Map. By default, it does nothing.

public virtual void OnRemoved()

ResetToStatic(bool, bool)

Resets this map object to a static state when the Map that is on is exported.

public virtual bool ResetToStatic(bool thorough, bool custom)

Parameters

thorough bool

Whether a more thorough reset is expected, which usually involves normalizing additional data and cleaning up player data entirely.

custom bool

Whether 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.

SetMapAndValidate(Map)

Shorthand method for setting this object's Map and then calling ValidateEarly() and Validate(). If an exception occurs while validating, the exception is caught and false is returned. If moving an already validated object to a different map is desired, MoveToMap(Map, Vector2, float) should be used instead.

public bool SetMapAndValidate(Map map)

Parameters

map Map

The map to set

Returns

bool

false if the object is not valid, true otherwise

Validate()

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 virtual bool Validate()

Returns

bool

false if the object is not valid, true otherwise

ValidateEarly()

This method is called right after this object is loaded from disk, before Validate() is called on this object and all others. By default, this method invokes OnValidatedEarly.

public virtual void ValidateEarly()

Events

OnCreated

An event that is invoked when a map object is created. This event is invoked in the MapObject constructor.

public static event Action<MapObject> OnCreated

Event Type

Action<MapObject>

OnDraw

An event that is invoked when this object is drawn, right after Draw(GameTime, object, Vector2, Color?, List<Item>) is called. This event can be subscribed to using OnEventsAttachable.

public event DrawDelegate OnDraw

Event Type

DrawDelegate

OnEventsAttachable

An event that is invoked when non-static events for an object are ready to be attached to. This event is invoked in the MapObject constructor, and in the Validate() method.

public static event Action<MapObject> OnEventsAttachable

Event Type

Action<MapObject>

OnGetDebugLines

An event that is invoked when debug lines for this object are being gathered as part of Debug. This event can be subscribed to using OnEventsAttachable.

public event Action<List<string>> OnGetDebugLines

Event Type

Action<List<string>>

OnGetHoverInfo

An event that is invoked when this object's GetHoverInfo(Tooltip) method is called. This event can be subscribed to using OnEventsAttachable.

public event Action<Tooltip> OnGetHoverInfo

Event Type

Action<Tooltip>

OnUpdate

An event that is invoked when this object is updated, right after Microsoft.Xna.Framework.IUpdateable.Update(Microsoft.Xna.Framework.GameTime) is called. Note that, if this object does not extend Microsoft.Xna.Framework.IUpdateable, this event is not invoked. This event can be subscribed to using OnEventsAttachable.

public event UpdateDelegate OnUpdate

Event Type

UpdateDelegate

OnValidated

An event that is invoked when a map object is validated. This event is invoked in Validate(), which is usually called after subclass validation.

public static event Action<MapObject> OnValidated

Event Type

Action<MapObject>

OnValidatedEarly

An event that is invoked when a map object is validated early. This event is invoked in ValidateEarly().

public static event Action<MapObject> OnValidatedEarly

Event Type

Action<MapObject>