Class UnitSystem
- Namespace
- AshesOfVelsingrad.Systems
- Assembly
- Ashes of Velsingrad.dll
Base class for all units in the tactical grid-based system. Handles stats, movement, effects, and Godot integration.
[ScriptPath("res://scripts/systems/unit_system/UnitSystem.cs")]
public abstract class UnitSystem : CharacterBody3D, IDisposable, IEffectTarget<UnitSystem>, IStatusEffectBehavior
- Inheritance
-
GodotObjectNodeNode3DCollisionObject3DPhysicsBody3DCharacterBody3DUnitSystem
- Implements
- Derived
- Inherited Members
-
CharacterBody3D.MoveAndSlide()CharacterBody3D.ApplyFloorSnap()CharacterBody3D.IsOnFloor()CharacterBody3D.IsOnFloorOnly()CharacterBody3D.IsOnCeiling()CharacterBody3D.IsOnCeilingOnly()CharacterBody3D.IsOnWall()CharacterBody3D.IsOnWallOnly()CharacterBody3D.GetFloorNormal()CharacterBody3D.GetWallNormal()CharacterBody3D.GetLastMotion()CharacterBody3D.GetPositionDelta()CharacterBody3D.GetRealVelocity()CharacterBody3D.GetFloorAngle(Vector3?)CharacterBody3D.GetPlatformVelocity()CharacterBody3D.GetPlatformAngularVelocity()CharacterBody3D.GetSlideCollisionCount()CharacterBody3D.GetLastSlideCollision()CharacterBody3D.InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)CharacterBody3D.HasGodotClassMethod(in godot_string_name)CharacterBody3D.HasGodotClassSignal(in godot_string_name)CharacterBody3D.MotionModeCharacterBody3D.UpDirectionCharacterBody3D.SlideOnCeilingCharacterBody3D.VelocityCharacterBody3D.MaxSlidesCharacterBody3D.WallMinSlideAngleCharacterBody3D.FloorStopOnSlopeCharacterBody3D.FloorConstantSpeedCharacterBody3D.FloorBlockOnWallCharacterBody3D.FloorMaxAngleCharacterBody3D.FloorSnapLengthCharacterBody3D.PlatformOnLeaveCharacterBody3D.PlatformFloorLayersCharacterBody3D.PlatformWallLayersCharacterBody3D.SafeMarginPhysicsBody3D.GetGravity()PhysicsBody3D.GetCollisionExceptions()PhysicsBody3D.AddCollisionExceptionWith(Node)PhysicsBody3D.RemoveCollisionExceptionWith(Node)PhysicsBody3D.AxisLockLinearXPhysicsBody3D.AxisLockLinearYPhysicsBody3D.AxisLockLinearZPhysicsBody3D.AxisLockAngularXPhysicsBody3D.AxisLockAngularYPhysicsBody3D.AxisLockAngularZCollisionObject3D._MouseEnter()CollisionObject3D._MouseExit()CollisionObject3D.GetRid()CollisionObject3D.CreateShapeOwner(GodotObject)CollisionObject3D.GetShapeOwners()CollisionObject3D.EmitSignalMouseEntered()CollisionObject3D.EmitSignalMouseExited()CollisionObject3D.DisableModeCollisionObject3D.CollisionLayerCollisionObject3D.CollisionMaskCollisionObject3D.CollisionPriorityCollisionObject3D.InputRayPickableCollisionObject3D.InputCaptureOnDragCollisionObject3D.InputEventCollisionObject3D.MouseEnteredCollisionObject3D.MouseExitedNode3D.NotificationTransformChangedNode3D.NotificationEnterWorldNode3D.NotificationExitWorldNode3D.NotificationVisibilityChangedNode3D.NotificationLocalTransformChangedNode3D.GetGlobalTransformInterpolated()Node3D.GetParentNode3D()Node3D.IsScaleDisabled()Node3D.GetWorld3D()Node3D.ForceUpdateTransform()Node3D.UpdateGizmos()Node3D.AddGizmo(Node3DGizmo)Node3D.GetGizmos()Node3D.ClearGizmos()Node3D.ClearSubgizmoSelection()Node3D.IsVisibleInTree()Node3D.Show()Node3D.Hide()Node3D.IsLocalTransformNotificationEnabled()Node3D.IsTransformNotificationEnabled()Node3D.GlobalScale(Vector3)Node3D.GlobalTranslate(Vector3)Node3D.ScaleObjectLocal(Vector3)Node3D.TranslateObjectLocal(Vector3)Node3D.Translate(Vector3)Node3D.Orthonormalize()Node3D.SetIdentity()Node3D.ToLocal(Vector3)Node3D.ToGlobal(Vector3)Node3D.EmitSignalVisibilityChanged()Node3D.TransformNode3D.GlobalTransformNode3D.PositionNode3D.RotationNode3D.RotationDegreesNode3D.QuaternionNode3D.BasisNode3D.ScaleNode3D.RotationEditModeNode3D.RotationOrderNode3D.TopLevelNode3D.GlobalPositionNode3D.GlobalBasisNode3D.GlobalRotationNode3D.GlobalRotationDegreesNode3D.VisibleNode3D.VisibilityParentNode3D.VisibilityChangedNode.NotificationEnterTreeNode.NotificationExitTreeNode.NotificationMovedInParentNode.NotificationReadyNode.NotificationPausedNode.NotificationUnpausedNode.NotificationPhysicsProcessNode.NotificationProcessNode.NotificationParentedNode.NotificationUnparentedNode.NotificationSceneInstantiatedNode.NotificationDragBeginNode.NotificationDragEndNode.NotificationPathRenamedNode.NotificationChildOrderChangedNode.NotificationInternalProcessNode.NotificationInternalPhysicsProcessNode.NotificationPostEnterTreeNode.NotificationDisabledNode.NotificationEnabledNode.NotificationResetPhysicsInterpolationNode.NotificationEditorPreSaveNode.NotificationEditorPostSaveNode.NotificationWMMouseEnterNode.NotificationWMMouseExitNode.NotificationWMWindowFocusInNode.NotificationWMWindowFocusOutNode.NotificationWMCloseRequestNode.NotificationWMGoBackRequestNode.NotificationWMSizeChangedNode.NotificationWMDpiChangeNode.NotificationVpMouseEnterNode.NotificationVpMouseExitNode.NotificationWMPositionChangedNode.NotificationOsMemoryWarningNode.NotificationTranslationChangedNode.NotificationWMAboutNode.NotificationCrashNode.NotificationOsImeUpdateNode.NotificationApplicationResumedNode.NotificationApplicationPausedNode.NotificationApplicationFocusInNode.NotificationApplicationFocusOutNode.NotificationTextServerChangedNode.NotificationAccessibilityUpdateNode.NotificationAccessibilityInvalidateNode.GetNode<T>(NodePath)Node.GetNodeOrNull<T>(NodePath)Node.GetOwner<T>()Node.GetOwnerOrNull<T>()Node.GetParent<T>()Node.GetParentOrNull<T>()Node._EnterTree()Node._GetAccessibilityConfigurationWarnings()Node._GetConfigurationWarnings()Node._GetFocusedAccessibilityElement()Node._Input(InputEvent)Node._ShortcutInput(InputEvent)Node._UnhandledInput(InputEvent)Node._UnhandledKeyInput(InputEvent)Node.PrintOrphanNodes()Node.GetOrphanNodeIds()Node.RemoveChild(Node)Node.HasNode(NodePath)Node.GetNode(NodePath)Node.GetNodeOrNull(NodePath)Node.GetParent()Node.HasNodeAndResource(NodePath)Node.GetNodeAndResource(NodePath)Node.IsInsideTree()Node.IsPartOfEditedScene()Node.IsAncestorOf(Node)Node.IsGreaterThan(Node)Node.GetPath()Node.RemoveFromGroup(StringName)Node.IsInGroup(StringName)Node.GetGroups()Node.PrintTree()Node.PrintTreePretty()Node.GetTreeString()Node.GetTreeStringPretty()Node.GetPhysicsProcessDeltaTime()Node.IsPhysicsProcessing()Node.GetProcessDeltaTime()Node.IsProcessing()Node.IsProcessingInput()Node.IsProcessingShortcutInput()Node.IsProcessingUnhandledInput()Node.IsProcessingUnhandledKeyInput()Node.CanProcess()Node.QueueAccessibilityUpdate()Node.GetAccessibilityElement()Node.IsDisplayedFolded()Node.IsProcessingInternal()Node.IsPhysicsProcessingInternal()Node.IsPhysicsInterpolated()Node.IsPhysicsInterpolatedAndEnabled()Node.ResetPhysicsInterpolation()Node.CanAutoTranslate()Node.SetTranslationDomainInherited()Node.GetWindow()Node.GetLastExclusiveWindow()Node.GetTree()Node.CreateTween()Node.GetSceneInstanceLoadPlaceholder()Node.IsEditableInstance(Node)Node.GetViewport()Node.QueueFree()Node.RequestReady()Node.IsNodeReady()Node.GetMultiplayerAuthority()Node.IsMultiplayerAuthority()Node.RpcConfig(StringName, Variant)Node.GetNodeRpcConfig()Node.Rpc(StringName, params Variant[])Node.UpdateConfigurationWarnings()Node.CallDeferredThreadGroup(StringName, params Variant[])Node.SetDeferredThreadGroup(StringName, Variant)Node.CallThreadSafe(StringName, params Variant[])Node.SetThreadSafe(StringName, Variant)Node.EmitSignalReady()Node.EmitSignalRenamed()Node.EmitSignalTreeEntered()Node.EmitSignalTreeExiting()Node.EmitSignalTreeExited()Node.EmitSignalChildEnteredTree(Node)Node.EmitSignalChildExitingTree(Node)Node.EmitSignalChildOrderChanged()Node.EmitSignalReplacingBy(Node)Node.EmitSignalEditorDescriptionChanged(Node)Node.EmitSignalEditorStateChanged()Node.NameNode.UniqueNameInOwnerNode.SceneFilePathNode.OwnerNode.MultiplayerNode.ProcessModeNode.ProcessPriorityNode.ProcessPhysicsPriorityNode.ProcessThreadGroupNode.ProcessThreadGroupOrderNode.ProcessThreadMessagesNode.PhysicsInterpolationModeNode.AutoTranslateModeNode.EditorDescriptionNode.ReadyNode.RenamedNode.TreeEnteredNode.TreeExitingNode.TreeExitedNode.ChildEnteredTreeNode.ChildExitingTreeNode.ChildOrderChangedNode.ReplacingByNode.EditorDescriptionChangedNode.EditorStateChangedGodotObject.NotificationPostinitializeGodotObject.NotificationPredeleteGodotObject.NotificationExtensionReloadedGodotObject.IsInstanceValid(GodotObject)GodotObject.WeakRef(GodotObject)GodotObject.Dispose()GodotObject.ToString()GodotObject.ToSignal(GodotObject, StringName)GodotObject._Get(StringName)GodotObject._GetPropertyList()GodotObject._IterGet(Variant)GodotObject._IterInit(Array)GodotObject._IterNext(Array)GodotObject._PropertyCanRevert(StringName)GodotObject._PropertyGetRevert(StringName)GodotObject._Set(StringName, Variant)GodotObject._ValidateProperty(Dictionary)GodotObject.Free()GodotObject.GetClass()GodotObject.Set(StringName, Variant)GodotObject.Get(StringName)GodotObject.SetIndexed(NodePath, Variant)GodotObject.GetIndexed(NodePath)GodotObject.GetPropertyList()GodotObject.GetMethodList()GodotObject.PropertyCanRevert(StringName)GodotObject.PropertyGetRevert(StringName)GodotObject.GetInstanceId()GodotObject.SetScript(Variant)GodotObject.GetScript()GodotObject.SetMeta(StringName, Variant)GodotObject.RemoveMeta(StringName)GodotObject.GetMeta(StringName, Variant)GodotObject.HasMeta(StringName)GodotObject.GetMetaList()GodotObject.HasUserSignal(StringName)GodotObject.RemoveUserSignal(StringName)GodotObject.EmitSignal(StringName, params Variant[])GodotObject.Call(StringName, params Variant[])GodotObject.CallDeferred(StringName, params Variant[])GodotObject.SetDeferred(StringName, Variant)GodotObject.Callv(StringName, Array)GodotObject.HasMethod(StringName)GodotObject.GetMethodArgumentCount(StringName)GodotObject.HasSignal(StringName)GodotObject.GetSignalList()GodotObject.GetSignalConnectionList(StringName)GodotObject.GetIncomingConnections()GodotObject.Disconnect(StringName, Callable)GodotObject.IsConnected(StringName, Callable)GodotObject.HasConnections(StringName)GodotObject.IsBlockingSignals()GodotObject.NotifyPropertyListChanged()GodotObject.CanTranslateMessages()GodotObject.Tr(StringName, StringName)GodotObject.GetTranslationDomain()GodotObject.SetTranslationDomain(StringName)GodotObject.IsQueuedForDeletion()GodotObject.CancelFree()GodotObject.EmitSignalScriptChanged()GodotObject.EmitSignalPropertyListChanged()GodotObject.NativeInstanceGodotObject.ScriptChangedGodotObject.PropertyListChanged
Remarks
This class provides fundamental behavior for all combat units, including:
- Base stats (HP, attack, defense, etc.)
- Turn logic (HasPlayed)
- Movement logic (BFS pathfinding in 3D)
- Integration with MapSystem and StatusEffect<TTarget>
Properties
ActiveSkills
List of active (usable) skills available to this unit.
public List<SkillSystem> ActiveSkills { get; protected set; }
Property Value
BaseAtk
The base physical attack value of the unit.
public float BaseAtk { get; protected set; }
Property Value
BaseDef
The base physical defense value of the unit.
public float BaseDef { get; protected set; }
Property Value
BaseSpeed
The unit's base speed (used for turn order or initiative).
public float BaseSpeed { get; protected set; }
Property Value
CharacterSprite
The 3D Sprite of the unit displayed in the UI.
public Sprite3D? CharacterSprite { get; protected set; }
Property Value
- Sprite3D
Curse
The unit’s curse value (used for status mechanics or debuffs).
public float Curse { get; protected set; }
Property Value
Description
Descriptive text about the unit.
public string Description { get; protected set; }
Property Value
Hp
The current health points of the unit.
public float Hp { get; protected set; }
Property Value
Intelligence
The unit's intelligence stat, affecting magical power or effects.
public float Intelligence { get; protected set; }
Property Value
IsAlive
Indicates whether the unit is alive.
public bool IsAlive { get; protected set; }
Property Value
IsControlled
Tell if the unit is controlled or not
public bool IsControlled { get; }
Property Value
Mana
The current mana points of the unit.
public float Mana { get; protected set; }
Property Value
ManaMax
The unit's available mana points for casting skills.
public float ManaMax { get; protected set; }
Property Value
MaxHp
The maximum health points of the unit.
public float MaxHp { get; protected set; }
Property Value
PassiveSkills
List of passive (always-on) skills applied to this unit.
public List<SkillSystem> PassiveSkills { get; protected set; }
Property Value
Personality
The default AI personality type of the unit.
public AIPersonality Personality { get; protected set; }
Property Value
PortraitTexture
The portrait texture displayed for this unit in the UI.
public Texture2D? PortraitTexture { get; protected set; }
Property Value
- Texture2D
PossibleMovesRange
The maximum number of tiles the unit can move per turn.
public int PossibleMovesRange { get; protected set; }
Property Value
TotalAtk
public float TotalAtk { get; }
Property Value
TotalDef
public float TotalDef { get; }
Property Value
Type
The type or archetype of the unit.
public AovDataStructures.UnitType Type { get; protected set; }
Property Value
UnitName
The name of the unit.
public string UnitName { get; protected set; }
Property Value
Methods
ApplyEffect(StatusEffect<UnitSystem>)
Applies a status effect to this target.
public void ApplyEffect(StatusEffect<UnitSystem> statusEffect)
Parameters
statusEffectStatusEffect<UnitSystem>The StatusEffect<TTarget> instance to apply.
BypassDamage(float)
Applies damage that bypasses defense to the unit and updates HP.
public virtual void BypassDamage(float damage)
Parameters
damagefloatThe amount of damage to apply.
CanMoveTo(int, int, int, MapSystem)
Checks if the unit can move to a given position.
public virtual bool CanMoveTo(int x, int y, int z, MapSystem map)
Parameters
xintThe X coordinate.
yintThe Y coordinate (height).
zintThe Z coordinate.
mapMapSystemThe map to check against.
Returns
- bool
trueif the position is walkable; otherwisefalse.
Cleanup()
Cleans up the unit instance. This method can be overridden in derived classes to implement specific cleanup logic.
protected virtual void Cleanup()
Remarks
This method is called when the unit is removed from the scene tree. It provides a place for derived classes to implement any necessary cleanup logic, such as disconnecting signals or releasing resources. By default, it does nothing, but derived classes can override it to perform specific cleanup tasks.
EmitSignalHealthChanged(float, float)
protected void EmitSignalHealthChanged(float currentHp, float maxHp)
Parameters
EmitSignalPortraitChanged(Texture2D)
protected void EmitSignalPortraitChanged(Texture2D texture)
Parameters
textureTexture2D
GetActiveEffects()
Retrieves all status effects currently active on this target.
public List<StatusEffect<UnitSystem>> GetActiveEffects()
Returns
- List<StatusEffect<UnitSystem>>
A list of StatusEffect<TTarget> representing all active effects.
GetPossibleMoves(MapSystem)
Calculates all possible movement tiles for this unit based on its range and position.
public virtual List<Vector3I> GetPossibleMoves(MapSystem map)
Parameters
mapMapSystemThe map to evaluate movement on.
Returns
- List<Vector3I>
A list of reachable coordinates (x, y, z).
Remarks
This method uses a Breadth-First Search (BFS) algorithm to evaluate all valid moves considering walkable tiles and vertical traversal (e.g. stairs, cliffs).
GetReachableCellsForSkills(MapSystem, SkillSystem)
Calculates all reachable cells for this unit based on the skill range and the unit position.
public virtual List<Vector3I> GetReachableCellsForSkills(MapSystem map, SkillSystem skill)
Parameters
mapMapSystemThe map to evaluate reachable cells on.
skillSkillSystemThe selected skill
Returns
- List<Vector3I>
A list of reachable coordinates (x, y, z).
Remarks
This method uses a Breadth-First Search (BFS) algorithm to evaluate all valid cells considering vertical traversal (e.g. stairs, cliffs).
HasEffect<T>()
Checks whether this target currently has an active status effect of the specified type.
public bool HasEffect<T>() where T : StatusEffect<UnitSystem>
Returns
- bool
trueif the effect is present on this target; otherwise,false.
Type Parameters
TThe type of StatusEffect<TTarget> to check for.
Initialize()
Initializes the unit instance This method should be overridden in derived classes to set up specific functionality.
protected virtual void Initialize()
Remarks
This method is called by the _Ready method to initialize the map. It should contain the logic necessary to set up the unit's state and functionality. Derived classes must implement this method to provide their specific initialization logic.
InjectDependencies(StatusEffectSystem)
Injects an instance of the status effect system into this unit.
public virtual void InjectDependencies(StatusEffectSystem statusEffectSystem)
Parameters
statusEffectSystemStatusEffectSystemThe status effect system to be used by this unit.
MoveTo(int, int, int, MapSystem)
Moves the unit to the specified coordinates if possible.
public virtual bool MoveTo(int x, int y, int z, MapSystem map)
Parameters
xintTarget X coordinate.
yintTarget Y coordinate (height).
zintTarget Z coordinate.
mapMapSystemThe map to interact with.
Returns
- bool
trueif the move was successful; otherwisefalse.
OnEffectControlApplied()
Called when a control effect (e.g. stun, silence, root) is applied to the entity.
public virtual void OnEffectControlApplied()
OnEffectControlRemoved()
Called when a control effect is removed from the entity.
public virtual void OnEffectControlRemoved()
OnEffectDamage(ModifierType, float)
Called when a damage effect is applied to the entity.
public virtual void OnEffectDamage(AovDataStructures.ModifierType modifierType, float amount)
Parameters
modifierTypeAovDataStructures.ModifierTypeThe type of modifier responsible for the damage (e.g. Flat, Percent).
amountfloatThe amount of damage applied.
OnEffectHeal(float)
Called when a healing effect is applied to the entity.
public virtual void OnEffectHeal(float amount)
Parameters
amountfloatThe amount of health restored.
OnEffectModifierApplied(StatTypeWithModifier, ModifierType, float)
Called when a stat modifier effect is applied to the entity.
public virtual void OnEffectModifierApplied(AovDataStructures.StatTypeWithModifier statType, AovDataStructures.ModifierType modifierType, float amount)
Parameters
statTypeAovDataStructures.StatTypeWithModifiermodifierTypeAovDataStructures.ModifierTypeThe type of modifier applied.
amountfloatThe value of the applied modifier.
OnEffectModifierRemoved(StatTypeWithModifier, ModifierType, float)
Called when a stat modifier effect is removed from the entity.
public virtual void OnEffectModifierRemoved(AovDataStructures.StatTypeWithModifier statType, AovDataStructures.ModifierType modifierType, float amount)
Parameters
statTypeAovDataStructures.StatTypeWithModifiermodifierTypeAovDataStructures.ModifierTypeThe type of modifier being removed.
amountfloatThe value of the removed modifier.
OnEffectRevive(ModifierType, float)
Called when a revive effect is applied to the entity.
public virtual void OnEffectRevive(AovDataStructures.ModifierType modifierType, float amount)
Parameters
modifierTypeAovDataStructures.ModifierTypeThe type of modifier responsible for the revive effect.
amountfloatThe amount of health restored upon revival.
PassTurn()
Marks the unit as having completed its turn.
public void PassTurn()
Play(List<UnitSystem>, MapSystem?, SkillSystem)
Performs an attack on the specified targets.
public virtual void Play(List<UnitSystem> targets, MapSystem? map, SkillSystem skill)
Parameters
targetsList<UnitSystem>List of target units to attack.
mapMapSystemReference to the map system for positional logic.
skillSkillSystemTells which active skill to use
RemoveEffect(StatusEffect<UnitSystem>)
Removes a status effect from this target.
public void RemoveEffect(StatusEffect<UnitSystem> statusEffect)
Parameters
statusEffectStatusEffect<UnitSystem>The StatusEffect<TTarget> instance to remove.
ReportSystemUnitHasPlayed()
Called by every UnitSystem function with an action to report to the system that the unit has played.
protected void ReportSystemUnitHasPlayed()
SetGridPosition(int, int, int, MapSystem)
Moves the unit to the specified grid coordinates in the MapSystem.
public virtual void SetGridPosition(int x, int y, int z, MapSystem map)
Parameters
xintThe X grid coordinate.
yintThe Y grid coordinate (height).
zintThe Z grid coordinate.
mapMapSystemThe map on which the unit exists.
SetIsAlive(bool)
Set if the unit is alive or not.
public void SetIsAlive(bool isAlive)
Parameters
SetStatusEffectOnUnit(StatusEffect<UnitSystem>)
Applies a status effect to this unit.
public virtual void SetStatusEffectOnUnit(StatusEffect<UnitSystem> statusEffect)
Parameters
statusEffectStatusEffect<UnitSystem>The status effect to apply.
TakeDamage(float)
Applies incoming damage to the unit and updates HP.
public void TakeDamage(float damage)
Parameters
damagefloatThe amount of damage received.
WaitForActionAsync()
Lock the system and wait the unit for an action
public Task WaitForActionAsync()
Returns
_ExitTree()
Called when the node is removed from the scene tree. Cleans up the unit instance and sets it to null.
public override void _ExitTree()
Remarks
This method is called automatically by Godot when the node is removed from the scene tree. It ensures that the unit instance is properly cleaned up and set to null. This is important for preventing memory leaks and ensuring that the manager can be re-initialized later if needed.
_PhysicsProcess(double)
Handles the physics of the unit in the UI.
public override void _PhysicsProcess(double delta)
Parameters
deltadouble
_Ready()
Called when the node is added to the scene tree. Initializes the unit instance.
public override void _Ready()
Remarks
This method is called automatically by Godot when the node is ready.
Events
HealthChanged
Emitted when the unit's health changes.
public event UnitSystem.HealthChangedEventHandler HealthChanged
Event Type
PortraitChanged
Emitted when the unit's portrait texture changes.
public event UnitSystem.PortraitChangedEventHandler PortraitChanged