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

@ -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