From cfe357eb7197a127f1a5dc62ccc9eaa87e6c2668 Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Sat, 25 Nov 2023 15:07:02 -0600 Subject: [PATCH] The Messenger, LADX: use collect and remove as intended (#2093) Co-authored-by: el-u <109771707+el-u@users.noreply.github.com> --- worlds/ladx/__init__.py | 31 ++++++++++++----------------- worlds/ladx/test/testShop.py | 38 ++++++++++++++++++++++++++++++++++++ worlds/messenger/__init__.py | 17 +++++++++------- 3 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 worlds/ladx/test/testShop.py diff --git a/worlds/ladx/__init__.py b/worlds/ladx/__init__.py index eaaea5be..181cc053 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 @@ -511,16 +508,12 @@ class LinksAwakeningWorld(World): def collect(self, state, item: Item) -> bool: change = super().collect(state, item) - if change: - rupees = self.rupees.get(item.name, 0) - state.prog_items[item.player]["RUPEES"] += rupees - + if change and item.name in self.rupees: + state.prog_items[self.player]["RUPEES"] += self.rupees[item.name] return change def remove(self, state, item: Item) -> bool: change = super().remove(state, item) - if change: - rupees = self.rupees.get(item.name, 0) - state.prog_items[item.player]["RUPEES"] -= rupees - + if change and item.name in self.rupees: + state.prog_items[self.player]["RUPEES"] -= self.rupees[item.name] return change diff --git a/worlds/ladx/test/testShop.py b/worlds/ladx/test/testShop.py new file mode 100644 index 00000000..91d504d5 --- /dev/null +++ b/worlds/ladx/test/testShop.py @@ -0,0 +1,38 @@ +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): + options = { + "plando_items": [{ + "items": { + "Progressive Sword": 2, + }, + "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.""" + 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)) diff --git a/worlds/messenger/__init__.py b/worlds/messenger/__init__.py index f1268736..d569dd75 100644 --- a/worlds/messenger/__init__.py +++ b/worlds/messenger/__init__.py @@ -176,11 +176,14 @@ class MessengerWorld(World): 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[self.player]["Shards"] += shard_count + def collect(self, state: "CollectionState", item: "Item") -> bool: + change = super().collect(state, item) + if change and "Time Shard" in item.name: + state.prog_items[self.player]["Shards"] += int(item.name.strip("Time Shard ()")) + return change - return super().collect_item(state, item, remove) + def remove(self, state: "CollectionState", item: "Item") -> bool: + change = super().remove(state, item) + if change and "Time Shard" in item.name: + state.prog_items[self.player]["Shards"] -= int(item.name.strip("Time Shard ()")) + return change