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

@ -15,6 +15,6 @@ item_menu = &"res://menus/Base Menu/root_menu.tres"
[resource]
script = ExtResource("2_u5q7w")
item_ids = Array[String](["BASE_FETCH_SELL_CANCEL", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM"])
item_ids = Array[String](["BASE_FETCH_BUY_SELL_CANCEL", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM", "BASE_SELL_ITEM"])
item_actions = Array[int]([3, 3, 3, 3, 3, 3, 3, 3])
item_data = Array[Resource("res://scripts/Classes/Menu/menu_resource.gd")]([SubResource("Resource_5pmle"), SubResource("Resource_81rsd"), SubResource("Resource_81rsd"), SubResource("Resource_81rsd"), SubResource("Resource_81rsd"), SubResource("Resource_81rsd"), SubResource("Resource_81rsd"), SubResource("Resource_81rsd")])

13
quests/test2.tres Normal file
View file

@ -0,0 +1,13 @@
[gd_resource type="Resource" script_class="Quest" load_steps=2 format=3 uid="uid://cgmsueq6k8jhj"]
[ext_resource type="Script" path="res://scripts/Classes/quest.gd" id="1_ixxvy"]
[resource]
script = ExtResource("1_ixxvy")
type = 1
progress_max = 1
reward_money = 50.0
restrictions = Array[int]([1])
data = {
"base_name": "BASE_NAME_0"
}

View file

@ -35,7 +35,7 @@ script = ExtResource("1_o387g")
[node name="HullHolder" type="Node" parent="."]
[node name="Hull" parent="HullHolder" instance=ExtResource("2_kthut")]
collision_mask = 1
collision_mask = 3
[node name="Engine" parent="." instance=ExtResource("3_ysnrn")]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://crneq2enhxsw5"]
[gd_scene load_steps=12 format=3 uid="uid://crneq2enhxsw5"]
[ext_resource type="PackedScene" uid="uid://bsnrcw64qr2hr" path="res://scenes/Star System/star_system_template.tscn" id="1_2ai1l"]
[ext_resource type="PackedScene" uid="uid://dk3nvl8f0v24e" path="res://scenes/Base/base_template.tscn" id="3_m5ica"]
@ -9,7 +9,8 @@
[ext_resource type="Resource" uid="uid://dlnl6w416qylo" path="res://items/Valuables/raw_materials.tres" id="6_mrd6j"]
[ext_resource type="PackedScene" uid="uid://dok3i8u5t1ka4" path="res://scenes/Ships/player_ship.tscn" id="7_jyplv"]
[ext_resource type="Resource" uid="uid://16xqvcrmuga6" path="res://items/Valuables/energy_cell.tres" id="7_x535v"]
[ext_resource type="Resource" uid="uid://6s288ijcp7f" path="res://quests/test1.tres" id="8_6tapm"]
[ext_resource type="Resource" uid="uid://6s288ijcp7f" path="res://quests/test1.tres" id="8_i1pnu"]
[ext_resource type="Resource" uid="uid://cgmsueq6k8jhj" path="res://quests/test2.tres" id="10_gy1bh"]
[node name="StarSystem" instance=ExtResource("1_2ai1l")]
width = 16384
@ -31,7 +32,12 @@ position = Vector2(19, 10)
position = Vector2(719, -559)
items_on_sell = Array[Resource("res://scripts/Classes/item.gd")]([ExtResource("4_xwim1"), ExtResource("5_oxe5h"), ExtResource("6_mrd6j")])
items_on_buy = Array[Resource("res://scripts/Classes/item.gd")]([ExtResource("7_x535v"), ExtResource("6_mrd6j")])
quest = ExtResource("8_6tapm")
quest = ExtResource("8_i1pnu")
[node name="Base2" parent="FactionPeaceful" index="1" instance=ExtResource("3_m5ica")]
position = Vector2(721, 785)
rotation = 3.14159
quest = ExtResource("10_gy1bh")
[node name="KamikazeShip" parent="FactionAggressive" index="0" instance=ExtResource("4_i6rbg")]
position = Vector2(-1712, -608)

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)

View file

@ -14,8 +14,10 @@ var selected_node: Node2D = null
var money: float = 1000.0
## Base which was requested to dock last
var docking_base: Base = null
## Items that player ship carries
var cargo = {}
## Current quest
var quest: Quest = null
func destroy():
super.destroy()
@ -23,3 +25,6 @@ func destroy():
docking_base.dock_ready()
docking_base = null
selected_node = null
if quest != null:
if Quest.Restriction.NoDeaths in quest.restrictions:
quest.fail()

View file

@ -42,6 +42,10 @@ func _process(_delta) -> void:
ship.shield.can_recharge_laser = false
func shoot() -> void:
if ship is PlayerShip:
if ship.quest != null:
if Quest.Restriction.NoWeapon in ship.quest.restrictions:
ship.quest.fail()
for spawner in spawner_points:
var projectile_instance = projectile.instantiate()
ProjectileContainer.instance.add_child(projectile_instance)

View file

@ -22,7 +22,7 @@ BASE_TAKE_QUEST_RECEIVED,Do you have any work for me?\n{answer},Есть ли у
BASE_TAKE_QUEST_FAILED,"No errands, I'm afraid.\nAnything else?\n> ","Боюсь, что нет.\nЧто-то ещё?\n> "
BASE_TAKE_QUEST_SUCCEED,"Yes, we have one errand, that you can do\n{quest_info}\nDo you agree?\n> ","Да, у нас есть одно дельце, которое некому поручить.\n{quest_info}\nВы согласны?\n> "
BASE_QUEST_INFO_LOCAL,Ask about current errand state,Узнать состояние текущего поручения
BASE_QUEST_INFO_RECEIVED,"Can I ask about my errand state?\nYou errand was:\n{answer}\nCurrent progress:\n{progress}\n> ","Можно узнать состояние моего поручения?\nВаше поручение звучало так:\n{answer}\nТекущий прогресс:\n{progress}\n> "
BASE_QUEST_INFO_RECEIVED,"Can I ask about my errand state?\nYou errand was given by: {given_by}\n{answer}\nCurrent progress:\n{progress}\n> ","Можно узнать состояние моего поручения?\nПоручение было выдано: {given_by}\n{answer}\nТекущий прогресс:\n{progress}\n> "
BASE_QUEST_ACCEPT_LOCAL,Accept,Принять
BASE_QUEST_ACCEPT_RECEIVED,"I agree\nGood, I'll assign that errand to you.\nAnything else?\n> ","Я согласен\nХорошо, назначаю Вам это поручение.\nЧто-то ещё?\n> "
BASE_QUEST_DECLINE_LOCAL,Decline,Отказаться
@ -30,9 +30,9 @@ BASE_QUEST_DECLINE_RECEIVED,"Maybe another time\nAs you wish.\nAnything else?\n>
BASE_QUEST_CANCEL_LOCAL,Reject the errand,Отказаться от поручения
BASE_QUEST_CANCEL_RECEIVED,"I want to reject the errand\nIn that case, you won't get any reward.\nAnything else?\n> ","Я хочу отказаться от поручения\nВ таком случае, никакой награды Вам не положено.\nЧто-то ещё?\n> "
BASE_QUEST_REWARD_LOCAL,Receive reward,Получить награду
BASE_QUEST_REWARD_RECEIVED,"I've completed the assignment, what about reward?\nOne moment...\nThe work is done, I see. The reward will be transferred now.\n[RECEIVED {reward} SPINOTS]\nAnything else?\n> ","Я выполнил ваше поручение, что насчёт награды?\nСекунду...\nДа, действительно, дело сделано, сейчас переведу вашу награду...\n[ПОЛУЧЕНО {reward} СПИНОТОВ]\nЧто-то ещё?\n> "
BASE_QUEST_ELIMINATION,"Eliminate {target_class} class ships: {amount}\n[ul]{restrictions}[/ul]","Уничтожьте корабли класса {target_class}: {amount}\n[ul]{restrictions}[/ul]"
BASE_QUEST_DELIVERY,"We'll entrust you with a valuable cargo. Deliver it to the base {base_name}\n[ul]{restrictions}[/ul]","Мы поручим вам ценный груз. Доставьте его на базу {base_name}.\n[ul]{restrictions}[/ul]"
BASE_QUEST_REWARD_RECEIVED,"I've completed the assignment, what about reward?\nOne moment...\nThe work is done, I see. The reward will be transferred now.\n[RECEIVED SPINOTS: {reward}]\nAnything else?\n> ","Я выполнил ваше поручение, что насчёт награды?\nСекунду...\nДа, действительно, дело сделано, сейчас переведу вашу награду...\n[ПОЛУЧЕНЫ СПИНОТЫ: {reward}]\nЧто-то ещё?\n> "
BASE_QUEST_ELIMINATION,"Eliminate {target_class} class ships: {amount}\n[ul]{restrictions}[/ul]\Reward: {reward}","Уничтожьте корабли класса {target_class}: {amount}\n[ul]{restrictions}[/ul]\nНаграда: {reward}"
BASE_QUEST_DELIVERY,"We'll entrust you with a valuable cargo. Deliver it to the base {base_name}\n[ul]{restrictions}[/ul]\nReward: {reward}","Мы поручим вам ценный груз. Доставьте его на базу {base_name}.\n[ul]{restrictions}[/ul]\nНаграда: {reward}"
BASE_QUEST_RESTRICTION_NO_DEATHS,"The reward is nullified if your ship is destroyed","При разрушении Вашего корабля награда аннулируется"
BASE_QUEST_RESTRICTION_NO_WEAPON,"Usage of weaponry during errand is prohibited","Использовать вооружение корабля в процессе выполнения поручения запрещено"
BASE_QUEST_RESTRICTION_TIMER,"You have {time} s. to complete the errand","У вас есть {time} сек. на выполнение поручения"

1 en ru
22 BASE_TAKE_QUEST_FAILED No errands, I'm afraid.\nAnything else?\n> Боюсь, что нет.\nЧто-то ещё?\n>
23 BASE_TAKE_QUEST_SUCCEED Yes, we have one errand, that you can do\n{quest_info}\nDo you agree?\n> Да, у нас есть одно дельце, которое некому поручить.\n{quest_info}\nВы согласны?\n>
24 BASE_QUEST_INFO_LOCAL Ask about current errand state Узнать состояние текущего поручения
25 BASE_QUEST_INFO_RECEIVED Can I ask about my errand state?\nYou errand was:\n{answer}\nCurrent progress:\n{progress}\n> Can I ask about my errand state?\nYou errand was given by: {given_by}\n{answer}\nCurrent progress:\n{progress}\n> Можно узнать состояние моего поручения?\nВаше поручение звучало так:\n{answer}\nТекущий прогресс:\n{progress}\n> Можно узнать состояние моего поручения?\nПоручение было выдано: {given_by}\n{answer}\nТекущий прогресс:\n{progress}\n>
26 BASE_QUEST_ACCEPT_LOCAL Accept Принять
27 BASE_QUEST_ACCEPT_RECEIVED I agree\nGood, I'll assign that errand to you.\nAnything else?\n> Я согласен\nХорошо, назначаю Вам это поручение.\nЧто-то ещё?\n>
28 BASE_QUEST_DECLINE_LOCAL Decline Отказаться
30 BASE_QUEST_CANCEL_LOCAL Reject the errand Отказаться от поручения
31 BASE_QUEST_CANCEL_RECEIVED I want to reject the errand\nIn that case, you won't get any reward.\nAnything else?\n> Я хочу отказаться от поручения\nВ таком случае, никакой награды Вам не положено.\nЧто-то ещё?\n>
32 BASE_QUEST_REWARD_LOCAL Receive reward Получить награду
33 BASE_QUEST_REWARD_RECEIVED I've completed the assignment, what about reward?\nOne moment...\nThe work is done, I see. The reward will be transferred now.\n[RECEIVED {reward} SPINOTS]\nAnything else?\n> I've completed the assignment, what about reward?\nOne moment...\nThe work is done, I see. The reward will be transferred now.\n[RECEIVED SPINOTS: {reward}]\nAnything else?\n> Я выполнил ваше поручение, что насчёт награды?\nСекунду...\nДа, действительно, дело сделано, сейчас переведу вашу награду...\n[ПОЛУЧЕНО {reward} СПИНОТОВ]\nЧто-то ещё?\n> Я выполнил ваше поручение, что насчёт награды?\nСекунду...\nДа, действительно, дело сделано, сейчас переведу вашу награду...\n[ПОЛУЧЕНЫ СПИНОТЫ: {reward}]\nЧто-то ещё?\n>
34 BASE_QUEST_ELIMINATION Eliminate {target_class} class ships: {amount}\n[ul]{restrictions}[/ul] Eliminate {target_class} class ships: {amount}\n[ul]{restrictions}[/ul]\Reward: {reward} Уничтожьте корабли класса {target_class}: {amount}\n[ul]{restrictions}[/ul] Уничтожьте корабли класса {target_class}: {amount}\n[ul]{restrictions}[/ul]\nНаграда: {reward}
35 BASE_QUEST_DELIVERY We'll entrust you with a valuable cargo. Deliver it to the base {base_name}\n[ul]{restrictions}[/ul] We'll entrust you with a valuable cargo. Deliver it to the base {base_name}\n[ul]{restrictions}[/ul]\nReward: {reward} Мы поручим вам ценный груз. Доставьте его на базу {base_name}.\n[ul]{restrictions}[/ul] Мы поручим вам ценный груз. Доставьте его на базу {base_name}.\n[ul]{restrictions}[/ul]\nНаграда: {reward}
36 BASE_QUEST_RESTRICTION_NO_DEATHS The reward is nullified if your ship is destroyed При разрушении Вашего корабля награда аннулируется
37 BASE_QUEST_RESTRICTION_NO_WEAPON Usage of weaponry during errand is prohibited Использовать вооружение корабля в процессе выполнения поручения запрещено
38 BASE_QUEST_RESTRICTION_TIMER You have {time} s. to complete the errand У вас есть {time} сек. на выполнение поручения