Table of Contents

Class AttributeSetInstance

Namespace
ElectricDrill.AstraRpgFramework.Attributes
Assembly
com.electricdrill.astra-rpg-framework.Runtime.dll

Represents a runtime instance of an AttributeSet with actual values for each attribute. Provides methods to manipulate and access attribute values during gameplay.

public class AttributeSetInstance : IAttributeReader, IValueContainer<AttributeSO>
Inheritance
object
AttributeSetInstance
Implements

Constructors

AttributeSetInstance(AttributeSetSO)

Initializes a new instance of AttributeSetInstance based on an AttributeSet. All attributes are initialized with a value of 0.

public AttributeSetInstance(AttributeSetSO attrSet)

Parameters

attrSet AttributeSetSO

The AttributeSet to base this instance on

Properties

Attributes

Gets the internal dictionary containing all attribute-value pairs.

public Dictionary<AttributeSO, long> Attributes { get; }

Property Value

Dictionary<AttributeSO, long>

this[AttributeSO]

Gets or sets the value of an attribute using indexer syntax.

public long this[AttributeSO attribute] { get; set; }

Parameters

attribute AttributeSO

The attribute to access

Property Value

long

The current value when getting, or sets the value when setting

Methods

AddValue(AttributeSO, long)

Adds a value to the specified attribute. If the attribute doesn't exist, it will be created.

public void AddValue(AttributeSO attribute, long value)

Parameters

attribute AttributeSO

The attribute to modify

value long

The value to add. Can be negative to decrease the value.

Clone()

Creates a deep copy of this AttributeSetInstance.

public AttributeSetInstance Clone()

Returns

AttributeSetInstance

A new AttributeSetInstance with the same attribute values

Contains(AttributeSO)

Checks whether the specified attribute is contained in this instance.

public bool Contains(AttributeSO attribute)

Parameters

attribute AttributeSO

The attribute to check for

Returns

bool

True if the attribute exists, false otherwise

Get(AttributeSO)

Gets the current value of the specified attribute.

public long Get(AttributeSO attribute)

Parameters

attribute AttributeSO

The attribute to retrieve

Returns

long

The current value of the attribute

GetAsPercentage(AttributeSO)

Gets the value of an attribute as a percentage.

public Percentage GetAsPercentage(AttributeSO attribute)

Parameters

attribute AttributeSO

The attribute to convert to percentage

Returns

Percentage

A Percentage representation of the attribute value

GetEnumerator()

Struct-typed enumerator so foreach resolves to the underlying dictionary's struct enumerator without boxing. The System.Collections.Generic.IEnumerable<T> implementations below are preserved for LINQ/interface consumers and remain boxing for those paths.

public Dictionary<AttributeSO, long>.Enumerator GetEnumerator()

Returns

Dictionary<AttributeSO, long>.Enumerator

TryGet(AttributeSO, out long)

Tries to get the current value of the specified attribute.

public bool TryGet(AttributeSO attribute, out long value)

Parameters

attribute AttributeSO

The attribute to query.

value long

The attribute value if present; otherwise, 0.

Returns

bool

True if the attribute exists in this instance; otherwise, false.

TryGetBase(AttributeSO, out long)

Always returns false. AttributeSetInstance stores raw accumulated values (e.g., flat modifiers) and has no concept of an unmodified base value.

public bool TryGetBase(AttributeSO attribute, out long value)

Parameters

attribute AttributeSO

The attribute to query.

value long

Always 0.

Returns

bool

Always false.

Operators

operator +(AttributeSetInstance, AttributeSetInstance)

Adds two AttributeSetInstance objects together, combining their attribute values.

public static AttributeSetInstance operator +(AttributeSetInstance a, AttributeSetInstance b)

Parameters

a AttributeSetInstance

The first AttributeSetInstance

b AttributeSetInstance

The second AttributeSetInstance

Returns

AttributeSetInstance

A new AttributeSetInstance with combined values

explicit operator AttributeSetInstance(SerializableDictionary<AttributeSO, long>)

Explicitly converts a SerializableDictionary to an AttributeSetInstance.

public static explicit operator AttributeSetInstance(SerializableDictionary<AttributeSO, long> dictionary)

Parameters

dictionary SerializableDictionary<AttributeSO, long>

The dictionary to convert

Returns

AttributeSetInstance

A new AttributeSetInstance based on the dictionary