From fb1c3e0dfd39522ed77c0220779164d9df500be6 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 8 Aug 2023 11:07:02 -0500 Subject: [PATCH 01/10] The Messenger: use `collect` and `remove` as intended --- worlds/messenger/__init__.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index b37f23749df..9ee8745726c 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -1,5 +1,5 @@ import logging -from typing import Dict, Any, List, Optional +from typing import Dict, Any, List, Optional, Tuple from BaseClasses import Tutorial, ItemClassification, CollectionState, Item, MultiWorld from worlds.AutoWorld import World, WebWorld @@ -187,11 +187,22 @@ def create_item(self, name: str) -> MessengerItem: self.total_shards += count return MessengerItem(name, self.player, item_id, override_prog, count) - def collect_item(self, state: "CollectionState", item: "Item", remove: bool = False) -> Optional[str]: - if item.advancement and "Time Shard" in item.name: - shard_count = int(item.name.strip("Time Shard ()")) - if remove: - shard_count = -shard_count - state.prog_items["Shards", self.player] += shard_count - - return super().collect_item(state, item, remove) + def collect_item(self, state: "CollectionState", item: "Item", remove: bool = False) -> Tuple[str, int]: + if "Shard" in item.name: + count = int(item.name.strip("Time Shard ()")) + return "Shards", count + return item.name, 1 + + def collect(self, state: "CollectionState", item: "Item") -> bool: + if item.advancement: + name, count = self.collect_item(state, item) + state.prog_items[name, self.player] += count + return True + return False + + def remove(self, state: "CollectionState", item: "Item") -> bool: + if item.advancement: + name, count = self.collect_item(state, item) + state.prog_items[name, self.player] -= count + return True + return False From 7fd706f3240483640211141d8221bb0bfbe6bc2d Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 8 Aug 2023 11:12:22 -0500 Subject: [PATCH 02/10] LADX: use `collect_item` for rupee name and count --- worlds/ladx/__init__.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/worlds/ladx/__init__.py b/worlds/ladx/__init__.py index 1d6c85dd644..62d132a4f9d 100644 --- a/worlds/ladx/__init__.py +++ b/worlds/ladx/__init__.py @@ -514,18 +514,21 @@ def generate_multi_key(self): def modify_multidata(self, multidata: dict): multidata["connect_names"][binascii.hexlify(self.multi_key).decode()] = multidata["connect_names"][self.multiworld.player_name[self.player]] - def collect(self, state, item: Item) -> bool: - change = super().collect(state, item) - if change: - rupees = self.rupees.get(item.name, 0) - state.prog_items["RUPEES", item.player] += rupees + def collect_item(self, state: "CollectionState", item: "Item", remove: bool = False) -> typing.Tuple[str, int]: + if "Rupees" in item.name: + return "RUPEES", self.rupees.get(item.name, 0) + return item.name, 1 - return change + def collect(self, state, item: Item) -> bool: + if item.advancement: + name, count = self.collect_item(state, item) + state.prog_items[name, self.player] += count + return True + return False def remove(self, state, item: Item) -> bool: - change = super().remove(state, item) - if change: - rupees = self.rupees.get(item.name, 0) - state.prog_items["RUPEES", item.player] -= rupees - - return change + if item.advancement: + name, count = self.collect_item(state, item) + state.prog_items[name, self.player] -= count + return True + return False From 9b41d2df8b92636e794b34ced337ee152495ea4d Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 8 Aug 2023 11:26:35 -0500 Subject: [PATCH 03/10] LADX: unit test for plandoing the swords in the shop --- worlds/ladx/test/testShop.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 worlds/ladx/test/testShop.py diff --git a/worlds/ladx/test/testShop.py b/worlds/ladx/test/testShop.py new file mode 100644 index 00000000000..fdf05816706 --- /dev/null +++ b/worlds/ladx/test/testShop.py @@ -0,0 +1,17 @@ +from . import LADXTestBase + + +class PlandoTest(LADXTestBase): + """Tests plandoing swords in the shop.""" + options = { + "plando_items": [{ + "items": { + "Progressive Sword": 2 + }, + "locations": [ + "Shop 10 Item (Mabe Village)", + "Shop 200 Item (Mabe Village)", + "Shop 980 Item (Mabe Village)" + ] + }] + } From 754c946f0fd1b25ef5fffc7dc9cc9da591ba09fa Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 8 Aug 2023 11:37:27 -0500 Subject: [PATCH 04/10] plando items is default off so force the block in and check the locations --- worlds/ladx/test/testShop.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/worlds/ladx/test/testShop.py b/worlds/ladx/test/testShop.py index fdf05816706..96583e4343a 100644 --- a/worlds/ladx/test/testShop.py +++ b/worlds/ladx/test/testShop.py @@ -1,17 +1,27 @@ +from typing import Optional + +from Fill import distribute_planned from . import LADXTestBase class PlandoTest(LADXTestBase): - """Tests plandoing swords in the shop.""" options = { "plando_items": [{ "items": { "Progressive Sword": 2 }, "locations": [ - "Shop 10 Item (Mabe Village)", "Shop 200 Item (Mabe Village)", "Shop 980 Item (Mabe Village)" ] }] } + + def test_planned(self): + """Tests plandoing swords in the shop.""" + self.multiworld.plando_items[1] = self.options["plando_items"] + distribute_planned(self.multiworld) + self.assertEqual("Progressive Sword", + self.multiworld.get_location("Shop 200 Item (Mabe Village)", 1).item.name) + self.assertEqual("Progressive Sword", + self.multiworld.get_location("Shop 980 Item (Mabe Village)", 1).item.name) From 90de610f96984aae65045a3413fb0a6eb5bd8cbf Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 8 Aug 2023 22:04:23 -0500 Subject: [PATCH 05/10] cleanup the unit test --- worlds/ladx/test/testShop.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/worlds/ladx/test/testShop.py b/worlds/ladx/test/testShop.py index 96583e4343a..6112445276a 100644 --- a/worlds/ladx/test/testShop.py +++ b/worlds/ladx/test/testShop.py @@ -1,7 +1,10 @@ from typing import Optional from Fill import distribute_planned +from test.general import setup_solo_multiworld +from worlds.AutoWorld import call_all from . import LADXTestBase +from .. import LinksAwakeningWorld class PlandoTest(LADXTestBase): @@ -13,15 +16,23 @@ class PlandoTest(LADXTestBase): "locations": [ "Shop 200 Item (Mabe Village)", "Shop 980 Item (Mabe Village)" - ] - }] + ], + }], } + + def world_setup(self, seed: Optional[int] = None) -> None: + self.multiworld = setup_solo_multiworld( + LinksAwakeningWorld, + ("generate_early", "create_regions", "create_items", "set_rules", "generate_basic") + ) + self.multiworld.plando_items[1] = self.options["plando_items"] + distribute_planned(self.multiworld) + call_all(self.multiworld, "pre_fill") def test_planned(self): """Tests plandoing swords in the shop.""" - self.multiworld.plando_items[1] = self.options["plando_items"] - distribute_planned(self.multiworld) - self.assertEqual("Progressive Sword", - self.multiworld.get_location("Shop 200 Item (Mabe Village)", 1).item.name) - self.assertEqual("Progressive Sword", - self.multiworld.get_location("Shop 980 Item (Mabe Village)", 1).item.name) + location_names = ["Shop 200 Item (Mabe Village)", "Shop 980 Item (Mabe Village)"] + locations = [self.multiworld.get_location(loc, 1) for loc in location_names] + for loc in locations: + self.assertEqual("Progressive Sword", loc.item.name) + self.assertFalse(loc.can_reach(self.multiworld.state)) From b87aae1672262d4cc35617d2610f568b5e3fadb6 Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Tue, 8 Aug 2023 22:05:18 -0500 Subject: [PATCH 06/10] cleaner messenger collect Co-authored-by: el-u <109771707+el-u@users.noreply.github.com> --- worlds/messenger/__init__.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 9ee8745726c..0b57dd15c4d 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -187,22 +187,16 @@ def create_item(self, name: str) -> MessengerItem: self.total_shards += count return MessengerItem(name, self.player, item_id, override_prog, count) - def collect_item(self, state: "CollectionState", item: "Item", remove: bool = False) -> Tuple[str, int]: - if "Shard" in item.name: - count = int(item.name.strip("Time Shard ()")) - return "Shards", count - return item.name, 1 - def collect(self, state: "CollectionState", item: "Item") -> bool: - if item.advancement: - name, count = self.collect_item(state, item) - state.prog_items[name, self.player] += count + if "Time Shard" in item.name and item.advancement: + state.prog_items["Shards", self.player] += int(item.name.strip("Time Shard ()")) return True - return False + else: + return super().collect(state, item) def remove(self, state: "CollectionState", item: "Item") -> bool: - if item.advancement: - name, count = self.collect_item(state, item) - state.prog_items[name, self.player] -= count + if "Time Shard" in item.name and item.advancement: + state.prog_items["Shards", self.player] -= int(item.name.strip("Time Shard ()")) return True - return False + else: + return super().remove(state, item) From 902851d5a5525d8a0b4c999411217870e0184b19 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 8 Aug 2023 22:08:24 -0500 Subject: [PATCH 07/10] cleaner LADX collect and optimize imports --- worlds/ladx/__init__.py | 38 +++++++++++++----------------------- worlds/messenger/__init__.py | 18 ++++++++--------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/worlds/ladx/__init__.py b/worlds/ladx/__init__.py index 62d132a4f9d..606fed3aaff 100644 --- a/worlds/ladx/__init__.py +++ b/worlds/ladx/__init__.py @@ -1,32 +1,29 @@ import binascii -import bsdiff4 import os import pkgutil -import settings -import typing import tempfile +import typing +import bsdiff4 +import settings from BaseClasses import Entrance, Item, ItemClassification, Location, Tutorial from Fill import fill_restrictive from worlds.AutoWorld import WebWorld, World - from .Common import * -from .Items import (DungeonItemData, DungeonItemType, LinksAwakeningItem, TradeItemData, - ladxr_item_to_la_item_name, links_awakening_items, - links_awakening_items_by_name, ItemName) +from .Items import (DungeonItemData, DungeonItemType, ItemName, LinksAwakeningItem, TradeItemData, + ladxr_item_to_la_item_name, links_awakening_items, links_awakening_items_by_name) from .LADXR import generator from .LADXR.itempool import ItemPool as LADXRItemPool +from .LADXR.locations.constants import CHEST_ITEMS +from .LADXR.locations.instrument import Instrument from .LADXR.logic import Logic as LAXDRLogic from .LADXR.main import get_parser from .LADXR.settings import Settings as LADXRSettings from .LADXR.worldSetup import WorldSetup as LADXRWorldSetup -from .LADXR.locations.instrument import Instrument -from .LADXR.locations.constants import CHEST_ITEMS from .Locations import (LinksAwakeningLocation, LinksAwakeningRegion, create_regions_from_ladxr, get_locations_to_id) -from .Options import links_awakening_options, DungeonItemShuffle - +from .Options import DungeonItemShuffle, links_awakening_options from .Rom import LADXDeltaPatch DEVELOPER_MODE = False @@ -514,21 +511,14 @@ def generate_multi_key(self): def modify_multidata(self, multidata: dict): multidata["connect_names"][binascii.hexlify(self.multi_key).decode()] = multidata["connect_names"][self.multiworld.player_name[self.player]] - def collect_item(self, state: "CollectionState", item: "Item", remove: bool = False) -> typing.Tuple[str, int]: - if "Rupees" in item.name: - return "RUPEES", self.rupees.get(item.name, 0) - return item.name, 1 - def collect(self, state, item: Item) -> bool: - if item.advancement: - name, count = self.collect_item(state, item) - state.prog_items[name, self.player] += count + if item.name in self.rupees and item.advancement: + state.prog_items["RUPEES", self.player] += self.rupees[item.name] return True - return False + return super().collect(state, item) def remove(self, state, item: Item) -> bool: - if item.advancement: - name, count = self.collect_item(state, item) - state.prog_items[name, self.player] -= count + if item.name in self.rupees and item.advancement: + state.prog_items["RUPEES", self.player] -= self.rupees[item.name] return True - return False + return super().remove(state, item) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 0b57dd15c4d..dd003857b4e 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -1,14 +1,14 @@ import logging -from typing import Dict, Any, List, Optional, Tuple - -from BaseClasses import Tutorial, ItemClassification, CollectionState, Item, MultiWorld -from worlds.AutoWorld import World, WebWorld -from .Constants import NOTES, PHOBEKINS, ALL_ITEMS, ALWAYS_LOCATIONS, BOSS_LOCATIONS, FILLER -from .Options import messenger_options, NotesNeeded, Goal, PowerSeals, Logic -from .Regions import REGIONS, REGION_CONNECTIONS, SEALS, MEGA_SHARDS -from .Shop import SHOP_ITEMS, shuffle_shop_prices, FIGURINES -from .SubClasses import MessengerRegion, MessengerItem +from typing import Any, Dict, List, Optional + +from BaseClasses import CollectionState, Item, ItemClassification, MultiWorld, Tutorial +from worlds.AutoWorld import WebWorld, World from . import Rules +from .Constants import ALL_ITEMS, ALWAYS_LOCATIONS, BOSS_LOCATIONS, FILLER, NOTES, PHOBEKINS +from .Options import Goal, Logic, NotesNeeded, PowerSeals, messenger_options +from .Regions import MEGA_SHARDS, REGIONS, REGION_CONNECTIONS, SEALS +from .Shop import FIGURINES, SHOP_ITEMS, shuffle_shop_prices +from .SubClasses import MessengerItem, MessengerRegion class MessengerWeb(WebWorld): From ef38f3635b1224b9dde9fb764522336f4374e728 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Tue, 8 Aug 2023 22:12:05 -0500 Subject: [PATCH 08/10] missing , --- worlds/ladx/test/testShop.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worlds/ladx/test/testShop.py b/worlds/ladx/test/testShop.py index 6112445276a..91d504d521b 100644 --- a/worlds/ladx/test/testShop.py +++ b/worlds/ladx/test/testShop.py @@ -11,11 +11,11 @@ class PlandoTest(LADXTestBase): options = { "plando_items": [{ "items": { - "Progressive Sword": 2 + "Progressive Sword": 2, }, "locations": [ "Shop 200 Item (Mabe Village)", - "Shop 980 Item (Mabe Village)" + "Shop 980 Item (Mabe Village)", ], }], } From 20ce55a304d5842c1133d010a193dc7a0ca78f68 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 22 Nov 2023 16:18:52 -0600 Subject: [PATCH 09/10] copy paste mistake --- worlds/ladx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/ladx/__init__.py b/worlds/ladx/__init__.py index e1d09e10ad7..181cc053222 100644 --- a/worlds/ladx/__init__.py +++ b/worlds/ladx/__init__.py @@ -513,7 +513,7 @@ def collect(self, state, item: Item) -> bool: return change def remove(self, state, item: Item) -> bool: - change = super().collect(state, item) + change = super().remove(state, item) if change and item.name in self.rupees: state.prog_items[self.player]["RUPEES"] -= self.rupees[item.name] return change From ce947c03dc5eed341b622842b619567d349ee6e6 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 22 Nov 2023 16:55:37 -0600 Subject: [PATCH 10/10] forgot to swap prog_items --- worlds/messenger/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index 022592e2b3b..b5087cbc8eb 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -187,11 +187,11 @@ def create_item(self, name: str) -> MessengerItem: def collect(self, state: "CollectionState", item: "Item") -> bool: change = super().collect(state, item) if change and "Time Shard" in item.name: - state.prog_items["Shards", self.player] += int(item.name.strip("Time Shard ()")) + state.prog_items[self.player]["Shards"] += int(item.name.strip("Time Shard ()")) return change def remove(self, state: "CollectionState", item: "Item") -> bool: change = super().remove(state, item) if change and "Time Shard" in item.name: - state.prog_items["Shards", self.player] -= int(item.name.strip("Time Shard ()")) + state.prog_items[self.player]["Shards"] -= int(item.name.strip("Time Shard ()")) return change