Quest taking and rejecting

This commit is contained in:
2ndbeam 2024-05-31 11:23:15 +03:00
commit c6d8ae8be0
12 changed files with 87 additions and 14 deletions

View file

@ -10,6 +10,10 @@ const BUY_ITEM = "BASE_BUY_ITEM"
const SELL_ITEM = "BASE_SELL_ITEM"
## This message will trigger quest node to make answer format
const TAKE_QUEST = "BASE_TAKE_QUEST"
## This message will trigger quest node to assign quest to player
const ACCEPT_QUEST = "BASE_QUEST_ACCEPT"
## This message will trigger quest node to take quest from player
const CANCEL_QUEST = "BASE_QUEST_CANCEL"
@onready var dialogue = $DialogueView
@onready var buy_sell = $"../../BuySell"
@ -45,6 +49,13 @@ func send_message(msg: Message):
format["item_name"] = item_name
TAKE_QUEST:
format["answer"] = quest.answer
if quest.answer == tr(quest.NO_QUEST):
get_tree().create_timer(0.05).timeout.connect(actions_menu.transit_menu.bind(0))
ACCEPT_QUEST:
actions_menu.player_ship.quest = quest.assign_to_player()
CANCEL_QUEST:
actions_menu.player_ship.quest = null
var new_msg = tr(msg.fact + "_RECEIVED").format(format)
var old_len = len(dialogue.get_parsed_text())
dialogue.append_text(new_msg)

View file

@ -2,14 +2,22 @@ extends Node
var base: Base
var quest: Quest
## Quest this node holds
var quest: Quest:
set(value):
has_quest = value != null
quest = value
## Const of answer when quest is null
const NO_QUEST = "BASE_TAKE_QUEST_FAILED"
## Const of answer when quest is not null
const HAS_QUEST = "BASE_TAKE_QUEST_SUCCEED"
## Const of quest types
const QUEST_TYPE = {
Quest.Type.Elimination: "BASE_QUEST_ELIMINATION",
Quest.Type.Delivery: "BASE_QUEST_DELIVERY"
}
## Const of restrictions
const RESTRICTIONS = {
Quest.Restriction.NoDeaths: "BASE_QUEST_RESTRICTION_NO_DEATHS",
Quest.Restriction.NoWeapon: "BASE_QUEST_RESTRICTION_NO_WEAPON",
@ -27,7 +35,7 @@ func fetch_quest():
make_answer(quest)
func make_answer(quest: Quest):
has_quest = quest != null
var has_quest = quest != null
if !has_quest:
answer = tr(NO_QUEST)
return
@ -42,6 +50,15 @@ func make_answer(quest: Quest):
for restriction in quest.restrictions:
restrictions += tr(RESTRICTIONS[restriction]) + "\n"
quest_format["restrictions"] = restrictions
quest_format["reward"] = quest.reward_money
var quest_info = tr(QUEST_TYPE[quest.type]).format(quest_format)
var final_format = {"quest_info": quest_info}
answer = tr(HAS_QUEST).format(final_format)
## Assigns quest to player by returning it and nullifying self quest
func assign_to_player() -> Quest:
quest.status = Quest.Status.Taken
var temp_quest = quest
quest = null
make_answer(quest)
return temp_quest

View file

@ -26,6 +26,14 @@ const BASE_BUY_SELL = "BASE_BUY_SELL"
const BASE_BUY_ITEM = "BASE_BUY_ITEM"
## Button to sell amount of item
const BASE_SELL_ITEM = "BASE_SELL_ITEM"
## Button to fetch quest
const BASE_TAKE_QUEST = "BASE_TAKE_QUEST"
## Button to get current quest info
const BASE_QUEST_INFO = "BASE_QUEST_INFO"
## Button to cancel current quest
const BASE_QUEST_CANCEL = "BASE_QUEST_CANCEL"
## Button to get reward from quest
const BASE_QUEST_REWARD = "BASE_QUEST_REWARD"
## Null button ID
const NULL = "NULL"
@ -44,18 +52,19 @@ var buy_sell_selected_item: int = -1
var buy_sell_amount = 0
func _ready():
load_menu()
get_tree().create_timer(0.05).timeout.connect(post_ready)
func post_ready():
base = get_parent().get_parent().get_parent().base
player_ship = base.player_ship
load_menu()
## Called when menu is changed
func load_menu():
var format = {}
# iterating through all actions
for i in range(len(menu.item_ids)):
actions[i].disabled = false
match menu.item_ids[i]:
BASE_BUY_SELL:
if i <= buy_sell_options:
@ -67,7 +76,15 @@ func load_menu():
format = get_buy_sell_button_format(buy_sell_selected_item, i)
BASE_SELL_ITEM:
format = get_buy_sell_button_format(buy_sell_selected_item, i)
actions[i].disabled = false
BASE_TAKE_QUEST:
actions[i].disabled = player_ship.quest != null
BASE_QUEST_INFO:
actions[i].disabled = player_ship.quest == null
BASE_QUEST_CANCEL:
actions[i].disabled = player_ship.quest.status != Quest.Status.Taken
BASE_QUEST_REWARD:
actions[i].disabled = player_ship.quest.status != Quest.Status.Reward
# disconnect previous action
if actions[i] is TransitButton:
actions[i].button_up.disconnect(transit_menu)