Files
2006Scape/2006Scape Server/src/main/java/com/rs2/game/objects
Josh Shippam c37e3e8dfb Various Changes & Issue Fixes (#686)
* fix(client): restore authentic 317/377 minimap fallback walk radius in doWalkTo

Restores the client-side pathfinding fallback search radius in `Game.doWalkTo` to match authentic 2006 RS2 / 317 client behavior when clicking unreachable tiles such as underground void or blocked terrain. Previously, the search radius was restricted to a single tile, causing minimap and ground clicks more than one tile into unwalkable areas to be silently ignored.

### Bug Fixes & Edge Cases
- `2006Scape Client/src/main/java/Game.java` (`doWalkTo`):
  - Expanded the alternative-destination search loop from `k5 < 2` (1-tile radius) to `k5 < 11` (10-tile Chebyshev radius, matching authentic 317/377 clients) when `flag` is `true` and the exact target tile is unreachable.
  - Preserves the existing `i5 = 100` maximum path-cost threshold and `104x104` region boundary checks (`i6 >= 0 && l6 >= 0 && i6 < 104 && l6 < 104`), allowing players to walk to the nearest reachable tile when clicking black void on the minimap.

Closes #380

* fix(firemaking): fix fire lighting race, object sync, level scaling, and log walk-on

Fixes firemaking reliability, object lifecycle desyncs, and authentic 2006 RS2 movement and level-scaling behavior on the server. Previously, rapid firemaking could cancel the next attempt and still spawn phantom ashes, fires were spawned on hardcoded height 0 with mismatched ObjectManager/ObjectHandler state, and ground-log lighting triggered from an adjacent tile instead of walking onto the logs first.

### Bug Fixes & Edge Cases
- `2006Scape Server/src/main/java/com/rs2/game/content/skills/firemaking/Firemaking.java`:
  - Removed the delayed `stopFiremaking(c)` call from the 2-tick post-lighting `turnPlayerTo` event so rapid consecutive firemaking attempts no longer cancel the next log's cycle.
  - Moved the `100 + Misc.random(98)` tick fire-despawn and ashes (`592`) event inside the lit branch so aborted/cancelled attempts never leave behind phantom ashes.
  - Spawned fires on `c.heightLevel` (instead of `0`) and removed `fireObj` directly from `GameEngine.objectManager.objects` via `updateObject(fireObj)` on burnout, eliminating `ObjectManager` stale-entry desyncs.
  - Replaced the redundant 4-iteration `firemakingItems` loop with `isFiremakingItem(...)`, gated colored firelighters (`7329`, `7330`, `7331`) to regular logs (`1511`), and ensured `stopFiremaking` / skilling interruptions call `container.stop()`.
- `2006Scape Server/src/main/java/com/rs2/game/items/UseItem.java`:
  - Fixed the `||` / `&&` operator precedence bug on `firemakingItems` checks and added `break` after matching a firemaking item.
- `2006Scape Server/src/main/java/com/rs2/net/packets/impl/ItemOnGroundItem.java`:
  - Added `isFiremakingItem(...)` and `isInRange(...)` so using a tinderbox or firelighter on ground logs requires standing on `(gItemX, gItemY)` rather than stopping 1 tile away.

### Authentic 2006 RS2 Behavior
- `2006Scape Server/src/main/java/com/rs2/game/content/skills/firemaking/Firemaking.java`:
  - Moved `Region.getClipping` step-off (`West -> East -> South -> North`) and `walkTo` to execute when the fire catches rather than when lighting begins, and turned the player to `(x, y)` after stepping off.
  - Added `canLightLog(int level, LogData log)` using RS2 `interpolate(low, high, level)` rolls out of 256 (re-rolling every 3 ticks on failure with animation `733` and `SoundList.FIRE_LIGHT`).
- `2006Scape Server/src/main/java/com/rs2/world/clip/Region.java` & `Firemaking.java`:
  - Added `Region.hasSceneryObject(x, y, z)` (`objectType >= 9 && objectType != 22`) and `Firemaking.isTileBlocked(x, y, height)` checking `ObjectManager`, `ObjectHandler`, static scenery objects, and tile clipping (`0x1280100`) before starting and before spawning the fire.

Closes #295
Closes #543

* fix(objects): preserve cache-defined orientation when opening and closing chests

Fixes chest and toggleable object rotation bugs where opening or closing an object not listed in `ObjectDefaults.GET_FACE` rotated it to face South (`0`), and `OpenObject` passed swapped `type`/`face` arguments to `Region.addObject`. Looking up the existing object's orientation from `Region` and `ObjectHandler` ensures all toggleable objects preserve their cache-defined facing across the world.

### Bug Fixes & Edge Cases
- `2006Scape Server/src/main/java/com/rs2/game/objects/ObjectDefaults.java`:
  - Updated `getObjectFace(Player, int)` to check `Region.getObject(...)` and `GameEngine.objectHandler.objectExists(...)` for the current object's `objectFace` before falling back to the hardcoded `GET_FACE` / `switch` defaults.
- `2006Scape Server/src/main/java/com/rs2/game/objects/impl/OpenObject.java`:
  - Preserved the object's `face` and `objectType` when toggling between closed and open IDs in `OBJECT_DATA`.
  - Removed the previous object from `Region` and `GameEngine.objectHandler.globalObjects` before adding and placing the toggled object, and fixed the swapped `type`/`face` parameter order in `Region.addObject(newId, x, y, h, type, face, false)`.

Closes #549

* fix(desert): start desert heat timer on entry and remove shared static state

Fixes instantaneous desert heat damage when entering the desert, eliminates per-tick `CycleEvent` accumulation, and removes shared `static` state across players. Previously, `player.lastDesert` defaulted to `0` on login and was never reset on exit, causing immediate damage on the first tick inside `Boundary.DESERT`, while `Player.process()` queued a new `CycleEvent` every tick.

### Bug Fixes & Edge Cases
- `2006Scape Server/src/main/java/com/rs2/game/players/Player.java`:
  - Updated `process()` to invoke `DesertHeat.callHeat(this)` unconditionally so `lastDesert` resets whenever the player leaves `Boundary.DESERT`, moves off `heightLevel == 0`, or enters `Boundary.NO_HEAT`.
- `2006Scape Server/src/main/java/com/rs2/game/content/traveling/DesertHeat.java`:
  - Initialized `player.lastDesert = now` on desert heat entry (`lastDesert == 0`) instead of applying damage on the first tick, and reset `lastDesert = 0` when outside desert heat.
  - Evaluated the `90s` base (`+10s` per equipped desert clothing piece) timer directly per tick in `callHeat(Player)` rather than spawning duplicate 1-tick `CycleEvent`s.
  - Replaced shared `static int DAMAGE` and `static int waterskin` fields with per-hit `1 + Misc.random(9)` (`1-10`) damage rolls and a local `checkWaterskin(Player)` loop.
  - Replaced hardcoded waterskin item IDs with `StaticItemList.WATERSKIN0` through `StaticItemList.WATERSKIN4` ordered from lowest to highest dose.

Closes #596

* fix(shops): start restock timer on purchase from full stock

Fixes instantaneous restocking of the first item purchased from a fully stocked shop and cleans up shop tick processing. Previously, `shopItemsRestock[shop_id][j]` remained `0` (or stale) when a player bought from full stock, causing `ShopHandler.process()` to immediately restock 1 item on the next tick.

### Bug Fixes & Edge Cases
- `2006Scape Server/src/main/java/com/rs2/game/shops/ShopHandler.java`:
  - Updated `buyItem(int, int, int)` to set `shopItemsRestock[shop_id][j] = System.currentTimeMillis()` and reset `shopItemsDelay[shop_id][j] = 0` when a purchase reduces stock from at/above standard stock (`shopItemsSN`) to below `shopItemsSN`, without resetting an in-progress restock timer on subsequent purchases.
  - Fixed the off-by-one standard-stock boundary in `process()` (`j < shopItemsStandard[i]` instead of `<=`), removed the redundant `shopItemsDelay[i][j] = 1;` assignment, and gated `refreshshop(i)` on `shopUpdated` so unchanged shops are not broadcast every tick.
  - Cleared `shopItemsRestock[shopID][ArrayID] = 0` in `ResetItem(int, int)` when a shop slot is emptied.

Closes #595

* feat(randomevents): migrate random events, lamps, and Thessalia to Kotlin plugins and add ::randomevent

Rewrite all legacy Java random events, experience lamps, and Thessalia interactions into Kotlin plugins under plugins/game/content/randomevents/, plugins/game/content/items/lamps/, plugins/npc/thessalia/, and Revision 377 quest packages, while adding Zanaris Choir and developer testing commands. Core Java hooks now post RandomActionEvent and NpcDeathEvent, preserve legacy save migration via PlayerPluginData, and enforce authentic 2006 RS2 (Revision 377) mechanics, dialogues, and variable XP rate scaling.

### Command Infrastructure
- `RandomActionEvent.java` & `NpcDeathEvent.java`:
  - Added core event classes posted from skilling/action/shop handlers (`Fishing`, `Woodcutting`, `Mining`, `Prayer`, `ShopAssistant.openShop`, `Cooking`, `Potatoes`, `Runecrafting`, `SoftClay`, `SearchForTraps`, `Pickpocket`, `Stalls`, `MagicTeleports`, `PlayerAssistant`, `NpcHandler`) and NPC death processing.
- `ClickNPC.java` & `NpcHandler.java`:
  - Fixed `ClickNPC` to pass `npc.npcId` instead of `player.npcClickIndex` (which `firstClickNpc` resets to `0`) to `NpcFirstClickEvent`.
  - Added `NpcHandler.spawnNpcReturn` and guarded `npcs[i] == null` after `Player.postNpcTick` to prevent NPEs when tick plugins despawn NPCs.
- `Player.java` & `PlayerSave.java`:
  - Removed obsolete random event fields from `Player` while migrating legacy `randomActions` and `recievedReward` save keys into `PlayerPluginData`.

### Migrated Command Plugins
- `RandomToggle.kt` (`::random`, `::randomtoggle`, `::togglerandom`):
  - Migrated `randomEventsEnabled` toggling out of `Commands.java` into `plugins/commands/`.
- `Teleport.kt` (`::teleport`, `::tele`):
  - Added `zanaris` (`2452, 4470, 0`) to `NAMED_LOCATIONS` and `VALID_CITIES_MESSAGES`.

### New Search Commands
- `TriggerRandomEvent.kt` (`::randomevent <name>`, `::randomevents`, `::revent`):
  - Added developer command plugin to trigger `sandwich`, `chicken`, `forester`, `swarm`, `genie`, `frog`, `troll`, `golem`, `spirit`, `shade`, `zombie`, and `choir` on demand, with multi-line help and Zanaris location hint.

### Random Event & Lamp Plugins
- `RandomEventSupport.kt`, `RandomEventDispatcherPlugin.kt`, `RandomEventNpcDeathPlugin.kt`, & `RandomEventFollowPlugin.kt`:
  - Implemented per-player session state, clipped adjacent tile spawning, active NPC slot tracking, unified non-combat NPC following/facing/despawn (`GENIE`, `SANDWICH_LADY`, `FROG_PRINCE`, `FROG_PRINCESS`, `ZANARIS_CHOIR`), and global guards (`randomEventsEnabled`, `!inFightCaves()`, `tutorialProgress >= 36`, `MONKEY_GREEGREE`).
- `CombatRandoms.kt`:
  - Unified `EvilChicken`, `RiverTroll` (Fishing), `RockGolem` (Mining), `TreeSpirit` (Woodcutting), `Shade` & `Zombie` (Prayer bone burying), and `Swarm` with full `3..138` combat level coverage.
- `GeniePlugin.kt`, `SandwichLadyPlugin.kt`, `SandwichLadyTalkPlugin.kt`, `FrogPlugin.kt`, `FreakyForesterPlugin.kt`, `FreakyForesterPortalPlugin.kt`, `ZanarisChoirPlugin.kt`, & `ZanarisChoirTalkPlugin.kt`:
  - Implemented authentic 2006 RS2 NPC spawns, dialogues (`Master`/`Mistress` Genie greeting, Kiss-the-Frog, Freaky Forester 1–4 tail pheasants, Sandwich Lady tray `16135`, Zanaris Choir), and `DialogueFactory.onAction` reward/despawn sequencing.
- `LampInterfaceSupport.kt` & Revision 377 Lamp Plugins:
  - Replaced `ExperienceLamp.java` with config `261` (`1..21`) skill highlighting and `VARIABLE_XP_RATE` / `XP_RATE` scaling across Genie Lamp (`2528`, `10 * level`), One Small Favour (`4447`, level 30+, `10,000` XP), A Tail of Two Cats (`6543`, level 30+, `2,500` XP), Shadow of the Storm (`6796`, combat skills, `10,000` XP), and Recipe for Disaster (`7498`, level 50+, `20,000` XP).
- `ThessaliaFirstClickPlugin.kt` & `ThessaliaSecondClickPlugin.kt`:
  - Migrated Thessalia (`548`) Talk-to shop/Frog Token (`6183`) exchange and Trade (`shop 12`) actions out of `DialogueHandler` and `Shops.java` into `plugins/npc/thessalia/`.

### Cleanups & Deprecations
- Removed all 12 legacy Java classes under `com/rs2/game/content/randomevents/`, `ExperienceLamp.java`, and dead random-event/dialogue/button hooks across `ClickingButtons.java`, `ClickItem.java`, `DialogueHandler.java`, `NpcActions.java`, `ObjectsActions.java`, and `Shops.java`.

* feat(audio): overhaul 377 music, audio playback, and GameOptionsPlugin

Overhauls the 2006Scape Server and Client audio systems to match authentic 2006 RS2 (Revision 377) behavior, fixing MIDI deadlocks, volume persistence, title-screen music handoff, and varp-driven track unlocking. Consolidates all interface 904 Settings-tab buttons into a single Kotlin plugin and populates PlayList and Music with cache-verified 377 track and region mappings.

### Audio & Client Playback Fixes
- `Class56_Sub1_Sub1.java` & `Class56.java` & `Class56_Sub1_Sub2.java`
  - Split `RECEIVER_LOCK` from `MIDI_LOCK` so Java Sound's `Sequencer.stop()` cannot deadlock against `Receiver.send(...)` when switching tracks.
  - Replaced `method835(0, i, -1L)` with `method840(i, -1L)` in `method827` to reset all 16 channel volumes and unconditionally apply `musicVolume` on track changes.
  - Added `setLoop(boolean loop, boolean restartIfStopped)` to toggle looping live via `config 19` and rewind/restart finished tracks when `LOOP` is enabled while unmuted.
- `Game.java` & `DesktopHooks.java` & `SoundPlayer.java`
  - Stops title-screen `Scape Main` on login (`method55(false); currentSong = -1;`) so region music starts immediately.
  - Respects `!loggedIn || variousSettings[19] == 1` for track looping while keeping jingles one-shot.
  - Replaced unbounded per-sound thread creation in `SoundPlayer` with a 4-thread daemon executor and try-with-resources stream/line cleanup, and fixed `DesktopHooks` MIDI receiver/synthesizer cleanup.
- `HdMaterial.java`
  - Added `populateSingleLayer(int layerId, ByteBuffer diffuseLayerBuf, ByteBuffer normalLayerBuf)` sharing `writeLayerToBuffers` for memory-constrained Android texture streaming.

### Server Music & Playlist Architecture
- `PlayList.java`
  - Mapped all 383 clickable songs from `interface 962` to cache-verified `idx3` MIDI IDs and the 14 native RS2 music unlock varps (`20, 21, 22, 23, 24, 25, 298, 311, 346, 414, 464, 598, 662, 721`), fixing 25 legacy mis-mapped song IDs and `FAITHLESS` `childId` (`10129`).
  - Replaced `fixAllColors()` `sendColor` bursts with `sendMusicConfigs()` sending the 14 music varps plus `config 18` (`AUTO`/`MAN`) and `config 19` (`LOOP`), handling `Strange Place` (`464`, bit `17`) natively.
  - Fixed `AUTO` (`24125`), `MAN` (`24126`), and `LOOP` (`38197`) action button IDs in `handleButton`.
- `Music.java`
  - Expanded `MUSIC_DATA` to 517 unique regions cross-checked against the 377 `map_index`, `LostCityRS`, and OSRS Wiki polygons, and fixed Ape Atoll `(43, 43)` to `303` (`Monkey Madness`) and 73 legacy mismatches.
  - Removed `player.musicOn` gates in `Music.playMusic`, `ChangeRegions`, `ClickingButtons`, and `PacketSender.login` so tracks still unlock and `PlayList` controls work while muted.
- `PacketSender.java` & `Player.java` & `PlayerSave.java`
  - Flushed `sendSong` immediately and standardized `sendSound` on packet 174 (`id`, `volume`, `delay`).
  - Persisted `musicVolume`, `soundVolume`, `mouseButton`, `chatEffects`, and `acceptAid` in `PlayerSave` and synced configs `168`, `169`, `170`, `171`, `287`, and `427` on login.

### New & Migrated Plugins
- `GameOptionsPlugin.kt`
  - Migrated `BrightnessButtons.java`, `MusicVolumeButtons.java`, `SoundVolumeButtons.java`, and `ToggleSplitChatButtons.java` plus `Mouse Buttons` (`3145`/`3146`), `Chat Effects` (`3147`/`3148`), and `Accept Aid` (`48176`/`48177`) into a single Kotlin plugin using named constants and lookup maps, removing legacy `500`–`503` configs and stale `74176`/`74180`/`74188` cases from `ClickingButtons.java`.
- `UnlockSongs.kt`
  - Added developer command `::unlocksongs` (`::unlockmusic`, `::allsongs`) to unlock all playlist tracks and refresh music varps.

* fix(client): replace ThreadFactory lambda in SoundPlayer for JDK 8 javac

Replaces the `ThreadFactory` lambda in `SoundPlayer.SOUND_EXECUTOR` with an anonymous `ThreadFactory` class to resolve a JDK 8 `javac` definite-assignment bug (`variable r might not have been initialized`) hit by GitHub Actions CI on PR #686.

### Bug Fixes
- `SoundPlayer.java`
  - Replaced `r -> { ... }` in `Executors.newFixedThreadPool(4, ...)` with an anonymous `ThreadFactory` implementation.

* refactor(combat): replace DeprecatedItems.getItemName with ItemDefinition.lookup in AutocastCancelButtonPlugin

Removes the deprecated `DeprecatedItems.getItemName(weaponId)` call from `AutocastCancelButtonPlugin.kt` in favor of `ItemDefinition.lookup(weaponId)?.name`, eliminating the Kotlin compiler deprecation warning.

### Cleanups & Deprecations
- `AutocastCancelButtonPlugin.kt`
  - Replaced `DeprecatedItems.getItemName(weaponId)` with `ItemDefinition.lookup(weaponId)?.name ?: "Unarmed"` (preserving `"Unarmed"` when `weaponId == -1`).

* build(maven): set explicit UTF-8 source and reporting encoding across modules

Configures `project.build.sourceEncoding` and `project.reporting.outputEncoding` to `UTF-8` in the root and server POMs so resource filtering and Java compilation are platform-independent and free of platform-encoding warnings.

### Build Configuration
- `pom.xml` & `2006Scape Server/pom.xml`
  - Added `<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>` and `<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>`.

* style(client): fix space-before-tab indentation in Class56_Sub1_Sub2

Replace mixed space-and-tab indentation with spaces in Class56_Sub1_Sub2 to clear the git diff --check whitespace lint prior to merging PR #686.

### Cleanups & Deprecations
- 2006Scape Client/src/main/java/Class56_Sub1_Sub2.java:
  - Normalized line 34 indentation inside setLoop(boolean, boolean) from space-before-tab to 8 spaces.

* fix(audio): remove post-377 Stronghold of Security song entries from Music

Remove the four legacy Stronghold of Security region music mappings from Music.java so MUSIC_DATA stays strictly aligned with Revision 377 (May 2006) tracks and PlayList idx3 entries.

### Cleanups & Deprecations
- 2006Scape Server/src/main/java/com/rs2/game/content/music/Music.java:
  - Removed pre-existing post-377 Stronghold of Security entries { 29, 81, 537 }, { 31, 81, 558 }, { 33, 82, 559 }, and { 36, 81, 560 } from MUSIC_DATA.
2026-12-02 00:08:13 +00:00
..
2026-12-02 00:08:13 +00:00
2021-03-11 00:30:16 +00:00
2026-12-01 03:21:56 +00:00