From f79657b41a8aa7904193331b7ae181e0ff9ab967 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Tue, 10 Dec 2024 19:53:42 +0100 Subject: [PATCH 01/18] WebHost: disable abbreviations for argparse (#4352) --- WebHost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebHost.py b/WebHost.py index 3790a5f6f4d2..768eeb512289 100644 --- a/WebHost.py +++ b/WebHost.py @@ -34,7 +34,7 @@ def get_app() -> "Flask": app.config.from_file(configpath, yaml.safe_load) logging.info(f"Updated config from {configpath}") # inside get_app() so it's usable in systems like gunicorn, which do not run WebHost.py, but import it. - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(allow_abbrev=False) parser.add_argument('--config_override', default=None, help="Path to yaml config file that overrules config.yaml.") args = parser.parse_known_args()[0] From 3fb0b57d19b9c223107308c84605e05e6b16e1cf Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:09:36 +0100 Subject: [PATCH 02/18] Core: fix exceptions coming from LocationStore (#4358) * Speedups: add instructions for ASAN * Speedups: move typevars out of classes * Speedups, NetUtils: raise correct exceptions * Speedups: double-check malloc * Tests: more LocationStore tests --- NetUtils.py | 2 ++ _speedups.pyx | 43 ++++++++++++++++++---------- _speedups.pyxbld | 18 ++++++++---- test/netutils/test_location_store.py | 41 ++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 20 deletions(-) diff --git a/NetUtils.py b/NetUtils.py index ec6ff3eb1d81..196a030f4969 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -410,6 +410,8 @@ def get_checked(self, state: typing.Dict[typing.Tuple[int, int], typing.Set[int] checked = state[team, slot] if not checked: # This optimizes the case where everyone connects to a fresh game at the same time. + if slot not in self: + raise KeyError(slot) return [] return [location_id for location_id in self[slot] if diff --git a/_speedups.pyx b/_speedups.pyx index dc039e336500..2ad1a2953a2b 100644 --- a/_speedups.pyx +++ b/_speedups.pyx @@ -69,6 +69,14 @@ cdef struct IndexEntry: size_t count +if TYPE_CHECKING: + State = Dict[Tuple[int, int], Set[int]] +else: + State = Union[Tuple[int, int], Set[int], defaultdict] + +T = TypeVar('T') + + @cython.auto_pickle(False) cdef class LocationStore: """Compact store for locations and their items in a MultiServer""" @@ -137,10 +145,16 @@ cdef class LocationStore: warnings.warn("Game has no locations") # allocate the arrays and invalidate index (0xff...) - self.entries = self._mem.alloc(count, sizeof(LocationEntry)) + if count: + # leaving entries as NULL if there are none, makes potential memory errors more visible + self.entries = self._mem.alloc(count, sizeof(LocationEntry)) self.sender_index = self._mem.alloc(max_sender + 1, sizeof(IndexEntry)) self._raw_proxies = self._mem.alloc(max_sender + 1, sizeof(PyObject*)) + assert (not self.entries) == (not count) + assert self.sender_index + assert self._raw_proxies + # build entries and index cdef size_t i = 0 for sender, locations in sorted(locations_dict.items()): @@ -190,8 +204,6 @@ cdef class LocationStore: raise KeyError(key) return self._raw_proxies[key] - T = TypeVar('T') - def get(self, key: int, default: T) -> Union[PlayerLocationProxy, T]: # calling into self.__getitem__ here is slow, but this is not used in MultiServer try: @@ -246,12 +258,11 @@ cdef class LocationStore: all_locations[sender].add(entry.location) return all_locations - if TYPE_CHECKING: - State = Dict[Tuple[int, int], Set[int]] - else: - State = Union[Tuple[int, int], Set[int], defaultdict] - def get_checked(self, state: State, team: int, slot: int) -> List[int]: + cdef ap_player_t sender = slot + if sender < 0 or sender >= self.sender_index_size: + raise KeyError(slot) + # This used to validate checks actually exist. A remnant from the past. # If the order of locations becomes relevant at some point, we could not do sorted(set), so leaving it. cdef set checked = state[team, slot] @@ -263,7 +274,6 @@ cdef class LocationStore: # Unless the set is close to empty, it's cheaper to use the python set directly, so we do that. cdef LocationEntry* entry - cdef ap_player_t sender = slot cdef size_t start = self.sender_index[sender].start cdef size_t count = self.sender_index[sender].count return [entry.location for @@ -273,9 +283,11 @@ cdef class LocationStore: def get_missing(self, state: State, team: int, slot: int) -> List[int]: cdef LocationEntry* entry cdef ap_player_t sender = slot + if sender < 0 or sender >= self.sender_index_size: + raise KeyError(slot) + cdef set checked = state[team, slot] cdef size_t start = self.sender_index[sender].start cdef size_t count = self.sender_index[sender].count - cdef set checked = state[team, slot] if not len(checked): # Skip `in` if none have been checked. # This optimizes the case where everyone connects to a fresh game at the same time. @@ -290,9 +302,11 @@ cdef class LocationStore: def get_remaining(self, state: State, team: int, slot: int) -> List[Tuple[int, int]]: cdef LocationEntry* entry cdef ap_player_t sender = slot + if sender < 0 or sender >= self.sender_index_size: + raise KeyError(slot) + cdef set checked = state[team, slot] cdef size_t start = self.sender_index[sender].start cdef size_t count = self.sender_index[sender].count - cdef set checked = state[team, slot] return sorted([(entry.receiver, entry.item) for entry in self.entries[start:start+count] if entry.location not in checked]) @@ -328,7 +342,8 @@ cdef class PlayerLocationProxy: cdef LocationEntry* entry = NULL # binary search cdef size_t l = self._store.sender_index[self._player].start - cdef size_t r = l + self._store.sender_index[self._player].count + cdef size_t e = l + self._store.sender_index[self._player].count + cdef size_t r = e cdef size_t m while l < r: m = (l + r) // 2 @@ -337,7 +352,7 @@ cdef class PlayerLocationProxy: l = m + 1 else: r = m - if entry: # count != 0 + if l < e: entry = self._store.entries + l if entry.location == loc: return entry @@ -349,8 +364,6 @@ cdef class PlayerLocationProxy: return entry.item, entry.receiver, entry.flags raise KeyError(f"No location {key} for player {self._player}") - T = TypeVar('T') - def get(self, key: int, default: T) -> Union[Tuple[int, int, int], T]: cdef LocationEntry* entry = self._get(key) if entry: diff --git a/_speedups.pyxbld b/_speedups.pyxbld index 974eaed03b6a..98f9734614cc 100644 --- a/_speedups.pyxbld +++ b/_speedups.pyxbld @@ -3,8 +3,16 @@ import os def make_ext(modname, pyxfilename): from distutils.extension import Extension - return Extension(name=modname, - sources=[pyxfilename], - depends=["intset.h"], - include_dirs=[os.getcwd()], - language="c") + return Extension( + name=modname, + sources=[pyxfilename], + depends=["intset.h"], + include_dirs=[os.getcwd()], + language="c", + # to enable ASAN and debug build: + # extra_compile_args=["-fsanitize=address", "-UNDEBUG", "-Og", "-g"], + # extra_objects=["-fsanitize=address"], + # NOTE: we can not put -lasan at the front of link args, so needs to be run with + # LD_PRELOAD=/usr/lib/libasan.so ASAN_OPTIONS=detect_leaks=0 path/to/exe + # NOTE: this can't find everything unless libpython and cymem are also built with ASAN + ) diff --git a/test/netutils/test_location_store.py b/test/netutils/test_location_store.py index 1b984015844d..264f35b3cc65 100644 --- a/test/netutils/test_location_store.py +++ b/test/netutils/test_location_store.py @@ -115,6 +115,7 @@ def test_find_item(self) -> None: def test_get_for_player(self) -> None: self.assertEqual(self.store.get_for_player(3), {4: {9}}) self.assertEqual(self.store.get_for_player(1), {1: {13}, 2: {22, 23}}) + self.assertEqual(self.store.get_for_player(9999), {}) def test_get_checked(self) -> None: self.assertEqual(self.store.get_checked(full_state, 0, 1), [11, 12, 13]) @@ -122,18 +123,48 @@ def test_get_checked(self) -> None: self.assertEqual(self.store.get_checked(empty_state, 0, 1), []) self.assertEqual(self.store.get_checked(full_state, 0, 3), [9]) + def test_get_checked_exception(self) -> None: + with self.assertRaises(KeyError): + self.store.get_checked(empty_state, 0, 9999) + bad_state = {(0, 6): {1}} + with self.assertRaises(KeyError): + self.store.get_checked(bad_state, 0, 6) + bad_state = {(0, 9999): set()} + with self.assertRaises(KeyError): + self.store.get_checked(bad_state, 0, 9999) + def test_get_missing(self) -> None: self.assertEqual(self.store.get_missing(full_state, 0, 1), []) self.assertEqual(self.store.get_missing(one_state, 0, 1), [11, 13]) self.assertEqual(self.store.get_missing(empty_state, 0, 1), [11, 12, 13]) self.assertEqual(self.store.get_missing(empty_state, 0, 3), [9]) + def test_get_missing_exception(self) -> None: + with self.assertRaises(KeyError): + self.store.get_missing(empty_state, 0, 9999) + bad_state = {(0, 6): {1}} + with self.assertRaises(KeyError): + self.store.get_missing(bad_state, 0, 6) + bad_state = {(0, 9999): set()} + with self.assertRaises(KeyError): + self.store.get_missing(bad_state, 0, 9999) + def test_get_remaining(self) -> None: self.assertEqual(self.store.get_remaining(full_state, 0, 1), []) self.assertEqual(self.store.get_remaining(one_state, 0, 1), [(1, 13), (2, 21)]) self.assertEqual(self.store.get_remaining(empty_state, 0, 1), [(1, 13), (2, 21), (2, 22)]) self.assertEqual(self.store.get_remaining(empty_state, 0, 3), [(4, 99)]) + def test_get_remaining_exception(self) -> None: + with self.assertRaises(KeyError): + self.store.get_remaining(empty_state, 0, 9999) + bad_state = {(0, 6): {1}} + with self.assertRaises(KeyError): + self.store.get_missing(bad_state, 0, 6) + bad_state = {(0, 9999): set()} + with self.assertRaises(KeyError): + self.store.get_remaining(bad_state, 0, 9999) + def test_location_set_intersection(self) -> None: locations = {10, 11, 12} locations.intersection_update(self.store[1]) @@ -181,6 +212,16 @@ def test_no_locations(self) -> None: }) self.assertEqual(len(store), 1) self.assertEqual(len(store[1]), 0) + self.assertEqual(sorted(store.find_item(set(), 1)), []) + self.assertEqual(sorted(store.find_item({1}, 1)), []) + self.assertEqual(sorted(store.find_item({1, 2}, 1)), []) + self.assertEqual(store.get_for_player(1), {}) + self.assertEqual(store.get_checked(empty_state, 0, 1), []) + self.assertEqual(store.get_checked(full_state, 0, 1), []) + self.assertEqual(store.get_missing(empty_state, 0, 1), []) + self.assertEqual(store.get_missing(full_state, 0, 1), []) + self.assertEqual(store.get_remaining(empty_state, 0, 1), []) + self.assertEqual(store.get_remaining(full_state, 0, 1), []) def test_no_locations_for_1(self) -> None: store = self.type({ From 781100a571fe7e4850272a8899c5ef9d078f19d8 Mon Sep 17 00:00:00 2001 From: Jouramie <16137441+Jouramie@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:26:33 -0500 Subject: [PATCH 03/18] CI: remove version restriction on pytest-subtests (#4356) This reverts commit e3b5451672c694c12974801f5c89cc172db3ff5a. --- .github/workflows/unittests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 9db9de9b4042..88b5d12987ad 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -53,7 +53,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest "pytest-subtests<0.14.0" pytest-xdist + pip install pytest pytest-subtests pytest-xdist python ModuleUpdate.py --yes --force --append "WebHostLib/requirements.txt" python Launcher.py --update_settings # make sure host.yaml exists for tests - name: Unittests From 5dd19fccd0dc89966095c93c3fdb3ad72b4bea08 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:35:36 +0100 Subject: [PATCH 04/18] MultiServer/CommonClient: We forgot about Item Links again (Hint Priority) (#4314) * Vi don't forget about itemlinks challenge difficulty impossible * People other than Vi also don't forget about ItemLinks challenge difficulty impossible --- MultiServer.py | 2 +- NetUtils.py | 2 +- kvui.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MultiServer.py b/MultiServer.py index 2561b0692a3c..0601e179152c 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -1914,7 +1914,7 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): hint = ctx.get_hint(client.team, player, location) if not hint: return # Ignored safely - if hint.receiving_player != client.slot: + if client.slot not in ctx.slot_set(hint.receiving_player): await ctx.send_msgs(client, [{'cmd': 'InvalidPacket', "type": "arguments", "text": 'UpdateHint: No Permission', "original_cmd": cmd}]) diff --git a/NetUtils.py b/NetUtils.py index 196a030f4969..a961850639a0 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -232,7 +232,7 @@ def _handle_text(self, node: JSONMessagePart): def _handle_player_id(self, node: JSONMessagePart): player = int(node["text"]) - node["color"] = 'magenta' if player == self.ctx.slot else 'yellow' + node["color"] = 'magenta' if self.ctx.slot_concerns_self(player) else 'yellow' node["text"] = self.ctx.player_names[player] return self._handle_color(node) diff --git a/kvui.py b/kvui.py index d98fc7ed9ab8..b2ab004e274a 100644 --- a/kvui.py +++ b/kvui.py @@ -371,7 +371,7 @@ def on_touch_down(self, touch): if self.hint["status"] == HintStatus.HINT_FOUND: return ctx = App.get_running_app().ctx - if ctx.slot == self.hint["receiving_player"]: # If this player owns this hint + if ctx.slot_concerns_self(self.hint["receiving_player"]): # If this player owns this hint # open a dropdown self.dropdown.open(self.ids["status"]) elif self.selected: @@ -800,7 +800,7 @@ def refresh_hints(self, hints): hint_status_node = self.parser.handle_node({"type": "color", "color": status_colors.get(hint["status"], "red"), "text": status_names.get(hint["status"], "Unknown")}) - if hint["status"] != HintStatus.HINT_FOUND and hint["receiving_player"] == ctx.slot: + if hint["status"] != HintStatus.HINT_FOUND and ctx.slot_concerns_self(hint["receiving_player"]): hint_status_node = f"[u]{hint_status_node}[/u]" data.append({ "receiving": {"text": self.parser.handle_node({"type": "player_id", "text": hint["receiving_player"]})}, From 925fb967d3274e64a8f88b73d81b97ce51c6d0d2 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 10 Dec 2024 14:36:38 -0500 Subject: [PATCH 05/18] Lingo: Fix number hunt issues on panels mode (#4342) --- worlds/lingo/data/generated.dat | Bin 149230 -> 149485 bytes worlds/lingo/test/TestDatafile.py | 7 ++++++- worlds/lingo/utils/pickle_static_data.py | 16 ++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/worlds/lingo/data/generated.dat b/worlds/lingo/data/generated.dat index 9abb0276c8b5ac2fb1e81eff1e2c2cc06489ddec..8b159d4ae4ac7c565e2372b1cc43d7a349b2ca7c 100644 GIT binary patch delta 5053 zcma)ZV~ zz$q=awm#WI(@LE!b3fMlM#V=7mV~xjuDu_tpWUAOJLfkby0xG64}ahJp7T5RchB#4 z@71r?`+m8>cbOCXK-uFD%Lk#q8C0}XK!DEfHL0WwzfFM<+%pLFb42aXo*(4lfkVs? zhGF9&hO95nHiMtbH5k70q~G4YTBk@_?Og7}mxsV^*y@^NfVB$f@oFTjfe2g>1v!-I zgImoIfNw{^FE9)DMMDnEa{U?&Qx$jk(Jaz&KD6(5?S_K~gUuKG@gT_k<* z{9N$E0)(udb>j9)C~#%XfQ??T*VQ%~)+w+7XWk2TcoDDM3%O#5uYgP)@1(1?0%APH zazqdDskxA$)8bjTiX58D4;GxM>~);+%Pqq~wO-dn4p;@HN^X>E{wnCBS2_o|tQ+B&C$wUw6UK;Pi4#VPVYd?=g=;vz z8Agd=akG%u@Qr5Ct|5syt_9L)T+{;TG``jXk0@*8i4f~@twHGLNwr%x!<{-ZSN{kj z`av`f+5tsA(JAhgeZ3ea;@%zNz|C+~z6v`AKn4yx2uWg?co2q(!Fo`f)eL-F{`&MF z#EM`255X|CcCd$smVudvAX{B3dF3I9Q5}+Z9)ehPtK^G^AVJ+H+5a$%Q1#*fiMjcQ zVT?Y4d6b8TJ=(GViNUz-Fa)c!WWu4tkfpvU+4l%cQrjfYIszr?Cz5v^fg<%s$#4`( zRaKl7QT(x^;vGaR* zw;YFo`X71%363)vA$a~cM5v(=T;=EEFj~!zWX@~_lUgPD(N@v!#gfkwuaq2e0>-Nw zCC@nl+1^hvk8*tb_U-uA2^g-vD1)Dipt@Uf@=3^14@h2mQuq^+-#sacbx8I(CH!!4 zltoKRPCe_Yp?KjGgm?#v$5iypQF3e``nSOVHJk+w zZxan&I+TN=MvNmMEC`$0AV{CsBcn+=`nRgMuMPav4IIGJB1wHw@)vF5kkG4Mtg6px z2vg|=A^48dFwjQNv)ryeWtEE!r4`lYDyy@Yo<)AI$ynbq^Fnj=%~AR;xTATM^DXr^ zN9nC1qx#~?YV%FO2Fuk(r?xFtWT<>n;vARTgRtwg*wRf#nuqEc@pSx2a?%+XrEZs8 zeFoCiy^^<|5!-%A@)yKsCC8r?d{A=LS(u=jhjGo_#4{!TbQTiTVe#yf&WZX{5}2#c zL5A8YdB-`Js9ux&(>W+qha_^&r1yk3N#61vWU7x#{)l++2+oOkUp%?jlbG*%U#yv4 zBjUcA--lxT3}$&MYWhPs_B{{5`u35OK{f_Af3c>%2isLjQIch}rGp_`Q;^gyM{L zD1c@7Y&!(aT$e5`x=j34q|lbzeNzl&4b_V(>S~?ZjhLs5jr^^cmyD&}8pD7NaRg-z zyrTmm{FqnJwSeYeZIqJeEw8cy9UTy9@(6&97;w ztGE1jST0weUpeo$qH@7{aoTThkth)8u7qI@vY*^Jd9qQ;@jZnxK8mkar4Yh@v358iH)7& zqv+<>dU96c9jZN3VyQg(xTO#|3fB9zTyIavDb|=mB~z#L*0R4|GxMhORKem);+@V7;fnIC zdzMX{-g_e7oVcmHX?fi@#o2t)?Yg{)1*Y=e`QFqFyI1kV;+vM`!w*LHkyCTB%gQHF zf==9v#-}btHo}IHmm#T}#c?y>M>$GA_deNh{bd-Nxj+jPXV=o9JxoJ^Rz!nY3l@VG zO}x%B+tSanUrQttO6E1qKtrYFj7$9(0>gZoTMIns4~F~-zwU`p8WRJqWYPm+)UJxL z(Br7;;Rtv=$fpnlHE5sV$wVc?_X~=t?pRu(H^;u@iQ3l`^AX0XeZ$76eMibyDD8Wq zK1Bb-StFG2zSl?u@ciqzYJ^gK@4tAG_5%e1xy+B!{7hy5n_t)%HIFQzf~Xu24J1;C zf{8qd1`&A?4JOiMVOf%rY*U31pHv?T7(~FT`AVZF6TzmhH2uj$vhkPZHZpzL+%C-k zGEr=TqzNVy%_fA6Q5#GuMkppZ6I+GPcVZ2ODAU~2*6QxNaGm1?z8>2RoRJu@FD$!^`4O*Hz zn2x_BDDamO+#J%=V{5#{m3aoCokq!wh8F|nDz=~^zCLSd|0 zo-_qyirARg*u5uLSnJJoOPqz1Sr=i^NF~iSS>~5eeklh^rI|wJPBvxIOeIssW|}n9 z$&|C1AwVb2pm>(pbsNW>e3`s4XOQk5Kl$6VR5b7;_hqsSrk6OmrX75~BNw{y;QWP=mHq zpg84?WX!@?wI()3Z5e)^sze4Zr-+4fSGXf9F(OS#AFzrdRa9>^(St;5usTf%3VMV@ zEs3>63wZiE+?=MwjkS}hr`UR;2BOD^77}eBT12#wXtAIMZIeKH;W%1GDF&O9e`zfg zUn=5O4c+l4Nj*f9Hxo7T070FhK!BPv(h|AW*M93rFntO3O3uMd5I6} z!>nGGYC9#ZWV1t>on%(A*(J^EWLC3z1255S?2!Q%1s>tRpQU+=%y2gQq}fkqEt|hc zbAZe`Ht$IDS2B;XImpJS9VTTL%HF@cW|6thkXKz_S5bYx*;%;$s7j4J;(k(}OjpK7 z9H;chMS6qQ$`!OzayTQ0_wa{wCCt_?e_aqmVKZOv18FXjX<^gJ#;A3XLZP%vL{AW1 zCVEm(gZ43}X@4iPnJ0cC%@s0R*!)A9&&WI_Oq5moT&gcgJ+NMHzDQzrm z29Kt-*4kE2hGy$CZLM8wy&&EYQ`AJQZP(h?*4k%#T(kB)=Y{dI7yg*{_x;X!&v(A} zeZOJ;_Pp5*mp?wJ?@*U-yp#fKm*IhkPh?O^Syp3hc($6JR|Y#B>9! zg-(~t09Sz0eQ-|_jN{5)UPZ;@FeVk^T|);$2tW-MCqt1KUPy*1P~*Cu47YrhvC%lQ z7WCNP0tVOMEa>Y4yKwYq*e8bXM~hof!`M0omWkqdd62K{(!0C!c6H^!SRL3frV#GP z)Qlqd6{KKG5eyZ>wIaxX6j#4uSgR8ix0ga0cZZ&3kRz#QS-kOjAqxr zA6fMFba+cf?&cWRz(Y7-8wBE|L~dY24I32ks0*vX4o&z&HH;HO z_B_bNt^Fa$wR#>zdg4n-&<9&gkcw~5fFS(V1Ver7x{89S1*J}WJ_4d}%tDC9&IplK zuoe1Z(?S@4KgEjswk(A0%Gw0nTqE@C8c0`i`68djb2TtgF(zQVS&mmtqDo4w=rpkm z1}M`KFoxzG9xMuN6)M!B-7%DadPDf`M7kR7 z<|w?@3gK!Ei!H}Qv)%(ZZ^$u7Qc?1(V=&ZjY&3al(BMdWJsfL}i=+1GG0>~k9Ko-T zL9%Mo^X!N=7^Lo!T-XK)e%qL7cB13vo=C^&y*hlc4MP2{y8|hX_7UOuSsTQtJ~3S7 zr#2X=rVM1xISxf?rR4VG;yro!I1Ewex<#J4Nb)BqMKJk<=w-P(7>t$^FvNQei!8^@ zKlH`lpMb&Yrh77e78&XeDbi0uzWT;J!RJnj;P0dmHyERSEZO^%*!I4$++pb{Nb##> zrsqs>#MJe}9j74NyFp6F$%B#DN#bT4&B$_;wT5EgY3QfkW`Rkk#X?sM;-DxI@8}a1 zf-6r$h@ZDx#*uXNZd397(-5fEZ~#w z8gs>~C^yq@eC^T)5{>R)uZr5`_ZOjeSWfh>FfBFJ-5*_WH(F3zV{W)Vy2KsD*V-Y> zZ>{?}$#Ly`2zIrLt*9FGqr|CM;JcR;G@oyz$ z!VgO2{1-oiT=g-@mx*sl)}Isa_t|vLnR-t2OkXzQxt!;q)Gv#f4++-y7GK4F=f!gD z&!h~p@wll#3BfUe;Eg5c!GIs0hY0+hJ~p0*{+Qb-s8dkC;BrfSjm2cO(kABDFRHgJ zv@JrvP6)^2g-STu>0^2)6vAxW*$E+4=4^43+2W%_p+jN!&Cpla>Xubo9&>7UW1cdW z`QKt*GB)hN7zSN{5LMQ|iJ$UK+s1vCfibN#43|Ay54|PB29BjFC zcS`P6h{LV~CD0wMClg?}$LzccvDoxE1jTcgT)P)_Y1QU~hsR2%-K$`EZA16+RN?h& zpbxlT#eDG}D)6%SYUhGgm~**j>1Y1mrRV7XUiz85^s?wo{OB@_O6D8Pa~HMReJ9jg z8}xY=Q?-*Cr(cuZjnBixF7Y2m&cGR65G8pQuILi~CfU!zz3!Y@c(qG>r?cn%iNlpY zg137i#V!rRpgcu&8?jgMy>;~d%W1PlzUEs+$~37RQS}DPJ`XEa#~q;1J&-OvFj>}CKnXk>*Y#& zjW3%r`CcvGMX#!Y$?hsR@fw6S@=|a`dFDMUil^T@QO7T8_s>B2xSY*L-mWVsE-dQV z4EElf?^Rk{dS6>U{D$m+nglj%psL z{Or?wV!Q|axuQW?mD=Y}F1;BB?T8qS9!FIVN1uHmK1L8^(~jctG-ZVEF^Z|(vEfE< zjgJx~Nm?fbg1O8E zX)clJ$L4c32Ca)!2$j1+6iRfJD2(VDQGcQ@h$4u-%*Dw=m7$G)5@w}S`!fafB4E}2 zBF)!iV%U5m&9`I*vbiD6-^uv1xhc&LWMbL;Lz;h*iDUC48-sR>RJ>5yzxojlBD_tM zK=e~ChGi(x}_6r4m!v#D>akGjTj45n9rO}Z|Wuvk&Xg;LU@Vntk7&Ku48BV5>O_nqx$V_1~QkonxQ`zK7Gn&ja zHe(v48cS+At9)q+$jo3fUYa5@Rcwl-DIxO+n+ejCl9|b-Oqxk#X0e&f#-LS_nk|&w ze=M#Vt{BEmAyX}kHkD`|(KMp@MAL~D2(oE21d5aX2pN+wR&6F5gEkw#8LkWroyg`XCh(w$ACePJ&%VCck z_TjA&N>t;1dF2v=v6=7mo;2^1*}~=nHU{kgDHKZkkZ3E>M?~8M*|d*2O*=^DMV|Pn nG>6D+XLDGZqhxjn6KmC4rD`Mf5+@y(rd None: "LL1.yaml hash does not match generated.dat. Please regenerate using 'python worlds/lingo/utils/pickle_static_data.py'") self.assertEqual(ids_file_hash, HASHES["ids.yaml"], "ids.yaml hash does not match generated.dat. Please regenerate using 'python worlds/lingo/utils/pickle_static_data.py'") + + def test_panel_doors_are_set(self) -> None: + # This panel is defined earlier in the file than the panel door, so we want to check that the panel door is + # correctly applied. + self.assertNotEqual(PANELS_BY_ROOM["Outside The Agreeable"]["FIVE (1)"].panel_door, None) diff --git a/worlds/lingo/utils/pickle_static_data.py b/worlds/lingo/utils/pickle_static_data.py index cd5c4b41df4b..df82a12861a4 100644 --- a/worlds/lingo/utils/pickle_static_data.py +++ b/worlds/lingo/utils/pickle_static_data.py @@ -111,6 +111,16 @@ def load_static_data(ll1_path, ids_path): with open(ll1_path, "r") as file: config = Utils.parse_yaml(file) + # We have to process all panel doors first so that panels can see what panel doors they're in even if they're + # defined earlier in the file than the panel door. + for room_name, room_data in config.items(): + if "panel_doors" in room_data: + PANEL_DOORS_BY_ROOM[room_name] = dict() + + for panel_door_name, panel_door_data in room_data["panel_doors"].items(): + process_panel_door(room_name, panel_door_name, panel_door_data) + + # Process the rest of the room. for room_name, room_data in config.items(): process_room(room_name, room_data) @@ -515,12 +525,6 @@ def process_room(room_name, room_data): for source_room, doors in room_data["entrances"].items(): process_entrance(source_room, doors, room_obj) - if "panel_doors" in room_data: - PANEL_DOORS_BY_ROOM[room_name] = dict() - - for panel_door_name, panel_door_data in room_data["panel_doors"].items(): - process_panel_door(room_name, panel_door_name, panel_door_data) - if "panels" in room_data: PANELS_BY_ROOM[room_name] = dict() From 704f14ffcd80d32a4c0ffed4bdf4cf38324b0dc5 Mon Sep 17 00:00:00 2001 From: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:37:54 -0500 Subject: [PATCH 06/18] Core: Add toggles_as_bools to options.as_dict (#3770) * Add toggles_as_bools to options.as_dict * Update Options.py Co-authored-by: Doug Hoskisson * Add param to docstring * if -> elif --------- Co-authored-by: Doug Hoskisson --- Options.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Options.py b/Options.py index d3b2e6c1ba11..4e26a0d56c5c 100644 --- a/Options.py +++ b/Options.py @@ -754,7 +754,7 @@ def __init__(self, value: int) -> None: elif value > self.range_end and value not in self.special_range_names.values(): raise Exception(f"{value} is higher than maximum {self.range_end} for option {self.__class__.__name__} " + f"and is also not one of the supported named special values: {self.special_range_names}") - + # See docstring for key in self.special_range_names: if key != key.lower(): @@ -1180,7 +1180,7 @@ def __len__(self) -> int: class Accessibility(Choice): """ Set rules for reachability of your items/locations. - + **Full:** ensure everything can be reached and acquired. **Minimal:** ensure what is needed to reach your goal can be acquired. @@ -1198,7 +1198,7 @@ class Accessibility(Choice): class ItemsAccessibility(Accessibility): """ Set rules for reachability of your items/locations. - + **Full:** ensure everything can be reached and acquired. **Minimal:** ensure what is needed to reach your goal can be acquired. @@ -1249,12 +1249,16 @@ class CommonOptions(metaclass=OptionsMetaProperty): progression_balancing: ProgressionBalancing accessibility: Accessibility - def as_dict(self, *option_names: str, casing: str = "snake") -> typing.Dict[str, typing.Any]: + def as_dict(self, + *option_names: str, + casing: typing.Literal["snake", "camel", "pascal", "kebab"] = "snake", + toggles_as_bools: bool = False) -> typing.Dict[str, typing.Any]: """ Returns a dictionary of [str, Option.value] :param option_names: names of the options to return :param casing: case of the keys to return. Supports `snake`, `camel`, `pascal`, `kebab` + :param toggles_as_bools: whether toggle options should be output as bools instead of strings """ assert option_names, "options.as_dict() was used without any option names." option_results = {} @@ -1276,6 +1280,8 @@ def as_dict(self, *option_names: str, casing: str = "snake") -> typing.Dict[str, value = getattr(self, option_name).value if isinstance(value, set): value = sorted(value) + elif toggles_as_bools and issubclass(type(self).type_hints[option_name], Toggle): + value = bool(value) option_results[display_name] = value else: raise ValueError(f"{option_name} not found in {tuple(type(self).type_hints)}") From 54a0a5ac0002ff1edf858441891625600b69e812 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:06:06 +0100 Subject: [PATCH 07/18] The Witness: Put progression + useful on some items. (#4027) * proguseful * ruff * variable rename * variable rename * Better (?) comment * Better way to do this? I guess * sure * ruff * Eh, it's not worth it. Here's the much simpler version * don't need this now * Improve some classification checks while we're at it * Only proguseful obelisk keys if eps are individual --- worlds/witness/player_items.py | 48 +++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/worlds/witness/player_items.py b/worlds/witness/player_items.py index 831e614f21c4..d1b951fa8e15 100644 --- a/worlds/witness/player_items.py +++ b/worlds/witness/player_items.py @@ -7,6 +7,7 @@ from BaseClasses import Item, ItemClassification, MultiWorld from .data import static_items as static_witness_items +from .data import static_logic as static_witness_logic from .data.item_definition_classes import ( DoorItemDefinition, ItemCategory, @@ -53,9 +54,8 @@ def __init__(self, world: "WitnessWorld", player_logic: WitnessPlayerLogic, # Remove all progression items that aren't actually in the game. self.item_data = { name: data for (name, data) in self.item_data.items() - if data.classification not in - {ItemClassification.progression, ItemClassification.progression_skip_balancing} - or name in player_logic.PROGRESSION_ITEMS_ACTUALLY_IN_THE_GAME + if ItemClassification.progression not in data.classification + or name in player_logic.PROGRESSION_ITEMS_ACTUALLY_IN_THE_GAME } # Downgrade door items @@ -72,7 +72,7 @@ def __init__(self, world: "WitnessWorld", player_logic: WitnessPlayerLogic, # Add progression items to the mandatory item list. progression_dict = { name: data for (name, data) in self.item_data.items() - if data.classification in {ItemClassification.progression, ItemClassification.progression_skip_balancing} + if ItemClassification.progression in data.classification } for item_name, item_data in progression_dict.items(): if isinstance(item_data.definition, ProgressiveItemDefinition): @@ -100,6 +100,46 @@ def __init__(self, world: "WitnessWorld", player_logic: WitnessPlayerLogic, self.item_data[location_name] = ItemData(None, ItemDefinition(0, ItemCategory.EVENT), ItemClassification.progression, False) + # Determine which items should be progression + useful, if they exist in some capacity. + # Note: Some of these may need to be updated for the "independent symbols" PR. + self._proguseful_items = { + "Dots", "Stars", "Shapers", "Black/White Squares", + "Caves Shortcuts", "Caves Mountain Shortcut (Door)", "Caves Swamp Shortcut (Door)", + "Boat", + } + + if self._world.options.shuffle_EPs == "individual": + self._proguseful_items |= { + "Town Obelisk Key", # Most checks + "Monastery Obelisk Key", # Most sphere 1 checks, and also super dense ("Jackpot" vibes)} + } + + if self._world.options.shuffle_discarded_panels: + # Discards only give a moderate amount of checks, but are very spread out and a lot of them are in sphere 1. + # Thus, you really want to have the discard-unlocking item as quickly as possible. + + if self._world.options.puzzle_randomization in ("none", "sigma_normal"): + self._proguseful_items.add("Triangles") + elif self._world.options.puzzle_randomization == "sigma_expert": + self._proguseful_items.add("Arrows") + # Discards require two symbols in Variety, so the "sphere 1 unlocking power" of Arrows is not there. + if self._world.options.puzzle_randomization == "sigma_expert": + self._proguseful_items.add("Triangles") + self._proguseful_items.add("Full Dots") + self._proguseful_items.add("Stars + Same Colored Symbol") + self._proguseful_items.discard("Stars") # Stars are not that useful on their own. + if self._world.options.puzzle_randomization == "umbra_variety": + self._proguseful_items.add("Triangles") + + # This needs to be improved when the improved independent&progressive symbols PR is merged + for item in list(self._proguseful_items): + self._proguseful_items.add(static_witness_logic.get_parent_progressive_item(item)) + + for item_name, item_data in self.item_data.items(): + if item_name in self._proguseful_items: + item_data.classification |= ItemClassification.useful + + def get_mandatory_items(self) -> Dict[str, int]: """ Returns the list of items that must be in the pool for the game to successfully generate. From 9a37a136a1ab02c561b704a144b6424eac5db416 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:13:45 +0100 Subject: [PATCH 08/18] The Witness: Add more panels to the "doors: panels" mode (#2916) * Add more panels that should be panels * Make it so the caves panel items don't exist in early caves * Remove unused import * oops * Remove Jungle to Monastery Garden from usefulification list * Add a basic test * ruff --------- Co-authored-by: Fabian Dill --- worlds/witness/data/WitnessItems.txt | 12 ++++++-- .../Door_Shuffle/Complex_Door_Panels.txt | 5 ++++ .../settings/Door_Shuffle/Simple_Panels.txt | 4 +-- worlds/witness/data/settings/Early_Caves.txt | 6 +++- .../data/settings/Early_Caves_Start.txt | 6 +++- worlds/witness/player_items.py | 7 +++-- worlds/witness/player_logic.py | 12 ++++++-- worlds/witness/test/test_door_shuffle.py | 28 ++++++++++++++++++- 8 files changed, 67 insertions(+), 13 deletions(-) diff --git a/worlds/witness/data/WitnessItems.txt b/worlds/witness/data/WitnessItems.txt index 782fa9c3d226..57aee28e45b6 100644 --- a/worlds/witness/data/WitnessItems.txt +++ b/worlds/witness/data/WitnessItems.txt @@ -56,6 +56,7 @@ Doors: 1119 - Quarry Stoneworks Entry (Panel) - 0x01E5A,0x01E59 1120 - Quarry Stoneworks Ramp Controls (Panel) - 0x03678,0x03676 1122 - Quarry Stoneworks Lift Controls (Panel) - 0x03679,0x03675 +1123 - Quarry Stoneworks Stairs (Panel) - 0x03677 1125 - Quarry Boathouse Ramp Height Control (Panel) - 0x03852 1127 - Quarry Boathouse Ramp Horizontal Control (Panel) - 0x03858 1129 - Quarry Boathouse Hook Control (Panel) - 0x275FA @@ -84,6 +85,7 @@ Doors: 1205 - Treehouse Laser House Door Timer (Panel) - 0x2700B,0x17CBC 1208 - Treehouse Drawbridge (Panel) - 0x037FF 1175 - Jungle Popup Wall (Panel) - 0x17CAB +1178 - Jungle Monastery Garden Shortcut (Panel) - 0x17CAA 1180 - Bunker Entry (Panel) - 0x17C2E 1183 - Bunker Tinted Glass Door (Panel) - 0x0A099 1186 - Bunker Elevator Control (Panel) - 0x0A079 @@ -94,12 +96,15 @@ Doors: 1195 - Swamp Rotating Bridge (Panel) - 0x181F5 1196 - Swamp Long Bridge (Panel) - 0x17E2B 1197 - Swamp Maze Controls (Panel) - 0x17C0A,0x17E07 +1199 - Swamp Laser Shortcut (Panel) - 0x17C05 1220 - Mountain Floor 1 Light Bridge (Panel) - 0x09E39 1225 - Mountain Floor 2 Light Bridge Near (Panel) - 0x09E86 1230 - Mountain Floor 2 Light Bridge Far (Panel) - 0x09ED8 1235 - Mountain Floor 2 Elevator Control (Panel) - 0x09EEB 1240 - Caves Entry (Panel) - 0x00FF8 1242 - Caves Elevator Controls (Panel) - 0x335AB,0x335AC,0x3369D +1243 - Caves Mountain Shortcut (Panel) - 0x021D7 +1244 - Caves Swamp Shortcut (Panel) - 0x17CF2 1245 - Challenge Entry (Panel) - 0x0A16E 1250 - Tunnels Entry (Panel) - 0x039B4 1255 - Tunnels Town Shortcut (Panel) - 0x09E85 @@ -250,19 +255,20 @@ Doors: 2101 - Outside Tutorial Outpost Panels - 0x0A171,0x04CA4 2105 - Desert Panels - 0x09FAA,0x1C2DF,0x1831E,0x1C260,0x1831C,0x1C2F3,0x1831D,0x1C2B1,0x1831B,0x0C339,0x0A249,0x0A015,0x09FA0,0x09F86 2110 - Quarry Outside Panels - 0x17C09,0x09E57,0x17CC4 -2115 - Quarry Stoneworks Panels - 0x01E5A,0x01E59,0x03678,0x03676,0x03679,0x03675 +2115 - Quarry Stoneworks Panels - 0x01E5A,0x01E59,0x03678,0x03676,0x03679,0x03675,0x03677 2120 - Quarry Boathouse Panels - 0x03852,0x03858,0x275FA 2122 - Keep Hedge Maze Panels - 0x00139,0x019DC,0x019E7,0x01A0F 2125 - Monastery Panels - 0x09D9B,0x00C92,0x00B10 +2127 - Jungle Panels - 0x17CAB,0x17CAA 2130 - Town Church & RGB House Panels - 0x28998,0x28A0D,0x334D8 2135 - Town Maze Panels - 0x2896A,0x28A79 2137 - Town Dockside House Panels - 0x0A0C8,0x09F98 2140 - Windmill & Theater Panels - 0x17D02,0x00815,0x17F5F,0x17F89,0x0A168,0x33AB2 2145 - Treehouse Panels - 0x0A182,0x0288C,0x02886,0x2700B,0x17CBC,0x037FF 2150 - Bunker Panels - 0x34BC5,0x34BC6,0x0A079,0x0A099,0x17C2E -2155 - Swamp Panels - 0x00609,0x18488,0x181F5,0x17E2B,0x17C0A,0x17E07,0x17C0D,0x0056E +2155 - Swamp Panels - 0x00609,0x18488,0x181F5,0x17E2B,0x17C0A,0x17E07,0x17C0D,0x0056E,0x17C05 2160 - Mountain Panels - 0x09ED8,0x09E86,0x09E39,0x09EEB -2165 - Caves Panels - 0x3369D,0x00FF8,0x0A16E,0x335AB,0x335AC +2165 - Caves Panels - 0x3369D,0x00FF8,0x0A16E,0x335AB,0x335AC,0x021D7,0x17CF2 2170 - Tunnels Panels - 0x09E85,0x039B4 2200 - Desert Obelisk Key - 0x0332B,0x03367,0x28B8A,0x037B6,0x037B2,0x000F7,0x3351D,0x0053C,0x00771,0x335C8,0x335C9,0x337F8,0x037BB,0x220E4,0x220E5,0x334B9,0x334BC,0x22106,0x0A14C,0x0A14D,0x00359 diff --git a/worlds/witness/data/settings/Door_Shuffle/Complex_Door_Panels.txt b/worlds/witness/data/settings/Door_Shuffle/Complex_Door_Panels.txt index 63d8a58d2676..6c3b328691f9 100644 --- a/worlds/witness/data/settings/Door_Shuffle/Complex_Door_Panels.txt +++ b/worlds/witness/data/settings/Door_Shuffle/Complex_Door_Panels.txt @@ -9,6 +9,7 @@ Desert Flood Room Entry (Panel) Quarry Entry 1 (Panel) Quarry Entry 2 (Panel) Quarry Stoneworks Entry (Panel) +Quarry Stoneworks Stairs (Panel) Shadows Door Timer (Panel) Keep Hedge Maze 1 (Panel) Keep Hedge Maze 2 (Panel) @@ -28,11 +29,15 @@ Treehouse Third Door (Panel) Treehouse Laser House Door Timer (Panel) Treehouse Drawbridge (Panel) Jungle Popup Wall (Panel) +Jungle Monastery Garden Shortcut (Panel) Bunker Entry (Panel) Bunker Tinted Glass Door (Panel) Swamp Entry (Panel) Swamp Platform Shortcut (Panel) +Swamp Laser Shortcut (Panel) Caves Entry (Panel) +Caves Mountain Shortcut (Panel) +Caves Swamp Shortcut (Panel) Challenge Entry (Panel) Tunnels Entry (Panel) Tunnels Town Shortcut (Panel) \ No newline at end of file diff --git a/worlds/witness/data/settings/Door_Shuffle/Simple_Panels.txt b/worlds/witness/data/settings/Door_Shuffle/Simple_Panels.txt index 23501d20d3a7..f9b8b1b43ae7 100644 --- a/worlds/witness/data/settings/Door_Shuffle/Simple_Panels.txt +++ b/worlds/witness/data/settings/Door_Shuffle/Simple_Panels.txt @@ -7,6 +7,7 @@ Quarry Stoneworks Panels Quarry Boathouse Panels Keep Hedge Maze Panels Monastery Panels +Jungle Panels Town Church & RGB House Panels Town Maze Panels Windmill & Theater Panels @@ -18,5 +19,4 @@ Mountain Panels Caves Panels Tunnels Panels Glass Factory Entry (Panel) -Shadows Door Timer (Panel) -Jungle Popup Wall (Panel) \ No newline at end of file +Shadows Door Timer (Panel) \ No newline at end of file diff --git a/worlds/witness/data/settings/Early_Caves.txt b/worlds/witness/data/settings/Early_Caves.txt index 48c8056bc7b6..df1e7b114a47 100644 --- a/worlds/witness/data/settings/Early_Caves.txt +++ b/worlds/witness/data/settings/Early_Caves.txt @@ -3,4 +3,8 @@ Caves Shortcuts Remove Items: Caves Mountain Shortcut (Door) -Caves Swamp Shortcut (Door) \ No newline at end of file +Caves Swamp Shortcut (Door) + +Forbidden Doors: +0x021D7 (Caves Mountain Shortcut Panel) +0x17CF2 (Caves Swamp Shortcut Panel) \ No newline at end of file diff --git a/worlds/witness/data/settings/Early_Caves_Start.txt b/worlds/witness/data/settings/Early_Caves_Start.txt index a16a6d02bb9f..bc79007fa54b 100644 --- a/worlds/witness/data/settings/Early_Caves_Start.txt +++ b/worlds/witness/data/settings/Early_Caves_Start.txt @@ -6,4 +6,8 @@ Caves Shortcuts Remove Items: Caves Mountain Shortcut (Door) -Caves Swamp Shortcut (Door) \ No newline at end of file +Caves Swamp Shortcut (Door) + +Forbidden Doors: +0x021D7 (Caves Mountain Shortcut Panel) +0x17CF2 (Caves Swamp Shortcut Panel) \ No newline at end of file diff --git a/worlds/witness/player_items.py b/worlds/witness/player_items.py index d1b951fa8e15..2fb987bb456a 100644 --- a/worlds/witness/player_items.py +++ b/worlds/witness/player_items.py @@ -227,10 +227,13 @@ def get_door_ids_in_pool(self) -> List[int]: Returns the total set of all door IDs that are controlled by items in the pool. """ output: List[int] = [] - for item_name, item_data in dict(self.item_data.items()).items(): + + for item_name, item_data in self.item_data.items(): if not isinstance(item_data.definition, DoorItemDefinition): continue - output += [int(hex_string, 16) for hex_string in item_data.definition.panel_id_hexes] + + output += [int(hex_string, 16) for hex_string in item_data.definition.panel_id_hexes + if hex_string not in self._logic.FORBIDDEN_DOORS] return output diff --git a/worlds/witness/player_logic.py b/worlds/witness/player_logic.py index 58f15532f58c..9e6c9597382b 100644 --- a/worlds/witness/player_logic.py +++ b/worlds/witness/player_logic.py @@ -82,6 +82,7 @@ def __init__(self, world: "WitnessWorld", disabled_locations: Set[str], start_in self.PARENT_ITEM_COUNT_PER_BASE_ITEM: Dict[str, int] = defaultdict(lambda: 1) self.PROGRESSIVE_LISTS: Dict[str, List[str]] = {} self.DOOR_ITEMS_BY_ID: Dict[str, List[str]] = {} + self.FORBIDDEN_DOORS: Set[str] = set() self.STARTING_INVENTORY: Set[str] = set() @@ -192,8 +193,9 @@ def reduce_req_within_region(self, entity_hex: str) -> WitnessRule: for subset in these_items: self.BASE_PROGESSION_ITEMS_ACTUALLY_IN_THE_GAME.update(subset) - # Handle door entities (door shuffle) - if entity_hex in self.DOOR_ITEMS_BY_ID: + # If this entity is opened by a door item that exists in the itempool, add that item to its requirements. + # Also, remove any original power requirements this entity might have had. + if entity_hex in self.DOOR_ITEMS_BY_ID and entity_hex not in self.FORBIDDEN_DOORS: # If this entity is opened by a door item that exists in the itempool, add that item to its requirements. door_items = frozenset({frozenset([item]) for item in self.DOOR_ITEMS_BY_ID[entity_hex]}) @@ -329,6 +331,10 @@ def make_single_adjustment(self, adj_type: str, line: str) -> None: if entity_hex in self.DOOR_ITEMS_BY_ID and item_name in self.DOOR_ITEMS_BY_ID[entity_hex]: self.DOOR_ITEMS_BY_ID[entity_hex].remove(item_name) + if adj_type == "Forbidden Doors": + entity_hex = line[:7] + self.FORBIDDEN_DOORS.add(entity_hex) + if adj_type == "Starting Inventory": self.STARTING_INVENTORY.add(line) @@ -704,7 +710,7 @@ def make_options_adjustments(self, world: "WitnessWorld") -> None: self.make_single_adjustment(current_adjustment_type, line) - for entity_id in self.COMPLETELY_DISABLED_ENTITIES: + for entity_id in self.COMPLETELY_DISABLED_ENTITIES | self.FORBIDDEN_DOORS: if entity_id in self.DOOR_ITEMS_BY_ID: del self.DOOR_ITEMS_BY_ID[entity_id] diff --git a/worlds/witness/test/test_door_shuffle.py b/worlds/witness/test/test_door_shuffle.py index 0e38c32d69e2..d593a84bdb8f 100644 --- a/worlds/witness/test/test_door_shuffle.py +++ b/worlds/witness/test/test_door_shuffle.py @@ -1,4 +1,4 @@ -from ..test import WitnessTestBase +from ..test import WitnessMultiworldTestBase, WitnessTestBase class TestIndividualDoors(WitnessTestBase): @@ -22,3 +22,29 @@ def test_swamp_laser_shortcut(self) -> None: ], only_check_listed=True, ) + + +class TestForbiddenDoors(WitnessMultiworldTestBase): + options_per_world = [ + { + "early_caves": "off", + }, + { + "early_caves": "add_to_pool", + }, + ] + + common_options = { + "shuffle_doors": "panels", + "shuffle_postgame": True, + } + + def test_forbidden_doors(self) -> None: + self.assertTrue( + self.get_items_by_name("Caves Mountain Shortcut (Panel)", 1), + "Caves Mountain Shortcut (Panel) should exist in panels shuffle, but it didn't." + ) + self.assertFalse( + self.get_items_by_name("Caves Mountain Shortcut (Panel)", 2), + "Caves Mountain Shortcut (Panel) should be removed when Early Caves is enabled, but it still exists." + ) From 3c5ec49dbee129579573ab7528ddb87185f9fc9a Mon Sep 17 00:00:00 2001 From: Jouramie <16137441+Jouramie@users.noreply.github.com> Date: Thu, 12 Dec 2024 03:17:19 -0500 Subject: [PATCH 09/18] Stardew Valley: Fix potential incompletable seed when starting winter (#4361) * make moss available with any season except winter * add tool and region requirement for moss --- worlds/stardew_valley/logic/logic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worlds/stardew_valley/logic/logic.py b/worlds/stardew_valley/logic/logic.py index 9d4447439f7b..6efc1ade4980 100644 --- a/worlds/stardew_valley/logic/logic.py +++ b/worlds/stardew_valley/logic/logic.py @@ -281,7 +281,7 @@ def __init__(self, player: int, options: StardewValleyOptions, content: StardewC Material.coal: self.mine.can_mine_in_the_mines_floor_41_80() | self.tool.has_tool(Tool.pan), Material.fiber: True_(), Material.hardwood: self.tool.has_tool(Tool.axe, ToolMaterial.copper) & (self.region.can_reach(Region.secret_woods) | self.region.can_reach(Region.island_west)), - Material.moss: True_(), + Material.moss: self.season.has_any_not_winter() & (self.tool.has_tool(Tool.scythe) | self.combat.has_any_weapon) & self.region.can_reach(Region.forest), Material.sap: self.ability.can_chop_trees(), Material.stone: self.tool.has_tool(Tool.pickaxe), Material.wood: self.tool.has_tool(Tool.axe), From f91537fb481e58ff429929f7919a288f3630ba04 Mon Sep 17 00:00:00 2001 From: Justus Lind Date: Thu, 12 Dec 2024 18:18:19 +1000 Subject: [PATCH 10/18] Muse Dash: Remove bad option defaults. #4340 --- worlds/musedash/Options.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/worlds/musedash/Options.py b/worlds/musedash/Options.py index e647c18d7096..b8c969c39b0f 100644 --- a/worlds/musedash/Options.py +++ b/worlds/musedash/Options.py @@ -11,7 +11,6 @@ class DLCMusicPacks(OptionSet): Note: The [Just As Planned] DLC contains all [Muse Plus] songs. """ display_name = "DLC Packs" - default = {} valid_keys = [dlc for dlc in MuseDashCollections.DLC] @@ -142,7 +141,6 @@ class ChosenTraps(OptionSet): Note: SFX traps are only available if [Just as Planned] DLC songs are enabled. """ display_name = "Chosen Traps" - default = {} valid_keys = {trap for trap in MuseDashCollections.trap_items.keys()} From 7d0b701a2df01b93cf292c231d38c4753e6f0715 Mon Sep 17 00:00:00 2001 From: Scipio Wright Date: Thu, 12 Dec 2024 06:54:03 -0500 Subject: [PATCH 11/18] TUNIC: Change rule for heir access in non-hex quest #4365 --- worlds/tunic/er_rules.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/worlds/tunic/er_rules.py b/worlds/tunic/er_rules.py index d5d6f16c57ec..786af0d617a8 100644 --- a/worlds/tunic/er_rules.py +++ b/worlds/tunic/er_rules.py @@ -1079,7 +1079,7 @@ def set_er_region_rules(world: "TunicWorld", regions: Dict[str, Region], portal_ connecting_region=regions["Spirit Arena Victory"], rule=lambda state: (state.has(gold_hexagon, player, world.options.hexagon_goal.value) if world.options.hexagon_quest else - (state.has_all({red_hexagon, green_hexagon, blue_hexagon, "Unseal the Heir"}, player) + (state.has("Unseal the Heir", player) and state.has_group_unique("Hero Relics", player, 6) and has_sword(state, player)))) @@ -1447,6 +1447,9 @@ def set_er_location_rules(world: "TunicWorld") -> None: lambda state: has_ability(prayer, state, world)) set_rule(world.get_location("Library Fuse"), lambda state: has_ability(prayer, state, world) and has_ladder("Ladders in Library", state, world)) + if not world.options.hexagon_quest: + set_rule(world.get_location("Place Questagons"), + lambda state: state.has_all((red_hexagon, blue_hexagon, green_hexagon), player)) # Bombable Walls for location_name in bomb_walls: From 3acbe9ece14ba792ea0c50bf3623e0e377cb18f3 Mon Sep 17 00:00:00 2001 From: LiquidCat64 <74896918+LiquidCat64@users.noreply.github.com> Date: Thu, 12 Dec 2024 06:47:47 -0700 Subject: [PATCH 12/18] Castlevania: Circle of the Moon - Implement New Game (#3299) * Add the cotm package with working seed playthrough generation. * Add the proper event flag IDs for the Item codes. * Oooops. Put the world completion condition in! * Adjust the game name and abbreviations. * Implement more settings. * Account for too many start_inventory_from_pool cards with Halve DSS Cards Placed. * Working (albeit very sloooooooooooow) ROM patching. * Screw you, bsdiff! AP Procedure Patch for life! * Nuke stage_assert_generate as the ROM is no longer needed for that. * Working item writing and position adjusting. * Fix the magic item graphics in Locations wherein they can be fixed. * Enable sub-weapon shuffle * Get the seed display working. * Get the enemy item drop randomization working. Phew! * Enemy drop rando and seed display fixes. * Functional Countdown + Early Double setting * Working multiworld (yay!) * Fix item links and demo shenanigans. * Add Wii U VC hash and a docs section explaining the rereleases. * Change all client read/writes to EWRAM instead of Combined WRAM. * Custom text insertion foundations. * Working text converter and word wrap detector. * More refinements to the text wrap system. * Well and truly working sent/received messages. * Add DeathLink and Battle Arena goal options. * Add tracker stuff, unittests, all locations countdown, presets. * Add to README, CODEOWNERS, and inno_setup * Add to README, CODEOWNERS, and inno_setup * Address some suggestions/problems. * Switch the Items and Locations to using dataclasses. * Add note about the alternate classes to the Game Page. * Oooops, typo! * Touch up the Options descriptions. * Fix Battle Arena flag being detected incorrectly on connection and name the locked location/item pairs better. * Implement option groups * Swap the Lizard-man Locations into their correct Regions. * Local start inventory, better DeathLink message handling, handle receiving over 255 of an item. * Update the PopTracker pack links to no longer point to the Releases page. * Add Skip Dialogues option. * Update the presets for the accessibility rework. * Swap the choices in the accessibility preset options. * Uhhhhhhh...just see the apworld v4 changelog for this one. * Ooops, typo! * . * Bunch of small stuff * Correctly change "Fake" to "Breakable" in this comment. Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Make can_touch_water one line. Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Make broke_iron_maidens one line. Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Fix majors countdown and make can_open_ceremonial_door one line. * Make the Trap AP Item less obvious. * Add Progression + Useful stuff, patcher handling for incompatible versions, and fix some mypy stuff. * Better option groups. * Change Early Double to Early Escape Item. * Update DeathLink description and ditch the Menu region. * Fix the Start Broken choice for Iron Maiden Behavior * Remove the forced option change with Arena goal + required All Bosses and Arena. * Update the Game Page with the removal of the forced option combination change. * Fix client potential to send packets nonstop. * More review addressing. * Fix the new select_drop code. * Fix the new select_drop code for REAL this time. * Send another LocationScout if we send Location checks without having the Location info. --------- Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Co-authored-by: Exempt-Medic Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> --- README.md | 1 + docs/CODEOWNERS | 3 + inno_setup.iss | 5 + worlds/cvcotm/LICENSES.txt | 248 ++++++ worlds/cvcotm/NOTICE.txt | 4 + worlds/cvcotm/__init__.py | 221 +++++ worlds/cvcotm/aesthetics.py | 761 ++++++++++++++++ worlds/cvcotm/client.py | 563 ++++++++++++ worlds/cvcotm/cvcotm_text.py | 178 ++++ worlds/cvcotm/data/iname.py | 36 + worlds/cvcotm/data/ips/AllowAlwaysDrop.ips | Bin 0 -> 67 bytes worlds/cvcotm/data/ips/AllowSpeedDash.ips | Bin 0 -> 66 bytes worlds/cvcotm/data/ips/BrokenMaidens.ips | Bin 0 -> 54 bytes worlds/cvcotm/data/ips/BuffFamiliars.ips | Bin 0 -> 44 bytes worlds/cvcotm/data/ips/BuffSubweapons.ips | Bin 0 -> 68 bytes worlds/cvcotm/data/ips/CandleFix.ips | Bin 0 -> 20 bytes worlds/cvcotm/data/ips/CardCombosRevealed.ips | Bin 0 -> 17 bytes worlds/cvcotm/data/ips/CardUp_v3_Custom2.ips | Bin 0 -> 348 bytes worlds/cvcotm/data/ips/Countdown.ips | Bin 0 -> 240 bytes worlds/cvcotm/data/ips/DSSGlitchFix.ips | Bin 0 -> 95 bytes worlds/cvcotm/data/ips/DSSRunSpeed.ips | Bin 0 -> 18 bytes worlds/cvcotm/data/ips/DemoForceFirst.ips | Bin 0 -> 15 bytes .../data/ips/DropReworkMultiEdition.ips | Bin 0 -> 783 bytes worlds/cvcotm/data/ips/GameClearBypass.ips | Bin 0 -> 29 bytes worlds/cvcotm/data/ips/MPComboFix.ips | Bin 0 -> 15 bytes worlds/cvcotm/data/ips/MapEdits.ips | Bin 0 -> 32 bytes worlds/cvcotm/data/ips/MultiLastKey.ips | Bin 0 -> 191 bytes worlds/cvcotm/data/ips/NoDSSDrops.ips | Bin 0 -> 232 bytes worlds/cvcotm/data/ips/NoMPDrain.ips | Bin 0 -> 17 bytes worlds/cvcotm/data/ips/PermanentDash.ips | Bin 0 -> 33 bytes .../cvcotm/data/ips/SeedDisplay20Digits.ips | Bin 0 -> 110 bytes worlds/cvcotm/data/ips/ShooterStrength.ips | Bin 0 -> 16 bytes worlds/cvcotm/data/ips/SoftlockBlockFix.ips | Bin 0 -> 15 bytes worlds/cvcotm/data/lname.py | 128 +++ worlds/cvcotm/data/patches.py | 431 ++++++++++ .../en_Castlevania - Circle of the Moon.md | 169 ++++ worlds/cvcotm/docs/setup_en.md | 72 ++ worlds/cvcotm/items.py | 211 +++++ worlds/cvcotm/locations.py | 265 ++++++ worlds/cvcotm/lz10.py | 265 ++++++ worlds/cvcotm/options.py | 282 ++++++ worlds/cvcotm/presets.py | 190 ++++ worlds/cvcotm/regions.py | 189 ++++ worlds/cvcotm/rom.py | 600 +++++++++++++ worlds/cvcotm/rules.py | 203 +++++ worlds/cvcotm/test/__init__.py | 5 + worlds/cvcotm/test/test_access.py | 811 ++++++++++++++++++ 47 files changed, 5841 insertions(+) create mode 100644 worlds/cvcotm/LICENSES.txt create mode 100644 worlds/cvcotm/NOTICE.txt create mode 100644 worlds/cvcotm/__init__.py create mode 100644 worlds/cvcotm/aesthetics.py create mode 100644 worlds/cvcotm/client.py create mode 100644 worlds/cvcotm/cvcotm_text.py create mode 100644 worlds/cvcotm/data/iname.py create mode 100644 worlds/cvcotm/data/ips/AllowAlwaysDrop.ips create mode 100644 worlds/cvcotm/data/ips/AllowSpeedDash.ips create mode 100644 worlds/cvcotm/data/ips/BrokenMaidens.ips create mode 100644 worlds/cvcotm/data/ips/BuffFamiliars.ips create mode 100644 worlds/cvcotm/data/ips/BuffSubweapons.ips create mode 100644 worlds/cvcotm/data/ips/CandleFix.ips create mode 100644 worlds/cvcotm/data/ips/CardCombosRevealed.ips create mode 100644 worlds/cvcotm/data/ips/CardUp_v3_Custom2.ips create mode 100644 worlds/cvcotm/data/ips/Countdown.ips create mode 100644 worlds/cvcotm/data/ips/DSSGlitchFix.ips create mode 100644 worlds/cvcotm/data/ips/DSSRunSpeed.ips create mode 100644 worlds/cvcotm/data/ips/DemoForceFirst.ips create mode 100644 worlds/cvcotm/data/ips/DropReworkMultiEdition.ips create mode 100644 worlds/cvcotm/data/ips/GameClearBypass.ips create mode 100644 worlds/cvcotm/data/ips/MPComboFix.ips create mode 100644 worlds/cvcotm/data/ips/MapEdits.ips create mode 100644 worlds/cvcotm/data/ips/MultiLastKey.ips create mode 100644 worlds/cvcotm/data/ips/NoDSSDrops.ips create mode 100644 worlds/cvcotm/data/ips/NoMPDrain.ips create mode 100644 worlds/cvcotm/data/ips/PermanentDash.ips create mode 100644 worlds/cvcotm/data/ips/SeedDisplay20Digits.ips create mode 100644 worlds/cvcotm/data/ips/ShooterStrength.ips create mode 100644 worlds/cvcotm/data/ips/SoftlockBlockFix.ips create mode 100644 worlds/cvcotm/data/lname.py create mode 100644 worlds/cvcotm/data/patches.py create mode 100644 worlds/cvcotm/docs/en_Castlevania - Circle of the Moon.md create mode 100644 worlds/cvcotm/docs/setup_en.md create mode 100644 worlds/cvcotm/items.py create mode 100644 worlds/cvcotm/locations.py create mode 100644 worlds/cvcotm/lz10.py create mode 100644 worlds/cvcotm/options.py create mode 100644 worlds/cvcotm/presets.py create mode 100644 worlds/cvcotm/regions.py create mode 100644 worlds/cvcotm/rom.py create mode 100644 worlds/cvcotm/rules.py create mode 100644 worlds/cvcotm/test/__init__.py create mode 100644 worlds/cvcotm/test/test_access.py diff --git a/README.md b/README.md index 21a6faaa2698..36b7a07fb4b3 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Currently, the following games are supported: * Yacht Dice * Faxanadu * Saving Princess +* Castlevania: Circle of the Moon For setup and instructions check out our [tutorials page](https://archipelago.gg/tutorial/). Downloads can be found at [Releases](https://github.com/ArchipelagoMW/Archipelago/releases), including compiled diff --git a/docs/CODEOWNERS b/docs/CODEOWNERS index 1aec57fc90f6..8b39f96068af 100644 --- a/docs/CODEOWNERS +++ b/docs/CODEOWNERS @@ -36,6 +36,9 @@ # Castlevania 64 /worlds/cv64/ @LiquidCat64 +# Castlevania: Circle of the Moon +/worlds/cvcotm/ @LiquidCat64 + # Celeste 64 /worlds/celeste64/ @PoryGone diff --git a/inno_setup.iss b/inno_setup.iss index 38e655d917c1..eb794650f3a6 100644 --- a/inno_setup.iss +++ b/inno_setup.iss @@ -186,6 +186,11 @@ Root: HKCR; Subkey: "{#MyAppName}cv64patch"; ValueData: "Arc Root: HKCR; Subkey: "{#MyAppName}cv64patch\DefaultIcon"; ValueData: "{app}\ArchipelagoBizHawkClient.exe,0"; ValueType: string; ValueName: ""; Root: HKCR; Subkey: "{#MyAppName}cv64patch\shell\open\command"; ValueData: """{app}\ArchipelagoBizHawkClient.exe"" ""%1"""; ValueType: string; ValueName: ""; +Root: HKCR; Subkey: ".apcvcotm"; ValueData: "{#MyAppName}cvcotmpatch"; Flags: uninsdeletevalue; ValueType: string; ValueName: ""; +Root: HKCR; Subkey: "{#MyAppName}cvcotmpatch"; ValueData: "Archipelago Castlevania Circle of the Moon Patch"; Flags: uninsdeletekey; ValueType: string; ValueName: ""; +Root: HKCR; Subkey: "{#MyAppName}cvcotmpatch\DefaultIcon"; ValueData: "{app}\ArchipelagoBizHawkClient.exe,0"; ValueType: string; ValueName: ""; +Root: HKCR; Subkey: "{#MyAppName}cvcotmpatch\shell\open\command"; ValueData: """{app}\ArchipelagoBizHawkClient.exe"" ""%1"""; ValueType: string; ValueName: ""; + Root: HKCR; Subkey: ".apmm2"; ValueData: "{#MyAppName}mm2patch"; Flags: uninsdeletevalue; ValueType: string; ValueName: ""; Root: HKCR; Subkey: "{#MyAppName}mm2patch"; ValueData: "Archipelago Mega Man 2 Patch"; Flags: uninsdeletekey; ValueType: string; ValueName: ""; Root: HKCR; Subkey: "{#MyAppName}mm2patch\DefaultIcon"; ValueData: "{app}\ArchipelagoBizHawkClient.exe,0"; ValueType: string; ValueName: ""; diff --git a/worlds/cvcotm/LICENSES.txt b/worlds/cvcotm/LICENSES.txt new file mode 100644 index 000000000000..815e52d5f668 --- /dev/null +++ b/worlds/cvcotm/LICENSES.txt @@ -0,0 +1,248 @@ + +Regarding the sprite data specifically for the Archipelago logo found in data > patches.py: + +The Archipelago Logo is © 2022 by Krista Corkos and Christopher Wilson and licensed under Attribution-NonCommercial 4.0 +International. Logo modified by Liquid Cat to fit artstyle and uses within this mod. To view a copy of this license, +visit http://creativecommons.org/licenses/by-nc/4.0/ + +The other custom sprites that I made, as long as you don't lie by claiming you were the one who drew them, I am fine +with you using and distributing them however you want to. -Liquid Cat + +======================================================================================================================== + +For the lz10.py and cvcotm_text.py modules specifically the MIT license applies. Its terms are as follows: + +MIT License + +cvcotm_text.py Copyright (c) 2024 Liquid Cat +(Please consider the associated pixel data for the ASCII characters missing from CotM in data > patches.py +in the public domain, if there was any thought that that could even be copyrighted. -Liquid Cat) + +lz10.py Copyright (c) 2024 lilDavid, NoiseCrush + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +======================================================================================================================== + +Everything else in this world package not mentioned above can be assumed covered by standalone CotMR's Apache license +being a piece of a direct derivative of it. The terms are as follows: + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2021-2024 DevAnj, fusecavator, spooky, Malaert64 + + Archipelago version by Liquid Cat + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/worlds/cvcotm/NOTICE.txt b/worlds/cvcotm/NOTICE.txt new file mode 100644 index 000000000000..7a6f4d10ff5c --- /dev/null +++ b/worlds/cvcotm/NOTICE.txt @@ -0,0 +1,4 @@ +Circle of the Moon Randomizer +Copyright 2021-2024 DevAnj, fusecavator, spooky, Malaert64 + +Archipelago version by Liquid Cat \ No newline at end of file diff --git a/worlds/cvcotm/__init__.py b/worlds/cvcotm/__init__.py new file mode 100644 index 000000000000..4466ed79bdd2 --- /dev/null +++ b/worlds/cvcotm/__init__.py @@ -0,0 +1,221 @@ +import os +import typing +import settings +import base64 +import logging + +from BaseClasses import Item, Region, Tutorial, ItemClassification +from .items import CVCotMItem, FILLER_ITEM_NAMES, ACTION_CARDS, ATTRIBUTE_CARDS, cvcotm_item_info, \ + get_item_names_to_ids, get_item_counts +from .locations import CVCotMLocation, get_location_names_to_ids, BASE_ID, get_named_locations_data, \ + get_location_name_groups +from .options import cvcotm_option_groups, CVCotMOptions, SubWeaponShuffle, IronMaidenBehavior, RequiredSkirmishes, \ + CompletionGoal, EarlyEscapeItem +from .regions import get_region_info, get_all_region_names +from .rules import CVCotMRules +from .data import iname, lname +from .presets import cvcotm_options_presets +from worlds.AutoWorld import WebWorld, World + +from .aesthetics import shuffle_sub_weapons, get_location_data, get_countdown_flags, populate_enemy_drops, \ + get_start_inventory_data +from .rom import RomData, patch_rom, get_base_rom_path, CVCotMProcedurePatch, CVCOTM_CT_US_HASH, CVCOTM_AC_US_HASH, \ + CVCOTM_VC_US_HASH +from .client import CastlevaniaCotMClient + + +class CVCotMSettings(settings.Group): + class RomFile(settings.UserFilePath): + """File name of the Castlevania CotM US rom""" + copy_to = "Castlevania - Circle of the Moon (USA).gba" + description = "Castlevania CotM (US) ROM File" + md5s = [CVCOTM_CT_US_HASH, CVCOTM_AC_US_HASH, CVCOTM_VC_US_HASH] + + rom_file: RomFile = RomFile(RomFile.copy_to) + + +class CVCotMWeb(WebWorld): + theme = "stone" + options_presets = cvcotm_options_presets + + tutorials = [Tutorial( + "Multiworld Setup Guide", + "A guide to setting up the Archipleago Castlevania: Circle of the Moon randomizer on your computer and " + "connecting it to a multiworld.", + "English", + "setup_en.md", + "setup/en", + ["Liquid Cat"] + )] + + option_groups = cvcotm_option_groups + + +class CVCotMWorld(World): + """ + Castlevania: Circle of the Moon is a launch title for the Game Boy Advance and the first of three Castlevania games + released for the handheld in the "Metroidvania" format. As Nathan Graves, wielding the Hunter Whip and utilizing the + Dual Set-Up System for new possibilities, you must battle your way through Camilla's castle and rescue your master + from a demonic ritual to restore the Count's power... + """ + game = "Castlevania - Circle of the Moon" + item_name_groups = { + "DSS": ACTION_CARDS.union(ATTRIBUTE_CARDS), + "Card": ACTION_CARDS.union(ATTRIBUTE_CARDS), + "Action": ACTION_CARDS, + "Action Card": ACTION_CARDS, + "Attribute": ATTRIBUTE_CARDS, + "Attribute Card": ATTRIBUTE_CARDS, + "Freeze": {iname.serpent, iname.cockatrice, iname.mercury, iname.mars}, + "Freeze Action": {iname.mercury, iname.mars}, + "Freeze Attribute": {iname.serpent, iname.cockatrice} + } + location_name_groups = get_location_name_groups() + options_dataclass = CVCotMOptions + options: CVCotMOptions + settings: typing.ClassVar[CVCotMSettings] + origin_region_name = "Catacomb" + hint_blacklist = frozenset({lname.ba24}) # The Battle Arena reward, if it's put in, will always be a Last Key. + + item_name_to_id = {name: cvcotm_item_info[name].code + BASE_ID for name in cvcotm_item_info + if cvcotm_item_info[name].code is not None} + location_name_to_id = get_location_names_to_ids() + + # Default values to possibly be updated in generate_early + total_last_keys: int = 0 + required_last_keys: int = 0 + + auth: bytearray + + web = CVCotMWeb() + + def generate_early(self) -> None: + # Generate the player's unique authentication + self.auth = bytearray(self.random.getrandbits(8) for _ in range(16)) + + # If Required Skirmishes are on, force the Required and Available Last Keys to 8 or 9 depending on which option + # was chosen. + if self.options.required_skirmishes == RequiredSkirmishes.option_all_bosses: + self.options.required_last_keys.value = 8 + self.options.available_last_keys.value = 8 + elif self.options.required_skirmishes == RequiredSkirmishes.option_all_bosses_and_arena: + self.options.required_last_keys.value = 9 + self.options.available_last_keys.value = 9 + + self.total_last_keys = self.options.available_last_keys.value + self.required_last_keys = self.options.required_last_keys.value + + # If there are more Last Keys required than there are Last Keys in total, drop the required Last Keys to + # the total Last Keys. + if self.required_last_keys > self.total_last_keys: + self.required_last_keys = self.total_last_keys + logging.warning(f"[{self.player_name}] The Required Last Keys " + f"({self.options.required_last_keys.value}) is higher than the Available Last Keys " + f"({self.options.available_last_keys.value}). Lowering the required number to: " + f"{self.required_last_keys}") + self.options.required_last_keys.value = self.required_last_keys + + # Place the Double or Roc Wing in local_early_items if the Early Escape option is being used. + if self.options.early_escape_item == EarlyEscapeItem.option_double: + self.multiworld.local_early_items[self.player][iname.double] = 1 + elif self.options.early_escape_item == EarlyEscapeItem.option_roc_wing: + self.multiworld.local_early_items[self.player][iname.roc_wing] = 1 + elif self.options.early_escape_item == EarlyEscapeItem.option_double_or_roc_wing: + self.multiworld.local_early_items[self.player][self.random.choice([iname.double, iname.roc_wing])] = 1 + + def create_regions(self) -> None: + # Create every Region object. + created_regions = [Region(name, self.player, self.multiworld) for name in get_all_region_names()] + + # Attach the Regions to the Multiworld. + self.multiworld.regions.extend(created_regions) + + for reg in created_regions: + + # Add the Entrances to all the Regions. + ent_destinations_and_names = get_region_info(reg.name, "entrances") + if ent_destinations_and_names is not None: + reg.add_exits(ent_destinations_and_names) + + # Add the Locations to all the Regions. + loc_names = get_region_info(reg.name, "locations") + if loc_names is None: + continue + locations_with_ids, locked_pairs = get_named_locations_data(loc_names, self.options) + reg.add_locations(locations_with_ids, CVCotMLocation) + + # Place locked Items on all of their associated Locations. + for locked_loc, locked_item in locked_pairs.items(): + self.get_location(locked_loc).place_locked_item(self.create_item(locked_item, + ItemClassification.progression)) + + def create_item(self, name: str, force_classification: typing.Optional[ItemClassification] = None) -> Item: + if force_classification is not None: + classification = force_classification + else: + classification = cvcotm_item_info[name].default_classification + + code = cvcotm_item_info[name].code + if code is not None: + code += BASE_ID + + created_item = CVCotMItem(name, classification, code, self.player) + + return created_item + + def create_items(self) -> None: + item_counts = get_item_counts(self) + + # Set up the items correctly + self.multiworld.itempool += [self.create_item(item, classification) for classification in item_counts for item + in item_counts[classification] for _ in range(item_counts[classification][item])] + + def set_rules(self) -> None: + # Set all the Entrance and Location rules properly. + CVCotMRules(self).set_cvcotm_rules() + + def generate_output(self, output_directory: str) -> None: + # Get out all the Locations that are not Events. Only take the Iron Maiden switch if the Maiden Detonator is in + # the item pool. + active_locations = [loc for loc in self.multiworld.get_locations(self.player) if loc.address is not None and + (loc.name != lname.ct21 or self.options.iron_maiden_behavior == + IronMaidenBehavior.option_detonator_in_pool)] + + # Location data + offset_data = get_location_data(self, active_locations) + # Sub-weapons + if self.options.sub_weapon_shuffle: + offset_data.update(shuffle_sub_weapons(self)) + # Item drop randomization + if self.options.item_drop_randomization: + offset_data.update(populate_enemy_drops(self)) + # Countdown + if self.options.countdown: + offset_data.update(get_countdown_flags(self, active_locations)) + # Start Inventory + start_inventory_data = get_start_inventory_data(self) + offset_data.update(start_inventory_data[0]) + + patch = CVCotMProcedurePatch(player=self.player, player_name=self.player_name) + patch_rom(self, patch, offset_data, start_inventory_data[1]) + + rom_path = os.path.join(output_directory, f"{self.multiworld.get_out_file_name_base(self.player)}" + f"{patch.patch_file_ending}") + + patch.write(rom_path) + + def fill_slot_data(self) -> dict: + return {"death_link": self.options.death_link.value, + "iron_maiden_behavior": self.options.iron_maiden_behavior.value, + "ignore_cleansing": self.options.ignore_cleansing.value, + "skip_tutorials": self.options.skip_tutorials.value, + "required_last_keys": self.required_last_keys, + "completion_goal": self.options.completion_goal.value} + + def get_filler_item_name(self) -> str: + return self.random.choice(FILLER_ITEM_NAMES) + + def modify_multidata(self, multidata: typing.Dict[str, typing.Any]): + # Put the player's unique authentication in connect_names. + multidata["connect_names"][base64.b64encode(self.auth).decode("ascii")] = \ + multidata["connect_names"][self.player_name] diff --git a/worlds/cvcotm/aesthetics.py b/worlds/cvcotm/aesthetics.py new file mode 100644 index 000000000000..d1668b1db18d --- /dev/null +++ b/worlds/cvcotm/aesthetics.py @@ -0,0 +1,761 @@ +from BaseClasses import ItemClassification, Location +from .options import ItemDropRandomization, Countdown, RequiredSkirmishes, IronMaidenBehavior +from .locations import cvcotm_location_info +from .items import cvcotm_item_info, MAJORS_CLASSIFICATIONS +from .data import iname + +from typing import TYPE_CHECKING, Dict, List, Iterable, Tuple, NamedTuple, Optional, TypedDict + +if TYPE_CHECKING: + from . import CVCotMWorld + + +class StatInfo(TypedDict): + # Amount this stat increases per Max Up the player starts with. + amount_per: int + # The most amount of this stat the player is allowed to start with. Problems arise if the stat exceeds 9999, so we + # must ensure it can't if the player raises any class to level 99 as well as collects 255 of that max up. The game + # caps hearts at 999 automatically, so it doesn't matter so much for that one. + max_allowed: int + # The key variable in extra_stats that the stat max up affects. + variable: str + + +extra_starting_stat_info: Dict[str, StatInfo] = { + iname.hp_max: {"amount_per": 10, + "max_allowed": 5289, + "variable": "extra health"}, + iname.mp_max: {"amount_per": 10, + "max_allowed": 3129, + "variable": "extra magic"}, + iname.heart_max: {"amount_per": 6, + "max_allowed": 999, + "variable": "extra hearts"}, +} + +other_player_subtype_bytes = { + 0xE4: 0x03, + 0xE6: 0x14, + 0xE8: 0x0A +} + + +class OtherGameAppearancesInfo(TypedDict): + # What type of item to place for the other player. + type: int + # What item to display it as for the other player. + appearance: int + + +other_game_item_appearances: Dict[str, Dict[str, OtherGameAppearancesInfo]] = { + # NOTE: Symphony of the Night is currently an unsupported world not in main. + "Symphony of the Night": {"Life Vessel": {"type": 0xE4, + "appearance": 0x01}, + "Heart Vessel": {"type": 0xE4, + "appearance": 0x00}}, + "Timespinner": {"Max HP": {"type": 0xE4, + "appearance": 0x01}, + "Max Aura": {"type": 0xE4, + "appearance": 0x02}, + "Max Sand": {"type": 0xE8, + "appearance": 0x0F}} +} + +# 0 = Holy water 22 +# 1 = Axe 24 +# 2 = Knife 32 +# 3 = Cross 6 +# 4 = Stopwatch 12 +# 5 = Small heart +# 6 = Big heart +rom_sub_weapon_offsets = { + 0xD034E: b"\x01", + 0xD0462: b"\x02", + 0xD064E: b"\x00", + 0xD06F6: b"\x02", + 0xD0882: b"\x00", + 0xD0912: b"\x02", + 0xD0C2A: b"\x02", + 0xD0C96: b"\x01", + 0xD0D92: b"\x02", + 0xD0DCE: b"\x01", + 0xD1332: b"\x00", + 0xD13AA: b"\x01", + 0xD1722: b"\x02", + 0xD17A6: b"\x01", + 0xD1926: b"\x01", + 0xD19AA: b"\x02", + 0xD1A9A: b"\x02", + 0xD1AA6: b"\x00", + 0xD1EBA: b"\x00", + 0xD1ED2: b"\x01", + 0xD2262: b"\x02", + 0xD23B2: b"\x03", + 0xD256E: b"\x02", + 0xD2742: b"\x02", + 0xD2832: b"\x04", + 0xD2862: b"\x01", + 0xD2A2A: b"\x01", + 0xD2DBA: b"\x04", + 0xD2DC6: b"\x00", + 0xD2E02: b"\x02", + 0xD2EFE: b"\x04", + 0xD2F0A: b"\x02", + 0xD302A: b"\x00", + 0xD3042: b"\x01", + 0xD304E: b"\x04", + 0xD3066: b"\x02", + 0xD322E: b"\x04", + 0xD334E: b"\x04", + 0xD3516: b"\x03", + 0xD35CA: b"\x02", + 0xD371A: b"\x01", + 0xD38EE: b"\x00", + 0xD3BE2: b"\x02", + 0xD3D1A: b"\x01", + 0xD3D56: b"\x02", + 0xD3ECA: b"\x00", + 0xD3EE2: b"\x02", + 0xD4056: b"\x01", + 0xD40E6: b"\x04", + 0xD413A: b"\x04", + 0xD4326: b"\x00", + 0xD460E: b"\x00", + 0xD48D2: b"\x00", + 0xD49E6: b"\x01", + 0xD4ABE: b"\x02", + 0xD4B8A: b"\x01", + 0xD4D0A: b"\x04", + 0xD4EAE: b"\x02", + 0xD4F0E: b"\x00", + 0xD4F92: b"\x02", + 0xD4FB6: b"\x01", + 0xD503A: b"\x03", + 0xD5646: b"\x01", + 0xD5682: b"\x02", + 0xD57C6: b"\x02", + 0xD57D2: b"\x02", + 0xD58F2: b"\x00", + 0xD5922: b"\x01", + 0xD5B9E: b"\x02", + 0xD5E26: b"\x01", + 0xD5E56: b"\x02", + 0xD5E7A: b"\x02", + 0xD5F5E: b"\x00", + 0xD69EA: b"\x02", + 0xD69F6: b"\x01", + 0xD6A02: b"\x00", + 0xD6A0E: b"\x04", + 0xD6A1A: b"\x03", + 0xD6BE2: b"\x00", + 0xD6CBA: b"\x01", + 0xD6CDE: b"\x02", + 0xD6EEE: b"\x00", + 0xD6F1E: b"\x02", + 0xD6F42: b"\x01", + 0xD6FC6: b"\x04", + 0xD706E: b"\x00", + 0xD716A: b"\x02", + 0xD72AE: b"\x01", + 0xD75BA: b"\x03", + 0xD76AA: b"\x04", + 0xD76B6: b"\x00", + 0xD76C2: b"\x01", + 0xD76CE: b"\x02", + 0xD76DA: b"\x03", + 0xD7D46: b"\x00", + 0xD7D52: b"\x00", +} + +LOW_ITEMS = [ + 41, # Potion + 42, # Meat + 48, # Mind Restore + 51, # Heart + 46, # Antidote + 47, # Cure Curse + + 17, # Cotton Clothes + 18, # Prison Garb + 12, # Cotton Robe + 1, # Leather Armor + 2, # Bronze Armor + 3, # Gold Armor + + 39, # Toy Ring + 40, # Bear Ring + 34, # Wristband + 36, # Arm Guard + 37, # Magic Gauntlet + 38, # Miracle Armband + 35, # Gauntlet +] + +MID_ITEMS = [ + 43, # Spiced Meat + 49, # Mind High + 52, # Heart High + + 19, # Stylish Suit + 20, # Night Suit + 13, # Silk Robe + 14, # Rainbow Robe + 4, # Chainmail + 5, # Steel Armor + 6, # Platinum Armor + + 24, # Star Bracelet + 29, # Cursed Ring + 25, # Strength Ring + 26, # Hard Ring + 27, # Intelligence Ring + 28, # Luck Ring + 23, # Double Grips +] + +HIGH_ITEMS = [ + 44, # Potion High + 45, # Potion Ex + 50, # Mind Ex + 53, # Heart Ex + 54, # Heart Mega + + 21, # Ninja Garb + 22, # Soldier Fatigues + 15, # Magic Robe + 16, # Sage Robe + + 7, # Diamond Armor + 8, # Mirror Armor + 9, # Needle Armor + 10, # Dark Armor + + 30, # Strength Armband + 31, # Defense Armband + 32, # Sage Armband + 33, # Gambler Armband +] + +COMMON_ITEMS = LOW_ITEMS + MID_ITEMS + +RARE_ITEMS = LOW_ITEMS + MID_ITEMS + HIGH_ITEMS + + +class CVCotMEnemyData(NamedTuple): + name: str + hp: int + attack: int + defense: int + exp: int + type: Optional[str] = None + + +cvcotm_enemy_info: List[CVCotMEnemyData] = [ + # Name HP ATK DEF EXP + CVCotMEnemyData("Medusa Head", 6, 120, 60, 2), + CVCotMEnemyData("Zombie", 48, 70, 20, 2), + CVCotMEnemyData("Ghoul", 100, 190, 79, 3), + CVCotMEnemyData("Wight", 110, 235, 87, 4), + CVCotMEnemyData("Clinking Man", 80, 135, 25, 21), + CVCotMEnemyData("Zombie Thief", 120, 185, 30, 58), + CVCotMEnemyData("Skeleton", 25, 65, 45, 4), + CVCotMEnemyData("Skeleton Bomber", 20, 50, 40, 4), + CVCotMEnemyData("Electric Skeleton", 42, 80, 50, 30), + CVCotMEnemyData("Skeleton Spear", 30, 65, 46, 6), + CVCotMEnemyData("Skeleton Boomerang", 60, 170, 90, 112), + CVCotMEnemyData("Skeleton Soldier", 35, 90, 60, 16), + CVCotMEnemyData("Skeleton Knight", 50, 140, 80, 39), + CVCotMEnemyData("Bone Tower", 84, 201, 280, 160), + CVCotMEnemyData("Fleaman", 60, 142, 45, 29), + CVCotMEnemyData("Poltergeist", 105, 360, 380, 510), + CVCotMEnemyData("Bat", 5, 50, 15, 4), + CVCotMEnemyData("Spirit", 9, 55, 17, 1), + CVCotMEnemyData("Ectoplasm", 12, 165, 51, 2), + CVCotMEnemyData("Specter", 15, 295, 95, 3), + CVCotMEnemyData("Axe Armor", 55, 120, 130, 31), + CVCotMEnemyData("Flame Armor", 160, 320, 300, 280), + CVCotMEnemyData("Flame Demon", 300, 315, 270, 600), + CVCotMEnemyData("Ice Armor", 240, 470, 520, 1500), + CVCotMEnemyData("Thunder Armor", 204, 340, 320, 800), + CVCotMEnemyData("Wind Armor", 320, 500, 460, 1800), + CVCotMEnemyData("Earth Armor", 130, 230, 280, 240), + CVCotMEnemyData("Poison Armor", 260, 382, 310, 822), + CVCotMEnemyData("Forest Armor", 370, 390, 390, 1280), + CVCotMEnemyData("Stone Armor", 90, 220, 320, 222), + CVCotMEnemyData("Ice Demon", 350, 492, 510, 4200), + CVCotMEnemyData("Holy Armor", 350, 420, 450, 1700), + CVCotMEnemyData("Thunder Demon", 180, 270, 230, 450), + CVCotMEnemyData("Dark Armor", 400, 680, 560, 3300), + CVCotMEnemyData("Wind Demon", 400, 540, 490, 3600), + CVCotMEnemyData("Bloody Sword", 30, 220, 500, 200), + CVCotMEnemyData("Golem", 650, 520, 700, 1400), + CVCotMEnemyData("Earth Demon", 150, 90, 85, 25), + CVCotMEnemyData("Were-wolf", 160, 265, 110, 140), + CVCotMEnemyData("Man Eater", 400, 330, 233, 700), + CVCotMEnemyData("Devil Tower", 10, 140, 200, 17), + CVCotMEnemyData("Skeleton Athlete", 100, 100, 50, 25), + CVCotMEnemyData("Harpy", 120, 275, 200, 271), + CVCotMEnemyData("Siren", 160, 443, 300, 880), + CVCotMEnemyData("Imp", 90, 220, 99, 103), + CVCotMEnemyData("Mudman", 25, 79, 30, 2), + CVCotMEnemyData("Gargoyle", 60, 160, 66, 3), + CVCotMEnemyData("Slime", 40, 102, 18, 11), + CVCotMEnemyData("Frozen Shade", 112, 490, 560, 1212), + CVCotMEnemyData("Heat Shade", 80, 240, 200, 136), + CVCotMEnemyData("Poison Worm", 120, 30, 20, 12), + CVCotMEnemyData("Myconid", 50, 250, 114, 25), + CVCotMEnemyData("Will O'Wisp", 11, 110, 16, 9), + CVCotMEnemyData("Spearfish", 40, 360, 450, 280), + CVCotMEnemyData("Merman", 60, 303, 301, 10), + CVCotMEnemyData("Minotaur", 410, 520, 640, 2000), + CVCotMEnemyData("Were-horse", 400, 540, 360, 1970), + CVCotMEnemyData("Marionette", 80, 160, 150, 127), + CVCotMEnemyData("Gremlin", 30, 80, 33, 2), + CVCotMEnemyData("Hopper", 40, 87, 35, 8), + CVCotMEnemyData("Evil Pillar", 20, 460, 800, 480), + CVCotMEnemyData("Were-panther", 200, 300, 130, 270), + CVCotMEnemyData("Were-jaguar", 270, 416, 170, 760), + CVCotMEnemyData("Bone Head", 24, 60, 80, 7), + CVCotMEnemyData("Fox Archer", 75, 130, 59, 53), + CVCotMEnemyData("Fox Hunter", 100, 290, 140, 272), + CVCotMEnemyData("Were-bear", 265, 250, 140, 227), + CVCotMEnemyData("Grizzly", 600, 380, 200, 960), + CVCotMEnemyData("Cerberus", 600, 150, 100, 500, "boss"), + CVCotMEnemyData("Beast Demon", 150, 330, 250, 260), + CVCotMEnemyData("Arch Demon", 320, 505, 400, 1000), + CVCotMEnemyData("Demon Lord", 460, 660, 500, 1950), + CVCotMEnemyData("Gorgon", 230, 215, 165, 219), + CVCotMEnemyData("Catoblepas", 550, 500, 430, 1800), + CVCotMEnemyData("Succubus", 150, 400, 350, 710), + CVCotMEnemyData("Fallen Angel", 370, 770, 770, 6000), + CVCotMEnemyData("Necromancer", 500, 200, 250, 2500, "boss"), + CVCotMEnemyData("Hyena", 93, 140, 70, 105), + CVCotMEnemyData("Fishhead", 80, 320, 504, 486), + CVCotMEnemyData("Dryad", 120, 300, 360, 300), + CVCotMEnemyData("Mimic Candle", 990, 600, 600, 6600, "candle"), + CVCotMEnemyData("Brain Float", 20, 50, 25, 10), + CVCotMEnemyData("Evil Hand", 52, 150, 120, 63), + CVCotMEnemyData("Abiondarg", 88, 388, 188, 388), + CVCotMEnemyData("Iron Golem", 640, 290, 450, 8000, "boss"), + CVCotMEnemyData("Devil", 1080, 800, 900, 10000), + CVCotMEnemyData("Witch", 144, 330, 290, 600), + CVCotMEnemyData("Mummy", 100, 100, 35, 3), + CVCotMEnemyData("Hipogriff", 300, 500, 210, 740), + CVCotMEnemyData("Adramelech", 1800, 380, 360, 16000, "boss"), + CVCotMEnemyData("Arachne", 330, 420, 288, 1300), + CVCotMEnemyData("Death Mantis", 200, 318, 240, 400), + CVCotMEnemyData("Alraune", 774, 490, 303, 2500), + CVCotMEnemyData("King Moth", 140, 290, 160, 150), + CVCotMEnemyData("Killer Bee", 8, 308, 108, 88), + CVCotMEnemyData("Dragon Zombie", 1400, 390, 440, 15000, "boss"), + CVCotMEnemyData("Lizardman", 100, 345, 400, 800), + CVCotMEnemyData("Franken", 1200, 700, 350, 2100), + CVCotMEnemyData("Legion", 420, 610, 375, 1590), + CVCotMEnemyData("Dullahan", 240, 550, 440, 2200), + CVCotMEnemyData("Death", 880, 600, 800, 60000, "boss"), + CVCotMEnemyData("Camilla", 1500, 650, 700, 80000, "boss"), + CVCotMEnemyData("Hugh", 1400, 570, 750, 120000, "boss"), + CVCotMEnemyData("Dracula", 1100, 805, 850, 150000, "boss"), + CVCotMEnemyData("Dracula", 3000, 1000, 1000, 0, "final boss"), + CVCotMEnemyData("Skeleton Medalist", 250, 100, 100, 1500), + CVCotMEnemyData("Were-jaguar", 320, 518, 260, 1200, "battle arena"), + CVCotMEnemyData("Were-wolf", 340, 525, 180, 1100, "battle arena"), + CVCotMEnemyData("Catoblepas", 560, 510, 435, 2000, "battle arena"), + CVCotMEnemyData("Hipogriff", 500, 620, 280, 1900, "battle arena"), + CVCotMEnemyData("Wind Demon", 490, 600, 540, 4000, "battle arena"), + CVCotMEnemyData("Witch", 210, 480, 340, 1000, "battle arena"), + CVCotMEnemyData("Stone Armor", 260, 585, 750, 3000, "battle arena"), + CVCotMEnemyData("Devil Tower", 50, 560, 700, 600, "battle arena"), + CVCotMEnemyData("Skeleton", 150, 400, 200, 500, "battle arena"), + CVCotMEnemyData("Skeleton Bomber", 150, 400, 200, 550, "battle arena"), + CVCotMEnemyData("Electric Skeleton", 150, 400, 200, 700, "battle arena"), + CVCotMEnemyData("Skeleton Spear", 150, 400, 200, 580, "battle arena"), + CVCotMEnemyData("Flame Demon", 680, 650, 600, 4500, "battle arena"), + CVCotMEnemyData("Bone Tower", 120, 500, 650, 800, "battle arena"), + CVCotMEnemyData("Fox Hunter", 160, 510, 220, 600, "battle arena"), + CVCotMEnemyData("Poison Armor", 380, 680, 634, 3600, "battle arena"), + CVCotMEnemyData("Bloody Sword", 55, 600, 1200, 2000, "battle arena"), + CVCotMEnemyData("Abiondarg", 188, 588, 288, 588, "battle arena"), + CVCotMEnemyData("Legion", 540, 760, 480, 2900, "battle arena"), + CVCotMEnemyData("Marionette", 200, 420, 400, 1200, "battle arena"), + CVCotMEnemyData("Minotaur", 580, 700, 715, 4100, "battle arena"), + CVCotMEnemyData("Arachne", 430, 590, 348, 2400, "battle arena"), + CVCotMEnemyData("Succubus", 300, 670, 630, 3100, "battle arena"), + CVCotMEnemyData("Demon Lord", 590, 800, 656, 4200, "battle arena"), + CVCotMEnemyData("Alraune", 1003, 640, 450, 5000, "battle arena"), + CVCotMEnemyData("Hyena", 210, 408, 170, 1000, "battle arena"), + CVCotMEnemyData("Devil Armor", 500, 804, 714, 6600), + CVCotMEnemyData("Evil Pillar", 55, 655, 900, 1500, "battle arena"), + CVCotMEnemyData("White Armor", 640, 770, 807, 7000), + CVCotMEnemyData("Devil", 1530, 980, 1060, 30000, "battle arena"), + CVCotMEnemyData("Scary Candle", 150, 300, 300, 900, "candle"), + CVCotMEnemyData("Trick Candle", 200, 400, 400, 1400, "candle"), + CVCotMEnemyData("Nightmare", 250, 550, 550, 2000), + CVCotMEnemyData("Lilim", 400, 800, 800, 8000), + CVCotMEnemyData("Lilith", 660, 960, 960, 20000), +] +# NOTE: Coffin is omitted from the end of this, as its presence doesn't +# actually impact the randomizer (all stats and drops inherited from Mummy). + +BOSS_IDS = [enemy_id for enemy_id in range(len(cvcotm_enemy_info)) if cvcotm_enemy_info[enemy_id].type == "boss"] + +ENEMY_TABLE_START = 0xCB2C4 + +NUMBER_ITEMS = 55 + +COUNTDOWN_TABLE_ADDR = 0x673400 +ITEM_ID_SHINNING_ARMOR = 11 + + +def shuffle_sub_weapons(world: "CVCotMWorld") -> Dict[int, bytes]: + """Shuffles the sub-weapons amongst themselves.""" + sub_bytes = list(rom_sub_weapon_offsets.values()) + world.random.shuffle(sub_bytes) + return dict(zip(rom_sub_weapon_offsets, sub_bytes)) + + +def get_countdown_flags(world: "CVCotMWorld", active_locations: Iterable[Location]) -> Dict[int, bytes]: + """Figures out which Countdown numbers to increase for each Location after verifying the Item on the Location should + count towards a number. + + Which number to increase is determined by the Location's "countdown" attr in its CVCotMLocationData.""" + + next_pos = COUNTDOWN_TABLE_ADDR + 0x40 + countdown_flags: List[List[int]] = [[] for _ in range(16)] + countdown_dict = {} + ptr_offset = COUNTDOWN_TABLE_ADDR + + # Loop over every Location. + for loc in active_locations: + # If the Location's Item is not Progression/Useful-classified with the "Majors" Countdown being used, or if the + # Location is the Iron Maiden switch with the vanilla Iron Maiden behavior, skip adding its flag to the arrays. + if (not loc.item.classification & MAJORS_CLASSIFICATIONS and world.options.countdown == + Countdown.option_majors): + continue + + countdown_index = cvcotm_location_info[loc.name].countdown + # Take the Location's address if the above condition is satisfied, and get the flag value out of it. + countdown_flags[countdown_index] += [loc.address & 0xFF, 0] + + # Write the Countdown flag arrays and array pointers correctly. Each flag list should end with a 0xFFFF to indicate + # the end of an area's list. + for area_flags in countdown_flags: + countdown_dict[ptr_offset] = int.to_bytes(next_pos | 0x08000000, 4, "little") + countdown_dict[next_pos] = bytes(area_flags + [0xFF, 0xFF]) + ptr_offset += 4 + next_pos += len(area_flags) + 2 + + return countdown_dict + + +def get_location_data(world: "CVCotMWorld", active_locations: Iterable[Location]) -> Dict[int, bytes]: + """Gets ALL the Item data to go into the ROM. Items consist of four bytes; the first two represent the object ID + for the "category" of item that it belongs to, the third is the sub-value for which item within that "category" it + is, and the fourth controls the appearance it takes.""" + + location_bytes = {} + + for loc in active_locations: + # Figure out the item ID bytes to put in each Location's offset here. + # If it's a CotM Item, always write the Item's primary type byte. + if loc.item.game == "Castlevania - Circle of the Moon": + type_byte = cvcotm_item_info[loc.item.name].code >> 8 + + # If the Item is for this player, set the subtype to actually be that Item. + # Otherwise, set a dummy subtype value that is different for every item type. + if loc.item.player == world.player: + subtype_byte = cvcotm_item_info[loc.item.name].code & 0xFF + else: + subtype_byte = other_player_subtype_bytes[type_byte] + + # If it's a DSS Card, set the appearance based on whether it's progression or not; freeze combo cards should + # all appear blue in color while the others are standard purple/yellow. Otherwise, set the appearance the + # same way as the subtype for local items regardless of whether it's actually local or not. + if type_byte == 0xE6: + if loc.item.advancement: + appearance_byte = 1 + else: + appearance_byte = 0 + else: + appearance_byte = cvcotm_item_info[loc.item.name].code & 0xFF + + # If it's not a CotM Item at all, always set the primary type to that of a Magic Item and the subtype to that of + # a dummy item. The AP Items are all under Magic Items. + else: + type_byte = 0xE8 + subtype_byte = 0x0A + # Decide which AP Item to use to represent the other game item. + if loc.item.classification & ItemClassification.progression and \ + loc.item.classification & ItemClassification.useful: + appearance_byte = 0x0E # Progression + Useful + elif loc.item.classification & ItemClassification.progression: + appearance_byte = 0x0C # Progression + elif loc.item.classification & ItemClassification.useful: + appearance_byte = 0x0B # Useful + elif loc.item.classification & ItemClassification.trap: + appearance_byte = 0x0D # Trap + else: + appearance_byte = 0x0A # Filler + + # Check if the Item's game is in the other game item appearances' dict, and if so, if the Item is under that + # game's name. If it is, change the appearance accordingly. + # Right now, only SotN and Timespinner stat ups are supported. + other_game_name = world.multiworld.worlds[loc.item.player].game + if other_game_name in other_game_item_appearances: + if loc.item.name in other_game_item_appearances[other_game_name]: + type_byte = other_game_item_appearances[other_game_name][loc.item.name]["type"] + subtype_byte = other_player_subtype_bytes[type_byte] + appearance_byte = other_game_item_appearances[other_game_name][loc.item.name]["appearance"] + + # Create the correct bytes object for the Item on that Location. + location_bytes[cvcotm_location_info[loc.name].offset] = bytes([type_byte, 1, subtype_byte, appearance_byte]) + return location_bytes + + +def populate_enemy_drops(world: "CVCotMWorld") -> Dict[int, bytes]: + """Randomizes the enemy-dropped items throughout the game within each other. There are three tiers of item drops: + Low, Mid, and High. Each enemy has two item slots that can both drop its own item; a Common slot and a Rare one. + + On Normal item randomization, easy enemies (below 61 HP) will only have Low-tier drops in both of their stats, + bosses and candle enemies will be guaranteed to have High drops in one or both of their slots respectively (bosses + are made to only drop one slot 100% of the time), and everything else can have a Low or Mid-tier item in its Common + drop slot and a Low, Mid, OR High-tier item in its Rare drop slot. + + If Item Drop Randomization is set to Tiered, the HP threshold for enemies being considered "easily" will raise to + below 144, enemies in the 144-369 HP range (inclusive) will have a Low-tier item in its Common slot and a Mid-tier + item in its rare slot, and enemies with more than 369 HP will have a Mid-tier in its Common slot and a High-tier in + its Rare slot. Candles and bosses still have Rares in all their slots, but now the guaranteed drops that land on + bosses will be exclusive to them; no other enemy in the game will have their item. + + This and select_drop are the most directly adapted code from upstream CotMR in this package by far. Credit where + it's due to Spooky for writing the original, and Malaert64 for further refinements and updating what used to be + Random Item Hardmode to instead be Tiered Item Mode. The original C code this was adapted from can be found here: + https://github.com/calm-palm/cotm-randomizer/blob/master/Program/randomizer.c#L1028""" + + placed_low_items = [0] * len(LOW_ITEMS) + placed_mid_items = [0] * len(MID_ITEMS) + placed_high_items = [0] * len(HIGH_ITEMS) + + placed_common_items = [0] * len(COMMON_ITEMS) + placed_rare_items = [0] * len(RARE_ITEMS) + + regular_drops = [0] * len(cvcotm_enemy_info) + regular_drop_chances = [0] * len(cvcotm_enemy_info) + rare_drops = [0] * len(cvcotm_enemy_info) + rare_drop_chances = [0] * len(cvcotm_enemy_info) + + # Set boss items first to prevent boss drop duplicates. + # If Tiered mode is enabled, make these items exclusive to these enemies by adding an arbitrary integer larger + # than could be reached normally (e.g.the total number of enemies) and use the placed high items array instead of + # the placed rare items one. + if world.options.item_drop_randomization == ItemDropRandomization.option_tiered: + for boss_id in BOSS_IDS: + regular_drops[boss_id] = select_drop(world, HIGH_ITEMS, placed_high_items, True) + else: + for boss_id in BOSS_IDS: + regular_drops[boss_id] = select_drop(world, RARE_ITEMS, placed_rare_items, start_index=len(COMMON_ITEMS)) + + # Setting drop logic for all enemies. + for i in range(len(cvcotm_enemy_info)): + + # Give Dracula II Shining Armor occasionally as a joke. + if cvcotm_enemy_info[i].type == "final boss": + regular_drops[i] = rare_drops[i] = ITEM_ID_SHINNING_ARMOR + regular_drop_chances[i] = rare_drop_chances[i] = 5000 + + # Set bosses' secondary item to none since we already set the primary item earlier. + elif cvcotm_enemy_info[i].type == "boss": + # Set rare drop to none. + rare_drops[i] = 0 + + # Max out rare boss drops (normally, drops are capped to 50% and 25% for common and rare respectively, but + # Fuse's patch AllowAlwaysDrop.ips allows setting the regular item drop chance to 10000 to force a drop + # always) + regular_drop_chances[i] = 10000 + rare_drop_chances[i] = 0 + + # Candle enemies use a similar placement logic to the bosses, except items that land on them are NOT exclusive + # to them on Tiered mode. + elif cvcotm_enemy_info[i].type == "candle": + if world.options.item_drop_randomization == ItemDropRandomization.option_tiered: + regular_drops[i] = select_drop(world, HIGH_ITEMS, placed_high_items) + rare_drops[i] = select_drop(world, HIGH_ITEMS, placed_high_items) + else: + regular_drops[i] = select_drop(world, RARE_ITEMS, placed_rare_items, start_index=len(COMMON_ITEMS)) + rare_drops[i] = select_drop(world, RARE_ITEMS, placed_rare_items, start_index=len(COMMON_ITEMS)) + + # Set base drop chances at 20-30% for common and 15-20% for rare. + regular_drop_chances[i] = 2000 + world.random.randint(0, 1000) + rare_drop_chances[i] = 1500 + world.random.randint(0, 500) + + # On All Bosses and Battle Arena Required, the Shinning Armor at the end of Battle Arena is removed. + # We compensate for this by giving the Battle Arena Devil a 100% chance to drop Shinning Armor. + elif cvcotm_enemy_info[i].name == "Devil" and cvcotm_enemy_info[i].type == "battle arena" and \ + world.options.required_skirmishes == RequiredSkirmishes.option_all_bosses_and_arena: + regular_drops[i] = ITEM_ID_SHINNING_ARMOR + rare_drops[i] = 0 + + regular_drop_chances[i] = 10000 + rare_drop_chances[i] = 0 + + # Low-tier items drop from enemies that are trivial to farm (60 HP or less) + # on Normal drop logic, or enemies under 144 HP on Tiered logic. + elif (world.options.item_drop_randomization == ItemDropRandomization.option_normal and + cvcotm_enemy_info[i].hp <= 60) or \ + (world.options.item_drop_randomization == ItemDropRandomization.option_tiered and + cvcotm_enemy_info[i].hp <= 143): + # Low-tier enemy drops. + regular_drops[i] = select_drop(world, LOW_ITEMS, placed_low_items) + rare_drops[i] = select_drop(world, LOW_ITEMS, placed_low_items) + + # Set base drop chances at 6-10% for common and 3-6% for rare. + regular_drop_chances[i] = 600 + world.random.randint(0, 400) + rare_drop_chances[i] = 300 + world.random.randint(0, 300) + + # Rest of Tiered logic, by Malaert64. + elif world.options.item_drop_randomization == ItemDropRandomization.option_tiered: + # If under 370 HP, mid-tier enemy. + if cvcotm_enemy_info[i].hp <= 369: + regular_drops[i] = select_drop(world, LOW_ITEMS, placed_low_items) + rare_drops[i] = select_drop(world, MID_ITEMS, placed_mid_items) + # Otherwise, enemy HP is 370+, thus high-tier enemy. + else: + regular_drops[i] = select_drop(world, MID_ITEMS, placed_mid_items) + rare_drops[i] = select_drop(world, HIGH_ITEMS, placed_high_items) + + # Set base drop chances at 6-10% for common and 3-6% for rare. + regular_drop_chances[i] = 600 + world.random.randint(0, 400) + rare_drop_chances[i] = 300 + world.random.randint(0, 300) + + # Regular enemies outside Tiered logic. + else: + # Select a random regular and rare drop for every enemy from their respective lists. + regular_drops[i] = select_drop(world, COMMON_ITEMS, placed_common_items) + rare_drops[i] = select_drop(world, RARE_ITEMS, placed_rare_items) + + # Set base drop chances at 6-10% for common and 3-6% for rare. + regular_drop_chances[i] = 600 + world.random.randint(0, 400) + rare_drop_chances[i] = 300 + world.random.randint(0, 300) + + # Return the randomized drop data as bytes with their respective offsets. + enemy_address = ENEMY_TABLE_START + drop_data = {} + for i, enemy_info in enumerate(cvcotm_enemy_info): + drop_data[enemy_address] = bytes([regular_drops[i], 0, regular_drop_chances[i] & 0xFF, + regular_drop_chances[i] >> 8, rare_drops[i], 0, rare_drop_chances[i] & 0xFF, + rare_drop_chances[i] >> 8]) + enemy_address += 20 + + return drop_data + + +def select_drop(world: "CVCotMWorld", drop_list: List[int], drops_placed: List[int], exclusive_drop: bool = False, + start_index: int = 0) -> int: + """Chooses a drop from a given list of drops based on another given list of how many drops from that list were + selected before. In order to ensure an even number of drops are distributed, drops that were selected the least are + the ones that will be picked from. + + Calling this with exclusive_drop param being True will force the number of the chosen item really high to ensure it + will never be picked again.""" + + # Take the list of placed item drops beginning from the starting index. + drops_from_start_index = drops_placed[start_index:] + + # Determine the lowest drop counts and the indices with that drop count. + lowest_number = min(drops_from_start_index) + indices_with_lowest_number = [index for index, placed in enumerate(drops_from_start_index) if + placed == lowest_number] + + random_index = world.random.choice(indices_with_lowest_number) + random_index += start_index # Add start_index back on + + # Increment the number of this item placed, unless it should be exclusive to the boss / candle, in which case + # set it to an arbitrarily large number to make it exclusive. + if exclusive_drop: + drops_placed[random_index] += 999 + else: + drops_placed[random_index] += 1 + + # Return the in-game item ID of the chosen item. + return drop_list[random_index] + + +def get_start_inventory_data(world: "CVCotMWorld") -> Tuple[Dict[int, bytes], bool]: + """Calculate and return the starting inventory arrays. Different items go into different arrays, so they all have + to be handled accordingly.""" + start_inventory_data = {} + + magic_items_array = [0 for _ in range(8)] + cards_array = [0 for _ in range(20)] + extra_stats = {"extra health": 0, + "extra magic": 0, + "extra hearts": 0} + start_with_detonator = False + # If the Iron Maiden Behavior option is set to Start Broken, consider ourselves starting with the Maiden Detonator. + if world.options.iron_maiden_behavior == IronMaidenBehavior.option_start_broken: + start_with_detonator = True + + # Always start with the Dash Boots. + magic_items_array[0] = 1 + + for item in world.multiworld.precollected_items[world.player]: + + array_offset = item.code & 0xFF + + # If it's a Maiden Detonator we're starting with, set the boolean for it to True. + if item.name == iname.ironmaidens: + start_with_detonator = True + # If it's a Max Up we're starting with, check if increasing the extra amount of that stat will put us over the + # max amount of the stat allowed. If it will, set the current extra amount to the max. Otherwise, increase it by + # the amount that it should. + elif "Max Up" in item.name: + info = extra_starting_stat_info[item.name] + if extra_stats[info["variable"]] + info["amount_per"] > info["max_allowed"]: + extra_stats[info["variable"]] = info["max_allowed"] + else: + extra_stats[info["variable"]] += info["amount_per"] + # If it's a DSS card we're starting with, set that card's value in the cards array. + elif "Card" in item.name: + cards_array[array_offset] = 1 + # If it's none of the above, it has to be a regular Magic Item. + # Increase that Magic Item's value in the Magic Items array if it's not greater than 240. Last Keys are the only + # Magic Item wherein having more than one is relevant. + else: + # Decrease the Magic Item array offset by 1 if it's higher than the unused Map's item value. + if array_offset > 5: + array_offset -= 1 + if magic_items_array[array_offset] < 240: + magic_items_array[array_offset] += 1 + + # Add the start inventory arrays to the offset data in bytes form. + start_inventory_data[0x680080] = bytes(magic_items_array) + start_inventory_data[0x6800A0] = bytes(cards_array) + + # Add the extra max HP/MP/Hearts to all classes' base stats. Doing it this way makes us less likely to hit the max + # possible Max Ups. + # Vampire Killer + start_inventory_data[0xE08C6] = int.to_bytes(100 + extra_stats["extra health"], 2, "little") + start_inventory_data[0xE08CE] = int.to_bytes(100 + extra_stats["extra magic"], 2, "little") + start_inventory_data[0xE08D4] = int.to_bytes(50 + extra_stats["extra hearts"], 2, "little") + + # Magician + start_inventory_data[0xE090E] = int.to_bytes(50 + extra_stats["extra health"], 2, "little") + start_inventory_data[0xE0916] = int.to_bytes(400 + extra_stats["extra magic"], 2, "little") + start_inventory_data[0xE091C] = int.to_bytes(50 + extra_stats["extra hearts"], 2, "little") + + # Fighter + start_inventory_data[0xE0932] = int.to_bytes(200 + extra_stats["extra health"], 2, "little") + start_inventory_data[0xE093A] = int.to_bytes(50 + extra_stats["extra magic"], 2, "little") + start_inventory_data[0xE0940] = int.to_bytes(50 + extra_stats["extra hearts"], 2, "little") + + # Shooter + start_inventory_data[0xE0832] = int.to_bytes(50 + extra_stats["extra health"], 2, "little") + start_inventory_data[0xE08F2] = int.to_bytes(100 + extra_stats["extra magic"], 2, "little") + start_inventory_data[0xE08F8] = int.to_bytes(250 + extra_stats["extra hearts"], 2, "little") + + # Thief + start_inventory_data[0xE0956] = int.to_bytes(50 + extra_stats["extra health"], 2, "little") + start_inventory_data[0xE095E] = int.to_bytes(50 + extra_stats["extra magic"], 2, "little") + start_inventory_data[0xE0964] = int.to_bytes(50 + extra_stats["extra hearts"], 2, "little") + + return start_inventory_data, start_with_detonator diff --git a/worlds/cvcotm/client.py b/worlds/cvcotm/client.py new file mode 100644 index 000000000000..4db2c2faabfa --- /dev/null +++ b/worlds/cvcotm/client.py @@ -0,0 +1,563 @@ +from typing import TYPE_CHECKING, Set +from .locations import BASE_ID, get_location_names_to_ids +from .items import cvcotm_item_info, MAJORS_CLASSIFICATIONS +from .locations import cvcotm_location_info +from .cvcotm_text import cvcotm_string_to_bytearray +from .options import CompletionGoal, CVCotMDeathLink, IronMaidenBehavior +from .rom import ARCHIPELAGO_IDENTIFIER_START, ARCHIPELAGO_IDENTIFIER, AUTH_NUMBER_START, QUEUED_TEXT_STRING_START +from .data import iname, lname + +from BaseClasses import ItemClassification +from NetUtils import ClientStatus +import worlds._bizhawk as bizhawk +import base64 +from worlds._bizhawk.client import BizHawkClient + +if TYPE_CHECKING: + from worlds._bizhawk.context import BizHawkClientContext + +CURRENT_STATUS_ADDRESS = 0xD0 +POISON_TIMER_TILL_DAMAGE_ADDRESS = 0xD8 +POISON_DAMAGE_VALUE_ADDRESS = 0xDE +GAME_STATE_ADDRESS = 0x45D8 +FLAGS_ARRAY_START = 0x25374 +CARDS_ARRAY_START = 0x25674 +NUM_RECEIVED_ITEMS_ADDRESS = 0x253D0 +MAX_UPS_ARRAY_START = 0x2572C +MAGIC_ITEMS_ARRAY_START = 0x2572F +QUEUED_TEXTBOX_1_ADDRESS = 0x25300 +QUEUED_TEXTBOX_2_ADDRESS = 0x25302 +QUEUED_MSG_DELAY_TIMER_ADDRESS = 0x25304 +QUEUED_SOUND_ID_ADDRESS = 0x25306 +DELAY_TIMER_ADDRESS = 0x25308 +CURRENT_CUTSCENE_ID_ADDRESS = 0x26000 +NATHAN_STATE_ADDRESS = 0x50 +CURRENT_HP_ADDRESS = 0x2562E +CURRENT_MP_ADDRESS = 0x25636 +CURRENT_HEARTS_ADDRESS = 0x2563C +CURRENT_LOCATION_VALUES_START = 0x253FC +ROM_NAME_START = 0xA0 + +AREA_SEALED_ROOM = 0x00 +AREA_BATTLE_ARENA = 0x0E +GAME_STATE_GAMEPLAY = 0x06 +GAME_STATE_CREDITS = 0x21 +NATHAN_STATE_SAVING = 0x34 +STATUS_POISON = b"\x02" +TEXT_ID_DSS_TUTORIAL = b"\x1D\x82" +TEXT_ID_MULTIWORLD_MESSAGE = b"\xF2\x84" +SOUND_ID_UNUSED_SIMON_FANFARE = b"\x04" +SOUND_ID_MAIDEN_BREAKING = b"\x79" +# SOUND_ID_NATHAN_FREEZING = b"\x7A" +SOUND_ID_BAD_CONFIG = b"\x2D\x01" +SOUND_ID_DRACULA_CHARGE = b"\xAB\x01" +SOUND_ID_MINOR_PICKUP = b"\xB3\x01" +SOUND_ID_MAJOR_PICKUP = b"\xB4\x01" + +ITEM_NAME_LIMIT = 300 +PLAYER_NAME_LIMIT = 50 + +FLAG_HIT_IRON_MAIDEN_SWITCH = 0x2A +FLAG_SAW_DSS_TUTORIAL = 0xB1 +FLAG_WON_BATTLE_ARENA = 0xB2 +FLAG_DEFEATED_DRACULA_II = 0xBC + +# These flags are communicated to the tracker as a bitfield using this order. +# Modifying the order will cause undetectable autotracking issues. +EVENT_FLAG_MAP = { + FLAG_HIT_IRON_MAIDEN_SWITCH: "FLAG_HIT_IRON_MAIDEN_SWITCH", + FLAG_WON_BATTLE_ARENA: "FLAG_WON_BATTLE_ARENA", + 0xB3: "FLAG_DEFEATED_CERBERUS", + 0xB4: "FLAG_DEFEATED_NECROMANCER", + 0xB5: "FLAG_DEFEATED_IRON_GOLEM", + 0xB6: "FLAG_DEFEATED_ADRAMELECH", + 0xB7: "FLAG_DEFEATED_DRAGON_ZOMBIES", + 0xB8: "FLAG_DEFEATED_DEATH", + 0xB9: "FLAG_DEFEATED_CAMILLA", + 0xBA: "FLAG_DEFEATED_HUGH", + 0xBB: "FLAG_DEFEATED_DRACULA_I", + FLAG_DEFEATED_DRACULA_II: "FLAG_DEFEATED_DRACULA_II" +} + +DEATHLINK_AREA_NAMES = ["Sealed Room", "Catacomb", "Abyss Staircase", "Audience Room", "Triumph Hallway", + "Machine Tower", "Eternal Corridor", "Chapel Tower", "Underground Warehouse", + "Underground Gallery", "Underground Waterway", "Outer Wall", "Observation Tower", + "Ceremonial Room", "Battle Arena"] + + +class CastlevaniaCotMClient(BizHawkClient): + game = "Castlevania - Circle of the Moon" + system = "GBA" + patch_suffix = ".apcvcotm" + sent_initial_packets: bool + self_induced_death: bool + local_checked_locations: Set[int] + client_set_events = {flag_name: False for flag, flag_name in EVENT_FLAG_MAP.items()} + killed_dracula_2: bool + won_battle_arena: bool + sent_message_queue: list + death_causes: list + currently_dead: bool + synced_set_events: bool + saw_arena_win_message: bool + saw_dss_tutorial: bool + + async def validate_rom(self, ctx: "BizHawkClientContext") -> bool: + from CommonClient import logger + + try: + # Check ROM name/patch version + game_names = await bizhawk.read(ctx.bizhawk_ctx, [(ROM_NAME_START, 0xC, "ROM"), + (ARCHIPELAGO_IDENTIFIER_START, 12, "ROM")]) + if game_names[0].decode("ascii") != "DRACULA AGB1": + return False + if game_names[1] == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00': + logger.info("ERROR: You appear to be running an unpatched version of Castlevania: Circle of the Moon. " + "You need to generate a patch file and use it to create a patched ROM.") + return False + if game_names[1].decode("ascii") != ARCHIPELAGO_IDENTIFIER: + logger.info("ERROR: The patch file used to create this ROM is not compatible with " + "this client. Double check your client version against the version being " + "used by the generator.") + return False + except UnicodeDecodeError: + return False + except bizhawk.RequestFailedError: + return False # Should verify on the next pass + + ctx.game = self.game + ctx.items_handling = 0b001 + ctx.want_slot_data = True + ctx.watcher_timeout = 0.125 + return True + + async def set_auth(self, ctx: "BizHawkClientContext") -> None: + auth_raw = (await bizhawk.read(ctx.bizhawk_ctx, [(AUTH_NUMBER_START, 16, "ROM")]))[0] + ctx.auth = base64.b64encode(auth_raw).decode("utf-8") + # Initialize all the local client attributes here so that nothing will be carried over from a previous CotM if + # the player tried changing CotM ROMs without resetting their Bizhawk Client instance. + self.sent_initial_packets = False + self.local_checked_locations = set() + self.self_induced_death = False + self.client_set_events = {flag_name: False for flag, flag_name in EVENT_FLAG_MAP.items()} + self.killed_dracula_2 = False + self.won_battle_arena = False + self.sent_message_queue = [] + self.death_causes = [] + self.currently_dead = False + self.synced_set_events = False + self.saw_arena_win_message = False + self.saw_dss_tutorial = False + + def on_package(self, ctx: "BizHawkClientContext", cmd: str, args: dict) -> None: + if cmd != "Bounced": + return + if "tags" not in args: + return + if ctx.slot is None: + return + if "DeathLink" in args["tags"] and args["data"]["source"] != ctx.slot_info[ctx.slot].name: + if "cause" in args["data"]: + cause = args["data"]["cause"] + if cause == "": + cause = f"{args['data']['source']} killed you without a word!" + if len(cause) > ITEM_NAME_LIMIT + PLAYER_NAME_LIMIT: + cause = cause[:ITEM_NAME_LIMIT + PLAYER_NAME_LIMIT] + else: + cause = f"{args['data']['source']} killed you without a word!" + + # Highlight the player that killed us in the game's orange text. + if args['data']['source'] in cause: + words = cause.split(args['data']['source'], 1) + cause = words[0] + "「" + args['data']['source'] + "」" + words[1] + + self.death_causes += [cause] + + async def game_watcher(self, ctx: "BizHawkClientContext") -> None: + if ctx.server is None or ctx.server.socket.closed or ctx.slot_data is None or ctx.slot is None: + return + + try: + # Scout all Locations and get our Set events upon initial connection. + if not self.sent_initial_packets: + await ctx.send_msgs([{ + "cmd": "LocationScouts", + "locations": [code for name, code in get_location_names_to_ids().items() + if code in ctx.server_locations], + "create_as_hint": 0 + }]) + await ctx.send_msgs([{ + "cmd": "Get", + "keys": [f"castlevania_cotm_events_{ctx.team}_{ctx.slot}"] + }]) + self.sent_initial_packets = True + + read_state = await bizhawk.read(ctx.bizhawk_ctx, [(GAME_STATE_ADDRESS, 1, "EWRAM"), + (FLAGS_ARRAY_START, 32, "EWRAM"), + (CARDS_ARRAY_START, 20, "EWRAM"), + (NUM_RECEIVED_ITEMS_ADDRESS, 2, "EWRAM"), + (MAX_UPS_ARRAY_START, 3, "EWRAM"), + (MAGIC_ITEMS_ARRAY_START, 8, "EWRAM"), + (QUEUED_TEXTBOX_1_ADDRESS, 2, "EWRAM"), + (DELAY_TIMER_ADDRESS, 2, "EWRAM"), + (CURRENT_CUTSCENE_ID_ADDRESS, 1, "EWRAM"), + (NATHAN_STATE_ADDRESS, 1, "EWRAM"), + (CURRENT_HP_ADDRESS, 18, "EWRAM"), + (CURRENT_LOCATION_VALUES_START, 2, "EWRAM")]) + + game_state = int.from_bytes(read_state[0], "little") + event_flags_array = read_state[1] + cards_array = list(read_state[2]) + max_ups_array = list(read_state[4]) + magic_items_array = list(read_state[5]) + num_received_items = int.from_bytes(bytearray(read_state[3]), "little") + queued_textbox = int.from_bytes(bytearray(read_state[6]), "little") + delay_timer = int.from_bytes(bytearray(read_state[7]), "little") + cutscene = int.from_bytes(bytearray(read_state[8]), "little") + nathan_state = int.from_bytes(bytearray(read_state[9]), "little") + health_stats_array = bytearray(read_state[10]) + area = int.from_bytes(bytearray(read_state[11][0:1]), "little") + room = int.from_bytes(bytearray(read_state[11][1:]), "little") + + # Get out each of the individual health/magic/heart values. + hp = int.from_bytes(health_stats_array[0:2], "little") + max_hp = int.from_bytes(health_stats_array[4:6], "little") + # mp = int.from_bytes(health_stats_array[8:10], "little") Not used. But it's here if it's ever needed! + max_mp = int.from_bytes(health_stats_array[12:14], "little") + hearts = int.from_bytes(health_stats_array[14:16], "little") + max_hearts = int.from_bytes(health_stats_array[16:], "little") + + # If there's no textbox already queued, the delay timer is 0, we are not in a cutscene, and Nathan's current + # state value is not 0x34 (using a save room), it should be safe to inject a textbox message. + ok_to_inject = not queued_textbox and not delay_timer and not cutscene \ + and nathan_state != NATHAN_STATE_SAVING + + # Make sure we are in the Gameplay or Credits states before detecting sent locations. + # If we are in any other state, such as the Game Over state, reset the textbox buffers back to 0 so that we + # don't receive the most recent item upon loading back in. + # + # If the intro cutscene floor broken flag is not set, then assume we are in the demo; at no point during + # regular gameplay will this flag not be set. + if game_state not in [GAME_STATE_GAMEPLAY, GAME_STATE_CREDITS] or not event_flags_array[6] & 0x02: + self.currently_dead = False + await bizhawk.write(ctx.bizhawk_ctx, [(QUEUED_TEXTBOX_1_ADDRESS, [0 for _ in range(12)], "EWRAM")]) + return + + # Enable DeathLink if it's in our slot_data. + if "DeathLink" not in ctx.tags and ctx.slot_data["death_link"]: + await ctx.update_death_link(True) + + # Send a DeathLink if we died on our own independently of receiving another one. + if "DeathLink" in ctx.tags and hp == 0 and not self.currently_dead: + self.currently_dead = True + + # Check if we are in Dracula II's arena. The game considers this part of the Sealed Room area, + # which I don't think makes sense to be player-facing like this. + if area == AREA_SEALED_ROOM and room == 2: + area_of_death = "Dracula's realm" + # If we aren't in Dracula II's arena, then take the name of whatever area the player is currently in. + else: + area_of_death = DEATHLINK_AREA_NAMES[area] + + await ctx.send_death(f"{ctx.player_names[ctx.slot]} perished in {area_of_death}. Dracula has won!") + + # Update the Dracula II and Battle Arena events already being done on past separate sessions for if the + # player is running the Battle Arena and Dracula goal. + if f"castlevania_cotm_events_{ctx.team}_{ctx.slot}" in ctx.stored_data: + if ctx.stored_data[f"castlevania_cotm_events_{ctx.team}_{ctx.slot}"] is not None: + if ctx.stored_data[f"castlevania_cotm_events_{ctx.team}_{ctx.slot}"] & 0x2: + self.won_battle_arena = True + + if ctx.stored_data[f"castlevania_cotm_events_{ctx.team}_{ctx.slot}"] & 0x800: + self.killed_dracula_2 = True + + # If we won the Battle Arena, haven't seen the win message yet, and are in the Arena at the moment, pop up + # the win message while playing the game's unused Theme of Simon Belmont fanfare. + if self.won_battle_arena and not self.saw_arena_win_message and area == AREA_BATTLE_ARENA \ + and ok_to_inject and not self.currently_dead: + win_message = cvcotm_string_to_bytearray(" A 「WINNER」 IS 「YOU」!▶", "little middle", 0, + wrap=False) + await bizhawk.write(ctx.bizhawk_ctx, [(QUEUED_TEXTBOX_1_ADDRESS, TEXT_ID_MULTIWORLD_MESSAGE, "EWRAM"), + (QUEUED_SOUND_ID_ADDRESS, SOUND_ID_UNUSED_SIMON_FANFARE, "EWRAM"), + (QUEUED_TEXT_STRING_START, win_message, "ROM")]) + self.saw_arena_win_message = True + + # If we have any queued death causes, handle DeathLink giving here. + elif self.death_causes and ok_to_inject and not self.currently_dead: + + # Inject the oldest cause as a textbox message and play the Dracula charge attack sound. + death_text = self.death_causes[0] + death_writes = [(QUEUED_TEXTBOX_1_ADDRESS, TEXT_ID_MULTIWORLD_MESSAGE, "EWRAM"), + (QUEUED_SOUND_ID_ADDRESS, SOUND_ID_DRACULA_CHARGE, "EWRAM")] + + # If we are in the Battle Arena and are not using the On Including Arena DeathLink option, extend the + # DeathLink message and don't actually kill Nathan. + if ctx.slot_data["death_link"] != CVCotMDeathLink.option_arena_on and area == AREA_BATTLE_ARENA: + death_text += "◊The Battle Arena nullified the DeathLink. Go fight fair and square!" + else: + # Otherwise, kill Nathan by giving him a 9999 damage-dealing poison status that hurts him as soon as + # the death cause textbox is dismissed. + death_writes += [(CURRENT_STATUS_ADDRESS, STATUS_POISON, "EWRAM"), + (POISON_TIMER_TILL_DAMAGE_ADDRESS, b"\x38", "EWRAM"), + (POISON_DAMAGE_VALUE_ADDRESS, b"\x0F\x27", "EWRAM")] + + # Add the final death text and write the whole shebang. + death_writes += [(QUEUED_TEXT_STRING_START, + bytes(cvcotm_string_to_bytearray(death_text + "◊", "big middle", 0)), "ROM")] + await bizhawk.write(ctx.bizhawk_ctx, death_writes) + + # Delete the oldest death cause that we just wrote and set currently_dead to True so the client doesn't + # think we just died on our own on the subsequent frames before the Game Over state. + del(self.death_causes[0]) + self.currently_dead = True + + # If we have a queue of Locations to inject "sent" messages with, do so before giving any subsequent Items. + elif self.sent_message_queue and ok_to_inject and not self.currently_dead and ctx.locations_info: + loc = self.sent_message_queue[0] + # Truncate the Item name. ArchipIDLE's FFXIV Item is 214 characters, for comparison. + item_name = ctx.item_names.lookup_in_slot(ctx.locations_info[loc].item, ctx.locations_info[loc].player) + if len(item_name) > ITEM_NAME_LIMIT: + item_name = item_name[:ITEM_NAME_LIMIT] + # Truncate the player name. Player names are normally capped at 16 characters, but there is no limit on + # ItemLink group names. + player_name = ctx.player_names[ctx.locations_info[loc].player] + if len(player_name) > PLAYER_NAME_LIMIT: + player_name = player_name[:PLAYER_NAME_LIMIT] + + sent_text = cvcotm_string_to_bytearray(f"「{item_name}」 sent to 「{player_name}」◊", "big middle", 0) + + # Set the correct sound to play depending on the Item's classification. + if item_name == iname.ironmaidens and \ + ctx.slot_info[ctx.locations_info[loc].player].game == "Castlevania - Circle of the Moon": + mssg_sfx_id = SOUND_ID_MAIDEN_BREAKING + sent_text = cvcotm_string_to_bytearray(f"「Iron Maidens」 broken for 「{player_name}」◊", + "big middle", 0) + elif ctx.locations_info[loc].flags & MAJORS_CLASSIFICATIONS: + mssg_sfx_id = SOUND_ID_MAJOR_PICKUP + elif ctx.locations_info[loc].flags & ItemClassification.trap: + mssg_sfx_id = SOUND_ID_BAD_CONFIG + else: # Filler + mssg_sfx_id = SOUND_ID_MINOR_PICKUP + + await bizhawk.write(ctx.bizhawk_ctx, [(QUEUED_TEXTBOX_1_ADDRESS, TEXT_ID_MULTIWORLD_MESSAGE, "EWRAM"), + (QUEUED_SOUND_ID_ADDRESS, mssg_sfx_id, "EWRAM"), + (QUEUED_TEXT_STRING_START, sent_text, "ROM")]) + + del(self.sent_message_queue[0]) + + # If the game hasn't received all items yet, it's ok to inject, and the current number of received items + # still matches what we read before, then write the next incoming item into the inventory and, separately, + # the textbox ID to trigger the multiworld textbox, sound effect to play when the textbox opens, number to + # increment the received items count by, and the text to go into the multiworld textbox. The game will then + # do the rest when it's able to. + elif num_received_items < len(ctx.items_received) and ok_to_inject and not self.currently_dead: + next_item = ctx.items_received[num_received_items] + + # Figure out what inventory array and offset from said array to increment based on what we are + # receiving. + flag_index = 0 + flag_array = b"" + inv_array = [] + inv_array_start = 0 + text_id_2 = b"\x00\x00" + item_type = next_item.item & 0xFF00 + inv_array_index = next_item.item & 0xFF + if item_type == 0xE600: # Card + inv_array_start = CARDS_ARRAY_START + inv_array = cards_array + mssg_sfx_id = SOUND_ID_MAJOR_PICKUP + # If skip_tutorials is off and the saw DSS tutorial flag is not set, set the flag and display it + # for the second textbox. + if not self.saw_dss_tutorial and not ctx.slot_data["skip_tutorials"]: + flag_index = FLAG_SAW_DSS_TUTORIAL + flag_array = event_flags_array + text_id_2 = TEXT_ID_DSS_TUTORIAL + elif item_type == 0xE800 and inv_array_index == 0x09: # Maiden Detonator + flag_index = FLAG_HIT_IRON_MAIDEN_SWITCH + flag_array = event_flags_array + mssg_sfx_id = SOUND_ID_MAIDEN_BREAKING + elif item_type == 0xE800: # Any other Magic Item + inv_array_start = MAGIC_ITEMS_ARRAY_START + inv_array = magic_items_array + mssg_sfx_id = SOUND_ID_MAJOR_PICKUP + if inv_array_index > 5: # The unused Map's index is skipped over. + inv_array_index -= 1 + else: # Max Up + inv_array_start = MAX_UPS_ARRAY_START + mssg_sfx_id = SOUND_ID_MINOR_PICKUP + inv_array = max_ups_array + + item_name = ctx.item_names.lookup_in_slot(next_item.item) + player_name = ctx.player_names[next_item.player] + # Truncate the player name. + if len(player_name) > PLAYER_NAME_LIMIT: + player_name = player_name[:PLAYER_NAME_LIMIT] + + # If the Item came from a different player, display a custom received message. Otherwise, display the + # vanilla received message for that Item. + if next_item.player != ctx.slot: + text_id_1 = TEXT_ID_MULTIWORLD_MESSAGE + if item_name == iname.ironmaidens: + received_text = cvcotm_string_to_bytearray(f"「Iron Maidens」 broken by " + f"「{player_name}」◊", "big middle", 0) + else: + received_text = cvcotm_string_to_bytearray(f"「{item_name}」 received from " + f"「{player_name}」◊", "big middle", 0) + text_write = [(QUEUED_TEXT_STRING_START, bytes(received_text), "ROM")] + + # If skip_tutorials is off, display the Item's tutorial for the second textbox (if it has one). + if not ctx.slot_data["skip_tutorials"] and cvcotm_item_info[item_name].tutorial_id is not None: + text_id_2 = cvcotm_item_info[item_name].tutorial_id + else: + text_id_1 = cvcotm_item_info[item_name].text_id + text_write = [] + + # Check if the player has 255 of the item being received. If they do, don't increment that counter + # further. + refill_write = [] + count_write = [] + flag_write = [] + count_guard = [] + flag_guard = [] + + # If there's a value to increment in an inventory array, do so here after checking to see if we can. + if inv_array_start: + if inv_array[inv_array_index] + 1 > 0xFF: + # If it's a stat max up being received, manually give a refill of that item's stat. + # Normally, the game does this automatically by incrementing the number of that max up. + if item_name == iname.hp_max: + refill_write = [(CURRENT_HP_ADDRESS, int.to_bytes(max_hp, 2, "little"), "EWRAM")] + elif item_name == iname.mp_max: + refill_write = [(CURRENT_MP_ADDRESS, int.to_bytes(max_mp, 2, "little"), "EWRAM")] + elif item_name == iname.heart_max: + # If adding +6 Hearts doesn't put us over the player's current max Hearts, do so. + # Otherwise, set the player's current Hearts to the current max. + if hearts + 6 > max_hearts: + new_hearts = max_hearts + else: + new_hearts = hearts + 6 + refill_write = [(CURRENT_HEARTS_ADDRESS, int.to_bytes(new_hearts, 2, "little"), "EWRAM")] + else: + # If our received count of that item is not more than 255, increment it normally. + inv_address = inv_array_start + inv_array_index + count_guard = [(inv_address, int.to_bytes(inv_array[inv_array_index], 1, "little"), "EWRAM")] + count_write = [(inv_address, int.to_bytes(inv_array[inv_array_index] + 1, 1, "little"), + "EWRAM")] + + # If there's a flag value to set, do so here. + if flag_index: + flag_bytearray_index = flag_index // 8 + flag_address = FLAGS_ARRAY_START + flag_bytearray_index + flag_guard = [(flag_address, int.to_bytes(flag_array[flag_bytearray_index], 1, "little"), "EWRAM")] + flag_write = [(flag_address, int.to_bytes(flag_array[flag_bytearray_index] | + (0x01 << (flag_index % 8)), 1, "little"), "EWRAM")] + + await bizhawk.guarded_write(ctx.bizhawk_ctx, + [(QUEUED_TEXTBOX_1_ADDRESS, text_id_1, "EWRAM"), + (QUEUED_TEXTBOX_2_ADDRESS, text_id_2, "EWRAM"), + (QUEUED_MSG_DELAY_TIMER_ADDRESS, b"\x01", "EWRAM"), + (QUEUED_SOUND_ID_ADDRESS, mssg_sfx_id, "EWRAM")] + + count_write + flag_write + text_write + refill_write, + # Make sure the number of received items and number to overwrite are still + # what we expect them to be. + [(NUM_RECEIVED_ITEMS_ADDRESS, read_state[3], "EWRAM")] + + count_guard + flag_guard), + + locs_to_send = set() + + # Check each bit in each flag byte for set Location and event flags. + checked_set_events = {flag_name: False for flag, flag_name in EVENT_FLAG_MAP.items()} + for byte_index, byte in enumerate(event_flags_array): + for i in range(8): + and_value = 0x01 << i + if byte & and_value != 0: + flag_id = byte_index * 8 + i + + location_id = flag_id + BASE_ID + if location_id in ctx.server_locations: + locs_to_send.add(location_id) + + # If the flag for pressing the Iron Maiden switch is set, and the Iron Maiden behavior is + # vanilla (meaning we really pressed the switch), send the Iron Maiden switch as checked. + if flag_id == FLAG_HIT_IRON_MAIDEN_SWITCH and ctx.slot_data["iron_maiden_behavior"] == \ + IronMaidenBehavior.option_vanilla: + locs_to_send.add(cvcotm_location_info[lname.ct21].code + BASE_ID) + + # If the DSS tutorial flag is set, let the client know, so it's not shown again for + # subsequently-received cards. + if flag_id == FLAG_SAW_DSS_TUTORIAL: + self.saw_dss_tutorial = True + + if flag_id in EVENT_FLAG_MAP: + checked_set_events[EVENT_FLAG_MAP[flag_id]] = True + + # Update the client's statuses for the Battle Arena and Dracula goals. + if flag_id == FLAG_WON_BATTLE_ARENA: + self.won_battle_arena = True + + if flag_id == FLAG_DEFEATED_DRACULA_II: + self.killed_dracula_2 = True + + # Send Locations if there are any to send. + if locs_to_send != self.local_checked_locations: + self.local_checked_locations = locs_to_send + + if locs_to_send is not None: + # Capture all the Locations with non-local Items to send that are in ctx.missing_locations + # (the ones that were definitely never sent before). + if ctx.locations_info: + self.sent_message_queue += [loc for loc in locs_to_send if loc in ctx.missing_locations and + ctx.locations_info[loc].player != ctx.slot] + # If we still don't have the locations info at this point, send another LocationScout packet just + # in case something went wrong, and we never received the initial LocationInfo packet. + else: + await ctx.send_msgs([{ + "cmd": "LocationScouts", + "locations": [code for name, code in get_location_names_to_ids().items() + if code in ctx.server_locations], + "create_as_hint": 0 + }]) + + await ctx.send_msgs([{ + "cmd": "LocationChecks", + "locations": list(locs_to_send) + }]) + + # Check the win condition depending on what our completion goal is. + # The Dracula option requires the "killed Dracula II" flag to be set or being in the credits state. + # The Battle Arena option requires the Shinning Armor pickup flag to be set. + # Otherwise, the Battle Arena and Dracula option requires both of the above to be satisfied simultaneously. + if ctx.slot_data["completion_goal"] == CompletionGoal.option_dracula: + win_condition = self.killed_dracula_2 + elif ctx.slot_data["completion_goal"] == CompletionGoal.option_battle_arena: + win_condition = self.won_battle_arena + else: + win_condition = self.killed_dracula_2 and self.won_battle_arena + + # Send game clear if we've satisfied the win condition. + if not ctx.finished_game and win_condition: + ctx.finished_game = True + await ctx.send_msgs([{ + "cmd": "StatusUpdate", + "status": ClientStatus.CLIENT_GOAL + }]) + + # Update the tracker event flags + if checked_set_events != self.client_set_events and ctx.slot is not None: + event_bitfield = 0 + for index, (flag, flag_name) in enumerate(EVENT_FLAG_MAP.items()): + if checked_set_events[flag_name]: + event_bitfield |= 1 << index + + await ctx.send_msgs([{ + "cmd": "Set", + "key": f"castlevania_cotm_events_{ctx.team}_{ctx.slot}", + "default": 0, + "want_reply": False, + "operations": [{"operation": "or", "value": event_bitfield}], + }]) + self.client_set_events = checked_set_events + + except bizhawk.RequestFailedError: + # Exit handler and return to main loop to reconnect. + pass diff --git a/worlds/cvcotm/cvcotm_text.py b/worlds/cvcotm/cvcotm_text.py new file mode 100644 index 000000000000..803435a5fce8 --- /dev/null +++ b/worlds/cvcotm/cvcotm_text.py @@ -0,0 +1,178 @@ +from typing import Literal + +cvcotm_char_dict = {"\n": 0x09, " ": 0x26, "!": 0x4A, '"': 0x78, "#": 0x79, "$": 0x7B, "%": 0x68, "&": 0x73, "'": 0x51, + "(": 0x54, ")": 0x55, "*": 0x7A, "+": 0x50, ",": 0x4C, "-": 0x58, ".": 0x35, "/": 0x70, "0": 0x64, + "1": 0x6A, "2": 0x63, "3": 0x6C, "4": 0x71, "5": 0x69, "6": 0x7C, "7": 0x7D, "8": 0x72, "9": 0x85, + ":": 0x86, ";": 0x87, "<": 0x8F, "=": 0x90, ">": 0x91, "?": 0x48, "@": 0x98, "A": 0x3E, "B": 0x4D, + "C": 0x44, "D": 0x45, "E": 0x4E, "F": 0x56, "G": 0x4F, "H": 0x40, "I": 0x43, "J": 0x6B, "K": 0x66, + "L": 0x5F, "M": 0x42, "N": 0x52, "O": 0x67, "P": 0x4B, "Q": 0x99, "R": 0x46, "S": 0x41, "T": 0x47, + "U": 0x60, "V": 0x6E, "W": 0x49, "X": 0x6D, "Y": 0x53, "Z": 0x6F, "[": 0x59, "\\": 0x9A, "]": 0x5A, + "^": 0x9B, "_": 0xA1, "a": 0x29, "b": 0x3C, "c": 0x33, "d": 0x32, "e": 0x28, "f": 0x3A, "g": 0x39, + "h": 0x31, "i": 0x2D, "j": 0x62, "k": 0x3D, "l": 0x30, "m": 0x36, "n": 0x2E, "o": 0x2B, "p": 0x38, + "q": 0x61, "r": 0x2C, "s": 0x2F, "t": 0x2A, "u": 0x34, "v": 0x3F, "w": 0x37, "x": 0x57, "y": 0x3B, + "z": 0x65, "{": 0xA3, "|": 0xA4, "}": 0xA5, "`": 0xA2, "~": 0xAC, + # Special command characters + "▶": 0x02, # Press A with prompt arrow. + "◊": 0x03, # Press A without prompt arrow. + "\t": 0x01, # Clear the text buffer; usually after pressing A to advance. + "\b": 0x0A, # Reset text alignment; usually after pressing A. + "「": 0x06, # Start orange text + "」": 0x07, # End orange text + } + +# Characters that do not contribute to the line length. +weightless_chars = {"\n", "▶", "◊", "\b", "\t", "「", "」"} + + +def cvcotm_string_to_bytearray(cvcotm_text: str, textbox_type: Literal["big top", "big middle", "little middle"], + speed: int, portrait: int = 0xFF, wrap: bool = True, + skip_textbox_controllers: bool = False) -> bytearray: + """Converts a string into a textbox bytearray following CVCotM's string format.""" + text_bytes = bytearray(0) + if portrait == 0xFF and textbox_type != "little middle": + text_bytes.append(0x0C) # Insert the character to convert a 3-line named textbox into a 4-line nameless one. + + # Figure out the start and end params for the textbox based on what type it is. + if textbox_type == "little middle": + main_control_start_param = 0x10 + main_control_end_param = 0x20 + elif textbox_type == "big top": + main_control_start_param = 0x40 + main_control_end_param = 0xC0 + else: + main_control_start_param = 0x80 + main_control_end_param = 0xC0 + + # Figure out the number of lines and line length limit. + if textbox_type == "little middle": + total_lines = 1 + len_limit = 29 + elif textbox_type != "little middle" and portrait != 0xFF: + total_lines = 3 + len_limit = 21 + else: + total_lines = 4 + len_limit = 23 + + # Wrap the text if we are opting to do so. + if wrap: + refined_text = cvcotm_text_wrap(cvcotm_text, len_limit, total_lines) + else: + refined_text = cvcotm_text + + # Add the textbox control characters if we are opting to add them. + if not skip_textbox_controllers: + text_bytes.extend([0x1D, main_control_start_param + (speed & 0xF)]) # Speed should be a value between 0 and 15. + + # Add the portrait (if we are adding one). + if portrait != 0xFF and textbox_type != "little middle": + text_bytes.extend([0x1E, portrait & 0xFF]) + + for i, char in enumerate(refined_text): + if char in cvcotm_char_dict: + text_bytes.extend([cvcotm_char_dict[char]]) + # If we're pressing A to advance, add the text clear and reset alignment characters. + if char in ["▶", "◊"] and not skip_textbox_controllers: + text_bytes.extend([0x01, 0x0A]) + else: + text_bytes.extend([0x48]) + + # Add the characters indicating the end of the whole message. + if not skip_textbox_controllers: + text_bytes.extend([0x1D, main_control_end_param, 0x00]) + else: + text_bytes.extend([0x00]) + return text_bytes + + +def cvcotm_text_truncate(cvcotm_text: str, textbox_len_limit: int) -> str: + """Truncates a string at a given in-game text line length.""" + line_len = 0 + + for i in range(len(cvcotm_text)): + if cvcotm_text[i] not in weightless_chars: + line_len += 1 + + if line_len > textbox_len_limit: + return cvcotm_text[0x00:i] + + return cvcotm_text + + +def cvcotm_text_wrap(cvcotm_text: str, textbox_len_limit: int, total_lines: int = 4) -> str: + """Rebuilds a string with some of its spaces replaced with newlines to ensure the text wraps properly in an in-game + textbox of a given length. If the number of lines allowed per textbox is exceeded, an A prompt will be placed + instead of a newline.""" + words = cvcotm_text.split(" ") + new_text = "" + line_len = 0 + num_lines = 1 + + for word_index, word in enumerate(words): + # Reset the word length to 0 on every word iteration and make its default divider a space. + word_len = 0 + word_divider = " " + + # Check if we're at the very beginning of a line and handle the situation accordingly by increasing the current + # line length to account for the space if we are not. Otherwise, the word divider should be nothing. + if line_len != 0: + line_len += 1 + else: + word_divider = "" + + new_word = "" + + for char_index, char in enumerate(word): + # Check if the current character contributes to the line length. + if char not in weightless_chars: + line_len += 1 + word_len += 1 + + # If we're looking at a manually-placed newline, add +1 to the lines counter and reset the length counters. + if char == "\n": + word_len = 0 + line_len = 0 + num_lines += 1 + # If this puts us over the line limit, insert the A advance prompt character. + if num_lines > total_lines: + num_lines = 1 + new_word += "▶" + + # If we're looking at a manually-placed A advance prompt, reset the lines and length counters. + if char in ["▶", "◊"]: + word_len = 0 + line_len = 0 + num_lines = 1 + + # If the word alone is long enough to exceed the line length, wrap without moving the entire word. + if word_len > textbox_len_limit: + word_len = 1 + line_len = 1 + num_lines += 1 + word_splitter = "\n" + + # If this puts us over the line limit, replace the newline with the A advance prompt character. + if num_lines > total_lines: + num_lines = 1 + word_splitter = "▶" + + new_word += word_splitter + + # If the total length of the current line exceeds the line length, wrap the current word to the next line. + if line_len > textbox_len_limit: + word_divider = "\n" + line_len = word_len + num_lines += 1 + # If we're over the allowed number of lines to be displayed in the textbox, insert the A advance + # character instead. + if num_lines > total_lines: + num_lines = 1 + word_divider = "▶" + + # Add the character to the new word if the character is not a newline immediately following up an A advance. + if char != "\n" or new_word[len(new_word)-1] not in ["▶", "◊"]: + new_word += char + + new_text += word_divider + new_word + + return new_text diff --git a/worlds/cvcotm/data/iname.py b/worlds/cvcotm/data/iname.py new file mode 100644 index 000000000000..f121217fdf20 --- /dev/null +++ b/worlds/cvcotm/data/iname.py @@ -0,0 +1,36 @@ +double = "Double" +tackle = "Tackle" +kick_boots = "Kick Boots" +heavy_ring = "Heavy Ring" +cleansing = "Cleansing" +roc_wing = "Roc Wing" +last_key = "Last Key" +ironmaidens = "Maiden Detonator" + +heart_max = "Heart Max Up" +mp_max = "MP Max Up" +hp_max = "HP Max Up" + +salamander = "Salamander Card" +serpent = "Serpent Card" +mandragora = "Mandragora Card" +golem = "Golem Card" +cockatrice = "Cockatrice Card" +manticore = "Manticore Card" +griffin = "Griffin Card" +thunderbird = "Thunderbird Card" +unicorn = "Unicorn Card" +black_dog = "Black Dog Card" +mercury = "Mercury Card" +venus = "Venus Card" +jupiter = "Jupiter Card" +mars = "Mars Card" +diana = "Diana Card" +apollo = "Apollo Card" +neptune = "Neptune Card" +saturn = "Saturn Card" +uranus = "Uranus Card" +pluto = "Pluto Card" + +dracula = "The Count Downed" +shinning_armor = "Where's My Super Suit?" diff --git a/worlds/cvcotm/data/ips/AllowAlwaysDrop.ips b/worlds/cvcotm/data/ips/AllowAlwaysDrop.ips new file mode 100644 index 0000000000000000000000000000000000000000..ece911545e907c7bdb2ccbcbc8108053f3feed49 GIT binary patch literal 67 zcmWG=3~}~gw9R2)5%y?zW3=7Fz`~%M&XKOnz@Wn7HN}bf0;`vqB(ukKHx@57ndxo< V>I@7W!VC-rwu~HQKqR#?vkG=S#*54z?QRSe5)xL1 SOdw?pS$o(x0)W`n-wgl}8xREm literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/BrokenMaidens.ips b/worlds/cvcotm/data/ips/BrokenMaidens.ips new file mode 100644 index 0000000000000000000000000000000000000000..84cee2c227bdfb01a1cde17c4ab1c47398eb1af3 GIT binary patch literal 54 zcmWG=3~}~gsBdB5VDRK{XH-b%NLOHBkYVv)QDiJIkeOq^py&|CX6(z!>G~?*;%-Tn{k- literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/BuffSubweapons.ips b/worlds/cvcotm/data/ips/BuffSubweapons.ips new file mode 100644 index 0000000000000000000000000000000000000000..373c1d425cfc13b7caddea85075eb14bfb0423af GIT binary patch literal 68 zcmWG=3~}~gdl|vNn8Nlkih;3~oqZnzdx|2X2E)Z(cCHHy?6qL_Ja)bX4D9w`b_%0<$&7(H&=f*05<6cIsgCw literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/CardUp_v3_Custom2.ips b/worlds/cvcotm/data/ips/CardUp_v3_Custom2.ips new file mode 100644 index 0000000000000000000000000000000000000000..e73ece2fbd06cf3d1e8f4f62bee5a9e5929e99da GIT binary patch literal 348 zcmWG=3~}~geHFmKbij@EdkO;wgC~dk!S-~H^!5V`CJLPj9e#=dK?xl}K=MIH2#{3h z324h^E-nmej0#LZHUoo79RtUOSF9YjfSC2Q3(ypxa3a{0 z1O^2LC60m_SxyBZiit5InvA!ZfL1Vg_PhDKX60xDV%Ap+7?{|qSYJmlFlhj(Dh4La zD%R%}Kx4e;yLo`U$=j2BqE7#=WrffP18XXV(y zz{}wP)W84+AOHJaHfi|rA4Ib@`~lMbP&yD!i-P5YFRL^#Fns(Ud|9-?)!z*OD0+C7 literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/Countdown.ips b/worlds/cvcotm/data/ips/Countdown.ips new file mode 100644 index 0000000000000000000000000000000000000000..4da69502a94093ee4b36ebaa0998912499b4a43a GIT binary patch literal 240 zcmWG=3~}~gQ<}!W#puD{&cIM>kj{~Az`$^Y&6A^oUxV@Pe+AYD3>wTAJu8?r87}@; zC;%$@6U@X^utnIjfx#()LG`}^8xxzeK*t6r$qNU$88mq>^7=S(b}}SK$SX2BFe-F7 zNH{QPFkECbWiopGoZZKP#eqjLh5=|ANaWFT4Vi*HKvPZ9IZA-$mV_}e{r`U8|9=gZ ziwp_^o*WGx4Z;upe?R`;k-1$V{` l+Y~z)awRk?PBJh9y>sUhFUJf92DX`e3>*uU*f?DM-2h23iG s3``l188{r2R>Zg)D8?{oGG1H|vm(S1$PWbbUxE40pS$|I)&Ktw0H9AD-2eap literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/DSSRunSpeed.ips b/worlds/cvcotm/data/ips/DSSRunSpeed.ips new file mode 100644 index 0000000000000000000000000000000000000000..33c29c2367981cb5939489cc296309093d03844f GIT binary patch literal 18 ZcmWG=3~~10V-;dxWny4pU~%<#0{|M>0($@e literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/DemoForceFirst.ips b/worlds/cvcotm/data/ips/DemoForceFirst.ips new file mode 100644 index 0000000000000000000000000000000000000000..26e12794d34b3ca0f0e00caa4158d60dbfadcb39 GIT binary patch literal 15 WcmWG=3~}~gWYJ(?VpMeXcLM+xg94lY literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/DropReworkMultiEdition.ips b/worlds/cvcotm/data/ips/DropReworkMultiEdition.ips new file mode 100644 index 0000000000000000000000000000000000000000..a11303195626c3f3049778697b655128879b7ac4 GIT binary patch literal 783 zcmX|9Pe>F|82{eNbv%`PNUOtga*BN?ql;34hl7P;~oL=+?_3VTteZ&tU{_kO>R_x--#@4b;5$r)I@1KG=Fzd+&(QPCL=8!yo2jr1_ymUT; z;0$FV8i@V9vPWP1*#vQI&ht2s;-a*u3Vg`1d?_8tuN=!%TL%*)QI&GgsZDZ;tCc}% zhZ?j7a5y6f!adR>b{+m8DK@BW2pcp5z$K=N3&KJqa;J~bWDYv=kSNTzkrZWM(QTno zGaS{tQ(;w`GL4rq zQ9r#d8DV`hlnphv49TlnP=!{P>9YZqt8I#_3^QFXD(-K>^n8(KE5(X$8R^FMe<4m! z&Zgwxjho#`tghP)yDcl3Iu9W`vb6RE5P)YTq2-$dc)!|d<1}ol{X%3+WGiW z5bjPWbk!{7AN#ccEZ9*~q<73LjfVB!vvI6l0SB-xj$DCbfJ$Ktl&qo$!J(-LgjuK% zYv@>9&ic=uJKbdo)tV7T8b2{k??9%}w}|3dO%uO0kW!jWdDe${$qnmA|AP`RD1e)< Lfhri+&{O9hGmg#u literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/GameClearBypass.ips b/worlds/cvcotm/data/ips/GameClearBypass.ips new file mode 100644 index 0000000000000000000000000000000000000000..5fc351b3972355dc91948a420681c28278e934d3 GIT binary patch literal 29 jcmWG=3~}~gm_LbuNluwz|0N)$$S^UDfr){^)!z*OYug5j literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/MPComboFix.ips b/worlds/cvcotm/data/ips/MPComboFix.ips new file mode 100644 index 0000000000000000000000000000000000000000..4c7dfab36e5795fecd288965458714a6b4e2658c GIT binary patch literal 15 WcmWG=3~~10^H{;a#K7R{?*;%I-~&ql literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/MapEdits.ips b/worlds/cvcotm/data/ips/MapEdits.ips new file mode 100644 index 0000000000000000000000000000000000000000..4e4c07551698ce221179b731aa2b7f6650321c4e GIT binary patch literal 32 lcmWG=3~}~|(Obj7%+0_Uqo2UQ%*enMdno`!bGZ7u0RV051{44Q literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/MultiLastKey.ips b/worlds/cvcotm/data/ips/MultiLastKey.ips new file mode 100644 index 0000000000000000000000000000000000000000..20df85d1c91fccaf6794930013064a8546d08784 GIT binary patch literal 191 zcmWG=3~}~gIGx5|X5`1<(e9=opU!c>4HGgb7|LjQF@JdctcRm4;yTG>W0^72?10=Hh0GPZ1BKHJ< oNwCR#PJq~ZMHpBa7=AJ6@a(l=VAY1OG8h=OdG^)-NmqY204o798~^|S literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/NoMPDrain.ips b/worlds/cvcotm/data/ips/NoMPDrain.ips new file mode 100644 index 0000000000000000000000000000000000000000..7481a63b556cbf2c09e957d8837ef4416695b90d GIT binary patch literal 17 YcmWG=3~}~gJ28cU#qEIG0at%F05I|ey#N3J literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/PermanentDash.ips b/worlds/cvcotm/data/ips/PermanentDash.ips new file mode 100644 index 0000000000000000000000000000000000000000..458c8c935ac9d1bfa6a969a8f70398163bf7199b GIT binary patch literal 33 ncmWG=3~}~gGw@(wWMJFq!N7FDjcsEh1LFg>jSWB{SARDEf`SMF literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/SeedDisplay20Digits.ips b/worlds/cvcotm/data/ips/SeedDisplay20Digits.ips new file mode 100644 index 0000000000000000000000000000000000000000..ffcd22972d0f6add0c5ab34306e07cf30531e4b1 GIT binary patch literal 110 zcmWG=3~}~gIHkbA!Qj#E#-Nzak*>(V5c12AQGug?&5O-bL|LGNqk++y$%x62LHoxY zW{-`E?QS|ig+VzCY#OH+ICKN_0`vn60t^F;0*nJp0!#zU0?Y#}0xScp0;~gU0&D~9 M0_+1E0$lyw0Ge1E00000 literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/ShooterStrength.ips b/worlds/cvcotm/data/ips/ShooterStrength.ips new file mode 100644 index 0000000000000000000000000000000000000000..865d201c387cf3aad887278511311844b0de5bfa GIT binary patch literal 16 XcmWG=3~~10hA^sB1{9$ literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/ips/SoftlockBlockFix.ips b/worlds/cvcotm/data/ips/SoftlockBlockFix.ips new file mode 100644 index 0000000000000000000000000000000000000000..5f4f4b902b5f5c08eb016a91aeac64ce431da840 GIT binary patch literal 15 WcmWG=3~~10)%w7|#8~g@?*;%M2?O*1 literal 0 HcmV?d00001 diff --git a/worlds/cvcotm/data/lname.py b/worlds/cvcotm/data/lname.py new file mode 100644 index 000000000000..4ef312f2fa23 --- /dev/null +++ b/worlds/cvcotm/data/lname.py @@ -0,0 +1,128 @@ +sr3 = "Sealed Room: Main shaft left fake wall" +cc1 = "Catacomb: Push crate treasure room" +cc3 = "Catacomb: Fleamen brain room - Lower" +cc3b = "Catacomb: Fleamen brain room - Upper" +cc4 = "Catacomb: Earth Demon dash room" +cc5 = "Catacomb: Tackle block treasure room" +cc8 = "Catacomb: Earth Demon bone pit - Lower" +cc8b = "Catacomb: Earth Demon bone pit - Upper" +cc9 = "Catacomb: Below right column save room" +cc10 = "Catacomb: Right column fake wall" +cc13 = "Catacomb: Right column Spirit room" +cc14 = "Catacomb: Muddy Mudman platforms room - Lower" +cc14b = "Catacomb: Muddy Mudman platforms room - Upper" +cc16 = "Catacomb: Slide space zone" +cc20 = "Catacomb: Pre-Cerberus lone Skeleton room" +cc22 = "Catacomb: Pre-Cerberus Hopper treasure room" +cc24 = "Catacomb: Behind Cerberus" +cc25 = "Catacomb: Mummies' fake wall" +as2 = "Abyss Staircase: Lower fake wall" +as3 = "Abyss Staircase: Loopback drop" +as4 = "Abyss Staircase: Roc ledge" +as9 = "Abyss Staircase: Upper fake wall" +ar4 = "Audience Room: Skeleton foyer fake wall" +ar7 = "Audience Room: Main gallery fake wall" +ar8 = "Audience Room: Below coyote jump" +ar9 = "Audience Room: Push crate gallery" +ar10 = "Audience Room: Past coyote jump" +ar11 = "Audience Room: Tackle block gallery" +ar14 = "Audience Room: Wicked roc chamber - Lower" +ar14b = "Audience Room: Wicked roc chamber - Upper" +ar16 = "Audience Room: Upper Devil Tower hallway" +ar17 = "Audience Room: Right exterior - Lower" +ar17b = "Audience Room: Right exterior - Upper" +ar18 = "Audience Room: Right exterior fake wall" +ar19 = "Audience Room: 100 meter skelly dash hallway" +ar21 = "Audience Room: Lower Devil Tower hallway fake wall" +ar25 = "Audience Room: Behind Necromancer" +ar26 = "Audience Room: Below Machine Tower roc ledge" +ar27 = "Audience Room: Below Machine Tower push crate room" +ar30 = "Audience Room: Roc horse jaguar armory - Left" +ar30b = "Audience Room: Roc horse jaguar armory - Right" +ow0 = "Outer Wall: Left roc ledge" +ow1 = "Outer Wall: Right-brained ledge" +ow2 = "Outer Wall: Fake Nightmare floor" +th1 = "Triumph Hallway: Skeleton slopes fake wall" +th3 = "Triumph Hallway: Entrance Flame Armor climb" +mt0 = "Machine Tower: Foxy platforms ledge" +mt2 = "Machine Tower: Knight fox meeting room" +mt3 = "Machine Tower: Boneheaded argument wall kicks room" +mt4 = "Machine Tower: Foxy fake wall" +mt6 = "Machine Tower: Skelly-rang wall kicks room" +mt8 = "Machine Tower: Fake Lilim wall" +mt10 = "Machine Tower: Thunderous zone fake wall" +mt11 = "Machine Tower: Thunderous zone lone Stone Armor room" +mt13 = "Machine Tower: Top lone Stone Armor room" +mt14 = "Machine Tower: Stone fox hallway" +mt17 = "Machine Tower: Pre-Iron Golem fake wall" +mt19 = "Machine Tower: Behind Iron Golem" +ec5 = "Eternal Corridor: Midway fake wall" +ec7 = "Eternal Corridor: Skelly-rang wall kicks room" +ec9 = "Eternal Corridor: Skelly-rang fake wall" +ct1 = "Chapel Tower: Flame Armor climb room" +ct4 = "Chapel Tower: Lower chapel push crate room" +ct5 = "Chapel Tower: Lower chapel fake wall" +ct6 = "Chapel Tower: Beastly wall kicks room - Brain side" +ct6b = "Chapel Tower: Beastly wall kicks room - Brawn side" +ct8 = "Chapel Tower: Middle chapel fake wall" +ct10 = "Chapel Tower: Middle chapel push crate room" +ct13 = "Chapel Tower: Sharp mind climb room" +ct15 = "Chapel Tower: Upper chapel fake wall" +ct16 = "Chapel Tower: Upper chapel Marionette wall kicks" +ct18 = "Chapel Tower: Upper belfry fake wall" +ct21 = "Chapel Tower: Iron maiden switch" +ct22 = "Chapel Tower: Behind Adramelech iron maiden" +ct26 = "Chapel Tower: Outside Battle Arena - Upper" +ct26b = "Chapel Tower: Outside Battle Arena - Lower" +ug0 = "Underground Gallery: Conveyor platform ride" +ug1 = "Underground Gallery: Conveyor upper push crate room" +ug2 = "Underground Gallery: Conveyor lower push crate room" +ug3 = "Underground Gallery: Harpy climb room - Lower" +ug3b = "Underground Gallery: Harpy climb room - Upper" +ug8 = "Underground Gallery: Harpy mantis tackle hallway" +ug10 = "Underground Gallery: Handy bee hallway" +ug13 = "Underground Gallery: Myconid fake wall" +ug15 = "Underground Gallery: Crumble bridge fake wall" +ug20 = "Underground Gallery: Behind Dragon Zombies" +uw1 = "Underground Warehouse: Entrance push crate room" +uw6 = "Underground Warehouse: Forever pushing room" +uw8 = "Underground Warehouse: Crate-nudge fox room" +uw9 = "Underground Warehouse: Crate-nudge fake wall" +uw10 = "Underground Warehouse: Succubus shaft roc ledge" +uw11 = "Underground Warehouse: Fake Lilith wall" +uw14 = "Underground Warehouse: Optional puzzle ceiling fake wall" +uw16 = "Underground Warehouse: Holy fox hideout - Left" +uw16b = "Underground Warehouse: Holy fox hideout - Right roc ledge" +uw19 = "Underground Warehouse: Forest Armor's domain fake wall" +uw23 = "Underground Warehouse: Behind Death" +uw24 = "Underground Warehouse: Behind Death fake wall" +uw25 = "Underground Warehouse: Dryad expulsion chamber" +uy1 = "Underground Waterway: Entrance fake wall" +uy3 = "Underground Waterway: Before illusory wall" +uy3b = "Underground Waterway: Beyond illusory wall" +uy4 = "Underground Waterway: Ice Armor's domain fake wall" +uy5 = "Underground Waterway: Brain freeze room" +uy7 = "Underground Waterway: Middle lone Ice Armor room" +uy8 = "Underground Waterway: Roc fake ceiling" +uy9 = "Underground Waterway: Wicked Fishhead moat - Bottom" +uy9b = "Underground Waterway: Wicked Fishhead moat - Top" +uy12 = "Underground Waterway: Lizard-man turf - Bottom" +uy12b = "Underground Waterway: Lizard-man turf - Top" +uy13 = "Underground Waterway: Roc exit shaft" +uy17 = "Underground Waterway: Behind Camilla" +uy18 = "Underground Waterway: Roc exit shaft fake wall" +ot1 = "Observation Tower: Wind Armor rampart" +ot2 = "Observation Tower: Legion plaza fake wall" +ot3 = "Observation Tower: Legion plaza Minotaur hallway" +ot5 = "Observation Tower: Siren balcony fake wall" +ot8 = "Observation Tower: Evil Pillar pit fake wall" +ot9 = "Observation Tower: Alraune garden" +ot12 = "Observation Tower: Dark Armor's domain fake wall" +ot13 = "Observation Tower: Catoblepeas hallway" +ot16 = "Observation Tower: Near warp room fake wall" +ot20 = "Observation Tower: Behind Hugh" +cr1 = "Ceremonial Room: Fake floor" +ba24 = "Battle Arena: End reward" + +arena_victory = "Arena Victory" +dracula = "Dracula" diff --git a/worlds/cvcotm/data/patches.py b/worlds/cvcotm/data/patches.py new file mode 100644 index 000000000000..c2a9aa791f91 --- /dev/null +++ b/worlds/cvcotm/data/patches.py @@ -0,0 +1,431 @@ +remote_textbox_shower = [ + # Pops up the textbox(s) of whatever textbox IDs is written at 0x02025300 and 0x02025302 and increments the current + # received item index at 0x020253D0 if a number to increment it by is written at 0x02025304. Also plays the sound + # effect of the ID written at 0x02025306, if one is written there. This will NOT give any items on its own; the item + # has to be written by the client into the inventory alongside writing the above-mentioned things. + + # Make sure we didn't hit the lucky one frame before room transitioning wherein Nathan is on top of the room + # transition tile. + 0x0C, 0x88, # ldrh r4, [r1] + 0x80, 0x20, # movs r0, #0x80 + 0x20, 0x40, # ands r0, r4 + 0x00, 0x28, # cmp r0, #0 + 0x2F, 0xD1, # bne 0x87FFF8A + 0x11, 0xB4, # push r0, r4 + # Check the cutscene value to make sure we are not in a cutscene; forcing a textbox while there's already another + # textbox on-screen messes things up. + 0x1E, 0x4A, # ldr r2, =0x2026000 + 0x13, 0x78, # ldrb r3, [r2] + 0x00, 0x2B, # cmp r0, #0 + 0x29, 0xD1, # bne 0x87FFF88 + # Check our "delay" timer buffer for a non-zero. If it is, decrement it by one and skip straight to the return part + # of this code, as we may have received an item on a frame wherein it's "unsafe" to pop the item textbox. + 0x16, 0x4A, # ldr r2, =0x2025300 + 0x13, 0x89, # ldrh r3, [r2, #8] + 0x00, 0x2B, # cmp r0, #0 + 0x02, 0xD0, # beq 0x87FFF42 + 0x01, 0x3B, # subs r3, #1 + 0x13, 0x81, # strh r3, [r2, #8] + 0x22, 0xE0, # beq 0x87FFF88 + # Check our first custom "textbox ID" buffers for a non-zero number. + 0x10, 0x88, # ldrh r0, [r2] + 0x00, 0x28, # cmp r0, #0 + 0x12, 0xD0, # beq 0x87FFF6E + # Increase the "received item index" by the specified number in our "item index amount to increase" buffer. + 0x93, 0x88, # ldrh r3, [r2, #4] + 0xD0, 0x32, # adds r2, #0xD0 + 0x11, 0x88, # ldrh r1, [r2] + 0xC9, 0x18, # adds r1, r1, r3 + 0x11, 0x80, # strh r1, [r2] + # Check our second custom "textbox ID" buffers for a non-zero number. + 0xD0, 0x3A, # subs r2, #0xD0 + 0x51, 0x88, # ldrh r1, [r2, #2] + 0x00, 0x29, # cmp r1, #0 + 0x01, 0xD0, # beq 0x87FFF5E + # If we have a second textbox ID, run the "display two textboxes" function. + # Otherwise, run the "display one textbox" function. + 0x0E, 0x4A, # ldr r2, =0x805F104 + 0x00, 0xE0, # b 0x87FFF60 + 0x0E, 0x4A, # ldr r2, =0x805F0C8 + 0x7B, 0x46, # mov r3, r15 + 0x05, 0x33, # adds r3, #5 + 0x9E, 0x46, # mov r14, r3 + 0x97, 0x46, # mov r15, r2 + 0x09, 0x48, # ldr r0, =0x2025300 + 0x02, 0x21, # movs r1, #2 + 0x01, 0x81, # strh r1, [r0, #8] + # Check our "sound effect ID" buffer and run the "play sound" function if it's a non-zero number. + 0x08, 0x48, # ldr r0, =0x2025300 + 0xC0, 0x88, # ldrh r0, [r0, #6] + 0x00, 0x28, # cmp r0, #0 + 0x04, 0xD0, # beq 0x87FFF7E + 0x0B, 0x4A, # ldr r2, =0x8005E80 + 0x7B, 0x46, # mov r3, r15 + 0x05, 0x33, # adds r3, #5 + 0x9E, 0x46, # mov r14, r3 + 0x97, 0x46, # mov r15, r2 + # Clear all our buffers and return to the "check for Nathan being in a room transition" function we've hooked into. + 0x03, 0x48, # ldr r0, =0x2025300 + 0x00, 0x21, # movs r1, #0 + 0x01, 0x60, # str r1, [r0] + 0x41, 0x60, # str r1, [r0, #4] + 0x11, 0xBC, # pop r0, r4 + 0x04, 0x4A, # ldr r2, =0x8007D68 + 0x00, 0x28, # cmp r0, #0 + 0x97, 0x46, # mov r15, r2 + # LDR number pool + 0x00, 0x53, 0x02, 0x02, + 0x04, 0xF1, 0x05, 0x08, + 0xC8, 0xF0, 0x05, 0x08, + 0x68, 0x7D, 0x00, 0x08, + 0x90, 0x1E, 0x02, 0x02, + 0x80, 0x5E, 0x00, 0x08, + 0x00, 0x60, 0x02, 0x02 +] + +transition_textbox_delayer = [ + # Sets the remote item textbox delay timer whenever the player screen transitions to ensure the item textbox won't + # pop during said transition. + 0x40, 0x78, # ldrb r0, [r0, #1] + 0x28, 0x70, # strb r0, [r5] + 0xF8, 0x6D, # ldr r0, [r7, #0x5C] + 0x20, 0x18, # adds r0, r4, r0 + 0x02, 0x4A, # ldr r2, =0x2025300 + 0x10, 0x23, # movs r3, #0x10 + 0x13, 0x80, # strh r3, [r2] + 0x02, 0x4A, # ldr r2, =0x806CE1C + 0x97, 0x46, # mov r15, r2 + 0x00, 0x00, + # LDR number pool + 0x08, 0x53, 0x02, 0x02, + 0x1C, 0xCE, 0x06, 0x08, +] + +magic_item_sfx_customizer = [ + # Enables a different sound to be played depending on which Magic Item was picked up. The array starting at 086797C0 + # contains each 2-byte sound ID for each Magic Item. Putting 0000 for a sound will cause no sound to play; this is + # currently used for the dummy AP Items as their sound is played by the "sent" textbox instead. + 0x70, 0x68, # ldr r0, [r6, #4] + 0x80, 0x79, # ldrb r0, [r0, #6] + 0x40, 0x00, # lsl r0, r0, 1 + 0x07, 0x49, # ldr r1, =0x86797C0 + 0x08, 0x5A, # ldrh r0, [r1, r0] + 0x00, 0x28, # cmp r0, 0 + 0x04, 0xD0, # beq 0x8679818 + 0x03, 0x4A, # ldr r2, =0x8005E80 + 0x7B, 0x46, # mov r3, r15 + 0x05, 0x33, # adds r3, #5 + 0x9E, 0x46, # mov r14, r3 + 0x97, 0x46, # mov r15, r2 + 0x01, 0x48, # ldr r0, =0x8095BEC + 0x87, 0x46, # mov r15, r0 + # LDR number pool + 0x80, 0x5E, 0x00, 0x08, + 0xEC, 0x5B, 0x09, 0x08, + 0xC0, 0x97, 0x67, 0x08, +] + +start_inventory_giver = [ + # This replaces AutoDashBoots.ips from standalone CotMR by allowing the player to start with any set of items, not + # just the Dash Boots. If playing Magician Mode, they will be given all cards that were not put into the starting + # inventory right after this code runs. + + # Magic Items + 0x13, 0x48, # ldr r0, =0x202572F + 0x14, 0x49, # ldr r1, =0x8680080 + 0x00, 0x22, # mov r2, #0 + 0x8B, 0x5C, # ldrb r3, [r1, r2] + 0x83, 0x54, # strb r3, [r0, r2] + 0x01, 0x32, # adds r2, #1 + 0x08, 0x2A, # cmp r2, #8 + 0xFA, 0xDB, # blt 0x8680006 + # Max Ups + 0x11, 0x48, # ldr r0, =0x202572C + 0x12, 0x49, # ldr r1, =0x8680090 + 0x00, 0x22, # mov r2, #0 + 0x8B, 0x5C, # ldrb r3, [r1, r2] + 0x83, 0x54, # strb r3, [r0, r2] + 0x01, 0x32, # adds r2, #1 + 0x03, 0x2A, # cmp r2, #3 + 0xFA, 0xDB, # blt 0x8680016 + # Cards + 0x0F, 0x48, # ldr r0, =0x2025674 + 0x10, 0x49, # ldr r1, =0x86800A0 + 0x00, 0x22, # mov r2, #0 + 0x8B, 0x5C, # ldrb r3, [r1, r2] + 0x83, 0x54, # strb r3, [r0, r2] + 0x01, 0x32, # adds r2, #1 + 0x14, 0x2A, # cmp r2, #0x14 + 0xFA, 0xDB, # blt 0x8680026 + # Inventory Items (not currently supported) + 0x0D, 0x48, # ldr r0, =0x20256ED + 0x0E, 0x49, # ldr r1, =0x86800C0 + 0x00, 0x22, # mov r2, #0 + 0x8B, 0x5C, # ldrb r3, [r1, r2] + 0x83, 0x54, # strb r3, [r0, r2] + 0x01, 0x32, # adds r2, #1 + 0x36, 0x2A, # cmp r2, #36 + 0xFA, 0xDB, # blt 0x8680036 + # Return to the function that checks for Magician Mode. + 0xBA, 0x21, # movs r1, #0xBA + 0x89, 0x00, # lsls r1, r1, #2 + 0x70, 0x18, # adds r0, r6, r1 + 0x04, 0x70, # strb r4, [r0] + 0x00, 0x4A, # ldr r2, =0x8007F78 + 0x97, 0x46, # mov r15, r2 + # LDR number pool + 0x78, 0x7F, 0x00, 0x08, + 0x2F, 0x57, 0x02, 0x02, + 0x80, 0x00, 0x68, 0x08, + 0x2C, 0x57, 0x02, 0x02, + 0x90, 0x00, 0x68, 0x08, + 0x74, 0x56, 0x02, 0x02, + 0xA0, 0x00, 0x68, 0x08, + 0xED, 0x56, 0x02, 0x02, + 0xC0, 0x00, 0x68, 0x08, +] + +max_max_up_checker = [ + # Whenever the player picks up a Max Up, this will check to see if they currently have 255 of that particular Max Up + # and only increment the number further if they don't. This is necessary for extreme Item Link seeds, as going over + # 255 of any Max Up will reset the counter to 0. + 0x08, 0x78, # ldrb r0, [r1] + 0xFF, 0x28, # cmp r0, 0xFF + 0x17, 0xD1, # bne 0x86A0036 + # If it's an HP Max, refill our HP. + 0xFF, 0x23, # mov r3, #0xFF + 0x0B, 0x40, # and r3, r1 + 0x2D, 0x2B, # cmp r3, 0x2D + 0x03, 0xD1, # bne 0x86A0016 + 0x0D, 0x4A, # ldr r2, =0x202562E + 0x93, 0x88, # ldrh r3, [r2, #4] + 0x13, 0x80, # strh r3, [r2] + 0x11, 0xE0, # b 0x86A003A + # If it's an MP Max, refill our MP. + 0x2E, 0x2B, # cmp r3, 0x2E + 0x03, 0xD1, # bne 0x86A0022 + 0x0B, 0x4A, # ldr r2, =0x2025636 + 0x93, 0x88, # ldrh r3, [r2, #4] + 0x13, 0x80, # strh r3, [r2] + 0x0B, 0xE0, # b 0x86A003A + # Else, meaning it's a Hearts Max, add +6 Hearts. If adding +6 Hearts would put us over our current max, set our + # current amount to said current max instead. + 0x0A, 0x4A, # ldr r2, =0x202563C + 0x13, 0x88, # ldrh r3, [r2] + 0x06, 0x33, # add r3, #6 + 0x51, 0x88, # ldrh r1, [r2, #2] + 0x8B, 0x42, # cmp r3, r1 + 0x00, 0xDB, # blt 0x86A0030 + 0x0B, 0x1C, # add r3, r1, #0 + 0x13, 0x80, # strh r3, [r2] + 0x02, 0xE0, # b 0x86A003A + 0x00, 0x00, + # Increment the Max Up count like normal. Should only get here if the Max Up count was determined to be less than + # 255, branching past if not the case. + 0x01, 0x30, # adds r0, #1 + 0x08, 0x70, # strb r0, [r1] + # Return to the function that gives Max Ups normally. + 0x05, 0x48, # ldr r0, =0x1B3 + 0x00, 0x4A, # ldr r2, =0x805E170 + 0x97, 0x46, # mov r15, r2 + # LDR number pool + 0x78, 0xE1, 0x05, 0x08, + 0x2E, 0x56, 0x02, 0x02, + 0x36, 0x56, 0x02, 0x02, + 0x3C, 0x56, 0x02, 0x02, + 0xB3, 0x01, 0x00, 0x00, +] + +maiden_detonator = [ + # Detonates the iron maidens upon picking up the Maiden Detonator item by setting the "broke iron maidens" flag. + 0x2A, 0x20, # mov r0, #0x2A + 0x03, 0x4A, # ldr r2, =0x8007E24 + 0x7B, 0x46, # mov r3, r15 + 0x05, 0x33, # adds r3, #5 + 0x9E, 0x46, # mov r14, r3 + 0x97, 0x46, # mov r15, r2 + 0x01, 0x4A, # ldr r2, =0x8095BE4 + 0x97, 0x46, # mov r15, r2 + # LDR number pool + 0x24, 0x7E, 0x00, 0x08, + 0xE4, 0x5B, 0x09, 0x08, +] + +doubleless_roc_midairs_preventer = [ + # Prevents being able to Roc jump in midair without the Double. Will pass if the jump counter is 0 or if Double is + # in the inventory. + # Check for Roc Wing in the inventory normally. + 0x58, 0x18, # add r0, r3, r1 + 0x00, 0x78, # ldrb r0, [r0] + 0x00, 0x28, # cmp r0, 0 + 0x11, 0xD0, # beq 0x8679A2C + # Check the "jumps since last on the ground" counter. Is it 0? + # If so, then we are on the ground and can advance to the Kick Boots question. If not, advance to the Double check. + 0x0B, 0x48, # ldr r0, =0x2000080 + 0x01, 0x78, # ldrb r1, [r0] + 0x00, 0x29, # cmp r1, 0 + 0x03, 0xD0, # beq 0x8679A18 + # Check for Double in the inventory. Is it there? + # If not, then it's not time to Roc! Otherwise, advance to the next check. + 0x0A, 0x4A, # ldr r2, =0x202572F + 0x52, 0x78, # ldrb r2, [r2, 1] + 0x00, 0x2A, # cmp r2, 0 + 0x09, 0xD0, # beq 0x8679A2C + # Check for Kick Boots in the inventory. Are they there? + # If they are, then we can definitely Roc! If they aren't, however, then on to the next question... + 0x08, 0x4A, # ldr r2, =0x202572F + 0xD2, 0x78, # ldrb r2, [r2, 3] + 0x00, 0x2A, # cmp r2, 0 + 0x03, 0xD1, # bne 0x8679A28 + # Is our "jumps since last on the ground" counter 2? + # If it is, then we already Double jumped and should not Roc jump as well. + # Should always pass if we came here from the "on the ground" 0 check. + 0x02, 0x29, # cmp r1, 2 + 0x03, 0xD0, # beq 0x8679A2C + # If we did not Double jump yet, then set the above-mentioned counter to 2, and now we can finally Roc on! + 0x02, 0x21, # mov r1, 2 + 0x01, 0x70, # strb r1, [r0] + # Go to the "Roc jump" code. + 0x01, 0x4A, # ldr r2, =0x806B8A8 + 0x97, 0x46, # mov r15, r2 + # Go to the "don't Roc jump" code. + 0x01, 0x4A, # ldr r2, =0x806B93C + 0x97, 0x46, # mov r15, r2 + # LDR number pool + 0xA8, 0xB8, 0x06, 0x08, + 0x3C, 0xB9, 0x06, 0x08, + 0x80, 0x00, 0x00, 0x02, + 0x2F, 0x57, 0x02, 0x02, +] + +kickless_roc_height_shortener = [ + # Shortens the amount of time spent rising with Roc Wing if the player doesn't have Kick Boots. + 0x06, 0x49, # ldr r1, =0x202572F + 0xC9, 0x78, # ldrb r1, [r1, 3] + 0x00, 0x29, # cmp r1, 0 + 0x00, 0xD1, # bne 0x8679A6A + 0x10, 0x20, # mov r0, 0x12 + 0xA8, 0x65, # str r0, [r5, 0x58] + # Go back to the Roc jump code. + 0x00, 0x24, # mov r4, 0 + 0x2C, 0x64, # str r4, [r5, 0x40] + 0x03, 0x49, # ldr r1, =0x80E03A0 + 0x01, 0x4A, # ldr r2, =0x806B8BC + 0x97, 0x46, # mov r15, r2 + 0x00, 0x00, + # LDR number pool + 0xBC, 0xB8, 0x06, 0x08, + 0x2F, 0x57, 0x02, 0x02, + 0xA0, 0x03, 0x0E, 0x08 +] + +missing_char_data = { + # The pixel data for all ASCII characters missing from the game's dialogue textbox font. + + # Each character consists of 8 bytes, with each byte representing one row of pixels in the character. The bytes are + # arranged from top to bottom row going from left to right. + + # Each bit within each byte represents the following pixels within that row: + # 8- = -+------ + # 4- = +------- + # 2- = ---+---- + # 1- = --+----- + # -8 = -----+-- + # -4 = ----+--- + # -2 = -------+ + # -1 = ------+- + 0x396C54: [0x00, 0x9C, 0x9C, 0x18, 0x84, 0x00, 0x00, 0x00], # " + 0x396C5C: [0x00, 0x18, 0xBD, 0x18, 0x18, 0x18, 0xBD, 0x18], # # + 0x396C64: [0x00, 0x0C, 0x2D, 0x0C, 0x21, 0x00, 0x00, 0x00], # * + 0x396C6C: [0x00, 0x20, 0x3C, 0xA0, 0x34, 0x28, 0xB4, 0x20], # $ + 0x396C74: [0x00, 0x34, 0x88, 0x80, 0xB4, 0x88, 0x88, 0x34], # 6 + 0x396C7C: [0x00, 0xBC, 0x88, 0x04, 0x04, 0x20, 0x20, 0x20], # 7 + 0x396CBC: [0x00, 0x34, 0x88, 0x88, 0x3C, 0x08, 0x88, 0x34], # 9 + 0x396CC4: [0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0xC0], # : + 0x396CCC: [0x00, 0xC0, 0xC0, 0x00, 0xC0, 0xC0, 0x80, 0x40], # ; + 0x396D0C: [0x00, 0x00, 0x09, 0x24, 0x90, 0x24, 0x09, 0x00], # < + 0x396D14: [0x00, 0x00, 0xFD, 0x00, 0x00, 0x00, 0xFD, 0x00], # = + 0x396D1C: [0x00, 0x00, 0xC0, 0x30, 0x0C, 0x30, 0xC0, 0x00], # > + 0x396D54: [0x00, 0x34, 0x88, 0xAC, 0xA8, 0xAC, 0x80, 0x34], # @ + 0x396D5C: [0x00, 0x34, 0x88, 0x88, 0xA8, 0x8C, 0x88, 0x35], # Q + 0x396D64: [0x00, 0x40, 0x80, 0x10, 0x20, 0x04, 0x08, 0x01], # \ + 0x396D6C: [0x00, 0x20, 0x14, 0x88, 0x00, 0x00, 0x00, 0x00], # ^ + 0x396D9C: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD], # _ + 0x396DA4: [0x00, 0x90, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00], # ` + 0x396DAC: [0x00, 0x08, 0x04, 0x04, 0x20, 0x04, 0x04, 0x08], # { + 0x396DB4: [0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20], # | + 0x396DBC: [0x00, 0x80, 0x10, 0x10, 0x20, 0x10, 0x10, 0x80], # } + 0x396DF4: [0x00, 0x00, 0x00, 0x90, 0x61, 0x0C, 0x00, 0x00], # ~ +} + +extra_item_sprites = [ + # The VRAM data for all the extra item sprites, including the Archipelago Items. + + # NOTE: The Archipelago logo is © 2022 by Krista Corkos and Christopher Wilson + # and licensed under Attribution-NonCommercial 4.0 International. + # See LICENSES.txt at the root of this apworld's directory for more licensing information. + + # Maiden Detonator + 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x10, 0xCC, 0x00, 0x00, 0xC1, 0xBB, 0x00, 0x10, 0x1C, 0xB8, + 0x00, 0x10, 0x1C, 0xB1, 0x00, 0x10, 0xBC, 0xBB, 0x00, 0x00, 0x11, 0x11, 0x00, 0x10, 0xCC, 0xBB, + 0x11, 0x00, 0x00, 0x00, 0xCC, 0x01, 0x00, 0x00, 0xBB, 0x1C, 0x00, 0x00, 0x8B, 0xC1, 0x01, 0x00, + 0x1B, 0xC1, 0x01, 0x00, 0xBB, 0xCB, 0x01, 0x00, 0x11, 0x11, 0x00, 0x00, 0xBB, 0xCC, 0x01, 0x00, + 0x00, 0x10, 0x11, 0x11, 0x00, 0xC1, 0xBC, 0x1B, 0x00, 0x10, 0x11, 0x11, 0x00, 0xC1, 0xBC, 0x1B, + 0x00, 0x10, 0x11, 0x11, 0x00, 0xC1, 0xBC, 0x1B, 0x00, 0xC1, 0xBC, 0x1B, 0x00, 0x10, 0x11, 0x01, + 0x11, 0x11, 0x01, 0x00, 0xB1, 0xCB, 0x1C, 0x00, 0x11, 0x11, 0x01, 0x00, 0xB1, 0xCB, 0x1C, 0x00, + 0x11, 0x11, 0x01, 0x00, 0xB1, 0xCB, 0x1C, 0x00, 0xB1, 0xCB, 0x1C, 0x00, 0x10, 0x11, 0x01, 0x00, + # Archipelago Filler + 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x20, 0x88, 0x00, 0x22, 0x82, 0x88, 0x20, 0x66, 0x26, 0x88, + 0x62, 0x66, 0x62, 0x82, 0x62, 0x66, 0x66, 0x82, 0x62, 0x22, 0x62, 0x22, 0x20, 0xAA, 0x2A, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x82, 0x22, 0x02, 0x00, 0x28, 0xCC, 0x2C, 0x00, + 0xC2, 0xCC, 0xC2, 0x02, 0xC2, 0xCC, 0xCC, 0x02, 0xC2, 0x22, 0xC2, 0x02, 0x20, 0xFF, 0x2F, 0x00, + 0xA2, 0xAA, 0xA2, 0x02, 0xA2, 0xAA, 0xAA, 0x22, 0xA2, 0xAA, 0x2A, 0x77, 0x20, 0xAA, 0x72, 0x77, + 0x00, 0x22, 0x72, 0x77, 0x00, 0x00, 0x72, 0x77, 0x00, 0x00, 0x20, 0x77, 0x00, 0x00, 0x00, 0x22, + 0xF2, 0xFF, 0xF2, 0x02, 0xF2, 0xFF, 0xFF, 0x02, 0x27, 0xFF, 0xFF, 0x02, 0x72, 0xF2, 0x2F, 0x00, + 0x77, 0x22, 0x02, 0x00, 0x77, 0x02, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + # Archipelago Useful + 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x20, 0x88, 0x00, 0x22, 0x82, 0x88, 0x20, 0x66, 0x26, 0x88, + 0x62, 0x66, 0x62, 0x82, 0x62, 0x66, 0x66, 0x82, 0x62, 0x22, 0x62, 0x22, 0x20, 0xAA, 0x2A, 0x00, + 0x02, 0xAA, 0x0A, 0x00, 0x28, 0x9A, 0x0A, 0x00, 0xAA, 0x9A, 0xAA, 0x0A, 0x9A, 0x99, 0x99, 0x0A, + 0xAA, 0x9A, 0xAA, 0x0A, 0xC2, 0x9A, 0xCA, 0x02, 0xC2, 0xAA, 0xCA, 0x02, 0x20, 0xFF, 0x2F, 0x00, + 0xA2, 0xAA, 0xA2, 0x02, 0xA2, 0xAA, 0xAA, 0x22, 0xA2, 0xAA, 0x2A, 0x77, 0x20, 0xAA, 0x72, 0x77, + 0x00, 0x22, 0x72, 0x77, 0x00, 0x00, 0x72, 0x77, 0x00, 0x00, 0x20, 0x77, 0x00, 0x00, 0x00, 0x22, + 0xF2, 0xFF, 0xF2, 0x02, 0xF2, 0xFF, 0xFF, 0x02, 0x27, 0xFF, 0xFF, 0x02, 0x72, 0xF2, 0x2F, 0x00, + 0x77, 0x22, 0x02, 0x00, 0x77, 0x02, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + # Archipelago Progression + 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x20, 0x88, 0x00, 0x22, 0x82, 0x88, 0x20, 0x66, 0x26, 0x88, + 0x62, 0x66, 0x62, 0x82, 0x62, 0x66, 0x66, 0x82, 0x62, 0x22, 0x62, 0x22, 0x20, 0xAA, 0x2A, 0x00, + 0x02, 0x10, 0x00, 0x00, 0x28, 0x71, 0x01, 0x00, 0x12, 0x77, 0x17, 0x00, 0x71, 0x77, 0x77, 0x01, + 0x11, 0x77, 0x17, 0x01, 0x12, 0x77, 0x17, 0x02, 0x12, 0x11, 0x11, 0x02, 0x20, 0xFF, 0x2F, 0x00, + 0xA2, 0xAA, 0xA2, 0x02, 0xA2, 0xAA, 0xAA, 0x22, 0xA2, 0xAA, 0x2A, 0x77, 0x20, 0xAA, 0x72, 0x77, + 0x00, 0x22, 0x72, 0x77, 0x00, 0x00, 0x72, 0x77, 0x00, 0x00, 0x20, 0x77, 0x00, 0x00, 0x00, 0x22, + 0xF2, 0xFF, 0xF2, 0x02, 0xF2, 0xFF, 0xFF, 0x02, 0x27, 0xFF, 0xFF, 0x02, 0x72, 0xF2, 0x2F, 0x00, + 0x77, 0x22, 0x02, 0x00, 0x77, 0x02, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + # Archipelago Trap + 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x20, 0x88, 0x00, 0x22, 0x82, 0x82, 0x20, 0x66, 0x26, 0x88, + 0x62, 0x62, 0x66, 0x82, 0x62, 0x66, 0x66, 0x82, 0x62, 0x22, 0x62, 0x22, 0x20, 0xAA, 0x2A, 0x00, + 0x02, 0x10, 0x00, 0x00, 0x28, 0x71, 0x01, 0x00, 0x18, 0x77, 0x17, 0x00, 0x71, 0x77, 0x77, 0x01, + 0x11, 0x77, 0x17, 0x01, 0x12, 0x77, 0x17, 0x02, 0x12, 0x11, 0x11, 0x02, 0x20, 0xFF, 0x2F, 0x00, + 0xA2, 0xA2, 0xAA, 0x02, 0xA2, 0xAA, 0xAA, 0x22, 0xA2, 0xAA, 0x2A, 0x77, 0x20, 0xAA, 0x72, 0x72, + 0x00, 0x22, 0x72, 0x77, 0x00, 0x00, 0x72, 0x77, 0x00, 0x00, 0x20, 0x77, 0x00, 0x00, 0x00, 0x22, + 0xF2, 0xF2, 0xFF, 0x02, 0xF2, 0xFF, 0xFF, 0x02, 0x27, 0xFF, 0xFF, 0x02, 0x77, 0xF2, 0x2F, 0x00, + 0x77, 0x22, 0x02, 0x00, 0x77, 0x02, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + # Archipelago Progression + Useful + 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x20, 0x88, 0x00, 0x22, 0x82, 0x88, 0x20, 0x66, 0x26, 0x88, + 0x62, 0x66, 0x62, 0x82, 0x62, 0x66, 0x66, 0x82, 0x62, 0x22, 0x62, 0x22, 0x20, 0xAA, 0x2A, 0x00, + 0x02, 0x10, 0x00, 0x00, 0x28, 0x71, 0x01, 0x00, 0x12, 0x77, 0x17, 0x00, 0x71, 0x77, 0x77, 0x01, + 0x11, 0x77, 0x17, 0x01, 0x12, 0x77, 0x17, 0x02, 0x12, 0x11, 0x11, 0x02, 0x20, 0xFF, 0x2F, 0x00, + 0xA2, 0xAA, 0xA2, 0x02, 0xA2, 0xAA, 0xAA, 0x22, 0xA2, 0xAA, 0x2A, 0x77, 0x20, 0xAA, 0x72, 0x77, + 0x00, 0x22, 0x72, 0x77, 0x00, 0x00, 0x72, 0x77, 0x00, 0x00, 0x20, 0x77, 0x00, 0x00, 0x00, 0x22, + 0xF2, 0xFF, 0xF2, 0x02, 0xF2, 0xAA, 0xFA, 0x02, 0x27, 0x9A, 0xFA, 0x02, 0xAA, 0x9A, 0xAA, 0x0A, + 0x9A, 0x99, 0x99, 0x0A, 0xAA, 0x9A, 0xAA, 0x0A, 0x27, 0x9A, 0x0A, 0x00, 0x02, 0xAA, 0x0A, 0x00, + # Hourglass (Specifically used to represent Max Sand from Timespinner) + 0x00, 0x00, 0xFF, 0xFF, 0x00, 0xF0, 0xEE, 0xCC, 0x00, 0xF0, 0x43, 0x42, 0x00, 0xF0, 0x12, 0x11, + 0x00, 0x00, 0x1F, 0x11, 0x00, 0x00, 0x2F, 0x88, 0x00, 0x00, 0xF0, 0x82, 0x00, 0x00, 0x00, 0x1F, + 0xFF, 0xFF, 0x00, 0x00, 0xCC, 0xEE, 0x0F, 0x00, 0x42, 0x34, 0x0F, 0x00, 0x11, 0x21, 0x0F, 0x00, + 0x11, 0xF1, 0x00, 0x00, 0x98, 0xF2, 0x00, 0x00, 0x29, 0x0F, 0x00, 0x00, 0xF9, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0xF0, 0x81, 0x00, 0x00, 0x2F, 0x81, 0x00, 0x00, 0x1F, 0x88, + 0x00, 0xF0, 0x12, 0xA9, 0x00, 0xF0, 0x43, 0x24, 0x00, 0xF0, 0xEE, 0xCC, 0x00, 0x00, 0xFF, 0xFF, + 0xF9, 0x00, 0x00, 0x00, 0x19, 0x0F, 0x00, 0x00, 0x99, 0xF2, 0x00, 0x00, 0xA9, 0xF1, 0x00, 0x00, + 0xAA, 0x21, 0x0F, 0x00, 0x42, 0x34, 0x0F, 0x00, 0xCC, 0xEE, 0x0F, 0x00, 0xFF, 0xFF, 0x00, 0x00, +] diff --git a/worlds/cvcotm/docs/en_Castlevania - Circle of the Moon.md b/worlds/cvcotm/docs/en_Castlevania - Circle of the Moon.md new file mode 100644 index 000000000000..e81b79bf2048 --- /dev/null +++ b/worlds/cvcotm/docs/en_Castlevania - Circle of the Moon.md @@ -0,0 +1,169 @@ +# Castlevania: Circle of the Moon + +## Quick Links +- [Setup](/tutorial/Castlevania%20-%20Circle%20of%20the%20Moon/setup/en) +- [Options Page](/games/Castlevania%20-%20Circle%20of%20the%20Moon/player-options) +- [PopTracker Pack](https://github.com/sassyvania/Circle-of-the-Moon-Rando-AP-Map-Tracker-/releases/latest) +- [Repo for the original, standalone CotMR](https://github.com/calm-palm/cotm-randomizer) +- [Web version of the above randomizer](https://rando.circleofthemoon.com/) +- [A more in-depth guide to CotMR's nuances](https://docs.google.com/document/d/1uot4BD9XW7A--A8ecgoY8mLK_vSoQRpY5XCkzgas87c/view?usp=sharing) + +This Game Page is focused more specifically on the Archipelago functionality. If you have a more general Circle of the Moon-related +question that is not answered here, try the above guide. + +## What does randomization do to this game? + +Almost all items that you would normally find on pedestals throughout the game have had their locations changed. In addition to +Magic Items (barring the Dash Boots which you always start with) and stat max ups, the DSS Cards have been added to the +item pool as well; you will now find these as randomized items rather than by farming them via enemy drops. + +## Can I use any of the alternate modes? + +Yes. All alternate modes (Magician, Fighter, Shooter, and Thief Mode) are all unlocked and usable from the start by registering +the name password shown on the Data Select screen for the mode of your choice. + +If you intend to play Magician Mode, putting all of your cards in "Start Inventory from Pool" is recommended due to the fact +that it naturally starts with all cards. In Fighter Mode, unlike in the regular game, you will be able to receive and use +DSS Cards like in all other modes. + +## What is the goal of Castlevania: Circle of the Moon when randomized? + +Depending on what was chosen for the "Completion Goal" option, your goal may be to defeat Dracula, complete the Battle Arena, or both. + +- "Dracula": Make it to the Ceremonial Room and kill Dracula's first and second forms to view the credits. The door to the +Ceremonial Room can be set to require anywhere between 0-9 Last Keys to open it. +- "Battle Arena": Survive every room in the Battle Arena and pick up the Shinning Armor sic on the pedestal at the end. To make it +easier, the "Disable Battle Arena Mp Drain" option can be enabled to make the Battle Arena not drain your MP to 0, allowing +DSS to be used. Reaching the Battle Arena in the first place requires finding the Heavy Ring and Roc Wing (as well as Double or Kick Boots +if "Nerf Roc Wing" is on). +- "Battle Arena And Dracula": Complete both of the above-mentioned objectives. The server will remember which ones (if any) were +already completed on previous sessions upon connecting. + +NOTE: If "All Bosses" was chosen for the "Required Skirmishes" option, 8 Last Keys will be required, and they will be guaranteed +to be placed behind all 8 bosses (that are not Dracula). If "All Bosses And Arena" was chosen for the option, an additional +required 9th Last Key will be placed on the Shinning Armor sic pedestal at the end of the Battle Arena in addition to +the 8 that will be behind all the bosses. + +If you aren't sure what goal you have, there are two in-game ways you can check: + +- Pause the game, go to the Magic Item menu, and view the Dash Boots tutorial. +- Approach the door to the first Battle Arena combat room and the textbox that normally explains how the place works will tell you. + +There are also two in-game ways to see how many Last Keys are in the item pool for the slot: + +- Pause the game, go to the Magic Item menu, and view the Last Key tutorial. +- If you don't have any keys, touch the Ceremonial Room door before acquiring the necessary amount. + + +## What items and locations get shuffled? + +Stat max ups, Magic Items, and DSS Cards are all randomized into the item pool, and the check locations are the pedestals +that you would normally find the first two types of items on. + +The sole exception is the pedestal at the end of the Battle Arena. This location, most of the time, will always have +Shinning Armor sic unless "Required Skirmishes" is set to "All Bosses And Arena", in which case it will have a Last Key instead. + +## Which items can be in another player's world? + +Stat max ups, Magic Items, and DSS Cards can all be placed into another player's world. + +The Dash Boots and Shinning Armor sic are not randomized in the item pool; the former you will always start with and the +latter will always be found at the end of the Battle Arena in your own world. And depending on your goal, you may or may +not be required to pick it up. + +## What does another world's item look like in Castlevania: Circle of the Moon? + +Items for other Circle of the Moon players will show up in your game as that item, though you won't receive it yourself upon +picking it up. Items for non-Circle of the Moon players will show up as one of four Archipelago Items depending on how its +classified: + +* "Filler": Just the six spheres, nothing extra. +* "Useful": Blue plus sign in the top-right corner. +* "Progression": Orange up arrow in the top-right corner. +* "Progression" and "Useful": Orange up arrow in the top-right corner, blue plus sign in the bottom-right corner. +* "Trap": Reports from the local residents of the remote Austrian village of \[REDACTED], Styria claim that they disguise themselves +as Progression but with the important difference of \[DATA EXPUNGED]. Verification of these claims are currently pending... + +Upon sending an item, a textbox announcing the item being sent and the player who it's for will show up on-screen, accompanied +by a sound depending on whether the item is filler-, progression-/useful-, or trap-classified. + +## When the player receives an item, what happens? + +A textbox announcing the item being received and the player who sent it will pop up on-screen, and it will be given. +Similar to the outgoing item textbox, it will be accompanied by a sound depending on the item received being filler or progression/useful. + +## What are the item name groups? + +When you attempt to hint for items in Archipelago you can use either the name for the specific item, or the name of a group +of items. Hinting for a group will choose a random item from the group that you do not currently have and hint for it. The +groups you can use for Castlevania: Circle of the Moon are as follows: + +* "DSS" or "Card": Any DSS Card of either type. +* "Action" or "Action Card": Any Action Card. +* "Attribute" or "Attribute Card": Any Attribute Card. +* "Freeze": Any card that logically lets you freeze enemies to use as platforms. +* "Action Freeze": Either Action Card that logically lets you freeze enemies. +* "Attribute Freeze": Either Attribute Card that logically lets you freeze enemies. + +## What are the location name groups? + +In Castlevania: Circle of the Moon, every location is part of a location group under that location's area name. +So if you want to exclude all of, say, Underground Waterway from having progression, you can do so by just excluding +"Underground Waterway" as a whole. + +In addition to the area location groups, the following groups also exist: + +* "Breakable Secrets": All locations behind the secret breakable walls, floors, and ceilings. +* "Bosses": All the primary locations behind bosses that Last Keys normally get forced onto when bosses are required. If you want +to prioritize every boss to be guarding a progression item for someone, this is the group for you! + +## How does the item drop randomization work? + +There are three tiers of item drops: Low, Mid, and High. Each enemy has two item "slots" that can both drop its own item; a Common slot and a Rare one. + +On Normal item randomization, "easy" enemies (below 61 HP) will only have Low-tier drops in both of their slots, bosses +and candle enemies will be guaranteed to have High drops in one or both of their slots respectively (bosses are made to +only drop one slot 100% of the time), and everything else can have a Low or Mid-tier item in its Common drop slot and a +Low, Mid, OR High-tier item in its Rare drop slot. + +If Item Drop Randomization is set to Tiered, the HP threshold for enemies being considered "easy" will raise to below +144, enemies in the 144-369 HP range (inclusive) will have a Low-tier item in its Common slot and a Mid-tier item in +its rare slot, and enemies with more than 369 HP will have a Mid-tier in its Common slot and a High-tier in its Rare +slot, making them more worthwhile to go after. Candles and bosses still have Rares in all their slots, but now the guaranteed +drops that land on bosses will be exclusive to them; no other enemy in the game will have their item. + +Note that the Shinning Armor sic can never be placed randomly onto a normal enemy; you can only receive it by completing the Battle Arena. +If "Required Skirmishes" is set to "All Bosses And Arena", which replaces the Shinning Armor sic on the pedestal at the end with +a Last Key, the Devil fought in the last room before the end pedestal will drop Shinning Armor sic 100% of the time upon defeat. + +For more information and an exact breakdown of what items are considered which tier, see Malaert64's guide +[here](https://docs.google.com/document/d/1uot4BD9XW7A--A8ecgoY8mLK_vSoQRpY5XCkzgas87c/view#heading=h.5iz6ytaji08m). + +## Is it just me, or does the Countdown seem inaccurate to the number of checks in the area? +Some Countdown regions are funny because of how the developers of the game decided what rooms belong to which areas in spite of +what most players might think. For instance, the Skeleton Athlete room is actually part of the Chapel Tower area, not the Audience Room. +And the Outer Wall very notably has several rooms isolated from its "main" area, like the Were-Horse/Jaguar Armory. +See [this map](https://docs.google.com/document/d/1uot4BD9XW7A--A8ecgoY8mLK_vSoQRpY5XCkzgas87c/view#heading=h.scu4u49kvcd4) +to know exactly which rooms make up which Countdown regions. + +## Will the Castlevania Advance Collection and/or Wii U Virtual Console versions work? + +The Castlevania Advance Collection ROM is tested and known to work. However, there are some major caveats when playing with the +Advance Collection ROM; most notably the fact that the audio does not function when played in an emulator outside the collection, +which is currently a requirement to connect to a multiworld. This happens because all audio code was stripped +from the ROM, and all sound is instead played by the collection through external means. + +For this reason, it is most recommended to obtain the ROM by dumping it from an original cartridge of the game that you legally own. +Though, the Advance Collection *can* still technically be an option if you cannot do that and don't mind the lack of sound. + +The Wii U Virtual Console version is currently untested. If you happen to have purchased it before the Wii U eShop shut down, you can try +dumping and playing with it. However, at the moment, we cannot guarantee that it will work well due to it being untested. + +Regardless of which released ROM you intend to try playing with, the US version of the game is required. + +## What are the odds of a pentabone? +The odds of skeleton Nathan throwing a big bone instead of a little one, verified by looking at the code itself, is 18, or 12.5%. + +Soooooooooo, to throw 5 big bones back-to-back... + +(18)5 = 132768, or 0.0030517578125%. Good luck, you're gonna need it! diff --git a/worlds/cvcotm/docs/setup_en.md b/worlds/cvcotm/docs/setup_en.md new file mode 100644 index 000000000000..7899ac997366 --- /dev/null +++ b/worlds/cvcotm/docs/setup_en.md @@ -0,0 +1,72 @@ +# Castlevania: Circle of the Moon Setup Guide + +## Required Software + +- [Archipelago](https://github.com/ArchipelagoMW/Archipelago/releases/latest). +- A Castlevania: Circle of the Moon ROM of the US version specifically. The Archipelago community cannot provide this. +The Castlevania Advance Collection ROM can technically be used, but it has no audio. The Wii U Virtual Console ROM is untested. +- [BizHawk](https://tasvideos.org/BizHawk/ReleaseHistory) 2.7 or later. + +### Configuring BizHawk + +Once you have installed BizHawk, open `EmuHawk.exe` and change the following settings: + +- If you're using BizHawk 2.7 or 2.8, go to `Config > Customize`. On the Advanced tab, switch the Lua Core from +`NLua+KopiLua` to `Lua+LuaInterface`, then restart EmuHawk. (If you're using BizHawk 2.9, you can skip this step.) +- Under `Config > Customize`, check the "Run in background" option to prevent disconnecting from the client while you're +tabbed out of EmuHawk. +- Open a `.gba` file in EmuHawk and go to `Config > Controllers…` to configure your inputs. If you can't click +`Controllers…`, load any `.gba` ROM first. +- Consider clearing keybinds in `Config > Hotkeys…` if you don't intend to use them. Select the keybind and press Esc to +clear it. + +## Optional Software + +- [Castlevania: Circle of the Moon AP Tracker](https://github.com/sassyvania/Circle-of-the-Moon-Rando-AP-Map-Tracker-/releases/latest), for use with +[PopTracker](https://github.com/black-sliver/PopTracker/releases). + +## Generating and Patching a Game + +1. Create your settings file (YAML). You can make one on the [Castlevania: Circle of the Moon options page](../../../games/Castlevania%20-%20Circle%20of%20the%20Moon/player-options). +2. Follow the general Archipelago instructions for [generating a game](../../Archipelago/setup/en#generating-a-game). +This will generate an output file for you. Your patch file will have the `.apcvcotm` file extension. +3. Open `ArchipelagoLauncher.exe`. +4. Select "Open Patch" on the left side and select your patch file. +5. If this is your first time patching, you will be prompted to locate your vanilla ROM. +6. A patched `.gba` file will be created in the same place as the patch file. +7. On your first time opening a patch with BizHawk Client, you will also be asked to locate `EmuHawk.exe` in your +BizHawk install. + +If you're playing a single-player seed, and you don't care about hints, you can stop here, close the client, and load +the patched ROM in any emulator of your choice. However, for multiworlds and other Archipelago features, +continue below using BizHawk as your emulator. + +## Connecting to a Server + +By default, opening a patch file will do steps 1-5 below for you automatically. Even so, keep them in your memory just +in case you have to close and reopen a window mid-game for some reason. + +1. Castlevania: Circle of the Moon uses Archipelago's BizHawk Client. If the client isn't still open from when you patched your game, +you can re-open it from the launcher. +2. Ensure EmuHawk is running the patched ROM. +3. In EmuHawk, go to `Tools > Lua Console`. This window must stay open while playing. +4. In the Lua Console window, go to `Script > Open Script…`. +5. Navigate to your Archipelago install folder and open `data/lua/connector_bizhawk_generic.lua`. +6. The emulator may freeze every few seconds until it manages to connect to the client. This is expected. The BizHawk +Client window should indicate that it connected and recognized Castlevania: Circle of the Moon. +7. To connect the client to the server, enter your room's address and port (e.g. `archipelago.gg:38281`) into the +top text field of the client and click Connect. + +You should now be able to receive and send items. You'll need to do these steps every time you want to reconnect. It is +perfectly safe to make progress offline; everything will re-sync when you reconnect. + +## Auto-Tracking + +Castlevania: Circle of the Moon has a fully functional map tracker that supports auto-tracking. + +1. Download [Castlevania: Circle of the Moon AP Tracker](https://github.com/sassyvania/Circle-of-the-Moon-Rando-AP-Map-Tracker-/releases/latest) and +[PopTracker](https://github.com/black-sliver/PopTracker/releases). +2. Put the tracker pack into `packs/` in your PopTracker install. +3. Open PopTracker, and load the Castlevania: Circle of the Moon pack. +4. For autotracking, click on the "AP" symbol at the top. +5. Enter the Archipelago server address (the one you connected your client to), slot name, and password. diff --git a/worlds/cvcotm/items.py b/worlds/cvcotm/items.py new file mode 100644 index 000000000000..bce2b3fc0c4d --- /dev/null +++ b/worlds/cvcotm/items.py @@ -0,0 +1,211 @@ +import logging + +from BaseClasses import Item, ItemClassification +from .data import iname +from .locations import BASE_ID +from .options import IronMaidenBehavior + +from typing import TYPE_CHECKING, Dict, NamedTuple, Optional +from collections import Counter + +if TYPE_CHECKING: + from . import CVCotMWorld + + +class CVCotMItem(Item): + game: str = "Castlevania - Circle of the Moon" + + +class CVCotMItemData(NamedTuple): + code: Optional[int] + text_id: Optional[bytes] + default_classification: ItemClassification + tutorial_id: Optional[bytes] = None +# "code" = The unique part of the Item's AP code attribute, as well as the value to call the in-game "prepare item +# textbox" function with to give the Item in-game. Add this + base_id to get the actual AP code. +# "text_id" = The textbox ID for the vanilla message for receiving the Item. Used when receiving an Item through the +# client that was not sent by a different player. +# "default_classification" = The AP Item Classification that gets assigned to instances of that Item in create_item +# by default, unless I deliberately override it (as is the case for the Cleansing on the +# Ignore Cleansing option). +# "tutorial_id" = The textbox ID for the item's tutorial. Used by the client if tutorials are not skipped. + + +cvcotm_item_info: Dict[str, CVCotMItemData] = { + iname.heart_max: CVCotMItemData(0xE400, b"\x57\x81", ItemClassification.filler), + iname.hp_max: CVCotMItemData(0xE401, b"\x55\x81", ItemClassification.filler), + iname.mp_max: CVCotMItemData(0xE402, b"\x56\x81", ItemClassification.filler), + iname.salamander: CVCotMItemData(0xE600, b"\x1E\x82", ItemClassification.useful), + iname.serpent: CVCotMItemData(0xE601, b"\x1F\x82", ItemClassification.useful | + ItemClassification.progression), + iname.mandragora: CVCotMItemData(0xE602, b"\x20\x82", ItemClassification.useful), + iname.golem: CVCotMItemData(0xE603, b"\x21\x82", ItemClassification.useful), + iname.cockatrice: CVCotMItemData(0xE604, b"\x22\x82", ItemClassification.useful | + ItemClassification.progression), + iname.manticore: CVCotMItemData(0xE605, b"\x23\x82", ItemClassification.useful), + iname.griffin: CVCotMItemData(0xE606, b"\x24\x82", ItemClassification.useful), + iname.thunderbird: CVCotMItemData(0xE607, b"\x25\x82", ItemClassification.useful), + iname.unicorn: CVCotMItemData(0xE608, b"\x26\x82", ItemClassification.useful), + iname.black_dog: CVCotMItemData(0xE609, b"\x27\x82", ItemClassification.useful), + iname.mercury: CVCotMItemData(0xE60A, b"\x28\x82", ItemClassification.useful | + ItemClassification.progression), + iname.venus: CVCotMItemData(0xE60B, b"\x29\x82", ItemClassification.useful), + iname.jupiter: CVCotMItemData(0xE60C, b"\x2A\x82", ItemClassification.useful), + iname.mars: CVCotMItemData(0xE60D, b"\x2B\x82", ItemClassification.useful | + ItemClassification.progression), + iname.diana: CVCotMItemData(0xE60E, b"\x2C\x82", ItemClassification.useful), + iname.apollo: CVCotMItemData(0xE60F, b"\x2D\x82", ItemClassification.useful), + iname.neptune: CVCotMItemData(0xE610, b"\x2E\x82", ItemClassification.useful), + iname.saturn: CVCotMItemData(0xE611, b"\x2F\x82", ItemClassification.useful), + iname.uranus: CVCotMItemData(0xE612, b"\x30\x82", ItemClassification.useful), + iname.pluto: CVCotMItemData(0xE613, b"\x31\x82", ItemClassification.useful), + # Dash Boots + iname.double: CVCotMItemData(0xE801, b"\x59\x81", ItemClassification.useful | + ItemClassification.progression, b"\xF4\x84"), + iname.tackle: CVCotMItemData(0xE802, b"\x5A\x81", ItemClassification.progression, b"\xF5\x84"), + iname.kick_boots: CVCotMItemData(0xE803, b"\x5B\x81", ItemClassification.progression, b"\xF6\x84"), + iname.heavy_ring: CVCotMItemData(0xE804, b"\x5C\x81", ItemClassification.progression, b"\xF7\x84"), + # Map + iname.cleansing: CVCotMItemData(0xE806, b"\x5D\x81", ItemClassification.progression, b"\xF8\x84"), + iname.roc_wing: CVCotMItemData(0xE807, b"\x5E\x81", ItemClassification.useful | + ItemClassification.progression, b"\xF9\x84"), + iname.last_key: CVCotMItemData(0xE808, b"\x5F\x81", ItemClassification.progression_skip_balancing, + b"\xFA\x84"), + iname.ironmaidens: CVCotMItemData(0xE809, b"\xF1\x84", ItemClassification.progression), + iname.dracula: CVCotMItemData(None, None, ItemClassification.progression), + iname.shinning_armor: CVCotMItemData(None, None, ItemClassification.progression), +} + +ACTION_CARDS = {iname.mercury, iname.venus, iname.jupiter, iname.mars, iname.diana, iname.apollo, iname.neptune, + iname.saturn, iname.uranus, iname.pluto} + +ATTRIBUTE_CARDS = {iname.salamander, iname.serpent, iname.mandragora, iname.golem, iname.cockatrice, iname.griffin, + iname.manticore, iname.thunderbird, iname.unicorn, iname.black_dog} + +FREEZE_ACTIONS = [iname.mercury, iname.mars] +FREEZE_ATTRS = [iname.serpent, iname.cockatrice] + +FILLER_ITEM_NAMES = [iname.heart_max, iname.hp_max, iname.mp_max] + +MAJORS_CLASSIFICATIONS = ItemClassification.progression | ItemClassification.useful + + +def get_item_names_to_ids() -> Dict[str, int]: + return {name: cvcotm_item_info[name].code + BASE_ID for name in cvcotm_item_info + if cvcotm_item_info[name].code is not None} + + +def get_item_counts(world: "CVCotMWorld") -> Dict[ItemClassification, Dict[str, int]]: + + item_counts: Dict[ItemClassification, Counter[str, int]] = { + ItemClassification.progression: Counter(), + ItemClassification.progression_skip_balancing: Counter(), + ItemClassification.useful | ItemClassification.progression: Counter(), + ItemClassification.useful: Counter(), + ItemClassification.filler: Counter(), + } + total_items = 0 + # Items to be skipped over in the main Item creation loop. + excluded_items = [iname.hp_max, iname.mp_max, iname.heart_max, iname.last_key] + + # If Halve DSS Cards Placed is on, determine which cards we will exclude here. + if world.options.halve_dss_cards_placed: + excluded_cards = list(ACTION_CARDS.union(ATTRIBUTE_CARDS)) + + has_freeze_action = False + has_freeze_attr = False + start_card_cap = 8 + + # Get out all cards from start_inventory_from_pool that the player isn't starting with 0 of. + start_cards = [item for item in world.options.start_inventory_from_pool.value if "Card" in item] + + # Check for ice/stone cards that are in the player's starting cards. Increase the starting card capacity by 1 + # for each card type satisfied. + for card in start_cards: + if card in FREEZE_ACTIONS and not has_freeze_action: + has_freeze_action = True + start_card_cap += 1 + if card in FREEZE_ATTRS and not has_freeze_attr: + has_freeze_attr = True + start_card_cap += 1 + + # If we are over our starting card capacity, some starting cards will need to be removed... + if len(start_cards) > start_card_cap: + + # Ice/stone cards will be kept no matter what. As for the others, put them in a list of possible candidates + # to remove. + kept_start_cards = [] + removal_candidates = [] + for card in start_cards: + if card in FREEZE_ACTIONS + FREEZE_ATTRS: + kept_start_cards.append(card) + else: + removal_candidates.append(card) + + # Add a random sample of the removal candidate cards to our kept cards list. + kept_start_cards += world.random.sample(removal_candidates, start_card_cap - len(kept_start_cards)) + + # Make a list of the cards we are not keeping. + removed_start_cards = [card for card in removal_candidates if card not in kept_start_cards] + + # Remove the cards we're not keeping from start_inventory_from_pool. + for card in removed_start_cards: + del world.options.start_inventory_from_pool.value[card] + + logging.warning(f"[{world.player_name}] Too many DSS Cards in " + f"Start Inventory from Pool to satisfy the Halve DSS Cards Placed option. The following " + f"{len(removed_start_cards)} card(s) were removed: {removed_start_cards}") + + start_cards = kept_start_cards + + # Remove the starting cards from the excluded cards. + for card in ACTION_CARDS.union(ATTRIBUTE_CARDS): + if card in start_cards: + excluded_cards.remove(card) + + # Remove a valid ice/stone action and/or attribute card if the player isn't starting with one. + if not has_freeze_action: + excluded_cards.remove(world.random.choice(FREEZE_ACTIONS)) + if not has_freeze_attr: + excluded_cards.remove(world.random.choice(FREEZE_ATTRS)) + + # Remove 10 random cards from the exclusions. + excluded_items += world.random.sample(excluded_cards, 10) + + # Exclude the Maiden Detonator from creation if the maidens start broken. + if world.options.iron_maiden_behavior == IronMaidenBehavior.option_start_broken: + excluded_items += [iname.ironmaidens] + + # Add one of each Item to the pool that is not filler or progression skip balancing. + for item in cvcotm_item_info: + classification = cvcotm_item_info[item].default_classification + code = cvcotm_item_info[item].code + + # Skip event Items and Items that are excluded from creation. + if code is None or item in excluded_items: + continue + + # Classify the Cleansing as Useful instead of Progression if Ignore Cleansing is on. + if item == iname.cleansing and world.options.ignore_cleansing: + classification = ItemClassification.useful + + # Classify the Kick Boots as Progression + Useful if Nerf Roc Wing is on. + if item == iname.kick_boots and world.options.nerf_roc_wing: + classification |= ItemClassification.useful + + item_counts[classification][item] = 1 + total_items += 1 + + # Add the total Last Keys if no skirmishes are required (meaning they're not forced anywhere). + if not world.options.required_skirmishes: + item_counts[ItemClassification.progression_skip_balancing][iname.last_key] = \ + world.options.available_last_keys.value + total_items += world.options.available_last_keys.value + + # Add filler items at random until the total Items = the total Locations. + while total_items < len(world.multiworld.get_unfilled_locations(world.player)): + filler_to_add = world.random.choice(FILLER_ITEM_NAMES) + item_counts[ItemClassification.filler][filler_to_add] += 1 + total_items += 1 + + return item_counts diff --git a/worlds/cvcotm/locations.py b/worlds/cvcotm/locations.py new file mode 100644 index 000000000000..02f1e65ab6f8 --- /dev/null +++ b/worlds/cvcotm/locations.py @@ -0,0 +1,265 @@ +from BaseClasses import Location +from .data import lname, iname +from .options import CVCotMOptions, CompletionGoal, IronMaidenBehavior, RequiredSkirmishes + +from typing import Dict, List, Union, Tuple, Optional, Set, NamedTuple + +BASE_ID = 0xD55C0000 + + +class CVCotMLocation(Location): + game: str = "Castlevania - Circle of the Moon" + + +class CVCotMLocationData(NamedTuple): + code: Union[int, str] + offset: Optional[int] + countdown: Optional[int] + type: Optional[str] = None +# code = The unique part of the Location's AP code attribute, as well as the in-game bitflag index starting from +# 0x02025374 that indicates the Location has been checked. Add this + base_id to get the actual AP code. +# If we put an Item name string here instead of an int, then it is an event Location and that Item should be +# forced on it while calling the actual code None. +# offset = The offset in the ROM to overwrite to change the Item on that Location. +# countdown = The index of the Countdown number region it contributes to. +# rule = What rule should be applied to the Location during set_rules, as defined in self.rules in the CVCotMRules class +# definition in rules.py. +# event = What event Item to place on that Location, for Locations that are events specifically. +# type = Anything special about this Location that should be considered, whether it be a boss Location, etc. + + +cvcotm_location_info: Dict[str, CVCotMLocationData] = { + # Sealed Room + lname.sr3: CVCotMLocationData(0x35, 0xD0310, 0), + # Catacombs + lname.cc1: CVCotMLocationData(0x37, 0xD0658, 1), + lname.cc3: CVCotMLocationData(0x43, 0xD0370, 1), + lname.cc3b: CVCotMLocationData(0x36, 0xD0364, 1), + lname.cc4: CVCotMLocationData(0xA8, 0xD0934, 1, type="magic item"), + lname.cc5: CVCotMLocationData(0x38, 0xD0DE4, 1), + lname.cc8: CVCotMLocationData(0x3A, 0xD1078, 1), + lname.cc8b: CVCotMLocationData(0x3B, 0xD1084, 1), + lname.cc9: CVCotMLocationData(0x40, 0xD0F94, 1), + lname.cc10: CVCotMLocationData(0x39, 0xD12C4, 1), + lname.cc13: CVCotMLocationData(0x41, 0xD0DA8, 1), + lname.cc14: CVCotMLocationData(0x3C, 0xD1168, 1), + lname.cc14b: CVCotMLocationData(0x3D, 0xD1174, 1), + lname.cc16: CVCotMLocationData(0x3E, 0xD0C40, 1), + lname.cc20: CVCotMLocationData(0x42, 0xD103C, 1), + lname.cc22: CVCotMLocationData(0x3F, 0xD07C0, 1), + lname.cc24: CVCotMLocationData(0xA9, 0xD1288, 1, type="boss"), + lname.cc25: CVCotMLocationData(0x44, 0xD12A0, 1), + # Abyss Staircase + lname.as2: CVCotMLocationData(0x47, 0xD181C, 2), + lname.as3: CVCotMLocationData(0x45, 0xD1774, 2), + lname.as4: CVCotMLocationData(0x46, 0xD1678, 2), + lname.as9: CVCotMLocationData(0x48, 0xD17EC, 2), + # Audience Room + lname.ar4: CVCotMLocationData(0x53, 0xD2344, 3), + lname.ar7: CVCotMLocationData(0x54, 0xD2368, 3), + lname.ar8: CVCotMLocationData(0x51, 0xD1BF4, 3), + lname.ar9: CVCotMLocationData(0x4B, 0xD1E1C, 3), + lname.ar10: CVCotMLocationData(0x4A, 0xD1DE0, 3), + lname.ar11: CVCotMLocationData(0x49, 0xD1E58, 3), + lname.ar14: CVCotMLocationData(0x4D, 0xD2158, 3), + lname.ar14b: CVCotMLocationData(0x4C, 0xD214C, 3), + lname.ar16: CVCotMLocationData(0x52, 0xD20BC, 3), + lname.ar17: CVCotMLocationData(0x50, 0xD2290, 3), + lname.ar17b: CVCotMLocationData(0x4F, 0xD2284, 3), + lname.ar18: CVCotMLocationData(0x4E, 0xD1FA8, 3), + lname.ar19: CVCotMLocationData(0x6A, 0xD44A4, 7), + lname.ar21: CVCotMLocationData(0x55, 0xD238C, 3), + lname.ar25: CVCotMLocationData(0xAA, 0xD1E04, 3, type="boss"), + lname.ar26: CVCotMLocationData(0x59, 0xD3370, 5), + lname.ar27: CVCotMLocationData(0x58, 0xD34E4, 5), + lname.ar30: CVCotMLocationData(0x99, 0xD6A24, 11), + lname.ar30b: CVCotMLocationData(0x9A, 0xD6A30, 11), + # Outer Wall + lname.ow0: CVCotMLocationData(0x97, 0xD6BEC, 11), + lname.ow1: CVCotMLocationData(0x98, 0xD6CE8, 11), + lname.ow2: CVCotMLocationData(0x9E, 0xD6DE4, 11), + # Triumph Hallway + lname.th1: CVCotMLocationData(0x57, 0xD26D4, 4), + lname.th3: CVCotMLocationData(0x56, 0xD23C8, 4), + # Machine Tower + lname.mt0: CVCotMLocationData(0x61, 0xD307C, 5), + lname.mt2: CVCotMLocationData(0x62, 0xD32A4, 5), + lname.mt3: CVCotMLocationData(0x5B, 0xD3244, 5), + lname.mt4: CVCotMLocationData(0x5A, 0xD31FC, 5), + lname.mt6: CVCotMLocationData(0x5F, 0xD2F38, 5), + lname.mt8: CVCotMLocationData(0x5E, 0xD2EC0, 5), + lname.mt10: CVCotMLocationData(0x63, 0xD3550, 5), + lname.mt11: CVCotMLocationData(0x5D, 0xD2D88, 5), + lname.mt13: CVCotMLocationData(0x5C, 0xD3580, 5), + lname.mt14: CVCotMLocationData(0x60, 0xD2A64, 5), + lname.mt17: CVCotMLocationData(0x64, 0xD3520, 5), + lname.mt19: CVCotMLocationData(0xAB, 0xD283C, 5, type="boss"), + # Eternal Corridor + lname.ec5: CVCotMLocationData(0x66, 0xD3B50, 6), + lname.ec7: CVCotMLocationData(0x65, 0xD3A90, 6), + lname.ec9: CVCotMLocationData(0x67, 0xD3B98, 6), + # Chapel Tower + lname.ct1: CVCotMLocationData(0x68, 0xD40F0, 7), + lname.ct4: CVCotMLocationData(0x69, 0xD4630, 7), + lname.ct5: CVCotMLocationData(0x72, 0xD481C, 7), + lname.ct6: CVCotMLocationData(0x6B, 0xD4294, 7), + lname.ct6b: CVCotMLocationData(0x6C, 0xD42A0, 7), + lname.ct8: CVCotMLocationData(0x6D, 0xD4330, 7), + lname.ct10: CVCotMLocationData(0x6E, 0xD415C, 7), + lname.ct13: CVCotMLocationData(0x6F, 0xD4060, 7), + lname.ct15: CVCotMLocationData(0x73, 0xD47F8, 7), + lname.ct16: CVCotMLocationData(0x70, 0xD3DA8, 7), + lname.ct18: CVCotMLocationData(0x74, 0xD47C8, 7), + lname.ct21: CVCotMLocationData(0xF0, 0xD47B0, 7, type="maiden switch"), + lname.ct22: CVCotMLocationData(0x71, 0xD3CF4, 7, type="max up boss"), + lname.ct26: CVCotMLocationData(0x9C, 0xD6ACC, 11), + lname.ct26b: CVCotMLocationData(0x9B, 0xD6AC0, 11), + # Underground Gallery + lname.ug0: CVCotMLocationData(0x82, 0xD5944, 9), + lname.ug1: CVCotMLocationData(0x83, 0xD5890, 9), + lname.ug2: CVCotMLocationData(0x81, 0xD5A1C, 9), + lname.ug3: CVCotMLocationData(0x85, 0xD56A4, 9), + lname.ug3b: CVCotMLocationData(0x84, 0xD5698, 9), + lname.ug8: CVCotMLocationData(0x86, 0xD5E30, 9), + lname.ug10: CVCotMLocationData(0x87, 0xD5F68, 9), + lname.ug13: CVCotMLocationData(0x88, 0xD5AB8, 9), + lname.ug15: CVCotMLocationData(0x89, 0xD5BD8, 9), + lname.ug20: CVCotMLocationData(0xAC, 0xD5470, 9, type="boss"), + # Underground Warehouse + lname.uw1: CVCotMLocationData(0x75, 0xD48DC, 8), + lname.uw6: CVCotMLocationData(0x76, 0xD4D20, 8), + lname.uw8: CVCotMLocationData(0x77, 0xD4BA0, 8), + lname.uw9: CVCotMLocationData(0x7E, 0xD53EC, 8), + lname.uw10: CVCotMLocationData(0x78, 0xD4C84, 8), + lname.uw11: CVCotMLocationData(0x79, 0xD4EC4, 8), + lname.uw14: CVCotMLocationData(0x7F, 0xD5410, 8), + lname.uw16: CVCotMLocationData(0x7A, 0xD5050, 8), + lname.uw16b: CVCotMLocationData(0x7B, 0xD505C, 8), + lname.uw19: CVCotMLocationData(0x7C, 0xD5344, 8), + lname.uw23: CVCotMLocationData(0xAE, 0xD53B0, 8, type="boss"), + lname.uw24: CVCotMLocationData(0x80, 0xD5434, 8), + lname.uw25: CVCotMLocationData(0x7D, 0xD4FC0, 8), + # Underground Waterway + lname.uy1: CVCotMLocationData(0x93, 0xD5F98, 10), + lname.uy3: CVCotMLocationData(0x8B, 0xD5FEC, 10), + lname.uy3b: CVCotMLocationData(0x8A, 0xD5FE0, 10), + lname.uy4: CVCotMLocationData(0x94, 0xD697C, 10), + lname.uy5: CVCotMLocationData(0x8C, 0xD6214, 10), + lname.uy7: CVCotMLocationData(0x8D, 0xD65A4, 10), + lname.uy8: CVCotMLocationData(0x95, 0xD69A0, 10), + lname.uy9: CVCotMLocationData(0x8E, 0xD640C, 10), + lname.uy9b: CVCotMLocationData(0x8F, 0xD6418, 10), + lname.uy12: CVCotMLocationData(0x90, 0xD6730, 10), + lname.uy12b: CVCotMLocationData(0x91, 0xD673C, 10), + lname.uy13: CVCotMLocationData(0x92, 0xD685C, 10), + lname.uy17: CVCotMLocationData(0xAF, 0xD6940, 10, type="boss"), + lname.uy18: CVCotMLocationData(0x96, 0xD69C4, 10), + # Observation Tower + lname.ot1: CVCotMLocationData(0x9D, 0xD6B38, 11), + lname.ot2: CVCotMLocationData(0xA4, 0xD760C, 12), + lname.ot3: CVCotMLocationData(0x9F, 0xD72E8, 12), + lname.ot5: CVCotMLocationData(0xA5, 0xD75E8, 12), + lname.ot8: CVCotMLocationData(0xA0, 0xD71EC, 12), + lname.ot9: CVCotMLocationData(0xA2, 0xD6FE8, 12), + lname.ot12: CVCotMLocationData(0xA6, 0xD75C4, 12), + lname.ot13: CVCotMLocationData(0xA3, 0xD6F64, 12), + lname.ot16: CVCotMLocationData(0xA1, 0xD751C, 12), + lname.ot20: CVCotMLocationData(0xB0, 0xD6E20, 12, type="boss"), + # Ceremonial Room + lname.cr1: CVCotMLocationData(0xA7, 0xD7690, 13), + lname.dracula: CVCotMLocationData(iname.dracula, None, None), + # Battle Arena + lname.ba24: CVCotMLocationData(0xB2, 0xD7D20, 14, type="arena"), + lname.arena_victory: CVCotMLocationData(iname.shinning_armor, None, None), + } + + +def get_location_names_to_ids() -> Dict[str, int]: + return {name: cvcotm_location_info[name].code+BASE_ID for name in cvcotm_location_info + if isinstance(cvcotm_location_info[name].code, int)} + + +def get_location_name_groups() -> Dict[str, Set[str]]: + loc_name_groups: Dict[str, Set[str]] = {"Breakable Secrets": set(), + "Bosses": set()} + + for loc_name in cvcotm_location_info: + # If we are looking at an event Location, don't include it. + if isinstance(cvcotm_location_info[loc_name].code, str): + continue + + # The part of the Location name's string before the colon is its area name. + area_name = loc_name.split(":")[0] + + # Add each Location to its corresponding area name group. + if area_name not in loc_name_groups: + loc_name_groups[area_name] = {loc_name} + else: + loc_name_groups[area_name].add(loc_name) + + # If the word "fake" is in the Location's name, add it to the "Breakable Walls" Location group. + if "fake" in loc_name.casefold(): + loc_name_groups["Breakable Secrets"].add(loc_name) + + # If it's a behind boss Location, add it to the "Bosses" Location group. + if cvcotm_location_info[loc_name].type in ["boss", "max up boss"]: + loc_name_groups["Bosses"].add(loc_name) + + return loc_name_groups + + +def get_named_locations_data(locations: List[str], options: CVCotMOptions) -> \ + Tuple[Dict[str, Optional[int]], Dict[str, str]]: + locations_with_ids = {} + locked_pairs = {} + locked_key_types = [] + + # Decide which Location types should have locked Last Keys placed on them, if skirmishes are required. + # If the Maiden Detonator is in the pool, Adramelech's key should be on the switch instead of behind the maiden. + if options.required_skirmishes: + locked_key_types += ["boss"] + if options.iron_maiden_behavior == IronMaidenBehavior.option_detonator_in_pool: + locked_key_types += ["maiden switch"] + else: + locked_key_types += ["max up boss"] + # If all bosses and the Arena is required, the Arena end reward should have a Last Key as well. + if options.required_skirmishes == RequiredSkirmishes.option_all_bosses_and_arena: + locked_key_types += ["arena"] + + for loc in locations: + if loc == lname.ct21: + # If the maidens are pre-broken, don't create the iron maiden switch Location at all. + if options.iron_maiden_behavior == IronMaidenBehavior.option_start_broken: + continue + # If the maiden behavior is vanilla, lock the Maiden Detonator on this Location. + if options.iron_maiden_behavior == IronMaidenBehavior.option_vanilla: + locked_pairs[loc] = iname.ironmaidens + + # Don't place the Dracula Location if our Completion Goal is the Battle Arena only. + if loc == lname.dracula and options.completion_goal == CompletionGoal.option_battle_arena: + continue + + # Don't place the Battle Arena normal Location if the Arena is not required by the Skirmishes option. + if loc == lname.ba24 and options.required_skirmishes != RequiredSkirmishes.option_all_bosses_and_arena: + continue + + # Don't place the Battle Arena event Location if our Completion Goal is Dracula only. + if loc == lname.arena_victory and options.completion_goal == CompletionGoal.option_dracula: + continue + + loc_code = cvcotm_location_info[loc].code + + # If we are looking at an event Location, add its associated event Item to the events' dict. + # Otherwise, add the base_id to the Location's code. + if isinstance(loc_code, str): + locked_pairs[loc] = loc_code + locations_with_ids.update({loc: None}) + else: + loc_code += BASE_ID + locations_with_ids.update({loc: loc_code}) + + # Place a locked Last Key on this Location if its of a type that should have one. + if cvcotm_location_info[loc].type in locked_key_types: + locked_pairs[loc] = iname.last_key + + return locations_with_ids, locked_pairs diff --git a/worlds/cvcotm/lz10.py b/worlds/cvcotm/lz10.py new file mode 100644 index 000000000000..5ca24c13dd17 --- /dev/null +++ b/worlds/cvcotm/lz10.py @@ -0,0 +1,265 @@ +from collections import defaultdict +from operator import itemgetter +import struct +from typing import Union + +ByteString = Union[bytes, bytearray, memoryview] + + +""" +Taken from the Archipelago Metroid: Zero Mission implementation by Lil David at: +https://github.com/lilDavid/Archipelago-Metroid-Zero-Mission/blob/main/lz10.py + +Tweaked version of nlzss modified to work with raw data and return bytes instead of operating on whole files. +LZ11 functionality has been removed since it is not necessary for Zero Mission nor Circle of the Moon. + +https://github.com/magical/nlzss +""" + + +def decompress(data: ByteString): + """Decompress LZSS-compressed bytes. Returns a bytearray containing the decompressed data.""" + header = data[:4] + if header[0] == 0x10: + decompress_raw = decompress_raw_lzss10 + else: + raise DecompressionError("not as lzss-compressed file") + + decompressed_size = int.from_bytes(header[1:], "little") + + data = data[4:] + return decompress_raw(data, decompressed_size) + + +def compress(data: bytearray): + byteOut = bytearray() + # header + byteOut.extend(struct.pack("B", packflags(flags))) + + for t in tokens: + if type(t) is tuple: + count, disp = t + count -= 3 + disp = (-disp) - 1 + assert 0 <= disp < 4096 + sh = (count << 12) | disp + byteOut.extend(struct.pack(">H", sh)) + else: + byteOut.extend(struct.pack(">B", t)) + + length += 1 + length += sum(2 if f else 1 for f in flags) + + # padding + padding = 4 - (length % 4 or 4) + if padding: + byteOut.extend(b'\xff' * padding) + return byteOut + + +class SlidingWindow: + # The size of the sliding window + size = 4096 + + # The minimum displacement. + disp_min = 2 + + # The hard minimum — a disp less than this can't be represented in the + # compressed stream. + disp_start = 1 + + # The minimum length for a successful match in the window + match_min = 3 + + # The maximum length of a successful match, inclusive. + match_max = 3 + 0xf + + def __init__(self, buf): + self.data = buf + self.hash = defaultdict(list) + self.full = False + + self.start = 0 + self.stop = 0 + # self.index = self.disp_min - 1 + self.index = 0 + + assert self.match_max is not None + + def next(self): + if self.index < self.disp_start - 1: + self.index += 1 + return + + if self.full: + olditem = self.data[self.start] + assert self.hash[olditem][0] == self.start + self.hash[olditem].pop(0) + + item = self.data[self.stop] + self.hash[item].append(self.stop) + self.stop += 1 + self.index += 1 + + if self.full: + self.start += 1 + else: + if self.size <= self.stop: + self.full = True + + def advance(self, n=1): + """Advance the window by n bytes""" + for _ in range(n): + self.next() + + def search(self): + match_max = self.match_max + match_min = self.match_min + + counts = [] + indices = self.hash[self.data[self.index]] + for i in indices: + matchlen = self.match(i, self.index) + if matchlen >= match_min: + disp = self.index - i + if self.disp_min <= disp: + counts.append((matchlen, -disp)) + if matchlen >= match_max: + return counts[-1] + + if counts: + match = max(counts, key=itemgetter(0)) + return match + + return None + + def match(self, start, bufstart): + size = self.index - start + + if size == 0: + return 0 + + matchlen = 0 + it = range(min(len(self.data) - bufstart, self.match_max)) + for i in it: + if self.data[start + (i % size)] == self.data[bufstart + i]: + matchlen += 1 + else: + break + return matchlen + + +def _compress(input, windowclass=SlidingWindow): + """Generates a stream of tokens. Either a byte (int) or a tuple of (count, + displacement).""" + + window = windowclass(input) + + i = 0 + while True: + if len(input) <= i: + break + match = window.search() + if match: + yield match + window.advance(match[0]) + i += match[0] + else: + yield input[i] + window.next() + i += 1 + + +def packflags(flags): + n = 0 + for i in range(8): + n <<= 1 + try: + if flags[i]: + n |= 1 + except IndexError: + pass + return n + + +def chunkit(it, n): + buf = [] + for x in it: + buf.append(x) + if n <= len(buf): + yield buf + buf = [] + if buf: + yield buf + + +def bits(byte): + return ((byte >> 7) & 1, + (byte >> 6) & 1, + (byte >> 5) & 1, + (byte >> 4) & 1, + (byte >> 3) & 1, + (byte >> 2) & 1, + (byte >> 1) & 1, + byte & 1) + + +def decompress_raw_lzss10(indata, decompressed_size, _overlay=False): + """Decompress LZSS-compressed bytes. Returns a bytearray.""" + data = bytearray() + + it = iter(indata) + + if _overlay: + disp_extra = 3 + else: + disp_extra = 1 + + def writebyte(b): + data.append(b) + + def readbyte(): + return next(it) + + def readshort(): + # big-endian + a = next(it) + b = next(it) + return (a << 8) | b + + def copybyte(): + data.append(next(it)) + + while len(data) < decompressed_size: + b = readbyte() + flags = bits(b) + for flag in flags: + if flag == 0: + copybyte() + elif flag == 1: + sh = readshort() + count = (sh >> 0xc) + 3 + disp = (sh & 0xfff) + disp_extra + + for _ in range(count): + writebyte(data[-disp]) + else: + raise ValueError(flag) + + if decompressed_size <= len(data): + break + + if len(data) != decompressed_size: + raise DecompressionError("decompressed size does not match the expected size") + + return data + + +class DecompressionError(ValueError): + pass diff --git a/worlds/cvcotm/options.py b/worlds/cvcotm/options.py new file mode 100644 index 000000000000..3f7d93661cc0 --- /dev/null +++ b/worlds/cvcotm/options.py @@ -0,0 +1,282 @@ +from dataclasses import dataclass +from Options import OptionGroup, Choice, Range, Toggle, PerGameCommonOptions, StartInventoryPool, DeathLink + + +class IgnoreCleansing(Toggle): + """ + Removes the logical requirement for the Cleansing to go beyond the first Underground Waterway rooms from either of the area's sides. You may be required to brave the harmful water without it. + """ + display_name = "Ignore Cleansing" + + +class AutoRun(Toggle): + """ + Makes Nathan always run when pressing left or right without needing to double-tap. + """ + display_name = "Auto Run" + + +class DSSPatch(Toggle): + """ + Patches out being able to pause during the DSS startup animation and switch the cards in the menu to use any combos you don't currently have, as well as changing the element of a summon to one you don't currently have. + """ + display_name = "DSS Patch" + + +class AlwaysAllowSpeedDash(Toggle): + """ + Allows activating the speed dash combo (Pluto + Griffin) without needing the respective cards first. + """ + display_name = "Always Allow Speed Dash" + + +class IronMaidenBehavior(Choice): + """ + Sets how the iron maiden barriers blocking the entrances to Underground Gallery and Waterway will behave. + Vanilla: Vanilla behavior. Must press the button guarded by Adramelech to break them. + Start Broken: The maidens will be broken from the start. + Detonator In Pool: Adds a Maiden Detonator item in the pool that will detonate the maidens when found. Adramelech will guard an extra check. + """ + display_name = "Iron Maiden Behavior" + option_vanilla = 0 + option_start_broken = 1 + option_detonator_in_pool = 2 + + +class RequiredLastKeys(Range): + """ + How many Last Keys are needed to open the door to the Ceremonial Room. This will lower if higher than Available Last Keys. + """ + range_start = 0 + range_end = 9 + default = 1 + display_name = "Required Last Keys" + + +class AvailableLastKeys(Range): + """ + How many Last Keys are in the pool in total. + To see this in-game, select the Last Key in the Magic Item menu (when you have at least one) or touch the Ceremonial Room door. + """ + range_start = 0 + range_end = 9 + default = 1 + display_name = "Available Last Keys" + + +class BuffRangedFamiliars(Toggle): + """ + Makes Familiar projectiles deal double damage to enemies. + """ + display_name = "Buff Ranged Familiars" + + +class BuffSubWeapons(Toggle): + """ + Increases damage dealt by sub-weapons and item crushes in Shooter and non-Shooter Modes. + """ + display_name = "Buff Sub-weapons" + + +class BuffShooterStrength(Toggle): + """ + Increases Nathan's strength in Shooter Mode to match his strength in Vampire Killer Mode. + """ + display_name = "Buff Shooter Strength" + + +class ItemDropRandomization(Choice): + """ + Randomizes what enemies drop what items as well as the drop rates for said items. + Bosses and candle enemies will be guaranteed to have high-tier items in all of their drop slots, and "easy" enemies (below 61 HP) will only drop low-tier items in all of theirs. + All other enemies will drop a low or mid-tier item in their common drop slot, and a low, mid, or high-tier item in their rare drop slot. + The common slot item has a 6-10% base chance of appearing, and the rare has a 3-6% chance. + If Tiered is chosen, all enemies below 144 (instead of 61) HP will be considered "easy", rare items that land on bosses will be exclusive to them, enemies with 144-369 HP will have a low-tier in its common slot and a mid-tier in its rare slot, and enemies with more than 369 HP will have a mid-tier in its common slot and a high-tier in its rare slot. + See the Game Page for more info. + """ + display_name = "Item Drop Randomization" + option_disabled = 0 + option_normal = 1 + option_tiered = 2 + default = 1 + + +class HalveDSSCardsPlaced(Toggle): + """ + Places only half of the DSS Cards in the item pool. + A valid combo that lets you freeze or petrify enemies to use as platforms will always be placed. + """ + display_name = "Halve DSS Cards Placed" + + +class Countdown(Choice): + """ + Displays, below and near the right side of the MP bar, the number of un-found progression/useful-marked items or the total check locations remaining in the area you are currently in. + """ + display_name = "Countdown" + option_none = 0 + option_majors = 1 + option_all_locations = 2 + default = 0 + + +class SubWeaponShuffle(Toggle): + """ + Randomizes which sub-weapon candles have which sub-weapons. + The total available count of each sub-weapon will be consistent with that of the vanilla game. + """ + display_name = "Sub-weapon Shuffle" + + +class DisableBattleArenaMPDrain(Toggle): + """ + Makes the Battle Arena not drain Nathan's MP, so that DSS combos can be used like normal. + """ + display_name = "Disable Battle Arena MP Drain" + + +class RequiredSkirmishes(Choice): + """ + Forces a Last Key after every boss or after every boss and the Battle Arena and forces the required Last Keys to enter the Ceremonial Room to 8 or 9 for All Bosses and All Bosses And Arena respectively. + The Available and Required Last Keys options will be overridden to the respective values. + """ + display_name = "Required Skirmishes" + option_none = 0 + option_all_bosses = 1 + option_all_bosses_and_arena = 2 + default = 0 + + +class EarlyEscapeItem(Choice): + """ + Ensures the chosen Catacomb escape item will be placed in a starting location within your own game, accessible with nothing. + """ + display_name = "Early Escape Item" + option_none = 0 + option_double = 1 + option_roc_wing = 2 + option_double_or_roc_wing = 3 + default = 1 + + +class NerfRocWing(Toggle): + """ + Initially nerfs the Roc Wing by removing its ability to jump infinitely and reducing its jump height. You can power it back up to its vanilla behavior by obtaining the following: + Double: Allows one jump in midair, using your double jump. + Kick Boots: Restores its vanilla jump height. + Both: Enables infinite midair jumping. + Note that holding A while Roc jumping will cause you to rise slightly higher; this is accounted for in logic. + """ + display_name = "Nerf Roc Wing" + + +class PlutoGriffinAirSpeed(Toggle): + """ + Increases Nathan's air speeds with the Pluto + Griffin combo active to be the same as his ground speeds. Anything made possible with the increased air speed is out of logic. + """ + display_name = "DSS Pluto and Griffin Run Speed in Air" + + +class SkipDialogues(Toggle): + """ + Skips all cutscene dialogue besides the ending. + """ + display_name = "Skip Cutscene Dialogue" + + +class SkipTutorials(Toggle): + """ + Skips all Magic Item and DSS-related tutorial textboxes. + """ + display_name = "Skip Magic Item Tutorials" + + +class BattleArenaMusic(Choice): + """ + Enables any looping song from the game to play inside the Battle Arena instead of it being silent the whole time. + """ + display_name = "Battle Arena Music" + option_nothing = 0 + option_requiem = 1 + option_a_vision_of_dark_secrets = 2 + option_inversion = 3 + option_awake = 4 + option_the_sinking_old_sanctuary = 5 + option_clockwork = 6 + option_shudder = 7 + option_fate_to_despair = 8 + option_aquarius = 9 + option_clockwork_mansion = 10 + option_big_battle = 11 + option_nightmare = 12 + option_vampire_killer = 13 + option_illusionary_dance = 14 + option_proof_of_blood = 15 + option_repose_of_souls = 16 + option_circle_of_the_moon = 17 + default = 0 + + +class CVCotMDeathLink(Choice): + __doc__ = (DeathLink.__doc__ + + "\n\n Received DeathLinks will not kill you in the Battle Arena unless Arena On is chosen.") + display_name = "Death Link" + option_off = 0 + alias_false = 0 + alias_no = 0 + option_on = 1 + alias_true = 1 + alias_yes = 1 + option_arena_on = 2 + default = 0 + + +class CompletionGoal(Choice): + """ + The goal for game completion. Can be defeating Dracula, winning in the Battle Arena, or both. + If you aren't sure which one you have while playing, select the Dash Boots in the Magic Item menu. + """ + display_name = "Completion Goal" + option_dracula = 0 + option_battle_arena = 1 + option_battle_arena_and_dracula = 2 + default = 0 + + +@dataclass +class CVCotMOptions(PerGameCommonOptions): + start_inventory_from_pool: StartInventoryPool + completion_goal: CompletionGoal + ignore_cleansing: IgnoreCleansing + auto_run: AutoRun + dss_patch: DSSPatch + always_allow_speed_dash: AlwaysAllowSpeedDash + iron_maiden_behavior: IronMaidenBehavior + required_last_keys: RequiredLastKeys + available_last_keys: AvailableLastKeys + buff_ranged_familiars: BuffRangedFamiliars + buff_sub_weapons: BuffSubWeapons + buff_shooter_strength: BuffShooterStrength + item_drop_randomization: ItemDropRandomization + halve_dss_cards_placed: HalveDSSCardsPlaced + countdown: Countdown + sub_weapon_shuffle: SubWeaponShuffle + disable_battle_arena_mp_drain: DisableBattleArenaMPDrain + required_skirmishes: RequiredSkirmishes + pluto_griffin_air_speed: PlutoGriffinAirSpeed + skip_dialogues: SkipDialogues + skip_tutorials: SkipTutorials + nerf_roc_wing: NerfRocWing + early_escape_item: EarlyEscapeItem + battle_arena_music: BattleArenaMusic + death_link: CVCotMDeathLink + + +cvcotm_option_groups = [ + OptionGroup("difficulty", [ + BuffRangedFamiliars, BuffSubWeapons, BuffShooterStrength, ItemDropRandomization, IgnoreCleansing, + HalveDSSCardsPlaced, SubWeaponShuffle, EarlyEscapeItem, CVCotMDeathLink]), + OptionGroup("quality of life", [ + AutoRun, DSSPatch, AlwaysAllowSpeedDash, PlutoGriffinAirSpeed, Countdown, DisableBattleArenaMPDrain, + SkipDialogues, SkipTutorials, BattleArenaMusic]) +] diff --git a/worlds/cvcotm/presets.py b/worlds/cvcotm/presets.py new file mode 100644 index 000000000000..7865935c7c7a --- /dev/null +++ b/worlds/cvcotm/presets.py @@ -0,0 +1,190 @@ +from typing import Any, Dict + +from Options import Accessibility, ProgressionBalancing +from .options import IgnoreCleansing, AutoRun, DSSPatch, AlwaysAllowSpeedDash, IronMaidenBehavior, BuffRangedFamiliars,\ + BuffSubWeapons, BuffShooterStrength, ItemDropRandomization, HalveDSSCardsPlaced, Countdown, SubWeaponShuffle,\ + DisableBattleArenaMPDrain, RequiredSkirmishes, EarlyEscapeItem, CVCotMDeathLink, CompletionGoal, SkipDialogues,\ + NerfRocWing, SkipTutorials, BattleArenaMusic, PlutoGriffinAirSpeed + +all_random_options = { + "progression_balancing": "random", + "accessibility": "random", + "ignore_cleansing": "random", + "auto_run": "random", + "dss_patch": "random", + "always_allow_speed_dash": "random", + "iron_maiden_behavior": "random", + "required_last_keys": "random", + "available_last_keys": "random", + "buff_ranged_familiars": "random", + "buff_sub_weapons": "random", + "buff_shooter_strength": "random", + "item_drop_randomization": "random", + "halve_dss_cards_placed": "random", + "countdown": "random", + "sub_weapon_shuffle": "random", + "disable_battle_arena_mp_drain": "random", + "required_skirmishes": "random", + "pluto_griffin_air_speed": "random", + "skip_dialogues": "random", + "skip_tutorials": "random", + "nerf_roc_wing": "random", + "early_escape_item": "random", + "battle_arena_music": "random", + "death_link": CVCotMDeathLink.option_off, + "completion_goal": "random", +} + +beginner_mode_options = { + "progression_balancing": ProgressionBalancing.default, + "accessibility": Accessibility.option_full, + "ignore_cleansing": IgnoreCleansing.option_false, + "auto_run": AutoRun.option_true, + "dss_patch": DSSPatch.option_true, + "always_allow_speed_dash": AlwaysAllowSpeedDash.option_true, + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + "required_last_keys": 3, + "available_last_keys": 6, + "buff_ranged_familiars": BuffRangedFamiliars.option_true, + "buff_sub_weapons": BuffSubWeapons.option_true, + "buff_shooter_strength": BuffShooterStrength.option_true, + "item_drop_randomization": ItemDropRandomization.option_normal, + "halve_dss_cards_placed": HalveDSSCardsPlaced.option_false, + "countdown": Countdown.option_majors, + "sub_weapon_shuffle": SubWeaponShuffle.option_false, + "disable_battle_arena_mp_drain": DisableBattleArenaMPDrain.option_true, + "required_skirmishes": RequiredSkirmishes.option_none, + "pluto_griffin_air_speed": PlutoGriffinAirSpeed.option_false, + "skip_dialogues": SkipDialogues.option_false, + "skip_tutorials": SkipTutorials.option_false, + "nerf_roc_wing": NerfRocWing.option_false, + "early_escape_item": EarlyEscapeItem.option_double, + "battle_arena_music": BattleArenaMusic.option_nothing, + "death_link": CVCotMDeathLink.option_off, + "completion_goal": CompletionGoal.option_dracula, +} + +standard_competitive_options = { + "progression_balancing": ProgressionBalancing.default, + "accessibility": Accessibility.option_full, + "ignore_cleansing": IgnoreCleansing.option_false, + "auto_run": AutoRun.option_false, + "dss_patch": DSSPatch.option_true, + "always_allow_speed_dash": AlwaysAllowSpeedDash.option_true, + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + "required_last_keys": 3, + "available_last_keys": 5, + "buff_ranged_familiars": BuffRangedFamiliars.option_true, + "buff_sub_weapons": BuffSubWeapons.option_true, + "buff_shooter_strength": BuffShooterStrength.option_false, + "item_drop_randomization": ItemDropRandomization.option_normal, + "halve_dss_cards_placed": HalveDSSCardsPlaced.option_true, + "countdown": Countdown.option_majors, + "sub_weapon_shuffle": SubWeaponShuffle.option_true, + "disable_battle_arena_mp_drain": DisableBattleArenaMPDrain.option_false, + "required_skirmishes": RequiredSkirmishes.option_none, + "pluto_griffin_air_speed": PlutoGriffinAirSpeed.option_false, + "skip_dialogues": SkipDialogues.option_true, + "skip_tutorials": SkipTutorials.option_true, + "nerf_roc_wing": NerfRocWing.option_false, + "early_escape_item": EarlyEscapeItem.option_double, + "battle_arena_music": BattleArenaMusic.option_nothing, + "death_link": CVCotMDeathLink.option_off, + "completion_goal": CompletionGoal.option_dracula, +} + +randomania_2023_options = { + "progression_balancing": ProgressionBalancing.default, + "accessibility": Accessibility.option_full, + "ignore_cleansing": IgnoreCleansing.option_false, + "auto_run": AutoRun.option_false, + "dss_patch": DSSPatch.option_true, + "always_allow_speed_dash": AlwaysAllowSpeedDash.option_true, + "iron_maiden_behavior": IronMaidenBehavior.option_vanilla, + "required_last_keys": 3, + "available_last_keys": 5, + "buff_ranged_familiars": BuffRangedFamiliars.option_true, + "buff_sub_weapons": BuffSubWeapons.option_true, + "buff_shooter_strength": BuffShooterStrength.option_false, + "item_drop_randomization": ItemDropRandomization.option_normal, + "halve_dss_cards_placed": HalveDSSCardsPlaced.option_false, + "countdown": Countdown.option_majors, + "sub_weapon_shuffle": SubWeaponShuffle.option_true, + "disable_battle_arena_mp_drain": DisableBattleArenaMPDrain.option_false, + "required_skirmishes": RequiredSkirmishes.option_none, + "pluto_griffin_air_speed": PlutoGriffinAirSpeed.option_false, + "skip_dialogues": SkipDialogues.option_false, + "skip_tutorials": SkipTutorials.option_false, + "nerf_roc_wing": NerfRocWing.option_false, + "early_escape_item": EarlyEscapeItem.option_double, + "battle_arena_music": BattleArenaMusic.option_nothing, + "death_link": CVCotMDeathLink.option_off, + "completion_goal": CompletionGoal.option_dracula, +} + +competitive_all_bosses_options = { + "progression_balancing": ProgressionBalancing.default, + "accessibility": Accessibility.option_full, + "ignore_cleansing": IgnoreCleansing.option_false, + "auto_run": AutoRun.option_false, + "dss_patch": DSSPatch.option_true, + "always_allow_speed_dash": AlwaysAllowSpeedDash.option_true, + "iron_maiden_behavior": IronMaidenBehavior.option_vanilla, + "required_last_keys": 8, + "available_last_keys": 8, + "buff_ranged_familiars": BuffRangedFamiliars.option_true, + "buff_sub_weapons": BuffSubWeapons.option_true, + "buff_shooter_strength": BuffShooterStrength.option_false, + "item_drop_randomization": ItemDropRandomization.option_tiered, + "halve_dss_cards_placed": HalveDSSCardsPlaced.option_true, + "countdown": Countdown.option_none, + "sub_weapon_shuffle": SubWeaponShuffle.option_true, + "disable_battle_arena_mp_drain": DisableBattleArenaMPDrain.option_false, + "required_skirmishes": RequiredSkirmishes.option_all_bosses, + "pluto_griffin_air_speed": PlutoGriffinAirSpeed.option_false, + "skip_dialogues": SkipDialogues.option_true, + "skip_tutorials": SkipTutorials.option_true, + "nerf_roc_wing": NerfRocWing.option_false, + "early_escape_item": EarlyEscapeItem.option_double, + "battle_arena_music": BattleArenaMusic.option_nothing, + "death_link": CVCotMDeathLink.option_off, + "completion_goal": CompletionGoal.option_dracula, +} + +hardcore_mode_options = { + "progression_balancing": ProgressionBalancing.default, + "accessibility": Accessibility.option_minimal, + "ignore_cleansing": IgnoreCleansing.option_true, + "auto_run": AutoRun.option_false, + "dss_patch": DSSPatch.option_true, + "always_allow_speed_dash": AlwaysAllowSpeedDash.option_false, + "iron_maiden_behavior": IronMaidenBehavior.option_vanilla, + "required_last_keys": 9, + "available_last_keys": 9, + "buff_ranged_familiars": BuffRangedFamiliars.option_false, + "buff_sub_weapons": BuffSubWeapons.option_false, + "buff_shooter_strength": BuffShooterStrength.option_false, + "item_drop_randomization": ItemDropRandomization.option_tiered, + "halve_dss_cards_placed": HalveDSSCardsPlaced.option_true, + "countdown": Countdown.option_none, + "sub_weapon_shuffle": SubWeaponShuffle.option_true, + "disable_battle_arena_mp_drain": DisableBattleArenaMPDrain.option_false, + "required_skirmishes": RequiredSkirmishes.option_none, + "pluto_griffin_air_speed": PlutoGriffinAirSpeed.option_false, + "skip_dialogues": SkipDialogues.option_false, + "skip_tutorials": SkipTutorials.option_false, + "nerf_roc_wing": NerfRocWing.option_false, + "early_escape_item": EarlyEscapeItem.option_double, + "battle_arena_music": BattleArenaMusic.option_nothing, + "death_link": CVCotMDeathLink.option_off, + "completion_goal": CompletionGoal.option_battle_arena_and_dracula, +} + +cvcotm_options_presets: Dict[str, Dict[str, Any]] = { + "All Random": all_random_options, + "Beginner Mode": beginner_mode_options, + "Standard Competitive": standard_competitive_options, + "Randomania 2023": randomania_2023_options, + "Competitive All Bosses": competitive_all_bosses_options, + "Hardcore Mode": hardcore_mode_options, +} diff --git a/worlds/cvcotm/regions.py b/worlds/cvcotm/regions.py new file mode 100644 index 000000000000..5403d12c81a3 --- /dev/null +++ b/worlds/cvcotm/regions.py @@ -0,0 +1,189 @@ +from .data import lname +from typing import Dict, List, Optional, TypedDict, Union + + +class RegionInfo(TypedDict, total=False): + locations: List[str] + entrances: Dict[str, str] + + +# # # KEY # # # +# "locations" = A list of the Locations to add to that Region when adding said Region. +# "entrances" = A dict of the connecting Regions to the Entrances' names to add to that Region when adding said Region. +cvcotm_region_info: Dict[str, RegionInfo] = { + "Catacomb": {"locations": [lname.sr3, + lname.cc1, + lname.cc3, + lname.cc3b, + lname.cc4, + lname.cc5, + lname.cc8, + lname.cc8b, + lname.cc9, + lname.cc10, + lname.cc13, + lname.cc14, + lname.cc14b, + lname.cc16, + lname.cc20, + lname.cc22, + lname.cc24, + lname.cc25], + "entrances": {"Abyss Stairway": "Catacomb to Stairway"}}, + + "Abyss Stairway": {"locations": [lname.as2, + lname.as3], + "entrances": {"Audience Room": "Stairway to Audience"}}, + + "Audience Room": {"locations": [lname.as4, + lname.as9, + lname.ar4, + lname.ar7, + lname.ar8, + lname.ar9, + lname.ar10, + lname.ar11, + lname.ar14, + lname.ar14b, + lname.ar16, + lname.ar17, + lname.ar17b, + lname.ar18, + lname.ar19, + lname.ar21, + lname.ar25, + lname.ar26, + lname.ar27, + lname.ar30, + lname.ar30b, + lname.ow0, + lname.ow1, + lname.ow2, + lname.th1, + lname.th3], + "entrances": {"Machine Tower Bottom": "Audience to Machine Bottom", + "Machine Tower Top": "Audience to Machine Top", + "Chapel Tower Bottom": "Audience to Chapel", + "Underground Gallery Lower": "Audience to Gallery", + "Underground Warehouse Start": "Audience to Warehouse", + "Underground Waterway Start": "Audience to Waterway", + "Observation Tower": "Audience to Observation", + "Ceremonial Room": "Ceremonial Door"}}, + + "Machine Tower Bottom": {"locations": [lname.mt0, + lname.mt2, + lname.mt3, + lname.mt4, + lname.mt6, + lname.mt8, + lname.mt10, + lname.mt11], + "entrances": {"Machine Tower Top": "Machine Bottom to Top"}}, + + "Machine Tower Top": {"locations": [lname.mt13, + lname.mt14, + lname.mt17, + lname.mt19]}, + + "Eternal Corridor Pit": {"locations": [lname.ec5], + "entrances": {"Underground Gallery Upper": "Corridor to Gallery", + "Chapel Tower Bottom": "Escape the Gallery Pit"}}, + + "Chapel Tower Bottom": {"locations": [lname.ec7, + lname.ec9, + lname.ct1, + lname.ct4, + lname.ct5, + lname.ct6, + lname.ct6b, + lname.ct8, + lname.ct10, + lname.ct13, + lname.ct15], + "entrances": {"Eternal Corridor Pit": "Into the Corridor Pit", + "Underground Waterway End": "Dip Into Waterway End", + "Chapel Tower Top": "Climb to Chapel Top"}}, + + "Chapel Tower Top": {"locations": [lname.ct16, + lname.ct18, + lname.ct21, + lname.ct22], + "entrances": {"Battle Arena": "Arena Passage"}}, + + "Battle Arena": {"locations": [lname.ct26, + lname.ct26b, + lname.ba24, + lname.arena_victory]}, + + "Underground Gallery Upper": {"locations": [lname.ug0, + lname.ug1, + lname.ug2, + lname.ug3, + lname.ug3b], + "entrances": {"Eternal Corridor Pit": "Gallery to Corridor", + "Underground Gallery Lower": "Gallery Upper to Lower"}}, + + "Underground Gallery Lower": {"locations": [lname.ug8, + lname.ug10, + lname.ug13, + lname.ug15, + lname.ug20], + "entrances": {"Underground Gallery Upper": "Gallery Lower to Upper"}}, + + "Underground Warehouse Start": {"locations": [lname.uw1], + "entrances": {"Underground Warehouse Main": "Into Warehouse Main"}}, + + "Underground Warehouse Main": {"locations": [lname.uw6, + lname.uw8, + lname.uw9, + lname.uw10, + lname.uw11, + lname.uw14, + lname.uw16, + lname.uw16b, + lname.uw19, + lname.uw23, + lname.uw24, + lname.uw25]}, + + "Underground Waterway Start": {"locations": [lname.uy1], + "entrances": {"Underground Waterway Main": "Into Waterway Main"}}, + + "Underground Waterway Main": {"locations": [lname.uy3, + lname.uy3b, + lname.uy4, + lname.uy5, + lname.uy7, + lname.uy8, + lname.uy9, + lname.uy9b, + lname.uy12], + "entrances": {"Underground Waterway End": "Onward to Waterway End"}}, + + "Underground Waterway End": {"locations": [lname.uy12b, + lname.uy13, + lname.uy17, + lname.uy18]}, + + "Observation Tower": {"locations": [lname.ot1, + lname.ot2, + lname.ot3, + lname.ot5, + lname.ot8, + lname.ot9, + lname.ot12, + lname.ot13, + lname.ot16, + lname.ot20]}, + + "Ceremonial Room": {"locations": [lname.cr1, + lname.dracula]}, +} + + +def get_region_info(region: str, info: str) -> Optional[Union[List[str], Dict[str, str]]]: + return cvcotm_region_info[region].get(info, None) + + +def get_all_region_names() -> List[str]: + return [reg_name for reg_name in cvcotm_region_info] diff --git a/worlds/cvcotm/rom.py b/worlds/cvcotm/rom.py new file mode 100644 index 000000000000..e7b0710d134e --- /dev/null +++ b/worlds/cvcotm/rom.py @@ -0,0 +1,600 @@ + +import Utils +import logging +import json + +from worlds.Files import APProcedurePatch, APTokenMixin, APTokenTypes, APPatchExtension +from typing import Dict, Optional, Collection, TYPE_CHECKING + +import hashlib +import os +import pkgutil + +from .data import patches +from .locations import cvcotm_location_info +from .cvcotm_text import cvcotm_string_to_bytearray +from .options import CompletionGoal, IronMaidenBehavior, RequiredSkirmishes +from .lz10 import decompress +from settings import get_settings + +if TYPE_CHECKING: + from . import CVCotMWorld + +CVCOTM_CT_US_HASH = "50a1089600603a94e15ecf287f8d5a1f" # Original GBA cartridge ROM +CVCOTM_AC_US_HASH = "87a1bd6577b6702f97a60fc55772ad74" # Castlevania Advance Collection ROM +CVCOTM_VC_US_HASH = "2cc38305f62b337281663bad8c901cf9" # Wii U Virtual Console ROM + +# NOTE: The Wii U VC version is untested as of when this comment was written. I am only including its hash in case it +# does work. If someone who has it can confirm it does indeed work, this comment should be removed. If it doesn't, the +# hash should be removed in addition. See the Game Page for more information about supported versions. + +ARCHIPELAGO_IDENTIFIER_START = 0x7FFF00 +ARCHIPELAGO_IDENTIFIER = "ARCHIPELAG03" +AUTH_NUMBER_START = 0x7FFF10 +QUEUED_TEXT_STRING_START = 0x7CEB00 +MULTIWORLD_TEXTBOX_POINTERS_START = 0x671C10 + +BATTLE_ARENA_SONG_IDS = [0x01, 0x03, 0x12, 0x06, 0x08, 0x09, 0x07, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x13, 0x14] + + +class RomData: + def __init__(self, file: bytes, name: Optional[str] = None) -> None: + self.file = bytearray(file) + self.name = name + + def read_byte(self, offset: int) -> int: + return self.file[offset] + + def read_bytes(self, offset: int, length: int) -> bytes: + return self.file[offset:offset + length] + + def write_byte(self, offset: int, value: int) -> None: + self.file[offset] = value + + def write_bytes(self, offset: int, values: Collection[int]) -> None: + self.file[offset:offset + len(values)] = values + + def get_bytes(self) -> bytes: + return bytes(self.file) + + def apply_ips(self, filename: str) -> None: + # Try loading the IPS file. + try: + ips_file = pkgutil.get_data(__name__, "data/ips/" + filename) + except IOError: + raise Exception(f"{filename} is not present in the ips folder. If it was removed, please replace it.") + + # Verify that the IPS patch is, indeed, an IPS patch. + if ips_file[0:5].decode("ascii") != "PATCH": + logging.error(filename + " does not appear to be an IPS patch...") + return + + file_pos = 5 + while True: + # Get the ROM offset bytes of the current record. + rom_offset = int.from_bytes(ips_file[file_pos:file_pos + 3], "big") + + # If we've hit the "EOF" codeword (aka 0x454F46), stop iterating because we've reached the end of the patch. + if rom_offset == 0x454F46: + return + + # Get the size bytes of the current record. + bytes_size = int.from_bytes(ips_file[file_pos + 3:file_pos + 5], "big") + + if bytes_size != 0: + # Write the bytes to the ROM. + self.write_bytes(rom_offset, ips_file[file_pos + 5:file_pos + 5 + bytes_size]) + + # Increase our position in the IPS patch to the start of the next record. + file_pos += 5 + bytes_size + else: + # If the size is 0, we are looking at an RLE record. + # Get the size of the RLE. + rle_size = int.from_bytes(ips_file[file_pos + 5:file_pos + 7], "big") + + # Get the byte to be written over and over. + rle_byte = int.from_bytes(ips_file[file_pos + 7:file_pos + 8], "big") + + # Write the RLE byte to the ROM the RLE size times over. + self.write_bytes(rom_offset, [rle_byte for _ in range(rle_size)]) + + # Increase our position in the IPS patch to the start of the next record. + file_pos += 8 + + +class CVCotMPatchExtensions(APPatchExtension): + game = "Castlevania - Circle of the Moon" + + @staticmethod + def apply_patches(caller: APProcedurePatch, rom: bytes, options_file: str) -> bytes: + """Applies every patch to mod the game into its rando state, both CotMR's pre-made IPS patches and some + additional byte writes. Each patch is credited to its author.""" + + rom_data = RomData(rom) + options = json.loads(caller.get_file(options_file).decode("utf-8")) + + # Check to see if the patch was generated on a compatible APWorld version. + if "compat_identifier" not in options: + raise Exception("Incompatible patch/APWorld version. Make sure the Circle of the Moon APWorlds of both you " + "and the person who generated are matching (and preferably up-to-date).") + if options["compat_identifier"] != ARCHIPELAGO_IDENTIFIER: + raise Exception("Incompatible patch/APWorld version. Make sure the Circle of the Moon APWorlds of both you " + "and the person who generated are matching (and preferably up-to-date).") + + # This patch allows placing DSS cards on pedestals, prevents them from timing out, and removes them from enemy + # drop tables. Created by DevAnj originally as a standalone hack known as Card Mode, it has been modified for + # this randomizer's purposes by stripping out additional things like drop and pedestal item replacements. + + # Further modified by Liquid Cat to make placed cards set their flags upon pickup (instead of relying on whether + # the card is in the player's inventory when determining to spawn it or not), enable placing dummy DSS Cards to + # represent other players' Cards in a multiworld setting, and turn specific cards blue to visually indicate + # their status as valid ice/stone combo cards. + rom_data.apply_ips("CardUp_v3_Custom2.ips") + + # This patch replaces enemy drops that included DSS cards. Created by DevAnj as part of the Card Up patch but + # modified for different replacement drops (Lowered rate, Potion instead of Meat, and no Shinning Armor change + # on Devil). + rom_data.apply_ips("NoDSSDrops.ips") + + # This patch reveals card combination descriptions instead of showing "???" until the combination is used. + # Created by DevAnj. + rom_data.apply_ips("CardCombosRevealed.ips") + + # In lategame, the Trick Candle and Scary Candle load in the Cerberus and Iron Golem boss rooms after defeating + # Camilla and Twin Dragon Zombies respectively. If the former bosses have not yet been cleared (i.e., we have + # sequence broken the game and returned to the earlier boss rooms to fight them), the candle enemies will cause + # the bosses to fail to load and soft lock the game. This patches the candles to appear after the early boss is + # completed instead. + # Created by DevAnj. + rom_data.apply_ips("CandleFix.ips") + + # A Tackle block in Machine Tower will cause a softlock if you access the Machine Tower from the Audience Room + # using the stone tower route with Kick Boots and not Double. This is a small level edit that moves that block + # slightly, removing the potential for a softlock. + # Created by DevAnj. + rom_data.apply_ips("SoftlockBlockFix.ips") + + # Normally, the MP boosting card combination is useless since it depletes more MP than it gains. This patch + # makes it consume zero MP. + # Created by DevAnj. + rom_data.apply_ips("MPComboFix.ips") + + # Normally, you must clear the game with each mode to unlock subsequent modes, and complete the game at least + # once to be able to skip the introductory text crawl. This allows all game modes to be selected and the + # introduction to be skipped even without game/mode completion. + # Created by DevAnj. + rom_data.apply_ips("GameClearBypass.ips") + + # This patch adds custom mapping in Underground Gallery and Underground Waterway to avoid softlocking/Kick Boots + # requirements. + # Created by DevAnj. + rom_data.apply_ips("MapEdits.ips") + + # Prevents demos on the main title screen after the first one from being displayed to avoid pedestal item + # reconnaissance from the menu. + # Created by Fusecavator. + rom_data.apply_ips("DemoForceFirst.ips") + + # Used internally in the item randomizer to allow setting drop rate to 10000 (100%) and actually drop the item + # 100% of the time. Normally, it is hard capped at 50% for common drops and 25% for rare drops. + # Created by Fusecavator. + rom_data.apply_ips("AllowAlwaysDrop.ips") + + # Displays the seed on the pause menu. Originally created by Fusecavator and modified by Liquid Cat to display a + # 20-digit seed (which AP seeds most commonly are). + rom_data.apply_ips("SeedDisplay20Digits.ips") + + # Write the seed. Upwards of 20 digits can be displayed for the seed number. + curr_seed_addr = 0x672152 + total_digits = 0 + while options["seed"] and total_digits < 20: + seed_digit = (options["seed"] % 10) + 0x511C + rom_data.write_bytes(curr_seed_addr, int.to_bytes(seed_digit, 2, "little")) + curr_seed_addr -= 2 + total_digits += 1 + options["seed"] //= 10 + + # Optional patch created by Fusecavator. Permanent dash effect without double tapping. + if options["auto_run"]: + rom_data.apply_ips("PermanentDash.ips") + + # Optional patch created by Fusecavator. Prohibits the DSS glitch. You will not be able to update the active + # effect unless the card combination switched to is obtained. For example, if you switch to another DSS + # combination that you have not obtained during DSS startup, you will still have the effect of the original + # combination you had selected when you started the DSS activation. In addition, you will not be able to + # increase damage and/or change the element of a summon attack unless you possess the cards you swap to. + if options["dss_patch"]: + rom_data.apply_ips("DSSGlitchFix.ips") + + # Optional patch created by DevAnj. Breaks the iron maidens blocking access to the Underground Waterway, + # Underground Gallery, and the room beyond the Adramelech boss room from the beginning of the game. + if options["break_iron_maidens"]: + rom_data.apply_ips("BrokenMaidens.ips") + + # Optional patch created by Fusecavator. Changes game behavior to add instead of set Last Key values, and check + # for a specific value of Last Keys on the door to the Ceremonial Room, allowing multiple keys to be required to + # complete the game. Relies on the program to set required key values. + if options["required_last_keys"] != 1: + rom_data.apply_ips("MultiLastKey.ips") + rom_data.write_byte(0x96C1E, options["required_last_keys"]) + rom_data.write_byte(0xDFB4, options["required_last_keys"]) + rom_data.write_byte(0xCB84, options["required_last_keys"]) + + # Optional patch created by Fusecavator. Doubles the damage dealt by projectiles fired by ranged familiars. + if options["buff_ranged_familiars"]: + rom_data.apply_ips("BuffFamiliars.ips") + + # Optional patch created by Fusecavator. Increases the base damage dealt by some sub-weapons. + # Changes below (normal multiplier on left/shooter on right): + # Original: Changed: + # Dagger: 45 / 141 ----> 100 / 141 (Non-Shooter buffed) + # Dagger crush: 32 / 45 ----> 100 / 141 (Both buffed to match non-crush values) + # Axe: 89 / 158 ----> 125 / 158 (Non-Shooter somewhat buffed) + # Axe crush: 89 / 126 ----> 125 / 158 (Both buffed to match non-crush values) + # Holy water: 63 / 100 ----> 63 / 100 (Unchanged) + # Holy water crush: 45 / 63 ----> 63 / 100 (Large buff to Shooter, non-Shooter slightly buffed) + # Cross: 110 / 173 ----> 110 / 173 (Unchanged) + # Cross crush: 100 / 141 ----> 110 / 173 (Slightly buffed to match non-crush values) + if options["buff_sub_weapons"]: + rom_data.apply_ips("BuffSubweapons.ips") + + # Optional patch created by Fusecavator. Increases the Shooter gamemode base strength and strength per level to + # match Vampire Killer. + if options["buff_shooter_strength"]: + rom_data.apply_ips("ShooterStrength.ips") + + # Optional patch created by Fusecavator. Allows using the Pluto + Griffin combination for the speed boost with + # or without the cards being obtained. + if options["always_allow_speed_dash"]: + rom_data.apply_ips("AllowSpeedDash.ips") + + # Optional patch created by fuse. Displays a counter on the HUD showing the number of magic items and cards + # remaining in the current area. Requires a lookup table generated by the randomizer to function. + if options["countdown"]: + rom_data.apply_ips("Countdown.ips") + + # This patch disables the MP drain effect in the Battle Arena. + # Created by Fusecavator. + if options["disable_battle_arena_mp_drain"]: + rom_data.apply_ips("NoMPDrain.ips") + + # Patch created by Fusecavator. Makes various changes to dropped item graphics to avoid garbled Magic Items and + # allow displaying arbitrary items on pedestals. Modified by Liquid Cat for the purposes of changing the + # appearances of items regardless of what they really are, as well as allowing additional Magic Items. + rom_data.apply_ips("DropReworkMultiEdition.ips") + # Decompress the Magic Item graphics and reinsert them (decompressed) where the patch expects them. + # Doing it this way is more copyright-safe. + rom_data.write_bytes(0x678C00, decompress(rom_data.read_bytes(0x630690, 0x605))[0x300:]) + + # Everything past here was added by Liquid Cat. + + # Makes the Pluto + Griffin speed increase apply even while in the air, instead of losing it. + if options["pluto_griffin_air_speed"]: + rom_data.apply_ips("DSSRunSpeed.ips") + + # Move the item sprite info table. + rom_data.write_bytes(0x678A00, rom_data.read_bytes(0x630B98, 0x98)) + # Update the ldr numbers pointing to the above item sprite table. + rom_data.write_bytes(0x95A08, [0x00, 0x8A, 0x67, 0x08]) + rom_data.write_bytes(0x100380, [0x00, 0x8A, 0x67, 0x08]) + # Move the magic item text ID table. + rom_data.write_bytes(0x6788B0, rom_data.read_bytes(0x100A7E, 0x48)) + # Update the ldr numbers pointing to the above magic item text ID table. + rom_data.write_bytes(0x95C10, [0xB0, 0x88, 0x67, 0x08]) + rom_data.write_bytes(0x95CE0, [0xB0, 0x88, 0x67, 0x08]) + # Move the magic item pickup function jump table. + rom_data.write_bytes(0x678B20, rom_data.read_bytes(0x95B80, 0x24)) + # Update the ldr number point to the above jump table. + rom_data.write_bytes(0x95B7C, [0x20, 0x8B, 0x67, 0x08]) + rom_data.write_byte(0x95B6A, 0x09) # Raise the magic item function index limit. + + # Make the Maiden Detonator detonate the maidens when picked up. + rom_data.write_bytes(0x678B44, [0x90, 0x1F, 0x67, 0x08]) + rom_data.write_bytes(0x671F90, patches.maiden_detonator) + # Add the text for detonating the maidens. + rom_data.write_bytes(0x671C0C, [0xC0, 0x1F, 0x67, 0x08]) + rom_data.write_bytes(0x671FC0, cvcotm_string_to_bytearray(" 「Iron Maidens」 broken◊", "little middle", 0, + wrap=False)) + + # Put the new text string IDs for all our new items. + rom_data.write_bytes(0x6788F8, [0xF1, 0x84, 0xF1, 0x84, 0xF1, 0x84, 0xF1, 0x84, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]) + # Have the game get the entry in that table to use by adding the item's parameter. + rom_data.write_bytes(0x95980, [0x0A, 0x30, 0x00, 0x00, 0x00, 0x00]) + # Add the AP Item sprites and their associated info. + rom_data.write_bytes(0x679080, patches.extra_item_sprites) + rom_data.write_bytes(0x678A98, [0xF8, 0xFF, 0xF8, 0xFF, 0xFC, 0x21, 0x45, 0x00, + 0xF8, 0xFF, 0xF8, 0xFF, 0x00, 0x22, 0x45, 0x00, + 0xF8, 0xFF, 0xF8, 0xFF, 0x04, 0x22, 0x45, 0x00, + 0xF8, 0xFF, 0xF8, 0xFF, 0x08, 0x22, 0x45, 0x00, + 0xF8, 0xFF, 0xF8, 0xFF, 0x0C, 0x22, 0x45, 0x00, + 0xF8, 0xFF, 0xF8, 0xFF, 0x10, 0x22, 0x45, 0x00, + 0xF8, 0xFF, 0xF8, 0xFF, 0x14, 0x32, 0x45, 0x00]) + # Enable changing the Magic Item appearance separately from what it really is. + # Change these ldrh's to ldrb's to read only the high or low byte of the object list entry's parameter field. + rom_data.write_bytes(0x9597A, [0xC1, 0x79]) + rom_data.write_bytes(0x95B64, [0x80, 0x79]) + rom_data.write_bytes(0x95BF0, [0x81, 0x79]) + rom_data.write_bytes(0x95CBE, [0x82, 0x79]) + # Enable changing the Max Up appearance separately from what it really is. + rom_data.write_bytes(0x5DE98, [0xC1, 0x79]) + rom_data.write_byte(0x5E152, 0x13) + rom_data.write_byte(0x5E15C, 0x0E) + rom_data.write_byte(0x5E20A, 0x0B) + + # Set the 0xF0 flag on the iron maiden switch if we're placing an Item on it. + if options["iron_maiden_behavior"] == IronMaidenBehavior.option_detonator_in_pool: + rom_data.write_byte(0xD47B4, 0xF0) + + if options["nerf_roc_wing"]: + # Prevent Roc jumping in midair if the Double is not in the player's inventory. + rom_data.write_bytes(0x6B8A0, [0x00, 0x4A, 0x97, 0x46, 0x00, 0x9A, 0x67, 0x08]) + rom_data.write_bytes(0x679A00, patches.doubleless_roc_midairs_preventer) + + # Make Roc Wing not jump as high if Kick Boots isn't in the inventory. + rom_data.write_bytes(0x6B8B4, [0x00, 0x49, 0x8F, 0x46, 0x60, 0x9A, 0x67, 0x08]) + rom_data.write_bytes(0x679A60, patches.kickless_roc_height_shortener) + + # Give the player their Start Inventory upon entering their name on a new file. + rom_data.write_bytes(0x7F70, [0x00, 0x48, 0x87, 0x46, 0x00, 0x00, 0x68, 0x08]) + rom_data.write_bytes(0x680000, patches.start_inventory_giver) + + # Prevent Max Ups from exceeding 255. + rom_data.write_bytes(0x5E170, [0x00, 0x4A, 0x97, 0x46, 0x00, 0x00, 0x6A, 0x08]) + rom_data.write_bytes(0x6A0000, patches.max_max_up_checker) + + # Write the textbox messaging system code. + rom_data.write_bytes(0x7D60, [0x00, 0x48, 0x87, 0x46, 0x20, 0xFF, 0x7F, 0x08]) + rom_data.write_bytes(0x7FFF20, patches.remote_textbox_shower) + + # Write the code that sets the screen transition delay timer. + rom_data.write_bytes(0x6CE14, [0x00, 0x4A, 0x97, 0x46, 0xC0, 0xFF, 0x7F, 0x08]) + rom_data.write_bytes(0x7FFFC0, patches.transition_textbox_delayer) + + # Write the code that allows any sound to be played with any Magic Item. + rom_data.write_bytes(0x95BE4, [0x00, 0x4A, 0x97, 0x46, 0x00, 0x98, 0x67, 0x08]) + rom_data.write_bytes(0x679800, patches.magic_item_sfx_customizer) + # Array of sound IDs for each Magic Item. + rom_data.write_bytes(0x6797C0, [0xB4, 0x01, 0xB4, 0x01, 0xB4, 0x01, 0xB4, 0x01, 0xB4, 0x01, 0xB4, 0x01, + 0xB4, 0x01, 0xB4, 0x01, 0xB4, 0x01, 0x79, 0x00]) + + # Write all the data for the missing ASCII text characters. + for offset, data in patches.missing_char_data.items(): + rom_data.write_bytes(offset, data) + + # Change all the menu item name strings that use the overwritten character IDs to use a different, equivalent + # space character ID. + rom_data.write_bytes(0x391A1B, [0xAD, 0xAD, 0xAD, 0xAD, 0xAD, 0xAD]) + rom_data.write_bytes(0x391CB6, [0xAD, 0xAD, 0xAD]) + rom_data.write_bytes(0x391CC1, [0xAD, 0xAD, 0xAD]) + rom_data.write_bytes(0x391CCB, [0xAD, 0xAD, 0xAD, 0xAD]) + rom_data.write_bytes(0x391CD5, [0xAD, 0xAD, 0xAD, 0xAD, 0xAD]) + rom_data.write_byte(0x391CE1, 0xAD) + + # Put the unused bottom-of-screen textbox in the middle of the screen instead. + # Its background's new y position will be 0x28 instead of 0x50. + rom_data.write_byte(0xBEDEA, 0x28) + # Change all the hardcoded checks for the 0x50 position to instead check for 0x28. + rom_data.write_byte(0xBF398, 0x28) + rom_data.write_byte(0xBF41C, 0x28) + rom_data.write_byte(0xBF4CC, 0x28) + # Change all the hardcoded checks for greater than 0x48 to instead check for 0x28 specifically. + rom_data.write_byte(0xBF4A4, 0x28) + rom_data.write_byte(0xBF4A7, 0xD0) + rom_data.write_byte(0xBF37E, 0x28) + rom_data.write_byte(0xBF381, 0xD0) + rom_data.write_byte(0xBF40A, 0x28) + rom_data.write_byte(0xBF40D, 0xD0) + # Change the y position of the contents within the textbox from 0xA0 to 0xB4. + # KCEK didn't program hardcoded checks for these, thankfully! + rom_data.write_byte(0xBF3BC, 0xB4) + + # Insert the multiworld message pointer at the end of the text pointers. + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START, int.to_bytes(QUEUED_TEXT_STRING_START + 0x8000000, + 4, "little")) + # Insert pointers for every item tutorial. + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 4, [0x8E, 0x3B, 0x39, 0x08]) + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 8, [0xDF, 0x3B, 0x39, 0x08]) + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 12, [0x35, 0x3C, 0x39, 0x08]) + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 16, [0xC4, 0x3C, 0x39, 0x08]) + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 20, [0x41, 0x3D, 0x39, 0x08]) + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 24, [0x88, 0x3D, 0x39, 0x08]) + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 28, [0xF7, 0x3D, 0x39, 0x08]) + rom_data.write_bytes(MULTIWORLD_TEXTBOX_POINTERS_START + 32, [0x67, 0x3E, 0x39, 0x08]) + + # Write the completion goal messages over the menu Dash Boots tutorial and Battle Arena's explanation message. + if options["completion_goal"] == CompletionGoal.option_dracula: + dash_tutorial_message = "Your goal is:\n Dracula◊" + if options["required_skirmishes"] == RequiredSkirmishes.option_all_bosses_and_arena: + arena_goal_message = "Your goal is:\n「Dracula」▶" \ + "A required 「Last Key」 is waiting for you at the end of the Arena. Good luck!◊" + else: + arena_goal_message = "Your goal is:\n「Dracula」▶" \ + "You don't have to win the Arena, but you are certainly welcome to try!◊" + elif options["completion_goal"] == CompletionGoal.option_battle_arena: + dash_tutorial_message = "Your goal is:\n Battle Arena◊" + arena_goal_message = "Your goal is:\n「Battle Arena」▶" \ + "Win the Arena, and your goal will send. Good luck!◊" + else: + dash_tutorial_message = "Your goal is:\n Arena and Dracula◊" + arena_goal_message = "Your goal is:\n「Battle Arena & Dracula」▶" \ + "Your goal will send once you've both won the Arena and beaten Dracula. Good luck!◊" + + rom_data.write_bytes(0x393EAE, cvcotm_string_to_bytearray(dash_tutorial_message, "big top", 4, + skip_textbox_controllers=True)) + rom_data.write_bytes(0x393A0C, cvcotm_string_to_bytearray(arena_goal_message, "big top", 4)) + + # Change the pointer to the Ceremonial Room locked door text. + rom_data.write_bytes(0x670D94, [0xE0, 0xE9, 0x7C, 0x08]) + # Write the Ceremonial Room door and menu Last Key tutorial messages telling the player's Last Key options. + door_message = f"Hmmmmmm...\nI need 「{options['required_last_keys']}」/" \ + f"「{options['available_last_keys']}」 Last Keys.◊" + key_tutorial_message = f"You need {options['required_last_keys']}/{options['available_last_keys']} keys.◊" + rom_data.write_bytes(0x7CE9E0, cvcotm_string_to_bytearray(door_message, "big top", 4, 0)) + rom_data.write_bytes(0x394098, cvcotm_string_to_bytearray(key_tutorial_message, "big top", 4, + skip_textbox_controllers=True)) + + # Nuke all the tutorial-related text if Skip Tutorials is enabled. + if options["skip_tutorials"]: + rom_data.write_byte(0x5EB55, 0xE0) # DSS + rom_data.write_byte(0x393B8C, 0x00) # Dash Boots + rom_data.write_byte(0x393BDD, 0x00) # Double + rom_data.write_byte(0x393C33, 0x00) # Tackle + rom_data.write_byte(0x393CC2, 0x00) # Kick Boots + rom_data.write_byte(0x393D41, 0x00) # Heavy Ring + rom_data.write_byte(0x393D86, 0x00) # Cleansing + rom_data.write_byte(0x393DF5, 0x00) # Roc Wing + rom_data.write_byte(0x393E65, 0x00) # Last Key + + # Nuke all the cutscene dialogue before the ending if Skip Dialogues is enabled. + if options["skip_dialogues"]: + rom_data.write_byte(0x392372, 0x00) + rom_data.write_bytes(0x3923C9, [0x20, 0x80, 0x00]) + rom_data.write_bytes(0x3924EE, [0x20, 0x81, 0x00]) + rom_data.write_byte(0x392621, 0x00) + rom_data.write_bytes(0x392650, [0x20, 0x81, 0x00]) + rom_data.write_byte(0x392740, 0x00) + rom_data.write_byte(0x3933C8, 0x00) + rom_data.write_byte(0x39346E, 0x00) + rom_data.write_byte(0x393670, 0x00) + rom_data.write_bytes(0x393698, [0x20, 0x80, 0x00]) + rom_data.write_byte(0x3936A6, 0x00) + rom_data.write_byte(0x393741, 0x00) + rom_data.write_byte(0x392944, 0x00) + rom_data.write_byte(0x392FFB, 0x00) + rom_data.write_byte(0x39305D, 0x00) + rom_data.write_byte(0x393114, 0x00) + rom_data.write_byte(0x392771, 0x00) + rom_data.write_byte(0x3928E9, 0x00) + rom_data.write_byte(0x392A3C, 0x00) + rom_data.write_byte(0x392A55, 0x00) + rom_data.write_byte(0x392A8B, 0x00) + rom_data.write_byte(0x392AA4, 0x00) + rom_data.write_byte(0x392AF4, 0x00) + rom_data.write_byte(0x392B3F, 0x00) + rom_data.write_byte(0x392C4D, 0x00) + rom_data.write_byte(0x392DEA, 0x00) + rom_data.write_byte(0x392E65, 0x00) + rom_data.write_byte(0x392F09, 0x00) + rom_data.write_byte(0x392FE4, 0x00) + + # Make the Battle Arena play the player's chosen track. + if options["battle_arena_music"]: + arena_track_id = BATTLE_ARENA_SONG_IDS[options["battle_arena_music"] - 1] + rom_data.write_bytes(0xEDEF0, [0xFC, 0xFF, arena_track_id]) + rom_data.write_bytes(0xEFA50, [0xFC, 0xFF, arena_track_id]) + rom_data.write_bytes(0xF24F0, [0xFC, 0xFF, arena_track_id]) + rom_data.write_bytes(0xF3420, [0xF5, 0xFF]) + rom_data.write_bytes(0xF3430, [0xFC, 0xFF, arena_track_id]) + + return rom_data.get_bytes() + + @staticmethod + def fix_item_positions(caller: APProcedurePatch, rom: bytes) -> bytes: + """After writing all the items into the ROM via token application, translates Magic Items in non-Magic Item + Locations up by 8 units and the reverse down by 8 units. This is necessary for them to look properly placed, + as Magic Items are offset differently on the Y axis from the other item types.""" + rom_data = RomData(rom) + for loc in cvcotm_location_info: + offset = cvcotm_location_info[loc].offset + if offset is None: + continue + item_type = rom_data.read_byte(offset) + + # Magic Items in non-Magic Item Locations should have their Y position decreased by 8. + if item_type == 0xE8 and cvcotm_location_info[loc].type not in ["magic item", "boss"]: + y_pos = int.from_bytes(rom_data.read_bytes(offset-2, 2), "little") + y_pos -= 8 + rom_data.write_bytes(offset-2, int.to_bytes(y_pos, 2, "little")) + + # Non-Magic Items in Magic Item Locations should have their Y position increased by 8. + if item_type != 0xE8 and cvcotm_location_info[loc].type in ["magic item", "boss"]: + y_pos = int.from_bytes(rom_data.read_bytes(offset - 2, 2), "little") + y_pos += 8 + rom_data.write_bytes(offset - 2, int.to_bytes(y_pos, 2, "little")) + + return rom_data.get_bytes() + + +class CVCotMProcedurePatch(APProcedurePatch, APTokenMixin): + hash = [CVCOTM_CT_US_HASH, CVCOTM_AC_US_HASH, CVCOTM_VC_US_HASH] + patch_file_ending: str = ".apcvcotm" + result_file_ending: str = ".gba" + + game = "Castlevania - Circle of the Moon" + + procedure = [ + ("apply_patches", ["options.json"]), + ("apply_tokens", ["token_data.bin"]), + ("fix_item_positions", []) + ] + + @classmethod + def get_source_data(cls) -> bytes: + return get_base_rom_bytes() + + +def patch_rom(world: "CVCotMWorld", patch: CVCotMProcedurePatch, offset_data: Dict[int, bytes], + start_with_detonator: bool) -> None: + + # Write all the new item values + for offset, data in offset_data.items(): + patch.write_token(APTokenTypes.WRITE, offset, data) + + # Write the secondary name the client will use to distinguish a vanilla ROM from an AP one. + patch.write_token(APTokenTypes.WRITE, ARCHIPELAGO_IDENTIFIER_START, ARCHIPELAGO_IDENTIFIER.encode("utf-8")) + # Write the slot authentication + patch.write_token(APTokenTypes.WRITE, AUTH_NUMBER_START, bytes(world.auth)) + + patch.write_file("token_data.bin", patch.get_token_binary()) + + # Write these slot options to a JSON. + options_dict = { + "auto_run": world.options.auto_run.value, + "dss_patch": world.options.dss_patch.value, + "break_iron_maidens": start_with_detonator, + "iron_maiden_behavior": world.options.iron_maiden_behavior.value, + "required_last_keys": world.required_last_keys, + "available_last_keys": world.options.available_last_keys.value, + "required_skirmishes": world.options.required_skirmishes.value, + "buff_ranged_familiars": world.options.buff_ranged_familiars.value, + "buff_sub_weapons": world.options.buff_sub_weapons.value, + "buff_shooter_strength": world.options.buff_shooter_strength.value, + "always_allow_speed_dash": world.options.always_allow_speed_dash.value, + "countdown": world.options.countdown.value, + "disable_battle_arena_mp_drain": world.options.disable_battle_arena_mp_drain.value, + "completion_goal": world.options.completion_goal.value, + "skip_dialogues": world.options.skip_dialogues.value, + "skip_tutorials": world.options.skip_tutorials.value, + "nerf_roc_wing": world.options.nerf_roc_wing.value, + "pluto_griffin_air_speed": world.options.pluto_griffin_air_speed.value, + "battle_arena_music": world.options.battle_arena_music.value, + "seed": world.multiworld.seed, + "compat_identifier": ARCHIPELAGO_IDENTIFIER + } + + patch.write_file("options.json", json.dumps(options_dict).encode('utf-8')) + + +def get_base_rom_bytes(file_name: str = "") -> bytes: + base_rom_bytes = getattr(get_base_rom_bytes, "base_rom_bytes", None) + if not base_rom_bytes: + file_name = get_base_rom_path(file_name) + base_rom_bytes = bytes(open(file_name, "rb").read()) + + basemd5 = hashlib.md5() + basemd5.update(base_rom_bytes) + if basemd5.hexdigest() not in [CVCOTM_CT_US_HASH, CVCOTM_AC_US_HASH, CVCOTM_VC_US_HASH]: + raise Exception("Supplied Base ROM does not match known MD5s for Castlevania: Circle of the Moon USA." + "Get the correct game and version, then dump it.") + setattr(get_base_rom_bytes, "base_rom_bytes", base_rom_bytes) + return base_rom_bytes + + +def get_base_rom_path(file_name: str = "") -> str: + if not file_name: + file_name = get_settings()["cvcotm_options"]["rom_file"] + if not os.path.exists(file_name): + file_name = Utils.user_path(file_name) + return file_name diff --git a/worlds/cvcotm/rules.py b/worlds/cvcotm/rules.py new file mode 100644 index 000000000000..01c240418804 --- /dev/null +++ b/worlds/cvcotm/rules.py @@ -0,0 +1,203 @@ +from typing import Dict, TYPE_CHECKING + +from BaseClasses import CollectionState +from worlds.generic.Rules import CollectionRule +from .data import iname, lname +from .options import CompletionGoal, IronMaidenBehavior + +if TYPE_CHECKING: + from . import CVCotMWorld + + +class CVCotMRules: + player: int + world: "CVCotMWorld" + rules: Dict[str, CollectionRule] + required_last_keys: int + iron_maiden_behavior: int + nerf_roc_wing: int + ignore_cleansing: int + completion_goal: int + + def __init__(self, world: "CVCotMWorld") -> None: + self.player = world.player + self.world = world + self.required_last_keys = world.required_last_keys + self.iron_maiden_behavior = world.options.iron_maiden_behavior.value + self.nerf_roc_wing = world.options.nerf_roc_wing.value + self.ignore_cleansing = world.options.ignore_cleansing.value + self.completion_goal = world.options.completion_goal.value + + self.location_rules = { + # Sealed Room + lname.sr3: self.has_jump_level_5, + # Catacomb + lname.cc1: self.has_push, + lname.cc3: self.has_jump_level_1, + lname.cc3b: lambda state: + (self.has_jump_level_1(state) and self.has_ice_or_stone(state)) or self.has_jump_level_4(state), + lname.cc5: self.has_tackle, + lname.cc8b: lambda state: self.has_jump_level_3(state) or self.has_kick(state), + lname.cc14b: lambda state: self.has_jump_level_1(state) or self.has_kick(state), + lname.cc25: self.has_jump_level_1, + # Abyss Staircase + lname.as4: self.has_jump_level_4, + # Audience Room + lname.ar9: self.has_push, + lname.ar11: self.has_tackle, + lname.ar14b: self.has_jump_level_4, + lname.ar17b: lambda state: self.has_jump_level_2(state) or self.has_kick(state), + lname.ar19: lambda state: self.has_jump_level_2(state) or self.has_kick(state), + lname.ar26: lambda state: self.has_tackle(state) and self.has_jump_level_5(state), + lname.ar27: lambda state: self.has_tackle(state) and self.has_push(state), + lname.ar30: lambda state: + (self.has_jump_level_3(state) and self.has_ice_or_stone(state)) or self.has_jump_level_4(state), + lname.ar30b: lambda state: + (self.has_jump_level_3(state) and self.has_ice_or_stone(state)) or self.has_jump_level_4(state), + # Outer Wall + lname.ow0: self.has_jump_level_4, + lname.ow1: lambda state: self.has_jump_level_5(state) or self.has_ice_or_stone(state), + # Triumph Hallway + lname.th3: lambda state: + (self.has_kick(state) and self.has_ice_or_stone(state)) or self.has_jump_level_2(state), + # Machine Tower + lname.mt3: lambda state: self.has_jump_level_2(state) or self.has_kick(state), + lname.mt6: lambda state: self.has_jump_level_2(state) or self.has_kick(state), + lname.mt14: self.has_tackle, + # Chapel Tower + lname.ct1: lambda state: self.has_jump_level_2(state) or self.has_ice_or_stone(state), + lname.ct4: self.has_push, + lname.ct10: self.has_push, + lname.ct13: lambda state: self.has_jump_level_2(state) or self.has_ice_or_stone(state), + lname.ct22: self.broke_iron_maidens, + lname.ct26: lambda state: + (self.has_jump_level_3(state) and self.has_ice_or_stone(state)) or self.has_jump_level_4(state), + lname.ct26b: lambda state: + (self.has_jump_level_3(state) and self.has_ice_or_stone(state)) or self.has_jump_level_4(state), + # Underground Gallery + lname.ug1: self.has_push, + lname.ug2: self.has_push, + lname.ug3: lambda state: self.has_jump_level_2(state) or self.has_ice_or_stone(state), + lname.ug3b: lambda state: self.has_jump_level_4(state) or self.has_ice_or_stone(state), + lname.ug8: self.has_tackle, + # Underground Warehouse + lname.uw10: lambda state: + (self.has_jump_level_4(state) and self.has_ice_or_stone(state)) or self.has_jump_level_5(state), + lname.uw14: lambda state: self.has_jump_level_2(state) or self.has_ice_or_stone(state), + lname.uw16b: lambda state: + (self.has_jump_level_2(state) and self.has_ice_or_stone(state)) or self.has_jump_level_3(state), + # Underground Waterway + lname.uy5: lambda state: self.has_jump_level_3(state) or self.has_ice_or_stone(state), + lname.uy8: self.has_jump_level_2, + lname.uy12b: self.can_touch_water, + lname.uy17: self.can_touch_water, + lname.uy13: self.has_jump_level_3, + lname.uy18: self.has_jump_level_3, + # Ceremonial Room + lname.cr1: lambda state: self.has_jump_level_2(state) or self.has_kick(state), + lname.dracula: self.has_jump_level_2, + } + + self.entrance_rules = { + "Catacomb to Stairway": lambda state: self.has_jump_level_1(state) or self.has_kick(state), + "Stairway to Audience": self.has_jump_level_1, + "Audience to Machine Bottom": self.has_tackle, + "Audience to Machine Top": lambda state: self.has_jump_level_2(state) or self.has_kick(state), + "Audience to Chapel": lambda state: + (self.has_jump_level_2(state) and self.has_ice_or_stone(state)) or self.has_jump_level_3(state) + or self.has_kick(state), + "Audience to Gallery": lambda state: self.broke_iron_maidens(state) and self.has_push(state), + "Audience to Warehouse": self.has_push, + "Audience to Waterway": self.broke_iron_maidens, + "Audience to Observation": self.has_jump_level_5, + "Ceremonial Door": self.can_open_ceremonial_door, + "Corridor to Gallery": self.broke_iron_maidens, + "Escape the Gallery Pit": lambda state: self.has_jump_level_2(state) or self.has_kick(state), + "Climb to Chapel Top": lambda state: self.has_jump_level_3(state) or self.has_kick(state), + "Arena Passage": lambda state: self.has_push(state) and self.has_jump_level_2(state), + "Dip Into Waterway End": self.has_jump_level_3, + "Gallery Upper to Lower": self.has_tackle, + "Gallery Lower to Upper": self.has_tackle, + "Into Warehouse Main": self.has_tackle, + "Into Waterway Main": self.can_touch_water, + } + + def has_jump_level_1(self, state: CollectionState) -> bool: + """Double or Roc Wing, regardless of Roc being nerfed or not.""" + return state.has_any([iname.double, iname.roc_wing], self.player) + + def has_jump_level_2(self, state: CollectionState) -> bool: + """Specifically Roc Wing, regardless of Roc being nerfed or not.""" + return state.has(iname.roc_wing, self.player) + + def has_jump_level_3(self, state: CollectionState) -> bool: + """Roc Wing and Double OR Kick Boots if Roc is nerfed. Otherwise, just Roc.""" + if self.nerf_roc_wing: + return state.has(iname.roc_wing, self.player) and \ + state.has_any([iname.double, iname.kick_boots], self.player) + else: + return state.has(iname.roc_wing, self.player) + + def has_jump_level_4(self, state: CollectionState) -> bool: + """Roc Wing and Kick Boots specifically if Roc is nerfed. Otherwise, just Roc.""" + if self.nerf_roc_wing: + return state.has_all([iname.roc_wing, iname.kick_boots], self.player) + else: + return state.has(iname.roc_wing, self.player) + + def has_jump_level_5(self, state: CollectionState) -> bool: + """Roc Wing, Double, AND Kick Boots if Roc is nerfed. Otherwise, just Roc.""" + if self.nerf_roc_wing: + return state.has_all([iname.roc_wing, iname.double, iname.kick_boots], self.player) + else: + return state.has(iname.roc_wing, self.player) + + def has_tackle(self, state: CollectionState) -> bool: + return state.has(iname.tackle, self.player) + + def has_push(self, state: CollectionState) -> bool: + return state.has(iname.heavy_ring, self.player) + + def has_kick(self, state: CollectionState) -> bool: + return state.has(iname.kick_boots, self.player) + + def has_ice_or_stone(self, state: CollectionState) -> bool: + """Valid DSS combo that allows freezing or petrifying enemies to use as platforms.""" + return state.has_any([iname.serpent, iname.cockatrice], self.player) and \ + state.has_any([iname.mercury, iname.mars], self.player) + + def can_touch_water(self, state: CollectionState) -> bool: + """Cleansing unless it's ignored, in which case this will always return True.""" + return self.ignore_cleansing or state.has(iname.cleansing, self.player) + + def broke_iron_maidens(self, state: CollectionState) -> bool: + """Maiden Detonator unless the Iron Maidens start broken, in which case this will always return True.""" + return (self.iron_maiden_behavior == IronMaidenBehavior.option_start_broken + or state.has(iname.ironmaidens, self.player)) + + def can_open_ceremonial_door(self, state: CollectionState) -> bool: + """The required number of Last Keys. If 0 keys are required, this should always return True.""" + return state.has(iname.last_key, self.player, self.required_last_keys) + + def set_cvcotm_rules(self) -> None: + multiworld = self.world.multiworld + + for region in multiworld.get_regions(self.player): + # Set each Entrance's rule if it should have one. + for ent in region.entrances: + if ent.name in self.entrance_rules: + ent.access_rule = self.entrance_rules[ent.name] + + # Set each Location's rule if it should have one. + for loc in region.locations: + if loc.name in self.location_rules: + loc.access_rule = self.location_rules[loc.name] + + # Set the World's completion condition depending on what its Completion Goal option is. + if self.completion_goal == CompletionGoal.option_dracula: + multiworld.completion_condition[self.player] = lambda state: state.has(iname.dracula, self.player) + elif self.completion_goal == CompletionGoal.option_battle_arena: + multiworld.completion_condition[self.player] = lambda state: state.has(iname.shinning_armor, self.player) + else: + multiworld.completion_condition[self.player] = \ + lambda state: state.has_all([iname.dracula, iname.shinning_armor], self.player) diff --git a/worlds/cvcotm/test/__init__.py b/worlds/cvcotm/test/__init__.py new file mode 100644 index 000000000000..d8092a937924 --- /dev/null +++ b/worlds/cvcotm/test/__init__.py @@ -0,0 +1,5 @@ +from test.bases import WorldTestBase + + +class CVCotMTestBase(WorldTestBase): + game = "Castlevania - Circle of the Moon" diff --git a/worlds/cvcotm/test/test_access.py b/worlds/cvcotm/test/test_access.py new file mode 100644 index 000000000000..7fba9964e112 --- /dev/null +++ b/worlds/cvcotm/test/test_access.py @@ -0,0 +1,811 @@ +from . import CVCotMTestBase +from ..data import iname, lname +from ..options import IronMaidenBehavior + + +class CatacombSphere1Test(CVCotMTestBase): + + def test_always_accessible(self) -> None: + self.assertTrue(self.can_reach_location(lname.cc4)) + self.assertTrue(self.can_reach_location(lname.cc8)) + self.assertTrue(self.can_reach_location(lname.cc9)) + self.assertTrue(self.can_reach_location(lname.cc10)) + self.assertTrue(self.can_reach_location(lname.cc13)) + self.assertTrue(self.can_reach_location(lname.cc14)) + self.assertTrue(self.can_reach_location(lname.cc16)) + self.assertTrue(self.can_reach_location(lname.cc20)) + self.assertTrue(self.can_reach_location(lname.cc22)) + self.assertTrue(self.can_reach_location(lname.cc24)) + + +class DoubleTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + "nerf_roc_wing": True, + "ignore_cleansing": True + } + + def test_double_only(self) -> None: + self.assertFalse(self.can_reach_location(lname.cc3)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.cc14b)) + self.assertFalse(self.can_reach_location(lname.cc25)) + self.assertFalse(self.can_reach_entrance("Catacomb to Stairway")) + self.assertFalse(self.can_reach_entrance("Stairway to Audience")) + + self.collect_by_name([iname.double]) + + self.assertTrue(self.can_reach_location(lname.cc3)) + self.assertTrue(self.can_reach_location(lname.cc14b)) + self.assertTrue(self.can_reach_location(lname.cc25)) + self.assertTrue(self.can_reach_entrance("Catacomb to Stairway")) + self.assertTrue(self.can_reach_entrance("Stairway to Audience")) + + # Jump-locked things that Double still shouldn't be able to reach. + self.assertFalse(self.can_reach_location(lname.sr3)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.cc8b)) + self.assertFalse(self.can_reach_location(lname.as4)) + self.assertFalse(self.can_reach_location(lname.ar14b)) + self.assertFalse(self.can_reach_location(lname.ar17b)) + self.assertFalse(self.can_reach_location(lname.ar19)) + self.assertFalse(self.can_reach_location(lname.ar26)) + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ow0)) + self.assertFalse(self.can_reach_location(lname.ow1)) + self.assertFalse(self.can_reach_location(lname.th3)) + self.assertFalse(self.can_reach_entrance("Audience to Machine Top")) + self.assertFalse(self.can_reach_entrance("Audience to Chapel")) + self.assertFalse(self.can_reach_entrance("Audience to Observation")) + + self.collect_by_name([iname.heavy_ring, iname.tackle]) + + self.assertFalse(self.can_reach_entrance("Escape the Gallery Pit")) + + def test_double_with_freeze(self) -> None: + self.collect_by_name([iname.mercury, iname.serpent]) + self.assertFalse(self.can_reach_location(lname.cc3b)) + + self.collect_by_name([iname.double]) + + self.assertTrue(self.can_reach_location(lname.cc3b)) + + def test_nerfed_roc_double_path(self) -> None: + self.collect_by_name([iname.roc_wing, iname.tackle, iname.heavy_ring]) + + self.assertFalse(self.can_reach_entrance("Audience to Chapel")) + self.assertFalse(self.can_reach_entrance("Arena Passage")) + self.assertFalse(self.can_reach_entrance("Dip Into Waterway End")) + self.assertFalse(self.can_reach_entrance("Climb to Chapel Top")) + self.assertFalse(self.can_reach_location(lname.cc8b)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.as4)) + self.assertFalse(self.can_reach_location(lname.ar14b)) + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ow0)) + self.assertFalse(self.can_reach_location(lname.ct26)) + self.assertFalse(self.can_reach_location(lname.ct26b)) + self.assertFalse(self.can_reach_location(lname.ug3b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + self.assertFalse(self.can_reach_location(lname.uw16b)) + self.assertFalse(self.can_reach_location(lname.uy5)) + self.assertFalse(self.can_reach_location(lname.uy13)) + self.assertFalse(self.can_reach_location(lname.uy18)) + + self.collect_by_name([iname.double]) + + self.assertTrue(self.can_reach_entrance("Audience to Chapel")) + self.assertTrue(self.can_reach_entrance("Arena Passage")) + self.assertTrue(self.can_reach_entrance("Dip Into Waterway End")) + self.assertTrue(self.can_reach_entrance("Climb to Chapel Top")) + self.assertTrue(self.can_reach_location(lname.cc8b)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.as4)) + self.assertFalse(self.can_reach_location(lname.ar14b)) + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ow0)) + self.assertFalse(self.can_reach_location(lname.ct26)) + self.assertFalse(self.can_reach_location(lname.ct26b)) + self.assertFalse(self.can_reach_location(lname.ug3b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + self.assertTrue(self.can_reach_location(lname.uw16b)) + self.assertTrue(self.can_reach_location(lname.uy5)) + self.assertTrue(self.can_reach_location(lname.uy13)) + self.assertTrue(self.can_reach_location(lname.uy18)) + + self.assertFalse(self.can_reach_entrance("Audience to Observation")) + self.assertFalse(self.can_reach_location(lname.sr3)) + self.assertFalse(self.can_reach_location(lname.ar26)) + self.assertFalse(self.can_reach_location(lname.ow1)) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_entrance("Arena Passage")) + self.assertTrue(self.can_reach_location(lname.cc3b)) + self.assertTrue(self.can_reach_location(lname.as4)) + self.assertTrue(self.can_reach_location(lname.ar14b)) + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ow0)) + self.assertTrue(self.can_reach_location(lname.ct26)) + self.assertTrue(self.can_reach_location(lname.ct26b)) + self.assertTrue(self.can_reach_location(lname.ug3b)) + self.assertTrue(self.can_reach_location(lname.uw10)) + self.assertTrue(self.can_reach_entrance("Audience to Observation")) + self.assertTrue(self.can_reach_location(lname.sr3)) + self.assertTrue(self.can_reach_location(lname.ar26)) + self.assertTrue(self.can_reach_location(lname.ow1)) + + +class TackleTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + } + + def test_tackle_only_in_catacomb(self) -> None: + self.assertFalse(self.can_reach_location(lname.cc5)) + + self.collect_by_name([iname.tackle]) + + self.assertTrue(self.can_reach_location(lname.cc5)) + + def test_tackle_only_in_audience_room(self) -> None: + self.collect_by_name([iname.double]) + + self.assertFalse(self.can_reach_location(lname.ar11)) + self.assertFalse(self.can_reach_entrance("Audience to Machine Bottom")) + + self.collect_by_name([iname.tackle]) + + self.assertTrue(self.can_reach_location(lname.ar11)) + self.assertTrue(self.can_reach_entrance("Audience to Machine Bottom")) + + def test_tackle_with_kick_boots(self) -> None: + self.collect_by_name([iname.double, iname.kick_boots]) + + self.assertFalse(self.can_reach_location(lname.mt14)) + self.assertFalse(self.can_reach_entrance("Gallery Upper to Lower")) + + self.collect_by_name([iname.tackle]) + + self.assertTrue(self.can_reach_location(lname.mt14)) + self.assertTrue(self.can_reach_entrance("Gallery Upper to Lower")) + + def test_tackle_with_heavy_ring(self) -> None: + self.collect_by_name([iname.double, iname.heavy_ring]) + + self.assertFalse(self.can_reach_location(lname.ar27)) + self.assertFalse(self.can_reach_location(lname.ug8)) + self.assertFalse(self.can_reach_entrance("Into Warehouse Main")) + self.assertFalse(self.can_reach_entrance("Gallery Lower to Upper")) + + self.collect_by_name([iname.tackle]) + + self.assertTrue(self.can_reach_location(lname.ar27)) + self.assertTrue(self.can_reach_location(lname.ug8)) + self.assertTrue(self.can_reach_entrance("Into Warehouse Main")) + self.assertTrue(self.can_reach_entrance("Gallery Lower to Upper")) + + def test_tackle_with_roc_wing(self) -> None: + self.collect_by_name([iname.roc_wing]) + + self.assertFalse(self.can_reach_location(lname.ar26)) + + self.collect_by_name([iname.tackle]) + + self.assertTrue(self.can_reach_location(lname.ar26)) + + +class KickBootsTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + "nerf_roc_wing": True, + "ignore_cleansing": True, + } + + def test_kick_boots_only_in_catacomb(self) -> None: + self.assertFalse(self.can_reach_location(lname.cc8b)) + self.assertFalse(self.can_reach_location(lname.cc14b)) + self.assertFalse(self.can_reach_entrance("Catacomb to Stairway")) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_location(lname.cc8b)) + self.assertTrue(self.can_reach_location(lname.cc14b)) + self.assertTrue(self.can_reach_entrance("Catacomb to Stairway")) + + def test_kick_boots_only_in_audience_room(self) -> None: + self.collect_by_name([iname.double]) + + self.assertFalse(self.can_reach_location(lname.ar17b)) + self.assertFalse(self.can_reach_location(lname.ar19)) + self.assertFalse(self.can_reach_entrance("Audience to Machine Top")) + self.assertFalse(self.can_reach_entrance("Audience to Chapel")) + self.assertFalse(self.can_reach_entrance("Climb to Chapel Top")) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_location(lname.ar17b)) + self.assertTrue(self.can_reach_location(lname.ar19)) + self.assertTrue(self.can_reach_entrance("Audience to Machine Top")) + self.assertTrue(self.can_reach_entrance("Audience to Chapel")) + self.assertTrue(self.can_reach_entrance("Climb to Chapel Top")) + + def test_kick_boots_with_tackle(self) -> None: + self.collect_by_name([iname.double, iname.tackle]) + + self.assertFalse(self.can_reach_location(lname.mt3)) + self.assertFalse(self.can_reach_location(lname.mt6)) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_location(lname.mt3)) + self.assertTrue(self.can_reach_location(lname.mt6)) + + def test_kick_boots_with_freeze(self) -> None: + self.collect_by_name([iname.double, iname.mars, iname.cockatrice]) + + self.assertFalse(self.can_reach_region("Underground Gallery Upper")) + self.assertFalse(self.can_reach_location(lname.th3)) + self.assertFalse(self.can_reach_location(lname.ug3)) + self.assertFalse(self.can_reach_location(lname.ug3b)) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_region("Underground Gallery Upper")) + self.assertTrue(self.can_reach_location(lname.th3)) + self.assertTrue(self.can_reach_location(lname.ug3)) + self.assertTrue(self.can_reach_location(lname.ug3b)) + + def test_kick_boots_with_last_key(self) -> None: + self.collect_by_name([iname.double, iname.last_key]) + + self.assertFalse(self.can_reach_location(lname.cr1)) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_location(lname.cr1)) + + def test_nerfed_roc_kick_boots_path(self) -> None: + self.collect_by_name([iname.roc_wing, iname.tackle, iname.heavy_ring]) + + self.assertFalse(self.can_reach_entrance("Audience to Chapel")) + self.assertFalse(self.can_reach_entrance("Arena Passage")) + self.assertFalse(self.can_reach_entrance("Dip Into Waterway End")) + self.assertFalse(self.can_reach_entrance("Climb to Chapel Top")) + self.assertFalse(self.can_reach_location(lname.cc8b)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.as4)) + self.assertFalse(self.can_reach_location(lname.ar14b)) + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ow0)) + self.assertFalse(self.can_reach_location(lname.ct26)) + self.assertFalse(self.can_reach_location(lname.ct26b)) + self.assertFalse(self.can_reach_location(lname.ug3b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + self.assertFalse(self.can_reach_location(lname.uw16b)) + self.assertFalse(self.can_reach_location(lname.uy5)) + self.assertFalse(self.can_reach_location(lname.uy13)) + self.assertFalse(self.can_reach_location(lname.uy18)) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_entrance("Audience to Chapel")) + self.assertTrue(self.can_reach_entrance("Arena Passage")) + self.assertTrue(self.can_reach_entrance("Dip Into Waterway End")) + self.assertTrue(self.can_reach_entrance("Climb to Chapel Top")) + self.assertTrue(self.can_reach_location(lname.cc8b)) + self.assertTrue(self.can_reach_location(lname.cc3b)) + self.assertTrue(self.can_reach_location(lname.as4)) + self.assertTrue(self.can_reach_location(lname.ar14b)) + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ow0)) + self.assertTrue(self.can_reach_location(lname.ct26)) + self.assertTrue(self.can_reach_location(lname.ct26b)) + self.assertTrue(self.can_reach_location(lname.ug3b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + self.assertTrue(self.can_reach_location(lname.uw16b)) + self.assertTrue(self.can_reach_location(lname.uy5)) + self.assertTrue(self.can_reach_location(lname.uy13)) + self.assertTrue(self.can_reach_location(lname.uy18)) + + self.assertFalse(self.can_reach_entrance("Audience to Observation")) + self.assertFalse(self.can_reach_location(lname.sr3)) + self.assertFalse(self.can_reach_location(lname.ar26)) + self.assertFalse(self.can_reach_location(lname.ow1)) + + self.collect_by_name([iname.double]) + + self.assertTrue(self.can_reach_location(lname.uw10)) + self.assertTrue(self.can_reach_entrance("Audience to Observation")) + self.assertTrue(self.can_reach_location(lname.sr3)) + self.assertTrue(self.can_reach_location(lname.ar26)) + self.assertTrue(self.can_reach_location(lname.ow1)) + + +class HeavyRingTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken + } + + def test_heavy_ring_only_in_catacomb(self) -> None: + self.assertFalse(self.can_reach_location(lname.cc1)) + + self.collect_by_name([iname.heavy_ring]) + + self.assertTrue(self.can_reach_location(lname.cc1)) + + def test_heavy_ring_only_in_audience_room(self) -> None: + self.collect_by_name([iname.double]) + + self.assertFalse(self.can_reach_location(lname.ar9)) + self.assertFalse(self.can_reach_entrance("Audience to Gallery")) + self.assertFalse(self.can_reach_entrance("Audience to Warehouse")) + + self.collect_by_name([iname.heavy_ring]) + + self.assertTrue(self.can_reach_location(lname.ar9)) + self.assertTrue(self.can_reach_entrance("Audience to Gallery")) + self.assertTrue(self.can_reach_entrance("Audience to Warehouse")) + + def test_heavy_ring_with_tackle(self) -> None: + self.collect_by_name([iname.double, iname.tackle]) + + self.assertFalse(self.can_reach_location(lname.ar27)) + self.assertFalse(self.can_reach_entrance("Into Warehouse Main")) + + self.collect_by_name([iname.heavy_ring]) + + self.assertTrue(self.can_reach_location(lname.ar27)) + self.assertTrue(self.can_reach_entrance("Into Warehouse Main")) + + def test_heavy_ring_with_kick_boots(self) -> None: + self.collect_by_name([iname.double, iname.kick_boots]) + + self.assertFalse(self.can_reach_location(lname.ct4)) + self.assertFalse(self.can_reach_location(lname.ct10)) + self.assertFalse(self.can_reach_location(lname.ug1)) + self.assertFalse(self.can_reach_location(lname.ug2)) + + self.collect_by_name([iname.heavy_ring]) + + self.assertTrue(self.can_reach_location(lname.ct4)) + self.assertTrue(self.can_reach_location(lname.ct10)) + self.assertTrue(self.can_reach_location(lname.ug1)) + self.assertTrue(self.can_reach_location(lname.ug2)) + + def test_heavy_ring_with_roc_wing(self) -> None: + self.collect_by_name([iname.roc_wing]) + + self.assertFalse(self.can_reach_entrance("Arena Passage")) + + self.collect_by_name([iname.heavy_ring]) + + self.assertTrue(self.can_reach_entrance("Arena Passage")) + + +class CleansingTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken + } + + def test_cleansing_only(self) -> None: + self.collect_by_name([iname.double]) + + self.assertFalse(self.can_reach_entrance("Into Waterway Main")) + + self.collect_by_name([iname.cleansing]) + + self.assertTrue(self.can_reach_entrance("Into Waterway Main")) + + def test_cleansing_with_roc(self) -> None: + self.collect_by_name([iname.roc_wing]) + + self.assertFalse(self.can_reach_location(lname.uy12b)) + self.assertFalse(self.can_reach_location(lname.uy17)) + + self.assertTrue(self.can_reach_entrance("Dip Into Waterway End")) + + self.collect_by_name([iname.cleansing]) + + self.assertTrue(self.can_reach_location(lname.uy12b)) + self.assertTrue(self.can_reach_location(lname.uy17)) + + +class IgnoredCleansingTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + "ignore_cleansing": True + } + + def test_ignored_cleansing(self) -> None: + self.assertFalse(self.can_reach_entrance("Into Waterway Main")) + self.assertFalse(self.can_reach_location(lname.uy12b)) + self.assertFalse(self.can_reach_location(lname.uy17)) + + self.collect_by_name([iname.double]) + + self.assertTrue(self.can_reach_entrance("Into Waterway Main")) + self.assertTrue(self.can_reach_location(lname.uy12b)) + self.assertTrue(self.can_reach_location(lname.uy17)) + + +class UnNerfedRocTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken + } + + def test_roc_wing_only(self) -> None: + self.assertFalse(self.can_reach_location(lname.sr3)) + self.assertFalse(self.can_reach_location(lname.cc3)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.cc8b)) + self.assertFalse(self.can_reach_location(lname.cc14b)) + self.assertFalse(self.can_reach_location(lname.cc25)) + self.assertFalse(self.can_reach_location(lname.as4)) + self.assertFalse(self.can_reach_location(lname.ar14b)) + self.assertFalse(self.can_reach_location(lname.ar17b)) + self.assertFalse(self.can_reach_location(lname.ar19)) + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ow0)) + self.assertFalse(self.can_reach_location(lname.ow1)) + self.assertFalse(self.can_reach_location(lname.th3)) + self.assertFalse(self.can_reach_location(lname.ct1)) + self.assertFalse(self.can_reach_location(lname.ct13)) + self.assertFalse(self.can_reach_location(lname.ug3)) + self.assertFalse(self.can_reach_location(lname.ug3b)) + self.assertFalse(self.can_reach_entrance("Catacomb to Stairway")) + self.assertFalse(self.can_reach_entrance("Stairway to Audience")) + self.assertFalse(self.can_reach_entrance("Audience to Machine Top")) + self.assertFalse(self.can_reach_entrance("Audience to Chapel")) + self.assertFalse(self.can_reach_entrance("Audience to Observation")) + self.assertFalse(self.can_reach_entrance("Dip Into Waterway End")) + + self.collect_by_name([iname.roc_wing]) + + self.assertTrue(self.can_reach_location(lname.sr3)) + self.assertTrue(self.can_reach_location(lname.cc3)) + self.assertTrue(self.can_reach_location(lname.cc3b)) + self.assertTrue(self.can_reach_location(lname.cc8b)) + self.assertTrue(self.can_reach_location(lname.cc14b)) + self.assertTrue(self.can_reach_location(lname.cc25)) + self.assertTrue(self.can_reach_location(lname.as4)) + self.assertTrue(self.can_reach_location(lname.ar14b)) + self.assertTrue(self.can_reach_location(lname.ar17b)) + self.assertTrue(self.can_reach_location(lname.ar19)) + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ow0)) + self.assertTrue(self.can_reach_location(lname.ow1)) + self.assertTrue(self.can_reach_location(lname.th3)) + self.assertTrue(self.can_reach_location(lname.ct1)) + self.assertTrue(self.can_reach_location(lname.ct13)) + self.assertTrue(self.can_reach_location(lname.ug3)) + self.assertTrue(self.can_reach_location(lname.ug3b)) + self.assertTrue(self.can_reach_entrance("Catacomb to Stairway")) + self.assertTrue(self.can_reach_entrance("Stairway to Audience")) + self.assertTrue(self.can_reach_entrance("Audience to Machine Top")) + self.assertTrue(self.can_reach_entrance("Audience to Chapel")) + self.assertTrue(self.can_reach_entrance("Audience to Observation")) + self.assertTrue(self.can_reach_entrance("Dip Into Waterway End")) + self.assertFalse(self.can_reach_entrance("Arena Passage")) + + def test_roc_wing_exclusive_accessibility(self) -> None: + self.collect_by_name([iname.double, iname.tackle, iname.kick_boots, iname.heavy_ring, iname.cleansing, + iname.last_key, iname.mercury, iname.cockatrice]) + + self.assertFalse(self.can_reach_location(lname.sr3)) + self.assertFalse(self.can_reach_location(lname.as4)) + self.assertFalse(self.can_reach_location(lname.ar14b)) + self.assertFalse(self.can_reach_location(lname.ar26)) + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ow0)) + self.assertFalse(self.can_reach_location(lname.uw10)) + self.assertFalse(self.can_reach_location(lname.uw16b)) + self.assertFalse(self.can_reach_location(lname.uy8)) + self.assertFalse(self.can_reach_location(lname.uy13)) + self.assertFalse(self.can_reach_location(lname.uy18)) + self.assertFalse(self.can_reach_location(lname.dracula)) + self.assertFalse(self.can_reach_entrance("Audience to Observation")) + self.assertFalse(self.can_reach_entrance("Arena Passage")) + self.assertFalse(self.can_reach_entrance("Dip Into Waterway End")) + + self.collect_by_name([iname.roc_wing]) + + self.assertTrue(self.can_reach_location(lname.sr3)) + self.assertTrue(self.can_reach_location(lname.as4)) + self.assertTrue(self.can_reach_location(lname.ar14b)) + self.assertTrue(self.can_reach_location(lname.ar26)) + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ow0)) + self.assertTrue(self.can_reach_location(lname.uw10)) + self.assertTrue(self.can_reach_location(lname.uw16b)) + self.assertTrue(self.can_reach_location(lname.uy8)) + self.assertTrue(self.can_reach_location(lname.uy13)) + self.assertTrue(self.can_reach_location(lname.uy18)) + self.assertTrue(self.can_reach_location(lname.dracula)) + self.assertTrue(self.can_reach_entrance("Audience to Observation")) + self.assertTrue(self.can_reach_entrance("Arena Passage")) + self.assertTrue(self.can_reach_entrance("Dip Into Waterway End")) + + +class NerfedRocTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + "nerf_roc_wing": True, + "ignore_cleansing": True + } + + def test_nerfed_roc_without_double_or_kick(self) -> None: + self.collect_by_name([iname.tackle, iname.heavy_ring, iname.last_key]) + self.assertFalse(self.can_reach_location(lname.cc3)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.cc14b)) + self.assertFalse(self.can_reach_location(lname.cc25)) + self.assertFalse(self.can_reach_entrance("Catacomb to Stairway")) + self.assertFalse(self.can_reach_entrance("Stairway to Audience")) + + self.collect_by_name([iname.roc_wing]) + + # Jump-locked things inside Catacomb that just Roc Wing should be able to reach while nerfed. + self.assertTrue(self.can_reach_location(lname.cc3)) + self.assertTrue(self.can_reach_location(lname.cc14b)) + self.assertTrue(self.can_reach_location(lname.cc25)) + self.assertTrue(self.can_reach_entrance("Catacomb to Stairway")) + self.assertTrue(self.can_reach_entrance("Stairway to Audience")) + + # Jump-locked things outside Catacomb that just Roc Wing should be able to reach while nerfed. + self.assertTrue(self.can_reach_location(lname.ar17b)) + self.assertTrue(self.can_reach_location(lname.ar19)) + self.assertTrue(self.can_reach_location(lname.th3)) + self.assertTrue(self.can_reach_location(lname.mt3)) + self.assertTrue(self.can_reach_location(lname.mt6)) + self.assertTrue(self.can_reach_location(lname.ct1)) + self.assertTrue(self.can_reach_location(lname.ct13)) + self.assertTrue(self.can_reach_location(lname.ug3)) + self.assertTrue(self.can_reach_location(lname.uw14)) + self.assertTrue(self.can_reach_location(lname.uy8)) + self.assertTrue(self.can_reach_location(lname.cr1)) + self.assertTrue(self.can_reach_location(lname.dracula)) + self.assertTrue(self.can_reach_entrance("Audience to Machine Top")) + self.assertTrue(self.can_reach_entrance("Escape the Gallery Pit")) + + # Jump-locked things outside Catacomb that just Roc Wing shouldn't be able to reach while nerfed. + self.assertFalse(self.can_reach_location(lname.sr3)) + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.cc8b)) + self.assertFalse(self.can_reach_location(lname.as4)) + self.assertFalse(self.can_reach_location(lname.ar14b)) + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ow0)) + self.assertFalse(self.can_reach_location(lname.ow1)) + self.assertFalse(self.can_reach_location(lname.ct26)) + self.assertFalse(self.can_reach_location(lname.ct26b)) + self.assertFalse(self.can_reach_location(lname.ug3b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + self.assertFalse(self.can_reach_location(lname.uw16b)) + self.assertFalse(self.can_reach_location(lname.uy5)) + self.assertFalse(self.can_reach_location(lname.uy13)) + self.assertFalse(self.can_reach_location(lname.uy18)) + self.assertFalse(self.can_reach_entrance("Audience to Chapel")) + self.assertFalse(self.can_reach_entrance("Audience to Observation")) + self.assertFalse(self.can_reach_entrance("Climb to Chapel Top")) + + self.collect_by_name([iname.double, iname.kick_boots]) + + self.assertTrue(self.can_reach_location(lname.sr3)) + self.assertTrue(self.can_reach_location(lname.cc3b)) + self.assertTrue(self.can_reach_location(lname.cc8b)) + self.assertTrue(self.can_reach_location(lname.as4)) + self.assertTrue(self.can_reach_location(lname.ar14b)) + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ow0)) + self.assertTrue(self.can_reach_location(lname.ow1)) + self.assertTrue(self.can_reach_location(lname.ct26)) + self.assertTrue(self.can_reach_location(lname.ct26b)) + self.assertTrue(self.can_reach_location(lname.ug3b)) + self.assertTrue(self.can_reach_location(lname.uw10)) + self.assertTrue(self.can_reach_location(lname.uw16b)) + self.assertTrue(self.can_reach_location(lname.uy5)) + self.assertTrue(self.can_reach_location(lname.uy13)) + self.assertTrue(self.can_reach_location(lname.uy18)) + self.assertTrue(self.can_reach_entrance("Audience to Chapel")) + self.assertTrue(self.can_reach_entrance("Audience to Observation")) + self.assertTrue(self.can_reach_entrance("Climb to Chapel Top")) + + +class LastKeyTest(CVCotMTestBase): + options = { + "required_last_keys": 9, + "available_last_keys": 9 + } + + def test_last_keys(self) -> None: + self.collect_by_name([iname.double]) + + self.assertFalse(self.can_reach_entrance("Ceremonial Door")) + + self.collect([self.get_item_by_name(iname.last_key)] * 1) + + self.assertFalse(self.can_reach_entrance("Ceremonial Door")) + + self.collect([self.get_item_by_name(iname.last_key)] * 7) + + self.assertFalse(self.can_reach_entrance("Ceremonial Door")) + + self.collect([self.get_item_by_name(iname.last_key)] * 1) + + self.assertTrue(self.can_reach_entrance("Ceremonial Door")) + + +class FreezeTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_start_broken, + "nerf_roc_wing": True + } + + def test_freeze_only_in_audience_room(self) -> None: + self.collect_by_name([iname.double]) + + self.assertFalse(self.can_reach_location(lname.cc3b)) + self.assertFalse(self.can_reach_location(lname.ow1)) + + self.collect_by_name([iname.mars, iname.serpent]) + + self.assertTrue(self.can_reach_location(lname.cc3b)) + self.assertTrue(self.can_reach_location(lname.ow1)) + + def test_freeze_with_kick_boots(self) -> None: + self.collect_by_name([iname.double, iname.kick_boots]) + + self.assertFalse(self.can_reach_location(lname.th3)) + self.assertFalse(self.can_reach_location(lname.ct1)) + self.assertFalse(self.can_reach_location(lname.ct13)) + self.assertFalse(self.can_reach_location(lname.ug3)) + self.assertFalse(self.can_reach_location(lname.ug3b)) + + self.collect_by_name([iname.mercury, iname.serpent]) + + self.assertTrue(self.can_reach_location(lname.th3)) + self.assertTrue(self.can_reach_location(lname.ct1)) + self.assertTrue(self.can_reach_location(lname.ct13)) + self.assertTrue(self.can_reach_location(lname.ug3)) + self.assertTrue(self.can_reach_location(lname.ug3b)) + + def test_freeze_with_heavy_ring_and_tackle(self) -> None: + self.collect_by_name([iname.double, iname.heavy_ring, iname.tackle]) + + self.assertFalse(self.can_reach_location(lname.uw14)) + + self.collect_by_name([iname.mercury, iname.cockatrice]) + + self.assertTrue(self.can_reach_location(lname.uw14)) + + def test_freeze_with_cleansing(self) -> None: + self.collect_by_name([iname.double, iname.cleansing]) + + self.assertFalse(self.can_reach_location(lname.uy5)) + + self.collect_by_name([iname.mercury, iname.serpent]) + + self.assertTrue(self.can_reach_location(lname.uy5)) + + def test_freeze_with_nerfed_roc(self) -> None: + self.collect_by_name([iname.roc_wing, iname.heavy_ring, iname.tackle]) + + self.assertFalse(self.can_reach_entrance("Audience to Chapel")) + self.assertFalse(self.can_reach_location(lname.uw16b)) + + self.collect_by_name([iname.mercury, iname.cockatrice]) + + self.assertTrue(self.can_reach_entrance("Audience to Chapel")) + self.assertTrue(self.can_reach_location(lname.uw16b)) + + # Freeze spots requiring Double + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ct26)) + self.assertFalse(self.can_reach_location(lname.ct26b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + + self.collect_by_name([iname.double]) + + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ct26)) + self.assertTrue(self.can_reach_location(lname.ct26b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + + self.remove_by_name([iname.double]) + + # Freeze spots requiring Kick Boots + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ct26)) + self.assertFalse(self.can_reach_location(lname.ct26b)) + self.assertFalse(self.can_reach_location(lname.uw10)) + + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ct26)) + self.assertTrue(self.can_reach_location(lname.ct26b)) + self.assertTrue(self.can_reach_location(lname.uw10)) + + def test_freeze_with_nerfed_roc_and_double(self) -> None: + self.collect_by_name([iname.roc_wing, iname.heavy_ring, iname.tackle, iname.double]) + + self.assertFalse(self.can_reach_location(lname.ar30)) + self.assertFalse(self.can_reach_location(lname.ar30b)) + self.assertFalse(self.can_reach_location(lname.ct26)) + self.assertFalse(self.can_reach_location(lname.ct26b)) + + self.collect_by_name([iname.mars, iname.cockatrice]) + + self.assertTrue(self.can_reach_location(lname.ar30)) + self.assertTrue(self.can_reach_location(lname.ar30b)) + self.assertTrue(self.can_reach_location(lname.ct26)) + self.assertTrue(self.can_reach_location(lname.ct26b)) + + def test_freeze_with_nerfed_roc_and_kick_boots(self) -> None: + self.collect_by_name([iname.roc_wing, iname.heavy_ring, iname.tackle, iname.kick_boots]) + + self.assertFalse(self.can_reach_location(lname.uw10)) + + self.collect_by_name([iname.mars, iname.serpent]) + + self.assertTrue(self.can_reach_location(lname.uw10)) + + +class VanillaMaidensTest(CVCotMTestBase): + + def test_waterway_and_right_gallery_maidens(self) -> None: + self.collect_by_name([iname.double]) + + self.assertFalse(self.can_reach_entrance("Audience to Waterway")) + self.assertFalse(self.can_reach_entrance("Corridor to Gallery")) + + # Gives access to Chapel Tower wherein we collect the locked Maiden Detonator item. + self.collect_by_name([iname.kick_boots]) + + self.assertTrue(self.can_reach_entrance("Audience to Waterway")) + self.assertTrue(self.can_reach_entrance("Corridor to Gallery")) + + def test_left_gallery_maiden(self) -> None: + self.collect_by_name([iname.double, iname.heavy_ring]) + + self.assertFalse(self.can_reach_entrance("Audience to Gallery")) + + self.collect_by_name([iname.roc_wing]) + + self.assertTrue(self.can_reach_entrance("Audience to Gallery")) + + +class MaidenDetonatorInPoolTest(CVCotMTestBase): + options = { + "iron_maiden_behavior": IronMaidenBehavior.option_detonator_in_pool + } + + def test_maiden_detonator(self) -> None: + self.collect_by_name([iname.double, iname.heavy_ring, iname.kick_boots]) + + self.assertFalse(self.can_reach_entrance("Audience to Waterway")) + self.assertFalse(self.can_reach_entrance("Corridor to Gallery")) + self.assertFalse(self.can_reach_entrance("Audience to Gallery")) + + self.collect_by_name([iname.ironmaidens]) + + self.assertTrue(self.can_reach_entrance("Audience to Waterway")) + self.assertTrue(self.can_reach_entrance("Corridor to Gallery")) + self.assertTrue(self.can_reach_entrance("Audience to Gallery")) From 144d612c527ac02eb290c8e7960c61c6b2fe1d79 Mon Sep 17 00:00:00 2001 From: josephwhite Date: Thu, 12 Dec 2024 08:50:48 -0500 Subject: [PATCH 13/18] Super Mario 64: Rework logic for 100 Coins (#4131) * sm64ex: Rework logic for 100 Coins * sm64ex: 100 Coins Vanilla Option * sm64ex: Avoiding raw int comparisons for 100 coin option * sm64ex: Change 100 coin option from toggle to choice * sm64ex: use snake_case for 100 coin option * just use "vanilla" for option comparison (exempt-medic feedback) Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * sm64ex: remove vanilla 100 coins from item pool to remove overfilling stars * yeah Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Remove range condition (35 is the min for total stars) Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> --------- Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> --- worlds/sm64ex/Options.py | 17 ++++++++++++++--- worlds/sm64ex/__init__.py | 23 ++++++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/worlds/sm64ex/Options.py b/worlds/sm64ex/Options.py index 6cf233558ce2..9c428c99590e 100644 --- a/worlds/sm64ex/Options.py +++ b/worlds/sm64ex/Options.py @@ -3,10 +3,21 @@ from Options import DefaultOnToggle, Range, Toggle, DeathLink, Choice, PerGameCommonOptions, OptionSet, OptionGroup from .Items import action_item_table -class EnableCoinStars(DefaultOnToggle): - """Disable to Ignore 100 Coin Stars. You can still collect them, but they don't do anything. - Removes 15 locations from the pool.""" +class EnableCoinStars(Choice): + """ + Determine logic for 100 Coin Stars. + + Off - Removed from pool. You can still collect them, but they don't do anything. + Optimal for ignoring 100 Coin Stars entirely. Removes 15 locations from the pool. + + On - Kept in pool, potentially randomized. + + Vanilla - Kept in pool, but NOT randomized. + """ display_name = "Enable 100 Coin Stars" + option_off = 0 + option_on = 1 + option_vanilla = 2 class StrictCapRequirements(DefaultOnToggle): diff --git a/worlds/sm64ex/__init__.py b/worlds/sm64ex/__init__.py index 40c778ebe66c..afa67f233c69 100644 --- a/worlds/sm64ex/__init__.py +++ b/worlds/sm64ex/__init__.py @@ -104,7 +104,11 @@ def create_items(self): # 1Up Mushrooms self.multiworld.itempool += [self.create_item("1Up Mushroom") for i in range(0,self.filler_count)] # Power Stars - self.multiworld.itempool += [self.create_item("Power Star") for i in range(0,self.number_of_stars)] + star_range = self.number_of_stars + # Vanilla 100 Coin stars have to removed from the pool if other max star increasing options are active. + if self.options.enable_coin_stars == "vanilla": + star_range -= 15 + self.multiworld.itempool += [self.create_item("Power Star") for i in range(0,star_range)] # Keys if (not self.options.progressive_keys): key1 = self.create_item("Basement Key") @@ -166,6 +170,23 @@ def generate_basic(self): self.multiworld.get_location("Wing Mario Over the Rainbow 1Up Block", self.player).place_locked_item(self.create_item("1Up Mushroom")) self.multiworld.get_location("Bowser in the Sky 1Up Block", self.player).place_locked_item(self.create_item("1Up Mushroom")) + if (self.options.enable_coin_stars == "vanilla"): + self.multiworld.get_location("BoB: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("WF: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("JRB: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("CCM: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("BBH: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("HMC: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("LLL: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("SSL: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("DDD: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("SL: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("WDW: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("TTM: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("THI: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("TTC: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + self.multiworld.get_location("RR: 100 Coins", self.player).place_locked_item(self.create_item("Power Star")) + def get_filler_item_name(self) -> str: return "1Up Mushroom" From f5e3677ef1ec741f830e6ce3d231a25dca7c2689 Mon Sep 17 00:00:00 2001 From: Mysteryem Date: Thu, 12 Dec 2024 18:04:27 +0000 Subject: [PATCH 14/18] Pokemon Emerald: Fix invalid escape sequence warnings (#4328) Generation on Python 3.12 would print SyntaxWarnings due to invalid '\d' escape sequences added in #3832. Use raw strings to avoid `\` being used to escape characters. --- worlds/pokemon_emerald/data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worlds/pokemon_emerald/data.py b/worlds/pokemon_emerald/data.py index d93ff926229b..34bebae2d66a 100644 --- a/worlds/pokemon_emerald/data.py +++ b/worlds/pokemon_emerald/data.py @@ -397,13 +397,13 @@ def _init() -> None: label = [] for word in map_name[4:].split("_"): # 1F, B1F, 2R, etc. - re_match = re.match("^B?\d+[FRP]$", word) + re_match = re.match(r"^B?\d+[FRP]$", word) if re_match: label.append(word) continue # Route 103, Hall 1, House 5, etc. - re_match = re.match("^([A-Z]+)(\d+)$", word) + re_match = re.match(r"^([A-Z]+)(\d+)$", word) if re_match: label.append(re_match.group(1).capitalize()) label.append(re_match.group(2).lstrip("0")) From d7736950cd48d3df9ee35ff1167dc6586172903e Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:42:14 +0100 Subject: [PATCH 15/18] The Witness: Panel Hunt Plando (#3549) * Add panel hunt plando option * Keys are strs * oops * better message * , * this doesn ot need to be here * don't replace pre picked panels * Update options.py * rebase error * rebase error * oops * Mypy * ruff * another rebase error * actually this is a stupid change too * bring over that change:tm: * Update entity_hunt.py * Update entity_hunt.py * Update entity_hunt.py --- worlds/witness/entity_hunt.py | 57 +++++++++++++++++++++++++++-------- worlds/witness/options.py | 14 +++++++++ 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/worlds/witness/entity_hunt.py b/worlds/witness/entity_hunt.py index 86881930c3e1..9549246ce479 100644 --- a/worlds/witness/entity_hunt.py +++ b/worlds/witness/entity_hunt.py @@ -1,5 +1,5 @@ from collections import defaultdict -from logging import debug +from logging import debug, warning from pprint import pformat from typing import TYPE_CHECKING, Dict, List, Set, Tuple @@ -48,6 +48,8 @@ def __init__(self, player_logic: "WitnessPlayerLogic", world: "WitnessWorld", self.PRE_PICKED_HUNT_ENTITIES = pre_picked_entities.copy() self.HUNT_ENTITIES: Set[str] = set() + self._add_plandoed_hunt_panels_to_pre_picked() + self.ALL_ELIGIBLE_ENTITIES, self.ELIGIBLE_ENTITIES_PER_AREA = self._get_eligible_panels() def pick_panel_hunt_panels(self, total_amount: int) -> Set[str]: @@ -69,24 +71,51 @@ def pick_panel_hunt_panels(self, total_amount: int) -> Set[str]: return self.HUNT_ENTITIES - def _entity_is_eligible(self, panel_hex: str) -> bool: + def _entity_is_eligible(self, panel_hex: str, plando: bool = False) -> bool: """ Determine whether an entity is eligible for entity hunt based on player options. """ panel_obj = static_witness_logic.ENTITIES_BY_HEX[panel_hex] - return ( - self.player_logic.solvability_guaranteed(panel_hex) - and panel_hex not in self.player_logic.EXCLUDED_ENTITIES - and not ( - # Due to an edge case, Discards have to be on in disable_non_randomized even if Discard Shuffle is off. - # However, I don't think they should be hunt panels in this case. - self.player_options.disable_non_randomized_puzzles - and not self.player_options.shuffle_discarded_panels - and panel_obj["locationType"] == "Discard" - ) + if not self.player_logic.solvability_guaranteed(panel_hex) or panel_hex in self.player_logic.EXCLUDED_ENTITIES: + if plando: + warning(f"Panel {panel_obj['checkName']} is disabled / excluded and thus not eligible for panel hunt.") + return False + + return plando or not ( + # Due to an edge case, Discards have to be on in disable_non_randomized even if Discard Shuffle is off. + # However, I don't think they should be hunt panels in this case. + self.player_options.disable_non_randomized_puzzles + and not self.player_options.shuffle_discarded_panels + and panel_obj["locationType"] == "Discard" ) + def _add_plandoed_hunt_panels_to_pre_picked(self) -> None: + """ + Add panels the player explicitly specified to be included in panel hunt to the pre picked hunt panels. + Output a warning if a panel could not be added for some reason. + """ + + # Plandoed hunt panels should be in random order, but deterministic by seed, so we sort, then shuffle + panels_to_plando = sorted(self.player_options.panel_hunt_plando.value) + self.random.shuffle(panels_to_plando) + + for location_name in panels_to_plando: + entity_hex = static_witness_logic.ENTITIES_BY_NAME[location_name]["entity_hex"] + + if entity_hex in self.PRE_PICKED_HUNT_ENTITIES: + continue + + if self._entity_is_eligible(entity_hex, plando=True): + if len(self.PRE_PICKED_HUNT_ENTITIES) == self.player_options.panel_hunt_total: + warning( + f"Panel {location_name} could not be plandoed as a hunt panel for {self.player_name}'s world, " + f"because it would exceed their panel hunt total." + ) + continue + + self.PRE_PICKED_HUNT_ENTITIES.add(entity_hex) + def _get_eligible_panels(self) -> Tuple[List[str], Dict[str, Set[str]]]: """ There are some entities that are not allowed for panel hunt for various technical of gameplay reasons. @@ -215,6 +244,10 @@ def _replace_unfair_hunt_entities_with_good_hunt_entities(self) -> None: if good_entity in self.HUNT_ENTITIES or good_entity not in self.ALL_ELIGIBLE_ENTITIES: continue + # ... and it's not a forced pick that should stay the same ... + if bad_entitiy in self.PRE_PICKED_HUNT_ENTITIES: + continue + # ... replace the bad entity with the good entity. self.HUNT_ENTITIES.remove(bad_entitiy) self.HUNT_ENTITIES.add(good_entity) diff --git a/worlds/witness/options.py b/worlds/witness/options.py index b5c15e242f10..d739517870a5 100644 --- a/worlds/witness/options.py +++ b/worlds/witness/options.py @@ -5,6 +5,7 @@ from Options import ( Choice, DefaultOnToggle, + LocationSet, OptionDict, OptionError, OptionGroup, @@ -17,6 +18,7 @@ from .data import static_logic as static_witness_logic from .data.item_definition_classes import ItemCategory, WeightedItemDefinition +from .entity_hunt import ALL_HUNTABLE_PANELS class DisableNonRandomizedPuzzles(Toggle): @@ -268,6 +270,16 @@ class PanelHuntDiscourageSameAreaFactor(Range): default = 40 +class PanelHuntPlando(LocationSet): + """ + Specify specific hunt panels you want for your panel hunt game. + """ + + display_name = "Panel Hunt Plando" + + valid_keys = [static_witness_logic.ENTITIES_BY_HEX[panel_hex]["checkName"] for panel_hex in ALL_HUNTABLE_PANELS] + + class PuzzleRandomization(Choice): """ Puzzles in this randomizer are randomly generated. This option changes the difficulty/types of puzzles. @@ -477,6 +489,7 @@ class TheWitnessOptions(PerGameCommonOptions): panel_hunt_required_percentage: PanelHuntRequiredPercentage panel_hunt_postgame: PanelHuntPostgame panel_hunt_discourage_same_area_factor: PanelHuntDiscourageSameAreaFactor + panel_hunt_plando: PanelHuntPlando early_caves: EarlyCaves early_symbol_item: EarlySymbolItem elevators_come_to_you: ElevatorsComeToYou @@ -505,6 +518,7 @@ class TheWitnessOptions(PerGameCommonOptions): PanelHuntTotal, PanelHuntPostgame, PanelHuntDiscourageSameAreaFactor, + PanelHuntPlando, ], start_collapsed=True), OptionGroup("Locations", [ ShuffleDiscardedPanels, From 9815306875f8c6a4d683679a090babc0b4f96e0d Mon Sep 17 00:00:00 2001 From: qwint Date: Thu, 12 Dec 2024 14:30:49 -0500 Subject: [PATCH 16/18] Docs: Use ModuleUpdate.py #3785 --- docs/running from source.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/running from source.md b/docs/running from source.md index 33d6b3928e54..8e8b4f4b61c3 100644 --- a/docs/running from source.md +++ b/docs/running from source.md @@ -43,9 +43,9 @@ Recommended steps [Discord in #ap-core-dev](https://discord.com/channels/731205301247803413/731214280439103580/905154456377757808) * It is recommended to use [PyCharm IDE](https://www.jetbrains.com/pycharm/) - * Run Generate.py which will prompt installation of missing modules, press enter to confirm - * In PyCharm: right-click Generate.py and select `Run 'Generate'` - * Without PyCharm: open a command prompt in the source folder and type `py Generate.py` + * Run ModuleUpdate.py which will prompt installation of missing modules, press enter to confirm + * In PyCharm: right-click ModuleUpdate.py and select `Run 'ModuleUpdate'` + * Without PyCharm: open a command prompt in the source folder and type `py ModuleUpdate.py` ## macOS From 1ca8d3e4a8b4a4a3850a0829c7c934bc4f8475c6 Mon Sep 17 00:00:00 2001 From: qwint Date: Thu, 12 Dec 2024 15:24:38 -0500 Subject: [PATCH 17/18] Docs: add description of Indirect Condition problem (#4295) * Docs: Dev FAQ - About indirect conditions I wrote up a big effortpost about indirect conditions for nex on the [DS3 3.0 PR](https://github.com/ArchipelagoMW/Archipelago/pull/3128#discussion_r1693843193). The version I'm [PRing to the world API document](https://github.com/ArchipelagoMW/Archipelago/pull/3552) is very brief and unnuanced, because I'd rather people use too many indirect conditions than too few. But that might leave some devs wanting to know more. I think that comment on nex's DS3 PR is probably the best detailed explanation for indirect conditions that exists currently. So I think it's good if it exists somewhere. And the FAQ doc seems like the best place right now, because I don't want to write an entirely new doc at the moment. * Actually copy in the text * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update docs/apworld_dev_faq.md Co-authored-by: Scipio Wright * Update docs/apworld_dev_faq.md Co-authored-by: Scipio Wright * Update docs/apworld_dev_faq.md Co-authored-by: qwint * Update docs/apworld_dev_faq.md Co-authored-by: qwint * Update apworld_dev_faq.md * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update apworld_dev_faq.md * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update docs/apworld_dev_faq.md Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> * Update apworld_dev_faq.md * Update docs/apworld_dev_faq.md Co-authored-by: qwint * Update docs/apworld_dev_faq.md Co-authored-by: qwint * fix the last couple of wording issues I have with the indirect condition section to apworld dev faq doc * I didn't like that wording * Apply suggestions from code review Co-authored-by: Scipio Wright * Apply suggestions from code review Co-authored-by: Scipio Wright * Update docs/apworld_dev_faq.md Co-authored-by: Scipio Wright * Update docs/apworld_dev_faq.md * Update docs/apworld_dev_faq.md Co-authored-by: Scipio Wright --------- Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com> Co-authored-by: Scipio Wright --- docs/apworld_dev_faq.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/apworld_dev_faq.md b/docs/apworld_dev_faq.md index 8d9429afa321..769a2fb3a0a7 100644 --- a/docs/apworld_dev_faq.md +++ b/docs/apworld_dev_faq.md @@ -43,3 +43,26 @@ A faster alternative to the `for` loop would be to use a [list comprehension](ht ```py item_pool += [self.create_filler() for _ in range(total_locations - len(item_pool))] ``` + +--- + +### I learned about indirect conditions in the world API document, but I want to know more. What are they and why are they necessary? + +The world API document mentions how to use `multiworld.register_indirect_condition` to register indirect conditions and **when** you should use them, but not *how* they work and *why* they are necessary. This is because the explanation is quite complicated. + +Region sweep (the algorithm that determines which regions are reachable) is a Breadth-First Search of the region graph. It starts from the origin region, checks entrances one by one, and adds newly reached regions and their entrances to the queue until there is nothing more to check. + +For performance reasons, AP only checks every entrance once. However, if an entrance's access_rule depends on region access, then the following may happen: +1. The entrance is checked and determined to be nontraversable because the region in its access_rule hasn't been reached yet during the graph search. +2. Then, the region in its access_rule is determined to be reachable. + +This entrance *would* be in logic if it were rechecked, but it won't be rechecked this cycle. +To account for this case, AP would have to recheck all entrances every time a new region is reached until no new regions are reached. + +An indirect condition is how you can manually define that a specific entrance needs to be rechecked during region sweep if a specific region is reached during it. +This keeps most of the performance upsides. Even in a game making heavy use of indirect conditions (ex: The Witness), using them is significantly faster than just "rechecking each entrance until nothing new is found". +The reason entrance access rules using `location.can_reach` and `entrance.can_reach` are also affected is because they call `region.can_reach` on their respective parent/source region. + +We recognize it can feel like a trap since it will not alert you when you are missing an indirect condition, and that some games have very complex access rules. +As of [PR #3682 (Core: Region handling customization)](https://github.com/ArchipelagoMW/Archipelago/pull/3682) being merged, it is possible for a world to opt out of indirect conditions entirely, instead using the system of checking each entrance whenever a region has been reached, although this does come with a performance cost. +Opting out of using indirect conditions should only be used by games that *really* need it. For most games, it should be reasonable to know all entrance → region dependencies, making indirect conditions preferred because they are much faster. From 8d9454ea3bca864cc0e3f20f39563966feeffb86 Mon Sep 17 00:00:00 2001 From: qwint Date: Thu, 12 Dec 2024 15:36:56 -0500 Subject: [PATCH 18/18] Core: cast all the settings values so they don't try to get pickled later #4362 --- WebHostLib/generate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WebHostLib/generate.py b/WebHostLib/generate.py index b19f3d483515..0bd9f7e5e066 100644 --- a/WebHostLib/generate.py +++ b/WebHostLib/generate.py @@ -31,11 +31,11 @@ def get_meta(options_source: dict, race: bool = False) -> Dict[str, Union[List[s server_options = { "hint_cost": int(options_source.get("hint_cost", ServerOptions.hint_cost)), - "release_mode": options_source.get("release_mode", ServerOptions.release_mode), - "remaining_mode": options_source.get("remaining_mode", ServerOptions.remaining_mode), - "collect_mode": options_source.get("collect_mode", ServerOptions.collect_mode), + "release_mode": str(options_source.get("release_mode", ServerOptions.release_mode)), + "remaining_mode": str(options_source.get("remaining_mode", ServerOptions.remaining_mode)), + "collect_mode": str(options_source.get("collect_mode", ServerOptions.collect_mode)), "item_cheat": bool(int(options_source.get("item_cheat", not ServerOptions.disable_item_cheat))), - "server_password": options_source.get("server_password", None), + "server_password": str(options_source.get("server_password", None)), } generator_options = { "spoiler": int(options_source.get("spoiler", GeneratorOptions.spoiler)),