Files
gamedev-the-steward/simulation/SimNPC.gd
T

51 lines
1.0 KiB
GDScript

class_name SimNPC
extends RefCounted
var id: int
var npc_name: String
var profession: String
var hunger: float
var energy: float
var strength: float
var intelligence: float
var current_task: String = "idle"
var position: Vector3
func _init(
_id: int,
_npc_name: String,
_profession: String,
_strength: float,
_intelligence: float
) -> void:
id = _id
npc_name = _npc_name
profession = _profession
strength = _strength
intelligence = _intelligence
hunger = randf_range(20.0, 80.0)
energy = randf_range(40.0, 100.0)
position = Vector3(randf_range(-8.0, 8.0), 0.0, randf_range(-8.0, 8.0))
func simulate_tick() -> void:
hunger += 5.0
energy -= 2.0
if hunger > 75.0:
current_task = "eat"
hunger -= 25.0
elif energy < 30.0:
current_task = "rest"
energy += 20.0
elif profession == "farmer":
current_task = "gather_food"
elif profession == "woodcutter":
current_task = "gather_wood"
elif profession == "guard":
current_task = "patrol"
elif profession == "scholar":
current_task = "study"
else:
current_task = "wander"