.
This commit is contained in:
parent
a462970c67
commit
0591c91ac0
3 changed files with 62 additions and 2 deletions
33
economy.gd
33
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:
|
||||
|
|
@ -61,6 +74,17 @@ func simulate():
|
|||
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()
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
24
event.gd
24
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue