From c6d8ae8be0e48de85400b2986b80f4cfbd3ca593 Mon Sep 17 00:00:00 2001 From: 2ndbeam <166764593+2ndbeam@users.noreply.github.com> Date: Fri, 31 May 2024 11:23:15 +0300 Subject: [PATCH] Quest taking and rejecting --- menus/Base Menu/BuySell/menu_sell_amount.tres | 2 +- quests/test2.tres | 13 +++++++++++ scenes/Ships/NPC Ships/shooter_ship.tscn | 2 +- scenes/Star System/star_system_debug.tscn | 12 +++++++--- scripts/Base/Menu/dialogue.gd | 11 +++++++++ scripts/Base/Menu/quest.gd | 21 ++++++++++++++++-- scripts/Base/actions_menu.gd | 21 ++++++++++++++++-- scripts/Ship/player_ship.gd | 7 +++++- scripts/Ship/weapon.gd | 4 ++++ translations/base_dialogue.csv | 8 +++---- translations/base_dialogue.en.translation | Bin 2694 -> 2750 bytes translations/base_dialogue.ru.translation | Bin 4257 -> 4309 bytes 12 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 quests/test2.tres diff --git a/menus/Base Menu/BuySell/menu_sell_amount.tres b/menus/Base Menu/BuySell/menu_sell_amount.tres index b7fef61..c708ca5 100644 --- a/menus/Base Menu/BuySell/menu_sell_amount.tres +++ b/menus/Base Menu/BuySell/menu_sell_amount.tres @@ -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")]) diff --git a/quests/test2.tres b/quests/test2.tres new file mode 100644 index 0000000..d33391b --- /dev/null +++ b/quests/test2.tres @@ -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" +} diff --git a/scenes/Ships/NPC Ships/shooter_ship.tscn b/scenes/Ships/NPC Ships/shooter_ship.tscn index c491a5c..bcac0af 100644 --- a/scenes/Ships/NPC Ships/shooter_ship.tscn +++ b/scenes/Ships/NPC Ships/shooter_ship.tscn @@ -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")] diff --git a/scenes/Star System/star_system_debug.tscn b/scenes/Star System/star_system_debug.tscn index 8a681c9..a667e61 100644 --- a/scenes/Star System/star_system_debug.tscn +++ b/scenes/Star System/star_system_debug.tscn @@ -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) diff --git a/scripts/Base/Menu/dialogue.gd b/scripts/Base/Menu/dialogue.gd index df35ccd..2445aa0 100644 --- a/scripts/Base/Menu/dialogue.gd +++ b/scripts/Base/Menu/dialogue.gd @@ -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) diff --git a/scripts/Base/Menu/quest.gd b/scripts/Base/Menu/quest.gd index 30dc907..45718e9 100644 --- a/scripts/Base/Menu/quest.gd +++ b/scripts/Base/Menu/quest.gd @@ -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 diff --git a/scripts/Base/actions_menu.gd b/scripts/Base/actions_menu.gd index 82d606d..0fbcb72 100644 --- a/scripts/Base/actions_menu.gd +++ b/scripts/Base/actions_menu.gd @@ -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) diff --git a/scripts/Ship/player_ship.gd b/scripts/Ship/player_ship.gd index ca84b9e..8f925f0 100644 --- a/scripts/Ship/player_ship.gd +++ b/scripts/Ship/player_ship.gd @@ -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() diff --git a/scripts/Ship/weapon.gd b/scripts/Ship/weapon.gd index 42300aa..37f3083 100644 --- a/scripts/Ship/weapon.gd +++ b/scripts/Ship/weapon.gd @@ -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) diff --git a/translations/base_dialogue.csv b/translations/base_dialogue.csv index b0902d0..f4f1249 100644 --- a/translations/base_dialogue.csv +++ b/translations/base_dialogue.csv @@ -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} сек. на выполнение поручения" diff --git a/translations/base_dialogue.en.translation b/translations/base_dialogue.en.translation index fdb9fdf7018d3a01de146ce8d6403c761008bea9..1e0fc309f512db90d8cf15068fd41ac2d9abf2bb 100644 GIT binary patch delta 328 zcmZn@-6y(1nvpff*eo$|vjQU+7NnG$cP_!N>vIdA*&c9o0KlwXTJ7fIh zdS-FPsL9ir?IojtD%gRt96$ju>pLbP2J2nt>;G9X{HwO!W&AI`{$K58 zYYt;Zk^k($0iJ&TA;BOi#cMng{~2p1H*oriFvZ3MF#-8tJurz2oL-{;Vh#Uc%E)rX O@~s3_?Jh6UCI+GC7^eS=AlL zivnUMAZ7&OUujv5l0cP)K(+%A`=}WI51f3SNnG$aP_z~(vKok4&c9pBIr%$NJEP|0 zdS-D(mC4hY?Ipc{D%gRt96pLc=Hew diff --git a/translations/base_dialogue.ru.translation b/translations/base_dialogue.ru.translation index 7882737b1ec88b226e574f0c768e998fd45abec0..f9fccff0012b69d18dbbb47b81a01c8cfab92427 100644 GIT binary patch delta 381 zcmZ3ecvW$OG$X5NS#e4EW(7u3M#kpJW=#5mf7uuqbQvHxCyFUiYjPQrv+8!B2naI) zF(VNFO3P}L1**&evO(BK#rXfc$@iGVg+8$}FvtOwfH2GXcWe2%C$lrRF=kHgV-{zO zo4kzKUa}LYQ52{Ng#Ry>x+K8Kz)%fjS5N-O?9a$I*^gzpRyR;=22c!yVU}*ya*MhI zG+qHH2Esz0Ue+sfO_pc1V$9wg#k!Q$c>aZb7aJ}%Uu?gy^}^l@J1%ThxUlhJ_l4aT z_9>J+mw|FFvWVcC!ID2eb5Qg$oNW%)c<>!rTkHUf`Wsb E0V|n;J^%m! delta 327 zcmcbrxKMF}G$X5pahh@IW(7u3M#g~2W=#5mzu6cVbQvHxCyFUiV{#djv+7o$2naI) zF(VNFO3P}L2CB>fvO(BK#rXf6$@iGVg+8z|FvtUyfH2GXcWdu(O=f3qV>FxG$1KjM zJ$V_ky<|I3qbN`l2>)L$b%~#ofguUVPMZ9W*`JYTvLDNGtwNw!Jx~mUVU}*ya*MhE zG+qHH2Esz0UeabfO-c^4J| j@ub+v=eQ*&=kX;>e$H3Fxt`yXkq77ka2Nyy2RQ=(`o3tP