AutoWorld: Should no longer need to overwrite collect, collect_item should be used instead

AutoWorld: Now correctly automatically applies State.remove if collect_item is also correct
LttP: Make keys advancement items

This feels like it improved generation chance. Might not be the case.
This commit is contained in:
Fabian Dill
2021-08-10 09:47:28 +02:00
parent 9ec0680ce5
commit a532ceeb0a
8 changed files with 76 additions and 122 deletions

View File

@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import Dict, Set, Tuple, List
from typing import Dict, Set, Tuple, List, Optional
from BaseClasses import MultiWorld, Item, CollectionState, Location
@@ -150,18 +150,33 @@ class World(metaclass=AutoWorldRegister):
# end of Main.py calls
def collect(self, state: CollectionState, item: Item) -> bool:
"""Collect an item into state. For speed reasons items that aren't logically useful get skipped."""
def collect_item(self, state: CollectionState, item: Item) -> Optional[str]:
"""Collect an item name into state. For speed reasons items that aren't logically useful get skipped.
Collect None to skip item."""
if item.advancement:
state.prog_items[item.name, item.player] += 1
return True # indicate that a logical state change has occured
return False
return item.name
def create_item(self, name: str) -> Item:
"""Create an item for this world type and player.
Warning: this may be called with self.world = None, for example by MultiServer"""
raise NotImplementedError
# following methods should not need to be overriden.
def collect(self, state: CollectionState, item: Item) -> bool:
name = self.collect_item(state, item)
if name:
state.prog_items[name, item.player] += 1
return True
return False
def remove(self, state: CollectionState, item: Item) -> bool:
name = self.collect_item(state, item)
if name:
state.prog_items[name, item.player] -= 1
if state.prog_items[name, item.player] < 1:
del (state.prog_items[name, item.player])
return True
return False
# any methods attached to this can be used as part of CollectionState,
# please use a prefix as all of them get clobbered together