feat: shared creature root, enemy definitions, defend duty, and player downing
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
class_name EnemyDefinition
|
||||
extends Resource
|
||||
|
||||
@export var enemy_id: StringName
|
||||
@export var display_name: String
|
||||
@export var kind: StringName = SimulationIds.COMBATANT_KIND_RAIDER
|
||||
@export var weapon_id: StringName = SimulationIds.ITEM_SWORD
|
||||
@export var health := 60.0
|
||||
@export var move_speed := 3.5
|
||||
@export var body_color := Color(0.4, 0.13, 0.1, 1.0)
|
||||
@export var accent_color := Color(0.55, 0.55, 0.58, 1.0)
|
||||
@export var visual_scale := Vector3.ONE
|
||||
|
||||
|
||||
func validate() -> Array[String]:
|
||||
var errors: Array[String] = []
|
||||
if enemy_id.is_empty():
|
||||
errors.append("enemy_id is empty")
|
||||
if display_name.is_empty():
|
||||
errors.append("display_name is empty for '%s'" % enemy_id)
|
||||
if (
|
||||
kind
|
||||
not in [
|
||||
SimulationIds.COMBATANT_KIND_RAIDER,
|
||||
SimulationIds.COMBATANT_KIND_WOLF,
|
||||
]
|
||||
):
|
||||
errors.append("kind '%s' is invalid for '%s'" % [kind, enemy_id])
|
||||
if health <= 0.0:
|
||||
errors.append("health must be positive for '%s'" % enemy_id)
|
||||
return errors
|
||||
@@ -0,0 +1 @@
|
||||
uid://5tfgb1oww0e0
|
||||
@@ -13,7 +13,8 @@ const ACTION_PATHS := [
|
||||
"res://simulation/definitions/actions/deposit_food.tres",
|
||||
"res://simulation/definitions/actions/withdraw_food.tres",
|
||||
"res://simulation/definitions/actions/sleep.tres",
|
||||
"res://simulation/definitions/actions/deposit_wood.tres"
|
||||
"res://simulation/definitions/actions/deposit_wood.tres",
|
||||
"res://simulation/definitions/actions/defend.tres"
|
||||
]
|
||||
|
||||
const PROFESSION_PATHS := [
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
class_name SimulationEnemies
|
||||
extends RefCounted
|
||||
|
||||
static var _enemies: Dictionary = {}
|
||||
static var _cache_valid := false
|
||||
|
||||
|
||||
static func _ensure_cache() -> void:
|
||||
if _cache_valid:
|
||||
return
|
||||
_enemies = {}
|
||||
var raider := EnemyDefinition.new()
|
||||
raider.enemy_id = &"enemy_raider"
|
||||
raider.display_name = "Raider"
|
||||
raider.kind = SimulationIds.COMBATANT_KIND_RAIDER
|
||||
raider.weapon_id = SimulationIds.ITEM_SWORD
|
||||
raider.health = 60.0
|
||||
raider.move_speed = 3.5
|
||||
raider.body_color = Color(0.4, 0.13, 0.1, 1.0)
|
||||
raider.accent_color = Color(0.55, 0.55, 0.58, 1.0)
|
||||
_enemies[raider.enemy_id] = raider
|
||||
|
||||
var wolf := EnemyDefinition.new()
|
||||
wolf.enemy_id = &"enemy_wolf"
|
||||
wolf.display_name = "Wolf"
|
||||
wolf.kind = SimulationIds.COMBATANT_KIND_WOLF
|
||||
wolf.weapon_id = SimulationIds.ITEM_CLAW
|
||||
wolf.health = 40.0
|
||||
wolf.move_speed = 4.2
|
||||
wolf.body_color = Color(0.32, 0.32, 0.34, 1.0)
|
||||
wolf.accent_color = Color(0.95, 0.5, 0.12, 1.0)
|
||||
wolf.visual_scale = Vector3(0.8, 0.8, 0.8)
|
||||
_enemies[wolf.enemy_id] = wolf
|
||||
_cache_valid = true
|
||||
|
||||
|
||||
static func invalidate_cache() -> void:
|
||||
_cache_valid = false
|
||||
|
||||
|
||||
static func get_enemy(enemy_id: StringName) -> EnemyDefinition:
|
||||
_ensure_cache()
|
||||
return _enemies.get(enemy_id) as EnemyDefinition
|
||||
|
||||
|
||||
static func get_all() -> Array[EnemyDefinition]:
|
||||
_ensure_cache()
|
||||
var values: Array[EnemyDefinition] = []
|
||||
for enemy in _enemies.values():
|
||||
values.append(enemy)
|
||||
return values
|
||||
@@ -0,0 +1 @@
|
||||
uid://daurjkbl4hcd8
|
||||
@@ -18,6 +18,7 @@ const ACTION_WANDER := &"wander"
|
||||
const ACTION_DEPOSIT_FOOD := &"deposit_food"
|
||||
const ACTION_WITHDRAW_FOOD := &"withdraw_food"
|
||||
const ACTION_DEPOSIT_WOOD := &"deposit_wood"
|
||||
const ACTION_DEFEND := &"defend"
|
||||
|
||||
const PROFESSION_FARMER := &"farmer"
|
||||
const PROFESSION_WOODCUTTER := &"woodcutter"
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[gd_resource type="Resource" script_class="ActionDefinition" load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://simulation/definitions/ActionDefinition.gd" id="1"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1")
|
||||
action_id = &"defend"
|
||||
display_name = "Defend"
|
||||
default_duration = 5.0
|
||||
preferred_profession_id = &"guard"
|
||||
target_type = &"activity"
|
||||
Reference in New Issue
Block a user