Class MapObject
An instance of this class represents an object that can be, or is, part of a Map.
[DataContract]
public class MapObject : JsonTypeSafeGenericDataHolder, IGenericDataHolder
- Inheritance
-
JsonTypeSafeGenericDataHolderMapObject
- 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
GuidThe object's id
map
MapThe map the object should be on
position
Vector2The position that the object should have
floor
floatThe floor that this map object is on.
Properties
CurrentLot
public Lot CurrentLot { get; }
Property Value
CurrentRoom
public Room CurrentRoom { get; }
Property Value
Floor
The floor that this map object is on.
[DataMember]
public float Floor { get; set; }
Property Value
HoldingPerson
The person that is currently holding this object. If no person is currently holding this object, this property returns null.
public PersonLike HoldingPerson { get; }
Property Value
Id
The Guid of this object instance
[DataMember]
public Guid Id { get; protected set; }
Property Value
IsInWorld
A property that returns true if this object is currently present on a Map
public bool IsInWorld { get; }
Property Value
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
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
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
ActionThe action
time
GameTimeThe current game time
passedInGame
TimeSpanThe amount of time that has passed, in game time
speedMultiplier
floatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
isAuxiliary
boolWhether this object counts as an auxiliary object. If this value is false, the object is th eGetActionObject<T>(bool)
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
ActionTypeThe action that is querying whether it can be executed.
info
ActionInfoThe action info.
automatic
boolWhether the action was started automatically.
isAuxiliary
boolWhether 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
GameTimeThe current time
batch
objectThe 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
boolWhether 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
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
Returns
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
GameTimeThe current time
batch
objectThe sprite batch to use for drawing, which is either a Microsoft.Xna.Framework.Graphics.SpriteBatch or MLEM.Graphics.StaticSpriteBatch.
drawPos
Vector2The 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, Vector2, 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, Vector2 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
MapThe map that the object is on
position
Vector2The position that the object is on, in world space
floor
floatThe floor to draw on.
batch
objectThe sprite batch to draw with, which is either a Microsoft.Xna.Framework.Graphics.SpriteBatch or MLEM.Graphics.StaticSpriteBatch.
drawPos
Vector2The position to draw at, in draw space
texture
TextureRegionThe texture region to draw
color
ColorThe color to draw with
scale
Vector2The scale to draw at
size
PointThe 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
boolThe texture's pivot point, in texture-space pixels
parent
ParentInfoThe object's parent object
depthOffset
floatA value that is added to the calculated object's depth
effects
SpriteEffectsThe sprite effects to use when rendering
editDrawPos
boolWhether this object's
drawPos
should be changed based on this object's circumstances, especially based on itsparent
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 virtual 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.
GetAiPriority(PersonLike, 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(PersonLike person, ObjectCategory categories)
Parameters
person
PersonLikeThe person whose AI is attempting to interact with this object
categories
ObjectCategoryThe categories that are relevant for the ai interaction
Returns
- float
This object's priority
GetCategories(PersonLike)
Returns a set of ObjectCategory flags that this object has, based on the given PersonLike.
public virtual ObjectCategory GetCategories(PersonLike person)
Parameters
person
PersonLikeThe 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
GetEfficiencyModifier(PersonLike, 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(PersonLike person, ActionInfo info, bool isAuxiliary, SkillType skill, float levelModifier)
Parameters
person
PersonLikeThe person whose efficiency should be influenced
info
ActionInfoThe action info
isAuxiliary
boolWhether this object is auxiliary (or the main action object)
skill
SkillTypeThe skill that should influence the efficiency
levelModifier
floatThe level modifier for the
skill
Returns
- float
The efficiency modifier for this object
GetFreeActionSpotInfo(PersonLike, ObjectCategory)
Returns the first entry of a set of ActionInfo instances that represent action spots that the person
can currently use or interact with.
By default, an empty collection is returned by MapObject, but relevant spots are returnd by objects like Furniture and PersonLike.
public ActionInfo GetFreeActionSpotInfo(PersonLike person, ObjectCategory context = null)
Parameters
person
PersonLikeThe person who wants to interact with this object.
context
ObjectCategoryThe context for which to return free action spots, or null to return action spots for any contexts.
Returns
- ActionInfo
The first free action spot, or null if there are none.
GetFreeActionSpotInfos(PersonLike, ObjectCategory)
Returns a set of ActionInfo instances that represent action spots that the person
can currently use or interact with.
By default, an empty collection is returned by MapObject, but relevant spots are returnd by objects like Furniture and PersonLike.
public virtual IEnumerable<ActionInfo> GetFreeActionSpotInfos(PersonLike person, ObjectCategory context = null)
Parameters
person
PersonLikeThe person who wants to interact with this object.
context
ObjectCategoryThe context for which to return free action spots, or null to return action spots for any contexts.
Returns
- IEnumerable<ActionInfo>
The free action spots.
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 virtual void GetHoverInfo(Tooltip tooltip)
Parameters
tooltip
TooltipThe 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
stringThe 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
PointThe position whose path cost modifier is being calculated.
Returns
- float
This object's path cost modifier for the given
position
GetRestoreNeedModifier(PersonLike, 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(PersonLike person, ActionInfo info, bool isAuxiliary, NeedType type)
Parameters
person
PersonLikeThe person whose need restoration should be influenced.
info
ActionInfoThe action info.
isAuxiliary
boolWhether this object is auxiliary (or the main action object).
type
NeedTypeThe type of need that is being restored.
Returns
- float
The need restoration modifier for this object.
HasCategory(PersonLike, ObjectCategory)
A shorthand that checks whether GetCategories(PersonLike) overlaps with the given category
flags
public bool HasCategory(PersonLike person, ObjectCategory category)
Parameters
person
PersonLikeThe person to query categories for
category
ObjectCategoryA 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
RectangleFThe area that should be checked for
Returns
- bool
true if this object intersects with the given rectangle
IsFreeSpot(Point)
Returns whether a PersonLike 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
PointThe position whose path cost modifier is being calculated.
Returns
- bool
Whether a PersonLike 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
ActionTypeThe action type.
info
ActionInfoThe action info.
isAuxiliary
boolWhether 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.
This method also removes the object from the current map if it IsInWorld and adds it to the new map
, but only if its current Map is not already equal to map
, in which case, no action is performed.
public virtual bool MoveToMap(Map map, Vector2? position = null, float? floor = null)
Parameters
map
MapThe map to move to.
position
Vector2?The position on the new map to move to, or null to keep it the same.
floor
float?The floor to move to, or null to keep it the same.
Returns
- bool
Whether moving to the map was successful, which is false if this object's Map is already the given
map
. If true is returned, the object is guaranteed to have been added to the newmap
using AddObject(MapObject). If false is returned, no action was performed.
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
ActionThe action
type
CompletionTypeThe type of the action's completion
isAuxiliary
boolWhether 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
Direction2The old camera rotation
newRotation
Direction2The 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
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
Vector2This object's previous position.
lastFloor
floatThis object's previous floor.
OnRandomQuality(PersonLike, 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(PersonLike, Random, ActionInfo, bool, IEmotionSource, bool). This method is invoked for all GetInvolvedObjects<T>(ObjectCategory, bool, bool) of the passed ActionInfo.
public virtual void OnRandomQuality(PersonLike person, ActionInfo info, bool isAuxiliary, SkillType skill, Random random, bool alwaysAllowAverage, Dictionary<Quality, float> weights)
Parameters
person
PersonLikeThe person.
info
ActionInfoThe action info.
isAuxiliary
boolWhether this object is auxiliary (or the main action object).
skill
SkillTypeThe skill.
random
RandomThe Random instance used for determining the quality.
alwaysAllowAverage
boolWhether 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
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.
SetMapAndValidate(Map, AppliedMigrations)
Shorthand method for setting this object's Map and then calling ValidateEarly() and Validate(AppliedMigrations). 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, AppliedMigrations appliedMigrations)
Parameters
map
MapThe map to set
appliedMigrations
AppliedMigrationsThe set of migrations that have already been applied.
Returns
- bool
false if the object is not valid, true otherwise
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 virtual bool Validate(AppliedMigrations appliedMigrations)
Parameters
appliedMigrations
AppliedMigrations
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(AppliedMigrations) 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
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
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(AppliedMigrations) method.
public static event Action<MapObject> OnEventsAttachable
Event Type
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
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
OnValidated
An event that is invoked when a map object is validated. This event is invoked in Validate(AppliedMigrations), which is usually called after subclass validation.
public static event Action<MapObject> OnValidated
Event Type
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