everything_has_a_price_jam/letters/counteroffer.gd
2026-09-26 15:02:19 -06:00

57 lines
1.7 KiB
GDScript

extends Letter
@export var request: Production
func start():
Dialogic.VAR.for_timeline_calls.requested_currency = request.currency.name
Dialogic.VAR.for_timeline_calls.requested_amount = request.amount
Dialogic.VAR.for_timeline_calls.requestee_class = source.name
Dialogic.VAR.for_timeline_calls.requestee_name = "a " + source.name
Dialogic.start(timeline)
await Dialogic.timeline_ended
var response: int
while true:
Dialogic.start(preload("res://counteroffer_response.dtl"))
await Dialogic.timeline_ended
response = int(Dialogic.VAR.get_variable("COUNTEROFFER_REPONSE"))
if response == 0:
# Accept
if not Economy.can_consume(request):
var supply := Economy.get_currency_amount(request.currency)
Dialogic.VAR.for_timeline_calls.economy_amount = supply
Dialogic.start(preload("res://cannot_consume.dtl"))
await Dialogic.timeline_ended
continue
var request_neg = request.duplicate()
request_neg.amount = -request_neg.amount
Economy.produce(request_neg)
Economy.production_log.emit(null, request_neg)
break
#elif response == 1:
## Reject
#pass
elif response == 1 or response == 2:
# Execute
var execution := Production.new()
execution.currency = source
execution.amount = -1
Economy.produce(execution)
Economy.production_log.emit(null, execution)
break
elif response == 3:
# Cancel
break
else:
push_error("Got unknown response: ", response)
return
if response == 2:
var corpse := Production.new()
corpse.currency = preload("res://currency/inanimate/corpse.tres")
corpse.amount = 1
Economy.produce(corpse)
Economy.production_log.emit(null, corpse)
if response != 3:
GameState.remove_letter.emit(self)