From a041fe0a389e4c961d808b1d4013ac0fd6d1b932 Mon Sep 17 00:00:00 2001 From: PHIDIAS Date: Tue, 4 Feb 2025 06:43:40 +0900 Subject: [PATCH] Allow Waterfill with Recipe (#364) * Update waterfill.lua * Update en.cfg * Update zh-CN.cfg * Update zh-TW.cfg * Update zh-CN.cfg * Update zh-TW.cfg * Update waterfill.lua * Update waterfill.lua * Update waterfill.lua * Update tool.lua * Update waterfill.lua --- exp_legacy/module/modules/gui/tool.lua | 13 +++++--- exp_scenario/module/commands/waterfill.lua | 38 +++++++++++++++++----- exp_scenario/module/locale/en.cfg | 2 +- exp_scenario/module/locale/zh-CN.cfg | 2 +- exp_scenario/module/locale/zh-TW.cfg | 2 +- 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/exp_legacy/module/modules/gui/tool.lua b/exp_legacy/module/modules/gui/tool.lua index c6c67acb..6ccfc7ff 100644 --- a/exp_legacy/module/modules/gui/tool.lua +++ b/exp_legacy/module/modules/gui/tool.lua @@ -83,11 +83,16 @@ local tool_gui_waterfill_b = Gui.element("tool_gui_waterfill_b") if Selection.is_selecting(player, SelectionWaterfillArea) then Selection.stop(player) return player.print{ "exp-commands_waterfill.exit" } - elseif player.get_item_count("cliff-explosives") == 0 then - return player.print{ "exp-commands_waterfill.requires-explosives" } else - Selection.start(player, SelectionWaterfillArea) - return player.print{ "exp-commands_waterfill.enter" } + local item_count_cliff = player.get_item_count("cliff-explosives") + local item_count_craft = math.min(math.floor(player.get_item_count("explosives") / 10), player.get_item_count("barrel"), player.get_item_count("grenade")) + local item_count_total = item_count_cliff + item_count_craft + if item_count_total == 0 then + return player.print{ "exp-commands_waterfill.requires-explosives" } + else + Selection.start(player, SelectionWaterfillArea) + return player.print{ "exp-commands_waterfill.enter" } + end end end) diff --git a/exp_scenario/module/commands/waterfill.lua b/exp_scenario/module/commands/waterfill.lua index d748356f..a3c9d602 100644 --- a/exp_scenario/module/commands/waterfill.lua +++ b/exp_scenario/module/commands/waterfill.lua @@ -13,11 +13,16 @@ Commands.new("waterfill", { "exp-commands_waterfill.description" }) if Selection.is_selecting(player, SelectionName) then Selection.stop(player) return Commands.status.success{ "exp-commands_waterfill.exit" } - elseif player.get_item_count("cliff-explosives") == 0 then - return Commands.status.error{ "exp-commands_waterfill.requires-explosives" } else - Selection.start(player, SelectionName) - return Commands.status.success{ "exp-commands_waterfill.enter" } + local item_count_cliff = player.get_item_count("cliff-explosives") + local item_count_craft = math.min(math.floor(player.get_item_count("explosives") / 10), player.get_item_count("barrel"), player.get_item_count("grenade")) + local item_count_total = item_count_cliff + item_count_craft + if item_count_total == 0 then + return player.print{ "exp-commands_waterfill.requires-explosives" } + else + Selection.start(player, SelectionName) + return player.print{ "exp-commands_waterfill.enter" } + end end end) @@ -39,9 +44,12 @@ Selection.on_selection(SelectionName, function(event) return end - local item_count = player.get_item_count("cliff-explosives") - if item_count < area_size then - player.print({ "exp-commands_waterfill.too-few-explosives", area_size, item_count }, Commands.print_settings.error) + local item_count_cliff = player.get_item_count("cliff-explosives") + local item_count_craft = math.min(math.floor(player.get_item_count("explosives") / 10), player.get_item_count("barrel"), player.get_item_count("grenade")) + local item_count_total = item_count_cliff + item_count_craft + + if item_count_total < area_size then + player.print({ "exp-commands_waterfill.too-few-explosives", area_size, item_count_total }, Commands.print_settings.error) return end @@ -59,7 +67,21 @@ Selection.on_selection(SelectionName, function(event) surface.set_tiles(tiles_to_make, true, "abort_on_collision", true, false, player, 0) local remaining_tiles = surface.count_tiles_filtered{ area = area, name = "water-mud" } - player.remove_item{ name = "cliff-explosives", count = tile_count - remaining_tiles } + local t_diff = tile_count - remaining_tiles + + if item_count_cliff >= t_diff then + player.remove_item{ name = "cliff-explosives", count = t_diff } + else + if item_count_cliff > 0 then + player.remove_item{ name = "cliff-explosives", count = item_count_cliff } + end + local item_count_needed = t_diff - item_count_cliff + if item_count_needed > 0 then + player.remove_item{ name = "explosives", count = 10 * item_count_needed } + player.remove_item{ name = "barrel", count = item_count_needed } + player.remove_item{ name = "grenade", count = item_count_needed } + end + end if remaining_tiles > 0 then player.print({ "exp-commands_waterfill.part-complete", tile_count, remaining_tiles }, Commands.print_settings.default) diff --git a/exp_scenario/module/locale/en.cfg b/exp_scenario/module/locale/en.cfg index 2dd747e4..1b928702 100644 --- a/exp_scenario/module/locale/en.cfg +++ b/exp_scenario/module/locale/en.cfg @@ -278,6 +278,6 @@ enter=Entered waterfill selection mode, select the area to fill with water. exit=Exited waterfill selection mode. nauvis-only=Can only waterfill on Nauvis, this may change in the future. area-too-large=Selected area is too large, must be less than __1__ tiles, selected __2__. -too-few-explosives=Requires __1__ __ITEM__cliff-explosives__ you have __2__. +too-few-explosives=Requires __1__ __ITEM__cliff-explosives__ or its ingredients, you have __2__. part-complete=__1__ tiles were filled with water, but entities are blocking __2__ tiles. complete=__1__ tiles were filled with water. diff --git a/exp_scenario/module/locale/zh-CN.cfg b/exp_scenario/module/locale/zh-CN.cfg index bc4a69a3..09cc70d3 100644 --- a/exp_scenario/module/locale/zh-CN.cfg +++ b/exp_scenario/module/locale/zh-CN.cfg @@ -278,6 +278,6 @@ enter=現在進入挖水區域選擇 exit=已進入挖水區域選擇 nauvis-only=只可在地星上填水,之後可能會再改變。 area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格。 -too-few-explosives=需要 __1__ 個 __ITEM__cliff-explosives__,你現在有 __2__ 個。 +too-few-explosives=需要 __1__ 個 __ITEM__cliff-explosives__ 或其材料,你現在有 __2__ 個。 part-complete=__1__ 格已填水,但有 __2__ 格有東西擋著。 complete=__1__ 格已經轉換好。 diff --git a/exp_scenario/module/locale/zh-TW.cfg b/exp_scenario/module/locale/zh-TW.cfg index bc4a69a3..09cc70d3 100644 --- a/exp_scenario/module/locale/zh-TW.cfg +++ b/exp_scenario/module/locale/zh-TW.cfg @@ -278,6 +278,6 @@ enter=現在進入挖水區域選擇 exit=已進入挖水區域選擇 nauvis-only=只可在地星上填水,之後可能會再改變。 area-too-large=區域太大了,需少過 __1__ 格,你選了 __2__ 格。 -too-few-explosives=需要 __1__ 個 __ITEM__cliff-explosives__,你現在有 __2__ 個。 +too-few-explosives=需要 __1__ 個 __ITEM__cliff-explosives__ 或其材料,你現在有 __2__ 個。 part-complete=__1__ 格已填水,但有 __2__ 格有東西擋著。 complete=__1__ 格已經轉換好。