Randomized mob gear and worn-gear drops (Claude, 2026-11-23)
Owner approved the plan on 2026-11-23 ("jah" to the plan, then "mõlemad" = both stages). Humanoid mobs wear a random set of real items, look different per spawn, and can drop what they wear.
Rules (Scripts/Enemies/MobGearRules.gd, scene-free, used by native game and server)
- Mobs are matched by scene path (MOB_PROFILES); enemy .tscn exports are not used for this. Skeletons, goblins, orcs, demons. Orc Warlord and Demon Lord wear a fixed boss set. Orcs and demons never get a helmet (no_helmet; Janari 23.11: keep eyes and horns visible).
- Armor slots (helmet, vest, bracers, boots): each filled with 50 % chance; the piece comes from a random set of the mob's FAMILY_SETS theme (skeleton/goblin/orc/demon, approved by Janari 23.11 from the catalogue sheet test-results-free preview "komplektid_skeletil.png"; mix and match per slot). Weapons/off-hands: POOLS per archetype. Skeleton king archer keeps its own baked crown (no helmet roll).
- Weapon + shield/quiver: only for scenes in BARE_BASE_SCENES (bodies exported without weapon, shield, bow, quiver and helmet). Those always get a weapon; off-hand 50 % if the weapon is 1H.
- Drop: each worn piece 4 % (elite 10 %, boss 25 %), at most one worn piece per kill (MobGearRules.roll_drop). It REPLACES the old fixed equipment_drop_* of these mobs (before: 100 % Guard Shield or Bone Quiver every kill). Other loot/material drops are unchanged.
- Defense: + 15 % of each worn piece's average physical defense (starter set about +6), added in SkeletonEnemy.calculate_damage via gear_defense_bonus (exported
defenseis not changed, so respawn templates do not stack it).
Drawing (Scripts/Enemies/MobGearVisual.gd)
- Uses the player's paper-doll SpriteFrames (res://Assets/Spritesheets/Player/SpriteFrames/ <part>_<variant>_<dir>.tres). Mob and player sheets are HeroEditor4D exports with the same rows, 16 frames, 512 px cells and feet line (y=363), so each gear Sprite2D copies the body sprite's animation/frame/transform every frame. Action map: Attack->slash, Shoot->fire, others lowercase.
- Boots follow the lower-body sprite, everything else the upper/full sprite.
- Z order: NativeEquipmentLayerOrder squeezed around the baked body; the enemy's NativeWorldDepth reservation grows to fit (draw_depth_below/above in SkeletonEnemy).
- Sheets load through FrameStreamer (no hitch; the body shows first, gear appears after a few frames on first sight). Not created in headless runs.
- Measured cost: one piece = 4 direction sheets (~7-8 MB VRAM Basis, shared with players).
Multiplayer
- OnlineCombatService.make_enemy -> enemy["gear"] = roll_enemy_gear(scene_path, id) (native item ids). Sent once by the field-delta snapshot. OnlineEnemyVisual.apply_gear draws it with MobGearVisual and switches to the bare body frames when a weapon is in the list.
- NOT done online: worn-gear drops. The online item catalog (Data/Online/items.json, 14 string ids, one "armor" slot) cannot hold native armor pieces yet; needs the catalog unification.
Stage 2: bare bodies (Unity)
- Unity: WieldHavenUnity Assets/Editor/WieldHavenBareMobExporter.cs (ExportAllBatch, optional -mobs SkeletonSword1Bare,...). Output SpriteSheets/WieldHavenGodot/BareMobs/<Group>/<Slug>Bare. Skeleton camera Y 1.0 and goblin 0.9 put the feet on y=363 like the player sheets. The original SkeletonSword1 Unity config is lost; the bare skeleton is Skeleton1 body + SkeletonArmor1 (no brown cap). Orcs/demons are not re-exported (their exporter belongs to the monster export work); they keep baked weapons and get armor only.
- Godot: Scripts/Build/build_bare_mob_spriteframes.py copies the PNGs and writes SpriteFrames with the same animation names as the old ones; then Godot --import, trim_spriteframes_atlases.py (backup D:/WieldHavenBackups/archive/mob_gear_20261123/trim_backup), Godot --import, set only the *Bare/*/Trimmed/*.trim.png.import files to compress/mode=4 + uastc_level=2 (Basis, like the other enemy sheets; set_player_sheets_basis.py convert enemy would also touch other folders), --import.
- DONE 23.11: SkeletonSword1, SkeletonKingBow1, GoblinRecruit, GoblinScout, GoblinBerserker scenes now reference Assets/Spritesheets/Enemy/<Group>/<Slug>Bare/ (old folders untouched; pets, the loading screen and the online fallback still use the old sheets). These mobs always carry a rolled weapon (axes for melee, bows for ranged) and 50 % a shield/quiver.
Tests
- Scripts/Build/VerifyMobGear.gd (headless): items/sheets exist, roll averages, drop rate, defense bonus, real scene rolls + drop replaces fixed drop, server roll. 285 PASS / 0 FAIL after stage 2.
- Scripts/Build/VerifyMobGearRender.gd (rendered, isolated APPDATA, Start-Process): contact sheets of every geared mob in 4 directions x Idle/Walk/Attack.
Rollback
Originals: D:/WieldHavenBackups/archive/mob_gear_20261123/before/ (same relative paths). New files can be removed: MobGearRules.gd, MobGearVisual.gd, VerifyMobGear*.gd, build_bare_mob_spriteframes.py, Assets/Spritesheets/Enemy/*/*Bare/.
All paper-doll armor sets are items (Janari 23.11.2026)
- Scripts/Build/build_generated_armor_sets.py -> Scripts/Lists/GeneratedArmorSets.gd (117 sets, 468 items, ids 10000 + variant*10 + piece) + Assets/Generated/ArmorSetIcons/<slot>/<variant>.png (HeroEditor4D pack icons; sheet crops when no icon). Equipment.gd appends them in get_generated_set_equipment and supports set "icon_paths". Variant number = index in the pack's sorted armor list (Basic 1-85, Epic 86-115, costumes 116-129), reconstructed by matching helm art to pack icons; existing catalog sets keep their old (art-mismatching) names; clashing new ones are "Epic ..." / "Wild Boar" / "Royal Bowman".
- Open: sets outside the mob themes have no source yet (shop or rare drop - asked Janari); online catalog (Data/Online) does not contain them.
Fewer sheets on screen (Janari 23.11.2026)
- MobGearRules.area_sets: mobs of one 2048 px area cell share AREA_SET_COUNT (3) sets of their family (fixed shuffle per cell); world-wide variety stays. Native passes spawn_position, the server passes the spawn point.
- MobGearVisual loads its sheets only while the mob is on screen (VisibleOnScreenNotifier2D) and frees them 4 s after it leaves. Before: every mob in the world loaded its gear at spawn.
- Measured (run_game_checks, RTX 4080, Unity pack update running in parallel = noisy): no gear 2549 MB / 89 FPS stress_40; all gear at spawn 3134 MB / 76 FPS; area sets + on-screen loading: spawn 2572 MB, stress_40 80-87 FPS / ~3080 MB (40 mobs of four families in one spot).
- WIELDHAVEN_NO_MOB_GEAR=1 hides the gear layers for A/B measurements.
Fully covering armor hides the body part under it (Janari 23.11.2026)
- Scripts/Build/measure_armor_coverage.py measures every Helm/Chest/Gauntlet/Boots variant against the player's Head (union of variants), Body, Arms and Legs in every direction, row and frame (<= 0.2 % visible) -> Scripts/Lists/ArmorCoverage.gd. Result 23.11: 7 helmets cover the head, 86 chests the body, a few gloves/boots.
- Scripts/Player/BodyCoverage.gd (rules) used by Player.update_covered_body_layers (Head, Eyes, Eyebrows, Mouth, Mustache / Body / Armleft / Armright / Legs) and OnlinePlayerVisual.
- Mobs (DONE 23.11): WieldHavenBareMobExporter exports a 4th split "Head" (head, face, ears, hair, kept crown) and Full/Lower/Upper without it; Godot <Slug>Bare_Head.spriteframes.tres. MobGearVisual.set_head draws it (mirrors the upper/full body frame; z from LayerOrder "Head") and hides it when MobGearRules.helmet_covers_head: the worn helmet is a full helmet by the player-head measurement (mob skulls/goblin ears are larger, so no helmet would pass a strict mob-head test; the parts that peeked out at the edges are exactly what Janari wanted gone). Online: OnlineEnemyVisual adds the head on bare bodies. Old Trimmed sheets and frames before the head split: D:/WieldHavenBackups/archive/mob_gear_20261123/bare_before_head_split/.
- 23.11 after skipping off-screen and unchanged updates in MobGearVisual (cache key = animation hash + frame + source sprite; off-screen mobs do nothing): run_game_checks ALL PASSED, spawn 236 FPS / 2552 MB, brawl_12 195 FPS, stress_40 91.9 FPS p99 15.7 ms / 3034 MB (test-results/game_checks/20261123_232815).
Orcs and demons: always a full helmet (Janari 23.11.2026, "pigem asendame full kiivriga pea")
- MOB_PROFILES orc/demon: "full_helmet": true -> helmet slot always filled from FULL_HELMETS (orc 86/102/100, demon 98/102/126; all pass the player full-head measurement); bosses: Orc Warlord 10860 (H86), Demon Lord 2110 (A98). Their head layer is then always hidden.
- WieldHavenBareMobExporter.OrcDemonPresets builds them through WieldHavenOrcDemonSpriteSheetExporter.CreateCharacter (reflection; same body, armor, skin, baked weapon/shield), head + horns + baked helmet on the Head layer. Godot Assets/Spritesheets/Enemy/{Orcs,Demons}/<Slug>Bare/, the 8 scenes point there (originals in the archive). They are not BARE_BASE (no weapon roll; weapons stay baked).
Paused 23.11.2026 ~23:45 (owner shut down the PC)
- Done and tested: everything above (VerifyMobGear 1358 PASS; rendered preview OK).
- Last run_game_checks (20261123_234136): all FPS budgets pass (stress_40 88.6 FPS), only "armor one swap worst frame" 28 ms > 16.7 (the player-armor swap test; it also failed once earlier and passed on rerun - likely contention with mob gear/head streaming; investigate first: give mob gear streaming lower priority than player armor in FrameStreamer).
- Next: that check; then send Janari the orc/demon full-helmet preview (scratchpad image is gone after reboot - re-render with Scripts/Build/VerifyMobGearRender.gd).
24.11.2026: armor-swap spike follow-up
- FrameStreamer got a background lane (request(..., low_priority=true)): mob gear sheets and mob heads wait while any player request is queued/loading and at most 1 is handed over per frame; a player request for the same path promotes it.
- A/B, armor check only, 4 runs each: with mob gear worst swap frame 8-14 ms (all PASS), WIELDHAVEN_NO_MOB_GEAR=1 6 ms. In full run_game_checks the 28 ms swap frame still appeared in 1 of 2 runs (20261124_151837); FPS budgets all pass (stress_40 82-83 FPS). Likely a GPU upload of a just-arrived mob sheet on its first draw coinciding with the swap. Open, low impact.
- run 20261124_151522 also had "play: dodge_moves" fail once (player blocked / slow 16.5 s world load); passed in the other run; not related to gear code as far as checked.
24.11.2026: armor loading research (owner asked: keep all armor loaded?)
- Instrumented (FrameStreamer.slow_log, game_check_armor prints frames > 12 ms): the rare 21-24 ms frame happens while the player's new set (20 sheets) reaches the GPU; hand-overs themselves cost 0.01 ms. With mob gear typical 8-14 ms, without 6 ms. Tried and reverted: MAX_IN_FLIGHT 1, background-lane pause/throttle after player work, no gear release - none removed the rare spike.
- All armor sheets resident = ~4.2 GB VRAM (+ weapons 3.4 GB, body 1.7 GB; 1 B/px Basis/BC7, measured from Trimmed sheet sizes). Not feasible, especially for instanced multiplayer.
- Options given to Janari: (1) now: prefetch equipped + inventory armor on area entry with a VRAM cap (~300 MB) and LRU; (2) long-term: runtime skeletal characters (HeroEditor4D bones + part sprites exported from Unity, drawn by bone transforms in Godot) - all sets in tens of MB, instant swaps, sharp at 4K. Waiting for the owner's choice.
- DONE 24.11 (Janari "jah palun"): Scripts/Player/ArmorPrefetch.gd (child of Player) keeps the sheets of equipped + bag Equipment items in memory (BUDGET_SHEETS 180 ~ 300 MB), checks every 2 s, loads in batches of 6 through FrameStreamer's background lane, first check 3 s after spawn. game_check_armor "owned vest swap instant": 0.7-0.9 ms; first unseen armor worst frame 5.3-6.0 ms (was up to 24 ms). VRAM +~300-400 MB. All FPS budgets pass (stress_40 82-90 FPS). Mob heads load through the normal lane (in the background lane they waited behind the prefetch and mobs stayed invisible).
- Flaky, not gear-caused as far as checked: play "enemy_attack_starts" fails ~1/6: the GoblinRecruit stays in CHASE with Ready stance ~236 px away (GOBLIN_PROBE line in the play log).
- Next approved step (later): one-animation prototype of runtime skeletal characters.