From 0591c91ac002f9884b2ec19c7e7272369863bc05 Mon Sep 17 00:00:00 2001 From: Spencer Killen Date: Sat, 26 Sep 2026 22:00:53 -0600 Subject: [PATCH] . --- economy.gd | 35 +++++++++++++++++++++++++++++++++-- economy.tscn | 5 +++++ event.gd | 24 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/economy.gd b/economy.gd index 9c6822a..eda8b96 100644 --- a/economy.gd +++ b/economy.gd @@ -6,6 +6,19 @@ signal production_log(producer: Currency, p: Production) @export var currencies: Array[Production] @export var members: Array + +@onready var events: Array[Event] = load_events() + + +func load_events() -> Array[Event]: + var dir := "res://random events" + var es: Array[Event] = [] + for event_name in ResourceLoader.list_directory(dir): + var event: Event = load(dir + "/" + event_name) + es.push_back(event) + return es + + func get_currency(c: Currency) -> Production: sync_currency.call_deferred() for p in currencies: @@ -52,7 +65,7 @@ func produce(production: Production): var c := get_currency(production.currency) c.amount += production.amount -func simulate(): +func update_currencies(): productions_update.emit.call_deferred(currencies) for c in currencies: for p in c.currency.production: @@ -60,7 +73,18 @@ func simulate(): pp.currency = p.currency pp.amount = c.amount * p.amount produce(pp) - + +func simulate(): + update_currencies() + for e in events: + if e.requirements_satisfied() and e.will_happen(): + var outcome := e.outcome() + for o in outcome: + produce(o) + production_log.emit(null, o) + if e.timeline != null: + Dialogic.start(e.timeline) + func get_all_currencies_in(dir: StringName): var reses := ResourceLoader.list_directory(dir) @@ -77,4 +101,11 @@ func get_all_inanimate_currencies() -> Array: return get_all_currencies_in("res://currency/inanimate") func _ready() -> void: + %SimulateTickTimer.start() + update_currencies() + +func _on_timer_timeout() -> void: + if Dialogic.current_timeline != null: + %SimulateTickTimer.start() + return simulate() diff --git a/economy.tscn b/economy.tscn index af02a24..4e1b247 100644 --- a/economy.tscn +++ b/economy.tscn @@ -62,3 +62,8 @@ metadata/_custom_type_script = "uid://dddyxbkq0ienn" [node name="Economy" type="Node" unique_id=1950923383] script = ExtResource("1_csm0v") currencies = Array[ExtResource("2_tljx8")]([SubResource("Resource_g3220"), SubResource("Resource_bb1uu"), SubResource("Resource_vw3jp"), SubResource("Resource_xg8li"), SubResource("Resource_f6kxb"), SubResource("Resource_6u4g3"), SubResource("Resource_aqv3t"), SubResource("Resource_g2km3")]) + +[node name="SimulateTickTimer" type="Timer" parent="." unique_id=1726107261] +unique_name_in_owner = true + +[connection signal="timeout" from="SimulateTickTimer" to="." method="_on_timer_timeout"] diff --git a/event.gd b/event.gd index 9497d20..240772b 100644 --- a/event.gd +++ b/event.gd @@ -4,3 +4,27 @@ class_name Event @export var extra_mods: Array[Production] @export var timeline: DialogicTimeline @export var requirements: Array[Production] + +enum EventNature { + Random, + Certain, +} +@export var probability: float = 0.005 +@export var nature: EventNature = EventNature.Random + +func requirements_satisfied() -> bool: + for requirement in requirements: + if Economy.get_currency_amount(requirement.currency) < requirement.amount: + return false + return true + +func will_happen() -> bool: + if nature == EventNature.Certain: + return true + return randf() <= probability + +func outcome() -> Array[Production]: + var stuff: Array[Production] = [modified_resource] + stuff.append_array(extra_mods) + return stuff +