Skip to content

Commit

Permalink
The Messenger, LADX: use collect and remove as intended (ArchipelagoM…
Browse files Browse the repository at this point in the history
…W#2093)

Co-authored-by: el-u <[email protected]>
  • Loading branch information
alwaysintreble and el-u authored Nov 25, 2023
1 parent fe6a70a commit cfe357e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
31 changes: 12 additions & 19 deletions worlds/ladx/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -511,16 +508,12 @@ def modify_multidata(self, multidata: dict):

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
38 changes: 38 additions & 0 deletions worlds/ladx/test/testShop.py
Original file line number Diff line number Diff line change
@@ -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))
19 changes: 11 additions & 8 deletions worlds/messenger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,14 @@ 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[self.player]["Shards"] += shard_count

return super().collect_item(state, item, remove)
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

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

0 comments on commit cfe357e

Please sign in to comment.