From 37383993485c610827cb862b78dddd54242deb4d Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Sun, 26 Nov 2023 21:25:43 -0800 Subject: [PATCH] Factorio: Add an Allow Collect Option --- Options.py | 5 ++ worlds/alttp/Options.py | 9 +--- worlds/factorio/Options.py | 5 +- worlds/factorio/data/mod_template/control.lua | 46 +++++++++++++++++-- .../data/mod_template/locale/en/locale.cfg | 4 +- .../factorio/data/mod_template/settings.lua | 10 ++++ 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/Options.py b/Options.py index 2e3927aae3..2465195a43 100644 --- a/Options.py +++ b/Options.py @@ -1033,6 +1033,11 @@ class DeathLink(Toggle): display_name = "Death Link" +class AllowCollect(DefaultOnToggle): + """Allows checks in your world to be automatically marked as collected when !collect is run.""" + display_name = "Allow Collect" + + class ItemLinks(OptionList): """Share part of your item pool with other players.""" display_name = "Item Links" diff --git a/worlds/alttp/Options.py b/worlds/alttp/Options.py index a89a9adb83..a5601eb82f 100644 --- a/worlds/alttp/Options.py +++ b/worlds/alttp/Options.py @@ -1,7 +1,8 @@ import typing from BaseClasses import MultiWorld -from Options import Choice, Range, Option, Toggle, DefaultOnToggle, DeathLink, StartInventoryPool, PlandoBosses +from Options import Choice, Range, Option, Toggle, DefaultOnToggle, DeathLink, AllowCollect, StartInventoryPool, \ + PlandoBosses class Logic(Choice): @@ -426,12 +427,6 @@ class BeemizerTrapChance(BeemizerRange): display_name = "Beemizer Trap Chance" -class AllowCollect(Toggle): - """Allows for !collect / co-op to auto-open chests containing items for other players. - Off by default, because it currently crashes on real hardware.""" - display_name = "Allow Collection of checks for other players" - - alttp_options: typing.Dict[str, type(Option)] = { "crystals_needed_for_gt": CrystalsTower, "crystals_needed_for_ganon": CrystalsGanon, diff --git a/worlds/factorio/Options.py b/worlds/factorio/Options.py index 18eee67e03..da99f79e8d 100644 --- a/worlds/factorio/Options.py +++ b/worlds/factorio/Options.py @@ -2,8 +2,8 @@ from __future__ import annotations import typing import datetime -from Options import Choice, OptionDict, OptionSet, ItemDict, Option, DefaultOnToggle, Range, DeathLink, Toggle, \ - StartInventoryPool +from Options import Choice, OptionDict, OptionSet, ItemDict, Option, DefaultOnToggle, Range, DeathLink, AllowCollect, \ + Toggle, StartInventoryPool from schema import Schema, Optional, And, Or # schema helpers @@ -454,6 +454,7 @@ factorio_options: typing.Dict[str, type(Option)] = { "evolution_traps": EvolutionTrapCount, "evolution_trap_increase": EvolutionTrapIncrease, "death_link": DeathLink, + "allow_collect": AllowCollect, "energy_link": EnergyLink, "start_inventory_from_pool": StartInventoryPool, } diff --git a/worlds/factorio/data/mod_template/control.lua b/worlds/factorio/data/mod_template/control.lua index 8ce0b45a5f..a48e45c04f 100644 --- a/worlds/factorio/data/mod_template/control.lua +++ b/worlds/factorio/data/mod_template/control.lua @@ -11,6 +11,7 @@ TRAP_EVO_FACTOR = {{ evolution_trap_increase }} / 100 MAX_SCIENCE_PACK = {{ max_science_pack }} GOAL = {{ goal }} ARCHIPELAGO_DEATH_LINK_SETTING = "archipelago-death-link-{{ slot_player }}-{{ seed_name }}" +ARCHIPELAGO_ALLOW_COLLECT_SETTING = "archipelago-allow-collect-{{ slot_player }}-{{ seed_name }}" ENERGY_INCREMENT = {{ energy_link * 10000000 }} ENERGY_LINK_EFFICIENCY = 0.75 @@ -20,6 +21,12 @@ else DEATH_LINK = 0 end +if settings.global[ARCHIPELAGO_ALLOW_COLLECT_SETTING].value then + ALLOW_COLLECT = 1 +else + ALLOW_COLLECT = 0 +end + CURRENTLY_DEATH_LOCK = 0 {% if chunk_shuffle %} @@ -257,6 +264,26 @@ function on_runtime_mod_setting_changed(event) dumpInfo(force) end end + if event.setting == ARCHIPELAGO_ALLOW_COLLECT_SETTING then + local force = game.forces["player"] + if global.received_tech == nil then + global.received_tech = {} + end + if settings.global[ARCHIPELAGO_ALLOW_COLLECT_SETTING].value then + ALLOW_COLLECT = 1 + for item_name, _ in pairs(global.received_tech) do + tech = force.technologies[item_name] + if tech ~= nil and tech.researched ~= true then + game.print({"", "Received [technology=" .. tech.name .. "] as it is already checked."}) + game.play_sound({path="utility/research_completed"}) + tech.researched = true + end + end + global.received_tech = {} + else + ALLOW_COLLECT = 0 + end + end end script.on_event(defines.events.on_runtime_mod_setting_changed, on_runtime_mod_setting_changed) @@ -658,18 +685,29 @@ commands.add_command("ap-get-technology", "Grant a technology, used by the Archi if global.index_sync == nil then global.index_sync = {} end + if global.received_tech == nil then + global.received_tech = {} + end local tech local force = game.forces["player"] chunks = split(call.parameter, "\t") local item_name = chunks[1] - local index = chunks[2] + local index = tonumber(chunks[2]) or chunks[2] local source = chunks[3] or "Archipelago" if index == -1 then -- for coop sync and restoring from an older savegame tech = force.technologies[item_name] + if tech == nil then + game.print("Unknown Item " .. item_name) + return + end if tech.researched ~= true then - game.print({"", "Received [technology=" .. tech.name .. "] as it is already checked."}) - game.play_sound({path="utility/research_completed"}) - tech.researched = true + if ALLOW_COLLECT == 1 then + game.print({"", "Received [technology=" .. tech.name .. "] as it is already checked."}) + game.play_sound({path="utility/research_completed"}) + tech.researched = true + else + global.received_tech[item_name] = 1 + end end return elseif progressive_technologies[item_name] ~= nil then diff --git a/worlds/factorio/data/mod_template/locale/en/locale.cfg b/worlds/factorio/data/mod_template/locale/en/locale.cfg index 59dcffcd63..659c5193d9 100644 --- a/worlds/factorio/data/mod_template/locale/en/locale.cfg +++ b/worlds/factorio/data/mod_template/locale/en/locale.cfg @@ -26,6 +26,8 @@ ap-{{ location.address }}-=Researching this technology sends something to someon [mod-setting-name] archipelago-death-link-{{ slot_player }}-{{ seed_name }}=Death Link +archipelago-allow-collect-{{ slot_player }}-{{ seed_name }}=Allow Collect [mod-setting-description] -archipelago-death-link-{{ slot_player }}-{{ seed_name }}=Kill other players in the same Archipelago Multiworld that also have Death Link turned on, when you die. \ No newline at end of file +archipelago-death-link-{{ slot_player }}-{{ seed_name }}=Kill other players in the same Archipelago Multiworld that also have Death Link turned on, when you die. +archipelago-allow-collect-{{ slot_player }}-{{ seed_name }}=Allows released/collected tech locations to be marked as researched automatically. \ No newline at end of file diff --git a/worlds/factorio/data/mod_template/settings.lua b/worlds/factorio/data/mod_template/settings.lua index 73e131a60e..8cf79c48f3 100644 --- a/worlds/factorio/data/mod_template/settings.lua +++ b/worlds/factorio/data/mod_template/settings.lua @@ -26,5 +26,15 @@ data:extend({ {% else %} default_value = false {% endif %} + }, + { + type = "bool-setting", + name = "archipelago-allow-collect-{{ slot_player }}-{{ seed_name }}", + setting_type = "runtime-global", + {% if allow_collect %} + default_value = true + {% else %} + default_value = false + {% endif %} } }) \ No newline at end of file