oettaM123 commited on
Commit
f0bb4a4
·
1 Parent(s): 212fe39

improve new boss setup automation

Browse files
BOSS_UPDATE_GUIDE.md CHANGED
@@ -25,19 +25,28 @@ The official client supplies:
25
  - gold reward range
26
  - possible sword and shield drops
27
  - item-specific sword and shield drop chances
 
28
 
29
- The optimizer automatically picks the rarest configured sword and shield in the
30
- boss drop pool as the featured epic drops.
 
 
 
31
 
32
  ## What still needs one measurement
33
 
34
  - effective downtime from the killing hit to the first hit after respawn
35
  - normal gold divisor
36
- - maximum accounts per room, if the new world does not use 8
 
37
 
38
  These values are stored in `boss_overrides.json`. The website settings can
39
  override both drop chances and room capacity at any time.
40
 
 
 
 
 
41
  ## Add a new boss
42
 
43
  1. Start the optimizer locally.
@@ -67,8 +76,9 @@ SM_BOSS_PROBE.copyJson()
67
  7. Run `configure_new_boss.bat`.
68
 
69
  The batch refreshes the official catalog, reads the probe JSON from the
70
- clipboard, asks only for the remaining values, updates `boss_overrides.json`,
71
- and pushes the optimizer files. The new boss then appears as a settings preset.
 
72
 
73
  If the optimizer uses another port, replace `8000` in the fetch command with
74
  that port.
 
25
  - gold reward range
26
  - possible sword and shield drops
27
  - item-specific sword and shield drop chances
28
+ - room capacity rules for each world number
29
 
30
+ The setup helper lists every newly discovered enemy so the actual boss can be
31
+ selected. It then lists only that enemy's official sword and shield drops and
32
+ asks which two are the featured boss drops. If their world label contains a
33
+ number such as `W11`, the matching official room capacity is selected
34
+ automatically and can still be confirmed or changed.
35
 
36
  ## What still needs one measurement
37
 
38
  - effective downtime from the killing hit to the first hit after respawn
39
  - normal gold divisor
40
+ - world number or room capacity only if the official item labels do not identify
41
+ the world clearly
42
 
43
  These values are stored in `boss_overrides.json`. The website settings can
44
  override both drop chances and room capacity at any time.
45
 
46
+ Until a timing measurement is supplied, effective downtime defaults to the
47
+ official raw respawn plus `1.15` seconds. The existing three main bosses all
48
+ matched this offset closely, but a new boss should still be measured once.
49
+
50
  ## Add a new boss
51
 
52
  1. Start the optimizer locally.
 
76
  7. Run `configure_new_boss.bat`.
77
 
78
  The batch refreshes the official catalog, reads the probe JSON from the
79
+ clipboard, asks which new enemy and boss drops to use, confirms the inferred
80
+ world and remaining measured values, updates `boss_overrides.json`, and pushes
81
+ the optimizer files. The new boss then appears as a settings preset.
82
 
83
  If the optimizer uses another port, replace `8000` in the fetch command with
84
  that port.
game_catalog.json CHANGED
@@ -13,6 +13,19 @@
13
  "data_sha256": "f52cbba9daf2b84ae9d311b17ee2072088ac87ae63c10b0aa82b3078804b4f70"
14
  },
15
  "level_scale_per_level": 0.25,
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  "enemies": [
17
  {
18
  "name": "Roundhead",
 
13
  "data_sha256": "f52cbba9daf2b84ae9d311b17ee2072088ac87ae63c10b0aa82b3078804b4f70"
14
  },
15
  "level_scale_per_level": 0.25,
16
+ "world_room_capacities": {
17
+ "default": 8,
18
+ "by_world": {
19
+ "3": 4,
20
+ "6": 4,
21
+ "100": 16,
22
+ "102": 16,
23
+ "103": 32,
24
+ "104": 6,
25
+ "105": 16,
26
+ "106": -1
27
+ }
28
+ },
29
  "enemies": [
30
  {
31
  "name": "Roundhead",
static/game_catalog.js CHANGED
The diff for this file is too large to render. See raw diff
 
tests/test_game_catalog_sync.py CHANGED
@@ -3,7 +3,12 @@ from pathlib import Path
3
 
4
  import pytest
5
 
6
- from tools.sync_game_catalog import CatalogError, _evaluate_arithmetic
 
 
 
 
 
7
 
8
 
9
  ROOT = Path(__file__).resolve().parents[1]
@@ -23,6 +28,9 @@ def test_generated_catalog_contains_complete_official_item_sets():
23
  ))
24
  assert catalog["level_scale_per_level"] == pytest.approx(0.25)
25
  assert len(catalog["enemies"]) >= 26
 
 
 
26
 
27
 
28
  def test_catalog_keeps_stats_and_images_aligned_by_game_type():
@@ -55,3 +63,46 @@ def test_rotation_expression_parser_only_accepts_arithmetic():
55
  assert _evaluate_arithmetic("-12/0x3*(4+2)") == pytest.approx(-24)
56
  with pytest.raises(CatalogError):
57
  _evaluate_arithmetic("__import__('os').system('echo no')")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  import pytest
5
 
6
+ from tools.sync_game_catalog import (
7
+ CatalogError,
8
+ _evaluate_arithmetic,
9
+ _parse_decoded_world_room_capacities,
10
+ )
11
+ from tools.configure_new_boss import room_capacity_for_world, world_number_from_items
12
 
13
 
14
  ROOT = Path(__file__).resolve().parents[1]
 
28
  ))
29
  assert catalog["level_scale_per_level"] == pytest.approx(0.25)
30
  assert len(catalog["enemies"]) >= 26
31
+ assert catalog["world_room_capacities"]["default"] == 8
32
+ assert catalog["world_room_capacities"]["by_world"]["3"] == 4
33
+ assert catalog["world_room_capacities"]["by_world"]["6"] == 4
34
 
35
 
36
  def test_catalog_keeps_stats_and_images_aligned_by_game_type():
 
63
  assert _evaluate_arithmetic("-12/0x3*(4+2)") == pytest.approx(-24)
64
  with pytest.raises(CatalogError):
65
  _evaluate_arithmetic("__import__('os').system('echo no')")
66
+
67
+
68
+ def test_room_capacity_parser_reads_default_and_special_worlds():
69
+ source = (
70
+ "this['onlineCounter']['element']&&(0x3===this['worldNumber']||"
71
+ "0x6===this['worldNumber']?this['maxClients']=0x4:this['maxClients']=0x8,"
72
+ "0x64!=this['worldNumber']&&0x66!=this['worldNumber']||(this['maxClients']=0x10),"
73
+ "0x67==this['worldNumber']&&(this['maxClients']=0x20),"
74
+ "0x68==this['worldNumber']&&(this['maxClients']=0x6),"
75
+ "0x69==this['worldNumber']&&(this['maxClients']=0x10),"
76
+ "0x6a==this['worldNumber']&&(this['maxClients']=-0x1));"
77
+ )
78
+ rules = _parse_decoded_world_room_capacities(source)
79
+
80
+ assert rules["default"] == 8
81
+ assert rules["by_world"] == {
82
+ "3": 4,
83
+ "6": 4,
84
+ "100": 16,
85
+ "102": 16,
86
+ "103": 32,
87
+ "104": 6,
88
+ "105": 16,
89
+ "106": -1,
90
+ }
91
+
92
+
93
+ def test_boss_config_infers_world_and_room_capacity_from_selected_drops():
94
+ catalog = {
95
+ "world_room_capacities": {
96
+ "default": 8,
97
+ "by_world": {"3": 4, "6": 4},
98
+ }
99
+ }
100
+ items = [
101
+ {"name": "Drop Sword", "world": "New Realm W11"},
102
+ {"name": "Drop Shield", "world": "New Realm W11"},
103
+ ]
104
+
105
+ world_number = world_number_from_items(items)
106
+ assert world_number == 11
107
+ assert room_capacity_for_world(catalog, world_number) == 8
108
+ assert room_capacity_for_world(catalog, 3) == 4
tools/configure_new_boss.py CHANGED
@@ -45,6 +45,14 @@ def prompt(label: str, default: Any, cast=str):
45
  return cast(raw)
46
 
47
 
 
 
 
 
 
 
 
 
48
  def slug(value: str) -> str:
49
  return re.sub(r"[^a-z0-9]+", "-", value.lower()).strip("-")
50
 
@@ -57,10 +65,18 @@ def item_by_type(catalog: dict[str, Any], category: str) -> dict[int, dict[str,
57
  }
58
 
59
 
60
- def featured_drop(catalog: dict[str, Any], enemy: dict[str, Any], category: str):
 
 
 
 
61
  list_key = "dropsSword" if category == "swords" else "dropsShield"
62
  items = item_by_type(catalog, category)
63
- candidates = [items[value] for value in enemy.get(list_key, []) if value in items]
 
 
 
 
64
  if not candidates:
65
  return "", 0.0
66
  chosen = min(
@@ -74,6 +90,60 @@ def featured_drop(catalog: dict[str, Any], enemy: dict[str, Any], category: str)
74
  return chosen["name"], chance
75
 
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  def choose_enemy(catalog: dict[str, Any], overrides: dict[str, Any], wanted: int | None):
78
  enemies = catalog.get("enemies") or []
79
  if wanted is not None:
@@ -130,8 +200,19 @@ def main() -> int:
130
  enemy = choose_enemy(catalog, overrides, wanted_type)
131
  enemy_type = int(enemy["type"])
132
  existing = (overrides.get("bosses") or {}).get(str(enemy_type), {})
133
- sword_name, sword_chance = featured_drop(catalog, enemy, "swords")
134
- shield_name, shield_chance = featured_drop(catalog, enemy, "shields")
 
 
 
 
 
 
 
 
 
 
 
135
  default_delay = float(overrides.get("default_first_hit_delay_seconds", 1.15))
136
  automatic_respawn = float(enemy.get("respawDelay", 0.0)) / 1000.0 + default_delay
137
  measured_respawn = probe.get("effective_respawn_seconds")
@@ -151,6 +232,7 @@ def main() -> int:
151
  "key": prompt("Preset key", existing.get("key") or slug(enemy["name"])),
152
  "display_name": prompt("Displayed boss name", existing.get("display_name") or enemy["name"]),
153
  "order": prompt("Preset order", existing.get("order", enemy_type), int),
 
154
  "effective_respawn_seconds": prompt(
155
  "Kill hit -> first respawn hit (seconds)",
156
  measured_respawn if measured_respawn is not None else existing.get(
@@ -160,7 +242,7 @@ def main() -> int:
160
  ),
161
  "room_capacity": prompt(
162
  "Maximum accounts in one room",
163
- existing.get("room_capacity", 8),
164
  int,
165
  ),
166
  "normal_gold_divisor": prompt(
@@ -170,13 +252,13 @@ def main() -> int:
170
  ),
171
  float,
172
  ),
173
- "sword_item": prompt("Featured sword", existing.get("sword_item", sword_name)),
174
  "sword_drop_chance": prompt(
175
  "Sword drop chance as decimal (1% = 0.01)",
176
  existing.get("sword_drop_chance", sword_chance / 100.0),
177
  float,
178
  ),
179
- "shield_item": prompt("Featured shield", existing.get("shield_item", shield_name)),
180
  "shield_drop_chance": prompt(
181
  "Shield drop chance as decimal (1% = 0.01)",
182
  existing.get("shield_drop_chance", shield_chance / 100.0),
 
45
  return cast(raw)
46
 
47
 
48
+ def prompt_optional_int(label: str, default: int | None = None) -> int | None:
49
+ suffix = f" [{default}]" if default is not None else " [unknown]"
50
+ raw = input(f"{label}{suffix}: ").strip()
51
+ if not raw:
52
+ return default
53
+ return int(raw)
54
+
55
+
56
  def slug(value: str) -> str:
57
  return re.sub(r"[^a-z0-9]+", "-", value.lower()).strip("-")
58
 
 
65
  }
66
 
67
 
68
+ def drop_candidates(
69
+ catalog: dict[str, Any],
70
+ enemy: dict[str, Any],
71
+ category: str,
72
+ ) -> list[dict[str, Any]]:
73
  list_key = "dropsSword" if category == "swords" else "dropsShield"
74
  items = item_by_type(catalog, category)
75
+ return [items[value] for value in enemy.get(list_key, []) if value in items]
76
+
77
+
78
+ def featured_drop(catalog: dict[str, Any], enemy: dict[str, Any], category: str):
79
+ candidates = drop_candidates(catalog, enemy, category)
80
  if not candidates:
81
  return "", 0.0
82
  chosen = min(
 
90
  return chosen["name"], chance
91
 
92
 
93
+ def choose_drop(
94
+ catalog: dict[str, Any],
95
+ enemy: dict[str, Any],
96
+ category: str,
97
+ existing_name: str = "",
98
+ ) -> tuple[dict[str, Any] | None, float]:
99
+ candidates = drop_candidates(catalog, enemy, category)
100
+ singular = "sword" if category == "swords" else "shield"
101
+ if not candidates:
102
+ print(f"No official {singular} drops are configured for this enemy.")
103
+ return None, 0.0
104
+
105
+ default_name, _default_chance = featured_drop(catalog, enemy, category)
106
+ default_index = next(
107
+ (
108
+ index
109
+ for index, item in enumerate(candidates, start=1)
110
+ if item["name"] == (existing_name or default_name)
111
+ ),
112
+ 1,
113
+ )
114
+ print(f"\nOfficial {singular} drop candidates:")
115
+ for index, item in enumerate(candidates, start=1):
116
+ chance = float(item.get("drop_chance", item.get("commonnessPercentage", 0.0)) or 0.0)
117
+ world = str(item.get("world") or "unknown world")
118
+ print(f" {index:>2} {item['name']} {chance:g}% ({world})")
119
+ selected = prompt(f"Boss {singular} number", default_index, int)
120
+ if not 1 <= selected <= len(candidates):
121
+ raise SystemExit(f"Boss {singular} number must be between 1 and {len(candidates)}.")
122
+ item = candidates[selected - 1]
123
+ chance = float(item.get("drop_chance", item.get("commonnessPercentage", 0.0)) or 0.0)
124
+ return item, chance
125
+
126
+
127
+ def world_number_from_items(items: list[dict[str, Any] | None]) -> int | None:
128
+ values = set()
129
+ for item in items:
130
+ if not item:
131
+ continue
132
+ match = re.search(r"\bW(\d+)\b", str(item.get("world") or ""), re.IGNORECASE)
133
+ if match:
134
+ values.add(int(match.group(1)))
135
+ return next(iter(values)) if len(values) == 1 else None
136
+
137
+
138
+ def room_capacity_for_world(catalog: dict[str, Any], world_number: int | None) -> int:
139
+ rules = catalog.get("world_room_capacities") or {}
140
+ default = int(rules.get("default", 8) or 8)
141
+ if world_number is None:
142
+ return default
143
+ limit = int((rules.get("by_world") or {}).get(str(world_number), default))
144
+ return 50 if limit < 0 else limit
145
+
146
+
147
  def choose_enemy(catalog: dict[str, Any], overrides: dict[str, Any], wanted: int | None):
148
  enemies = catalog.get("enemies") or []
149
  if wanted is not None:
 
200
  enemy = choose_enemy(catalog, overrides, wanted_type)
201
  enemy_type = int(enemy["type"])
202
  existing = (overrides.get("bosses") or {}).get(str(enemy_type), {})
203
+ sword_item, sword_chance = choose_drop(
204
+ catalog, enemy, "swords", str(existing.get("sword_item") or "")
205
+ )
206
+ shield_item, shield_chance = choose_drop(
207
+ catalog, enemy, "shields", str(existing.get("shield_item") or "")
208
+ )
209
+ sword_name = str((sword_item or {}).get("name") or "")
210
+ shield_name = str((shield_item or {}).get("name") or "")
211
+ inferred_world = world_number_from_items([sword_item, shield_item])
212
+ existing_world = existing.get("world_number")
213
+ default_world = int(existing_world) if existing_world is not None else inferred_world
214
+ world_number = prompt_optional_int("World number", default_world)
215
+ inferred_capacity = room_capacity_for_world(catalog, world_number)
216
  default_delay = float(overrides.get("default_first_hit_delay_seconds", 1.15))
217
  automatic_respawn = float(enemy.get("respawDelay", 0.0)) / 1000.0 + default_delay
218
  measured_respawn = probe.get("effective_respawn_seconds")
 
232
  "key": prompt("Preset key", existing.get("key") or slug(enemy["name"])),
233
  "display_name": prompt("Displayed boss name", existing.get("display_name") or enemy["name"]),
234
  "order": prompt("Preset order", existing.get("order", enemy_type), int),
235
+ "world_number": world_number,
236
  "effective_respawn_seconds": prompt(
237
  "Kill hit -> first respawn hit (seconds)",
238
  measured_respawn if measured_respawn is not None else existing.get(
 
242
  ),
243
  "room_capacity": prompt(
244
  "Maximum accounts in one room",
245
+ existing.get("room_capacity", inferred_capacity),
246
  int,
247
  ),
248
  "normal_gold_divisor": prompt(
 
252
  ),
253
  float,
254
  ),
255
+ "sword_item": sword_name,
256
  "sword_drop_chance": prompt(
257
  "Sword drop chance as decimal (1% = 0.01)",
258
  existing.get("sword_drop_chance", sword_chance / 100.0),
259
  float,
260
  ),
261
+ "shield_item": shield_name,
262
  "shield_drop_chance": prompt(
263
  "Shield drop chance as decimal (1% = 0.01)",
264
  existing.get("shield_drop_chance", shield_chance / 100.0),
tools/sync_game_catalog.py CHANGED
@@ -302,6 +302,62 @@ def _find_item_arrays(bundle: str) -> dict[str, list[dict[str, Any]]]:
302
  return arrays
303
 
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  def _find_enemy_array(bundle: str) -> list[dict[str, Any]]:
306
  decode_calls = _build_string_decoder(bundle)
307
  best: list[dict[str, Any]] = []
@@ -615,6 +671,7 @@ def build_catalog(
615
  "data_sha256": hashlib.sha256(data_raw).hexdigest(),
616
  },
617
  "level_scale_per_level": _extract_level_scale(bundle),
 
618
  "enemies": enemies,
619
  "swords": [item for item in rows["swords"] if item["name"] != "Empty"],
620
  "shields": [item for item in rows["shields"] if item["name"] != "Empty"],
 
302
  return arrays
303
 
304
 
305
+ def _parse_decoded_world_room_capacities(source: str) -> dict[str, Any]:
306
+ world = r"this\['worldNumber'\]"
307
+ clients = r"this\['maxClients'\]"
308
+ default_match = re.search(
309
+ rf"0x([0-9a-f]+)==={world}\|\|0x([0-9a-f]+)==={world}"
310
+ rf"\?{clients}=(0x[0-9a-f]+):{clients}=(0x[0-9a-f]+)",
311
+ source,
312
+ re.IGNORECASE,
313
+ )
314
+ pair_match = re.search(
315
+ rf"0x([0-9a-f]+)!={world}&&0x([0-9a-f]+)!={world}"
316
+ rf"\|\|\({clients}=(0x[0-9a-f]+)\)",
317
+ source,
318
+ re.IGNORECASE,
319
+ )
320
+ if not default_match or not pair_match:
321
+ raise CatalogError("Could not parse the official room-capacity defaults.")
322
+
323
+ first_world, second_world, shared_limit, default_limit = (
324
+ int(value, 16) for value in default_match.groups()
325
+ )
326
+ pair_first, pair_second, pair_limit = (
327
+ int(value, 16) for value in pair_match.groups()
328
+ )
329
+ by_world = {
330
+ str(first_world): shared_limit,
331
+ str(second_world): shared_limit,
332
+ str(pair_first): pair_limit,
333
+ str(pair_second): pair_limit,
334
+ }
335
+ for match in re.finditer(
336
+ rf"0x([0-9a-f]+)=={world}&&\({clients}=(-?0x[0-9a-f]+)\)",
337
+ source,
338
+ re.IGNORECASE,
339
+ ):
340
+ world_number = int(match.group(1), 16)
341
+ raw_limit = match.group(2)
342
+ limit = -int(raw_limit[3:], 16) if raw_limit.startswith("-") else int(raw_limit, 16)
343
+ by_world[str(world_number)] = limit
344
+
345
+ return {
346
+ "default": default_limit,
347
+ "by_world": dict(sorted(by_world.items(), key=lambda row: int(row[0]))),
348
+ }
349
+
350
+
351
+ def _extract_world_room_capacities(bundle: str) -> dict[str, Any]:
352
+ decode_calls = _build_string_decoder(bundle)
353
+ marker = "this['maxClients']=0x6"
354
+ marker_pos = bundle.find(marker)
355
+ if marker_pos < 0:
356
+ raise CatalogError("Could not identify the official room-capacity rules.")
357
+ source = decode_calls(bundle[max(0, marker_pos - 1800) : marker_pos + 900])
358
+ return _parse_decoded_world_room_capacities(source)
359
+
360
+
361
  def _find_enemy_array(bundle: str) -> list[dict[str, Any]]:
362
  decode_calls = _build_string_decoder(bundle)
363
  best: list[dict[str, Any]] = []
 
671
  "data_sha256": hashlib.sha256(data_raw).hexdigest(),
672
  },
673
  "level_scale_per_level": _extract_level_scale(bundle),
674
+ "world_room_capacities": _extract_world_room_capacities(bundle),
675
  "enemies": enemies,
676
  "swords": [item for item in rows["swords"] if item["name"] != "Empty"],
677
  "shields": [item for item in rows["shields"] if item["name"] != "Empty"],