Skip to content

Commit

Permalink
DLCQuest: logic speed up (ArchipelagoMW#2323)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berserker66 authored Oct 25, 2023
1 parent aa73dba commit 88d69db
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 35 deletions.
2 changes: 2 additions & 0 deletions worlds/dlcquest/Items.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class DLCQuestItem(Item):
game: str = "DLCQuest"
coins: int = 0
coin_suffix: str = ""


offset = 120_000
Expand Down
5 changes: 4 additions & 1 deletion worlds/dlcquest/Regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
48 changes: 16 additions & 32 deletions worlds/dlcquest/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,34 @@
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 coin_possessed >= coins
def has_enough_coin(player: int, coin: int):
return lambda state: state.prog_items[" coins", player] >= coin

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
def has_enough_coin_freemium(player: int, coin: int):
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)
set_basic_self_obtained_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_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)


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand Down
19 changes: 17 additions & 2 deletions worlds/dlcquest/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -71,7 +71,6 @@ def precollect_coinsanity(self):
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]
Expand All @@ -87,3 +86,19 @@ def fill_slot_data(self):
"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

0 comments on commit 88d69db

Please sign in to comment.