DLCQuest: logic speed up (#2323)
This commit is contained in:
		
							parent
							
								
									aa73dbab2d
								
							
						
					
					
						commit
						88d69dba97
					
				| 
						 | 
					@ -11,6 +11,8 @@ from . import Options, data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DLCQuestItem(Item):
 | 
					class DLCQuestItem(Item):
 | 
				
			||||||
    game: str = "DLCQuest"
 | 
					    game: str = "DLCQuest"
 | 
				
			||||||
 | 
					    coins: int = 0
 | 
				
			||||||
 | 
					    coin_suffix: str = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
offset = 120_000
 | 
					offset = 120_000
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,10 @@ def add_coin(region: Region, coin: int, player: int, suffix: str):
 | 
				
			||||||
    location_coin = f"{region.name}{suffix}"
 | 
					    location_coin = f"{region.name}{suffix}"
 | 
				
			||||||
    location = DLCQuestLocation(player, location_coin, None, region)
 | 
					    location = DLCQuestLocation(player, location_coin, None, region)
 | 
				
			||||||
    region.locations.append(location)
 | 
					    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):
 | 
					def create_regions(multiworld: MultiWorld, player: int, world_options: Options.DLCQuestOptions):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,41 +7,25 @@ from . import Options
 | 
				
			||||||
from .Items import DLCQuestItem
 | 
					from .Items import DLCQuestItem
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def create_event(player, event: str):
 | 
					def create_event(player, event: str) -> DLCQuestItem:
 | 
				
			||||||
    return DLCQuestItem(event, ItemClassification.progression, None, player)
 | 
					    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_enough_coin(player: int, coin: int):
 | 
				
			||||||
        def has_coin(state, player: int, coins: int):
 | 
					    return lambda state: state.prog_items[" coins", player] >= coin
 | 
				
			||||||
            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 coin_possessed >= coins
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return lambda state: has_coin(state, player, coin)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def has_enough_coin_freemium(player: int, coin: int):
 | 
					def has_enough_coin_freemium(player: int, coin: int):
 | 
				
			||||||
        def has_coin(state, player: int, coins: int):
 | 
					    return lambda state: state.prog_items[" coins freemium", player] >= coin
 | 
				
			||||||
            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 coin_possessed >= coins
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return lambda state: has_coin(state, player, coin)
 | 
					def set_rules(world, player, World_Options: Options.DLCQuestOptions):
 | 
				
			||||||
 | 
					    set_basic_rules(World_Options, player, world)
 | 
				
			||||||
    set_basic_rules(World_Options, has_enough_coin, player, world)
 | 
					    set_lfod_rules(World_Options, player, world)
 | 
				
			||||||
    set_lfod_rules(World_Options, has_enough_coin_freemium, player, world)
 | 
					 | 
				
			||||||
    set_completion_condition(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:
 | 
					    if World_Options.campaign == Options.Campaign.option_live_freemium_or_die:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    set_basic_entrance_rules(player, world)
 | 
					    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_basic_shuffled_items_rules(World_Options, player, world)
 | 
				
			||||||
    set_double_jump_glitchless_rules(World_Options, player, world)
 | 
					    set_double_jump_glitchless_rules(World_Options, player, world)
 | 
				
			||||||
    set_easy_double_jump_glitch_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)
 | 
					    self_basic_coinsanity_funded_purchase_rules(World_Options, player, world)
 | 
				
			||||||
    set_basic_self_funded_purchase_rules(World_Options, has_enough_coin, player, world)
 | 
					    set_basic_self_funded_purchase_rules(World_Options, player, world)
 | 
				
			||||||
    self_basic_win_condition(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))
 | 
					             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:
 | 
					    if World_Options.coinsanity != Options.CoinSanity.option_coin:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    number_of_bundle = math.floor(825 / World_Options.coinbundlequantity)
 | 
					    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)))
 | 
					                                     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:
 | 
					    if World_Options.coinsanity != Options.CoinSanity.option_none:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    set_rule(world.get_location("Movement Pack", player),
 | 
					    set_rule(world.get_location("Movement Pack", player),
 | 
				
			||||||
| 
						 | 
					@ -241,14 +225,14 @@ def self_basic_win_condition(World_Options, player, world):
 | 
				
			||||||
                                                                                            player))
 | 
					                                                                                            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:
 | 
					    if World_Options.campaign == Options.Campaign.option_basic:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    set_lfod_entrance_rules(player, world)
 | 
					    set_lfod_entrance_rules(player, world)
 | 
				
			||||||
    set_boss_door_requirements_rules(player, world)
 | 
					    set_boss_door_requirements_rules(player, world)
 | 
				
			||||||
    set_lfod_self_obtained_items_rules(World_Options, player, world)
 | 
					    set_lfod_self_obtained_items_rules(World_Options, player, world)
 | 
				
			||||||
    set_lfod_shuffled_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)
 | 
					    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))
 | 
					             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:
 | 
					    if World_Options.coinsanity != Options.CoinSanity.option_coin:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    number_of_bundle = math.floor(889 / World_Options.coinbundlequantity)
 | 
					    number_of_bundle = math.floor(889 / World_Options.coinbundlequantity)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
from typing import Union
 | 
					from typing import Union
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from BaseClasses import Tutorial
 | 
					from BaseClasses import Tutorial, CollectionState
 | 
				
			||||||
from worlds.AutoWorld import WebWorld, World
 | 
					from worlds.AutoWorld import WebWorld, World
 | 
				
			||||||
from . import Options
 | 
					from . import Options
 | 
				
			||||||
from .Items import DLCQuestItem, ItemData, create_items, item_table
 | 
					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:
 | 
					            if self.options.coinsanity == Options.CoinSanity.option_coin and self.options.coinbundlequantity >= 5:
 | 
				
			||||||
                self.multiworld.push_precollected(self.create_item("Movement Pack"))
 | 
					                self.multiworld.push_precollected(self.create_item("Movement Pack"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def create_item(self, item: Union[str, ItemData]) -> DLCQuestItem:
 | 
					    def create_item(self, item: Union[str, ItemData]) -> DLCQuestItem:
 | 
				
			||||||
        if isinstance(item, str):
 | 
					        if isinstance(item, str):
 | 
				
			||||||
            item = item_table[item]
 | 
					            item = item_table[item]
 | 
				
			||||||
| 
						 | 
					@ -87,3 +86,19 @@ class DLCqworld(World):
 | 
				
			||||||
            "seed": self.random.randrange(99999999)
 | 
					            "seed": self.random.randrange(99999999)
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        return options_dict
 | 
					        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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue