66 lines
1.8 KiB
GDScript
66 lines
1.8 KiB
GDScript
extends Letter
|
|
class_name Counteroffer
|
|
|
|
@export var request: Production
|
|
|
|
|
|
func sync():
|
|
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
|
|
var supply := Economy.get_currency_amount(request.currency)
|
|
Dialogic.VAR.for_timeline_calls.economy_amount = supply
|
|
|
|
|
|
func start():
|
|
sync()
|
|
Dialogic.start(timeline)
|
|
await Dialogic.timeline_ended
|
|
reply()
|
|
|
|
func reply():
|
|
sync()
|
|
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):
|
|
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)
|