DLCQuest: logic speed up (#2323)

This commit is contained in:
Fabian Dill 2023-10-26 00:51:32 +02:00 committed by GitHub
parent aa73dbab2d
commit 88d69dba97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 38 deletions

View File

@ -11,6 +11,8 @@ from . import Options, data
class DLCQuestItem(Item):
game: str = "DLCQuest"
coins: int = 0
coin_suffix: str = ""
offset = 120_000

View File

@ -23,7 +23,10 @@ def add_coin(region: Region, coin: int, player: int, suffix: str):
location_coin = f"{region.name}{suffix}"
location = DLCQuestLocation(player, location_coin, None, region)
region.locations.append(location)
location.place_locked_item(create_event(player, number_coin))
event = create_event(player, number_coin)
event.coins = coin
event.coin_suffix = suffix
location.place_locked_item(event)
def create_regions(multiworld: MultiWorld, player: int, world_options: Options.DLCQuestOptions):

View File

@ -7,41 +7,25 @@ from . import Options
from .Items import DLCQuestItem
def create_event(player, event: str):
def create_event(player, event: str) -> DLCQuestItem:
return DLCQuestItem(event, ItemClassification.progression, None, player)
def set_rules(world, player, World_Options: Options.DLCQuestOptions):
def has_enough_coin(player: int, coin: int):
def has_coin(state, player: int, coins: int):
coin_possessed = 0
for i in [4, 7, 9, 10, 46, 50, 60, 76, 89, 100, 171, 203]:
name_coin = f"{i} coins"
if state.has(name_coin, player):
coin_possessed += i
return lambda state: state.prog_items[" coins", player] >= coin
return coin_possessed >= coins
return lambda state: has_coin(state, player, coin)
def has_enough_coin_freemium(player: int, coin: int):
def has_coin(state, player: int, coins: int):
coin_possessed = 0
for i in [20, 50, 90, 95, 130, 150, 154, 200]:
name_coin = f"{i} coins freemium"
if state.has(name_coin, player):
coin_possessed += i
return lambda state: state.prog_items[" coins freemium", player] >= coin
return coin_possessed >= coins
return lambda state: has_coin(state, player, coin)
set_basic_rules(World_Options, has_enough_coin, player, world)
set_lfod_rules(World_Options, has_enough_coin_freemium, player, world)
def set_rules(world, player, World_Options: Options.DLCQuestOptions):
set_basic_rules(World_Options, player, world)
set_lfod_rules(World_Options, player, world)
set_completion_condition(World_Options, player, world)
def set_basic_rules(World_Options, has_enough_coin, player, world):
def set_basic_rules(World_Options, player, world):
if World_Options.campaign == Options.Campaign.option_live_freemium_or_die:
return
set_basic_entrance_rules(player, world)
@ -49,8 +33,8 @@ def set_basic_rules(World_Options, has_enough_coin, player, world):
set_basic_shuffled_items_rules(World_Options, player, world)
set_double_jump_glitchless_rules(World_Options, player, world)
set_easy_double_jump_glitch_rules(World_Options, player, world)
self_basic_coinsanity_funded_purchase_rules(World_Options, has_enough_coin, player, world)
set_basic_self_funded_purchase_rules(World_Options, has_enough_coin, player, world)
self_basic_coinsanity_funded_purchase_rules(World_Options, player, world)
set_basic_self_funded_purchase_rules(World_Options, player, world)
self_basic_win_condition(World_Options, player, world)
@ -131,7 +115,7 @@ def set_easy_double_jump_glitch_rules(World_Options, player, world):
lambda state: state.has("Double Jump Pack", player))
def self_basic_coinsanity_funded_purchase_rules(World_Options, has_enough_coin, player, world):
def self_basic_coinsanity_funded_purchase_rules(World_Options, player, world):
if World_Options.coinsanity != Options.CoinSanity.option_coin:
return
number_of_bundle = math.floor(825 / World_Options.coinbundlequantity)
@ -194,7 +178,7 @@ def self_basic_coinsanity_funded_purchase_rules(World_Options, has_enough_coin,
math.ceil(5 / World_Options.coinbundlequantity)))
def set_basic_self_funded_purchase_rules(World_Options, has_enough_coin, player, world):
def set_basic_self_funded_purchase_rules(World_Options, player, world):
if World_Options.coinsanity != Options.CoinSanity.option_none:
return
set_rule(world.get_location("Movement Pack", player),
@ -241,14 +225,14 @@ def self_basic_win_condition(World_Options, player, world):
player))
def set_lfod_rules(World_Options, has_enough_coin_freemium, player, world):
def set_lfod_rules(World_Options, player, world):
if World_Options.campaign == Options.Campaign.option_basic:
return
set_lfod_entrance_rules(player, world)
set_boss_door_requirements_rules(player, world)
set_lfod_self_obtained_items_rules(World_Options, player, world)
set_lfod_shuffled_items_rules(World_Options, player, world)
self_lfod_coinsanity_funded_purchase_rules(World_Options, has_enough_coin_freemium, player, world)
self_lfod_coinsanity_funded_purchase_rules(World_Options, player, world)
set_lfod_self_funded_purchase_rules(World_Options, has_enough_coin_freemium, player, world)
@ -327,7 +311,7 @@ def set_lfod_shuffled_items_rules(World_Options, player, world):
lambda state: state.can_reach("Cut Content", 'region', player))
def self_lfod_coinsanity_funded_purchase_rules(World_Options, has_enough_coin_freemium, player, world):
def self_lfod_coinsanity_funded_purchase_rules(World_Options, player, world):
if World_Options.coinsanity != Options.CoinSanity.option_coin:
return
number_of_bundle = math.floor(889 / World_Options.coinbundlequantity)

View File

@ -1,6 +1,6 @@
from typing import Union
from BaseClasses import Tutorial
from BaseClasses import Tutorial, CollectionState
from worlds.AutoWorld import WebWorld, World
from . import Options
from .Items import DLCQuestItem, ItemData, create_items, item_table
@ -71,7 +71,6 @@ class DLCqworld(World):
if self.options.coinsanity == Options.CoinSanity.option_coin and self.options.coinbundlequantity >= 5:
self.multiworld.push_precollected(self.create_item("Movement Pack"))
def create_item(self, item: Union[str, ItemData]) -> DLCQuestItem:
if isinstance(item, str):
item = item_table[item]
@ -87,3 +86,19 @@ class DLCqworld(World):
"seed": self.random.randrange(99999999)
})
return options_dict
def collect(self, state: CollectionState, item: DLCQuestItem) -> bool:
change = super().collect(state, item)
if change:
suffix = item.coin_suffix
if suffix:
state.prog_items[suffix, self.player] += item.coins
return change
def remove(self, state: CollectionState, item: DLCQuestItem) -> bool:
change = super().remove(state, item)
if change:
suffix = item.coin_suffix
if suffix:
state.prog_items[suffix, self.player] -= item.coins
return change