Reorganized files, started splitting up unit
This commit is contained in:
56
scripts/units/unit.gd
Normal file
56
scripts/units/unit.gd
Normal file
@@ -0,0 +1,56 @@
|
||||
class_name Unit extends Node2D
|
||||
|
||||
enum UnitState { ALIVE, DEAD }
|
||||
|
||||
#region Templates
|
||||
@export var stat_template: UnitStats
|
||||
@export var info_template: UnitInfo
|
||||
@export var allegiance_template: UnitAllegiance
|
||||
@export var tactics: Array[CombatTactic] = []
|
||||
#endregion
|
||||
|
||||
var current_stats: UnitStats
|
||||
var current_info: UnitInfo
|
||||
var current_allegiance: UnitAllegiance
|
||||
var state: UnitState = UnitState.ALIVE
|
||||
|
||||
signal unit_selected_changed(unit: Unit, selected: bool)
|
||||
signal unit_allegiance_changed(unit: Unit, allegiance: UnitAllegiance)
|
||||
signal unit_died(unit: Unit)
|
||||
|
||||
func _ready() -> void:
|
||||
current_stats = stat_template.duplicate(true)
|
||||
current_info = info_template.duplicate(true)
|
||||
current_allegiance = allegiance_template.duplicate(true)
|
||||
_append_builtin_tactics()
|
||||
unit_allegiance_changed.emit(self, current_allegiance)
|
||||
|
||||
func _append_builtin_tactics() -> void:
|
||||
var attack := AttackCombatTactic.new()
|
||||
attack.tactic_name = "Attack"
|
||||
attack.tactic_range = UnitMatchingCombatTacticRange.new()
|
||||
tactics.append(attack)
|
||||
|
||||
var defend := DefendCombatTactic.new()
|
||||
defend.tactic_name = "Defend"
|
||||
defend.tactic_range = AnyCombatTacticRange.new()
|
||||
tactics.append(defend)
|
||||
|
||||
func set_selected(selected: bool) -> void:
|
||||
unit_selected_changed.emit(self, selected)
|
||||
|
||||
func is_alive() -> bool:
|
||||
return state == UnitState.ALIVE
|
||||
|
||||
func take_damage(amount: int) -> void:
|
||||
if state != UnitState.ALIVE:
|
||||
return
|
||||
current_stats.current_hp -= amount
|
||||
if current_stats.current_hp <= 0:
|
||||
current_stats.current_hp = 0
|
||||
_die()
|
||||
|
||||
func _die() -> void:
|
||||
state = UnitState.DEAD
|
||||
unit_died.emit(self)
|
||||
queue_free()
|
||||
1
scripts/units/unit.gd.uid
Normal file
1
scripts/units/unit.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c016mxgatcpse
|
||||
12
scripts/units/unit_allegiance.gd
Normal file
12
scripts/units/unit_allegiance.gd
Normal file
@@ -0,0 +1,12 @@
|
||||
class_name UnitAllegiance extends Resource
|
||||
|
||||
enum AllegianceType {
|
||||
PLAYER,
|
||||
ENEMY,
|
||||
PLAYER_ALLY,
|
||||
ENEMY_ALLY,
|
||||
UNAFFILIATED
|
||||
}
|
||||
|
||||
@export var type: AllegianceType
|
||||
@export var color: Color
|
||||
1
scripts/units/unit_allegiance.gd.uid
Normal file
1
scripts/units/unit_allegiance.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bhglsexm8dtpj
|
||||
3
scripts/units/unit_info.gd
Normal file
3
scripts/units/unit_info.gd
Normal file
@@ -0,0 +1,3 @@
|
||||
class_name UnitInfo extends Resource
|
||||
|
||||
@export var name: String = "Unit"
|
||||
1
scripts/units/unit_info.gd.uid
Normal file
1
scripts/units/unit_info.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d37ulss2k0bq5
|
||||
15
scripts/units/unit_stats.gd
Normal file
15
scripts/units/unit_stats.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
class_name UnitStats extends Resource
|
||||
|
||||
@export var max_hp: int = 10
|
||||
@export var max_sp: int = 10
|
||||
@export var max_fs: int = 10
|
||||
@export var phys_atk: int = 10
|
||||
@export var phys_def: int = 5
|
||||
@export var magic_atk: int = 0
|
||||
@export var magic_def: int = 0
|
||||
@export var hit: int = 85
|
||||
@export var atk_range: int = 1
|
||||
@export var spd: int = 1
|
||||
@export var eva: int = 1
|
||||
@export var lck: int = 1
|
||||
@export var mov: int = 3
|
||||
1
scripts/units/unit_stats.gd.uid
Normal file
1
scripts/units/unit_stats.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cydoey8a8nmb8
|
||||
Reference in New Issue
Block a user