Table of Contents

Class EntityExtensions

Namespace
RisingV.Core.Extensions
Assembly
RisingV.Core.CastleEngine.dll
public static class EntityExtensions
Inheritance
EntityExtensions
Inherited Members

Methods

AddCustomComponentData<TX>(Entity, bool)

Adds custom component data of type TX to the entity.

public static TX? AddCustomComponentData<TX>(this Entity entity, bool failIfExists = true) where TX : IEntityComponentData

Parameters

entity Entity

The entity to add the custom component data to.

failIfExists bool

If true, throws an exception if the custom component data already exists; otherwise, it will not throw.

Returns

TX

The custom component data of type TX if added successfully; otherwise, null.

Type Parameters

TX

The type of the custom component data to add, must implement IEntityComponentData.

Exceptions

AccessViolationException

Thrown if the custom component data already exists and failIfExists is true.

As<TX>(Entity, bool, params object?[]?)

Entity as aspect of type TX.

public static TX As<TX>(this Entity entity, bool strict = true, params object?[]? args) where TX : EntityAspect

Parameters

entity Entity

The entity to create the aspect for.

strict bool

If true, throws an exception if the entity does not qualify for the aspect.

args object[]

Optional arguments to pass to the aspect constructor.

Returns

TX

An instance of the aspect type TX.

Type Parameters

TX

The type of aspect to create, must implement EntityAspect.

Aspect<TX>(Entity, bool, params object?[]?)

Creates an aspect of type TX for the given entity.

public static TX Aspect<TX>(this Entity entity, bool strict = true, params object?[]? args) where TX : EntityAspect

Parameters

entity Entity

The entity to create the aspect for.

strict bool

If true, throws an exception if the entity does not qualify for the aspect.

args object[]

Optional arguments to pass to the aspect constructor.

Returns

TX

An instance of the aspect type TX.

Type Parameters

TX

The type of aspect to create, must implement EntityAspect.

CountStashedItems(Entity, PrefabGUID, bool)

Counts the number of stashed items of a specific type in an entity's stashes.

public static int CountStashedItems(this Entity entity, PrefabGUID itemGuid, bool alliedOnly = false)

Parameters

entity Entity

The entity to count stashed items for.

itemGuid PrefabGUID

The PrefabGUID of the item to count.

alliedOnly bool

If true, only counts items from stashes that are allied with the entity's team.

Returns

int

The count of stashed items matching the specified PrefabGUID.

DisplayName(Entity)

public static string DisplayName(this Entity entity)

Parameters

entity Entity

Returns

string

FetchPlayer(Entity)

Fetches the PlayerAspect for a player entity.

public static PlayerAspect? FetchPlayer(this Entity entity)

Parameters

entity Entity

The entity to fetch the PlayerAspect from.

Returns

PlayerAspect

The PlayerAspect if the entity is a player; otherwise, null.

GetAllStashItems(Entity, bool)

Gets all stash items associated with an entity.

public static IEnumerable<InventoryItemData> GetAllStashItems(this Entity entity, bool alliedOnly = false)

Parameters

entity Entity

The entity to get stash items for.

alliedOnly bool

If true, only returns items from stashes that are allied with the entity's team.

Returns

IEnumerable<InventoryItemData>

An enumerable collection of InventoryItemData representing the items in the stashes.

GetCustomComponentData<TX>(Entity)

Gets custom component data of type TX from the entity.

public static TX? GetCustomComponentData<TX>(this Entity entity) where TX : IEntityComponentData

Parameters

entity Entity

The entity to get the custom component data from.

Returns

TX

The custom component data of type TX if it exists; otherwise, null.

Type Parameters

TX

The type of the custom component data to retrieve, must implement IEntityComponentData.

GetOrCreateCustomComponentData<TX>(Entity)

Gets or creates custom component data of type TX for the entity.

public static TX? GetOrCreateCustomComponentData<TX>(this Entity entity) where TX : IEntityComponentData

Parameters

entity Entity

The entity to get or create the custom component data for.

Returns

TX

The custom component data of type TX if it exists or is created; otherwise, null.

Type Parameters

TX

The type of the custom component data to retrieve or create, must implement IEntityComponentData.

GetPrefabEntity(Entity)

Gets the PrefabGUID of an entity.

public static Entity GetPrefabEntity(this Entity entity)

Parameters

entity Entity

The entity to get the PrefabGUID from.

Returns

Entity

The PrefabGUID of the entity.

GetStashes(Entity, bool)

Gets all stashes associated with an entity.

public static IEnumerable<InventoryAspect> GetStashes(this Entity entity, bool alliedOnly = false)

Parameters

entity Entity

The entity to get stashes for.

alliedOnly bool

If true, only returns stashes that are allied with the entity's team.

Returns

IEnumerable<InventoryAspect>

An enumerable collection of InventoryAspect representing the stashes.

IsAllied(Entity, Entity)

Checks if an entity is allied with a player entity.

public static bool IsAllied(this Entity entity, Entity player)

Parameters

entity Entity

The entity to check.

player Entity

The player entity to check against.

Returns

bool

True if the entity is allied with the player; otherwise, false.

IsAspect<TAspect>(object)

Checks if an entity has a specific aspect type.

public static bool IsAspect<TAspect>(this object entity) where TAspect : IAspect

Parameters

entity object

The entity to check.

Returns

bool

True if the entity has the specified aspect; otherwise, false.

Type Parameters

TAspect

The type of aspect to check for, must implement Unity.Entities.IAspect.

IsDifferentPlayer(Entity, Entity)

Checks if two entities are different players.

public static bool IsDifferentPlayer(this Entity entity, Entity target)

Parameters

entity Entity

The first entity to compare.

target Entity

The second entity to compare.

Returns

bool

True if both entities are players and they are not the same entity; otherwise, false.

IsFollowingPlayer(Entity)

Checks if an entity is following a player.

public static bool IsFollowingPlayer(this Entity entity)

Parameters

entity Entity

The entity to check.

Returns

bool

True if the entity is a follower and is following a player; otherwise, false.

IsGatherable(Entity)

Checks if an entity is a gatherable entity (e.g., resources, plants).

public static bool IsGatherable(this Entity entity)

Parameters

entity Entity

The entity to check.

Returns

bool

True if the entity is gatherable; otherwise, false.

IsInBase(Entity, out Entity, out TerritoryAlignment?, bool)

Checks if an entity is within a castle territory and determines the alignment relationship.

public static bool IsInBase(this Entity entity, out Entity territory, out TerritoryAlignment? territoryAlignment, bool requireRoom = false)

Parameters

entity Entity

The entity to check

territory Entity

The output territory entity if found

territoryAlignment TerritoryAlignment?

The alignment relationship (Friendly, Enemy, or Neutral) or null if unable to find

requireRoom bool

If true, also checks if the entity is within an enclosed room

Returns

bool

True if the entity is in a territory, false otherwise

IsMinion(Entity)

Checks if an entity is a minion entity (e.g., summoned creatures).

public static bool IsMinion(this Entity entity)

Parameters

entity Entity

The entity to check.

Returns

bool

True if the entity is a minion; otherwise, false.

IsNpc(Entity)

Checks if an entity is a minion entity (e.g., summoned creatures).

public static bool IsNpc(this Entity entity)

Parameters

entity Entity

The entity to check.

Returns

bool

True if the entity is a minion; otherwise, false.

IsPlayer(Entity)

Checks if an entity is a player entity.

public static bool IsPlayer(this Entity entity)

Parameters

entity Entity

The entity to check.

Returns

bool

True if the entity is a player; otherwise, false.

IsUnit(Entity)

Checks if an entity is a player character entity.

public static bool IsUnit(this Entity entity)

Parameters

entity Entity

The entity to check.

Returns

bool

True if the entity is a player character; otherwise, false.

IsVBlood(Entity)

Checks if an entity is a VBlood entity (e.g., bosses, special enemies).

public static bool IsVBlood(this Entity entity)

Parameters

entity Entity

The entity to check.

Returns

bool

True if the entity is a VBlood; otherwise, false.

RemoveCustomComponentData<TX>(Entity)

Removes custom component data of type TX from the entity.

public static TX? RemoveCustomComponentData<TX>(this Entity entity) where TX : IEntityComponentData

Parameters

entity Entity

The entity to remove the custom component data from.

Returns

TX

The custom component data of type TX if it was removed; otherwise, null.

Type Parameters

TX

The type of the custom component data to remove, must implement IEntityComponentData.

TryAspect<TX>(Entity, bool, params object?[]?)

Attempts to create an aspect of type TX for the given entity.

public static TX? TryAspect<TX>(this Entity entity, bool strict = true, params object?[]? args) where TX : EntityAspect

Parameters

entity Entity

The entity to create the aspect for.

strict bool

If true, throws an exception if the entity does not qualify for the aspect.

args object[]

Optional arguments to pass to the aspect constructor.

Returns

TX

An instance of the aspect type TX if successful; otherwise, null.

Type Parameters

TX

The type of aspect to create, must implement EntityAspect.

TryAspect<TX>(Entity, out TX?, bool, params object?[]?)

Attempts to create an aspect of type TX for the given entity.

public static bool TryAspect<TX>(this Entity entity, out TX? aspect, bool strict = true, params object?[]? args) where TX : EntityAspect

Parameters

entity Entity

The entity to create the aspect for.

aspect TX

The output aspect if creation is successful.

strict bool

If true, throws an exception if the entity does not qualify for the aspect.

args object[]

Optional arguments to pass to the aspect constructor.

Returns

bool

True if the aspect was created successfully; otherwise, false.

Type Parameters

TX

The type of aspect to create, must implement EntityAspect.

TryGetCustomComponentData<TX>(Entity, out TX?)

Attempts to get custom component data of type TX from the entity.

public static bool TryGetCustomComponentData<TX>(this Entity entity, out TX? componentData) where TX : IEntityComponentData

Parameters

entity Entity

The entity to get the custom component data from.

componentData TX

The output custom component data of type TX if it exists; otherwise, null.

Returns

bool

True if the custom component data was successfully retrieved; otherwise, false.

Type Parameters

TX

The type of the custom component data to retrieve, must implement IEntityComponentData.

TryGetFloorEntityBelow(Entity, out Entity)

Attempts to find the floor entity directly below a given entity.

public static bool TryGetFloorEntityBelow(this Entity entity, out Entity floorEntity)

Parameters

entity Entity

The entity to check below

floorEntity Entity

The output floor entity if found

Returns

bool

True if a floor entity was found, false otherwise

TryRemoveCustomComponentData<TX>(Entity, out TX?)

Attempts to remove custom component data of type TX from the entity.

public static bool TryRemoveCustomComponentData<TX>(this Entity entity, out TX? componentData) where TX : IEntityComponentData

Parameters

entity Entity

The entity to remove the custom component data from.

componentData TX

The output custom component data of type TX if it was removed; otherwise, null.

Returns

bool

True if the custom component data was successfully removed; otherwise, false.

Type Parameters

TX

The type of the custom component data to remove, must implement IEntityComponentData.