Table of Contents

Class EntityLevel

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

Represents the level and experience system of an entity in the RPG framework. Handles experience gain, level progression, and experience-based calculations. Implements ILevelable to provide standard leveling functionality.

[Serializable]
public class EntityLevel : ILevelable
Inheritance
object
EntityLevel
Implements

Properties

CurrentTotalExperience

Gets the current total experience of the entity. This represents all experience gained since the entity was created.

public long CurrentTotalExperience { get; }

Property Value

long

Level

Gets or sets the current level of the entity. Level must be between 1 and the maximum level. Setting the level will trigger the OnLevelUp or OnLevelDown event for each level changed.

public virtual int Level { get; set; }

Property Value

int

Methods

AddExp(long)

Adds experience to the entity. The experience will be modified by any experience gain modifiers. If the entity gains enough experience to level up, the OnLevelUp event will be raised. Can trigger multiple level ups if enough experience is added.

public void AddExp(long amount)

Parameters

amount long

The base amount of experience to add before modifiers are applied.

CurrentLevelTotalExperience()

Gets the total experience required to reach the current level. For level 1, this returns 0. For higher levels, it uses the experience growth formula.

public long CurrentLevelTotalExperience()

Returns

long

The total experience required for the current level.

NextLevelTotalExperience()

Gets the total experience required to reach the next level. If the entity is already at the maximum level, returns the experience for the current level.

public long NextLevelTotalExperience()

Returns

long

The total experience required for the next level, or current level experience if at max level.

RemoveExp(long)

Removes experience from the entity. The experience is removed as a flat amount without modifiers. If the entity loses enough experience to level down, the OnLevelDown event will be raised. Can trigger multiple level downs if enough experience is removed. Experience cannot go below 0 and level cannot go below 1.

public void RemoveExp(long amount)

Parameters

amount long

The amount of experience to remove.

ResetToLevelOne()

Resets the entity to level 1 with 0 experience. This will trigger OnLevelDown events for each level lost.

public void ResetToLevelOne()

SetTotalCurrentExp(long)

Sets the total current experience and automatically updates the level to match. The level will be calculated based on the experience growth formula. This method properly triggers OnLevelUp or OnLevelDown events to ensure all dependent components (like EntityAttributes) react correctly to the level change.

public void SetTotalCurrentExp(long totalCurrentExperience)

Parameters

totalCurrentExperience long

The total experience to set. Will be clamped between 0 and max level experience.

ValidateExperience()

Validates that the current total experience corresponds to the current level. If the experience doesn't match the level, it will be reset to the base experience for the current level. This method is useful for debugging and ensuring data consistency.

public void ValidateExperience()

Events

OnEntityLevelDown

Event raised when the entity levels down.

public virtual event Action<EntityLevelChangedContext> OnEntityLevelDown

Event Type

Action<EntityLevelChangedContext>

OnEntityLevelUp

Event raised when the entity levels up.

public virtual event Action<EntityLevelChangedContext> OnEntityLevelUp

Event Type

Action<EntityLevelChangedContext>

OnLevelDown

Event raised when the entity levels down. The parameters are the EntityCore that leveled down and its new level respectively.

[Obsolete("Use OnEntityLevelDown instead.")]
public virtual event Action<EntityCore, int> OnLevelDown

Event Type

Action<EntityCore, int>

OnLevelUp

Event raised when the entity levels up. The parameters are the EntityCore that leveled up and its new level respectively.

[Obsolete("Use OnEntityLevelUp instead.")]
public virtual event Action<EntityCore, int> OnLevelUp

Event Type

Action<EntityCore, int>

Operators

implicit operator int(EntityLevel)

Implicitly converts an EntityLevel to its integer level value. Allows EntityLevel objects to be used directly as integers in calculations.

public static implicit operator int(EntityLevel entityLevel)

Parameters

entityLevel EntityLevel

The EntityLevel instance to convert.

Returns

int

The current level as an integer.