Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Messenger, LADX: use collect and remove as intended #2093

Merged
merged 12 commits into from
Nov 25, 2023
39 changes: 16 additions & 23 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 @@ -515,17 +512,13 @@ 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

return change
if item.name in self.rupees and item.advancement:
state.prog_items["RUPEES", self.player] += self.rupees[item.name]
return True
return super().collect(state, item)

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.name in self.rupees and item.advancement:
state.prog_items["RUPEES", self.player] -= self.rupees[item.name]
return True
return super().remove(state, item)
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

alwaysintreble marked this conversation as resolved.
Show resolved Hide resolved
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):
alwaysintreble marked this conversation as resolved.
Show resolved Hide resolved
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))
37 changes: 21 additions & 16 deletions worlds/messenger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from typing import Dict, Any, List, Optional

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):
Expand Down Expand Up @@ -187,11 +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) -> 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
def collect(self, state: "CollectionState", item: "Item") -> bool:
if "Time Shard" in item.name and item.advancement:
state.prog_items["Shards", self.player] += int(item.name.strip("Time Shard ()"))
return True
else:
return super().collect(state, item)

return super().collect_item(state, item, remove)
def remove(self, state: "CollectionState", item: "Item") -> bool:
if "Time Shard" in item.name and item.advancement:
state.prog_items["Shards", self.player] -= int(item.name.strip("Time Shard ()"))
return True
else:
return super().remove(state, item)
Loading