Quest system base

This commit is contained in:
2ndbeam 2024-05-25 22:32:48 +03:00
commit 8a40de576e
20 changed files with 178 additions and 9 deletions

View file

@ -8,10 +8,13 @@ const SELL_FETCH = "BASE_FETCH_SELL"
const BUY_ITEM = "BASE_BUY_ITEM"
## This message will trigger dialogue to get selected item data
const SELL_ITEM = "BASE_SELL_ITEM"
## This message will trigger quest node to make answer format
const TAKE_QUEST = "BASE_TAKE_QUEST"
@onready var dialogue = $DialogueView
@onready var buy_sell = $"../../BuySell"
@onready var actions_menu = $"../Actions/ActionsMenu"
@onready var quest = $"../../Quest"
func _ready():
var tween = create_tween() \
@ -40,6 +43,8 @@ func send_message(msg: Message):
var item_name = list[id].name
format["amount"] = actions_menu.buy_sell_amount
format["item_name"] = item_name
TAKE_QUEST:
format["answer"] = quest.answer
var new_msg = tr(msg.fact + "_RECEIVED").format(format)
var old_len = len(dialogue.get_parsed_text())
dialogue.append_text(new_msg)

View file

@ -4,9 +4,44 @@ var base: Base
var quest: Quest
const NO_QUEST = "BASE_TAKE_QUEST_FAILED"
const HAS_QUEST = "BASE_TAKE_QUEST_SUCCEED"
const QUEST_TYPE = {
Quest.Type.Elimination: "BASE_QUEST_ELIMINATION",
Quest.Type.Delivery: "BASE_QUEST_DELIVERY"
}
const RESTRICTIONS = {
Quest.Restriction.NoDeaths: "BASE_QUEST_RESTRICTION_NO_DEATHS",
Quest.Restriction.NoWeapon: "BASE_QUEST_RESTRICTION_NO_WEAPON",
Quest.Restriction.Timer: "BASE_QUEST_RESTRICTION_TIMER"
}
var has_quest: bool = false
var answer: String = ""
func _ready():
get_tree().create_timer(0.05).timeout.connect(fetch_quest)
func fetch_quest():
base = get_parent().base
quest = base.quest
make_answer(quest)
func make_answer(quest: Quest):
has_quest = quest != null
if !has_quest:
answer = tr(NO_QUEST)
return
var quest_format = {}
match quest.type:
Quest.Type.Elimination:
quest_format["amount"] = quest.progress_max
quest_format["target_class"] = tr(quest.data["target_class"])
Quest.Type.Delivery:
quest_format["base_name"] = tr(quest.data["base_name"])
var restrictions = ""
for restriction in quest.restrictions:
restrictions += tr(RESTRICTIONS[restriction]) + "\n"
quest_format["restrictions"] = restrictions
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)

View file

@ -41,11 +41,11 @@ enum Status{
var progress : int = 0:
set(value):
if value >= progress_max:
quest_ended.emit(true)
end()
@export var reward_money : float
@export var restrictions : Array[Restriction] = []
@export var data : Dictionary = {}
@export var status: Status
var status: Status = Status.Idle
## Emits when quest was given to player
signal quest_added
@ -55,7 +55,7 @@ signal quest_ended
signal quest_failed
## Creates quest with given parameters
static func create(type : Type, progress_max : int, reward_money : float, restrictions : Array[Restriction] = [], data : Dictionary = {}) -> void:
static func create(type : Type, progress_max : int, reward_money : float, restrictions : Array[Restriction] = [], data : Dictionary = {}) -> Quest:
var quest = Quest.new()
quest.type = type
quest.progress_max = progress_max
@ -64,6 +64,7 @@ static func create(type : Type, progress_max : int, reward_money : float, restri
quest.data = data
quest.status = Status.Taken
quest.quest_added.emit(quest)
return quest
## Progress by quest
func do_progress() -> void:
@ -74,6 +75,14 @@ func fail() -> void:
quest_failed.emit(false)
status = Status.Idle
func end() -> void:
quest_ended.emit(true)
status = Status.Reward
func reward() -> float:
status = Status.Idle
return reward_money
## Trigger restriction
func trigger_restriction(restriction: Restriction) -> void:
if restrictions.has(restriction):