From 0930e66e54008c9daab953b3cbb3bbc3a051507b Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 29 Feb 2020 16:10:10 -0500 Subject: [PATCH 01/63] Cache definitions, update server and most of login done for rev 181. --- build.gradle | 4 +- cache/build.gradle | 4 + .../main/java/org/apollo/cache/Archive.java | 595 +++++++++++++++++ .../src/main/java/org/apollo/cache/Cache.java | 253 +++++++ .../java/org/apollo/cache/CacheBuffer.java | 631 ++++++++++++++++++ .../java/org/apollo/cache/FileDescriptor.java | 66 -- .../org/apollo/cache/FileSystemConstants.java | 42 -- .../src/main/java/org/apollo/cache/Group.java | 593 ++++++++++++++++ .../main/java/org/apollo/cache/Helper.java | 277 ++++++++ .../src/main/java/org/apollo/cache/Index.java | 344 ++++++++-- .../org/apollo/cache/IndexedFileSystem.java | 332 --------- .../main/java/org/apollo/cache/RSFile.java | 185 +++++ .../org/apollo/cache/StringUtilities.java | 142 ++++ .../main/java/org/apollo/cache/Whirlpool.java | 416 ++++++++++++ .../org/apollo/cache/archive/Archive.java | 110 --- .../apollo/cache/archive/ArchiveEntry.java | 51 -- .../apollo/cache/archive/package-info.java | 4 - .../cache/decoder/ItemDefinitionDecoder.java | 177 +++-- .../cache/decoder/NpcDefinitionDecoder.java | 229 ++++--- .../decoder/ObjectDefinitionDecoder.java | 227 ++++--- .../org/apollo/cache/def/ItemDefinition.java | 425 +++++++++++- .../org/apollo/cache/def/NpcDefinition.java | 216 +++++- .../apollo/cache/def/ObjectDefinition.java | 343 ++++++++++ .../org/apollo/cache/map/MapConstants.java | 2 +- .../java/org/apollo/cache/map/MapIndex.java | 223 +++---- .../org/apollo/cache/map/MapIndexDecoder.java | 49 +- ...sDecoder.java => MapLandscapeDecoder.java} | 30 +- ...ileDecoder.java => MapTerrainDecoder.java} | 38 +- .../org/apollo/cache/map/XteaDecoder.java | 61 ++ .../apollo/cache/tools/EquipmentUpdater.java | 19 +- game/data/equipment-181.dat | Bin 0 -> 52238 bytes game/data/net.xml | 3 +- .../locations/al-kharid/src/npcs.plugin.kts | 114 ---- .../locations/al-kharid/src/shops.plugin.kts | 146 ---- .../locations/edgeville/src/npcs.plugin.kts | 53 -- .../locations/edgeville/src/shops.plugin.kts | 31 - .../locations/falador/src/npcs.plugin.kts | 171 ----- .../locations/falador/src/shops.plugin.kts | 76 --- .../locations/lumbridge/src/npcs.plugin.kts | 15 - .../locations/lumbridge/src/shops.plugin.kts | 42 -- .../tutorial-island/src/npcs.plugin.kts | 44 -- .../locations/varrock/src/npcs.plugin.kts | 268 -------- .../locations/varrock/src/shops.plugin.kts | 176 ----- game/src/main/java/org/apollo/Server.java | 59 +- .../main/java/org/apollo/ServerContext.java | 12 +- .../game/fs/decoder/WorldMapDecoder.java | 14 +- .../game/fs/decoder/WorldObjectsDecoder.java | 16 +- .../java/org/apollo/game/model/World.java | 31 +- .../area/collision/CollisionManager.java | 6 +- .../game/release/r181/ReleaseOSRS181.java | 126 ++++ .../apollo/game/service/UpdateService.java | 31 +- .../org/apollo/game/session/LoginSession.java | 39 +- .../apollo/game/session/UpdateSession.java | 29 +- gradle/properties.gradle | 6 +- .../java/org/apollo/net/NetworkConstants.java | 16 +- .../net/codec/handshake/HandshakeDecoder.java | 21 +- .../apollo/net/codec/login/LoginDecoder.java | 93 +-- .../net/codec/login/LoginDecoderState.java | 6 - .../apollo/net/codec/login/LoginEncoder.java | 6 +- .../apollo/net/codec/login/LoginRequest.java | 13 +- .../apollo/net/codec/login/LoginResponse.java | 44 +- .../update/OnDemandEncryptionMessage.java | 14 + .../apollo/net/codec/update/OnDemandInfo.java | 14 + .../net/codec/update/OnDemandInfoEncoder.java | 13 + .../codec/update/OnDemandInfoResponse.java | 14 + .../net/codec/update/OnDemandRequest.java | 26 +- .../net/codec/update/OnDemandResponse.java | 60 +- .../codec/update/OnDemandResponseEncoder.java | 48 ++ .../net/codec/update/UpdateDecoder.java | 34 +- .../net/codec/update/UpdateEncoder.java | 35 - .../apollo/net/update/HttpRequestWorker.java | 4 +- .../net/update/JagGrabRequestWorker.java | 4 +- .../net/update/OnDemandRequestWorker.java | 46 +- .../resource/VirtualResourceProvider.java | 12 +- .../main/java/org/apollo/util/BufferUtil.java | 12 + 75 files changed, 5526 insertions(+), 2605 deletions(-) create mode 100644 cache/src/main/java/org/apollo/cache/Archive.java create mode 100644 cache/src/main/java/org/apollo/cache/Cache.java create mode 100644 cache/src/main/java/org/apollo/cache/CacheBuffer.java delete mode 100644 cache/src/main/java/org/apollo/cache/FileDescriptor.java delete mode 100644 cache/src/main/java/org/apollo/cache/FileSystemConstants.java create mode 100644 cache/src/main/java/org/apollo/cache/Group.java create mode 100644 cache/src/main/java/org/apollo/cache/Helper.java delete mode 100644 cache/src/main/java/org/apollo/cache/IndexedFileSystem.java create mode 100644 cache/src/main/java/org/apollo/cache/RSFile.java create mode 100644 cache/src/main/java/org/apollo/cache/StringUtilities.java create mode 100644 cache/src/main/java/org/apollo/cache/Whirlpool.java delete mode 100644 cache/src/main/java/org/apollo/cache/archive/Archive.java delete mode 100644 cache/src/main/java/org/apollo/cache/archive/ArchiveEntry.java delete mode 100644 cache/src/main/java/org/apollo/cache/archive/package-info.java rename cache/src/main/java/org/apollo/cache/map/{MapObjectsDecoder.java => MapLandscapeDecoder.java} (60%) rename cache/src/main/java/org/apollo/cache/map/{MapFileDecoder.java => MapTerrainDecoder.java} (76%) create mode 100644 cache/src/main/java/org/apollo/cache/map/XteaDecoder.java create mode 100644 game/data/equipment-181.dat delete mode 100644 game/plugin/locations/al-kharid/src/npcs.plugin.kts delete mode 100644 game/plugin/locations/al-kharid/src/shops.plugin.kts delete mode 100644 game/plugin/locations/edgeville/src/npcs.plugin.kts delete mode 100644 game/plugin/locations/edgeville/src/shops.plugin.kts delete mode 100644 game/plugin/locations/falador/src/npcs.plugin.kts delete mode 100644 game/plugin/locations/falador/src/shops.plugin.kts delete mode 100644 game/plugin/locations/lumbridge/src/npcs.plugin.kts delete mode 100644 game/plugin/locations/lumbridge/src/shops.plugin.kts delete mode 100644 game/plugin/locations/tutorial-island/src/npcs.plugin.kts delete mode 100644 game/plugin/locations/varrock/src/npcs.plugin.kts delete mode 100644 game/plugin/locations/varrock/src/shops.plugin.kts create mode 100644 game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java create mode 100644 net/src/main/java/org/apollo/net/codec/update/OnDemandEncryptionMessage.java create mode 100644 net/src/main/java/org/apollo/net/codec/update/OnDemandInfo.java create mode 100644 net/src/main/java/org/apollo/net/codec/update/OnDemandInfoEncoder.java create mode 100644 net/src/main/java/org/apollo/net/codec/update/OnDemandInfoResponse.java create mode 100644 net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java delete mode 100644 net/src/main/java/org/apollo/net/codec/update/UpdateEncoder.java diff --git a/build.gradle b/build.gradle index c1756fcf0..88f7364a8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '1.3.41' apply(false) + id 'org.jetbrains.kotlin.jvm' version '1.3.61' apply(false) id 'org.jetbrains.intellij' version '0.4.9' apply(false) id 'org.jmailen.kotlinter' version '1.26.0' apply(false) id 'org.sonarqube' version '2.7.1' @@ -15,6 +15,8 @@ allprojects { maven { url "https://repo.maven.apache.org/maven2" } maven { url "https://dl.bintray.com/kotlin/kotlinx/" } } + + } apply from: 'gradle/properties.gradle' diff --git a/cache/build.gradle b/cache/build.gradle index af79e12dd..755407a6b 100644 --- a/cache/build.gradle +++ b/cache/build.gradle @@ -5,6 +5,10 @@ description = 'Apollo Cache' dependencies { implementation project(':util') implementation group: 'com.google.guava', name: 'guava', version: guavaVersion + implementation group: 'org.tukaani', name: 'xz', version: '1.8' + implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.1' + implementation group: 'org.apache.ant', name: 'ant', version: '1.10.7' + implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6' test.useJUnitPlatform() testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion diff --git a/cache/src/main/java/org/apollo/cache/Archive.java b/cache/src/main/java/org/apollo/cache/Archive.java new file mode 100644 index 000000000..e3ece280f --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Archive.java @@ -0,0 +1,595 @@ +package org.apollo.cache; + +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectCollection; + +import java.util.Comparator; + +public class Archive { + + /** + * Underlying cache. + */ + private Cache cache; + /** + * Contains ID of the file system. + */ + private int id; + + /** + * Wheter to use automatic version incrementor. + */ + private boolean useAutomaticVersionIncremetor = true; + + /** + * Contains all groups by id. + */ + private Int2ObjectLinkedOpenHashMap folders; + + /** + * Contains all groups by name. + */ + private Int2IntOpenHashMap foldersByName; + + /** + * Wheter whirlpool hashes are used. + */ + private boolean useWhirlpool; + /** + * Wheter names are used. + */ + private boolean useNames; + + /** + * Whether compression lenths are used. + */ + private boolean useCompressionLengths; + + /** + * Whether flag8 is used. + */ + private boolean useFlag8; + + /** + * Version of this file system. + */ + private int version; + /** + * CRC32 of this file system. + */ + private int crc; + /** + * 64byte whirlpool digest + * of this file system. + */ + private byte[] digest; + + /** + * Contains packed filesystem file + * which was provided with load() call. + */ + private CacheBuffer packed; + /** + * Wheter any changes were made to + * file system properties such as version or properties. + */ + private boolean changed; + + private int protocol = 7; + + public Archive(int id, Cache cache) { + this.id = id; + this.cache = cache; + } + + /** + * Tries to load this file system from cache. + */ + public void load() { + //if (isLoaded()) + // throw new RuntimeException("Already loaded!"); + CacheBuffer buffer = cache.getMasterIndex().get(id); + if (buffer == null) throw new RuntimeException("Missing filesystem file."); + + CacheBuffer unpacked = Helper.decodeFITContainer(buffer); + + unpacked.setPosition(0); + + protocol = unpacked.readUByte(); + if (protocol >= 6) version = unpacked.readInt(); + + int properties = unpacked.readUByte(); + useNames = (properties & 0x1) != 0; + useWhirlpool = (properties & 0x2) != 0; + useCompressionLengths = (properties & 0x4) != 0; + useFlag8 = (properties & 0x8) != 0; + + int foldersLength = protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort(); + folders = new Int2ObjectLinkedOpenHashMap<>(); + foldersByName = new Int2IntOpenHashMap(); + + int[] folderIDS = new int[foldersLength]; + int[] folderNames = new int[foldersLength]; + int[] folderCRCS = new int[foldersLength]; + byte[][] folderDigests = new byte[foldersLength][64]; + int[] folderVersions = new int[foldersLength]; + int[][] folderFilesIDS = new int[foldersLength][]; + int[][] folderFilesNames = new int[foldersLength][]; + + for (int offset = 0, i = 0; i < foldersLength; i++) + folderIDS[i] = offset += (protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort()); + + for (int i = 0; i < foldersLength; i++) + folderNames[i] = useNames ? unpacked.readInt() : -1; + + for (int i = 0; i < foldersLength; i++) + folderCRCS[i] = unpacked.readInt(); + + if (useWhirlpool) { + for (int i = 0; i < foldersLength; i++) + unpacked.readBytes(folderDigests[i], 0, 64); + } + + for (int i = 0; i < foldersLength; i++) + folderVersions[i] = unpacked.readInt(); + + for (int i = 0; i < foldersLength; i++) { + int filesCount = protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort(); + folderFilesIDS[i] = new int[filesCount]; + folderFilesNames[i] = new int[filesCount]; + } + + for (int i = 0; i < foldersLength; i++) + for (int offset = 0, a = 0; a < folderFilesIDS[i].length; a++) + folderFilesIDS[i][a] = offset += (protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort()); + + for (int i = 0; i < foldersLength; i++) + for (int a = 0; a < folderFilesIDS[i].length; a++) + folderFilesNames[i][a] = useNames ? unpacked.readInt() : -1; + + for (int i = 0; i < foldersLength; i++) { + var folder = new Group(folderIDS[i], folderNames[i], folderVersions[i], folderCRCS[i], folderDigests[i], + folderFilesIDS[i], folderFilesNames[i]); + folders.put(folder.getID(), folder); + if (folder.hasName()) { + foldersByName.put(folder.getName(), folder.getID()); + } + } + + updateHashes(buffer); + + packed = buffer; + } + + /** + * Delete's all folders on this filesystem. + * Reset's version to 0. + */ + public void reset() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + changed = true; + folders.clear(); + version = 0; + } + + + /** + * Finishe's any changes to this filesystem. + */ + public void finish() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (!needsRepack()) return; + + for (var folder : folders.values()) { + if (folder.isFileSystemInfoChanged()) { + if (useAutomaticVersionIncremetor) folder.setVersion(folder.getVersion() + 1); + CacheBuffer buffer = folder.finish(); + if (!cache.getIndex(id).put(folder.getID(), buffer, buffer.getBuffer().length)) { + throw new RuntimeException("Couldn't update folder:" + folder); + } + } + } + + + if (useAutomaticVersionIncremetor) version++; + + packed = pack(); + updateHashes(packed); + + if (!cache.getMasterIndex().put(id, packed, packed.getBuffer().length)) { + throw new RuntimeException("Couldn't update packed filesystem."); + } + + changed = false; + for (var folder : folders.values()) + folder.markFileSystemInfoAsNotChanged(); + } + + /** + * Pack's this filesystem. + */ + public CacheBuffer pack() { + CacheBuffer pack = new CacheBuffer(0); + + pack.writeByte(protocol); + if (protocol >= 6) pack.writeInt(version); + + pack.writeByte((useNames ? 0x1 : 0x0) | (useWhirlpool ? 0x2 : 0x0)); + + var foldersLength = foldersSize(); + if (protocol >= 7) { + pack.writeSmart32(foldersLength); + } else { + pack.writeShort(foldersLength); + } + + var foldersSorted = folders.values().parallelStream().sorted(Comparator.comparingInt(Group::getID)) + .toArray(Group[]::new); + { + int delta = 0; + for (var folder : foldersSorted) { + if (protocol >= 7) { + pack.writeSmart32(folder.getID() - delta); + } else { + pack.writeShort(folder.getID() - delta); + } + delta = folder.getID(); + } + } + + + if (useNames) { + for (var folder : foldersSorted) + pack.writeInt(folder.getName()); + } + + for (var folder : foldersSorted) + pack.writeInt(folder.getCRC32()); + + if (useWhirlpool) { + for (var folder : foldersSorted) + pack.writeBytes(folder.getDigest(), 0, 64); + } + + for (var folder : foldersSorted) + pack.writeInt(folder.getVersion()); + + for (var folder : foldersSorted) + if (protocol >= 7) { + pack.writeSmart32(folder.filesCount()); + } else { + pack.writeShort(folder.filesCount()); + } + + for (var folder : foldersSorted) { + int delta = 0; + var sortedFiles = folder.getRSFiles().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + for (var file : sortedFiles) { + if (protocol >= 7) { + pack.writeSmart32(file.getID() - delta); + } else { + pack.writeShort(file.getID() - delta); + } + delta = file.getID(); + } + } + + if (useNames) { + for (var folder : foldersSorted) { + var sortedFiles = folder.getRSFiles().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + for (var file : sortedFiles) { + pack.writeInt(file.getName()); + } + } + } + + return Helper.encodeFITContainer(new CacheBuffer(pack.toArray(0, pack.getPosition())), version).trim(); + } + + /** + * Find's folder by id. Returns null if none found. + */ + public Group findFolderByID(int id) { + return findFolderByID(id, null); + } + + /** + * Find's folder by id. Returns null if none found. + */ + public Group findFolderByID(int id, int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + var folder = folders.get(id); + if (folder == null) { + return null; + } else if (folder.isLoaded()) { + return folder; + } + + CacheBuffer data = cache.getIndex(this.id).get(id); + if (data == null) throw new RuntimeException("Missing folder:" + id); + folder.load(data, xtea); + + return folder; + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(String name) { + return findFolderByName(name, null); + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(int name) { + return findFolderByName(name, null); + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(String name, int[] xtea) { + return findFolderByName(Helper.strToI(name), xtea); + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(int name, int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (name == -1) return null; + + var folder = folders.get(foldersByName.getOrDefault(name, -1)); + if (folder == null) { + return null; + } else if (folder.isLoaded()) { + return folder; + } + + CacheBuffer data = cache.getIndex(this.id).get(folder.getID()); + if (data == null) throw new RuntimeException("Missing folder:" + folder.getID()); + folder.load(data, xtea); + + return folder; + } + + /** + * Add's new folder to this filesystem. If there's already a folder with + * same id then it get's overwriten. + */ + public void addFolder(Group group) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (!group.isLoaded()) throw new RuntimeException("folder is not loaded."); + + if (group.getID() == -1) group.setID(getFreeFolderID()); + folders.put(group.getID(), group); + if (group.hasName()) { + foldersByName.put(group.getName(), group.getID()); + } + group.markFileSystemInfoAsChanged(); // cause it needs to be packed to store. + changed = true; + } + + /** + * Delete's given folder. + */ + public void deleteFolder(Group group) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + folders.remove(group.getID()); + foldersByName.remove(group.getID()); + changed = true; + } + + /** + * Delete's all folders in this fs. + */ + public void deleteAllFolders() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + folders.clear(); + changed = true; + } + + /** + * Load's folder if it's not yet loaded. + */ + public void load(Group group) { + load(group, null); + } + + /** + * Load's folder if it's not yet loaded. + */ + public void load(Group group, int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (!folders.containsKey(group.getID())) { + return; + } else if (group.isLoaded()) { + return; + } else if (group.getID() == -1) { + return; + } + CacheBuffer data = cache.getIndex(id).get(group.getID()); + if (data == null) throw new RuntimeException("Missing folder:" + group.getID()); + group.load(data, xtea); + } + + /** + * Finishe's any pending caches on this filesystem and then unload's some + * buffered files. + */ + public void unloadCachedFiles() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + finish(); + for (var folder : folders.values()) + if (folder.isLoaded()) folder.unload(); + } + + /** + * Returns highest folder id. + */ + public int getHighestId() { + return getFreeFolderID() - 1; + } + + public int size() { + if (folders.isEmpty()) { + return 0; + } + + return getHighestId() + 1; + } + + /** + * Get's free folder ID. + */ + private int getFreeFolderID() { + if (folders.isEmpty()) return 0; + int highest = -1; + for (var folder : folders.values()) + if (folder.getID() > highest) highest = folder.getID(); + return highest + 1; + } + + /** + * Update's crc32 and whirlpool hash to one's from given buffer. + */ + private void updateHashes(CacheBuffer packed) { + crc = Helper.crc32(packed, 0, packed.getBuffer().length); + digest = Whirlpool.whirlpool(packed.getBuffer(), 0, packed.getBuffer().length); + } + + + /** + * Wheter this filesystem is loaded. + */ + public boolean isLoaded() { + return packed != null; + } + + /** + * Wheter file system file needs repack. + */ + private boolean needsRepack() { + if (changed) return true; + for (var folder : folders.values()) + if (folder.isFileSystemInfoChanged()) return true; + return false; + } + + /** + * Get's ID of this filesystem. + */ + public int getID() { + return id; + } + + /** + * Wheter this filesystem uses names. + */ + public boolean usesNames() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return useNames; + } + + /** + * Wheter this filesystem uses whirlpool. + */ + public boolean usesWhirlpool() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return useWhirlpool; + } + + /** + * Set's wheter this filesystem uses names. + */ + public void setUsesNames(boolean uses) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (this.useNames != uses) { + changed = true; + this.useNames = uses; + } + } + + /** + * Set's wheter this filesystem uses whirlpool. + */ + public void setUsesWhirlpool(boolean uses) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (this.useWhirlpool != uses) { + changed = true; + this.useWhirlpool = uses; + } + } + + /** + * Get's version of this filesystem. + */ + public int getVersion() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return version; + } + + /** + * Set's version of this filesystem. + */ + public void setVersion(int version) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (this.version != version) { + changed = true; + this.version = version; + } + } + + /** + * Get's crc32 of packed version of this filesystem. + */ + public int getCRC32() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return crc; + } + + /** + * Get's whirlpool digest of packed version of this filesystem. + */ + public byte[] getDigest() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return digest; + } + + /** + * Wheter versions are automatically incremented each time finish() is + * called. + */ + public boolean usingAutomaticVersionsIncremetor() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return useAutomaticVersionIncremetor; + } + + + /** + * Set's wheter to use automatic versions incrementor. + */ + public void setUseAutomaticVersionsIncremetor(boolean use) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + this.useAutomaticVersionIncremetor = use; + } + + /** + * Get's all folders. + * Returned folders array can't be modified + * in any way. + * + * @return + */ + public ObjectCollection getFolders() { + return folders.values(); + } + + public int foldersSize() { + return folders.size(); + } +} diff --git a/cache/src/main/java/org/apollo/cache/Cache.java b/cache/src/main/java/org/apollo/cache/Cache.java new file mode 100644 index 000000000..0b23ae1d0 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Cache.java @@ -0,0 +1,253 @@ +package org.apollo.cache; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.math.BigInteger; +import java.nio.file.Path; + + +public class Cache { + + private static final String DATA_FILE = "main_file_cache.dat2"; + private static final String INDEX_FILE = "main_file_cache.idx"; + + private Index[] indexes; + private Index masterIndex; + private Archive[] archives; + private int[] crcs; + + private Cache(String path) { + openFiles(path); + } + + @SuppressWarnings("resource") + private final void openFiles(String path) { + try { + String seperator = System.getProperty("file.separator", "/"); + + RandomAccessFile dataFile = new RandomAccessFile(path + seperator + DATA_FILE, "rw"); + + RandomAccessFile referenceFile = new RandomAccessFile(path + seperator + INDEX_FILE + "255", "rw"); + masterIndex = new Index(255, dataFile.getChannel(), referenceFile.getChannel(), 0x20000000); + + int numIndices = masterIndex.getFileCount(); + indexes = new Index[numIndices]; + archives = new Archive[numIndices]; + for (int i = 0; i < numIndices; i++) { + RandomAccessFile indexFile = new RandomAccessFile(path + seperator + INDEX_FILE + i, "rw"); + indexes[i] = new Index(i, dataFile.getChannel(), indexFile.getChannel(), 0x10000000); + if (masterIndex.get(i) != null) archives[i] = new Archive(i, this); + } + + crcs = new int[numIndices]; + for (int i = 0; i < archives.length; i++) { + var fs = getArchive(i); + crcs[i] = fs == null ? 0 : fs.getCRC32(); + } + } catch (IOException ioex) { + ioex.printStackTrace(); + } + } + + /** + * Finishing all pending operations. + */ + public void flush() { + if (archives == null) throw new RuntimeException("Cache is closed."); + for (int i = 0; i < archives.length; i++) + if (archives[i] != null && archives[i].isLoaded()) archives[i].finish(); + } + + /** + * Finishing all pending operations then + * Closes cache and disposes all data. + * Calling close() on closed cache has no effect. + */ + public void close() { + if (indexes == null) return; // closed cache + flush(); + for (int i = 0; i < indexes.length; i++) + indexes[i].close(); + masterIndex.close(); + + archives = null; + indexes = null; + masterIndex = null; + } + + /** + * Closes cache without finishing all pending operations. + */ + public void closeDiscard() { + if (indexes == null) return; // closed cache + + for (int i = 0; i < indexes.length; i++) + indexes[i].close(); + masterIndex.close(); + + archives = null; + indexes = null; + masterIndex = null; + } + + + /** + * Opens cache at given path. + * + * @param path Folder where cache is located. + * @return Opened cache or null if something failed. + */ + public static Cache openCache(String path) { + return new Cache(path); + } + + public static Cache openCache(Path path) { + return new Cache(path.toString()); + } + + + /** + * Create's new cache on given path. + * + * @param path Folder where to create new cache. + * @param indicesCount Count of indices , can't be lower than 0 or higher than 254. + * @return Created cache or null if something failed. + */ + @SuppressWarnings("resource") + public static Cache createNewCache(String path, int indicesCount) { + if (indicesCount < 0 || indicesCount > 254) return null; + + File file = new File(path); + if (file.isFile()) return null; + + if (!file.exists()) file.mkdirs(); + + if (!file.isDirectory()) return null; + + try { + String seperator = System.getProperty("file.separator", "/"); + File data = new File(path + seperator + DATA_FILE); + if (data.exists() || !data.createNewFile() || !data.canWrite() || !data.canRead()) return null; + + for (int i = 0; i < indicesCount; i++) { + File index = new File(path + seperator + INDEX_FILE + i); + if (index.exists() || !index.createNewFile() || !index.canWrite() || !data.canRead()) return null; + } + + File index255 = new File(path + seperator + INDEX_FILE + "255"); + if (index255.exists() || !index255.createNewFile() || !index255.canWrite() || !index255.canRead()) { + return null; + } + + RandomAccessFile dataFile = new RandomAccessFile(path + seperator + DATA_FILE, "rw"); + RandomAccessFile referenceFile = new RandomAccessFile(path + seperator + INDEX_FILE + "255", "rw"); + Index store_255 = new Index(255, dataFile.getChannel(), referenceFile.getChannel(), 0x7a120); + + for (int i = 0; i < indicesCount; i++) { + byte[] pdata = Helper.encodeFITContainer(new byte[]{5, 0, 0, 0}, + 0); // empty fs (protocol 5, props 0, folders count - 0) + store_255.put(i, new CacheBuffer(pdata), pdata.length); + } + + dataFile.getChannel().close(); + referenceFile.getChannel().close(); + return new Cache(path); + } catch (IOException ex) { + ex.printStackTrace(); + return null; + } + + } + + + /** + * Get's specific file store. + * Returns null if store is not available in this cache. + * Note:Using this method to get information store (idx255) results in + * null return, use getInformationStore() instead. + */ + public Index getIndex(int id) { + if (indexes == null) throw new RuntimeException("Cache is closed."); + if (id < 0 || id >= indexes.length) return null; + return indexes[id]; + } + + /** + * Get's specific file system. + * If it's not loaded then it loads it. + */ + public Archive getArchive(int id) { + if (archives == null) throw new RuntimeException("Cache is closed."); + if (id < 0 || id >= archives.length || archives[id] == null) return null; + Archive system = archives[id]; + if (!system.isLoaded()) system.load(); + return system; + } + + /** + * Get's information about files store. + */ + public Index getMasterIndex() { + if (masterIndex == null) throw new RuntimeException("Cache is closed."); + return masterIndex; + } + + /** + * Get's count of indices in this cache. + */ + public int getIndicesCount() { + if (indexes == null) throw new RuntimeException("Cache is closed."); + return indexes.length; + } + + /** + * Get's an array of all index CRCs. + */ + public int[] getCrcs() { + if (indexes == null) throw new RuntimeException("Cache is closed."); + return crcs; + } + + public CacheBuffer generateInformationStoreDescriptor(boolean whirlpool) { + if (archives == null) + throw new RuntimeException("Cache is closed."); + for (int i = 0; i < archives.length; i++) + if (!archives[i].isLoaded()) + archives[i].load(); + flush(); + int indicesCount = getIndicesCount(); + CacheBuffer alloc = new CacheBuffer(whirlpool ? ((1 + (indicesCount * 72) + 1 + 64) * 10) : (256 * 8)); + if (whirlpool) + alloc.writeByte(indicesCount); + for (int i = 0; i < (whirlpool ? indicesCount : 256); i++) { + if (i >= archives.length) { + alloc.writeInt(0xCAFEBABE); + alloc.writeInt(0xBEEFBEEF); + continue; + } + alloc.writeInt(archives[i].getCRC32()); + alloc.writeInt(archives[i].getVersion()); + if (whirlpool) + alloc.writeBytes(archives[i].getDigest(), 0, 64); + } + if (whirlpool) { + byte[] selfDigest = Whirlpool.whirlpool(alloc.getBuffer(), 0, alloc.getPosition()); + CacheBuffer rsa = new CacheBuffer(65); + rsa.writeByte(10); + rsa.writeBytes(selfDigest, 0, 64); + BigInteger data = new BigInteger(rsa.getBuffer()); + byte[] encrypted = data.toByteArray(); + alloc.writeBytes(encrypted, 0, encrypted.length); + } + return Helper.encodeFITContainer(new CacheBuffer(alloc.toArray(0, alloc.getPosition())), 0, Helper.COMPRESSION_NONE); + } + + @Override + public void finalize() { + if (indexes != null) { + System.err.println("mgi.tools.jagcached.cache:Cache not closed."); + close(); + } + } +} diff --git a/cache/src/main/java/org/apollo/cache/CacheBuffer.java b/cache/src/main/java/org/apollo/cache/CacheBuffer.java new file mode 100644 index 000000000..67c489132 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/CacheBuffer.java @@ -0,0 +1,631 @@ +package org.apollo.cache; + +public class CacheBuffer { + + private static final int xteaDelta = 0x9E3779B9; + private static final int xteaRounds = 32; + + private int position; + public byte[] buffer; + private boolean dontExpand; + + public CacheBuffer() { + this(16); + } + + public CacheBuffer(byte[] data) { + this(data, 0); + } + + public CacheBuffer(int capacity) { + this.position = 0; + this.buffer = new byte[capacity]; + } + + public CacheBuffer(byte[] data, int position) { + this.position = position; + this.buffer = new byte[data.length]; + System.arraycopy(data, 0, buffer, 0, buffer.length); + } + + public void setDontExpand(boolean dontExpand) { + this.dontExpand = dontExpand; + } + + public final void xteaEncrypt(int[] keys, int offset, int length) { + int originalPosition = this.position; + this.position = offset; + int numCycles = (length - offset) / 8; + for (int cycle = 0; cycle < numCycles; cycle++) { + int v0 = readInt(); + int v1 = readInt(); + int sum = 0; + int numRounds = xteaRounds; + while (numRounds-- > 0) { + v0 += (sum + keys[sum & 0x3] ^ (v1 << 4 ^ v1 >>> 5) + v1); + sum += xteaDelta; + v1 += (sum + keys[(sum & 0x1d2f) >>> 11] ^ v0 + (v0 << 4 ^ v0 >>> 5)); + } + this.position -= 8; + writeInt(v0); + writeInt(v1); + } + this.position = originalPosition; + } + + public final void xteaDecrypt(int[] keys, int start, int length) { + int l = position; + position = start; + int i1 = (length - start) / 8; + for (int j1 = 0; j1 < i1; j1++) { + position += 4; + int k1 = ((0xff & buffer[-3 + position]) << 16) + ((((0xff & buffer[-4 + position]) << 24) + ((buffer[-2 + position] & 0xff) << 8)) + (buffer[-1 + position] & 0xff)); + position += 4; + int l1 = ((0xff & buffer[-3 + position]) << 16) + ((((0xff & buffer[-4 + position]) << 24) + ((buffer[-2 + position] & 0xff) << 8)) + (buffer[-1 + position] & 0xff)); + int sum = 0xc6ef3720; + for (int k2 = 32; k2-- > 0; ) { + l1 -= keys[(sum & 0x1c84) >>> 11] + sum ^ (k1 >>> 5 ^ k1 << 4) + k1; + sum -= 0x9e3779b9; + k1 -= (l1 >>> 5 ^ l1 << 4) + l1 ^ keys[sum & 3] + sum; + } + + position -= 8; + buffer[position++] = (byte) (k1 >> 24); + buffer[position++] = (byte) (k1 >> 16); + buffer[position++] = (byte) (k1 >> 8); + buffer[position++] = (byte) k1; + buffer[position++] = (byte) (l1 >> 24); + buffer[position++] = (byte) (l1 >> 16); + buffer[position++] = (byte) (l1 >> 8); + buffer[position++] = (byte) l1; + } + position = l; + } + + public byte[] toArray(int offset, int length) { + byte[] bf = new byte[length - offset]; + for (int i = 0; i < length; i++) { + bf[i] = this.buffer[offset + i]; + } + return bf; + } + + public void setPosition(int position) { + this.position = position; + } + + public int getPosition() { + return position; + } + + public byte[] getBuffer() { + return buffer; + } + + public int getRemaining() { + int length = buffer.length; + return position < length ? length - position : 0; + } + + public void skip(int length) { + position += length; + } + + public int readByte() { + return getRemaining() > 0 ? buffer[position++] : 0; + } + + public byte readSignedByte() { + return (byte) readByte(); + } + + public int peekByte() { + return getRemaining() > 0 ? buffer[position] : 0; + } + + public void readBytes(byte buffer[]) { + readBytes(buffer, 0, buffer.length); + } + + public void readBytes(byte buffer[], int off, int len) { + for (int k = off; k < len + off; k++) { + buffer[k] = (byte) readByte(); + } + } + + public String readString() { + int startpos = position; + while (position < buffer.length && buffer[position++] != 0) { + } + int strlen = position - startpos - 1; + if (strlen <= 0) + return ""; + return StringUtilities.decodeString(buffer, startpos, strlen); + } + + public String readHttpHeaderString() { + int length = 0; + while ((position + length + 2) <= buffer.length && buffer[position + length + 0] != '\r' && buffer[position + length + 1] != '\n') + length++; + + if ((position + length + 2) > buffer.length) + return null; + + String str = new String(buffer, position, length); + position += length + 2; + return str; + } + + public String readVersionedString() { // aka JAG string getService you called it + return readVersionedString((byte) 0); + } + + public String readVersionedString(byte versionNumber) { + if (readByte() != versionNumber) + throw new IllegalStateException("Bad string version number!"); + return readString(); + } + + public String readNullString() { + if (peekByte() == 0) { + skip(1); + return null; + } + return readString(); + } + + public int readUMedInt() { + return (readUByte() << 16) + (readUByte() << 8) + (readUByte()); + } + + public int readUByte() { + return readByte() & 0xff; + } + + public int readByte128() { + return (byte) (readByte() - 128); + } + + public int readByteC() { + return (byte) -readByte(); + } + + public int read128Byte() { + return (byte) (128 - readByte()); + } + + public int readUByteA() { + return readUByte() - 128 & 0xff; + } + + public int readUByteC() { + return -readUByte() & 0xff; + } + + public int readUByteS() { + return 128 - readUByte() & 0xff; + } + + public int readSignedLEShort() { + int i = readUByte() + (readUByte() << 8); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedShortA() { + int i = (readUByte() << 8) + (readByte() - 128 & 0xff); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedLEShortA() { + int i = (readByte() - 128 & 0xff) + (readUByte() << 8); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedLEShortS() { + int i = (128 - readByte() & 0xff) + (readUByte() << 8); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedShort() { + int i = (readUByte() << 8) + readUByte(); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readULEShort() { + return readUByte() + (readUByte() << 8); + } + + public int readUShort() { + return (readUByte() << 8) + readUByte(); + } + + public int readSignedSmart() { + int var2 = peekByte() & 0xff; + if (var2 < 128) { + return readUByte() - 64; + } + return readUShort() - 49152; + } + + public int readSmart32() { + if ((peekByte() ^ 0xffffffff) <= -1) { + int value = readUShort(); + if (value == 32767) { + return -1; + } + return value; + } + return readInt() & 0x7fffffff; + } + + public int readDecoratedSmart() { + int var2 = peekByte() & 0xff; + if (var2 < 128) { + return readUByte() - 1; + } + return readUShort() - 32769; + } + + public int readUnsignedShortA() { + return (readUByte() << 8) + (readByte() - 128 & 0xff); + } + + public int readUnsignedLEShortA() { + return (readByte() - 128 & 0xff) + (readUByte() << 8); + } + + public int readInt() { + return (readUByte() << 24) + (readUByte() << 16) + (readUByte() << 8) + readUByte(); + } + + public int readIntV1() { + return (readUByte() << 8) + readUByte() + (readUByte() << 24) + (readUByte() << 16); + } + + public int readIntV2() { + return (readUByte() << 16) + (readUByte() << 24) + readUByte() + (readUByte() << 8); + } + + public int readLEInt() { + return readUByte() + (readUByte() << 8) + (readUByte() << 16) + (readUByte() << 24); + } + + public long readLong() { + long l = readInt() & 0xffffffffL; + long l1 = readInt() & 0xffffffffL; + return (l << 32) + l1; + } + + public int readUnsignedSmart() { + int peak = peekByte() & 0xff; + if (peak < 128) + return readUByte(); + return readUShort() - 32768; + } + + public int readSmartLE() { + int peak = peekByte(); + if (peak <= Byte.MAX_VALUE && peak >= Byte.MIN_VALUE) + return readSignedByte(); + return readSignedLEShort() - 32768; + } + + public int readCustomInt() { + return (readUByte() << 24) + (readUByte() << 16) + (readUByte() << 8) + readUByte() + 128; + } + + public long readDynamic(int byteCount) { + if (--byteCount < 0 || byteCount > 7) { + throw new IllegalArgumentException(); + } + int bitposition = byteCount * 8; + long l = 0L; + for (/**/; bitposition >= 0; bitposition -= 8) { + + l |= (0xffL & readByte()) << bitposition; + } + return l; + } + + public int readHugeSmart() { + int value = 0; + int read; + for (read = readUnsignedSmart(); read == 32767; read = readUnsignedSmart()) { + value += 32767; + } + value += read; + return value; + } + + public void writeHugeSmart(int value) { + for (int i = 0; i < value / 0x7fff; i++) { + writeShort((short) 0xffff); + } + writeUnsignedSmart(value & 0x7fff); + } + + public float readFloat() { + return Float.intBitsToFloat(readInt()); + } + + public void expand(int position) { + if (dontExpand) { + return; + } + + int length = this.buffer.length; + if (position >= length) { + byte[] newBuffer = new byte[position + 1000]; + System.arraycopy(buffer, 0, newBuffer, 0, length); + this.buffer = newBuffer; + } + } + + public void writeByte(int value, int position) { + expand(position); + buffer[position] = (byte) value; + } + + public void writeBytes(byte[] b, int offset, int length) { + expand(this.position + length - 1); + System.arraycopy(b, offset, buffer, this.position, length); + + this.position += length; + } + + public void writeBytes(byte[] b) { + expand(this.position + b.length - 1); + System.arraycopy(b, 0, buffer, this.position, b.length); + + this.position += b.length; + } + + public void writeBytes128Reverse(byte[] b) { + for (int i = b.length - 1; i >= 0; i--) + writeByteA(b[i]); + } + + public void writeBytesReverse(byte[] b) { + for (int i = b.length - 1; i >= 0; i--) + writeByte(b[i]); + } + + public void writeBytesA(byte[] buffer, int offset, int length) { + for (int index = offset; index < length; index++) { + writeByteA(buffer[index]); + } + } + + public void writeBytesA(byte[] buffer) { + writeBytesA(buffer, 0, buffer.length); + } + + public void writeVersionedString(String s) { + writeVersionedString(s, (byte) 0); + } + + public void writeVersionedString(String s, byte version) { + writeByte(version); + writeString(s); + } + + public void writeString(String s) { + int n = s.indexOf('\0'); + if (n >= 0) + throw new IllegalArgumentException("NUL character at " + n + "!"); + expand(position + s.length()); + position += StringUtilities.encodeString(buffer, position, s, 0, s.length()); + writeByte(0); + } + + public void writeByte(int value) { + writeByte(value, position++); + } + + public void writeByteA(int i) { + writeByte(i + 128); + } + + public void writeByteC(int i) { + writeByte(-i); + } + + public void writeByteS(int i) { + writeByte(128 - i); + } + + public void writeLEShortA(int i) { + writeByte(i + 128); + writeByte(i >> 8); + } + + public void writeShortA(int i) { + writeByte(i >> 8); + writeByte(i + 128); + } + + public void writeUnsignedSmart(int value) { + if (value < 128) + writeByte(value); + else if (value < 32768) + writeShort(value + 32768); + else + throw new IllegalArgumentException(); + } + + public void writeSmart32(int value) { + if ((value & 0xFFFF) < 32768) + writeShort(value); + else + writeInt(0x80000000 | value); + } + + public void writeShort(int value) { + writeByte(value >> 8); + writeByte(value); + } + + public void writeLEShort(int i) { + writeByte(i); + writeByte(i >> 8); + } + + public void writeMedInt(int i) { + writeByte(i >> 16); + writeByte(i >> 8); + writeByte(i); + } + + public void write24BitIntegerV2(int i) { + writeByte(i >> 16); + writeByte(i); + writeByte(i >> 8); + } + + public void write24BitIntegerV3(int i) { + writeByte(i); + writeByte(i >> 8); + writeByte(i >> 16); + } + + + public void writeInt(int i) { + writeByte(i >> 24); + writeByte(i >> 16); + writeByte(i >> 8); + writeByte(i); + } + + public void writeIntV1(int i) { + writeByte(i >> 8); + writeByte(i); + writeByte(i >> 24); + writeByte(i >> 16); + } + + public void writeIntV2(int i) { + writeByte(i >> 16); + writeByte(i >> 24); + writeByte(i); + writeByte(i >> 8); + } + + public void writeIntLE(int i) { + writeByte(i); + writeByte(i >> 8); + writeByte(i >> 16); + writeByte(i >> 24); + } + + public void writeLong(long l) { + writeByte((int) (l >> 56)); + writeByte((int) (l >> 48)); + writeByte((int) (l >> 40)); + writeByte((int) (l >> 32)); + writeByte((int) (l >> 24)); + writeByte((int) (l >> 16)); + writeByte((int) (l >> 8)); + writeByte((int) l); + } + + public void write5ByteInteger(long l) { + writeByte((int) (l >> 32)); + writeByte((int) (l >> 24)); + writeByte((int) (l >> 16)); + writeByte((int) (l >> 8)); + writeByte((int) l); + } + + public void writeDynamic(int bytes, long l) { + bytes--; + if (bytes < 0 || bytes > 7) { + throw new IllegalArgumentException(); + } + for (int shift = 8 * bytes; shift >= 0; shift -= 8) { + writeByte((int) (l >> shift)); + } + } + + public void writeFloat(float value) { + writeInt(Float.floatToIntBits(value)); + } + + public void writeBoolean(boolean condition) { + writeByte(condition ? 1 : 0); + } + + public void writeSignedSmart(int value) { + if (value < 64 && value >= -64) { + writeByte(value + 64); + return; + } + if (value < 16384 && value >= -16384) { + writeShort(value + 49152); + return; + } else { + System.out.println("Error psmart out of range: " + value); + return; + } + } + + public final int readVarSeized() { + int f = this.buffer[this.position++]; + int sum = 0; + for (; f < 0; f = this.buffer[this.position++]) + sum = (sum | f & 0x7f) << 7; + return sum | f; + } + + public final void writeVarSeized(int val) { + if ((val & ~0x7f) != 0) { + if ((val & ~0x3fff) != 0) { + if ((val & ~0x1fffff) != 0) { + if ((val & ~0xfffffff) != 0) + this.writeByte(val >>> 28 | 0x80); + this.writeByte((val | 0x100a2c1c) >>> 21); + } + this.writeByte(val >>> 14 | 0x80); + } + this.writeByte((val | 0x4021) >>> 7); + } + this.writeByte(val & 0x7f); + } + + public void writeMidiInt(int value) { + this.buffer[this.position - value - 4] = (byte) (value >> 24); + this.buffer[this.position - value - 3] = (byte) (value >> 16); + this.buffer[this.position - value - 2] = (byte) (value >> 8); + this.buffer[this.position - value - 1] = (byte) value; + } + + public byte getByte(int position) { + return buffer[position]; + } + + public void setByte(int value, byte position) { + buffer[position] = (byte) value; + } + + public CacheBuffer trim() { + return new CacheBuffer(toArray(0, position)); + } + + public boolean isEmpty() { + return buffer.length == 0; + } +} diff --git a/cache/src/main/java/org/apollo/cache/FileDescriptor.java b/cache/src/main/java/org/apollo/cache/FileDescriptor.java deleted file mode 100644 index e5df5b4e6..000000000 --- a/cache/src/main/java/org/apollo/cache/FileDescriptor.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apollo.cache; - -import java.io.File; - -/** - * A class which points to a file in the cache. - * - * @author Graham - */ -public final class FileDescriptor { - - /** - * The file id. - */ - private final int file; - - /** - * The file type. - */ - private final int type; - - /** - * Creates the file descriptor. - * - * @param type The file type. - * @param file The file id. - */ - public FileDescriptor(int type, int file) { - this.type = type; - this.file = file; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof FileDescriptor) { - FileDescriptor other = (FileDescriptor) obj; - return type == other.type && file == other.file; - } - - return false; - } - - /** - * Gets the file id. - * - * @return The file id. - */ - public int getFile() { - return file; - } - - /** - * Gets the file type. - * - * @return The file type. - */ - public int getType() { - return type; - } - - @Override - public int hashCode() { - return file * FileSystemConstants.ARCHIVE_COUNT + type; - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/FileSystemConstants.java b/cache/src/main/java/org/apollo/cache/FileSystemConstants.java deleted file mode 100644 index d0c523ba2..000000000 --- a/cache/src/main/java/org/apollo/cache/FileSystemConstants.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apollo.cache; - -/** - * Holds file system related constants. - * - * @author Graham - */ -public final class FileSystemConstants { - - /** - * The number of archives in cache 0. - */ - public static final int ARCHIVE_COUNT = 9; - - /** - * The size of a chunk. - */ - public static final int CHUNK_SIZE = 512; - - /** - * The size of a header. - */ - public static final int HEADER_SIZE = 8; - - /** - * The size of a block. - */ - public static final int BLOCK_SIZE = HEADER_SIZE + CHUNK_SIZE; - - /** - * The size of an index. - */ - public static final int INDEX_SIZE = 6; - - /** - * Default private constructor to prevent instantiation. - */ - private FileSystemConstants() { - - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/Group.java b/cache/src/main/java/org/apollo/cache/Group.java new file mode 100644 index 000000000..94e97b051 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Group.java @@ -0,0 +1,593 @@ +package org.apollo.cache; + +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectCollection; + +import java.util.Comparator; + +public class Group { + + /** + * Contains ID of the folder. + */ + private int id; + /** + * Contains name hash of this folder. + */ + private int name; + /** + * Contains version of packed folder file. + */ + private int version; + + /** + * Contains crc of packed folder file. + */ + private int crc; + /** + * Contains 64-byte whirlpool digest. + */ + private byte[] digest; + + private Int2ObjectLinkedOpenHashMap files; + private Int2IntOpenHashMap filesByName; + + /** + * Contains packed files buffer + * which was provided with load() call. + */ + private CacheBuffer packedFiles; + /** + * Contains xtea keys. (int[4]) + * Can be null. + */ + private int[] xtea; + /** + * Wheter any changes were made. + */ + private boolean needsRepack; + /** + * Wheter any of those things changed (id,name,version,crc,digest,files and their data). + */ + private boolean fileSystemInfoChanged; + + /** + * Constructor for copy() methods. + */ + private Group() { + + } + + /** + * Create's new folder with autoassigned id from given data. + * Each file must have it's buffer attached. + */ + public Group(Int2ObjectLinkedOpenHashMap files) { + this(-1, -1, 0, files); + } + + /** + * Create's new folder with autoassigned id from given data. + * Each file must have it's buffer attached. + */ + public Group(String name, int version, Int2ObjectLinkedOpenHashMap files) { + this(-1, Helper.strToI(name), version, files); + } + + /** + * Create's new folder with autoassigned id from given data. + * Each file must have it's buffer attached. + */ + public Group(int name, int version, Int2ObjectLinkedOpenHashMap files) { + this(-1, name, version, files); + } + + /** + * Create's new folder from given data. + * Each file must have it's buffer attached. + */ + public Group(int folderID, String name, int version, Int2ObjectLinkedOpenHashMap files) { + this(folderID, Helper.strToI(name), version, files); + } + + /** + * Create's new folder from given data. + * Each file must have it's buffer attached. + */ + public Group(int folderID, int name, int version, Int2ObjectLinkedOpenHashMap files) { + this.id = folderID; + this.name = name; + this.version = version; + this.files = files; + for (var file : files.values()) { + if (file.getID() != -1) { + continue; + } + file.setID(getRSFreeFileID()); + } + this.filesByName = new Int2IntOpenHashMap(); + updateHashes(this.packedFiles = pack()); + } + + /** + * Create's new unloaded folder from given FIT data. + */ + public Group(int folderID, int name, int version, int crc32, byte[] digest, int[] filesIDS, int[] filesNames) { + if (digest.length != 64 || filesIDS.length != filesNames.length) { + throw new RuntimeException("Invalid data provided."); + } + this.id = folderID; + this.name = name; + this.version = version; + this.crc = crc32; + this.digest = digest; + this.files = new Int2ObjectLinkedOpenHashMap<>(filesIDS.length);//[filesIDS.length]; + this.filesByName = new Int2IntOpenHashMap(); + for (int i = 0; i < filesIDS.length; i++) { + var file = new RSFile(filesIDS[i], filesNames[i]); + files.put(file.getID(), file); + if (file.hasName()) { + filesByName.put(file.getName(), file.getID()); + } + } + } + + /** + * Copy's this folder and every file in it. + */ + public Group copy() { + Group copy = new Group(); + copy.id = id; + copy.name = name; + copy.version = version; + copy.crc = crc; + if (digest != null) { + copy.digest = new byte[64]; + System.arraycopy(digest, 0, copy.digest, 0, 64); + } + if (files != null) { + copy.files = new Int2ObjectLinkedOpenHashMap<>(files.size()); + for (var file : files.values()) { + copy.files.put(file.getID(), file.copy()); + } + } + if (filesByName != null) { + copy.filesByName = new Int2IntOpenHashMap(); + for (int file : filesByName.values()) { + copy.filesByName.put(file, filesByName.get(file)); + } + } + if (packedFiles != null) { + copy.packedFiles = new CacheBuffer(packedFiles.toArray(0, packedFiles.getBuffer().length), + packedFiles.getPosition()); + } + if (xtea != null) { + copy.xtea = new int[4]; + System.arraycopy(xtea, 0, copy.xtea, 0, 4); + } + copy.needsRepack = needsRepack; + copy.fileSystemInfoChanged = fileSystemInfoChanged; + return copy; + } + + + /** + * Load's packed folder file. + */ + public void load(CacheBuffer packedFiles) { + load(packedFiles, null); + } + + /** + * Unload's this folder , can be called + * only by filesystem unloadCachedData() method. + */ + public void unload() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded folder."); + packedFiles = null; + for (var file : files.values()) { + file.unload(); + } + } + + /** + * Load's packed folder file. + */ + public void load(CacheBuffer packedFiles, int[] xtea) { + if (isLoaded()) throw new RuntimeException("Already loaded."); + this.packedFiles = packedFiles; + this.xtea = xtea; + unpack(packedFiles); + } + + + /** + * Finishe's any changes by generating new packedFiles buffer and updating hashes + * if something was changed. + */ + public CacheBuffer finish() { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + + if (needsRepack()) { + //sortFiles(); + packedFiles = pack(); + updateHashes(packedFiles); + markAsNotNeedRepack(); + return packedFiles; + } + return packedFiles; + } + + /** + * Unpack's given packed files buffer. + */ + @SuppressWarnings("Duplicates") + private void unpack(CacheBuffer packed) { + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.decryptContainer(packed, xtea); + } + + packed = Helper.decodeFilesContainer(packed); + + if (filesCount() <= 1) { + if (filesCount() <= 0) return; + CacheBuffer copy = new CacheBuffer(packed.getBuffer().length); + copy.writeBytes(packed.getBuffer(), 0, packed.getBuffer().length); + files.get(files.firstIntKey()).load(copy); + return; + } + + int sectorsCount = packed.getBuffer()[packed.getBuffer().length - 1] & 0xFF; + int[] lengths = new int[filesCount()]; + packed.setPosition(packed.getBuffer().length - ((sectorsCount * filesCount() * 4) + 1)); + for (int sectorID = 0; sectorID < sectorsCount; sectorID++) { + for (int i = 0, length = 0; i < filesCount(); i++) { + lengths[i] += (length += packed.readInt()); + } + } + int index = 0; + var sortedFiles = files.values().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + for (var file : sortedFiles) { + file.load(new CacheBuffer(lengths[index])); + lengths[index++] = 0; + } + packed.setPosition(packed.getBuffer().length - ((sectorsCount * filesCount() * 4) + 1)); + for (int fRead = 0, sectorID = 0; sectorID < sectorsCount; sectorID++) { + int length = 0; + int counter = 0; + for (var file : sortedFiles) { + length += packed.readInt(); + System.arraycopy(packed.getBuffer(), fRead, file.getData().getBuffer(), lengths[counter], length); + lengths[counter++] += length; + fRead += length; + } + } + + } + + /** + * Pack's unpacked files. + */ + private CacheBuffer pack() { + if (filesCount() <= 1) { + if (filesCount() <= 0) { + CacheBuffer container = Helper.encodeFilesContainer(new CacheBuffer(new byte[0]), version); + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.encryptContainer(container, xtea); + } + return container.trim(); + } + var firstFile = files.get(files.firstIntKey()); + CacheBuffer packed = new CacheBuffer(firstFile.getData().getBuffer().length); + packed.writeBytes(firstFile.getData().getBuffer(), 0, firstFile.getData().getBuffer().length); + CacheBuffer container = Helper.encodeFilesContainer(packed, version); + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.encryptContainer(container, xtea); + } + return container.trim(); + } + var sortedFiles = files.values().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + int allocLength = 1 + (4 * filesCount()); // sector header + for (var file : sortedFiles) + allocLength += file.getData().getBuffer().length; + CacheBuffer packed = new CacheBuffer(allocLength); + for (var file : sortedFiles) { + packed.writeBytes(file.getData().getBuffer(), 0, file.getData().getBuffer().length); + } + + var lengthOffset = 0; + for (var file : sortedFiles) { + var length = file.getData().getBuffer().length; + packed.writeInt(length - lengthOffset); + lengthOffset += length - lengthOffset; + } + packed.writeByte(1); // 1 sector + CacheBuffer container = Helper.encodeFilesContainer(packed, version); + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.encryptContainer(container, xtea); + } + return container.trim(); + } + + /** + * Update's crc32 and whirlpool hash to one's from + * given buffer. + */ + private void updateHashes(CacheBuffer packedFiles) { + crc = Helper.crc32(packedFiles, 0, packedFiles.getBuffer().length - 2); + digest = Whirlpool.whirlpool(packedFiles.getBuffer(), 0, packedFiles.getBuffer().length - 2); + } + + + /** + * Add's new file to this folder. + * If there's already a file with same id then + * it get's overwriten. + */ + public void addRSFile(RSFile file) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (file.getID() == -1) file.setID(getRSFreeFileID()); + files.put(file.getID(), file); + if (file.hasName()) { + filesByName.put(file.getName(), file.getID()); + } + needsRepack = fileSystemInfoChanged = true; + } + + /** + * Remove's file from this folder. + */ + public void removeFile(RSFile file) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + files.remove(file.getID()); + filesByName.remove(file.getName()); + needsRepack = fileSystemInfoChanged = true; + } + + /** + * Delete's all files on this folder. + */ + public void deleteAllFiles() { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + files.clear(); + needsRepack = fileSystemInfoChanged = true; + } + + /** + * Recalculate's folder's hashes. + */ + public void recalculate() { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + updateHashes(packedFiles); + fileSystemInfoChanged = true; + } + + /** + * Returns highest file ids. + */ + public int getHighestId() { + return getRSFreeFileID() - 1; + } + + + /** + * Get's free file ID. + */ + private int getRSFreeFileID() { + if (files.isEmpty()) { + return 0; + } + + int highest = -1; + for (var file : files.values()) { + if (file.getID() > highest) { + highest = file.getID(); + } + } + return highest + 1; + } + + /** + * Find's file by id's id. + * Returns null if not found. + */ + public RSFile findRSFileByID(int id) { + if (!isLoaded()) throw new RuntimeException("Folder is not loaded."); + return files.get(id); + } + + /** + * Find's file by name. + * Returns null if not found. + */ + public RSFile findRSFileByName(String name) { + return findRSFileByName(Helper.strToI(name)); + } + + /** + * Find's file by name. + * Returns null if not found. + */ + public RSFile findRSFileByName(int name) { + if (!isLoaded()) throw new RuntimeException("Folder is not loaded."); + + if (name == -1) return null; + + return files.get(filesByName.get(name)); + } + + /** + * Wheter this folder was loaded. + */ + public boolean isLoaded() { + return packedFiles != null; + } + + /** + * Wheter this folder needs repacking. + */ + private boolean needsRepack() { + if (needsRepack) return true; + for (var file : files.values()) { + if (file.isDataChanged()) { + return true; + } + } + return false; + } + + /** + * Mark's this folder as already repacked. + */ + private void markAsNotNeedRepack() { + needsRepack = false; + for (var file : files.values()) { + file.markDataAsNotChanged(); + } + } + + + /** + * Wheter this folder was changed in any way. + */ + public boolean isFileSystemInfoChanged() { + if (fileSystemInfoChanged) return true; + for (var file : files.values()) { + if (file.isFileSystemInfoChanged()) { + return true; + } + } + return false; + } + + /** + * Mark's this folder as not changed, this + * happens when fit is repacked. + */ + public void markFileSystemInfoAsNotChanged() { + fileSystemInfoChanged = false; + for (var file : files.values()) { + file.markFileSystemInfoAsNotChanged(); + } + } + + /** + * Mark's this folder file system info as changed, + * get's called by FS only. + */ + public void markFileSystemInfoAsChanged() { + fileSystemInfoChanged = true; + } + + /** + * Get's count of files this folder has. + */ + public int filesCount() { + return files.size(); //files.keySet().stream().max(Comparator.naturalOrder()).orElse(-1) + 1; + } + + /** + * Get's all files that this folder has. + * Modifying the array in any way is not allowed. + * + * @return + */ + public ObjectCollection getRSFiles() { + return files.values(); + } + + /** + * Get's ID of this folder. + */ + public int getID() { + return id; + } + + /** + * Set's ID of this folder. + */ + public void setID(int id) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.id != id) this.fileSystemInfoChanged = true; + this.id = id; + } + + /** + * Get's name of this folder. + */ + public int getName() { + return name; + } + + /** + * Set's name of this folder. + */ + public void setName(String name) { + setName(Helper.strToI(name)); + } + + /** + * Set's name of this folder. + */ + public void setName(int name) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.name != name) this.fileSystemInfoChanged = true; + this.name = name; + } + + /** + * Get's version of this folder. + */ + public int getVersion() { + return version; + } + + /** + * Set's version of this folder. + */ + public void setVersion(int version) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.version != version) this.fileSystemInfoChanged = this.needsRepack = true; + this.version = version; + } + + /** + * Set's XTEA keys of this folder. + */ + public void setXTEA(int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.xtea != xtea) this.fileSystemInfoChanged = this.needsRepack = true; + this.xtea = xtea; + } + + + /** + * Get's crc32 of packed version of this folder. + */ + public int getCRC32() { + return crc; + } + + /** + * Get's whirlpool digest of packed version of this folder. + */ + public byte[] getDigest() { + return digest; + } + + /** + * Get's packed files buffer. + * Call to finish() is a must if you want + * to get up-to-date version. + */ + public CacheBuffer getPackedFiles() { + return packedFiles; + } + + public boolean hasName() { + return name != -1; + } +} diff --git a/cache/src/main/java/org/apollo/cache/Helper.java b/cache/src/main/java/org/apollo/cache/Helper.java new file mode 100644 index 000000000..c24d60929 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Helper.java @@ -0,0 +1,277 @@ +package org.apollo.cache; + +import org.apache.tools.bzip2.CBZip2InputStream; +import org.apache.tools.bzip2.CBZip2OutputStream; +import org.tukaani.xz.LZMA2Options; +import org.tukaani.xz.LZMAInputStream; +import org.tukaani.xz.XZOutputStream; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.concurrent.CompletionException; +import java.util.zip.CRC32; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +public class Helper { + + private static CRC32 crc32 = new CRC32(); + + public static final int COMPRESSION_NONE = 0; + public static final int COMPRESSION_BZIP2 = 1; + public static final int COMPRESSION_GZIP = 2; + public static final int COMPRESSION_LZMA = 3; + + + public static void decryptContainer(byte[] container, int[] keys) { + decryptContainer(new CacheBuffer(container), keys); + } + + public static void decryptContainer(CacheBuffer container, int[] keys) { + container.xteaDecrypt(keys, 5, container.getBuffer().length - 2); + } + + + public static void encryptContainer(byte[] container, int[] keys) { + encryptContainer(new CacheBuffer(container), keys); + } + + public static void encryptContainer(CacheBuffer container, int[] keys) { + container.xteaEncrypt(keys, 5, container.getBuffer().length - 2); + } + + public static byte[] decodeFilesContainer(byte[] data) { + return decodeFilesContainer(new CacheBuffer(data)).getBuffer(); + } + + public static CacheBuffer decodeFilesContainer(CacheBuffer container) { + return decodeContainer(container, false); + } + + public static byte[] decodeFITContainer(byte[] data) { + return decodeFITContainer(new CacheBuffer(data)).getBuffer(); + } + + public static CacheBuffer decodeFITContainer(CacheBuffer container) { + return decodeContainer(container, true); + } + + private static CacheBuffer decodeContainer(CacheBuffer container, boolean isFITContainer) { + container.setPosition(0); + int compressionType = container.readUByte(); + if (compressionType > COMPRESSION_LZMA) + throw new RuntimeException("Unknown compression type:" + compressionType); + int length = container.readInt(); + CacheBuffer data; + if (compressionType != COMPRESSION_NONE) { + int decompressedLength = container.readInt(); + data = new CacheBuffer(decompressedLength); + try { + if (compressionType == COMPRESSION_GZIP) { + DataInputStream stream = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(container.getBuffer(), + container.getPosition(), length))); + stream.readFully(data.getBuffer()); + stream.close(); + } else if (compressionType == COMPRESSION_BZIP2) { + // we need to add header + byte[] reloc = new byte[length + 2]; + reloc[0] = 'h';reloc[1] = '1'; + System.arraycopy(container.getBuffer(), container.getPosition(), reloc, 2, length); + DataInputStream stream = new DataInputStream(new CBZip2InputStream(new ByteArrayInputStream(reloc))); + stream.readFully(data.getBuffer()); + stream.close(); + } else { + // we need to add length + byte[] reloc = new byte[length + 8]; + reloc[5] = (byte) (decompressedLength >>> 0); + reloc[6] = (byte) (decompressedLength >>> 8); + reloc[7] = (byte) (decompressedLength >>> 16); + reloc[8] = (byte) (decompressedLength >>> 24); + reloc[9] = reloc[10] = reloc[11] = reloc[12] = 0; + System.arraycopy(container.getBuffer(), container.getPosition() + 0, reloc, 0, 5); + System.arraycopy(container.getBuffer(), container.getPosition() + 5, reloc, 13, length - 5); + LZMAInputStream stream = new LZMAInputStream(new ByteArrayInputStream(reloc)); + while (data.getPosition() < data.getBuffer().length) { + int amt = stream.read(data.getBuffer(), data.getPosition(), data.getBuffer().length - data.getPosition()); + if (amt == -1) { + stream.close(); + throw new IOException(); + } + data.setPosition(data.getPosition() + amt); + } + + stream.close(); + } + } catch (IOException ioex) { + throw new CompletionException(ioex); + } + } else { + data = new CacheBuffer(length); + container.readBytes(data.getBuffer(), data.getPosition(), length); + } + if (!isFITContainer) { + @SuppressWarnings("unused") + int version = container.readUShort(); + } + return data; + } + + /** + * Does basic verification and decides if container is valid. + */ + public static boolean validFilesContainer(CacheBuffer container) { + if (container.getBuffer().length < 7) + return false; + container.setPosition(0); + int compressionType = container.readUByte(); + if (compressionType > COMPRESSION_LZMA) + return false; + int length = container.readInt(); + if (compressionType != COMPRESSION_NONE) { + if ((container.getBuffer().length - container.getPosition()) < 4) + return false; + container.readInt(); + } + if (length < 0 || (container.getBuffer().length - container.getPosition() - length - 2) != 0) + return false; + return true; + + } + + public static int decodeVersion(CacheBuffer container) { + container.setPosition(0); + int compressionType = container.readUByte(); + if (compressionType > COMPRESSION_LZMA) + throw new RuntimeException("Unknown compression type:" + compressionType); + int length = container.readInt(); + if (compressionType != COMPRESSION_NONE) + container.readInt(); // decompressed length + container.setPosition(container.getPosition() + length); + return container.readUShort(); + } + + + public static byte[] encodeFilesContainer(byte[] file, int fileVersion) { + return encodeFilesContainer(new CacheBuffer(file), fileVersion).getBuffer(); + } + + public static byte[] encodeFilesContainer(byte[] file, int fileVersion, int compressionType) { + return encodeFilesContainer(new CacheBuffer(file), fileVersion, compressionType).getBuffer(); + } + + public static CacheBuffer encodeFilesContainer(CacheBuffer file, int fileVersion) { + return encodeFilesContainer(file, fileVersion, decideCompression(file)); + } + + public static CacheBuffer encodeFilesContainer(CacheBuffer file, int fileVersion, int compressionType) { + return encodeContainer(file, fileVersion, compressionType, false); + } + + public static byte[] encodeFITContainer(byte[] file, int fileVersion) { + return encodeFITContainer(new CacheBuffer(file), fileVersion).getBuffer(); + } + + public static byte[] encodeFITContainer(byte[] file, int fileVersion, int compressionType) { + return encodeFITContainer(new CacheBuffer(file), fileVersion, compressionType).getBuffer(); + } + + public static CacheBuffer encodeFITContainer(CacheBuffer file, int fileVersion) { + return encodeFITContainer(file, fileVersion, decideCompression(file)); + } + + public static CacheBuffer encodeFITContainer(CacheBuffer file, int fileVersion, int compressionType) { + return encodeContainer(file, fileVersion, compressionType, true); + } + + private static CacheBuffer encodeContainer(CacheBuffer file, int fileVersion, int compressionType, boolean isFITContainer) { + if (compressionType > COMPRESSION_GZIP) // This is wrong + throw new RuntimeException("Unsupported compression type:" + compressionType); + + int allocLength = 1 + 4 + (!isFITContainer ? 2 : 0); + int fileLength = file.getBuffer().length; + if (compressionType != COMPRESSION_NONE) { + allocLength += 4; + try { + if (compressionType == COMPRESSION_GZIP) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream out = new GZIPOutputStream(baos); + out.write(file.getBuffer()); + out.finish(); + out.close(); + file = new CacheBuffer(baos.toByteArray()); + baos.close(); + } else if (compressionType == COMPRESSION_BZIP2) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + CBZip2OutputStream out = new CBZip2OutputStream(baos,1); + out.write(file.getBuffer()); + out.close(); + byte[] data = baos.toByteArray(); // we need to remove h1 + byte[] reloc = new byte[data.length - 2]; + System.arraycopy(data, 2, reloc, 0, reloc.length); + file = new CacheBuffer(reloc); + baos.close(); + } else { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + LZMA2Options options = new LZMA2Options(); + + options.setPreset(7); // play with this number: 6 is default but 7 works better for mid sized archives ( > 8mb) + + XZOutputStream out = new XZOutputStream(baos, options); + out.write(file.getBuffer()); + out.flush(); + out.close(); + + byte[] data = baos.toByteArray(); // we need to remove h1 + byte[] reloc = new byte[data.length - 8]; + System.arraycopy(data, 8, reloc, 0, reloc.length); + file = new CacheBuffer(reloc); + baos.close(); + } + } catch (IOException ioex) { + throw new RuntimeException(ioex); + } + } + allocLength += file.getBuffer().length; + + CacheBuffer container = new CacheBuffer(allocLength); + container.writeByte(compressionType); + container.writeInt(file.getBuffer().length); + if (compressionType != COMPRESSION_NONE) + container.writeInt(fileLength); + container.writeBytes(file.getBuffer(), 0, file.getBuffer().length); + if (!isFITContainer) { + container.writeShort(fileVersion); + } + return container; + } + + public static int crc32(byte[] data, int offset, int length) { + return crc32(new CacheBuffer(data), offset, length); + } + + public static int crc32(CacheBuffer data, int offset, int length) { + crc32.update(data.getBuffer(), offset, length); + int v = (int) crc32.getValue(); + crc32.reset(); + return v; + } + + public static int strToI(String str) { + if (str == null) + return -1; + + // same as return str.hashcode(); + int i = 0; + for (int a = 0; a < str.length(); a++) + i = (31 * i) + str.charAt(a); + return i; + } + + private static int decideCompression(CacheBuffer data) { + if (data.getBuffer().length < 100) + return COMPRESSION_NONE; + return COMPRESSION_GZIP; // bzip2 is unreliable + } +} diff --git a/cache/src/main/java/org/apollo/cache/Index.java b/cache/src/main/java/org/apollo/cache/Index.java index a03996978..20377214e 100644 --- a/cache/src/main/java/org/apollo/cache/Index.java +++ b/cache/src/main/java/org/apollo/cache/Index.java @@ -1,67 +1,287 @@ package org.apollo.cache; -import com.google.common.base.Preconditions; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; /** - * An {@link Index} points to a file in the {@code main_file_cache.dat} file. - * - * @author Graham + * Manages the reading and writing for a particular file store in the cache. */ -public final class Index { - - /** - * Decodes a buffer into an index. - * - * @param buffer The buffer. - * @return The decoded {@link Index}. - * @throws IllegalArgumentException If the buffer length is invalid. - */ - public static Index decode(byte[] buffer) { - Preconditions.checkArgument(buffer.length == FileSystemConstants.INDEX_SIZE, "Incorrect buffer length."); - - int size = (buffer[0] & 0xFF) << 16 | (buffer[1] & 0xFF) << 8 | buffer[2] & 0xFF; - int block = (buffer[3] & 0xFF) << 16 | (buffer[4] & 0xFF) << 8 | buffer[5] & 0xFF; - - return new Index(size, block); - } - - /** - * The first block of the file. - */ - private final int block; - - /** - * The size of the file. - */ - private final int size; - - /** - * Creates the index. - * - * @param size The size of the file. - * @param block The first block of the file. - */ - public Index(int size, int block) { - this.size = size; - this.block = block; - } - - /** - * Gets the first block of the file. - * - * @return The first block of the file. - */ - public int getBlock() { - return block; - } - - /** - * Gets the size of the file. - * - * @return The size of the file. - */ - public int getSize() { - return size; - } - -} \ No newline at end of file +public class Index { + + private static final int IDX_BLOCK_LEN = 6; + private static final int HEADER_LEN = 8; + private static final int EXPANDED_HEADER_LEN = 10; + private static final int BLOCK_LEN = 512; + private static final int EXPANDED_BLOCK_LEN = 510; + private static final int TOTAL_BLOCK_LEN = HEADER_LEN + BLOCK_LEN; + private static ByteBuffer tempBuffer = ByteBuffer.allocateDirect(TOTAL_BLOCK_LEN); + + private int index; + private FileChannel indexChannel; + private FileChannel dataChannel; + private int maxSize; + + /** + * Creates a new FileStore object. + * + * @param index The index of this file store. + * @param dataChannel The channel of the data file for this file store. + * @param indexChannel The channel of the index file for this file store. + * @param maxSize The maximum size of a file in this file store. + */ + public Index(int index, FileChannel dataChannel, + FileChannel indexChannel, int maxSize) { + this.index = index; + this.dataChannel = dataChannel; + this.indexChannel = indexChannel; + this.maxSize = maxSize; + } + + /** + * Gets the number of files stored in this file store. + * + * @return This file store's file count. + */ + public int getFileCount() { + try { + return (int) (indexChannel.size() / IDX_BLOCK_LEN); + } catch (IOException ex) { + return 0; + } + } + + /** + * Reads a file from the file store. + * + * @param file The file to read. + * @return The file's data, or null if the file was invalid. + */ + public CacheBuffer get(int file) { + synchronized (dataChannel) { + try { + if (file * IDX_BLOCK_LEN + IDX_BLOCK_LEN > indexChannel.size()) { + return null; + } + + tempBuffer.position(0).limit(IDX_BLOCK_LEN); + indexChannel.read(tempBuffer, file * IDX_BLOCK_LEN); + tempBuffer.flip(); + int size = getMediumInt(tempBuffer); + int block = getMediumInt(tempBuffer); + + if (size < 0 || size > maxSize) { + return null; + } + if (block <= 0 || block > dataChannel.size() / TOTAL_BLOCK_LEN) { + return null; + } + + ByteBuffer fileBuffer = ByteBuffer.allocate(size); + int remaining = size; + int chunk = 0; + int blockLen = file <= 0xffff ? BLOCK_LEN : EXPANDED_BLOCK_LEN; + int headerLen = file <= 0xffff ? HEADER_LEN : EXPANDED_HEADER_LEN; + while (remaining > 0) { + if (block == 0) { + return null; + } + + int blockSize = remaining > blockLen ? blockLen : remaining; + tempBuffer.position(0).limit(blockSize + headerLen); + int read = dataChannel.read(tempBuffer, (long) block * TOTAL_BLOCK_LEN); + if (read == -1) { + return null; + } + + tempBuffer.flip(); + + int currentFile, currentChunk, nextBlock, currentIndex; + if (file <= 65535) { + currentFile = tempBuffer.getShort() & 0xffff; + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } else { + currentFile = tempBuffer.getInt(); + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } + + if (file != currentFile || chunk != currentChunk || index != currentIndex) { + return null; + } + if (nextBlock < 0 || nextBlock > dataChannel.size() / TOTAL_BLOCK_LEN) { + return null; + } + + fileBuffer.put(tempBuffer); + remaining -= blockSize; + block = nextBlock; + chunk++; + } + + fileBuffer.flip(); + return new CacheBuffer(fileBuffer.array()); + } catch (IOException ex) { + return null; + } + } + } + + /** + * Writes an item to the file store. + * + * @param file The file to write. + * @param data The file's data. + * @param size The size of the file. + * @return true if the file was written, false otherwise. + */ + public boolean put(int file, CacheBuffer data, int size) { + if (size < 0 || size > maxSize) { + throw new IllegalArgumentException("File too big: " + index + "," + file + " size: " + size); + } + + boolean success = put(file, ByteBuffer.wrap(data.getBuffer()), size, true); + if (!success) { + success = put(file, ByteBuffer.wrap(data.getBuffer()), size, false); + } + + return success; + } + + private boolean put(int file, ByteBuffer data, int size, boolean exists) { + try { + int block; + if (exists) { + if (file * IDX_BLOCK_LEN + IDX_BLOCK_LEN > indexChannel.size()) { + return false; + } + + tempBuffer.position(0).limit(IDX_BLOCK_LEN); + indexChannel.read(tempBuffer, file * IDX_BLOCK_LEN); + tempBuffer.flip().position(3); + block = getMediumInt(tempBuffer); + + if (block <= 0 || block > dataChannel.size() / TOTAL_BLOCK_LEN) { + return false; + } + } else { + block = (int) ((dataChannel.size() + TOTAL_BLOCK_LEN - 1) / TOTAL_BLOCK_LEN); + if (block == 0) { + block = 1; + } + } + + tempBuffer.position(0); + putMediumInt(tempBuffer, size); + putMediumInt(tempBuffer, block); + tempBuffer.flip(); + indexChannel.write(tempBuffer, file * IDX_BLOCK_LEN); + + int remaining = size; + int chunk = 0; + int blockLen = file <= 0xffff ? BLOCK_LEN : EXPANDED_BLOCK_LEN; + int headerLen = file <= 0xffff ? HEADER_LEN : EXPANDED_HEADER_LEN; + while (remaining > 0) { + int nextBlock = 0; + if (exists) { + tempBuffer.position(0).limit(headerLen); + int read = dataChannel.read(tempBuffer, (long) block * TOTAL_BLOCK_LEN); + if (read == -1) { + return false; + } + + tempBuffer.flip(); + + int currentFile, currentChunk, currentIndex; + if (file <= 0xffff) { + currentFile = tempBuffer.getShort() & 0xffff; + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } else { + currentFile = tempBuffer.getInt(); + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } + + if (file != currentFile || chunk != currentChunk || index != currentIndex) { + return false; + } + if (nextBlock < 0 || nextBlock > dataChannel.size() / TOTAL_BLOCK_LEN) { + return false; + } + } + + if (nextBlock == 0) { + exists = false; + nextBlock = (int) ((dataChannel.size() + TOTAL_BLOCK_LEN - 1) / TOTAL_BLOCK_LEN); + if (nextBlock == 0) { + nextBlock = 1; + } + if (nextBlock == block) { + nextBlock++; + } + } + + if (remaining <= blockLen) { + nextBlock = 0; + } + tempBuffer.position(0).limit(TOTAL_BLOCK_LEN); + if (file <= 0xffff) { + tempBuffer.putShort((short) file); + tempBuffer.putShort((short) chunk); + putMediumInt(tempBuffer, nextBlock); + tempBuffer.put((byte) index); + } else { + tempBuffer.putInt(file); + tempBuffer.putShort((short) chunk); + putMediumInt(tempBuffer, nextBlock); + tempBuffer.put((byte) index); + } + + int blockSize = remaining > blockLen ? blockLen : remaining; + data.limit(data.position() + blockSize); + tempBuffer.put(data); + tempBuffer.flip(); + + dataChannel.write(tempBuffer, (long) block * TOTAL_BLOCK_LEN); + remaining -= blockSize; + block = nextBlock; + chunk++; + } + + return true; + } catch (IOException ex) { + return false; + } + } + + private static int getMediumInt(ByteBuffer buffer) { + return ((buffer.get() & 0xff) << 16) | ((buffer.get() & 0xff) << 8) | + (buffer.get() & 0xff); + } + + private static void putMediumInt(ByteBuffer buffer, int val) { + buffer.put((byte) (val >> 16)); + buffer.put((byte) (val >> 8)); + buffer.put((byte) val); + } + + /** + * Close's this store. + */ + public void close() { + try { + this.dataChannel.close(); + } catch (IOException e) { + } + try { + this.indexChannel.close(); + } catch (IOException e) { + } + } +} diff --git a/cache/src/main/java/org/apollo/cache/IndexedFileSystem.java b/cache/src/main/java/org/apollo/cache/IndexedFileSystem.java deleted file mode 100644 index 43c837461..000000000 --- a/cache/src/main/java/org/apollo/cache/IndexedFileSystem.java +++ /dev/null @@ -1,332 +0,0 @@ -package org.apollo.cache; - -import com.google.common.base.Preconditions; -import org.apollo.cache.archive.Archive; - -import java.io.Closeable; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.zip.CRC32; - -/** - * A file system based on top of the operating system's file system. It consists of a data file and index files. Index - * files point to blocks in the data file, which contains the actual data. - * - * @author Graham - */ -public final class IndexedFileSystem implements Closeable { - - /** - * The Map that caches already-decoded Archives. - */ - private final Map cache = new HashMap<>(FileSystemConstants.ARCHIVE_COUNT); - - /** - * The index files. - */ - private final RandomAccessFile[] indices = new RandomAccessFile[256]; - - /** - * Read only flag. - */ - private final boolean readOnly; - - /** - * The cached CRC table. - */ - private ByteBuffer crcTable; - - /** - * The {@link #crcTable} represented as an {@code int} array. - */ - private int[] crcs; - - /** - * The data file. - */ - private RandomAccessFile data; - - /** - * Creates the file system with the specified base directory. - * - * @param base The base directory. - * @param readOnly Indicates whether the file system will be read only or not. - * @throws FileNotFoundException If the data files could not be found. - */ - public IndexedFileSystem(Path base, boolean readOnly) throws FileNotFoundException { - this.readOnly = readOnly; - detectLayout(base); - } - - @Override - public void close() throws IOException { - if (data != null) { - synchronized (data) { - data.close(); - } - } - - for (RandomAccessFile index : indices) { - if (index != null) { - synchronized (index) { - index.close(); - } - } - } - } - - /** - * Gets the {@link Archive} pointed to by the specified {@link FileDescriptor}. - * - * @param type The file type. - * @param file The file id. - * @return The Archive. - * @throws IOException If there is an error decoding the Archive. - */ - public Archive getArchive(int type, int file) throws IOException { - FileDescriptor descriptor = new FileDescriptor(type, file); - Archive cached = cache.get(descriptor); - - if (cached == null) { - cached = Archive.decode(getFile(descriptor)); - - synchronized (this) { - cache.put(descriptor, cached); - } - } - - return cached; - } - - /** - * Gets the CRC table. - * - * @return The CRC table. - * @throws IOException If there is an error accessing files to create the table. - * @throws IllegalStateException If this file system is not read-only. - */ - public ByteBuffer getCrcTable() throws IOException { - if (readOnly) { - synchronized (this) { - if (crcTable != null) { - return crcTable.duplicate(); - } - } - - int archives = getFileCount(0); - int hash = 1234; - int[] crcs = new int[archives]; - - CRC32 crc32 = new CRC32(); - for (int i = 1; i < crcs.length; i++) { - crc32.reset(); - - ByteBuffer buffer = getFile(0, i); - byte[] bytes = new byte[buffer.remaining()]; - buffer.get(bytes, 0, bytes.length); - crc32.update(bytes, 0, bytes.length); - - crcs[i] = (int) crc32.getValue(); - } - - ByteBuffer buffer = ByteBuffer.allocate((crcs.length + 1) * Integer.BYTES); - for (int crc : crcs) { - hash = (hash << 1) + crc; - buffer.putInt(crc); - } - - buffer.putInt(hash); - buffer.flip(); - - synchronized (this) { - crcTable = buffer.asReadOnlyBuffer(); - return crcTable.duplicate(); - } - } - - throw new IllegalStateException("Cannot get CRC table from a writable file system."); - } - - /** - * Gets the CRC table as an {@code int} array. - * - * @return The CRC table as an {@code int} array. - * @throws IOException If there is an error accessing files to create the table. - */ - public int[] getCrcs() throws IOException { - if (crcs == null) { - ByteBuffer buffer = getCrcTable(); - crcs = new int[(buffer.remaining() / Integer.BYTES) - 1]; - Arrays.setAll(crcs, crc -> buffer.getInt()); - } - return crcs; - } - - /** - * Gets a file. - * - * @param descriptor The {@link FileDescriptor} pointing to the file. - * @return A {@link ByteBuffer} containing the contents of the file. - * @throws IOException If there is an error decoding the file. - */ - public ByteBuffer getFile(FileDescriptor descriptor) throws IOException { - Index index = getIndex(descriptor); - ByteBuffer buffer = ByteBuffer.allocate(index.getSize()); - - long position = index.getBlock() * FileSystemConstants.BLOCK_SIZE; - int read = 0; - int size = index.getSize(); - int blocks = size / FileSystemConstants.CHUNK_SIZE; - if (size % FileSystemConstants.CHUNK_SIZE != 0) { - blocks++; - } - - for (int i = 0; i < blocks; i++) { - byte[] header = new byte[FileSystemConstants.HEADER_SIZE]; - synchronized (data) { - data.seek(position); - data.readFully(header); - } - - position += FileSystemConstants.HEADER_SIZE; - - int nextFile = (header[0] & 0xFF) << 8 | header[1] & 0xFF; - int curChunk = (header[2] & 0xFF) << 8 | header[3] & 0xFF; - int nextBlock = (header[4] & 0xFF) << 16 | (header[5] & 0xFF) << 8 | header[6] & 0xFF; - int nextType = header[7] & 0xFF; - - Preconditions.checkArgument(i == curChunk, "Chunk id mismatch."); - - int chunkSize = size - read; - if (chunkSize > FileSystemConstants.CHUNK_SIZE) { - chunkSize = FileSystemConstants.CHUNK_SIZE; - } - - byte[] chunk = new byte[chunkSize]; - synchronized (data) { - data.seek(position); - data.readFully(chunk); - } - buffer.put(chunk); - - read += chunkSize; - position = (long) nextBlock * (long) FileSystemConstants.BLOCK_SIZE; - - // if we still have more data to read, check the validity of the header - if (size > read) { - if (nextType != descriptor.getType() + 1) { - throw new IOException("File type mismatch."); - } - - if (nextFile != descriptor.getFile()) { - throw new IOException("File id mismatch."); - } - } - } - - buffer.flip(); - return buffer; - } - - /** - * Gets a file. - * - * @param type The file type. - * @param file The file id. - * @return A {@link ByteBuffer} which contains the contents of the file. - * @throws IOException If an I/O error occurs. - */ - public ByteBuffer getFile(int type, int file) throws IOException { - return getFile(new FileDescriptor(type, file)); - } - - /** - * Checks if this {@link IndexedFileSystem} is read only. - * - * @return {@code true} if so, {@code false} if not. - */ - public boolean isReadOnly() { - return readOnly; - } - - /** - * Automatically detect the layout of the specified directory. - * - * @param base The base directory. - * @throws FileNotFoundException If the data files could not be found. - */ - private void detectLayout(Path base) throws FileNotFoundException { - int indexCount = 0; - for (int index = 0; index < indices.length; index++) { - Path idx = base.resolve("main_file_cache.idx" + index); - if (Files.exists(idx) && !Files.isDirectory(idx)) { - indexCount++; - indices[index] = new RandomAccessFile(idx.toFile(), readOnly ? "r" : "rw"); - } - } - if (indexCount <= 0) { - throw new FileNotFoundException("No index file(s) present in " + base + "."); - } - - Path resources = base.resolve("main_file_cache.dat"); - if (Files.exists(resources) && !Files.isDirectory(resources)) { - data = new RandomAccessFile(resources.toFile(), readOnly ? "r" : "rw"); - } else { - throw new FileNotFoundException("No data file present."); - } - } - - /** - * Gets the number of files with the specified type. - * - * @param type The type. - * @return The number of files. - * @throws IOException If there is an error getting the length of the specified index file. - * @throws IndexOutOfBoundsException If {@code type} is less than 0, or greater than or equal to the amount of - * indices. - */ - private int getFileCount(int type) throws IOException { - Preconditions.checkElementIndex(type, indices.length, "File type out of bounds."); - - RandomAccessFile indexFile = indices[type]; - synchronized (indexFile) { - return (int) (indexFile.length() / FileSystemConstants.INDEX_SIZE); - } - } - - /** - * Gets the index of a file. - * - * @param descriptor The {@link FileDescriptor} which points to the file. - * @return The {@link Index}. - * @throws IOException If there is an error reading from the index file. - * @throws IndexOutOfBoundsException If the descriptor type is less than 0, or greater than or equal to the amount - * of indices. - */ - private Index getIndex(FileDescriptor descriptor) throws IOException { - int index = descriptor.getType(); - Preconditions.checkElementIndex(index, indices.length, "File descriptor type out of bounds."); - - byte[] buffer = new byte[FileSystemConstants.INDEX_SIZE]; - RandomAccessFile indexFile = indices[index]; - synchronized (indexFile) { - long position = descriptor.getFile() * FileSystemConstants.INDEX_SIZE; - if (position >= 0 && indexFile.length() >= position + FileSystemConstants.INDEX_SIZE) { - indexFile.seek(position); - indexFile.readFully(buffer); - } else { - throw new FileNotFoundException("Could not find find index."); - } - } - - return Index.decode(buffer); - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/RSFile.java b/cache/src/main/java/org/apollo/cache/RSFile.java new file mode 100644 index 000000000..df9136c30 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/RSFile.java @@ -0,0 +1,185 @@ +package org.apollo.cache; + +public class RSFile { + + /** + * Contains file ID. + */ + private int id; + /** + * Contains name hash of this file. + */ + private int name; + /** + * Contains file data if loaded. + */ + private CacheBuffer data; + /** + * Wheter filesystem info about this file + * changed in any way. + */ + private boolean fsInfoChanged; + /** + * Wheter file data was changed. + */ + private boolean dataChanged; + + @SuppressWarnings("unused") + private RSFile() { + + } + + /** + * This constructor can be used only by FS + * loader. + */ + public RSFile(int fileID, int name) { + this(fileID,name,null); + } + + + /** + * Construct's new file with autoassigned ID. + */ + public RSFile(String name, CacheBuffer data) { + this(-1, Helper.strToI(name),data); + } + + /** + * Construct's new file with autoassigned ID. + */ + public RSFile(CacheBuffer data) { + this(-1,-1,data); + } + + public RSFile(int filID, CacheBuffer data) { + this(filID,-1,data); + } + + public RSFile(int fileID, String name, CacheBuffer data) { + this(fileID,Helper.strToI(name),data); + } + + public RSFile(int fileID, int name, CacheBuffer data) { + this.id = fileID; + this.name = name; + this.data = data; + } + + /** + * Copies this file, including the + * buffer if it's present. + */ + public RSFile copy() { + RSFile f = new RSFile(id,name); + if (data != null) { + f.data = new CacheBuffer(data.toArray(0, data.getBuffer().length),data.getPosition()); + } + return f; + } + + public int getID() { + return id; + } + + public void setID(int id) { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file: " + id); + if (this.id != id) { + this.id = id; + fsInfoChanged = true; + } + } + + public int getName() { + return name; + } + + public void setName(String name) { + setName(Helper.strToI(name)); + } + + public void setName(int name) { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file."); + + if (this.name != name) { + fsInfoChanged = true; + this.name = name; + } + } + + public CacheBuffer getData() { + return data; + } + + /** + * Load's this file. + */ + public void load(CacheBuffer data) { + if (isLoaded()) + throw new RuntimeException("Already loaded."); + this.data = data; + } + + /** + * Set's file data. + */ + public void setData(CacheBuffer data) { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file."); + if (this.data != data) { + dataChanged = fsInfoChanged = true; + this.data = data; + } + } + + /** + * Wheter this file is loaded. + */ + public boolean isLoaded() { + return data != null; + } + + /** + * Unload's this file , can be called + * only by folder unload() method. + */ + public void unload() { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file."); + data = null; + } + + /** + * Whether filesystem info about this file changed. + */ + public boolean isFileSystemInfoChanged() { + return fsInfoChanged; + } + + /** + * Wheter data was changed. + */ + public boolean isDataChanged() { + return dataChanged; + } + + /** + * Mark's this file as not changed. + */ + public void markFileSystemInfoAsNotChanged() { + fsInfoChanged = false; + } + + /** + * Mark's data as not changed. + */ + public void markDataAsNotChanged() { + dataChanged = false; + } + + public boolean hasName() { + return name != -1; + } +} diff --git a/cache/src/main/java/org/apollo/cache/StringUtilities.java b/cache/src/main/java/org/apollo/cache/StringUtilities.java new file mode 100644 index 000000000..5811fde3c --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/StringUtilities.java @@ -0,0 +1,142 @@ +package org.apollo.cache; + +public class StringUtilities { + + private static char[] UNICODE_TABLE = {'\u20ac', '\0', '\u201a', '\u0192', '\u201e', '\u2026', '\u2020', '\u2021', '\u02c6', '\u2030', + '\u0160', '\u2039', '\u0152', '\0', '\u017d', '\0', '\0', + '\u2018', '\u2019', '\u201c', '\u201d', '\u2022', '\u2013', '\u2014', '\u02dc', '\u2122', '\u0161', '\u203a', '\u0153', '\0', '\u017e', + '\u0178'}; + + public static final String decodeString(byte[] buffer, int offset, int length) { + char[] strBuffer = new char[length]; + int write = 0; + for (int dc = 0; dc < length; dc++) { + int data = buffer[dc + offset] & 0xff; + if (data == 0) + continue; + if (data >= 128 && data < 160) { + char uni = UNICODE_TABLE[data - 128]; + if (uni == 0) + uni = '?'; + strBuffer[write++] = (char) uni; + continue; + } + strBuffer[write++] = (char) data; + } + return new String(strBuffer, 0, write); + } + + public static char fromCP1252(byte value) { + int i = 0xff & value; + if (i == 0) { + throw new IllegalArgumentException("Non cp1252 character 0x" + Integer.toString(i, 16) + " provided"); + } + if (i >= 128 && i < 160) { + int i_1_ = UNICODE_TABLE[i - 128]; + if (i_1_ == 0) { + i_1_ = 63; + } + i = i_1_; + } + return (char) i; + } + + public static final int encodeString(byte[] buffer, int boffset, String str, int soffset, int slength) { + int charsToEncode = slength - soffset; + for (int cc = 0; cc < charsToEncode; cc++) { + char c = str.charAt(cc + soffset); + if ((c > 0 && c < 128) || (c >= 160 && c <= 255)) { + buffer[boffset + cc] = (byte) c; + continue; + } + + switch (c) { + case '\u20ac': + buffer[boffset + cc] = -128; + break; + case '\u201a': + buffer[boffset + cc] = -126; + break; + case '\u0192': + buffer[boffset + cc] = -125; + break; + case '\u201e': + buffer[boffset + cc] = -124; + break; + case '\u2026': + buffer[boffset + cc] = -123; + break; + case '\u2020': + buffer[boffset + cc] = -122; + break; + case '\u2021': + buffer[boffset + cc] = -121; + break; + case '\u02c6': + buffer[boffset + cc] = -120; + break; + case '\u2030': + buffer[boffset + cc] = -119; + break; + case '\u0160': + buffer[boffset + cc] = -118; + break; + case '\u2039': + buffer[boffset + cc] = -117; + break; + case '\u0152': + buffer[boffset + cc] = -116; + break; + case '\u017d': + buffer[boffset + cc] = -114; + break; + case '\u2018': + buffer[boffset + cc] = -111; + break; + case '\u2019': + buffer[boffset + cc] = -110; + break; + case '\u201c': + buffer[boffset + cc] = -109; + break; + case '\u201d': + buffer[boffset + cc] = -108; + break; + case '\u2022': + buffer[boffset + cc] = -107; + break; + case '\u2013': + buffer[boffset + cc] = -106; + break; + case '\u2014': + buffer[boffset + cc] = -105; + break; + case '\u02dc': + buffer[boffset + cc] = -104; + break; + case '\u2122': + buffer[boffset + cc] = -103; + break; + case '\u0161': + buffer[boffset + cc] = -102; + break; + case '\u203a': + buffer[boffset + cc] = -101; + break; + case '\u0153': + buffer[boffset + cc] = -100; + break; + case '\u017e': + buffer[boffset + cc] = -98; + break; + case '\u0178': + buffer[boffset + cc] = -97; + break; + default: + buffer[boffset + cc] = (byte) '?'; + break; + } + } + return charsToEncode; + } +} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/Whirlpool.java b/cache/src/main/java/org/apollo/cache/Whirlpool.java new file mode 100644 index 000000000..8ed240d0e --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Whirlpool.java @@ -0,0 +1,416 @@ +package org.apollo.cache; + +/** + * The Whirlpool hashing function. + * + *

+ * References + * + *

+ * The Whirlpool algorithm was developed by + * Paulo S. L. M. Barreto and + * Vincent Rijmen. + * + * See + * P.S.L.M. Barreto, V. Rijmen, + * ``The Whirlpool hashing function,'' + * First NESSIE workshop, 2000 (tweaked version, 2003), + * + * + * @author Paulo S.L.M. Barreto + * @author Vincent Rijmen. + * + * @version 3.0 (2003.03.12) + * + * ============================================================================= + * + * Differences from version 2.1: + * + * - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2, 9). + * + * ============================================================================= + * + * Differences from version 2.0: + * + * - Generation of ISO/IEC 10118-3 test vectors. + * - Bug fix: nonzero carry was ignored when tallying the data length + * (this bug apparently only manifested itself when feeding data + * in pieces rather than in a single chunk at once). + * + * Differences from version 1.0: + * + * - Original S-box replaced by the tweaked, hardware-efficient version. + * + * ============================================================================= + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +import java.util.Arrays; + +public class Whirlpool { + + /** + * The message digest size (in bits) + */ + public static final int DIGESTBITS = 512; + + /** + * The message digest size (in bytes) + */ + public static final int DIGESTBYTES = DIGESTBITS >>> 3; + + /** + * The number of rounds of the internal dedicated block cipher. + */ + protected static final int R = 10; + + /** + * The substitution box. + */ + private static final String sbox = + "\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152" + + "\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57" + + "\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85" + + "\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8" + + "\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333" + + "\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0" + + "\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE" + + "\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d" + + "\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF" + + "\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A" + + "\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c" + + "\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04" + + "\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB" + + "\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9" + + "\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1" + + "\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886"; + + private static long[][] C = new long[8][256]; + private static long[] rc = new long[R + 1]; + + static { + for (int x = 0; x < 256; x++) { + char c = sbox.charAt(x/2); + long v1 = ((x & 1) == 0) ? c >>> 8 : c & 0xff; + long v2 = v1 << 1; + if (v2 >= 0x100L) { + v2 ^= 0x11dL; + } + long v4 = v2 << 1; + if (v4 >= 0x100L) { + v4 ^= 0x11dL; + } + long v5 = v4 ^ v1; + long v8 = v4 << 1; + if (v8 >= 0x100L) { + v8 ^= 0x11dL; + } + long v9 = v8 ^ v1; + /* + * build the circulant table C[0][x] = S[x].[1, 1, 4, 1, 8, 5, 2, 9]: + */ + C[0][x] = + (v1 << 56) | (v1 << 48) | (v4 << 40) | (v1 << 32) | + (v8 << 24) | (v5 << 16) | (v2 << 8) | (v9 ); + /* + * build the remaining circulant tables C[t][x] = C[0][x] rotr t + */ + for (int t = 1; t < 8; t++) { + C[t][x] = (C[t - 1][x] >>> 8) | ((C[t - 1][x] << 56)); + } + } + + /* + * build the round constants: + */ + rc[0] = 0L; /* not used (assigment kept only to properly initialize all variables) */ + for (int r = 1; r <= R; r++) { + int i = 8*(r - 1); + rc[r] = + (C[0][i ] & 0xff00000000000000L) ^ + (C[1][i + 1] & 0x00ff000000000000L) ^ + (C[2][i + 2] & 0x0000ff0000000000L) ^ + (C[3][i + 3] & 0x000000ff00000000L) ^ + (C[4][i + 4] & 0x00000000ff000000L) ^ + (C[5][i + 5] & 0x0000000000ff0000L) ^ + (C[6][i + 6] & 0x000000000000ff00L) ^ + (C[7][i + 7] & 0x00000000000000ffL); + } + } + + public static byte[] whirlpool(byte[] data, int off, int len) { + byte source[]; + if(off <= 0) { + source = data; + } else { + source = new byte[len]; + for(int i = 0; i < len; i++) + source[i] = data[off + i]; + } + Whirlpool whirlpool = new Whirlpool(); + whirlpool.NESSIEinit(); + whirlpool.NESSIEadd(source, len * 8); + byte digest[] = new byte[64]; + whirlpool.NESSIEfinalize(digest); + return digest; + } + + /** + * Global number of hashed bits (256-bit counter). + */ + protected byte[] bitLength = new byte[32]; + + /** + * Buffer of data to hash. + */ + protected byte[] buffer = new byte[64]; + + /** + * Current number of bits on the buffer. + */ + protected int bufferBits = 0; + + /** + * Current (possibly incomplete) byte slot on the buffer. + */ + protected int bufferPos = 0; + + /** + * The hashing state. + */ + protected long[] hash = new long[8]; + protected long[] K = new long[8]; // the round key + protected long[] L = new long[8]; + protected long[] block = new long[8]; // mu(buffer) + protected long[] state = new long[8]; // the cipher state + + public Whirlpool() { + } + + /** + * The core Whirlpool transform. + */ + protected void processBuffer() { + /* + * map the buffer to a block: + */ + for (int i = 0, j = 0; i < 8; i++, j += 8) { + block[i] = + (((long)buffer[j ] ) << 56) ^ + (((long)buffer[j + 1] & 0xffL) << 48) ^ + (((long)buffer[j + 2] & 0xffL) << 40) ^ + (((long)buffer[j + 3] & 0xffL) << 32) ^ + (((long)buffer[j + 4] & 0xffL) << 24) ^ + (((long)buffer[j + 5] & 0xffL) << 16) ^ + (((long)buffer[j + 6] & 0xffL) << 8) ^ + (((long)buffer[j + 7] & 0xffL) ); + } + /* + * compute and apply K^0 to the cipher state: + */ + for (int i = 0; i < 8; i++) { + state[i] = block[i] ^ (K[i] = hash[i]); + } + /* + * iterate over all rounds: + */ + for (int r = 1; r <= R; r++) { + /* + * compute K^r from K^{r-1}: + */ + for (int i = 0; i < 8; i++) { + L[i] = 0L; + for (int t = 0, s = 56; t < 8; t++, s -= 8) { + L[i] ^= C[t][(int)(K[(i - t) & 7] >>> s) & 0xff]; + } + } + for (int i = 0; i < 8; i++) { + K[i] = L[i]; + } + K[0] ^= rc[r]; + /* + * apply the r-th round transformation: + */ + for (int i = 0; i < 8; i++) { + L[i] = K[i]; + for (int t = 0, s = 56; t < 8; t++, s -= 8) { + L[i] ^= C[t][(int)(state[(i - t) & 7] >>> s) & 0xff]; + } + } + for (int i = 0; i < 8; i++) { + state[i] = L[i]; + } + } + /* + * apply the Miyaguchi-Preneel compression function: + */ + for (int i = 0; i < 8; i++) { + hash[i] ^= state[i] ^ block[i]; + } + } + + /** + * Initialize the hashing state. + */ + public void NESSIEinit() { + Arrays.fill(bitLength, (byte)0); + bufferBits = bufferPos = 0; + buffer[0] = 0; // it's only necessary to cleanup buffer[bufferPos]. + Arrays.fill(hash, 0L); // initial value + } + + /** + * Delivers input data to the hashing algorithm. + * + * @param source plaintext data to hash. + * @param sourceBits how many bits of plaintext to process. + * + * This method maintains the invariant: bufferBits < 512 + */ + public void NESSIEadd(byte[] source, long sourceBits) { + /* + sourcePos + | + +-------+-------+------- + ||||||||||||||||||||| source + +-------+-------+------- + +-------+-------+-------+-------+-------+------- + |||||||||||||||||||||| buffer + +-------+-------+-------+-------+-------+------- + | + bufferPos + */ + int sourcePos = 0; // index of leftmost source byte containing data (1 to 8 bits). + int sourceGap = (8 - ((int)sourceBits & 7)) & 7; // space on source[sourcePos]. + int bufferRem = bufferBits & 7; // occupied bits on buffer[bufferPos]. + int b; + // tally the length of the added data: + long value = sourceBits; + for (int i = 31, carry = 0; i >= 0; i--) { + carry += (bitLength[i] & 0xff) + ((int)value & 0xff); + bitLength[i] = (byte)carry; + carry >>>= 8; + value >>>= 8; + } + // process data in chunks of 8 bits: + while (sourceBits > 8) { // at least source[sourcePos] and source[sourcePos+1] contain data. + // take a byte from the source: + b = ((source[sourcePos] << sourceGap) & 0xff) | + ((source[sourcePos + 1] & 0xff) >>> (8 - sourceGap)); + if (b < 0 || b >= 256) { + throw new RuntimeException("LOGIC ERROR"); + } + // process this byte: + buffer[bufferPos++] |= b >>> bufferRem; + bufferBits += 8 - bufferRem; // bufferBits = 8*bufferPos; + if (bufferBits == 512) { + // process data block: + processBuffer(); + // reset buffer: + bufferBits = bufferPos = 0; + } + buffer[bufferPos] = (byte)((b << (8 - bufferRem)) & 0xff); + bufferBits += bufferRem; + // proceed to remaining data: + sourceBits -= 8; + sourcePos++; + } + // now 0 <= sourceBits <= 8; + // furthermore, all data (if any is left) is in source[sourcePos]. + if (sourceBits > 0) { + b = (source[sourcePos] << sourceGap) & 0xff; // bits are left-justified on b. + // process the remaining bits: + buffer[bufferPos] |= b >>> bufferRem; + } else { + b = 0; + } + if (bufferRem + sourceBits < 8) { + // all remaining data fits on buffer[bufferPos], and there still remains some space. + bufferBits += sourceBits; + } else { + // buffer[bufferPos] is full: + bufferPos++; + bufferBits += 8 - bufferRem; // bufferBits = 8*bufferPos; + sourceBits -= 8 - bufferRem; + // now 0 <= sourceBits < 8; furthermore, all data is in source[sourcePos]. + if (bufferBits == 512) { + // process data block: + processBuffer(); + // reset buffer: + bufferBits = bufferPos = 0; + } + buffer[bufferPos] = (byte)((b << (8 - bufferRem)) & 0xff); + bufferBits += (int)sourceBits; + } + } + + /** + * Get the hash value from the hashing state. + * + * This method uses the invariant: bufferBits < 512 + */ + public void NESSIEfinalize(byte[] digest) { + // append a '1'-bit: + buffer[bufferPos] |= 0x80 >>> (bufferBits & 7); + bufferPos++; // all remaining bits on the current byte are set to zero. + // pad with zero bits to complete 512N + 256 bits: + if (bufferPos > 32) { + while (bufferPos < 64) { + buffer[bufferPos++] = 0; + } + // process data block: + processBuffer(); + // reset buffer: + bufferPos = 0; + } + while (bufferPos < 32) { + buffer[bufferPos++] = 0; + } + // append bit length of hashed data: + System.arraycopy(bitLength, 0, buffer, 32, 32); + // process data block: + processBuffer(); + // return the completed message digest: + for (int i = 0, j = 0; i < 8; i++, j += 8) { + long h = hash[i]; + digest[j ] = (byte)(h >>> 56); + digest[j + 1] = (byte)(h >>> 48); + digest[j + 2] = (byte)(h >>> 40); + digest[j + 3] = (byte)(h >>> 32); + digest[j + 4] = (byte)(h >>> 24); + digest[j + 5] = (byte)(h >>> 16); + digest[j + 6] = (byte)(h >>> 8); + digest[j + 7] = (byte)(h ); + } + } + + /** + * Delivers string input data to the hashing algorithm. + * + * @param source plaintext data to hash (ASCII text string). + * + * This method maintains the invariant: bufferBits < 512 + */ + public void NESSIEadd(String source) { + if (source.length() > 0) { + byte[] data = new byte[source.length()]; + for (int i = 0; i < source.length(); i++) { + data[i] = (byte)source.charAt(i); + } + NESSIEadd(data, 8 * data.length); + } + } + +} diff --git a/cache/src/main/java/org/apollo/cache/archive/Archive.java b/cache/src/main/java/org/apollo/cache/archive/Archive.java deleted file mode 100644 index 896e202bb..000000000 --- a/cache/src/main/java/org/apollo/cache/archive/Archive.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.apollo.cache.archive; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.apollo.util.BufferUtil; -import org.apollo.util.CompressionUtil; - -/** - * Represents an archive. - * - * @author Graham - */ -public final class Archive { - - /** - * Decodes the archive in the specified buffer. - * - * @param buffer The buffer. - * @return The archive. - * @throws IOException If there is an error decompressing the archive. - */ - public static Archive decode(ByteBuffer buffer) throws IOException { - int extractedSize = BufferUtil.readUnsignedMedium(buffer); - int size = BufferUtil.readUnsignedMedium(buffer); - boolean extracted = false; - - if (size != extractedSize) { - byte[] compressed = new byte[size]; - byte[] decompressed = new byte[extractedSize]; - buffer.get(compressed); - CompressionUtil.debzip2(compressed, decompressed); - buffer = ByteBuffer.wrap(decompressed); - extracted = true; - } - - int entryCount = buffer.getShort() & 0xFFFF; - int[] identifiers = new int[entryCount]; - int[] extractedSizes = new int[entryCount]; - int[] sizes = new int[entryCount]; - - for (int i = 0; i < entryCount; i++) { - identifiers[i] = buffer.getInt(); - extractedSizes[i] = BufferUtil.readUnsignedMedium(buffer); - sizes[i] = BufferUtil.readUnsignedMedium(buffer); - } - - ArchiveEntry[] entries = new ArchiveEntry[entryCount]; - for (int entry = 0; entry < entryCount; entry++) { - ByteBuffer entryBuffer; - if (!extracted) { - byte[] compressed = new byte[sizes[entry]]; - byte[] decompressed = new byte[extractedSizes[entry]]; - buffer.get(compressed); - CompressionUtil.debzip2(compressed, decompressed); - entryBuffer = ByteBuffer.wrap(decompressed); - } else { - byte[] buf = new byte[extractedSizes[entry]]; - buffer.get(buf); - entryBuffer = ByteBuffer.wrap(buf); - } - entries[entry] = new ArchiveEntry(identifiers[entry], entryBuffer); - } - return new Archive(entries); - } - - /** - * The entries in this archive. - */ - private final ArchiveEntry[] entries; - - /** - * Creates a new archive. - * - * @param entries The entries in this archive. - */ - public Archive(ArchiveEntry[] entries) { - this.entries = entries; - } - - /** - * Gets an {@link ArchiveEntry} by its name. - * - * @param name The name. - * @return The entry. - * @throws FileNotFoundException If the entry could not be found. - */ - public ArchiveEntry getEntry(String name) throws FileNotFoundException { - int hash = hash(name); - - for (ArchiveEntry entry : entries) { - if (entry.getIdentifier() == hash) { - return entry; - } - } - throw new FileNotFoundException("Could not find entry: " + name + "."); - } - - /** - * Hashes the specified string into an integer used to identify an {@link ArchiveEntry}. - * - * @param name The name of the entry. - * @return The hash. - */ - public static int hash(String name) { - return name.toUpperCase().chars().reduce(0, (hash, character) -> hash * 61 + character - 32); - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/archive/ArchiveEntry.java b/cache/src/main/java/org/apollo/cache/archive/ArchiveEntry.java deleted file mode 100644 index ce95a4376..000000000 --- a/cache/src/main/java/org/apollo/cache/archive/ArchiveEntry.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apollo.cache.archive; - -import java.nio.ByteBuffer; - -/** - * Represents a single entry in an {@link Archive}. - * - * @author Graham - */ -public final class ArchiveEntry { - - /** - * The buffer of this entry. - */ - private final ByteBuffer buffer; - - /** - * The identifier of this entry. - */ - private final int identifier; - - /** - * Creates a new archive entry. - * - * @param identifier The identifier. - * @param buffer The buffer. - */ - public ArchiveEntry(int identifier, ByteBuffer buffer) { - this.identifier = identifier; - this.buffer = buffer.asReadOnlyBuffer(); - } - - /** - * Gets the buffer of this entry. - * - * @return This buffer of this entry. - */ - public ByteBuffer getBuffer() { - return buffer.duplicate(); - } - - /** - * Gets the identifier of this entry. - * - * @return The identifier of this entry. - */ - public int getIdentifier() { - return identifier; - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/archive/package-info.java b/cache/src/main/java/org/apollo/cache/archive/package-info.java deleted file mode 100644 index 35b89a22b..000000000 --- a/cache/src/main/java/org/apollo/cache/archive/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains classes which deal with archives. - */ -package org.apollo.cache.archive; \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java index 5ba666216..996f93403 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java @@ -1,13 +1,11 @@ package org.apollo.cache.decoder; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.ByteBuffer; - -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.Archive; +import org.apollo.cache.RSFile; import org.apollo.cache.def.ItemDefinition; -import org.apollo.util.BufferUtil; /** * Decodes item data from the {@code obj.dat} file into {@link ItemDefinition}s. @@ -19,112 +17,157 @@ public final class ItemDefinitionDecoder implements Runnable { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fs; + private final Cache cache; /** * Creates the ItemDefinitionDecoder. * - * @param fs The {@link IndexedFileSystem}. + * @param cache The {@link Archive}. */ - public ItemDefinitionDecoder(IndexedFileSystem fs) { - this.fs = fs; + public ItemDefinitionDecoder(Cache cache) { + this.cache = cache; } @Override public void run() { - try { - Archive config = fs.getArchive(0, 2); - ByteBuffer data = config.getEntry("obj.dat").getBuffer(); - ByteBuffer idx = config.getEntry("obj.idx").getBuffer(); - - int count = idx.getShort(), index = 2; - int[] indices = new int[count]; - for (int i = 0; i < count; i++) { - indices[i] = index; - index += idx.getShort(); - } + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(10); - ItemDefinition[] definitions = new ItemDefinition[count]; - for (int i = 0; i < count; i++) { - data.position(indices[i]); - definitions[i] = decode(i, data); - } - - ItemDefinition.init(definitions); - } catch (IOException e) { - throw new UncheckedIOException("Error decoding ItemDefinitions.", e); + ItemDefinition[] definitions = new ItemDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); } + + ItemDefinition.init(definitions); } /** * Decodes a single definition. * - * @param id The item's id. + * @param id The item's id. * @param buffer The buffer. * @return The {@link ItemDefinition}. */ - private ItemDefinition decode(int id, ByteBuffer buffer) { + private ItemDefinition decode(int id, CacheBuffer buffer) { ItemDefinition definition = new ItemDefinition(id); - while (true) { - int opcode = buffer.get() & 0xFF; - + for (; ; ) { + int opcode = buffer.readUByte(); if (opcode == 0) { return definition; } else if (opcode == 1) { - buffer.getShort(); + definition.setBaseModel(buffer.readUShort()); } else if (opcode == 2) { - definition.setName(BufferUtil.readString(buffer)); - } else if (opcode == 3) { - definition.setDescription(BufferUtil.readString(buffer)); - } else if (opcode >= 4 && opcode <= 8 || opcode == 10) { - buffer.getShort(); + definition.setName(buffer.readString()); + } else if (opcode == 4) { + definition.setModelScale(buffer.readUShort()); + } else if (opcode == 5) { + definition.setModelPitch(buffer.readUShort()); + } else if (opcode == 6) { + definition.setModelRoll(buffer.readUShort()); + } else if (opcode == 7) { + definition.setModelTranslateX(buffer.readSignedShort()); + } else if (opcode == 8) { + definition.setModelTranslateY(buffer.readSignedShort()); } else if (opcode == 11) { definition.setStackable(true); } else if (opcode == 12) { - definition.setValue(buffer.getInt()); + definition.setValue(buffer.readInt()); } else if (opcode == 16) { definition.setMembersOnly(true); } else if (opcode == 23) { - buffer.getShort(); - buffer.get(); + definition.setPrimaryMaleModel(buffer.readUShort()); + definition.setMaleYOffset(buffer.readUByte()); } else if (opcode == 24) { - buffer.getShort(); + definition.setSecondaryMaleModel(buffer.readUShort()); } else if (opcode == 25) { - buffer.getShort(); - buffer.get(); + definition.setPrimaryFemaleModel(buffer.readUShort()); + definition.setFemaleYOffset(buffer.readUByte()); } else if (opcode == 26) { - buffer.getShort(); + definition.setSecondaryFemaleModel(buffer.readUShort()); } else if (opcode >= 30 && opcode < 35) { - String str = BufferUtil.readString(buffer); + String str = buffer.readString(); if (str.equalsIgnoreCase("hidden")) { str = null; } definition.setGroundAction(opcode - 30, str); } else if (opcode >= 35 && opcode < 40) { - definition.setInventoryAction(opcode - 35, BufferUtil.readString(buffer)); + definition.setInventoryAction(opcode - 35, buffer.readString()); } else if (opcode == 40) { - int colourCount = buffer.get() & 0xFF; - for (int i = 0; i < colourCount; i++) { - buffer.getShort(); - buffer.getShort(); + int size = buffer.readUByte(); + definition.setOriginalModelColors(new short[size]); + definition.setModifiedModelColors(new short[size]); + for (int count = 0; count < size; count++) { + definition.getOriginalModelColors()[count] = (short) buffer.readUShort(); + definition.getModifiedModelColors()[count] = (short) buffer.readUShort(); + } + } else if (opcode == 41) { + int size = buffer.readUByte(); + definition.setOriginalTextureColors(new short[size]); + definition.setModifiedTextureColors(new short[size]); + for (int count = 0; count < size; count++) { + definition.getOriginalTextureColors()[count] = (short) buffer.readUShort(); + definition.getModifiedTextureColors()[count] = (short) buffer.readUShort(); } - } else if (opcode == 78 || opcode == 79 || (opcode >= 90 && opcode <= 93) || opcode == 95) { - buffer.getShort(); + } else if (opcode == 42) { + definition.setShiftClickDropIndex(buffer.readByte()); + } else if (opcode == 65) { + definition.setNonExchangeItem(true); + } else if (opcode == 78) { + definition.setTertiaryMaleModel(buffer.readUShort()); + } else if (opcode == 79) { + definition.setTertiaryFemaleModel(buffer.readUShort()); + } else if (opcode == 90) { + definition.setMaleHead(buffer.readUShort()); + } else if (opcode == 91) { + definition.setFemaleHead(buffer.readUShort()); + } else if (opcode == 92) { + definition.setSecondaryMaleHead(buffer.readUShort()); + } else if (opcode == 93) { + definition.setSecondaryFemaleHead(buffer.readUShort()); + } else if (opcode == 95) { + definition.setModelYaw(buffer.readUShort()); } else if (opcode == 97) { - definition.setNoteInfoId(buffer.getShort() & 0xFFFF); + definition.setNoteInfoId(buffer.readUShort()); } else if (opcode == 98) { - definition.setNoteGraphicId(buffer.getShort() & 0xFFFF); + definition.setNoteGraphicId(buffer.readUShort()); } else if (opcode >= 100 && opcode < 110) { - buffer.getShort(); - buffer.getShort(); - } else if (opcode >= 110 && opcode <= 112) { - buffer.getShort(); - } else if (opcode == 113 || opcode == 114) { - buffer.get(); + if (definition.getStackIds() == null) { + definition.setStackIds(new int[10]); + definition.setStackAmounts(new int[10]); + } + definition.getStackIds()[opcode - 100] = buffer.readUShort(); + definition.getStackAmounts()[opcode - 100] = buffer.readUShort(); + } else if (opcode == 110) { + definition.setScaleX(buffer.readUShort()); + } else if (opcode == 111) { + definition.setScaleY(buffer.readUShort()); + } else if (opcode == 112) { + definition.setScaleZ(buffer.readUShort()); + } else if (opcode == 113) { + definition.setAmbience(buffer.readSignedByte()); + } else if (opcode == 114) { + definition.setContrast(buffer.readSignedByte()); } else if (opcode == 115) { - definition.setTeam(buffer.get() & 0xFF); + definition.setTeam(buffer.readUByte()); + } else if (opcode == 139) { + definition.setLoanInfo(buffer.readUShort()); + } else if (opcode == 140) { + definition.setLoanGraphicId(buffer.readUShort()); + } else if (opcode == 148) { + definition.setPlaceHolderInfo(buffer.readUShort()); + } else if (opcode == 149) { + definition.setPlaceHolderTemplate(buffer.readUShort()); + } else if (opcode == 249) { + final int size = buffer.readUByte(); + definition.setParameters(new Int2ObjectArrayMap<>(size)); + for (int index = 0; index < size; index++) { + final boolean stringInstance = buffer.readUByte() == 1; + final int key = buffer.readUMedInt(); + final Object value = stringInstance ? buffer.readString() : buffer.readInt(); + definition.getParameters().put(key, value); + } } + } } - } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java index aa5dfd20b..23310fffb 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java @@ -1,14 +1,11 @@ package org.apollo.cache.decoder; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.ByteBuffer; -import java.util.Arrays; - -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.Archive; +import org.apollo.cache.RSFile; import org.apollo.cache.def.NpcDefinition; -import org.apollo.util.BufferUtil; /** * Decodes npc data from the {@code npc.dat} file into {@link NpcDefinition}s. @@ -20,118 +17,196 @@ public final class NpcDefinitionDecoder implements Runnable { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fs; + private final Cache cache; /** * Creates the NpcDefinitionDecoder. * - * @param fs The {@link IndexedFileSystem}. + * @param cache The {@link Archive}. */ - public NpcDefinitionDecoder(IndexedFileSystem fs) { - this.fs = fs; + public NpcDefinitionDecoder(Cache cache) { + this.cache = cache; + + } @Override public void run() { - try { - Archive config = fs.getArchive(0, 2); - ByteBuffer data = config.getEntry("npc.dat").getBuffer(); - ByteBuffer idx = config.getEntry("npc.idx").getBuffer(); - - int count = idx.getShort(), index = 2; - int[] indices = new int[count]; - - for (int i = 0; i < count; i++) { - indices[i] = index; - index += idx.getShort(); - } - - NpcDefinition[] definitions = new NpcDefinition[count]; - for (int i = 0; i < count; i++) { - data.position(indices[i]); - definitions[i] = decode(i, data); - } - - NpcDefinition.init(definitions); - } catch (IOException e) { - throw new UncheckedIOException("Error decoding NpcDefinitions.", e); + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(9); + NpcDefinition[] definitions = new NpcDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); } + NpcDefinition.init(definitions); } /** * Decodes a single definition. * - * @param id The npc's id. + * @param id The npc's id. * @param buffer The buffer. * @return The {@link NpcDefinition}. */ - private NpcDefinition decode(int id, ByteBuffer buffer) { + private NpcDefinition decode(int id, CacheBuffer buffer) { NpcDefinition definition = new NpcDefinition(id); - while (true) { - int opcode = buffer.get() & 0xFF; - + int length; + int index; + for (; ; ) { + int opcode = buffer.readUByte(); if (opcode == 0) { return definition; } else if (opcode == 1) { - int length = buffer.get() & 0xFF; - int[] models = new int[length]; - for (int index = 0; index < length; index++) { - models[index] = buffer.getShort(); + length = buffer.readUByte(); + definition.setModels(new int[length]); + + for (index = 0; index < length; ++index) { + definition.getModels()[index] = buffer.readUShort(); } + } else if (opcode == 2) { - definition.setName(BufferUtil.readString(buffer)); - } else if (opcode == 3) { - definition.setDescription(BufferUtil.readString(buffer)); + definition.setName(buffer.readString()); } else if (opcode == 12) { - definition.setSize(buffer.get()); + definition.setSize(buffer.readUByte()); } else if (opcode == 13) { - definition.setStandAnimation(buffer.getShort()); + definition.setStandAnimation(buffer.readUShort()); } else if (opcode == 14) { - definition.setWalkAnimation(buffer.getShort()); + definition.setWalkAnimation(buffer.readUShort()); + } else if (opcode == 15) { + definition.setTurnLeftSequence(buffer.readUShort()); + } else if (opcode == 16) { + definition.setTurnRightSequence(buffer.readUShort()); } else if (opcode == 17) { - definition - .setWalkAnimations(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort()); - } else if (opcode >= 30 && opcode < 40) { - String action = BufferUtil.readString(buffer); + definition.setWalkAnimations(buffer.readUShort(), buffer.readUShort(), buffer.readUShort(), + buffer.readUShort()); + } else if (opcode >= 30 && opcode < 35) { + String action = buffer.readString(); if (action.equals("hidden")) { action = null; } definition.setInteraction(opcode - 30, action); } else if (opcode == 40) { - int length = buffer.get() & 0xFF; - int[] originalColours = new int[length]; - int[] replacementColours = new int[length]; + length = buffer.readUByte(); + definition.setOriginalColours(new short[length]); + definition.setReplacementColours(new short[length]); + + for (index = 0; index < length; ++index) { + definition.getOriginalColours()[index] = (short) buffer.readUShort(); + definition.getReplacementColours()[index] = (short) buffer.readUShort(); + } + + } else if (opcode == 41) { + length = buffer.readUByte(); + definition.setOriginalTextures(new short[length]); + definition.setReplacementTextures(new short[length]); - for (int index = 0; index < length; index++) { - originalColours[index] = buffer.getShort(); - replacementColours[index] = buffer.getShort(); + for (index = 0; index < length; ++index) { + definition.getOriginalTextures()[index] = (short) buffer.readUShort(); + definition.getReplacementTextures()[index] = (short) buffer.readUShort(); } + } else if (opcode == 60) { - int length = buffer.get() & 0xFF; - int[] additionalModels = new int[length]; + length = buffer.readUByte(); + definition.setHeadModels(new int[length]); - for (int index = 0; index < length; index++) { - additionalModels[index] = buffer.getShort(); + for (index = 0; index < length; ++index) { + definition.getHeadModels()[index] = buffer.readUShort(); } - } else if (opcode >= 90 && opcode <= 92) { - buffer.getShort(); // Dummy + + } else if (opcode == 93) { + definition.setDrawMapdot(false); } else if (opcode == 95) { - definition.setCombatLevel(buffer.getShort()); - } else if (opcode == 97 || opcode == 98) { - buffer.getShort(); - } else if (opcode == 100 || opcode == 101) { - buffer.get(); - } else if (opcode == 102 || opcode == 103) { - buffer.getShort(); + definition.setCombatLevel(buffer.readUShort()); + } else if (opcode == 97) { + definition.setScaleX(buffer.readUShort()); + } else if (opcode == 98) { + definition.setScaleY(buffer.readUShort()); + } else if (opcode == 99) { + definition.setPriority(true); + } else if (opcode == 100) { + definition.setAmbience(buffer.readByte()); + } else if (opcode == 101) { + definition.setContrast(buffer.readByte()); + } else if (opcode == 102) { + definition.setHeadIcon(buffer.readUShort()); + } else if (opcode == 103) { + definition.setRotation(buffer.readUShort()); } else if (opcode == 106) { - wrap(buffer.getShort()); - wrap(buffer.getShort()); + definition.setVarbit(buffer.readUShort()); + if ('\uffff' == definition.getVarbit()) { + definition.setVarbit(-1); + } - int count = buffer.get() & 0xFF; - int[] morphisms = new int[count + 1]; - Arrays.setAll(morphisms, index -> wrap(buffer.getShort())); + definition.setVarp(buffer.readUShort()); + if ('\uffff' == definition.getVarp()) { + definition.setVarp(-1); + } + + length = buffer.readUByte(); + definition.setMorphisms(new int[length + 2]); + + for (index = 0; index <= length; ++index) { + definition.getMorphisms()[index] = buffer.readUShort(); + if (definition.getMorphisms()[index] == 0xFFFF) { + definition.getMorphisms()[index] = -1; + } + } + + definition.getMorphisms()[length + 1] = -1; + + } else if (opcode == 107) { + definition.setClickable(false); + } else if (opcode == 109) { + definition.setSlowWalk(false); + } else if (opcode == 111) { + definition.setAnimateIdle(true); + } else if (opcode == 118) { + definition.setVarbit(buffer.readUShort()); + if ('\uffff' == definition.getVarbit()) { + definition.setVarbit(-1); + } + + definition.setVarp(buffer.readUShort()); + if ('\uffff' == definition.getVarp()) { + definition.setVarp(-1); + } + + int var = buffer.readUShort(); + if (var == 0xFFFF) { + var = -1; + } + + length = buffer.readUByte(); + definition.setMorphisms(new int[length + 2]); + + for (index = 0; index <= length; ++index) { + definition.getMorphisms()[index] = buffer.readUShort(); + if (definition.getMorphisms()[index] == '\uffff') { + definition.getMorphisms()[index] = -1; + } + } + + definition.getMorphisms()[length + 1] = var; + } else if (opcode == 249) { + length = buffer.readUByte(); + + definition.setParameters(new Int2ObjectArrayMap<>(length)); + + for (int i = 0; i < length; i++) { + boolean isString = buffer.readUByte() == 1; + int key = buffer.readUMedInt(); + Object value; + + if (isString) { + value = buffer.readString(); + } else { + value = buffer.readInt(); + } + + definition.getParameters().put(key, value); + } } } } diff --git a/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java index 3ffc797a9..8684efc83 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java @@ -1,14 +1,13 @@ package org.apollo.cache.decoder; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.ByteBuffer; - -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; -import org.apollo.cache.def.ItemDefinition; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.Archive; +import org.apollo.cache.RSFile; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.util.BufferUtil; + +import java.nio.ByteBuffer; /** * Decodes object data from the {@code loc.dat} file into {@link ObjectDefinition}s. @@ -20,123 +19,193 @@ public final class ObjectDefinitionDecoder implements Runnable { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fs; + private final Cache cache; /** * Creates the ObjectDefinitionDecoder. * - * @param fs The {@link IndexedFileSystem}. + * @param cache The {@link Archive}. */ - public ObjectDefinitionDecoder(IndexedFileSystem fs) { - this.fs = fs; + public ObjectDefinitionDecoder(Cache cache) { + this.cache = cache; } @Override public void run() { - try { - Archive config = fs.getArchive(0, 2); - ByteBuffer data = config.getEntry("loc.dat").getBuffer(); - ByteBuffer idx = config.getEntry("loc.idx").getBuffer(); - - int count = idx.getShort(), index = 2; - int[] indices = new int[count]; - for (int i = 0; i < count; i++) { - indices[i] = index; - index += idx.getShort(); - } - - ObjectDefinition[] definitions = new ObjectDefinition[count]; - for (int i = 0; i < count; i++) { - data.position(indices[i]); - definitions[i] = decode(i, data); - } - - ObjectDefinition.init(definitions); - } catch (IOException e) { - throw new UncheckedIOException("Error decoding ObjectDefinitions.", e); + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(6); + ObjectDefinition[] definitions = new ObjectDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); } + ObjectDefinition.init(definitions); } /** * Decodes data from the cache into an {@link ObjectDefinition}. * - * @param id The id of the object. - * @param data The {@link ByteBuffer} containing the data. + * @param id The id of the object. + * @param buffer The {@link ByteBuffer} containing the data. * @return The object definition. */ - private ObjectDefinition decode(int id, ByteBuffer data) { + private ObjectDefinition decode(int id, CacheBuffer buffer) { ObjectDefinition definition = new ObjectDefinition(id); - while (true) { - int opcode = data.get() & 0xFF; - + for (; ; ) { + final var opcode = buffer.readUByte(); if (opcode == 0) { return definition; } else if (opcode == 1) { - int amount = data.get() & 0xFF; - for (int i = 0; i < amount; i++) { - data.getShort(); - data.get(); + int count = buffer.readUByte(); + if (count > 0) { + definition.setTypes(new int[count]); + definition.setModels(new int[count][1]); + for (int index = 0; index < count; index++) { + definition.getModels()[index][0] = buffer.readUShort(); + definition.getTypes()[index] = buffer.readUByte(); + } } } else if (opcode == 2) { - definition.setName(BufferUtil.readString(data)); - } else if (opcode == 3) { - definition.setDescription(BufferUtil.readString(data)); + definition.setName(buffer.readString()); } else if (opcode == 5) { - int amount = data.get() & 0xFF; - for (int i = 0; i < amount; i++) { - data.getShort(); + int count = buffer.readUByte(); + if (count > 0) { + definition.setTypes(null); + definition.setModels(new int[count][1]); + for (int index = 0; index < count; index++) + definition.getModels()[index][0] = buffer.readUShort(); } } else if (opcode == 14) { - definition.setWidth(data.get() & 0xFF); + definition.setWidth(buffer.readUByte()); } else if (opcode == 15) { - definition.setLength(data.get() & 0xFF); + definition.setLength(buffer.readUByte()); } else if (opcode == 17) { definition.setSolid(false); } else if (opcode == 18) { definition.setImpenetrable(false); } else if (opcode == 19) { - definition.setInteractive((data.get() & 0xFF) == 1); + definition.setInteractive(buffer.readUByte() == 1); + } else if (opcode == 21) { + definition.setAdjustValue(0); + } else if (opcode == 22) { + definition.setDynamicShading(true); + } else if (opcode == 23) { + definition.setOccludes((byte) 1); } else if (opcode == 24) { - data.getShort(); - } else if (opcode == 28 || opcode == 29) { - data.get(); - } else if (opcode >= 30 && opcode < 39) { + definition.setAnimations(new int[]{buffer.readUShort()}); + if (definition.getAnimations()[0] == 65535) { + definition.getAnimations()[0] = -1; + } + } else if (opcode == 27) { + definition.setCollisionType(1); + } else if (opcode == 28) { + definition.setDecorationDisplacement(buffer.readUByte()); + } else if (opcode == 29) { + definition.setContrast(buffer.readSignedByte()); + } else if (opcode == 39) { + definition.setAmbience(buffer.readSignedByte()); + } else if (opcode >= 30 && opcode < 35) { String[] actions = definition.getMenuActions(); if (actions == null) { actions = new String[10]; } - String action = BufferUtil.readString(data); - actions[opcode - 30] = action; + actions[opcode - 30] = buffer.readString(); definition.setMenuActions(actions); - } else if (opcode == 39) { - data.get(); } else if (opcode == 40) { - int amount = data.get() & 0xFF; - for (int i = 0; i < amount; i++) { - data.getShort(); - data.getShort(); + final int count = buffer.readUByte(); + definition.setOriginalColours(new short[count]); + definition.setReplacementColours(new short[count]); + for (int i = 0; i < count; i++) { + definition.getOriginalColours()[i] = (short) buffer.readUShort(); + definition.getReplacementColours()[i] = (short) buffer.readUShort(); + } + } else if (opcode == 41) { + final int count = buffer.readUByte(); + definition.setOriginalTextures(new short[count]); + definition.setReplacementTextures(new short[count]); + for (int i_7_ = 0; i_7_ < count; i_7_++) { + definition.getOriginalTextures()[i_7_] = (short) buffer.readUShort(); + definition.getReplacementTextures()[i_7_] = (short) buffer.readUShort(); } - } else if (opcode == 60 || opcode >= 65 && opcode <= 68) { - data.getShort(); + } else if (opcode == 62) { + definition.setMirrorModel(true); + } else if (opcode == 64) { + definition.setCastsShadow(false); + } else if (opcode == 65) { + definition.setScaleX(buffer.readUShort()); + } else if (opcode == 66) { + definition.setScaleY(buffer.readUShort()); + } else if (opcode == 67) { + definition.setScaleZ(buffer.readUShort()); + } else if (opcode == 68) { + definition.setMapscene(buffer.readUShort()); } else if (opcode == 69) { - data.get(); - } else if (opcode >= 70 && opcode <= 72) { - data.getShort(); + definition.setRotationFlag(buffer.readUByte()); + } else if (opcode == 70) { + definition.setTranslateX((buffer.readSignedShort())); + } else if (opcode == 71) { + definition.setTranslateY((buffer.readSignedShort())); + } else if (opcode == 72) { + definition.setTranslateZ((buffer.readSignedShort())); } else if (opcode == 73) { + definition.setDecoration(true); + } else if (opcode == 74) { definition.setObstructive(true); } else if (opcode == 75) { - data.get(); - } else if (opcode == 77) { - data.getShort(); - data.getShort(); - int count = data.get(); - for (int i = 0; i <= count; i++) { - data.getShort(); + definition.setHoldsItemPiles(buffer.readUByte()); + } else if (opcode == 77 || opcode == 92) { + definition.setVarbit(buffer.readUShort()); + if (65535 == definition.getVarbit()) { + definition.setVarbit(-1); + } + definition.setVarp(buffer.readUShort()); + if (65535 == definition.getVarp()) { + definition.setVarp(-1); + } + + int model = -1; + if (opcode == 92) { + model = buffer.readSmart32(); + } + + int length = buffer.readUByte(); + definition.setMorphisms(new int[length + 2]); + + for (int index = 0; index <= length; index++) { + definition.getMorphisms()[index] = buffer.readSmart32(); + } + + definition.getMorphisms()[1 + length] = model; + } else if (opcode == 78) { + definition.setF2117(buffer.readUShort()); + definition.setF2118(buffer.readUByte()); + } else if (opcode == 79) { + definition.setF2119(buffer.readUShort()); + definition.setF2120(buffer.readUShort()); + definition.setF2118(buffer.readUByte()); + final int count = buffer.readUByte(); + definition.setF2121(new int[count]); + for (int i = 0; i < count; i++) + definition.getF2121()[i] = buffer.readUShort(); + } else if (opcode == 81) { + definition.setAdjustValue(buffer.readUByte() * 256); + } else if (opcode == 82) { + definition.setMapSceneType(buffer.readUShort()); + } else if (opcode == 249) { + final int size = buffer.readUByte(); + definition.setParameters(new Int2ObjectArrayMap<>(size)); + + for (int index = 0; size > index; index++) { + final boolean stringInstance = buffer.readUByte() == 1; + final int key = buffer.readUMedInt(); + final Object value; + if (stringInstance) { + value = buffer.readString(); + } else { + value = buffer.readInt(); + } + definition.getParameters().put(key, value); } - } else { - continue; } } } - } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java b/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java index 9c678f1dc..8140c580d 100644 --- a/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java @@ -3,6 +3,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; /** * Represents a type of Item. @@ -54,12 +55,20 @@ public static void init(ItemDefinition[] definitions) { ItemDefinition.definitions = definitions; for (int id = 0; id < definitions.length; id++) { ItemDefinition def = definitions[id]; + if (def == null) { + ItemDefinition.definitions[id] = def = new ItemDefinition(id); + } + if (def.getId() != id) { throw new RuntimeException("Item definition id mismatch."); } if (def.isNote()) { - def.toNote(); + def.generate(ItemGenerationType.NOTE, ItemDefinition.lookup(def.getNoteInfoId()), + ItemDefinition.lookup(def.getNoteGraphicId())); notes.put(def.getNoteInfoId(), def.getId()); + } else if (def.isLoaner()) { + def.generate(ItemGenerationType.LOAN, ItemDefinition.lookup(def.getLoanInfo()), + ItemDefinition.lookup(def.getLoanGraphicId())); } } } @@ -159,6 +168,45 @@ public static int noteToItem(int id) { */ private int value = 1; + private int baseModel; + private int modelScale; + private int modelPitch; + private int modelRoll; + private int modelTranslateX; + private int modelTranslateY; + private int stackType; + private int primaryMaleModel; + private int maleYOffset; + private int secondaryMaleModel; + private int primaryFemaleModel; + private int femaleYOffset; + private int secondaryFemaleModel; + private short[] originalModelColors; + private short[] modifiedModelColors; + private short[] modifiedTextureColors; + private short[] originalTextureColors; + private boolean nonExchangeItem; + private int tertiaryMaleModel; + private int tertiaryFemaleModel; + private int maleHead; + private int femaleHead; + private int secondaryMaleHead; + private int secondaryFemaleHead; + private int modelYaw; + private int[] stackIds; + private int[] stackAmounts; + private int scaleX; + private int scaleY; + private int scaleZ; + private int shiftClickDropIndex; + private byte ambience; + private byte contrast; + private int loanInfo = -1; + private int loanGraphicId = -1; + private int placeHolderInfo; + private int placeHolderTemplate; + private Int2ObjectArrayMap parameters; + /** * Creates an item definition with the default values. * @@ -168,6 +216,7 @@ public ItemDefinition(int id) { this.id = id; } + /** * Gets the description of this item. * @@ -210,6 +259,158 @@ public String getInventoryAction(int id) { return inventoryActions[id]; } + public int getBaseModel() { + return baseModel; + } + + public int getModelScale() { + return modelScale; + } + + public int getModelPitch() { + return modelPitch; + } + + public int getModelRoll() { + return modelRoll; + } + + public int getModelTranslateX() { + return modelTranslateX; + } + + public int getModelTranslateY() { + return modelTranslateY; + } + + public int getStackType() { + return stackType; + } + + public int getPrimaryMaleModel() { + return primaryMaleModel; + } + + public int getMaleYOffset() { + return maleYOffset; + } + + public int getSecondaryMaleModel() { + return secondaryMaleModel; + } + + public int getPrimaryFemaleModel() { + return primaryFemaleModel; + } + + public int getFemaleYOffset() { + return femaleYOffset; + } + + public int getSecondaryFemaleModel() { + return secondaryFemaleModel; + } + + public short[] getOriginalModelColors() { + return originalModelColors; + } + + public short[] getModifiedModelColors() { + return modifiedModelColors; + } + + public short[] getModifiedTextureColors() { + return modifiedTextureColors; + } + + public short[] getOriginalTextureColors() { + return originalTextureColors; + } + + public boolean isNonExchangeItem() { + return nonExchangeItem; + } + + public int getTertiaryMaleModel() { + return tertiaryMaleModel; + } + + public int getTertiaryFemaleModel() { + return tertiaryFemaleModel; + } + + public int getMaleHead() { + return maleHead; + } + + public int getFemaleHead() { + return femaleHead; + } + + public int getSecondaryMaleHead() { + return secondaryMaleHead; + } + + public int getSecondaryFemaleHead() { + return secondaryFemaleHead; + } + + public int getModelYaw() { + return modelYaw; + } + + public int[] getStackIds() { + return stackIds; + } + + public int[] getStackAmounts() { + return stackAmounts; + } + + public int getScaleX() { + return scaleX; + } + + public int getScaleY() { + return scaleY; + } + + public int getScaleZ() { + return scaleZ; + } + + public int getShiftClickDropIndex() { + return shiftClickDropIndex; + } + + public byte getAmbience() { + return ambience; + } + + public byte getContrast() { + return contrast; + } + + public int getLoanInfo() { + return loanInfo; + } + + public int getLoanGraphicId() { + return loanGraphicId; + } + + public int getPlaceHolderInfo() { + return placeHolderInfo; + } + + public int getPlaceHolderTemplate() { + return placeHolderTemplate; + } + + public Int2ObjectArrayMap getParameters() { + return parameters; + } + /** * Gets this item's name. * @@ -273,6 +474,15 @@ public boolean isNote() { return noteGraphicId != -1 && noteInfoId != -1; } + /** + * Checks if this item is loaned. + * + * @return {@code true} if so, {@code false} otherwise. + */ + public boolean isLoaner() { + return loanInfo != -1 && loanGraphicId != -1; + } + /** * Checks if the item specified by this definition is stackable. * @@ -294,7 +504,7 @@ public void setDescription(String description) { /** * Sets a ground action. * - * @param id The id. + * @param id The id. * @param action The action. * @throws IndexOutOfBoundsException If the id is out of bounds. */ @@ -306,7 +516,7 @@ public void setGroundAction(int id, String action) { /** * Sets an inventory action. * - * @param id The id. + * @param id The id. * @param action The action. * @throws IndexOutOfBoundsException If the id is out of bounds. */ @@ -378,21 +588,180 @@ public void setValue(int value) { this.value = value; } - /** - * Converts this item to a note, if possible. - * - * @throws IllegalStateException If {@link ItemDefinition#isNote()} returns {@code false}. - */ - public void toNote() { - if (isNote()) { - if (description != null && description.startsWith("Swap this note at any bank for ")) { - return; // already converted. - } + public void setBaseModel(int baseModel) { + this.baseModel = baseModel; + } + + public void setModelScale(int modelScale) { + this.modelScale = modelScale; + } + + public void setModelPitch(int modelPitch) { + this.modelPitch = modelPitch; + } + + public void setModelRoll(int modelRoll) { + this.modelRoll = modelRoll; + } + + public void setModelTranslateX(int modelTranslateX) { + this.modelTranslateX = modelTranslateX; + } + + public void setModelTranslateY(int modelTranslateY) { + this.modelTranslateY = modelTranslateY; + } + + public void setStackType(int stackType) { + this.stackType = stackType; + } + + public void setPrimaryMaleModel(int primaryMaleModel) { + this.primaryMaleModel = primaryMaleModel; + } + + public void setMaleYOffset(int maleYOffset) { + this.maleYOffset = maleYOffset; + } + + public void setSecondaryMaleModel(int secondaryMaleModel) { + this.secondaryMaleModel = secondaryMaleModel; + } + + public void setPrimaryFemaleModel(int primaryFemaleModel) { + this.primaryFemaleModel = primaryFemaleModel; + } + + public void setFemaleYOffset(int femaleYOffset) { + this.femaleYOffset = femaleYOffset; + } + + public void setSecondaryFemaleModel(int secondaryFemaleModel) { + this.secondaryFemaleModel = secondaryFemaleModel; + } + + public void setOriginalModelColors(short[] originalModelColors) { + this.originalModelColors = originalModelColors; + } + + public void setModifiedModelColors(short[] modifiedModelColors) { + this.modifiedModelColors = modifiedModelColors; + } + + public void setModifiedTextureColors(short[] modifiedTextureColors) { + this.modifiedTextureColors = modifiedTextureColors; + } + + public void setOriginalTextureColors(short[] originalTextureColors) { + this.originalTextureColors = originalTextureColors; + } + + public void setNonExchangeItem(boolean nonExchangeItem) { + this.nonExchangeItem = nonExchangeItem; + } - ItemDefinition infoDef = lookup(noteInfoId); - name = infoDef.name; - members = infoDef.members; + public void setTertiaryMaleModel(int tertiaryMaleModel) { + this.tertiaryMaleModel = tertiaryMaleModel; + } + + public void setTertiaryFemaleModel(int tertiaryFemaleModel) { + this.tertiaryFemaleModel = tertiaryFemaleModel; + } + + public void setMaleHead(int maleHead) { + this.maleHead = maleHead; + } + + public void setFemaleHead(int femaleHead) { + this.femaleHead = femaleHead; + } + + public void setSecondaryMaleHead(int secondaryMaleHead) { + this.secondaryMaleHead = secondaryMaleHead; + } + + public void setSecondaryFemaleHead(int secondaryFemaleHead) { + this.secondaryFemaleHead = secondaryFemaleHead; + } + + public void setModelYaw(int modelYaw) { + this.modelYaw = modelYaw; + } + + public void setStackIds(int[] stackIds) { + this.stackIds = stackIds; + } + + public void setStackAmounts(int[] stackAmounts) { + this.stackAmounts = stackAmounts; + } + + public void setScaleX(int scaleX) { + this.scaleX = scaleX; + } + + public void setScaleY(int scaleY) { + this.scaleY = scaleY; + } + public void setScaleZ(int scaleZ) { + this.scaleZ = scaleZ; + } + + public void setShiftClickDropIndex(int shiftClickDropIndex) { + this.shiftClickDropIndex = shiftClickDropIndex; + } + + public void setAmbience(byte ambience) { + this.ambience = ambience; + } + + public void setContrast(byte contrast) { + this.contrast = contrast; + } + + public void setLoanInfo(int loanInfo) { + this.loanInfo = loanInfo; + } + + public void setLoanGraphicId(int loanGraphicId) { + this.loanGraphicId = loanGraphicId; + } + + public void setPlaceHolderInfo(int placeHolderInfo) { + this.placeHolderInfo = placeHolderInfo; + } + + public void setPlaceHolderTemplate(int placeHolderTemplate) { + this.placeHolderTemplate = placeHolderTemplate; + } + + public void setParameters(Int2ObjectArrayMap parameters) { + this.parameters = parameters; + } + + public enum ItemGenerationType { + NOTE, LOAN, BOUGHT, COMBINE + } + + void generate(ItemGenerationType type, ItemDefinition template, ItemDefinition info) { + baseModel = template.baseModel; + modelScale = template.modelScale; + modelPitch = template.modelPitch; + modelRoll = template.modelRoll; + modelYaw = template.modelYaw; + modelTranslateX = template.modelTranslateX; + modelTranslateY = template.modelTranslateY; + + ItemDefinition replacements = (type == ItemGenerationType.NOTE) ? template : info; + originalModelColors = replacements.originalModelColors; + modifiedModelColors = replacements.modifiedModelColors; + originalTextureColors = replacements.originalTextureColors; + modifiedTextureColors = replacements.modifiedTextureColors; + + name = info.name; + members = info.members; + if (type == ItemGenerationType.NOTE) { String prefix = "a"; char firstChar = name == null ? 'n' : name.charAt(0); @@ -400,12 +769,28 @@ public void toNote() { prefix = "an"; } + value = info.value; + stackType = 1; description = "Swap this note at any bank for " + prefix + " " + name + "."; - value = infoDef.value; - stackable = true; } else { - throw new IllegalStateException("Item cannot be noted."); + value = 0; + stackType = info.stackType; + primaryMaleModel = info.primaryMaleModel; + secondaryMaleModel = info.secondaryMaleModel; + tertiaryMaleModel = info.tertiaryMaleModel; + primaryFemaleModel = info.primaryFemaleModel; + secondaryFemaleModel = info.secondaryFemaleModel; + tertiaryFemaleModel = info.tertiaryFemaleModel; + maleHead = info.maleHead; + secondaryMaleHead = info.secondaryMaleHead; + femaleHead = info.femaleHead; + secondaryFemaleHead = info.secondaryFemaleHead; + team = info.team; + System.arraycopy(info.groundActions, 0, groundActions, 0, groundActions.length); + System.arraycopy(info.inventoryActions, 0, inventoryActions, 0, 4); + parameters = info.parameters; + inventoryActions[4] = "Discard"; + value = 0; } } - } diff --git a/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java b/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java index 0e81396de..a01010b2f 100644 --- a/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java @@ -1,6 +1,7 @@ package org.apollo.cache.def; import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; /** * Represents a type of Npc. @@ -94,6 +95,30 @@ public static NpcDefinition lookup(int id) { * The various animation ids. */ private int standAnim = -1, walkAnim = -1, walkBackAnim = -1, walkLeftAnim = -1, walkRightAnim = -1; + private int turnLeftSequence = -1; + private int turnRightSequence = -1; + + private short[] originalColours; + private int rotation; + private short[] replacementColours; + private int[] models; + private int[] headModels; + private short[] replacementTextures; + private boolean slowWalk; + private int scaleX; + private int contrast; + private int varbit; + private boolean drawMapdot; + private int scaleY; + private boolean priority; + private int ambience; + private int headIcon; + private int[] morphisms; + private short[] originalTextures; + private int varp; + private boolean isClickable; + private boolean animateIdle; + private Int2ObjectArrayMap parameters; /** * Creates a new npc definition. @@ -302,7 +327,7 @@ public void setDescription(String description) { /** * Sets an interaction option. * - * @param slot The slot of the option. + * @param slot The slot of the option. * @param interaction The interaction options. * @throws IndexOutOfBoundsException If the slot is out of bounds. */ @@ -350,9 +375,9 @@ public void setWalkAnimation(int walkAnim) { /** * Sets the various walking animations of the npc. * - * @param walkAnim The walking animation. - * @param walkBackAnim The walk-back animation. - * @param walkLeftAnim The walk-left animation. + * @param walkAnim The walking animation. + * @param walkBackAnim The walk-back animation. + * @param walkLeftAnim The walk-left animation. * @param walkRightAnim The walk-right animation. */ public void setWalkAnimations(int walkAnim, int walkBackAnim, int walkLeftAnim, int walkRightAnim) { @@ -362,4 +387,187 @@ public void setWalkAnimations(int walkAnim, int walkBackAnim, int walkLeftAnim, this.walkRightAnim = walkRightAnim; } + public int getTurnLeftSequence() { + return turnLeftSequence; + } + + public void setTurnLeftSequence(int turnLeftSequence) { + this.turnLeftSequence = turnLeftSequence; + } + + public int getTurnRightSequence() { + return turnRightSequence; + } + + public void setTurnRightSequence(int turnRightSequence) { + this.turnRightSequence = turnRightSequence; + } + + public short[] getOriginalColours() { + return originalColours; + } + + public void setOriginalColours(short[] originalColours) { + this.originalColours = originalColours; + } + + public int getRotation() { + return rotation; + } + + public void setRotation(int rotation) { + this.rotation = rotation; + } + + public short[] getReplacementColours() { + return replacementColours; + } + + public void setReplacementColours(short[] replacementColours) { + this.replacementColours = replacementColours; + } + + public int[] getModels() { + return models; + } + + public void setModels(int[] models) { + this.models = models; + } + + public int[] getHeadModels() { + return headModels; + } + + public void setHeadModels(int[] headModels) { + this.headModels = headModels; + } + + public short[] getReplacementTextures() { + return replacementTextures; + } + + public void setReplacementTextures(short[] replacementTextures) { + this.replacementTextures = replacementTextures; + } + + public boolean isSlowWalk() { + return slowWalk; + } + + public void setSlowWalk(boolean slowWalk) { + this.slowWalk = slowWalk; + } + + public int getScaleX() { + return scaleX; + } + + public void setScaleX(int scaleX) { + this.scaleX = scaleX; + } + + public int getContrast() { + return contrast; + } + + public void setContrast(int contrast) { + this.contrast = contrast; + } + + public int getVarbit() { + return varbit; + } + + public void setVarbit(int varbit) { + this.varbit = varbit; + } + + public boolean isDrawMapdot() { + return drawMapdot; + } + + public void setDrawMapdot(boolean drawMapdot) { + this.drawMapdot = drawMapdot; + } + + public int getScaleY() { + return scaleY; + } + + public void setScaleY(int scaleY) { + this.scaleY = scaleY; + } + + public boolean isPriority() { + return priority; + } + + public void setPriority(boolean priority) { + this.priority = priority; + } + + public int getAmbience() { + return ambience; + } + + public void setAmbience(int ambience) { + this.ambience = ambience; + } + + public int getHeadIcon() { + return headIcon; + } + + public void setHeadIcon(int headIcon) { + this.headIcon = headIcon; + } + + public int[] getMorphisms() { + return morphisms; + } + + public void setMorphisms(int[] morphisms) { + this.morphisms = morphisms; + } + + public short[] getOriginalTextures() { + return originalTextures; + } + + public void setOriginalTextures(short[] originalTextures) { + this.originalTextures = originalTextures; + } + + public int getVarp() { + return varp; + } + + public void setVarp(int varp) { + this.varp = varp; + } + + public boolean isClickable() { + return isClickable; + } + + public void setClickable(boolean clickable) { + isClickable = clickable; + } + + public boolean isAnimateIdle() { + return animateIdle; + } + + public void setAnimateIdle(boolean animateIdle) { + this.animateIdle = animateIdle; + } + + public Int2ObjectArrayMap getParameters() { + return parameters; + } + + public void setParameters(Int2ObjectArrayMap parameters) { + this.parameters = parameters; + } } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java b/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java index 8f0543076..0738b967c 100644 --- a/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java @@ -1,6 +1,7 @@ package org.apollo.cache.def; import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; /** * Represents a type of GameObject. @@ -110,6 +111,45 @@ public static ObjectDefinition lookup(int id) { */ private int width = 1; + private int[] types; + private int[][] models; + private int height; + private int collisionType; + private int adjustValue; + private boolean dynamicShading; + private byte occludes; + private int decorationDisplacement; + private int contrast; + private int ambience; + private short[] originalColours; + private short[] replacementColours; + private short[] originalTextures; + private short[] replacementTextures; + private boolean mirrorModel; + private boolean castsShadow; + private int scaleX; + private int scaleY; + private int scaleZ; + private int mapscene; + private int rotationFlag; + private int translateX; + private int translateY; + private int translateZ; + private boolean decoration; + private int holdsItemPiles; + private int varbit; + private int varp; + private int[] morphisms; + private int f2117; + private int f2118; + private int f2119; + private int f2120; + private int[] f2121; + private boolean members; + private int mapSceneType; + private int[] animations; + private Int2ObjectMap parameters; + /** * Creates a new object definition. * @@ -290,4 +330,307 @@ public void setObstructive(boolean obstructive) { this.obstructive = obstructive; } + public int[] getTypes() { + return types; + } + + public void setTypes(int[] types) { + this.types = types; + } + + public int[][] getModels() { + return models; + } + + public void setModels(int[][] models) { + this.models = models; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getCollisionType() { + return collisionType; + } + + public void setCollisionType(int collisionType) { + this.collisionType = collisionType; + } + + public int getAdjustValue() { + return adjustValue; + } + + public void setAdjustValue(int adjustValue) { + this.adjustValue = adjustValue; + } + + public boolean isDynamicShading() { + return dynamicShading; + } + + public void setDynamicShading(boolean dynamicShading) { + this.dynamicShading = dynamicShading; + } + + public byte getOccludes() { + return occludes; + } + + public void setOccludes(byte occludes) { + this.occludes = occludes; + } + + public int getDecorationDisplacement() { + return decorationDisplacement; + } + + public void setDecorationDisplacement(int decorationDisplacement) { + this.decorationDisplacement = decorationDisplacement; + } + + public int getContrast() { + return contrast; + } + + public void setContrast(int contrast) { + this.contrast = contrast; + } + + public int getAmbience() { + return ambience; + } + + public void setAmbience(int ambience) { + this.ambience = ambience; + } + + public short[] getOriginalColours() { + return originalColours; + } + + public void setOriginalColours(short[] originalColours) { + this.originalColours = originalColours; + } + + public short[] getReplacementColours() { + return replacementColours; + } + + public void setReplacementColours(short[] replacementColours) { + this.replacementColours = replacementColours; + } + + public short[] getOriginalTextures() { + return originalTextures; + } + + public void setOriginalTextures(short[] originalTextures) { + this.originalTextures = originalTextures; + } + + public short[] getReplacementTextures() { + return replacementTextures; + } + + public void setReplacementTextures(short[] replacementTextures) { + this.replacementTextures = replacementTextures; + } + + public boolean isMirrorModel() { + return mirrorModel; + } + + public void setMirrorModel(boolean mirrorModel) { + this.mirrorModel = mirrorModel; + } + + public boolean isCastsShadow() { + return castsShadow; + } + + public void setCastsShadow(boolean castsShadow) { + this.castsShadow = castsShadow; + } + + public int getScaleX() { + return scaleX; + } + + public void setScaleX(int scaleX) { + this.scaleX = scaleX; + } + + public int getScaleY() { + return scaleY; + } + + public void setScaleY(int scaleY) { + this.scaleY = scaleY; + } + + public int getScaleZ() { + return scaleZ; + } + + public void setScaleZ(int scaleZ) { + this.scaleZ = scaleZ; + } + + public int getMapscene() { + return mapscene; + } + + public void setMapscene(int mapscene) { + this.mapscene = mapscene; + } + + public int getRotationFlag() { + return rotationFlag; + } + + public void setRotationFlag(int rotationFlag) { + this.rotationFlag = rotationFlag; + } + + public int getTranslateX() { + return translateX; + } + + public void setTranslateX(int translateX) { + this.translateX = translateX; + } + + public int getTranslateY() { + return translateY; + } + + public void setTranslateY(int translateY) { + this.translateY = translateY; + } + + public int getTranslateZ() { + return translateZ; + } + + public void setTranslateZ(int translateZ) { + this.translateZ = translateZ; + } + + public boolean isDecoration() { + return decoration; + } + + public void setDecoration(boolean decoration) { + this.decoration = decoration; + } + + public int getHoldsItemPiles() { + return holdsItemPiles; + } + + public void setHoldsItemPiles(int holdsItemPiles) { + this.holdsItemPiles = holdsItemPiles; + } + + public int getVarbit() { + return varbit; + } + + public void setVarbit(int varbit) { + this.varbit = varbit; + } + + public int getVarp() { + return varp; + } + + public void setVarp(int varp) { + this.varp = varp; + } + + public int[] getMorphisms() { + return morphisms; + } + + public void setMorphisms(int[] morphisms) { + this.morphisms = morphisms; + } + + public int getF2117() { + return f2117; + } + + public void setF2117(int f2117) { + this.f2117 = f2117; + } + + public int getF2118() { + return f2118; + } + + public void setF2118(int f2118) { + this.f2118 = f2118; + } + + public int getF2119() { + return f2119; + } + + public void setF2119(int f2119) { + this.f2119 = f2119; + } + + public int getF2120() { + return f2120; + } + + public void setF2120(int f2120) { + this.f2120 = f2120; + } + + public int[] getF2121() { + return f2121; + } + + public void setF2121(int[] f2121) { + this.f2121 = f2121; + } + + public boolean isMembers() { + return members; + } + + public void setMembers(boolean members) { + this.members = members; + } + + public int getMapSceneType() { + return mapSceneType; + } + + public void setMapSceneType(int mapSceneType) { + this.mapSceneType = mapSceneType; + } + + public int[] getAnimations() { + return animations; + } + + public void setAnimations(int[] animations) { + this.animations = animations; + } + + public Int2ObjectMap getParameters() { + return parameters; + } + + public void setParameters(Int2ObjectMap parameters) { + this.parameters = parameters; + } } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/map/MapConstants.java b/cache/src/main/java/org/apollo/cache/map/MapConstants.java index 634929787..cc0e1f047 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapConstants.java +++ b/cache/src/main/java/org/apollo/cache/map/MapConstants.java @@ -10,7 +10,7 @@ public final class MapConstants { /** * The index containing the map files. */ - public static final int MAP_INDEX = 4; + public static final int MAP_INDEX = 5; /** * The width (and length) of a {@link MapFile} in {@link Tile}s. diff --git a/cache/src/main/java/org/apollo/cache/map/MapIndex.java b/cache/src/main/java/org/apollo/cache/map/MapIndex.java index 9b707c85c..f5e3fe0e6 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapIndex.java +++ b/cache/src/main/java/org/apollo/cache/map/MapIndex.java @@ -1,9 +1,9 @@ package org.apollo.cache.map; -import org.apollo.cache.def.ItemDefinition; +import org.apollo.cache.Group; +import java.lang.ref.WeakReference; import java.util.Collections; -import java.util.HashMap; import java.util.Map; /** @@ -11,115 +11,114 @@ */ public final class MapIndex { - /** - * Indicates whether or not this map is members-only. - */ - private final boolean members; - - /** - * The object file id. - */ - private final int objects; - - /** - * The packed coordinates. - */ - private final int packedCoordinates; - - /** - * The terrain file id. - */ - private final int terrain; - - /** - * A mapping of region ids to {@link MapIndex}es. - */ - private static Map indices; - - /** - * Initialises the class with the specified set of indices. - */ - public static void init(Map indices) { - MapIndex.indices = Collections.unmodifiableMap(indices); - } - - /** - * Gets the {@code Map} of {@link MapIndex} instances. - * - * @return The map of {@link MapIndex} instances. - */ - public static Map getIndices() { - return indices; - } - - /** - * Creates the {@link MapIndex}. - * - * @param packedCoordinates The packed coordinates. - * @param terrain The terrain file id. - * @param objects The object file id. - * @param members Indicates whether or not this map is members-only. - */ - public MapIndex(int packedCoordinates, int terrain, int objects, boolean members) { - this.packedCoordinates = packedCoordinates; - this.terrain = terrain; - this.objects = objects; - this.members = members; - } - - /** - * Gets the id of the file containing the object data. - * - * @return The file id. - */ - public int getObjectFile() { - return objects; - } - - /** - * Gets the packed coordinates. - * - * @return The packed coordinates. - */ - public int getPackedCoordinates() { - return packedCoordinates; - } - - /** - * Gets the id of the file containing the terrain data. - * - * @return The file id. - */ - public int getMapFile() { - return terrain; - } - - /** - * Gets the X coordinate of this map. - * - * @return The X coordinate of this map. - */ - public int getX() { - return (packedCoordinates >> 8 & 0xFF) * MapConstants.MAP_WIDTH; - } - - /** - * Gets the Y coordinate of this map. - * - * @return The y coordinate of this map. - */ - public int getY() { - return (packedCoordinates & 0xFF) * MapConstants.MAP_WIDTH; - - } - - /** - * Returns whether or not this MapIndex is for a members-only area of the world. - * - * @return {@code true} if this MapIndex is for a members-only area, {@code false} if not. - */ - public boolean isMembersOnly() { - return members; - } + /** + * Indicates whether or not this map is members-only. + */ + private final boolean members; + + /** + * The object file id. + */ + private final WeakReference landscapeFolder; + + /** + * The packed coordinates. + */ + private final int packedCoordinates; + + /** + * The terrain file id. + */ + private final WeakReference terrainFolder; + + /** + * A mapping of region ids to {@link MapIndex}es. + */ + private static Map indices; + + /** + * Initialises the class with the specified set of indices. + */ + public static void init(Map indices) { + MapIndex.indices = Collections.unmodifiableMap(indices); + } + + /** + * Gets the {@code Map} of {@link MapIndex} instances. + * + * @return The map of {@link MapIndex} instances. + */ + public static Map getIndices() { + return indices; + } + + /** + * Creates the {@link MapIndex}. + * @param packedCoordinates The packed coordinates. + * @param terrainGroup The terrain file id. + * @param landscapeGroup The object file id. + * @param members Indicates whether or not this map is members-only. + */ + public MapIndex(int packedCoordinates, Group terrainGroup, Group landscapeGroup, boolean members) { + this.packedCoordinates = packedCoordinates; + this.terrainFolder = new WeakReference<>(terrainGroup); + this.landscapeFolder = new WeakReference<>(landscapeGroup); + this.members = members; + } + + /** + * Gets the id of the file containing the object data. + * + * @return The file id. + */ + public WeakReference getLandscapeFolder() { + return landscapeFolder; + } + + /** + * Gets the packed coordinates. + * + * @return The packed coordinates. + */ + public int getPackedCoordinates() { + return packedCoordinates; + } + + /** + * Gets the id of the file containing the terrain data. + * + * @return The file id. + */ + public WeakReference getTerrainFolder() { + return terrainFolder; + } + + /** + * Gets the X coordinate of this map. + * + * @return The X coordinate of this map. + */ + public int getX() { + return (packedCoordinates >> 8 & 0xFF) * MapConstants.MAP_WIDTH; + } + + /** + * Gets the Y coordinate of this map. + * + * @return The y coordinate of this map. + */ + public int getY() { + return (packedCoordinates & 0xFF) * MapConstants.MAP_WIDTH; + + } + + /** + * Returns whether or not this MapIndex is for a members-only area of the world. + * + * @return {@code true} if this MapIndex is for a members-only area, {@code false} if not. + */ + public boolean isMembersOnly() { + return members; + } } diff --git a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java index 7bca2addc..ba33e0907 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java @@ -1,18 +1,15 @@ package org.apollo.cache.map; +import org.apollo.cache.Cache; +import org.apollo.cache.Archive; + import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; -import org.apollo.cache.archive.ArchiveEntry; -import org.apollo.cache.map.MapIndex; - /** - * Decodes {@link MapIndex}s from the {@link IndexedFileSystem}. + * Decodes {@link MapIndex}s from the {@link Archive}. * * @author Ryley * @author Major @@ -25,35 +22,42 @@ public final class MapIndexDecoder implements Runnable { private static final int VERSIONS_ARCHIVE_FILE_ID = 5; /** - * The IndexedFileSystem. + * The Cache. */ - private final IndexedFileSystem fs; + private final Cache cache; + private final XteaDecoder xteaDecoder; - public MapIndexDecoder(IndexedFileSystem fs) { - this.fs = fs; + public MapIndexDecoder(Cache cache, XteaDecoder xteaDecoder) { + this.cache = cache; + this.xteaDecoder = xteaDecoder; } /** - * Decodes {@link MapIndex}s from the specified {@link IndexedFileSystem}. + * Decodes {@link MapIndex}s from the specified {@link Archive}. * * @return A {@link Map} of packed coordinates to their MapDefinitions. * @throws IOException If there is an error reading or decoding the Archive. */ public Map decode() throws IOException { - Archive archive = fs.getArchive(0, VERSIONS_ARCHIVE_FILE_ID); - ArchiveEntry entry = archive.getEntry("map_index"); Map definitions = new HashMap<>(); - ByteBuffer buffer = entry.getBuffer(); - int count = buffer.capacity() / (3 * Short.BYTES + Byte.BYTES); + final var fs = cache.getArchive(MapConstants.MAP_INDEX); + for (var entry : xteaDecoder.getAll()) { + final var region = entry.getIntKey(); + final var regionX = region >> 8; + final var regionY = region & 0xFF; + + try { + final var terrainFolder = fs.findFolderByName("m" + regionX + "_" + regionY); + final var landscapeFolder = fs.findFolderByName("l" + regionX + "_" + regionY, entry.getValue()); + if (landscapeFolder == null) { + continue; + } - for (int times = 0; times < count; times++) { - int id = buffer.getShort() & 0xFFFF; - int terrain = buffer.getShort() & 0xFFFF; - int objects = buffer.getShort() & 0xFFFF; - boolean members = buffer.get() == 1; + definitions.put(region, new MapIndex(region, terrainFolder, landscapeFolder, true)); + } catch (Throwable e) { - definitions.put(id, new MapIndex(id, terrain, objects, members)); + } } return definitions; @@ -62,6 +66,7 @@ public Map decode() throws IOException { @Override public void run() { try { + xteaDecoder.run(); MapIndex.init(decode()); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/cache/src/main/java/org/apollo/cache/map/MapObjectsDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapLandscapeDecoder.java similarity index 60% rename from cache/src/main/java/org/apollo/cache/map/MapObjectsDecoder.java rename to cache/src/main/java/org/apollo/cache/map/MapLandscapeDecoder.java index 351ea7d7e..f0f7afe7f 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapObjectsDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapLandscapeDecoder.java @@ -1,11 +1,7 @@ package org.apollo.cache.map; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.map.MapIndex; -import org.apollo.cache.map.MapConstants; -import org.apollo.cache.map.MapObject; +import org.apollo.cache.CacheBuffer; import org.apollo.util.BufferUtil; -import org.apollo.util.CompressionUtil; import java.io.IOException; import java.nio.ByteBuffer; @@ -17,20 +13,20 @@ * * @author Major */ -public final class MapObjectsDecoder { +public final class MapLandscapeDecoder { /** * Creates a MapObjectsDecoder for the specified map file. * - * @param fs The {@link IndexedFileSystem} to get the file from. * @param index The map index to decode objects for. * @return The MapObjectsDecoder. * @throws IOException If there is an error reading or decompressing the file. */ - public static MapObjectsDecoder create(IndexedFileSystem fs, MapIndex index) throws IOException { - ByteBuffer compressed = fs.getFile(MapConstants.MAP_INDEX, index.getObjectFile()); - ByteBuffer decompressed = ByteBuffer.wrap(CompressionUtil.degzip(compressed)); - - return new MapObjectsDecoder(decompressed); + public static MapLandscapeDecoder create(MapIndex index) throws IOException { + final var folder = index.getLandscapeFolder().get(); + if (folder == null) { + return null; + } + return new MapLandscapeDecoder(folder.findRSFileByID(0).getData()); } /** @@ -39,12 +35,12 @@ public static MapObjectsDecoder create(IndexedFileSystem fs, MapIndex index) thr private final ByteBuffer buffer; /** - * Create a new {@link MapObjectsDecoder} from the given buffer and map coordinates. + * Create a new {@link MapLandscapeDecoder} from the given buffer and map coordinates. * * @param buffer The decompressed object file buffer. */ - public MapObjectsDecoder(ByteBuffer buffer) { - this.buffer = buffer.asReadOnlyBuffer(); + public MapLandscapeDecoder(CacheBuffer buffer) { + this.buffer = ByteBuffer.wrap(buffer.getBuffer()); } /** @@ -56,7 +52,7 @@ public List decode() { List objects = new ArrayList<>(); int id = -1; - int idOffset = BufferUtil.readSmart(buffer); + int idOffset = BufferUtil.readHugeSmart(buffer); while (idOffset != 0) { id += idOffset; @@ -75,7 +71,7 @@ public List decode() { positionOffset = BufferUtil.readSmart(buffer); } - idOffset = BufferUtil.readSmart(buffer); + idOffset = BufferUtil.readHugeSmart(buffer); } return objects; diff --git a/cache/src/main/java/org/apollo/cache/map/MapFileDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapTerrainDecoder.java similarity index 76% rename from cache/src/main/java/org/apollo/cache/map/MapFileDecoder.java rename to cache/src/main/java/org/apollo/cache/map/MapTerrainDecoder.java index e85ae5e28..f4693bd10 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapFileDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapTerrainDecoder.java @@ -1,30 +1,29 @@ package org.apollo.cache.map; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.util.CompressionUtil; +import org.apollo.cache.CacheBuffer; -import java.nio.ByteBuffer; import java.io.IOException; +import java.nio.ByteBuffer; /** * A decoder for the terrain data stored in {@link MapFile}s. * * @author Major */ -public class MapFileDecoder { +public class MapTerrainDecoder { /** * Creates a MapFileDecoder for the specified map file. * - * @param fs The {@link IndexedFileSystem} to get the file from. * @param index The {@link MapIndex} to get the file index from. * @return The MapFileDecoder. * @throws IOException If there is an error reading or decompressing the file. */ - public static MapFileDecoder create(IndexedFileSystem fs, MapIndex index) throws IOException { - ByteBuffer compressed = fs.getFile(MapConstants.MAP_INDEX, index.getMapFile()); - ByteBuffer decompressed = ByteBuffer.wrap(CompressionUtil.degzip(compressed)); - - return new MapFileDecoder(decompressed); + public static MapTerrainDecoder create(MapIndex index) throws IOException { + final var folder = index.getTerrainFolder().get(); + if (folder == null) { + return null; + } + return new MapTerrainDecoder(folder.findRSFileByID(0).getData()); } /** @@ -39,8 +38,8 @@ public static MapFileDecoder create(IndexedFileSystem fs, MapIndex index) throws * * @param buffer The DataBuffer containing the MapFile data. */ - public MapFileDecoder(ByteBuffer buffer) { - this.buffer = buffer.asReadOnlyBuffer(); + public MapTerrainDecoder(CacheBuffer buffer) { + this.buffer = ByteBuffer.wrap(buffer.getBuffer()); } /** @@ -62,7 +61,7 @@ public MapFile decode() { * Decodes a {@link MapPlane} with the specified level. * * @param planes The previously-decoded {@link MapPlane}s, for calculating the height of the tiles. - * @param level The level. + * @param level The level. * @return The MapPlane. */ private MapPlane decodePlane(MapPlane[] planes, int level) { @@ -81,9 +80,9 @@ private MapPlane decodePlane(MapPlane[] planes, int level) { * Decodes the data into a {@link Tile}. * * @param planes The previously-decoded {@link MapPlane}s, for calculating the height of the Tile. - * @param level The level the Tile is on. - * @param x The x coordinate of the Tile. - * @param z The z coordinate of the Tile. + * @param level The level the Tile is on. + * @param x The x coordinate of the Tile. + * @param z The z coordinate of the Tile. * @return The MapFile. */ private Tile decodeTile(MapPlane[] planes, int level, int x, int z) { @@ -107,10 +106,9 @@ private Tile decodeTile(MapPlane[] planes, int level, int x, int z) { builder.setHeight((height == 1 ? 0 : height) * MapConstants.HEIGHT_MULTIPLICAND + below); } else if (type <= MapConstants.MINIMUM_OVERLAY_TYPE) { builder.setOverlay(buffer.get()); - builder.setOverlayType((type - MapConstants.LOWEST_CONTINUED_TYPE) - / MapConstants.ORIENTATION_COUNT); - builder.setOverlayOrientation(type - MapConstants.LOWEST_CONTINUED_TYPE - % MapConstants.ORIENTATION_COUNT); + builder.setOverlayType((type - MapConstants.LOWEST_CONTINUED_TYPE) / MapConstants.ORIENTATION_COUNT); + builder.setOverlayOrientation( + type - MapConstants.LOWEST_CONTINUED_TYPE % MapConstants.ORIENTATION_COUNT); } else if (type <= MapConstants.MINIMUM_ATTRIBUTES_TYPE) { builder.setAttributes(type - MapConstants.MINIMUM_OVERLAY_TYPE); } else { diff --git a/cache/src/main/java/org/apollo/cache/map/XteaDecoder.java b/cache/src/main/java/org/apollo/cache/map/XteaDecoder.java new file mode 100644 index 000000000..4fa576595 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/map/XteaDecoder.java @@ -0,0 +1,61 @@ +package org.apollo.cache.map; + +import com.google.gson.Gson; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +public class XteaDecoder implements Runnable { + + private static final Gson GSON = new Gson(); + + public static class Xtea { + private final int region; + private final int[] keys; + + public Xtea(int region, int[] keys) { + this.region = region; + this.keys = keys; + } + + public int getRegion() { + return region; + } + + public int[] getKeys() { + return keys; + } + } + + private final int release; + private final Int2ObjectArrayMap xteas; + + public XteaDecoder(int release) { + this.xteas = new Int2ObjectArrayMap<>(); + this.release = release; + } + + @Override + public void run() { + File file = new File("./data/fs/" + release + "/xtea.json"); + try { + var xteas = GSON.fromJson(Files.newBufferedReader(file.toPath()), Xtea[].class); + for (var xtea : xteas) { + this.xteas.put(xtea.region, xtea.getKeys()); + } + } catch (IOException io) { + io.printStackTrace(); + } + } + + public int[] get(int region) { + return xteas.getOrDefault(region, null); + } + + public Int2ObjectMap.FastEntrySet getAll() { + return xteas.int2ObjectEntrySet(); + } +} diff --git a/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java b/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java index 7345704c5..97486fc8a 100644 --- a/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java +++ b/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java @@ -1,16 +1,15 @@ package org.apollo.cache.tools; -import java.io.BufferedOutputStream; -import java.io.DataOutputStream; -import java.io.FileOutputStream; -import java.nio.file.Paths; - -import org.apollo.cache.IndexedFileSystem; +import com.google.common.base.Preconditions; +import org.apollo.cache.Cache; import org.apollo.cache.decoder.ItemDefinitionDecoder; import org.apollo.cache.def.ItemDefinition; import org.apollo.util.tools.EquipmentConstants; -import com.google.common.base.Preconditions; +import java.io.BufferedOutputStream; +import java.io.DataOutputStream; +import java.io.FileOutputStream; +import java.nio.file.Paths; /** * A tool for updating the equipment data. @@ -30,8 +29,8 @@ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length == 1, "Usage:\njava -cp ... org.apollo.tools.EquipmentUpdater [release]."); String release = args[0]; - try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/equipment-" + release + ".dat"))); - IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) { + try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/equipment-" + release + ".dat")))) { + Cache fs = Cache.openCache(Paths.get("data/fs/", release)); ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs); decoder.run(); @@ -359,8 +358,6 @@ private static int getDefenceRequirement(ItemDefinition definition) { return 60; } else if (name.equals("Dragon platelegs")) { return 60; - } else if (name.equals("Dragon sq shield")) { - return 60; } else if (name.equals("Rune med helm")) { return 40; } else if (name.equals("Rune chainbody")) { diff --git a/game/data/equipment-181.dat b/game/data/equipment-181.dat new file mode 100644 index 0000000000000000000000000000000000000000..6404ca998f9bf95904da09b4504374ea1ff46d83 GIT binary patch literal 52238 zcmeI5yOJxn5r#!eDwkDuro@TjQ?62S;uAaZE4ZBK{hxtGH@auO9|O#V!`(yL!(jOX z=sOw>%w>1~^Y8n?&yPQp&&@w~;``q)(2;4Q$#-86i=_K6Gc908==*m4X?F3j6MqFS z@nJy&hKFtAES|w?*BMD8Ue&N{{q(~P*~%8N@$CwhP1v0LRb7XXOX%kgOKT?=$5Bi_ zj^aPVwxifsGZaU$7MwO3m}>?S-7Uwc-HSbKH9m+1REdxScqeXn(ZtF|s{CaR-zIcp zs7$ScuHEpr+bwCo%&_bR*}DnPOBkxC?(Mb&az4_iA4?_4g#RA6%+o#fI-WCVcc?xv zKCq!V7GM#72rN!@ThUaL6eWcDscf$Dzw{$Sj7M=d;aXkNK50m|sSn^c&c1 z2pYE`ulDvw|%A(h4%*w=OWn!~3v00GVVeq~JKI+S}Y-W6(C3BA)&czGZ5dtKa2_+{IT`F* z#Ye*zAxk~m-#o50)OiLeA>a)IZ~#``Ie%}Buw|2*z;d+LLxbu#E;oA&*2fcp(zGKK zb_RzQ2ImY`qid^;#2NX|;)R_@MS^t`a%L99Pz-2f$Tq-902U$OG&}*#8Q#8f5)RAY zLTJy3Nz3zqEy&!Zo+tG~C9O_yqq%cAWCeS=a$@k-Kh=yDwL zkJ9@UX~=gRG98Egjzj)#`jAt?lX+u3xe!LUCIv^2>g~|G4WazBUzxV=_>CnB*zrWS z1#RWxu!)Uedw{dRSU)E)3zhZ%zwvfL+jJpPZwwo!_BVaow3;Q4pz5aSy|){33@L`J zVp6SZo;PVe@S1rjiFl?csIG>uW$($Od}u_7N8S^p}wO(|*e zc7&aB>SR=2E0#&q(FKQiRl)Ap!m+}NTVJNLj^TO#`;uoVry1tJS+_!=&A}4d3`8%W z&BbizHtg(!CIY_Znby0x)t~k5_4qlFJY(*&wB=Y9>fbH0(Y=a$>jVW(Hq<@+>Hyum z=S&yVCfgjNbSnF>g#*A5IFz?F03}MJ-) zv9{_}R`1OoS54K+am=mb$OgyIn!KJ1A>XkXyO)lc*1%iX|uv94Z{3l5ez>ucYtv@Yxty>X@cwD0e@z@4~($t~huY z&gBEv^jhkYtY0VAxXak6=uj}rIhOnm5-ucS*)OnJ0Iu3SrW=g7t$D3tG%-c+fkoQ8 zH!f9H4QvM2rp9&IWnifwquFT0%`ci56MPtM$_&c~(N7g~kNn(COID0c(K`P3CDb4u>JOKxnMZTUZ(~P3 zyfq0vmPT|Rfq9fHcS{`ByC$(Dt$|*@XYB;_MYl>@?_@h(Dn#Igr?MTq69Kg)C1>`C72 z?QBED^Y6FY*UUx7A=Yusu;WNX$Fr0HYDz?*3cGB6+pR)mFu`QNjdWjn-YDtwTAFnT zd8p9wrDyH<(lV4a5g&8fpS-1*@705(%`|e8_w*N=>E*lNNYP)*bNoDOInGjT{luBl zWhExP{K7F_`o0-XUZd|}(h%FyN_xZg8BIf;*6dw`pz+rdoN4cmwsc}cI0uU3=_1|1_*NSkId=Tnx9Yxa-7x$;eD;j|9|Bg=g(C`U%iBgeFoRK$|1_{+i(%W82Xsdq!FH zYW=5Dni~x^0Uk5p?|JCPLQG>kOo)+XkFYQiKO0-dluxyX%EiKHa2!ED4{-6( zUlnMVu~P7d)i zV=9Ls5e!4*Vo!)ZzQM_T7tC}yiY=n#VOm+5XQDG9NUt~Zar&0?3pp57)(`R?#rlgu zv{hc)va^5Jqq9`XzZO$Qg0X&9e`^VK92sj@8tofl>KfrzuD5X#&2eUc_c3kq7ii~; z{ABBYgLe~#b9U1Vm#|1FKsxD~na}w|vIt_q-L%jMD90JXY&=Oc-}}yl2lf&{5EN&= zz?nW9%Yadsg7WDTHw2XwB|QIriNBIV$;h4a5LRsK;3Uve2)SUL$gMaaJzp2%4T2>! zKe0gjaM~Gd*y_xdedVTnJNnR3iq9NA;9$}S?( zn}xLfmR6bdCswzdom8);#FYA_o3bj_tsYj<-CR7AgwAB^!L!*hY4_5GK~Jj{79p2l za*+d?l!{s+IoODY$mCr49y+9vQK8yek)A_3IoZ4T)^)ZR*2B0AZ*mGXoTg>OLN5(f zg;@gxLvz=&X*!|w!3e-Yr!8oh;E+O+$;^zp2{$RW(duIumKR64+t9p zO~Z2a_IovU{T3tIP|TY6BBrd(hGW>|hDe+Y>?7t0<0wwq^pKc(l9mgK2PjOyMEWKG z*+-8i>qq0rPj2>d*nLM{a~zp1c;rt8Yv;JV-JY>_92hiae}IcJiA@1n2e@w?dUH|P%nGK(@O+rwH0~pKv5gnk z8*O=T;NkZ))iS_G(%&XX@BAazTKjWlRi?u~nQ6|vXJhB2j_@%{=9`1{IYWdC*>J%c zlgHw4Y&O=YkuaN3<%}{bsg8&Ptpy}@7ZfL~@=XFcMd`v@YcccF2m3a2!k|*gEwl5F z_41HQOzs{w53+!;PGK+GLDG}VJ`<646O(4bbRJ=+brbDpfPMinhteflxz8fx&?aOK zAvS%urXC!W*=6A@5gRdAn=pfL6RwCcnVUfe!E6JvRxa_`kM%8wp;<~nFrSl4IeL^L zH{uK{i^xnE?alQ!P^3o;>S-_%2?{16^bJkv8~8}?U;@>MtOx;EKQ%fhz)61g;2tN(AC2 zS@Yl1K1KDVoM-OU-GVmJgSqCDrj{aPkp!5 z289UR!NuneXRti~Sk;T?8bOE0E2RfdOiGJ3RdR`9-`z(77q-0Sm&D|BW5Y+TgO*gL zLmE1X!6(xriibkRUx4Yn`XaPqlb9h53D*Y-h?$upUD`7J<3^pP-cPfg z0+nVSEWcnZ4RKSMp4yVq*^!*TbXR`oKVeyKAjEw8nzi58F8_PTV&y3Q`;Og$(SJ!~ z?#BNinmw$v=RU`;Jep%U<1F@=iCntq!_^sEyyv zmBYd#jip5z0a_HamNYd&)1RuaW*Macz?`g6OcAy|^wiF2X3k-nm(C1&%!Msklq=-{ zo(;r*|L)dCZ`XpN(`2SH8eBljA{tkwWOu>-eabu!Kf;XBuvIiHDqHj{+K!&8DbhU+9z_3rMZ6{@cV}gwWO^2~x zSvEPnRRn8HEonf<5P|`4B4;1*MBt!|ObG}d0p+aAe&c5wSo9%N$7=@RV(8q)+@CDU z#P_D<#PaWenfEce{l#)d+z5la7py7$3URu^lv|wcUr9dxMs}E{UKQNcUo=qE2)iLt7rUkjg;dT; zZsQTE($T+eX$lpHnmbMszJ9ouM$$rJF;*s+Au;oF%ac6Q!ftBGrVTfW414g>lMm|= z%b%hJRjmn(iRUy}JECs~lefh5=N+-l!PW;Uy9r&^cztn17M}4*$168#z@#SBF8pjq z;ZHjxC-5R-Ii7MEzLi~hEFcBh_dY6e6bv_-kzVr{bx#8O`UXqAA^AQmLZ!jYsM(Eb z9h){cPK#1fATjqAZjH@V2U%o?-@LlVh5H~5R;?xv1~hbRCEo_z2fOJkv58@u_@Ii9 zBA1h%G?p59JHSTuWV3b~U@5EZ>8a+fw3#*#NIqha6iDl-o!P=H;(22%Rdqbpk~m8t zI^8G+g-`aF=CMYRF|9bpN{@|W`uHsJ1Z=0d(7e>0~JHRfn; zJrIe>YPPPa_XU7ODpP}Xg)5nBhM2R)86M&BmO@D*+_}b^s(@uGCb|!8+QQXM$Q-51 zqjF25rO04_G8Z!sx;nP#Sg<_315wF!;Uxg!+|UW50VgIVRqcezK131iLm1bGlXguY z*azsuOEV`KeIwD^Hxj*lBhg!R!KOZ(OnMx^Y`I4OYh@Fok;E`i4~pM75Nz={tlhkZJZ4z9oK$SuaW*b^iq%+`Qoc literal 0 HcmV?d00001 diff --git a/game/data/net.xml b/game/data/net.xml index 8bd754310..d9f8bda22 100644 --- a/game/data/net.xml +++ b/game/data/net.xml @@ -1,7 +1,8 @@ 80 - 43594 + 43594 + 43594 43595 \ No newline at end of file diff --git a/game/plugin/locations/al-kharid/src/npcs.plugin.kts b/game/plugin/locations/al-kharid/src/npcs.plugin.kts deleted file mode 100644 index 79b74471c..000000000 --- a/game/plugin/locations/al-kharid/src/npcs.plugin.kts +++ /dev/null @@ -1,114 +0,0 @@ -package org.apollo.plugin.locations.alKharid - -import org.apollo.game.model.Direction -import org.apollo.game.plugin.entity.spawn.spawnNpc - -// Generic npcs - -spawnNpc("man", x = 3276, y = 3186) -spawnNpc("man", x = 3282, y = 3197) - -spawnNpc("man", id = 3, x = 3301, y = 3200) -spawnNpc("man", id = 3, x = 3300, y = 3208) - -spawnNpc("man", id = 2, x = 3297, y = 3196) - -spawnNpc("man", id = 16, x = 3294, y = 3204) - -spawnNpc("spider", x = 3319, y = 3145) -spawnNpc("spider", x = 3319, y = 3140) -spawnNpc("spider", x = 3323, y = 3138) - -spawnNpc("scorpion", x = 3282, y = 3149) - -// Camels - -spawnNpc("cam_the_camel", x = 3295, y = 3232) -spawnNpc("elly_the_camel", x = 3312, y = 3210) -spawnNpc("camel", x = 3285, y = 3198) -spawnNpc("ollie_the_camel", x = 3291, y = 3209) -spawnNpc("al_the_camel", x = 3275, y = 3162) - -// Quest npc - -spawnNpc("osman", x = 3286, y = 3180, facing = Direction.EAST) - -spawnNpc("hassan", x = 3302, y = 3163) - -spawnNpc("father_reen", x = 3272, y = 3158) - -spawnNpc("man", id = 663, x = 3297, y = 3287) - -// Boarder guards - -spawnNpc("border_guard", x = 3268, y = 3226) -spawnNpc("border_guard", x = 3267, y = 3226) -spawnNpc("border_guard", x = 3268, y = 3229, facing = Direction.SOUTH) -spawnNpc("border_guard", x = 3267, y = 3229, facing = Direction.SOUTH) - -// Palace guards - -spawnNpc("Al-Kharid warrior", x = 3285, y = 3174) -spawnNpc("Al-Kharid warrior", x = 3283, y = 3168) -spawnNpc("Al-Kharid warrior", x = 3285, y = 3169) -spawnNpc("Al-Kharid warrior", x = 3290, y = 3162) -spawnNpc("Al-Kharid warrior", x = 3295, y = 3170) -spawnNpc("Al-Kharid warrior", x = 3300, y = 3175) -spawnNpc("Al-Kharid warrior", x = 3300, y = 3171) -spawnNpc("Al-Kharid warrior", x = 3301, y = 3168) - -// Shanty pass - -spawnNpc("shantay_guard", x = 3301, y = 3120) -spawnNpc("shantay_guard", x = 3302, y = 3126) -spawnNpc("shantay_guard", x = 3306, y = 3126) -spawnNpc("shantay_guard", id = 838, x = 3303, y = 3118) - -// Mine - -spawnNpc("scorpion", x = 3296, y = 3294) -spawnNpc("scorpion", x = 3298, y = 3280) -spawnNpc("scorpion", x = 3299, y = 3299) -spawnNpc("scorpion", x = 3299, y = 3309) -spawnNpc("scorpion", x = 3300, y = 3287) -spawnNpc("scorpion", x = 3300, y = 3315) -spawnNpc("scorpion", x = 3301, y = 3305) -spawnNpc("scorpion", x = 3301, y = 3312) - -// Functional npcs - -spawnNpc("gnome_pilot", x = 3279, y = 3213) - -spawnNpc("banker", id = 496, x = 3267, y = 3164, facing = Direction.EAST) -spawnNpc("banker", id = 496, x = 3267, y = 3167, facing = Direction.EAST) -spawnNpc("banker", id = 496, x = 3267, y = 3169, facing = Direction.EAST) - -spawnNpc("banker", id = 497, x = 3267, y = 3166, facing = Direction.EAST) -spawnNpc("banker", id = 497, x = 3267, y = 3168, facing = Direction.EAST) - -spawnNpc("gem_trader", x = 3287, y = 3210) - -spawnNpc("zeke", x = 3289, y = 3189) - -spawnNpc("shantay", x = 3304, y = 3124) - -spawnNpc("rug_merchant", id = 2296, x = 3311, y = 3109, facing = Direction.WEST) - -spawnNpc("ranael", x = 3315, y = 3163) - -spawnNpc("shop_keeper", id = 524, x = 3315, y = 3178) -spawnNpc("shop_assistant", id = 525, x = 3315, y = 3180, facing = Direction.WEST) - -spawnNpc("louie_legs", x = 3316, y = 3175, facing = Direction.WEST) - -spawnNpc("ellis", x = 3274, y = 3192) - -spawnNpc("dommik", x = 3321, y = 3193) - -spawnNpc("tool_leprechaun", x = 3319, y = 3204) - -spawnNpc("ali_morrisane", x = 3304, y = 3211, facing = Direction.EAST) - -spawnNpc("silk_trader", x = 3300, y = 3203) - -spawnNpc("karim", x = 3273, y = 3180) \ No newline at end of file diff --git a/game/plugin/locations/al-kharid/src/shops.plugin.kts b/game/plugin/locations/al-kharid/src/shops.plugin.kts deleted file mode 100644 index 2d51292bc..000000000 --- a/game/plugin/locations/al-kharid/src/shops.plugin.kts +++ /dev/null @@ -1,146 +0,0 @@ -package org.apollo.plugin.locations.alKharid - -import org.apollo.game.plugin.shops.builder.shop - -shop("Al-Kharid General Store") { - operated by "Shop keeper"(524) and "Shop assistant"(525) - buys any items - - sell(5) of "Pot" - sell(2) of "Jug" - sell(2) of "Shears" - sell(3) of "Bucket" - sell(2) of "Bowl" - sell(2) of "Cake tin" - sell(2) of "Tinderbox" - sell(2) of "Chisel" - sell(5) of "Hammer" - sell(5) of "Newcomer map" -} - -/** - * TODO add a way to "unlock" items, as more of Ali Morrisane's items are unlocked by completing certain parts of - * the Rogue Trader minigame progressively. - * - * TODO this shop can be accessed only through dialogue, so support for that should be added. - */ -/*shop("Ali's Discount Wares") { - operated by "Ali Morrisane" - - sell(3) of "Pot" - sell(2) of "Jug" - sell(10) of { "Waterskin"(1825) } - sell(3) of "Desert shirt" - sell(2) of "Desert boots" - sell(19) of "Bucket" - sell(11) of "Fake beard" - sell(12) of "Karidian headpiece" - sell(50) of "Papyrus" - sell(5) of "Knife" - sell(11) of "Tinderbox" - sell(23) of "Bronze pickaxe" - sell(15) of "Raw chicken" -}*/ - -shop("Dommik's Crafting Store") { - operated by "Dommik" - - sell(2) of "Chisel" - category("mould") { - sell(10) of "Ring" - sell(2) of "Necklace" - sell(10) of "Amulet" - } - sell(3) of "Needle" - sell(100) of "Thread" - category("mould") { - sell(3) of "Holy" - sell(10) of "Sickle" - sell(10) of "Tiara" - } -} - -shop("Gem Trader") { - operated by "Gem trader" - - category("uncut", affix = prefix) { - sell(1) of { - -"Sapphire" - -"Emerald" - } - sell(0) of { - -"Ruby" - -"Diamond" - } - } - - sell(1) of { - -"Sapphire" - -"Emerald" - } - sell(0) of { - -"Ruby" - -"Diamond" - } -} - -shop("Louie's Armoured Legs Bazaar") { - operated by "Louie Legs" - - category("platelegs", depluralise = false) { - sell(5) of "Bronze" - sell(3) of "Iron" - sell(2) of "Steel" - sell(1) of "Black" - sell(1) of "Mithril" - sell(1) of "Adamant" - } -} - -shop("Ranael's Super Skirt Store") { - operated by "Ranael" - - category("plateskirt") { - sell(5) of "Bronze" - sell(3) of "Iron" - sell(2) of "Steel" - sell(1) of "Black" - sell(1) of "Mithril" - sell(1) of "Adamant" - } -} - -shop("Shantay Pass Shop") { - operated by "Shantay" - - sell(100) of { "Waterskin"(1823) } - sell(100) of { "Waterskin"(1831) } - sell(10) of "Jug of water" - sell(10) of "Bowl of water" - sell(10) of "Bucket of water" - sell(10) of "Knife" - category("desert", affix = prefix) { - sell(10) of "shirt" - sell(10) of "robe" - sell(10) of "boots" - } - sell(10) of "Bronze bar" - sell(500) of "Feather" - sell(10) of "Hammer" - sell(0) of "Bucket" - sell(0) of "Bowl" - sell(0) of "Jug" - sell(500) of "Shantay pass" - sell(20) of "Rope" -} - -shop("Zeke's Superior Scimitars") { - operated by "Zeke" - - category("scimitar") { - sell(5) of "Bronze" - sell(3) of "Iron" - sell(2) of "Steel" - sell(1) of "Mithril" - } -} \ No newline at end of file diff --git a/game/plugin/locations/edgeville/src/npcs.plugin.kts b/game/plugin/locations/edgeville/src/npcs.plugin.kts deleted file mode 100644 index d89e84926..000000000 --- a/game/plugin/locations/edgeville/src/npcs.plugin.kts +++ /dev/null @@ -1,53 +0,0 @@ -package org.apollo.plugin.locations.edgeville - -import org.apollo.game.model.Direction -import org.apollo.game.plugin.entity.spawn.spawnNpc - -// Generic npcs - -spawnNpc("man", x = 3095, y = 3508) -spawnNpc("man", x = 3095, y = 3511) -spawnNpc("man", x = 3098, y = 3509) -spawnNpc("man", id = 2, x = 3093, y = 3511) -spawnNpc("man", id = 3, x = 3097, y = 3508) -spawnNpc("man", id = 3, x = 3092, y = 3508) -spawnNpc("man", id = 3, x = 3097, y = 3512) - -spawnNpc("guard", x = 3086, y = 3516) -spawnNpc("guard", x = 3094, y = 3518) -spawnNpc("guard", x = 3108, y = 3514) -spawnNpc("guard", x = 3110, y = 3514) -spawnNpc("guard", x = 3113, y = 3514) -spawnNpc("guard", x = 3113, y = 3516) - -spawnNpc("sheep", id = 43, x = 3050, y = 3516) -spawnNpc("sheep", id = 43, x = 3051, y = 3514) -spawnNpc("sheep", id = 43, x = 3056, y = 3517) -spawnNpc("ram", id = 3673, x = 3048, y = 3515) - -spawnNpc("monk", x = 3044, y = 3491) -spawnNpc("monk", x = 3045, y = 3483) -spawnNpc("monk", x = 3045, y = 3497) -spawnNpc("monk", x = 3050, y = 3490) -spawnNpc("monk", x = 3054, y = 3490) -spawnNpc("monk", x = 3058, y = 3497) - -// Functional npcs - -spawnNpc("richard", x = 3098, y = 3516) -spawnNpc("doris", x = 3079, y = 3491) -spawnNpc("brother_jered", x = 3045, y = 3488) -spawnNpc("brother_althric", x = 3054, y = 3504) - -spawnNpc("abbot_langley", x = 3059, y = 3484) -spawnNpc("oziach", x = 3067, y = 3518, facing = Direction.EAST) - -spawnNpc("shop_keeper", id = 528, x = 3079, y = 3509) -spawnNpc("shop_assistant", id = 529, x = 3082, y = 3513) - -spawnNpc("banker", x = 3096, y = 3489, facing = Direction.WEST) -spawnNpc("banker", x = 3096, y = 3491, facing = Direction.WEST) -spawnNpc("banker", x = 3096, y = 3492) -spawnNpc("banker", x = 3098, y = 3492) - -spawnNpc("mage_of_zamorak", x = 3106, y = 3560) \ No newline at end of file diff --git a/game/plugin/locations/edgeville/src/shops.plugin.kts b/game/plugin/locations/edgeville/src/shops.plugin.kts deleted file mode 100644 index 0a5facec5..000000000 --- a/game/plugin/locations/edgeville/src/shops.plugin.kts +++ /dev/null @@ -1,31 +0,0 @@ -package org.apollo.plugin.locations.edgeville - -import org.apollo.game.plugin.shops.builder.shop - -shop("Edgeville General Store") { - operated by "Shop keeper"(528) and "Shop assistant"(529) - buys any items - - sell(5) of "Pot" - sell(2) of "Jug" - sell(2) of "Shears" - sell(3) of "Bucket" - sell(2) of "Bowl" - sell(2) of "Cake tin" - sell(2) of "Tinderbox" - sell(2) of "Chisel" - sell(5) of "Hammer" - sell(5) of "Newcomer map" -} - -/** - * TODO make a way to have requirements to open shops. Players have to have finished Dragon Slayer to access - * "Oziach's Armour" - */ -shop("Oziach's Armour") { - operated by "Oziach" - - sell(2) of "Rune platebody" - sell(2) of "Green d'hide body" - sell(35) of "Anti-dragon shield" -} \ No newline at end of file diff --git a/game/plugin/locations/falador/src/npcs.plugin.kts b/game/plugin/locations/falador/src/npcs.plugin.kts deleted file mode 100644 index 9136f9c09..000000000 --- a/game/plugin/locations/falador/src/npcs.plugin.kts +++ /dev/null @@ -1,171 +0,0 @@ -package org.apollo.plugin.locations.falador - -import org.apollo.game.plugin.entity.spawn.spawnNpc - -// Generic npcs - -spawnNpc("chicken", x = 2965, y = 3345) - -spawnNpc("duck", x = 2988, y = 3383) -spawnNpc("duck", x = 2992, y = 3383) -spawnNpc("duck", x = 2993, y = 3385) - -spawnNpc("drunken_man", x = 2957, y = 3368, z = 1) - -spawnNpc("dwarf", id = 118, x = 3023, y = 3334) -spawnNpc("dwarf", id = 118, x = 3027, y = 3341) -spawnNpc("dwarf", id = 118, x = 3012, y = 3341) -spawnNpc("dwarf", id = 118, x = 3017, y = 3346, z = 1) -spawnNpc("dwarf", id = 118, x = 3011, y = 3341, z = 1) - -spawnNpc("dwarf", id = 121, x = 3027, y = 3341) - -spawnNpc("dwarf", id = 382, x = 3017, y = 3340) - -spawnNpc("dwarf", id = 3294, x = 3022, y = 3338) -spawnNpc("dwarf", id = 3295, x = 3021, y = 3341) - -spawnNpc("gardener", x = 2998, y = 3385) -spawnNpc("gardener", x = 3019, y = 3369) -spawnNpc("gardener", id = 3234, x = 3016, y = 3386) - -spawnNpc("guard", x = 2965, y = 3394) -spawnNpc("guard", x = 2964, y = 3396) -spawnNpc("guard", x = 2966, y = 3397) -spawnNpc("guard", x = 2964, y = 3384) -spawnNpc("guard", x = 2963, y = 3380) -spawnNpc("guard", x = 3006, y = 3325) -spawnNpc("guard", x = 3008, y = 3320) -spawnNpc("guard", x = 3006, y = 3322) -spawnNpc("guard", x = 3038, y = 3356) - -spawnNpc("guard", id = 10, x = 2942, y = 3375) -spawnNpc("guard", id = 10, x = 3040, y = 3352) - -spawnNpc("guard", id = 3230, x = 2967, y = 3395) -spawnNpc("guard", id = 3230, x = 2966, y = 3392) -spawnNpc("guard", id = 3230, x = 2963, y = 3376) -spawnNpc("guard", id = 3230, x = 2954, y = 3382) -spawnNpc("guard", id = 3230, x = 2950, y = 3377) -spawnNpc("guard", id = 3230, x = 2968, y = 3381) - -spawnNpc("guard", id = 3231, x = 3033, y = 3389, z = 1) -spawnNpc("guard", id = 3231, x = 3041, y = 3388, z = 1) -spawnNpc("guard", id = 3231, x = 3048, y = 3389, z = 1) -spawnNpc("guard", id = 3231, x = 3056, y = 3389, z = 1) -spawnNpc("guard", id = 3231, x = 3062, y = 3386, z = 1) -spawnNpc("guard", id = 3231, x = 3058, y = 3329, z = 1) -spawnNpc("guard", id = 3231, x = 3050, y = 3329, z = 1) -spawnNpc("guard", id = 3231, x = 3038, y = 3329, z = 1) -spawnNpc("guard", id = 3231, x = 3029, y = 3329, z = 1) - -spawnNpc("swan", x = 2960, y = 3359) -spawnNpc("swan", x = 2963, y = 3360) -spawnNpc("swan", x = 2968, y = 3359) -spawnNpc("swan", x = 2971, y = 3360) -spawnNpc("swan", x = 2976, y = 3358) -spawnNpc("swan", x = 2989, y = 3384) - -spawnNpc("man", id = 3223, x = 2991, y = 3365) -spawnNpc("man", id = 3225, x = 3037, y = 3345, z = 1) - -spawnNpc("white_knight", x = 2983, y = 3343) -spawnNpc("white_knight", x = 2981, y = 3334) -spawnNpc("white_knight", x = 2988, y = 3335) -spawnNpc("white_knight", x = 2996, y = 3342) -spawnNpc("white_knight", x = 2960, y = 3340) -spawnNpc("white_knight", x = 2962, y = 3336) -spawnNpc("white_knight", x = 2974, y = 3342) -spawnNpc("white_knight", x = 2972, y = 3345) -spawnNpc("white_knight", x = 2977, y = 3348) - -spawnNpc("white_knight", id = 3348, x = 2971, y = 3340) -spawnNpc("white_knight", id = 3348, x = 2978, y = 3350) - -spawnNpc("white_knight", x = 2964, y = 3330, z = 1) -spawnNpc("white_knight", x = 2968, y = 3334, z = 1) -spawnNpc("white_knight", x = 2969, y = 3339, z = 1) -spawnNpc("white_knight", x = 2978, y = 3332, z = 1) -spawnNpc("white_knight", x = 2958, y = 3340, z = 1) -spawnNpc("white_knight", x = 2960, y = 3343, z = 1) - -spawnNpc("white_knight", id = 3348, x = 2987, y = 3334, z = 1) -spawnNpc("white_knight", id = 3348, x = 2983, y = 3336, z = 1) -spawnNpc("white_knight", id = 3348, x = 2987, y = 3334, z = 1) -spawnNpc("white_knight", id = 3348, x = 2979, y = 3348, z = 1) -spawnNpc("white_knight", id = 3348, x = 2964, y = 3337, z = 1) - -spawnNpc("white_knight", id = 3349, x = 2989, y = 3344, z = 1) - -spawnNpc("white_knight", x = 2985, y = 3342, z = 2) - -spawnNpc("white_knight", id = 3348, x = 2979, y = 3348, z = 2) -spawnNpc("white_knight", id = 3348, x = 2974, y = 3329, z = 2) -spawnNpc("white_knight", id = 3348, x = 2982, y = 3341, z = 2) - -spawnNpc("white_knight", id = 3349, x = 2990, y = 3341, z = 2) -spawnNpc("white_knight", id = 3349, x = 2971, y = 3330, z = 2) -spawnNpc("white_knight", id = 3349, x = 2965, y = 3350, z = 2) -spawnNpc("white_knight", id = 3349, x = 2965, y = 3329, z = 2) - -spawnNpc("white_knight", id = 3350, x = 2961, y = 3347, z = 2) - -spawnNpc("white_knight", id = 3349, x = 2962, y = 3339, z = 3) - -spawnNpc("white_knight", id = 3350, x = 2960, y = 3336, z = 3) -spawnNpc("white_knight", id = 3350, x = 2984, y = 3349, z = 3) - -spawnNpc("woman", id = 3226, x = 2991, y = 3384) - -// Functional npcs - -spawnNpc("apprentice_workman", id = 3235, x = 2971, y = 3369, z = 1) - -spawnNpc("banker", id = 495, x = 2945, y = 3366) -spawnNpc("banker", id = 495, x = 2946, y = 3366) -spawnNpc("banker", id = 495, x = 2947, y = 3366) -spawnNpc("banker", id = 495, x = 2948, y = 3366) - -spawnNpc("banker", x = 2949, y = 3366) - -spawnNpc("banker", x = 3015, y = 3353) -spawnNpc("banker", x = 3014, y = 3353) -spawnNpc("banker", x = 3013, y = 3353) -spawnNpc("banker", x = 3012, y = 3353) -spawnNpc("banker", x = 3011, y = 3353) -spawnNpc("banker", x = 3010, y = 3353) - -spawnNpc("cassie", x = 2976, y = 3383) - -spawnNpc("emily", x = 2954, y = 3372) - -spawnNpc("flynn", x = 2950, y = 3387) - -spawnNpc("hairdresser", x = 2944, y = 3380) - -spawnNpc("herquin", x = 2945, y = 3335) - -spawnNpc("heskel", x = 3007, y = 3374) - -spawnNpc("kaylee", x = 2957, y = 3372) - -spawnNpc("tina", x = 2955, y = 3371, z = 1) - -spawnNpc("tool_leprechaun", x = 3005, y = 3370) - -spawnNpc("squire", x = 2977, y = 3343) - -spawnNpc("sir_tiffy_cashien", x = 2997, y = 3373) - -spawnNpc("sir_amik_varze", x = 2960, y = 3336, z = 2) - -spawnNpc("sir_vyvin", x = 2983, y = 3335, z = 2) - -spawnNpc("shop_keeper", id = 524, x = 2955, y = 3389) -spawnNpc("shop_assistant", id = 525, x = 2957, y = 3387) - -spawnNpc("wayne", x = 2972, y = 3312) - -spawnNpc("workman", id = 3236, x = 2975, y = 3369, z = 1) - -spawnNpc("wyson_the_gardener", x = 3028, y = 3381) \ No newline at end of file diff --git a/game/plugin/locations/falador/src/shops.plugin.kts b/game/plugin/locations/falador/src/shops.plugin.kts deleted file mode 100644 index 5b7446fa9..000000000 --- a/game/plugin/locations/falador/src/shops.plugin.kts +++ /dev/null @@ -1,76 +0,0 @@ -package org.apollo.plugin.locations.falador - -import org.apollo.game.plugin.shops.builder.shop - -shop("Falador General Store") { - operated by "Shop keeper"(524) and "Shop assistant"( 525) - buys any items - - sell(5) of "Pot" - sell(2) of "Jug" - sell(2) of "Shears" - sell(3) of "Bucket" - sell(2) of "Bowl" - sell(2) of "Cake tin" - sell(2) of "Tinderbox" - sell(2) of "Chisel" - sell(5) of "Hammer" - sell(5) of "Newcomer map" -} - -shop("Cassie's Shield Shop") { - operated by "Cassie" - - sell(5) of "Wooden shield" - sell(3) of "Bronze sq shield" - sell(3) of "Bronze kiteshield" - sell(2) of "Iron sq shield" - sell(0) of "Iron kiteshield" - sell(0) of "Steel sq shield" - sell(0) of "Steel kiteshield" - sell(0) of "Mithril sq shield" -} - -shop("Flynn's Mace Market") { - operated by "Flynn" - - category("mace") { - sell(5) of "Bronze" - sell(4) of "Iron" - sell(3) of "Mithril" - sell(2) of "Adamant" - } -} - -shop("Herquin's Gems") { - operated by "Herquin" - - category("uncut", affix = prefix) { - sell(1) of "Sapphire" - sell(0) of { - -"Emerald" - -"Ruby" - -"Diamond" - } - } - - sell(1) of "Sapphire" - sell(0) of { - -"Emerald" - -"Ruby" - -"Diamond" - } -} - -shop("Wayne's Chains - Chainmail Specialist") { - operated by "Wayne" - - category("chainbody") { - sell(3) of "Bronze" - sell(2) of "Iron" - sell(1) of "Steel" - sell(1) of "Black" - sell(1) of "Mithril" - sell(1) of "Adamant" - } -} \ No newline at end of file diff --git a/game/plugin/locations/lumbridge/src/npcs.plugin.kts b/game/plugin/locations/lumbridge/src/npcs.plugin.kts deleted file mode 100644 index 03094618d..000000000 --- a/game/plugin/locations/lumbridge/src/npcs.plugin.kts +++ /dev/null @@ -1,15 +0,0 @@ -package org.apollo.plugin.locations.lumbridge - -import org.apollo.game.plugin.entity.spawn.spawnNpc - -spawnNpc("woman", id = 4, x = 3232, y = 3207) -spawnNpc("man", id = 1, x = 3231, y = 3237) -spawnNpc("man", id = 2, x = 3224, y = 3240) -spawnNpc("woman", id = 5, x = 3229, y = 2329) - -spawnNpc("hans", x = 3221, y = 3221) -spawnNpc("father aereck", x = 3243, y = 3210) -spawnNpc("bob", x = 3231, y = 3203) -spawnNpc("shop keeper", x = 3212, y = 3247) -spawnNpc("shop assistant", x = 3211, y = 3245) -spawnNpc("lumbridge guide", x = 323, y = 3229) diff --git a/game/plugin/locations/lumbridge/src/shops.plugin.kts b/game/plugin/locations/lumbridge/src/shops.plugin.kts deleted file mode 100644 index 942bb62d3..000000000 --- a/game/plugin/locations/lumbridge/src/shops.plugin.kts +++ /dev/null @@ -1,42 +0,0 @@ -package org.apollo.plugin.locations.lumbridge - -import org.apollo.game.plugin.shops.builder.shop - -shop("Lumbridge General Store") { - operated by "Shop keeper" and "Shop assistant" - buys any items - - sell(5) of "Pot" - sell(2) of "Jug" - sell(2) of "Shears" - sell(3) of "Bucket" - sell(2) of "Bowl" - sell(2) of "Cake tin" - sell(2) of "Tinderbox" - sell(2) of "Chisel" - sell(5) of "Hammer" - sell(5) of "Newcomer map" -} - -shop("Bob's Brilliant Axes") { - operated by "Bob" - - category("pickaxe") { - sell(5) of "Bronze" - } - - category("axe") { - sell(10) of "Bronze" - sell(5) of "Iron" - sell(3) of "Steel" - } - - category("battleaxe") { - sell(5) of "Iron" - sell(2) of "Steel" - sell(1) of "Mithril" - } -} - -// TODO find out how to make objects be able to open stores for the Culinaromancer's Chest. Also links to TODO in -// Al-Kharid's shops plugin for "unlockable" items. \ No newline at end of file diff --git a/game/plugin/locations/tutorial-island/src/npcs.plugin.kts b/game/plugin/locations/tutorial-island/src/npcs.plugin.kts deleted file mode 100644 index 5ec51c09b..000000000 --- a/game/plugin/locations/tutorial-island/src/npcs.plugin.kts +++ /dev/null @@ -1,44 +0,0 @@ -package org.apollo.plugin.locations.tutorialIsland - -import org.apollo.game.model.Direction -import org.apollo.game.plugin.entity.spawn.spawnNpc - -// Functional npcs - -// 'Above-ground' npcs - -spawnNpc("master_chef", x = 3076, y = 3085) -spawnNpc("quest_guide", x = 3086, y = 3122) -spawnNpc("financial_advisor", x = 3127, y = 3124, facing = Direction.WEST) -spawnNpc("brother_brace", x = 3124, y = 3107, facing = Direction.EAST) -spawnNpc("magic_instructor", x = 3140, y = 3085) - -// 'Below-ground' npcs -// Note: They aren't actually on a different plane, they're just in a different location that -// pretends to be underground. - -spawnNpc("mining_instructor", x = 3081, y = 9504) -spawnNpc("combat_instructor", x = 3104, y = 9506) - -// Non-humanoid npcs - -spawnNpc("fishing_spot", id = 316, x = 3102, y = 3093) - -spawnNpc("chicken", x = 3140, y = 3095) -spawnNpc("chicken", x = 3140, y = 3093) -spawnNpc("chicken", x = 3138, y = 3092) -spawnNpc("chicken", x = 3137, y = 3094) -spawnNpc("chicken", x = 3138, y = 3095) - -// 'Below-ground' npcs -// Note: They aren't actually on a different plane, they're just in a different location that -// pretends to be underground. - -spawnNpc("giant_rat", id = 87, x = 3105, y = 9514) -spawnNpc("giant_rat", id = 87, x = 3105, y = 9517) -spawnNpc("giant_rat", id = 87, x = 3106, y = 9514) -spawnNpc("giant_rat", id = 87, x = 3104, y = 9514) -spawnNpc("giant_rat", id = 87, x = 3105, y = 9519) -spawnNpc("giant_rat", id = 87, x = 3109, y = 9516) -spawnNpc("giant_rat", id = 87, x = 3108, y = 9520) -spawnNpc("giant_rat", id = 87, x = 3102, y = 9517) \ No newline at end of file diff --git a/game/plugin/locations/varrock/src/npcs.plugin.kts b/game/plugin/locations/varrock/src/npcs.plugin.kts deleted file mode 100644 index 83d5fb9ec..000000000 --- a/game/plugin/locations/varrock/src/npcs.plugin.kts +++ /dev/null @@ -1,268 +0,0 @@ -package org.apollo.plugin.locations.varrock - -import org.apollo.game.model.Direction -import org.apollo.game.plugin.entity.spawn.spawnNpc - -spawnNpc("barbarian_woman", x = 3222, y = 3399) - -spawnNpc("bear", id = 106, x = 3289, y = 3351) - -spawnNpc("black_knight", x = 3238, y = 3514) -spawnNpc("black_knight", x = 3227, y = 3518) -spawnNpc("black_knight", x = 3279, y = 3502) - -spawnNpc("dark_wizard", id = 174, x = 3230, y = 3366) - -spawnNpc("dark_wizard", id = 174, x = 3228, y = 3368) -spawnNpc("dark_wizard", id = 174, x = 3225, y = 3367) -spawnNpc("dark_wizard", id = 174, x = 3226, y = 3365) -spawnNpc("dark_wizard", id = 174, x = 3226, y = 3372) -spawnNpc("dark_wizard", id = 174, x = 3231, y = 3371) - -spawnNpc("dark_wizard", id = 172, x = 3229, y = 3372) -spawnNpc("dark_wizard", id = 172, x = 3224, y = 3370) -spawnNpc("dark_wizard", id = 172, x = 3228, y = 3366) -spawnNpc("dark_wizard", id = 172, x = 3232, y = 3368) -spawnNpc("dark_wizard", id = 172, x = 3226, y = 3369) - -spawnNpc("giant_rat", id = 87, x = 3292, y = 3375) -spawnNpc("giant_rat", id = 87, x = 3265, y = 3384) -spawnNpc("giant_rat", id = 87, x = 3267, y = 3381) - -spawnNpc("guard", id = 368, x = 3263, y = 3407, facing = Direction.SOUTH) - -spawnNpc("jeremy_clerksin", x = 3253, y = 3477) -spawnNpc("martina_scorsby", x = 3256, y = 3481) - -spawnNpc("man", x = 3281, y = 3500) -spawnNpc("man", x = 3193, y = 3394) -spawnNpc("man", x = 3159, y = 3429) -spawnNpc("man", x = 3245, y = 3394) -spawnNpc("man", x = 3283, y = 3492, z = 1) - -spawnNpc("man", id = 2, x = 3283, y = 3492, z = 1) -spawnNpc("man", id = 2, x = 3263, y = 3400) - -spawnNpc("man", id = 3, x = 3227, y = 3395, z = 1) -spawnNpc("man", id = 3, x = 3231, y = 3399, z = 1) - -spawnNpc("mugger", x = 3251, y = 3390) -spawnNpc("mugger", x = 3177, y = 3363) - -spawnNpc("tramp", id = 2792, x = 3177, y = 3363) - -spawnNpc("woman", x = 3221, y = 3396) - -spawnNpc("woman", id = 5, x = 3279, y = 3497) -spawnNpc("woman", id = 25, x = 3278, y = 3492) - -spawnNpc("thief", x = 3285, y = 3500) -spawnNpc("thief", x = 3234, y = 3389) -spawnNpc("thief", x = 3188, y = 3383) -spawnNpc("thief", x = 3184, y = 3390) -spawnNpc("thief", x = 3188, y = 3394) - -spawnNpc("unicorn", x = 3286, y = 3342) -spawnNpc("unicorn", x = 3279, y = 3345) - -// North Guards - -spawnNpc("guard", x = 3244, y = 3500) -spawnNpc("guard", x = 3247, y = 3503) - -// East Guards - -spawnNpc("guard", x = 3271, y = 3431) -spawnNpc("guard", x = 3270, y = 3425) -spawnNpc("guard", x = 3274, y = 3421) -spawnNpc("guard", x = 3274, y = 3427) - -// South Guards - -spawnNpc("guard", x = 3210, y = 3382) -spawnNpc("guard", x = 3212, y = 3380) -spawnNpc("guard", x = 3207, y = 3376) - -// West Guards - -spawnNpc("guard", x = 3174, y = 3427) -spawnNpc("guard", x = 3176, y = 3430) -spawnNpc("guard", x = 3176, y = 3427) -spawnNpc("guard", x = 3180, y = 3399) -spawnNpc("guard", x = 3175, y = 3415, z = 1) -spawnNpc("guard", x = 3174, y = 3403, z = 1) - -// Varrock Palace - -spawnNpc("guard", x = 3210, y = 3461) -spawnNpc("guard", x = 3211, y = 3465) -spawnNpc("guard", x = 3214, y = 3462) -spawnNpc("guard", x = 3216, y = 3464) -spawnNpc("guard", x = 3220, y = 3461) -spawnNpc("guard", x = 3206, y = 3461) -spawnNpc("guard", x = 3204, y = 3495) - -spawnNpc("guard", x = 3204, y = 3495, z = 1) -spawnNpc("guard", x = 3205, y = 3492, z = 1) -spawnNpc("guard", x = 3203, y = 3492, z = 1) -spawnNpc("guard", x = 3205, y = 3497, z = 1) - -spawnNpc("guard", x = 3221, y = 3471, z = 2) -spawnNpc("guard", x = 3214, y = 3474, z = 2) -spawnNpc("guard", x = 3215, y = 3471, z = 2) -spawnNpc("guard", x = 3211, y = 3471, z = 2) -spawnNpc("guard", x = 3209, y = 3473, z = 2) -spawnNpc("guard", x = 3212, y = 3475, z = 2) -spawnNpc("guard", x = 3207, y = 3477, z = 2) -spawnNpc("guard", x = 3203, y = 3476, z = 2) -spawnNpc("guard", x = 3205, y = 3479, z = 2) -spawnNpc("guard", x = 3203, y = 3483, z = 2) -spawnNpc("guard", x = 3221, y = 3485, z = 2) - -spawnNpc("monk_of_zamorak", id = 189, x = 3213, y = 3476) - -spawnNpc("warrior_woman", x = 3203, y = 3490) -spawnNpc("warrior_woman", x = 3205, y = 3493) - -// Varrock/Lumbridge Pen - -spawnNpc("swan", x = 3261, y = 3354) -spawnNpc("swan", x = 3260, y = 3356) - -spawnNpc("ram", id = 3673, x = 3238, y = 3346) -spawnNpc("ram", id = 3673, x = 3248, y = 3352) -spawnNpc("ram", id = 3673, x = 3260, y = 3348) - -spawnNpc("sheep", id = 42, x = 3263, y = 3347) -spawnNpc("sheep", id = 42, x = 3268, y = 3350) -spawnNpc("sheep", id = 42, x = 3252, y = 3352) -spawnNpc("sheep", id = 42, x = 3243, y = 3344) -spawnNpc("sheep", id = 42, x = 3235, y = 3347) - -spawnNpc("sheep", id = 3579, x = 3234, y = 3344) -spawnNpc("sheep", id = 3579, x = 3241, y = 3347) -spawnNpc("sheep", id = 3579, x = 3257, y = 3350) - -// Champions Guild - -spawnNpc("chicken", x = 3195, y = 3359) -spawnNpc("chicken", x = 3198, y = 3356) -spawnNpc("chicken", x = 3195, y = 3355) - -spawnNpc("chicken", id = 1017, x = 3196, y = 3353) -spawnNpc("chicken", id = 1017, x = 3197, y = 3356) - -spawnNpc("evil_chicken", x = 3198, y = 3359) - -// Function Npc - -spawnNpc("apothecary", x = 3196, y = 3403) - -spawnNpc("captain_rovin", x = 3204, y = 3496, z = 2) - -spawnNpc("curator", x = 3256, y = 3447) - -spawnNpc("dimintheis", x = 3280, y = 3403) - -spawnNpc("dr_harlow", x = 3224, y = 3398) - -spawnNpc("ellamaria", x = 3228, y = 3475) - -spawnNpc("father_lawrence", x = 3253, y = 3484) - -spawnNpc("guidors_wife", id = 342, x = 3280, y = 3382) - -spawnNpc("guidor", x = 3284, y = 3381, facing = Direction.SOUTH) - -spawnNpc("guild_master", x = 3189, y = 3360) - -spawnNpc("gypsy", x = 3203, y = 3423) - -spawnNpc("hooknosed_jack", x = 3268, y = 3400) - -spawnNpc("jonny_the_beard", x = 3223, y = 3395) - -spawnNpc("johnathon", x = 3278, y = 3503, z = 1) - -spawnNpc("katrine", x = 3185, y = 3386) - -spawnNpc("king_roald", x = 3223, y = 3473) - -spawnNpc("master_farmer", x = 3243, y = 3349) - -spawnNpc("pox", x = 3267, y = 3399) - -spawnNpc("reldo", x = 3210, y = 3492) - -spawnNpc("romeo", x = 3211, y = 3423) - -spawnNpc("shilop", x = 3211, y = 3435) - -spawnNpc("sir_prysin", x = 3204, y = 3472) - -spawnNpc("tarquin", x = 3203, y = 3344, facing = Direction.SOUTH) - -spawnNpc("tool_leprechaun", x = 3182, y = 3355) - -spawnNpc("tool_leprechaun", x = 3229, y = 3455) - -spawnNpc("tramp", id = 641, x = 3207, y = 3392) - -spawnNpc("wilough", x = 3222, y = 3437) - -// Shop Npc - -spawnNpc("aubury", x = 3253, y = 3401) - -spawnNpc("baraek", x = 3217, y = 3434) - -spawnNpc("bartender", x = 3226, y = 3400) - -spawnNpc("bartender", id = 1921, x = 3277, y = 3487) - -spawnNpc("fancy_dress_shop_owner", x = 3281, y = 3398) - -spawnNpc("horvik", x = 3229, y = 3438) - -spawnNpc("lowe", x = 3233, y = 3421) - -spawnNpc("scavvo", x = 3192, y = 3353, z = 1) - -spawnNpc("shop_keeper", id = 551, x = 3206, y = 3399) -spawnNpc("shop_assistant", id = 552, x = 3207, y = 3396) - -spawnNpc("shop_keeper", id = 522, x = 3216, y = 3414) -spawnNpc("shop_assistant", id = 523, x = 3216, y = 3417) - -spawnNpc("tea_seller", x = 3271, y = 3411) - -spawnNpc("thessalia", x = 3206, y = 3417) - -spawnNpc("zaff", x = 3203, y = 3434) - -// Juliet House - -spawnNpc("draul_leptoc", x = 3228, y = 3475) -spawnNpc("juliet", x = 3159, y = 3425, z = 1) -spawnNpc("phillipa", x = 3160, y = 3429, z = 1) - -// Gertrude House - -spawnNpc("gertrude", x = 3153, y = 3413) -spawnNpc("kanel", x = 3155, y = 3405, facing = Direction.EAST) -spawnNpc("philop", x = 3150, y = 3405, facing = Direction.SOUTH) - -// Small Bank - -spawnNpc("banker", id = 495, x = 3252, y = 3418) -spawnNpc("banker", id = 494, x = 3252, y = 3418) -spawnNpc("banker", id = 494, x = 3252, y = 3418) -spawnNpc("banker", id = 494, x = 3252, y = 3418) - -// Big Bank - -spawnNpc("banker", id = 494, x = 3187, y = 3436, facing = Direction.WEST) -spawnNpc("banker", id = 494, x = 3187, y = 3440, facing = Direction.WEST) -spawnNpc("banker", id = 494, x = 3187, y = 3444, facing = Direction.WEST) -spawnNpc("banker", id = 495, x = 3187, y = 3438, facing = Direction.WEST) -spawnNpc("banker", id = 495, x = 3187, y = 3442, facing = Direction.WEST) \ No newline at end of file diff --git a/game/plugin/locations/varrock/src/shops.plugin.kts b/game/plugin/locations/varrock/src/shops.plugin.kts deleted file mode 100644 index cc3d14881..000000000 --- a/game/plugin/locations/varrock/src/shops.plugin.kts +++ /dev/null @@ -1,176 +0,0 @@ -package org.apollo.plugin.locations.varrock - -import org.apollo.game.plugin.shops.builder.shop - -shop("Aubury's Rune Shop.") { - operated by "Aubury" - - category("runes") { - sell(5000) of { - -"Earth" - -"Water" - -"Fire" - -"Air" - -"Mind" - -"Body" - } - - sell(250) of { - -"Chaos" - -"Death" - } - } -} - -shop("Lowe's Archery Emporium.") { - operated by "Lowe" - - category("arrows") { - sell(2000) of "Bronze" - sell(1500) of "Iron" - sell(1000) of "Steel" - sell(800) of "Mithril" - sell(600) of "Adamant" - } - - category("normal weapons", affix = nothing) { - sell(4) of "Shortbow" - sell(4) of "Longbow" - sell(2) of "Crossbow" - } - - category("shortbows") { - sell(3) of "Oak" - sell(2) of "Willow" - sell(1) of "Maple" - } - - category("longbows") { - sell(3) of "Oak" - sell(2) of "Willow" - sell(1) of "Maple" - } -} - -shop("Horvik's Armour Shop.") { - operated by "Horvik" - - category("chainbody") { - sell(5) of "Bronze" - sell(3) of "Iron" - sell(3) of "Steel" - sell(1) of "Mithril" - } - - category("platebody") { - sell(3) of "Bronze" - - sell(1) of { - -"Iron" - -"Steel" - -"Black" - -"Mithril" - } - } - - sell(1) of { - -"Iron platelegs" - -"Studded body" - -"Studded chaps" - } -} - -shop("Thessalia's Fine Clothes.") { - operated by "Thessalia" - - category("apron") { - sell(3) of "White" - sell(1) of "Brown" - } - - category("leather", affix = prefix) { - sell(12) of "Body" - sell(10) of "Gloves" - sell(10) of "Boots" - } - - category("skirt") { - sell(5) of "Pink" - sell(3) of "Black" - sell(2) of "Blue" - } - - sell(4) of "Cape" - sell(5) of "Silk" - - sell(3) of { - -"Priest gown"(426) - -"Priest gown"(428) - } -} - -shop("Varrock General Store.") { - operated by "Shopkeeper"(522) and "Shop assistant"(523) - buys any items - - sell(5) of "Pot" - sell(2) of "Jug" - sell(2) of "Shears" - sell(3) of "Bucket" - sell(2) of "Bowl" - sell(2) of "Cake tin" - sell(2) of "Tinderbox" - sell(2) of "Chisel" - sell(5) of "Hammer" - sell(5) of "Newcomer map" -} - -shop("Varrock Swordshop.") { - operated by "Shopkeeper"(551) and "Shop assistant"(552) - - category("swords") { - sell(5) of "Bronze" - sell(4) of "Iron" - sell(4) of "Steel" - sell(3) of "Black" - sell(3) of "Mithril" - sell(2) of "Adamant" - } - - category("longswords") { - sell(4) of "Bronze" - sell(3) of "Iron" - sell(3) of "Steel" - sell(2) of "Black" - sell(2) of "Mithril" - sell(1) of "Adamant" - } - - category("daggers") { - sell(10) of "Bronze" - sell(6) of "Iron" - sell(5) of "Steel" - sell(4) of "Black" - sell(3) of "Mithril" - sell(2) of "Adamant" - } -} - -shop("Zaff's Superior Staffs!") { - operated by "Zaff" - - category("staves", affix = nothing) { - sell(5) of { - -"Battlestaff" - -"Staff" - -"Magic staff" - } - - sell(2) of { - -"Staff of air" - -"Staff of water" - -"Staff of earth" - -"Staff of fire" - } - } -} diff --git a/game/src/main/java/org/apollo/Server.java b/game/src/main/java/org/apollo/Server.java index 348711a78..55a53175f 100644 --- a/game/src/main/java/org/apollo/Server.java +++ b/game/src/main/java/org/apollo/Server.java @@ -1,14 +1,5 @@ package org.apollo; -import java.io.IOException; -import java.net.BindException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.file.Paths; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; - import com.google.common.base.Stopwatch; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; @@ -16,7 +7,7 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.game.model.World; import org.apollo.game.plugin.PluginContext; import org.apollo.game.plugin.PluginManager; @@ -28,6 +19,16 @@ import org.apollo.net.ServiceChannelInitializer; import org.apollo.net.release.Release; +import java.io.IOException; +import java.net.BindException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * The core class of the Apollo server. * @@ -52,11 +53,10 @@ public static void main(String[] args) { Server server = new Server(); server.init(args.length == 1 ? args[0] : Release377.class.getName()); - SocketAddress service = new InetSocketAddress(NetworkConstants.SERVICE_PORT); - SocketAddress http = new InetSocketAddress(NetworkConstants.HTTP_PORT); - SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT); - - server.bind(service, http, jaggrab); + server.bind(new InetSocketAddress(NetworkConstants.HTTP_PORT), + new InetSocketAddress(NetworkConstants.JAGGRAB_PORT), + new InetSocketAddress(NetworkConstants.GAME_PORT), + new InetSocketAddress(NetworkConstants.UPDATE_PORT)); } catch (Throwable t) { logger.log(Level.SEVERE, "Error whilst starting server.", t); System.exit(0); @@ -95,14 +95,14 @@ public Server() { /** * Binds the server to the specified address. * - * @param service The service address to bind to. - * @param http The HTTP address to bind to. - * @param jaggrab The JAGGRAB address to bind to. + * @param services The service addresses to bind to. + * @param http The HTTP address to bind to. + * @param jaggrab The JAGGRAB address to bind to. * @throws BindException If the ServerBootstrap fails to bind to the SocketAddress. */ - public void bind(SocketAddress service, SocketAddress http, SocketAddress jaggrab) throws IOException { - logger.fine("Binding service listener to address: " + service + "..."); - bind(serviceBootstrap, service); + public void bind(SocketAddress http, SocketAddress jaggrab, SocketAddress... services) throws IOException { + logger.fine("Binding service listener to address: " + Arrays.toString(services) + "..."); + bind(serviceBootstrap, services); try { logger.fine("Binding HTTP listener to address: " + http + "..."); @@ -136,7 +136,7 @@ public void init(String releaseName) throws Exception { World world = new World(); ServiceManager services = new ServiceManager(world); - IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs", Integer.toString(version)), true); + Cache fs = Cache.openCache(Paths.get("data/fs", Integer.toString(version))); ServerContext context = new ServerContext(release, services, fs); ApolloHandler handler = new ApolloHandler(context); @@ -162,15 +162,16 @@ public void init(String releaseName) throws Exception { * Attempts to bind the specified ServerBootstrap to the specified SocketAddress. * * @param bootstrap The ServerBootstrap. - * @param address The SocketAddress. + * @param addresses The SocketAddress. * @throws IOException If the ServerBootstrap fails to bind to the SocketAddress. */ - private void bind(ServerBootstrap bootstrap, SocketAddress address) throws IOException { - try { - bootstrap.bind(address).sync(); - } catch (Exception cause) { - throw new IOException("Failed to bind to " + address, cause); + private void bind(ServerBootstrap bootstrap, SocketAddress... addresses) throws IOException { + for (SocketAddress address : addresses) { + try { + bootstrap.bind(address).sync(); + } catch (Exception cause) { + throw new IOException("Failed to bind to " + address, cause); + } } } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/ServerContext.java b/game/src/main/java/org/apollo/ServerContext.java index 4eaf355ba..778acb9f9 100644 --- a/game/src/main/java/org/apollo/ServerContext.java +++ b/game/src/main/java/org/apollo/ServerContext.java @@ -1,13 +1,13 @@ package org.apollo; -import java.util.Objects; - -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.game.service.GameService; import org.apollo.game.service.LoginService; import org.apollo.game.service.UpdateService; import org.apollo.net.release.Release; +import java.util.Objects; + /** * A {@link ServerContext} is created along with the {@link Server} object. The primary difference is that a reference * to the current context should be passed around within the server. The {@link Server} should not be as it allows @@ -21,7 +21,7 @@ public final class ServerContext { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fileSystem; + private final Cache fileSystem; /** * The current release. @@ -40,7 +40,7 @@ public final class ServerContext { * @param services The service manager. * @param fileSystem The indexed file system. */ - protected ServerContext(Release release, ServiceManager services, IndexedFileSystem fileSystem) { + protected ServerContext(Release release, ServiceManager services, Cache fileSystem) { this.release = Objects.requireNonNull(release); this.services = Objects.requireNonNull(services); this.services.setContext(this); @@ -52,7 +52,7 @@ protected ServerContext(Release release, ServiceManager services, IndexedFileSys * * @return The IndexedFileSystem. */ - public IndexedFileSystem getFileSystem() { + public Cache getFileSystem() { return fileSystem; } diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java index 8162842aa..b4fa4e3c8 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java @@ -1,9 +1,9 @@ package org.apollo.game.fs.decoder; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.cache.map.MapConstants; import org.apollo.cache.map.MapFile; -import org.apollo.cache.map.MapFileDecoder; +import org.apollo.cache.map.MapTerrainDecoder; import org.apollo.cache.map.MapIndex; import org.apollo.cache.map.MapPlane; import org.apollo.cache.map.Tile; @@ -31,9 +31,9 @@ public final class WorldMapDecoder implements Runnable { private static final int BRIDGE_TILE = 0x2; /** - * The {@link IndexedFileSystem}. + * The {@link Cache}. */ - private IndexedFileSystem fs; + private Cache fs; /** * The {@link CollisionManager} to notify of bridged / blocked tiles. @@ -43,10 +43,10 @@ public final class WorldMapDecoder implements Runnable { /** * Create a new {@link WorldMapDecoder}. * - * @param fs The {@link IndexedFileSystem} to load {@link MapFile}s. from. + * @param fs The {@link Cache} to load {@link MapFile}s. from. * @param collisionManager The {@link CollisionManager} to register tiles with. */ - public WorldMapDecoder(IndexedFileSystem fs, CollisionManager collisionManager) { + public WorldMapDecoder(Cache fs, CollisionManager collisionManager) { this.fs = fs; this.collisionManager = collisionManager; } @@ -61,7 +61,7 @@ public void run() { try { for (MapIndex index : mapIndices.values()) { - MapFileDecoder decoder = MapFileDecoder.create(fs, index); + MapTerrainDecoder decoder = MapTerrainDecoder.create(index); MapFile mapFile = decoder.decode(); MapPlane[] mapPlanes = mapFile.getPlanes(); diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java index 2b8d01eb5..61244b618 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java @@ -1,9 +1,9 @@ package org.apollo.game.fs.decoder; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.cache.map.MapIndex; +import org.apollo.cache.map.MapLandscapeDecoder; import org.apollo.cache.map.MapObject; -import org.apollo.cache.map.MapObjectsDecoder; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.Region; @@ -20,9 +20,9 @@ */ public final class WorldObjectsDecoder implements Runnable { /** - * The IndexedFileSystem. + * The Cache. */ - private final IndexedFileSystem fs; + private final Cache cache; /** * The {@link RegionRepository} to lookup {@link Region}s from. @@ -37,12 +37,12 @@ public final class WorldObjectsDecoder implements Runnable { /** * Create a new {@link WorldObjectsDecoder}. * - * @param fs The {@link IndexedFileSystem} to load object files from. + * @param cache The {@link Cache} to load object files from. * @param world The {@link World} to register objects with. * @param regionRepository The {@link RegionRepository} to lookup {@link Region}s from. */ - public WorldObjectsDecoder(IndexedFileSystem fs, World world, RegionRepository regionRepository) { - this.fs = fs; + public WorldObjectsDecoder(Cache cache, World world, RegionRepository regionRepository) { + this.cache = cache; this.world = world; this.regionRepository = regionRepository; } @@ -56,7 +56,7 @@ public void run() { try { for (MapIndex index : mapIndices.values()) { - MapObjectsDecoder decoder = MapObjectsDecoder.create(fs, index); + MapLandscapeDecoder decoder = MapLandscapeDecoder.create(index); List objects = decoder.decode(); int mapX = index.getX(), mapY = index.getY(); diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index 5d5adb0f8..87a9f7177 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -1,15 +1,13 @@ package org.apollo.game.model; -import java.util.*; -import java.util.logging.Logger; - import com.google.common.base.Preconditions; import org.apollo.Service; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.cache.decoder.ItemDefinitionDecoder; import org.apollo.cache.decoder.NpcDefinitionDecoder; import org.apollo.cache.decoder.ObjectDefinitionDecoder; import org.apollo.cache.map.MapIndexDecoder; +import org.apollo.cache.map.XteaDecoder; import org.apollo.game.command.CommandDispatcher; import org.apollo.game.fs.decoder.SynchronousDecoder; import org.apollo.game.fs.decoder.WorldMapDecoder; @@ -19,11 +17,7 @@ import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.game.model.area.collision.CollisionUpdateListener; -import org.apollo.game.model.entity.Entity; -import org.apollo.game.model.entity.EntityType; -import org.apollo.game.model.entity.MobRepository; -import org.apollo.game.model.entity.Npc; -import org.apollo.game.model.entity.Player; +import org.apollo.game.model.entity.*; import org.apollo.game.model.event.Event; import org.apollo.game.model.event.EventListener; import org.apollo.game.model.event.EventListenerChainSet; @@ -33,6 +27,9 @@ import org.apollo.game.scheduling.impl.NpcMovementTask; import org.apollo.util.NameUtil; +import java.util.*; +import java.util.logging.Logger; + /** * The world class is a singleton which contains objects like the {@link MobRepository} for players and NPCs. It should * only contain things relevant to the in-game world and not classes which deal with I/O and such (these may be better @@ -213,26 +210,26 @@ public int getReleaseNumber() { * system. * * @param release The release number. - * @param fs The file system. + * @param cache The file system. * @param manager The plugin manager. TODO move this. * @throws Exception If there was a failure when loading plugins. */ - public void init(int release, IndexedFileSystem fs, PluginManager manager) throws Exception { + public void init(int release, Cache cache, PluginManager manager) throws Exception { releaseNumber = release; SynchronousDecoder firstStageDecoder = new SynchronousDecoder( - new NpcDefinitionDecoder(fs), - new ItemDefinitionDecoder(fs), - new ObjectDefinitionDecoder(fs), - new MapIndexDecoder(fs), + new NpcDefinitionDecoder(cache), + new ItemDefinitionDecoder(cache), + new ObjectDefinitionDecoder(cache), + new MapIndexDecoder(cache, new XteaDecoder(release)), EquipmentDefinitionParser.fromFile("data/equipment-" + release + "" + ".dat") ); firstStageDecoder.block(); SynchronousDecoder secondStageDecoder = new SynchronousDecoder( - new WorldObjectsDecoder(fs, this, regions), - new WorldMapDecoder(fs, collisionManager) + new WorldObjectsDecoder(cache, this, regions), + new WorldMapDecoder(cache, collisionManager) ); secondStageDecoder.block(); diff --git a/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java b/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java index d8a428ff7..47703a26b 100644 --- a/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java +++ b/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java @@ -65,11 +65,11 @@ public void build(boolean rebuilding) { } } - regions.getRegions().forEach(region -> { + regions.getRegions().parallelStream().forEach(region -> { CollisionUpdate.Builder builder = new CollisionUpdate.Builder(); builder.type(CollisionUpdateType.ADDING); - blocked.get(region.getCoordinates()).forEach(tile -> { + for (var tile : blocked.get(region.getCoordinates())) { int x = tile.getX(), y = tile.getY(); int height = tile.getHeight(); @@ -80,7 +80,7 @@ public void build(boolean rebuilding) { if (height >= 0) { builder.tile(new Position(x, y, height), false, Direction.NESW); } - }); + } apply(builder.build()); diff --git a/game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java b/game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java new file mode 100644 index 000000000..1eacdc43c --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java @@ -0,0 +1,126 @@ +package org.apollo.game.release.r181; + +import org.apollo.net.meta.PacketMetaDataGroup; +import org.apollo.net.release.Release; + +import java.util.Arrays; + +public class ReleaseOSRS181 extends Release { + + private static final int[] PACKET_LENGTHS = new int[256]; + + static { + PACKET_LENGTHS[0] = 8; + PACKET_LENGTHS[1] = 3; + PACKET_LENGTHS[2] = 14; + PACKET_LENGTHS[3] = 7; + PACKET_LENGTHS[4] = -1; + PACKET_LENGTHS[5] = 7; + PACKET_LENGTHS[6] = 7; + PACKET_LENGTHS[7] = 8; + PACKET_LENGTHS[8] = -1; + PACKET_LENGTHS[9] = 4; + PACKET_LENGTHS[10] = 7; + PACKET_LENGTHS[11] = 10; + PACKET_LENGTHS[12] = 13; + PACKET_LENGTHS[13] = -1; + PACKET_LENGTHS[14] = 8; + PACKET_LENGTHS[15] = 3; + PACKET_LENGTHS[16] = -2; + PACKET_LENGTHS[17] = 4; + PACKET_LENGTHS[18] = 15; + PACKET_LENGTHS[19] = 8; + PACKET_LENGTHS[20] = 0; + PACKET_LENGTHS[21] = 8; + PACKET_LENGTHS[22] = 0; + PACKET_LENGTHS[23] = 11; + PACKET_LENGTHS[24] = 2; + PACKET_LENGTHS[25] = -2; + PACKET_LENGTHS[26] = 8; + PACKET_LENGTHS[27] = 3; + PACKET_LENGTHS[28] = -1; + PACKET_LENGTHS[29] = 7; + PACKET_LENGTHS[30] = 2; + PACKET_LENGTHS[31] = 3; + PACKET_LENGTHS[32] = 8; + PACKET_LENGTHS[33] = 3; + PACKET_LENGTHS[34] = -1; + PACKET_LENGTHS[35] = 5; + PACKET_LENGTHS[36] = 2; + PACKET_LENGTHS[37] = 0; + PACKET_LENGTHS[38] = -1; + PACKET_LENGTHS[39] = 4; + PACKET_LENGTHS[40] = 8; + PACKET_LENGTHS[41] = 6; + PACKET_LENGTHS[42] = 2; + PACKET_LENGTHS[43] = -1; + PACKET_LENGTHS[44] = 15; + PACKET_LENGTHS[45] = 4; + PACKET_LENGTHS[46] = 8; + PACKET_LENGTHS[47] = 3; + PACKET_LENGTHS[48] = 8; + PACKET_LENGTHS[49] = 0; + PACKET_LENGTHS[50] = 3; + PACKET_LENGTHS[51] = 7; + PACKET_LENGTHS[52] = -1; + PACKET_LENGTHS[53] = 13; + PACKET_LENGTHS[54] = -1; + PACKET_LENGTHS[55] = 9; + PACKET_LENGTHS[56] = 3; + PACKET_LENGTHS[57] = 16; + PACKET_LENGTHS[58] = 8; + PACKET_LENGTHS[59] = 3; + PACKET_LENGTHS[60] = -1; + PACKET_LENGTHS[61] = 9; + PACKET_LENGTHS[62] = 3; + PACKET_LENGTHS[63] = 16; + PACKET_LENGTHS[64] = 8; + PACKET_LENGTHS[65] = 8; + PACKET_LENGTHS[66] = 8; + PACKET_LENGTHS[67] = -2; + PACKET_LENGTHS[68] = 8; + PACKET_LENGTHS[69] = 4; + PACKET_LENGTHS[70] = 6; + PACKET_LENGTHS[71] = 3; + PACKET_LENGTHS[72] = 8; + PACKET_LENGTHS[73] = 1; + PACKET_LENGTHS[74] = 7; + PACKET_LENGTHS[75] = 3; + PACKET_LENGTHS[76] = 0; + PACKET_LENGTHS[77] = -1; + PACKET_LENGTHS[78] = -1; + PACKET_LENGTHS[79] = 7; + PACKET_LENGTHS[80] = 9; + PACKET_LENGTHS[81] = 11; + PACKET_LENGTHS[82] = 16; + PACKET_LENGTHS[83] = 3; + PACKET_LENGTHS[84] = 8; + PACKET_LENGTHS[85] = 8; + PACKET_LENGTHS[86] = 9; + PACKET_LENGTHS[87] = 8; + PACKET_LENGTHS[88] = -1; + PACKET_LENGTHS[89] = 7; + PACKET_LENGTHS[90] = -1; + PACKET_LENGTHS[91] = -1; + PACKET_LENGTHS[92] = 13; + PACKET_LENGTHS[93] = 3; + PACKET_LENGTHS[94] = 7; + PACKET_LENGTHS[95] = -1; + PACKET_LENGTHS[96] = -1; + PACKET_LENGTHS[97] = -1; + PACKET_LENGTHS[98] = 8; + PACKET_LENGTHS[99] = 7; + } + + /** + * Creates the release. + */ + public ReleaseOSRS181() { + super(181, PacketMetaDataGroup.createFromArray(PACKET_LENGTHS)); + init(); + } + + private void init() { + //TODO register completed client prot here. + } +} diff --git a/game/src/main/java/org/apollo/game/service/UpdateService.java b/game/src/main/java/org/apollo/game/service/UpdateService.java index dacd37fe0..df4f99207 100644 --- a/game/src/main/java/org/apollo/game/service/UpdateService.java +++ b/game/src/main/java/org/apollo/game/service/UpdateService.java @@ -1,23 +1,17 @@ package org.apollo.game.service; -import java.io.FileNotFoundException; +import org.apollo.Service; +import org.apollo.cache.Cache; +import org.apollo.net.update.*; + import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.logging.Level; import java.util.logging.Logger; -import org.apollo.Service; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.net.update.HttpRequestWorker; -import org.apollo.net.update.JagGrabRequestWorker; -import org.apollo.net.update.OnDemandRequestWorker; -import org.apollo.net.update.RequestWorker; -import org.apollo.net.update.UpdateDispatcher; - /** * A class which services file requests. * @@ -66,17 +60,12 @@ public UpdateDispatcher getDispatcher() { @Override public void start() { - int release = context.getRelease().getReleaseNumber(); - try { - Path base = Paths.get("data/fs/", Integer.toString(release)); - - for (int i = 0; i < THREADS_PER_TYPE; i++) { - workers.add(new JagGrabRequestWorker(dispatcher, new IndexedFileSystem(base, true))); - workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true))); - workers.add(new HttpRequestWorker(dispatcher, new IndexedFileSystem(base, true))); - } - } catch (FileNotFoundException reason) { - logger.log(Level.SEVERE, "Unable to find index or data files from the file system.", reason); + Path base = Paths.get("data/fs/", Integer.toString(context.getRelease().getReleaseNumber())); + final var cache = Cache.openCache(base); + for (int i = 0; i < THREADS_PER_TYPE; i++) { + workers.add(new JagGrabRequestWorker(dispatcher, cache)); + workers.add(new OnDemandRequestWorker(dispatcher, cache)); + workers.add(new HttpRequestWorker(dispatcher, cache)); } workers.forEach(service::submit); diff --git a/game/src/main/java/org/apollo/game/session/LoginSession.java b/game/src/main/java/org/apollo/game/session/LoginSession.java index a87e48968..f454abcac 100644 --- a/game/src/main/java/org/apollo/game/session/LoginSession.java +++ b/game/src/main/java/org/apollo/game/session/LoginSession.java @@ -1,15 +1,10 @@ package org.apollo.game.session; +import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; - -import java.io.IOException; -import java.util.Optional; - import org.apollo.ServerContext; import org.apollo.game.io.player.PlayerLoaderResponse; -import org.apollo.game.model.World.RegistrationStatus; import org.apollo.game.model.entity.Player; import org.apollo.game.service.GameService; import org.apollo.game.service.LoginService; @@ -23,6 +18,10 @@ import org.apollo.net.release.Release; import org.apollo.util.security.IsaacRandomPair; +import java.io.IOException; +import java.security.SecureRandom; +import java.util.Optional; + /** * A login session. * @@ -30,6 +29,11 @@ */ public final class LoginSession extends Session { + /** + * The secure random number generator. + */ + private static final SecureRandom RANDOM = new SecureRandom(); + /** * The ServerContext. */ @@ -40,6 +44,11 @@ public final class LoginSession extends Session { */ private LoginRequest request; + /** + * The key assigned for this session. + */ + private long serverSessionKey = RANDOM.nextLong(); + /** * Creates a login session for the specified channel. * @@ -49,6 +58,13 @@ public final class LoginSession extends Session { public LoginSession(Channel channel, ServerContext context) { super(channel); this.context = context; + init(); + } + + private void init() { + ByteBuf buf = channel.alloc().buffer(Long.BYTES); + buf.writeLong(serverSessionKey); + channel.write(new LoginResponse(LoginConstants.STATUS_EXCHANGE_DATA, buf)); } @Override @@ -59,7 +75,7 @@ public void destroy() { /** * Handles a response from the login service. * - * @param request The request this response corresponds to. + * @param request The request this response corresponds to. * @param response The response. */ public void handlePlayerLoaderResponse(LoginRequest request, PlayerLoaderResponse response) { @@ -87,9 +103,7 @@ public void messageReceived(Object message) throws Exception { * @param status The failure status. */ public void sendLoginFailure(int status) { - boolean flagged = false; - LoginResponse response = new LoginResponse(status, 0, flagged); - channel.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); + channel.writeAndFlush(new LoginResponse(status)).addListener(ChannelFutureListener.CLOSE); } /** @@ -106,12 +120,13 @@ public void sendLoginSuccess(Player player) { player.setSession(session); int rights = player.getPrivilegeLevel().toInteger(); - channel.writeAndFlush(new LoginResponse(LoginConstants.STATUS_OK, rights, flagged)); + channel.writeAndFlush(new LoginResponse(LoginConstants.STATUS_OK, session.getChannel().alloc().buffer())); Release release = context.getRelease(); channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release)); - channel.pipeline().addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom())); + channel.pipeline() + .addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom())); channel.pipeline().addBefore("handler", "gameDecoder", new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease())); diff --git a/game/src/main/java/org/apollo/game/session/UpdateSession.java b/game/src/main/java/org/apollo/game/session/UpdateSession.java index a6e1a6c8f..08e33d4b4 100644 --- a/game/src/main/java/org/apollo/game/session/UpdateSession.java +++ b/game/src/main/java/org/apollo/game/session/UpdateSession.java @@ -1,10 +1,14 @@ package org.apollo.game.session; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; import io.netty.handler.codec.http.HttpRequest; - import org.apollo.ServerContext; import org.apollo.net.codec.jaggrab.JagGrabRequest; +import org.apollo.net.codec.login.LoginConstants; +import org.apollo.net.codec.update.OnDemandInfo; +import org.apollo.net.codec.update.OnDemandInfoResponse; import org.apollo.net.codec.update.OnDemandRequest; import org.apollo.net.update.UpdateDispatcher; @@ -19,6 +23,7 @@ public final class UpdateSession extends Session { * The server context. */ private final ServerContext context; + private boolean handshakeComplete; /** * Creates an update session for the specified channel. @@ -40,8 +45,27 @@ public void destroy() { public void messageReceived(Object message) { UpdateDispatcher dispatcher = context.getUpdateService().getDispatcher(); + if (message instanceof OnDemandRequest) { - dispatcher.dispatch(getChannel(), (OnDemandRequest) message); + if (handshakeComplete) { + dispatcher.dispatch(getChannel(), (OnDemandRequest) message); + } + } else if (message instanceof OnDemandInfo) { + OnDemandInfo info = (OnDemandInfo) message; + + int status; + if (info.getReleaseNumber() == 181) {//context.getRelease().getReleaseNumber() + status = LoginConstants.STATUS_EXCHANGE_DATA; + } else { + status = LoginConstants.STATUS_GAME_UPDATED; + } + + ChannelFuture future = channel.write(new OnDemandInfoResponse(status)); + if (status == LoginConstants.STATUS_EXCHANGE_DATA) { + handshakeComplete = true; + } else { + future.addListener(ChannelFutureListener.CLOSE); + } } else if (message instanceof JagGrabRequest) { dispatcher.dispatch(getChannel(), (JagGrabRequest) message); } else if (message instanceof HttpRequest) { @@ -50,5 +74,4 @@ public void messageReceived(Object message) { throw new IllegalArgumentException("Unknown message type."); } } - } \ No newline at end of file diff --git a/gradle/properties.gradle b/gradle/properties.gradle index 63d32988d..4ebfc745b 100644 --- a/gradle/properties.gradle +++ b/gradle/properties.gradle @@ -1,12 +1,12 @@ ext { - kotlinVersion = '1.3.40' - kotlinxCoroutinesVersion = '1.3.0-M2' + kotlinVersion = '1.3.61' + kotlinxCoroutinesVersion = '1.3.3' junitVersion = '4.12' powermockVersion = '2.0.2' bouncycastleVersion = '1.54' c3p0Version = '0.9.5.2' scryptVersion = '1.4.0' - nettyVersion = '4.0.34.Final' + nettyVersion = '4.1.45.Final' guavaVersion = '19.0' commonsCompressVersion = '1.10' assertjVersion = '3.8.0' diff --git a/net/src/main/java/org/apollo/net/NetworkConstants.java b/net/src/main/java/org/apollo/net/NetworkConstants.java index d91029f07..71e80e1a6 100644 --- a/net/src/main/java/org/apollo/net/NetworkConstants.java +++ b/net/src/main/java/org/apollo/net/NetworkConstants.java @@ -51,9 +51,14 @@ public final class NetworkConstants { public static final BigInteger RSA_MODULUS; /** - * The service port. + * The game port. */ - public static final int SERVICE_PORT; + public static final int GAME_PORT; + + /** + * The update port. + */ + public static final int UPDATE_PORT; static { try (InputStream is = new FileInputStream("data/net.xml")) { @@ -65,12 +70,13 @@ public final class NetworkConstants { XmlNode ports = net.getChild("ports"); Preconditions.checkState(ports != null, "Root node must have a child named 'ports'."); - XmlNode http = ports.getChild("http"), service = ports.getChild("service"), jaggrab = ports.getChild("jaggrab"); - Preconditions.checkState(http != null && service != null && jaggrab != null, "Ports node must have three children: 'http', 'service', and 'jaggrab'."); + XmlNode http = ports.getChild("http"), game = ports.getChild("game"), update = ports.getChild("update"), jaggrab = ports.getChild("jaggrab"); + Preconditions.checkState(http != null && game != null && update != null && jaggrab != null, "Ports node must have four children: 'http', 'game', 'update', and 'jaggrab'."); HTTP_PORT = Integer.parseInt(http.getValue()); - SERVICE_PORT = Integer.parseInt(service.getValue()); JAGGRAB_PORT = Integer.parseInt(jaggrab.getValue()); + GAME_PORT = Integer.parseInt(game.getValue()); + UPDATE_PORT = Integer.parseInt(update.getValue()); } catch (Exception exception) { throw new ExceptionInInitializerError(new IOException("Error parsing net.xml.", exception)); } diff --git a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java index aa768ae8c..7e268781a 100644 --- a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java @@ -3,14 +3,15 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; - -import java.util.List; -import java.util.logging.Logger; - +import org.apollo.net.codec.login.LoginConstants; import org.apollo.net.codec.login.LoginDecoder; import org.apollo.net.codec.login.LoginEncoder; +import org.apollo.net.codec.update.OnDemandInfoEncoder; +import org.apollo.net.codec.update.OnDemandResponseEncoder; import org.apollo.net.codec.update.UpdateDecoder; -import org.apollo.net.codec.update.UpdateEncoder; + +import java.util.List; +import java.util.logging.Logger; /** * A {@link ByteToMessageDecoder} which decodes the handshake and makes changes to the pipeline as appropriate for the @@ -32,21 +33,15 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List ou } int id = buffer.readUnsignedByte(); - switch (id) { case HandshakeConstants.SERVICE_GAME: - ctx.pipeline().addFirst("loginEncoder", new LoginEncoder()); + ctx.pipeline().addFirst(new LoginEncoder()); ctx.pipeline().addAfter("handshakeDecoder", "loginDecoder", new LoginDecoder()); break; - case HandshakeConstants.SERVICE_UPDATE: - ctx.pipeline().addFirst("updateEncoder", new UpdateEncoder()); + ctx.pipeline().addFirst(new OnDemandInfoEncoder(), new OnDemandResponseEncoder()); //OnDemandInfoEncoder ctx.pipeline().addBefore("handler", "updateDecoder", new UpdateDecoder()); - - ByteBuf buf = ctx.alloc().buffer(8).writeLong(0); - ctx.channel().writeAndFlush(buf); break; - default: ByteBuf data = buffer.readBytes(buffer.readableBytes()); logger.info(String.format("Unexpected handshake request received: %d data: %s", id, data.toString())); diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java index b59cc70ea..0c01f7f62 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java @@ -1,17 +1,10 @@ package org.apollo.net.codec.login; +import com.google.common.net.InetAddresses; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; - -import java.math.BigInteger; -import java.net.InetSocketAddress; -import java.security.SecureRandom; -import java.util.List; -import java.util.logging.Logger; - -import org.apollo.cache.FileSystemConstants; import org.apollo.net.NetworkConstants; import org.apollo.util.BufferUtil; import org.apollo.util.StatefulFrameDecoder; @@ -19,7 +12,11 @@ import org.apollo.util.security.IsaacRandomPair; import org.apollo.util.security.PlayerCredentials; -import com.google.common.net.InetAddresses; +import java.math.BigInteger; +import java.net.InetSocketAddress; +import java.security.SecureRandom; +import java.util.List; +import java.util.logging.Logger; /** * A {@link StatefulFrameDecoder} which decodes the login request frames. @@ -33,11 +30,6 @@ public final class LoginDecoder extends StatefulFrameDecoder */ private static final Logger logger = Logger.getLogger(LoginDecoder.class.getName()); - /** - * The secure random number generator. - */ - private static final SecureRandom RANDOM = new SecureRandom(); - /** * The login packet length. */ @@ -62,15 +54,12 @@ public final class LoginDecoder extends StatefulFrameDecoder * Creates the login decoder with the default initial state. */ public LoginDecoder() { - super(LoginDecoderState.LOGIN_HANDSHAKE); + super(LoginDecoderState.LOGIN_HEADER); } @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out, LoginDecoderState state) { switch (state) { - case LOGIN_HANDSHAKE: - decodeHandshake(ctx, in, out); - break; case LOGIN_HEADER: decodeHeader(ctx, in, out); break; @@ -82,37 +71,15 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out, L } } - /** - * Decodes in the handshake state. - * - * @param ctx The channel handler context. - * @param buffer The buffer. - * @param out The {@link List} of objects to pass forward through the pipeline. - */ - private void decodeHandshake(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.isReadable()) { - usernameHash = buffer.readUnsignedByte(); - serverSeed = RANDOM.nextLong(); - - ByteBuf response = ctx.alloc().buffer(17); - response.writeByte(LoginConstants.STATUS_EXCHANGE_DATA); - response.writeLong(0); - response.writeLong(serverSeed); - ctx.channel().write(response); - - setState(LoginDecoderState.LOGIN_HEADER); - } - } - /** * Decodes in the header state. * - * @param ctx The channel handler context. + * @param ctx The channel handler context. * @param buffer The buffer. - * @param out The {@link List} of objects to pass forward through the pipeline. + * @param out The {@link List} of objects to pass forward through the pipeline. */ private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.readableBytes() >= 2) { + if (buffer.readableBytes() >= Byte.BYTES + Integer.BYTES + Integer.BYTES) { int type = buffer.readUnsignedByte(); if (type != LoginConstants.TYPE_STANDARD && type != LoginConstants.TYPE_RECONNECTION) { @@ -121,8 +88,8 @@ private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List out) { if (buffer.readableBytes() >= loginLength) { ByteBuf payload = buffer.readBytes(loginLength); - int version = 255 - payload.readUnsignedByte(); - int release = payload.readUnsignedShort(); + long release = payload.readUnsignedInt(); + long version = payload.readUnsignedInt(); int memoryStatus = payload.readUnsignedByte(); if (memoryStatus != 0 && memoryStatus != 1) { @@ -151,10 +118,6 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List> 32); + seed[1] = (int) clientSeed; + seed[2] = (int) (serverSeed >> 32); + seed[3] = (int) serverSeed; + long reportedSeed = secure.readLong(); if (reportedSeed != serverSeed) { logger.fine("Reported seed differed from server seed."); @@ -196,11 +171,11 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List> 32); - seed[1] = (int) clientSeed; - seed[2] = (int) (serverSeed >> 32); - seed[3] = (int) serverSeed; + int[] crcs = new int[25]; + for (int index = 0; index < 9; index++) { + crcs[index] = payload.readInt(); + } + IsaacRandom decodingRandom = new IsaacRandom(seed); for (int index = 0; index < seed.length; index++) { @@ -219,7 +194,7 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List { + + @Override + protected void encode(ChannelHandlerContext ctx, OnDemandInfoResponse msg, ByteBuf buf) throws Exception { + buf.writeByte(msg.getResponse()); + } +} diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoResponse.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoResponse.java new file mode 100644 index 000000000..6aed25ee5 --- /dev/null +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoResponse.java @@ -0,0 +1,14 @@ +package org.apollo.net.codec.update; + +public class OnDemandInfoResponse { + + private final int response; + + public OnDemandInfoResponse(int response) { + this.response = response; + } + + public int getResponse() { + return response; + } +} diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java index 1ad253eb7..66c816e76 100644 --- a/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java @@ -1,7 +1,5 @@ package org.apollo.net.codec.update; -import org.apollo.cache.FileDescriptor; - /** * Represents a single 'on-demand' request. * @@ -90,7 +88,8 @@ public int toInteger() { /** * The FileDescriptor. */ - private final FileDescriptor descriptor; + private final int fs; + private final int folder; /** * The request Priority. @@ -100,11 +99,13 @@ public int toInteger() { /** * Creates the OnDemandRequest. * - * @param descriptor The {@link FileDescriptor}. + * @param fs The file system. + * @param folder The folder. * @param priority The {@link Priority}. */ - public OnDemandRequest(FileDescriptor descriptor, Priority priority) { - this.descriptor = descriptor; + public OnDemandRequest(int fs, int folder, Priority priority) { + this.fs = fs; + this.folder = folder; this.priority = priority; } @@ -113,13 +114,12 @@ public int compareTo(OnDemandRequest other) { return priority.compareWith(other.priority); } - /** - * Gets the {@link FileDescriptor}. - * - * @return The FileDescriptor. - */ - public FileDescriptor getFileDescriptor() { - return descriptor; + public int getFs() { + return fs; + } + + public int getFolder() { + return folder; } /** diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java index 750331b92..35504259b 100644 --- a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java @@ -1,8 +1,7 @@ package org.apollo.net.codec.update; import io.netty.buffer.ByteBuf; - -import org.apollo.cache.FileDescriptor; +import org.apollo.net.codec.update.OnDemandRequest.Priority; /** * Represents a single 'on-demand' response. @@ -16,33 +15,20 @@ public final class OnDemandResponse { */ private final ByteBuf chunkData; - /** - * The chunk id. - */ - private final int chunkId; - - /** - * The file descriptor. - */ - private final FileDescriptor fileDescriptor; - - /** - * The file size. - */ - private final int fileSize; + private final int fs; + private final int folder; + private final Priority priority; /** * Creates the 'on-demand' response. * - * @param fileDescriptor The file descriptor. - * @param fileSize The file size. - * @param chunkId The chunk id. + * @param fs The file descriptor. * @param chunkData The chunk data. */ - public OnDemandResponse(FileDescriptor fileDescriptor, int fileSize, int chunkId, ByteBuf chunkData) { - this.fileDescriptor = fileDescriptor; - this.fileSize = fileSize; - this.chunkId = chunkId; + public OnDemandResponse(int fs, int folder, Priority priority, ByteBuf chunkData) { + this.fs = fs; + this.folder = folder; + this.priority = priority; this.chunkData = chunkData; } @@ -55,31 +41,15 @@ public ByteBuf getChunkData() { return chunkData; } - /** - * Gets the chunk id. - * - * @return The chunk id. - */ - public int getChunkId() { - return chunkId; + public int getFs() { + return fs; } - /** - * Gets the file descriptor. - * - * @return The file descriptor. - */ - public FileDescriptor getFileDescriptor() { - return fileDescriptor; + public int getFolder() { + return folder; } - /** - * Gets the file size. - * - * @return The file size. - */ - public int getFileSize() { - return fileSize; + public Priority getPriority() { + return priority; } - } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java new file mode 100644 index 000000000..be888724c --- /dev/null +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java @@ -0,0 +1,48 @@ +package org.apollo.net.codec.update; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.netty.handler.codec.MessageToMessageEncoder; + +/** + * A {@link MessageToMessageEncoder} for the 'on-demand' protocol. + * + * @author Graham + */ +public final class OnDemandResponseEncoder extends MessageToByteEncoder { + + @Override + protected void encode(ChannelHandlerContext ctx, OnDemandResponse response, ByteBuf buf) { + int fs = response.getFs(); + int folder = response.getFolder(); + ByteBuf container = response.getChunkData(); + + buf.writeByte(fs); + buf.writeShort(folder); + + int compression = container.readUnsignedByte(); + if (response.getPriority() == OnDemandRequest.Priority.LOW) { + compression |= 0x80; + } + + buf.writeByte(compression); + + int bytes = container.readableBytes(); + if (bytes > 508) + bytes = 508; + + buf.writeBytes(container.readBytes(bytes)); + + for (;;) { + bytes = container.readableBytes(); + if (bytes == 0) + break; + else if (bytes > 511) + bytes = 511; + + buf.writeByte(0xFF); + buf.writeBytes(container.readBytes(bytes)); + } + } +} \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java b/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java index 807435770..64a0f7a58 100644 --- a/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java @@ -3,12 +3,10 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; +import org.apollo.net.codec.update.OnDemandRequest.Priority; import java.util.List; -import org.apollo.cache.FileDescriptor; -import org.apollo.net.codec.update.OnDemandRequest.Priority; - /** * A {@link ByteToMessageDecoder} for the 'on-demand' protocol. * @@ -16,16 +14,32 @@ */ public final class UpdateDecoder extends ByteToMessageDecoder { + private enum State { + READ_VERSION, READ_REQUEST + } + + private State state = State.READ_VERSION; + @Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.readableBytes() >= 4) { - int type = buffer.readUnsignedByte() + 1; - int file = buffer.readUnsignedShort(); - Priority priority = Priority.valueOf(buffer.readUnsignedByte()); + if (!buffer.isReadable( Byte.BYTES + Byte.BYTES + Short.BYTES)) { + return; + } - FileDescriptor desc = new FileDescriptor(type, file); - out.add(new OnDemandRequest(desc, priority)); + if (state == State.READ_VERSION) { + this.state = State.READ_REQUEST; + out.add(new OnDemandInfo(buffer.readUnsignedInt())); + } else { + int opcode = buffer.readUnsignedByte(); + if (opcode == 0 || opcode == 1) { + out.add(new OnDemandRequest(buffer.readUnsignedByte(), buffer.readUnsignedShort(), + Priority.valueOf(opcode))); + } else if (opcode == 4) { + int key = buffer.readUnsignedByte(); + buffer.readerIndex(buffer.readerIndex() + Short.BYTES); + } else { + buffer.readerIndex(buffer.readerIndex() + Byte.BYTES + Short.BYTES); + } } } - } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/update/UpdateEncoder.java b/net/src/main/java/org/apollo/net/codec/update/UpdateEncoder.java deleted file mode 100644 index 5c6592a9d..000000000 --- a/net/src/main/java/org/apollo/net/codec/update/UpdateEncoder.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.net.codec.update; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageEncoder; - -import java.util.List; - -import org.apollo.cache.FileDescriptor; - -/** - * A {@link MessageToMessageEncoder} for the 'on-demand' protocol. - * - * @author Graham - */ -public final class UpdateEncoder extends MessageToMessageEncoder { - - @Override - protected void encode(ChannelHandlerContext ctx, OnDemandResponse response, List out) { - FileDescriptor descriptor = response.getFileDescriptor(); - int fileSize = response.getFileSize(); - int chunkId = response.getChunkId(); - ByteBuf chunkData = response.getChunkData(); - - ByteBuf buffer = ctx.alloc().buffer(2 * Byte.BYTES + 2 * Short.BYTES + chunkData.readableBytes()); - buffer.writeByte(descriptor.getType() - 1); - buffer.writeShort(descriptor.getFile()); - buffer.writeShort(fileSize); - buffer.writeByte(chunkId); - buffer.writeBytes(chunkData); - - out.add(buffer); - } - -} \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java b/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java index 4e9a91a29..ec54fa0fa 100644 --- a/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java +++ b/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java @@ -17,7 +17,7 @@ import java.util.Date; import java.util.Optional; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.net.update.resource.CombinedResourceProvider; import org.apollo.net.update.resource.HypertextResourceProvider; import org.apollo.net.update.resource.ResourceProvider; @@ -53,7 +53,7 @@ public final class HttpRequestWorker extends RequestWorker { - - /** - * The maximum length of a chunk, in {@code byte}s. - */ - private static final int CHUNK_LENGTH = 500; +public final class OnDemandRequestWorker extends RequestWorker { /** * Creates the 'on-demand' request worker. * * @param dispatcher The dispatcher. - * @param fs The file system. + * @param fs The file system. */ - public OnDemandRequestWorker(UpdateDispatcher dispatcher, IndexedFileSystem fs) { + public OnDemandRequestWorker(UpdateDispatcher dispatcher, Cache fs) { super(dispatcher, fs); } @@ -39,16 +32,23 @@ protected ChannelRequest nextRequest(UpdateDispatcher dispatche } @Override - protected void service(IndexedFileSystem fs, Channel channel, OnDemandRequest request) throws IOException { - FileDescriptor descriptor = request.getFileDescriptor(); - ByteBuf buffer = Unpooled.wrappedBuffer(fs.getFile(descriptor)); - int length = buffer.readableBytes(); - - for (int chunk = 0; buffer.readableBytes() > 0; chunk++) { - int chunkSize = Math.min(buffer.readableBytes(), CHUNK_LENGTH); - OnDemandResponse response = new OnDemandResponse(descriptor, length, chunk, buffer.readBytes(chunkSize)); - channel.writeAndFlush(response); + protected void service(Cache cache, Channel channel, OnDemandRequest request) throws IOException { + final var fs = request.getFs(); + final var folder = request.getFolder(); + + ByteBuf buf; + if (fs == 255 && folder == 255) { + buf = Unpooled.wrappedBuffer(cache.generateInformationStoreDescriptor(false).getBuffer()); + } else { + final var store = fs == 255 ? cache.getMasterIndex() : cache.getIndex(fs); + if (store == null) { + return; + } + buf = Unpooled.wrappedBuffer(store.get(folder).getBuffer()); + if (fs != 255) buf = buf.slice(0, buf.readableBytes() - 2); } - } + OnDemandResponse response = new OnDemandResponse(fs, folder, request.getPriority(), buf); + channel.writeAndFlush(response); + } } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java b/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java index 54093b672..a3016fa17 100644 --- a/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java +++ b/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java @@ -7,11 +7,11 @@ import java.util.Objects; import java.util.Optional; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; /** * A {@link ResourceProvider} which maps virtual resources (such as {@code /media}) to files in an - * {@link IndexedFileSystem}. + * {@link Cache}. * * @author Graham */ @@ -25,14 +25,14 @@ public final class VirtualResourceProvider implements ResourceProvider { /** * The file system. */ - private final IndexedFileSystem fs; + private final Cache fs; /** * Creates a new virtual resource provider with the specified file system. * * @param fs The file system. */ - public VirtualResourceProvider(IndexedFileSystem fs) { + public VirtualResourceProvider(Cache fs) { this.fs = fs; } @@ -45,7 +45,7 @@ public boolean accept(String path) throws IOException { @Override public Optional get(String path) throws IOException { - if (path.startsWith("/crc")) { + /*if (path.startsWith("/crc")) { return Optional.of(fs.getCrcTable()); } else if (path.startsWith("/title")) { return Optional.of(fs.getFile(0, 1)); @@ -63,7 +63,7 @@ public Optional get(String path) throws IOException { return Optional.of(fs.getFile(0, 7)); } else if (path.startsWith("/sounds")) { return Optional.of(fs.getFile(0, 8)); - } + }*/ return Optional.empty(); } diff --git a/util/src/main/java/org/apollo/util/BufferUtil.java b/util/src/main/java/org/apollo/util/BufferUtil.java index 146763796..a479e2dcd 100644 --- a/util/src/main/java/org/apollo/util/BufferUtil.java +++ b/util/src/main/java/org/apollo/util/BufferUtil.java @@ -24,6 +24,18 @@ public static int readSmart(ByteBuffer buffer) { return value; } + + public static int readHugeSmart(ByteBuffer buffer) { + int value = 0; + int read; + for (read = readSmart(buffer); read == 32767; read = readSmart(buffer)) { + value += 32767; + } + value += read; + return value; + } + + /** * Reads a string from the specified {@link ByteBuffer}. * From 910a9c6326a614e185d72270c421e0033f233d5a Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 29 Feb 2020 16:13:38 -0500 Subject: [PATCH 02/63] Replaced numeric constant '181' with the release revision. --- game/src/main/java/org/apollo/game/session/UpdateSession.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/src/main/java/org/apollo/game/session/UpdateSession.java b/game/src/main/java/org/apollo/game/session/UpdateSession.java index 08e33d4b4..4cc30278a 100644 --- a/game/src/main/java/org/apollo/game/session/UpdateSession.java +++ b/game/src/main/java/org/apollo/game/session/UpdateSession.java @@ -54,7 +54,7 @@ public void messageReceived(Object message) { OnDemandInfo info = (OnDemandInfo) message; int status; - if (info.getReleaseNumber() == 181) {//context.getRelease().getReleaseNumber() + if (info.getReleaseNumber() == context.getRelease().getReleaseNumber()) { status = LoginConstants.STATUS_EXCHANGE_DATA; } else { status = LoginConstants.STATUS_GAME_UPDATED; From 36ee4c0b3be6be0831a5c28eb1e32c464287d61e Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 29 Feb 2020 16:15:42 -0500 Subject: [PATCH 03/63] Bumped the JDK version in the azure-pipelines.yml to 11 from 1.8. --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2167045f3..0a528e0cb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,7 +25,7 @@ steps: gradleWrapperFile: 'gradlew' gradleOptions: '-Xmx3072m -Dorg.gradle.parallel=true -Dorg.gradle.caching=true -Dsonar.host.url=https://sonarcloud.io' javaHomeOption: 'JDKVersion' - jdkVersionOption: '1.8' + jdkVersionOption: '11' jdkArchitectureOption: 'x64' publishJUnitResults: true testResultsFiles: '**/TEST-*.xml' From 1f6041c13fbde70d8a48ebc83463a0d4c5f7c650 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 29 Feb 2020 16:55:48 -0500 Subject: [PATCH 04/63] Binding on the same port is now filtered out. This occurs when the net.xml file has duplicates in it. --- game/src/main/java/org/apollo/Server.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/game/src/main/java/org/apollo/Server.java b/game/src/main/java/org/apollo/Server.java index 55a53175f..de429aeaf 100644 --- a/game/src/main/java/org/apollo/Server.java +++ b/game/src/main/java/org/apollo/Server.java @@ -1,6 +1,7 @@ package org.apollo; import com.google.common.base.Stopwatch; +import com.google.common.collect.Sets; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; @@ -25,6 +26,7 @@ import java.net.SocketAddress; import java.nio.file.Paths; import java.util.Arrays; +import java.util.HashSet; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -166,7 +168,8 @@ public void init(String releaseName) throws Exception { * @throws IOException If the ServerBootstrap fails to bind to the SocketAddress. */ private void bind(ServerBootstrap bootstrap, SocketAddress... addresses) throws IOException { - for (SocketAddress address : addresses) { + final var set = Sets.newHashSet(addresses); + for (SocketAddress address : set) { try { bootstrap.bind(address).sync(); } catch (Exception cause) { From 662570e34abfcd7a4056564b29eaa332599af05f Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 29 Feb 2020 23:23:51 -0500 Subject: [PATCH 05/63] Login decoding updated to OSRS. Renamed XteaDecoder.java to XteaParser.java Added XteaUtil which decrypts/encrypts a ByteBuf with Xtea rounds. Added UserStats which details the incoming connection's hardware specs. --- .../org/apollo/cache/map/MapIndexDecoder.java | 10 +- .../map/{XteaDecoder.java => XteaParser.java} | 4 +- .../java/org/apollo/game/model/World.java | 4 +- .../apollo/net/codec/login/LoginDecoder.java | 184 ++++++++++-------- .../main/java/org/apollo/util/BufferUtil.java | 19 +- .../main/java/org/apollo/util/XteaUtil.java | 53 +++++ .../org/apollo/util/security/UserStats.java | 154 +++++++++++++++ 7 files changed, 335 insertions(+), 93 deletions(-) rename cache/src/main/java/org/apollo/cache/map/{XteaDecoder.java => XteaParser.java} (93%) create mode 100644 util/src/main/java/org/apollo/util/XteaUtil.java create mode 100644 util/src/main/java/org/apollo/util/security/UserStats.java diff --git a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java index ba33e0907..9149cf698 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java @@ -25,11 +25,11 @@ public final class MapIndexDecoder implements Runnable { * The Cache. */ private final Cache cache; - private final XteaDecoder xteaDecoder; + private final XteaParser xteaParser; - public MapIndexDecoder(Cache cache, XteaDecoder xteaDecoder) { + public MapIndexDecoder(Cache cache, XteaParser xteaParser) { this.cache = cache; - this.xteaDecoder = xteaDecoder; + this.xteaParser = xteaParser; } /** @@ -42,7 +42,7 @@ public Map decode() throws IOException { Map definitions = new HashMap<>(); final var fs = cache.getArchive(MapConstants.MAP_INDEX); - for (var entry : xteaDecoder.getAll()) { + for (var entry : xteaParser.getAll()) { final var region = entry.getIntKey(); final var regionX = region >> 8; final var regionY = region & 0xFF; @@ -66,7 +66,7 @@ public Map decode() throws IOException { @Override public void run() { try { - xteaDecoder.run(); + xteaParser.run(); MapIndex.init(decode()); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/cache/src/main/java/org/apollo/cache/map/XteaDecoder.java b/cache/src/main/java/org/apollo/cache/map/XteaParser.java similarity index 93% rename from cache/src/main/java/org/apollo/cache/map/XteaDecoder.java rename to cache/src/main/java/org/apollo/cache/map/XteaParser.java index 4fa576595..f3b42eb87 100644 --- a/cache/src/main/java/org/apollo/cache/map/XteaDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/XteaParser.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.nio.file.Files; -public class XteaDecoder implements Runnable { +public class XteaParser implements Runnable { private static final Gson GSON = new Gson(); @@ -33,7 +33,7 @@ public int[] getKeys() { private final int release; private final Int2ObjectArrayMap xteas; - public XteaDecoder(int release) { + public XteaParser(int release) { this.xteas = new Int2ObjectArrayMap<>(); this.release = release; } diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index 87a9f7177..850709b9f 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -7,7 +7,7 @@ import org.apollo.cache.decoder.NpcDefinitionDecoder; import org.apollo.cache.decoder.ObjectDefinitionDecoder; import org.apollo.cache.map.MapIndexDecoder; -import org.apollo.cache.map.XteaDecoder; +import org.apollo.cache.map.XteaParser; import org.apollo.game.command.CommandDispatcher; import org.apollo.game.fs.decoder.SynchronousDecoder; import org.apollo.game.fs.decoder.WorldMapDecoder; @@ -221,7 +221,7 @@ public void init(int release, Cache cache, PluginManager manager) throws Excepti new NpcDefinitionDecoder(cache), new ItemDefinitionDecoder(cache), new ObjectDefinitionDecoder(cache), - new MapIndexDecoder(cache, new XteaDecoder(release)), + new MapIndexDecoder(cache, new XteaParser(release)), EquipmentDefinitionParser.fromFile("data/equipment-" + release + "" + ".dat") ); diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java index 0c01f7f62..d8ca92472 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java @@ -8,13 +8,14 @@ import org.apollo.net.NetworkConstants; import org.apollo.util.BufferUtil; import org.apollo.util.StatefulFrameDecoder; +import org.apollo.util.XteaUtil; import org.apollo.util.security.IsaacRandom; import org.apollo.util.security.IsaacRandomPair; import org.apollo.util.security.PlayerCredentials; +import org.apollo.util.security.UserStats; import java.math.BigInteger; import java.net.InetSocketAddress; -import java.security.SecureRandom; import java.util.List; import java.util.logging.Logger; @@ -40,11 +41,6 @@ public final class LoginDecoder extends StatefulFrameDecoder */ private boolean reconnecting; - /** - * The server-side session key. - */ - private long serverSeed; - /** * The username hash. */ @@ -79,116 +75,138 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out, L * @param out The {@link List} of objects to pass forward through the pipeline. */ private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.readableBytes() >= Byte.BYTES + Integer.BYTES + Integer.BYTES) { - int type = buffer.readUnsignedByte(); - - if (type != LoginConstants.TYPE_STANDARD && type != LoginConstants.TYPE_RECONNECTION) { - logger.fine("Failed to decode login header."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + if (!buffer.isReadable(Byte.BYTES + Short.BYTES)) { + return; + } - loginLength = buffer.readUnsignedShort(); - reconnecting = type == LoginConstants.TYPE_RECONNECTION; + int type = buffer.readUnsignedByte(); - setState(LoginDecoderState.LOGIN_PAYLOAD); + if (type != LoginConstants.TYPE_STANDARD && type != LoginConstants.TYPE_RECONNECTION) { + logger.fine("Failed to decode login header."); + writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); + return; } + + loginLength = buffer.readUnsignedShort(); + reconnecting = type == LoginConstants.TYPE_RECONNECTION; + + setState(LoginDecoderState.LOGIN_PAYLOAD); } /** * Decodes in the payload state. * - * @param ctx The channel handler context. + * @param ctx The channel handler context. * @param buffer The buffer. - * @param out The {@link List} of objects to pass forward through the pipeline. + * @param out The {@link List} of objects to pass forward through the pipeline. */ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.readableBytes() >= loginLength) { - ByteBuf payload = buffer.readBytes(loginLength); + if (!buffer.isReadable(loginLength)) { + return; + } - long release = payload.readUnsignedInt(); - long version = payload.readUnsignedInt(); + final var payload = buffer.readBytes(loginLength); + final var release = payload.readUnsignedInt(); + final var version = payload.readUnsignedInt(); + final var clientType = payload.readUnsignedByte() & 0x3; // 0 desktop, 1 android, 2 ios - int memoryStatus = payload.readUnsignedByte(); - if (memoryStatus != 0 && memoryStatus != 1) { - logger.fine("Login memoryStatus (" + memoryStatus + ") not in expected range of [0, 1]."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + byte[] securePayload = new byte[payload.readUnsignedShort()]; + payload.readBytes(securePayload); - boolean lowMemory = memoryStatus == 1; + final var secureBuf = Unpooled.wrappedBuffer( + new BigInteger(securePayload).modPow(NetworkConstants.RSA_EXPONENT, NetworkConstants.RSA_MODULUS) + .toByteArray()); + final var secureCheck = secureBuf.readUnsignedByte(); + if (secureCheck != 1) { + logger.fine("Login secureCheck (" + secureCheck + ") is not expected value of 1."); + writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); + return; + } - int length = payload.readUnsignedByte(); - if (length != loginLength - 41) { - logger.fine("Login packet unexpected length (" + length + ")"); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + final var seed = new int[4]; + for (int index = 0; index < seed.length; index++) { + seed[index] = secureBuf.readInt(); + } - ByteBuf secure = payload.readBytes(length); + final var serverSessionKey = secureBuf.readLong(); - BigInteger value = new BigInteger(secure.array()); - value = value.modPow(NetworkConstants.RSA_EXPONENT, NetworkConstants.RSA_MODULUS); - secure = Unpooled.wrappedBuffer(value.toByteArray()); + final short authType; + final int authCode; + final String password; + final var previousSeed = new int[4]; - int id = secure.readUnsignedByte(); - if (id != 1) { - logger.fine("Unable to read id from secure payload."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; + if (reconnecting) { + for (int index = 0; index < previousSeed.length; index++) { + previousSeed[index] = secureBuf.readInt(); } - int[] rounds = new int[4]; - for (int index = 0; index < rounds.length; index++) { - rounds[index] = secure.readInt(); + authType = -1; + authCode = -1; + password = ""; + } else { + authType = secureBuf.readUnsignedByte(); + if (authType == 1) { // Authenticator Related = 1 + authCode = secureBuf.readInt(); + } else if (authType == 0 || authType == 2) {//Authenticator Related = 2, TrustedPC = 0 + authCode = secureBuf.readUnsignedMedium(); + secureBuf.skipBytes(Byte.BYTES); + } else { //Regular Login + authCode = secureBuf.readInt(); } - long clientSeed = secure.readLong(); - - int[] seed = new int[4]; - seed[0] = (int) (clientSeed >> 32); - seed[1] = (int) clientSeed; - seed[2] = (int) (serverSeed >> 32); - seed[3] = (int) serverSeed; + secureBuf.skipBytes(Byte.BYTES); + password = BufferUtil.readString(secureBuf); + } - long reportedSeed = secure.readLong(); - if (reportedSeed != serverSeed) { - logger.fine("Reported seed differed from server seed."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + XteaUtil.decipher(payload, payload.readerIndex(), loginLength, seed); - int uid = secure.readInt(); - String username = BufferUtil.readString(secure); - String password = BufferUtil.readString(secure); - InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); - String hostAddress = InetAddresses.toAddrString(socketAddress.getAddress()); + final var username = BufferUtil.readString(payload); + if (password.length() < 4 || password.length() > 20 || username.isEmpty() || username.length() > 12) { + logger.fine("Username ('" + username + "') or password did not pass validation."); + writeResponseCode(ctx, LoginConstants.STATUS_INVALID_CREDENTIALS); + return; + } - if (password.length() < 6 || password.length() > 20 || username.isEmpty() || username.length() > 12) { - logger.fine("Username ('" + username + "') or password did not pass validation."); - writeResponseCode(ctx, LoginConstants.STATUS_INVALID_CREDENTIALS); - return; - } + final var clientProperties = payload.readUnsignedByte(); + final var lowMemory = (clientProperties & 0x1) == 1; + final var frameType = (clientProperties >> 1) == 1;// Resizable/Fixed + final var frameWidth = payload.readShort(); + final var frameHeight = payload.readShort(); - int[] crcs = new int[25]; - for (int index = 0; index < 9; index++) { - crcs[index] = payload.readInt(); - } + final var randFileContents = new byte[24]; + payload.readBytes(randFileContents); + final var areaKey = BufferUtil.readString(payload); // TODO this is known. + final var someID = payload.readInt(); // Some sort of ID - IsaacRandom decodingRandom = new IsaacRandom(seed); - for (int index = 0; index < seed.length; index++) { - seed[index] += 50; - } + final var stats = new UserStats(); + if (!stats.populate(payload)) { + logger.fine("User statistics version mismatched."); + writeResponseCode(ctx, LoginConstants.STATUS_GAME_UPDATED); + return; + } - IsaacRandom encodingRandom = new IsaacRandom(seed); + final var jsEnabled = payload.readUnsignedByte() == 1; - PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid, hostAddress); - IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom); + int[] crcs = new int[20]; + for (int index = 0; index < 9; index++) { + crcs[index] = payload.readInt(); + } - out.add(new LoginRequest(credentials, randomPair, reconnecting, lowMemory, release, crcs, version)); + IsaacRandom decodingRandom = new IsaacRandom(seed); + for (int index = 0; index < seed.length; index++) { + seed[index] += 50; } + IsaacRandom encodingRandom = new IsaacRandom(seed); + + InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); + String hostAddress = InetAddresses.toAddrString(socketAddress.getAddress()); + + PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, 0, hostAddress); + IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom); + + out.add(new LoginRequest(credentials, randomPair, reconnecting, lowMemory, release, crcs, version)); } /** diff --git a/util/src/main/java/org/apollo/util/BufferUtil.java b/util/src/main/java/org/apollo/util/BufferUtil.java index a479e2dcd..bb534feb8 100644 --- a/util/src/main/java/org/apollo/util/BufferUtil.java +++ b/util/src/main/java/org/apollo/util/BufferUtil.java @@ -77,10 +77,26 @@ public static int readUnsignedMedium(ByteBuffer buffer) { return (buffer.getShort() & 0xFFFF) << 8 | buffer.get() & 0xFF; } + /** + * Reads a 24-bit medium integer from the specified {@link ByteBuffer}s current position and increases the buffers + * position by 3. + * + * @param buffer The {@link ByteBuffer} to read from. + * @return The read 24-bit medium integer. + */ + public static int readUnsignedMedium(ByteBuf buffer) { + return buffer.readUnsignedShort() << 8 | buffer.readUnsignedByte(); + } + + public static String readJagexString(ByteBuf buffer) { + buffer.readByte(); + return readString(buffer); + } + /** * The terminator of a string. */ - public static final int STRING_TERMINATOR = 10; + public static final int STRING_TERMINATOR = 0; /** * Default private constructor to prevent instantiation. @@ -89,4 +105,5 @@ private BufferUtil() { } + } \ No newline at end of file diff --git a/util/src/main/java/org/apollo/util/XteaUtil.java b/util/src/main/java/org/apollo/util/XteaUtil.java new file mode 100644 index 000000000..a9f67287b --- /dev/null +++ b/util/src/main/java/org/apollo/util/XteaUtil.java @@ -0,0 +1,53 @@ +package org.apollo.util; + +import io.netty.buffer.ByteBuf; + +public class XteaUtil { + + + /** + * The golden ratio XTEA uses. + */ + private static final int GOLDEN_RATIO = -1640531527; + + /** + * The number of rounds XTEA uses. + */ + private static final int ROUNDS = 32; + + public static void decipher(ByteBuf buffer, int start, int end, int[] key) { + if (key.length != 4) throw new IllegalArgumentException(); + + int numQuads = (end - start) / 8; + for (int i = 0; i < numQuads; i++) { + int sum = GOLDEN_RATIO * ROUNDS; + int v0 = buffer.getInt(start + i * 8); + int v1 = buffer.getInt(start + i * 8 + 4); + for (int j = 0; j < ROUNDS; j++) { + v1 -= (((v0 << 4) ^ (v0 >>> 5)) + v0) ^ (sum + key[(sum >>> 11) & 3]); + sum -= GOLDEN_RATIO; + v0 -= (((v1 << 4) ^ (v1 >>> 5)) + v1) ^ (sum + key[sum & 3]); + } + buffer.setInt(start + i * 8, v0); + buffer.setInt(start + i * 8 + 4, v1); + } + } + + public static void encypher(ByteBuf buffer, int start, int end, int[] key) { + if (key.length != 4) throw new IllegalArgumentException(); + + int numQuads = (end - start) / 8; + for (int i = 0; i < numQuads; i++) { + int sum = 0; + int v0 = buffer.getInt(start + i * 8); + int v1 = buffer.getInt(start + i * 8 + 4); + for (int j = 0; j < ROUNDS; j++) { + v0 += (((v1 << 4) ^ (v1 >>> 5)) + v1) ^ (sum + key[sum & 3]); + sum += GOLDEN_RATIO; + v1 += (((v0 << 4) ^ (v0 >>> 5)) + v0) ^ (sum + key[(sum >>> 11) & 3]); + } + buffer.setInt(start + i * 8, v0); + buffer.setInt(start + i * 8 + 4, v1); + } + } +} diff --git a/util/src/main/java/org/apollo/util/security/UserStats.java b/util/src/main/java/org/apollo/util/security/UserStats.java new file mode 100644 index 000000000..d56f00c02 --- /dev/null +++ b/util/src/main/java/org/apollo/util/security/UserStats.java @@ -0,0 +1,154 @@ +package org.apollo.util.security; + +import io.netty.buffer.ByteBuf; +import org.apollo.util.BufferUtil; + +public class UserStats { + + public static final int STATS_VERSION = 8; + + private int osType; + private boolean os64Bit; + private int osVersion; + private int javaVendor; + private int javaMajor; + private int javaMinor; + private int javaBuild; + private int availableProcessors; + private int gpuDriverYear; + private int gpuDriverMonth; + private boolean isConsole; + private int maxMemory; + private int cpuCount; + private int ramAmount; + private int cpuClockspeed; + private String gpuName; + private String directxVersion; + private int cpuBrandId; + private String cpuVendor; + private String cpuBrandString; + private int[] cpuFeatures = new int[3]; + private int cpuModel; + + public boolean populate(ByteBuf buffer) { + final var version = buffer.readUnsignedByte(); + if (version != STATS_VERSION) { + return false; + } + + osType = buffer.readUnsignedByte(); + os64Bit = buffer.readBoolean(); + osVersion = buffer.readUnsignedByte(); + javaVendor = buffer.readUnsignedByte(); + javaMajor = buffer.readUnsignedByte(); + javaMinor = buffer.readUnsignedByte(); + javaBuild = buffer.readUnsignedByte(); + isConsole = buffer.readBoolean(); + maxMemory = buffer.readUnsignedShort(); + availableProcessors = buffer.readUnsignedByte(); + ramAmount = BufferUtil.readUnsignedMedium(buffer); + cpuClockspeed = buffer.readUnsignedShort(); + gpuName = BufferUtil.readJagexString(buffer); + directxVersion = BufferUtil.readJagexString(buffer); + gpuDriverYear = buffer.readUnsignedByte(); + gpuDriverMonth = buffer.readUnsignedShort(); + cpuVendor = BufferUtil.readJagexString(buffer); + cpuBrandString = BufferUtil.readJagexString(buffer); + cpuCount = buffer.readUnsignedByte(); + cpuBrandId = buffer.readUnsignedByte(); + for (int index = 0; index < cpuFeatures.length; index++) { + cpuFeatures[index] = buffer.readInt(); + } + cpuModel = buffer.readInt(); + BufferUtil.readJagexString(buffer); // This is always empty so don't know. Possibly mobile related? + return true; + } + + public int getOsType() { + return osType; + } + + public boolean isOs64Bit() { + return os64Bit; + } + + public int getOsVersion() { + return osVersion; + } + + public int getJavaVendor() { + return javaVendor; + } + + public int getJavaMajor() { + return javaMajor; + } + + public int getJavaMinor() { + return javaMinor; + } + + public int getJavaBuild() { + return javaBuild; + } + + public int getAvailableProcessors() { + return availableProcessors; + } + + public int getGpuDriverYear() { + return gpuDriverYear; + } + + public int getGpuDriverMonth() { + return gpuDriverMonth; + } + + public boolean isConsole() { + return isConsole; + } + + public int getMaxMemory() { + return maxMemory; + } + + public int getCpuCount() { + return cpuCount; + } + + public int getRamAmount() { + return ramAmount; + } + + public int getCpuClockspeed() { + return cpuClockspeed; + } + + public String getGpuName() { + return gpuName; + } + + public String getDirectxVersion() { + return directxVersion; + } + + public int getCpuBrandId() { + return cpuBrandId; + } + + public String getCpuVendor() { + return cpuVendor; + } + + public String getCpuBrandString() { + return cpuBrandString; + } + + public int[] getCpuFeatures() { + return cpuFeatures; + } + + public int getCpuModel() { + return cpuModel; + } +} From b901cb584f37c2347dd1f34e8fb070c7a85bc936 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 29 Feb 2020 23:51:50 -0500 Subject: [PATCH 06/63] Documented user stats. Added user stats to the credentials to replace uid. --- .../plugin/testing/junit/ApolloTestState.kt | 2 +- .../game/model/entity/WalkingQueueTests.java | 2 +- .../apollo/net/codec/login/LoginDecoder.java | 8 +- .../util/security/PlayerCredentials.java | 23 +- .../org/apollo/util/security/UserStats.java | 263 ++++++++++++++++-- 5 files changed, 251 insertions(+), 47 deletions(-) diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt index cae992930..3d9071919 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt @@ -39,7 +39,7 @@ data class ApolloTestState(val handlers: MessageHandlerChainSet, val world: Worl } fun createPlayer(info: PlayerStubInfo): Player { - val credentials = PlayerCredentials(info.name, "test", 1, 1, "0.0.0.0") + val credentials = PlayerCredentials(info.name, "test", 1, null, "0.0.0.0") val region = world.regionRepository.fromPosition(info.position) val player = spyk(Player(world, credentials, info.position)) diff --git a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java index 51dd4d60c..a7ee6e2da 100644 --- a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java @@ -34,7 +34,7 @@ private World createFakeWorld(boolean traversable) { } private Player createFakePlayer(World world) { - PlayerCredentials credentials = new PlayerCredentials("test", "test", -1, -1, "0.0.0.0"); + PlayerCredentials credentials = new PlayerCredentials("test", "test", -1, null, "0.0.0.0"); Player player = new Player(world, credentials, START_POSITION); Region region = world.getRegionRepository().fromPosition(START_POSITION); diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java index d8ca92472..6876967af 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java @@ -178,10 +178,10 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List Date: Sun, 1 Mar 2020 11:19:48 -0500 Subject: [PATCH 07/63] Updated UserStats to revision 8. Resolved issue with Crc check being invalid due to index sixteen being manually zeroed over the wire by Jagex. --- .../src/main/java/org/apollo/cache/Cache.java | 4 +- .../org/apollo/game/service/LoginService.java | 29 ++++++------ .../apollo/net/codec/login/LoginDecoder.java | 46 ++++++++++--------- .../org/apollo/util/security/UserStats.java | 22 +++++++-- 4 files changed, 59 insertions(+), 42 deletions(-) diff --git a/cache/src/main/java/org/apollo/cache/Cache.java b/cache/src/main/java/org/apollo/cache/Cache.java index 0b23ae1d0..a358a6d93 100644 --- a/cache/src/main/java/org/apollo/cache/Cache.java +++ b/cache/src/main/java/org/apollo/cache/Cache.java @@ -42,8 +42,8 @@ private final void openFiles(String path) { crcs = new int[numIndices]; for (int i = 0; i < archives.length; i++) { - var fs = getArchive(i); - crcs[i] = fs == null ? 0 : fs.getCRC32(); + var archive = getArchive(i); + crcs[i] = archive == null ? 0 : archive.getCRC32(); } } catch (IOException ioex) { ioex.printStackTrace(); diff --git a/game/src/main/java/org/apollo/game/service/LoginService.java b/game/src/main/java/org/apollo/game/service/LoginService.java index 326fbf87e..906b6f018 100644 --- a/game/src/main/java/org/apollo/game/service/LoginService.java +++ b/game/src/main/java/org/apollo/game/service/LoginService.java @@ -1,12 +1,5 @@ package org.apollo.game.service; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - import org.apollo.Service; import org.apollo.game.io.player.PlayerLoaderResponse; import org.apollo.game.io.player.PlayerSerializer; @@ -24,6 +17,12 @@ import org.apollo.util.xml.XmlParser; import org.xml.sax.SAXException; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + /** * The {@link LoginService} manages {@link LoginRequest}s. * @@ -88,7 +87,7 @@ public void submitLoadRequest(LoginSession session, LoginRequest request) throws * Submits a save request. * * @param session The session submitting this request. - * @param player The player to save. + * @param player The player to save. */ public void submitSaveRequest(GameSession session, Player player) { executor.submit(new PlayerSaverWorker(serializer, session, player)); @@ -97,8 +96,8 @@ public void submitSaveRequest(GameSession session, Player player) { /** * Initialises the login service. * - * @throws SAXException If there is an error parsing the XML file. - * @throws IOException If there is an error accessing the file. + * @throws SAXException If there is an error parsing the XML file. + * @throws IOException If there is an error accessing the file. * @throws ReflectiveOperationException If the {@link PlayerSerializer} implementation could not be created. */ private void init() throws SAXException, IOException, ReflectiveOperationException { @@ -136,9 +135,13 @@ private boolean requiresUpdate(LoginRequest request) throws IOException { } int[] clientCrcs = request.getArchiveCrcs(); - int[] serverCrcs = context.getFileSystem().getCrcs(); - - return !Arrays.equals(clientCrcs, serverCrcs); + for (int index = 0; index < clientCrcs.length; index++) { + int crc = context.getFileSystem().getArchive(index).getCRC32(); + if (index != 16 && crc != clientCrcs[index]) { + return true; + } + } + return false; } } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java index 6876967af..aa2165d3f 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java @@ -2,6 +2,7 @@ import com.google.common.net.InetAddresses; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -96,9 +97,9 @@ private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List out) { if (!buffer.isReadable(loginLength)) { @@ -110,14 +111,13 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List Date: Sun, 1 Mar 2020 18:08:46 -0500 Subject: [PATCH 08/63] Worldlist is now available. Currently it's just magic constants until someone decides how to move forward with a multi-world impl. --- .../net/codec/handshake/HandshakeDecoder.java | 2 +- .../apollo/net/update/HttpRequestWorker.java | 7 +-- .../resource/WorldListResourceProvider.java | 43 +++++++++++++++++++ .../main/java/org/apollo/util/BufferUtil.java | 19 ++++++++ 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java diff --git a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java index 7e268781a..a0d4b6bab 100644 --- a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java @@ -35,7 +35,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List ou int id = buffer.readUnsignedByte(); switch (id) { case HandshakeConstants.SERVICE_GAME: - ctx.pipeline().addFirst(new LoginEncoder()); + ctx.pipeline().addFirst("loginEncoder", new LoginEncoder()); ctx.pipeline().addAfter("handshakeDecoder", "loginDecoder", new LoginDecoder()); break; case HandshakeConstants.SERVICE_UPDATE: diff --git a/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java b/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java index ec54fa0fa..3c945fac7 100644 --- a/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java +++ b/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java @@ -18,10 +18,7 @@ import java.util.Optional; import org.apollo.cache.Cache; -import org.apollo.net.update.resource.CombinedResourceProvider; -import org.apollo.net.update.resource.HypertextResourceProvider; -import org.apollo.net.update.resource.ResourceProvider; -import org.apollo.net.update.resource.VirtualResourceProvider; +import org.apollo.net.update.resource.*; import com.google.common.base.Charsets; @@ -54,7 +51,7 @@ public final class HttpRequestWorker extends RequestWorker get(String path) throws IOException { + final var buf = Unpooled.buffer(); + final var world = createWorld(); + + buf.writeInt(world.readableBytes()); + buf.writeBytes(world); + + return Optional.of(buf.nioBuffer()); + } + + private ByteBuf createWorld() { + ByteBuf world = Unpooled.buffer(); + world.writeShort(1); // number of worlds + + world.writeShort(1); // world id + world.writeInt(0); // world settings + BufferUtil.writeString(world, "127.0.0.1"); // address + BufferUtil.writeString(world, "Converting Apollo"); // address + world.writeByte(0); // country + world.writeShort(2000);// number of players + return world; + } +} diff --git a/util/src/main/java/org/apollo/util/BufferUtil.java b/util/src/main/java/org/apollo/util/BufferUtil.java index bb534feb8..400f14bac 100644 --- a/util/src/main/java/org/apollo/util/BufferUtil.java +++ b/util/src/main/java/org/apollo/util/BufferUtil.java @@ -3,6 +3,7 @@ import io.netty.buffer.ByteBuf; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; /** * A utility class which contains {@link ByteBuffer}-related utility methods. @@ -88,11 +89,29 @@ public static int readUnsignedMedium(ByteBuf buffer) { return buffer.readUnsignedShort() << 8 | buffer.readUnsignedByte(); } + /** + * Reads a jagex-string from the specified {@link ByteBuf}. + * + * @param buffer The buffer. + * @return The string. + */ public static String readJagexString(ByteBuf buffer) { buffer.readByte(); return readString(buffer); } + + /** + * Writes a string to the specified {@link ByteBuf} + * @param buffer + * @param str + */ + public static void writeString(ByteBuf buffer, String str) { + byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1); + buffer.writeBytes(bytes); + buffer.writeByte(0); + } + /** * The terminator of a string. */ From 72292a22eb5283ad7b423696cd8c56c031857967 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 1 Mar 2020 19:17:16 -0500 Subject: [PATCH 09/63] Worldlist is now available. Currently it's just magic constants until someone decides how to move forward with a multi-world impl. --- .../resource/WorldListResourceProvider.java | 40 +++++++++++-------- .../main/java/org/apollo/util/BufferUtil.java | 11 +++++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java b/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java index 4bbe52551..cb312729a 100644 --- a/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java +++ b/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java @@ -1,7 +1,5 @@ package org.apollo.net.update.resource; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import org.apollo.util.BufferUtil; import java.io.IOException; @@ -19,25 +17,33 @@ public boolean accept(String path) throws IOException { @Override public Optional get(String path) throws IOException { - final var buf = Unpooled.buffer(); final var world = createWorld(); + final var buf = ByteBuffer.allocate(Integer.BYTES + world.remaining()); - buf.writeInt(world.readableBytes()); - buf.writeBytes(world); + buf.putInt(world.remaining()); + buf.put(world); - return Optional.of(buf.nioBuffer()); + return Optional.of(buf.flip()); } - private ByteBuf createWorld() { - ByteBuf world = Unpooled.buffer(); - world.writeShort(1); // number of worlds - - world.writeShort(1); // world id - world.writeInt(0); // world settings - BufferUtil.writeString(world, "127.0.0.1"); // address - BufferUtil.writeString(world, "Converting Apollo"); // address - world.writeByte(0); // country - world.writeShort(2000);// number of players - return world; + private ByteBuffer createWorld() { + final var address = "127.0.0.1";//10 + final var activity = "Converting Apollo";//18 + + ByteBuffer world = ByteBuffer.allocate(Short.BYTES + Integer.BYTES + address.length() + activity + .length() + Byte.BYTES + Byte.BYTES + Byte.BYTES + Short.BYTES); + world.putShort((short) 1); // world id + world.putInt(0); // world settings + BufferUtil.writeString(world, address); // address + BufferUtil.writeString(world, activity); // activity + world.put((byte) 0); // country + world.putShort((short) 2000);// number of players + world.flip(); + + ByteBuffer list = ByteBuffer.allocate(Short.BYTES + world.remaining()); + list.putShort((short) 1); // number of worlds + list.put(world); + + return list.flip(); } } diff --git a/util/src/main/java/org/apollo/util/BufferUtil.java b/util/src/main/java/org/apollo/util/BufferUtil.java index 400f14bac..ea0c522aa 100644 --- a/util/src/main/java/org/apollo/util/BufferUtil.java +++ b/util/src/main/java/org/apollo/util/BufferUtil.java @@ -112,6 +112,17 @@ public static void writeString(ByteBuf buffer, String str) { buffer.writeByte(0); } + /** + * Writes a string to the specified {@link ByteBuf} + * @param buffer + * @param str + */ + public static void writeString(ByteBuffer buffer, String str) { + byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1); + buffer.put(bytes); + buffer.put((byte) 0); + } + /** * The terminator of a string. */ From 071b04da86658866bc1888325ad7e6f35f6fb35c Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 1 Mar 2020 23:57:41 -0500 Subject: [PATCH 10/63] Added the following encode messages: Varp Added the following decode messages: Add/Remove Ignores&Friends, Private Chat Messages. --- build.gradle | 2 +- .../runecrafting/src/Runecrafting.plugin.kts | 2 +- .../release/r181/AddFriendMessageDecoder.java | 22 +++++++++++ .../release/r181/AddIgnoreMessageDecoder.java | 22 +++++++++++ .../release/r181/ConfigMessageEncoder.java | 38 +++++++++++++++++++ .../r181/PrivateChatMessageDecoder.java | 36 ++++++++++++++++++ .../game/release/r181/ReleaseOSRS181.java | 33 +++++++++++++++- .../r181/RemoveFriendMessageDecoder.java | 22 +++++++++++ .../r181/RemoveIgnoreMessageDecoder.java | 22 +++++++++++ gradle/properties.gradle | 4 +- 10 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/release/r181/AddFriendMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/AddIgnoreMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/ConfigMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/PrivateChatMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/RemoveFriendMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/RemoveIgnoreMessageDecoder.java diff --git a/build.gradle b/build.gradle index 88f7364a8..daf4bce3a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version '1.3.61' apply(false) + id 'org.jetbrains.kotlin.jvm' version '1.3.41' apply(false) id 'org.jetbrains.intellij' version '0.4.9' apply(false) id 'org.jmailen.kotlinter' version '1.26.0' apply(false) id 'org.sonarqube' version '2.7.1' diff --git a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts index 88f983f77..c9eb1cfc4 100644 --- a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts +++ b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts @@ -4,7 +4,7 @@ import org.apollo.game.message.impl.* import org.apollo.game.model.entity.EquipmentConstants import org.apollo.game.model.event.impl.LoginEvent -private val changeAltarObjectConfigId = 491 +internal val changeAltarObjectConfigId = 491 internal val RUNES = mutableListOf() diff --git a/game/src/main/java/org/apollo/game/release/r181/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/AddFriendMessageDecoder.java new file mode 100644 index 000000000..2d14c406b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/AddFriendMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.AddFriendMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the {@link AddFriendMessage}. + * + * @author Major + */ +public final class AddFriendMessageDecoder extends MessageDecoder { + + @Override + public AddFriendMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + String username = reader.getString(); + return new AddFriendMessage(username); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/AddIgnoreMessageDecoder.java new file mode 100644 index 000000000..21eca587f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/AddIgnoreMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.AddIgnoreMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the {@link AddIgnoreMessage}. + * + * @author Major + */ +public final class AddIgnoreMessageDecoder extends MessageDecoder { + + @Override + public AddIgnoreMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + String username = reader.getString(); + return new AddIgnoreMessage(username); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/ConfigMessageEncoder.java new file mode 100644 index 000000000..75139e8c0 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/ConfigMessageEncoder.java @@ -0,0 +1,38 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.ConfigMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link ConfigMessage}. + * + * @author Chris Fletcher + * @author Major + */ +public final class ConfigMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(ConfigMessage message) { + GamePacketBuilder builder; + int value = message.getValue(); + + if (value > Byte.MIN_VALUE && value < Byte.MAX_VALUE) { + builder = new GamePacketBuilder(4); + + builder.put(DataType.BYTE, DataTransformation.ADD, value & 0xFF); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); + } else { + builder = new GamePacketBuilder(63); + + builder.put(DataType.SHORT, message.getId()); + builder.put(DataType.INT, value); + } + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/PrivateChatMessageDecoder.java new file mode 100644 index 000000000..c78878ac8 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/PrivateChatMessageDecoder.java @@ -0,0 +1,36 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.PrivateChatMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; +import org.apollo.util.TextUtil; + +/** + * A {@link MessageDecoder} for the {@link PrivateChatMessage}. + * + * @author Major + */ +public final class PrivateChatMessageDecoder extends MessageDecoder { + + @Override + public PrivateChatMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + String username = reader.getString(); + int length = packet.getLength() - Long.BYTES; + + byte[] originalCompressed = new byte[length]; + reader.getBytes(originalCompressed); + + String decompressed = TextUtil.decompress(originalCompressed, length); + decompressed = TextUtil.filterInvalidCharacters(decompressed); + decompressed = TextUtil.capitalize(decompressed); + + byte[] recompressed = new byte[length]; + TextUtil.compress(decompressed, recompressed); + + return new PrivateChatMessage(decompressed, recompressed, username); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java b/game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java index 1eacdc43c..7c1e88ed4 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java +++ b/game/src/main/java/org/apollo/game/release/r181/ReleaseOSRS181.java @@ -1,10 +1,9 @@ package org.apollo.game.release.r181; +import org.apollo.game.message.impl.ConfigMessage; import org.apollo.net.meta.PacketMetaDataGroup; import org.apollo.net.release.Release; -import java.util.Arrays; - public class ReleaseOSRS181 extends Release { private static final int[] PACKET_LENGTHS = new int[256]; @@ -121,6 +120,36 @@ public ReleaseOSRS181() { } private void init() { + /** + * Server + */ + + + + register(ConfigMessage.class, new ConfigMessageEncoder()); + + + /** + * Client + */ + + /** + * Friends List + */ + register(88, new AddFriendMessageDecoder()); + register(54, new RemoveFriendMessageDecoder()); + + /** + * Ignores List + */ + register(90, new AddIgnoreMessageDecoder()); + register(28, new RemoveIgnoreMessageDecoder()); + + /** + * Private Message + */ + register(25, new PrivateChatMessageDecoder()); + //TODO register completed client prot here. } } diff --git a/game/src/main/java/org/apollo/game/release/r181/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/RemoveFriendMessageDecoder.java new file mode 100644 index 000000000..77792cccd --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/RemoveFriendMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.RemoveFriendMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the {@link RemoveFriendMessage}. + * + * @author Major + */ +public final class RemoveFriendMessageDecoder extends MessageDecoder { + + @Override + public RemoveFriendMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + String username = reader.getString(); + return new RemoveFriendMessage(username); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/RemoveIgnoreMessageDecoder.java new file mode 100644 index 000000000..4fc42deb4 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/RemoveIgnoreMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.RemoveIgnoreMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the {@link RemoveIgnoreMessage}. + * + * @author Major + */ +public final class RemoveIgnoreMessageDecoder extends MessageDecoder { + + @Override + public RemoveIgnoreMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + String username = reader.getString(); + return new RemoveIgnoreMessage(username); + } + +} \ No newline at end of file diff --git a/gradle/properties.gradle b/gradle/properties.gradle index 4ebfc745b..8b5a78be7 100644 --- a/gradle/properties.gradle +++ b/gradle/properties.gradle @@ -1,6 +1,6 @@ ext { - kotlinVersion = '1.3.61' - kotlinxCoroutinesVersion = '1.3.3' + kotlinVersion = '1.3.40' + kotlinxCoroutinesVersion = '1.3.0-M2' junitVersion = '4.12' powermockVersion = '2.0.2' bouncycastleVersion = '1.54' From 570745a2d8cd86e64fb68b5c710b71c1da1b3197 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 2 Mar 2020 19:23:49 -0500 Subject: [PATCH 11/63] Player options decoders. Report abuse decoder. Keepalive decoder. Walk decoder. Arrowkey decoder. Close interface decoder. Amount input decoder. Removed 317 rev and 377 to follow soon. Note: You may need to exclude the 377 directory manually. --- game/data/equipment-317.dat | Bin 22608 -> 0 bytes game/data/equipment-377.dat | Bin 28378 -> 0 bytes .../testing/junit/api/interactions/player.kt | 2 +- game/src/main/java/org/apollo/Server.java | 5 +- .../message/impl/PlayerActionMessage.java | 21 +- .../ArrowKeyMessageDecoder.java | 10 +- .../ClosedInterfaceMessageDecoder.java | 2 +- .../{r317 => r181}/CommandMessageDecoder.java | 2 +- .../r181/EightPlayerActionMessageDecoder.java | 21 + .../EnteredAmountMessageDecoder.java | 2 +- .../FifthPlayerActionMessageDecoder.java | 10 +- .../FirstPlayerActionMessageDecoder.java | 10 +- .../FourthPlayerActionMessageDecoder.java | 12 +- .../KeepAliveMessageDecoder.java | 2 +- .../PrivacyOptionMessageDecoder.java | 2 +- .../{ReleaseOSRS181.java => Release181.java} | 47 +- .../ReportAbuseMessageDecoder.java | 8 +- .../SecondPlayerActionMessageDecoder.java | 10 +- .../SeventhPlayerActionMessageDecoder.java | 23 + .../r181/SixthPlayerActionMessageDecoder.java | 24 + .../SpamPacketMessageDecoder.java | 2 +- .../ThirdPlayerActionMessageDecoder.java | 12 +- .../game/release/r181/WalkMessageDecoder.java | 32 ++ .../release/r317/AddFriendMessageDecoder.java | 24 - .../r317/AddGlobalTileItemMessageEncoder.java | 27 - .../release/r317/AddIgnoreMessageDecoder.java | 24 - .../r317/AddTileItemMessageEncoder.java | 27 - .../release/r317/ButtonMessageDecoder.java | 23 - .../r317/ClearRegionMessageEncoder.java | 29 -- .../r317/CloseInterfaceMessageEncoder.java | 21 - .../release/r317/ConfigMessageEncoder.java | 38 -- .../r317/DialogueContinueMessageDecoder.java | 24 - .../r317/DisplayCrossbonesMessageEncoder.java | 23 - .../DisplayTabInterfaceMessageEncoder.java | 24 - .../r317/EnterAmountMessageEncoder.java | 22 - .../r317/FifthItemActionMessageDecoder.java | 27 - .../r317/FifthItemOptionMessageDecoder.java | 28 -- .../r317/FifthNpcActionMessageDecoder.java | 25 - .../r317/FirstItemActionMessageDecoder.java | 26 - .../r317/FirstItemOptionMessageDecoder.java | 29 -- .../r317/FirstNpcActionMessageDecoder.java | 24 - .../r317/FirstObjectActionMessageDecoder.java | 28 -- .../r317/FlaggedMouseEventMessageDecoder.java | 39 -- .../r317/FlashTabInterfaceMessageEncoder.java | 24 - .../FlashingTabClickedMessageDecoder.java | 23 - .../r317/FocusUpdateMessageDecoder.java | 23 - .../ForwardPrivateChatMessageEncoder.java | 36 -- .../r317/FourthItemActionMessageDecoder.java | 26 - .../r317/FourthItemOptionMessageDecoder.java | 29 -- .../r317/FourthNpcActionMessageDecoder.java | 24 - .../FriendServerStatusMessageEncoder.java | 23 - .../GroupedRegionUpdateMessageEncoder.java | 56 --- .../r317/IdAssignmentMessageEncoder.java | 26 - .../r317/IgnoreListMessageEncoder.java | 32 -- .../r317/ItemOnItemMessageDecoder.java | 34 -- .../release/r317/ItemOnNpcMessageDecoder.java | 30 -- .../r317/ItemOnObjectMessageDecoder.java | 32 -- .../release/r317/LogoutMessageEncoder.java | 21 - .../r317/MagicOnItemMessageDecoder.java | 29 -- .../r317/MagicOnNpcMessageDecoder.java | 28 -- .../r317/MagicOnPlayerMessageDecoder.java | 28 -- .../r317/MobAnimationResetMessageEncoder.java | 20 - .../r317/MobHintIconMessageEncoder.java | 36 -- .../r317/MouseClickedMessageDecoder.java | 31 -- .../NpcSynchronizationMessageEncoder.java | 300 ------------ .../OpenDialogueInterfaceMessageEncoder.java | 24 - .../OpenDialogueOverlayMessageEncoder.java | 25 - .../r317/OpenInterfaceMessageEncoder.java | 23 - .../OpenInterfaceSidebarMessageEncoder.java | 25 - .../r317/OpenOverlayMessageEncoder.java | 24 - .../r317/OpenSidebarMessageEncoder.java | 24 - .../r317/PlayerDesignMessageDecoder.java | 39 -- .../PlayerSynchronizationMessageEncoder.java | 460 ------------------ .../r317/PositionHintIconMessageEncoder.java | 36 -- .../r317/PrivacyOptionMessageEncoder.java | 27 - .../r317/PrivateChatMessageDecoder.java | 38 -- .../r317/PublicChatMessageDecoder.java | 40 -- .../r317/RegionChangeMessageEncoder.java | 25 - .../apollo/game/release/r317/Release317.java | 239 --------- .../r317/RemoveFriendMessageDecoder.java | 24 - .../r317/RemoveIgnoreMessageDecoder.java | 24 - .../r317/RemoveObjectMessageEncoder.java | 26 - .../r317/RemoveTileItemMessageEncoder.java | 25 - .../r317/SecondItemActionMessageDecoder.java | 29 -- .../r317/SecondItemOptionMessageDecoder.java | 28 -- .../r317/SecondNpcActionMessageDecoder.java | 24 - .../SecondObjectActionMessageDecoder.java | 30 -- .../r317/SendFriendMessageEncoder.java | 25 - .../r317/SendObjectMessageEncoder.java | 27 - .../r317/ServerMessageMessageEncoder.java | 23 - .../r317/SetPlayerActionMessageEncoder.java | 27 - .../r317/SetUpdatedRegionMessageEncoder.java | 29 -- .../SetWidgetItemModelMessageEncoder.java | 28 -- ...SetWidgetModelAnimationMessageEncoder.java | 26 - .../r317/SetWidgetModelMessageEncoder.java | 28 -- .../r317/SetWidgetNpcModelMessageEncoder.java | 28 -- .../SetWidgetPlayerModelMessageEncoder.java | 25 - .../r317/SetWidgetTextMessageEncoder.java | 27 - .../SetWidgetVisibilityMessageEncoder.java | 26 - .../r317/SwitchItemMessageDecoder.java | 28 -- .../SwitchTabInterfaceMessageEncoder.java | 25 - .../r317/TakeTileItemMessageDecoder.java | 27 - .../r317/ThirdItemActionMessageDecoder.java | 29 -- .../r317/ThirdItemOptionMessageDecoder.java | 29 -- .../r317/ThirdNpcActionMessageDecoder.java | 25 - .../r317/ThirdObjectActionMessageDecoder.java | 30 -- .../r317/UpdateItemsMessageEncoder.java | 46 -- .../r317/UpdateRunEnergyMessageEncoder.java | 23 - .../r317/UpdateSkillMessageEncoder.java | 30 -- .../UpdateSlottedItemsMessageEncoder.java | 46 -- .../r317/UpdateTileItemMessageEncoder.java | 26 - .../r317/UpdateWeightMessageEncoder.java | 23 - .../game/release/r317/WalkMessageDecoder.java | 48 -- .../game/release/r317/package-info.java | 5 - .../r377/FirstPlayerActionMessageDecoder.java | 4 +- 115 files changed, 209 insertions(+), 3515 deletions(-) delete mode 100644 game/data/equipment-317.dat delete mode 100644 game/data/equipment-377.dat rename game/src/main/java/org/apollo/game/release/{r317 => r181}/ArrowKeyMessageDecoder.java (63%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/ClosedInterfaceMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/CommandMessageDecoder.java (93%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/EightPlayerActionMessageDecoder.java rename game/src/main/java/org/apollo/game/release/{r317 => r181}/EnteredAmountMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/FifthPlayerActionMessageDecoder.java (64%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/FirstPlayerActionMessageDecoder.java (61%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/FourthPlayerActionMessageDecoder.java (64%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/KeepAliveMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/PrivacyOptionMessageDecoder.java (95%) rename game/src/main/java/org/apollo/game/release/r181/{ReleaseOSRS181.java => Release181.java} (75%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/ReportAbuseMessageDecoder.java (76%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/SecondPlayerActionMessageDecoder.java (64%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/SeventhPlayerActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/SixthPlayerActionMessageDecoder.java rename game/src/main/java/org/apollo/game/release/{r317 => r181}/SpamPacketMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/{r317 => r181}/ThirdPlayerActionMessageDecoder.java (56%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/WalkMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/AddFriendMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/AddGlobalTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/AddIgnoreMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/AddTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ButtonMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ClearRegionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/CloseInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ConfigMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/DialogueContinueMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/DisplayCrossbonesMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/DisplayTabInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/EnterAmountMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FifthItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FifthItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FifthNpcActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FirstItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FirstItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FirstNpcActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FirstObjectActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FlaggedMouseEventMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FlashTabInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FlashingTabClickedMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FocusUpdateMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ForwardPrivateChatMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FourthItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FourthItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FourthNpcActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/FriendServerStatusMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/GroupedRegionUpdateMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/IdAssignmentMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/IgnoreListMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ItemOnItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ItemOnNpcMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ItemOnObjectMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/LogoutMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/MagicOnItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/MagicOnNpcMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/MagicOnPlayerMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/MobAnimationResetMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/MobHintIconMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/MouseClickedMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/NpcSynchronizationMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/OpenDialogueInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/OpenDialogueOverlayMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/OpenInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/OpenInterfaceSidebarMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/OpenOverlayMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/OpenSidebarMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/PlayerDesignMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/PositionHintIconMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/PrivateChatMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/PublicChatMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/RegionChangeMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/Release317.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/RemoveFriendMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/RemoveIgnoreMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/RemoveObjectMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/RemoveTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SecondItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SecondItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SecondNpcActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SecondObjectActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SendFriendMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SendObjectMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ServerMessageMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetPlayerActionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetUpdatedRegionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetWidgetItemModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetWidgetModelAnimationMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetWidgetModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetWidgetNpcModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetWidgetPlayerModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetWidgetTextMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SetWidgetVisibilityMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SwitchItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/SwitchTabInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/TakeTileItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ThirdItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ThirdItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ThirdNpcActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/ThirdObjectActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/UpdateItemsMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/UpdateRunEnergyMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/UpdateSkillMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/UpdateSlottedItemsMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/UpdateTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/UpdateWeightMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/WalkMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r317/package-info.java diff --git a/game/data/equipment-317.dat b/game/data/equipment-317.dat deleted file mode 100644 index ee3475761f418c9d44613e772009adbfc91721ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22608 zcmeI4y>{a^5Js2D?#aoXq;r$TwVE`pRqO5Y%*qE~fQz3YMN*P&dF5h#IRFMT17HAx zKKsvq=Z!zVf78ztewOL{cd6+05DJqTm3CE8tg@e_BIGH2SlMsI!ObrGRhll-X2mlN z_L|CozAv?Iyl>yjy|tDtKdp&+m>pKZ>jO zBcgvlIy1F~v8u|dL0)Pws%Rzn5#^|Y+6HH))H0y}k}4iZYE0oj%OIXXD4IgIon@%r zN{0)(-Kg)iwAkL(-&>P2V^4nVT<`XFWXFVlnf(FoDi)h(mCWEJt!UNFd^GG;4jl;EuhyTgY*hCX#QDb(4oj6udOG;0?4aJ zZxEJ3SO9tYrkCOybSScE`d$WjH_1|K3&~59L9*UtkgPXZBuy=O5o9|l_7>Yhv9~CL zqNPy=VF6Y}TNEO*DiU5&`tp+ffDVT&lfKZhB%FODk4y_Bk4y&98+0u7Ao*c!6D9M4 zY#$}7LR%dQ(Y^<^?heVGhWEKCN;ACo~rbiJjIqlHL9L=qyB5RrsF z%5yA$KFXGB`ei0Uj10ucK#UA@Yg;^hSO8%G#K$5jA^L_oD`LO+0-<@CXaQjXgawdii`QE}qplrAua9eGuVnzxozFa0Hl-R| zVa~KTd#@~Q-MJd*enj#{>M5J1XAG{3LA7>n9m-1eMf8^B(8x0|R9Z|xUXmX)&!iRa z7A>|V$5bEO>u)is2Mil~yqzSZ>U5O=-A?;mHLV)<&Vu0*QAd|+WTu|6g1Vmd=yf#K znv-1DdQR)Tz9?B)w(WBD-=uyyF&(~7t@_}Q{oFLCfinr=QJIjua>{Q9}@Vq(m z>FCH#l`LPczEzizS$1?}r%JZq4d zJqR)_l0nu&GRQPb2B8H)3xpO3Es&LJcY)GU3D5n8yH+-@0jnXbhOG08@hF>B6V1>+ z`XTf~>w8LGJ>tJ!T6O%eX`#uWLLMM;Nu4(=zG?na9SUEGL6L};1*=3yz>mTD8PMgN?ZK;!4Vo^PBSumJP_X{>~c!X$znq{JeC@t-` zx47bSNhh=ep04enT-E!HaXTqq5H^~x{-~fch<%2D(#>U9Ur-vtAcM5CSX(IFVTO96 zv6ba@=B&h@3d1y2emP7BD4*%415|d*17wp}ZJ`@GXPs%-2GS6j3~G)6#n4<&1Br}d z0Ys@sDN@y68mKoL;)ZS%&$5~y9PFYHONN)-ioTjP&R^` zem}~6rQbvfD#u@DHtsjXegn1o^~5=GD3X9|ww96>uePUuQHGMmYWFLgyO&+vBfDXJ zCp7v+M^UvcAnh}d&F`0zvqd%y8?qLXK{ou7K{lZzgT6{1ES6RDqkikK7D|glTb&sO znYN)prj5a5qG7JE;Nt8!Y00L~w249@3x~7xR~3=mRmjwWP_16WUTFH?66!><fG{-#sfuz#JQAes#eq1&FP*YRDfbG#Use9Y|ePGG~F`< zEsOUItyRlU3xgNC49AVMgGQPex3&+)3(Dhhnocr5jEpGu5Y9Fg+5V+c$O0l6RJ4TM zDCtYP>nSLV`)s75CEvTLxM-OdcqHgxInqz+P7>$9V@gz*F>nDG;>ec@2NzRUC1n*xtGFhF^X_Rp@Q!TXn9wp0D7*wg)#)e+(i{Ikc!-&2utUW9^A z-hBSmWMuTnO;oj2Je+o@D#*JcMT*v=k1&i#w;txNA16dl_-P!1;FD{4&pzAdD+a+#e~>0?G{ zam2$iau>8t1$Hf2kS-?e^zw?POWPVpuU87Gf#F0miy; z3`FQagd<#^Rpz-U0Igk-nuQOwAg;q4x>-A&fVuNY3d|i!Qef^|lA@b&&h|*NW2^Dg z35cWuF#te>gCKJZDPABt59ufK?D+-0m^EZwrs@iJ1*)5F45)6p6sQil6!@h|f$E#< zI(oR0UV$E@EC4-7Nr4`uq(Fp&AWf&lOEe$e3%SDq_#UWm+%8bvbSY5XbSY5XbSY57 z;!>aqi}WBONFag)B1j;D6mCAkt?SCI8w1L%OM!ChQlQf0QlL8NQeYC^D)e`3454&~-d!kCmS1MfBK!VsEO4 z_)aX{r5u~sBi$F=9?P*Vrbn!By%a8{7}tN-EDlO)SZaV51M!l7xqX4rIuXCQOwG`Q z-`;3Ge9QKuz%HI|2U@KCJqvJ~eKY`WYkN1Xjm5F>kN1~1MR$Y21TJE*%h-3XH<9mCgc?!oZ5bzXb!SZo1Q`WL9k+R^c<-!h0`zj1F7U>k^qHoC z>`_DJQlN&+r3-{r{?`+aOPRB@iD3_38mwyyo9XK5+D&txu4G#)b%N{fw@#i0;9Wxv3mZ zrn>i07{7Gi><=4qQ{+MC;4PW=0?P*hn?$FR(8tww%(6=eU3Y=Lx=IT4ftM8MB_%2F zd-jG&v=x7~0qAwLB==IwWFXb9*z0Onbg8hbE@YgpoHhO)ddp_IlQed%bQeZh&npC+*%s}JKHl}`g<`Yhh zL7}UcD+E|odMk?B=gdLOHa&KA^dS1+$-+TA*a0*veYxbsU!vx2ZI>SG0Gc7FgZMr6 z#nuQ7#k0mN1t^w-c(Ab0tkl@+kIV3QgJ^-}S|5n=cD))&FcK`ZxBw zN7{VXAae1PH7UXyh_{}Z!Ojjb&Z9u}D=zb=G|zFIVU&_AJn@~?N||_zPxf^}x3j=` zU2QN?PPi7^tKqyOS!2(7_0;XQnPp14N8zQy)WTa(c)PvmBID;6-2daeZ=DrSz0n`^ zVXulYOdS?&VDm}C%BmfiY}B<6_)dTiEV^b|y8EXT9MPcwjGr{o42Whx^cjd|Ky>UN zA_WJr%bW?~?jZ2y&seE0YtWOSyvX&Rj|MMhab$X8&f7B&?>-NhO$RZWqg94w259&9 zEM}_@UkAfRGXw@~RvKulZ%_lic8it35G4?cA#mKiwXW;l!JoCyP&S$@rz|^`CCtY& zU!QaVX?pdZ6!M=$X5A!BUx@PE04)Y~R1|YNC>>zauM&NUGp{O0%ix4lK4+1>Z0B}B zd4U;VY;lhi#(=SfeTU;X9lNB;LC!`V*TlOl)O^mH?eKP4`103oQPb@n_}|ftCM;Sw85~SHVnmx6asbU&`;VGzJ2>pQqA^IpNqvwkD&m4e^|XbsEE(om~$hbu%1Ts;M@R6a}q6*ew`afh&vplU9E zgKmjNT>)cjZ$j$TsUmp*T9-X7@m8YghDqqCsn_EVZ^0)l{%_+k`Vyl5dv}U%7ynVR z2B0ht#swh_|8tE~D=m)ALP4`oFqWEyq5$1k3WXtR&h4r5vOMT77`&ZuB(?)W+BwWW z7TxuUjtv~BHaMnShx)4lxA5-}*Q4Bg7ui*t#bq%Qe-u^juK(sTE%VB?{UAkLoY!ro zyS}!_NLii|&zr*M6fwATXigTF*W_jvGJ=??@;=Vaqcbop18L;W990^Q;sfuC-2V@( Cfv|u8 diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt index 6fffee19a..252bc9dd9 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt @@ -37,6 +37,6 @@ fun Player.interactWith(entity: Entity, option: Int = 1) { when (entity) { is GameObject -> send(ObjectActionMessage(option, entity.id, entity.position)) is Npc -> send(NpcActionMessage(option, entity.index)) - is Player -> send(PlayerActionMessage(option, entity.index)) + is Player -> send(PlayerActionMessage(option, entity.index, movementType)) } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/Server.java b/game/src/main/java/org/apollo/Server.java index de429aeaf..f0b206f43 100644 --- a/game/src/main/java/org/apollo/Server.java +++ b/game/src/main/java/org/apollo/Server.java @@ -12,7 +12,7 @@ import org.apollo.game.model.World; import org.apollo.game.plugin.PluginContext; import org.apollo.game.plugin.PluginManager; -import org.apollo.game.release.r377.Release377; +import org.apollo.game.release.r181.Release181; import org.apollo.game.session.ApolloHandler; import org.apollo.net.HttpChannelInitializer; import org.apollo.net.JagGrabChannelInitializer; @@ -26,7 +26,6 @@ import java.net.SocketAddress; import java.nio.file.Paths; import java.util.Arrays; -import java.util.HashSet; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -53,7 +52,7 @@ public static void main(String[] args) { try { Server server = new Server(); - server.init(args.length == 1 ? args[0] : Release377.class.getName()); + server.init(args.length == 1 ? args[0] : Release181.class.getName()); server.bind(new InetSocketAddress(NetworkConstants.HTTP_PORT), new InetSocketAddress(NetworkConstants.JAGGRAB_PORT), diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java index ee88bc834..2e2f3fc62 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java @@ -17,6 +17,11 @@ public final class PlayerActionMessage extends Message { */ private final int index; + /** + * The movement type that the player performs. + */ + private final int movementType; + /** * The option number. */ @@ -24,13 +29,14 @@ public final class PlayerActionMessage extends Message { /** * Creates a player action message. - * - * @param option The option number. + * @param option The option number. * @param index The index of the player. + * @param movementType The type of movement. */ - public PlayerActionMessage(int option, int index) { + public PlayerActionMessage(int option, int index, int movementType) { this.option = option; this.index = index; + this.movementType = movementType; } /** @@ -42,6 +48,15 @@ public int getIndex() { return index; } + /** + * Gets movement type. + * + * @return the movement type + */ + public int getMovementType() { + return movementType; + } + /** * Gets the menu action number (i.e. the action message 'option') clicked. * diff --git a/game/src/main/java/org/apollo/game/release/r317/ArrowKeyMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/ArrowKeyMessageDecoder.java similarity index 63% rename from game/src/main/java/org/apollo/game/release/r317/ArrowKeyMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/ArrowKeyMessageDecoder.java index 9a73b04d5..47ffad951 100644 --- a/game/src/main/java/org/apollo/game/release/r317/ArrowKeyMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/ArrowKeyMessageDecoder.java @@ -1,10 +1,7 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.ArrowKeyMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** @@ -17,8 +14,9 @@ public final class ArrowKeyMessageDecoder extends MessageDecoder { + + @Override + public PlayerActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); + int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + return new PlayerActionMessage(8, index, movementType); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/EnteredAmountMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/EnteredAmountMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r317/EnteredAmountMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/EnteredAmountMessageDecoder.java index 1b43ed44c..660ae11c6 100644 --- a/game/src/main/java/org/apollo/game/release/r317/EnteredAmountMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/EnteredAmountMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.EnteredAmountMessage; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/FifthPlayerActionMessageDecoder.java similarity index 64% rename from game/src/main/java/org/apollo/game/release/r317/FifthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/FifthPlayerActionMessageDecoder.java index d7a37ae09..5ca7666ee 100644 --- a/game/src/main/java/org/apollo/game/release/r317/FifthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/FifthPlayerActionMessageDecoder.java @@ -1,7 +1,7 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -17,8 +17,8 @@ public final class FifthPlayerActionMessageDecoder extends MessageDecoder { @@ -18,7 +17,8 @@ public final class ReportAbuseMessageDecoder extends MessageDecoder { + + @Override + public PlayerActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + return new PlayerActionMessage(7, index, movementType); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/SixthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/SixthPlayerActionMessageDecoder.java new file mode 100644 index 000000000..951e8afc5 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/SixthPlayerActionMessageDecoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the sixth {@link PlayerActionMessage}. + * + * @author Major + */ +public final class SixthPlayerActionMessageDecoder extends MessageDecoder { + + @Override + public PlayerActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + return new PlayerActionMessage(6, index, movementType); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SpamPacketMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/SpamPacketMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r317/SpamPacketMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/SpamPacketMessageDecoder.java index 4a1a85834..651888495 100644 --- a/game/src/main/java/org/apollo/game/release/r317/SpamPacketMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/SpamPacketMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.SpamPacketMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/ThirdPlayerActionMessageDecoder.java similarity index 56% rename from game/src/main/java/org/apollo/game/release/r317/ThirdPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/ThirdPlayerActionMessageDecoder.java index f50e64b5a..c5490bff7 100644 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/ThirdPlayerActionMessageDecoder.java @@ -1,10 +1,7 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** @@ -17,8 +14,9 @@ public final class ThirdPlayerActionMessageDecoder extends MessageDecoder { + + @Override + public WalkMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + + int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + long type = reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + + Position[] positions = new Position[1]; + positions[0] = new Position(x, y); + return new WalkMessage(positions, type == 1); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/AddFriendMessageDecoder.java deleted file mode 100644 index 606c246da..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/AddFriendMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.AddFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link AddFriendMessage}. - * - * @author Major - */ -public final class AddFriendMessageDecoder extends MessageDecoder { - - @Override - public AddFriendMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new AddFriendMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/AddGlobalTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/AddGlobalTileItemMessageEncoder.java deleted file mode 100644 index 3461c7e77..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/AddGlobalTileItemMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendPublicTileItemMessage}. - * - * @author Major - */ -public final class AddGlobalTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendPublicTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(215); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getPositionOffset()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getIndex()); - builder.put(DataType.SHORT, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/AddIgnoreMessageDecoder.java deleted file mode 100644 index 879ad5ff7..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/AddIgnoreMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.AddIgnoreMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link AddIgnoreMessage}. - * - * @author Major - */ -public final class AddIgnoreMessageDecoder extends MessageDecoder { - - @Override - public AddIgnoreMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new AddIgnoreMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/AddTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/AddTileItemMessageEncoder.java deleted file mode 100644 index 06c0ff9d0..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/AddTileItemMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendTileItemMessage}. - * - * @author Major - */ -public final class AddTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(44); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - builder.put(DataType.SHORT, message.getAmount()); - builder.put(DataType.BYTE, message.getPositionOffset()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ButtonMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ButtonMessageDecoder.java deleted file mode 100644 index 0abccdb57..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ButtonMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ButtonMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ButtonMessage}. - * - * @author Graham - */ -public final class ButtonMessageDecoder extends MessageDecoder { - - @Override - public ButtonMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - return new ButtonMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ClearRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ClearRegionMessageEncoder.java deleted file mode 100644 index 8a7076d4c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ClearRegionMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ClearRegionMessage}. - * - * @author Major - */ -public final class ClearRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ClearRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(64); - Position player = message.getPlayerPosition(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/CloseInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/CloseInterfaceMessageEncoder.java deleted file mode 100644 index df11c074c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/CloseInterfaceMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link CloseInterfaceMessage}. - * - * @author Graham - */ -public final class CloseInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(CloseInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(219); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ConfigMessageEncoder.java deleted file mode 100644 index e51207feb..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ConfigMessageEncoder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ConfigMessage}. - * - * @author Chris Fletcher - * @author Major - */ -public final class ConfigMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ConfigMessage message) { - GamePacketBuilder builder; - int value = message.getValue(); - - if (value > Byte.MIN_VALUE && value < Byte.MAX_VALUE) { - builder = new GamePacketBuilder(36); - - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - builder.put(DataType.BYTE, value & 0xFF); - } else { - builder = new GamePacketBuilder(87); - - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - builder.put(DataType.INT, DataOrder.MIDDLE, value); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/DialogueContinueMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/DialogueContinueMessageDecoder.java deleted file mode 100644 index 17daaa1f3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/DialogueContinueMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.DialogueContinueMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link DialogueContinueMessage}. - * - * @author Chris Fletcher - */ -public final class DialogueContinueMessageDecoder extends MessageDecoder { - - @Override - public DialogueContinueMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - - return new DialogueContinueMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/DisplayCrossbonesMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/DisplayCrossbonesMessageEncoder.java deleted file mode 100644 index fed00fbad..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/DisplayCrossbonesMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayCrossbonesMessage}. - * - * @author Major - */ -public final class DisplayCrossbonesMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayCrossbonesMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(61); - builder.put(DataType.BYTE, message.isDisplayed() ? 1 : 0); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/DisplayTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/DisplayTabInterfaceMessageEncoder.java deleted file mode 100644 index e1366dd23..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/DisplayTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayTabInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class DisplayTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(106); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/EnterAmountMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/EnterAmountMessageEncoder.java deleted file mode 100644 index ea8e33fd9..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/EnterAmountMessageEncoder.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apollo.game.release.r317; - -import io.netty.buffer.Unpooled; - -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link EnterAmountMessage}. - * - * @author Graham - */ -public final class EnterAmountMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(EnterAmountMessage message) { - return new GamePacket(27, PacketType.FIXED, Unpooled.EMPTY_BUFFER); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FifthItemActionMessageDecoder.java deleted file mode 100644 index a27d2d31c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FifthItemActionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FifthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new ItemActionMessage(5, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FifthItemOptionMessageDecoder.java deleted file mode 100644 index 04ff2f6ed..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FifthItemOptionMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FifthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(5, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FifthNpcActionMessageDecoder.java deleted file mode 100644 index bc813629b..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FifthNpcActionMessageDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link NpcActionMessage}. - * - * @author Stuart - * @author Major - */ -public final class FifthNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new NpcActionMessage(5, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstItemActionMessageDecoder.java deleted file mode 100644 index 7e38c74fa..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstItemActionMessageDecoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FirstItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new ItemActionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstItemOptionMessageDecoder.java deleted file mode 100644 index 5f8c4c46f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemOptionMessage}. - * - * @author Graham - */ -public final class FirstItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemOptionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstNpcActionMessageDecoder.java deleted file mode 100644 index c42f916f1..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstNpcActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link NpcActionMessage}. - * - * @author Major - */ -public final class FirstNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - return new NpcActionMessage(1, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstObjectActionMessageDecoder.java deleted file mode 100644 index b71feb1fa..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstObjectActionMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class FirstObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT); - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new ObjectActionMessage(1, id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FlaggedMouseEventMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FlaggedMouseEventMessageDecoder.java deleted file mode 100644 index 8092a66b5..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FlaggedMouseEventMessageDecoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FlaggedMouseEventMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link org.apollo.game.message.impl.FlaggedMouseEventMessage}. - * - * @author Major - */ -public final class FlaggedMouseEventMessageDecoder extends MessageDecoder { - - @Override - public FlaggedMouseEventMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int read; - if (reader.getLength() == 2) { - read = (int) reader.getUnsigned(DataType.SHORT); - int clicks = read >> 12; - int dX = read >> 6 & 0x3f; - int dY = read & 0x3f; - return new FlaggedMouseEventMessage(clicks, dX, dY, true); - } else if (reader.getLength() == 3) { - read = (int) reader.getUnsigned(DataType.TRI_BYTE) & ~0x800000; - } else { - read = (int) reader.getUnsigned(DataType.INT) & ~0xc0000000; - } - - int clicks = read >> 19; - int x = (read & 0x7f) % 765; - int y = (read & 0x7f) / 765; - - return new FlaggedMouseEventMessage(clicks, x, y, false); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FlashTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/FlashTabInterfaceMessageEncoder.java deleted file mode 100644 index f51cb7298..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FlashTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FlashTabInterfaceMessage}. - * - * @author Major - */ -public final class FlashTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FlashTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(24); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FlashingTabClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FlashingTabClickedMessageDecoder.java deleted file mode 100644 index 5d44411e1..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FlashingTabClickedMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FlashingTabClickedMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link FlashingTabClickedMessage}. - * - * @author Major - */ -public final class FlashingTabClickedMessageDecoder extends MessageDecoder { - - @Override - public FlashingTabClickedMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int tab = (int) reader.getUnsigned(DataType.BYTE); - return new FlashingTabClickedMessage(tab); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FocusUpdateMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FocusUpdateMessageDecoder.java deleted file mode 100644 index 4883ebe10..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FocusUpdateMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FocusUpdateMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link FocusUpdateMessage}. - * - * @author Major - */ -public final class FocusUpdateMessageDecoder extends MessageDecoder { - - @Override - public FocusUpdateMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - boolean focused = (byte) reader.getUnsigned(DataType.BYTE) == 1; - return new FocusUpdateMessage(focused); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ForwardPrivateChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ForwardPrivateChatMessageEncoder.java deleted file mode 100644 index 0d4b39b9b..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ForwardPrivateChatMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r317; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link ForwardPrivateChatMessage}. - * - * @author Major - */ -public final class ForwardPrivateChatMessageEncoder extends MessageEncoder { - - /** - * The amount of messages sent globally, offset by a random variable x, {@code 0 <= x < 100,000,000}. - */ - private static AtomicInteger messageCounter = new AtomicInteger((int) (Math.random() * 100_000_000)); - - @Override - public GamePacket encode(ForwardPrivateChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(196, PacketType.VARIABLE_BYTE); - - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getSenderUsername())); - builder.put(DataType.INT, messageCounter.incrementAndGet()); - builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger()); - builder.putBytes(message.getCompressedMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FourthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FourthItemActionMessageDecoder.java deleted file mode 100644 index 10630a3d4..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FourthItemActionMessageDecoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FourthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new ItemActionMessage(4, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FourthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FourthItemOptionMessageDecoder.java deleted file mode 100644 index 6d21c806f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FourthItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FourthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(4, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FourthNpcActionMessageDecoder.java deleted file mode 100644 index de9226d6b..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FourthNpcActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link NpcActionMessage}. - * - * @author Stuart - * @author Major - */ -public final class FourthNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT); - return new NpcActionMessage(4, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FriendServerStatusMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/FriendServerStatusMessageEncoder.java deleted file mode 100644 index 9da6868df..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FriendServerStatusMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FriendServerStatusMessage}. - * - * @author Major - */ -public final class FriendServerStatusMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FriendServerStatusMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(221); - builder.put(DataType.BYTE, message.getStatusCode()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/GroupedRegionUpdateMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/GroupedRegionUpdateMessageEncoder.java deleted file mode 100644 index cd6703b77..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/GroupedRegionUpdateMessageEncoder.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.RegionUpdateMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.net.release.Release; - -/** - * A {@link MessageEncoder} for the {@link GroupedRegionUpdateMessage}. - * - * @author Major - */ -public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder { - - /** - * The Release containing the MessageEncoders for the RegionUpdateMessages. - */ - private final Release release; - - /** - * Creates the GroupedRegionUpdateMessageEncoder. - * - * @param release The {@link Release} containing the {@link MessageEncoder}s for the {@link RegionUpdateMessage}s. - */ - public GroupedRegionUpdateMessageEncoder(Release release) { - this.release = release; - } - - @Override - public GamePacket encode(GroupedRegionUpdateMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT); - Position base = message.getLastKnownRegion(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, region.getLocalY(base)); - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(base)); - - for (RegionUpdateMessage update : message.getMessages()) { - @SuppressWarnings("unchecked") - MessageEncoder encoder = (MessageEncoder) release - .getMessageEncoder(update.getClass()); - - GamePacket packet = encoder.encode(update); - builder.put(DataType.BYTE, packet.getOpcode()); - builder.putBytes(packet.content()); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/IdAssignmentMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/IdAssignmentMessageEncoder.java deleted file mode 100644 index 8c95a2220..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/IdAssignmentMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link IdAssignmentMessage}. - * - * @author Graham - */ -public final class IdAssignmentMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IdAssignmentMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(249); - builder.put(DataType.BYTE, DataTransformation.ADD, message.isMembers() ? 1 : 0); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/IgnoreListMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/IgnoreListMessageEncoder.java deleted file mode 100644 index bf8056649..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/IgnoreListMessageEncoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apollo.game.release.r317; - -import java.util.List; - -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link IgnoreListMessage}. - * - * @author Major - */ -public final class IgnoreListMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IgnoreListMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(214, PacketType.VARIABLE_SHORT); - - List usernames = message.getUsernames(); - for (String username : usernames) { - builder.put(DataType.LONG, NameUtil.encodeBase37(username)); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ItemOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ItemOnItemMessageDecoder.java deleted file mode 100644 index e2f34d1ac..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ItemOnItemMessageDecoder.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOnItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnItemMessageDecoder}. - * - * @author Chris Fletcher - */ -public final class ItemOnItemMessageDecoder extends MessageDecoder { - - @Override - public ItemOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int targetSlot = (int) reader.getUnsigned(DataType.SHORT); - int usedSlot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - int targetId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int targetInterface = (int) reader.getUnsigned(DataType.SHORT); - - int usedId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int usedInterface = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOnItemMessage(usedInterface, usedId, usedSlot, targetInterface, targetId, targetSlot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ItemOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ItemOnNpcMessageDecoder.java deleted file mode 100644 index 6d9eefcd3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ItemOnNpcMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnNpcMessage}. - * - * @author Lmctruck30 - */ -public final class ItemOnNpcMessageDecoder extends MessageDecoder { - - @Override - public ItemOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOnNpcMessage(id, index, slot, interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ItemOnObjectMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ItemOnObjectMessageDecoder.java deleted file mode 100644 index 4482a7826..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ItemOnObjectMessageDecoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOnObjectMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnObjectMessage}. - * - * @author Major - */ -public final class ItemOnObjectMessageDecoder extends MessageDecoder { - - @Override - public ItemOnObjectMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int objectId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int itemId = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOnObjectMessage(interfaceId, itemId, slot, objectId, x, y); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/LogoutMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/LogoutMessageEncoder.java deleted file mode 100644 index 15a7b7235..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/LogoutMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link LogoutMessage}. - * - * @author Graham - */ -public final class LogoutMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(LogoutMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(109); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MagicOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MagicOnItemMessageDecoder.java deleted file mode 100644 index 677a81db1..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MagicOnItemMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MagicOnItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnItemMessage}. - * - * @author Chris Fletcher - */ -public final class MagicOnItemMessageDecoder extends MessageDecoder { - - @Override - public MagicOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnItemMessage(interfaceId, id, slot, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MagicOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MagicOnNpcMessageDecoder.java deleted file mode 100644 index e794d8400..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MagicOnNpcMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MagicOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnNpcMessage} - * - * @author Stuart - */ -public final class MagicOnNpcMessageDecoder extends MessageDecoder { - - @Override - public MagicOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnNpcMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MagicOnPlayerMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MagicOnPlayerMessageDecoder.java deleted file mode 100644 index 085fe5096..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MagicOnPlayerMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MagicOnPlayerMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnPlayerMessage} - * - * @author Stuart - */ -public final class MagicOnPlayerMessageDecoder extends MessageDecoder { - - @Override - public MagicOnPlayerMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new MagicOnPlayerMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MobAnimationResetMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/MobAnimationResetMessageEncoder.java deleted file mode 100644 index 14f47f1a0..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MobAnimationResetMessageEncoder.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MobAnimationResetMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobAnimationResetMessage}. - * - * @author Major - */ -public final class MobAnimationResetMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobAnimationResetMessage message) { - return new GamePacketBuilder(1).toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MobHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/MobHintIconMessageEncoder.java deleted file mode 100644 index 7ad60c39d..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MobHintIconMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobHintIconMessage}. - * - * @author Major - */ -public final class MobHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(254); - HintIconMessage.Type type = message.getType(); - builder.put(DataType.BYTE, type.getValue()); - - switch (type) { - case NPC: - case PLAYER: - builder.put(DataType.SHORT, message.getIndex()); - builder.put(DataType.TRI_BYTE, 0); // Dummy bytes - break; - default: - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MouseClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MouseClickedMessageDecoder.java deleted file mode 100644 index 68c10e24f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MouseClickedMessageDecoder.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MouseClickedMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MouseClickedMessage} - * - * @author Stuart - */ -public final class MouseClickedMessageDecoder extends MessageDecoder { - - @Override - public MouseClickedMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int value = (int) reader.getUnsigned(DataType.INT); - - long delay = (value >> 20) * 50; - boolean right = (value >> 19 & 0x1) == 1; - - int cords = value & 0x3FFFF; - int x = cords % 765; - int y = cords / 765; - - return new MouseClickedMessage(delay, right, x, y); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/NpcSynchronizationMessageEncoder.java deleted file mode 100644 index a426a7b83..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/NpcSynchronizationMessageEncoder.java +++ /dev/null @@ -1,300 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Position; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TransformBlock; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddNpcSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link NpcSynchronizationMessage}. - * - * @author Major - */ -public final class NpcSynchronizationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(NpcSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(65, PacketType.VARIABLE_SHORT); - builder.switchToBitAccess(); - - GamePacketBuilder blockBuilder = new GamePacketBuilder(); - builder.putBits(8, message.getLocalNpcCount()); - - for (SynchronizationSegment segment : message.getSegments()) { - SegmentType type = segment.getType(); - if (type == SegmentType.REMOVE_MOB) { - putRemoveMobUpdate(builder); - } else if (type == SegmentType.ADD_MOB) { - putAddNpcUpdate((AddNpcSegment) segment, message, builder); - putBlocks(segment, blockBuilder); - } else { - putMovementUpdate(segment, message, builder); - putBlocks(segment, blockBuilder); - } - } - - if (blockBuilder.getLength() > 0) { - builder.putBits(14, 16383); - builder.switchToByteAccess(); - builder.putRawBuilder(blockBuilder); - } else { - builder.switchToByteAccess(); - } - - return builder.toGamePacket(); - } - - /** - * Puts an add npc update. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - Position npc = message.getPosition(); - Position other = seg.getPosition(); - builder.putBits(14, seg.getIndex()); - builder.putBits(5, other.getY() - npc.getY()); - builder.putBits(5, other.getX() - npc.getX()); - builder.putBits(1, 0); // discard walking queue - builder.putBits(12, seg.getNpcId()); - builder.putBits(1, updateRequired ? 1 : 0); - } - - /** - * Puts an animation block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { - Animation animation = block.getAnimation(); - builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId()); - builder.put(DataType.BYTE, animation.getDelay()); - } - - /** - * Puts the blocks for the specified segment. - * - * @param segment The segment. - * @param builder The block builder. - */ - private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { - SynchronizationBlockSet blockSet = segment.getBlockSet(); - if (blockSet.size() > 0) { - int mask = 0; - - if (blockSet.contains(AnimationBlock.class)) { - mask |= 0x10; - } - - if (blockSet.contains(HitUpdateBlock.class)) { - mask |= 0x8; - } - - if (blockSet.contains(GraphicBlock.class)) { - mask |= 0x80; - } - - if (blockSet.contains(InteractingMobBlock.class)) { - mask |= 0x20; - } - - if (blockSet.contains(ForceChatBlock.class)) { - mask |= 0x1; - } - - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - mask |= 0x40; - } - - if (blockSet.contains(TransformBlock.class)) { - mask |= 0x2; - } - - if (blockSet.contains(TurnToPositionBlock.class)) { - mask |= 0x4; - } - - builder.put(DataType.BYTE, mask); - - if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), builder); - } - - if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); - } - - if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), builder); - } - - if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); - } - - if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); - } - - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } - - if (blockSet.contains(TransformBlock.class)) { - putTransformBlock(blockSet.get(TransformBlock.class), builder); - } - - if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); - } - } - } - - /** - * Puts a force chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { - builder.putString(block.getMessage()); - } - - /** - * Puts a graphic block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { - Graphic graphic = block.getGraphic(); - builder.put(DataType.SHORT, graphic.getId()); - builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF); - } - - /** - * Puts a hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType()); - builder.put(DataType.BYTE, DataTransformation.ADD, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts an interacting mob block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, block.getIndex()); - } - - /** - * Puts a movement update for the specified segment. - * - * @param segment The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putMovementUpdate(SynchronizationSegment segment, NpcSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = segment.getBlockSet().size() > 0; - if (segment.getType() == SegmentType.RUN) { - Direction[] directions = ((MovementSegment) segment).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 2); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(3, directions[1].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (segment.getType() == SegmentType.WALK) { - Direction[] directions = ((MovementSegment) segment).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 1); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else { - if (updateRequired) { - builder.putBits(1, 1); - builder.putBits(2, 0); - } else { - builder.putBits(1, 0); - } - } - } - - /** - * Puts a remove mob update. - * - * @param builder The builder. - */ - private static void putRemoveMobUpdate(GamePacketBuilder builder) { - builder.putBits(1, 1); - builder.putBits(2, 3); - } - - /** - * Puts a second hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getMaximumHealth()); - } - - /** - * Puts a transform block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTransformBlock(TransformBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, block.getId()); - } - - /** - * Puts a turn to position block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position position = block.getPosition(); - builder.put(DataType.SHORT, DataOrder.LITTLE, position.getX() * 2 + 1); - builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenDialogueInterfaceMessageEncoder.java deleted file mode 100644 index 6a9352f19..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class OpenDialogueInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(164); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenDialogueOverlayMessageEncoder.java deleted file mode 100644 index 49017e0f2..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueOverlayMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueOverlayMessage}. - * - * @author Major - */ -public final class OpenDialogueOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(218); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceMessageEncoder.java deleted file mode 100644 index d5aafeb3e..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceMessage}. - * - * @author Graham - */ -public final class OpenInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(97); - builder.put(DataType.SHORT, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceSidebarMessageEncoder.java deleted file mode 100644 index 24cb565ec..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceSidebarMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceSidebarMessage}. - * - * @author Graham - */ -public final class OpenInterfaceSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(248); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenOverlayMessageEncoder.java deleted file mode 100644 index d7baafd1a..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenOverlayMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenOverlayMessage}. - * - * @author Major - */ -public final class OpenOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(208); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getOverlayId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenSidebarMessageEncoder.java deleted file mode 100644 index f9b4f073c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenSidebarMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenSidebarMessage}. - * - * @author Major - */ -public final class OpenSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(142); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PlayerDesignMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/PlayerDesignMessageDecoder.java deleted file mode 100644 index 9fa85a634..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PlayerDesignMessageDecoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PlayerDesignMessage; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link PlayerDesignMessage}. - * - * @author Graham - */ -public final class PlayerDesignMessageDecoder extends MessageDecoder { - - @Override - public PlayerDesignMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int genderIntValue = (int) reader.getUnsigned(DataType.BYTE); - - int[] style = new int[7]; - for (int i = 0; i < style.length; i++) { - style[i] = (int) reader.getUnsigned(DataType.BYTE); - } - - int[] color = new int[5]; - for (int i = 0; i < color.length; i++) { - color[i] = (int) reader.getUnsigned(DataType.BYTE); - } - - Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE; - - return new PlayerDesignMessage(new Appearance(gender, style, color)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java deleted file mode 100644 index b628ded53..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java +++ /dev/null @@ -1,460 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Item; -import org.apollo.game.model.Position; -import org.apollo.game.model.entity.EquipmentConstants; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.game.model.inv.Inventory; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.ForceMovementBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddPlayerSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PlayerSynchronizationMessage}. - * - * @author Graham - * @author Major - */ -public final class PlayerSynchronizationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PlayerSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(81, PacketType.VARIABLE_SHORT); - builder.switchToBitAccess(); - - GamePacketBuilder blockBuilder = new GamePacketBuilder(); - - putMovementUpdate(message.getSegment(), message, builder); - putBlocks(message.getSegment(), blockBuilder); - - builder.putBits(8, message.getLocalPlayers()); - - for (SynchronizationSegment segment : message.getSegments()) { - SegmentType type = segment.getType(); - if (type == SegmentType.REMOVE_MOB) { - putRemovePlayerUpdate(builder); - } else if (type == SegmentType.ADD_MOB) { - putAddPlayerUpdate((AddPlayerSegment) segment, message, builder); - putBlocks(segment, blockBuilder); - } else { - putMovementUpdate(segment, message, builder); - putBlocks(segment, blockBuilder); - } - } - - if (blockBuilder.getLength() > 0) { - builder.putBits(11, 2047); - builder.switchToByteAccess(); - builder.putRawBuilder(blockBuilder); - } else { - builder.switchToByteAccess(); - } - - return builder.toGamePacket(); - } - - /** - * Puts an add player update. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - Position player = message.getPosition(); - Position other = seg.getPosition(); - builder.putBits(11, seg.getIndex()); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(1, 1); // discard walking queue? - builder.putBits(5, other.getY() - player.getY()); - builder.putBits(5, other.getX() - player.getX()); - } - - /** - * Puts an animation block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { - Animation animation = block.getAnimation(); - builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, animation.getDelay()); - } - - /** - * Puts an appearance block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { - Appearance appearance = block.getAppearance(); - GamePacketBuilder playerProperties = new GamePacketBuilder(); - - playerProperties.put(DataType.BYTE, appearance.getGender().toInteger()); - playerProperties.put(DataType.BYTE, 0); - - if (block.appearingAsNpc()) { - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.SHORT, block.getNpcId()); - } else { - Inventory equipment = block.getEquipment(); - int[] style = appearance.getStyle(); - Item item, chest, helm; - - for (int slot = 0; slot < 4; slot++) { - if ((item = equipment.get(slot)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } - - if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + chest.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[2]); - } - - if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - - if (chest != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId()); - if (def != null && !def.isFullBody()) { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } - - if ((item = equipment.get(EquipmentConstants.LEGS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[5]); - } - - if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId()); - if (def != null && !def.isFullHat() && !def.isFullMask()) { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } - - if ((item = equipment.get(EquipmentConstants.HANDS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[4]); - } - - if ((item = equipment.get(EquipmentConstants.FEET)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[6]); - } - - EquipmentDefinition def = null; - if (helm != null) { - def = EquipmentDefinition.lookup(helm.getId()); - } - if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { - playerProperties.put(DataType.BYTE, 0); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[1]); - } - } - - int[] colors = appearance.getColors(); - for (int color : colors) { - playerProperties.put(DataType.BYTE, color); - } - - playerProperties.put(DataType.SHORT, 0x328); // stand - playerProperties.put(DataType.SHORT, 0x337); // stand turn - playerProperties.put(DataType.SHORT, 0x333); // walk - playerProperties.put(DataType.SHORT, 0x334); // turn 180 - playerProperties.put(DataType.SHORT, 0x335); // turn 90 cw - playerProperties.put(DataType.SHORT, 0x336); // turn 90 ccw - playerProperties.put(DataType.SHORT, 0x338); // run - - playerProperties.put(DataType.LONG, block.getName()); - playerProperties.put(DataType.BYTE, block.getCombatLevel()); - playerProperties.put(DataType.SHORT, block.getSkillLevel()); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, playerProperties.getLength()); - - builder.putRawBuilder(playerProperties); - } - - /** - * Puts the blocks for the specified segment. - * - * @param segment The segment. - * @param builder The block builder. - */ - private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { - SynchronizationBlockSet blockSet = segment.getBlockSet(); - if (blockSet.size() > 0) { - int mask = 0; - - if (blockSet.contains(ForceMovementBlock.class)) { - mask |= 0x400; - } - if (blockSet.contains(GraphicBlock.class)) { - mask |= 0x100; - } - if (blockSet.contains(AnimationBlock.class)) { - mask |= 0x8; - } - if (blockSet.contains(ForceChatBlock.class)) { - mask |= 0x4; - } - if (blockSet.contains(ChatBlock.class)) { - mask |= 0x80; - } - if (blockSet.contains(InteractingMobBlock.class)) { - mask |= 0x1; - } - if (blockSet.contains(AppearanceBlock.class)) { - mask |= 0x10; - } - if (blockSet.contains(TurnToPositionBlock.class)) { - mask |= 0x2; - } - if (blockSet.contains(HitUpdateBlock.class)) { - mask |= 0x20; - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - mask |= 0x200; - } - - if (mask >= 0x100) { - mask |= 0x40; - builder.put(DataType.SHORT, DataOrder.LITTLE, mask); - } else { - builder.put(DataType.BYTE, mask); - } - - if (blockSet.contains(ForceMovementBlock.class)) { - putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder); - } - if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), builder); - } - if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), builder); - } - if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); - } - if (blockSet.contains(ChatBlock.class)) { - putChatBlock(blockSet.get(ChatBlock.class), builder); - } - if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); - } - if (blockSet.contains(AppearanceBlock.class)) { - putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder); - } - if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); - } - if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } - } - } - - /** - * Puts a chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) { - byte[] bytes = block.getCompressedMessage(); - builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextColor() << 8 | block.getTextEffects()); - builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, bytes.length); - builder.putBytesReverse(bytes); - } - - /** - * Puts a force chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { - builder.putString(block.getMessage()); - } - - /** - * Puts a force movement block in the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialX()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialY()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalY()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, block.getTravelDurationX()); - builder.put(DataType.SHORT, DataTransformation.ADD, block.getTravelDurationY()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDirection().toInteger()); - } - - /** - * Puts a graphic block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { - Graphic graphic = block.getGraphic(); - builder.put(DataType.SHORT, DataOrder.LITTLE, graphic.getId()); - builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF); - } - - /** - * Puts a hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.ADD, block.getType()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts an interacting mob block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataOrder.LITTLE, block.getIndex()); - } - - /** - * Puts a movement update for the specified segment. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - if (seg.getType() == SegmentType.TELEPORT) { - Position position = ((TeleportSegment) seg).getDestination(); - builder.putBits(1, 1); - builder.putBits(2, 3); - builder.putBits(2, position.getHeight()); - builder.putBits(1, message.hasRegionChanged() ? 0 : 1); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(7, position.getLocalY(message.getLastKnownRegion())); - builder.putBits(7, position.getLocalX(message.getLastKnownRegion())); - } else if (seg.getType() == SegmentType.RUN) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 2); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(3, directions[1].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (seg.getType() == SegmentType.WALK) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 1); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else { - if (updateRequired) { - builder.putBits(1, 1); - builder.putBits(2, 0); - } else { - builder.putBits(1, 0); - } - } - } - - /** - * Puts a remove player update. - * - * @param builder The builder. - */ - private static void putRemovePlayerUpdate(GamePacketBuilder builder) { - builder.putBits(1, 1); - builder.putBits(2, 3); - } - - /** - * Puts a Second Hit Update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); - builder.put(DataType.BYTE, block.getCurrentHealth()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getMaximumHealth()); - } - - /** - * Puts a Turn To Position block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position pos = block.getPosition(); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, pos.getX() * 2 + 1); - builder.put(DataType.SHORT, DataOrder.LITTLE, pos.getY() * 2 + 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PositionHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/PositionHintIconMessageEncoder.java deleted file mode 100644 index 73df34dfe..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PositionHintIconMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.HintIconMessage.Type; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PositionHintIconMessage}. - */ -public final class PositionHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PositionHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(254); - HintIconMessage.Type type = message.getType(); - - if (type == Type.PLAYER || type == Type.NPC) { - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - builder.put(DataType.BYTE, type.getValue()); - - Position position = message.getPosition(); - builder.put(DataType.SHORT, position.getX()); - builder.put(DataType.SHORT, position.getY()); - builder.put(DataType.BYTE, message.getHeight()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageEncoder.java deleted file mode 100644 index 043b8432c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PrivacyOptionMessage}. - * - * @author Kyle Stevenson - */ -public final class PrivacyOptionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(final PrivacyOptionMessage message) { - final GamePacketBuilder builder = new GamePacketBuilder(206); - - builder.put(DataType.BYTE, message.getChatPrivacy().toInteger(true)); - builder.put(DataType.BYTE, message.getFriendPrivacy().toInteger(true)); - builder.put(DataType.BYTE, message.getTradePrivacy().toInteger(true)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/PrivateChatMessageDecoder.java deleted file mode 100644 index 7d73af118..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PrivateChatMessageDecoder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PrivateChatMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; -import org.apollo.util.TextUtil; - -/** - * A {@link MessageDecoder} for the {@link PrivateChatMessage}. - * - * @author Major - */ -public final class PrivateChatMessageDecoder extends MessageDecoder { - - @Override - public PrivateChatMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - int length = packet.getLength() - Long.BYTES; - - byte[] originalCompressed = new byte[length]; - reader.getBytes(originalCompressed); - - String decompressed = TextUtil.decompress(originalCompressed, length); - decompressed = TextUtil.filterInvalidCharacters(decompressed); - decompressed = TextUtil.capitalize(decompressed); - - byte[] recompressed = new byte[length]; - TextUtil.compress(decompressed, recompressed); - - return new PrivateChatMessage(new String(decompressed), recompressed, username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PublicChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/PublicChatMessageDecoder.java deleted file mode 100644 index 42e4abcaf..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PublicChatMessageDecoder.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PublicChatMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.TextUtil; - -/** - * A {@link MessageDecoder} for the {@link PublicChatMessage}. - * - * @author Graham - */ -public final class PublicChatMessageDecoder extends MessageDecoder { - - @Override - public PublicChatMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); - int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); - int length = packet.getLength() - 2; - - byte[] originalCompressed = new byte[length]; - reader.getBytesReverse(DataTransformation.ADD, originalCompressed); - - String uncompressed = TextUtil.decompress(originalCompressed, length); - uncompressed = TextUtil.filterInvalidCharacters(uncompressed); - uncompressed = TextUtil.capitalize(uncompressed); - - byte[] recompressed = new byte[length]; - TextUtil.compress(uncompressed, recompressed); - // in case invalid data gets sent, this effectively verifies it - - return new PublicChatMessage(uncompressed, recompressed, color, effects); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RegionChangeMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/RegionChangeMessageEncoder.java deleted file mode 100644 index 71e070ac3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RegionChangeMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RegionChangeMessage}. - * - * @author Graham - */ -public final class RegionChangeMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RegionChangeMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(73); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralRegionX()); - builder.put(DataType.SHORT, message.getPosition().getCentralRegionY()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/Release317.java b/game/src/main/java/org/apollo/game/release/r317/Release317.java deleted file mode 100644 index 8cfa4fc4c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/Release317.java +++ /dev/null @@ -1,239 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.SetPlayerActionMessage; -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.game.message.impl.SetWidgetModelMessage; -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.message.impl.UpdateRunEnergyMessage; -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.game.message.impl.UpdateWeightMessage; -import org.apollo.net.meta.PacketMetaDataGroup; -import org.apollo.net.release.Release; - -/** - * A {@link Release} implementation for the 317 protocol. - * - * @author Graham - */ -public final class Release317 extends Release { - - /** - * The incoming packet lengths array. - */ - public static final int[] PACKET_LENGTHS = { - 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 8, 0, 6, 2, 2, 0, // 10 - 0, 2, 0, 6, 0, 12, 0, 0, 0, 0, // 20 - 0, 0, 0, 0, 0, 8, 4, 0, 0, 2, // 30 - 2, 6, 0, 6, 0, -1, 0, 0, 0, 0, // 40 - 0, 0, 0, 12, 0, 0, 0, 8, 8, 0, // 50 - 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, // 60 - 6, 0, 2, 2, 8, 6, 0, -1, 0, 6, // 70 - 0, 0, 0, 0, 0, 1, 4, 6, 0, 0, // 80 - 0, 0, 0, 0, 0, 3, 0, 0, -1, 0, // 90 - 0, 13, 0, -1, 0, 0, 0, 0, 0, 0, // 100 - 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, // 110 - 1, 0, 6, 0, 0, 0, -1, 0, 2, 6, // 120 - 0, 4, 6, 8, 0, 6, 0, 0, 0, 2, // 130 - 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, // 140 - 0, 0, 1, 2, 0, 2, 6, 0, 0, 0, // 150 - 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, // 160 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170 - 0, 8, 0, 3, 0, 2, 0, 0, 8, 1, // 180 - 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, // 190 - 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, // 200 - 4, 0, 0, 0, 7, 8, 0, 0, 10, 0, // 210 - 0, 0, 0, 0, 0, 0, -1, 0, 6, 0, // 220 - 1, 0, 0, 0, 6, 0, 6, 8, 1, 0, // 230 - 0, 4, 0, 0, 0, 0, -1, 0, -1, 4, // 240 - 0, 0, 6, 6, 0, 0, // 250 - }; - - /** - * Creates and initialises this release. - */ - public Release317() { - super(317, PacketMetaDataGroup.createFromArray(PACKET_LENGTHS)); - init(); - } - - /** - * Initialises this release by registering encoders and decoders. - */ - private void init() { - // register decoders - WalkMessageDecoder walkMessageDecoder = new WalkMessageDecoder(); - register(248, walkMessageDecoder); - register(164, walkMessageDecoder); - register(98, walkMessageDecoder); - - register(0, new KeepAliveMessageDecoder()); - register(101, new PlayerDesignMessageDecoder()); - register(4, new PublicChatMessageDecoder()); - register(103, new CommandMessageDecoder()); - register(214, new SwitchItemMessageDecoder()); - - register(132, new FirstObjectActionMessageDecoder()); - register(252, new SecondObjectActionMessageDecoder()); - register(70, new ThirdObjectActionMessageDecoder()); - - register(122, new FirstItemOptionMessageDecoder()); - register(41, new SecondItemOptionMessageDecoder()); - register(16, new ThirdItemOptionMessageDecoder()); - register(75, new FourthItemOptionMessageDecoder()); - register(87, new FifthItemOptionMessageDecoder()); - - register(145, new FirstItemActionMessageDecoder()); - register(117, new SecondItemActionMessageDecoder()); - register(43, new ThirdItemActionMessageDecoder()); - register(129, new FourthItemActionMessageDecoder()); - register(135, new FifthItemActionMessageDecoder()); - - register(185, new ButtonMessageDecoder()); - register(130, new ClosedInterfaceMessageDecoder()); - register(208, new EnteredAmountMessageDecoder()); - register(40, new DialogueContinueMessageDecoder()); - register(120, new FlashingTabClickedMessageDecoder()); - - register(53, new ItemOnItemMessageDecoder()); - register(57, new ItemOnNpcMessageDecoder()); - register(237, new MagicOnItemMessageDecoder()); - register(249, new MagicOnPlayerMessageDecoder()); - register(131, new MagicOnNpcMessageDecoder()); - - register(3, new FocusUpdateMessageDecoder()); - register(45, new FlaggedMouseEventMessageDecoder()); - register(241, new MouseClickedMessageDecoder()); - register(86, new ArrowKeyMessageDecoder()); - register(95, new PrivacyOptionMessageDecoder()); - - SpamPacketMessageDecoder spamMessageDecoder = new SpamPacketMessageDecoder(); - register(77, spamMessageDecoder); - register(78, spamMessageDecoder); - register(165, spamMessageDecoder); - register(189, spamMessageDecoder); - register(210, spamMessageDecoder); - register(226, spamMessageDecoder); - register(121, spamMessageDecoder); - - register(155, new FirstNpcActionMessageDecoder()); - register(72, new SecondNpcActionMessageDecoder()); - register(17, new ThirdNpcActionMessageDecoder()); - register(21, new FourthNpcActionMessageDecoder()); - register(18, new FifthNpcActionMessageDecoder()); - - register(236, new TakeTileItemMessageDecoder()); - register(192, new ItemOnObjectMessageDecoder()); - - register(128, new FirstPlayerActionMessageDecoder()); - register(153, new SecondPlayerActionMessageDecoder()); - register(73, new ThirdPlayerActionMessageDecoder()); - register(139, new FourthPlayerActionMessageDecoder()); - register(39, new FifthPlayerActionMessageDecoder()); - - register(188, new AddFriendMessageDecoder()); - register(133, new AddIgnoreMessageDecoder()); - register(215, new RemoveFriendMessageDecoder()); - register(74, new RemoveIgnoreMessageDecoder()); - register(126, new PrivateChatMessageDecoder()); - - register(218, new ReportAbuseMessageDecoder()); - - // register encoders - register(IdAssignmentMessage.class, new IdAssignmentMessageEncoder()); - register(RegionChangeMessage.class, new RegionChangeMessageEncoder()); - register(ServerChatMessage.class, new ServerMessageMessageEncoder()); - register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); - register(OpenInterfaceMessage.class, new OpenInterfaceMessageEncoder()); - register(CloseInterfaceMessage.class, new CloseInterfaceMessageEncoder()); - register(SwitchTabInterfaceMessage.class, new SwitchTabInterfaceMessageEncoder()); - register(LogoutMessage.class, new LogoutMessageEncoder()); - register(UpdateItemsMessage.class, new UpdateItemsMessageEncoder()); - register(UpdateSlottedItemsMessage.class, new UpdateSlottedItemsMessageEncoder()); - register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); - register(OpenInterfaceSidebarMessage.class, new OpenInterfaceSidebarMessageEncoder()); - register(EnterAmountMessage.class, new EnterAmountMessageEncoder()); - register(SetWidgetTextMessage.class, new SetWidgetTextMessageEncoder()); - register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); - - register(SetWidgetVisibilityMessage.class, new SetWidgetVisibilityMessageEncoder()); - register(SetWidgetItemModelMessage.class, new SetWidgetItemModelMessageEncoder()); - register(SetWidgetNpcModelMessage.class, new SetWidgetNpcModelMessageEncoder()); - register(SetWidgetPlayerModelMessage.class, new SetWidgetPlayerModelMessageEncoder()); - register(SetWidgetModelAnimationMessage.class, new SetWidgetModelAnimationMessageEncoder()); - register(SetWidgetModelMessage.class, new SetWidgetModelMessageEncoder()); - - register(ConfigMessage.class, new ConfigMessageEncoder()); - register(DisplayTabInterfaceMessage.class, new DisplayTabInterfaceMessageEncoder()); - register(SetUpdatedRegionMessage.class, new SetUpdatedRegionMessageEncoder()); - register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); - register(PrivacyOptionMessage.class, new PrivacyOptionMessageEncoder()); - register(OpenDialogueInterfaceMessage.class, new OpenDialogueInterfaceMessageEncoder()); - register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); - register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); - register(DisplayCrossbonesMessage.class, new DisplayCrossbonesMessageEncoder()); - - register(SendPublicTileItemMessage.class, new AddGlobalTileItemMessageEncoder()); - register(SendTileItemMessage.class, new AddTileItemMessageEncoder()); - register(UpdateTileItemMessage.class, new UpdateTileItemMessageEncoder()); - register(RemoveTileItemMessage.class, new RemoveTileItemMessageEncoder()); - register(SendObjectMessage.class, new SendObjectMessageEncoder()); - register(RemoveObjectMessage.class, new RemoveObjectMessageEncoder()); - - register(GroupedRegionUpdateMessage.class, new GroupedRegionUpdateMessageEncoder(this)); - register(ClearRegionMessage.class, new ClearRegionMessageEncoder()); - - register(ForwardPrivateChatMessage.class, new ForwardPrivateChatMessageEncoder()); - register(FriendServerStatusMessage.class, new FriendServerStatusMessageEncoder()); - register(IgnoreListMessage.class, new IgnoreListMessageEncoder()); - register(SendFriendMessage.class, new SendFriendMessageEncoder()); - register(MobHintIconMessage.class, new MobHintIconMessageEncoder()); - register(PositionHintIconMessage.class, new PositionHintIconMessageEncoder()); - register(FlashTabInterfaceMessage.class, new FlashTabInterfaceMessageEncoder()); - register(OpenSidebarMessage.class, new OpenSidebarMessageEncoder()); - register(OpenOverlayMessage.class, new OpenOverlayMessageEncoder()); - register(OpenDialogueOverlayMessage.class, new OpenDialogueOverlayMessageEncoder()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveFriendMessageDecoder.java deleted file mode 100644 index ffbaafc32..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveFriendMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link RemoveFriendMessage}. - * - * @author Major - */ -public final class RemoveFriendMessageDecoder extends MessageDecoder { - - @Override - public RemoveFriendMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new RemoveFriendMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveIgnoreMessageDecoder.java deleted file mode 100644 index aee1abce2..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveIgnoreMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveIgnoreMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link RemoveIgnoreMessage}. - * - * @author Major - */ -public final class RemoveIgnoreMessageDecoder extends MessageDecoder { - - @Override - public RemoveIgnoreMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new RemoveIgnoreMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveObjectMessageEncoder.java deleted file mode 100644 index 61dc247c3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveObjectMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RemoveObjectMessage}. - * - * @author Major - */ -public final class RemoveObjectMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RemoveObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(101); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getType() << 2 | message.getOrientation()); - builder.put(DataType.BYTE, message.getPositionOffset()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveTileItemMessageEncoder.java deleted file mode 100644 index c844f79b5..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveTileItemMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RemoveTileItemMessage}. - * - * @author Major - */ -public final class RemoveTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RemoveTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(156); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - builder.put(DataType.SHORT, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondItemActionMessageDecoder.java deleted file mode 100644 index a5df384eb..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ItemActionMessage}. - * - * @author Graham - */ -public final class SecondItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemActionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondItemOptionMessageDecoder.java deleted file mode 100644 index 3d13490c7..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondItemOptionMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOptionMessage}. - * - * @author Graham - */ -public final class SecondItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondNpcActionMessageDecoder.java deleted file mode 100644 index c1f5d23dd..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondNpcActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link NpcActionMessage}. - * - * @author Major - */ -public final class SecondNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getSigned(DataType.SHORT, DataTransformation.ADD); - return new NpcActionMessage(2, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondObjectActionMessageDecoder.java deleted file mode 100644 index e5e8f2fba..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondObjectActionMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class SecondObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ObjectActionMessage(2, id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SendFriendMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SendFriendMessageEncoder.java deleted file mode 100644 index 932dca8ef..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SendFriendMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link SendFriendMessage}. - * - * @author Major - */ -public final class SendFriendMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendFriendMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(50); - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getUsername())); - builder.put(DataType.BYTE, message.getEncodedWorld()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SendObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SendObjectMessageEncoder.java deleted file mode 100644 index 6e3e5f350..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SendObjectMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendObjectMessage}. - * - * @author Major - */ -public final class SendObjectMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(151); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getType() << 2 | message.getOrientation()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ServerMessageMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ServerMessageMessageEncoder.java deleted file mode 100644 index d330f1ffc..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ServerMessageMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ServerChatMessage}. - * - * @author Graham - */ -public final class ServerMessageMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ServerChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(253, PacketType.VARIABLE_BYTE); - builder.putString(message.getMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetPlayerActionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetPlayerActionMessageEncoder.java deleted file mode 100644 index bfa2b2e2a..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetPlayerActionMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetPlayerActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * The {@link MessageEncoder} for the {@link SetPlayerActionMessage}. - * - * @author Major - */ -public final class SetPlayerActionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetPlayerActionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(104, PacketType.VARIABLE_BYTE); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getSlot()); - builder.put(DataType.BYTE, DataTransformation.ADD, message.isPrimaryAction() ? 0 : 1); - builder.putString(message.getText()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetUpdatedRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetUpdatedRegionMessageEncoder.java deleted file mode 100644 index e490c7139..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetUpdatedRegionMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetUpdatedRegionMessage}. - * - * @author Chris Fletcher - */ -public final class SetUpdatedRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetUpdatedRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(85); - Position player = message.getPlayerPosition(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalY(player)); - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetItemModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetItemModelMessageEncoder.java deleted file mode 100644 index e353a2972..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetItemModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetItemModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetItemModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetItemModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(246); - - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - builder.put(DataType.SHORT, message.getZoom()); - builder.put(DataType.SHORT, message.getModelId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelAnimationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelAnimationMessageEncoder.java deleted file mode 100644 index 5c61b450c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelAnimationMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelAnimationMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetModelAnimationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelAnimationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(200); - - builder.put(DataType.SHORT, message.getInterfaceId() & 0xFFFF); - builder.put(DataType.SHORT, message.getAnimation()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelMessageEncoder.java deleted file mode 100644 index 75f27a9e3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelMessage}. - * - * @author Major - */ -public class SetWidgetModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(8); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, message.getModel()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetNpcModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetNpcModelMessageEncoder.java deleted file mode 100644 index be4d8ee70..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetNpcModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetNpcModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetNpcModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetNpcModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(75); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getModelId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetPlayerModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetPlayerModelMessageEncoder.java deleted file mode 100644 index 3f273f60a..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetPlayerModelMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetPlayerModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetPlayerModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetPlayerModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(185); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetTextMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetTextMessageEncoder.java deleted file mode 100644 index e8f81fbba..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetTextMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetTextMessage}. - * - * @author The Wanderer - */ -public final class SetWidgetTextMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetTextMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(126, PacketType.VARIABLE_SHORT); - builder.putString(message.getText()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetVisibilityMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetVisibilityMessageEncoder.java deleted file mode 100644 index c29117cd8..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetVisibilityMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetVisibilityMessage}. - * - * @author Major - */ -public final class SetWidgetVisibilityMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetVisibilityMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(171); - - builder.put(DataType.BYTE, message.isVisible() ? 0 : 1); - builder.put(DataType.SHORT, message.getWidgetId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SwitchItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SwitchItemMessageDecoder.java deleted file mode 100644 index 3c3d50912..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SwitchItemMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SwitchItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link SwitchItemMessage}. - * - * @author Graham - */ -public final class SwitchItemMessageDecoder extends MessageDecoder { - - @Override - public SwitchItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - boolean inserting = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE) == 1; - int oldSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int newSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new SwitchItemMessage(interfaceId, inserting, oldSlot, newSlot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SwitchTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SwitchTabInterfaceMessageEncoder.java deleted file mode 100644 index 23a8070fd..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SwitchTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SwitchTabInterfaceMessage}. - * - * @author Graham - */ -public final class SwitchTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SwitchTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(71); - builder.put(DataType.SHORT, message.getInterfaceId()); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getTabId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/TakeTileItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/TakeTileItemMessageDecoder.java deleted file mode 100644 index 7130f5a05..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/TakeTileItemMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.TakeTileItemMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link TakeTileItemMessage}. - * - * @author Major - */ -public final class TakeTileItemMessageDecoder extends MessageDecoder { - - @Override - public TakeTileItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new TakeTileItemMessage(id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdItemActionMessageDecoder.java deleted file mode 100644 index 89976f8b7..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemActionMessage}. - * - * @author Graham - */ -public final class ThirdItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemActionMessage(3, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdItemOptionMessageDecoder.java deleted file mode 100644 index e14c7c414..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class ThirdItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ItemOptionMessage(3, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdNpcActionMessageDecoder.java deleted file mode 100644 index f98441d07..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdNpcActionMessageDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link NpcActionMessage}. - * - * @author Major - */ -public final class ThirdNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - return new NpcActionMessage(3, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdObjectActionMessageDecoder.java deleted file mode 100644 index f4622700d..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdObjectActionMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class ThirdObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int y = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ObjectActionMessage(3, id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateItemsMessageEncoder.java deleted file mode 100644 index 64fc8183a..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateItemsMessageEncoder.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.model.Item; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateItemsMessage}. - * - * @author Graham - */ -public final class UpdateItemsMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(53, PacketType.VARIABLE_SHORT); - - Item[] items = message.getItems(); - - builder.put(DataType.SHORT, message.getInterfaceId()); - builder.put(DataType.SHORT, items.length); - - for (Item item : items) { - int id = item == null ? -1 : item.getId(); - int amount = item == null ? 0 : item.getAmount(); - - if (amount > 254) { - builder.put(DataType.BYTE, 255); - builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, amount); - } else { - builder.put(DataType.BYTE, amount); - } - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, id + 1); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateRunEnergyMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateRunEnergyMessageEncoder.java deleted file mode 100644 index 7fcf293d8..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateRunEnergyMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateRunEnergyMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateRunEnergyMessage} - * - * @author Major - */ -public final class UpdateRunEnergyMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateRunEnergyMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(110); - builder.put(DataType.BYTE, message.getEnergy()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateSkillMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateSkillMessageEncoder.java deleted file mode 100644 index 3b6033a57..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateSkillMessageEncoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.model.entity.Skill; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateSkillMessage}. - * - * @author Graham - */ -public final class UpdateSkillMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateSkillMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(134); - Skill skill = message.getSkill(); - - builder.put(DataType.BYTE, message.getId()); - builder.put(DataType.INT, DataOrder.MIDDLE, (int) skill.getExperience()); - builder.put(DataType.BYTE, skill.getCurrentLevel()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateSlottedItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateSlottedItemsMessageEncoder.java deleted file mode 100644 index 68c790f7e..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateSlottedItemsMessageEncoder.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; -import org.apollo.game.model.Item; -import org.apollo.game.model.inv.SlottedItem; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateSlottedItemsMessage}. - * - * @author Graham - */ -public final class UpdateSlottedItemsMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateSlottedItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(34, PacketType.VARIABLE_SHORT); - SlottedItem[] items = message.getSlottedItems(); - - builder.put(DataType.SHORT, message.getInterfaceId()); - - for (SlottedItem slottedItem : items) { - builder.putSmart(slottedItem.getSlot()); - - Item item = slottedItem.getItem(); - int id = item == null ? -1 : item.getId(); - int amount = item == null ? 0 : item.getAmount(); - - builder.put(DataType.SHORT, id + 1); - - if (amount > 254) { - builder.put(DataType.BYTE, 255); - builder.put(DataType.INT, amount); - } else { - builder.put(DataType.BYTE, amount); - } - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateTileItemMessageEncoder.java deleted file mode 100644 index 7159921df..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateTileItemMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateTileItemMessage}. - * - * @author Major - */ -public final class UpdateTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(84); - builder.put(DataType.BYTE, message.getPositionOffset()); - builder.put(DataType.SHORT, message.getId()); - builder.put(DataType.SHORT, message.getPreviousAmount()); - builder.put(DataType.SHORT, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateWeightMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateWeightMessageEncoder.java deleted file mode 100644 index 4ac9ffe68..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateWeightMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateWeightMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateWeightMessage}. - * - * @author Major - */ -public final class UpdateWeightMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateWeightMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(240); - builder.put(DataType.SHORT, message.getWeight()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/WalkMessageDecoder.java deleted file mode 100644 index 3440fbc1e..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/WalkMessageDecoder.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.WalkMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link WalkMessage}. - * - * @author Graham - */ -public final class WalkMessageDecoder extends MessageDecoder { - - @Override - public WalkMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int length = packet.getLength(); - if (packet.getOpcode() == 248) { - length -= 14; // strip off anti-cheat data - } - - int steps = (length - 5) / 2; - int[][] path = new int[steps][2]; - - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - for (int i = 0; i < steps; i++) { - path[i][0] = (int) reader.getSigned(DataType.BYTE); - path[i][1] = (int) reader.getSigned(DataType.BYTE); - } - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - boolean run = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE) == 1; - - Position[] positions = new Position[steps + 1]; - positions[0] = new Position(x, y); - for (int i = 0; i < steps; i++) { - positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y); - } - - return new WalkMessage(positions, run); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/package-info.java b/game/src/main/java/org/apollo/game/release/r317/package-info.java deleted file mode 100644 index 8e1e94c6f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Contains codecs for the 317 release. - */ -package org.apollo.game.release.r317; - diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java index 4d18a15b2..ae3166cbf 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java @@ -19,7 +19,7 @@ public final class FirstPlayerActionMessageDecoder extends MessageDecoder Date: Mon, 2 Mar 2020 20:48:52 -0500 Subject: [PATCH 12/63] Npc options decoders. Object options decoders. --- .../game/message/impl/NpcActionMessage.java | 20 +- .../message/impl/ObjectActionMessage.java | 16 +- .../message/impl/PlayerActionMessage.java | 10 +- .../FifthNpcActionMessageDecoder.java | 10 +- .../r181/FifthObjectActionMessageDecoder.java | 27 ++ .../FirstNpcActionMessageDecoder.java | 10 +- .../FirstObjectActionMessageDecoder.java | 11 +- .../FourthNpcActionMessageDecoder.java | 13 +- .../FourthObjectActionMessageDecoder.java | 27 ++ .../apollo/game/release/r181/Release181.java | 18 ++ .../SecondNpcActionMessageDecoder.java | 7 +- .../SecondObjectActionMessageDecoder.java | 12 +- .../r181/SixthNpcActionMessageDecoder.java | 23 ++ .../r181/SixthObjectActionMessageDecoder.java | 27 ++ .../ThirdNpcActionMessageDecoder.java | 6 +- .../r181/ThirdObjectActionMessageDecoder.java | 27 ++ .../release/r377/AddFriendMessageDecoder.java | 24 -- .../release/r377/AddIgnoreMessageDecoder.java | 24 -- .../r377/ClosedInterfaceMessageDecoder.java | 19 -- .../release/r377/CommandMessageDecoder.java | 21 -- .../r377/EnteredAmountMessageDecoder.java | 23 -- .../r377/FifthPlayerActionMessageDecoder.java | 24 -- .../r377/FirstPlayerActionMessageDecoder.java | 25 -- .../FourthPlayerActionMessageDecoder.java | 24 -- .../release/r377/KeepAliveMessageDecoder.java | 19 -- .../r377/PrivacyOptionMessageDecoder.java | 27 -- .../r377/PrivateChatMessageDecoder.java | 38 --- .../apollo/game/release/r377/Release377.java | 231 ------------------ .../r377/RemoveFriendMessageDecoder.java | 24 -- .../r377/RemoveIgnoreMessageDecoder.java | 24 -- .../SecondPlayerActionMessageDecoder.java | 24 -- .../r377/SendObjectMessageEncoder.java | 27 -- .../r377/SpamPacketMessageDecoder.java | 19 -- .../r377/ThirdPlayerActionMessageDecoder.java | 24 -- .../game/release/r377/WalkMessageDecoder.java | 49 ---- 35 files changed, 223 insertions(+), 731 deletions(-) rename game/src/main/java/org/apollo/game/release/{r377 => r181}/FifthNpcActionMessageDecoder.java (66%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/FifthObjectActionMessageDecoder.java rename game/src/main/java/org/apollo/game/release/{r377 => r181}/FirstNpcActionMessageDecoder.java (65%) rename game/src/main/java/org/apollo/game/release/{r377 => r181}/FirstObjectActionMessageDecoder.java (62%) rename game/src/main/java/org/apollo/game/release/{r377 => r181}/FourthNpcActionMessageDecoder.java (60%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/FourthObjectActionMessageDecoder.java rename game/src/main/java/org/apollo/game/release/{r377 => r181}/SecondNpcActionMessageDecoder.java (81%) rename game/src/main/java/org/apollo/game/release/{r377 => r181}/SecondObjectActionMessageDecoder.java (61%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/SixthNpcActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/SixthObjectActionMessageDecoder.java rename game/src/main/java/org/apollo/game/release/{r377 => r181}/ThirdNpcActionMessageDecoder.java (82%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/ThirdObjectActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/AddFriendMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/AddIgnoreMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ClosedInterfaceMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/CommandMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/EnteredAmountMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FifthPlayerActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FourthPlayerActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/KeepAliveMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/PrivateChatMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/Release377.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/RemoveFriendMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/RemoveIgnoreMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SecondPlayerActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SendObjectMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SpamPacketMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ThirdPlayerActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/WalkMessageDecoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java index 0ab27b0f7..a952a012f 100644 --- a/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java @@ -21,15 +21,22 @@ public final class NpcActionMessage extends Message { */ private final int index; + /** + * The movement type that the player performs. + */ + private final int movementType; + /** * Creates an npc action message. * - * @param option The option number. + * @param option The option number. * @param index The index of the npc. + * @param movementType The type of movement. */ - public NpcActionMessage(int option, int index) { + public NpcActionMessage(int option, int index, int movementType) { this.option = option; this.index = index; + this.movementType = movementType; } /** @@ -50,4 +57,13 @@ public int getIndex() { return index; } + /** + * Gets movement type. + * + * @return the movement type + */ + public int getMovementType() { + return movementType; + } + } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java index e408f2022..da4bb950e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java @@ -28,6 +28,11 @@ public final class ObjectActionMessage extends Message { */ private final Position position; + /** + * The movement type that the player performs. + */ + private final int movementType; + /** * Creates a new object action message. * @@ -35,10 +40,11 @@ public final class ObjectActionMessage extends Message { * @param id The id of the object. * @param position The position of the object. */ - public ObjectActionMessage(int option, int id, Position position) { + public ObjectActionMessage(int option, int id, Position position, int movementType) { this.option = option; this.id = id; this.position = position; + this.movementType = movementType; } /** @@ -68,4 +74,12 @@ public Position getPosition() { return position; } + /** + * Gets movement type. + * + * @return the movement type + */ + public int getMovementType() { + return movementType; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java index 2e2f3fc62..9004cc885 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java @@ -12,6 +12,11 @@ */ public final class PlayerActionMessage extends Message { + /** + * The option number. + */ + private final int option; + /** * The index of the clicked player. */ @@ -22,11 +27,6 @@ public final class PlayerActionMessage extends Message { */ private final int movementType; - /** - * The option number. - */ - private final int option; - /** * Creates a player action message. * @param option The option number. diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/FifthNpcActionMessageDecoder.java similarity index 66% rename from game/src/main/java/org/apollo/game/release/r377/FifthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/FifthNpcActionMessageDecoder.java index 9801804d4..2e160f3e7 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FifthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/FifthNpcActionMessageDecoder.java @@ -1,7 +1,7 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -17,8 +17,8 @@ public final class FifthNpcActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int id = (int) reader.getUnsigned(DataType.SHORT); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ObjectActionMessage(5, id, new Position(x, y), movementType); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/FirstNpcActionMessageDecoder.java similarity index 65% rename from game/src/main/java/org/apollo/game/release/r377/FirstNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/FirstNpcActionMessageDecoder.java index a7c3c6070..c3cb7e6b6 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FirstNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/FirstNpcActionMessageDecoder.java @@ -1,10 +1,7 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** @@ -17,8 +14,9 @@ public final class FirstNpcActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + + return new ObjectActionMessage(4, id, new Position(x, y), movementType); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 6f22bdfa0..0765d6abe 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -186,7 +186,25 @@ private void init() { register(50, new EightPlayerActionMessageDecoder()); + /** + * NPC + */ + register(71, new FirstNpcActionMessageDecoder()); + register(1, new SecondNpcActionMessageDecoder()); + register(33, new ThirdNpcActionMessageDecoder()); + register(59, new FourthNpcActionMessageDecoder()); + register(31, new FifthNpcActionMessageDecoder()); + register(30, new SixthNpcActionMessageDecoder()); + /** + * Objects + */ + register(10, new FirstObjectActionMessageDecoder()); + register(79, new SecondObjectActionMessageDecoder()); + register(89, new ThirdObjectActionMessageDecoder()); + register(3, new FourthObjectActionMessageDecoder()); + register(94, new FifthObjectActionMessageDecoder()); + register(36, new SixthObjectActionMessageDecoder()); register(38, new ReportAbuseMessageDecoder()); diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/SecondNpcActionMessageDecoder.java similarity index 81% rename from game/src/main/java/org/apollo/game/release/r377/SecondNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/SecondNpcActionMessageDecoder.java index 0ea202b00..045eab6c5 100644 --- a/game/src/main/java/org/apollo/game/release/r377/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/SecondNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -17,8 +17,11 @@ public final class SecondNpcActionMessageDecoder extends MessageDecoder { + + @Override + public NpcActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int index = (int) reader.getSigned(DataType.SHORT, DataTransformation.ADD); + return new NpcActionMessage(6, index, 0); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/SixthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/SixthObjectActionMessageDecoder.java new file mode 100644 index 000000000..daaab41dd --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/SixthObjectActionMessageDecoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.model.Position; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the sixth {@link ObjectActionMessage}. + * + * @author Graham + */ +public final class SixthObjectActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + + return new ObjectActionMessage(6, id, new Position(-1, -1), 0); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/ThirdNpcActionMessageDecoder.java similarity index 82% rename from game/src/main/java/org/apollo/game/release/r377/ThirdNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/ThirdNpcActionMessageDecoder.java index 42ae9dd6a..10c5bb0b1 100644 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/ThirdNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataOrder; @@ -19,7 +19,9 @@ public final class ThirdNpcActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + + return new ObjectActionMessage(3, id, new Position(x, y), movementType); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r377/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/AddFriendMessageDecoder.java deleted file mode 100644 index a14a31c1c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/AddFriendMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.AddFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link AddFriendMessage}. - * - * @author Major - */ -public final class AddFriendMessageDecoder extends MessageDecoder { - - @Override - public AddFriendMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new AddFriendMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/AddIgnoreMessageDecoder.java deleted file mode 100644 index 00119d641..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/AddIgnoreMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.AddIgnoreMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link AddIgnoreMessage}. - * - * @author Major - */ -public final class AddIgnoreMessageDecoder extends MessageDecoder { - - @Override - public AddIgnoreMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new AddIgnoreMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ClosedInterfaceMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ClosedInterfaceMessageDecoder.java deleted file mode 100644 index 1bbcd5dad..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ClosedInterfaceMessageDecoder.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ClosedInterfaceMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ClosedInterfaceMessage}. - * - * @author Graham - */ -public final class ClosedInterfaceMessageDecoder extends MessageDecoder { - - @Override - public ClosedInterfaceMessage decode(GamePacket packet) { - return new ClosedInterfaceMessage(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/CommandMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/CommandMessageDecoder.java deleted file mode 100644 index 9f868e62a..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/CommandMessageDecoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.CommandMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link CommandMessage}. - * - * @author Graham - */ -public final class CommandMessageDecoder extends MessageDecoder { - - @Override - public CommandMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - return new CommandMessage(reader.getString()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/EnteredAmountMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/EnteredAmountMessageDecoder.java deleted file mode 100644 index 72c13b9b5..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/EnteredAmountMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.EnteredAmountMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link EnteredAmountMessage}. - * - * @author Graham - */ -public final class EnteredAmountMessageDecoder extends MessageDecoder { - - @Override - public EnteredAmountMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int amount = (int) reader.getUnsigned(DataType.INT); - return new EnteredAmountMessage(amount); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FifthPlayerActionMessageDecoder.java deleted file mode 100644 index 2a5f76ad1..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FifthPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link PlayerActionMessage}. - * - * @author Major - */ -public final class FifthPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new PlayerActionMessage(5, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java deleted file mode 100644 index ae3166cbf..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link PlayerActionMessage}. - * - * @author Major - */ -public final class FirstPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int type = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); - return new PlayerActionMessage(1, index, type); - } -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FourthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FourthPlayerActionMessageDecoder.java deleted file mode 100644 index 4f21919c4..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FourthPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link PlayerActionMessage}. - * - * @author Major - */ -public final class FourthPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(4, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/KeepAliveMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/KeepAliveMessageDecoder.java deleted file mode 100644 index cbd80f1b9..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/KeepAliveMessageDecoder.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.KeepAliveMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link KeepAliveMessage}. - * - * @author Graham - */ -public final class KeepAliveMessageDecoder extends MessageDecoder { - - @Override - public KeepAliveMessage decode(GamePacket packet) { - return new KeepAliveMessage(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageDecoder.java deleted file mode 100644 index 3c2239b21..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link PrivacyOptionMessage}. - * - * @author Major - */ -public final class PrivacyOptionMessageDecoder extends MessageDecoder { - - @Override - public PrivacyOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int publicChatState = (int) reader.getUnsigned(DataType.BYTE); - int privateChatState = (int) reader.getUnsigned(DataType.BYTE); - int tradeChatState = (int) reader.getUnsigned(DataType.BYTE); - - return new PrivacyOptionMessage(publicChatState, privateChatState, tradeChatState); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/PrivateChatMessageDecoder.java deleted file mode 100644 index beb02f411..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PrivateChatMessageDecoder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PrivateChatMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; -import org.apollo.util.TextUtil; - -/** - * A {@link MessageDecoder} for the {@link PrivateChatMessage}. - * - * @author Major - */ -public final class PrivateChatMessageDecoder extends MessageDecoder { - - @Override - public PrivateChatMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - int length = packet.getLength() - Long.BYTES; - - byte[] originalCompressed = new byte[length]; - reader.getBytes(originalCompressed); - - String decompressed = TextUtil.decompress(originalCompressed, length); - decompressed = TextUtil.filterInvalidCharacters(decompressed); - decompressed = TextUtil.capitalize(decompressed); - - byte[] recompressed = new byte[length]; - TextUtil.compress(decompressed, recompressed); - - return new PrivateChatMessage(decompressed, recompressed, username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/Release377.java b/game/src/main/java/org/apollo/game/release/r377/Release377.java deleted file mode 100644 index 2b2c1e577..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/Release377.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.game.message.impl.SendProjectileMessage; -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.SetPlayerActionMessage; -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.message.impl.UpdateRunEnergyMessage; -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.game.message.impl.UpdateWeightMessage; -import org.apollo.net.meta.PacketMetaDataGroup; -import org.apollo.net.release.Release; - -/** - * A {@link Release} implementation for the 377 protocol. - * - * @author Graham - */ -public final class Release377 extends Release { - - /** - * The incoming packet lengths array. - */ - public static final int[] PACKET_LENGTHS = { 0, 12, 0, 6, 6, 0, 0, 0, 2, 0, // 0 - 0, 0, 0, 2, 0, 0, 0, 0, 0, 4, // 10 - 0, 0, 2, 0, 6, 0, 0, 0, -1, 0, // 20 - 0, 4, 0, 0, 0, 0, 8, 0, 0, 0, // 30 - 0, 0, 2, 0, 0, 2, 0, 0, 0, -1, // 40 - 6, 0, 0, 0, 6, 6, -1, 8, 0, 0, // 50 - 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, // 60 - 0, 6, 0, 0, 0, 4, 0, 6, 4, 2, // 70 - 2, 0, 0, 8, 0, 0, 0, 0, 0, 0, // 80 - 0, 6, 0, 0, 0, 4, 0, 0, 0, 0, // 90 - 6, 0, 0, 0, 4, 0, 0, 0, 0, 0, // 100 - 0, 0, 2, 0, 0, 0, 2, 0, 0, 1, // 110 - 8, 0, 0, 7, 0, 0, 1, 0, 0, 0, // 120 - 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, // 130 - 4, 8, 0, 8, 0, 0, 0, 0, 0, 0, // 140 - 0, 0, 12, 0, 0, 0, 0, 4, 6, 0, // 150 - 8, 6, 0, 13, 0, 1, 0, 0, 0, 0, // 160 - 0, -1, 0, 3, 0, 0, 3, 6, 0, 0, // 170 - 0, 6, 0, 0, 10, 0, 0, 1, 0, 0, // 180 - 0, 0, 0, 0, 2, 0, 0, 4, 0, 0, // 190 - 0, 0, 0, 6, 0, 0, 8, 0, 0, 0, // 200 - 8, 12, 0, -1, 0, 0, 0, 8, 0, 0, // 210 - 0, 0, 3, 0, 0, 0, 2, 9, 6, 0, // 220 - 6, 6, 0, 2, 0, 0, 0, 0, 0, 0, // 230 - 0, 6, 0, 0, -1, 2, 0, -1, 0, 0, // 240 - 0, 0, 0, 0, 0, 0 // 250 - }; - - /** - * Creates and initialises this release. - */ - public Release377() { - super(377, PacketMetaDataGroup.createFromArray(PACKET_LENGTHS)); - init(); - } - - /** - * Initialises this release by registering encoders and decoders. - */ - private void init() { - WalkMessageDecoder walkMessageDecoder = new WalkMessageDecoder(); - register(213, walkMessageDecoder); - register(28, walkMessageDecoder); - register(247, walkMessageDecoder); - - register(248, new KeepAliveMessageDecoder()); - register(163, new PlayerDesignMessageDecoder()); - register(49, new PublicChatMessageDecoder()); - register(56, new CommandMessageDecoder()); - register(123, new SwitchItemMessageDecoder()); - - register(181, new FirstObjectActionMessageDecoder()); - register(241, new SecondObjectActionMessageDecoder()); - register(50, new ThirdObjectActionMessageDecoder()); - - register(203, new FirstItemOptionMessageDecoder()); - register(24, new SecondItemOptionMessageDecoder()); - register(161, new ThirdItemOptionMessageDecoder()); - register(228, new FourthItemOptionMessageDecoder()); - register(4, new FifthItemOptionMessageDecoder()); - - register(3, new FirstItemActionMessageDecoder()); - register(177, new SecondItemActionMessageDecoder()); - register(91, new ThirdItemActionMessageDecoder()); - register(231, new FourthItemActionMessageDecoder()); - register(158, new FifthItemActionMessageDecoder()); - - register(79, new ButtonMessageDecoder()); - register(110, new ClosedInterfaceMessageDecoder()); - register(75, new EnteredAmountMessageDecoder()); - register(226, new DialogueContinueMessageDecoder()); - register(119, new FlashingTabClickedMessageDecoder()); - - register(1, new ItemOnItemMessageDecoder()); - register(57, new ItemOnNpcMessageDecoder()); - register(36, new MagicOnItemMessageDecoder()); - register(31, new MagicOnPlayerMessageDecoder()); - register(104, new MagicOnNpcMessageDecoder()); - - register(187, new FocusUpdateMessageDecoder()); - register(19, new MouseClickedMessageDecoder()); - register(171, new FlaggedMouseEventMessageDecoder()); - register(140, new ArrowKeyMessageDecoder()); - register(176, new PrivacyOptionMessageDecoder()); - - SpamPacketMessageDecoder spamMessageDecoder = new SpamPacketMessageDecoder(); - register(40, spamMessageDecoder); - register(244, spamMessageDecoder); - - register(112, new FirstNpcActionMessageDecoder()); - register(67, new SecondNpcActionMessageDecoder()); - register(13, new ThirdNpcActionMessageDecoder()); - register(42, new FourthNpcActionMessageDecoder()); - register(8, new FifthNpcActionMessageDecoder()); - - register(71, new TakeTileItemMessageDecoder()); - register(152, new ItemOnObjectMessageDecoder()); - - register(245, new FirstPlayerActionMessageDecoder()); - register(233, new SecondPlayerActionMessageDecoder()); - register(194, new ThirdPlayerActionMessageDecoder()); - register(116, new FourthPlayerActionMessageDecoder()); - register(45, new FifthPlayerActionMessageDecoder()); - - register(120, new AddFriendMessageDecoder()); - register(217, new AddIgnoreMessageDecoder()); - register(141, new RemoveFriendMessageDecoder()); - register(160, new RemoveIgnoreMessageDecoder()); - register(227, new PrivateChatMessageDecoder()); - - register(184, new ReportAbuseMessageDecoder()); - - register(IdAssignmentMessage.class, new IdAssignmentMessageEncoder()); - register(RegionChangeMessage.class, new RegionChangeMessageEncoder()); - register(ServerChatMessage.class, new ServerMessageMessageEncoder()); - register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); - register(OpenInterfaceMessage.class, new OpenInterfaceMessageEncoder()); - register(CloseInterfaceMessage.class, new CloseInterfaceMessageEncoder()); - register(SwitchTabInterfaceMessage.class, new SwitchTabInterfaceMessageEncoder()); - register(LogoutMessage.class, new LogoutMessageEncoder()); - register(UpdateItemsMessage.class, new UpdateItemsMessageEncoder()); - register(UpdateSlottedItemsMessage.class, new UpdateSlottedItemsMessageEncoder()); - register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); - register(OpenInterfaceSidebarMessage.class, new OpenInterfaceSidebarMessageEncoder()); - register(EnterAmountMessage.class, new EnterAmountMessageEncoder()); - register(SetWidgetTextMessage.class, new SetWidgetTextMessageEncoder()); - register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); - - register(SetWidgetVisibilityMessage.class, new SetWidgetVisibilityMessageEncoder()); - register(SetWidgetItemModelMessage.class, new SetWidgetItemModelMessageEncoder()); - register(SetWidgetNpcModelMessage.class, new SetWidgetNpcModelMessageEncoder()); - register(SetWidgetPlayerModelMessage.class, new SetWidgetPlayerModelMessageEncoder()); - register(SetWidgetModelAnimationMessage.class, new SetWidgetModelAnimationMessageEncoder()); - - register(ConfigMessage.class, new ConfigMessageEncoder()); - register(DisplayTabInterfaceMessage.class, new DisplayTabInterfaceMessageEncoder()); - register(SetUpdatedRegionMessage.class, new SetUpdatedRegionMessageEncoder()); - register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); - register(PrivacyOptionMessage.class, new PrivacyOptionMessageEncoder()); - register(OpenDialogueInterfaceMessage.class, new OpenDialogueInterfaceMessageEncoder()); - register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); - register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); - register(DisplayCrossbonesMessage.class, new DisplayCrossbonesMessageEncoder()); - - register(SendPublicTileItemMessage.class, new AddGlobalTileItemMessageEncoder()); - register(SendTileItemMessage.class, new AddTileItemMessageEncoder()); - register(UpdateTileItemMessage.class, new UpdateTileItemMessageEncoder()); - register(RemoveTileItemMessage.class, new RemoveTileItemMessageEncoder()); - register(SendObjectMessage.class, new SendObjectMessageEncoder()); - register(RemoveObjectMessage.class, new RemoveObjectMessageEncoder()); - register(SendProjectileMessage.class, new SendProjectileMessageEncoder()); - - register(GroupedRegionUpdateMessage.class, new GroupedRegionUpdateMessageEncoder(this)); - register(ClearRegionMessage.class, new ClearRegionMessageEncoder()); - - register(ForwardPrivateChatMessage.class, new ForwardPrivateChatMessageEncoder()); - register(FriendServerStatusMessage.class, new FriendServerStatusMessageEncoder()); - register(IgnoreListMessage.class, new IgnoreListMessageEncoder()); - register(SendFriendMessage.class, new SendFriendMessageEncoder()); - register(MobHintIconMessage.class, new MobHintIconMessageEncoder()); - register(PositionHintIconMessage.class, new PositionHintIconMessageEncoder()); - register(FlashTabInterfaceMessage.class, new FlashTabInterfaceMessageEncoder()); - register(OpenSidebarMessage.class, new OpenSidebarMessageEncoder()); - register(OpenOverlayMessage.class, new OpenOverlayMessageEncoder()); - register(OpenDialogueOverlayMessage.class, new OpenDialogueOverlayMessageEncoder()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/RemoveFriendMessageDecoder.java deleted file mode 100644 index d0b443742..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveFriendMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.RemoveFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link RemoveFriendMessage}. - * - * @author Major - */ -public final class RemoveFriendMessageDecoder extends MessageDecoder { - - @Override - public RemoveFriendMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new RemoveFriendMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/RemoveIgnoreMessageDecoder.java deleted file mode 100644 index 5f39dc69c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveIgnoreMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.RemoveIgnoreMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link RemoveIgnoreMessage}. - * - * @author Major - */ -public final class RemoveIgnoreMessageDecoder extends MessageDecoder { - - @Override - public RemoveIgnoreMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new RemoveIgnoreMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SecondPlayerActionMessageDecoder.java deleted file mode 100644 index 65aad4bb7..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SecondPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link PlayerActionMessage}. - * - * @author Major - */ -public final class SecondPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new PlayerActionMessage(2, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SendObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SendObjectMessageEncoder.java deleted file mode 100644 index 5aadde3fe..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SendObjectMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendObjectMessage}. - * - * @author Major - */ -public final class SendObjectMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(152); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getType() << 2 | message.getOrientation()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SpamPacketMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SpamPacketMessageDecoder.java deleted file mode 100644 index dbf875089..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SpamPacketMessageDecoder.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SpamPacketMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link SpamPacketMessage}. - * - * @author Major - */ -public final class SpamPacketMessageDecoder extends MessageDecoder { - - @Override - public SpamPacketMessage decode(GamePacket packet) { - return new SpamPacketMessage(packet.content().array()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ThirdPlayerActionMessageDecoder.java deleted file mode 100644 index cceb1fb9c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link PlayerActionMessage}. - * - * @author Major - */ -public final class ThirdPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(3, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/WalkMessageDecoder.java deleted file mode 100644 index e57c5f0bb..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/WalkMessageDecoder.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.WalkMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link WalkMessage}. - * - * @author Graham - */ -public final class WalkMessageDecoder extends MessageDecoder { - - @Override - public WalkMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int length = packet.getLength(); - if (packet.getOpcode() == 213) { - length -= 14; // strip off anti-cheat data - } - - int steps = (length - 5) / 2; - int[][] path = new int[steps][2]; - - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - boolean run = reader.getUnsigned(DataType.BYTE) == 1; - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - for (int i = 0; i < steps; i++) { - path[i][0] = (int) reader.getSigned(DataType.BYTE); - path[i][1] = (int) reader.getSigned(DataType.BYTE, DataTransformation.SUBTRACT); - } - - Position[] positions = new Position[steps + 1]; - positions[0] = new Position(x, y); - for (int i = 0; i < steps; i++) { - positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y); - } - - return new WalkMessage(positions, run); - } - -} \ No newline at end of file From e0e3bd7139b80a474fa74840884c2320d67e599e Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 2 Mar 2020 21:11:31 -0500 Subject: [PATCH 13/63] Refractored the directories in which each file lives. This seems more organized but if anyone has suggestions I will gladly listen. --- .../apollo/game/release/r181/Release181.java | 19 ++++++++++++++++++- .../ArrowKeyMessageDecoder.java | 2 +- .../{ => decoders}/CommandMessageDecoder.java | 2 +- .../KeepAliveMessageDecoder.java | 2 +- .../{ => decoders}/WalkMessageDecoder.java | 2 +- .../ClosedInterfaceMessageDecoder.java | 2 +- .../EnteredAmountMessageDecoder.java | 2 +- .../npcs}/FifthNpcActionMessageDecoder.java | 2 +- .../npcs}/FirstNpcActionMessageDecoder.java | 2 +- .../npcs}/FourthNpcActionMessageDecoder.java | 2 +- .../npcs}/SecondNpcActionMessageDecoder.java | 2 +- .../npcs}/SixthNpcActionMessageDecoder.java | 2 +- .../npcs}/ThirdNpcActionMessageDecoder.java | 2 +- .../obj}/FifthObjectActionMessageDecoder.java | 2 +- .../obj}/FirstObjectActionMessageDecoder.java | 2 +- .../FourthObjectActionMessageDecoder.java | 2 +- .../SecondObjectActionMessageDecoder.java | 2 +- .../obj}/SixthObjectActionMessageDecoder.java | 2 +- .../obj}/SpamPacketMessageDecoder.java | 2 +- .../obj}/ThirdObjectActionMessageDecoder.java | 2 +- .../player}/ReportAbuseMessageDecoder.java | 2 +- .../EightPlayerActionMessageDecoder.java | 2 +- .../FifthPlayerActionMessageDecoder.java | 2 +- .../FirstPlayerActionMessageDecoder.java | 2 +- .../FourthPlayerActionMessageDecoder.java | 2 +- .../SecondPlayerActionMessageDecoder.java | 2 +- .../SeventhPlayerActionMessageDecoder.java | 4 +--- .../SixthPlayerActionMessageDecoder.java | 2 +- .../ThirdPlayerActionMessageDecoder.java | 2 +- .../social}/PrivacyOptionMessageDecoder.java | 2 +- .../social}/PrivateChatMessageDecoder.java | 2 +- .../friends}/AddFriendMessageDecoder.java | 2 +- .../friends}/RemoveFriendMessageDecoder.java | 2 +- .../ignores}/AddIgnoreMessageDecoder.java | 2 +- .../ignores}/RemoveIgnoreMessageDecoder.java | 2 +- .../{ => encoders}/ConfigMessageEncoder.java | 2 +- 36 files changed, 53 insertions(+), 38 deletions(-) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders}/ArrowKeyMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders}/CommandMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders}/KeepAliveMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders}/WalkMessageDecoder.java (95%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/interfaces}/ClosedInterfaceMessageDecoder.java (88%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/interfaces}/EnteredAmountMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/npcs}/FifthNpcActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/npcs}/FirstNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/npcs}/FourthNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/npcs}/SecondNpcActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/npcs}/SixthNpcActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/npcs}/ThirdNpcActionMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/obj}/FifthObjectActionMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/obj}/FirstObjectActionMessageDecoder.java (95%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/obj}/FourthObjectActionMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/obj}/SecondObjectActionMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/obj}/SixthObjectActionMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/obj}/SpamPacketMessageDecoder.java (89%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/obj}/ThirdObjectActionMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player}/ReportAbuseMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/EightPlayerActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/FifthPlayerActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/FirstPlayerActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/FourthPlayerActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/SecondPlayerActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/SeventhPlayerActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/SixthPlayerActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/player/actions}/ThirdPlayerActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/social}/PrivacyOptionMessageDecoder.java (94%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/social}/PrivateChatMessageDecoder.java (95%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/social/friends}/AddFriendMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/social/friends}/RemoveFriendMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/social/ignores}/AddIgnoreMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/{ => decoders/social/ignores}/RemoveIgnoreMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/{ => encoders}/ConfigMessageEncoder.java (95%) diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 0765d6abe..a75c8d206 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,7 +1,19 @@ package org.apollo.game.release.r181; import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.game.message.impl.ReportAbuseMessage; +import org.apollo.game.release.r181.decoders.*; +import org.apollo.game.release.r181.decoders.interfaces.ClosedInterfaceMessageDecoder; +import org.apollo.game.release.r181.decoders.interfaces.EnteredAmountMessageDecoder; +import org.apollo.game.release.r181.decoders.npcs.*; +import org.apollo.game.release.r181.decoders.obj.*; +import org.apollo.game.release.r181.decoders.player.actions.*; +import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; +import org.apollo.game.release.r181.decoders.social.PrivateChatMessageDecoder; +import org.apollo.game.release.r181.decoders.social.friends.AddFriendMessageDecoder; +import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; +import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; +import org.apollo.game.release.r181.decoders.social.ignores.RemoveIgnoreMessageDecoder; +import org.apollo.game.release.r181.encoders.ConfigMessageEncoder; import org.apollo.net.meta.PacketMetaDataGroup; import org.apollo.net.release.Release; @@ -206,6 +218,11 @@ private void init() { register(94, new FifthObjectActionMessageDecoder()); register(36, new SixthObjectActionMessageDecoder()); + /** + * Floor Items + */ + + register(38, new ReportAbuseMessageDecoder()); register(60, new CommandMessageDecoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/ArrowKeyMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/ArrowKeyMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java index 47ffad951..51c0f4075 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ArrowKeyMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders; import org.apollo.game.message.impl.ArrowKeyMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/CommandMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/CommandMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java index c9590e6e3..4b3516031 100644 --- a/game/src/main/java/org/apollo/game/release/r181/CommandMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders; import org.apollo.game.message.impl.CommandMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/KeepAliveMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/KeepAliveMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java index e42e4df66..d7b9df27f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/KeepAliveMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders; import org.apollo.game.message.impl.KeepAliveMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/WalkMessageDecoder.java similarity index 95% rename from game/src/main/java/org/apollo/game/release/r181/WalkMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/WalkMessageDecoder.java index a2ef4b427..228def9ba 100644 --- a/game/src/main/java/org/apollo/game/release/r181/WalkMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/WalkMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders; import org.apollo.game.message.impl.WalkMessage; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/release/r181/ClosedInterfaceMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java similarity index 88% rename from game/src/main/java/org/apollo/game/release/r181/ClosedInterfaceMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java index 74ec01998..180c19f05 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ClosedInterfaceMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.interfaces; import org.apollo.game.message.impl.ClosedInterfaceMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/EnteredAmountMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/EnteredAmountMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java index 660ae11c6..78dadf2c6 100644 --- a/game/src/main/java/org/apollo/game/release/r181/EnteredAmountMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.interfaces; import org.apollo.game.message.impl.EnteredAmountMessage; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FifthNpcActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/FifthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FifthNpcActionMessageDecoder.java index 2e160f3e7..bfb87e668 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FifthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FifthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.npcs; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FirstNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/FirstNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FirstNpcActionMessageDecoder.java index c3cb7e6b6..3e4afb749 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FirstNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FirstNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.npcs; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FourthNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/FourthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FourthNpcActionMessageDecoder.java index ae12278e3..aca60dec8 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FourthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FourthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.npcs; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SecondNpcActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/SecondNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SecondNpcActionMessageDecoder.java index 045eab6c5..888509ff8 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SecondNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.npcs; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/SixthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SixthNpcActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/SixthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SixthNpcActionMessageDecoder.java index 925363006..33558e69e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SixthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SixthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.npcs; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/ThirdNpcActionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/ThirdNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npcs/ThirdNpcActionMessageDecoder.java index 10c5bb0b1..ef1259d65 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/ThirdNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.npcs; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataOrder; diff --git a/game/src/main/java/org/apollo/game/release/r181/FifthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FifthObjectActionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/FifthObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/obj/FifthObjectActionMessageDecoder.java index ebe99ec7b..8a8e3552d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FifthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FifthObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/release/r181/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java similarity index 95% rename from game/src/main/java/org/apollo/game/release/r181/FirstObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java index 0ca3b89b0..3de643870 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FirstObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/release/r181/FourthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FourthObjectActionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/FourthObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/obj/FourthObjectActionMessageDecoder.java index bdc54bac8..d1fae7a44 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FourthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FourthObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/release/r181/SecondObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/SecondObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java index 931dc9b88..156398b1e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SecondObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/release/r181/SixthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SixthObjectActionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/SixthObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/obj/SixthObjectActionMessageDecoder.java index daaab41dd..2b4852fa3 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SixthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SixthObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/release/r181/SpamPacketMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r181/SpamPacketMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java index 651888495..3ecb0120b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SpamPacketMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.obj; import org.apollo.game.message.impl.SpamPacketMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/ThirdObjectActionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/ThirdObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/obj/ThirdObjectActionMessageDecoder.java index 3d363acbe..ff3e377bf 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ThirdObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/ThirdObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/release/r181/ReportAbuseMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/ReportAbuseMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/ReportAbuseMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/ReportAbuseMessageDecoder.java index 2581eeaa0..0043478d6 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ReportAbuseMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/ReportAbuseMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player; import org.apollo.game.message.impl.ReportAbuseMessage; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/EightPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/EightPlayerActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/EightPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/EightPlayerActionMessageDecoder.java index b7b39cd4e..5e4a8fb60 100644 --- a/game/src/main/java/org/apollo/game/release/r181/EightPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/EightPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/FifthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FifthPlayerActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/FifthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FifthPlayerActionMessageDecoder.java index 5ca7666ee..ea1d432df 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FifthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FifthPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/FirstPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java index 784efabc5..7abbfeb6a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FirstPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataOrder; diff --git a/game/src/main/java/org/apollo/game/release/r181/FourthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FourthPlayerActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/FourthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FourthPlayerActionMessageDecoder.java index bb8b2f41f..ee01de133 100644 --- a/game/src/main/java/org/apollo/game/release/r181/FourthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FourthPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/SecondPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SecondPlayerActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/SecondPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SecondPlayerActionMessageDecoder.java index fde830ca1..9d3143f38 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SecondPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SecondPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/SeventhPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SeventhPlayerActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/SeventhPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SeventhPlayerActionMessageDecoder.java index 8aa2305a8..8986a5bfa 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SeventhPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SeventhPlayerActionMessageDecoder.java @@ -1,11 +1,9 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; -import java.nio.ByteOrder; - /** * A {@link MessageDecoder} for the seventh {@link PlayerActionMessage}. * diff --git a/game/src/main/java/org/apollo/game/release/r181/SixthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SixthPlayerActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/SixthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SixthPlayerActionMessageDecoder.java index 951e8afc5..3957a08d8 100644 --- a/game/src/main/java/org/apollo/game/release/r181/SixthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SixthPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/ThirdPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java index c5490bff7..f13d8bdc0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ThirdPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/PrivacyOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/PrivacyOptionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java index fe48c5dcd..79b4c55e5 100644 --- a/game/src/main/java/org/apollo/game/release/r181/PrivacyOptionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.social; import org.apollo.game.message.impl.PrivacyOptionMessage; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java similarity index 95% rename from game/src/main/java/org/apollo/game/release/r181/PrivateChatMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java index c78878ac8..52489cbc2 100644 --- a/game/src/main/java/org/apollo/game/release/r181/PrivateChatMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.social; import org.apollo.game.message.impl.PrivateChatMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/AddFriendMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java index 2d14c406b..a46869bdc 100644 --- a/game/src/main/java/org/apollo/game/release/r181/AddFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.social.friends; import org.apollo.game.message.impl.AddFriendMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/RemoveFriendMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java index 77792cccd..912f85142 100644 --- a/game/src/main/java/org/apollo/game/release/r181/RemoveFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.social.friends; import org.apollo.game.message.impl.RemoveFriendMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/AddIgnoreMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java index 21eca587f..5e7b5ecea 100644 --- a/game/src/main/java/org/apollo/game/release/r181/AddIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.social.ignores; import org.apollo.game.message.impl.AddIgnoreMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/RemoveIgnoreMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java index 4fc42deb4..d07858d49 100644 --- a/game/src/main/java/org/apollo/game/release/r181/RemoveIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.decoders.social.ignores; import org.apollo.game.message.impl.RemoveIgnoreMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java similarity index 95% rename from game/src/main/java/org/apollo/game/release/r181/ConfigMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java index 75139e8c0..1182fad5d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/ConfigMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181; +package org.apollo.game.release.r181.encoders; import org.apollo.game.message.impl.ConfigMessage; import org.apollo.net.codec.game.DataTransformation; From b0c09183a3e7b9c9863f454b4bf294d14fa00b2a Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 2 Mar 2020 21:12:22 -0500 Subject: [PATCH 14/63] Refractored the directories in which each file lives. This seems more organized but if anyone has suggestions I will gladly listen. --- game/src/main/java/org/apollo/game/release/r181/Release181.java | 2 +- .../decoders/{npcs => npc}/FifthNpcActionMessageDecoder.java | 0 .../decoders/{npcs => npc}/FirstNpcActionMessageDecoder.java | 2 +- .../decoders/{npcs => npc}/FourthNpcActionMessageDecoder.java | 2 +- .../decoders/{npcs => npc}/SecondNpcActionMessageDecoder.java | 2 +- .../decoders/{npcs => npc}/SixthNpcActionMessageDecoder.java | 2 +- .../decoders/{npcs => npc}/ThirdNpcActionMessageDecoder.java | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename game/src/main/java/org/apollo/game/release/r181/decoders/{npcs => npc}/FifthNpcActionMessageDecoder.java (100%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{npcs => npc}/FirstNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{npcs => npc}/FourthNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{npcs => npc}/SecondNpcActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{npcs => npc}/SixthNpcActionMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{npcs => npc}/ThirdNpcActionMessageDecoder.java (94%) diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index a75c8d206..76d3e7262 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -4,7 +4,7 @@ import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.interfaces.ClosedInterfaceMessageDecoder; import org.apollo.game.release.r181.decoders.interfaces.EnteredAmountMessageDecoder; -import org.apollo.game.release.r181.decoders.npcs.*; +import org.apollo.game.release.r181.decoders.npc.*; import org.apollo.game.release.r181.decoders.obj.*; import org.apollo.game.release.r181.decoders.player.actions.*; import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java similarity index 100% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FifthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FirstNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FirstNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npc/FirstNpcActionMessageDecoder.java index 3e4afb749..6339afa6f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FirstNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FirstNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npcs; +package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FourthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java index aca60dec8..6a0c068d5 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/FourthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npcs; +package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SecondNpcActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SecondNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npc/SecondNpcActionMessageDecoder.java index 888509ff8..5a04e08d2 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SecondNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npcs; +package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SixthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SixthNpcActionMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SixthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npc/SixthNpcActionMessageDecoder.java index 33558e69e..c571cea08 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/SixthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SixthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npcs; +package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java similarity index 94% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npcs/ThirdNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java index ef1259d65..68588c853 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npcs/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npcs; +package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataOrder; From 1e133f6fceca102d9f030933af3fd37fa33cb89a Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Wed, 4 Mar 2020 00:11:43 -0500 Subject: [PATCH 15/63] Changes the writeString(...) method's in BufferUtil.java to use Windows-1252 characters. More decoding messages, have these remaining so far: ButtonMessageDecoder DialogueContinueMessageDecoder FlaggedMouseEventMessageDecoder ItemOnItemMessageDecoder ItemOnNpcMessageDecoder ItemOnObjectMessageDecoder SwitchItemMessageDecoder TakeTileItemMessageDecoder MagicOnItemMessageDecoder MagicOnNpcMessageDecoder MagicOnPlayerMessageDecoder FirstItemOptionMessageDecoder SecondItemOptionMessageDecoder ThirdItemOptionMessageDecoder FourthItemOptionMessageDecoder FifthItemOptionMessageDecoder PlayerDesignMessageDecoder PublicChatMessageDecoder Doesn't exist anymore: FlashingTabClickedMessageDecoder FirstItemActionMessageDecoder SecondItemActionMessageDecoder ThirdItemActionMessageDecoder FourthItemActionMessageDecoder FifthItemActionMessageDecoder --- .../testing/junit/api/interactions/player.kt | 6 +- .../apollo/game/release/r181/Release181.java | 7 +- .../decoders}/FocusUpdateMessageDecoder.java | 7 +- .../decoders}/MouseClickedMessageDecoder.java | 14 +- .../npc/FifthNpcActionMessageDecoder.java | 2 +- .../r377/AddGlobalTileItemMessageEncoder.java | 28 -- .../r377/AddTileItemMessageEncoder.java | 26 - .../release/r377/ArrowKeyMessageDecoder.java | 25 - .../release/r377/ButtonMessageDecoder.java | 23 - .../r377/ClearRegionMessageEncoder.java | 29 -- .../r377/CloseInterfaceMessageEncoder.java | 21 - .../release/r377/ConfigMessageEncoder.java | 39 -- .../r377/DialogueContinueMessageDecoder.java | 23 - .../r377/DisplayCrossbonesMessageEncoder.java | 23 - .../DisplayTabInterfaceMessageEncoder.java | 24 - .../r377/EnterAmountMessageEncoder.java | 22 - .../r377/FifthItemActionMessageDecoder.java | 27 - .../r377/FifthItemOptionMessageDecoder.java | 29 -- .../r377/FirstItemActionMessageDecoder.java | 26 - .../r377/FirstItemOptionMessageDecoder.java | 29 -- .../r377/FlaggedMouseEventMessageDecoder.java | 39 -- .../r377/FlashTabInterfaceMessageEncoder.java | 23 - .../FlashingTabClickedMessageDecoder.java | 23 - .../ForwardPrivateChatMessageEncoder.java | 36 -- .../r377/FourthItemActionMessageDecoder.java | 27 - .../r377/FourthItemOptionMessageDecoder.java | 29 -- .../FriendServerStatusMessageEncoder.java | 22 - .../GroupedRegionUpdateMessageEncoder.java | 56 --- .../r377/IdAssignmentMessageEncoder.java | 25 - .../r377/IgnoreListMessageEncoder.java | 31 -- .../r377/ItemOnItemMessageDecoder.java | 34 -- .../release/r377/ItemOnNpcMessageDecoder.java | 30 -- .../r377/ItemOnObjectMessageDecoder.java | 32 -- .../release/r377/LogoutMessageEncoder.java | 21 - .../r377/MagicOnItemMessageDecoder.java | 29 -- .../r377/MagicOnNpcMessageDecoder.java | 28 -- .../r377/MagicOnPlayerMessageDecoder.java | 28 -- .../r377/MobAnimationResetMessageEncoder.java | 20 - .../r377/MobHintIconMessageEncoder.java | 36 -- .../NpcSynchronizationMessageEncoder.java | 300 ------------ .../OpenDialogueInterfaceMessageEncoder.java | 23 - .../OpenDialogueOverlayMessageEncoder.java | 24 - .../r377/OpenInterfaceMessageEncoder.java | 25 - .../OpenInterfaceSidebarMessageEncoder.java | 26 - .../r377/OpenOverlayMessageEncoder.java | 23 - .../r377/OpenSidebarMessageEncoder.java | 25 - .../r377/PlayerDesignMessageDecoder.java | 39 -- .../PlayerSynchronizationMessageEncoder.java | 460 ------------------ .../r377/PositionHintIconMessageEncoder.java | 38 -- .../r377/PrivacyOptionMessageEncoder.java | 27 - .../r377/PublicChatMessageDecoder.java | 40 -- .../r377/RegionChangeMessageEncoder.java | 26 - .../r377/RemoveObjectMessageEncoder.java | 25 - .../r377/RemoveTileItemMessageEncoder.java | 25 - .../r377/ReportAbuseMessageDecoder.java | 28 -- .../r377/SecondItemActionMessageDecoder.java | 29 -- .../r377/SecondItemOptionMessageDecoder.java | 29 -- .../r377/SendFriendMessageEncoder.java | 25 - .../r377/SendProjectileMessageEncoder.java | 37 -- .../r377/ServerMessageMessageEncoder.java | 23 - .../r377/SetPlayerActionMessageEncoder.java | 27 - .../r377/SetUpdatedRegionMessageEncoder.java | 30 -- .../SetWidgetItemModelMessageEncoder.java | 29 -- ...SetWidgetModelAnimationMessageEncoder.java | 28 -- .../r377/SetWidgetModelMessageEncoder.java | 28 -- .../r377/SetWidgetNpcModelMessageEncoder.java | 28 -- .../SetWidgetPlayerModelMessageEncoder.java | 25 - .../r377/SetWidgetTextMessageEncoder.java | 27 - .../SetWidgetVisibilityMessageEncoder.java | 26 - .../r377/SwitchItemMessageDecoder.java | 28 -- .../SwitchTabInterfaceMessageEncoder.java | 25 - .../r377/TakeTileItemMessageDecoder.java | 28 -- .../r377/ThirdItemActionMessageDecoder.java | 29 -- .../r377/ThirdItemOptionMessageDecoder.java | 29 -- .../r377/ThirdObjectActionMessageDecoder.java | 30 -- .../r377/UpdateItemsMessageEncoder.java | 46 -- .../r377/UpdateRunEnergyMessageEncoder.java | 23 - .../r377/UpdateSkillMessageEncoder.java | 30 -- .../UpdateSlottedItemsMessageEncoder.java | 46 -- .../r377/UpdateTileItemMessageEncoder.java | 26 - .../r377/UpdateWeightMessageEncoder.java | 23 - .../game/release/r377/package-info.java | 4 - .../ObjectActionVerificationHandlerTests.java | 4 +- .../resource/WorldListResourceProvider.java | 2 +- .../main/java/org/apollo/util/BufferUtil.java | 11 +- 85 files changed, 29 insertions(+), 2899 deletions(-) rename game/src/main/java/org/apollo/game/release/{r377 => r181/decoders}/FocusUpdateMessageDecoder.java (69%) rename game/src/main/java/org/apollo/game/release/{r377 => r181/decoders}/MouseClickedMessageDecoder.java (67%) delete mode 100644 game/src/main/java/org/apollo/game/release/r377/AddGlobalTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/AddTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ArrowKeyMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ButtonMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ClearRegionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/CloseInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ConfigMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/DialogueContinueMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/DisplayCrossbonesMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/DisplayTabInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/EnterAmountMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FifthItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FifthItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FirstItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FirstItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FlaggedMouseEventMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FlashTabInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FlashingTabClickedMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ForwardPrivateChatMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FourthItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FourthItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/FriendServerStatusMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/GroupedRegionUpdateMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/IdAssignmentMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/IgnoreListMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ItemOnItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ItemOnNpcMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ItemOnObjectMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/LogoutMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/MagicOnItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/MagicOnNpcMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/MagicOnPlayerMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/MobAnimationResetMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/MobHintIconMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/NpcSynchronizationMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/OpenDialogueInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/OpenDialogueOverlayMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/OpenInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/OpenInterfaceSidebarMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/OpenOverlayMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/OpenSidebarMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/PlayerDesignMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/PositionHintIconMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/PublicChatMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/RegionChangeMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/RemoveObjectMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/RemoveTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ReportAbuseMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SecondItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SecondItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SendFriendMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SendProjectileMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ServerMessageMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetPlayerActionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetUpdatedRegionMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetWidgetItemModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetWidgetModelAnimationMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetWidgetModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetWidgetNpcModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetWidgetPlayerModelMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetWidgetTextMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SetWidgetVisibilityMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SwitchItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/SwitchTabInterfaceMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/TakeTileItemMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ThirdItemActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ThirdItemOptionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/ThirdObjectActionMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/UpdateItemsMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/UpdateRunEnergyMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/UpdateSkillMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/UpdateSlottedItemsMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/UpdateTileItemMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/UpdateWeightMessageEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r377/package-info.java diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt index 252bc9dd9..6956df95e 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt @@ -35,8 +35,8 @@ fun Player.interactWith(entity: Entity, option: Int = 1) { position = entity.position.step(1, Direction.NORTH) when (entity) { - is GameObject -> send(ObjectActionMessage(option, entity.id, entity.position)) - is Npc -> send(NpcActionMessage(option, entity.index)) - is Player -> send(PlayerActionMessage(option, entity.index, movementType)) + is GameObject -> send(ObjectActionMessage(option, entity.id, entity.position, 0)) + is Npc -> send(NpcActionMessage(option, entity.index, 0)) + is Player -> send(PlayerActionMessage(option, entity.index, 0)) } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 76d3e7262..64fa22fc3 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -7,8 +7,8 @@ import org.apollo.game.release.r181.decoders.npc.*; import org.apollo.game.release.r181.decoders.obj.*; import org.apollo.game.release.r181.decoders.player.actions.*; -import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; -import org.apollo.game.release.r181.decoders.social.PrivateChatMessageDecoder; +import org.apollo.game.release.r181.decoders.player.*; +import org.apollo.game.release.r181.decoders.social.*; import org.apollo.game.release.r181.decoders.social.friends.AddFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; @@ -224,8 +224,9 @@ private void init() { register(38, new ReportAbuseMessageDecoder()); - + register(73, new FocusUpdateMessageDecoder()); register(60, new CommandMessageDecoder()); + register(41, new MouseClickedMessageDecoder()); register(22, new KeepAliveMessageDecoder()); //TODO register completed client prot here. diff --git a/game/src/main/java/org/apollo/game/release/r377/FocusUpdateMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java similarity index 69% rename from game/src/main/java/org/apollo/game/release/r377/FocusUpdateMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java index 7b8a30382..e724fe7c4 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FocusUpdateMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders; import org.apollo.game.message.impl.FocusUpdateMessage; import org.apollo.net.codec.game.DataType; @@ -15,8 +15,9 @@ public final class FocusUpdateMessageDecoder extends MessageDecoder> 20) * 50; - boolean right = (value >> 19 & 0x1) == 1; - - int cords = value & 0x3FFFF; - int x = cords % 765; - int y = cords / 765; + long delay = mousePacked >> 1; + boolean right = (mousePacked & 0x1) == 1; return new MouseClickedMessage(delay, right, x, y); } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java index bfb87e668..bc0fd8097 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npcs; +package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r377/AddGlobalTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/AddGlobalTileItemMessageEncoder.java deleted file mode 100644 index 6fa6058c8..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/AddGlobalTileItemMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendPublicTileItemMessage}. - * - * @author Major - */ -public final class AddGlobalTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendPublicTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(106); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getAmount()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getIndex()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/AddTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/AddTileItemMessageEncoder.java deleted file mode 100644 index 06e9b08fa..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/AddTileItemMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendTileItemMessage}. - * - * @author Major - */ -public final class AddTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(107); - builder.put(DataType.SHORT, message.getId()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getPositionOffset()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ArrowKeyMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ArrowKeyMessageDecoder.java deleted file mode 100644 index fe11b17c3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ArrowKeyMessageDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ArrowKeyMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ArrowKeyMessage}. - * - * @author Major - */ -public final class ArrowKeyMessageDecoder extends MessageDecoder { - - @Override - public ArrowKeyMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int roll = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int yaw = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new ArrowKeyMessage(roll, yaw); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ButtonMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ButtonMessageDecoder.java deleted file mode 100644 index 45795ba40..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ButtonMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ButtonMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ButtonMessage}. - * - * @author Graham - */ -public final class ButtonMessageDecoder extends MessageDecoder { - - @Override - public ButtonMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - return new ButtonMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ClearRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/ClearRegionMessageEncoder.java deleted file mode 100644 index 6bd9cae72..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ClearRegionMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ClearRegionMessage}. - * - * @author Major - */ -public final class ClearRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ClearRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(40); - Position player = message.getPlayerPosition(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player)); - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/CloseInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/CloseInterfaceMessageEncoder.java deleted file mode 100644 index 9474edaf5..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/CloseInterfaceMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link CloseInterfaceMessage}. - * - * @author Graham - */ -public final class CloseInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(CloseInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(29); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/ConfigMessageEncoder.java deleted file mode 100644 index 03cd3a493..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ConfigMessageEncoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ConfigMessage}. - * - * @author Chris Fletcher - * @author Major - */ -public final class ConfigMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ConfigMessage message) { - GamePacketBuilder builder; - int value = message.getValue(); - - if (value > Byte.MIN_VALUE && value < Byte.MAX_VALUE) { - builder = new GamePacketBuilder(182); - - builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, value & 0xFF); - } else { - builder = new GamePacketBuilder(115); - - builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, value); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/DialogueContinueMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/DialogueContinueMessageDecoder.java deleted file mode 100644 index 070aded91..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/DialogueContinueMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.DialogueContinueMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link DialogueContinueMessage}. - * - * @author Chris Fletcher - */ -public final class DialogueContinueMessageDecoder extends MessageDecoder { - - @Override - public DialogueContinueMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - return new DialogueContinueMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/DisplayCrossbonesMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/DisplayCrossbonesMessageEncoder.java deleted file mode 100644 index 0154ed1d5..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/DisplayCrossbonesMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayCrossbonesMessage}. - * - * @author Major - */ -public final class DisplayCrossbonesMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayCrossbonesMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(233); - builder.put(DataType.BYTE, message.isDisplayed() ? 1 : 0); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/DisplayTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/DisplayTabInterfaceMessageEncoder.java deleted file mode 100644 index b61ab2a82..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/DisplayTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayTabInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class DisplayTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(252); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/EnterAmountMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/EnterAmountMessageEncoder.java deleted file mode 100644 index 930b8e59a..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/EnterAmountMessageEncoder.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apollo.game.release.r377; - -import io.netty.buffer.Unpooled; - -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link EnterAmountMessage}. - * - * @author Graham - */ -public final class EnterAmountMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(EnterAmountMessage message) { - return new GamePacket(58, PacketType.FIXED, Unpooled.EMPTY_BUFFER); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FifthItemActionMessageDecoder.java deleted file mode 100644 index 244ebf0fe..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FifthItemActionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FifthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new ItemActionMessage(5, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FifthItemOptionMessageDecoder.java deleted file mode 100644 index bf4a16ac1..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FifthItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FifthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ItemOptionMessage(5, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstItemActionMessageDecoder.java deleted file mode 100644 index e01cec997..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FirstItemActionMessageDecoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FirstItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int slot = (int) reader.getUnsigned(DataType.SHORT); - return new ItemActionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstItemOptionMessageDecoder.java deleted file mode 100644 index ff9180127..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FirstItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FirstItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemOptionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FlaggedMouseEventMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FlaggedMouseEventMessageDecoder.java deleted file mode 100644 index 198024bf2..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FlaggedMouseEventMessageDecoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FlaggedMouseEventMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link org.apollo.game.message.impl.FlaggedMouseEventMessage}. - * - * @author Major - */ -public final class FlaggedMouseEventMessageDecoder extends MessageDecoder { - - @Override - public FlaggedMouseEventMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int read, clicks, x, y; - - if (reader.getLength() == 2) { - read = (int) reader.getUnsigned(DataType.SHORT); - clicks = read >> 12; - x = read >> 6 & 0x3f; - y = read & 0x3f; - return new FlaggedMouseEventMessage(clicks, x, y, true); - } else if (reader.getLength() == 3) { - read = (int) reader.getUnsigned(DataType.TRI_BYTE) & ~0x800000; - } else { - read = (int) reader.getUnsigned(DataType.INT) & ~0xc0000000; - } - - clicks = read >> 19; - x = (read & 0x7f) % 765; - y = (read & 0x7f) / 765; - return new FlaggedMouseEventMessage(clicks, x, y, false); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FlashTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/FlashTabInterfaceMessageEncoder.java deleted file mode 100644 index 8fce05d27..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FlashTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FlashTabInterfaceMessage}. - * - * @author Major - */ -public final class FlashTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FlashTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(238); - builder.put(DataType.BYTE, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FlashingTabClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FlashingTabClickedMessageDecoder.java deleted file mode 100644 index 12f36e870..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FlashingTabClickedMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FlashingTabClickedMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link FlashingTabClickedMessage}. - * - * @author Major - */ -public final class FlashingTabClickedMessageDecoder extends MessageDecoder { - - @Override - public FlashingTabClickedMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int tab = (int) reader.getUnsigned(DataType.BYTE); - return new FlashingTabClickedMessage(tab); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ForwardPrivateChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/ForwardPrivateChatMessageEncoder.java deleted file mode 100644 index 6491370a0..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ForwardPrivateChatMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r377; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link ForwardPrivateChatMessage}. - * - * @author Major - */ -public final class ForwardPrivateChatMessageEncoder extends MessageEncoder { - - /** - * The amount of messages sent globally, offset by a random variable x, {@code 0 <= x < 100,000,000}. - */ - private static AtomicInteger messageCounter = new AtomicInteger((int) (Math.random() * 100_000_000)); - - @Override - public GamePacket encode(ForwardPrivateChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(135, PacketType.VARIABLE_BYTE); - - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getSenderUsername())); - builder.put(DataType.INT, messageCounter.incrementAndGet()); - builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger()); - builder.putBytes(message.getCompressedMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FourthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FourthItemActionMessageDecoder.java deleted file mode 100644 index 9f95c6426..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FourthItemActionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FourthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT); - return new ItemActionMessage(4, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FourthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FourthItemOptionMessageDecoder.java deleted file mode 100644 index f6fa9ef42..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FourthItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FourthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOptionMessage(4, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FriendServerStatusMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/FriendServerStatusMessageEncoder.java deleted file mode 100644 index 32c2621d3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FriendServerStatusMessageEncoder.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FriendServerStatusMessage}. - * - * @author Major - */ -public final class FriendServerStatusMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FriendServerStatusMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(251); - builder.put(DataType.BYTE, message.getStatusCode()); - return builder.toGamePacket(); - } -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/GroupedRegionUpdateMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/GroupedRegionUpdateMessageEncoder.java deleted file mode 100644 index b41e415b5..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/GroupedRegionUpdateMessageEncoder.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.RegionUpdateMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.net.release.Release; - -/** - * A {@link MessageEncoder} for the {@link GroupedRegionUpdateMessage}. - * - * @author Major - */ -public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder { - - /** - * The Release containing the MessageEncoders for the RegionUpdateMessages. - */ - private final Release release; - - /** - * Creates the GroupedRegionUpdateMessageEncoder. - * - * @param release The {@link Release} containing the {@link MessageEncoder}s for the {@link RegionUpdateMessage}s. - */ - public GroupedRegionUpdateMessageEncoder(Release release) { - this.release = release; - } - - @Override - public GamePacket encode(GroupedRegionUpdateMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(183, PacketType.VARIABLE_SHORT); - Position base = message.getLastKnownRegion(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, region.getLocalX(base)); - builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(base)); - - for (RegionUpdateMessage update : message.getMessages()) { - @SuppressWarnings("unchecked") - MessageEncoder encoder = (MessageEncoder) release - .getMessageEncoder(update.getClass()); - - GamePacket packet = encoder.encode(update); - builder.put(DataType.BYTE, packet.getOpcode()); - builder.putBytes(packet.content()); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/IdAssignmentMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/IdAssignmentMessageEncoder.java deleted file mode 100644 index 3abe6f950..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/IdAssignmentMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link IdAssignmentMessage}. - * - * @author Graham - */ -public final class IdAssignmentMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IdAssignmentMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(126); - builder.put(DataType.BYTE, message.isMembers() ? 1 : 0); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/IgnoreListMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/IgnoreListMessageEncoder.java deleted file mode 100644 index 8e98a9b2e..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/IgnoreListMessageEncoder.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apollo.game.release.r377; - -import java.util.List; - -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link IgnoreListMessage}. - * - * @author Major - */ -public final class IgnoreListMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IgnoreListMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(226); - - List usernames = message.getUsernames(); - for (String username : usernames) { - builder.put(DataType.LONG, NameUtil.encodeBase37(username)); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ItemOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ItemOnItemMessageDecoder.java deleted file mode 100644 index 6deba8b52..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ItemOnItemMessageDecoder.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOnItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnItemMessageDecoder}. - * - * @author Chris Fletcher - */ -public final class ItemOnItemMessageDecoder extends MessageDecoder { - - @Override - public ItemOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int targetId = (int) reader.getUnsigned(DataType.SHORT); - int usedSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - int usedId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int targetInterface = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - int targetSlot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int usedInterface = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOnItemMessage(usedInterface, usedId, usedSlot, targetInterface, targetId, targetSlot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ItemOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ItemOnNpcMessageDecoder.java deleted file mode 100644 index 8600b17b6..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ItemOnNpcMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnNpcMessage}. - * - * @author Major - */ -public final class ItemOnNpcMessageDecoder extends MessageDecoder { - - @Override - public ItemOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int widget = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOnNpcMessage(id, index, slot, widget); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ItemOnObjectMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ItemOnObjectMessageDecoder.java deleted file mode 100644 index 92aadd2f6..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ItemOnObjectMessageDecoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOnObjectMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnObjectMessage}. - * - * @author Major - */ -public final class ItemOnObjectMessageDecoder extends MessageDecoder { - - @Override - public ItemOnObjectMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int objectId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int slot = (int) reader.getUnsigned(DataType.SHORT); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ItemOnObjectMessage(interfaceId, itemId, slot, objectId, x, y); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/LogoutMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/LogoutMessageEncoder.java deleted file mode 100644 index 6b720db7f..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/LogoutMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link LogoutMessage}. - * - * @author Graham - */ -public final class LogoutMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(LogoutMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(5); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MagicOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/MagicOnItemMessageDecoder.java deleted file mode 100644 index d8aeb87da..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MagicOnItemMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MagicOnItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnItemMessage}. - * - * @author Chris Fletcher - */ -public final class MagicOnItemMessageDecoder extends MessageDecoder { - - @Override - public MagicOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int spell = (int) reader.getUnsigned(DataType.SHORT); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnItemMessage(interfaceId, id, slot, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MagicOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/MagicOnNpcMessageDecoder.java deleted file mode 100644 index fca7e27a2..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MagicOnNpcMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MagicOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnNpcMessage} - * - * @author Stuart - */ -public final class MagicOnNpcMessageDecoder extends MessageDecoder { - - @Override - public MagicOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnNpcMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MagicOnPlayerMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/MagicOnPlayerMessageDecoder.java deleted file mode 100644 index 0ea104e96..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MagicOnPlayerMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MagicOnPlayerMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnPlayerMessage} - * - * @author Stuart - */ -public final class MagicOnPlayerMessageDecoder extends MessageDecoder { - - @Override - public MagicOnPlayerMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new MagicOnPlayerMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MobAnimationResetMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/MobAnimationResetMessageEncoder.java deleted file mode 100644 index d9b21215e..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MobAnimationResetMessageEncoder.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MobAnimationResetMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobAnimationResetMessage}. - * - * @author Major - */ -public final class MobAnimationResetMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobAnimationResetMessage message) { - return new GamePacketBuilder(13).toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MobHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/MobHintIconMessageEncoder.java deleted file mode 100644 index 8d86f89b4..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MobHintIconMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobHintIconMessage}. - * - * @author Major - */ -public final class MobHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(199); - HintIconMessage.Type type = message.getType(); - builder.put(DataType.BYTE, type.getValue()); - - switch (type) { - case NPC: - case PLAYER: - builder.put(DataType.SHORT, message.getIndex()); - builder.put(DataType.TRI_BYTE, 0); // Dummy bytes - break; - default: - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/NpcSynchronizationMessageEncoder.java deleted file mode 100644 index 05b8212fc..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/NpcSynchronizationMessageEncoder.java +++ /dev/null @@ -1,300 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Position; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TransformBlock; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddNpcSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link NpcSynchronizationMessage}. - * - * @author Major - */ -public final class NpcSynchronizationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(NpcSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(71, PacketType.VARIABLE_SHORT); - builder.switchToBitAccess(); - - GamePacketBuilder blockBuilder = new GamePacketBuilder(); - builder.putBits(8, message.getLocalNpcCount()); - - for (SynchronizationSegment segment : message.getSegments()) { - SegmentType type = segment.getType(); - if (type == SegmentType.REMOVE_MOB) { - putRemoveNpcUpdate(builder); - } else if (type == SegmentType.ADD_MOB) { - putAddNpcUpdate((AddNpcSegment) segment, message, builder); - putBlocks(segment, blockBuilder); - } else { - putMovementUpdate(segment, message, builder); - putBlocks(segment, blockBuilder); - } - } - - if (blockBuilder.getLength() > 0) { - builder.putBits(14, 16383); - builder.switchToByteAccess(); - builder.putRawBuilder(blockBuilder); - } else { - builder.switchToByteAccess(); - } - - return builder.toGamePacket(); - } - - /** - * Puts an add npc update. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - Position npc = message.getPosition(); - Position other = seg.getPosition(); - builder.putBits(14, seg.getIndex()); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(5, other.getY() - npc.getY()); - builder.putBits(5, other.getX() - npc.getX()); - builder.putBits(1, 0); // discard walking queue - builder.putBits(13, seg.getNpcId()); - } - - /** - * Puts an animation block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { - Animation animation = block.getAnimation(); - builder.put(DataType.SHORT, animation.getId()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, animation.getDelay()); - } - - /** - * Puts the blocks for the specified segment. - * - * @param segment The segment. - * @param builder The block builder. - */ - private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { - SynchronizationBlockSet blockSet = segment.getBlockSet(); - if (blockSet.size() > 0) { - int mask = 0; - - if (blockSet.contains(TransformBlock.class)) { - mask |= 0x1; - } - - if (blockSet.contains(InteractingMobBlock.class)) { - mask |= 0x40; - } - - if (blockSet.contains(HitUpdateBlock.class)) { - mask |= 0x80; - } - - if (blockSet.contains(GraphicBlock.class)) { - mask |= 0x4; - } - - if (blockSet.contains(ForceChatBlock.class)) { - mask |= 0x20; - } - - if (blockSet.contains(TurnToPositionBlock.class)) { - mask |= 0x8; - } - - if (blockSet.contains(AnimationBlock.class)) { - mask |= 0x2; - } - - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - mask |= 0x10; - } - - builder.put(DataType.BYTE, mask); - - if (blockSet.contains(TransformBlock.class)) { - putTransformBlock(blockSet.get(TransformBlock.class), builder); - } - - if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); - } - - if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); - } - - if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), builder); - } - - if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); - } - - if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); - } - - if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), builder); - } - - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } - } - } - - /** - * Puts a force chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { - builder.putString(block.getMessage()); - } - - /** - * Puts a graphic block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { - Graphic graphic = block.getGraphic(); - builder.put(DataType.SHORT, graphic.getId()); - builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF); - } - - /** - * Puts a hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.ADD, block.getType()); - builder.put(DataType.BYTE, block.getCurrentHealth()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getMaximumHealth()); - } - - /** - * Puts an interacting mob block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataOrder.LITTLE, block.getIndex()); - } - - /** - * Puts a movement update for the specified segment. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putMovementUpdate(SynchronizationSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - if (seg.getType() == SegmentType.RUN) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 2); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(3, directions[1].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (seg.getType() == SegmentType.WALK) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 1); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else { - if (updateRequired) { - builder.putBits(1, 1); - builder.putBits(2, 0); - } else { - builder.putBits(1, 0); - } - } - } - - /** - * Puts a remove mob update. - * - * @param builder The builder. - */ - private static void putRemoveNpcUpdate(GamePacketBuilder builder) { - builder.putBits(1, 1); - builder.putBits(2, 3); - } - - /** - * Puts a second hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); - builder.put(DataType.BYTE, block.getCurrentHealth()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getMaximumHealth()); - } - - /** - * Puts a transform block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTransformBlock(TransformBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataTransformation.ADD, block.getId()); - } - - /** - * Puts a turn to position block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position position = block.getPosition(); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, position.getX() * 2 + 1); - builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenDialogueInterfaceMessageEncoder.java deleted file mode 100644 index b85f9c9b9..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueInterfaceMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class OpenDialogueInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(109); - builder.put(DataType.SHORT, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenDialogueOverlayMessageEncoder.java deleted file mode 100644 index aad3e23b4..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueOverlayMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueOverlayMessage}. - * - * @author Major - */ -public final class OpenDialogueOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(158); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceMessageEncoder.java deleted file mode 100644 index 95e41cf71..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceMessage}. - * - * @author Graham - */ -public final class OpenInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(159); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceSidebarMessageEncoder.java deleted file mode 100644 index d552df54c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceSidebarMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceSidebarMessage}. - * - * @author Graham - */ -public final class OpenInterfaceSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(128); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenOverlayMessageEncoder.java deleted file mode 100644 index b807abf91..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenOverlayMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenOverlayMessage}. - * - * @author Major - */ -public final class OpenOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(50); - builder.put(DataType.SHORT, message.getOverlayId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenSidebarMessageEncoder.java deleted file mode 100644 index fafe3d113..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenSidebarMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenSidebarMessage}. - * - * @author Major - */ -public final class OpenSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(246); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PlayerDesignMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/PlayerDesignMessageDecoder.java deleted file mode 100644 index 713d09edb..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PlayerDesignMessageDecoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PlayerDesignMessage; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link PlayerDesignMessage}. - * - * @author Graham - */ -public final class PlayerDesignMessageDecoder extends MessageDecoder { - - @Override - public PlayerDesignMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int genderIntValue = (int) reader.getUnsigned(DataType.BYTE); - - int[] style = new int[7]; - for (int i = 0; i < style.length; i++) { - style[i] = (int) reader.getUnsigned(DataType.BYTE); - } - - int[] color = new int[5]; - for (int i = 0; i < color.length; i++) { - color[i] = (int) reader.getUnsigned(DataType.BYTE); - } - - Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE; - - return new PlayerDesignMessage(new Appearance(gender, style, color)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java deleted file mode 100644 index 5ef61f80c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java +++ /dev/null @@ -1,460 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Item; -import org.apollo.game.model.Position; -import org.apollo.game.model.entity.EquipmentConstants; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.game.model.inv.Inventory; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.ForceMovementBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddPlayerSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PlayerSynchronizationMessage}. - * - * @author Graham - * @author Major - */ -public final class PlayerSynchronizationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PlayerSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(90, PacketType.VARIABLE_SHORT); - builder.switchToBitAccess(); - - GamePacketBuilder blockBuilder = new GamePacketBuilder(); - - putMovementUpdate(message.getSegment(), message, builder); - putBlocks(message.getSegment(), blockBuilder); - - builder.putBits(8, message.getLocalPlayers()); - - for (SynchronizationSegment segment : message.getSegments()) { - SegmentType type = segment.getType(); - if (type == SegmentType.REMOVE_MOB) { - putRemovePlayerUpdate(builder); - } else if (type == SegmentType.ADD_MOB) { - putAddPlayerUpdate((AddPlayerSegment) segment, message, builder); - putBlocks(segment, blockBuilder); - } else { - putMovementUpdate(segment, message, builder); - putBlocks(segment, blockBuilder); - } - } - - if (blockBuilder.getLength() > 0) { - builder.putBits(11, 2047); - builder.switchToByteAccess(); - builder.putRawBuilder(blockBuilder); - } else { - builder.switchToByteAccess(); - } - - return builder.toGamePacket(); - } - - /** - * Puts an add player update. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - Position player = message.getPosition(); - Position other = seg.getPosition(); - builder.putBits(11, seg.getIndex()); - builder.putBits(5, other.getX() - player.getX()); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(1, 1); // discard walking queue? - builder.putBits(5, other.getY() - player.getY()); - } - - /** - * Puts an Animation block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { - Animation animation = block.getAnimation(); - builder.put(DataType.SHORT, animation.getId()); - builder.put(DataType.BYTE, DataTransformation.ADD, animation.getDelay()); - } - - /** - * Puts an Appearance block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { - Appearance appearance = block.getAppearance(); - GamePacketBuilder playerProperties = new GamePacketBuilder(); - - playerProperties.put(DataType.BYTE, appearance.getGender().toInteger()); - playerProperties.put(DataType.BYTE, block.isSkulled() ? 1 : -1); - playerProperties.put(DataType.BYTE, block.getHeadIcon()); - - if (block.appearingAsNpc()) { - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.SHORT, block.getNpcId()); - } else { - Inventory equipment = block.getEquipment(); - int[] style = appearance.getStyle(); - Item item, chest, helm; - - for (int slot = 0; slot < 4; slot++) { - if ((item = equipment.get(slot)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } - - if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + chest.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[2]); - } - - if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - - if (chest != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId()); - if (def != null && !def.isFullBody()) { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } - - if ((item = equipment.get(EquipmentConstants.LEGS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[5]); - } - - if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId()); - if (def != null && !def.isFullHat() && !def.isFullMask()) { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } - - if ((item = equipment.get(EquipmentConstants.HANDS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[4]); - } - - if ((item = equipment.get(EquipmentConstants.FEET)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[6]); - } - - EquipmentDefinition def = null; - if (helm != null) { - def = EquipmentDefinition.lookup(helm.getId()); - } - if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { - playerProperties.put(DataType.BYTE, 0); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[1]); - } - } - - int[] colors = appearance.getColors(); - for (int color : colors) { - playerProperties.put(DataType.BYTE, color); - } - - playerProperties.put(DataType.SHORT, 0x328); // stand - playerProperties.put(DataType.SHORT, 0x337); // stand turn - playerProperties.put(DataType.SHORT, 0x333); // walk - playerProperties.put(DataType.SHORT, 0x334); // turn 180 - playerProperties.put(DataType.SHORT, 0x335); // turn 90 cw - playerProperties.put(DataType.SHORT, 0x336); // turn 90 ccw - playerProperties.put(DataType.SHORT, 0x338); // run - - playerProperties.put(DataType.LONG, block.getName()); - playerProperties.put(DataType.BYTE, block.getCombatLevel()); - playerProperties.put(DataType.SHORT, block.getSkillLevel()); - - builder.put(DataType.BYTE, playerProperties.getLength()); - builder.putRawBuilderReverse(playerProperties); - } - - /** - * Puts the blocks for the specified segment. - * - * @param segment The segment. - * @param builder The block builder. - */ - private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { - SynchronizationBlockSet blockSet = segment.getBlockSet(); - if (blockSet.size() > 0) { - int mask = 0; - - if (blockSet.contains(AnimationBlock.class)) { - mask |= 0x8; - } - if (blockSet.contains(ForceChatBlock.class)) { - mask |= 0x10; - } - if (blockSet.contains(ForceMovementBlock.class)) { - mask |= 0x100; - } - if (blockSet.contains(InteractingMobBlock.class)) { - mask |= 0x1; - } - if (blockSet.contains(TurnToPositionBlock.class)) { - mask |= 0x2; - } - if (blockSet.contains(GraphicBlock.class)) { - mask |= 0x200; - } - if (blockSet.contains(AppearanceBlock.class)) { - mask |= 0x4; - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - mask |= 0x400; - } - if (blockSet.contains(ChatBlock.class)) { - mask |= 0x40; - } - if (blockSet.contains(HitUpdateBlock.class)) { - mask |= 0x80; - } - - if (mask >= 0x100) { - mask |= 0x20; - builder.put(DataType.SHORT, DataOrder.LITTLE, mask); - } else { - builder.put(DataType.BYTE, mask); - } - - if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), builder); - } - if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); - } - if (blockSet.contains(ForceMovementBlock.class)) { - putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder); - } - if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); - } - if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); - } - if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), builder); - } - if (blockSet.contains(AppearanceBlock.class)) { - putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder); - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } - if (blockSet.contains(ChatBlock.class)) { - putChatBlock(blockSet.get(ChatBlock.class), builder); - } - if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); - } - } - } - - /** - * Puts a chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) { - byte[] bytes = block.getCompressedMessage(); - builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextEffects() << 8 | block.getTextColor()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getPrivilegeLevel().toInteger()); - builder.put(DataType.BYTE, DataTransformation.ADD, bytes.length); - builder.putBytes(DataTransformation.ADD, bytes); - } - - /** - * Puts a force chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { - builder.putString(block.getMessage()); - } - - /** - * Puts a force movement block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.ADD, block.getInitialX()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getInitialY()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX()); - builder.put(DataType.BYTE, block.getFinalY()); - builder.put(DataType.SHORT, block.getTravelDurationX()); - builder.put(DataType.SHORT, DataTransformation.ADD, block.getTravelDurationY()); - builder.put(DataType.BYTE, block.getDirection().toInteger()); - } - - /** - * Puts a graphic block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { - Graphic graphic = block.getGraphic(); - builder.put(DataType.SHORT, DataTransformation.ADD, graphic.getId()); - builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay() & 0x0000FFFF); - } - - /** - * Puts a hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts an interacting mob block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataTransformation.ADD, block.getIndex()); - } - - /** - * Puts a movement update for the specified segment. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - if (seg.getType() == SegmentType.TELEPORT) { - Position pos = ((TeleportSegment) seg).getDestination(); - builder.putBits(1, 1); - builder.putBits(2, 3); - builder.putBits(1, message.hasRegionChanged() ? 0 : 1); - builder.putBits(2, pos.getHeight()); - builder.putBits(7, pos.getLocalY(message.getLastKnownRegion())); - builder.putBits(7, pos.getLocalX(message.getLastKnownRegion())); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (seg.getType() == SegmentType.RUN) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 2); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(3, directions[1].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (seg.getType() == SegmentType.WALK) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 1); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else { - if (updateRequired) { - builder.putBits(1, 1); - builder.putBits(2, 0); - } else { - builder.putBits(1, 0); - } - } - } - - /** - * Puts a remove player update. - * - * @param builder The builder. - */ - private static void putRemovePlayerUpdate(GamePacketBuilder builder) { - builder.putBits(1, 1); - builder.putBits(2, 3); - } - - /** - * Puts a secondary hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts a turn to position block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position position = block.getPosition(); - builder.put(DataType.SHORT, position.getX() * 2 + 1); - builder.put(DataType.SHORT, position.getY() * 2 + 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PositionHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/PositionHintIconMessageEncoder.java deleted file mode 100644 index 562d7b242..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PositionHintIconMessageEncoder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.HintIconMessage.Type; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PositionHintIconMessage}. - * - * @author Major - */ -public final class PositionHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PositionHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(199); - HintIconMessage.Type type = message.getType(); - - if (type == Type.PLAYER || type == Type.NPC) { - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - builder.put(DataType.BYTE, type.getValue()); - - Position position = message.getPosition(); - builder.put(DataType.SHORT, position.getX()); - builder.put(DataType.SHORT, position.getY()); - builder.put(DataType.BYTE, message.getHeight()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageEncoder.java deleted file mode 100644 index e033b5d31..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PrivacyOptionMessage}. - * - * @author Major - */ -public final class PrivacyOptionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(final PrivacyOptionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(201); - - builder.put(DataType.BYTE, message.getChatPrivacy().ordinal()); - builder.put(DataType.BYTE, message.getFriendPrivacy().ordinal()); - builder.put(DataType.BYTE, message.getTradePrivacy().ordinal()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PublicChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/PublicChatMessageDecoder.java deleted file mode 100644 index f871147d0..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PublicChatMessageDecoder.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PublicChatMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.TextUtil; - -/** - * A {@link MessageDecoder} for the {@link PublicChatMessage}. - * - * @author Graham - */ -public final class PublicChatMessageDecoder extends MessageDecoder { - - @Override - public PublicChatMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); - int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); - - int length = packet.getLength() - 2; - - byte[] originalCompressed = new byte[length]; - reader.getBytes(originalCompressed); - - String uncompressed = TextUtil.decompress(originalCompressed, length); - uncompressed = TextUtil.filterInvalidCharacters(uncompressed); - uncompressed = TextUtil.capitalize(uncompressed); - - byte[] recompressed = new byte[length]; - TextUtil.compress(uncompressed, recompressed); // in case invalid data gets sent, this effectively verifies it - - return new PublicChatMessage(uncompressed, recompressed, color, effects); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RegionChangeMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/RegionChangeMessageEncoder.java deleted file mode 100644 index e7e1eda67..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/RegionChangeMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RegionChangeMessage}. - * - * @author Graham - */ -public final class RegionChangeMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RegionChangeMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(222); - builder.put(DataType.SHORT, message.getPosition().getCentralRegionY()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getPosition().getCentralRegionX()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/RemoveObjectMessageEncoder.java deleted file mode 100644 index 76a89c355..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveObjectMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RemoveObjectMessage}. - * - * @author Major - */ -public final class RemoveObjectMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RemoveObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(88); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getPositionOffset()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getType() << 2 | message.getOrientation()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/RemoveTileItemMessageEncoder.java deleted file mode 100644 index f4af1d053..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveTileItemMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RemoveTileItemMessage}. - * - * @author Major - */ -public final class RemoveTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RemoveTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(208); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ReportAbuseMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ReportAbuseMessageDecoder.java deleted file mode 100644 index 1a3f40343..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ReportAbuseMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ReportAbuseMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link ReportAbuseMessage}. - * - * @author Major - */ -public final class ReportAbuseMessageDecoder extends MessageDecoder { - - @Override - public ReportAbuseMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - String name = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - int rule = (int) reader.getUnsigned(DataType.BYTE); - boolean mute = reader.getUnsigned(DataType.BYTE) == 1; - - return new ReportAbuseMessage(name, rule, mute); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SecondItemActionMessageDecoder.java deleted file mode 100644 index a6ea32ff7..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SecondItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ItemActionMessage}. - * - * @author Graham - */ -public final class SecondItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemActionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SecondItemOptionMessageDecoder.java deleted file mode 100644 index d344c1011..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SecondItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ItemOptionMessage}. - * - * @author Graham - */ -public final class SecondItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SendFriendMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SendFriendMessageEncoder.java deleted file mode 100644 index 83d846d52..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SendFriendMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link SendFriendMessage}. - * - * @author Major - */ -public final class SendFriendMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendFriendMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(78); - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getUsername())); - builder.put(DataType.BYTE, message.getEncodedWorld()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SendProjectileMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SendProjectileMessageEncoder.java deleted file mode 100644 index 1d4703692..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SendProjectileMessageEncoder.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendProjectileMessage; -import org.apollo.game.model.Position; -import org.apollo.game.model.entity.Projectile; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendProjectileMessage}. - */ -public final class SendProjectileMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendProjectileMessage message) { - Projectile projectile = message.getProjectile(); - Position source = projectile.getPosition(); - Position destination = projectile.getDestination(); - - GamePacketBuilder builder = new GamePacketBuilder(181); - builder.put(DataType.BYTE, message.getPositionOffset()); - builder.put(DataType.BYTE, destination.getX() - source.getX()); - builder.put(DataType.BYTE, destination.getY() - source.getY()); - builder.put(DataType.SHORT, projectile.getTarget()); - builder.put(DataType.SHORT, projectile.getGraphic()); - builder.put(DataType.BYTE, projectile.getStartHeight()); - builder.put(DataType.BYTE, projectile.getEndHeight()); - builder.put(DataType.SHORT, projectile.getDelay()); - builder.put(DataType.SHORT, projectile.getLifetime()); - builder.put(DataType.BYTE, projectile.getPitch()); - builder.put(DataType.BYTE, projectile.getOffset()); - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ServerMessageMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/ServerMessageMessageEncoder.java deleted file mode 100644 index ae2c5f9b3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ServerMessageMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ServerChatMessage}. - * - * @author Graham - */ -public final class ServerMessageMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ServerChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(63, PacketType.VARIABLE_BYTE); - builder.putString(message.getMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetPlayerActionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetPlayerActionMessageEncoder.java deleted file mode 100644 index ea8097df2..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetPlayerActionMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetPlayerActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * The {@link MessageEncoder} for the {@link SetPlayerActionMessage}. - * - * @author Major - */ -public final class SetPlayerActionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetPlayerActionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(157, PacketType.VARIABLE_BYTE); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getSlot()); - builder.putString(message.getText()); - builder.put(DataType.BYTE, message.isPrimaryAction() ? 0 : 1); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetUpdatedRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetUpdatedRegionMessageEncoder.java deleted file mode 100644 index ac0ca908f..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetUpdatedRegionMessageEncoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetUpdatedRegionMessage}. - * - * @author Chris Fletcher - * @author Major - */ -public final class SetUpdatedRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetUpdatedRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(75); - Position base = message.getPlayerPosition(), position = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, position.getLocalX(base)); - builder.put(DataType.BYTE, DataTransformation.ADD, position.getLocalY(base)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetItemModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetItemModelMessageEncoder.java deleted file mode 100644 index ea9a1f006..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetItemModelMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetItemModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetItemModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetItemModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(21); - - builder.put(DataType.SHORT, message.getZoom()); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getModelId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelAnimationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelAnimationMessageEncoder.java deleted file mode 100644 index 030636f33..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelAnimationMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelAnimationMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetModelAnimationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelAnimationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(2); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getAnimation() & 0xFFFF); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelMessageEncoder.java deleted file mode 100644 index 8df38af57..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelMessage}. - * - * @author Major - */ -public final class SetWidgetModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(216); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getModel()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetNpcModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetNpcModelMessageEncoder.java deleted file mode 100644 index c705314b3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetNpcModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetNpcModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetNpcModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetNpcModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(162); - - builder.put(DataType.SHORT, DataTransformation.ADD, message.getModelId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetPlayerModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetPlayerModelMessageEncoder.java deleted file mode 100644 index 07da7893e..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetPlayerModelMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetPlayerModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetPlayerModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetPlayerModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(255); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetTextMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetTextMessageEncoder.java deleted file mode 100644 index 525e36fbe..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetTextMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetTextMessage}. - * - * @author Graham - */ -public final class SetWidgetTextMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetTextMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(232, PacketType.VARIABLE_SHORT); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - builder.putString(message.getText()); - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetVisibilityMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetVisibilityMessageEncoder.java deleted file mode 100644 index 2e7062608..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetVisibilityMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetVisibilityMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetVisibilityMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetVisibilityMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(82); - - builder.put(DataType.BYTE, message.isVisible() ? 0 : 1); - builder.put(DataType.SHORT, message.getWidgetId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SwitchItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SwitchItemMessageDecoder.java deleted file mode 100644 index 6c1bef294..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SwitchItemMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SwitchItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link SwitchItemMessage}. - * - * @author Graham - */ -public final class SwitchItemMessageDecoder extends MessageDecoder { - - @Override - public SwitchItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int newSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - boolean inserting = reader.getUnsigned(DataType.BYTE, DataTransformation.ADD) == 1; - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int oldSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new SwitchItemMessage(interfaceId, inserting, oldSlot, newSlot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SwitchTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SwitchTabInterfaceMessageEncoder.java deleted file mode 100644 index e7d5d4a95..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SwitchTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SwitchTabInterfaceMessage}. - * - * @author Graham - */ -public final class SwitchTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SwitchTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(10); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getTabId()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/TakeTileItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/TakeTileItemMessageDecoder.java deleted file mode 100644 index e11e58d42..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/TakeTileItemMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.TakeTileItemMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link TakeTileItemMessage}. - * - * @author Major - */ -public final class TakeTileItemMessageDecoder extends MessageDecoder { - - @Override - public TakeTileItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new TakeTileItemMessage(id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ThirdItemActionMessageDecoder.java deleted file mode 100644 index 315c40d65..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemActionMessage}. - * - * @author Graham - */ -public final class ThirdItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemActionMessage(3, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ThirdItemOptionMessageDecoder.java deleted file mode 100644 index e61c9ee28..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class ThirdItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemOptionMessage(3, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ThirdObjectActionMessageDecoder.java deleted file mode 100644 index 63a05a3fc..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdObjectActionMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class ThirdObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ObjectActionMessage(3, id, new Position(x, y)); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateItemsMessageEncoder.java deleted file mode 100644 index 0523051bf..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateItemsMessageEncoder.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.model.Item; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateItemsMessage}. - * - * @author Graham - */ -public final class UpdateItemsMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(206, PacketType.VARIABLE_SHORT); - - Item[] items = message.getItems(); - - builder.put(DataType.SHORT, message.getInterfaceId()); - builder.put(DataType.SHORT, items.length); - - for (Item item : items) { - int id = item == null ? -1 : item.getId(); - int amount = item == null ? 0 : item.getAmount(); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, id + 1); - - if (amount > 254) { - builder.put(DataType.BYTE, DataTransformation.NEGATE, 255); - builder.put(DataType.INT, DataOrder.LITTLE, amount); - } else { - builder.put(DataType.BYTE, DataTransformation.NEGATE, amount); - } - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateRunEnergyMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateRunEnergyMessageEncoder.java deleted file mode 100644 index 59eebe7a8..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateRunEnergyMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateRunEnergyMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateRunEnergyMessage} - * - * @author Major - */ -public final class UpdateRunEnergyMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateRunEnergyMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(125); - builder.put(DataType.BYTE, message.getEnergy()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateSkillMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateSkillMessageEncoder.java deleted file mode 100644 index f6ebc9c8d..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateSkillMessageEncoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.model.entity.Skill; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateSkillMessage}. - * - * @author Graham - */ -public final class UpdateSkillMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateSkillMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(49); - Skill skill = message.getSkill(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getId()); - builder.put(DataType.BYTE, skill.getCurrentLevel()); - builder.put(DataType.INT, (int) skill.getExperience()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateSlottedItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateSlottedItemsMessageEncoder.java deleted file mode 100644 index 1ed51adff..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateSlottedItemsMessageEncoder.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; -import org.apollo.game.model.Item; -import org.apollo.game.model.inv.SlottedItem; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateSlottedItemsMessage}. - * - * @author Graham - */ -public final class UpdateSlottedItemsMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateSlottedItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(134, PacketType.VARIABLE_SHORT); - SlottedItem[] items = message.getSlottedItems(); - - builder.put(DataType.SHORT, message.getInterfaceId()); - - for (SlottedItem slottedItem : items) { - builder.putSmart(slottedItem.getSlot()); - - Item item = slottedItem.getItem(); - int id = item == null ? -1 : item.getId(); - int amount = item == null ? 0 : item.getAmount(); - - builder.put(DataType.SHORT, id + 1); - - if (amount > 254) { - builder.put(DataType.BYTE, 255); - builder.put(DataType.INT, amount); - } else { - builder.put(DataType.BYTE, amount); - } - } - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateTileItemMessageEncoder.java deleted file mode 100644 index 4e671e4bb..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateTileItemMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateTileItemMessage}. - * - * @author Major - */ -public final class UpdateTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(121); - builder.put(DataType.BYTE, message.getPositionOffset()); - builder.put(DataType.SHORT, message.getId()); - builder.put(DataType.SHORT, message.getPreviousAmount()); - builder.put(DataType.SHORT, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateWeightMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateWeightMessageEncoder.java deleted file mode 100644 index 2c550cb52..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateWeightMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateWeightMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateWeightMessage}. - * - * @author Major - */ -public final class UpdateWeightMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateWeightMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(174); - builder.put(DataType.SHORT, message.getWeight()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/package-info.java b/game/src/main/java/org/apollo/game/release/r377/package-info.java deleted file mode 100644 index a212df7f3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains codecs for the 377 release. - */ -package org.apollo.game.release.r377; \ No newline at end of file diff --git a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java index c4c396f67..3f6913917 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java @@ -55,7 +55,7 @@ public void terminateIfOutOfRange() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition); + ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition, 0); ObjectActionVerificationHandler objectActionVerificationHandler = new ObjectActionVerificationHandler(world); objectActionVerificationHandler.handle(player, objectActionMessage); @@ -81,7 +81,7 @@ public void terminateIfNoObject() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition); + ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition, 0); ObjectActionVerificationHandler objectActionVerificationHandler = new ObjectActionVerificationHandler(world); objectActionVerificationHandler.handle(player, objectActionMessage); diff --git a/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java b/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java index cb312729a..409d26321 100644 --- a/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java +++ b/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java @@ -37,7 +37,7 @@ private ByteBuffer createWorld() { BufferUtil.writeString(world, address); // address BufferUtil.writeString(world, activity); // activity world.put((byte) 0); // country - world.putShort((short) 2000);// number of players + world.putShort((short) 100);// number of players world.flip(); ByteBuffer list = ByteBuffer.allocate(Short.BYTES + world.remaining()); diff --git a/util/src/main/java/org/apollo/util/BufferUtil.java b/util/src/main/java/org/apollo/util/BufferUtil.java index ea0c522aa..f8276e13f 100644 --- a/util/src/main/java/org/apollo/util/BufferUtil.java +++ b/util/src/main/java/org/apollo/util/BufferUtil.java @@ -3,7 +3,7 @@ import io.netty.buffer.ByteBuf; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; +import java.nio.charset.Charset; /** * A utility class which contains {@link ByteBuffer}-related utility methods. @@ -107,7 +107,7 @@ public static String readJagexString(ByteBuf buffer) { * @param str */ public static void writeString(ByteBuf buffer, String str) { - byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1); + byte[] bytes = str.getBytes(CHARSET); buffer.writeBytes(bytes); buffer.writeByte(0); } @@ -118,7 +118,7 @@ public static void writeString(ByteBuf buffer, String str) { * @param str */ public static void writeString(ByteBuffer buffer, String str) { - byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1); + byte[] bytes = str.getBytes(CHARSET); buffer.put(bytes); buffer.put((byte) 0); } @@ -128,6 +128,11 @@ public static void writeString(ByteBuffer buffer, String str) { */ public static final int STRING_TERMINATOR = 0; + /** + * Charset that Jagex uses. + */ + public static final Charset CHARSET = Charset.forName("Windows-1252"); + /** * Default private constructor to prevent instantiation. */ From b4a3a62acd533d3e2baba488e5ed908ff735ea61 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 10 Mar 2020 20:50:26 -0400 Subject: [PATCH 16/63] Login to World complete. NPCS are complete w/o masks. --- .../org/apollo/cache/map/MapIndexDecoder.java | 10 +- .../{XteaParser.java => XteaRepository.java} | 8 +- game/plugin/skills/prayer/src/Prayer.kt | 2 +- .../runecrafting/src/Runecrafting.plugin.kts | 1 + .../game/fs/decoder/WorldObjectsDecoder.java | 11 +- .../message/impl/IdAssignmentMessage.java | 52 --- .../impl/NpcSynchronizationMessage.java | 17 +- .../message/impl/RegionChangeMessage.java | 36 -- .../impl/{ => decode}/ArrowKeyMessage.java | 2 +- .../impl/{ => encode}/ConfigMessage.java | 2 +- .../message/impl/encode/IfOpenTopMessage.java | 26 ++ .../impl/encode/RebuildNormalMessage.java | 84 +++++ .../java/org/apollo/game/model/Position.java | 40 +-- .../java/org/apollo/game/model/World.java | 8 +- .../game/model/area/RegionRepository.java | 32 +- .../org/apollo/game/model/entity/Player.java | 51 ++- .../apollo/game/release/r181/Release181.java | 13 +- .../r181/decoders/ArrowKeyMessageDecoder.java | 2 +- .../r181/encoders/ConfigMessageEncoder.java | 6 +- .../npc/NpcSynchronizationMessageEncoder.java | 323 ++++++++++++++++++ .../region/RebuildNormalMessageEncoder.java | 63 ++++ .../encoders/ui/IfOpenTopMessageEncoder.java | 15 + .../org/apollo/game/service/GameService.java | 9 +- .../org/apollo/game/session/LoginSession.java | 14 +- .../apollo/game/sync/seg/AddNpcSegment.java | 21 +- .../sync/task/NpcSynchronizationTask.java | 4 +- .../task/PrePlayerSynchronizationTask.java | 4 +- .../net/codec/game/GamePacketBuilder.java | 10 + .../net/codec/game/GamePacketDecoder.java | 1 + 29 files changed, 680 insertions(+), 187 deletions(-) rename cache/src/main/java/org/apollo/cache/map/{XteaParser.java => XteaRepository.java} (88%) delete mode 100644 game/src/main/java/org/apollo/game/message/impl/IdAssignmentMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/RegionChangeMessage.java rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ArrowKeyMessage.java (94%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/ConfigMessage.java (94%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfOpenTopMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenTopMessageEncoder.java diff --git a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java index 9149cf698..4b10d398a 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java @@ -25,11 +25,11 @@ public final class MapIndexDecoder implements Runnable { * The Cache. */ private final Cache cache; - private final XteaParser xteaParser; + private final XteaRepository xteaRepository; - public MapIndexDecoder(Cache cache, XteaParser xteaParser) { + public MapIndexDecoder(Cache cache, XteaRepository xteaRepository) { this.cache = cache; - this.xteaParser = xteaParser; + this.xteaRepository = xteaRepository; } /** @@ -42,7 +42,7 @@ public Map decode() throws IOException { Map definitions = new HashMap<>(); final var fs = cache.getArchive(MapConstants.MAP_INDEX); - for (var entry : xteaParser.getAll()) { + for (var entry : xteaRepository.getAll()) { final var region = entry.getIntKey(); final var regionX = region >> 8; final var regionY = region & 0xFF; @@ -66,7 +66,7 @@ public Map decode() throws IOException { @Override public void run() { try { - xteaParser.run(); + xteaRepository.run(); MapIndex.init(decode()); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/cache/src/main/java/org/apollo/cache/map/XteaParser.java b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java similarity index 88% rename from cache/src/main/java/org/apollo/cache/map/XteaParser.java rename to cache/src/main/java/org/apollo/cache/map/XteaRepository.java index f3b42eb87..423b58736 100644 --- a/cache/src/main/java/org/apollo/cache/map/XteaParser.java +++ b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java @@ -8,7 +8,7 @@ import java.io.IOException; import java.nio.file.Files; -public class XteaParser implements Runnable { +public class XteaRepository implements Runnable { private static final Gson GSON = new Gson(); @@ -33,7 +33,7 @@ public int[] getKeys() { private final int release; private final Int2ObjectArrayMap xteas; - public XteaParser(int release) { + public XteaRepository(int release) { this.xteas = new Int2ObjectArrayMap<>(); this.release = release; } @@ -55,6 +55,10 @@ public int[] get(int region) { return xteas.getOrDefault(region, null); } + public int[] get(int x, int y) { + return get(x << 8 | y); + } + public Int2ObjectMap.FastEntrySet getAll() { return xteas.int2ObjectEntrySet(); } diff --git a/game/plugin/skills/prayer/src/Prayer.kt b/game/plugin/skills/prayer/src/Prayer.kt index 3f281cc05..c4ff34e47 100644 --- a/game/plugin/skills/prayer/src/Prayer.kt +++ b/game/plugin/skills/prayer/src/Prayer.kt @@ -1,6 +1,6 @@ import com.google.common.collect.MultimapBuilder import com.google.common.collect.SetMultimap -import org.apollo.game.message.impl.ConfigMessage +import org.apollo.game.message.impl.encode.ConfigMessage import org.apollo.game.model.entity.Player enum class Prayer(val button: Int, val level: Int, val setting: Int, val drain: Double) { diff --git a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts index c9eb1cfc4..6cca23a6a 100644 --- a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts +++ b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts @@ -1,6 +1,7 @@ package org.apollo.game.plugin.skill.runecrafting import org.apollo.game.message.impl.* +import org.apollo.game.message.impl.encode.ConfigMessage import org.apollo.game.model.entity.EquipmentConstants import org.apollo.game.model.event.impl.LoginEvent diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java index 61244b618..ba47424ff 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java @@ -24,11 +24,6 @@ public final class WorldObjectsDecoder implements Runnable { */ private final Cache cache; - /** - * The {@link RegionRepository} to lookup {@link Region}s from. - */ - private final RegionRepository regionRepository; - /** * The {@link World} to register {@link StaticGameObject}s with. */ @@ -39,12 +34,10 @@ public final class WorldObjectsDecoder implements Runnable { * * @param cache The {@link Cache} to load object files from. * @param world The {@link World} to register objects with. - * @param regionRepository The {@link RegionRepository} to lookup {@link Region}s from. */ - public WorldObjectsDecoder(Cache cache, World world, RegionRepository regionRepository) { + public WorldObjectsDecoder(Cache cache, World world) { this.cache = cache; this.world = world; - this.regionRepository = regionRepository; } /** @@ -68,7 +61,7 @@ public void run() { StaticGameObject gameObject = new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation()); - regionRepository.fromPosition(position).addEntity(gameObject, false); + world.getRegionRepository().fromPosition(position).addEntity(gameObject, false); } } } catch (IOException ex) { diff --git a/game/src/main/java/org/apollo/game/message/impl/IdAssignmentMessage.java b/game/src/main/java/org/apollo/game/message/impl/IdAssignmentMessage.java deleted file mode 100644 index 13e82030b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/IdAssignmentMessage.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.model.entity.setting.MembershipStatus; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that specifies the local id and membership status of the current player. - * - * @author Graham - */ -public final class IdAssignmentMessage extends Message { - - /** - * The id of this player. - */ - private final int id; - - /** - * The MembershipStatus. - */ - private final MembershipStatus members; - - /** - * Creates the local id message. - * - * @param id The id. - * @param members The MembershipStatus. - */ - public IdAssignmentMessage(int id, MembershipStatus members) { - this.id = id; - this.members = members; - } - - /** - * Gets the id. - * - * @return The id. - */ - public int getId() { - return id; - } - - /** - * Gets whether or not the Player is a {@link MembershipStatus#PAID paying member}. - * - * @return {@code true} if the Player is a paying member, {@code false} if not. - */ - public boolean isMembers() { - return members == MembershipStatus.PAID; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java index cfb7c7f79..0f39bbec1 100644 --- a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java @@ -29,6 +29,11 @@ public final class NpcSynchronizationMessage extends Message { */ private final List segments; + /** + * If the player has an extended viewport. + */ + private final boolean extendedView; + /** * Creates a new {@link NpcSynchronizationMessage}. * @@ -36,10 +41,11 @@ public final class NpcSynchronizationMessage extends Message { * @param segments The list of segments. * @param localNpcs The amount of local npcs. */ - public NpcSynchronizationMessage(Position position, List segments, int localNpcs) { + public NpcSynchronizationMessage(Position position, List segments, int localNpcs, boolean extendedView) { this.position = position; this.segments = segments; this.localNpcs = localNpcs; + this.extendedView = extendedView; } /** @@ -69,4 +75,13 @@ public List getSegments() { return segments; } + + /** + * Is view extended boolean. + * + * @return the boolean + */ + public boolean isViewExtended() { + return extendedView; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/RegionChangeMessage.java b/game/src/main/java/org/apollo/game/message/impl/RegionChangeMessage.java deleted file mode 100644 index ed8800ce1..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/RegionChangeMessage.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.model.Position; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client instructing it to load the specified region. - * - * @author Graham - */ -public final class RegionChangeMessage extends Message { - - /** - * The position of the region to load. - */ - private final Position position; - - /** - * Creates the region changed message. - * - * @param position The position of the region. - */ - public RegionChangeMessage(Position position) { - this.position = position; - } - - /** - * Gets the position of the region to load. - * - * @return The position of the region to load. - */ - public Position getPosition() { - return position; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ArrowKeyMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ArrowKeyMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/ArrowKeyMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ArrowKeyMessage.java index f2f0f2ca0..01f37a175 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ArrowKeyMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ArrowKeyMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ConfigMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/ConfigMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java index 5d9a4209c..3d0d572d8 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ConfigMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenTopMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenTopMessage.java new file mode 100644 index 000000000..aa6e5bb59 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenTopMessage.java @@ -0,0 +1,26 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +public class IfOpenTopMessage extends Message { + + private final int id; + + /** + * Instantiates a new If open top message. + * + * @param id the interface id + */ + public IfOpenTopMessage(int id) { + this.id = id; + } + + /** + * Gets interface id. + * + * @return the interface id. + */ + public int getId() { + return id; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java new file mode 100644 index 000000000..6abd49d43 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java @@ -0,0 +1,84 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.cache.map.XteaRepository; +import org.apollo.game.model.Position; +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client instructing it to load the specified region. + * + * @author Graham + */ +public final class RebuildNormalMessage extends Message { + + /** + * The position of the region to load. + */ + private final Position position; + + /** + * The index of the player. + */ + private final int index; + + /** + * The repository containing xteas. + */ + private final XteaRepository repository; + + /** + * If the player has a last known region. + */ + private final boolean hasLastKnownRegion; + + /** + * Creates the region changed message. + * + * @param position The position of the region. + * @param repository the repository + * @param hasLastKnownRegion if the player has been in a region. + */ + public RebuildNormalMessage(Position position, int index, XteaRepository repository, boolean hasLastKnownRegion) { + this.position = position; + this.index = index; + this.repository = repository; + this.hasLastKnownRegion = hasLastKnownRegion; + } + + /** + * Gets the position of the region to load. + * + * @return The position of the region to load. + */ + public Position getPosition() { + return position; + } + + + /** + * Gets the index of the player. + * + * @return the index. + */ + public int getIndex() { + return index; + } + + /** + * Gets repository. + * + * @return the repository + */ + public XteaRepository getRepository() { + return repository; + } + + /** + * Is has last known region boolean. + * + * @return the boolean + */ + public boolean isHasLastKnownRegion() { + return hasLastKnownRegion; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/Position.java b/game/src/main/java/org/apollo/game/model/Position.java index e68241a00..5c38f0e29 100644 --- a/game/src/main/java/org/apollo/game/model/Position.java +++ b/game/src/main/java/org/apollo/game/model/Position.java @@ -1,10 +1,9 @@ package org.apollo.game.model; -import org.apollo.game.model.area.Region; -import org.apollo.game.model.area.RegionCoordinates; - import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.RegionCoordinates; /** * Represents a position in the world. @@ -41,14 +40,14 @@ public Position(int x, int y) { /** * Creates a position with the specified height. * - * @param x The x coordinate. - * @param y The y coordinate. + * @param x The x coordinate. + * @param y The y coordinate. * @param height The height. */ public Position(int x, int y, int height) { Preconditions.checkElementIndex(height, HEIGHT_LEVELS, "Height must be [0, 3), received " + height + "."); - packed = height << 30 | (y & 0x7FFF) << 15 | x & 0x7FFF; + packed = y & 0x3fff | ((x & 0x3fff) << 14) | (height << 28); } @Override @@ -91,15 +90,6 @@ public int getDistance(Position other) { return (int) Math.ceil(Math.sqrt(deltaX * deltaX + deltaY * deltaY)); } - /** - * Gets the height level. - * - * @return The height level. - */ - public int getHeight() { - return packed >>> 30; - } - /** * Gets the x coordinate inside the region of this position. * @@ -183,7 +173,7 @@ public int getTopLeftRegionY() { * @return The x coordinate. */ public int getX() { - return packed & 0x7FFF; + return packed >>> 14 & 0x3fff; } /** @@ -192,7 +182,16 @@ public int getX() { * @return The y coordinate. */ public int getY() { - return packed >> 15 & 0x7FFF; + return packed & 0x3fff; + } + + /** + * Gets the height level. + * + * @return The height level. + */ + public int getHeight() { + return packed >>> 28; } @Override @@ -214,7 +213,7 @@ public boolean inside(Region region) { /** * Checks if the position is within distance of another. * - * @param other The other position. + * @param other The other position. * @param distance The distance. * @return {@code true} if so, {@code false} if not. */ @@ -227,7 +226,7 @@ public boolean isWithinDistance(Position other, int distance) { /** * Creates a new position {@code num} steps from this position in the given direction. * - * @param num The number of steps to make. + * @param num The number of steps to make. * @param direction The direction to make steps in. * @return A new {@code Position} that is {@code num} steps in {@code direction} ahead of this one. */ @@ -237,6 +236,7 @@ public Position step(int num, Direction direction) { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight()).add("map", getRegionCoordinates()).toString(); + return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight()) + .add("map", getRegionCoordinates()).toString(); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index 850709b9f..ae225bf95 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -7,7 +7,7 @@ import org.apollo.cache.decoder.NpcDefinitionDecoder; import org.apollo.cache.decoder.ObjectDefinitionDecoder; import org.apollo.cache.map.MapIndexDecoder; -import org.apollo.cache.map.XteaParser; +import org.apollo.cache.map.XteaRepository; import org.apollo.game.command.CommandDispatcher; import org.apollo.game.fs.decoder.SynchronousDecoder; import org.apollo.game.fs.decoder.WorldMapDecoder; @@ -217,18 +217,20 @@ public int getReleaseNumber() { public void init(int release, Cache cache, PluginManager manager) throws Exception { releaseNumber = release; + regions.setXteaRepository(new XteaRepository(release)); + SynchronousDecoder firstStageDecoder = new SynchronousDecoder( new NpcDefinitionDecoder(cache), new ItemDefinitionDecoder(cache), new ObjectDefinitionDecoder(cache), - new MapIndexDecoder(cache, new XteaParser(release)), + new MapIndexDecoder(cache, regions.getXteaRepository()), EquipmentDefinitionParser.fromFile("data/equipment-" + release + "" + ".dat") ); firstStageDecoder.block(); SynchronousDecoder secondStageDecoder = new SynchronousDecoder( - new WorldObjectsDecoder(cache, this, regions), + new WorldObjectsDecoder(cache, this), new WorldMapDecoder(cache, collisionManager) ); diff --git a/game/src/main/java/org/apollo/game/model/area/RegionRepository.java b/game/src/main/java/org/apollo/game/model/area/RegionRepository.java index 902ffdbf8..c19b5308e 100644 --- a/game/src/main/java/org/apollo/game/model/area/RegionRepository.java +++ b/game/src/main/java/org/apollo/game/model/area/RegionRepository.java @@ -1,15 +1,15 @@ package org.apollo.game.model.area; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import org.apollo.cache.map.XteaRepository; +import org.apollo.game.model.Position; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apollo.game.model.Position; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; - /** * A repository of {@link Region}s, backed by a {@link HashMap} of {@link RegionCoordinates} that correspond to their * appropriate regions. @@ -54,6 +54,11 @@ public static RegionRepository mutable() { */ private final List defaultRegionListeners = new ArrayList<>(); + /** + * A repository of xteas. + */ + private XteaRepository xteaRepository; + /** * Creates a new RegionRepository. * @@ -169,4 +174,21 @@ public boolean remove(Region region) { return regions.remove(region.getCoordinates()) != null; } + /** + * Gets xtea repository. + * + * @return the xtea repository + */ + public XteaRepository getXteaRepository() { + return xteaRepository; + } + + /** + * Sets xtea repository. + * + * @param xteaRepository the xtea repository + */ + public void setXteaRepository(XteaRepository xteaRepository) { + this.xteaRepository = xteaRepository; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 76c06db95..0225e8614 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -1,34 +1,16 @@ package org.apollo.game.model.entity; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; - import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.game.message.impl.UpdateRunEnergyMessage; +import org.apollo.game.message.impl.*; +import org.apollo.game.message.impl.encode.ConfigMessage; +import org.apollo.game.message.impl.encode.IfOpenTopMessage; +import org.apollo.game.message.impl.encode.RebuildNormalMessage; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.WorldConstants; -import org.apollo.game.model.entity.attr.Attribute; -import org.apollo.game.model.entity.attr.AttributeDefinition; -import org.apollo.game.model.entity.attr.AttributeMap; -import org.apollo.game.model.entity.attr.AttributePersistence; -import org.apollo.game.model.entity.attr.NumericalAttribute; -import org.apollo.game.model.entity.attr.BooleanAttribute; +import org.apollo.game.model.entity.attr.*; import org.apollo.game.model.entity.obj.DynamicGameObject; import org.apollo.game.model.entity.setting.MembershipStatus; import org.apollo.game.model.entity.setting.PrivacyState; @@ -41,13 +23,8 @@ import org.apollo.game.model.inter.InterfaceSet; import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inter.bank.BankInterfaceListener; -import org.apollo.game.model.inv.AppearanceInventoryListener; -import org.apollo.game.model.inv.FullInventoryListener; -import org.apollo.game.model.inv.Inventory; +import org.apollo.game.model.inv.*; import org.apollo.game.model.inv.Inventory.StackMode; -import org.apollo.game.model.inv.InventoryConstants; -import org.apollo.game.model.inv.InventoryListener; -import org.apollo.game.model.inv.SynchronizationInventoryListener; import org.apollo.game.model.skill.LevelUpSkillListener; import org.apollo.game.model.skill.SynchronizationSkillListener; import org.apollo.game.session.GameSession; @@ -56,6 +33,9 @@ import org.apollo.util.CollectionUtil; import org.apollo.util.security.PlayerCredentials; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; + /** * A {@link Mob} that a user is controlling. * @@ -67,7 +47,12 @@ public final class Player extends Mob { /** * The default viewing distance, in tiles. */ - private static final int DEFAULT_VIEWING_DISTANCE = 15; + public static final int DEFAULT_VIEWING_DISTANCE = 15; + + /** + * The default viewing distance, in tiles. + */ + public static final int EXTENDED_VIEWING_DISTANCE = 127; /** * The current amount of appearance tickets. @@ -738,8 +723,8 @@ public void send(Message message) { * Sends the initial messages. */ public void sendInitialMessages() { - updateAppearance(); - send(new IdAssignmentMessage(index, members)); + send(new RebuildNormalMessage(position, index, world.getRegionRepository().getXteaRepository(), false)); + send(new IfOpenTopMessage(161)); sendMessage("Welcome to RuneScape."); if (isMuted()) { @@ -751,6 +736,8 @@ public void sendInitialMessages() { send(new SwitchTabInterfaceMessage(tab, tabs[tab])); } + updateAppearance(); + inventory.forceRefresh(); equipment.forceRefresh(); bank.forceRefresh(); diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 64fa22fc3..aa5ac4c9f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,6 +1,9 @@ package org.apollo.game.release.r181; -import org.apollo.game.message.impl.ConfigMessage; +import org.apollo.game.message.impl.NpcSynchronizationMessage; +import org.apollo.game.message.impl.encode.ConfigMessage; +import org.apollo.game.message.impl.encode.RebuildNormalMessage; +import org.apollo.game.message.impl.encode.IfOpenTopMessage; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.interfaces.ClosedInterfaceMessageDecoder; import org.apollo.game.release.r181.decoders.interfaces.EnteredAmountMessageDecoder; @@ -14,6 +17,9 @@ import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.RemoveIgnoreMessageDecoder; import org.apollo.game.release.r181.encoders.ConfigMessageEncoder; +import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; +import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.IfOpenTopMessageEncoder; import org.apollo.net.meta.PacketMetaDataGroup; import org.apollo.net.release.Release; @@ -137,9 +143,10 @@ private void init() { * Server */ - - + register(IfOpenTopMessage.class, new IfOpenTopMessageEncoder()); + register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); + register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java index 51c0f4075..cf4d7f0a2 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.ArrowKeyMessage; +import org.apollo.game.message.impl.decode.ArrowKeyMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java index 1182fad5d..0470915c8 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders; -import org.apollo.game.message.impl.ConfigMessage; +import org.apollo.game.message.impl.encode.ConfigMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -21,12 +21,12 @@ public GamePacket encode(ConfigMessage message) { int value = message.getValue(); if (value > Byte.MIN_VALUE && value < Byte.MAX_VALUE) { - builder = new GamePacketBuilder(4); + builder = new GamePacketBuilder(63); builder.put(DataType.BYTE, DataTransformation.ADD, value & 0xFF); builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); } else { - builder = new GamePacketBuilder(63); + builder = new GamePacketBuilder(4); builder.put(DataType.SHORT, message.getId()); builder.put(DataType.INT, value); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java new file mode 100644 index 000000000..f244a942a --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java @@ -0,0 +1,323 @@ +package org.apollo.game.release.r181.encoders.npc; + +import kotlin.UByte; +import org.apollo.game.message.impl.NpcSynchronizationMessage; +import org.apollo.game.model.Animation; +import org.apollo.game.model.Direction; +import org.apollo.game.model.Graphic; +import org.apollo.game.model.Position; +import org.apollo.game.model.entity.Player; +import org.apollo.game.sync.block.AnimationBlock; +import org.apollo.game.sync.block.ForceChatBlock; +import org.apollo.game.sync.block.GraphicBlock; +import org.apollo.game.sync.block.HitUpdateBlock; +import org.apollo.game.sync.block.InteractingMobBlock; +import org.apollo.game.sync.block.SecondaryHitUpdateBlock; +import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.sync.block.TransformBlock; +import org.apollo.game.sync.block.TurnToPositionBlock; +import org.apollo.game.sync.seg.AddNpcSegment; +import org.apollo.game.sync.seg.MovementSegment; +import org.apollo.game.sync.seg.SegmentType; +import org.apollo.game.sync.seg.SynchronizationSegment; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link NpcSynchronizationMessage}. + * + * @author Major + */ +public final class NpcSynchronizationMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(NpcSynchronizationMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(message.isViewExtended() ? 81 : 33, PacketType.VARIABLE_SHORT); + builder.switchToBitAccess(); + + GamePacketBuilder blockBuilder = new GamePacketBuilder(); + builder.putBits(8, message.getLocalNpcCount()); + + for (SynchronizationSegment segment : message.getSegments()) { + SegmentType type = segment.getType(); + if (type == SegmentType.REMOVE_MOB) { + putRemoveNpcUpdate(builder); + } else if (type == SegmentType.ADD_MOB) { + putAddNpcUpdate((AddNpcSegment) segment, message, builder); + putBlocks(segment, blockBuilder); + } else { + putMovementUpdate(segment, message, builder); + putBlocks(segment, blockBuilder); + } + } + + if (blockBuilder.getLength() > 0) { + builder.putBits(15, 0x7fff); + builder.switchToByteAccess(); + builder.putRawBuilder(blockBuilder); + } else { + builder.switchToByteAccess(); + } + + return builder.toGamePacket(); + } + + /** + * Puts an add npc update. + * + * @param seg The segment. + * @param message The message. + * @param builder The builder. + */ + private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { + boolean updateRequired = seg.getBlockSet().size() > 0; + boolean viewExtended = message.isViewExtended(); + Position npc = message.getPosition(); + Position other = seg.getPosition(); + + var dx = other.getX() - npc.getX(); + var dy = other.getY() - npc.getY(); + if (!viewExtended) { + if (dx < Player.DEFAULT_VIEWING_DISTANCE) { + dx += 32; + } + if (dy < Player.DEFAULT_VIEWING_DISTANCE) { + dy += 32; + } + } else { + if (dx < Player.EXTENDED_VIEWING_DISTANCE) { + dx += 256; + } + if (dy < Player.EXTENDED_VIEWING_DISTANCE) { + dy += 256; + } + } + + builder.putBits(15, seg.getIndex()); + builder.putBits(viewExtended ? 8 : 5, dx); + builder.putBits(1, 0); // discard walking queue + builder.putBits(3, seg.getDirection().toInteger()); + builder.putBits(1, updateRequired ? 1 : 0); + builder.putBits(viewExtended ? 8 : 5, dy); + builder.putBits(14, seg.getNpcId()); + } + + /** + * Puts an animation block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { + Animation animation = block.getAnimation(); + builder.put(DataType.SHORT, animation.getId()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, animation.getDelay()); + } + + /** + * Puts the blocks for the specified segment. + * + * @param segment The segment. + * @param builder The block builder. + */ + private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { + SynchronizationBlockSet blockSet = segment.getBlockSet(); + if (blockSet.size() > 0) { + int mask = 0; + + /*if (blockSet.contains(TransformBlock.class)) { + mask |= 0x1; + } + + if (blockSet.contains(InteractingMobBlock.class)) { + mask |= 0x40; + } + + if (blockSet.contains(HitUpdateBlock.class)) { + mask |= 0x80; + } + + if (blockSet.contains(GraphicBlock.class)) { + mask |= 0x4; + } + + if (blockSet.contains(ForceChatBlock.class)) { + mask |= 0x20; + } + + if (blockSet.contains(TurnToPositionBlock.class)) { + mask |= 0x8; + } + + if (blockSet.contains(AnimationBlock.class)) { + mask |= 0x2; + } + + if (blockSet.contains(SecondaryHitUpdateBlock.class)) { + mask |= 0x10; + }*/ + + builder.put(DataType.BYTE, mask); + + /*if (blockSet.contains(TransformBlock.class)) { + putTransformBlock(blockSet.get(TransformBlock.class), builder); + } + + if (blockSet.contains(InteractingMobBlock.class)) { + putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); + } + + if (blockSet.contains(HitUpdateBlock.class)) { + putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); + } + + if (blockSet.contains(GraphicBlock.class)) { + putGraphicBlock(blockSet.get(GraphicBlock.class), builder); + } + + if (blockSet.contains(ForceChatBlock.class)) { + putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); + } + + if (blockSet.contains(TurnToPositionBlock.class)) { + putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); + } + + if (blockSet.contains(AnimationBlock.class)) { + putAnimationBlock(blockSet.get(AnimationBlock.class), builder); + } + + if (blockSet.contains(SecondaryHitUpdateBlock.class)) { + putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); + }*/ + } + } + + /** + * Puts a force chat block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { + builder.putString(block.getMessage()); + } + + /** + * Puts a graphic block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { + Graphic graphic = block.getGraphic(); + builder.put(DataType.SHORT, graphic.getId()); + builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF); + } + + /** + * Puts a hit update block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); + builder.put(DataType.BYTE, DataTransformation.ADD, block.getType()); + builder.put(DataType.BYTE, block.getCurrentHealth()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getMaximumHealth()); + } + + /** + * Puts an interacting mob block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { + builder.put(DataType.SHORT, DataOrder.LITTLE, block.getIndex()); + } + + /** + * Puts a movement update for the specified segment. + * + * @param seg The segment. + * @param message The message. + * @param builder The builder. + */ + private static void putMovementUpdate(SynchronizationSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { + boolean updateRequired = seg.getBlockSet().size() > 0; + if (seg.getType() == SegmentType.RUN) { + Direction[] directions = ((MovementSegment) seg).getDirections(); + builder.putBits(1, 1); + builder.putBits(2, 2); + builder.putBits(3, directions[0].toInteger()); + builder.putBits(3, directions[1].toInteger()); + builder.putBits(1, updateRequired ? 1 : 0); + } else if (seg.getType() == SegmentType.WALK) { + Direction[] directions = ((MovementSegment) seg).getDirections(); + builder.putBits(1, 1); + builder.putBits(2, 1); + builder.putBits(3, directions[0].toInteger()); + builder.putBits(1, updateRequired ? 1 : 0); + } else { + if (updateRequired) { + builder.putBits(1, 1); + builder.putBits(2, 0); + } else { + builder.putBits(1, 0); + } + } + } + + /** + * Puts a remove mob update. + * + * @param builder The builder. + */ + private static void putRemoveNpcUpdate(GamePacketBuilder builder) { + builder.putBits(1, 1); + builder.putBits(2, 3); + } + + /** + * Puts a second hit update block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); + builder.put(DataType.BYTE, block.getCurrentHealth()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getMaximumHealth()); + } + + /** + * Puts a transform block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putTransformBlock(TransformBlock block, GamePacketBuilder builder) { + builder.put(DataType.SHORT, DataTransformation.ADD, block.getId()); + } + + /** + * Puts a turn to position block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { + Position position = block.getPosition(); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, position.getX() * 2 + 1); + builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java new file mode 100644 index 000000000..622e87c76 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java @@ -0,0 +1,63 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.RebuildNormalMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link RebuildNormalMessage}. + * + * @author Graham + */ +public final class RebuildNormalMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(RebuildNormalMessage message) { + final var builder = new GamePacketBuilder(0, PacketType.VARIABLE_SHORT); + final var position = message.getPosition(); + // TODO the player shit here. + + if (!message.isHasLastKnownRegion()) { + builder.switchToBitAccess(); + builder.putBits(30, position.hashCode()); + for (int index = 1; index < 2048; index++) { + if (index == message.getIndex()) { + continue; + } + builder.putBits(18, 0); + } + builder.switchToByteAccess(); + } + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, + message.getPosition().getCentralRegionY()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralRegionX()); + + boolean force = true; + int centralMapX = position.getCentralRegionX() / 8; + int centralMapY = position.getCentralRegionY() / 8; + + if ((centralMapX == 48 || centralMapX == 49) && centralMapY == 48) force = false; + + if (centralMapX == 48 && centralMapY == 148) force = false; + + GamePacketBuilder map = new GamePacketBuilder(); + for (int mapX = ((position.getCentralRegionX() - 6) / 8); mapX <= ((position + .getCentralRegionX() + 6) / 8); mapX++) { + for (int mapY = ((position.getCentralRegionY() - 6) / 8); mapY <= ((position + .getCentralRegionY() + 6) / 8); mapY++) { + if (force || (mapY != 49 && mapY != 149 && mapY != 147 && mapX != 50 && (mapX != 49 || mapY != 47))) { + int[] keys = message.getRepository().get(mapX, mapY); + for (int i = 0; i < 4; i++) + map.put(DataType.INT, keys[i]); + } + } + } + + builder.put(DataType.SHORT, map.getLength() / Integer.BYTES); + builder.putBytes(map); + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenTopMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenTopMessageEncoder.java new file mode 100644 index 000000000..94b2fe6fb --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenTopMessageEncoder.java @@ -0,0 +1,15 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfOpenTopMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class IfOpenTopMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfOpenTopMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(84, PacketType.FIXED); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/service/GameService.java b/game/src/main/java/org/apollo/game/service/GameService.java index 0b393c6f4..14e2f925c 100644 --- a/game/src/main/java/org/apollo/game/service/GameService.java +++ b/game/src/main/java/org/apollo/game/service/GameService.java @@ -123,10 +123,6 @@ public synchronized void finalizePlayerRegistration(Player player) { world.register(player); Region region = world.getRegionRepository().fromPosition(player.getPosition()); region.addEntity(player); - - if (!player.getSession().isReconnecting()) { - player.sendInitialMessages(); - } } /** @@ -218,8 +214,11 @@ private void finalizeRegistrations() { } else if (world.getPlayerRepository().full()) { request.session.sendLoginFailure(LoginConstants.STATUS_SERVER_FULL); } else { - request.session.sendLoginSuccess(player); finalizePlayerRegistration(player); + request.session.sendLoginSuccess(player); + if (!player.getSession().isReconnecting()) { + player.sendInitialMessages(); + } } } } diff --git a/game/src/main/java/org/apollo/game/session/LoginSession.java b/game/src/main/java/org/apollo/game/session/LoginSession.java index f454abcac..710917064 100644 --- a/game/src/main/java/org/apollo/game/session/LoginSession.java +++ b/game/src/main/java/org/apollo/game/session/LoginSession.java @@ -119,8 +119,18 @@ public void sendLoginSuccess(Player player) { channel.attr(ApolloHandler.SESSION_KEY).set(session); player.setSession(session); - int rights = player.getPrivilegeLevel().toInteger(); - channel.writeAndFlush(new LoginResponse(LoginConstants.STATUS_OK, session.getChannel().alloc().buffer())); + final var payload = channel.alloc() + .buffer(Byte.BYTES * 2 + Integer.BYTES + Byte.BYTES * 2 + Short.BYTES + Byte.BYTES); + payload.writeByte(13); + + boolean isTrusted = false; + payload.writeBoolean(isTrusted); // If 2FA is enabled + payload.writeInt(isTrusted ? randomPair.getEncodingRandom().nextInt() : 0); + payload.writeByte(player.getPrivilegeLevel().toInteger()); + payload.writeBoolean(player.isMembers()); + payload.writeShort(player.getIndex()); + payload.writeBoolean(flagged); // flagged + channel.writeAndFlush(new LoginResponse(LoginConstants.STATUS_OK, payload)); Release release = context.getRelease(); diff --git a/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java b/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java index 196ba2b9d..298f79a16 100644 --- a/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java +++ b/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java @@ -1,5 +1,6 @@ package org.apollo.game.sync.seg; +import org.apollo.game.model.Direction; import org.apollo.game.model.Position; import org.apollo.game.sync.block.SynchronizationBlockSet; @@ -25,6 +26,11 @@ public final class AddNpcSegment extends SynchronizationSegment { */ private final Position position; + /** + * The direction. + */ + private final Direction direction; + /** * Creates the add npc segment. * @@ -32,12 +38,14 @@ public final class AddNpcSegment extends SynchronizationSegment { * @param index The npcs's index. * @param position The position. * @param npcId The id of the npc. + * @param direction The direction of the npc. */ - public AddNpcSegment(SynchronizationBlockSet blockSet, int index, Position position, int npcId) { + public AddNpcSegment(SynchronizationBlockSet blockSet, int index, Position position, int npcId, Direction direction) { super(blockSet); this.index = index; this.position = position; this.npcId = npcId; + this.direction = direction; } /** @@ -67,9 +75,20 @@ public Position getPosition() { return position; } + + /** + * Gets direction. + * + * @return the direction + */ + public Direction getDirection() { + return direction; + } + @Override public SegmentType getType() { return SegmentType.ADD_MOB; } + } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java index af06040c5..3448bb284 100644 --- a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java @@ -103,11 +103,11 @@ public void run() { added++; npc.turnTo(npc.getFacingPosition()); - segments.add(new AddNpcSegment(npc.getBlockSet(), npc.getIndex(), position, npc.getId())); + segments.add(new AddNpcSegment(npc.getBlockSet(), npc.getIndex(), position, npc.getId(), npc.getLastDirection())); } } - player.send(new NpcSynchronizationMessage(playerPosition, segments, originalCount)); + player.send(new NpcSynchronizationMessage(playerPosition, segments, originalCount, player.getViewingDistance() > Player.DEFAULT_VIEWING_DISTANCE)); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 33d1c7af7..59c09be26 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -6,7 +6,7 @@ import org.apollo.game.message.impl.ClearRegionMessage; import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.RegionChangeMessage; +import org.apollo.game.message.impl.encode.RebuildNormalMessage; import org.apollo.game.message.impl.RegionUpdateMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; @@ -72,7 +72,7 @@ public void run() { local = false; player.setLastKnownRegion(position); - player.send(new RegionChangeMessage(position)); + player.send(new RebuildNormalMessage(position, player.getIndex(), player.getWorld().getRegionRepository().getXteaRepository(), true)); } RegionRepository repository = player.getWorld().getRegionRepository(); diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java index 206e79212..0b1e1f0db 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java @@ -279,6 +279,16 @@ public void putBytes(ByteBuf buffer) { putBytes(bytes); } + /** + * Puts the bytes from the specified buffer into this packet's buffer. + * + * @param buffer The source {@link ByteBuf}. + */ + public void putBytes(GamePacketBuilder buffer) { + putBytes(buffer.buffer); + } + + /** * Puts the bytes into the buffer with the specified transformation. * diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java index 84a8fcbe5..000f06131 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java @@ -115,6 +115,7 @@ private void decodeOpcode(ByteBuf buffer, List out) { } break; case VARIABLE_BYTE: + case VARIABLE_SHORT: setState(GameDecoderState.GAME_LENGTH); break; default: From 3ef4250ca8eac319714daf9a6dbc334858acff79 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 14 Mar 2020 23:48:49 -0400 Subject: [PATCH 17/63] InterfaceSet.java is updated to support osrs functionality. EnumDefinition.java support for OSRS Enums. DisplayStatusMessage has been supported (The ability to switch the display mode). --- .../decoder/rsenum/EnumDefinitionDecoder.java | 83 +++++++++ .../cache/decoder/rsenum/ScriptVarType.java | 99 +++++++++++ .../org/apollo/cache/def/EnumDefinition.java | 141 ++++++++++++++++ game/build.gradle | 1 + game/data/messages.xml | 6 + .../game/plugin/shops/OpenShopAction.kt | 5 +- .../handler/DialogueButtonHandler.java | 4 +- .../DialogueContinueMessageHandler.java | 4 +- .../handler/DisplayStatusMessageDecoder.java | 21 +++ .../message/impl/OpenInterfaceMessage.java | 35 ---- .../game/message/impl/ServerChatMessage.java | 82 +++++++-- .../impl/decode/DisplayStatusMessage.java | 28 ++++ .../message/impl/encode/IfMoveSubMessage.java | 22 +++ .../message/impl/encode/IfOpenSubMessage.java | 67 ++++++++ .../java/org/apollo/game/model/World.java | 2 + .../org/apollo/game/model/entity/Player.java | 27 +-- .../game/model/inter/ClientInterfaceType.java | 5 + .../apollo/game/model/inter/DisplayMode.java | 25 +++ .../game/model/inter/InterfaceEvent.java | 158 ++++++++++++++++++ .../apollo/game/model/inter/InterfaceSet.java | 142 +++++++--------- .../game/model/inter/InterfaceType.java | 41 ----- .../game/model/inter/ServerInterfaceType.java | 22 +++ .../game/model/inter/TopLevelPosition.java | 49 ++++++ .../apollo/game/release/r181/Release181.java | 23 ++- .../DisplayStatusMessageDecoder.java | 19 +++ .../game/ServerChatMessageEncoder.java | 26 +++ .../{ => ui}/ConfigMessageEncoder.java | 2 +- .../encoders/ui/IfMoveSubMessageEncoder.java | 17 ++ .../encoders/ui/IfOpenSubMessageEncoder.java | 18 ++ .../org/apollo/game/service/GameService.java | 33 ++-- .../org/apollo/game/session/LoginSession.java | 4 + .../apollo/net/codec/login/LoginDecoder.java | 4 +- .../apollo/net/codec/login/LoginRequest.java | 11 +- 33 files changed, 1013 insertions(+), 213 deletions(-) create mode 100644 cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java create mode 100644 cache/src/main/java/org/apollo/cache/decoder/rsenum/ScriptVarType.java create mode 100644 cache/src/main/java/org/apollo/cache/def/EnumDefinition.java create mode 100644 game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageDecoder.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/OpenInterfaceMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/decode/DisplayStatusMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java create mode 100644 game/src/main/java/org/apollo/game/model/inter/ClientInterfaceType.java create mode 100644 game/src/main/java/org/apollo/game/model/inter/DisplayMode.java create mode 100644 game/src/main/java/org/apollo/game/model/inter/InterfaceEvent.java delete mode 100644 game/src/main/java/org/apollo/game/model/inter/InterfaceType.java create mode 100644 game/src/main/java/org/apollo/game/model/inter/ServerInterfaceType.java create mode 100644 game/src/main/java/org/apollo/game/model/inter/TopLevelPosition.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/DisplayStatusMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java rename game/src/main/java/org/apollo/game/release/r181/encoders/{ => ui}/ConfigMessageEncoder.java (95%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java diff --git a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java new file mode 100644 index 000000000..2345d50ed --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java @@ -0,0 +1,83 @@ +package org.apollo.cache.decoder.rsenum; + +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import org.apollo.cache.Archive; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.RSFile; +import org.apollo.cache.def.EnumDefinition; + +/** + * Decodes item data from the {@code obj.dat} file into {@link EnumDefinition}s. + * + * @author Graham + */ +public final class EnumDefinitionDecoder implements Runnable { + + /** + * The IndexedFileSystem. + */ + private final Cache cache; + + /** + * Creates the EnumDefinitionDecoder. + * + * @param cache The {@link Archive}. + */ + public EnumDefinitionDecoder(Cache cache) { + this.cache = cache; + } + + @Override + public void run() { + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(8); + + EnumDefinition[] definitions = new EnumDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); + } + + EnumDefinition.init(definitions); + } + + /** + * Decodes a single definition. + * + * @param id The item's id. + * @param buffer The buffer. + * @return The {@link EnumDefinition}. + */ + private EnumDefinition decode(int id, CacheBuffer buffer) { + EnumDefinition def = new EnumDefinition(id); + for (; ; ) { + int opcode = buffer.readUByte(); + if (opcode == 0) { + return def; + } else if (opcode == 1) { + def.setKeyType(ScriptVarType.forCharKey((char) buffer.readUByte())); + } else if (opcode == 2) { + def.setValType(ScriptVarType.forCharKey((char) buffer.readUByte())); + } else if (opcode == 3) { + def.setDefaultString(buffer.readString()); + } else if (opcode == 4) { + def.setDefaultInt(buffer.readInt()); + } else if (opcode == 5) { + final var size = buffer.readUShort(); + final var values = new Int2ObjectOpenHashMap(size); + for (int index = 0; index < size; index++) { + values.put(buffer.readInt(), buffer.readString()); + } + def.setStringValues(values); + } else if (opcode == 6) { + final var size = buffer.readUShort(); + final var values = new Int2IntOpenHashMap(size); + for (int index = 0; index < size; index++) { + values.put(buffer.readInt(), buffer.readInt()); + } + def.setIntValues(values); + } + } + } +} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/decoder/rsenum/ScriptVarType.java b/cache/src/main/java/org/apollo/cache/decoder/rsenum/ScriptVarType.java new file mode 100644 index 000000000..7e4668b7d --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/decoder/rsenum/ScriptVarType.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2018, Joshua Filby + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.apollo.cache.decoder.rsenum; + +import java.util.HashMap; +import java.util.Map; + +public enum ScriptVarType +{ + INTEGER('i', "integer"), + BOOLEAN('1', "boolean"), + SEQ('A', "seq"), + COLOUR('C', "colour"), + /** + * Also known as {@code Widget}. + */ + COMPONENT('I', "component"), + IDKIT('K', "idkit"), + MIDI('M', "midi"), + SYNTH('P', "synth"), + STAT('S', "stat"), + COORDGRID('c', "coordgrid"), + GRAPHIC('d', "graphic"), + FONTMETRICS('f', "fontmetrics"), + ENUM('g', "enum"), + JINGLE('j', "jingle"), + /** + * Also known as {@code Object}. + */ + LOC('l', "loc"), + MODEL('m', "model"), + NPC('n', "npc"), + /** + * Also known as {@code Item}. + */ + OBJ('o', "obj"), + /** + * Another version of {@code OBJ}, but means that on Jagex's side they used the internal name for an item. + */ + NAMEDOBJ('O', "namedobj"), + STRING('s', "string"), + SPOTANIM('t', "spotanim"), + INV('v', "inv"), + TEXTURE('x', "texture"), + CHAR('z', "char"), + MAPSCENEICON('£', "mapsceneicon"), + MAPELEMENT('µ', "mapelement"), + HITMARK('×', "hitmark"), + STRUCT('J', "struct"); + + private static final Map keyToTypeMap = new HashMap<>(); + + static { + for (ScriptVarType type : values()) { + keyToTypeMap.put(type.keyChar, type); + } + } + + public static ScriptVarType forCharKey(char key) { + return keyToTypeMap.get(key); + } + + /** + * The character used when encoding or decoding types. + */ + private final char keyChar; + + /** + * The full name of the var type. + */ + private final String fullName; + + ScriptVarType(char keyChar, String fullName) { + this.keyChar = keyChar; + this.fullName = fullName; + } +} diff --git a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java new file mode 100644 index 000000000..ea5ccba49 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java @@ -0,0 +1,141 @@ +package org.apollo.cache.def; + +import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import org.apollo.cache.decoder.rsenum.ScriptVarType; + +import java.util.HashMap; +import java.util.Map; + +public final class EnumDefinition { + + private static final Map definitions = new HashMap<>(); + + /** + * Gets the total number of enum definitions. + * + * @return The count. + */ + public static int count() { + return definitions.size(); + } + + /** + * Initialises the enum definitions. + * + * @param definitions The definitions. + * @throws RuntimeException If there is an id mismatch. + */ + public static void init(EnumDefinition[] definitions) { + for (int id = 0; id < definitions.length; id++) { + EnumDefinition def = definitions[id]; + if (def != null) { + if (def.getId() != id) { + throw new RuntimeException("Equipment definition id mismatch."); + } + EnumDefinition.definitions.put(def.getId(), def); + } + } + } + + /** + * Gets an enum definition by its id. + * + * @param id The id. + * @return {@code null} if the item is not enum, the definition otherwise. + * @throws IndexOutOfBoundsException If the id is out of bounds. + */ + public static EnumDefinition lookup(int id) { + Preconditions.checkElementIndex(id, EnumDefinition.count(), "Id out of bounds."); + return definitions.get(id); + } + + /** + * The enum id. + */ + private final int id; + + private ScriptVarType keyType = ScriptVarType.INTEGER; + private ScriptVarType valType = ScriptVarType.INTEGER; + private int defaultInt = 0; + private String defaultString = ""; + private Int2IntOpenHashMap intValues; + private Int2ObjectOpenHashMap stringValues; + + /** + * Creates a new enum definition. + * + * @param id The id. + */ + public EnumDefinition(int id) { + this.id = id; + } + + public int lookup(int id, int defaultInt) { + if (intValues == null) { + return id; + } + return intValues.getOrDefault(id, id); + } + + public String lookup(int id, String defaultString) { + if (stringValues == null) { + return defaultString; + } + return stringValues.getOrDefault(id, defaultString); + } + + public int getId() { + return id; + } + + public ScriptVarType getKeyType() { + return keyType; + } + + public void setKeyType(ScriptVarType keyType) { + this.keyType = keyType; + } + + public ScriptVarType getValType() { + return valType; + } + + public void setValType(ScriptVarType valType) { + this.valType = valType; + } + + public int getDefaultInt() { + return defaultInt; + } + + public void setDefaultInt(int defaultInt) { + this.defaultInt = defaultInt; + } + + public String getDefaultString() { + return defaultString; + } + + public void setDefaultString(String defaultString) { + this.defaultString = defaultString; + } + + public Int2IntOpenHashMap getIntValues() { + return intValues; + } + + public void setIntValues(Int2IntOpenHashMap intValues) { + this.intValues = intValues; + } + + public Int2ObjectOpenHashMap getStringValues() { + return stringValues; + } + + public void setStringValues(Int2ObjectOpenHashMap stringValues) { + this.stringValues = stringValues; + } +} + diff --git a/game/build.gradle b/game/build.gradle index 1a451eb99..87dcf5253 100644 --- a/game/build.gradle +++ b/game/build.gradle @@ -19,6 +19,7 @@ dependencies { implementation group: 'com.google.guava', name: 'guava', version: guavaVersion implementation group: 'io.github.classgraph', name: 'classgraph', version: classGraphVersion implementation group: 'com.lambdaworks', name: 'scrypt', version: scryptVersion + implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.1' test.useJUnitPlatform() testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion diff --git a/game/data/messages.xml b/game/data/messages.xml index f4a5bec2e..e3b8628e8 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -6,6 +6,12 @@ org.apollo.game.message.handler.BankButtonMessageHandler + + org.apollo.game.message.impl.decode.DisplayStatusMessage + + org.apollo.game.message.handler.DisplayStatusMessageDecoder + + org.apollo.game.message.impl.PublicChatMessage diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt b/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt index a87a31256..6718cdcab 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt @@ -6,6 +6,7 @@ import org.apollo.game.message.impl.SetWidgetTextMessage import org.apollo.game.model.entity.Mob import org.apollo.game.model.entity.Player import org.apollo.game.model.inter.InterfaceListener +import org.apollo.game.model.inter.TopLevelPosition import org.apollo.game.model.inv.Inventory import org.apollo.game.model.inv.SynchronizationInventoryListener @@ -24,8 +25,8 @@ class OpenShopAction( val closeListener = addInventoryListeners(mob, shop.inventory) mob.send(SetWidgetTextMessage(ShopInterfaces.SHOP_NAME, shop.name)) - mob.interfaceSet.openWindowWithSidebar(closeListener, ShopInterfaces.SHOP_WINDOW, - ShopInterfaces.INVENTORY_SIDEBAR) + mob.interfaceSet.openModal(closeListener, ShopInterfaces.SHOP_WINDOW); + mob.interfaceSet.openTopLevel(ShopInterfaces.INVENTORY_SIDEBAR, TopLevelPosition.INVENTORY_TAB) stop() } diff --git a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java index 8dcfaeea7..fc6be4342 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java @@ -3,7 +3,7 @@ import org.apollo.game.message.impl.ButtonMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; -import org.apollo.game.model.inter.InterfaceType; +import org.apollo.game.model.inter.ServerInterfaceType; /** * A {@link MessageHandler} which intercepts button clicks on dialogues, and forwards the message to the current @@ -24,7 +24,7 @@ public DialogueButtonHandler(World world) { @Override public void handle(Player player, ButtonMessage message) { - if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) { + if (player.getInterfaceSet().contains(ServerInterfaceType.DIALOGUE)) { boolean terminate = player.getInterfaceSet().buttonClicked(message.getWidgetId()); if (terminate) { diff --git a/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java index af5b952b8..896aa297d 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java @@ -3,7 +3,7 @@ import org.apollo.game.message.impl.DialogueContinueMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; -import org.apollo.game.model.inter.InterfaceType; +import org.apollo.game.model.inter.ServerInterfaceType; /** * A {@link MessageHandler} for the {@link DialogueContinueMessage}. @@ -23,7 +23,7 @@ public DialogueContinueMessageHandler(World world) { @Override public void handle(Player player, DialogueContinueMessage message) { - if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) { + if (player.getInterfaceSet().contains(ServerInterfaceType.DIALOGUE)) { player.getInterfaceSet().continueRequested(); } } diff --git a/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageDecoder.java b/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageDecoder.java new file mode 100644 index 000000000..725da45a2 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.message.handler; + +import org.apollo.game.message.impl.decode.DisplayStatusMessage; +import org.apollo.game.model.World; +import org.apollo.game.model.entity.Player; + +public class DisplayStatusMessageDecoder extends MessageHandler { + /** + * Creates the MessageListener. + * + * @param world The {@link World} the {@link DisplayStatusMessage} occurred in. + */ + public DisplayStatusMessageDecoder(World world) { + super(world); + } + + @Override + public void handle(Player player, DisplayStatusMessage message) { + player.getInterfaceSet().openTop(message.getMode()); + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceMessage.java deleted file mode 100644 index b12f304c5..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that opens an interface. - * - * @author Graham - */ -public final class OpenInterfaceMessage extends Message { - - /** - * The interface id. - */ - private final int id; - - /** - * Creates the message with the specified interface id. - * - * @param id The interface id. - */ - public OpenInterfaceMessage(int id) { - this.id = id; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getId() { - return id; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java index ab8996021..993a47e6a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import com.google.common.base.Strings; import org.apollo.net.message.Message; /** @@ -9,27 +10,86 @@ */ public final class ServerChatMessage extends Message { + public enum ChatType { + GAME_MESSAGE(0, false), + MOD_CHAT(1, false), + PUBLIC_CHAT(2, false), + PRIVATE_CHAT(3, false), + ENGINE(4, false), + LOGIN_LOGOUT_NOTIFICATION(5, false), + PRIVATE_CHAT_OUT(6, false), + MOD_PRIVATE_CHAT(7, false), + FRIENDS_CHAT(9, false), + FRIENDS_CHAT_NOTIFICATION(11, false), + BROADCAST(14, false), + SNAPSHOT_FEEDBACK(26, false), + ITEM_EXAMINE(27, false), + NPC_EXAMINE(28, false), + LOC_EXAMINE(29, false), + FRIEND_NOTIFICATION(30, false), + IGNORE_NOTIFICATION(31, false), + AUTO_TYPER(90, false), + MOD_AUTO_TYPER(91, false), + CONSOLE(99, false), + TRADE_REQ(101, true), + TRADE(102, false), + CHAL_REQ_TRADE(103, true), + CHAL_REQ_FRIENDS_CHAT(104, false), + SPAM(105, false), + PLAYER_RELATED(106, false), + TEN_SECOND_TIMOUT(107, false), + ; + + private final int id; + private final boolean extensionAvailable; + + ChatType(int id, boolean extensionAvailable) { + this.id = id; + this.extensionAvailable = extensionAvailable; + } + + public int getId() { + return id; + } + + public boolean isExtensionAvailable() { + return extensionAvailable; + } + } + /** * The message to send. */ private final String message; + private final ChatType type; + private final String extension; - /** - * Creates the ServerChatMessage. - * - * @param message The chat message to send. - */ - public ServerChatMessage(String message) { + public ServerChatMessage(String message, ChatType type, String extension) { + if (!type.isExtensionAvailable() && !extension.isEmpty()) { + throw new IllegalArgumentException("Type of " + type + " cannot contain an extension."); + } this.message = message; + this.type = type; + this.extension = Strings.nullToEmpty(extension); + } + + public ServerChatMessage(String message, ChatType type) { + this(message, type, ""); + } + + public ServerChatMessage(String message) { + this(message, ChatType.GAME_MESSAGE); } - /** - * Gets the chat message to send. - * - * @return The chat message. - */ public String getMessage() { return message; } + public ChatType getType() { + return type; + } + + public String getExtension() { + return extension; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/DisplayStatusMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/DisplayStatusMessage.java new file mode 100644 index 000000000..a704d4664 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/DisplayStatusMessage.java @@ -0,0 +1,28 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.game.model.inter.DisplayMode; +import org.apollo.net.message.Message; + +public class DisplayStatusMessage extends Message { + + private final DisplayMode mode; + private final int height, width; + + public DisplayStatusMessage(DisplayMode mode, int height, int width) { + this.mode = mode; + this.height = height; + this.width = width; + } + + public DisplayMode getMode() { + return mode; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java new file mode 100644 index 000000000..1e0967e83 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java @@ -0,0 +1,22 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +public class IfMoveSubMessage extends Message { + + private final int fromComponent; + private final int toComponent; + + public IfMoveSubMessage(int fromComponent, int toComponent) { + this.fromComponent = fromComponent; + this.toComponent = toComponent; + } + + public int getFromComponent() { + return fromComponent; + } + + public int getToComponent() { + return toComponent; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java new file mode 100644 index 000000000..19c6fc9fd --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java @@ -0,0 +1,67 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.inter.ClientInterfaceType; +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client that opens an interface. + * + * @author Graham + */ +public final class IfOpenSubMessage extends Message { + + /** + * The parent interface. + */ + private final int parentComponent; + + /** + * The type of the interface. + */ + private final ClientInterfaceType type; + + /** + * The interface id. + */ + private final int id; + + /** + * Creates the message with the specified interface id. + * + * @param parentComponent the parent component + * @param type the type + * @param id the id + */ + public IfOpenSubMessage(int parentComponent, ClientInterfaceType type, int id) { + this.parentComponent = parentComponent; + this.type = type; + this.id = id; + } + + /** + * Gets the interface id. + * + * @return The interface id. + */ + public int getId() { + return id; + } + + /** + * Gets parent component. + * + * @return the parent component + */ + public int getParentComponent() { + return parentComponent; + } + + /** + * Gets type. + * + * @return the type + */ + public ClientInterfaceType getType() { + return type; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index ae225bf95..955daed7b 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -6,6 +6,7 @@ import org.apollo.cache.decoder.ItemDefinitionDecoder; import org.apollo.cache.decoder.NpcDefinitionDecoder; import org.apollo.cache.decoder.ObjectDefinitionDecoder; +import org.apollo.cache.decoder.rsenum.EnumDefinitionDecoder; import org.apollo.cache.map.MapIndexDecoder; import org.apollo.cache.map.XteaRepository; import org.apollo.game.command.CommandDispatcher; @@ -222,6 +223,7 @@ public void init(int release, Cache cache, PluginManager manager) throws Excepti SynchronousDecoder firstStageDecoder = new SynchronousDecoder( new NpcDefinitionDecoder(cache), new ItemDefinitionDecoder(cache), + new EnumDefinitionDecoder(cache), new ObjectDefinitionDecoder(cache), new MapIndexDecoder(cache, regions.getXteaRepository()), EquipmentDefinitionParser.fromFile("data/equipment-" + release + "" + ".dat") diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 0225e8614..2948e295c 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -18,9 +18,7 @@ import org.apollo.game.model.entity.setting.ScreenBrightness; import org.apollo.game.model.event.impl.LoginEvent; import org.apollo.game.model.event.impl.LogoutEvent; -import org.apollo.game.model.inter.InterfaceConstants; -import org.apollo.game.model.inter.InterfaceListener; -import org.apollo.game.model.inter.InterfaceSet; +import org.apollo.game.model.inter.*; import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inter.bank.BankInterfaceListener; import org.apollo.game.model.inv.*; @@ -651,7 +649,8 @@ public void openBank() { bank.forceRefresh(); InterfaceListener interListener = new BankInterfaceListener(this, invListener, bankListener); - interfaceSet.openWindowWithSidebar(interListener, BankConstants.BANK_WINDOW_ID, BankConstants.SIDEBAR_ID); + interfaceSet.openModal(interListener, BankConstants.BANK_WINDOW_ID); + interfaceSet.openTopLevel(BankConstants.SIDEBAR_INVENTORY_ID, TopLevelPosition.INVENTORY_TAB); } /** @@ -722,18 +721,20 @@ public void send(Message message) { /** * Sends the initial messages. */ - public void sendInitialMessages() { + public void sendInitialMessages(DisplayMode mode) { send(new RebuildNormalMessage(position, index, world.getRegionRepository().getXteaRepository(), false)); - send(new IfOpenTopMessage(161)); - sendMessage("Welcome to RuneScape."); - if (isMuted()) { - sendMessage("You are currently muted. Other players will not see your chat messages."); + interfaceSet.openTop(mode); + for (TopLevelPosition position : TopLevelPosition.values()) { + if (position.getInterfaceId() == -1) { + continue; + } + interfaceSet.openTopLevel(position); } - int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS; - for (int tab = 0; tab < tabs.length; tab++) { - send(new SwitchTabInterfaceMessage(tab, tabs[tab])); + sendMessage("Welcome to RuneScape."); + if (isMuted()) { + sendMessage("You are currently muted. Other players will not see your chat messages."); } updateAppearance(); @@ -767,7 +768,7 @@ public void sendQuestInterface(List text) { for (int pos = 0; pos < lines; pos++) { send(new SetWidgetTextMessage(InterfaceConstants.QUEST_TEXT[pos], pos < size ? text.get(pos) : "")); } - interfaceSet.openWindow(InterfaceConstants.QUEST_INTERFACE); + interfaceSet.openModal(InterfaceConstants.QUEST_INTERFACE); } /** diff --git a/game/src/main/java/org/apollo/game/model/inter/ClientInterfaceType.java b/game/src/main/java/org/apollo/game/model/inter/ClientInterfaceType.java new file mode 100644 index 000000000..f2d7fb0c8 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/ClientInterfaceType.java @@ -0,0 +1,5 @@ +package org.apollo.game.model.inter; + +public enum ClientInterfaceType { + MODAL, OVERLAY +} diff --git a/game/src/main/java/org/apollo/game/model/inter/DisplayMode.java b/game/src/main/java/org/apollo/game/model/inter/DisplayMode.java new file mode 100644 index 000000000..b22471486 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/DisplayMode.java @@ -0,0 +1,25 @@ +package org.apollo.game.model.inter; + +public enum DisplayMode { + FIXED(548, 1129), + RESIZABLE(161, 1130), + SIDE_PANELS(164, 1131), + FULL_SCREEN(165, 1132), + MOBILE(601, 1745); + + private final int interfaceId; + private final int topLevelEnum; + + DisplayMode(int interfaceId, int topLevelEnum) { + this.interfaceId = interfaceId; + this.topLevelEnum = topLevelEnum; + } + + public int getInterfaceId() { + return interfaceId; + } + + public int getTopLevelEnum() { + return topLevelEnum; + } +} diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceEvent.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceEvent.java new file mode 100644 index 000000000..44022b28e --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceEvent.java @@ -0,0 +1,158 @@ +package org.apollo.game.model.inter; + +/** + * A class of possible events to enable on dynamic interface components. + * @author Joshua Filby + */ +@SuppressWarnings("PointlessBitwiseExpression") +public enum InterfaceEvent { + + /** + * Marks the component as a pause button. + */ + PAUSEBUTTON(1 << 0), + + /** + * Enables op1 on the component. + */ + IF_BUTTON1(1 << 1), + + /** + * Enables op2 on the component. + */ + IF_BUTTON2(1 << 2), + + /** + * Enables op3 on the component. + */ + IF_BUTTON3(1 << 3), + + /** + * Enables op4 on the component. + */ + IF_BUTTON4(1 << 4), + + /** + * Enables op5 on the component. + */ + IF_BUTTON5(1 << 5), + + /** + * Enables op6 on the component. + */ + IF_BUTTON6(1 << 6), + + /** + * Enables op7 on the component. + */ + IF_BUTTON7(1 << 7), + + /** + * Enables op8 on the component. + */ + IF_BUTTON8(1 << 8), + + /** + * Enables op9 on the component. + */ + IF_BUTTON9(1 << 9), + + /** + * Enables op10 on the component. + */ + IF_BUTTON10(1 << 10), + + /** + * Enables the ability to target an item on the ground with the component. + */ + OPOBJT(1 << 11), + + /** + * Enables the ability to target an NPC with the component. + */ + OPNPCT(1 << 12), + + /** + * Enables the ability to target an object with the component. + */ + OPLOCT(1 << 13), + + /** + * Enables the ability to target another player with the component. + */ + OPPLAYERT(1 << 14), + + /** + * Enabled the ability to target an item in the players inventory with the component. + */ + OPHELDT(1 << 15), + + /** + * Enables the ability to target another component with the component. Requires {@link #IF_TARGET} to be enabled on the components that + * are targetable. + */ + IF_BUTTONT(1 << 16), + + /** + * Sets the component to be dragged to any parent up to depth of 1. + */ + DRAG_DEPTH1(1 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 2. + */ + DRAG_DEPTH2(2 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 3. + */ + DRAG_DEPTH3(3 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 4. + */ + DRAG_DEPTH4(4 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 5. + */ + DRAG_DEPTH5(5 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 6. + */ + DRAG_DEPTH6(6 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 7. + */ + DRAG_DEPTH7(7 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 8. + */ + DRAG_TARGET(1 << 20), + + /** + * Enables the ability of {@link #IF_BUTTONT} enabled components to target the component. + */ + IF_TARGET(1 << 21), + + ; + + private int mask; + + + InterfaceEvent(int mask) { + this.mask = mask; + } + + /** + * Gets mask. + * + * @return the mask + */ + public int getMask() { + return mask; + } +} diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java index 953bff64c..b454a0766 100644 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java @@ -1,22 +1,21 @@ package org.apollo.game.model.inter; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - +import org.apollo.cache.def.EnumDefinition; import org.apollo.game.message.handler.MessageHandlerChain; import org.apollo.game.message.impl.CloseInterfaceMessage; import org.apollo.game.message.impl.EnterAmountMessage; import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.game.message.impl.OpenSidebarMessage; +import org.apollo.game.message.impl.encode.IfMoveSubMessage; +import org.apollo.game.message.impl.encode.IfOpenSubMessage; +import org.apollo.game.message.impl.encode.IfOpenTopMessage; import org.apollo.game.model.entity.Player; import org.apollo.game.model.event.impl.CloseInterfacesEvent; import org.apollo.game.model.inter.dialogue.DialogueListener; -import org.apollo.game.model.inv.InventoryListener; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; /** * Represents the set of interfaces the player has open. @@ -40,14 +39,19 @@ public final class InterfaceSet { /** - * A map of open interfaces. + * The player whose interfaces are being managed. */ - private final Map interfaces = new HashMap<>(); + private final Player player; /** - * The player whose interfaces are being managed. + * The display mode. */ - private final Player player; + private DisplayMode mode = DisplayMode.FIXED; + + /** + * A map of open interfaces. + */ + private final Map interfaces = new HashMap<>(); /** * The current enter amount listener. @@ -113,7 +117,7 @@ public boolean contains(int id) { * @param type The interface's type. * @return {@code true} if so, {@code false} if not. */ - public boolean contains(InterfaceType type) { + public boolean contains(ServerInterfaceType type) { return interfaces.containsKey(type); } @@ -121,9 +125,7 @@ public boolean contains(InterfaceType type) { * Called when the player has clicked the "Click here to continue" button on a dialogue. */ public void continueRequested() { - if (dialogueListener.isPresent()) { - dialogueListener.get().continued(); - } + dialogueListener.ifPresent(DialogueListener::continued); } /** @@ -148,7 +150,7 @@ public void interfaceClosed() { /** * Opens a dialogue interface. * - * @param listener The {@link DialogueListener}. + * @param listener The {@link DialogueListener}. * @param dialogueId The dialogue id. */ public void openDialogue(DialogueListener listener, int dialogueId) { @@ -157,7 +159,7 @@ public void openDialogue(DialogueListener listener, int dialogueId) { dialogueListener = Optional.ofNullable(listener); this.listener = Optional.ofNullable(listener); - interfaces.put(InterfaceType.DIALOGUE, dialogueId); + interfaces.put(ServerInterfaceType.DIALOGUE, dialogueId); player.send(new OpenDialogueInterfaceMessage(dialogueId)); } @@ -173,7 +175,7 @@ public void openDialogue(int dialogueId) { /** * Opens a dialogue overlay interface. * - * @param listener The {@link DialogueListener}. + * @param listener The {@link DialogueListener}. * @param dialogueId The dialogue id. */ public void openDialogueOverlay(DialogueListener listener, int dialogueId) { @@ -182,7 +184,7 @@ public void openDialogueOverlay(DialogueListener listener, int dialogueId) { dialogueListener = Optional.ofNullable(listener); this.listener = Optional.ofNullable(listener); - interfaces.put(InterfaceType.DIALOGUE, dialogueId); + interfaces.put(ServerInterfaceType.DIALOGUE, dialogueId); player.send(new OpenDialogueOverlayMessage(dialogueId)); } @@ -206,91 +208,69 @@ public void openEnterAmountDialogue(EnterAmountListener listener) { } /** - * Opens an overlay interface. + * Opens a modal. * - * @param overlay The overlay id. + * @param modal The window's id. */ - public void openOverlay(int overlay) { - interfaces.put(InterfaceType.OVERLAY, overlay); - player.send(new OpenOverlayMessage(overlay)); + public void openModal(int modal) { + openModal(null, modal); } /** - * Opens an sidebar interface. + * Opens a modal with the specified listener. * - * @param sidebar The sidebar id. + * @param listener The listener for this interface. + * @param modal The modal's id. */ - public void openSidebar(int sidebar) { + public void openModal(InterfaceListener listener, int modal) { closeAndNotify(); - interfaces.put(InterfaceType.SIDEBAR, sidebar); + this.listener = Optional.ofNullable(listener); - player.send(new OpenSidebarMessage(sidebar)); + interfaces.put(ServerInterfaceType.MODAL, modal); + openTopLevel(modal, TopLevelPosition.MODAL); } - /** - * Opens an sidebar interface with the specified {@link InventoryListener}. - * - * @param listener The listener. - * @param sidebar The sidebar id. - */ - public void openSidebar(InterfaceListener listener, int sidebar) { - closeAndNotify(); - this.listener = Optional.ofNullable(listener); - interfaces.put(InterfaceType.SIDEBAR, sidebar); - - player.send(new OpenSidebarMessage(sidebar)); + public void openTopLevel(TopLevelPosition position) { + openTopLevel(position.getInterfaceId(), position); } - /** - * Opens a window. - * - * @param windowId The window's id. - */ - public void openWindow(int windowId) { - openWindow(null, windowId); + public void openTopLevel(int id, TopLevelPosition position) { + player.send(new IfOpenSubMessage(position.getComponent(mode), position.getInterfaceType(), id)); } /** - * Opens a window with the specified listener. + * Opens the top interface. * - * @param listener The listener for this interface. - * @param windowId The window's id. + * @param mode - The display mode. */ - public void openWindow(InterfaceListener listener, int windowId) { - closeAndNotify(); - this.listener = Optional.ofNullable(listener); + public void openTop(DisplayMode mode) { + player.send(new IfOpenTopMessage(mode.getInterfaceId())); - interfaces.put(InterfaceType.WINDOW, windowId); - player.send(new OpenInterfaceMessage(windowId)); - } + final var oldEnumMap = EnumDefinition.lookup(this.mode.getTopLevelEnum()).getIntValues(); + final var newEnumMap = EnumDefinition.lookup(mode.getTopLevelEnum()).getIntValues(); + for (var newComponent : newEnumMap.int2IntEntrySet()) { + int key = newComponent.getIntKey(); + int to = newComponent.getIntValue(); - /** - * Opens a window and inventory sidebar. - * - * @param windowId The window's id. - * @param sidebarId The sidebar's id. - */ - public void openWindowWithSidebar(int windowId, int sidebarId) { - openWindowWithSidebar(null, windowId, sidebarId); - } + if (to == -1) { + continue; + } - /** - * Opens a window and inventory sidebar with the specified listener. - * - * @param listener The listener for this interface. - * @param windowId The window's id. - * @param sidebarId The sidebar's id. - */ - public void openWindowWithSidebar(InterfaceListener listener, int windowId, int sidebarId) { - closeAndNotify(); - this.listener = Optional.ofNullable(listener); + if (oldEnumMap.containsKey(key)) { + int from = oldEnumMap.get(key); + + if (from == -1) { + continue; + } - interfaces.put(InterfaceType.WINDOW, windowId); - interfaces.put(InterfaceType.SIDEBAR, sidebarId); + player.send(new IfMoveSubMessage(from, to)); + } + } - player.send(new OpenInterfaceSidebarMessage(windowId, sidebarId)); + this.mode = mode; } + /** * Gets the size of the interface set. * diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceType.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceType.java deleted file mode 100644 index 0e4b530c6..000000000 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceType.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apollo.game.model.inter; - -/** - * Represents the different types of interfaces. - * - * @author Graham - */ -public enum InterfaceType { - - /** - * An interface that appears in the chat box. - */ - DIALOGUE, - - /** - * An interface shown behind a fullscreen window. - */ - FULLSCREEN_BACKGROUND, - - /** - * An interface shown in full screen mode. - */ - FULLSCREEN_WINDOW, - - /** - * An interface that occupies the game screen like a window, but the player can still perform actions without the - * interface closing. - */ - OVERLAY, - - /** - * An interface displayed over the inventory area. - */ - SIDEBAR, - - /** - * An interface that occupies the game screen. - */ - WINDOW; - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/inter/ServerInterfaceType.java b/game/src/main/java/org/apollo/game/model/inter/ServerInterfaceType.java new file mode 100644 index 000000000..ad05d32a7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/ServerInterfaceType.java @@ -0,0 +1,22 @@ +package org.apollo.game.model.inter; + +/** + * Represents the different types of interfaces. + * + * @author Graham + */ +public enum ServerInterfaceType { + + /** + * These are actually sent to the client. + */ + MODAL, + OVERLAY, + + /** + * These are organizational. + */ + TOPLEVEL, + TOP, + DIALOGUE +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/inter/TopLevelPosition.java b/game/src/main/java/org/apollo/game/model/inter/TopLevelPosition.java new file mode 100644 index 000000000..08c432305 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/TopLevelPosition.java @@ -0,0 +1,49 @@ +package org.apollo.game.model.inter; + +import org.apollo.cache.def.EnumDefinition; + +public enum TopLevelPosition { + CHATBOX(29, 162, ClientInterfaceType.OVERLAY), PRIVATE_CHAT(9, 163, + ClientInterfaceType.OVERLAY), WILDERNESS_OVERLAY(4, ClientInterfaceType.OVERLAY), ORBS(28, + ClientInterfaceType.OVERLAY), SKILLS_TAB(69, 320, ClientInterfaceType.OVERLAY), JOURNAL_TAB_HEADER(70, 629, + ClientInterfaceType.OVERLAY), INVENTORY_TAB(71, 149, ClientInterfaceType.OVERLAY), EQUIPMENT_TAB(72, 387, + ClientInterfaceType.OVERLAY), PRAYER_TAB(73, 541, ClientInterfaceType.OVERLAY), SPELLBOOK_TAB(74, 218, + ClientInterfaceType.OVERLAY), ACCOUNT_MANAGEMENT(76, 109, ClientInterfaceType.OVERLAY), FRIENDS_TAB(77, 429, + ClientInterfaceType.OVERLAY), LOGOUT_TAB(78, 182, ClientInterfaceType.OVERLAY), SETTINGS_TAB(79, 261, + ClientInterfaceType.OVERLAY), EMOTE_TAB(80, 216, ClientInterfaceType.OVERLAY), MUSIC_TAB(81, 239, + ClientInterfaceType.OVERLAY), CLAN_TAB(75, 7, ClientInterfaceType.OVERLAY), COMBAT_TAB(68, 593, + ClientInterfaceType.OVERLAY), MODAL(13, ClientInterfaceType.MODAL), DIALOGUE(561, + ClientInterfaceType.MODAL), MINIGAME_OVERLAY(6, ClientInterfaceType.OVERLAY), OVERLAY(3, + ClientInterfaceType.OVERLAY), SINGLE_TAB(66, ClientInterfaceType.MODAL), WORLD_MAP(14, + ClientInterfaceType.OVERLAY), UNKNOWN_OVERLAY(8, ClientInterfaceType.OVERLAY), XP_TRACKER(7, + ClientInterfaceType.OVERLAY); + + private final int component, interfaceId; + private final ClientInterfaceType interfaceType; + + TopLevelPosition(int component, int interfaceId, ClientInterfaceType interfaceType) { + this.interfaceId = interfaceId; + this.component = component; + this.interfaceType = interfaceType; + } + + TopLevelPosition(int component, ClientInterfaceType interfaceType) { + this(component, -1, interfaceType); + } + + public int getComponent(DisplayMode mode) { + if (mode == DisplayMode.RESIZABLE) { + return DisplayMode.RESIZABLE.getInterfaceId() << 16 | component; + } + return EnumDefinition.lookup(mode.getTopLevelEnum()) + .lookup(DisplayMode.RESIZABLE.getInterfaceId() << 16 | component, -1); + } + + public int getInterfaceId() { + return interfaceId; + } + + public ClientInterfaceType getInterfaceType() { + return interfaceType; + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index aa5ac4c9f..8a3ba1c2b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,24 +1,28 @@ package org.apollo.game.release.r181; import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.message.impl.encode.ConfigMessage; -import org.apollo.game.message.impl.encode.RebuildNormalMessage; -import org.apollo.game.message.impl.encode.IfOpenTopMessage; +import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.interfaces.ClosedInterfaceMessageDecoder; +import org.apollo.game.release.r181.decoders.interfaces.DisplayStatusMessageDecoder; import org.apollo.game.release.r181.decoders.interfaces.EnteredAmountMessageDecoder; import org.apollo.game.release.r181.decoders.npc.*; import org.apollo.game.release.r181.decoders.obj.*; +import org.apollo.game.release.r181.decoders.player.ReportAbuseMessageDecoder; import org.apollo.game.release.r181.decoders.player.actions.*; -import org.apollo.game.release.r181.decoders.player.*; -import org.apollo.game.release.r181.decoders.social.*; +import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; +import org.apollo.game.release.r181.decoders.social.PrivateChatMessageDecoder; import org.apollo.game.release.r181.decoders.social.friends.AddFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.RemoveIgnoreMessageDecoder; -import org.apollo.game.release.r181.encoders.ConfigMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.ConfigMessageEncoder; +import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.IfMoveSubMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.IfOpenSubMessageEncoder; import org.apollo.game.release.r181.encoders.ui.IfOpenTopMessageEncoder; import org.apollo.net.meta.PacketMetaDataGroup; import org.apollo.net.release.Release; @@ -144,6 +148,12 @@ private void init() { */ register(IfOpenTopMessage.class, new IfOpenTopMessageEncoder()); + register(IfOpenSubMessage.class, new IfOpenSubMessageEncoder()); + register(IfMoveSubMessage.class, new IfMoveSubMessageEncoder()); + + + register(ServerChatMessage.class, new ServerChatMessageEncoder()); + register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); @@ -185,6 +195,7 @@ private void init() { /** * Interface */ + register(35, new DisplayStatusMessageDecoder()); register(20, new ClosedInterfaceMessageDecoder()); /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/DisplayStatusMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/DisplayStatusMessageDecoder.java new file mode 100644 index 000000000..e435a9246 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/DisplayStatusMessageDecoder.java @@ -0,0 +1,19 @@ +package org.apollo.game.release.r181.decoders.interfaces; + +import org.apollo.game.message.impl.decode.DisplayStatusMessage; +import org.apollo.game.model.inter.DisplayMode; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +public class DisplayStatusMessageDecoder extends MessageDecoder { + @Override + public DisplayStatusMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + DisplayMode mode = reader.getUnsigned(DataType.BYTE) == 1 ? DisplayMode.FIXED : DisplayMode.RESIZABLE; + int width = (int) reader.getUnsigned(DataType.SHORT); + int height = (int) reader.getUnsigned(DataType.SHORT); + return new DisplayStatusMessage(mode, height, width); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java new file mode 100644 index 000000000..c66bf16ad --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java @@ -0,0 +1,26 @@ +package org.apollo.game.release.r181.encoders.game; + +import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class ServerChatMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(ServerChatMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(3, PacketType.VARIABLE_BYTE); + final var ext = message.getExtension(); + + builder.putSmart(message.getType().getId()); + if (ext.isEmpty()) { + builder.put(DataType.BYTE, 1); + builder.putString(ext); + } else { + builder.put(DataType.BYTE, 0); + } + builder.putString(message.getMessage()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java similarity index 95% rename from game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java index 0470915c8..e7610a062 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ConfigMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.encoders; +package org.apollo.game.release.r181.encoders.ui; import org.apollo.game.message.impl.encode.ConfigMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java new file mode 100644 index 000000000..b969531cd --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java @@ -0,0 +1,17 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfMoveSubMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class IfMoveSubMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(IfMoveSubMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(82, PacketType.FIXED); + builder.put(DataType.INT, message.getToComponent()); + builder.put(DataType.INT, message.getFromComponent()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java new file mode 100644 index 000000000..b05726236 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java @@ -0,0 +1,18 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfOpenSubMessage; +import org.apollo.game.message.impl.encode.IfOpenTopMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class IfOpenSubMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfOpenSubMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(77, PacketType.FIXED); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getType().ordinal()); + builder.put(DataType.INT, DataOrder.MIDDLE, message.getParentComponent()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/service/GameService.java b/game/src/main/java/org/apollo/game/service/GameService.java index 14e2f925c..95a9fd6d0 100644 --- a/game/src/main/java/org/apollo/game/service/GameService.java +++ b/game/src/main/java/org/apollo/game/service/GameService.java @@ -1,14 +1,5 @@ package org.apollo.game.service; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - import org.apollo.Service; import org.apollo.game.GameConstants; import org.apollo.game.GamePulseHandler; @@ -18,6 +9,7 @@ import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Player; +import org.apollo.game.model.inter.DisplayMode; import org.apollo.game.session.GameSession; import org.apollo.game.session.LoginSession; import org.apollo.game.sync.ClientSynchronizer; @@ -27,6 +19,15 @@ import org.apollo.util.xml.XmlParser; import org.xml.sax.SAXException; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + /** * The {@link GameService} class schedules and manages the execution of the {@link GamePulseHandler} class. * @@ -52,7 +53,7 @@ private static final class LoginPlayerRequest { /** * Creates the LoginPlayerRequest. * - * @param player The {@link Player} logging in. + * @param player The {@link Player} logging in. * @param session The {@link LoginSession} of the Player. */ public LoginPlayerRequest(Player player, LoginSession session) { @@ -81,7 +82,8 @@ public LoginPlayerRequest(Player player, LoginSession session) { /** * The scheduled executor service. */ - private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(ThreadUtil.create("GameService")); + private final ScheduledExecutorService executor = Executors + .newSingleThreadScheduledExecutor(ThreadUtil.create("GameService")); /** * The Queue of LoginPlayers to add. @@ -166,7 +168,7 @@ public synchronized void pulse() { /** * Registers a {@link Player} at the end of the next cycle. * - * @param player The Player to register. + * @param player The Player to register. * @param session the {@link LoginSession} of the Player. */ public void registerPlayer(Player player, LoginSession session) { @@ -217,7 +219,8 @@ private void finalizeRegistrations() { finalizePlayerRegistration(player); request.session.sendLoginSuccess(player); if (!player.getSession().isReconnecting()) { - player.sendInitialMessages(); + player.sendInitialMessages(request.session.getRequest() + .getDisplayMode() == 1 ? DisplayMode.RESIZABLE : DisplayMode.FIXED); } } } @@ -242,8 +245,8 @@ private void finalizeUnregistrations() { /** * Initializes the game service. * - * @throws IOException If there is an error accessing the file. - * @throws SAXException If there is an error parsing the file. + * @throws IOException If there is an error accessing the file. + * @throws SAXException If there is an error parsing the file. * @throws ReflectiveOperationException If a MessageHandler could not be created. */ private void init() throws IOException, SAXException, ReflectiveOperationException { diff --git a/game/src/main/java/org/apollo/game/session/LoginSession.java b/game/src/main/java/org/apollo/game/session/LoginSession.java index 710917064..fc7afa8f1 100644 --- a/game/src/main/java/org/apollo/game/session/LoginSession.java +++ b/game/src/main/java/org/apollo/game/session/LoginSession.java @@ -156,4 +156,8 @@ private void handleLoginRequest(LoginRequest request) throws IOException { LoginService service = context.getLoginService(); service.submitLoadRequest(this, request); } + + public LoginRequest getRequest() { + return request; + } } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java index aa2165d3f..7438127b9 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java @@ -170,7 +170,7 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List> 1) == 1;// Resizable/Fixed + final var displayMode = clientProperties >> 1; final var frameWidth = payload.readShort(); final var frameHeight = payload.readShort(); @@ -208,7 +208,7 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List Date: Sat, 14 Mar 2020 23:50:04 -0400 Subject: [PATCH 18/63] Reduces the move-toplevel code. --- .../org/apollo/game/model/inter/InterfaceSet.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java index b454a0766..9b614260f 100644 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java @@ -251,20 +251,16 @@ public void openTop(DisplayMode mode) { for (var newComponent : newEnumMap.int2IntEntrySet()) { int key = newComponent.getIntKey(); int to = newComponent.getIntValue(); - if (to == -1) { continue; } - if (oldEnumMap.containsKey(key)) { - int from = oldEnumMap.get(key); - - if (from == -1) { - continue; - } - - player.send(new IfMoveSubMessage(from, to)); + int from = oldEnumMap.getOrDefault(key, -1); + if (from == -1) { + continue; } + + player.send(new IfMoveSubMessage(from, to)); } this.mode = mode; From db9a44326bd08994ff0dbda36e2c6bb35a796024 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 15 Mar 2020 00:22:53 -0400 Subject: [PATCH 19/63] Experience and Weight Encoder messages. --- .../impl/{ => encode}/UpdateSkillMessage.java | 2 +- .../{ => encode}/UpdateWeightMessage.java | 2 +- .../skill/SynchronizationSkillListener.java | 7 +++-- .../apollo/game/release/r181/Release181.java | 5 +++- .../encoders/UpdateSkillMessageEncoder.java | 26 +++++++++++++++++++ .../encoders/UpdateWeightMessageEncoder.java | 22 ++++++++++++++++ 6 files changed, 57 insertions(+), 7 deletions(-) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/UpdateSkillMessage.java (94%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/UpdateWeightMessage.java (92%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateSkillMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateSkillMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/UpdateSkillMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateSkillMessage.java index 85dfca663..19d285e74 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateSkillMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateSkillMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.Skill; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateWeightMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateWeightMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/UpdateWeightMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateWeightMessage.java index ba153dafa..9215b022b 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateWeightMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateWeightMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java b/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java index f6555ec24..857c8fd40 100644 --- a/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java +++ b/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java @@ -1,12 +1,11 @@ package org.apollo.game.model.skill; -import java.util.stream.IntStream; - -import org.apollo.game.message.impl.UpdateSkillMessage; +import org.apollo.game.message.impl.encode.UpdateSkillMessage; import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.Skill; import org.apollo.game.model.entity.SkillSet; -import org.apollo.game.sync.block.SynchronizationBlock; + +import java.util.stream.IntStream; /** * A {@link SkillListener} which synchronizes the state of a {@link SkillSet} with a client. diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 8a3ba1c2b..2eabfa841 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -17,6 +17,8 @@ import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.RemoveIgnoreMessageDecoder; +import org.apollo.game.release.r181.encoders.UpdateSkillMessageEncoder; +import org.apollo.game.release.r181.encoders.UpdateWeightMessageEncoder; import org.apollo.game.release.r181.encoders.ui.ConfigMessageEncoder; import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; @@ -151,8 +153,9 @@ private void init() { register(IfOpenSubMessage.class, new IfOpenSubMessageEncoder()); register(IfMoveSubMessage.class, new IfMoveSubMessageEncoder()); - register(ServerChatMessage.class, new ServerChatMessageEncoder()); + register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); + register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java new file mode 100644 index 000000000..78338db89 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java @@ -0,0 +1,26 @@ +package org.apollo.game.release.r181.encoders; + +import org.apollo.game.message.impl.encode.UpdateSkillMessage; +import org.apollo.game.model.entity.Skill; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateSkillMessage}. + * + * @author Graham + */ +public class UpdateSkillMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateSkillMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(22, PacketType.FIXED); + Skill skill = message.getSkill(); + + builder.put(DataType.INT, DataOrder.LITTLE, (int) skill.getExperience()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getId()); + builder.put(DataType.BYTE, skill.getCurrentLevel()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java new file mode 100644 index 000000000..d53bc7992 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders; + +import org.apollo.game.message.impl.encode.UpdateWeightMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateWeightMessage}. + * + * @author Major + */ +public class UpdateWeightMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateWeightMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(71, PacketType.FIXED); + builder.put(DataType.SHORT, message.getWeight()); + return builder.toGamePacket(); + } +} From ccc7e0f3363ae17288ea46911967323e2f14cd13 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 15 Mar 2020 00:41:02 -0400 Subject: [PATCH 20/63] Added the run-energy message. --- game/data/messages.xml | 2 +- .../src/org/apollo/game/plugin/api/Player.kt | 3 ++- ....java => DisplayStatusMessageHandler.java} | 4 ++-- .../{ => encode}/UpdateRunEnergyMessage.java | 2 +- .../org/apollo/game/model/entity/Player.java | 2 +- .../org/apollo/game/model/entity/Skill.java | 12 +++++++++- .../apollo/game/release/r181/Release181.java | 4 +++- .../UpdateRunEnergyMessageEncoder.java | 23 +++++++++++++++++++ 8 files changed, 44 insertions(+), 8 deletions(-) rename game/src/main/java/org/apollo/game/message/handler/{DisplayStatusMessageDecoder.java => DisplayStatusMessageHandler.java} (81%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/UpdateRunEnergyMessage.java (92%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java diff --git a/game/data/messages.xml b/game/data/messages.xml index e3b8628e8..271f2d438 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -9,7 +9,7 @@ org.apollo.game.message.impl.decode.DisplayStatusMessage - org.apollo.game.message.handler.DisplayStatusMessageDecoder + org.apollo.game.message.handler.DisplayStatusMessageHandler diff --git a/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt b/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt index a98a54481..d845107c8 100644 --- a/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt +++ b/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt @@ -25,7 +25,8 @@ val Player.thieving: SkillProxy get() = SkillProxy(skillSet, Skill.THIEVING) val Player.slayer: SkillProxy get() = SkillProxy(skillSet, Skill.SLAYER) val Player.farming: SkillProxy get() = SkillProxy(skillSet, Skill.FARMING) val Player.runecraft: SkillProxy get() = SkillProxy(skillSet, Skill.RUNECRAFT) - +val Player.construction: SkillProxy get() = SkillProxy(skillSet, Skill.CONSTRUCTION) +val Player.hunter: SkillProxy get() = SkillProxy(skillSet, Skill.HUNTER) /** * A proxy class to allow */ diff --git a/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageDecoder.java b/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageHandler.java similarity index 81% rename from game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageDecoder.java rename to game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageHandler.java index 725da45a2..84d1312f3 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageHandler.java @@ -4,13 +4,13 @@ import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; -public class DisplayStatusMessageDecoder extends MessageHandler { +public class DisplayStatusMessageHandler extends MessageHandler { /** * Creates the MessageListener. * * @param world The {@link World} the {@link DisplayStatusMessage} occurred in. */ - public DisplayStatusMessageDecoder(World world) { + public DisplayStatusMessageHandler(World world) { super(world); } diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateRunEnergyMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateRunEnergyMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/UpdateRunEnergyMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateRunEnergyMessage.java index c4f3bef00..5eb64c9a5 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateRunEnergyMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateRunEnergyMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 2948e295c..1238a81ce 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -4,8 +4,8 @@ import com.google.common.base.Preconditions; import org.apollo.game.message.impl.*; import org.apollo.game.message.impl.encode.ConfigMessage; -import org.apollo.game.message.impl.encode.IfOpenTopMessage; import org.apollo.game.message.impl.encode.RebuildNormalMessage; +import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; import org.apollo.game.model.World; diff --git a/game/src/main/java/org/apollo/game/model/entity/Skill.java b/game/src/main/java/org/apollo/game/model/entity/Skill.java index a2a6fc9a1..ab8d148d3 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Skill.java +++ b/game/src/main/java/org/apollo/game/model/entity/Skill.java @@ -112,12 +112,22 @@ public final class Skill { */ public static final int RUNECRAFT = 20; + /** + * The construction id. + */ + public static final int CONSTRUCTION = 21; + + /** + * The hunter id. + */ + public static final int HUNTER = 20; + /** * The skill names. */ private static final String[] SKILL_NAMES = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", - "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft" }; + "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Construction", "Hunter" }; /** * Gets the name of a skill. diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 2eabfa841..0ce8a6d1a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -17,12 +17,13 @@ import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.RemoveIgnoreMessageDecoder; +import org.apollo.game.release.r181.encoders.UpdateRunEnergyMessageEncoder; import org.apollo.game.release.r181.encoders.UpdateSkillMessageEncoder; import org.apollo.game.release.r181.encoders.UpdateWeightMessageEncoder; -import org.apollo.game.release.r181.encoders.ui.ConfigMessageEncoder; import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.ConfigMessageEncoder; import org.apollo.game.release.r181.encoders.ui.IfMoveSubMessageEncoder; import org.apollo.game.release.r181.encoders.ui.IfOpenSubMessageEncoder; import org.apollo.game.release.r181.encoders.ui.IfOpenTopMessageEncoder; @@ -156,6 +157,7 @@ private void init() { register(ServerChatMessage.class, new ServerChatMessageEncoder()); register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); + register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java new file mode 100644 index 000000000..13a57c532 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java @@ -0,0 +1,23 @@ +package org.apollo.game.release.r181.encoders; + +import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; +import org.apollo.game.message.impl.encode.UpdateWeightMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateRunEnergyMessage}. + * + * @author Major + */ +public class UpdateRunEnergyMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateRunEnergyMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.FIXED); + builder.put(DataType.BYTE, message.getEnergy()); + return builder.toGamePacket(); + } +} From 9fcb2fd8cba4d8c6685f29ea2b9f4731ffa9b0b1 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 15 Mar 2020 00:43:08 -0400 Subject: [PATCH 21/63] Organized imports. --- .../main/java/org/apollo/ServiceManager.java | 4 +- .../org/apollo/game/GamePulseHandler.java | 4 +- .../game/command/CommandDispatcher.java | 4 +- .../game/command/CreditsCommandListener.java | 9 ++--- .../game/fs/decoder/SynchronousDecoder.java | 10 ++--- .../game/fs/decoder/WorldMapDecoder.java | 7 +--- .../game/fs/decoder/WorldObjectsDecoder.java | 2 - .../game/io/EquipmentDefinitionParser.java | 9 +---- .../game/io/MessageHandlerChainSetParser.java | 6 +-- .../apollo/game/io/PluginMetaDataParser.java | 10 ++--- .../io/player/BinaryPlayerSerializer.java | 40 +++++-------------- .../game/io/player/PlayerLoaderResponse.java | 5 +-- .../apollo/game/login/PlayerLoaderWorker.java | 6 +-- .../apollo/game/login/PlayerSaverWorker.java | 6 +-- .../handler/ItemVerificationHandler.java | 6 +-- .../message/handler/MessageHandlerChain.java | 7 ++-- .../handler/MessageHandlerChainSet.java | 6 +-- .../ObjectActionVerificationHandler.java | 6 +-- .../impl/GroupedRegionUpdateMessage.java | 5 +-- .../game/message/impl/IgnoreListMessage.java | 4 +- .../message/impl/InventoryItemMessage.java | 1 - .../impl/NpcSynchronizationMessage.java | 4 +- .../impl/PlayerSynchronizationMessage.java | 4 +- .../apollo/game/message/impl/WalkMessage.java | 3 +- .../org/apollo/game/model/Appearance.java | 3 +- .../main/java/org/apollo/game/model/Item.java | 3 +- .../org/apollo/game/model/area/Region.java | 7 +--- .../game/model/area/RegionCoordinates.java | 3 +- .../model/area/collision/CollisionMatrix.java | 7 ++-- .../model/area/update/UpdateOperation.java | 3 +- .../org/apollo/game/model/entity/Mob.java | 6 +-- .../game/model/entity/MobRepository.java | 6 +-- .../org/apollo/game/model/entity/Npc.java | 7 ++-- .../apollo/game/model/entity/SkillSet.java | 9 ++--- .../game/model/entity/WalkingQueue.java | 5 --- .../game/model/entity/attr/AttributeMap.java | 5 +-- .../model/entity/obj/DynamicGameObject.java | 6 +-- .../game/model/entity/obj/GameObject.java | 5 +-- .../path/AStarPathfindingAlgorithm.java | 11 +---- .../apollo/game/model/entity/path/Node.java | 7 ++-- .../entity/path/PathfindingAlgorithm.java | 10 ++--- .../path/SimplePathfindingAlgorithm.java | 10 ++--- .../game/model/event/EventListenerChain.java | 4 +- .../inv/AppearanceInventoryListener.java | 1 - .../game/plugin/KotlinPluginEnvironment.java | 12 +++--- .../apollo/game/plugin/PluginEnvironment.java | 1 - .../org/apollo/game/plugin/PluginManager.java | 8 ++-- .../npc/FourthNpcActionMessageDecoder.java | 5 ++- .../npc/ThirdNpcActionMessageDecoder.java | 6 +-- .../obj/FirstObjectActionMessageDecoder.java | 6 +-- .../obj/SecondObjectActionMessageDecoder.java | 5 ++- .../FirstPlayerActionMessageDecoder.java | 6 +-- .../ThirdPlayerActionMessageDecoder.java | 5 ++- .../UpdateRunEnergyMessageEncoder.java | 1 - .../npc/NpcSynchronizationMessageEncoder.java | 17 +------- .../encoders/ui/IfMoveSubMessageEncoder.java | 4 +- .../encoders/ui/IfOpenSubMessageEncoder.java | 1 - .../org/apollo/game/scheduling/Scheduler.java | 6 +-- .../game/scheduling/impl/NpcMovementTask.java | 11 +---- .../apollo/game/session/ApolloHandler.java | 8 ++-- .../org/apollo/game/session/GameSession.java | 11 +++-- .../game/sync/ParallelClientSynchronizer.java | 9 +---- .../sync/SequentialClientSynchronizer.java | 17 +++----- .../apollo/game/sync/seg/MovementSegment.java | 3 +- .../sync/task/NpcSynchronizationTask.java | 12 +++--- .../sync/task/PlayerSynchronizationTask.java | 20 ++++------ .../task/PrePlayerSynchronizationTask.java | 10 ++--- .../org/apollo/game/action/ActionCoroutine.kt | 4 +- .../ItemOnItemVerificationHandlerTests.java | 3 +- .../ItemOnObjectVerificationHandlerTests.java | 1 - .../ObjectActionVerificationHandlerTests.java | 8 +--- .../PublicChatMessageHandlerTests.java | 4 +- .../game/model/entity/MobRepositoryTests.java | 18 ++++----- .../game/model/entity/SkillSetTests.java | 2 +- .../game/model/entity/WalkingQueueTests.java | 1 - .../model/entity/attr/AttributeTests.java | 5 +-- 76 files changed, 188 insertions(+), 328 deletions(-) diff --git a/game/src/main/java/org/apollo/ServiceManager.java b/game/src/main/java/org/apollo/ServiceManager.java index 539fb60d6..a329806f1 100644 --- a/game/src/main/java/org/apollo/ServiceManager.java +++ b/game/src/main/java/org/apollo/ServiceManager.java @@ -1,12 +1,12 @@ package org.apollo; -import java.util.logging.Logger; - import org.apollo.game.model.World; import org.apollo.game.service.GameService; import org.apollo.game.service.LoginService; import org.apollo.game.service.UpdateService; +import java.util.logging.Logger; + /** * A class which manages {@link Service}s. * diff --git a/game/src/main/java/org/apollo/game/GamePulseHandler.java b/game/src/main/java/org/apollo/game/GamePulseHandler.java index fc53f6c51..da1ed1ec3 100644 --- a/game/src/main/java/org/apollo/game/GamePulseHandler.java +++ b/game/src/main/java/org/apollo/game/GamePulseHandler.java @@ -1,10 +1,10 @@ package org.apollo.game; +import org.apollo.game.service.GameService; + import java.util.logging.Level; import java.util.logging.Logger; -import org.apollo.game.service.GameService; - /** * A class which handles the logic for each pulse of the {@link GameService}. * diff --git a/game/src/main/java/org/apollo/game/command/CommandDispatcher.java b/game/src/main/java/org/apollo/game/command/CommandDispatcher.java index 70c76962c..130957c6f 100644 --- a/game/src/main/java/org/apollo/game/command/CommandDispatcher.java +++ b/game/src/main/java/org/apollo/game/command/CommandDispatcher.java @@ -1,11 +1,11 @@ package org.apollo.game.command; +import org.apollo.game.model.entity.Player; + import java.util.HashMap; import java.util.Map; import java.util.Set; -import org.apollo.game.model.entity.Player; - /** * A class that dispatches {@link Command}s to {@link CommandListener}s. * diff --git a/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java b/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java index 1363bf620..4279a847d 100644 --- a/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java +++ b/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java @@ -1,13 +1,12 @@ package org.apollo.game.command; +import com.google.common.collect.ImmutableSet; +import org.apollo.game.model.entity.Player; + import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.apollo.game.model.entity.Player; - -import com.google.common.collect.ImmutableSet; - /** * Implements a {@code ::credits} command that lists the authors of all plugins used in the server. * @@ -33,7 +32,7 @@ public CreditsCommandListener(Set authors) { * If you are considering removing this command, please bear in mind that Apollo took several people thousands of * hours to create. We released it to the world for free and it isn't much to ask to leave this command in. It isn't * very obtrusive and gives us some well-deserved recognition for the work we have done. Thank you! - * + * * The list of authors is generated from the plugin manager. If you create a custom plugin, make sure you add your * name to the plugin.xml file and it'll appear here automatically! */ diff --git a/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java index f17be7143..df667c85b 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java @@ -1,16 +1,12 @@ package org.apollo.game.fs.decoder; +import org.apollo.util.ThreadUtil; + import java.util.Arrays; import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.stream.Collectors; -import org.apollo.util.ThreadUtil; - /** * A composite decoder that executes each child in parallel. * diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java index b4fa4e3c8..6b8d9ae3f 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java @@ -1,12 +1,7 @@ package org.apollo.game.fs.decoder; import org.apollo.cache.Cache; -import org.apollo.cache.map.MapConstants; -import org.apollo.cache.map.MapFile; -import org.apollo.cache.map.MapTerrainDecoder; -import org.apollo.cache.map.MapIndex; -import org.apollo.cache.map.MapPlane; -import org.apollo.cache.map.Tile; +import org.apollo.cache.map.*; import org.apollo.game.model.Position; import org.apollo.game.model.area.collision.CollisionManager; diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java index ba47424ff..8ed9e026a 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java @@ -6,8 +6,6 @@ import org.apollo.cache.map.MapObject; import org.apollo.game.model.Position; import org.apollo.game.model.World; -import org.apollo.game.model.area.Region; -import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.obj.StaticGameObject; import java.io.IOException; diff --git a/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java b/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java index 19a79e71b..862e11d44 100644 --- a/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java +++ b/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java @@ -1,14 +1,9 @@ package org.apollo.game.io; -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; - import org.apollo.cache.def.EquipmentDefinition; +import java.io.*; + /** * A class that parses the {@code data/equipment-[release].dat} file to create an array of {@link * EquipmentDefinition}s. diff --git a/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java b/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java index 56f711387..9ec1241a9 100644 --- a/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java +++ b/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java @@ -1,8 +1,5 @@ package org.apollo.game.io; -import java.io.IOException; -import java.io.InputStream; - import org.apollo.game.message.handler.MessageHandler; import org.apollo.game.message.handler.MessageHandlerChain; import org.apollo.game.message.handler.MessageHandlerChainSet; @@ -12,6 +9,9 @@ import org.apollo.util.xml.XmlParser; import org.xml.sax.SAXException; +import java.io.IOException; +import java.io.InputStream; + /** * A class that parses the {@code messages.xml} file to produce {@link MessageHandlerChainSet}s. * diff --git a/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java b/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java index d7c58121e..26626a8dc 100644 --- a/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java +++ b/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java @@ -1,15 +1,15 @@ package org.apollo.game.io; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Objects; - import org.apollo.game.plugin.PluginMetaData; import org.apollo.util.xml.XmlNode; import org.apollo.util.xml.XmlParser; import org.xml.sax.SAXException; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; + /** * A class that parses {@code plugin.xml} files into {@link PluginMetaData} objects. * diff --git a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java index ceadee44b..6391d7144 100644 --- a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java +++ b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java @@ -1,21 +1,6 @@ package org.apollo.game.io.player; -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - +import com.lambdaworks.crypto.SCryptUtil; import org.apollo.game.model.Appearance; import org.apollo.game.model.Item; import org.apollo.game.model.Position; @@ -23,25 +8,20 @@ import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.Skill; import org.apollo.game.model.entity.SkillSet; -import org.apollo.game.model.entity.attr.Attribute; -import org.apollo.game.model.entity.attr.AttributeMap; -import org.apollo.game.model.entity.attr.AttributePersistence; -import org.apollo.game.model.entity.attr.AttributeType; -import org.apollo.game.model.entity.attr.BooleanAttribute; -import org.apollo.game.model.entity.attr.NumericalAttribute; -import org.apollo.game.model.entity.attr.StringAttribute; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.game.model.entity.setting.MembershipStatus; -import org.apollo.game.model.entity.setting.PrivacyState; -import org.apollo.game.model.entity.setting.PrivilegeLevel; -import org.apollo.game.model.entity.setting.ScreenBrightness; +import org.apollo.game.model.entity.attr.*; +import org.apollo.game.model.entity.setting.*; import org.apollo.game.model.inv.Inventory; import org.apollo.net.codec.login.LoginConstants; import org.apollo.util.NameUtil; import org.apollo.util.StreamUtil; import org.apollo.util.security.PlayerCredentials; -import com.lambdaworks.crypto.SCryptUtil; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.util.Map.Entry; /** * A {@link PlayerSerializer} implementation that uses a binary file to store player data. @@ -162,7 +142,7 @@ public PlayerLoaderResponse loadPlayer(PlayerCredentials credentials) throws IOE Map> attributes = readAttributes(in); attributes.forEach(player::setAttribute); - + if (player.isBanned()) { return new PlayerLoaderResponse(LoginConstants.STATUS_ACCOUNT_DISABLED); } diff --git a/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java b/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java index eb763bd38..003115510 100644 --- a/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java +++ b/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java @@ -1,11 +1,10 @@ package org.apollo.game.io.player; -import java.util.Optional; - +import com.google.common.base.Preconditions; import org.apollo.game.model.entity.Player; import org.apollo.net.codec.login.LoginConstants; -import com.google.common.base.Preconditions; +import java.util.Optional; /** * A response for the {@link PlayerSerializer#loadPlayer} call. diff --git a/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java b/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java index 6513d9ede..1101fabe1 100644 --- a/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java +++ b/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java @@ -1,14 +1,14 @@ package org.apollo.game.login; -import java.util.logging.Level; -import java.util.logging.Logger; - import org.apollo.game.io.player.PlayerLoaderResponse; import org.apollo.game.io.player.PlayerSerializer; import org.apollo.game.session.LoginSession; import org.apollo.net.codec.login.LoginConstants; import org.apollo.net.codec.login.LoginRequest; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * A class which processes a single login request. * diff --git a/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java b/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java index 6590566c7..c1ea211a3 100644 --- a/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java +++ b/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java @@ -1,12 +1,12 @@ package org.apollo.game.login; -import java.util.logging.Level; -import java.util.logging.Logger; - import org.apollo.game.io.player.PlayerSerializer; import org.apollo.game.model.entity.Player; import org.apollo.game.session.GameSession; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * A class which processes a single save request. * diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java index a6e96c9c2..666e250e2 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java @@ -1,8 +1,5 @@ package org.apollo.game.message.handler; -import java.util.HashMap; -import java.util.Map; - import org.apollo.game.message.impl.InventoryItemMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; @@ -11,6 +8,9 @@ import org.apollo.game.model.inv.Inventory; import org.apollo.game.model.inv.SynchronizationInventoryListener; +import java.util.HashMap; +import java.util.Map; + /** * A {@link MessageHandler} that verifies {@link InventoryItemMessage}s. * diff --git a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java index b82178b1b..d38395f8a 100644 --- a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java +++ b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java @@ -1,12 +1,11 @@ package org.apollo.game.message.handler; -import java.util.ArrayList; -import java.util.List; - +import com.google.common.base.MoreObjects; import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; -import com.google.common.base.MoreObjects; +import java.util.ArrayList; +import java.util.List; /** * A chain of {@link MessageHandler}s diff --git a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java index 11c466e12..fa02222ee 100644 --- a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java +++ b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java @@ -1,13 +1,13 @@ package org.apollo.game.message.handler; +import org.apollo.game.model.entity.Player; +import org.apollo.net.message.Message; + import java.util.ArrayDeque; import java.util.Deque; import java.util.HashMap; import java.util.Map; -import org.apollo.game.model.entity.Player; -import org.apollo.net.message.Message; - /** * A group of {@link MessageHandlerChain}s classified by the {@link Message} type. * diff --git a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java index 8983cee03..34852d93f 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java @@ -1,8 +1,5 @@ package org.apollo.game.message.handler; -import java.util.List; -import java.util.Set; - import org.apollo.cache.def.ObjectDefinition; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -12,6 +9,9 @@ import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.obj.GameObject; +import java.util.List; +import java.util.Set; + /** * A verification {@link MessageHandler} for the {@link ObjectActionMessage}. * diff --git a/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java index b563243e7..8a6feab1b 100644 --- a/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java @@ -1,12 +1,11 @@ package org.apollo.game.message.impl; -import java.util.List; -import java.util.Set; - import org.apollo.game.model.Position; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.net.message.Message; +import java.util.Set; + /** * A {@link Message} sent to the client that contains multiple * diff --git a/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java b/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java index cf492c02d..127f735d1 100644 --- a/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java @@ -1,9 +1,9 @@ package org.apollo.game.message.impl; -import java.util.List; - import org.apollo.net.message.Message; +import java.util.List; + /** * A {@link Message} sent to the client that updates the ignored user list. * diff --git a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java index 9419c4c3a..969435ba8 100644 --- a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java @@ -1,6 +1,5 @@ package org.apollo.game.message.impl; -import com.google.common.base.Preconditions; import org.apollo.net.message.Message; import java.util.NoSuchElementException; diff --git a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java index 0f39bbec1..e31985ccd 100644 --- a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java @@ -1,12 +1,12 @@ package org.apollo.game.message.impl; -import java.util.List; - import org.apollo.game.model.Position; import org.apollo.game.model.entity.Npc; import org.apollo.game.sync.seg.SynchronizationSegment; import org.apollo.net.message.Message; +import java.util.List; + /** * A {@link Message} sent to the client to synchronize npcs with players. * diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java index 530450d9b..45c5cfdf1 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java @@ -1,11 +1,11 @@ package org.apollo.game.message.impl; -import java.util.List; - import org.apollo.game.model.Position; import org.apollo.game.sync.seg.SynchronizationSegment; import org.apollo.net.message.Message; +import java.util.List; + /** * A {@link Message} sent to the client to synchronize players. * diff --git a/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java b/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java index 88e84f7eb..f37d290b2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java @@ -1,10 +1,9 @@ package org.apollo.game.message.impl; +import com.google.common.base.Preconditions; import org.apollo.game.model.Position; import org.apollo.net.message.Message; -import com.google.common.base.Preconditions; - /** * A {@link Message} sent by the client to request that the player walks somewhere. * diff --git a/game/src/main/java/org/apollo/game/model/Appearance.java b/game/src/main/java/org/apollo/game/model/Appearance.java index 12febc757..7069b37b7 100644 --- a/game/src/main/java/org/apollo/game/model/Appearance.java +++ b/game/src/main/java/org/apollo/game/model/Appearance.java @@ -1,8 +1,7 @@ package org.apollo.game.model; -import org.apollo.game.model.entity.setting.Gender; - import com.google.common.base.Preconditions; +import org.apollo.game.model.entity.setting.Gender; /** * Represents the appearance of a player. diff --git a/game/src/main/java/org/apollo/game/model/Item.java b/game/src/main/java/org/apollo/game/model/Item.java index 22e0661b5..eb972b350 100644 --- a/game/src/main/java/org/apollo/game/model/Item.java +++ b/game/src/main/java/org/apollo/game/model/Item.java @@ -1,9 +1,8 @@ package org.apollo.game.model; -import org.apollo.cache.def.ItemDefinition; - import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; +import org.apollo.cache.def.ItemDefinition; /** * Represents a single item. diff --git a/game/src/main/java/org/apollo/game/model/area/Region.java b/game/src/main/java/org/apollo/game/model/area/Region.java index df7a9a170..cdb726a6f 100644 --- a/game/src/main/java/org/apollo/game/model/area/Region.java +++ b/game/src/main/java/org/apollo/game/model/area/Region.java @@ -13,12 +13,7 @@ import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.obj.DynamicGameObject; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java b/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java index 61a9b3613..7e803a88d 100644 --- a/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java +++ b/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java @@ -1,8 +1,7 @@ package org.apollo.game.model.area; -import org.apollo.game.model.Position; - import com.google.common.base.MoreObjects; +import org.apollo.game.model.Position; /** * An immutable class representing the coordinates of a region, where the coordinates ({@code x, y}) are the top-left of diff --git a/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java b/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java index 86d755f6b..4917b9a74 100644 --- a/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java +++ b/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java @@ -1,12 +1,11 @@ package org.apollo.game.model.area.collision; -import java.util.Arrays; - +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; import org.apollo.game.model.Direction; import org.apollo.game.model.entity.EntityType; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; +import java.util.Arrays; /** * A 2-dimensional adjacency matrix containing tile collision data. diff --git a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java index 710eded25..b6dc74159 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java @@ -1,5 +1,6 @@ package org.apollo.game.model.area.update; +import com.google.common.base.Preconditions; import org.apollo.game.message.impl.RegionUpdateMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.EntityUpdateType; @@ -8,8 +9,6 @@ import org.apollo.game.model.entity.Entity; import org.apollo.net.message.Message; -import com.google.common.base.Preconditions; - /** * An type that is contained in the snapshot of a {@link Region}, which consists of an {@link Entity} being added, * removed, or moved. diff --git a/game/src/main/java/org/apollo/game/model/entity/Mob.java b/game/src/main/java/org/apollo/game/model/entity/Mob.java index ec09bb9cb..9277777f4 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Mob.java +++ b/game/src/main/java/org/apollo/game/model/entity/Mob.java @@ -2,11 +2,7 @@ import org.apollo.cache.def.NpcDefinition; import org.apollo.game.action.Action; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Position; -import org.apollo.game.model.World; +import org.apollo.game.model.*; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.attr.Attribute; diff --git a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java index 3a625b713..bb911b15a 100644 --- a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java +++ b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java @@ -1,10 +1,10 @@ package org.apollo.game.model.entity; +import com.google.common.base.Preconditions; + import java.util.Iterator; import java.util.NoSuchElementException; -import com.google.common.base.Preconditions; - /** * A {@link MobRepository} is a repository of {@link Mob}s that are currently active in the game world. * @@ -40,7 +40,7 @@ private final class MobRepositoryIterator implements Iterator { /** * Constructs a new {@link MobRepositoryIterator} with the specified * MobRepository. - * + * * @param repository * The MobRepository we're iterating over. */ diff --git a/game/src/main/java/org/apollo/game/model/entity/Npc.java b/game/src/main/java/org/apollo/game/model/entity/Npc.java index 07556a873..15cdd7980 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Npc.java +++ b/game/src/main/java/org/apollo/game/model/entity/Npc.java @@ -1,14 +1,13 @@ package org.apollo.game.model.entity; -import java.util.Optional; - +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; import org.apollo.cache.def.NpcDefinition; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.sync.block.SynchronizationBlock; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; +import java.util.Optional; /** * A {@link Mob} that is not controlled by a player. diff --git a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java index 3823c2644..95345a8b3 100644 --- a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java +++ b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java @@ -1,14 +1,13 @@ package org.apollo.game.model.entity; +import com.google.common.base.Preconditions; +import com.google.common.primitives.Ints; +import org.apollo.game.model.skill.SkillListener; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apollo.game.model.skill.SkillListener; - -import com.google.common.base.Preconditions; -import com.google.common.primitives.Ints; - /** * Represents the set of the player's skills. * diff --git a/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java b/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java index 7db2579d9..36f51dd25 100644 --- a/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java +++ b/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java @@ -5,16 +5,11 @@ import org.apollo.game.model.World; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionRepository; -import org.apollo.game.model.area.collision.CollisionFlag; import org.apollo.game.model.area.collision.CollisionManager; -import org.apollo.game.model.area.collision.CollisionMatrix; import java.util.ArrayDeque; -import java.util.Arrays; import java.util.Deque; import java.util.Queue; -import java.util.logging.Logger; -import java.util.stream.Collectors; /** * A queue of {@link Direction}s which a {@link Mob} will follow. diff --git a/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java b/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java index c521e7b79..b9da4176c 100644 --- a/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java +++ b/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java @@ -1,11 +1,10 @@ package org.apollo.game.model.entity.attr; +import com.google.common.base.Preconditions; + import java.util.HashMap; import java.util.Map; - -import com.google.common.base.Preconditions; - /** * A {@link Map} wrapper used to store {@link Attribute}s and their {@link AttributeDefinition definitions}. * diff --git a/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java b/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java index 91a071d0c..e2f91fc67 100644 --- a/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java +++ b/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java @@ -1,13 +1,13 @@ package org.apollo.game.model.entity.obj; -import java.util.HashSet; -import java.util.Set; - import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.Player; +import java.util.HashSet; +import java.util.Set; + /** * A {@link GameObject} that is loaded dynamically, usually for specific Players. * diff --git a/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java b/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java index 1ceb76897..105b66294 100644 --- a/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java +++ b/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java @@ -1,8 +1,9 @@ package org.apollo.game.model.entity.obj; +import com.google.common.base.MoreObjects; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.model.Position; import org.apollo.game.model.Direction; +import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; @@ -11,8 +12,6 @@ import org.apollo.game.model.entity.Entity; import org.apollo.game.model.entity.Player; -import com.google.common.base.MoreObjects; - import static org.apollo.game.model.entity.obj.ObjectType.RECTANGULAR_CORNER; import static org.apollo.game.model.entity.obj.ObjectType.TRIANGULAR_CORNER; diff --git a/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java b/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java index 2b8482f52..b7606cbb8 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java @@ -1,18 +1,11 @@ package org.apollo.game.model.entity.path; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.PriorityQueue; -import java.util.Queue; -import java.util.Set; - import org.apollo.game.model.Direction; import org.apollo.game.model.Position; import org.apollo.game.model.area.collision.CollisionManager; +import java.util.*; + /** * A {@link PathfindingAlgorithm} that utilises the A* algorithm to find a solution. *

diff --git a/game/src/main/java/org/apollo/game/model/entity/path/Node.java b/game/src/main/java/org/apollo/game/model/entity/path/Node.java index 8be1d9aea..83dfbf321 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/Node.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/Node.java @@ -1,11 +1,10 @@ package org.apollo.game.model.entity.path; -import java.util.NoSuchElementException; -import java.util.Optional; - +import com.google.common.base.MoreObjects; import org.apollo.game.model.Position; -import com.google.common.base.MoreObjects; +import java.util.NoSuchElementException; +import java.util.Optional; /** * A Node representing a weighted {@link Position}. diff --git a/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java b/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java index dddf426e6..6b5041503 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java @@ -1,17 +1,13 @@ package org.apollo.game.model.entity.path; -import java.util.Deque; -import java.util.Optional; - +import com.google.common.base.Preconditions; import org.apollo.game.model.Direction; import org.apollo.game.model.Position; -import org.apollo.game.model.World; -import org.apollo.game.model.area.Region; -import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.game.model.entity.EntityType; -import com.google.common.base.Preconditions; +import java.util.Deque; +import java.util.Optional; /** * An algorithm used to find a path between two {@link Position}s. diff --git a/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java b/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java index 421315f83..2ac023e0b 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java @@ -1,15 +1,13 @@ package org.apollo.game.model.entity.path; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Optional; - import org.apollo.game.model.Direction; import org.apollo.game.model.Position; -import org.apollo.game.model.World; -import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.Optional; + /** * A very simple pathfinding algorithm that simply walks in the direction of the target until it either reaches it or is * blocked. diff --git a/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java b/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java index feb49670e..2abb3c3fc 100644 --- a/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java +++ b/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java @@ -1,10 +1,10 @@ package org.apollo.game.model.event; +import com.google.common.base.MoreObjects; + import java.util.ArrayList; import java.util.List; -import com.google.common.base.MoreObjects; - /** * A chain of {@link EventListener}s. * diff --git a/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java b/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java index a59a883a3..1b3d73665 100644 --- a/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java +++ b/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java @@ -2,7 +2,6 @@ import org.apollo.game.model.Item; import org.apollo.game.model.entity.Player; -import org.apollo.game.sync.block.SynchronizationBlock; /** * An {@link InventoryListener} which updates the player's appearance when any items are updated. diff --git a/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java b/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java index 7e8d61fa7..d1db4cea9 100644 --- a/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java +++ b/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java @@ -1,11 +1,5 @@ package org.apollo.game.plugin; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; - import io.github.classgraph.ClassGraph; import io.github.classgraph.ClassInfo; import io.github.classgraph.ClassInfoList; @@ -13,6 +7,12 @@ import org.apollo.game.model.World; import org.apollo.game.plugin.kotlin.KotlinPluginScript; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Logger; + public class KotlinPluginEnvironment implements PluginEnvironment { private static final Logger logger = Logger.getLogger(KotlinPluginEnvironment.class.getName()); diff --git a/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java b/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java index 505d8473e..5cd235153 100644 --- a/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java +++ b/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java @@ -1,6 +1,5 @@ package org.apollo.game.plugin; -import java.io.InputStream; import java.util.Collection; import java.util.Set; diff --git a/game/src/main/java/org/apollo/game/plugin/PluginManager.java b/game/src/main/java/org/apollo/game/plugin/PluginManager.java index 5471cb697..054f8464f 100644 --- a/game/src/main/java/org/apollo/game/plugin/PluginManager.java +++ b/game/src/main/java/org/apollo/game/plugin/PluginManager.java @@ -1,5 +1,9 @@ package org.apollo.game.plugin; +import org.apollo.game.io.PluginMetaDataParser; +import org.apollo.game.model.World; +import org.xml.sax.SAXException; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -8,10 +12,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.apollo.game.io.PluginMetaDataParser; -import org.apollo.game.model.World; -import org.xml.sax.SAXException; - /** * A class which manages plugins. * diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java index 6a0c068d5..7c25b14cd 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java @@ -1,7 +1,10 @@ package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.*; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java index 68588c853..b6ec15629 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java @@ -1,11 +1,7 @@ package org.apollo.game.release.r181.decoders.npc; import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java index 3de643870..62b98c6e3 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java @@ -2,11 +2,7 @@ import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java index 156398b1e..45494e99c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java @@ -2,7 +2,10 @@ import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; -import org.apollo.net.codec.game.*; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java index 7abbfeb6a..7a3791e2b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java @@ -1,11 +1,7 @@ package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java index f13d8bdc0..1f6843f96 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java @@ -1,7 +1,10 @@ package org.apollo.game.release.r181.decoders.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.*; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; /** diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java index 13a57c532..f15e767cf 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java @@ -1,7 +1,6 @@ package org.apollo.game.release.r181.encoders; import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; -import org.apollo.game.message.impl.encode.UpdateWeightMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java index f244a942a..a50c91778 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java @@ -1,30 +1,17 @@ package org.apollo.game.release.r181.encoders.npc; -import kotlin.UByte; import org.apollo.game.message.impl.NpcSynchronizationMessage; import org.apollo.game.model.Animation; import org.apollo.game.model.Direction; import org.apollo.game.model.Graphic; import org.apollo.game.model.Position; import org.apollo.game.model.entity.Player; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TransformBlock; -import org.apollo.game.sync.block.TurnToPositionBlock; +import org.apollo.game.sync.block.*; import org.apollo.game.sync.seg.AddNpcSegment; import org.apollo.game.sync.seg.MovementSegment; import org.apollo.game.sync.seg.SegmentType; import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.codec.game.*; import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java index b969531cd..5a6d166e0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java @@ -1,7 +1,9 @@ package org.apollo.game.release.r181.encoders.ui; import org.apollo.game.message.impl.encode.IfMoveSubMessage; -import org.apollo.net.codec.game.*; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java index b05726236..235cc08db 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java @@ -1,7 +1,6 @@ package org.apollo.game.release.r181.encoders.ui; import org.apollo.game.message.impl.encode.IfOpenSubMessage; -import org.apollo.game.message.impl.encode.IfOpenTopMessage; import org.apollo.net.codec.game.*; import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; diff --git a/game/src/main/java/org/apollo/game/scheduling/Scheduler.java b/game/src/main/java/org/apollo/game/scheduling/Scheduler.java index f81913949..380af33dd 100644 --- a/game/src/main/java/org/apollo/game/scheduling/Scheduler.java +++ b/game/src/main/java/org/apollo/game/scheduling/Scheduler.java @@ -2,11 +2,7 @@ import org.apollo.util.CollectionUtil; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Queue; +import java.util.*; /** * A class which manages {@link ScheduledTask}s. diff --git a/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java b/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java index 66342f313..22283a6bb 100644 --- a/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java +++ b/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java @@ -1,21 +1,14 @@ package org.apollo.game.scheduling.impl; -import java.util.Comparator; -import java.util.Deque; -import java.util.PriorityQueue; -import java.util.Queue; -import java.util.Random; - +import com.google.common.base.Preconditions; import org.apollo.game.model.Position; -import org.apollo.game.model.World; -import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.game.model.entity.Npc; import org.apollo.game.model.entity.WalkingQueue; import org.apollo.game.model.entity.path.SimplePathfindingAlgorithm; import org.apollo.game.scheduling.ScheduledTask; -import com.google.common.base.Preconditions; +import java.util.*; /** * A {@link ScheduledTask} that causes {@link Npc}s to randomly walk around in their boundary. diff --git a/game/src/main/java/org/apollo/game/session/ApolloHandler.java b/game/src/main/java/org/apollo/game/session/ApolloHandler.java index 7c8629de2..13adc56fb 100644 --- a/game/src/main/java/org/apollo/game/session/ApolloHandler.java +++ b/game/src/main/java/org/apollo/game/session/ApolloHandler.java @@ -7,16 +7,14 @@ import io.netty.handler.codec.http.HttpRequest; import io.netty.util.Attribute; import io.netty.util.AttributeKey; -import io.netty.util.ReferenceCountUtil; - -import java.util.logging.Level; -import java.util.logging.Logger; - import org.apollo.ServerContext; import org.apollo.net.codec.handshake.HandshakeConstants; import org.apollo.net.codec.handshake.HandshakeMessage; import org.apollo.net.codec.jaggrab.JagGrabRequest; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * An implementation of {@link ChannelInboundHandlerAdapter} which handles incoming upstream events from Netty. * diff --git a/game/src/main/java/org/apollo/game/session/GameSession.java b/game/src/main/java/org/apollo/game/session/GameSession.java index 4c817a8b5..c61a3db89 100644 --- a/game/src/main/java/org/apollo/game/session/GameSession.java +++ b/game/src/main/java/org/apollo/game/session/GameSession.java @@ -3,12 +3,6 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; - -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.logging.Level; -import java.util.logging.Logger; - import org.apollo.ServerContext; import org.apollo.game.GameConstants; import org.apollo.game.message.handler.MessageHandlerChainSet; @@ -16,6 +10,11 @@ import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * A game session. * diff --git a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java index 6827b838c..edc966de6 100644 --- a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java @@ -6,14 +6,7 @@ import org.apollo.game.model.entity.Npc; import org.apollo.game.model.entity.Player; import org.apollo.game.service.GameService; -import org.apollo.game.sync.task.NpcSynchronizationTask; -import org.apollo.game.sync.task.PhasedSynchronizationTask; -import org.apollo.game.sync.task.PlayerSynchronizationTask; -import org.apollo.game.sync.task.PostNpcSynchronizationTask; -import org.apollo.game.sync.task.PostPlayerSynchronizationTask; -import org.apollo.game.sync.task.PreNpcSynchronizationTask; -import org.apollo.game.sync.task.PrePlayerSynchronizationTask; -import org.apollo.game.sync.task.SynchronizationTask; +import org.apollo.game.sync.task.*; import org.apollo.util.ThreadUtil; import java.util.Map; diff --git a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java index 90e0a8c09..e5309d3d7 100644 --- a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java @@ -1,23 +1,16 @@ package org.apollo.game.sync; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.apollo.game.message.impl.RegionUpdateMessage; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; import org.apollo.game.model.entity.Player; import org.apollo.game.service.GameService; -import org.apollo.game.sync.task.NpcSynchronizationTask; -import org.apollo.game.sync.task.PlayerSynchronizationTask; -import org.apollo.game.sync.task.PostNpcSynchronizationTask; -import org.apollo.game.sync.task.PostPlayerSynchronizationTask; -import org.apollo.game.sync.task.PreNpcSynchronizationTask; -import org.apollo.game.sync.task.PrePlayerSynchronizationTask; -import org.apollo.game.sync.task.SynchronizationTask; +import org.apollo.game.sync.task.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; /** * An implementation of {@link ClientSynchronizer} which runs in a single thread (the {@link GameService} thread from diff --git a/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java b/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java index b0ddf203c..6a89c328c 100644 --- a/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java +++ b/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java @@ -1,10 +1,9 @@ package org.apollo.game.sync.seg; +import com.google.common.base.Preconditions; import org.apollo.game.model.Direction; import org.apollo.game.sync.block.SynchronizationBlockSet; -import com.google.common.base.Preconditions; - /** * A {@link SynchronizationSegment} where a mob is moved (or doesn't move!). * diff --git a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java index 3448bb284..f0cfc4a91 100644 --- a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java @@ -1,11 +1,5 @@ package org.apollo.game.sync.task; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - import org.apollo.game.message.impl.NpcSynchronizationMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; @@ -19,6 +13,12 @@ import org.apollo.game.sync.seg.RemoveMobSegment; import org.apollo.game.sync.seg.SynchronizationSegment; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + /** * A {@link SynchronizationTask} which synchronizes npcs with the specified {@link Player}. * diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index 123f3e6d6..069a0ce64 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -1,11 +1,5 @@ package org.apollo.game.sync.task; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - import org.apollo.game.message.impl.PlayerSynchronizationMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; @@ -17,11 +11,13 @@ import org.apollo.game.sync.block.ChatBlock; import org.apollo.game.sync.block.SynchronizationBlock; import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.seg.AddPlayerSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.RemoveMobSegment; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; +import org.apollo.game.sync.seg.*; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; /** * A {@link SynchronizationTask} which synchronizes the specified {@link Player} . @@ -140,7 +136,7 @@ public void run() { /** * Tests whether or not the specified Player has a cached appearance within * the specified appearance ticket array. - * + * * @param appearanceTickets The appearance tickets. * @param index The index of the Player. * @param appearanceTicket The current appearance ticket for the Player. diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 59c09be26..6490a060e 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -1,19 +1,19 @@ package org.apollo.game.sync.task; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - import org.apollo.game.message.impl.ClearRegionMessage; import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.encode.RebuildNormalMessage; import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RebuildNormalMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.Player; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + /** * A {@link SynchronizationTask} which does pre-synchronization work for the specified {@link Player}. * diff --git a/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt b/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt index 9f1bd9fd9..3c817e9ca 100644 --- a/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt +++ b/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt @@ -1,12 +1,12 @@ package org.apollo.game.action +import kotlinx.coroutines.suspendCancellableCoroutine import java.util.concurrent.CancellationException import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicReference +import kotlin.coroutines.* import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn -import kotlinx.coroutines.suspendCancellableCoroutine -import kotlin.coroutines.* typealias ActionPredicate = () -> Boolean typealias ActionBlock = suspend ActionCoroutine.() -> Unit diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java index e332b0672..dab17277e 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java @@ -8,13 +8,12 @@ import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inv.Inventory; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; import static org.powermock.api.mockito.PowerMockito.*; @RunWith(PowerMockRunner.class) diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java index 8d0908c08..b86fe0376 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java @@ -12,7 +12,6 @@ import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.obj.StaticGameObject; -import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inv.Inventory; import org.apollo.game.model.inv.SynchronizationInventoryListener; import org.junit.Before; diff --git a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java index 3f6913917..ab9c14860 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java @@ -1,6 +1,5 @@ package org.apollo.game.message.handler; -import org.apollo.cache.def.ItemDefinition; import org.apollo.cache.def.ObjectDefinition; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -12,7 +11,6 @@ import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.obj.StaticGameObject; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -21,10 +19,8 @@ import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.*; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.junit.Assert.assertTrue; +import static org.powermock.api.mockito.PowerMockito.*; @RunWith(PowerMockRunner.class) @PrepareForTest({World.class, Player.class, ObjectDefinition.class, RegionRepository.class, Region.class}) diff --git a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java index 18f80ccfa..e0791c8b2 100644 --- a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java @@ -9,8 +9,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import static org.junit.Assert.*; -import static org.powermock.api.mockito.PowerMockito.*; +import static org.junit.Assert.assertTrue; +import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) diff --git a/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java b/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java index 0396789c5..a66cc09c8 100644 --- a/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java @@ -1,22 +1,20 @@ package org.apollo.game.model.entity; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -import java.util.Iterator; -import java.util.NoSuchElementException; - import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; +import java.util.Iterator; +import java.util.NoSuchElementException; + +import static org.junit.Assert.*; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; + /** * Tests the {@link MobRepository} class. - * + * * @author Ryley */ @RunWith(PowerMockRunner.class) diff --git a/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java b/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java index 32019becc..03f8ba3a3 100644 --- a/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Tests the {@link SkillSet} class. diff --git a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java index a7ee6e2da..96a0a4c83 100644 --- a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java @@ -3,7 +3,6 @@ import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.Region; -import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.util.security.PlayerCredentials; import org.junit.Test; diff --git a/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java b/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java index bbd656f8f..ee065b4a8 100644 --- a/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java @@ -1,12 +1,11 @@ package org.apollo.game.model.entity.attr; -import java.nio.charset.StandardCharsets; - +import com.google.common.primitives.Longs; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import com.google.common.primitives.Longs; +import java.nio.charset.StandardCharsets; /** * Tests for different {@link Attribute}s. From 3ac6b6b85efee534f8e89c7def3bd80d410082ac Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 15 Mar 2020 09:05:52 -0400 Subject: [PATCH 22/63] Added the plugins for shops back with proper npc ids. --- .../decoder/rsenum/EnumDefinitionDecoder.java | 2 +- .../org/apollo/cache/def/EnumDefinition.java | 1 + .../locations/al-kharid/src/npcs.plugin.kts | 114 ++++++++ .../locations/al-kharid/src/shops.plugin.kts | 146 ++++++++++ .../locations/edgeville/src/npcs.plugin.kts | 53 ++++ .../locations/edgeville/src/shops.plugin.kts | 31 ++ .../locations/falador/src/npcs.plugin.kts | 171 +++++++++++ .../locations/falador/src/shops.plugin.kts | 76 +++++ .../locations/lumbridge/src/npcs.plugin.kts | 15 + .../locations/lumbridge/src/shops.plugin.kts | 42 +++ .../tutorial-island/src/npcs.plugin.kts | 44 +++ .../locations/varrock/src/npcs.plugin.kts | 268 ++++++++++++++++++ .../locations/varrock/src/shops.plugin.kts | 176 ++++++++++++ 13 files changed, 1138 insertions(+), 1 deletion(-) create mode 100644 game/plugin/locations/al-kharid/src/npcs.plugin.kts create mode 100644 game/plugin/locations/al-kharid/src/shops.plugin.kts create mode 100644 game/plugin/locations/edgeville/src/npcs.plugin.kts create mode 100644 game/plugin/locations/edgeville/src/shops.plugin.kts create mode 100644 game/plugin/locations/falador/src/npcs.plugin.kts create mode 100644 game/plugin/locations/falador/src/shops.plugin.kts create mode 100644 game/plugin/locations/lumbridge/src/npcs.plugin.kts create mode 100644 game/plugin/locations/lumbridge/src/shops.plugin.kts create mode 100644 game/plugin/locations/tutorial-island/src/npcs.plugin.kts create mode 100644 game/plugin/locations/varrock/src/npcs.plugin.kts create mode 100644 game/plugin/locations/varrock/src/shops.plugin.kts diff --git a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java index 2345d50ed..f690ec9b2 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java @@ -11,7 +11,7 @@ /** * Decodes item data from the {@code obj.dat} file into {@link EnumDefinition}s. * - * @author Graham + * @author Cjay0091 */ public final class EnumDefinitionDecoder implements Runnable { diff --git a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java index ea5ccba49..cd15cfbd7 100644 --- a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.Map; + public final class EnumDefinition { private static final Map definitions = new HashMap<>(); diff --git a/game/plugin/locations/al-kharid/src/npcs.plugin.kts b/game/plugin/locations/al-kharid/src/npcs.plugin.kts new file mode 100644 index 000000000..79b74471c --- /dev/null +++ b/game/plugin/locations/al-kharid/src/npcs.plugin.kts @@ -0,0 +1,114 @@ +package org.apollo.plugin.locations.alKharid + +import org.apollo.game.model.Direction +import org.apollo.game.plugin.entity.spawn.spawnNpc + +// Generic npcs + +spawnNpc("man", x = 3276, y = 3186) +spawnNpc("man", x = 3282, y = 3197) + +spawnNpc("man", id = 3, x = 3301, y = 3200) +spawnNpc("man", id = 3, x = 3300, y = 3208) + +spawnNpc("man", id = 2, x = 3297, y = 3196) + +spawnNpc("man", id = 16, x = 3294, y = 3204) + +spawnNpc("spider", x = 3319, y = 3145) +spawnNpc("spider", x = 3319, y = 3140) +spawnNpc("spider", x = 3323, y = 3138) + +spawnNpc("scorpion", x = 3282, y = 3149) + +// Camels + +spawnNpc("cam_the_camel", x = 3295, y = 3232) +spawnNpc("elly_the_camel", x = 3312, y = 3210) +spawnNpc("camel", x = 3285, y = 3198) +spawnNpc("ollie_the_camel", x = 3291, y = 3209) +spawnNpc("al_the_camel", x = 3275, y = 3162) + +// Quest npc + +spawnNpc("osman", x = 3286, y = 3180, facing = Direction.EAST) + +spawnNpc("hassan", x = 3302, y = 3163) + +spawnNpc("father_reen", x = 3272, y = 3158) + +spawnNpc("man", id = 663, x = 3297, y = 3287) + +// Boarder guards + +spawnNpc("border_guard", x = 3268, y = 3226) +spawnNpc("border_guard", x = 3267, y = 3226) +spawnNpc("border_guard", x = 3268, y = 3229, facing = Direction.SOUTH) +spawnNpc("border_guard", x = 3267, y = 3229, facing = Direction.SOUTH) + +// Palace guards + +spawnNpc("Al-Kharid warrior", x = 3285, y = 3174) +spawnNpc("Al-Kharid warrior", x = 3283, y = 3168) +spawnNpc("Al-Kharid warrior", x = 3285, y = 3169) +spawnNpc("Al-Kharid warrior", x = 3290, y = 3162) +spawnNpc("Al-Kharid warrior", x = 3295, y = 3170) +spawnNpc("Al-Kharid warrior", x = 3300, y = 3175) +spawnNpc("Al-Kharid warrior", x = 3300, y = 3171) +spawnNpc("Al-Kharid warrior", x = 3301, y = 3168) + +// Shanty pass + +spawnNpc("shantay_guard", x = 3301, y = 3120) +spawnNpc("shantay_guard", x = 3302, y = 3126) +spawnNpc("shantay_guard", x = 3306, y = 3126) +spawnNpc("shantay_guard", id = 838, x = 3303, y = 3118) + +// Mine + +spawnNpc("scorpion", x = 3296, y = 3294) +spawnNpc("scorpion", x = 3298, y = 3280) +spawnNpc("scorpion", x = 3299, y = 3299) +spawnNpc("scorpion", x = 3299, y = 3309) +spawnNpc("scorpion", x = 3300, y = 3287) +spawnNpc("scorpion", x = 3300, y = 3315) +spawnNpc("scorpion", x = 3301, y = 3305) +spawnNpc("scorpion", x = 3301, y = 3312) + +// Functional npcs + +spawnNpc("gnome_pilot", x = 3279, y = 3213) + +spawnNpc("banker", id = 496, x = 3267, y = 3164, facing = Direction.EAST) +spawnNpc("banker", id = 496, x = 3267, y = 3167, facing = Direction.EAST) +spawnNpc("banker", id = 496, x = 3267, y = 3169, facing = Direction.EAST) + +spawnNpc("banker", id = 497, x = 3267, y = 3166, facing = Direction.EAST) +spawnNpc("banker", id = 497, x = 3267, y = 3168, facing = Direction.EAST) + +spawnNpc("gem_trader", x = 3287, y = 3210) + +spawnNpc("zeke", x = 3289, y = 3189) + +spawnNpc("shantay", x = 3304, y = 3124) + +spawnNpc("rug_merchant", id = 2296, x = 3311, y = 3109, facing = Direction.WEST) + +spawnNpc("ranael", x = 3315, y = 3163) + +spawnNpc("shop_keeper", id = 524, x = 3315, y = 3178) +spawnNpc("shop_assistant", id = 525, x = 3315, y = 3180, facing = Direction.WEST) + +spawnNpc("louie_legs", x = 3316, y = 3175, facing = Direction.WEST) + +spawnNpc("ellis", x = 3274, y = 3192) + +spawnNpc("dommik", x = 3321, y = 3193) + +spawnNpc("tool_leprechaun", x = 3319, y = 3204) + +spawnNpc("ali_morrisane", x = 3304, y = 3211, facing = Direction.EAST) + +spawnNpc("silk_trader", x = 3300, y = 3203) + +spawnNpc("karim", x = 3273, y = 3180) \ No newline at end of file diff --git a/game/plugin/locations/al-kharid/src/shops.plugin.kts b/game/plugin/locations/al-kharid/src/shops.plugin.kts new file mode 100644 index 000000000..94219655c --- /dev/null +++ b/game/plugin/locations/al-kharid/src/shops.plugin.kts @@ -0,0 +1,146 @@ +package org.apollo.plugin.locations.alKharid + +import org.apollo.game.plugin.shops.builder.shop + +shop("Al-Kharid General Store") { + operated by "Shop keeper"(506) and "Shop assistant"(507) + buys any items + + sell(5) of "Pot" + sell(2) of "Jug" + sell(2) of "Shears" + sell(3) of "Bucket" + sell(2) of "Bowl" + sell(2) of "Cake tin" + sell(2) of "Tinderbox" + sell(2) of "Chisel" + sell(5) of "Hammer" + sell(5) of "Newcomer map" +} + +/** + * TODO add a way to "unlock" items, as more of Ali Morrisane's items are unlocked by completing certain parts of + * the Rogue Trader minigame progressively. + * + * TODO this shop can be accessed only through dialogue, so support for that should be added. + */ +/*shop("Ali's Discount Wares") { + operated by "Ali Morrisane" + + sell(3) of "Pot" + sell(2) of "Jug" + sell(10) of { "Waterskin"(1825) } + sell(3) of "Desert shirt" + sell(2) of "Desert boots" + sell(19) of "Bucket" + sell(11) of "Fake beard" + sell(12) of "Karidian headpiece" + sell(50) of "Papyrus" + sell(5) of "Knife" + sell(11) of "Tinderbox" + sell(23) of "Bronze pickaxe" + sell(15) of "Raw chicken" +}*/ + +shop("Dommik's Crafting Store") { + operated by "Dommik" + + sell(2) of "Chisel" + category("mould") { + sell(10) of "Ring" + sell(2) of "Necklace" + sell(10) of "Amulet" + } + sell(3) of "Needle" + sell(100) of "Thread" + category("mould") { + sell(3) of "Holy" + sell(10) of "Sickle" + sell(10) of "Tiara" + } +} + +shop("Gem Trader") { + operated by "Gem trader" + + category("uncut", affix = prefix) { + sell(1) of { + -"Sapphire" + -"Emerald" + } + sell(0) of { + -"Ruby" + -"Diamond" + } + } + + sell(1) of { + -"Sapphire" + -"Emerald" + } + sell(0) of { + -"Ruby" + -"Diamond" + } +} + +shop("Louie's Armoured Legs Bazaar") { + operated by "Louie Legs" + + category("platelegs", depluralise = false) { + sell(5) of "Bronze" + sell(3) of "Iron" + sell(2) of "Steel" + sell(1) of "Black" + sell(1) of "Mithril" + sell(1) of "Adamant" + } +} + +shop("Ranael's Super Skirt Store") { + operated by "Ranael" + + category("plateskirt") { + sell(5) of "Bronze" + sell(3) of "Iron" + sell(2) of "Steel" + sell(1) of "Black" + sell(1) of "Mithril" + sell(1) of "Adamant" + } +} + +shop("Shantay Pass Shop") { + operated by "Shantay" + + sell(100) of { "Waterskin"(1823) } + sell(100) of { "Waterskin"(1831) } + sell(10) of "Jug of water" + sell(10) of "Bowl of water" + sell(10) of "Bucket of water" + sell(10) of "Knife" + category("desert", affix = prefix) { + sell(10) of "shirt" + sell(10) of "robe" + sell(10) of "boots" + } + sell(10) of "Bronze bar" + sell(500) of "Feather" + sell(10) of "Hammer" + sell(0) of "Bucket" + sell(0) of "Bowl" + sell(0) of "Jug" + sell(500) of "Shantay pass" + sell(20) of "Rope" +} + +shop("Zeke's Superior Scimitars") { + operated by "Zeke" + + category("scimitar") { + sell(5) of "Bronze" + sell(3) of "Iron" + sell(2) of "Steel" + sell(1) of "Mithril" + } +} \ No newline at end of file diff --git a/game/plugin/locations/edgeville/src/npcs.plugin.kts b/game/plugin/locations/edgeville/src/npcs.plugin.kts new file mode 100644 index 000000000..d89e84926 --- /dev/null +++ b/game/plugin/locations/edgeville/src/npcs.plugin.kts @@ -0,0 +1,53 @@ +package org.apollo.plugin.locations.edgeville + +import org.apollo.game.model.Direction +import org.apollo.game.plugin.entity.spawn.spawnNpc + +// Generic npcs + +spawnNpc("man", x = 3095, y = 3508) +spawnNpc("man", x = 3095, y = 3511) +spawnNpc("man", x = 3098, y = 3509) +spawnNpc("man", id = 2, x = 3093, y = 3511) +spawnNpc("man", id = 3, x = 3097, y = 3508) +spawnNpc("man", id = 3, x = 3092, y = 3508) +spawnNpc("man", id = 3, x = 3097, y = 3512) + +spawnNpc("guard", x = 3086, y = 3516) +spawnNpc("guard", x = 3094, y = 3518) +spawnNpc("guard", x = 3108, y = 3514) +spawnNpc("guard", x = 3110, y = 3514) +spawnNpc("guard", x = 3113, y = 3514) +spawnNpc("guard", x = 3113, y = 3516) + +spawnNpc("sheep", id = 43, x = 3050, y = 3516) +spawnNpc("sheep", id = 43, x = 3051, y = 3514) +spawnNpc("sheep", id = 43, x = 3056, y = 3517) +spawnNpc("ram", id = 3673, x = 3048, y = 3515) + +spawnNpc("monk", x = 3044, y = 3491) +spawnNpc("monk", x = 3045, y = 3483) +spawnNpc("monk", x = 3045, y = 3497) +spawnNpc("monk", x = 3050, y = 3490) +spawnNpc("monk", x = 3054, y = 3490) +spawnNpc("monk", x = 3058, y = 3497) + +// Functional npcs + +spawnNpc("richard", x = 3098, y = 3516) +spawnNpc("doris", x = 3079, y = 3491) +spawnNpc("brother_jered", x = 3045, y = 3488) +spawnNpc("brother_althric", x = 3054, y = 3504) + +spawnNpc("abbot_langley", x = 3059, y = 3484) +spawnNpc("oziach", x = 3067, y = 3518, facing = Direction.EAST) + +spawnNpc("shop_keeper", id = 528, x = 3079, y = 3509) +spawnNpc("shop_assistant", id = 529, x = 3082, y = 3513) + +spawnNpc("banker", x = 3096, y = 3489, facing = Direction.WEST) +spawnNpc("banker", x = 3096, y = 3491, facing = Direction.WEST) +spawnNpc("banker", x = 3096, y = 3492) +spawnNpc("banker", x = 3098, y = 3492) + +spawnNpc("mage_of_zamorak", x = 3106, y = 3560) \ No newline at end of file diff --git a/game/plugin/locations/edgeville/src/shops.plugin.kts b/game/plugin/locations/edgeville/src/shops.plugin.kts new file mode 100644 index 000000000..fd040c6f0 --- /dev/null +++ b/game/plugin/locations/edgeville/src/shops.plugin.kts @@ -0,0 +1,31 @@ +package org.apollo.plugin.locations.edgeville + +import org.apollo.game.plugin.shops.builder.shop + +shop("Edgeville General Store") { + operated by "Shop keeper"(510) and "Shop assistant"(509) + buys any items + + sell(5) of "Pot" + sell(2) of "Jug" + sell(2) of "Shears" + sell(3) of "Bucket" + sell(2) of "Bowl" + sell(2) of "Cake tin" + sell(2) of "Tinderbox" + sell(2) of "Chisel" + sell(5) of "Hammer" + sell(5) of "Newcomer map" +} + +/** + * TODO make a way to have requirements to open shops. Players have to have finished Dragon Slayer to access + * "Oziach's Armour" + */ +shop("Oziach's Armour") { + operated by "Oziach" + + sell(2) of "Rune platebody" + sell(2) of "Green d'hide body" + sell(35) of "Anti-dragon shield" +} \ No newline at end of file diff --git a/game/plugin/locations/falador/src/npcs.plugin.kts b/game/plugin/locations/falador/src/npcs.plugin.kts new file mode 100644 index 000000000..9136f9c09 --- /dev/null +++ b/game/plugin/locations/falador/src/npcs.plugin.kts @@ -0,0 +1,171 @@ +package org.apollo.plugin.locations.falador + +import org.apollo.game.plugin.entity.spawn.spawnNpc + +// Generic npcs + +spawnNpc("chicken", x = 2965, y = 3345) + +spawnNpc("duck", x = 2988, y = 3383) +spawnNpc("duck", x = 2992, y = 3383) +spawnNpc("duck", x = 2993, y = 3385) + +spawnNpc("drunken_man", x = 2957, y = 3368, z = 1) + +spawnNpc("dwarf", id = 118, x = 3023, y = 3334) +spawnNpc("dwarf", id = 118, x = 3027, y = 3341) +spawnNpc("dwarf", id = 118, x = 3012, y = 3341) +spawnNpc("dwarf", id = 118, x = 3017, y = 3346, z = 1) +spawnNpc("dwarf", id = 118, x = 3011, y = 3341, z = 1) + +spawnNpc("dwarf", id = 121, x = 3027, y = 3341) + +spawnNpc("dwarf", id = 382, x = 3017, y = 3340) + +spawnNpc("dwarf", id = 3294, x = 3022, y = 3338) +spawnNpc("dwarf", id = 3295, x = 3021, y = 3341) + +spawnNpc("gardener", x = 2998, y = 3385) +spawnNpc("gardener", x = 3019, y = 3369) +spawnNpc("gardener", id = 3234, x = 3016, y = 3386) + +spawnNpc("guard", x = 2965, y = 3394) +spawnNpc("guard", x = 2964, y = 3396) +spawnNpc("guard", x = 2966, y = 3397) +spawnNpc("guard", x = 2964, y = 3384) +spawnNpc("guard", x = 2963, y = 3380) +spawnNpc("guard", x = 3006, y = 3325) +spawnNpc("guard", x = 3008, y = 3320) +spawnNpc("guard", x = 3006, y = 3322) +spawnNpc("guard", x = 3038, y = 3356) + +spawnNpc("guard", id = 10, x = 2942, y = 3375) +spawnNpc("guard", id = 10, x = 3040, y = 3352) + +spawnNpc("guard", id = 3230, x = 2967, y = 3395) +spawnNpc("guard", id = 3230, x = 2966, y = 3392) +spawnNpc("guard", id = 3230, x = 2963, y = 3376) +spawnNpc("guard", id = 3230, x = 2954, y = 3382) +spawnNpc("guard", id = 3230, x = 2950, y = 3377) +spawnNpc("guard", id = 3230, x = 2968, y = 3381) + +spawnNpc("guard", id = 3231, x = 3033, y = 3389, z = 1) +spawnNpc("guard", id = 3231, x = 3041, y = 3388, z = 1) +spawnNpc("guard", id = 3231, x = 3048, y = 3389, z = 1) +spawnNpc("guard", id = 3231, x = 3056, y = 3389, z = 1) +spawnNpc("guard", id = 3231, x = 3062, y = 3386, z = 1) +spawnNpc("guard", id = 3231, x = 3058, y = 3329, z = 1) +spawnNpc("guard", id = 3231, x = 3050, y = 3329, z = 1) +spawnNpc("guard", id = 3231, x = 3038, y = 3329, z = 1) +spawnNpc("guard", id = 3231, x = 3029, y = 3329, z = 1) + +spawnNpc("swan", x = 2960, y = 3359) +spawnNpc("swan", x = 2963, y = 3360) +spawnNpc("swan", x = 2968, y = 3359) +spawnNpc("swan", x = 2971, y = 3360) +spawnNpc("swan", x = 2976, y = 3358) +spawnNpc("swan", x = 2989, y = 3384) + +spawnNpc("man", id = 3223, x = 2991, y = 3365) +spawnNpc("man", id = 3225, x = 3037, y = 3345, z = 1) + +spawnNpc("white_knight", x = 2983, y = 3343) +spawnNpc("white_knight", x = 2981, y = 3334) +spawnNpc("white_knight", x = 2988, y = 3335) +spawnNpc("white_knight", x = 2996, y = 3342) +spawnNpc("white_knight", x = 2960, y = 3340) +spawnNpc("white_knight", x = 2962, y = 3336) +spawnNpc("white_knight", x = 2974, y = 3342) +spawnNpc("white_knight", x = 2972, y = 3345) +spawnNpc("white_knight", x = 2977, y = 3348) + +spawnNpc("white_knight", id = 3348, x = 2971, y = 3340) +spawnNpc("white_knight", id = 3348, x = 2978, y = 3350) + +spawnNpc("white_knight", x = 2964, y = 3330, z = 1) +spawnNpc("white_knight", x = 2968, y = 3334, z = 1) +spawnNpc("white_knight", x = 2969, y = 3339, z = 1) +spawnNpc("white_knight", x = 2978, y = 3332, z = 1) +spawnNpc("white_knight", x = 2958, y = 3340, z = 1) +spawnNpc("white_knight", x = 2960, y = 3343, z = 1) + +spawnNpc("white_knight", id = 3348, x = 2987, y = 3334, z = 1) +spawnNpc("white_knight", id = 3348, x = 2983, y = 3336, z = 1) +spawnNpc("white_knight", id = 3348, x = 2987, y = 3334, z = 1) +spawnNpc("white_knight", id = 3348, x = 2979, y = 3348, z = 1) +spawnNpc("white_knight", id = 3348, x = 2964, y = 3337, z = 1) + +spawnNpc("white_knight", id = 3349, x = 2989, y = 3344, z = 1) + +spawnNpc("white_knight", x = 2985, y = 3342, z = 2) + +spawnNpc("white_knight", id = 3348, x = 2979, y = 3348, z = 2) +spawnNpc("white_knight", id = 3348, x = 2974, y = 3329, z = 2) +spawnNpc("white_knight", id = 3348, x = 2982, y = 3341, z = 2) + +spawnNpc("white_knight", id = 3349, x = 2990, y = 3341, z = 2) +spawnNpc("white_knight", id = 3349, x = 2971, y = 3330, z = 2) +spawnNpc("white_knight", id = 3349, x = 2965, y = 3350, z = 2) +spawnNpc("white_knight", id = 3349, x = 2965, y = 3329, z = 2) + +spawnNpc("white_knight", id = 3350, x = 2961, y = 3347, z = 2) + +spawnNpc("white_knight", id = 3349, x = 2962, y = 3339, z = 3) + +spawnNpc("white_knight", id = 3350, x = 2960, y = 3336, z = 3) +spawnNpc("white_knight", id = 3350, x = 2984, y = 3349, z = 3) + +spawnNpc("woman", id = 3226, x = 2991, y = 3384) + +// Functional npcs + +spawnNpc("apprentice_workman", id = 3235, x = 2971, y = 3369, z = 1) + +spawnNpc("banker", id = 495, x = 2945, y = 3366) +spawnNpc("banker", id = 495, x = 2946, y = 3366) +spawnNpc("banker", id = 495, x = 2947, y = 3366) +spawnNpc("banker", id = 495, x = 2948, y = 3366) + +spawnNpc("banker", x = 2949, y = 3366) + +spawnNpc("banker", x = 3015, y = 3353) +spawnNpc("banker", x = 3014, y = 3353) +spawnNpc("banker", x = 3013, y = 3353) +spawnNpc("banker", x = 3012, y = 3353) +spawnNpc("banker", x = 3011, y = 3353) +spawnNpc("banker", x = 3010, y = 3353) + +spawnNpc("cassie", x = 2976, y = 3383) + +spawnNpc("emily", x = 2954, y = 3372) + +spawnNpc("flynn", x = 2950, y = 3387) + +spawnNpc("hairdresser", x = 2944, y = 3380) + +spawnNpc("herquin", x = 2945, y = 3335) + +spawnNpc("heskel", x = 3007, y = 3374) + +spawnNpc("kaylee", x = 2957, y = 3372) + +spawnNpc("tina", x = 2955, y = 3371, z = 1) + +spawnNpc("tool_leprechaun", x = 3005, y = 3370) + +spawnNpc("squire", x = 2977, y = 3343) + +spawnNpc("sir_tiffy_cashien", x = 2997, y = 3373) + +spawnNpc("sir_amik_varze", x = 2960, y = 3336, z = 2) + +spawnNpc("sir_vyvin", x = 2983, y = 3335, z = 2) + +spawnNpc("shop_keeper", id = 524, x = 2955, y = 3389) +spawnNpc("shop_assistant", id = 525, x = 2957, y = 3387) + +spawnNpc("wayne", x = 2972, y = 3312) + +spawnNpc("workman", id = 3236, x = 2975, y = 3369, z = 1) + +spawnNpc("wyson_the_gardener", x = 3028, y = 3381) \ No newline at end of file diff --git a/game/plugin/locations/falador/src/shops.plugin.kts b/game/plugin/locations/falador/src/shops.plugin.kts new file mode 100644 index 000000000..d6f22a909 --- /dev/null +++ b/game/plugin/locations/falador/src/shops.plugin.kts @@ -0,0 +1,76 @@ +package org.apollo.plugin.locations.falador + +import org.apollo.game.plugin.shops.builder.shop + +shop("Falador General Store") { + operated by "Shop keeper"(512) and "Shop assistant"( 511) + buys any items + + sell(5) of "Pot" + sell(2) of "Jug" + sell(2) of "Shears" + sell(3) of "Bucket" + sell(2) of "Bowl" + sell(2) of "Cake tin" + sell(2) of "Tinderbox" + sell(2) of "Chisel" + sell(5) of "Hammer" + sell(5) of "Newcomer map" +} + +shop("Cassie's Shield Shop") { + operated by "Cassie" + + sell(5) of "Wooden shield" + sell(3) of "Bronze sq shield" + sell(3) of "Bronze kiteshield" + sell(2) of "Iron sq shield" + sell(0) of "Iron kiteshield" + sell(0) of "Steel sq shield" + sell(0) of "Steel kiteshield" + sell(0) of "Mithril sq shield" +} + +shop("Flynn's Mace Market") { + operated by "Flynn" + + category("mace") { + sell(5) of "Bronze" + sell(4) of "Iron" + sell(3) of "Mithril" + sell(2) of "Adamant" + } +} + +shop("Herquin's Gems") { + operated by "Herquin" + + category("uncut", affix = prefix) { + sell(1) of "Sapphire" + sell(0) of { + -"Emerald" + -"Ruby" + -"Diamond" + } + } + + sell(1) of "Sapphire" + sell(0) of { + -"Emerald" + -"Ruby" + -"Diamond" + } +} + +shop("Wayne's Chains - Chainmail Specialist") { + operated by "Wayne" + + category("chainbody") { + sell(3) of "Bronze" + sell(2) of "Iron" + sell(1) of "Steel" + sell(1) of "Black" + sell(1) of "Mithril" + sell(1) of "Adamant" + } +} \ No newline at end of file diff --git a/game/plugin/locations/lumbridge/src/npcs.plugin.kts b/game/plugin/locations/lumbridge/src/npcs.plugin.kts new file mode 100644 index 000000000..03094618d --- /dev/null +++ b/game/plugin/locations/lumbridge/src/npcs.plugin.kts @@ -0,0 +1,15 @@ +package org.apollo.plugin.locations.lumbridge + +import org.apollo.game.plugin.entity.spawn.spawnNpc + +spawnNpc("woman", id = 4, x = 3232, y = 3207) +spawnNpc("man", id = 1, x = 3231, y = 3237) +spawnNpc("man", id = 2, x = 3224, y = 3240) +spawnNpc("woman", id = 5, x = 3229, y = 2329) + +spawnNpc("hans", x = 3221, y = 3221) +spawnNpc("father aereck", x = 3243, y = 3210) +spawnNpc("bob", x = 3231, y = 3203) +spawnNpc("shop keeper", x = 3212, y = 3247) +spawnNpc("shop assistant", x = 3211, y = 3245) +spawnNpc("lumbridge guide", x = 323, y = 3229) diff --git a/game/plugin/locations/lumbridge/src/shops.plugin.kts b/game/plugin/locations/lumbridge/src/shops.plugin.kts new file mode 100644 index 000000000..942bb62d3 --- /dev/null +++ b/game/plugin/locations/lumbridge/src/shops.plugin.kts @@ -0,0 +1,42 @@ +package org.apollo.plugin.locations.lumbridge + +import org.apollo.game.plugin.shops.builder.shop + +shop("Lumbridge General Store") { + operated by "Shop keeper" and "Shop assistant" + buys any items + + sell(5) of "Pot" + sell(2) of "Jug" + sell(2) of "Shears" + sell(3) of "Bucket" + sell(2) of "Bowl" + sell(2) of "Cake tin" + sell(2) of "Tinderbox" + sell(2) of "Chisel" + sell(5) of "Hammer" + sell(5) of "Newcomer map" +} + +shop("Bob's Brilliant Axes") { + operated by "Bob" + + category("pickaxe") { + sell(5) of "Bronze" + } + + category("axe") { + sell(10) of "Bronze" + sell(5) of "Iron" + sell(3) of "Steel" + } + + category("battleaxe") { + sell(5) of "Iron" + sell(2) of "Steel" + sell(1) of "Mithril" + } +} + +// TODO find out how to make objects be able to open stores for the Culinaromancer's Chest. Also links to TODO in +// Al-Kharid's shops plugin for "unlockable" items. \ No newline at end of file diff --git a/game/plugin/locations/tutorial-island/src/npcs.plugin.kts b/game/plugin/locations/tutorial-island/src/npcs.plugin.kts new file mode 100644 index 000000000..5ec51c09b --- /dev/null +++ b/game/plugin/locations/tutorial-island/src/npcs.plugin.kts @@ -0,0 +1,44 @@ +package org.apollo.plugin.locations.tutorialIsland + +import org.apollo.game.model.Direction +import org.apollo.game.plugin.entity.spawn.spawnNpc + +// Functional npcs + +// 'Above-ground' npcs + +spawnNpc("master_chef", x = 3076, y = 3085) +spawnNpc("quest_guide", x = 3086, y = 3122) +spawnNpc("financial_advisor", x = 3127, y = 3124, facing = Direction.WEST) +spawnNpc("brother_brace", x = 3124, y = 3107, facing = Direction.EAST) +spawnNpc("magic_instructor", x = 3140, y = 3085) + +// 'Below-ground' npcs +// Note: They aren't actually on a different plane, they're just in a different location that +// pretends to be underground. + +spawnNpc("mining_instructor", x = 3081, y = 9504) +spawnNpc("combat_instructor", x = 3104, y = 9506) + +// Non-humanoid npcs + +spawnNpc("fishing_spot", id = 316, x = 3102, y = 3093) + +spawnNpc("chicken", x = 3140, y = 3095) +spawnNpc("chicken", x = 3140, y = 3093) +spawnNpc("chicken", x = 3138, y = 3092) +spawnNpc("chicken", x = 3137, y = 3094) +spawnNpc("chicken", x = 3138, y = 3095) + +// 'Below-ground' npcs +// Note: They aren't actually on a different plane, they're just in a different location that +// pretends to be underground. + +spawnNpc("giant_rat", id = 87, x = 3105, y = 9514) +spawnNpc("giant_rat", id = 87, x = 3105, y = 9517) +spawnNpc("giant_rat", id = 87, x = 3106, y = 9514) +spawnNpc("giant_rat", id = 87, x = 3104, y = 9514) +spawnNpc("giant_rat", id = 87, x = 3105, y = 9519) +spawnNpc("giant_rat", id = 87, x = 3109, y = 9516) +spawnNpc("giant_rat", id = 87, x = 3108, y = 9520) +spawnNpc("giant_rat", id = 87, x = 3102, y = 9517) \ No newline at end of file diff --git a/game/plugin/locations/varrock/src/npcs.plugin.kts b/game/plugin/locations/varrock/src/npcs.plugin.kts new file mode 100644 index 000000000..83d5fb9ec --- /dev/null +++ b/game/plugin/locations/varrock/src/npcs.plugin.kts @@ -0,0 +1,268 @@ +package org.apollo.plugin.locations.varrock + +import org.apollo.game.model.Direction +import org.apollo.game.plugin.entity.spawn.spawnNpc + +spawnNpc("barbarian_woman", x = 3222, y = 3399) + +spawnNpc("bear", id = 106, x = 3289, y = 3351) + +spawnNpc("black_knight", x = 3238, y = 3514) +spawnNpc("black_knight", x = 3227, y = 3518) +spawnNpc("black_knight", x = 3279, y = 3502) + +spawnNpc("dark_wizard", id = 174, x = 3230, y = 3366) + +spawnNpc("dark_wizard", id = 174, x = 3228, y = 3368) +spawnNpc("dark_wizard", id = 174, x = 3225, y = 3367) +spawnNpc("dark_wizard", id = 174, x = 3226, y = 3365) +spawnNpc("dark_wizard", id = 174, x = 3226, y = 3372) +spawnNpc("dark_wizard", id = 174, x = 3231, y = 3371) + +spawnNpc("dark_wizard", id = 172, x = 3229, y = 3372) +spawnNpc("dark_wizard", id = 172, x = 3224, y = 3370) +spawnNpc("dark_wizard", id = 172, x = 3228, y = 3366) +spawnNpc("dark_wizard", id = 172, x = 3232, y = 3368) +spawnNpc("dark_wizard", id = 172, x = 3226, y = 3369) + +spawnNpc("giant_rat", id = 87, x = 3292, y = 3375) +spawnNpc("giant_rat", id = 87, x = 3265, y = 3384) +spawnNpc("giant_rat", id = 87, x = 3267, y = 3381) + +spawnNpc("guard", id = 368, x = 3263, y = 3407, facing = Direction.SOUTH) + +spawnNpc("jeremy_clerksin", x = 3253, y = 3477) +spawnNpc("martina_scorsby", x = 3256, y = 3481) + +spawnNpc("man", x = 3281, y = 3500) +spawnNpc("man", x = 3193, y = 3394) +spawnNpc("man", x = 3159, y = 3429) +spawnNpc("man", x = 3245, y = 3394) +spawnNpc("man", x = 3283, y = 3492, z = 1) + +spawnNpc("man", id = 2, x = 3283, y = 3492, z = 1) +spawnNpc("man", id = 2, x = 3263, y = 3400) + +spawnNpc("man", id = 3, x = 3227, y = 3395, z = 1) +spawnNpc("man", id = 3, x = 3231, y = 3399, z = 1) + +spawnNpc("mugger", x = 3251, y = 3390) +spawnNpc("mugger", x = 3177, y = 3363) + +spawnNpc("tramp", id = 2792, x = 3177, y = 3363) + +spawnNpc("woman", x = 3221, y = 3396) + +spawnNpc("woman", id = 5, x = 3279, y = 3497) +spawnNpc("woman", id = 25, x = 3278, y = 3492) + +spawnNpc("thief", x = 3285, y = 3500) +spawnNpc("thief", x = 3234, y = 3389) +spawnNpc("thief", x = 3188, y = 3383) +spawnNpc("thief", x = 3184, y = 3390) +spawnNpc("thief", x = 3188, y = 3394) + +spawnNpc("unicorn", x = 3286, y = 3342) +spawnNpc("unicorn", x = 3279, y = 3345) + +// North Guards + +spawnNpc("guard", x = 3244, y = 3500) +spawnNpc("guard", x = 3247, y = 3503) + +// East Guards + +spawnNpc("guard", x = 3271, y = 3431) +spawnNpc("guard", x = 3270, y = 3425) +spawnNpc("guard", x = 3274, y = 3421) +spawnNpc("guard", x = 3274, y = 3427) + +// South Guards + +spawnNpc("guard", x = 3210, y = 3382) +spawnNpc("guard", x = 3212, y = 3380) +spawnNpc("guard", x = 3207, y = 3376) + +// West Guards + +spawnNpc("guard", x = 3174, y = 3427) +spawnNpc("guard", x = 3176, y = 3430) +spawnNpc("guard", x = 3176, y = 3427) +spawnNpc("guard", x = 3180, y = 3399) +spawnNpc("guard", x = 3175, y = 3415, z = 1) +spawnNpc("guard", x = 3174, y = 3403, z = 1) + +// Varrock Palace + +spawnNpc("guard", x = 3210, y = 3461) +spawnNpc("guard", x = 3211, y = 3465) +spawnNpc("guard", x = 3214, y = 3462) +spawnNpc("guard", x = 3216, y = 3464) +spawnNpc("guard", x = 3220, y = 3461) +spawnNpc("guard", x = 3206, y = 3461) +spawnNpc("guard", x = 3204, y = 3495) + +spawnNpc("guard", x = 3204, y = 3495, z = 1) +spawnNpc("guard", x = 3205, y = 3492, z = 1) +spawnNpc("guard", x = 3203, y = 3492, z = 1) +spawnNpc("guard", x = 3205, y = 3497, z = 1) + +spawnNpc("guard", x = 3221, y = 3471, z = 2) +spawnNpc("guard", x = 3214, y = 3474, z = 2) +spawnNpc("guard", x = 3215, y = 3471, z = 2) +spawnNpc("guard", x = 3211, y = 3471, z = 2) +spawnNpc("guard", x = 3209, y = 3473, z = 2) +spawnNpc("guard", x = 3212, y = 3475, z = 2) +spawnNpc("guard", x = 3207, y = 3477, z = 2) +spawnNpc("guard", x = 3203, y = 3476, z = 2) +spawnNpc("guard", x = 3205, y = 3479, z = 2) +spawnNpc("guard", x = 3203, y = 3483, z = 2) +spawnNpc("guard", x = 3221, y = 3485, z = 2) + +spawnNpc("monk_of_zamorak", id = 189, x = 3213, y = 3476) + +spawnNpc("warrior_woman", x = 3203, y = 3490) +spawnNpc("warrior_woman", x = 3205, y = 3493) + +// Varrock/Lumbridge Pen + +spawnNpc("swan", x = 3261, y = 3354) +spawnNpc("swan", x = 3260, y = 3356) + +spawnNpc("ram", id = 3673, x = 3238, y = 3346) +spawnNpc("ram", id = 3673, x = 3248, y = 3352) +spawnNpc("ram", id = 3673, x = 3260, y = 3348) + +spawnNpc("sheep", id = 42, x = 3263, y = 3347) +spawnNpc("sheep", id = 42, x = 3268, y = 3350) +spawnNpc("sheep", id = 42, x = 3252, y = 3352) +spawnNpc("sheep", id = 42, x = 3243, y = 3344) +spawnNpc("sheep", id = 42, x = 3235, y = 3347) + +spawnNpc("sheep", id = 3579, x = 3234, y = 3344) +spawnNpc("sheep", id = 3579, x = 3241, y = 3347) +spawnNpc("sheep", id = 3579, x = 3257, y = 3350) + +// Champions Guild + +spawnNpc("chicken", x = 3195, y = 3359) +spawnNpc("chicken", x = 3198, y = 3356) +spawnNpc("chicken", x = 3195, y = 3355) + +spawnNpc("chicken", id = 1017, x = 3196, y = 3353) +spawnNpc("chicken", id = 1017, x = 3197, y = 3356) + +spawnNpc("evil_chicken", x = 3198, y = 3359) + +// Function Npc + +spawnNpc("apothecary", x = 3196, y = 3403) + +spawnNpc("captain_rovin", x = 3204, y = 3496, z = 2) + +spawnNpc("curator", x = 3256, y = 3447) + +spawnNpc("dimintheis", x = 3280, y = 3403) + +spawnNpc("dr_harlow", x = 3224, y = 3398) + +spawnNpc("ellamaria", x = 3228, y = 3475) + +spawnNpc("father_lawrence", x = 3253, y = 3484) + +spawnNpc("guidors_wife", id = 342, x = 3280, y = 3382) + +spawnNpc("guidor", x = 3284, y = 3381, facing = Direction.SOUTH) + +spawnNpc("guild_master", x = 3189, y = 3360) + +spawnNpc("gypsy", x = 3203, y = 3423) + +spawnNpc("hooknosed_jack", x = 3268, y = 3400) + +spawnNpc("jonny_the_beard", x = 3223, y = 3395) + +spawnNpc("johnathon", x = 3278, y = 3503, z = 1) + +spawnNpc("katrine", x = 3185, y = 3386) + +spawnNpc("king_roald", x = 3223, y = 3473) + +spawnNpc("master_farmer", x = 3243, y = 3349) + +spawnNpc("pox", x = 3267, y = 3399) + +spawnNpc("reldo", x = 3210, y = 3492) + +spawnNpc("romeo", x = 3211, y = 3423) + +spawnNpc("shilop", x = 3211, y = 3435) + +spawnNpc("sir_prysin", x = 3204, y = 3472) + +spawnNpc("tarquin", x = 3203, y = 3344, facing = Direction.SOUTH) + +spawnNpc("tool_leprechaun", x = 3182, y = 3355) + +spawnNpc("tool_leprechaun", x = 3229, y = 3455) + +spawnNpc("tramp", id = 641, x = 3207, y = 3392) + +spawnNpc("wilough", x = 3222, y = 3437) + +// Shop Npc + +spawnNpc("aubury", x = 3253, y = 3401) + +spawnNpc("baraek", x = 3217, y = 3434) + +spawnNpc("bartender", x = 3226, y = 3400) + +spawnNpc("bartender", id = 1921, x = 3277, y = 3487) + +spawnNpc("fancy_dress_shop_owner", x = 3281, y = 3398) + +spawnNpc("horvik", x = 3229, y = 3438) + +spawnNpc("lowe", x = 3233, y = 3421) + +spawnNpc("scavvo", x = 3192, y = 3353, z = 1) + +spawnNpc("shop_keeper", id = 551, x = 3206, y = 3399) +spawnNpc("shop_assistant", id = 552, x = 3207, y = 3396) + +spawnNpc("shop_keeper", id = 522, x = 3216, y = 3414) +spawnNpc("shop_assistant", id = 523, x = 3216, y = 3417) + +spawnNpc("tea_seller", x = 3271, y = 3411) + +spawnNpc("thessalia", x = 3206, y = 3417) + +spawnNpc("zaff", x = 3203, y = 3434) + +// Juliet House + +spawnNpc("draul_leptoc", x = 3228, y = 3475) +spawnNpc("juliet", x = 3159, y = 3425, z = 1) +spawnNpc("phillipa", x = 3160, y = 3429, z = 1) + +// Gertrude House + +spawnNpc("gertrude", x = 3153, y = 3413) +spawnNpc("kanel", x = 3155, y = 3405, facing = Direction.EAST) +spawnNpc("philop", x = 3150, y = 3405, facing = Direction.SOUTH) + +// Small Bank + +spawnNpc("banker", id = 495, x = 3252, y = 3418) +spawnNpc("banker", id = 494, x = 3252, y = 3418) +spawnNpc("banker", id = 494, x = 3252, y = 3418) +spawnNpc("banker", id = 494, x = 3252, y = 3418) + +// Big Bank + +spawnNpc("banker", id = 494, x = 3187, y = 3436, facing = Direction.WEST) +spawnNpc("banker", id = 494, x = 3187, y = 3440, facing = Direction.WEST) +spawnNpc("banker", id = 494, x = 3187, y = 3444, facing = Direction.WEST) +spawnNpc("banker", id = 495, x = 3187, y = 3438, facing = Direction.WEST) +spawnNpc("banker", id = 495, x = 3187, y = 3442, facing = Direction.WEST) \ No newline at end of file diff --git a/game/plugin/locations/varrock/src/shops.plugin.kts b/game/plugin/locations/varrock/src/shops.plugin.kts new file mode 100644 index 000000000..d810ad0fd --- /dev/null +++ b/game/plugin/locations/varrock/src/shops.plugin.kts @@ -0,0 +1,176 @@ +package org.apollo.plugin.locations.varrock + +import org.apollo.game.plugin.shops.builder.shop + +shop("Aubury's Rune Shop.") { + operated by "Aubury" + + category("runes") { + sell(5000) of { + -"Earth" + -"Water" + -"Fire" + -"Air" + -"Mind" + -"Body" + } + + sell(250) of { + -"Chaos" + -"Death" + } + } +} + +shop("Lowe's Archery Emporium.") { + operated by "Lowe" + + category("arrows") { + sell(2000) of "Bronze" + sell(1500) of "Iron" + sell(1000) of "Steel" + sell(800) of "Mithril" + sell(600) of "Adamant" + } + + category("normal weapons", affix = nothing) { + sell(4) of "Shortbow" + sell(4) of "Longbow" + sell(2) of "Crossbow" + } + + category("shortbows") { + sell(3) of "Oak" + sell(2) of "Willow" + sell(1) of "Maple" + } + + category("longbows") { + sell(3) of "Oak" + sell(2) of "Willow" + sell(1) of "Maple" + } +} + +shop("Horvik's Armour Shop.") { + operated by "Horvik" + + category("chainbody") { + sell(5) of "Bronze" + sell(3) of "Iron" + sell(3) of "Steel" + sell(1) of "Mithril" + } + + category("platebody") { + sell(3) of "Bronze" + + sell(1) of { + -"Iron" + -"Steel" + -"Black" + -"Mithril" + } + } + + sell(1) of { + -"Iron platelegs" + -"Studded body" + -"Studded chaps" + } +} + +shop("Thessalia's Fine Clothes.") { + operated by "Thessalia" + + category("apron") { + sell(3) of "White" + sell(1) of "Brown" + } + + category("leather", affix = prefix) { + sell(12) of "Body" + sell(10) of "Gloves" + sell(10) of "Boots" + } + + category("skirt") { + sell(5) of "Pink" + sell(3) of "Black" + sell(2) of "Blue" + } + + sell(4) of "Cape" + sell(5) of "Silk" + + sell(3) of { + -"Priest gown"(426) + -"Priest gown"(428) + } +} + +shop("Varrock General Store.") { + operated by "Shopkeeper"(513) and "Shop assistant"(514) + buys any items + + sell(5) of "Pot" + sell(2) of "Jug" + sell(2) of "Shears" + sell(3) of "Bucket" + sell(2) of "Bowl" + sell(2) of "Cake tin" + sell(2) of "Tinderbox" + sell(2) of "Chisel" + sell(5) of "Hammer" + sell(5) of "Newcomer map" +} + +shop("Varrock Swordshop.") { + operated by "Shopkeeper"(515) and "Shop assistant"(516) + + category("swords") { + sell(5) of "Bronze" + sell(4) of "Iron" + sell(4) of "Steel" + sell(3) of "Black" + sell(3) of "Mithril" + sell(2) of "Adamant" + } + + category("longswords") { + sell(4) of "Bronze" + sell(3) of "Iron" + sell(3) of "Steel" + sell(2) of "Black" + sell(2) of "Mithril" + sell(1) of "Adamant" + } + + category("daggers") { + sell(10) of "Bronze" + sell(6) of "Iron" + sell(5) of "Steel" + sell(4) of "Black" + sell(3) of "Mithril" + sell(2) of "Adamant" + } +} + +shop("Zaff's Superior Staffs!") { + operated by "Zaff" + + category("staves", affix = nothing) { + sell(5) of { + -"Battlestaff" + -"Staff" + -"Magic staff" + } + + sell(2) of { + -"Staff of air" + -"Staff of water" + -"Staff of earth" + -"Staff of fire" + } + } +} From 7fe027292344047a84325dd4a6794b607a8c095e Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 15 Mar 2020 09:48:22 -0400 Subject: [PATCH 23/63] Added the plugins for shops back with proper npc ids. --- .../src/main/java/org/apollo/cache/def/EnumDefinition.java | 1 - game/plugin/locations/al-kharid/src/shops.plugin.kts | 2 +- game/plugin/locations/edgeville/src/shops.plugin.kts | 2 +- game/plugin/locations/falador/src/shops.plugin.kts | 2 +- game/plugin/locations/lumbridge/src/shops.plugin.kts | 4 ++-- game/plugin/locations/varrock/src/shops.plugin.kts | 6 +++--- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java index cd15cfbd7..ea5ccba49 100644 --- a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java @@ -8,7 +8,6 @@ import java.util.HashMap; import java.util.Map; - public final class EnumDefinition { private static final Map definitions = new HashMap<>(); diff --git a/game/plugin/locations/al-kharid/src/shops.plugin.kts b/game/plugin/locations/al-kharid/src/shops.plugin.kts index 94219655c..cf7f3925a 100644 --- a/game/plugin/locations/al-kharid/src/shops.plugin.kts +++ b/game/plugin/locations/al-kharid/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.alKharid import org.apollo.game.plugin.shops.builder.shop shop("Al-Kharid General Store") { - operated by "Shop keeper"(506) and "Shop assistant"(507) + operated by "Shop keeper"(2817) and "Shop assistant"(2818) buys any items sell(5) of "Pot" diff --git a/game/plugin/locations/edgeville/src/shops.plugin.kts b/game/plugin/locations/edgeville/src/shops.plugin.kts index fd040c6f0..fdc5ba8d2 100644 --- a/game/plugin/locations/edgeville/src/shops.plugin.kts +++ b/game/plugin/locations/edgeville/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.edgeville import org.apollo.game.plugin.shops.builder.shop shop("Edgeville General Store") { - operated by "Shop keeper"(510) and "Shop assistant"(509) + operated by "Shop keeper"(2821) and "Shop assistant"(2822) buys any items sell(5) of "Pot" diff --git a/game/plugin/locations/falador/src/shops.plugin.kts b/game/plugin/locations/falador/src/shops.plugin.kts index d6f22a909..f51d74b18 100644 --- a/game/plugin/locations/falador/src/shops.plugin.kts +++ b/game/plugin/locations/falador/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.falador import org.apollo.game.plugin.shops.builder.shop shop("Falador General Store") { - operated by "Shop keeper"(512) and "Shop assistant"( 511) + operated by "Shop keeper"(2819) and "Shop assistant"( 2820) buys any items sell(5) of "Pot" diff --git a/game/plugin/locations/lumbridge/src/shops.plugin.kts b/game/plugin/locations/lumbridge/src/shops.plugin.kts index 942bb62d3..54fd9e874 100644 --- a/game/plugin/locations/lumbridge/src/shops.plugin.kts +++ b/game/plugin/locations/lumbridge/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.lumbridge import org.apollo.game.plugin.shops.builder.shop shop("Lumbridge General Store") { - operated by "Shop keeper" and "Shop assistant" + operated by "Shop keeper"(2813) and "Shop assistant"(2814) buys any items sell(5) of "Pot" @@ -19,7 +19,7 @@ shop("Lumbridge General Store") { } shop("Bob's Brilliant Axes") { - operated by "Bob" + operated by "Bob"(2812) category("pickaxe") { sell(5) of "Bronze" diff --git a/game/plugin/locations/varrock/src/shops.plugin.kts b/game/plugin/locations/varrock/src/shops.plugin.kts index d810ad0fd..0240b6d6a 100644 --- a/game/plugin/locations/varrock/src/shops.plugin.kts +++ b/game/plugin/locations/varrock/src/shops.plugin.kts @@ -100,7 +100,7 @@ shop("Thessalia's Fine Clothes.") { sell(2) of "Blue" } - sell(4) of "Cape" + sell(4) of "Red cape" sell(5) of "Silk" sell(3) of { @@ -110,7 +110,7 @@ shop("Thessalia's Fine Clothes.") { } shop("Varrock General Store.") { - operated by "Shopkeeper"(513) and "Shop assistant"(514) + operated by "Shopkeeper"(2815) and "Shop assistant"(2816) buys any items sell(5) of "Pot" @@ -126,7 +126,7 @@ shop("Varrock General Store.") { } shop("Varrock Swordshop.") { - operated by "Shopkeeper"(515) and "Shop assistant"(516) + operated by "Shopkeeper"(2884) and "Shop assistant"(2885) category("swords") { sell(5) of "Bronze" From f972fd1cb7e38e481ce771cbd85076a633ec6c30 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 15 Mar 2020 10:01:21 -0400 Subject: [PATCH 24/63] Fixes spawns with modern names. --- game/plugin/locations/al-kharid/src/npcs.plugin.kts | 2 +- game/plugin/locations/tutorial-island/src/npcs.plugin.kts | 2 +- game/plugin/locations/varrock/src/npcs.plugin.kts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/game/plugin/locations/al-kharid/src/npcs.plugin.kts b/game/plugin/locations/al-kharid/src/npcs.plugin.kts index 79b74471c..54e783877 100644 --- a/game/plugin/locations/al-kharid/src/npcs.plugin.kts +++ b/game/plugin/locations/al-kharid/src/npcs.plugin.kts @@ -77,7 +77,7 @@ spawnNpc("scorpion", x = 3301, y = 3312) // Functional npcs -spawnNpc("gnome_pilot", x = 3279, y = 3213) +spawnNpc("captain_dalbur", x = 3279, y = 3213) spawnNpc("banker", id = 496, x = 3267, y = 3164, facing = Direction.EAST) spawnNpc("banker", id = 496, x = 3267, y = 3167, facing = Direction.EAST) diff --git a/game/plugin/locations/tutorial-island/src/npcs.plugin.kts b/game/plugin/locations/tutorial-island/src/npcs.plugin.kts index 5ec51c09b..f1ec6918b 100644 --- a/game/plugin/locations/tutorial-island/src/npcs.plugin.kts +++ b/game/plugin/locations/tutorial-island/src/npcs.plugin.kts @@ -9,7 +9,7 @@ import org.apollo.game.plugin.entity.spawn.spawnNpc spawnNpc("master_chef", x = 3076, y = 3085) spawnNpc("quest_guide", x = 3086, y = 3122) -spawnNpc("financial_advisor", x = 3127, y = 3124, facing = Direction.WEST) +spawnNpc("account_guide", x = 3127, y = 3124, facing = Direction.WEST) spawnNpc("brother_brace", x = 3124, y = 3107, facing = Direction.EAST) spawnNpc("magic_instructor", x = 3140, y = 3085) diff --git a/game/plugin/locations/varrock/src/npcs.plugin.kts b/game/plugin/locations/varrock/src/npcs.plugin.kts index 83d5fb9ec..cd2d09249 100644 --- a/game/plugin/locations/varrock/src/npcs.plugin.kts +++ b/game/plugin/locations/varrock/src/npcs.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.varrock import org.apollo.game.model.Direction import org.apollo.game.plugin.entity.spawn.spawnNpc -spawnNpc("barbarian_woman", x = 3222, y = 3399) +spawnNpc("barbarian_woman_3102", x = 3222, y = 3399) spawnNpc("bear", id = 106, x = 3289, y = 3351) @@ -160,7 +160,7 @@ spawnNpc("apothecary", x = 3196, y = 3403) spawnNpc("captain_rovin", x = 3204, y = 3496, z = 2) -spawnNpc("curator", x = 3256, y = 3447) +spawnNpc("curator_haig_halen", x = 3256, y = 3447) spawnNpc("dimintheis", x = 3280, y = 3403) @@ -174,7 +174,7 @@ spawnNpc("guidors_wife", id = 342, x = 3280, y = 3382) spawnNpc("guidor", x = 3284, y = 3381, facing = Direction.SOUTH) -spawnNpc("guild_master", x = 3189, y = 3360) +spawnNpc("guildmaster", x = 3189, y = 3360) spawnNpc("gypsy", x = 3203, y = 3423) @@ -220,7 +220,7 @@ spawnNpc("bartender", x = 3226, y = 3400) spawnNpc("bartender", id = 1921, x = 3277, y = 3487) -spawnNpc("fancy_dress_shop_owner", x = 3281, y = 3398) +spawnNpc("asyff", x = 3281, y = 3398) spawnNpc("horvik", x = 3229, y = 3438) From a0d9869ac27d241342a29010cdee52a95d77bca8 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 15 Mar 2020 15:56:04 -0400 Subject: [PATCH 25/63] Gets rid of leak from the ondemand response encoder. Standard named for id << component should be packedInterface. Added IfSetEventMessage encoder. --- game/data/plugins/.rubocop.yml | 36 -- game/data/plugins/areas/actions.rb | 49 -- game/data/plugins/areas/areas.rb | 108 ---- game/data/plugins/areas/plugin.xml | 15 - game/data/plugins/bank/bank.rb | 47 -- game/data/plugins/bank/plugin.xml | 14 - game/data/plugins/bootstrap.rb | 239 -------- game/data/plugins/chat/privacy/plugin.xml | 16 - game/data/plugins/chat/privacy/privacy.rb | 12 - .../plugins/chat/private-messaging/friend.rb | 102 ---- .../plugins/chat/private-messaging/ignore.rb | 9 - .../chat/private-messaging/messaging.rb | 23 - .../plugins/chat/private-messaging/plugin.xml | 16 - game/data/plugins/cmd/animate/animate.rb | 20 - game/data/plugins/cmd/animate/plugin.xml | 14 - game/data/plugins/cmd/bank/bank.rb | 6 - game/data/plugins/cmd/bank/plugin.xml | 14 - game/data/plugins/cmd/item/item.rb | 45 -- game/data/plugins/cmd/item/plugin.xml | 14 - game/data/plugins/cmd/lookup/lookup.rb | 69 --- game/data/plugins/cmd/lookup/plugin.xml | 16 - game/data/plugins/cmd/messaging/broadcast.rb | 12 - game/data/plugins/cmd/messaging/plugin.xml | 15 - game/data/plugins/cmd/npc/plugin.xml | 14 - game/data/plugins/cmd/npc/spawn.rb | 68 --- game/data/plugins/cmd/punishment/plugin.xml | 14 - game/data/plugins/cmd/punishment/punish.rb | 53 -- game/data/plugins/cmd/skill/plugin.xml | 15 - game/data/plugins/cmd/skill/skill.rb | 44 -- game/data/plugins/cmd/teleport/plugin.xml | 14 - game/data/plugins/cmd/teleport/teleport.rb | 20 - game/data/plugins/combat/plugin.xml | 17 - game/data/plugins/combat/wilderness.rb | 66 -- game/data/plugins/consumables/consumable.rb | 79 --- game/data/plugins/consumables/drink.rb | 76 --- game/data/plugins/consumables/food.rb | 221 ------- game/data/plugins/consumables/plugin.xml | 17 - game/data/plugins/consumables/potions.rb | 136 ----- game/data/plugins/dialogue/dialogue.rb | 567 ------------------ game/data/plugins/dialogue/emotes.rb | 31 - game/data/plugins/dialogue/plugin.xml | 17 - game/data/plugins/dummy/dummy.rb | 51 -- game/data/plugins/dummy/plugin.xml | 14 - game/data/plugins/emote-tab/emote_tab.rb | 57 -- game/data/plugins/emote-tab/plugin.xml | 14 - .../plugins/entity/attributes/attributes.rb | 79 --- .../data/plugins/entity/attributes/plugin.xml | 14 - .../plugins/entity/mob/extension/extension.rb | 20 - .../plugins/entity/mob/extension/plugin.xml | 15 - .../plugins/entity/mob/following/following.rb | 58 -- .../plugins/entity/mob/following/plugin.xml | 16 - .../plugins/entity/mob/walk-to/plugin.xml | 16 - .../plugins/entity/mob/walk-to/walk_to.rb | 83 --- .../data/plugins/entity/spawning/npc-spawn.rb | 197 ------ game/data/plugins/entity/spawning/plugin.xml | 16 - game/data/plugins/location/al-kharid/npcs.rb | 89 --- .../plugins/location/al-kharid/plugin.xml | 16 - game/data/plugins/location/edgeville/npcs.rb | 45 -- .../plugins/location/edgeville/plugin.xml | 17 - game/data/plugins/location/falador/npcs.rb | 157 ----- game/data/plugins/location/falador/plugin.xml | 16 - game/data/plugins/location/lumbridge/npcs.rb | 16 - .../plugins/location/lumbridge/plugin.xml | 16 - .../plugins/location/tutorial-island/guide.rb | 158 ----- .../location/tutorial-island/instructions.rb | 141 ----- .../plugins/location/tutorial-island/npcs.rb | 40 -- .../location/tutorial-island/plugin.xml | 24 - .../location/tutorial-island/stages.rb | 16 - .../location/tutorial-island/survival.rb | 154 ----- .../plugins/location/tutorial-island/utils.rb | 30 - game/data/plugins/location/varrock/npcs.rb | 258 -------- game/data/plugins/location/varrock/plugin.xml | 18 - game/data/plugins/location/varrock/shops.rb | 44 -- game/data/plugins/logout/logout.rb | 5 - game/data/plugins/logout/plugin.xml | 14 - .../data/plugins/navigation/door/constants.rb | 44 -- game/data/plugins/navigation/door/door.rb | 54 -- game/data/plugins/navigation/door/plugin.xml | 16 - game/data/plugins/navigation/door/util.rb | 83 --- game/data/plugins/player-action/action.rb | 61 -- game/data/plugins/player-action/login.rb | 6 - game/data/plugins/player-action/plugin.xml | 15 - game/data/plugins/quest/plugin.xml | 16 - game/data/plugins/quest/repository.rb | 132 ---- game/data/plugins/run/plugin.xml | 16 - game/data/plugins/run/run.rb | 10 - game/data/plugins/shops/currency.rb | 35 -- game/data/plugins/shops/plugin.xml | 20 - game/data/plugins/shops/shop.rb | 28 - game/data/plugins/shops/shop_item.rb | 20 - game/data/plugins/shops/shops.rb | 301 ---------- game/data/plugins/skill/fishing/fish.rb | 41 -- game/data/plugins/skill/fishing/fishing.rb | 120 ---- game/data/plugins/skill/fishing/plugin.xml | 20 - game/data/plugins/skill/fishing/spot.rb | 26 - game/data/plugins/skill/fishing/tool.rb | 60 -- game/data/plugins/skill/herblore/herb.rb | 95 --- game/data/plugins/skill/herblore/herblore.rb | 102 ---- .../data/plugins/skill/herblore/ingredient.rb | 251 -------- game/data/plugins/skill/herblore/plugin.xml | 18 - game/data/plugins/skill/herblore/potion.rb | 372 ------------ game/data/plugins/skill/magic/alchemy.rb | 81 --- game/data/plugins/skill/magic/convert.rb | 89 --- game/data/plugins/skill/magic/element.rb | 107 ---- game/data/plugins/skill/magic/enchant.rb | 106 ---- game/data/plugins/skill/magic/magic.rb | 172 ------ game/data/plugins/skill/magic/plugin.xml | 20 - game/data/plugins/skill/magic/teleport.rb | 101 ---- game/data/plugins/skill/mining/gem.rb | 20 - game/data/plugins/skill/mining/mining.rb | 155 ----- game/data/plugins/skill/mining/ore.rb | 95 --- game/data/plugins/skill/mining/pickaxe.rb | 33 - game/data/plugins/skill/mining/plugin.xml | 24 - game/data/plugins/skill/mining/respawn.rb | 16 - game/data/plugins/skill/prayer/bury.rb | 89 --- game/data/plugins/skill/prayer/plugin.xml | 18 - game/data/plugins/skill/prayer/prayers.rb | 88 --- game/data/plugins/skill/runecraft/altar.rb | 129 ---- game/data/plugins/skill/runecraft/plugin.xml | 21 - game/data/plugins/skill/runecraft/rune.rb | 52 -- .../data/plugins/skill/runecraft/runecraft.rb | 58 -- game/data/plugins/skill/runecraft/talisman.rb | 54 -- game/data/plugins/skill/runecraft/tiara.rb | 167 ------ game/data/plugins/util/command.rb | 44 -- game/data/plugins/util/name_lookup.rb | 50 -- game/data/plugins/util/plugin.xml | 15 - .../message/impl/encode/IfMoveSubMessage.java | 18 +- .../message/impl/encode/IfOpenSubMessage.java | 12 +- .../impl/encode/IfSetEventMessage.java | 35 ++ .../apollo/game/release/r181/Release181.java | 6 +- .../encoders/ui/IfMoveSubMessageEncoder.java | 4 +- .../encoders/ui/IfOpenSubMessageEncoder.java | 2 +- .../encoders/ui/IfSetEventMessageEncoder.java | 27 + .../codec/update/OnDemandResponseEncoder.java | 16 +- 134 files changed, 91 insertions(+), 8099 deletions(-) delete mode 100644 game/data/plugins/.rubocop.yml delete mode 100644 game/data/plugins/areas/actions.rb delete mode 100644 game/data/plugins/areas/areas.rb delete mode 100644 game/data/plugins/areas/plugin.xml delete mode 100644 game/data/plugins/bank/bank.rb delete mode 100644 game/data/plugins/bank/plugin.xml delete mode 100644 game/data/plugins/bootstrap.rb delete mode 100644 game/data/plugins/chat/privacy/plugin.xml delete mode 100644 game/data/plugins/chat/privacy/privacy.rb delete mode 100644 game/data/plugins/chat/private-messaging/friend.rb delete mode 100644 game/data/plugins/chat/private-messaging/ignore.rb delete mode 100644 game/data/plugins/chat/private-messaging/messaging.rb delete mode 100644 game/data/plugins/chat/private-messaging/plugin.xml delete mode 100644 game/data/plugins/cmd/animate/animate.rb delete mode 100644 game/data/plugins/cmd/animate/plugin.xml delete mode 100644 game/data/plugins/cmd/bank/bank.rb delete mode 100644 game/data/plugins/cmd/bank/plugin.xml delete mode 100644 game/data/plugins/cmd/item/item.rb delete mode 100644 game/data/plugins/cmd/item/plugin.xml delete mode 100644 game/data/plugins/cmd/lookup/lookup.rb delete mode 100644 game/data/plugins/cmd/lookup/plugin.xml delete mode 100644 game/data/plugins/cmd/messaging/broadcast.rb delete mode 100644 game/data/plugins/cmd/messaging/plugin.xml delete mode 100644 game/data/plugins/cmd/npc/plugin.xml delete mode 100644 game/data/plugins/cmd/npc/spawn.rb delete mode 100644 game/data/plugins/cmd/punishment/plugin.xml delete mode 100644 game/data/plugins/cmd/punishment/punish.rb delete mode 100644 game/data/plugins/cmd/skill/plugin.xml delete mode 100644 game/data/plugins/cmd/skill/skill.rb delete mode 100644 game/data/plugins/cmd/teleport/plugin.xml delete mode 100644 game/data/plugins/cmd/teleport/teleport.rb delete mode 100644 game/data/plugins/combat/plugin.xml delete mode 100644 game/data/plugins/combat/wilderness.rb delete mode 100644 game/data/plugins/consumables/consumable.rb delete mode 100644 game/data/plugins/consumables/drink.rb delete mode 100644 game/data/plugins/consumables/food.rb delete mode 100644 game/data/plugins/consumables/plugin.xml delete mode 100644 game/data/plugins/consumables/potions.rb delete mode 100644 game/data/plugins/dialogue/dialogue.rb delete mode 100644 game/data/plugins/dialogue/emotes.rb delete mode 100644 game/data/plugins/dialogue/plugin.xml delete mode 100644 game/data/plugins/dummy/dummy.rb delete mode 100644 game/data/plugins/dummy/plugin.xml delete mode 100644 game/data/plugins/emote-tab/emote_tab.rb delete mode 100644 game/data/plugins/emote-tab/plugin.xml delete mode 100644 game/data/plugins/entity/attributes/attributes.rb delete mode 100644 game/data/plugins/entity/attributes/plugin.xml delete mode 100644 game/data/plugins/entity/mob/extension/extension.rb delete mode 100644 game/data/plugins/entity/mob/extension/plugin.xml delete mode 100755 game/data/plugins/entity/mob/following/following.rb delete mode 100755 game/data/plugins/entity/mob/following/plugin.xml delete mode 100644 game/data/plugins/entity/mob/walk-to/plugin.xml delete mode 100644 game/data/plugins/entity/mob/walk-to/walk_to.rb delete mode 100644 game/data/plugins/entity/spawning/npc-spawn.rb delete mode 100644 game/data/plugins/entity/spawning/plugin.xml delete mode 100644 game/data/plugins/location/al-kharid/npcs.rb delete mode 100644 game/data/plugins/location/al-kharid/plugin.xml delete mode 100644 game/data/plugins/location/edgeville/npcs.rb delete mode 100644 game/data/plugins/location/edgeville/plugin.xml delete mode 100644 game/data/plugins/location/falador/npcs.rb delete mode 100644 game/data/plugins/location/falador/plugin.xml delete mode 100644 game/data/plugins/location/lumbridge/npcs.rb delete mode 100644 game/data/plugins/location/lumbridge/plugin.xml delete mode 100644 game/data/plugins/location/tutorial-island/guide.rb delete mode 100644 game/data/plugins/location/tutorial-island/instructions.rb delete mode 100644 game/data/plugins/location/tutorial-island/npcs.rb delete mode 100644 game/data/plugins/location/tutorial-island/plugin.xml delete mode 100644 game/data/plugins/location/tutorial-island/stages.rb delete mode 100644 game/data/plugins/location/tutorial-island/survival.rb delete mode 100644 game/data/plugins/location/tutorial-island/utils.rb delete mode 100644 game/data/plugins/location/varrock/npcs.rb delete mode 100644 game/data/plugins/location/varrock/plugin.xml delete mode 100644 game/data/plugins/location/varrock/shops.rb delete mode 100644 game/data/plugins/logout/logout.rb delete mode 100644 game/data/plugins/logout/plugin.xml delete mode 100644 game/data/plugins/navigation/door/constants.rb delete mode 100644 game/data/plugins/navigation/door/door.rb delete mode 100644 game/data/plugins/navigation/door/plugin.xml delete mode 100644 game/data/plugins/navigation/door/util.rb delete mode 100644 game/data/plugins/player-action/action.rb delete mode 100644 game/data/plugins/player-action/login.rb delete mode 100644 game/data/plugins/player-action/plugin.xml delete mode 100644 game/data/plugins/quest/plugin.xml delete mode 100644 game/data/plugins/quest/repository.rb delete mode 100644 game/data/plugins/run/plugin.xml delete mode 100644 game/data/plugins/run/run.rb delete mode 100644 game/data/plugins/shops/currency.rb delete mode 100644 game/data/plugins/shops/plugin.xml delete mode 100644 game/data/plugins/shops/shop.rb delete mode 100644 game/data/plugins/shops/shop_item.rb delete mode 100644 game/data/plugins/shops/shops.rb delete mode 100644 game/data/plugins/skill/fishing/fish.rb delete mode 100644 game/data/plugins/skill/fishing/fishing.rb delete mode 100644 game/data/plugins/skill/fishing/plugin.xml delete mode 100644 game/data/plugins/skill/fishing/spot.rb delete mode 100644 game/data/plugins/skill/fishing/tool.rb delete mode 100644 game/data/plugins/skill/herblore/herb.rb delete mode 100644 game/data/plugins/skill/herblore/herblore.rb delete mode 100644 game/data/plugins/skill/herblore/ingredient.rb delete mode 100644 game/data/plugins/skill/herblore/plugin.xml delete mode 100644 game/data/plugins/skill/herblore/potion.rb delete mode 100644 game/data/plugins/skill/magic/alchemy.rb delete mode 100644 game/data/plugins/skill/magic/convert.rb delete mode 100644 game/data/plugins/skill/magic/element.rb delete mode 100644 game/data/plugins/skill/magic/enchant.rb delete mode 100644 game/data/plugins/skill/magic/magic.rb delete mode 100644 game/data/plugins/skill/magic/plugin.xml delete mode 100644 game/data/plugins/skill/magic/teleport.rb delete mode 100644 game/data/plugins/skill/mining/gem.rb delete mode 100644 game/data/plugins/skill/mining/mining.rb delete mode 100644 game/data/plugins/skill/mining/ore.rb delete mode 100644 game/data/plugins/skill/mining/pickaxe.rb delete mode 100644 game/data/plugins/skill/mining/plugin.xml delete mode 100644 game/data/plugins/skill/mining/respawn.rb delete mode 100644 game/data/plugins/skill/prayer/bury.rb delete mode 100644 game/data/plugins/skill/prayer/plugin.xml delete mode 100644 game/data/plugins/skill/prayer/prayers.rb delete mode 100644 game/data/plugins/skill/runecraft/altar.rb delete mode 100644 game/data/plugins/skill/runecraft/plugin.xml delete mode 100644 game/data/plugins/skill/runecraft/rune.rb delete mode 100644 game/data/plugins/skill/runecraft/runecraft.rb delete mode 100644 game/data/plugins/skill/runecraft/talisman.rb delete mode 100644 game/data/plugins/skill/runecraft/tiara.rb delete mode 100644 game/data/plugins/util/command.rb delete mode 100644 game/data/plugins/util/name_lookup.rb delete mode 100644 game/data/plugins/util/plugin.xml create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetEventMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java diff --git a/game/data/plugins/.rubocop.yml b/game/data/plugins/.rubocop.yml deleted file mode 100644 index b0a58ae30..000000000 --- a/game/data/plugins/.rubocop.yml +++ /dev/null @@ -1,36 +0,0 @@ -Metrics/AbcSize: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/LineLength: - Max: 100 - -Metrics/MethodLength: - Max: 30 - -Metrics/PerceivedComplexity: - Enabled: false - -Style/CaseIndentation: - IndentOneStep: true - -Style/EmptyLinesAroundBlockBody: - Enabled: false - -Style/EmptyLinesAroundClassBody: - Enabled: false - -Style/EmptyLinesAroundModuleBody: - Enabled: false - -Style/GlobalVars: - Enabled: false - -Style/MethodName: # Disabled so we can override Java methods without rubocop complaining - Enabled: false - -Style/ParallelAssignment: - Enabled: false - diff --git a/game/data/plugins/areas/actions.rb b/game/data/plugins/areas/actions.rb deleted file mode 100644 index aeaaa6eae..000000000 --- a/game/data/plugins/areas/actions.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.message.impl.DisplayCrossbonesMessage' -java_import 'org.apollo.game.model.entity.Player' - -# Registers an area action. -def area_action(name, &block) - AREA_ACTIONS[name] = action = AreaAction.new - action.instance_eval(&block) -end - -AREA_ACTIONS = {} - -private - -# An action that is called when a player enters or exits an area. -class AreaAction - - # Sets the block to be called when the player enters the area. - def on_entry(&block) - @on_enter = block - end - - # Sets the block to be called while the player is in the area. - def while_in(&block) - @while_in = block - end - - # Sets the block to be called when the player exits the area. - def on_exit(&block) - @on_exit = block - end - - # Called when the player has entered an area this action is registered to. - def entered(player, position) - @on_enter.call(player, position) unless @on_enter.nil? - end - - # Called while the player is in area this action is registered to. - def inside(player, position) - @while_in.call(player, position) unless @while_in.nil? - end - - # Called when the player has exited an area this action is registered to. - def exited(player, position) - @on_exit.call(player, position) unless @on_exit.nil? - end - -end diff --git a/game/data/plugins/areas/areas.rb b/game/data/plugins/areas/areas.rb deleted file mode 100644 index 33a32bd89..000000000 --- a/game/data/plugins/areas/areas.rb +++ /dev/null @@ -1,108 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Position' -java_import 'org.apollo.game.model.entity.EntityType' -java_import 'org.apollo.game.model.entity.Player' - -# Creates a new area and registers it with the supplied coordinates. -def area(hash) - failure_message = 'Hash must contain a name, coordinates, and actions pair.' - fail failure_message unless hash.has_keys?(:name, :coordinates, :actions) - - name, coordinates, actions = hash[:name], hash[:coordinates], hash[:actions] - - actions = [actions] if actions.is_a?(Symbol) - actions.map! { |action| AREA_ACTIONS[action] } - @areas << Area.new(name, coordinates, actions) -end - -private - -# A map of coordinates (as an array) to areas. -@areas = [] - -# An area of the game world. -class Area - - def initialize(name, coordinates, actions) - @name = name - @coordinates = coordinates - @actions = actions - end - - def min_x # TODO: better data structure and methods than this - @coordinates[0] - end - - def min_y - @coordinates[1] - end - - def max_x - @coordinates[2] - end - - def max_y - @coordinates[3] - end - - def height - @coordinates[4] - end - - # Called when the player has entered the area. - def entered(player, position) - @actions.each { |action| action.entered(player, position) } - end - - # Called when the player has moved, but is still inside the area (and was in the area before). - def inside(player, position) - @actions.each { |action| action.inside(player, position) } - end - - # Called when the player has exited the area. - def exited(player, position) - @actions.each { |action| action.exited(player, position) } - end - -end - -on :login do |event| - player = event.player - - @areas.each do |area| - area.entered(player) if player.position.inside(area) - end -end - -# Listen for the MobPositionUpdateEvent and update the area listeners if appropriate. -on :mob_position_update do |event| - mob = event.mob - next unless mob.entity_type == EntityType::PLAYER - - old = mob.position - updated = event.next - @areas.each do |area| - was_inside = old.inside(area) - next_inside = updated.inside(area) - - if was_inside - next_inside ? area.inside(mob, updated) : area.exited(mob, updated) - else - area.entered(mob, updated) if next_inside - end - end -end - -# The existing Position class. -class Position - - # Returns whether or not this Position is inside the specified Area. - def inside(area) - return false if x < area.min_x || x > area.max_x || y < area.min_y || y > area.max_y - z = area.height - - z.nil? || z == height - end - -end diff --git a/game/data/plugins/areas/plugin.xml b/game/data/plugins/areas/plugin.xml deleted file mode 100644 index 2c18bb322..000000000 --- a/game/data/plugins/areas/plugin.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - areas - 0.9 - Areas - Adds support for areas. - - Major - - - - - - - diff --git a/game/data/plugins/bank/bank.rb b/game/data/plugins/bank/bank.rb deleted file mode 100644 index 6383f9b77..000000000 --- a/game/data/plugins/bank/bank.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.model.inter.bank.BankUtils' - -BANK_BOOTH_ID = 2213 -BANK_BOOTH_SIZE = 1 - -# The npcs with a 'bank' menu action. -BANKER_NPCS = [166, 494, 495, 496, 497, 498, 499, 1036, 1360, 1702, 2163, 2164, 2354, 2355, 2568, - 2569, 2570] - -# A distanced action to open a new bank. -class BankAction < DistancedAction - attr_reader :position - - def initialize(mob, position) - super(0, true, mob, position, BANK_BOOTH_SIZE) - @position = position - end - - def executeAction - mob.turn_to(@position) - BankUtils.open_bank(mob) - stop - end - - def equals(other) - get_class == other.get_class && @position == other.position - end -end - -# Intercepts the object action message -on :message, :second_object_action do |player, message| - if message.id == BANK_BOOTH_ID - player.start_action(BankAction.new(player, message.position)) - message.terminate - end -end - -on :message, :second_npc_action do |player, message| - npc = $world.npc_repository.get(message.index) - if BANKER_NPCS.include?(npc.id) - player.start_action(BankAction.new(player, npc.position)) - message.terminate - end -end diff --git a/game/data/plugins/bank/plugin.xml b/game/data/plugins/bank/plugin.xml deleted file mode 100644 index 894f4cf69..000000000 --- a/game/data/plugins/bank/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - bank - 1 - Bank - Opens the bank interface when players select 'use-quickly' on a bank booth. - - Graham - - - - - - diff --git a/game/data/plugins/bootstrap.rb b/game/data/plugins/bootstrap.rb deleted file mode 100644 index f36c1493a..000000000 --- a/game/data/plugins/bootstrap.rb +++ /dev/null @@ -1,239 +0,0 @@ -# A script bootstrapper for the rest of the plugins, which wraps Apollo's -# verbose Java-style API in a Ruby-style API. - -# ********************************** WARNING ********************************** -# * If you do not really understand what this is for, do not edit it without * -# * creating a backup! Many plugins rely on the behaviour of this script, and * -# * will break if you mess it up. * -# * * -# * This is actually part of the core server and in an ideal world shouldn't * -# * be changed. * -# ***************************************************************************** - -require 'java' - -java_import 'org.apollo.game.command.CommandListener' -java_import 'org.apollo.game.message.handler.MessageHandler' -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.entity.Player' -java_import 'org.apollo.game.model.event.EventListener' -java_import 'org.apollo.game.model.event.PlayerEvent' -java_import 'org.apollo.game.model.event.impl.LoginEvent' -java_import 'org.apollo.game.model.event.ProxyEvent' -java_import 'org.apollo.game.model.event.ProxyEventListener' -java_import 'org.apollo.game.model.entity.setting.PrivilegeLevel' -java_import 'org.apollo.game.scheduling.ScheduledTask' -java_import 'org.apollo.game.plugin.PluginContext' - -# Alias the privilege levels. -RIGHTS_ADMIN = PrivilegeLevel::ADMINISTRATOR -RIGHTS_MOD = PrivilegeLevel::MODERATOR -RIGHTS_STANDARD = PrivilegeLevel::STANDARD - -# Extends the (Ruby) String class with a method to convert a lower case, -# underscore delimited string to camel-case. -class String - - # Converts a ruby snake_case string to camel-case. - def camelize - gsub(/(?:^|_)(.)/) { $1.upcase } - end - -end - -# A CommandListener that executes a Proc object with two arguments: the player and the command. -class ProcCommandListener < CommandListener - - # Creates the ProcCommandListener. - def initialize(rights, block) - super(rights) - @block = block - end - - # Executes the block listening for the command. - def execute(player, command) - @block.call(player, command) - end - -end - -# A LogoutListener that executes a Proc object with the player argument. -class ProcEventListener - java_implements EventListener - - # Creates the ProcEventListener. - def initialize(block) - super() - @block = block - end - - # Executes the block handling the Event. - def handle(event) - args = [event] - args << event.player if event.is_a?(PlayerEvent) - @block.call(*args) - end - -end - -# A MessageHandler which executes a Proc object with two arguments: the player and the message. -class ProcMessageHandler < MessageHandler - - # Creates the ProcMessageHandler. - def initialize(block, option) - super($world) - @block = block - @option = option - end - - # Handles the message. - def handle(player, message) - @block.call(player, message) if @option == 0 || @option == message.option - end - -end - -# A ScheduledTask which executes a Proc object with one argument (itself). -class ProcScheduledTask < ScheduledTask - - # Creates the ProcScheduledTask. - def initialize(delay, immediate, block) - super(delay, immediate) - @block = block - end - - # Executes the block. - def execute - @block.call(self) - end - -end - -# Schedules a ScheduledTask. Can be used in two ways: passing an existing -# ScheduledTask object or passing a block along with one or two parameters: the -# delay (in pulses) and, optionally, the immediate flag. -# -# If the immediate flag is not given, it defaults to false. -# -# The ScheduledTask object is passed to the block so that methods such as -# setDelay and stop can be called. execute MUST NOT be called - if it is, the -# behaviour is undefined (and most likely it'll be bad). -def schedule(*args, &block) - if block_given? - fail 'Invalid combination of arguments.' unless (1..2).include?(args.length) - delay = args[0] - - immediate = args.length == 2 ? args[1] : false - $world.schedule(ProcScheduledTask.new(delay, immediate, block)) - elsif args.length == 1 - $world.schedule(args[0]) - else - fail 'Invalid combination of arguments.' - end -end - -@@proxy_listener = ProxyEventListener.new -$world.listen_for(ProxyEvent.java_class, @@proxy_listener) - -# Defines some sort of action to take upon an message. The following types of message are currently -# valid: -# -# * :command -# * :message -# * :button -# * Any valid Event, as a symbol in ruby snake_case form. -# -# A command takes one or two arguments (the command name and optionally the minimum rights level to -# use it). The minimum rights level defaults to STANDARD. The block should have two arguments: -# player and command. -# -# An message takes no arguments. The block should have two arguments: the player and the message -# object. -# -# A button takes one argument (the id). The block should have one argument: the player who clicked -# the button. -def on(type, *args, &block) - case type - when :command then on_command(args, block) - when :message then on_message(args, block) - when :button then on_button(args, block) - else - class_name = type.to_s.camelize.concat('Event') - - begin - type = Java::JavaClass.for_name("org.apollo.game.model.event.impl.#{class_name}") - rescue - @@proxy_listener.add(class_name, ProcEventListener.new(block)) - return - end - - $world.listen_for(type, ProcEventListener.new(block)) - end -end - -# Contains extension methods for World. -module WorldExtensions - - # Overrides World#submit, providing special-case behaviour for Events defined in Ruby, which - # need to be wrapped in a ProxyEvent, until https://github.com/jruby/jruby/issues/2359 is - # resolved. - def submit(event) - if event.java_class.name.end_with?(".Event", ".PlayerEvent") - event = ProxyEvent.new(event.class.name, event) - end - - super(event) - end - -end - -# Prepend the methods defined in WorldExtensions to World. -class World - prepend WorldExtensions -end - -private - -# Defines an action to be taken upon a button press. -def on_button(args, proc) - fail 'Button must have one argument.' unless args.length == 1 - - id = args[0].to_i - - on :message, :button do |player, message| - proc.call(player) if message.widget_id == id - end -end - -# Defines an action to be taken upon a message. -# The message can either be a symbol with the lowercase underscored class name, or the class itself. -def on_message(args, proc) - fail 'Message must have one or two arguments.' unless (1..2).include?(args.length) - - numbers = %w(first second third fourth fifth) - message = args[0].to_s - option = 0 - - (0...numbers.length).each do |index| - number = numbers[index] - - if message.start_with?(number) - option = index + 1 - message = message[number.length + 1, message.length] - break - end - end - - class_name = message.camelize.concat('Message') - message = Java::JavaClass.for_name("org.apollo.game.message.impl.#{class_name}") - - $ctx.add_message_handler(message, ProcMessageHandler.new(proc, option)) -end - -# Defines an action to be taken upon a command. -def on_command(args, proc) - fail 'Command message must have one or two arguments.' unless (1..2).include?(args.length) - - rights = args.length == 2 ? args[1] : RIGHTS_STANDARD - $world.command_dispatcher.register(args[0].to_s, ProcCommandListener.new(rights, proc)) -end diff --git a/game/data/plugins/chat/privacy/plugin.xml b/game/data/plugins/chat/privacy/plugin.xml deleted file mode 100644 index 1df608af7..000000000 --- a/game/data/plugins/chat/privacy/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - chat-privacy - 1 - Chat privacy - Adds chat privacy support. - - Major - - - - - - private-messaging - - \ No newline at end of file diff --git a/game/data/plugins/chat/privacy/privacy.rb b/game/data/plugins/chat/privacy/privacy.rb deleted file mode 100644 index 67c90d580..000000000 --- a/game/data/plugins/chat/privacy/privacy.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.entity.setting.PrivacyState' -java_import 'org.apollo.game.message.impl.SendFriendMessage' - -on :message, :privacy_option do |player, message| - player.chat_privacy = message.chat_privacy - player.friend_privacy = message.friend_privacy - player.trade_privacy = message.trade_privacy - - update_friends(player, message.friend_privacy == PrivacyState::OFF ? 0 : player.world_id) -end diff --git a/game/data/plugins/chat/private-messaging/friend.rb b/game/data/plugins/chat/private-messaging/friend.rb deleted file mode 100644 index 67ae6c287..000000000 --- a/game/data/plugins/chat/private-messaging/friend.rb +++ /dev/null @@ -1,102 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.message.impl.FriendServerStatusMessage' -java_import 'org.apollo.game.message.impl.IgnoreListMessage' -java_import 'org.apollo.game.message.impl.SendFriendMessage' -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.entity.setting.ServerStatus' -java_import 'org.apollo.game.model.entity.setting.PrivacyState' -java_import 'org.apollo.game.model.entity.Player' - -# Processes an add friend message, updating the logged-in status of the player (and the person they -# added) if necessary. -on :message, :add_friend do |player, message| - friend_username = message.username - player_username = player.username - - player.add_friend(friend_username) - friend = $world.get_player(friend_username) - - if friend.nil? # the friend the player added is offline - player.send(SendFriendMessage.new(friend_username, 0)) - elsif friend.friends_with(player_username) - - # player's private chat state is not off, so notify the friend - unless player.friend_privacy == PrivacyState::OFF - friend.send(SendFriendMessage.new(player_username, player.world_id)) - end - - # new friend's private chat state is not off, so notify the player - unless friend.friend_privacy == PrivacyState::OFF - player.send(SendFriendMessage.new(friend_username, friend.world_id)) - end - elsif friend.friend_privacy == PrivacyState::ON - # new friend doesn't have the player added but their private chat state is on, so inform the - # player of the world they are on. - player.send(SendFriendMessage.new(friend_username, friend.world_id)) - end -end - -# Processes a remove friend message, updating the logged-in status of the player if necessary. -on :message, :remove_friend do |player, message| - friend_username = message.username - player_username = player.username - - player.remove_friend(friend_username) - if $world.is_player_online(friend_username) - friend = $world.get_player(friend_username) - - remove = friend.friends_with(player_username) && player.friend_privacy != PrivacyState::ON - friend.send(SendFriendMessage.new(player_username, 0)) if remove - end -end - -# Update the friend server status and send the friend/ignore lists of the player logging in. -on :login do |_event, player| - player.send(FriendServerStatusMessage.new(ServerStatus::CONNECTING)) - player.send(IgnoreListMessage.new(player.ignored_usernames)) if player.ignored_usernames.size > 0 - - username = player.username - world = $world - iterator = player.friend_usernames.iterator - - # Iterate the player's friend list and notify the player that they are online if they are - while iterator.has_next - friend_username = iterator.next - friend = world.get_player(friend_username) - friend_world_id = (friend.nil? || !viewable?(friend, username)) ? 0 : friend.world_id - - player.send(SendFriendMessage.new(friend_username, friend_world_id)) - end - - player.send(FriendServerStatusMessage.new(ServerStatus::ONLINE)) - update_friends(player, player.world_id) -end - -# Notifies the player's friends that the player has logged out. -on :logout do |_event, player| - update_friends(player, 0) -end - -# Notifies the currently logged in players that the specified player has logged into the specified -# world, unless the newly logged-in player has their friend privacy state set to 'off'. -def update_friends(player, world = 0) - privacy = player.friend_privacy - - iterator = $world.player_repository.iterator - username = player.username - - while iterator.has_next - other = iterator.next - next if !other.friends_with(username) || other == player - - world = viewable?(player, other.username) ? world : 0 - other.send(SendFriendMessage.new(username, world)) - end -end - -# Checks if the specified player can be viewed by the player with the specified other username -def viewable?(player, other_username) - privacy = player.friend_privacy - privacy != PrivacyState::OFF && player.friends_with(other_username) || privacy == PrivacyState::ON -end diff --git a/game/data/plugins/chat/private-messaging/ignore.rb b/game/data/plugins/chat/private-messaging/ignore.rb deleted file mode 100644 index a903c9f83..000000000 --- a/game/data/plugins/chat/private-messaging/ignore.rb +++ /dev/null @@ -1,9 +0,0 @@ -on :message, :add_ignore do |player, message| - username = message.username - player.add_ignore(username) -end - -on :message, :remove_ignore do |player, message| - username = message.username - player.remove_ignore(username) -end diff --git a/game/data/plugins/chat/private-messaging/messaging.rb b/game/data/plugins/chat/private-messaging/messaging.rb deleted file mode 100644 index d1138bfcb..000000000 --- a/game/data/plugins/chat/private-messaging/messaging.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.message.impl.ForwardPrivateChatMessage' -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.entity.setting.PrivacyState' - -on :message, :private_chat do |player, message| - friend = $world.get_player(message.username) - - if interaction_permitted(player, friend) - chat = message.compressed_chat - friend.send(ForwardPrivateChatMessage.new(player.username, player.privilege_level, chat)) - end -end - -# Checks if the sender is permitted to interact with the friend they have added: -def interaction_permitted(sender, friend) - username = sender.username - return false if friend.nil? || friend.has_ignored(username) - - privacy = friend.friend_privacy - friend.friends_with(username) ? (privacy != PrivacyState::OFF) : (privacy == PrivacyState::ON) -end diff --git a/game/data/plugins/chat/private-messaging/plugin.xml b/game/data/plugins/chat/private-messaging/plugin.xml deleted file mode 100644 index a327a2dc5..000000000 --- a/game/data/plugins/chat/private-messaging/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - private-messaging - 1 - Private Messaging - Adds friend and ignore list support, and private messaging. - - Major - - - - - - - - \ No newline at end of file diff --git a/game/data/plugins/cmd/animate/animate.rb b/game/data/plugins/cmd/animate/animate.rb deleted file mode 100644 index 7e8c0c724..000000000 --- a/game/data/plugins/cmd/animate/animate.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Graphic' - -# Makes the player perform the animation with the specified id. -on :command, :animate, RIGHTS_MOD do |player, command| - args = command.arguments - next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::animate [animation-id]') - - player.play_animation(Animation.new(args[0].to_i)) -end - -# Makes the player perform the graphic with the specified id. -on :command, :graphic, RIGHTS_MOD do |player, command| - args = command.arguments - next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::graphic [graphic-id]') - - player.play_graphic(Graphic.new(args[0].to_i)) -end diff --git a/game/data/plugins/cmd/animate/plugin.xml b/game/data/plugins/cmd/animate/plugin.xml deleted file mode 100644 index 8f08c8659..000000000 --- a/game/data/plugins/cmd/animate/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - cmd-animate - 1 - Animate Commands - Adds animation-related commands. - - Major - - - - - - diff --git a/game/data/plugins/cmd/bank/bank.rb b/game/data/plugins/cmd/bank/bank.rb deleted file mode 100644 index 3946b783b..000000000 --- a/game/data/plugins/cmd/bank/bank.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'java' - -# Opens the player's bank. -on :command, :bank, RIGHTS_ADMIN do |player, _command| - player.open_bank -end diff --git a/game/data/plugins/cmd/bank/plugin.xml b/game/data/plugins/cmd/bank/plugin.xml deleted file mode 100644 index 23d7d0db2..000000000 --- a/game/data/plugins/cmd/bank/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - cmd-bank - 1 - Bank Command - Adds a ::bank command. - - Graham - - - - - - \ No newline at end of file diff --git a/game/data/plugins/cmd/item/item.rb b/game/data/plugins/cmd/item/item.rb deleted file mode 100644 index 9d22ce045..000000000 --- a/game/data/plugins/cmd/item/item.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'java' - -java_import 'org.apollo.cache.def.ItemDefinition' - -# Adds the specified item to the player's inventory. -on :command, :item, RIGHTS_ADMIN do |player, command| - args = command.arguments - next unless valid_arg_length(args, (1..2), player, 'Invalid syntax - ::item [id] [amount]') - - id = args[0].to_i - amount = args.length == 2 ? args[1].to_i : 1 - - if id < 0 || id >= ItemDefinition.count - player.send_message('The item id you specified is out of bounds!') - next - end - - player.inventory.add(id, amount) -end - -# Removes the specified item from the player's inventory. -on :command, :remove, RIGHTS_MOD do |player, command| - args = command.arguments - next unless valid_arg_length(args, (1..2), player, 'Invalid syntax - ::remove [id] [amount]') - - id = args[0].to_i - amount = args.length == 2 ? args[1].to_i : 1 - - if id < 0 || id >= ItemDefinition.count - player.send_message('The item id you specified is out of bounds!') - next - end - - player.inventory.remove(id, amount) -end - -# Clears the player's inventory. -on :command, :empty, RIGHTS_MOD do |player, _command| - player.inventory.clear -end - -# Gives the player 1,000 of each rune. -on :command, :runes, RIGHTS_ADMIN do |player, _command| - (554..566).each { |item| player.inventory.add(item, 1000) } -end diff --git a/game/data/plugins/cmd/item/plugin.xml b/game/data/plugins/cmd/item/plugin.xml deleted file mode 100644 index 2a7976fd9..000000000 --- a/game/data/plugins/cmd/item/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - cmd-item - 1 - Item Commands - Adds ::item, ::remove and ::empty commands. - - Graham - - - - - - \ No newline at end of file diff --git a/game/data/plugins/cmd/lookup/lookup.rb b/game/data/plugins/cmd/lookup/lookup.rb deleted file mode 100644 index 5851c0ada..000000000 --- a/game/data/plugins/cmd/lookup/lookup.rb +++ /dev/null @@ -1,69 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.cache.def.ItemDefinition' -java_import 'org.apollo.cache.def.NpcDefinition' -java_import 'org.apollo.cache.def.ObjectDefinition' -java_import 'org.apollo.game.model.entity.Entity' -java_import 'org.apollo.game.model.entity.Player' - -on :command, :lookup, RIGHTS_ADMIN do |player, command| - args = command.arguments.to_a - message = 'Invalid syntax - ::lookup [npc/object/item] [name]' - next unless valid_arg_length(args, (1..10), player, message) - - type = args.shift.downcase - limit = args.first.to_i == 0 ? 5 : args.shift.to_i - name = args.join(' ').downcase - - if %w(npc object item).index(type).nil? - player.send_message('Invalid syntax - ::lookup [npc/object/item] [name]') - next - end - - ids = find_entities(type, name, limit).join(', ') - - message = ids.empty? ? "Could not find an #{type} called #{name}." : - "Possible ids for \"#{name}\" are: #{ids}." - player.send_message(message) -end - -# Sends the user a message with information about the item with the specified id. -on :command, :iteminfo, RIGHTS_ADMIN do |player, command| - args = command.arguments - next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::iteminfo [item id]') - - id = args[0].to_i - definition = ItemDefinition.lookup(id) - members = definition.is_members_only ? 'members' : 'not members' - - player.send_message("Item #{id} is called #{definition.name}, is #{members} only, and has a "\ - "team of #{definition.team}.") - player.send_message("Its description is \"#{definition.description}\".") -end - -# Sends the user a message with information about the npc with the specified id. -on :command, :npcinfo, RIGHTS_ADMIN do |player, command| - args = command.arguments - next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::npcinfo [npc id]') - - id = args[0].to_i - definition = NpcDefinition.lookup(id) - is_combative = definition.has_combat_level ? "has a combat level of #{definition.combat_level}" : - 'does not have a combat level' - - player.send_message("Npc #{id} is called #{definition.name} and #{is_combative}.") - player.send_message("Its description is \"#{definition.description}\".") -end - -# Sends the user a message with information about the object with the specified id. -on :command, :objectinfo, RIGHTS_ADMIN do |player, command| - args = command.arguments - next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::objectinfo [object id]') - - id = args[0].to_i - definition = ObjectDefinition.lookup(id) - player.send_message("Object #{id} is called #{definition.name} and its description is "\ - "\"#{definition.description}\".") - player.send_message("Its width is #{definition.width} and its length is #{definition.length}.") -end diff --git a/game/data/plugins/cmd/lookup/plugin.xml b/game/data/plugins/cmd/lookup/plugin.xml deleted file mode 100644 index e4d84e4b3..000000000 --- a/game/data/plugins/cmd/lookup/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - cmd-lookup - 1 - Lookup Command - Adds a ::lookup command. - - Major - - - - - - util - - \ No newline at end of file diff --git a/game/data/plugins/cmd/messaging/broadcast.rb b/game/data/plugins/cmd/messaging/broadcast.rb deleted file mode 100644 index ddace7419..000000000 --- a/game/data/plugins/cmd/messaging/broadcast.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.entity.Player' - -# Adds a command to broadcast a message to every player on the server. -on :command, :broadcast, RIGHTS_ADMIN do |player, command| - message = command.arguments.to_a.join(' ') - broadcast = "[Broadcast] #{player.get_username.capitalize}: #{message}" - - $world.player_repository.each { |other| other.send_message(broadcast) } -end diff --git a/game/data/plugins/cmd/messaging/plugin.xml b/game/data/plugins/cmd/messaging/plugin.xml deleted file mode 100644 index 546062c0c..000000000 --- a/game/data/plugins/cmd/messaging/plugin.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - message - 1 - Messaging commands - Adds various message-related commands, such as enabling the server-side chat filter or broadcasting a message. - - Major - xEliqa - - - - - - diff --git a/game/data/plugins/cmd/npc/plugin.xml b/game/data/plugins/cmd/npc/plugin.xml deleted file mode 100644 index 4cca1a6ef..000000000 --- a/game/data/plugins/cmd/npc/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - cmd-npc - 1 - Npc Commands - Adds npc-related commands. - - Major - - - - - - \ No newline at end of file diff --git a/game/data/plugins/cmd/npc/spawn.rb b/game/data/plugins/cmd/npc/spawn.rb deleted file mode 100644 index 57cd88e1c..000000000 --- a/game/data/plugins/cmd/npc/spawn.rb +++ /dev/null @@ -1,68 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.Position' -java_import 'org.apollo.game.model.entity.Npc' - -# An array of npcs that cannot be spawned. -blacklist = [] - -# Spawns a non-blacklisted npc in the specified position, or the player's position if both 'x' and -# 'y' are not supplied. -on :command, :spawn, RIGHTS_ADMIN do |player, command| - args = command.arguments - unless [1, 3, 4].include?(args.length) && (id = args[0].to_i) > -1 - player.send_message('Invalid syntax - ::spawn [npc id] [optional-x] [optional-y] [optional-z]') - return - end - - if blacklist.include?(id) - player.send_message("Sorry, npc #{id} is blacklisted!") - return - end - - if args.length == 1 - position = player.position - else - height = args.length == 4 ? args[3].to_i : player.position.height - position = Position.new(args[1].to_i, args[2].to_i, height) - end - - $world.register(Npc.new($world, id, position)) -end - -# Mass spawns npcs around the player. -on :command, :mass, RIGHTS_ADMIN do |player, command| - args = command.arguments - unless args.length == 2 && (id = args[0].to_i) > -1 && (1..5).include?(range = args[1].to_i) - player.send_message('Invalid syntax - ::spawn [npc id] [range (1-5)]') - return - end - - if blacklist.include?(id) - player.send_message("Sorry, npc #{id} is blacklisted!") - return - end - - center_position = player.position - - min_x = center_position.x - range - min_y = center_position.y - range - max_x = center_position.x + range - max_y = center_position.y + range - z = center_position.height - - (min_x..max_x).each do |x| - (min_y..max_y).each do |y| - $world.register(Npc.new($world, id, Position.new(x, y, z))) - end - end - - player.send_message("Mass spawning npcs with id #{id}.") -end - -# Unregisters all npcs from the world npc repository. -on :command, :clearnpcs, RIGHTS_ADMIN do |player, _command| - $world.npc_repository.each { |npc| $world.unregister(npc) } - player.send_message('Unregistered all npcs from the world.') -end diff --git a/game/data/plugins/cmd/punishment/plugin.xml b/game/data/plugins/cmd/punishment/plugin.xml deleted file mode 100644 index a5c7a7e0e..000000000 --- a/game/data/plugins/cmd/punishment/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - punishment - 1 - Punishment commands - Adds various punishment commands, such as banning or muting a player. - - lare96 - - - - - - \ No newline at end of file diff --git a/game/data/plugins/cmd/punishment/punish.rb b/game/data/plugins/cmd/punishment/punish.rb deleted file mode 100644 index 997222b42..000000000 --- a/game/data/plugins/cmd/punishment/punish.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.entity.Player' - -# Adds a command to mute a player. Admins cannot be muted. -on :command, :mute, RIGHTS_MOD do |player, command| - name = command.arguments.to_a.join(' ') - on_player = $world.get_player(name) - - if validate(player, on_player) - on_player.muted = true - on_player.send_message('You have just been muted.') - player.send_message("You have just muted #{on_player.get_username}.") - end -end - -# Adds a command to unmute a player. -on :command, :unmute, RIGHTS_MOD do |player, command| - name = command.arguments.to_a.join(' ') - on_player = $world.get_player(name) - - if validate(player, on_player) - on_player.muted = false - on_player.send_message('You are no longer muted.') - player.send_message("You have just unmuted #{on_player.get_username}.") - end -end - -# Adds a command to ban a player. Admins cannot be banned. -on :command, :ban, RIGHTS_ADMIN do |player, command| - name = command.arguments.to_a.join(' ') - on_player = $world.get_player(name) - - if validate(player, on_player) - on_player.banned = true - on_player.logout # TODO force logout - player.send_message("You have just banned #{on_player.get_username}.") - end -end - -# Ensures the player isn't nil, and that they aren't an Administrator. -def validate(player, on_player) - if on_player.nil? - player.send_message('That player does not exist.') - return false - elsif on_player.get_privilege_level == RIGHTS_ADMIN - player.send_message('You cannot perform this action on Administrators.') - return false - end - - true -end diff --git a/game/data/plugins/cmd/skill/plugin.xml b/game/data/plugins/cmd/skill/plugin.xml deleted file mode 100644 index 519ff15b0..000000000 --- a/game/data/plugins/cmd/skill/plugin.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - cmd-skill - 1 - Skill Commands - Adds skill-related commands. - - Graham - Major - - - - - - diff --git a/game/data/plugins/cmd/skill/skill.rb b/game/data/plugins/cmd/skill/skill.rb deleted file mode 100644 index 466fc19c1..000000000 --- a/game/data/plugins/cmd/skill/skill.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'java' -java_import 'org.apollo.game.model.entity.SkillSet' -java_import 'org.apollo.game.model.entity.Skill' - -# Maximises the player's skill set. -on :command, :max, RIGHTS_ADMIN do |player, _command| - skills = player.skill_set - - (0...skills.size).each do |skill| - skills.add_experience(skill, SkillSet::MAXIMUM_EXP) - end -end - -# Levels the specified skill to the specified level, optionally updating the current level as well. -on :command, :level, RIGHTS_ADMIN do |player, command| - args = command.arguments - unless (2..3).include?(args.length) && (0..20).include?(skill_id = args[0].to_i) && - (1..99).include?(level = args[1].to_i) - player.send_message('Invalid syntax - ::level [skill-id] [level]') - next - end - - experience = SkillSet.get_experience_for_level(level) - current = level - - if args.length == 3 && args[2].to_s == 'old' - skill = player.skill_set.skill(skill_id) - current = skill.current_level - end - - player.skill_set.set_skill(skill_id, Skill.new(experience, current, level)) -end - -# Adds the specified amount of experience to the specified skill. -on :command, :xp, RIGHTS_ADMIN do |player, command| - args = command.arguments - unless args.length == 2 && (0..20).include?(skill_id = args[0].to_i) && - (experience = args[1].to_i) >= 0 - player.send_message('Invalid syntax - ::xp [skill-id] [experience]') - return - end - - player.skill_set.add_experience(skill_id, experience) -end diff --git a/game/data/plugins/cmd/teleport/plugin.xml b/game/data/plugins/cmd/teleport/plugin.xml deleted file mode 100644 index be9346a49..000000000 --- a/game/data/plugins/cmd/teleport/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - cmd-teleport - 1 - Teleport Commands - Adds ::pos and ::tele commands. - - Graham - - - - - - diff --git a/game/data/plugins/cmd/teleport/teleport.rb b/game/data/plugins/cmd/teleport/teleport.rb deleted file mode 100644 index 671a92cf9..000000000 --- a/game/data/plugins/cmd/teleport/teleport.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Position' - -# Sends the player's position. -on :command, :pos, RIGHTS_MOD do |player, _command| - player.send_message("You are at: #{player.position}.") -end - -# Teleports the player to the specified position. -on :command, :tele, RIGHTS_ADMIN do |player, command| - args = command.arguments - next unless valid_arg_length(args, (2..3), player, 'Invalid syntax - ::tele [x] [y] [optional-z]') - - x = args[0].to_i - y = args[1].to_i - z = args.length == 3 ? args[2].to_i : player.position.height - - player.teleport(Position.new(x, y, z)) if (0..4).include?(z) -end diff --git a/game/data/plugins/combat/plugin.xml b/game/data/plugins/combat/plugin.xml deleted file mode 100644 index b236b6b22..000000000 --- a/game/data/plugins/combat/plugin.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - combat - 1 - Combat - Manages combat between game characters. - - Ryley - - - - - - attributes - areas - - diff --git a/game/data/plugins/combat/wilderness.rb b/game/data/plugins/combat/wilderness.rb deleted file mode 100644 index e62989e47..000000000 --- a/game/data/plugins/combat/wilderness.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.entity.Player' -java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' -java_import 'org.apollo.game.message.impl.OpenOverlayMessage' - -declare_attribute(:wilderness_level, 0, :transient) - -# Constants constants related to the wilderness -module WildernessConstants - - # The wilderness level overlay interface id - OVERLAY_INTERFACE_ID = 197 - - # The wilderness level string id - LEVEL_STRING_ID = 199 - -end - -# Determines the wilderness level for the specified position -def wilderness_level(position) - ((position.y - 3520) / 8).ceil + 1 -end - -area_action :wilderness_level do - on_entry do |player, position| - player.wilderness_level = wilderness_level(position) - player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID) - - id = WildernessConstants::LEVEL_STRING_ID - player.send(SetWidgetTextMessage.new(id, "Level: #{player.wilderness_level}")) - show_action(player, ATTACK_ACTION) - end - - while_in do |player, position| - current = player.wilderness_level - updated = wilderness_level(position) - - if current != updated - player.wilderness_level = updated - - id = WildernessConstants::LEVEL_STRING_ID - player.send(SetWidgetTextMessage.new(id, "Level: #{player.wilderness_level}")) - end - end - - on_exit do |player, position| - player.wilderness_level = 0 - player.interface_set.close - - player.send(OpenOverlayMessage.new(-1)) - hide_action(player, ATTACK_ACTION) - end -end - -# Monkey patch the existing player class to add method of checking whether or not a player is -# within the wilderness -class Player - - def in_wilderness - wilderness_level > 0 - end - -end - -area name: :wilderness, coordinates: [2945, 3522, 3390, 3972, 0], actions: :wilderness_level diff --git a/game/data/plugins/consumables/consumable.rb b/game/data/plugins/consumables/consumable.rb deleted file mode 100644 index a0748d4f9..000000000 --- a/game/data/plugins/consumables/consumable.rb +++ /dev/null @@ -1,79 +0,0 @@ -require 'java' - -# A map of item ids to consumables. -CONSUMABLES = {} - -# The id of the food consumption animation. -CONSUME_ANIMATION_ID = 829 - -# Contains the different types of consumables -module ConsumableType - FOOD = 1 - POTION = 2 - DRINK = 3 -end - -# An item that can be consumed to produce a skill effect. -class Consumable - attr_reader :name, :id, :sound, :delay, :type - - def initialize(name, id, sound, delay, type) - @name = name.to_s.gsub(/_/, ' ') - @id = id - @sound = sound - @delay = delay - @type = type - end - - def consume(_player) - # Override to provide specific functionality. - end - -end - -# Appends a consumable to the map, with its id as the key. -def append_consumable(consumable) - CONSUMABLES[consumable.id] = consumable -end - -# An Action used for food consumption. -class ConsumeAction < Action - attr_reader :consumable - - def initialize(player, slot, consumable) - super(2, true, player) - @consumable = consumable - @slot = slot - @executions = 0 - end - - def execute - if @executions == 0 - mob.inventory.reset(@slot) - @consumable.consume(mob) - - mob.play_animation(Animation.new(CONSUME_ANIMATION_ID)) - end - - @executions += 1 - - if @executions >= @consumable.delay - stop - end - end - - def equals(other) - get_class == other.get_class && mob == other.mob && @consumable.type == other.consumable.type - end - -end - -# Intercepts the first item option message and consumes the consumable, if necessary. -on :message, :first_item_option do |player, message| - consumable = CONSUMABLES[message.id] - - unless consumable.nil? - player.start_action(ConsumeAction.new(player, message.slot, consumable)) - message.terminate - end -end diff --git a/game/data/plugins/consumables/drink.rb b/game/data/plugins/consumables/drink.rb deleted file mode 100644 index 4f0d5fe22..000000000 --- a/game/data/plugins/consumables/drink.rb +++ /dev/null @@ -1,76 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.entity.Skill' -java_import 'org.apollo.game.model.entity.Player' - -private - -# The id the of the sound made when drinking something. -#TODO change sound if this id is incorrect -DRINK_SOUND = 334 - -# Represents something drinkable, such as a jug of wine or a nettle tea. -class Drink < Consumable - - def initialize(name, id, restoration, replace, delay) - super(name, id, DRINK_SOUND, delay, ConsumableType::DRINK) - @restoration = restoration - @replace = replace - end - - # Restore the appropriate amount of hitpoints when consumed. - def consume(player) - hitpoints = player.skill_set.skill(Skill::HITPOINTS) - hitpoints_current = player.skill_set.get_current_level(Skill::HITPOINTS) - new_curr = [hitpoints.current_level + @restoration, hitpoints.maximum_level].min - - player.inventory.add(@replace) unless @replace == -1 - - player.send_message("You drink the #{name}.") - player.send_message('It heals some health.') if new_curr > hitpoints_current - - skill = Skill.new(hitpoints.experience, new_curr, hitpoints.maximum_level) - player.skill_set.set_skill(Skill::HITPOINTS, skill) - end - -end - -# The default delay before the consumable is drunk. -DEFAULT_DELAY = 3 - -# Appends a drink item to the list of consumables. -def drink(hash) - unless hash.has_keys?(:name, :id, :restoration) - fail 'Hash must contain a name, id, and a restoration value.' - end - - name, id, restoration = hash[:name], hash[:id], hash[:restoration]; - replace = hash[:replace] || -1 - delay = hash[:delay] || DEFAULT_DELAY # TODO: ?? - - append_consumable(Drink.new(name, id, restoration, replace, delay)) -end - -# Wine -drink name: :jug_of_wine, id: 1993, restoration: 11 - -# Hot Drinks -drink name: :nettle_tea, id: 4239, restoration: 3 -drink name: :nettle_tea, id: 4240, restoration: 3 - -# Gnome Cocktails -drink name: :fruit_blast, id: 2034, restoration: 9 -drink name: :fruit_blast, id: 2084, restoration: 9 -drink name: :pineapple_punch, id: 2036, restoration: 9 -drink name: :pineapple_punch, id: 2048, restoration: 9 -drink name: :wizard_blizzard, id: 2040, restoration: 5 # -4 attack, +5 strength also -drink name: :wizard_blizzard, id: 2054, restoration: 5 # -4 attack, +5 strength also -drink name: :short_green_guy, id: 2038, restoration: 5 # -4 attack, +5 strength also -drink name: :short_green_guy, id: 2080, restoration: 5 # -4 attack, +5 strength also -drink name: :drunk_dragon, id: 2032, restoration: 5 # -4 attack, +6 strength also -drink name: :drunk_dragon, id: 2092, restoration: 5 # -4 attack, +6 strength also -drink name: :chocolate_saturday, id: 2030, restoration: 7 # -4 attack, +6 strength also -drink name: :chocolate_saturday, id: 2074, restoration: 7 # -4 attack, +6 strength also -drink name: :blurberry_special, id: 2028, restoration: 7 # -4 attack, +6 strength also -drink name: :blurberry_special, id: 2064, restoration: 7 # -4 attack, +6 strength also diff --git a/game/data/plugins/consumables/food.rb b/game/data/plugins/consumables/food.rb deleted file mode 100644 index a128c4286..000000000 --- a/game/data/plugins/consumables/food.rb +++ /dev/null @@ -1,221 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.entity.Skill' -java_import 'org.apollo.game.model.entity.Player' - -private - -# The id the of the sound made when eating food. -EAT_FOOD_SOUND = 317 - -# Represents an edible piece of food, such as bread or fish. -# TODO: delay eating times -class Food < Consumable - - def initialize(name, id, restoration, replace, delay) - super(name, id, EAT_FOOD_SOUND, delay, ConsumableType::FOOD) - @restoration = restoration - @replace = replace - end - - # Restore the appropriate amount of hitpoints when consumed. - def consume(player) - hitpoints = player.skill_set.skill(Skill::HITPOINTS) - hitpoints_current = player.skill_set.get_current_level(Skill::HITPOINTS) - new_curr = [hitpoints.current_level + @restoration, hitpoints.maximum_level].min - - player.inventory.add(@replace) unless @replace == -1 - - player.send_message("You eat the #{name}.") - player.send_message('It heals some health.') if new_curr > hitpoints_current - - skill = Skill.new(hitpoints.experience, new_curr, hitpoints.maximum_level) - player.skill_set.set_skill(Skill::HITPOINTS, skill) - end - -end - -# The default delay before a piece of food is eaten -DEFAULT_DELAY = 3 - -# Appends a food item to the list of consumables. -def food(hash) - unless hash.has_keys?(:name, :id, :restoration) - fail 'Hash must contain a name, id, and a restoration value.' - end - - name, id, restoration = hash[:name], hash[:id], hash[:restoration]; - replace = hash[:replace] || -1 - delay = hash[:delay] || DEFAULT_DELAY # TODO: ?? - - append_consumable(Food.new(name, id, restoration, replace, delay)) -end - -# TODO: special effects -food name: :cooked_slimy_eel, id: 3381, restoration: 6 # this has a chance to heal 6 to 10 hp -food name: :thin_snail_meat, id: 3369, restoration: 5 # this has a chance to heal 5 to 7 hp -food name: :fat_snail_meat, id: 3373, restoration: 2 # this has a chance to heal 7 to 9 hp -food name: :watermelon_slice, id: 5984, restoration: 0 # this heals 5% of player's life -food name: :cooked_karambwan, id: 3146, restoration: 0 # poisons player(50) -food name: :spider_on_stick, id: 6297, restoration: 7 # heals between 7 and 10 -food name: :spider_on_shaft, id: 6299, restoration: 7 # heals between 7 and 10 - -# Meats/Fish -food name: :anchovies, id: 319, restoration: 1 -food name: :crab_meat, id: 7521, restoration: 2, replace: 7523 -food name: :crab_meat, id: 7523, restoration: 2, replace: 7524 -food name: :crab_meat, id: 7524, restoration: 2, replace: 7525 -food name: :crab_meat, id: 7525, restoration: 2, replace: 7526 -food name: :crab_meat, id: 7526, restoration: 2 -food name: :shrimp, id: 315, restoration: 3 -food name: :sardine, id: 325, restoration: 3 -food name: :cooked_meat, id: 2142, restoration: 3 -food name: :cooked_chicken, id: 2140, restoration: 3 -food name: :ugthanki_meat, id: 1861, restoration: 3 -food name: :karambwanji, id: 3151, restoration: 3 -food name: :cooked_rabbit, id: 3228, restoration: 5 -food name: :herring, id: 347, restoration: 6 -food name: :trout, id: 333, restoration: 7 -food name: :cod, id: 339, restoration: 7 -food name: :mackeral, id: 355, restoration: 7 -food name: :roast_rabbit, id: 7223, restoration: 7 -food name: :pike, id: 351, restoration: 8 -food name: :lean_snail_meat, id: 3371, restoration: 8 -food name: :salmon, id: 329, restoration: 9 -food name: :tuna, id: 361, restoration: 10 -food name: :lobster, id: 379, restoration: 12 -food name: :bass, id: 365, restoration: 13 -food name: :swordfish, id: 373, restoration: 14 -food name: :cooked_jubbly, id: 7568, restoration: 15 -food name: :monkfish, id: 7946, restoration: 16 -food name: :cooked_karambwan, id: 3144, restoration: 18, delay: 0 -food name: :shark, id: 385, restoration: 20 -food name: :sea_turtle, id: 397, restoration: 21 -food name: :manta_ray, id: 391, restoration: 22 - -# Breads/Wraps -food name: :bread, id: 2309, restoration: 5 -food name: :oomlie_wrap, id: 2343, restoration: 14 -food name: :ugthanki_kebab, id: 1883, restoration: 19 - -# Fruits -food name: :banana, id: 1963, restoration: 2 -food name: :sliced_banana, id: 3162, restoration: 2 -food name: :lemon, id: 2102, restoration: 2 -food name: :lemon_chunks, id: 2104, restoration: 2 -food name: :lemon_slices, id: 2106, restoration: 2 -food name: :lime, id: 2120, restoration: 2 -food name: :lime_chunks, id: 2122, restoration: 2 -food name: :lime_slices, id: 2124, restoration: 2 -food name: :strawberry, id: 5504, restoration: 5 -food name: :papaya_fruit, id: 5972, restoration: 8 -food name: :pineapple_chunks, id: 2116, restoration: 2 -food name: :pineapple_ring, id: 2118, restoration: 2 -food name: :orange, id: 2108, restoration: 2 -food name: :orange_rings, id: 2110, restoration: 2 -food name: :orange_slices, id: 2112, restoration: 2 - -# Pies -# TODO: pie special effects (e.g. fish pie raises fishing level) -food name: :redberry_pie, id: 2325, restoration: 5, replace: 2333, delay: 1 -food name: :redberry_pie, id: 2333, restoration: 5, delay: 1 - -food name: :meat_pie, id: 2327, restoration: 6, replace: 2331, delay: 1 -food name: :meat_pie, id: 2331, restoration: 6, delay: 1 - -food name: :apple_pie, id: 2323, restoration: 7, replace: 2335, delay: 1 -food name: :apple_pie, id: 2335, restoration: 7, delay: 1 - -food name: :fish_pie, id: 7188, restoration: 6, replace: 7190, delay: 1 -food name: :fish_pie, id: 7190, restoration: 6, delay: 1 - -food name: :admiral_pie, id: 7198, restoration: 8, replace: 7200, delay: 1 -food name: :admiral_pie, id: 7200, restoration: 8, delay: 1 - -food name: :wild_pie, id: 7208, restoration: 11, replace: 7210, delay: 1 -food name: :wild_pie, id: 7210, restoration: 11, delay: 1 - -food name: :summer_pie, id: 7218, restoration: 11, replace: 7220, delay: 1 -food name: :summer_pie, id: 7220, restoration: 11, delay: 1 - -# Stews -food name: :stew, id: 2003, restoration: 11 -food name: :banana_stew, id: 4016, restoration: 11 -food name: :curry, id: 2011, restoration: 19 - -# Pizzas -food name: :plain_pizza, id: 2289, restoration: 7, replace: 2291 -food name: :plain_pizza, id: 2291, restoration: 7 - -food name: :meat_pizza, id: 2293, restoration: 8, replace: 2295 -food name: :meat_pizza, id: 2295, restoration: 8 - -food name: :anchovy_pizza, id: 2297, restoration: 9, replace: 2299 -food name: :anchovy_pizza, id: 2299, restoration: 9 - -food name: :pineapple_pizza, id: 2301, restoration: 11, replace: 2303 -food name: :pineapple_pizza, id: 2303, restoration: 11 - -# Cakes -food name: :fishcake, id: 7530, restoration: 11 - -food name: :cake, id: 1891, restoration: 4, replace: 1893 -food name: :cake, id: 1893, restoration: 4, replace: 1895 -food name: :cake, id: 1895, restoration: 4 - -food name: :chocolate_cake, id: 1897, restoration: 5, replace: 1899 -food name: :chocolate_cake, id: 1899, restoration: 5, replace: 1901 -food name: :chocolate_cake, id: 1901, restoration: 5 - -# Vegetables -food name: :potato, id: 1942, restoration: 1 -food name: :spinach_roll, id: 1969, restoration: 2 -food name: :baked_potato, id: 6701, restoration: 4 -food name: :sweetcorn, id: 5988, restoration: 10 -food name: :sweetcorn_bowl, id: 7088, restoration: 13 -food name: :potato_with_butter, id: 6703, restoration: 14 -food name: :chili_potato, id: 7054, restoration: 14 -food name: :potato_with_cheese, id: 6705, restoration: 16 -food name: :egg_potato, id: 7056, restoration: 16 -food name: :mushroom_potato, id: 7058, restoration: 20 -food name: :tuna_potato, id: 7060, restoration: 22 - -# Dairy -food name: :cheese, id: 1985, restoration: 2 -food name: :pot_of_cream, id: 2130, restoration: 1 - -# Gnome Food -food name: :toads_legs, id: 2152, restoration: 3 - -# Gnome Bowls -food name: :worm_hole, id: 2191, restoration: 12 -food name: :worm_hole, id: 2233, restoration: 12 -food name: :vegetable_ball, id: 2195, restoration: 12 -food name: :vegetable_ball, id: 2235, restoration: 12 -food name: :tangled_toads_legs, id: 2187, restoration: 15 -food name: :tangled_toads_legs, id: 2231, restoration: 15 -food name: :chocolate_bomb, id: 2185, restoration: 15 -food name: :chocolate_bomb, id: 2229, restoration: 15 - -# Gnome Crunchies -food name: :toad_crunchies, id: 2217, restoration: 7 -food name: :toad_crunchies, id: 2243, restoration: 7 -food name: :spicy_crunchies, id: 2213, restoration: 7 -food name: :spicy_crunchies, id: 2241, restoration: 7 -food name: :worm_crunchies, id: 2205, restoration: 8 -food name: :worm_crunchies, id: 2237, restoration: 8 -food name: :chocchip_crunchies, id: 2209, restoration: 7 -food name: :chocchip_crunchies, id: 2239, restoration: 7 - -# Gnome Battas -food name: :fruit_batta, id: 2225, restoration: 11 -food name: :fruit_batta, id: 2277, restoration: 11 -food name: :toad_batta, id: 2221, restoration: 11 -food name: :toad_batta, id: 2255, restoration: 11 -food name: :worm_batta, id: 2219, restoration: 11 -food name: :worm_batta, id: 2253, restoration: 11 -food name: :vegetable_batta, id: 2227, restoration: 11 -food name: :vegetable_batta, id: 2281, restoration: 11 -food name: :cheese_tom_batta, id: 2223, restoration: 11 -food name: :cheese_tom_batta, id: 2259, restoration: 11 diff --git a/game/data/plugins/consumables/plugin.xml b/game/data/plugins/consumables/plugin.xml deleted file mode 100644 index 50f2ea90c..000000000 --- a/game/data/plugins/consumables/plugin.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - consumables - 0.1 - Consumables - Adds support for consumables (e.g. potions, food). - - Major - Ryley - - - - - - - - \ No newline at end of file diff --git a/game/data/plugins/consumables/potions.rb b/game/data/plugins/consumables/potions.rb deleted file mode 100644 index c3efe8fbb..000000000 --- a/game/data/plugins/consumables/potions.rb +++ /dev/null @@ -1,136 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.entity.Skill' - -private - -# Contains potion-related constants. -module Constants - - # The id of the sound made when drinking a potion. - DRINK_POTION_SOUND = 334 - - # The id of an empty vial. - EMPTY_VIAL_ID = 229 - - # The delay between drinking potions - POTION_DELAY = 2 -end - -# A drinkable potion. -class Potion < Consumable - - def initialize(id, name, doses) - super(name, id, Constants::DRINK_POTION_SOUND, Constants::POTION_DELAY, ConsumableType::POTION) - @doses = doses - end - - def consume(player) - index = @doses.find_index(id) + 1 - - if index != @doses.length # Consumable removes the old potion for us, so don't do it here. - player.inventory.add(@doses[index]) - player.send_message("You drink some of your #{name} potion.") - - remaining = "You have #{@doses.length - index} dose#{'s' unless index == 3} of potion left." - player.send_message(remaining) - else - player.send_message('You drink the last of your potion.') - player.inventory.add(Constants::EMPTY_VIAL_ID) - end - - drink(player) - end - - def drink(_player) - # Override to provide functionality - end - -end - -# A potion that can be consumed to boost the current skill level of a stat (or stats). -class BoostingPotion < Potion - - def initialize(id, name, doses, skills, boost) - super(id, name, doses) - @skill_ids = skills.is_a?(Array) ? skills : [skills] - @boost = boost - end - - def drink(player) - @skill_ids.each do |id| - skill = player.skill_set.skill(id) - max = skill.maximum_level - level = [skill.current_level, max].min - - new_current = @boost.call(max, level).floor - player.skill_set.set_skill(id, Skill.new(skill.experience, new_current, max)) - end - end - -end - -# Returns the parameters for the potion, as an array. Fails if any of the specified keys do not -# exist. -def get_parameters(hash, keys) - fail "Hash must contain the following keys: #{keys.join(', ')}." unless hash.has_keys?(*keys) - - keys.map { |key| hash[key] } -end - -# Appends a potion to the list of consumables. -def potion(hash) - class_name = 'Potion' - keys = [:name, :doses] - - unless (hash.size == 2) - keys << :skills << :boost - class_name.prepend('Boosting') - end - - parameters = get_parameters(hash, keys) - doses = hash[:doses] - doses.each { |dose| append_consumable(Object.const_get(class_name).new(dose, *parameters)) } -end - -# Some frequently-used boosts and skills -# Lambda parameters are | maximum_skill_level, current_skill_level | -basic_combat_boost = ->(_, level) { level * 1.10 + 3 } -super_combat_boost = ->(_, level) { level * 1.15 + 5 } -non_combat_boost = ->(_, level) { level + 3 } - -ATTACK, STRENGTH, DEFENCE = Skill::ATTACK, Skill::STRENGTH, Skill::DEFENCE -MAGIC, RANGED, PRAYER = Skill::MAGIC, Skill::RANGED, Skill::PRAYER - -all_skills = (Skill::ATTACK..Skill::RUNECRAFT).to_a -combat_skills = [ATTACK, STRENGTH, DEFENCE, MAGIC, RANGED] - -# Boosting potions: -# Note that the order of the elements must be: :name, :doses, :skills, :boost. -potion name: :attack, doses: [2428, 121, 123, 125], skills: ATTACK, boost: basic_combat_boost -potion name: :strength, doses: [113, 115, 117, 119], skills: STRENGTH, boost: basic_combat_boost -potion name: :defence, doses: [2432, 133, 135, 137], skills: DEFENCE, boost: basic_combat_boost - -potion name: :agility, doses: [3032, 3034, 3036, 3038], skills: Skill::AGILITY, - boost: non_combat_boost -potion name: :fishing, doses: [2438, 151, 153, 155], skills: Skill::FISHING, - boost: non_combat_boost -potion name: :prayer, doses: [2434, 139, 141, 143], skills: Skill::PRAYER, - boost: ->(_, level) { level / 4 + 7 } - -potion name: :restore, doses: [2430, 127, 129, 131], skills: combat_skills, - boost: ->(_, level) { [level * 1.3 + 10, max].min } -potion name: :super_restore, doses: [3024, 3026, 3028, 3030], skills: all_skills, - boost: ->(_, level) { [level * 1.25 + 8, max].min } - -potion name: :super_attack, doses: [2436, 145, 147, 149], skills: ATTACK, boost: super_combat_boost -potion name: :super_strength, doses: [2440, 157, 159, 161], skills: STRENGTH, - boost: super_combat_boost -potion name: :super_defence, doses: [2442, 163, 165, 167], skills: DEFENCE, - boost: super_combat_boost - -potion name: :ranging, doses: [2444, 169, 171, 173], skills: RANGED, - boost: ->(_, level) { level * 1.10 + 4 } - -potion name: :magic, doses: [3040, 3042, 3044, 3046], skills: MAGIC, - boost: ->(_, level) { level + 4 } diff --git a/game/data/plugins/dialogue/dialogue.rb b/game/data/plugins/dialogue/dialogue.rb deleted file mode 100644 index 7a026dc51..000000000 --- a/game/data/plugins/dialogue/dialogue.rb +++ /dev/null @@ -1,567 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.inter.dialogue.DialogueAdapter' -java_import 'org.apollo.game.message.impl.CloseInterfaceMessage' -java_import 'org.apollo.game.message.impl.SetWidgetItemModelMessage' -java_import 'org.apollo.game.message.impl.SetWidgetNpcModelMessage' -java_import 'org.apollo.game.message.impl.SetWidgetPlayerModelMessage' -java_import 'org.apollo.game.message.impl.SetWidgetModelAnimationMessage' -java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' -java_import 'org.apollo.game.action.DistancedAction' - -# The map of conversation names to Conversations. -CONVERSATIONS = {} - -# Declares a conversation. -def conversation(name, &block) - conversation = Conversation.new(name) - conversation.instance_eval(&block) - - raise "Conversation named #{name} already exists." if CONVERSATIONS.has_key?(name) - CONVERSATIONS[name] = conversation -end - -# A distanced action which opens the dialogue when getting into interaction distance of the given npc -class OpenDialogueAction < DistancedAction - attr_reader :player, :npc, :dialogue - - def initialize(player, npc, dialogue) - super(0, true, player, npc.position, 1) - - @player = player - @npc = npc - @dialogue = dialogue - end - - def executeAction - @player.set_interacting_mob(@npc) - send_dialogue(@player, @dialogue) - stop - end - - def equals(other) - return (@npc == other.npc && @dialogue == other.dialogue) - end - -end - -# A conversation held between two entities. -class Conversation - - # Creates the Conversation. - def initialize(name) - @dialogues = {} - @starters = [] - @name = name - end - - # Defines a dialogue, with the specified name and block. - def dialogue(name, &block) - raise 'Dialogues must have a name and block.' if (name.nil? || block.nil?) - - dialogue = Dialogue.new(name, self) - dialogue.instance_eval(&block) - dialogue.wrap - - raise "Conversations #{@name} already has a dialogue named #{name}." if @dialogues.has_key?(name) - @dialogues[name] = dialogue - - if ((@dialogues.empty? || dialogue.has_precondition?) && dialogue.type == :npc_speech) - npc_index = dialogue.npc - raise 'Npc cannot be null when opening a dialogue.' if npc_index.nil? - @starters << dialogue - - on :message, :first_npc_action do |player, message| - npc = $world.npc_repository.get(message.index) - if npc_index == npc.id - @starters.each do |start| - if dialogue.precondition(player) - player.start_action(OpenDialogueAction.new(player, npc, dialogue)) - message.terminate - break - end - end - end - end - end - end - - # Gets part of a conversation (i.e. a dialogue). - def part(name) - raise "Conversation #{@name} does not contain a dialogue called #{name}." unless @dialogues.has_key?(name) - @dialogues[name] - end - -end - -# Declares an emote, with the specified name and id. -def declare_emote(name, id) - EMOTES[name] = id -end - - -# Sends the dialogue from the specified Conversation with the specified name. -def get_dialogue(conversation, name) - CONVERSATIONS[conversation].part(name) -end - - -# Sends the specified dialogue. -def send_dialogue(player, dialogue) - type = dialogue.type - action = dialogue.action - action.call(player) unless action.nil? - - case type - when :message_with_item then send_item_dialogue(player, dialogue) - when :message_with_model then send_model_dialogue(player, dialogue) - when :npc_speech then send_npc_dialogue(player, dialogue) - when :options then send_options_dialogue(player, dialogue) - when :player_speech then send_player_dialogue(player, dialogue) - when :text - if dialogue.has_continue? then send_text_dialogue(player, dialogue) else send_statement_dialogue(player, dialogue) end - else raise "Unrecognised dialogue type #{type}." - end -end - -private - -# The hash of emote names to ids. -EMOTES = {} - -# The maximum amount of lines of text that can be displayed on a dialogue. -MAXIMUM_LINE_COUNT = 4 - -# The maximum amount of options that can be displayed on a dialogue. -MAXIMUM_OPTION_COUNT = 5 - -# The maximum width of a line, in pixels, for a dialogue with media. -MAXIMUM_MEDIA_LINE_WIDTH = 350 - -# The maximum width of a line, in pixels, for a dialogue with no media. -MAXIMUM_LINE_WIDTH = 430 - -# The possible types of a dialogue. -DIALOGUE_TYPES = [ :message_with_item, :message_with_model, :npc_speech, :options, :player_speech, :text ] - -# A type of dialogue. -class Dialogue - attr_reader :emote, :name, :media, :options, :text, :title, :type - - # Initializes the Dialogue. - def initialize(name, conversation) - @name = name.to_s - @conversation = conversation - @text = [] - @options = [] - end - - # An action that is executed when the dialogue is displayed. - def action(&block) - @action = block unless block.nil? - @action - end - - # Closes the dialogue interface when the player clicks the 'Click here to continue...' text. - def close(&block) - continue(:close => true, &block) - end - - # Defines the event that occurs when a player clicks the 'Click here to continue...' text. - def continue(type=nil, &block) - raise 'Cannot add a continue event on a dialogue with options.' if (@type == :options) - raise 'Must declare either a type or a block for a continue event.' if (type.nil? && block.nil?) - - action = decode_next_dialogue(type) unless type.nil? - @options[0] = ->(player) { action.call(player) unless type.nil?; block.call(player) unless block.nil? } - end - - # Sets the emote performed by the dialogue head. - def emote(emote=nil) - unless emote.nil? - raise 'Can only perform an emote on :player_speech or :npc_speech dialogues.' unless [ :npc_speech, :player_speech ].include?(@type) - @emote = emote.kind_of?(Symbol) ? EMOTES[emote] : emote - end - - @emote - end - - # Returns whether or not this Dialogue has a continue option. - def has_continue? - !@options.empty? - end - - # Returns whether or not this dialogue has a precondition. - def has_precondition? - !@precondition.nil? - end - - # Gets the media of this dialogue. - def media() - case @type - when :message_with_item then @item - when :npc_speech then @npc - when :message_with_model then @model - else raise "Cannot get media for #{@type}." - end - end - - # Sets the id of the item displayed. - def item(item=nil, scale=100) - unless item.nil? - raise 'Can only display an item on :message_with_item dialogues.' unless @type == :message_with_item - @item = lookup_item(item) - @item_scale = scale - end - - @item - end - - # Gets the scale of the item. - def item_scale - @item_scale - end - - # Sets the id of the model displayed. - def model(model=nil) - unless model.nil? - raise 'Can only display a model on :message_with_model dialogues.' unless @type == :message_with_model - @model = model - end - - @model - end - - # Sets the id of the npc displayed. - def npc(npc=nil) - unless npc.nil? - raise 'Can only display an npc on :npc_speech dialogues.' unless @type == :npc_speech - @npc = lookup_npc(npc) - end - @npc - end - - # Defines an option, displaying the specified message. - def option(message, type) - raise 'Can only display options on an :options dialogue.' unless @type == :options - raise "Cannot display more than #{MAXIMUM_OPTION_COUNT} options on a dialogue." unless @options.size < MAXIMUM_OPTION_COUNT - - @options[text.size] = decode_next_dialogue(type) - @text << message - end - - # Gets the array of options. - def options - @options.dup - end - - # Sets the precondition of this dialogue. - def precondition(player=nil, &block) - @precondition = block unless block.nil? - @precondition.call(player) unless player.nil? - end - - # Appends a message to the text list. - def text(*message) - @text.concat(message) unless message.nil? - @text - end - - # Sets the title of the dialogue. - def title(title=nil) - @title = title unless title.nil? - @title - end - - # Sets the type of dialogue. - def type(type=nil) - unless type.nil? - verify_dialogue_type(type) - @type = type - end - - @type - end - - # Wraps text in this Dialogue, inserting extra Dialogues in the chain if necessary. - def wrap # TODO redo this - next if @type == :options - lines = [] - maximum_lines = MAXIMUM_LINE_COUNT - - text = @text.first - segments = segment_text(text) - - if (segments.size <= maximum_lines) - lines = segments.clone - @text = @text[1..-1] - insert_copy(@text) if @text.size > 0 - else - lines = segments.first(maximum_lines).clone - segments = [ segments.drop(maximum_lines).join() ] - insert_copy(segments << @text[1..-1].join()) - end - - @text = lines - end - - protected - - # Copies the value of every variable from the specified Dialogue, optionally updating the text array. - def copy_from(dialogue, text=nil) - @emote = dialogue.emote - @item = dialogue.item - @model = dialogue.model - @npc = dialogue.npc - @options = dialogue.options - @text = if text.nil? then dialogue.text.dup else text.dup end - @type = dialogue.type - end - - private - - def segment_text(text) - maximum_width = (@type == :text) ? MAXIMUM_LINE_WIDTH : MAXIMUM_MEDIA_LINE_WIDTH - - segments = [] - index = 0; width = 0; space = 0 - - while index < text.length - char = text[index] - space = index if char == ' ' - width += get_width(char) - index += 1 - - if (width >= maximum_width) - segments << text[0..space] - text = text[(space + 1)..-1] - width = index = space = 0 - end - end - segments << text if ! text.empty? - - segments - end - - # Inserts a copy of this Dialogue into the chain, but with different text. - def insert_copy(text) - name = @name - index = name.index('-auto-inserted-') - - id = if index.nil? then 0 else name[name.rindex('-')..-1].to_i + 1 end - index ||= -1 - name = "#{name[0..index]}-auto-inserted-#{id}" - - dialogue = Dialogue.new(name, @conversation) - dialogue.copy_from(self, text.dup) - dialogue.wrap() - - @options[0] = ->(player) { send_dialogue(player, dialogue) } - end - - # Decodes the next dialogue interface from the hash, returning a proc. - def decode_next_dialogue(hash) - hash.each_pair do |key, value| - case key - when :disabled then return ->(player) { } - when :close then return ->(player) { player.send(CloseInterfaceMessage.new) } - when :dialogue then return ->(player) { send_dialogue(player, @conversation.part(value)) } - else raise "Unrecognised dialogue continue type #{key}." - end - end - end - -end - -# The dialogue interface ids for dialogues that only display text, but with no 'Click here to continue...' message. -STATEMENT_DIALOGUE_IDS = [ 12788, 12790, 12793, 12797, 6179 ] # TODO - -# The dialogue interface ids for dialogues that display an item and text, ordered by line count. -ITEM_DIALOGUE_IDS = [ 306, 310, 315, 321 ] - -# The dialogue interface ids for dialogues that only display text, ordered by line count. -TEXT_DIALOGUE_IDS = [ 356, 359, 363, 368, 374 ] - -# The dialogue interface ids for dialogues that display the head of the player, ordered by line count. -PLAYER_DIALOGUE_IDS = [ 968, 973, 979, 986 ] - -# The dialogue interface ids for dialogues that display the head of an npc, ordered by line count. -NPC_DIALOGUE_IDS = [ 4882, 4887, 4893, 4900 ] - -# The dialogue interface ids for option dialogues, ordered by (option_count - 1) -OPTIONS_DIALOGUE_IDS = [ 2459, 2469, 2480, 2492 ] - - - -## TODO separate this into different Dialogue types ## - -# Sends a dialogue displaying an item model and text. -def send_item_dialogue(player, dialogue) - text = dialogue.text - dialogue_id = ITEM_DIALOGUE_IDS[text.size - 1] - player.send(SetWidgetItemModelMessage.new(dialogue_id + 1, dialogue.item, dialogue.item_scale)) - - indices = [ dialogue_id + 1 + 2, dialogue_id + 1 + 1, dialogue_id + 1 + 4, dialogue_id + 1 + 5 ] - - text.each_with_index { |line, index| set_text(player, indices[index], line) } - player.interface_set.open_dialogue(ContinueDialogueAdapter.new(player, dialogue.options[0]), dialogue_id) -end - -# Sends a dialogue displaying only text, with no 'Click here to continue...' button. -def send_statement_dialogue(player, dialogue) - text = dialogue.text - dialogue_id = STATEMENT_DIALOGUE_IDS[text.size] - - set_text(player, dialogue_id + 1, dialogue.title) - text.each_with_index { |line, index| set_text(player, dialogue_id + 2 + index, line) } - player.interface_set.open_dialogue_overlay(dialogue_id) -end - -# Sends a dialogue displaying only text. -def send_text_dialogue(player, dialogue) - text = dialogue.text - dialogue_id = TEXT_DIALOGUE_IDS[text.size - 1] - - text.each_with_index { |line, index| set_text(player, dialogue_id + 1 + index, line) } - player.interface_set.open_dialogue(ContinueDialogueAdapter.new(player, dialogue.options[0]), dialogue_id) -end - -# Sends a dialogue displaying the player's head. -def send_player_dialogue(player, dialogue) - emote = dialogue.emote - - send_generic_dialogue player, dialogue, player.username, PLAYER_DIALOGUE_IDS do |id| - player.send(SetWidgetPlayerModelMessage.new(id + 1)) - player.send(SetWidgetModelAnimationMessage.new(id + 1, emote)) unless emote.nil? - end -end - -# Sends a dialogue displaying the head of an npc. -def send_npc_dialogue(player, dialogue) - npc = dialogue.npc - emote = dialogue.emote - name = NpcDefinition.lookup(npc).name.to_s - name = "" if (name.nil? || name == "null") - - send_generic_dialogue player, dialogue, name, NPC_DIALOGUE_IDS do |id| - player.send(SetWidgetNpcModelMessage.new(id + 1, npc)) - player.send(SetWidgetModelAnimationMessage.new(id + 1, emote)) unless emote.nil? - end -end - -# Sends a dialogue displaying an event. -def send_generic_dialogue(player, dialogue, title, ids, &event) - text = dialogue.text - dialogue_id = ids[text.size - 1] - event.call(dialogue_id) if block_given? - - set_text(player, dialogue_title_id(dialogue_id), title) - - text.each_with_index { |line, index| set_text(player, dialogue_text_id(dialogue_id, index), line) } - player.interface_set.open_dialogue(ContinueDialogueAdapter.new(player, dialogue.options[0]), dialogue_id) -end - - -# Sends an options dialogue interface. -def send_options_dialogue(player, dialogue) - options = dialogue.options - size = options.size - raise 'Illegal options count: must be between 2 and 5, inclusive.' unless (2..5).include?(size) - - text = dialogue.text - dialogue_id = OPTIONS_DIALOGUE_IDS[size - 1] - - question = dialogue.title - set_text(player, dialogue_question_id(dialogue_id), question) - - text.each_with_index { |line, index| set_text(player, dialogue_option_id(dialogue_id, index), line) } - player.interface_set.open_dialogue(OptionDialogueAdapter.new(player, options), dialogue_id) -end - - -# A DialogueAdapter for dialogues with a 'Click here to continue...' message. -class ContinueDialogueAdapter < DialogueAdapter - - # Creates the ContinueDialogueAdadpter. - def initialize(player, continue) - super() - @player = player - @continue = continue - end - - # Executes the 'continue' lambda when the player clicks the 'Click here to continue...' message. - def continued() - @continue.call(@player) - end - -end - - -# A DialogueAdapter for dialogues with a set of options that can be selected. -class OptionDialogueAdapter < DialogueAdapter - - # Creates the OptionDialogueAdadpter. - def initialize(player, options) - super() - @player = player - @options = options.dup - end - - # Executes an option. - def button_clicked(button) - option = OPTIONS_DIALOGUE_IDS.find_index(button) - options[option].call(@player) - end - -end - - -# Gets the widget id of the question, for an options dialogue interface. -def dialogue_question_id(id) - id + 1 -end - -# Gets the widget id of a dialogue option. -def dialogue_option_id(id, option) - id + 1 + option -end - -# Gets the widget id of a dialogue text line. -def dialogue_text_id(id, line) - id + 3 + line -end - -# Gets the widget id of a dialogue title. -def dialogue_title_id(id) - id + 2 -end - -# Sets the text of a widget. -def set_text(player, id, message) - player.send(SetWidgetTextMessage.new(id, message)) -end - -# Verifies that the dialogue type exists. -def verify_dialogue_type(type) - raise "Unrecognised dialogue type #{type}, expected one of #{DIALOGUE_TYPES}." unless DIALOGUE_TYPES.include?(type) -end - -# The spacing of each character glyph, for the font used for dialogue. TODO decode the font from the cache. -GLYPH_SPACING = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 7, 14, 9, 12, 12, 4, 5, - 5, 10, 8, 4, 8, 4, 7, 9, 7, 9, 8, 8, 8, 9, 7, 9, 9, 4, 5, 7, - 9, 7, 9, 14, 9, 8, 8, 8, 7, 7, 9, 8, 6, 8, 8, 7, 10, 9, 9, 8, - 9, 8, 8, 6, 9, 8, 10, 8, 8, 8, 6, 7, 6, 9, 10, 5, 8, 8, 7, 8, - 8, 7, 8, 8, 4, 7, 7, 4, 10, 8, 8, 8, 8, 6, 8, 6, 8, 8, 9, 8, - 8, 8, 6, 4, 6, 12, 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 8, 11, 8, 8, 4, 8, 7, 12, 6, 7, 9, 5, 12, 5, 6, 10, 6, 6, 6, - 8, 8, 4, 5, 5, 6, 7, 11, 11, 11, 9, 9, 9, 9, 9, 9, 9, 13, 8, 8, - 8, 8, 8, 4, 4, 5, 4, 8, 9, 9, 9, 9, 9, 9, 8, 10, 9, 9, 9, 9, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 13, 6, 8, 8, 8, 8, 4, 4, 5, 4, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 ] - -# Gets the width of a single character. -def get_width(char) - return GLYPH_SPACING[char.ord] -end diff --git a/game/data/plugins/dialogue/emotes.rb b/game/data/plugins/dialogue/emotes.rb deleted file mode 100644 index 77eea3e4b..000000000 --- a/game/data/plugins/dialogue/emotes.rb +++ /dev/null @@ -1,31 +0,0 @@ -# Declares all of the possible emotes -declare_emote(:calm, 588) -declare_emote(:anxious, 589) -declare_emote(:calm_talk, 590) -declare_emote(:default, 591) -declare_emote(:evil, 592) -declare_emote(:bad, 593) -declare_emote(:wicked, 594) -declare_emote(:annoyed, 595) -declare_emote(:distressed, 596) -declare_emote(:afflicted, 597) -declare_emote(:almost_crying, 598) -declare_emote(:drunk_left, 600) -declare_emote(:drunk_right, 601) -declare_emote(:not_interested, 602) -declare_emote(:sleepy, 603) -declare_emote(:plain_evil, 604) -declare_emote(:laugh, 605) -declare_emote(:snigger, 606) -declare_emote(:have_fun, 607) -declare_emote(:guffaw, 608) -declare_emote(:evil_laugh, 609) -declare_emote(:sad, 610) -declare_emote(:more_sad, 611) -declare_emote(:on_one_hand, 612) -declare_emote(:nearly_crying, 613) -declare_emote(:angry, 614) -declare_emote(:furious, 615) -declare_emote(:enraged, 616) -declare_emote(:mad, 617) - diff --git a/game/data/plugins/dialogue/plugin.xml b/game/data/plugins/dialogue/plugin.xml deleted file mode 100644 index 95a7402f5..000000000 --- a/game/data/plugins/dialogue/plugin.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - dialogue - 0.1 - Dialogue - Adds dialogue support. - - Major - - - - - - - util - - \ No newline at end of file diff --git a/game/data/plugins/dummy/dummy.rb b/game/data/plugins/dummy/dummy.rb deleted file mode 100644 index f602f32ae..000000000 --- a/game/data/plugins/dummy/dummy.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.model.Animation' - -DUMMY_ID = 823 -DUMMY_SIZE = 1 -PUNCH_ANIMATION = Animation.new(422) -ANIMATION_PULSES = 0 -LEVEL_THRESHOLD = 8 -EXP_PER_HIT = 5 - -# A DistancedAction for attacking a training dummy. -class DummyAction < DistancedAction - attr_reader :position - - def initialize(mob, position) - super(ANIMATION_PULSES, true, mob, position, DUMMY_SIZE) - - @position = position - @started = false - end - - def executeAction - if @started - skills = mob.skill_set - - if (skills.skill(Skill::ATTACK).maximum_level >= LEVEL_THRESHOLD) - mob.send_message('There is nothing more you can learn from hitting a dummy.') - else - skills.add_experience(Skill::ATTACK, EXP_PER_HIT) - end - - stop - else - @started = true - - mob.send_message('You hit the dummy.') - mob.turn_to(position) - mob.play_animation(PUNCH_ANIMATION) - end - end - - def equals(other) - get_class == other.get_class && @position == other.position - end -end - -on :message, :second_object_action do |player, message| - player.start_action(DummyAction.new(player, message.position)) if message.id == DUMMY_ID -end diff --git a/game/data/plugins/dummy/plugin.xml b/game/data/plugins/dummy/plugin.xml deleted file mode 100644 index 2bf4f8d31..000000000 --- a/game/data/plugins/dummy/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - dummy - 1 - Dummies - Allows low-level players to train on dummies. - - Graham - - - - - - diff --git a/game/data/plugins/emote-tab/emote_tab.rb b/game/data/plugins/emote-tab/emote_tab.rb deleted file mode 100644 index 6bf3bbdc1..000000000 --- a/game/data/plugins/emote-tab/emote_tab.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' - -# Animation constants. -ANGRY = Animation.new(859) -BECKON = Animation.new(864) -BLOW_KISS = Animation.new(1368) -BOW = Animation.new(858) -CHEER = Animation.new(862) -CLAP = Animation.new(865) -CLIMB_ROPE = Animation.new(1130) -CRY = Animation.new(860) -DANCE = Animation.new(866) -GLASS_BOX = Animation.new(1131) -GLASS_WALL = Animation.new(1128) -GOBLIN_BOW = Animation.new(2127) -GOBLIN_DANCE = Animation.new(2128) -HEAD_BANG = Animation.new(2108) -JIG = Animation.new(2106) -JOY_JUMP = Animation.new(2109) -LAUGH = Animation.new(861) -LEAN = Animation.new(1129) -NO = Animation.new(856) -PANIC = Animation.new(2105) -RASPBERRY = Animation.new(2110) -SALUTE = Animation.new(2112) -SHRUG = Animation.new(2113) -SPIN = Animation.new(2107) -THINKING = Animation.new(857) -WAVE = Animation.new(863) -YAWN = Animation.new(2111) -YES = Animation.new(855) - -# A map of buttons to animations. -ANIMATIONS = { - 162 => THINKING, 6_503 => CLIMB_ROPE, 169 => NO, - 164 => BOW, 13_384 => GOBLIN_DANCE, 161 => CRY, - 170 => LAUGH, 171 => CHEER, 163 => WAVE, - 167 => BECKON, 3_362 => PANIC, 172 => CLAP, - 166 => DANCE, 13_363 => JIG, 13_364 => SPIN, - 13_365 => HEAD_BANG, 6_506 => LEAN, 165 => ANGRY, - 13_368 => YAWN, 13_366 => JOY_JUMP, 667 => GLASS_BOX, - 13_367 => RASPBERRY, 13_369 => SALUTE, 13_370 => SHRUG, - 11_100 => BLOW_KISS, 666 => GLASS_WALL, 168 => YES, - 13_383 => GOBLIN_BOW -} - -# Intercept the button message. -on :message, :button do |player, message| - anim = ANIMATIONS[message.widget_id] - - unless anim.nil? - player.play_animation(anim) - message.terminate - end -end diff --git a/game/data/plugins/emote-tab/plugin.xml b/game/data/plugins/emote-tab/plugin.xml deleted file mode 100644 index 6485d83c1..000000000 --- a/game/data/plugins/emote-tab/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - emote-tab - 1 - Emote Tab - Adds emote tab functionality. - - Major - - - - - - diff --git a/game/data/plugins/entity/attributes/attributes.rb b/game/data/plugins/entity/attributes/attributes.rb deleted file mode 100644 index d16a00aac..000000000 --- a/game/data/plugins/entity/attributes/attributes.rb +++ /dev/null @@ -1,79 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.entity.Mob' -java_import 'org.apollo.game.model.entity.Npc' -java_import 'org.apollo.game.model.entity.Player' -java_import 'org.apollo.game.model.entity.attr.Attribute' -java_import 'org.apollo.game.model.entity.attr.AttributeDefinition' -java_import 'org.apollo.game.model.entity.attr.AttributeMap' -java_import 'org.apollo.game.model.entity.attr.AttributePersistence' -java_import 'org.apollo.game.model.entity.attr.AttributeType' -java_import 'org.apollo.game.model.entity.attr.BooleanAttribute' -java_import 'org.apollo.game.model.entity.attr.NumericalAttribute' -java_import 'org.apollo.game.model.entity.attr.StringAttribute' - -# Declares an attribute and adds its definition. -def declare_attribute(name, default, persistence = :transient) - if Player.method_defined?(name) || Mob.method_defined?(name) || Npc.method_defined?(name) - fail "Attribute #{name} clashes with an existing variable." - end - - definition = AttributeDefinition.new(default, get_persistence(persistence), get_type(default)) - AttributeMap::define(name.to_s, definition) -end - -private - -# The existing Mob class. -class Mob - - # Overrides method_missing to implement the functionality. - def method_missing(symbol, *args) - name = symbol.to_s.strip - - if name[-1] == '=' - fail "Expected argument count of 1, received #{args.length}" unless args.length == 1 - - name = name[0...-1].strip # Drop the equals and trim whitespace. - set_attribute(name, to_attribute(args[0])) - elsif AttributeMap::get_definition(name).nil? - super(symbol, *args) - else - attribute = get_attribute(name) - value = attribute.value - (attribute.type == AttributeType::SYMBOL) ? value.to_sym : value - end - end - -end - -# Gets the appropriate attribute for the specified value. -def to_attribute(value) - case value - when String, Symbol then return StringAttribute.new(value.to_s, value.is_a?(Symbol)) - when Integer, Float then return NumericalAttribute.new(value) - when TrueClass, FalseClass then return BooleanAttribute.new(value) - else fail "Undefined attribute type #{value.class}." - end -end - -# Gets the attribute type of the specified value. -def get_type(value) - case value - when String then return AttributeType::STRING - when Symbol then return AttributeType::SYMBOL - when Integer then return AttributeType::LONG - when Float then return AttributeType::DOUBLE - when TrueClass, FalseClass then return AttributeType::BOOLEAN - else fail "Undefined attribute type #{value.class}." - end -end - -# Gets the Persistence type of the specified value. -def get_persistence(persistence) - unless [:persistent, :transient].include?(persistence) - fail "Undefined persistence type #{persistence}." - end - - (persistence == :persistent) ? AttributePersistence::PERSISTENT : AttributePersistence::TRANSIENT -end diff --git a/game/data/plugins/entity/attributes/plugin.xml b/game/data/plugins/entity/attributes/plugin.xml deleted file mode 100644 index ea11bba46..000000000 --- a/game/data/plugins/entity/attributes/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - attributes - 0.9 - Attributes - Adds an attribute system for entites. - - Major - - - - - - \ No newline at end of file diff --git a/game/data/plugins/entity/mob/extension/extension.rb b/game/data/plugins/entity/mob/extension/extension.rb deleted file mode 100644 index 11e20c0d7..000000000 --- a/game/data/plugins/entity/mob/extension/extension.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.entity.Mob' - -module MobExtension - MOB_EXTENSIONS = [] - - def self.register(extension) - fail 'Provided extension object is not a module' unless extension.is_a?(Module) - - new_mixins = extension.public_instance_methods - current_mixins = MOB_EXTENSIONS.map { |e| {e.to_s => e.public_instance_methods} } - - current_mixins.each do |ext, methods| - methods.each {|m| fail "Extension #{ext} already provides method #{m}" if new_mixins.include?(m) } - end - - Mob.include(extension) - end -end \ No newline at end of file diff --git a/game/data/plugins/entity/mob/extension/plugin.xml b/game/data/plugins/entity/mob/extension/plugin.xml deleted file mode 100644 index e2c7d250e..000000000 --- a/game/data/plugins/entity/mob/extension/plugin.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - mob-extension - 0.1 - Mob Extensions - Adds support for extending Mobs with new functionality - - Gary Tierney - - - - - - - \ No newline at end of file diff --git a/game/data/plugins/entity/mob/following/following.rb b/game/data/plugins/entity/mob/following/following.rb deleted file mode 100755 index 0ca139c40..000000000 --- a/game/data/plugins/entity/mob/following/following.rb +++ /dev/null @@ -1,58 +0,0 @@ -on :message, :walk do |player, msg| - player.reset_interacting_mob -end - -on :message, :player_action do |player, msg| - ## todo: need a better way of mapping option numbers to their purpose - player.follow($world.player_repository.get(msg.index)) if msg.option == 3 -end - -## -# A MobExtension for making a Mob trail behind, or chase a given mob. -module FollowingMobExtension - ## - # Follow a mob and trail behind them. - def follow(mob) - do_follow(self, mob, behind: true) - end - - ## - # Chase a mob (with the intention of getting in front of them), also optionally - # stopping within a projectile distance when at a position where a projectile can - # reach the target. - def chase(mob, projectile_distance: nil) - do_follow(self, mob, front: true, projectile_distance: projectile_distance) - end -end - -MobExtension::register(FollowingMobExtension) - -private - -def do_follow(source, mob, behind: false, front: false, projectile_distance: nil) - source.interacting_mob = mob - - schedule 0, true do |task| - # stop the task unless we're still interacting with the other mob. - unless self.interacting_mob.eql? mob - task.stop - next - end - - next unless source.walking_queue.size <= 1 - - distance = mob.position.get_distance(source.position) - - unless projectile_distance.nil? - next if distance <= projectile_distance && - $world.collision_manager.raycast(source.position, mob.position) - end - - if distance > 15 - reset_interacting_mob - end - - walk_to(mob, behind: behind, front: front) - end -end - diff --git a/game/data/plugins/entity/mob/following/plugin.xml b/game/data/plugins/entity/mob/following/plugin.xml deleted file mode 100755 index b4480d882..000000000 --- a/game/data/plugins/entity/mob/following/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - mob-following - 1 - Following - Adds following for mobs. - - Steve Soltys - - - - - - mob-walk-to - - diff --git a/game/data/plugins/entity/mob/walk-to/plugin.xml b/game/data/plugins/entity/mob/walk-to/plugin.xml deleted file mode 100644 index 676560e80..000000000 --- a/game/data/plugins/entity/mob/walk-to/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - mob-walk-to - 0.1 - Mob path generation - Adds a mixin for making mobs walk to another entity. - - Gary Tierney - - - - - - mob-extension - - \ No newline at end of file diff --git a/game/data/plugins/entity/mob/walk-to/walk_to.rb b/game/data/plugins/entity/mob/walk-to/walk_to.rb deleted file mode 100644 index 6381172f1..000000000 --- a/game/data/plugins/entity/mob/walk-to/walk_to.rb +++ /dev/null @@ -1,83 +0,0 @@ -java_import 'org.apollo.game.model.entity.path.AStarPathfindingAlgorithm' -java_import 'org.apollo.game.model.entity.path.EuclideanHeuristic' -java_import 'org.apollo.game.model.entity.path.SimplePathfindingAlgorithm' -java_import 'org.apollo.game.model.entity.obj.GameObject' -java_import 'org.apollo.game.model.entity.Mob' -java_import 'org.apollo.game.model.entity.Player' -java_import 'org.apollo.game.model.entity.EntityType' -java_import 'org.apollo.game.model.Direction' - -## -# A pathfinder used for simple following (i.e.: An NPC attacking a player). -SIMPLE_PATH_FINDER = SimplePathfindingAlgorithm.new($world.collision_manager) - -## -# A pathfinder used for precise following (i.e.: A player attacking another player). -FOLLOW_PATH_FINDER = AStarPathfindingAlgorithm.new($world.collision_manager, EuclideanHeuristic.new) - -## -# The directions that we use as a random offset when not walking to the facing direction. -OFFSET_DIRECTIONS = Direction::NESW.to_a - -module WalkToMobExtension - def walk_to(entity, front: false, behind: false) - if [front, behind].count { |option| option == true } > 1 - fail 'Can only specify one of "front" or "behind"' - end - - position = self.position - target_position = entity.position - target_distance = position.get_distance(target_position) - target_offset = walk_to_offset(entity) - target_offset_direction = OFFSET_DIRECTIONS.sample - target_facing_direction = walk_to_facing_direction(entity) - - unless target_facing_direction.nil? - if front - target_offset_direction = target_facing_direction - elsif behind - target_offset_direction = target_facing_direction.opposite - end - end - - target_offset_position = target_position.step(target_offset, target_offset_direction) - return if target_offset_position.eql?(position) - - pathfinder = FOLLOW_PATH_FINDER - path = pathfinder.find(position, target_offset_position) - path.each { |tile| self.walking_queue.add_step(tile) } - end -end - -MobExtension::register(WalkToMobExtension) - -private - -## -# Gets the number of tiles away from an entity's actual origin that we can -# walk to. -def walk_to_offset(entity) - case entity.entity_type - when EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT - return max(entity.definition.width, entity.definition.length) + 1 - when EntityType::NPC - return entity.definition.size + 1 - when EntityType::PLAYER - return 1 - else - fail "walk_to_offset called with invalid entity type: #{type.to_s}" - end -end - -## -# Gets the direction that an entity is facing, so a mob can walk up infront of them. -def walk_to_facing_direction(entity) - case entity.entity_type - when EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT - return Direction::WNES[entity.orientation] - when EntityType::NPC, EntityType::PLAYER - return entity.last_direction - else - fail "walk_to_offset called with invalid entity type: #{type.to_s}" - end -end \ No newline at end of file diff --git a/game/data/plugins/entity/spawning/npc-spawn.rb b/game/data/plugins/entity/spawning/npc-spawn.rb deleted file mode 100644 index e90fcb848..000000000 --- a/game/data/plugins/entity/spawning/npc-spawn.rb +++ /dev/null @@ -1,197 +0,0 @@ -require 'java' - -java_import 'org.apollo.cache.def.NpcDefinition' -java_import 'org.apollo.game.action.Action' -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Graphic' -java_import 'org.apollo.game.model.Position' -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.entity.Npc' - -# Information about npc spawning -# -# Npcs are passed to spawn npc as a hash. Every key and every non-integer value must be a Symbol. -# Every hash must implement the following: -# :name - the name of the npc. If this npc shares its name with another, append the specific id -# after the name (e.g. :woman_4) -# :x - the x coordinate where the npc will spawn. -# :y - the y coordinate where the npc will spawn. -# Optional arguments are as follows: -# :face - the direction the npc should face when it spawns. Supported options are :north, -# :north_east, :east, :south_east, :south, :south_west, :west, and :north_west -# :bounds - the rectangular bound that the npc can wander about in. Order is -# [bottom-left x-coordinate, bottom-left y-coordinate, top-right x-coordinate, -# top-right y-coordinate] -# :delta_bounds - the rectangular bound that the npc can wander about in, as a difference from -# the spawn point. Order is [x-delta, y-delta]. Should not be used with :bounds. -# :spawn_animation - the animation that will be played when the npc spawns. -# :spawn_graphic - the graphic that will be played when the npc spawns. - -# Spawns an npc with the properties specified in the hash. -def spawn_npc(hash) - unless (hash.key?(:name) || hash.key?(:id)) && hash.has_keys?(:x, :y) - fail 'A name (or id), x coordinate, and y coordinate must be specified to spawn an npc.' - end - - npc = get_npc(hash) - spawn(npc, hash) - npc -end - -# Spawns the specified npc and applies the properties in the hash. -def spawn(npc, hash) - unless hash.empty? - hash = decode_hash(npc.position, hash) - apply_decoded_hash(npc, hash) - end - - $world.register(npc) -end - -# Returns an npc with the id and position specified by the hash. -def get_npc(hash) - id = lookup_npc(hash.delete(:name)) - - z = hash.delete(:z) - position = Position.new(hash.delete(:x), hash.delete(:y), z.nil? ? 0 : z) - Npc.new($world, id, position) -end - -# Applies a decoded hash (one aquired using parse_hash) to the specified npc. -def apply_decoded_hash(npc, hash) - hash.each do |key, value| - case key - when :face then npc.turn_to(value) - when :boundary then npc.boundaries = value - when :spawn_animation then npc.play_animation(Animation.new(value)) - when :spawn_graphic then npc.play_graphic(Graphic.new(value)) - else fail "Unrecognised key #{key} - value #{value}." - end - end -end - -# Parses the remaining key-value pairs in the hash. -def decode_hash(position, hash) - decoded = {} - - hash.each do |key, value| - case key - when :face - decoded[:face] = direction_to_position(value, position) - when :delta_bounds - fail ':delta_bounds must have two values.' unless value.length == 2 - dx, dy, x, y, z = value[0], value[1], position.x, position.y, position.height - fail 'Delta values cannot be less than 0.' if dx < 0 || dy < 0 - - decoded[:boundary] = [Position.new(x - dx, y - dy, z), Position.new(x + dx, y + dy, z)] - when :bounds - fail ':bounds must have four values.' unless value.length == 4 - min_x, min_y, max_x, max_y = value[0], value[1], value[2], value[3] - - decoded[:boundary] = [Position.new(min_x, min_y), Position.new(max_x, max_y)] - when :spawn_animation then decoded[:spawn_animation] = Animation.new(value) - when :spawn_graphic then decoded[:spawn_graphic] = Graphic.new(value) - else fail "Unrecognised key #{key} - value #{value}." - end - end - - decoded -end - -# Returns a position that an entity at the specified position should be facing towards if they are -# looking in the specified direction. -def direction_to_position(direction, position) - x, y, z = position.x, position.y, position.height - - case direction - when :north then return Position.new(x, y + 1, z) - when :north_east then return Position.new(x + 1, y + 1, z) - when :east then return Position.new(x + 1, y, z) - when :south_east then return Position.new(x + 1, y - 1, z) - when :south then return Position.new(x, y - 1, z) - when :south_west then return Position.new(x - 1, y - 1, z) - when :west then return Position.new(x - 1, y, z) - when :north_west then return Position.new(x - 1, y + 1, z) - else return position - end -end - -# An action that spawns an npc temporarily, before executing an action. -class TemporaryNpcAction < Action - attr_reader :executions, :combative - - def initialize(delay, immediate, hash) - super(delay, immediate, get_npc(hash)) - - @executions = 0 - @hash = hash - end - - def execute - if @executions == 0 - spawn(mob, @hash) - execute_spawn_action - else - execute_action - end - - @executions += 1 - end - - def execute_action - # Override to provide functionality. - end - - def execute_spawn_action - # Overridden to provide functionality for when the npc spawns. - end - -end - -# A random event that spawns and executes some sort of action. -class RandomEvent < TemporaryNpcAction - - def initialize(delay, immediate, hash, combative, target) - super(delay, immediate, hash) - - @combative = combative - @target = target - end - - def execute_spawn_action - mob.turn_to(target.position) - mob.update_interacting_mob(target.index) - end - -end - -# Adds a random event to the array. -def register_random_event(event) - RANDOM_EVENTS << event -end - -# Contains random event npcs -RANDOM_EVENTS = [] - -# Spawns a random event for the specified player. -def send_random_event(player) - position = player.position - npc_position = Position.new(position.x + 1, position.y, position.height) - # TODO: Find an unoccupied tile instead of the assumption that (x + 1) is traversable!! - - spawn_random_event(npc_position, false) -end - -# Spawns a random event in the specified position. -# If 'combat' is false, only non-combat events will be spawned. -def spawn_random_event(_position, _combat) - event = RANDOM_EVENTS[rand(RANDOM_EVENTS.size)] - attempts = 0 - - while event.combative && attempts < 5 - event = RANDOM_EVENTS[rand(RANDOM_EVENTS.size)] - attempts += 1 - end - - event.execute unless attempts == 5 # 5 iterations is plenty, just give up at this point -end diff --git a/game/data/plugins/entity/spawning/plugin.xml b/game/data/plugins/entity/spawning/plugin.xml deleted file mode 100644 index ac3b0b799..000000000 --- a/game/data/plugins/entity/spawning/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - entity-spawning - 0.1 - Entity Spawning - Adds support for easy ruby entity spawning. - - Major - - - - - - util - - \ No newline at end of file diff --git a/game/data/plugins/location/al-kharid/npcs.rb b/game/data/plugins/location/al-kharid/npcs.rb deleted file mode 100644 index daa55d89f..000000000 --- a/game/data/plugins/location/al-kharid/npcs.rb +++ /dev/null @@ -1,89 +0,0 @@ -# Generic npcs - -spawn_npc name: :man, x: 3276, y: 3186 -spawn_npc name: :man, x: 3282, y: 3197 -spawn_npc name: :man_3, x: 3301, y: 3200 -spawn_npc name: :man_3, x: 3300, y: 3208 -spawn_npc name: :man_2, x: 3297, y: 3196 -spawn_npc name: :man_16, x: 3294, y: 3204 -spawn_npc name: :spider_61, x: 3319, y: 3145 -spawn_npc name: :spider_61, x: 3319, y: 3140 -spawn_npc name: :spider_61, x: 3323, y: 3138 -spawn_npc name: :scorpion, x: 3282, y: 3149 - -# Camels -spawn_npc name: :cam_the_camel, x: 3295, y: 3232 -spawn_npc name: :elly_the_camel, x: 3312, y: 3210 -spawn_npc name: :camel, x: 3285, y: 3198 -spawn_npc name: :ollie_the_camel, x: 3291, y: 3209 -spawn_npc name: :al_the_camel, x: 3275, y: 3162 - -# Quest npc -spawn_npc name: :osman, x: 3286, y: 3180, face: :east -spawn_npc name: :hassan, x: 3302, y: 3163 -spawn_npc name: :father_reen, x: 3272, y: 3158 -spawn_npc name: :man_663, x: 3297, y: 3287 - -# Boarder guards - -spawn_npc name: 'border_guard', x: 3268, y: 3226, face: :north -spawn_npc name: 'border_guard', x: 3267, y: 3226, face: :north -spawn_npc name: 'border_guard', x: 3268, y: 3229, face: :south -spawn_npc name: 'border_guard', x: 3267, y: 3229, face: :south - -# Palace guards - -spawn_npc name: 'Al-Kharid warrior', x: 3285, y: 3174 -spawn_npc name: 'Al-Kharid warrior', x: 3283, y: 3168 -spawn_npc name: 'Al-Kharid warrior', x: 3285, y: 3169 -spawn_npc name: 'Al-Kharid warrior', x: 3290, y: 3162 -spawn_npc name: 'Al-Kharid warrior', x: 3295, y: 3162 -spawn_npc name: 'Al-Kharid warrior', x: 3295, y: 3170 -spawn_npc name: 'Al-Kharid warrior', x: 3300, y: 3175 -spawn_npc name: 'Al-Kharid warrior', x: 3300, y: 3171 -spawn_npc name: 'Al-Kharid warrior', x: 3301, y: 3168 - -# Shanty pass -spawn_npc name: :shantay_guard, x: 3301, y: 3120 -spawn_npc name: :shantay_guard, x: 3302, y: 3126 -spawn_npc name: :shantay_guard, x: 3306, y: 3126 -spawn_npc name: :shantay_guard_838, x: 3303, y: 3118, face: :north - -# Mine - -spawn_npc name: :scorpion, x: 3296, y: 3294 -spawn_npc name: :scorpion, x: 3298, y: 3280 -spawn_npc name: :scorpion, x: 3299, y: 3299 -spawn_npc name: :scorpion, x: 3299, y: 3309 -spawn_npc name: :scorpion, x: 3300, y: 3287 -spawn_npc name: :scorpion, x: 3300, y: 3315 -spawn_npc name: :scorpion, x: 3301, y: 3305 -spawn_npc name: :scorpion, x: 3301, y: 3312 - -# Functional npcs - -spawn_npc name: :gnome_pilot, x: 3279, y: 3213 - -spawn_npc name: :banker_496, x: 3267, y: 3164, face: :east -spawn_npc name: :banker_497, x: 3267, y: 3166, face: :east -spawn_npc name: :banker_496, x: 3267, y: 3167, face: :east -spawn_npc name: :banker_497, x: 3267, y: 3168, face: :east -spawn_npc name: :banker_496, x: 3267, y: 3169, face: :east - -spawn_npc name: :gem_trader, x: 3287, y: 3210 -spawn_npc name: :zeke, x: 3289, y: 3189 -spawn_npc name: :shantay, x: 3304, y: 3124 - -spawn_npc name: :rug_merchant_2296, x: 3311, y: 3109, face: :west -spawn_npc name: :ranael, x: 3315, y: 3163, face: :north - -spawn_npc name: :shop_assistant_525, x: 3315, y: 3178, face: :north -spawn_npc name: :shop_keeper_524, x: 3315, y: 3180, face: :west -spawn_npc name: :louie_legs, x: 3316, y: 3175, face: :west -spawn_npc name: :ellis, x: 3274, y: 3192 -spawn_npc name: :dommik, x: 3321, y: 3193 - -spawn_npc name: :tool_leprechaun, x: 3319, y: 3204 -spawn_npc name: :ali_morrisane, x: 3304, y: 3211, face: :east -spawn_npc name: :silk_trader, x: 3300, y: 3203 -spawn_npc name: :karim, x: 3273, y: 3180 diff --git a/game/data/plugins/location/al-kharid/plugin.xml b/game/data/plugins/location/al-kharid/plugin.xml deleted file mode 100644 index 64a10ed92..000000000 --- a/game/data/plugins/location/al-kharid/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - location-al-kharid - 0.1 - Al-Kharid - Adds functionality to Al-Kharid. - - Major - - - - - - entity-spawning - - \ No newline at end of file diff --git a/game/data/plugins/location/edgeville/npcs.rb b/game/data/plugins/location/edgeville/npcs.rb deleted file mode 100644 index d73ad2b6e..000000000 --- a/game/data/plugins/location/edgeville/npcs.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Generic npcs - -spawn_npc name: :man, x: 3095, y: 3508 -spawn_npc name: :man, x: 3095, y: 3511 -spawn_npc name: :man, x: 3098, y: 3509 -spawn_npc name: :man_2, x: 3093, y: 3511 -spawn_npc name: :man_3, x: 3097, y: 3508 -spawn_npc name: :man_3, x: 3092, y: 3508 -spawn_npc name: :man_3, x: 3097, y: 3512 - -spawn_npc name: :guard, x: 3086, y: 3516 -spawn_npc name: :guard, x: 3094, y: 3518 -spawn_npc name: :guard, x: 3108, y: 3514 -spawn_npc name: :guard, x: 3110, y: 3514 -spawn_npc name: :guard, x: 3113, y: 3514 -spawn_npc name: :guard, x: 3113, y: 3516 - -spawn_npc name: :sheep_43, x: 3050, y: 3516 -spawn_npc name: :sheep_43, x: 3051, y: 3514 -spawn_npc name: :sheep_43, x: 3056, y: 3517 -spawn_npc name: :ram_3673, x: 3048, y: 3515 - -spawn_npc name: :monk, x: 3044, y: 3491 -spawn_npc name: :monk, x: 3045, y: 3483 -spawn_npc name: :monk, x: 3045, y: 3497 -spawn_npc name: :monk, x: 3050, y: 3490 -spawn_npc name: :monk, x: 3054, y: 3490 -spawn_npc name: :monk, x: 3058, y: 3497 - -# Functional npcs - -spawn_npc name: :richard, x: 3098, y: 3516 -spawn_npc name: :doris, x: 3079, y: 3491 -spawn_npc name: :brother_jered, x: 3045, y: 3488 -spawn_npc name: :brother_althric, x: 3054, y: 3504 -spawn_npc name: :abbot_langley, x: 3059, y: 3484 -spawn_npc name: :oziach, x: 3067, y: 3518, face: :east -spawn_npc name: :shop_keeper_528, x: 3079, y: 3509 -spawn_npc name: :shop_assistant_529, x: 3082, y: 3513 - -spawn_npc name: :banker, x: 3096, y: 3489, face: :west -spawn_npc name: :banker_495, x: 3096, y: 3491, face: :west -spawn_npc name: :banker_495, x: 3096, y: 3492, face: :north -spawn_npc name: :banker, x: 3098, y: 3492, face: :north -spawn_npc name: :mage_of_zamorak, x: 3106, y: 3560 diff --git a/game/data/plugins/location/edgeville/plugin.xml b/game/data/plugins/location/edgeville/plugin.xml deleted file mode 100644 index 5874d0a2e..000000000 --- a/game/data/plugins/location/edgeville/plugin.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - location-edgeville - 0.1 - Edgeville - Adds functionality to Edgeville. - - xEliqa - Major - - - - - - entity-spawning - - \ No newline at end of file diff --git a/game/data/plugins/location/falador/npcs.rb b/game/data/plugins/location/falador/npcs.rb deleted file mode 100644 index 9d55c2e19..000000000 --- a/game/data/plugins/location/falador/npcs.rb +++ /dev/null @@ -1,157 +0,0 @@ -# Generic npcs - -spawn_npc name: :chicken, x: 2965, y: 3345 - -spawn_npc name: :duck, x: 2988, y: 3383 -spawn_npc name: :duck, x: 2992, y: 3383 -spawn_npc name: :duck, x: 2993, y: 3385 - -spawn_npc name: :drunken_man, x: 2957, y: 3368, z: 1 - -spawn_npc name: :dwarf_118, x: 3023, y: 3334 -spawn_npc name: :dwarf_118, x: 3027, y: 3341 -spawn_npc name: :dwarf_118, x: 3012, y: 3341 -spawn_npc name: :dwarf_118, x: 3017, y: 3346, z: 1 -spawn_npc name: :dwarf_118, x: 3011, y: 3341, z: 1 - -spawn_npc name: :dwarf_121, x: 3027, y: 3341 -spawn_npc name: :dwarf_382, x: 3017, y: 3340 -spawn_npc name: :dwarf_3294, x: 3022, y: 3338 -spawn_npc name: :dwarf_3295, x: 3021, y: 3341 - -spawn_npc name: :gardener, x: 2998, y: 3385 -spawn_npc name: :gardener, x: 3019, y: 3369 -spawn_npc name: :gardener_3234, x: 3016, y: 3386 - -spawn_npc name: :guard, x: 2965, y: 3394 -spawn_npc name: :guard, x: 2964, y: 3396 -spawn_npc name: :guard, x: 2966, y: 3397 -spawn_npc name: :guard, x: 2964, y: 3384 -spawn_npc name: :guard, x: 2963, y: 3380 -spawn_npc name: :guard, x: 3006, y: 3325 -spawn_npc name: :guard, x: 3008, y: 3320 -spawn_npc name: :guard, x: 3006, y: 3322 -spawn_npc name: :guard, x: 3038, y: 3356 - -spawn_npc name: :guard_10, x: 2942, y: 3375 -spawn_npc name: :guard_10, x: 3040, y: 3352 - -spawn_npc name: :guard_3230, x: 2967, y: 3395 -spawn_npc name: :guard_3230, x: 2966, y: 3392 -spawn_npc name: :guard_3230, x: 2963, y: 3376 -spawn_npc name: :guard_3230, x: 2954, y: 3382 -spawn_npc name: :guard_3231, x: 2950, y: 3377 -spawn_npc name: :guard_3231, x: 2968, y: 3381 - -spawn_npc name: :guard_3231, x: 3033, y: 3389, z: 1 -spawn_npc name: :guard_3231, x: 3041, y: 3388, z: 1 -spawn_npc name: :guard_3231, x: 3048, y: 3389, z: 1 -spawn_npc name: :guard_3231, x: 3056, y: 3389, z: 1 -spawn_npc name: :guard_3231, x: 3062, y: 3386, z: 1 -spawn_npc name: :guard_3231, x: 3058, y: 3329, z: 1 -spawn_npc name: :guard_3231, x: 3050, y: 3329, z: 1 -spawn_npc name: :guard_3231, x: 3038, y: 3329, z: 1 -spawn_npc name: :guard_3231, x: 3029, y: 3329, z: 1 - -spawn_npc name: :swan, x: 2960, y: 3359 -spawn_npc name: :swan, x: 2963, y: 3360 -spawn_npc name: :swan, x: 2968, y: 3359 -spawn_npc name: :swan, x: 2971, y: 3360 -spawn_npc name: :swan, x: 2976, y: 3358 -spawn_npc name: :swan, x: 2989, y: 3384 - -spawn_npc name: :man_3223, x: 2991, y: 3365 -spawn_npc name: :man_3225, x: 3037, y: 3345, z: 1 - -spawn_npc name: :white_knight, x: 2983, y: 3343 -spawn_npc name: :white_knight, x: 2981, y: 3334 -spawn_npc name: :white_knight, x: 2988, y: 3335 -spawn_npc name: :white_knight, x: 2996, y: 3342 -spawn_npc name: :white_knight, x: 2960, y: 3340 -spawn_npc name: :white_knight, x: 2962, y: 3336 -spawn_npc name: :white_knight, x: 2974, y: 3342 -spawn_npc name: :white_knight, x: 2972, y: 3345 -spawn_npc name: :white_knight, x: 2977, y: 3348 - -spawn_npc name: :white_knight_3348, x: 2971, y: 3340 -spawn_npc name: :white_knight_3348, x: 2978, y: 3350 - -spawn_npc name: :white_knight, x: 2964, y: 3330, z: 1 -spawn_npc name: :white_knight, x: 2968, y: 3334, z: 1 -spawn_npc name: :white_knight, x: 2969, y: 3339, z: 1 -spawn_npc name: :white_knight, x: 2978, y: 3332, z: 1 -spawn_npc name: :white_knight, x: 2958, y: 3340, z: 1 -spawn_npc name: :white_knight, x: 2960, y: 3343, z: 1 - -spawn_npc name: :white_knight_3348, x: 2987, y: 3334, z: 1 -spawn_npc name: :white_knight_3348, x: 2983, y: 3336, z: 1 -spawn_npc name: :white_knight_3348, x: 2987, y: 3334, z: 1 -spawn_npc name: :white_knight_3348, x: 2979, y: 3348, z: 1 -spawn_npc name: :white_knight_3348, x: 2964, y: 3337, z: 1 - -spawn_npc name: :white_knight_3349, x: 2989, y: 3344, z: 1 - -spawn_npc name: :white_knight, x: 2985, y: 3342, z: 2 -spawn_npc name: :white_knight_3348, x: 2979, y: 3348, z: 2 -spawn_npc name: :white_knight_3348, x: 2974, y: 3329, z: 2 -spawn_npc name: :white_knight_3348, x: 2982, y: 3341, z: 2 - -spawn_npc name: :white_knight_3349, x: 2990, y: 3341, z: 2 -spawn_npc name: :white_knight_3349, x: 2971, y: 3330, z: 2 -spawn_npc name: :white_knight_3349, x: 2965, y: 3350, z: 2 -spawn_npc name: :white_knight_3349, x: 2965, y: 3329, z: 2 - -spawn_npc name: :white_knight_3350, x: 2961, y: 3347, z: 2 - -spawn_npc name: :white_knight_3349, x: 2962, y: 3339, z: 3 - -spawn_npc name: :white_knight_3350, x: 2960, y: 3336, z: 3 -spawn_npc name: :white_knight_3350, x: 2984, y: 3349, z: 3 - -spawn_npc name: :woman_3226, x: 2991, y: 3384 - -# Functional npcs - -spawn_npc name: :apprentice_workman_3235, x: 2971, y: 3369, z: 1 - -spawn_npc name: :banker_495, x: 2945, y: 3366, face: :north -spawn_npc name: :banker_495, x: 2946, y: 3366, face: :north -spawn_npc name: :banker_495, x: 2947, y: 3366, face: :north -spawn_npc name: :banker_495, x: 2948, y: 3366, face: :north - -spawn_npc name: :banker, x: 2949, y: 3366, face: :north -spawn_npc name: :banker, x: 3015, y: 3353, face: :north -spawn_npc name: :banker, x: 3014, y: 3353, face: :north -spawn_npc name: :banker, x: 3013, y: 3353, face: :north -spawn_npc name: :banker, x: 3012, y: 3353, face: :north -spawn_npc name: :banker, x: 3011, y: 3353, face: :north -spawn_npc name: :banker, x: 3010, y: 3353, face: :north - -spawn_npc name: :cassie, x: 2976, y: 3383 -spawn_npc name: :emily, x: 2954, y: 3372 -spawn_npc name: :flynn, x: 2950, y: 3387 - -spawn_npc name: :hairdresser, x: 2944, y: 3380 - -spawn_npc name: :herquin, x: 2945, y: 3335 - -spawn_npc name: :heskel, x: 3007, y: 3374 -spawn_npc name: :kaylee, x: 2957, y: 3372 - -spawn_npc name: :tina, x: 2955, y: 3371, z: 1 -spawn_npc name: :tool_leprechaun, x: 3005, y: 3370 - -spawn_npc name: :squire, x: 2977, y: 3343 -spawn_npc name: :sir_tiffy_cashien, x: 2997, y: 3373, face: :north -spawn_npc name: :sir_amik_varze, x: 2960, y: 3336, z: 2 -spawn_npc name: :sir_vyvin, x: 2983, y: 3335, z: 2 - -spawn_npc name: :shop_asssistant_525, x: 2955, y: 3389 -spawn_npc name: :shop_keeper_524, x: 2957, y: 3387 - -spawn_npc name: :wayne, x: 2972, y: 3312 - -spawn_npc name: :workman_3236, x: 2975, y: 3369, z: 1 - -spawn_npc name: :wyson_the_gardener, x: 3028, y: 3381 - diff --git a/game/data/plugins/location/falador/plugin.xml b/game/data/plugins/location/falador/plugin.xml deleted file mode 100644 index 147cf4635..000000000 --- a/game/data/plugins/location/falador/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - location-falador - 0.1 - Falador - Adds functionality to Falador. - - Wizard Jesse - - - - - - entity-spawning - - \ No newline at end of file diff --git a/game/data/plugins/location/lumbridge/npcs.rb b/game/data/plugins/location/lumbridge/npcs.rb deleted file mode 100644 index 29e6df298..000000000 --- a/game/data/plugins/location/lumbridge/npcs.rb +++ /dev/null @@ -1,16 +0,0 @@ - -# Generic npcs - -spawn_npc name: :woman_4, x: 3232, y: 3207 # southernmost house -spawn_npc name: :man_1, x: 3231, y: 3237 # house by willow tree -spawn_npc name: :man_2, x: 3224, y: 3240 # house by willow tree -spawn_npc name: :woman_5, x: 3229, y: 2329 # house by willow tree - -# Functional npcs - -spawn_npc name: :hans, x: 3221, y: 3221 -spawn_npc name: :father_aereck, x: 3243, y: 3210 -spawn_npc name: :bob, x: 3231, y: 3203 -spawn_npc name: :shop_keeper, x: 3212, y: 3247 -spawn_npc name: :shop_assistant, x: 3211, y: 3245 -spawn_npc name: :lumbridge_guide, x: 3232, y: 3229 diff --git a/game/data/plugins/location/lumbridge/plugin.xml b/game/data/plugins/location/lumbridge/plugin.xml deleted file mode 100644 index 22ea2f94d..000000000 --- a/game/data/plugins/location/lumbridge/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - location-lumbridge - 0.1 - Lumbridge - Adds functionality to Lumbridge. - - Major - - - - - - entity-spawning - - \ No newline at end of file diff --git a/game/data/plugins/location/tutorial-island/guide.rb b/game/data/plugins/location/tutorial-island/guide.rb deleted file mode 100644 index 74778a484..000000000 --- a/game/data/plugins/location/tutorial-island/guide.rb +++ /dev/null @@ -1,158 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.message.impl.HintIconMessage' -java_import 'org.apollo.game.message.impl.MobHintIconMessage' -java_import 'org.apollo.game.message.impl.PositionHintIconMessage' -java_import 'org.apollo.game.message.impl.SwitchTabInterfaceMessage' -java_import 'org.apollo.game.model.entity.EntityType' -java_import 'org.apollo.game.model.Position' - -private - -# Contains constants used during the Runescape Guide part of Tutorial Island. -module GuideConstants - - # The Runescape Guide Npc. - RUNESCAPE_GUIDE = spawn_npc name: :runescape_guide, x: 3093, y: 3107 - - # The character design interface id. - CHARACTER_DESIGN_INTERFACE = 3559 - - # The id of the door of the house new players spawn in. - DOOR_ID = 3014 - - # The Position of the door of the house new players spawn in. - DOOR_POSITION = Position.new(3098, 3107) - - # The HintIconMessage sent to display a hint arrow above the door of the house new players spawn - # in. - DOOR_HINT = PositionHintIconMessage.new(HintIconMessage::Type::WEST, DOOR_POSITION, 120) - - # The ids of tabs that are displayed when the player has yet to start the tutorial. - INITIAL_TABS = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2449, 904, -1, -1].freeze - - # The HintIconMessage sent to remove a hint arrow from above the door. - RESET_DOOR_HINT = PositionHintIconMessage.reset - - # The HintIconMessage sent to remove a hint arrow from an Npc. - RESET_NPC_HINT = MobHintIconMessage.reset(EntityType::NPC) - -end - -# Sends the appropriate data to the client when the player logs in to the game. -on :login do |_event, player| - if player.in_tutorial_island && player.privilege_level != RIGHTS_ADMIN - TutorialInstructions.show_instruction(player) - - GuideConstants::INITIAL_TABS.each_with_index do |tab, index| - player.send(SwitchTabInterfaceMessage.new(index, tab)) - end - - if player.tutorial_island_progress == :not_started - player.interface_set.open_window(GuideConstants::CHARACTER_DESIGN_INTERFACE) - player.send(MobHintIconMessage.create(GuideConstants::RUNESCAPE_GUIDE)) - end - end -end - -# The conversation with the Runescape Guide, when on tutorial island. -conversation :tutorial_runescape_guide do - - # The first dialogue of the Runescape Guide, greeting the Player. - dialogue :greetings do - type :npc_speech - npc :runescape_guide - emote :calm - - precondition { |player| player.tutorial_island_progress == :not_started } - - text 'Greetings! I see you are a new arrival to this land. My job is to welcome all new '\ - 'visitors. So welcome!' - - continue dialogue: :talk_to_people do |player| - player.tutorial_island_progress = :talk_to_people - end - end - - # The Guide welcomes back the Player if they speak to him after they have already gone through - # the conversation once. - dialogue :welcome_back do - type :npc_speech - npc :runescape_guide - emote :calm - - precondition { |player| player.tutorial_island_progress != :not_started } - - text 'Welcome back.' - - continue dialogue: :talk_to_people - end - - # The Guide tells Players to speak to people in order to succeed. - dialogue :talk_to_people do - type :npc_speech - npc :runescape_guide - emote :calm - - text 'You have already learned the first thing you need to succeed in this world: talking to '\ - 'people!', - 'You will find many inhabitants of this world have useful things to say to you. By '\ - 'clicking on them with your mouse you can talk to them.', - 'I would also suggest reading through some of the supporting information on the website.'\ - ' There you can find maps, a bestiary, and much more.' - - continue dialogue: :go_through_door - end - - # The Guide tells Players to go through the door, advancing the tutorial progress if this is the - # first time the Player has heard this. - dialogue :go_through_door do - type :npc_speech - npc :runescape_guide - emote :calm - - text 'To continue the tutorial go through that door over there, and speak to your first '\ - 'instructor.' - - close do |player| - if player.tutorial_island_progress < :runescape_guide_finished - player.send(GuideConstants::RESET_NPC_HINT) - - player.send(GuideConstants::DOOR_HINT) - player.tutorial_island_progress = :runescape_guide_finished - end - - TutorialInstructions.show_instruction(player) - end - end - - # The dialogue displayed if the player attempts to leave the Runescape Guide's house before they - # have spoken to him. - dialogue :talk_to_guide do - type :text - - text 'You need to talk to the Runescape Guide before you are allowed to proceed through this '\ - 'door.' - - close do |player| - TutorialInstructions.show_instruction(player) - end - end - -end - -on :open_door do |event, player| - door = event.door - - if player.in_tutorial_island && door.position.equals(GuideConstants::DOOR_POSITION) - if player.tutorial_island_progress < :runescape_guide_finished - send_dialogue(player, get_dialogue(:tutorial_runescape_guide, :talk_to_guide)) - event.terminate - elsif player.tutorial_island_progress == :runescape_guide_finished - player.tutorial_island_progress = :moving_around - player.send(GuideConstants::RESET_DOOR_HINT) - TutorialInstructions.show_instruction(player) - end - end -end - diff --git a/game/data/plugins/location/tutorial-island/instructions.rb b/game/data/plugins/location/tutorial-island/instructions.rb deleted file mode 100644 index a9526937b..000000000 --- a/game/data/plugins/location/tutorial-island/instructions.rb +++ /dev/null @@ -1,141 +0,0 @@ - - -# Contains members related to the instructions issues during tutorial island. -module TutorialInstructions - - # Sends the appropriate instruction to the player. - def self.show_instruction(player) - instructions = CONVERSATIONS[:tutorial_island_instructions] - progress = player.tutorial_island_progress.name - name = case progress - # The Runescape Guide instructions. - when :not_started then :getting_started - when :runescape_guide_finished then :scenery - when :moving_around then :moving_around - - # The Survival Guide instructions. - when :given_axe then :viewing_items - when :cut_tree then :cut_tree - when :cutting_tree then :please_wait - - else raise "No dialogue for current stage #{progress} exists." - end - - dialogue = instructions.part(name) - send_dialogue(player, dialogue) - end - - # The one-sided 'conversation' of instruction instructions. - conversation :tutorial_island_instructions do - - # The initial instruction displayed when the player logs in, before they have spoken to the - # guide. - dialogue :getting_started do - type :text - - title 'Getting started' - text 'To start the tutorial, use your left mouse button to click on the Runescape Guide in '\ - 'this room. He is indicated by a flashing yellow arrow above his head. If you can\'t '\ - 'see him, use your keyboard\'s arrow keys to rotate the view.' - end - - # The instruction displayed after the player has spoken to the Runescape Guide. - dialogue :scenery do - type :text - - title 'Interacting with scenery' - text 'You can interact with many items of the scenery by simply clicking on them. Right '\ - 'clicking will also give more options. Click on the door indicated with the yellow '\ - 'arrow to go through to the next area and speak with your next instructor.' - end - - - # The instruction displayed after the player has left the initial building. - dialogue :moving_around do - type :text - - title 'Moving around' - text 'Follow the path to find the next instructor. Clicking on the ground will walk you to '\ - 'that point. Talk to the survival expert by the pond to continue the tutorial. '\ - 'Remember you can rotate the view by pressing the arrow keys.' - end - - # The instruction displayed after the player has been given the tinderbox and bronze axe by the - # Survival Guide. - dialogue :viewing_items do - type :text - - title 'Viewing the items you were given' - text 'Click on the flashing backpack icon to the right side of the main window to view your '\ - 'inventory. Your inventory is a list of everything you have in your backpack.' - end - - # The instruction displayed if the player tries to cut a tree before having the axe. - dialogue :try_cut_tree do - type :text - - title 'Follow the guide\'s instructions' - text 'You cannot cut down this tree, you must first follow the guide\'s instructions.' - end - - # The instruction displayed before the player has begun to cut the tree. - dialogue :cut_tree do - type :text - - title 'Cut down a tree' - text 'You can click on the backpack icon at any time to view the items that you currently '\ - 'have in your inventory. You will see that you now have an axe in your inventory. '\ - 'Use this to get some logs by clicking on the indicated tree.' - end - - # The instruction displayed when the player begins to cut the tree. - dialogue :please_wait do - type :text - - title 'Please wait...' - text 'Your character is now attempting to cut down the tree. Sit back for a moment whilst '\ - 'he does all the hard work.' # TODO: she instead of he if applicable - end - - # The instruction displayed after the player has successfully cut logs from the tree. - dialogue :make_a_fire do - type :text - - title 'Making a fire' - text 'Well done! You managed to cut some logs from the tree! Next, use the tinderbox in '\ - 'your inventory to light the logs. First click on the tinderbox to \'use\' it.'\ - 'Then click on the logs in your inventory to light them.' - end - - # The instruction displayed when the player begins to light the fire. - dialogue :lighting_fire do - type :text - - title 'Please wait...' - # TODO: she instead of he if applicable - text 'Your character is now attempting to light the logs. Sit back for a moment whilst he '\ - 'does all the hard work.' - end - - # The instruction displayed when the has lit the logs. - dialogue :gained_experience do - type :text - - text 'You gained some experience.'\ - 'Click on the flashing bar graph icon near the inventory button to see your skill '\ - 'stats.' - end - - # The dialogue displayed when the Player has clicked the flashing skill tab icon. - dialogue :skill_stats do - type :text - - title 'Your skill stats.' - text 'Here you will see how good your skills are. As you move your mouse over any of the '\ - 'icons in this panel, the small yellow popup box will show you the exact amount of '\ - 'experience you have and how much is needed to get to the next level. Speak to the '\ - 'Survival Expert to continue.' - end - end - -end diff --git a/game/data/plugins/location/tutorial-island/npcs.rb b/game/data/plugins/location/tutorial-island/npcs.rb deleted file mode 100644 index 264784782..000000000 --- a/game/data/plugins/location/tutorial-island/npcs.rb +++ /dev/null @@ -1,40 +0,0 @@ - -# Functional npcs - -# 'Above-ground' npcs - -spawn_npc name: :master_chef, x: 3076, y: 3085 -spawn_npc name: :quest_guide, x: 3086, y: 3122, face: :north -spawn_npc name: :financial_advisor, x: 3127, y: 3124, face: :west -spawn_npc name: :brother_brace, x: 3124, y: 3107, face: :east -spawn_npc name: :magic_instructor, x: 3140, y: 3085 - -# 'Below-ground' npcs -# Note: They aren't actually on a different plane, they're just in a different location that -# pretends to be underground. - -spawn_npc name: :mining_instructor, x: 3081, y: 9504 -spawn_npc name: :combat_instructor, x: 3104, y: 9506 - -# Non-humanoid npcs - -spawn_npc name: :fishing_spot_316, x: 3102, y: 3093 - -spawn_npc name: :chicken, x: 3140, y: 3095 -spawn_npc name: :chicken, x: 3140, y: 3093 -spawn_npc name: :chicken, x: 3138, y: 3092 -spawn_npc name: :chicken, x: 3137, y: 3094 -spawn_npc name: :chicken, x: 3138, y: 3095 - -# 'Below-ground' npcs -# Note: They aren't actually on a different plane, they're just in a different location that -# pretends to be underground. - -spawn_npc name: :giant_rat_87, x: 3105, y: 9514 -spawn_npc name: :giant_rat_87, x: 3105, y: 9517 -spawn_npc name: :giant_rat_87, x: 3106, y: 9514 -spawn_npc name: :giant_rat_87, x: 3104, y: 9514 -spawn_npc name: :giant_rat_87, x: 3105, y: 9519 -spawn_npc name: :giant_rat_87, x: 3109, y: 9516 -spawn_npc name: :giant_rat_87, x: 3108, y: 9520 -spawn_npc name: :giant_rat_87, x: 3102, y: 9517 diff --git a/game/data/plugins/location/tutorial-island/plugin.xml b/game/data/plugins/location/tutorial-island/plugin.xml deleted file mode 100644 index 72537461c..000000000 --- a/game/data/plugins/location/tutorial-island/plugin.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - location-tutorial-island - 0.1 - Tutorial Island - Adds functionality to Tutorial island. - - Major - - - - - - - - - - - dialogue - door - entity-spawning - quest - - diff --git a/game/data/plugins/location/tutorial-island/stages.rb b/game/data/plugins/location/tutorial-island/stages.rb deleted file mode 100644 index b5ac6ccab..000000000 --- a/game/data/plugins/location/tutorial-island/stages.rb +++ /dev/null @@ -1,16 +0,0 @@ - -private - -# The array of stages in tutorial island. -@stages = [] - -# The stages that are used when interacting with the Runescape Guide. -RUNESCAPE_GUIDE = [:not_started, :talk_to_people, :go_through_door, :runescape_guide_finished, - :moving_around].freeze -@stages.concat(RUNESCAPE_GUIDE) - -# The stages that are used when interacting with the Survival Expert. -SURVIVAL_EXPERT = [:given_axe, :cut_tree, :cutting_tree].freeze -@stages.concat(SURVIVAL_EXPERT) - -quest :tutorial_island, @stages diff --git a/game/data/plugins/location/tutorial-island/survival.rb b/game/data/plugins/location/tutorial-island/survival.rb deleted file mode 100644 index a5d47554b..000000000 --- a/game/data/plugins/location/tutorial-island/survival.rb +++ /dev/null @@ -1,154 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.message.impl.FlashTabInterfaceMessage' -java_import 'org.apollo.game.message.impl.FlashingTabClickedMessage' -java_import 'org.apollo.game.message.impl.SwitchTabInterfaceMessage' - -private - -# Contains Survival Expert-related constants. -module SurvivalConstants - - # The Survival Expert Npc. - @survival_expert = spawn_npc name: :survival_expert, x: 3104, y: 3095, face: :north - - # The inventory tab index. - INVENTORY_TAB_INDEX = 3 - - # The inventory tab id. - INVENTORY_TAB_ID = 3213 - - # The id of the tree the Player will cut down. - TREE_ID = 3033 - - # The id of the bronze axe. - BRONZE_AXE = lookup_item(:bronze_axe) - - # The id of the tinderbox. - TINDERBOX = lookup_item(:tinderbox) - -end - -# The conversation with the Survival Expert, when on tutorial island. -conversation :tutorial_survival_expert do - - dialogue :introduction do - type :npc_speech - npc :survival_expert - - precondition { |player| player.tutorial_island_progress == :moving_around } - - text 'Hello there, newcomer. My name is Brynna. My job is to teach you a few survival tips and'\ - ' tricks. First off we\'re going to start with the most basic survival skill of all: '\ - 'making a fire.' - - close { |player| add_survival_items(player) } - end - - dialogue :hello_again do - type :npc_speech - npc :survival_expert - - precondition { |player| player.tutorial_island_progress == :moving_around } - - text 'Hello again. I\'m here to teach you a few survival tips and tricks. First off we\'re '\ - 'going to start with the most basic survival skill of all: making a fire.' - - close { |player| add_survival_items(player) } - end - - # The dialogue displayed when the Survival Expert gives the player a bronze axe. - dialogue :give_bronze_axe do - type :message_with_item - item :bronze_axe - - text 'The Survival Expert gives you a bronze axe!' - - close { |player| TutorialInstructions.show_instruction(player) } - end - - # The dialogue displayed when the Survival Expert gives the player a tinderbox. - dialogue :give_tinderbox do - type :message_with_item - item :tinderbox - - text 'The Survival Expert gives you a tinderbox!' - - close { |player| TutorialInstructions.show_instruction(player) } - end - - # The dialogue displayed when the Survival Expert gives the player both a bronze axe and a - # tinderbox. - dialogue :give_axe_and_tinderbox do - type :message_with_item - item :bronze_axe - # TODO: the tinderbox is also displayed - find this dialogue id. Scale looks like the default - # http://i.imgur.com/i1abN5X.png - - text 'The Survival Expert gives you a tinderbox and a bronze axe!' - - close do |player| - if player.tutorial_island_progress < :given_axe - player.tutorial_island_progress = :given_axe - - index = SurvivalConstants::INVENTORY_TAB_INDEX - player.send(SwitchTabInterfaceMessage.new(index, SurvivalConstants::INVENTORY_TAB_ID)) - player.send(FlashTabInterfaceMessage.new(index)) - end - - TutorialInstructions.show_instruction(player) - end - end - - # The dialogue displayed when the player has succesfully cut down a tree. - dialogue :get_logs do - type :message_with_item - item :logs - - text 'You get some logs.' - close { |player| TutorialInstructions.show_instruction(player) } - end - -end - -# Add the survival items (bronze axe and tinderbox) to the inventory of the player, if they do not -# already have them. -def add_survival_items(player) - inventory = player.inventory - - unless inventory.contains(SurvivalConstants::BRONZE_AXE) - inventory.add(SurvivalConstants::BRONZE_AXE) - dialogue = :give_bronze_axe - end - - unless inventory.contains(SurvivalConstants::TINDERBOX) - inventory.add(SurvivalConstants::TINDERBOX) - dialogue = (dialogue == :give_bronze_axe) ? :give_axe_and_tinderbox : :give_tinderbox - end - - send_dialogue(player, get_dialogue(:tutorial_survival_expert, dialogue)) -end - -# Intercept the FirstObjectActionMessage to send tutorial-only events if the player is chopping -# down a tree. -on :message, :first_object_action do |player, message| - if player.in_tutorial_island && message.id == SurvivalConstants::TREE_ID - progress = player.tutorial_island_progress - - if progress < :cut_tree - send_dialogue(player, get_dialogue(:tutorial_island_instructions, :try_cut_tree)) - elsif player.tutorial_island_progress == :cut_tree - # Don't break the chain, so that the Woodcutting event actually happens. - player.tutorial_island_progress = :cutting_tree - end - end -end - -# Intercept the FlashingTabClickedMessage to update the player's progress, if applicable. -on :message, :flashing_tab_clicked do |player, message| - if player.in_tutorial_island && message.tab == SurvivalConstants::INVENTORY_TAB_INDEX && - player.tutorial_island_progress == :given_axe - player.tutorial_island_progress = :cut_tree - message.terminate - end -end diff --git a/game/data/plugins/location/tutorial-island/utils.rb b/game/data/plugins/location/tutorial-island/utils.rb deleted file mode 100644 index 7a873b873..000000000 --- a/game/data/plugins/location/tutorial-island/utils.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.entity.Player' - -# Declare the tutorial island progress attribute. -declare_attribute(:tutorial_island_progress, :not_started, :persistent) - -# The existing player class. -class Player - - # Returns whether or not this Player is currently on tutorial island. - def in_tutorial_island - x = position.x - y = position.y - above_ground(x, y) || below_ground(x, y) - end - -end - -private - -# Returns whether or not the specified coordinate pair is above ground on tutorial island. -def above_ground(x, y) - x >= 3053 && x <= 3156 && y >= 3056 && y <= 3136 -end - -# Returns whether or not the specified coordinate pair is 'below' ground on tutorial island. -def below_ground(x, y) - x >= 3072 && x <= 3118 && y >= 9492 && y <= 9535 -end diff --git a/game/data/plugins/location/varrock/npcs.rb b/game/data/plugins/location/varrock/npcs.rb deleted file mode 100644 index 0bd4c84ed..000000000 --- a/game/data/plugins/location/varrock/npcs.rb +++ /dev/null @@ -1,258 +0,0 @@ -# Generic Npc - -spawn_npc name: :barbarian_woman, x: 3222, y: 3399 - -spawn_npc name: :bear_106, x: 3289, y: 3351 - -spawn_npc name: :black_knight, x: 3238, y: 3514 -spawn_npc name: :black_knight, x: 3227, y: 3518 -spawn_npc name: :black_knight, x: 3279, y: 3502 - -spawn_npc name: :dark_wizard_174, x: 3230, y: 3366 -spawn_npc name: :dark_wizard_174, x: 3228, y: 3368 -spawn_npc name: :dark_wizard_174, x: 3225, y: 3367 -spawn_npc name: :dark_wizard_174, x: 3226, y: 3365 -spawn_npc name: :dark_wizard_174, x: 3226, y: 3372 -spawn_npc name: :dark_wizard_174, x: 3231, y: 3371 - -spawn_npc name: :dark_wizard_172, x: 3229, y: 3372 -spawn_npc name: :dark_wizard_172, x: 3224, y: 3370 -spawn_npc name: :dark_wizard_172, x: 3228, y: 3366 -spawn_npc name: :dark_wizard_172, x: 3232, y: 3368 -spawn_npc name: :dark_wizard_172, x: 3226, y: 3369 - -spawn_npc name: :giant_rat_87, x: 3292, y: 3375 -spawn_npc name: :giant_rat_87, x: 3265, y: 3384 -spawn_npc name: :giant_rat_87, x: 3267, y: 3381 - -spawn_npc name: :guard_368, x: 3263, y: 3407, face: :south - -spawn_npc name: :jeremy_clerksin, x: 3253, y: 3477 -spawn_npc name: :martina_scorsby, x: 3256, y: 3481 - -spawn_npc name: :man, x: 3281, y: 3500 -spawn_npc name: :man, x: 3193, y: 3394 -spawn_npc name: :man, x: 3159, y: 3429 -spawn_npc name: :man, x: 3245, y: 3394 -spawn_npc name: :man, x: 3283, y: 3492, z: 1 - -spawn_npc name: :man_2, x: 3263, y: 3400 -spawn_npc name: :man_3, x: 3227, y: 3395, z: 1 -spawn_npc name: :man_3, x: 3231, y: 3399, z: 1 - -spawn_npc name: :mugger, x: 3251, y: 3390 -spawn_npc name: :mugger, x: 3177, y: 3363 - -spawn_npc name: :tramp_2792, x: 3228, y: 3410 - -spawn_npc name: :woman, x: 3221, y: 3396 -spawn_npc name: :woman_5, x: 3279, y: 3497 -spawn_npc name: :woman_25, x: 3278, y: 3492 - -spawn_npc name: :thief, x: 3285, y: 3500 -spawn_npc name: :thief, x: 3234, y: 3389 -spawn_npc name: :thief, x: 3188, y: 3383 -spawn_npc name: :thief, x: 3184, y: 3390 -spawn_npc name: :thief, x: 3188, y: 3394 - -spawn_npc name: :unicorn, x: 3286, y: 3342 -spawn_npc name: :unicorn, x: 3279, y: 3345 - - -# North Guards - -spawn_npc name: :guard, x: 3244, y: 3500 -spawn_npc name: :guard, x: 3247, y: 3503 - -# East Guards - -spawn_npc name: :guard, x: 3271, y: 3431 -spawn_npc name: :guard, x: 3270, y: 3425 -spawn_npc name: :guard, x: 3274, y: 3421 -spawn_npc name: :guard, x: 3274, y: 3427 - -# South Guards - -spawn_npc name: :guard, x: 3210, y: 3382 -spawn_npc name: :guard, x: 3212, y: 3380 -spawn_npc name: :guard, x: 3207, y: 3376 - -# West Guards - -spawn_npc name: :guard, x: 3174, y: 3427 -spawn_npc name: :guard, x: 3176, y: 3430 -spawn_npc name: :guard, x: 3176, y: 3427 -spawn_npc name: :guard, x: 3180, y: 3399 -spawn_npc name: :guard, x: 3175, y: 3415, z: 1 -spawn_npc name: :guard, x: 3174, y: 3403, z: 1 - -# Varrock Palace - -spawn_npc name: :guard, x: 3210, y: 3461 -spawn_npc name: :guard, x: 3211, y: 3465 -spawn_npc name: :guard, x: 3214, y: 3462 -spawn_npc name: :guard, x: 3216, y: 3464 -spawn_npc name: :guard, x: 3220, y: 3461 -spawn_npc name: :guard, x: 3206, y: 3461 -spawn_npc name: :guard, x: 3204, y: 3495 -spawn_npc name: :guard, x: 3204, y: 3495, z: 1 -spawn_npc name: :guard, x: 3205, y: 3492, z: 1 -spawn_npc name: :guard, x: 3203, y: 3492, z: 1 -spawn_npc name: :guard, x: 3205, y: 3497, z: 1 -spawn_npc name: :guard, x: 3221, y: 3471, z: 2 -spawn_npc name: :guard, x: 3214, y: 3474, z: 2 -spawn_npc name: :guard, x: 3215, y: 3471, z: 2 -spawn_npc name: :guard, x: 3211, y: 3471, z: 2 -spawn_npc name: :guard, x: 3209, y: 3473, z: 2 -spawn_npc name: :guard, x: 3212, y: 3475, z: 2 -spawn_npc name: :guard, x: 3207, y: 3477, z: 2 -spawn_npc name: :guard, x: 3203, y: 3476, z: 2 -spawn_npc name: :guard, x: 3205, y: 3479, z: 2 -spawn_npc name: :guard, x: 3203, y: 3483, z: 2 -spawn_npc name: :guard, x: 3221, y: 3485, z: 2 - -spawn_npc name: :monk_of_zamorak_189, x: 3213, y: 3476 - -spawn_npc name: :warrior_woman, x: 3203, y: 3490 -spawn_npc name: :warrior_woman, x: 3205, y: 3493 - -# Varrock/Lumbridge Pen - -spawn_npc name: :swan, x: 3261, y: 3354 -spawn_npc name: :swan, x: 3260, y: 3356 - -spawn_npc name: :ram_3673, x: 3238, y: 3346 -spawn_npc name: :ram_3673, x: 3248, y: 3352 -spawn_npc name: :ram_3673, x: 3260, y: 3348 - -spawn_npc name: :sheep_42, x: 3263, y: 3347 -spawn_npc name: :sheep_42, x: 3268, y: 3350 -spawn_npc name: :sheep_42, x: 3252, y: 3352 -spawn_npc name: :sheep_42, x: 3243, y: 3344 -spawn_npc name: :sheep_42, x: 3235, y: 3347 - -spawn_npc name: :sheep_3579, x: 3234, y: 3344 -spawn_npc name: :sheep_3579, x: 3241, y: 3347 -spawn_npc name: :sheep_3579, x: 3257, y: 3350 - -# Champions Guild - -spawn_npc name: :chicken, x: 3195, y: 3359 -spawn_npc name: :chicken, x: 3198, y: 3356 -spawn_npc name: :chicken, x: 3195, y: 3355 - -spawn_npc name: :chicken_1017, x: 3196, y: 3353 -spawn_npc name: :chicken_1017, x: 3197, y: 3356 - -spawn_npc name: :evil_chicken, x: 3198, y: 3359 - -# Function Npc - -spawn_npc name: :apothecary, x: 3196, y: 3403 - -spawn_npc name: :captain_rovin, x: 3204, y: 3496, z: 2 - -spawn_npc name: :curator, x: 3256, y: 3447 - -spawn_npc name: :dimintheis, x: 3280, y: 3403 - -spawn_npc name: :dr_harlow, x: 3224, y: 3398 - -spawn_npc name: :ellamaria, x: 3228, y: 3475 - -spawn_npc name: :father_lawrence, x: 3253, y: 3484 - -spawn_npc name: :guidors_wife_342, x: 3280, y: 3382 - -spawn_npc name: :guidor, x: 3284, y: 3381, face: :south - -spawn_npc name: :guild_master, x: 3189, y: 3360 - -spawn_npc name: :gypsy, x: 3203, y: 3423 - -spawn_npc name: :hooknosed_jack, x: 3268, y: 3400 - -spawn_npc name: :jonny_the_beard, x: 3223, y: 3395 - -spawn_npc name: :johnathon, x: 3278, y: 3503, z: 1 - -spawn_npc name: :katrine, x: 3185, y: 3386 - -spawn_npc name: :king_roald, x: 3223, y: 3473 - -spawn_npc name: :master_farmer, x: 3243, y: 3349 - -spawn_npc name: :pox, x: 3267, y: 3399 - -spawn_npc name: :reldo, x: 3210, y: 3492 - -spawn_npc name: :romeo, x: 3211, y: 3423 - -spawn_npc name: :shilop, x: 3221, y: 3435 - -spawn_npc name: :sir_prysin, x: 3204, y: 3472 - -spawn_npc name: :tarquin, x: 3203, y: 3344, face: :south - -spawn_npc name: :tool_leprechaun, x: 3182, y: 3355 -spawn_npc name: :tool_leprechaun, x: 3229, y: 3455, face: :north - -spawn_npc name: :tramp_641, x: 3207, y: 3392 - -spawn_npc name: :wilough, x: 3222, y: 3437 - -# Shop Npc - -spawn_npc name: :aubury, x: 3253, y: 3401 - -spawn_npc name: :baraek, x: 3217, y: 3434 - -spawn_npc name: :bartender, x: 3226, y: 3400 -spawn_npc name: :bartender_1921, x: 3277, y: 3487 - -spawn_npc name: :fancy_dress_shop_owner, x: 3281, y: 3398 - -spawn_npc name: :horvik, x: 3229, y: 3438 - -spawn_npc name: :lowe, x: 3233, y: 3421 - -spawn_npc name: :scavvo, x: 3192, y: 3353, z: 1 - -spawn_npc name: :shop_keeper_551, x: 3206, y: 3399 -spawn_npc name: :shop_assistant_552, x: 3207, y: 3396 - -spawn_npc name: :shop_keeper_522, x: 3216, y: 3414 -spawn_npc name: :shop_assistant_523, x: 3216, y: 3417 - -spawn_npc name: :tea_seller, x: 3271, y: 3411 - -spawn_npc name: :thessalia, x: 3206, y: 3417 - -spawn_npc name: :zaff, x: 3203, y: 3434 - -# Juliet House - -spawn_npc name: :draul_leptoc, x: 3228, y: 3475 -spawn_npc name: :juliet, x: 3159, y: 3425, z: 1 -spawn_npc name: :phillipa, x: 3160, y: 3429, z: 1 - -# Gertrude House - -spawn_npc name: :gertrude, x: 3153, y: 3413 -spawn_npc name: :kanel, x: 3155, y: 3405, face: :east -spawn_npc name: :philop, x: 3150, y: 3405, face: :south - -# Small Bank - -spawn_npc name: :banker_495, x: 3252, y: 3418, face: :north -spawn_npc name: :banker_494, x: 3253, y: 3418, face: :north -spawn_npc name: :banker_494, x: 3254, y: 3418, face: :north -spawn_npc name: :banker_494, x: 3256, y: 3418, face: :north - -# Big Bank - -spawn_npc name: :banker_494, x: 3187, y: 3436, face: :west -spawn_npc name: :banker_495, x: 3187, y: 3438, face: :west -spawn_npc name: :banker_494, x: 3187, y: 3440, face: :west -spawn_npc name: :banker_495, x: 3187, y: 3442, face: :west -spawn_npc name: :banker_494, x: 3187, y: 3444, face: :west diff --git a/game/data/plugins/location/varrock/plugin.xml b/game/data/plugins/location/varrock/plugin.xml deleted file mode 100644 index 2e74c9fb7..000000000 --- a/game/data/plugins/location/varrock/plugin.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - location-varrock - 0.1 - Varrock - Adds functionality to Varrock. - - Wizard Jesse - - - - - - - entity-spawning - shops - - \ No newline at end of file diff --git a/game/data/plugins/location/varrock/shops.rb b/game/data/plugins/location/varrock/shops.rb deleted file mode 100644 index 37970e7b2..000000000 --- a/game/data/plugins/location/varrock/shops.rb +++ /dev/null @@ -1,44 +0,0 @@ - -create_shop npcs: :aubury, name: "Aubury's Rune Shop.", items: [ - [:fire_rune, 5_000], [:water_rune, 5_000], [:air_rune, 5_000], [:earth_rune, 5_000], - [:mind_rune, 5_000], [:body_rune, 5_000 ], [:chaos_rune, 250], [:death_rune, 250 ] -] - -create_shop npcs: :lowe, name: "Lowe's Archery Emporium", items: [ - [:bronze_arrow, 2_000], [:iron_arrow, 1_500], [:steel_arrow, 1_000], - [:mithril_arrow, 800], [:adamant_arrow, 600], [:shortbow, 4], [:longbow, 4], - [:oak_shortbow, 3], [:oak_longbow, 3], [:willow_shortbow, 2], [:willow_longbow, 2], - [:maple_shortbow, 1], [:maple_longbow, 1], [:crossbow, 2] -] - -create_shop npcs: :horvik, buys: :all, name: "Horvik's Armour Shop.", items: [ - [:bronze_chainbody, 5], [:iron_chainbody, 3], [:steel_chainbody, 3], - [:mithril_chainbody, 1], [:bronze_platebody, 3], [:iron_platebody, 1], - [:steel_platebody, 1], [:black_platebody, 1], [:mithril_platebody, 1], - [:iron_platelegs, 1], [:studded_body, 1], [:studded_chaps, 1] -] - -create_shop npcs: :thessalia, name: "Thessalia's Fine Clothes.", items: [ - [:white_apron, 3], [:leather_body, 12], [:leather_gloves, 10], [:leather_boots, 10], - [:brown_apron, 1], [:pink_skirt, 5], [:black_skirt, 3], [:blue_skirt, 2], [:cape, 4], - [:silk, 5], [:priest_gown_428, 3], [:priest_gown_426, 3] -] - -create_shop npcs: [:shop_keeper_522, :shop_assistant_523], buys: :all, - name: 'Varrock General Store', items: [ - [:pot, 5], [:jug, 2], [:shears, 2], [:bucket, 3], [:bowl, 2], [:cake_tin, 2], - [:tinderbox, 2], [:chisel, 2], [:hammer, 5], [:newcomer_map, 5] -] - -create_shop npcs: [:shop_keeper_551, :shop_assistant_552], name: 'Varrock Swordshop', items: [ - [:bronze_sword, 5], [:iron_sword, 4], [:steel_sword, 4], [:black_sword, 3], - [:mithril_sword, 3], [:adamant_sword, 2], [:bronze_longsword, 4], [:iron_longsword, 3], - [:steel_longsword, 3], [:black_longsword, 2], [:mithril_longsword, 2], - [:adamant_longsword, 1], [:bronze_dagger, 10], [:iron_dagger, 6], [:steel_dagger, 5], - [:black_dagger, 4], [:mithril_dagger, 3], [:adamant_dagger, 2] -] - -create_shop npcs: :zaff, name: "Zaff's Superior Staffs!", items: [ - [:battlestaff, 5], [:staff, 5], [:magic_staff, 5], [:staff_of_air, 2], - [:staff_of_water, 2], [:staff_of_earth, 2], [:staff_of_fire, 2] -] diff --git a/game/data/plugins/logout/logout.rb b/game/data/plugins/logout/logout.rb deleted file mode 100644 index 388834686..000000000 --- a/game/data/plugins/logout/logout.rb +++ /dev/null @@ -1,5 +0,0 @@ -LOGOUT_BUTTON_ID = 2458 - -on :button, LOGOUT_BUTTON_ID do |player| - player.logout -end diff --git a/game/data/plugins/logout/plugin.xml b/game/data/plugins/logout/plugin.xml deleted file mode 100644 index 6246ec704..000000000 --- a/game/data/plugins/logout/plugin.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - logout - 1 - Logout Button - Adds the logout button. - - Graham - - - - - - diff --git a/game/data/plugins/navigation/door/constants.rb b/game/data/plugins/navigation/door/constants.rb deleted file mode 100644 index 291d76083..000000000 --- a/game/data/plugins/navigation/door/constants.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'set' - -# Contains door-related constants. -module DoorConstants - - # TODO: GameObjectOrientation enumeration in Apollo's core? - # The orientation of a door. - module Orientation - WEST = 0 - NORTH = 1 - EAST = 2 - SOUTH = 3 - end - - # The size of a door object. - DOOR_SIZE = 1 - - # Door object ids that have a hinge on the left side. - LEFT_HINGE_DOORS = Set.new [1516, 1536, 1533] - - # Door object ids that have a hinge on the right side. - RIGHT_HINGE_DOORS = Set.new [1519, 1530, 4465, 4467, 3014, 3017, 3018, 3019] - - # The hash of orientations that a door will translate to when opened. - ORIENTATIONS = { - - # Orientations for doors that have a hinge on the left side. - left_side_hinge: { - Orientation::NORTH => Orientation::WEST, - Orientation::SOUTH => Orientation::EAST, - Orientation::WEST => Orientation::SOUTH, - Orientation::EAST => Orientation::NORTH - }, - - # Orientations for doors that have a hinge on the right side. - right_side_hinge: { - Orientation::NORTH => Orientation::EAST, - Orientation::SOUTH => Orientation::WEST, - Orientation::WEST => Orientation::NORTH, - Orientation::EAST => Orientation::SOUTH - } - } - -end diff --git a/game/data/plugins/navigation/door/door.rb b/game/data/plugins/navigation/door/door.rb deleted file mode 100644 index e0ee818b7..000000000 --- a/game/data/plugins/navigation/door/door.rb +++ /dev/null @@ -1,54 +0,0 @@ - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.model.event.Event' - -private - -# A distanced action which opens a door. -class OpenDoorAction < DistancedAction - include DoorConstants - - attr_reader :door - - def initialize(mob, door) - super(0, true, mob, door.position, DOOR_SIZE) - @door = door - end - - def executeAction - if $world.submit(OpenDoorEvent.new(mob, @door)) - mob.turn_to(@door.position) - DoorUtil.toggle(@door) - end - - stop - end - - def equals(other) - get_class == other.get_class && @door == other.door - end - -end - -# A PlayerEvent that is fired when a player attempts to open a door. -class OpenDoorEvent < PlayerEvent - attr_reader :door - - def initialize(player, door) - super(player) - @door = door - end - -end - - -# Listens for FirstObjectActions performed on doors. -on :message, :first_object_action do |player, message| - id = message.id - - if DoorUtil.door?(id) - door = DoorUtil.get_door_object(message.position, id) - player.start_action(OpenDoorAction.new(player, door)) unless door.nil? - end -end - diff --git a/game/data/plugins/navigation/door/plugin.xml b/game/data/plugins/navigation/door/plugin.xml deleted file mode 100644 index 4b5f435fe..000000000 --- a/game/data/plugins/navigation/door/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - door - 1 - Doors - Adds support for doors throughout the game. - - Shiver - - - - - - - - \ No newline at end of file diff --git a/game/data/plugins/navigation/door/util.rb b/game/data/plugins/navigation/door/util.rb deleted file mode 100644 index 4e17bad09..000000000 --- a/game/data/plugins/navigation/door/util.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Position' -java_import 'org.apollo.game.model.area.Region' -java_import 'org.apollo.game.model.entity.Entity' -java_import 'org.apollo.game.model.entity.obj.DynamicGameObject' - -# Contains door-related utility methods. -module DoorUtil - include DoorConstants - - # A hash containing currently toggled door objects mapped to the original door objects. - TOGGLED_DOORS = {} - - # Translates a door's position in the direction of its orientation. - def self.translate_door_position(door) - position = door.position - - case door.orientation - when Orientation::WEST - Position.new(position.x - 1, position.y, position.height) - when Orientation::EAST - Position.new(position.x + 1, position.y, position.height) - when Orientation::NORTH - Position.new(position.x, position.y + 1, position.height) - when Orientation::SOUTH - Position.new(position.x, position.y - 1, position.height) - else fail "Unsupported orientation #{door.orientation}." - end - end - - # Translates the orientation of a door to a toggled position. - def self.translate_door_orientation(door) - object_id = door.id - orientation = door.orientation - - if RIGHT_HINGE_DOORS.include?(object_id) - return ORIENTATIONS[:right_side_hinge][orientation] - elsif LEFT_HINGE_DOORS.include?(object_id) - return ORIENTATIONS[:left_side_hinge][orientation] - end - - fail 'Given object was not registered as a door.' - end - - # Toggles the given door. - def self.toggle(door) - region = $world.region_repository.from_position(door.position) - region.remove_entity(door) - - if TOGGLED_DOORS.include?(door) - original_door = TOGGLED_DOORS.delete(door) - - original_region = $world.region_repository.from_position(original_door.position) - original_region.add_entity(original_door) - else - position = translate_door_position(door) - orientation = translate_door_orientation(door) - type = door.type - - toggled_door = DynamicGameObject.create_public($world, door.id, position, type, orientation) - - toggled_region = $world.region_repository.from_position(position) - toggled_region.add_entity(toggled_door) - - TOGGLED_DOORS[toggled_door] = door - end - end - - # Gets the door object at the given position, if it exists. - def self.get_door_object(position, object_id) - region = $world.region_repository.from_position(position) - objects = region.get_entities(position, EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT) - objects.each { |game_object| return game_object if game_object.id == object_id } - nil - end - - # Checks if the given game object id is a door. - def self.door?(object_id) - RIGHT_HINGE_DOORS.include?(object_id) || LEFT_HINGE_DOORS.include?(object_id) - end - -end diff --git a/game/data/plugins/player-action/action.rb b/game/data/plugins/player-action/action.rb deleted file mode 100644 index 1752d659f..000000000 --- a/game/data/plugins/player-action/action.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.message.impl.SetPlayerActionMessage' -java_import 'org.apollo.game.model.entity.Player' - -# A right-click action for a Player. -class PlayerAction - attr_reader :slot, :primary, :name - - def initialize(slot, primary, name) - index = [:first, :second, :third, :fourth, :fifth].find_index(slot) - fail "Unsupported action slot #{slot}." if index.nil? - - @slot = index - @primary = primary - @name = name - end - -end - -ATTACK_ACTION = PlayerAction.new(:second, true, 'Attack') -CHALLENGE_ACTION = PlayerAction.new(:second, true, 'Challenge') -FOLLOW_ACTION = PlayerAction.new(:fourth, true, 'Follow') -TRADE_ACTION = PlayerAction.new(:fifth, true, 'Trade with') - -# Shows multiple context menu action for the specified player -def show_actions(player, *actions) - fail 'Must specify at least one action.' if actions.nil? - - actions.each do |action| - player.add_action(action) - player.send(SetPlayerActionMessage.new(action.name, action.slot, action.primary)) - end -end - -# Shows a single context menu action for the specified player -def show_action(player, action) - show_actions(player, action) -end - -# Hides a context menu action for the specified player -def hide_action(player, action) - player.send(SetPlayerActionMessage.new('null', action.slot, action.primary)) -end - -# Monkey-patch Player to provide action utility methods. -class Player - - def actions - @actions ||= {} - end - - def add_action(action) - actions[action.slot] = action.name - end - - def action?(action) - actions[action.slot] == action.name - end - -end diff --git a/game/data/plugins/player-action/login.rb b/game/data/plugins/player-action/login.rb deleted file mode 100644 index b2aaf85d1..000000000 --- a/game/data/plugins/player-action/login.rb +++ /dev/null @@ -1,6 +0,0 @@ -java_import 'org.apollo.game.model.entity.Player' - -on :login do |_event, player| - show_action(player, TRADE_ACTION) - show_action(player, FOLLOW_ACTION) -end diff --git a/game/data/plugins/player-action/plugin.xml b/game/data/plugins/player-action/plugin.xml deleted file mode 100644 index 48263a9f3..000000000 --- a/game/data/plugins/player-action/plugin.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - player-action - 1 - Player actions - Manages player right click actions - - Ryley - - - - - - - diff --git a/game/data/plugins/quest/plugin.xml b/game/data/plugins/quest/plugin.xml deleted file mode 100644 index b92ef5b3c..000000000 --- a/game/data/plugins/quest/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - quest - 0.9 - Quest - Adds - - Major - - - - - - attributes - - \ No newline at end of file diff --git a/game/data/plugins/quest/repository.rb b/game/data/plugins/quest/repository.rb deleted file mode 100644 index 21375570d..000000000 --- a/game/data/plugins/quest/repository.rb +++ /dev/null @@ -1,132 +0,0 @@ - -# Defines a quest with the specified name. -def quest(name, stage_names) - stages = {} - stage_names.each_with_index { |stage, index| stages[stage] = QuestStage.new(stage, index, name) } - - QUESTS[name] = Quest.new(name, stages) -end - -private - -# The repository of quests. -QUESTS = {} - -# An ingame Quest. -class Quest - attr_reader :name - - # Creates the Quest. - def initialize(name, stages) - fail "Quest name must be a symbol, received '#{name}'." unless name.is_a?(Symbol) - @name = name - @stages = stages - end - - # Gets the finishing quest stage (i.e. the stage that indicates the Player has completed the - # quest). - def final_stage - @stages.last - end - - # Gets the starting quest stage. - def initial_stage - @stages.first - end - - # Gets the QuestStage with the specified name. - def stage(name) - stage = @stages[name] - fail "No stage named #{name} exists in #{@name}." if stage.nil? - stage - end - -end - -# A stage in a quest, indicating the progress of a Player. -class QuestStage - attr_reader :name, :index - - # Creates the QuestProgress. - def initialize(name, index, quest, log_text = nil) - @name = name - @index = index - @quest = quest - @log_text = log_text - end - - # Returns whether or no this quest stage should be logged. - def logged - !@log_text.nil? - end - - # Gets the log text for this stage. - def log_text - fail 'Cannot get the log text from an unlogged quest stage.' unless logged - @log_text - end - - # Defines the equality operator. - def ==(other) - @index == index_of(other) - end - - # Defines the not equal operator. - def !=(other) - @index != index_of(other) - end - - # Defines the greater than or equal to operator. - def >=(other) - @index >= index_of(other) - end - - # Defines the greater than operator. - def >(other) - @index > index_of(other) - end - - # Defines the less than operator. - def <(other) - @index < index_of(other) - end - - # Defines the less than or equal to operator. - def <=(other) - @index <= index_of(other) - end - - private - - # Gets the index of the QuestStage with the specified name. - def index_of(name) - QUESTS[@quest].stage(name).index - end - -end - -# Define method_missing for player -class Player - - # Override method_missing to return a QuestStage if the method name indicates quest. - def method_missing(symbol, *args) - unless args.nil? - arg = args[0] - args[0] = arg.name if arg.is_a?(QuestStage) - end - - result = super(symbol, *args) - string = symbol.to_s - - if string.end_with?('_progress') - name = string[0..-10] # Cut the '_progress' from the end - quest = QUESTS[name.to_sym] - fail "No Quest with the name '#{name}' exists." if quest.nil? - - result = quest.stage(result) - end - - result - end - -end diff --git a/game/data/plugins/run/plugin.xml b/game/data/plugins/run/plugin.xml deleted file mode 100644 index 6594f2bbf..000000000 --- a/game/data/plugins/run/plugin.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - run - 1 - Running - Adds support for running via the options interface. - - Major - - - - - - attributes - - \ No newline at end of file diff --git a/game/data/plugins/run/run.rb b/game/data/plugins/run/run.rb deleted file mode 100644 index 8b1063518..000000000 --- a/game/data/plugins/run/run.rb +++ /dev/null @@ -1,10 +0,0 @@ -WALK_BUTTON_ID = 152 -RUN_BUTTON_ID = 153 - -on :button, WALK_BUTTON_ID do |player| - player.toggle_running -end - -on :button, RUN_BUTTON_ID do |player| - player.toggle_running -end diff --git a/game/data/plugins/shops/currency.rb b/game/data/plugins/shops/currency.rb deleted file mode 100644 index b0c9a5fc4..000000000 --- a/game/data/plugins/shops/currency.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'java' - -java_import 'org.apollo.cache.def.ItemDefinition' - -# A currency that can be used to purchase items in a Shop. -class Currency - attr_reader :name - - # Creates the Currency. - def initialize(id, name = ItemDefinition.lookup(id).name) - fail 'Currency must have a name.' if name.nil? - @id = id - @name = name.to_s - end - - # Adds the specified amount of this `Currency` to the specified `Player`'s inventory. - def add(player, amount) - player.inventory.add(@id, amount) - end - - # Removes the specified amount of this `Currency` from the specified `Player`'s inventory. - def remove(player, amount) - player.inventory.remove(@id, amount) - end - - # Gets the amount of this Currency in the specified player's inventory. - def total(player) - player.inventory.get_amount(@id) - end - - def sell_value(id) - (ItemDefinition.lookup(id).value * 0.60).floor - end - -end diff --git a/game/data/plugins/shops/plugin.xml b/game/data/plugins/shops/plugin.xml deleted file mode 100644 index e8d682317..000000000 --- a/game/data/plugins/shops/plugin.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - shops - 0.1 - Shops - Adds shop support. - - Stuart - Major - - - - - - - - - util - - diff --git a/game/data/plugins/shops/shop.rb b/game/data/plugins/shops/shop.rb deleted file mode 100644 index d455d27df..000000000 --- a/game/data/plugins/shops/shop.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.inv.Inventory' - -# A shop containing items that can be sold. -class Shop - attr_reader :buys, :currency, :items, :inventory, :name, :npc_options - - def initialize(name, items, currency, options, buys) - @name = name - @items = items - @currency = currency - @buys = buys - @npc_options = options - @inventory = Inventory.new(DEFAULT_CAPACITY, Inventory::StackMode::STACK_ALWAYS) - - items.each { |item| @inventory.add(item.id, item.amount) } - end - -end - -private - -# The `Currency` used by default. -DEFAULT_CURRENCY = Currency.new(995, 'coins') - -# The default capacity of a shop. -DEFAULT_CAPACITY = 30 diff --git a/game/data/plugins/shops/shop_item.rb b/game/data/plugins/shops/shop_item.rb deleted file mode 100644 index a761702ce..000000000 --- a/game/data/plugins/shops/shop_item.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'java' - -java_import 'org.apollo.cache.def.ItemDefinition' - -java_import 'org.apollo.game.model.Item' - -# An Item in a Shop. -class ShopItem - attr_reader :amount, :cost, :id, :name - - # Creates the ShopItem. - def initialize(id, amount, cost = nil) - definition = ItemDefinition.lookup(id) - @id = id - @amount = amount - @cost = cost.nil? ? definition.value : cost - @name = definition.name - end - -end diff --git a/game/data/plugins/shops/shops.rb b/game/data/plugins/shops/shops.rb deleted file mode 100644 index 3229ed660..000000000 --- a/game/data/plugins/shops/shops.rb +++ /dev/null @@ -1,301 +0,0 @@ -require 'java' - -java_import 'org.apollo.cache.def.ItemDefinition' - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' -java_import 'org.apollo.game.message.handler.ItemVerificationHandler' -java_import 'org.apollo.game.model.inv.SynchronizationInventoryListener' -java_import 'org.apollo.game.model.inter.InterfaceListener' - -# The hash of npc ids to Shops. -SHOPS = {} - -# Creates the Shop from the specified Hash. -def create_shop(hash) - unless hash.has_keys?(:items, :name, :npcs) - fail 'Shop name, npcs, and items must be specified to create a shop.' - end - - npcs, name = hash[:npcs], hash[:name] - npcs = [npcs] unless npcs.is_a?(Array) - currency = hash[:currency] || DEFAULT_CURRENCY - - options = hash[:npc_options] || [1] - buys = hash[:buys] || :own - - items = hash.delete(:items).collect { |data| ShopItem.new(lookup_item(data[0]), data[1]) } - shop = Shop.new(name, items, currency, options, buys) - - npcs.map { |name| lookup_npc(name) }.each { |npc| SHOPS[npc] = shop } -end - -private - -# The sidebar id for the inventory, when a Shop window is open. -INVENTORY_SIDEBAR = 3822 - -# The container id for the above inventory, when a Shop window is open. -INVENTORY_CONTAINER = 3823 - -# The Shop interface id. -SHOP_INTERFACE = 3824 - -# The container id for the Shop interface. -SHOP_CONTAINER = 3900 - -# The widget that displays the shop name. -SHOP_NAME_WIDGET = 3901 - -# The delay before a Shop is opened when the Player is in range of the Npc, in ticks. -SHOP_OPEN_DELAY = 0 - -# The distance, in tiles, the Player must reach before a Shop can be opened. -SHOP_DISTANCE = 1 - -# An `InventorySupplier` for a `Shop`. -class ShopInventorySupplier - java_implements ItemVerificationHandler::InventorySupplier - - def getInventory(player) - shop = player.open_shop - shop == -1 ? nil : SHOPS[shop].inventory - end - -end - -# An `InventorySupplier` for a `Player` with the shop window open. -class PlayerInventorySupplier - java_implements ItemVerificationHandler::InventorySupplier - - def getInventory(player) - player.open_shop == -1 ? nil : player.inventory - end - -end - -ItemVerificationHandler.add_inventory(SHOP_CONTAINER, ShopInventorySupplier.new) -ItemVerificationHandler.add_inventory(INVENTORY_CONTAINER, PlayerInventorySupplier.new) - -# A DistancedAction causing a Player to open a shop. -class OpenShopAction < DistancedAction - attr_reader :player, :npc, :shop - - # Creates the OpenShopAction. - def initialize(player, npc, shop) - super(SHOP_OPEN_DELAY, true, player, npc.position, 1) - @npc = npc - @shop = shop - end - - # Executes this DistancedAction, opening the shop. - def executeAction - mob.interacting_mob = @npc - open_shop(mob, @npc.id) - stop - end - - # Returns whether or not this DistancedAction is equal to the specified Object. - def equals(other) - get_class == other.get_class && @npc == other.npc && @shop == other.shop - end - -end - -# An InterfaceListener for when a Shop is closed. -class ShopCloseInterfaceListener - java_implements InterfaceListener - - # Creates the ShopCloseInterfaceListener. - def initialize(player, inventory_listener, shop_listener) - @player = player - @inventory_listener = inventory_listener - @shop_listener = shop_listener - end - - # Executed when the Shop interface is closed. - def interface_closed - @player.inventory.remove_listener(@inventory_listener) - SHOPS[@player.open_shop].inventory.remove_listener(@shop_listener) - - @player.open_shop = -1 - @player.reset_interacting_mob - end - -end - -# Intercept the npc action message. -on :message, :first_npc_action do |player, message| - npc = $world.npc_repository.get(message.index) - - if SHOPS.key?(npc.id) - shop = SHOPS[npc.id] - - valid = shop.npc_options.empty? || shop.npc_options.include?(message.option) - player.start_action(OpenShopAction.new(player, npc, SHOPS[npc.id])) if valid - end -end - -# Opens the Shop registered to the specified npc. -def open_shop(player, npc) - shop = SHOPS[npc] - fail "No shop registered to npc #{npc} exists." if shop.nil? - - player.open_shop = npc - - inventory_listener = SynchronizationInventoryListener.new(player, INVENTORY_CONTAINER) - shop_listener = SynchronizationInventoryListener.new(player, SHOP_CONTAINER) - - player_inventory, shop_inventory = player.inventory, shop.inventory - - player_inventory.add_listener(inventory_listener) - player_inventory.force_refresh - - shop_inventory.add_listener(shop_listener) - shop_inventory.force_refresh - - player.send(SetWidgetTextMessage.new(SHOP_NAME_WIDGET, shop.name)) - - listener = ShopCloseInterfaceListener.new(player, inventory_listener, shop_listener) - player.interface_set.open_window_with_sidebar(listener, SHOP_INTERFACE, INVENTORY_SIDEBAR) -end - -# Intercept the Item action. -on :message, :item_action do |player, message| - interface = message.interface_id - - if player.open_shop == -1 || !SHOPS.key?(player.open_shop) - message.terminate - next - end - - if interface != INVENTORY_CONTAINER && interface != SHOP_CONTAINER - message.terminate - next - end - - shop = SHOPS[player.open_shop] - inventory = shop.inventory - currency = shop.currency - slot = message.slot - - player_inventory = player.inventory - - if interface == INVENTORY_CONTAINER - id = message.id - contains = inventory.contains(id) - - if !shop.buys == :none || shop.buys == :own && !contains - player.send_message('You can\'t sell this item to this shop.') - message.terminate - next - end - - if !contains && inventory.free_slots == 0 - player.send_message('The shop is currently full at the moment.') - message.terminate - next - end - - item = player_inventory.get(slot) - value = currency.sell_value(id) - - option = message.option - if option == 1 - player.send_message("#{item.definition.name}: shop will buy for #{value} #{currency.name}.") - next - end - - sell_amount = case option - when 2 then 1 - when 3 then 5 - when 4 then 10 - else next - end - - available = player_inventory.get_amount(id) - sell_amount = available if sell_amount > available - - total_value = (value * sell_amount).floor - - player_inventory.remove(id, sell_amount) - inventory.add(id, sell_amount) - currency.add(player, total_value) if total_value > 0 - - message.terminate - elsif interface == SHOP_CONTAINER - buy(shop, player, message, currency) - end -end - -# Buys the item from the `Shop`. -def buy(shop, player, message, currency) - inventory, slot = shop.inventory, message.slot - shop_item, invent_item = shop.items[slot], inventory.get(slot) - - id = shop_item.id - - option = message.option - if option == 1 - player.send_message("#{shop_item.name}: currently costs #{shop_item.cost} #{currency.name}.") - return - end - - buy_amount = case option - when 2 then 1 - when 3 then 5 - when 4 then 10 - else next - end - - no_stock = false - if buy_amount > invent_item.amount - buy_amount = invent_item.amount - no_stock = true - end - - player_inventory = player.inventory - has_item = player_inventory.get_amount(id) == 0 - - definition = invent_item.definition - space_required = if definition.stackable && has_item then 0 - elsif !definition.stackable then buy_amount - else 1 - end - - free_slots = player_inventory.free_slots - not_enough_space = false - - if space_required > free_slots - not_enough_space = true - buy_amount = free_slots - end - - total_currency = shop.currency.total(player) - too_poor = false - total_cost = buy_amount * shop_item.cost - - if total_cost > total_currency - buy_amount = (total_currency / shop_item.cost).floor - too_poor = true - end - - if buy_amount > 0 - currency.remove(player, buy_amount * shop_item.cost) - player_inventory.add(id, buy_amount) - - keep = invent_item.amount == buy_amount && shop.buys == :own - keep ? inventory.set(slot, Item.new(id, 0)) : inventory.remove(id, buy_amount) - end - - warning = if too_poor then "You don't have enough #{currency.name}." - elsif no_stock then 'The shop has run out of stock.' - elsif not_enough_space then 'You don\'t have enough inventory space.' - end - - player.send_message(warning) unless warning.nil? - message.terminate -end - -# Declares the open_shop attribute, which contains the id of the currently open shop. -declare_attribute(:open_shop, -1) diff --git a/game/data/plugins/skill/fishing/fish.rb b/game/data/plugins/skill/fishing/fish.rb deleted file mode 100644 index 0abd571c1..000000000 --- a/game/data/plugins/skill/fishing/fish.rb +++ /dev/null @@ -1,41 +0,0 @@ - -# The hash of names to fish. -CATCHABLE_FISH = {} - -# A fish that can be caught. -class Fish - attr_reader :id, :level, :experience, :name - - # Creates the Fish. - def initialize(id, level, experience) - @id = id - @level = level - @experience = experience - @name = name_of(:item, id) - end - -end - -# Appends a Fish to the hash. -def append_fish(name, hash) - unless hash.has_keys?(:id, :level, :experience) - fail 'Hash must contain an id, level, and experience.' - end - - CATCHABLE_FISH[name] = Fish.new(hash[:id], hash[:level], hash[:experience]) -end - -append_fish :shrimp, id: 317, level: 1, experience: 10 -append_fish :sardine, id: 327, level: 5, experience: 20 -append_fish :herring, id: 345, level: 10, experience: 30 -append_fish :anchovy, id: 321, level: 15, experience: 40 -append_fish :mackerel, id: 353, level: 16, experience: 20 -append_fish :trout, id: 335, level: 20, experience: 50 -append_fish :cod, id: 341, level: 23, experience: 45 -append_fish :pike, id: 349, level: 25, experience: 60 -append_fish :salmon, id: 331, level: 30, experience: 70 -append_fish :tuna, id: 359, level: 35, experience: 80 -append_fish :lobster, id: 377, level: 40, experience: 90 -append_fish :bass, id: 363, level: 46, experience: 100 -append_fish :swordfish, id: 371, level: 50, experience: 100 -append_fish :shark, id: 383, level: 76, experience: 110 diff --git a/game/data/plugins/skill/fishing/fishing.rb b/game/data/plugins/skill/fishing/fishing.rb deleted file mode 100644 index 244a88000..000000000 --- a/game/data/plugins/skill/fishing/fishing.rb +++ /dev/null @@ -1,120 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.entity.Skill' - -# An action that causes a mob to fish at a spot. -class FishingAction < DistancedAction - attr_reader :position, :options, :spot, :started, :tool - - # Creates the FishingAction. - def initialize(mob, position, spot, option) - super(4, true, mob, position, 1) - @position = position - @spot = spot - @tool = spot.tools[option - 1] - - @options = (option == 1) ? spot.first_fish : spot.second_fish - @minimum_level = @options.map(&:level).min - end - - # Returns whether or not a catch is successful. - def successful_catch(level, requirement) - [level - requirement + 5, 30].min > rand(40) - end - - # Starts the fishing process. - def start_fishing - @started = true - mob.send_message(tool.message) - end - - # Executes the action. - def executeAction - skills = mob.skill_set - fishing_level = skills.get_skill(Skill::FISHING).current_level - mob.turn_to(position) - - if @minimum_level > fishing_level - mob.send_message("You need a fishing level of #{@minimum_level} to fish at this spot.") - stop - return - end - - inventory = mob.inventory - if inventory.free_slots.zero? - inventory.force_capacity_exceeded - stop - return - end - - unless inventory.contains(@tool.id) - mob.send_message("You need a #{@tool.name.downcase} to fish at this spot.") - stop - return - end - - bait = find_bait - if bait == -1 - mob.send_message("You need #{name_of(:item, bait).downcase}s to fish at this spot.") - stop - return - end - - if @started - options = @options.reject { |fish| fish.level > fishing_level } - # Player may level up mid-action so reject here, not at initialisation. - fish = options.sample # TODO: it's a ~70/30 chance, not 50/50 - - if successful_catch(fishing_level, fish.level) - inventory.remove(bait) unless bait.nil? - inventory.add(fish.id) - - name = fish.name - mob.send_message("You catch #{name.end_with?('s') ? 'some' : 'a'} #{name.downcase}.") - skills.add_experience(Skill::FISHING, fish.experience) - - if find_bait == -1 - mob.send_message("You need more #{name_of(:item, bait).downcase}s to fish at this spot.") - stop - return - end - end - else - start_fishing - end - - mob.play_animation(@tool.animation) - end - - # Finds the id of the first piece of bait in the player's inventory, or nil if no bait is - # required, or -1 if the player's inventory does not contain any valid bait. - def find_bait - baits = @tool.bait - baits.empty? ? nil : baits.find(-1) { |bait| mob.inventory.contains(bait) } - end - - # Stops this action. - def stop - super - mob.stop_animation - end - - def equals(other) - get_class == other.get_class && @spot == other.spot && @position == other.position && - @options == @other.options - end - -end - -# Intercepts the NpcAction message to determine whether or not a clicked npc was a fishing spot. -on :message, :npc_action do |player, message| - npc = $world.npc_repository.get(message.index) - spot = FISHING_SPOTS[npc.id] - - unless spot.nil? - player.start_action(FishingAction.new(player, npc.position, spot, message.option)) - message.terminate - end -end diff --git a/game/data/plugins/skill/fishing/plugin.xml b/game/data/plugins/skill/fishing/plugin.xml deleted file mode 100644 index 64f84d785..000000000 --- a/game/data/plugins/skill/fishing/plugin.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - skill-fishing - 1 - Fishing - Adds the fishing skill. - - Linux - Major - - - - - - - - - util - - \ No newline at end of file diff --git a/game/data/plugins/skill/fishing/spot.rb b/game/data/plugins/skill/fishing/spot.rb deleted file mode 100644 index c1875ab1e..000000000 --- a/game/data/plugins/skill/fishing/spot.rb +++ /dev/null @@ -1,26 +0,0 @@ - -# The hash of fishing spots. -FISHING_SPOTS = {} - -# A Fishing spot. -class Spot - attr_reader :tools, :first_fish, :second_fish - - # Creates the fishing spot. - def initialize(tools, first_fish, second_fish) - @tools = tools.map { |id| FISHING_TOOLS[id] } - @first_fish = first_fish.map { |fish| CATCHABLE_FISH[fish] } - @second_fish = second_fish.map { |fish| CATCHABLE_FISH[fish] } - end - -end - -# Appends a fishing spot to the hash. -def append_spot(id, spot) - FISHING_SPOTS[id] = spot -end - -append_spot(309, Spot.new([:fly_fishing_rod, :fishing_rod], [:trout, :salmon], [:pike])) -append_spot(312, Spot.new([:lobster_cage, :harpoon], [:lobster], [:tuna, :swordfish])) -append_spot(313, Spot.new([:big_net, :harpoon], [:mackerel, :cod], [:bass, :shark])) -append_spot(316, Spot.new([:small_net, :fishing_rod], [:shrimp, :anchovy], [:sardine, :herring])) diff --git a/game/data/plugins/skill/fishing/tool.rb b/game/data/plugins/skill/fishing/tool.rb deleted file mode 100644 index f6ff6144b..000000000 --- a/game/data/plugins/skill/fishing/tool.rb +++ /dev/null @@ -1,60 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' - -# The hash of fishing tool names to Tools. -FISHING_TOOLS = {} - -# A fishing tool. -class Tool - attr_reader :animation, :bait, :id, :message, :name - - # Creates the tool. - def initialize(id, animation, message, bait) - @id = id - @bait = bait - @animation = Animation.new(animation) - @message = message - - @name = name_of(:item, id) - end - -end - -private - -# Appends a tool with the specified name to the hash. -def tool(name, hash) - unless hash.has_keys?(:id, :animation, :message) - fail 'Hash must contain an id, animation, and message.' - end - - bait = hash[:bait] || [] - FISHING_TOOLS[name] = Tool.new(hash[:id], hash[:animation], hash[:message], bait) -end - -# The harpoon fishing animation id. -HARPOON_ANIMATION = 618 - -# The cage fishing animation id. -CAGE_ANIMATION = 619 - -# The net fishing animation id. -NET_ANIMATION = 620 - -# The rod fishing animation id. -ROD_ANIMATION = 622 - -# TODO: The other feathers that can be used -FISHING_ROD_BAIT = [313] -FLY_FISHING_ROD_BAIT = [314] - -tool :lobster_cage, id: 301, animation: CAGE_ANIMATION, message: 'You attempt to catch a lobster...' -tool :small_net, id: 303, animation: NET_ANIMATION, message: 'You cast out your net...' -tool :big_net, id: 305, animation: NET_ANIMATION, message: 'You cast out your net...' -tool :harpoon, id: 311, animation: HARPOON_ANIMATION, message: 'You start harpooning fish...' - -tool :fishing_rod, id: 307, animation: ROD_ANIMATION, message: 'You attempt to catch a fish...', - bait: FISHING_ROD_BAIT -tool :fly_fishing_rod, id: 309, animation: ROD_ANIMATION, message: 'You attempt to catch a fish...', - bait: FLY_FISHING_ROD_BAIT diff --git a/game/data/plugins/skill/herblore/herb.rb b/game/data/plugins/skill/herblore/herb.rb deleted file mode 100644 index 30a10bf4b..000000000 --- a/game/data/plugins/skill/herblore/herb.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.Action' -java_import 'org.apollo.util.LanguageUtil' - -# A herb is an ingredient that requires identification before being used. -class Herb < Ingredient - include HerbloreMethod - - attr_reader :unidentified, :level, :experience - - def initialize(item_id, unidentified, level, experience) - super item_id - - @unidentified = unidentified - @level = level - @experience = experience - end - - def invoke(player, _id, slot) - item = player.inventory.get(slot) - player.start_action(HerbIdentificationAction.new(player, self, slot, item)) - end -end - -# An action that makes a player identify a herb. -class HerbIdentificationAction < Action - attr_reader :herb, :slot, :item, :pulses - - def initialize(player, herb, slot, item) - super(0, true, player) - - @herb = herb - @slot = slot - @item = item - @pulses = 0 - end - - def execute - if @pulses == 0 - unless check_skill(mob, @herb.level, 'identify this herb') - stop - return - end - end - - execute_action - @pulses += 1 - end - - def execute_action - player = mob - inventory = player.inventory - - if inventory.remove_slot(@slot, 1) == 1 - identified = @herb.item - - inventory.add(identified) - - article = LanguageUtil.getIndefiniteArticle(identified.definition.name) - player.skill_set.add_experience(Skill::HERBLORE, @herb.experience) - player.send_message("This herb is #{article} #{identified.definition.name}.") - end - - stop - end - - def equals(other) - get_class == other.get_class && slot == other.slot && herb == other.herb - end -end - -# Appends a herb to the InventoryItemMessage interception. -def append_herb(item_id, unidentified, level, experience) - herb = Herb.new(item_id, unidentified, level, experience) - append_herblore_item(herb, unidentified) - herb -end - -# Herbs - -GUAM_LEAF = append_herb(249, 199, 1, 2.5) -MARRENTILL = append_herb(251, 201, 5, 3.8) -TARROMIN = append_herb(253, 203, 11, 5) -HARRALANDER = append_herb(255, 205, 20, 6.3) -RANARR = append_herb(257, 207, 25, 7.5) -TOADFLAX = append_herb(2998, 3049, 30, 8) -IRIT_LEAF = append_herb(259, 209, 40, 8.8) -AVANTOE = append_herb(261, 211, 48, 10) -KWUARM = append_herb(263, 213, 54, 11.3) -SNAPDRAGON = append_herb(3000, 3051, 59, 11.8) -CADANTINE = append_herb(265, 215, 65, 12.5) -LANTADYME = append_herb(2481, 2485, 67, 13.1) -DWARF_WEED = append_herb(267, 217, 70, 13.8) -TORSTOL = append_herb(269, 219, 75, 15) diff --git a/game/data/plugins/skill/herblore/herblore.rb b/game/data/plugins/skill/herblore/herblore.rb deleted file mode 100644 index 8ce822da3..000000000 --- a/game/data/plugins/skill/herblore/herblore.rb +++ /dev/null @@ -1,102 +0,0 @@ -# Thanks to Sillhouette for posting -# a large amount of Herblore skill data which has been thankfully used in this plugin. - -require 'java' - -java_import 'org.apollo.game.message.impl.SetWidgetItemModelMessage' -java_import 'org.apollo.game.model.entity.Skill' - -HERBLORE_DIALOGUE = 4429 - -HERBLORE_ITEM = {} -HERBLORE_ITEM_ON_ITEM = {} - -DRINK_ITEM = {} - -# A module which describes an invocable method of the Herblore skill. -module HerbloreMethod - def self.new - fail 'You cannot instantiate this module!' - end - - def invoke(_player, _primary, _secondary) - fail 'You must implement the invocation of HerbloreMethod!' - end -end - -# The ItemOnItemMessage listener for all Herblore-related functions. -on :message, :item_on_item do |player, message| - primary = message.id - secondary = message.target_id - hash = HERBLORE_ITEM_ON_ITEM[primary] - - if hash.nil? - secondary = message.id - primary = message.target_id - hash = HERBLORE_ITEM_ON_ITEM[primary] - end - - unless hash.nil? - method = hash[secondary] - unless method.nil? - method.invoke(player, primary, secondary) - message.terminate - end - end -end - -# The ItemOptionMessage listener for all Herblore-related functions. -on :message, :first_item_option do |player, message| - id = message.id - method = HERBLORE_ITEM[id] - - unless method.nil? - method.invoke(player, id, message.slot) - message.terminate - end - method = DRINK_ITEM[id] - - unless method.nil? - method.invoke(player, id, message.slot) - message.terminate - end -end - -# Utility for adding the various Herblore methods to the handled constant arrays. -def append_herblore_item(method, key, secondary = -1) - if secondary == -1 - HERBLORE_ITEM[key] = method - else - hash = HERBLORE_ITEM_ON_ITEM[key] - hash = {} if hash.nil? - - hash[secondary] = method - HERBLORE_ITEM_ON_ITEM[key] = hash - end -end - -# Utility method for checking if a player's inventory has a of the specified id, with optionally -# the specified amount (1 by default), at the specified slot. -def check_slot(player, slot, id, amount = 1) - item = player.inventory.get(slot) - !item.nil? && item.id == id && item.amount >= amount -end - -# Utility method for checking if a player's Herblore (maximum) level is at the required level. Also -# informs the player if this is not the case with use of the action variable, like so: -# "You need a Herblore level of at least #{required.to_s} to #{action}." -def check_skill(player, required, action) - if required > player.skill_set.get_skill(Skill::HERBLORE).current_level - player.send_message("You need a Herblore level of at least #{required} to #{action}.") - return false - end - - true -end - -# Opens a 'make' dialogue for the specified player, displaying the specified item. Optionally, a -# listener can be used for the dialogue. -def open_dialogue(player, item, listener = nil) - player.send(SetWidgetItemModelMessage.new(1746, item, 170)) - player.interface_set.open_dialogue(listener, HERBLORE_DIALOGUE) -end diff --git a/game/data/plugins/skill/herblore/ingredient.rb b/game/data/plugins/skill/herblore/ingredient.rb deleted file mode 100644 index f01bfef8f..000000000 --- a/game/data/plugins/skill/herblore/ingredient.rb +++ /dev/null @@ -1,251 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.Action' -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Item' -java_import 'org.apollo.game.model.inter.EnterAmountListener' -java_import 'org.apollo.game.model.inter.dialogue.DialogueAdapter' - -GRINDING_ANIM = Animation.new(364) -PESTLE_MORTAR = 233 - -# An ingredient which can be used for making (unfinished) potions. -class Ingredient - attr_reader :item_id, :item - - def initialize(item) - @item_id = item - @item = Item.new(item) # Share item instances. - end - - # Checks if the specified player has the specified amount of this ingredient. Optionally, they - # can immediately be removed if that amount was indeed found. - def check_remove(player, amount, remove) - inventory = player.inventory - counter = 0 - - inventory.items.each do |inv_item| - break unless counter < amount - next if inv_item.nil? - - id = inv_item.id - inventory_amount = inv_item.amount - - if id == @item_id - if inventory_amount >= amount - inventory.remove(@item_id, amount) if remove - return true - else - counter += inventory_amount - end - end - end - - if counter >= amount - inventory.remove(@item_id, amount) if remove - return true - end - - false - end -end - -# An ingredient which needs to be grinded before being usable for Herblore. -class GroundIngredient < Ingredient - include HerbloreMethod - - attr_reader :raw - - def initialize(item_id, raw) - super(item_id) - @raw = raw - end - - def invoke(player, _pestle_mortar, _ingredient) - action = GrindingAction.new(player, self) - listener = GrindingDialogueListener.new(player, action) - - open_dialogue(player, @item_id, listener) - end -end - -# A DialogueAdapter used for grinding ingredients. It is also used as an EnterAmountListener for -# the amount of grinding actions. -class GrindingDialogueListener < DialogueAdapter - include EnterAmountListener - - attr_reader :player, :action - - def initialize(player, action) - super() - @player = player - @action = action - end - - # Called when a button has been clicked whilst the dialogue was opened. - def buttonClicked(button) - amount = get_amount(button) - return false if amount == 0 - - interfaces = @player.interface_set - interfaces.close - - if amount == -1 - interfaces.open_enter_amount_dialogue(self) - return true - end - - amount = player.inventory.get_amount(@action.ingredient.raw) if amount == -2 - execute(amount) - end - - # Called when an amount of grinding actions has been entered. - def amountEntered(amount) - execute(amount) if amount > 0 - end - - # Called to set the action(s) in motion. - def execute(amount) - @action.set_amount(amount) - @player.start_action(@action) - end - - # Gets the amount of actions based on the specified button id. - def get_amount(button) - case button - when 2799 then return 1 - when 2798 then return 5 - when 1748 then return -1 - when 1747 then return -2 - else return 0 - end - end -end - -# An action which makes the player grind one or more GrindedIngredients from their 'raw' form. -class GrindingAction < Action - attr_reader :ingredient, :amount, :pulses, :slot, :listener - - def initialize(player, ingredient) - super(0, true, player) - - @ingredient = ingredient - @pulses = 0 - end - - def execute - grind - @pulses += 1 - end - - # Performs the grinding action once the materials have been checked. - def grind - if @pulses == 0 - mob.play_animation GRINDING_ANIM - elsif @pulses == 1 - unless gather_materials - stop - return - end - - player = mob - inventory = player.inventory - item = inventory.get(@slot) - - name = item.definition.name.downcase - player.send_message("You grind the #{name} to dust.") - - inventory.reset(@slot) - inventory.add(@ingredient.item) - - set_delay(1) - elsif @pulses == 2 - mob.stop_animation - continue - end - end - - # Checks if the player has the required materials to perform the (next) action. - def gather_materials - items = mob.inventory.items - - pst_mrt = false - ingr = false - raw = @ingredient.raw - (0...items.length).each do |slot| - item = items[slot] - next if item.nil? - - id = item.id - if id == PESTLE_MORTAR && !pst_mrt - pst_mrt = true - elsif id == raw && !ingr - ingr = true - @slot = slot - end - - return true if pst_mrt && ingr - end - - mob.send_message("You do not have any more #{name_of(raw).downcase}s.") - false - end - - # Either invokes the stop() method in Action to shut it down - # or continues to the next ingredient. - def continue - @amount -= 1 - - if @amount > 0 - set_delay(0) - @pulses = -1 - else - stop - end - end - - # Sets the amount of actions. - def set_amount(amount) - @amount = amount - end - - def stop - super - mob.inventory.remove_listener(@listener) unless listener.nil? - end - - def equals(other) - get_class == other.get_class && @ingredient == other.ingredient - end -end - -# Appends a ground ingredient to the ItemOnItemMessage listener interception. -def append_ground(id, raw) - ground = GroundIngredient.new(id, raw) - append_herblore_item(ground, PESTLE_MORTAR, raw) - ground -end - -# Normal ingredients -EYE_NEWT = Ingredient.new(221) -RED_SPIDERS_EGGS = Ingredient.new(223) -LIMPWURT_ROOT = Ingredient.new(225) -SNAPE_GRASS = Ingredient.new(231) -WHITE_BERRIES = Ingredient.new(239) -WINE_ZAMORAK = Ingredient.new(245) -JANGERBERRIES = Ingredient.new(247) -TOADS_LEGS = Ingredient.new(2152) -MORT_MYRE_FUNGI = Ingredient.new(2970) -POTATO_CACTUS = Ingredient.new(3138) -PHOENIX_FEATHER = Ingredient.new(4621) -FROG_SPAWN = Ingredient.new(5004) -PAPAYA_FRUIT = Ingredient.new(5972) -POISON_IVY_BERRIES = Ingredient.new(6018) -YEW_ROOTS = Ingredient.new(6049) -MAGIC_ROOTS = Ingredient.new(6051) - -# Ground ingredients -UNICORN_HORN_DUST = append_ground(235, 237) -DRAGON_SCALE_DUST = append_ground(241, 243) -CHOCOLATE_DUST = append_ground(1975, 1973) -CRUSHED_NEST = append_ground(6693, 5075) diff --git a/game/data/plugins/skill/herblore/plugin.xml b/game/data/plugins/skill/herblore/plugin.xml deleted file mode 100644 index 748712be0..000000000 --- a/game/data/plugins/skill/herblore/plugin.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - skill-herblore - 0.9 - Herblore - Adds the Herblore skill. - - Chris Fletcher - Major - - - - - - - - - \ No newline at end of file diff --git a/game/data/plugins/skill/herblore/potion.rb b/game/data/plugins/skill/herblore/potion.rb deleted file mode 100644 index 706feafab..000000000 --- a/game/data/plugins/skill/herblore/potion.rb +++ /dev/null @@ -1,372 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.Action' -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Item' -java_import 'org.apollo.game.model.entity.Skill' -java_import 'org.apollo.game.model.inter.EnterAmountListener' -java_import 'org.apollo.game.model.inter.dialogue.DialogueAdapter' - -private - -WATER_VIAL_ID = 227 -EMPTY_VIAL_ID = 229 - -MIXING_ANIM = Animation.new(363) - -# Represents an unfinished potion which can be invoked as a HerbloreMethod and used as an -# ingredient. -class UnfinishedPotion < Ingredient - include HerbloreMethod - - attr_reader :herb, :level - - def initialize(item_id, herb, level) - super(item_id) - @herb = herb - @level = level - end - - def invoke(player, _primary, _secondary) - action = UnfinishedMixingAction.new(player, self) - listener = UnfinishedMixingDialogueListener.new(player, action) - - open_dialogue(player, @item_id, listener) - end - -end - -# Represents a finished potion which can be invoked as a HerbloreMethod. -class FinishedPotion - include HerbloreMethod - - attr_reader :item, :ingredients, :level, :experience - - def initialize(item, ingredients, level, experience) - @item = Item.new(item) - @ingredients = ingredients - @level = level - @experience = experience - end - - def invoke(player, primary, secondary) - action = FinishedMixingAction.new(player, primary, secondary, self) - listener = FinishedMixingDialogueListener.new(player, action) - - open_dialogue(player, @item.id, listener) - end -end - -# A DialogueAdapter used for mixing potions. It is also used as an EnterAmountListener for the -# amount of mixing actions. -class MixingDialogueListener < DialogueAdapter - include EnterAmountListener - - attr_reader :player, :action - - def initialize(player, action) - super() - - @player = player - @action = action - end - - # Called when a button has been clicked whilst the dialogue was opened. - def buttonClicked(button) - amount = get_amount(button) - - return false if amount == 0 - - interfaces = @player.interface_set - interfaces.close - - if amount == -1 - interfaces.open_enter_amount_dialogue(self) - return true - end - - amount = calculate_maximum if amount == -2 - - execute(amount) - true - end - - # Called when an amount of mixing actions has been entered. - def amountEntered(amount) - execute(amount) if amount > 0 - end - - # Called to set the action(s) in motion. - def execute(amount) - @action.set_amount(amount) - @player.start_action(@action) - end - - def calculate_maximum(_code) - # Override for potion-specific amount calculation. - end - - # Gets the amount of actions based on the specified button id. - def get_amount(button) - case button - when 2799 then return 1 - when 2798 then return 5 - when 1748 then return -1 - when 1747 then return -2 - else return 0 - end - end - -end - -# A MixingDialogueListener used for mixing unfinished potions. -class UnfinishedMixingDialogueListener < MixingDialogueListener - - def calculate_maximum - inventory = @player.inventory - - amount = inventory.get_amount(WATER_VIAL_ID) - return 0 if amount <= 0 - - herbs = inventory.get_amount(@action.potion.herb.item.id) - [herbs, amount].min - end - -end - -# A MixingDialogueListener used for mixing finished potions. -class FinishedMixingDialogueListener < MixingDialogueListener - - def calculate_maximum - inventory = @player.inventory - - amount = inventory.capacity - @action.potion.ingredients.each do |ingredient| - item_amount = inventory.get_amount(ingredient.item.id) - amount = item_amount if amount > item_amount - end - - amount - end - -end - -# An Action which handles the none-finished-dependent mixing. -class MixingAction < Action - attr_reader :potion, :amount, :started, :pulses, :action, :listener - - def initialize(player, potion, action) - super(1, true, player) - - @potion = potion - @started = false - @pulses = 0 - @action = action - @action.freeze - end - - def execute - if @pulses == 0 - unless @started - unless check_skill(mob, @potion.level, @action) - stop - return - end - - @started = true - end - - unless gather_materials - stop - return - end - end - - mob.play_animation(MIXING_ANIM) - execute_action - - @amount -= 1 - @amount > 0 ? @pulses = 0 : stop - end - - def stop - super() - mob.inventory.remove_listener(@listener) unless @listener.nil? - end - - def execute_action - # Override for action execution. - end - - def gather_materials - # Override for ingredient checking and gathering - false - end - - # Sets the amount of actions. - def set_amount(amount) - @amount = amount - end - - def equals(other) - get_class == other.get_class && @potion == other.potion - end -end - -# A MixingAction which handles the execution of making UnfinishedPotions. -class UnfinishedMixingAction < MixingAction - attr_reader :slots - - def initialize(player, potion) - super(player, potion, 'use this herb.') - end - - def execute_action - name = @potion.herb.item.definition.name - player = mob - inventory = player.inventory - - created = name.sub(/ leaf$/, '') - message = "You put the #{name} in the water to make an unfinished #{created} potion." - player.send_message(message) - - @slots.each do |slot, amount| - unless inventory.remove_slot(slot, amount) - stop - return - end - end - - inventory.add(@potion.item) - end - - def gather_materials - @slots = {} - inventory = mob.inventory - - vial_slot = inventory.slot_of(WATER_VIAL_ID) - if vial_slot == -1 - mob.send_message('You do not have any more vials of water.') - return false - end - - item = @potion.herb.item - herb_slot = inventory.slot_of(item.id) - if herb_slot == -1 - mob.send_message("You do not have any more #{item.definition.name}.") - return false - end - - @slots[vial_slot] = 1 - @slots[herb_slot] = 1 - - true - end - -end - -# A MixingAction which handles the execution of making FinishedPotions. -class FinishedMixingAction < MixingAction - attr_reader :unfinished, :ingredient, :slots - - def initialize(player, unfinished, ingredient, potion) - super(player, potion, 'mix this potion') - @unfinished = unfinished - @ingredient = ingredient - end - - def execute_action - ingredient = name_of(:item, @ingredient).downcase - name = @potion.item.definition.name.sub('(3)', '') - - name = "#{LanguageUtil.get_indefinite_article(name)} #{name}" - mob.send_message("You add the #{ingredient} to the mixture to make #{name}.") - mob.skill_set.add_experience(Skill::HERBLORE, @potion.experience) - - inventory = mob.inventory - - @slots.each do |slot, amount| - unless inventory.remove_slot(slot, amount) # TODO: will this remove stuff incorrectly? - stop - return - end - end - - inventory.add(@potion.item) - end - - def gather_materials - @slots = {} - inventory = mob.inventory - - vial_slot = inventory.slot_of(@unfinished) - if vial_slot == -1 - mob.send_message('You do not have enough unfinished potions.') - return false - end - - ingredient_slot = inventory.slot_of(@ingredient) - if ingredient_slot == -1 - mob.send_message('You do not have enough ingredients.') - return false - end - - @slots[vial_slot] = 1 - @slots[ingredient_slot] = 1 - - true - end - -end - -# Appends a finished potion to the ItemOnItemMessage handling interception. -def finished_potion(item, unfinished, ingredient, level, experience) - potion = FinishedPotion.new(item, [unfinished, ingredient], level, experience) - append_herblore_item(potion, unfinished.item_id, ingredient.item_id) - potion -end - -# Appends an unfinished potion to the ItemOnItemMessage handling interception. -def unfinished_potion(item, herb, level) - potion = UnfinishedPotion.new(item, herb, level) - append_herblore_item(potion, herb.item_id, WATER_VIAL_ID) - potion -end - -# Unfinished potions -UNF_GUAM = unfinished_potion(91, GUAM_LEAF, 1) # 3 -UNF_MARRENTILL = unfinished_potion(93, MARRENTILL, 5) -UNF_TARROMIN = unfinished_potion(95, TARROMIN, 12) -UNF_HARRALANDER = unfinished_potion(97, HARRALANDER, 22) -UNF_RANARR = unfinished_potion(99, RANARR, 30) -UNF_TOADFLAX = unfinished_potion(3002, TOADFLAX, 34) -UNF_IRIT = unfinished_potion(101, IRIT_LEAF, 45) -UNF_AVANTOE = unfinished_potion(103, AVANTOE, 50) -UNF_KWUARM = unfinished_potion(105, KWUARM, 55) -UNF_SNAPDRAGON = unfinished_potion(3004, SNAPDRAGON, 63) -UNF_CADANTINE = unfinished_potion(107, CADANTINE, 66) -UNF_LANTADYME = unfinished_potion(2483, LANTADYME, 69) -UNF_DWARF_WEED = unfinished_potion(109, DWARF_WEED, 72) -UNF_TORSTOL = unfinished_potion(111, TORSTOL, 78) - -# Finished potions -ATTACK_POT = finished_potion(121, UNF_GUAM, EYE_NEWT, 1, 25) # 3 -ANTIPOISON_POT = finished_potion(175, UNF_MARRENTILL, UNICORN_HORN_DUST, 5, 37.5) -STRENGTH_POT = finished_potion(115, UNF_TARROMIN, LIMPWURT_ROOT, 12, 50) -RESTORE_POT = finished_potion(127, UNF_HARRALANDER, RED_SPIDERS_EGGS, 18, 62.5) -ENERGY_POT = finished_potion(3010, UNF_HARRALANDER, CHOCOLATE_DUST, 26, 67.5) -DEFENCE_POT = finished_potion(133, UNF_RANARR, WHITE_BERRIES, 30, 75) -AGILITY_POT = finished_potion(3034, UNF_TOADFLAX, TOADS_LEGS, 34, 80) -PRAYER_POT = finished_potion(139, UNF_RANARR, SNAPE_GRASS, 38, 87.5) -SUPER_ATTACK_POT = finished_potion(145, UNF_IRIT, EYE_NEWT, 45, 100) -SUPER_ANTIPOISON_POT = finished_potion(181, UNF_IRIT, UNICORN_HORN_DUST, 48, 106.3) -FISHING_POT = finished_potion(151, UNF_AVANTOE, SNAPE_GRASS, 50, 112.5) -SUPER_ENERGY_POT = finished_potion(3018, UNF_AVANTOE, MORT_MYRE_FUNGI, 52, 117.5) -SUPER_STRENGTH_POT = finished_potion(157, UNF_KWUARM, LIMPWURT_ROOT, 55, 125) -WEAPON_POISON = finished_potion(187, UNF_KWUARM, DRAGON_SCALE_DUST, 60, 137.5) -SUPER_RESTORE_POT = finished_potion(3026, UNF_SNAPDRAGON, RED_SPIDERS_EGGS, 63, 142.5) -SUPER_DEFENCE_POT = finished_potion(163, UNF_CADANTINE, WHITE_BERRIES, 66, 150) -ANTIFIRE_POT = finished_potion(2428, UNF_LANTADYME, DRAGON_SCALE_DUST, 69, 157.5) -RANGING_POT = finished_potion(169, UNF_DWARF_WEED, WINE_ZAMORAK, 72, 162.5) -MAGIC_POT = finished_potion(3042, UNF_LANTADYME, POTATO_CACTUS, 76, 172.5) -ZAMORAK_BREW = finished_potion(189, UNF_TORSTOL, JANGERBERRIES, 78, 175) diff --git a/game/data/plugins/skill/magic/alchemy.rb b/game/data/plugins/skill/magic/alchemy.rb deleted file mode 100644 index 755a04d5a..000000000 --- a/game/data/plugins/skill/magic/alchemy.rb +++ /dev/null @@ -1,81 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Graphic' -java_import 'org.apollo.game.model.entity.Skill' - -ALCHEMY_SPELLS = {} - -ILLEGAL_ALCH_ITEMS = [995] - -# A spell that alchemises an item. -class AlchemySpell < Spell - attr_reader :animation, :graphic, :multiplier, :experience, :delay - - def initialize(level, elements, experience, animation, graphic, multiplier, delay) - super(level, elements, experience) - @animation = animation - @graphic = graphic - @multiplier = multiplier - @delay = delay - end - -end - -# An Action that performs an AlchemySpell. -class AlchemyAction < ItemSpellAction - - def initialize(player, alchemy, slot, item) - super(player, alchemy, slot, item) - end - - def illegal_item? - ILLEGAL_ALCH_ITEMS.include?(@item.id) - end - - def execute_action - if @pulses == 0 - mob.play_animation(@spell.animation) - mob.play_graphic(@spell.graphic) - - inventory = mob.inventory - gold = (item.definition.value * @spell.multiplier) - - inventory.remove(inventory.get(@slot).id, 1) - inventory.add(995, gold) - - mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) - set_delay(@spell.delay) - elsif @pulses == 1 - mob.stop_animation - mob.stop_graphic - stop - end - end - -end - -private - -# The height of the graphic. -GRAPHIC_HEIGHT = 100 - -# Inserts an `AlchemySpell` into the hash of available alchemy spells. -def alchemy(_name, hash) - unless hash.has_keys?(:button, :level, :fires, :animation, :graphic, :multiplier, :experience, :delay) - fail 'Hash must have button, level, fires, animation, graphic, multiplier, experience, delay keys.' - end - - id, multiplier = hash[:button], hash[:multiplier] - level, experience = hash[:level], hash[:experience] - - runes = { NATURE => 1, FIRE => hash[:fires] } - animation = Animation.new(hash[:animation]) - graphic = Graphic.new(hash[:graphic], 0, GRAPHIC_HEIGHT) - delay = hash[:delay] - - ALCHEMY_SPELLS[id] = AlchemySpell.new(level, runes, experience, animation, graphic, multiplier, delay) -end - -alchemy :low_level, button: 1_162, level: 21, fires: 3, animation: 712, graphic: 112, multiplier: 0.4, experience: 31, delay: 2 -alchemy :high_level, button: 1_178, level: 55, fires: 5, animation: 713, graphic: 113, multiplier: 0.6, experience: 65, delay: 3 diff --git a/game/data/plugins/skill/magic/convert.rb b/game/data/plugins/skill/magic/convert.rb deleted file mode 100644 index 65c2284bf..000000000 --- a/game/data/plugins/skill/magic/convert.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Graphic' -java_import 'org.apollo.game.model.Item' -java_import 'org.apollo.game.model.entity.Skill' - -CONVERT_SPELLS = {} -BONES_ID = 526 - -CONVERT_ANIM = Animation.new(722) -CONVERT_GRAPHIC = Graphic.new(141, 0, 100) - -# A `Spell` for converting items. -class ConvertSpell < Spell - attr_reader :reward - - def initialize(level, elements, experience, reward) - super(level, elements, experience) - @reward = Item.new(reward) - end - -end - -# A `SpellAction` for a `ConvertSpell`. -class ConvertingAction < SpellAction - attr_reader :slots - - def initialize(player, spell, slots) - super(player, spell) - @slots = slots - end - - def execute_action - if @pulses == 0 - mob.play_animation(CONVERT_ANIM) - mob.play_graphic(CONVERT_GRAPHIC) - - inventory = mob.inventory - firing = (@slots.length * 2) < inventory.capacity - - inventory.stop_firing_events unless firing # In case of many changes, wait with firing events - - reward = @spell.reward - @slots.each { |slot| inventory.set(slot, reward) } - - unless firing - inventory.start_firing_events - inventory.force_refresh - end - - mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) - set_delay(2) - elsif @pulses == 1 - mob.stop_animation - mob.stop_graphic - stop - end - end - -end - -def bone_slots(player) - inventory = player.inventory - items = inventory.items - size = inventory.size - - counter = 0 - slots = [] - - (0...inventory.capacity).each do |slot| - break unless counter <= size - - item = items[slot] - slots << slot if !item.nil? && item.id == BONES_ID - - counter += 1 - end - - slots -end - -def convert(_name, button, level, elements, experience, reward) - CONVERT_SPELLS[button] = ConvertSpell.new(level, elements, experience, reward) -end - -convert :bones_to_bananas, 1159, 15, { NATURE => 1, WATER => 2, EARTH => 2 }, 25, 1963 -convert :bones_to_peaches, 15877, 60, { NATURE => 2, WATER => 4, EARTH => 4 }, 35.5, 6883 - diff --git a/game/data/plugins/skill/magic/element.rb b/game/data/plugins/skill/magic/element.rb deleted file mode 100644 index 46d3a352f..000000000 --- a/game/data/plugins/skill/magic/element.rb +++ /dev/null @@ -1,107 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.entity.EquipmentConstants' - -AIR_ELEMENTS = {} -WATER_ELEMENTS = {} -EARTH_ELEMENTS = {} -FIRE_ELEMENTS = {} - -AIR_RUNE = 556 -WATER_RUNE = 555 -EARTH_RUNE = 557 -FIRE_RUNE = 554 - -MIND_RUNE = 558 -CHAOS_RUNE = 562 -DEATH_RUNE = 560 -BLOOD_RUNE = 565 - -COSMIC_RUNE = 564 -LAW_RUNE = 563 -NATURE_RUNE = 561 -SOUL_RUNE = 566 - -MIST_RUNE = 4695 -DUST_RUNE = 4696 -SMOKE_RUNE = 4697 -MUD_RUNE = 4698 -STEAM_RUNE = 4694 -LAVA_RUNE = 4699 - -# An element of a spell. -class Element - attr_reader :runes, :staffs, :name - - def initialize(runes, staffs, name = 'Null') - @runes = runes - @staffs = staffs - @name = name - end - - def check_remove(player, amount, remove) - weapon = player.equipment.get(EquipmentConstants::WEAPON) - unless @staffs.nil? || weapon.nil? - @staffs.each { |staff| return true if weapon.id == staff } - end - - inventory = player.inventory - - found = {} - counter = 0 - - inventory.items.each do |item| - break unless counter < amount - next if item.nil? - - amt = item.amount - @runes.each do |rune| - break unless counter < amount - - id = item.id - if id == rune - if amt >= amount - inventory.remove(id, amount) if remove - return true - else - found[id] = amt - counter += amt - end - end - end - end - - if counter >= amount - found.each { |id, amt| inventory.remove(id, amt) } if remove - return true - end - - false - end - -end - -AIR_RUNES = [556, 4695, 4696, 4697] -WATER_RUNES = [555, 4695, 4698, 4694] -EARTH_RUNES = [557, 4696, 4697, 4698] -FIRE_RUNES = [554, 4697, 4694, 4699] - -AIR_STAFFS = [1381, 1397, 1405] -WATER_STAFFS = [1383, 1395, 1403] -EARTH_STAFFS = [1385, 1399, 1407, 3053, 3054] -FIRE_STAFFS = [1387, 1393, 1401, 3053, 3054] - -AIR = Element.new(AIR_RUNES, AIR_STAFFS, 'Air rune') -WATER = Element.new(WATER_RUNES, WATER_STAFFS, 'Water rune') -EARTH = Element.new(EARTH_RUNES, EARTH_STAFFS, 'Earth rune') -FIRE = Element.new(FIRE_RUNES, FIRE_STAFFS, 'Fire rune') - -MIND = Element.new([MIND_RUNE], nil, 'Mind rune') -CHAOS = Element.new([CHAOS_RUNE], nil, 'Chaos rune') -DEATH = Element.new([DEATH_RUNE], nil, 'Death rune') -BLOOD = Element.new([BLOOD_RUNE], nil, 'Blood rune') - -COSMIC = Element.new([COSMIC_RUNE], nil, 'Cosmic rune') -LAW = Element.new([LAW_RUNE], nil, 'Law rune') -NATURE = Element.new([NATURE_RUNE], nil, 'Nature rune') -SOUL = Element.new([SOUL_RUNE], nil, 'Soul rune') diff --git a/game/data/plugins/skill/magic/enchant.rb b/game/data/plugins/skill/magic/enchant.rb deleted file mode 100644 index 319726cbc..000000000 --- a/game/data/plugins/skill/magic/enchant.rb +++ /dev/null @@ -1,106 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Graphic' -java_import 'org.apollo.game.model.Item' - -ENCHANT_SPELLS = {} -ENCHANT_ITEMS = {} - -RING_GFX = Graphic.new(238, 0, 100) -RING_ANIM = Animation.new(931) - -LOW_NECK_GFX = Graphic.new(114, 0, 100) -LOW_NECK_ANIM = Animation.new(719) - -MED_NECK_GFX = Graphic.new(115, 0, 100) -MED_NECK_ANIM = Animation.new(720) - -HIGH_NECK_GFX = Graphic.new(116, 0, 100) -HIGH_NECK_ANIM = Animation.new(721) - -ONYX_NECK_GFX = Graphic.new(452, 0, 100) - -# A `Spell` for enchanting an item. -class EnchantSpell < Spell - attr_reader :button, :animation, :graphic, :delay - - def initialize(button, level, elements, animation, graphic, delay, experience) - super(level, elements, experience) - @button = button - @animation = animation - @graphic = graphic - @delay = delay - end - -end - -# A `SpellAction` for an `EnchantSpell`. -class EnchantAction < ItemSpellAction - attr_reader :reward - - def initialize(player, enchant, slot, item, reward) - super(player, enchant, slot, item) - @reward = Item.new(reward) - end - - def illegal_item? - ENCHANT_ITEMS[@item.id].nil? - end - - def execute_action - if @pulses == 0 - mob.play_animation(@spell.animation) - mob.play_graphic(@spell.graphic) - - mob.inventory.set(@slot, @reward) - mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) - - set_delay(@spell.delay) - elsif @pulses == 1 - mob.stop_animation - mob.stop_graphic - stop - end - end - -end - -def enchant(button, level, elements, item, animation, graphic, delay, experience, reward) - enchant = EnchantSpell.new(button, level, elements, animation, graphic, delay, experience) - ENCHANT_SPELLS[item] = enchant - ENCHANT_ITEMS[item] = reward -end - -SAPPHIRE_ELEMENTS = { COSMIC => 1, WATER => 1 } -EMERALD_ELEMENTS = { COSMIC => 1, AIR => 1 } -RUBY_ELEMENTS = { COSMIC => 1, FIRE => 5 } -DIAMOND_ELEMENTS = { COSMIC => 1, EARTH => 10 } -DSTONE_ELEMENTS = { COSMIC => 1, EARTH => 15, WATER => 15 } -ONYX_ELEMENTS = { COSMIC => 1, FIRE => 20, EARTH => 20 } - -# Sapphire -enchant 1155, 7, SAPPHIRE_ELEMENTS, 1637, RING_ANIM, RING_GFX, 2, 17.5, 2550 # Ring -enchant 1155, 7, SAPPHIRE_ELEMENTS, 1656, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 17.5, 3853 # Necklace -enchant 1155, 7, SAPPHIRE_ELEMENTS, 1692, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 17.5, 1727 # Amulet - -# Emerald -enchant 1165, 27, EMERALD_ELEMENTS, 1639, RING_ANIM, RING_GFX, 2, 37, 2552 # Ring -enchant 1165, 27, EMERALD_ELEMENTS, 1658, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 37, 5521 # Necklace -enchant 1165, 27, EMERALD_ELEMENTS, 1696, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 37, 1729 # Amulet - -# Ruby -enchant 1176, 49, RUBY_ELEMENTS, 1641, RING_ANIM, RING_GFX, 2, 59, 2568 # Ring -enchant 1176, 49, RUBY_ELEMENTS, 1698, MED_NECK_ANIM, MED_NECK_GFX, 2, 59, 1725 # Amulet - -# Diamond -enchant 1180, 57, DIAMOND_ELEMENTS, 1643, RING_ANIM, RING_GFX, 2, 67, 2570 # Ring -enchant 1180, 57, DIAMOND_ELEMENTS, 1700, MED_NECK_ANIM, MED_NECK_GFX, 2, 67, 1731 # Amulet - -# Dragonstone -enchant 1187, 68, DSTONE_ELEMENTS, 1645, RING_ANIM, RING_GFX, 2, 78, 2572 # Ring -enchant 1187, 68, DSTONE_ELEMENTS, 1702, HIGH_NECK_ANIM, HIGH_NECK_GFX, 3, 78, 1712 # Amulet - -# Onyx -enchant 6003, 87, ONYX_ELEMENTS, 6575, RING_ANIM, RING_GFX, 2, 97, 6583 # Ring -enchant 6003, 87, ONYX_ELEMENTS, 6581, HIGH_NECK_ANIM, ONYX_NECK_GFX, 2, 97, 6585 # Amulet diff --git a/game/data/plugins/skill/magic/magic.rb b/game/data/plugins/skill/magic/magic.rb deleted file mode 100644 index 71ddcfb49..000000000 --- a/game/data/plugins/skill/magic/magic.rb +++ /dev/null @@ -1,172 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.Action' -java_import 'org.apollo.game.message.impl.DisplayTabInterfaceMessage' -java_import 'org.apollo.game.model.entity.EquipmentConstants' -java_import 'org.apollo.game.model.entity.Skill' -java_import 'org.apollo.cache.def.ItemDefinition' - -# A `Message` to display the magic spellbook. -DISPLAY_SPELLBOOK = DisplayTabInterfaceMessage.new(6) - -# A spell that can be cast. -class Spell - attr_reader :level, :elements, :experience - - def initialize(level, elements, experience) - @level = level - @elements = elements - @experience = experience - end - -end - -# An `Action` for casting a `Spell`. -class SpellAction < Action - attr_reader :spell, :pulses - - def initialize(mob, spell) - super(0, true, mob) - @spell = spell - @pulses = 0 - end - - def illegal_item? - false - end - - def execute - if @pulses == 0 - unless check_skill - stop - return - end - if illegal_item? - mob.send_message('You cannot use that spell on this item!') - stop - return false - end - unless process_elements - stop - return - end - end - execute_action - @pulses += 1 - end - - def execute_action - stop - end - - def check_skill - required = @spell.level - if required > mob.skill_set.getSkill(Skill::MAGIC).current_level - mob.send_message("You need a Magic level of at least #{required} to cast this spell.") - return false - end - - true - end - - def process_elements - elements = @spell.elements - - elements.each do |element, amount| - unless element.check_remove(mob, amount, false) - mob.send_message("You do not have enough #{element.name.split.map(&:capitalize) * ' '}s to cast this spell.") - return false - end - end - - elements.each { |element, amount| element.check_remove(mob, amount, true) } - true - end - - def equals(other) - get_class == other.get_class - end - -end - -# A `SpellAction` that verifies an input `Item` is legal. -class ItemSpellAction < SpellAction - attr_reader :slot, :item - - def initialize(mob, spell, slot, item) - super(mob, spell) - @slot = slot - @item = item - end - - # We override SpellAction#execute to implement an illegal item check (e.g. coins for alchemy) - def execute - if @pulses == 0 - id = @item.id - - mob.send(DISPLAY_SPELLBOOK) - - # TODO: There has to be a better way to do this. - @spell.elements.each do |element, amount| - element.runes.each do |rune| - if id == rune && !element.check_remove(mob, amount + 1, false) - mob.send_message("You do not have enough #{element.name.split.map(&:capitalize) * ' '}s to cast this spell.") - stop - return false - end - end - end - - end - - super - end - -end - -# Intercepts the magic on item message. -on :message, :magic_on_item do |player, message| - spell = message.spell_id - - alchemy = ALCHEMY_SPELLS[spell] - unless alchemy.nil? - slot = message.slot - item = player.inventory.get(slot) - player.start_action(AlchemyAction.new(player, alchemy, slot, item)) - message.terminate - else - enchant = ENCHANT_SPELLS[message.id] - - if !enchant.nil? && enchant.button == spell - slot = message.slot - item = player.inventory.get(slot) - player.start_action(EnchantAction.new(player, enchant, slot, item, ENCHANT_ITEMS[item.id])) - message.terminate - end - end -end - -# Intercepts the button message -on :message, :button do |player, message| - button = message.widget_id - - tele = TELEPORT_SPELLS[button] - unless tele.nil? - player.start_action(TeleportingAction.new(player, tele)) - message.terminate - end - - conv = CONVERT_SPELLS[button] - unless conv.nil? - slots = bone_slots(player) - - if slots.length == 0 - player.send_message("You can't convert these bones!") - else - player.start_action(ConvertingAction.new(player, conv, slots)) - end - - message.terminate - end - -end diff --git a/game/data/plugins/skill/magic/plugin.xml b/game/data/plugins/skill/magic/plugin.xml deleted file mode 100644 index 24e3cede4..000000000 --- a/game/data/plugins/skill/magic/plugin.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - skill-magic - 1 - Magic - Adds the Magic skill. - - Chris Fletcher - Major - - - - - - - - - - - \ No newline at end of file diff --git a/game/data/plugins/skill/magic/teleport.rb b/game/data/plugins/skill/magic/teleport.rb deleted file mode 100644 index a62411ecf..000000000 --- a/game/data/plugins/skill/magic/teleport.rb +++ /dev/null @@ -1,101 +0,0 @@ -# Thanks to phl0w for providing -# the correct destination coordinates of the ancient teleports. - -require 'java' - -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Graphic' -java_import 'org.apollo.game.model.Position' -java_import 'org.apollo.game.model.entity.Skill' - -TELEPORT_SPELLS = {} - -MODERN_TELE_ANIM = Animation.new(714) -MODERN_TELE_GRAPHIC = Graphic.new(111, 5, 100) - -ANCIENT_TELE_END_GRAPHIC = Graphic.new(455) -ANCIENT_TELE_ANIM = Animation.new(1979) -ANCIENT_TELE_GRAPHIC = Graphic.new(392) - -# A `Spell` that teleports a `Player` to another `Position`. -class TeleportSpell < Spell - attr_reader :ancient, :destination, :experience, :name - - def initialize(ancient, level, elements, destination, experience, name) - super(level, elements, experience) - @ancient = ancient - @destination = destination - @name = name - end - -end - -# A `SpellAction` for a `TeleportSpell`. -class TeleportingAction < SpellAction - - def initialize(mob, spell) - super(mob, spell) - end - - def execute_action - @spell.ancient ? execute_ancient : execute_modern - end - - def execute_modern - if @pulses == 0 - mob.play_animation(MODERN_TELE_ANIM) - mob.play_graphic(MODERN_TELE_GRAPHIC) - elsif @pulses == 3 - mob.stop_graphic - mob.stop_animation - mob.teleport(@spell.destination) - mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) - stop - end - end - - def execute_ancient - if @pulses == 0 - mob.play_graphic(ANCIENT_TELE_GRAPHIC) - mob.play_animation(ANCIENT_TELE_ANIM) - set_delay(2) - elsif @pulses == 2 - mob.stop_graphic - mob.stop_animation - mob.teleport(@spell.destination) - mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) - stop - end - end - -end - -def tele(ancient = false, button, level, elements, x, y, experience, name) - position = Position.new(x, y) - TELEPORT_SPELLS[button] = TeleportSpell.new(ancient, level, elements, position, experience, name) -end - -def ancient_tele(*args) - tele(true, *args) -end - -# Modern teleports -tele 1_164, 25, { LAW => 1, AIR => 3, FIRE => 1 }, 3213, 3424, 35, 'Varrock' -tele 1_167, 31, { LAW => 1, AIR => 3, EARTH => 1 }, 3222, 3219, 41, 'Lumbridge' -tele 1_170, 37, { LAW => 1, AIR => 3, WATER => 1 }, 2965, 3379, 47, 'Falador' -tele 1_174, 45, { LAW => 1, AIR => 5 }, 2757, 3478, 55.5, 'Camelot' -tele 1_540, 51, { LAW => 2, WATER => 2 }, 2662, 3306, 61, 'Ardougne' -tele 1_541, 58, { LAW => 2, EARTH => 2 }, 2549, 3114, 68, 'the Watchtower' -tele 7_455, 61, { LAW => 2, FIRE => 2 }, 2871, 3590, 68, 'Trollheim' -tele 18_470, 64, { Element.new([1963], nil, 'Banana') => 1, LAW => 2, WATER => 2, FIRE => 2 }, - 2_754, 2_785, 76, 'Ape Atoll' - -# Ancient teleports -ancient_tele 13_035, 54, { LAW => 2, FIRE => 1, AIR => 1 }, 3098, 9882, 64, 'Paddewwa' -ancient_tele 13_045, 60, { LAW => 2, SOUL => 2 }, 3320, 3338, 70, 'Senntisten' -ancient_tele 13_053, 66, { LAW => 2, BLOOD => 1 }, 3493, 3472, 76, 'Kharyll' -ancient_tele 13_061, 72, { LAW => 2, WATER => 4 }, 3003, 3470, 82, 'Lassar' -ancient_tele 13_069, 78, { LAW => 2, FIRE => 3, AIR => 2 }, 2966, 3_696, 88, 'Dareeyak' -ancient_tele 13_079, 84, { LAW => 2, SOUL => 2 }, 3163, 3664, 94, 'Carrallangar' -ancient_tele 13_087, 90, { LAW => 2, BLOOD => 2 }, 3287, 3883, 100, 'Annakarl' -ancient_tele 13_095, 96, { LAW => 2, WATER => 8 }, 2972, 3873, 106, 'Ghorrock' diff --git a/game/data/plugins/skill/mining/gem.rb b/game/data/plugins/skill/mining/gem.rb deleted file mode 100644 index 6d2255d3a..000000000 --- a/game/data/plugins/skill/mining/gem.rb +++ /dev/null @@ -1,20 +0,0 @@ -GEMSTONES = {} - -# A gemstone that can be received when mining. -class Gemstone - attr_reader :id, :chance - - def initialize(id, chance) - @id = id - @chance = chance - end -end - -def gem(gem) - GEMSTONES[gem.id] = gem -end - -gem(Gemstone.new(1623, 0)) # uncut sapphire -gem(Gemstone.new(1605, 0)) # uncut emerald -gem(Gemstone.new(1619, 0)) # uncut ruby -gem(Gemstone.new(1617, 0)) # uncut diamond diff --git a/game/data/plugins/skill/mining/mining.rb b/game/data/plugins/skill/mining/mining.rb deleted file mode 100644 index 076577a1d..000000000 --- a/game/data/plugins/skill/mining/mining.rb +++ /dev/null @@ -1,155 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.model.entity.EquipmentConstants' -java_import 'org.apollo.game.model.entity.Skill' - -PROSPECT_PULSES = 3 -ORE_SIZE = 1 - -# TODO: finish implementing this -# A `DistancedAction` for mining ore. -class MiningAction < DistancedAction - attr_reader :position, :ore, :counter, :started - - def initialize(mob, position, ore) - super(0, true, mob, position, ORE_SIZE) - @position = position - @ore = ore - @started = false - @counter = 0 - end - - def find_pickaxe - weapon = mob.equipment.get(EquipmentConstants::WEAPON) - PICKAXE_IDS.each do |id| - return PICKAXES[id] if (!weapon.nil? && weapon.id == id) || mob.inventory.contains(id) - end - - nil - end - - # starts the mining animation, sets counters/flags and turns the mob to - # the ore - def start_mine(pickaxe) - @started = true - mob.send_message('You swing your pick at the rock.') - mob.play_animation(pickaxe.animation) - @counter = pickaxe.pulses - end - - def executeAction - skills = mob.skill_set - level = skills.get_skill(Skill::MINING).current_level - pickaxe = find_pickaxe - mob.turn_to(@position) - - # verify the mob can mine with their pickaxe - if pickaxe.nil? || level < pickaxe.level - mob.send_message('You do not have a pickaxe for which you have the level to use.') - stop - return - end - - # verify the mob can mine the ore - if ore.level > level - mob.send_message('You do not have the required level to mine this rock.') - stop - return - end - - # check if we need to kick start things - if @started - # count down and check if we can have a chance at some ore now - if @counter == 0 - # TODO: calculate the chance that the player can actually get the rock - - if mob.inventory.add(ore.id) - name = name_of(@ore.id).sub(/ ore$/, '').downcase - - mob.send_message("You manage to mine some #{name}.") - skills.add_experience(Skill::MINING, ore.exp) - # TODO: expire the rock - end - - stop - end - - @counter -= 1 - else - start_mine(pickaxe) - end - end - - def equals(other) - get_class == other.get_class && @position == other.position && @ore == other.ore - end - -end - -# A `DistancedAction` for a rock with no available ore. -class ExpiredProspectingAction < DistancedAction - attr_reader :position - - def initialize(mob, position) - super(0, true, mob, position, ORE_SIZE) - end - - def executeAction - mob.send_message('There is currently no ore available in this rock.') - stop - end - - def equals(other) - get_class == other.get_class && @position == other.position - end - -end - -# A `DistancedAction` for prospecting a rock. -class ProspectingAction < DistancedAction - attr_reader :position, :ore - - def initialize(mob, position, ore) - super(PROSPECT_PULSES, true, mob, position, ORE_SIZE) - @position = position - @ore = ore - @started = false - end - - def executeAction - if @started - ore_def = ItemDefinition.lookup(@ore.id) - name = ore_def.name.sub(/ ore$/, '').downcase - - mob.send_message("This rock contains #{name}.") - stop - else - @started = true - - mob.send_message('You examine the rock for ores...') - mob.turn_to(@position) - end - end - - def equals(other) - get_class == other.get_class && @position == other.position && @ore == other.ore - end - -end - -on :message, :first_object_action do |mob, message| - ore = ORES[message.id] - - mob.start_action(MiningAction.new(mob, message.position, ore)) unless ore.nil? -end - -on :message, :second_object_action do |mob, message| - ore = ORES[message.id] - - if !ore.nil? - mob.start_action(ProspectingAction.new(mob, message.position, ore)) - elsif !EXPIRED_ORES[message.id].nil? - mob.start_action(ExpiredProspectingAction.new(mob, message.position)) - end -end diff --git a/game/data/plugins/skill/mining/ore.rb b/game/data/plugins/skill/mining/ore.rb deleted file mode 100644 index 34b0a2f94..000000000 --- a/game/data/plugins/skill/mining/ore.rb +++ /dev/null @@ -1,95 +0,0 @@ -# Thanks to Mikey` for helping -# to find some of the item/object IDs, minimum levels and experiences. -# -# Thanks to Clifton for helping -# to find some of the expired object IDs. - -ORES = {} -EXPIRED_ORES = {} - -# An ore that can be mined. -class Ore - attr_reader :id, :objects, :level, :exp, :respawn - - def initialize(id, objects, level, exp, respawn) - @id = id - @objects = objects - @level = level - @exp = exp - @respawn = respawn - end -end - -def append_ore(ore) - ore.objects.each do |obj, expired_obj| - ORES[obj] = ore - EXPIRED_ORES[expired_obj] = true - end -end - -CLAY_OBJECTS = { - 2180 => 450, 2109 => 451, 14_904 => 14_896, 14_905 => 14_897 -} - -COPPER_OBJECTS = { - 11_960 => 11_555, 11_961 => 11_556, 11_962 => 11_557, 11_936 => 11_552, - 11_937 => 11_553, 11_938 => 11_554, 2090 => 450, 2091 => 451, - 14_906 => 14_898, 14_907 => 14_899, 14_856 => 14_832, 14_857 => 14_833, - 14_858 => 14_834 -} - -TIN_OBJECTS = { - 11_597 => 11_555, 11_958 => 11_556, 11_959 => 11_557, 11_933 => 11_552, - 11_934 => 11_553, 11_935 => 11_554, 2094 => 450, 2095 => 451, - 14_092 => 14_894, 14_903 => 14_895 -} - -IRON_OBJECTS = { - 11_954 => 11_555, 11_955 => 11_556, 11_956 => 11_557, 2092 => 450, - 2093 => 451, 14_900 => 14_892, 14_901 => 14_893, 14_913 => 14_915, - 14_914 => 14_916 -} - -COAL_OBJECTS = { - 11_963 => 11_555, 11_964 => 11_556, 11_965 => 11_557, 11_930 => 11_552, - 11_931 => 11_553, 11_932 => 11_554, 2096 => 450, 2097 => 451, - 14_850 => 14_832, 14_851 => 14_833, 14_852 => 14_834 -} - -SILVER_OBJECTS = { - 11_948 => 11_555, 11_949 => 11_556, 11_950 => 11_557, 2100 => 450, 2101 => 451 -} - -GOLD_OBJECTS = { - 11_951 => 11_555, 11_952 => 11_556, 11_953 => 11_557, 2098 => 450, 2099 => 451 -} - -MITHRIL_OBJECTS = { - 11_945 => 11_555, 11_946 => 11_556, 11_947 => 11_557, 11_942 => 11_552, - 11_943 => 11_553, 11_944 => 11_554, 2102 => 450, 2103 => 451, - 14_853 => 14_832, 14_854 => 14_833, 14_855 => 14_834 -} - -ADAMANT_OBJECTS = { - 11_939 => 11_552, 11_940 => 11_553, 11_941 => 11_554, 2104 => 450, - 2105 => 451, 14_862 => 14_832, 14_863 => 14_833, 14_864 => 14_834 -} - -RUNITE_OBJECTS = { - 2106 => 450, 2107 => 451, 14_859 => 14_832, 14_860 => 14_833, - 14_861 => 14_834 -} - -append_ore Ore.new 434, CLAY_OBJECTS, 1, 5, 3 # clay -append_ore Ore.new 436, COPPER_OBJECTS, 1, 17.5, 6 # copper ore -append_ore Ore.new 438, TIN_OBJECTS, 1, 17.5, 6 # tin ore -append_ore Ore.new 440, IRON_OBJECTS, 15, 35, 16 # iron ore -append_ore Ore.new 453, COAL_OBJECTS, 30, 50, 100 # coal -append_ore Ore.new 444, GOLD_OBJECTS, 40, 65, 200 # gold ore -append_ore Ore.new 442, SILVER_OBJECTS, 20, 40, 200 # silver ore -append_ore Ore.new 447, MITHRIL_OBJECTS, 55, 80, 400 # mithril ore -append_ore Ore.new 449, ADAMANT_OBJECTS, 70, 95, 800 # adamant ore -append_ore Ore.new 451, RUNITE_OBJECTS, 85, 125, 2500 # runite ore - -# TODO: rune essence object id = 2491 -# level 1, exp 5, rune ess = 1436, pure ess = 7936 diff --git a/game/data/plugins/skill/mining/pickaxe.rb b/game/data/plugins/skill/mining/pickaxe.rb deleted file mode 100644 index 5c99ba3c8..000000000 --- a/game/data/plugins/skill/mining/pickaxe.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Animation' - -PICKAXES = {} -PICKAXE_IDS = [] - -# A pickaxe that can be mined with. -class Pickaxe - attr_reader :id, :level, :animation, :pulses - - def initialize(id, level, animation, pulses) - @id = id - @level = level - @animation = Animation.new(animation) - @pulses = pulses - end -end - -def append_pickaxe(pickaxe) - PICKAXES[pickaxe.id] = pickaxe - PICKAXE_IDS << pickaxe.id # tacky way of keeping things in order -end - -# NOTE: ADD LOWER LEVEL PICKAXES FIRST -append_pickaxe(Pickaxe.new(1265, 1, 625, 8)) # bronze pickaxe -append_pickaxe(Pickaxe.new(1267, 1, 626, 7)) # iron pickaxe -append_pickaxe(Pickaxe.new(1269, 1, 627, 6)) # steel pickaxe -append_pickaxe(Pickaxe.new(1273, 21, 629, 5)) # mithril pickaxe -append_pickaxe(Pickaxe.new(1271, 31, 628, 4)) # adamant pickaxe -append_pickaxe(Pickaxe.new(1275, 41, 624, 3)) # rune pickaxe - -PICKAXE_IDS.reverse! diff --git a/game/data/plugins/skill/mining/plugin.xml b/game/data/plugins/skill/mining/plugin.xml deleted file mode 100644 index 5e68d2453..000000000 --- a/game/data/plugins/skill/mining/plugin.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - skill-mining - 1 - Mining - Adds the mining skill. - - Graham - Mikey` - WH:II:DOW - Requa - Clifton - - - - - - - - - - util - - \ No newline at end of file diff --git a/game/data/plugins/skill/mining/respawn.rb b/game/data/plugins/skill/mining/respawn.rb deleted file mode 100644 index 137fd7b69..000000000 --- a/game/data/plugins/skill/mining/respawn.rb +++ /dev/null @@ -1,16 +0,0 @@ -# Calculates the number of pulses it takes for an ore to respawn based on the -# number of players currently online. -# -# The 'base' argument is the number of pulses it takes with no players online. -# The 'players' argument is the number of players currently logged into the -# current world. -# -# The base times can be found on this website: -# http://runescape.salmoneus.net/mining.html#respawn -# -# These must be converted to pulses (seconds * 10 / 6) to work with this -# function. The rest of the mining plugin rounds the base respawn times in -# pulses down where appropriate. -def respawn_pulses(base, players) - base - players * base / ($world.player_repository.size * 2) -end diff --git a/game/data/plugins/skill/prayer/bury.rb b/game/data/plugins/skill/prayer/bury.rb deleted file mode 100644 index 2d3b6bc72..000000000 --- a/game/data/plugins/skill/prayer/bury.rb +++ /dev/null @@ -1,89 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.Action' -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.entity.Skill' - -BURY_BONE_ANIMATION = Animation.new(827) -BONES = {} - -# A bone with an id and experience value. -class Bone - attr_reader :id, :experience - - def initialize(id, experience) - @id = id - @experience = experience - end - -end - -# An action where a bone in a player's inventory is buried. -class BuryBoneAction < Action - attr_reader :slot, :bone - - def initialize(mob, slot, bone) - super(1, true, mob) - @slot = slot - @bone = bone - @executions = 0 - end - - def execute - if @executions == 0 - mob.send_message('You dig a hole in the ground...') - mob.play_animation(BURY_BONE_ANIMATION) - @executions += 1 - elsif @executions == 1 - if mob.inventory.get(@slot).id == @bone.id - mob.send_message('You bury the bones.') - mob.inventory.reset(@slot) - mob.skill_set.add_experience(Skill::PRAYER, @bone.experience) - end - stop - end - end - - def equals(other) - get_class == other.get_class - end - -end - -# Intercepts the first item option message. -on :message, :first_item_option do |player, message| - bone = BONES[message.id] - - unless bone.nil? - player.start_action(BuryBoneAction.new(player, message.slot, bone)) - message.terminate - end -end - -# Appends a bone to the array -def append_bone(hash) - fail 'Hash must contain an id and an experience value.' unless hash.has_keys?(:id, :experience) - id = hash[:id] - BONES[id] = Bone.new(id, hash[:experience]) -end - -append_bone name: :regular_bones, id: 526, experience: 5 -append_bone name: :burnt_bones, id: 528, experience: 5 -append_bone name: :bat_bones, id: 530, experience: 4 -append_bone name: :big_bones, id: 532, experience: 45 -append_bone name: :babydragon_bones, id: 534, experience: 30 -append_bone name: :dragon_bones, id: 536, experience: 72 -append_bone name: :wolf_bones, id: 2859, experience: 14 -append_bone name: :shaikahan_bones, id: 3123, experience: 25 -append_bone name: :jogre_bones, id: 3125, experience: 15 -append_bone name: :burnt_zogre_bones, id: 3127, experience: 25 -append_bone name: :monkey_bones, id: 3179, experience: 14 # smallish -append_bone name: :monkey_bones, id: 3180, experience: 14 # medium -append_bone name: :monkey_bones, id: 3181, experience: 14 # quite large -append_bone name: :monkey_bones, id: 3182, experience: 14 # quite large -append_bone name: :monkey_bones, id: 3183, experience: 14 # small -append_bone name: :shaking_bones, id: 3187, experience: 14 -append_bone name: :zogre_bones, id: 4812, experience: 23 -append_bone name: :fayrg_bones, id: 4830, experience: 84 -append_bone name: :raurg_bones, id: 4832, experience: 96 -append_bone name: :ourg_bones, id: 4834, experience: 140 diff --git a/game/data/plugins/skill/prayer/plugin.xml b/game/data/plugins/skill/prayer/plugin.xml deleted file mode 100644 index edbeb4415..000000000 --- a/game/data/plugins/skill/prayer/plugin.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - skill-prayer - 0.9 - Prayer - Adds the Prayer skill. - - Major - 010253 - - - - - - - attributes - - \ No newline at end of file diff --git a/game/data/plugins/skill/prayer/prayers.rb b/game/data/plugins/skill/prayer/prayers.rb deleted file mode 100644 index 7f185ce6a..000000000 --- a/game/data/plugins/skill/prayer/prayers.rb +++ /dev/null @@ -1,88 +0,0 @@ - -java_import 'org.apollo.game.message.impl.ConfigMessage' - -# Declares the active prayer attribute. -declare_attribute(:active_prayer, -1, :persistent) - -# The hash of button ids to prayers. -PRAYERS = {} - -# Intercept the ButtonMessage to toggle a prayer. -on :message, :button do |player, message| - button = message.widget_id - prayer = PRAYERS[button] - - unless prayer.nil? - if prayer.level > player.skill_set.get_maximum_level(Skill::PRAYER) - update_setting(player, prayer, :off) - next - end - - player.send_message('after level check') - previous = player.active_prayer - - update_setting(player, PRAYERS[previous], :off) unless previous == -1 - - if previous != button - player.send_message("Previous: #{previous}, new: #{button}.") - update_setting(player, prayer, :on) - player.active_prayer = button - end - end -end - -private - -# A Prayer that can be activated by a player. -class Prayer - attr_reader :name, :level, :button, :setting, :drain - - def initialize(name, level, button, setting, drain) - @name = name - @level = level - @button = button - @setting = setting - @drain = drain - end - -end - -def update_setting(player, prayer, state) - value = (state == :on) ? 1 : 0 - player.send_message("Toggling prayer #{prayer.name}, state: #{state}.") - player.send(ConfigMessage.new(prayer.setting, value)) -end - -# Appends a Prayer to the hash. -def append_prayer(name, hash) - unless hash.has_keys?(:level, :button, :setting, :drain) - fail 'Error: prayer hash hash must contain a level, button, setting, and drain.' - end - - button = hash[:button] - PRAYERS[button] = Prayer.new(name, hash[:level], button, hash[:setting], hash[:drain]) -end - -# Don't deal with the actual effect here to avoid mess (TODO do it, but with attributes?). -append_prayer :thick_skin, level: 1, button: 5609, setting: 83, drain: 0.01 -append_prayer :burst_of_strength, level: 4, button: 5610, setting: 84, drain: 0.01 -append_prayer :clarity_of_thought, level: 7, button: 5611, setting: 85, drain: 0.01 -append_prayer :rock_skin, level: 10, button: 5612, setting: 86, drain: 0.04 -append_prayer :superhuman_strength, level: 13, button: 5613, setting: 87, drain: 0.04 -append_prayer :improved_reflexes, level: 16, button: 5614, setting: 88, drain: 0.04 - -append_prayer :rapid_restore, level: 19, button: 5615, setting: 89, drain: 0.01 -append_prayer :rapid_heal, level: 22, button: 5615, setting: 90, drain: 0.01 -append_prayer :protect_item, level: 25, button: 5617, setting: 91, drain: 0.01 - -append_prayer :steel_skin, level: 28, button: 5618, setting: 92, drain: 0.1 -append_prayer :ultimate_strength, level: 31, button: 5619, setting: 93, drain: 0.1 -append_prayer :incredible_reflexes, level: 34, button: 5620, setting: 94, drain: 0.1 - -append_prayer :protect_from_magic, level: 37, button: 5621, setting: 95, drain: 0.15 -append_prayer :protect_from_missiles, level: 40, button: 5622, setting: 96, drain: 0.15 -append_prayer :protect_from_melee, level: 43, button: 5623, setting: 97, drain: 0.15 - -append_prayer :retribution, level: 46, button: 683, setting: 98, drain: 0.15 -append_prayer :redemption, level: 49, button: 684, setting: 99, drain: 0.15 -append_prayer :smite, level: 52, button: 685, setting: 100, drain: 0.2 diff --git a/game/data/plugins/skill/runecraft/altar.rb b/game/data/plugins/skill/runecraft/altar.rb deleted file mode 100644 index 04ac395de..000000000 --- a/game/data/plugins/skill/runecraft/altar.rb +++ /dev/null @@ -1,129 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.model.Position' - -PORTALS = {} -ENTRANCE_ALTARS = {} -CRAFTING_ALTARS = {} - -# Represents a runecrafting altar. -class Altar - attr_reader :entrance_altar, :crafting, :portal_id, :entrance, :exit, :crafting_centre - - def initialize(entrance_altar, crafting, portal_id, entrance_position, exit_position, - crafting_centre) - @entrance_altar = entrance_altar - @altar = crafting - @portal_id = portal_id - @entrance_position = entrance_position - @exit_position = exit_position - @crafting_centre = crafting_centre - end - -end - -# Intercepts the item on object message. -on :message, :item_on_object do |player, message| - talisman = TALISMANS[message.id] - altar = ENTRANCE_ALTARS[message.object_id] - - unless talisman.nil? || altar.nil? - player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position)) - message.terminate - end -end - -# Intercepts the first object action message. -on :message, :object_action do |player, message| - if message.option == 1 - object_id = message.id - - if PORTALS.key?(object_id) - altar = PORTALS[object_id] - entrance = altar.entrance_position - - player.start_action(TeleportAction.new(player, entrance, 1, altar.exit_position)) - message.terminate - elsif RUNES.key?(object_id) - rune = RUNES[object_id] - altar = CRAFTING_ALTARS[object_id] - - player.start_action(RunecraftingAction.new(player, rune, altar.crafting_centre)) - message.terminate - end - end -end - -# An action that causes a mob to teleport when it comes within the specified distance of a -# specified position. -class TeleportAction < DistancedAction - attr_reader :teleport_position - - def initialize(mob, position, distance, teleport_position) - super(0, true, mob, position, distance) - @teleport_position = teleport_position - end - - def executeAction - mob.teleport(@teleport_position) - stop - end - - def equals(other) - get_class == other.get_class && mob == other.mob && - @teleport_position == other.teleport_position - end - -end - -# Appends an altar to the list. -def altar(name, hash) - unless hash.has_keys?(:entrance_altar, :crafting, :portal, :entrance, :exit, :altar_centre) - fail "#{name} is missing one of: entrance altar id, crafting altar id, entrance portal position, "\ - "and altar centre position." - end - - entrance_altar, crafting = hash[:entrance_altar], hash[:crafting] - portal_id = hash[:portal] - - entrance = Position.new(*hash[:entrance]) - exit_position = Position.new(*hash[:exit]) - centre = Position.new(*hash[:altar_centre]) - - altar = Altar.new(entrance_altar, crafting, portal_id, entrance, exit_position, centre) - PORTALS[portal_id] = ENTRANCE_ALTARS[entrance_altar] = CRAFTING_ALTARS[crafting] = altar -end - -altar :air, entrance_altar: 2452, crafting: 2478, portal: 2465, - entrance: [2841, 4829], exit: [2983, 3292], altar_centre: [2844, 4834] - -altar :mind, entrance_altar: 2453, crafting: 2479, portal: 2466, - entrance: [2793, 4828], exit: [2980, 3514], altar_centre: [2786, 4841] - -altar :water, entrance_altar: 2454, crafting: 2480, portal: 2467, - entrance: [2726, 4832], exit: [3187, 3166], altar_centre: [2716, 4836] - -altar :earth, entrance_altar: 2455, crafting: 2481, portal: 2468, - entrance: [2655, 4830], exit: [3304, 3474], altar_centre: [2658, 4841] - -altar :fire, entrance_altar: 2456, crafting: 2482, portal: 2469, - entrance: [2574, 4849], exit: [3311, 3256], altar_centre: [2585, 4838] - -altar :body, entrance_altar: 2457, crafting: 2483, portal: 2470, - entrance: [2524, 4825], exit: [3051, 3445], altar_centre: [2525, 4832] - -altar :cosmic, entrance_altar: 2458, crafting: 2484, portal: 2471, - entrance: [2142, 4813], exit: [2408, 4379], altar_centre: [2142, 4833] - -altar :law, entrance_altar: 2459, crafting: 2485, portal: 2472, - entrance: [2464, 4818], exit: [2858, 3379], altar_centre: [2464, 4832] - -altar :nature, entrance_altar: 2460, crafting: 2486, portal: 2473, - entrance: [2400, 4835], exit: [2867, 3019], altar_centre: [2400, 4841] - -altar :chaos, entrance_altar: 2461, crafting: 2487, portal: 2474, - entrance: [2268, 4842], exit: [3058, 3591], altar_centre: [2271, 4842] - -altar :death, entrance_altar: 2462, crafting: 2488, portal: 2475, - entrance: [2208, 4830], exit: [3222, 3222], altar_centre: [2205, 4836] diff --git a/game/data/plugins/skill/runecraft/plugin.xml b/game/data/plugins/skill/runecraft/plugin.xml deleted file mode 100644 index bdd1f063d..000000000 --- a/game/data/plugins/skill/runecraft/plugin.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - skill-runecraft - 0.9 - Runecraft - Adds the Runecraft skill. - - Major - BugCrusher - - - - - - - - - - util - - \ No newline at end of file diff --git a/game/data/plugins/skill/runecraft/rune.rb b/game/data/plugins/skill/runecraft/rune.rb deleted file mode 100644 index 37260f9b9..000000000 --- a/game/data/plugins/skill/runecraft/rune.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'java' - -# The hash of runes. -RUNES = {} - -# Represents a rune that can be crafted. -class Rune - attr_reader :name, :id, :level, :experience - - def initialize(id, level, experience, multiplier) - @id = id - @name = name_of(:item, id) - @level = level - @experience = experience - @multiplier = multiplier - end - - def equals(other) - get_class == other.get_class && id == other.id - end - - def multiplier(level) - @multiplier.call(level) - end - -end - -# Appends a rune to the list. -def rune(name, hash) - unless hash.has_keys?(:altar, :id, :level, :reward) - fail "#{name} is missing one of id, altar, level, or reward." - end - - id, altar, level, experience = hash[:id], hash[:altar], hash[:level], hash[:reward] - bonus = hash[:bonus] || ->(_) { 1 } - - RUNES[altar] = Rune.new(id, level, experience, bonus) -end - -rune :air, altar: 2478, id: 556, level: 1, reward: 5, bonus: ->(level) { (level / 11).floor + 1 } -rune :mind, altar: 2479, id: 558, level: 1, reward: 5.5, bonus: ->(level) { (level / 14).floor + 1 } -rune :water, altar: 2480, id: 555, level: 5, reward: 6, bonus: ->(level) { (level / 19).floor + 1 } -rune :earth, altar: 2481, id: 557, level: 9, reward: 6.5, - bonus: ->(level) { (level / 26).floor + 1 } -rune :fire, altar: 2482, id: 554, level: 14, reward: 7, bonus: ->(level) { (level / 35).floor + 1 } -rune :body, altar: 2483, id: 559, level: 20, reward: 7.5, - bonus: ->(level) { (level / 46).floor + 1 } -rune :cosmic, altar: 2484, id: 564, level: 27, reward: 8, bonus: ->(level) { level >= 59 ? 2 : 1 } -rune :chaos, altar: 2487, id: 562, level: 35, reward: 8.5, bonus: ->(level) { level >= 74 ? 2 : 1 } -rune :nature, altar: 2486, id: 561, level: 44, reward: 9, bonus: ->(level) { level >= 91 ? 2 : 1 } -rune :law, altar: 2485, id: 563, level: 54, reward: 9.5 -rune :death, altar: 2488, id: 560, level: 65, reward: 10 diff --git a/game/data/plugins/skill/runecraft/runecraft.rb b/game/data/plugins/skill/runecraft/runecraft.rb deleted file mode 100644 index bce1b0594..000000000 --- a/game/data/plugins/skill/runecraft/runecraft.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.action.DistancedAction' -java_import 'org.apollo.game.model.Animation' -java_import 'org.apollo.game.model.Graphic' -java_import 'org.apollo.game.model.entity.Skill' - -RUNECRAFTING_ANIMATION = Animation.new(791) -RUNECRAFTING_GRAPHIC = Graphic.new(186, 0, 100) - -RUNE_ESSENCE_ID = 1436 - -# An action when the player crafts a rune. -class RunecraftingAction < DistancedAction - attr_reader :player, :rune - - def initialize(player, rune, object_position) - super(1, true, player, object_position, 3) - @player = player - @rune = rune - @position = object_position - @executions = 0 - end - - def executeAction - runecrafting_level = @player.skill_set.get_skill(Skill::RUNECRAFT).current_level - - if runecrafting_level < @rune.level - @player.send_message("You need a runecrafting level of #{@rune.level} to craft this rune.") - stop - elsif !@player.inventory.contains(RUNE_ESSENCE_ID) - @player.send_message('You need rune essence to craft runes.') - stop - elsif @executions == 0 - @player.turn_to(@position) - @player.play_animation(RUNECRAFTING_ANIMATION) - @player.play_graphic(RUNECRAFTING_GRAPHIC) - @executions += 1 - elsif @executions == 1 - inventory = @player.inventory - removed = inventory.remove(RUNE_ESSENCE_ID, inventory.get_amount(RUNE_ESSENCE_ID)) - - added = removed * @rune.multiplier(runecrafting_level) - inventory.add(@rune.id, added) - - name = added > 1 ? 'some ' + @rune.name + 's' : 'an ' + @rune.name - @player.send_message("You craft the rune essence into #{name}.") - - @player.skill_set.add_experience(Skill::RUNECRAFT, removed * @rune.experience) - stop - end - end - - def equals(other) - get_class == other.get_class && @player == other.player && @rune == other.rune - end - -end diff --git a/game/data/plugins/skill/runecraft/talisman.rb b/game/data/plugins/skill/runecraft/talisman.rb deleted file mode 100644 index 16b6c6e8f..000000000 --- a/game/data/plugins/skill/runecraft/talisman.rb +++ /dev/null @@ -1,54 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.model.Position' - -# The list of talismans. -TALISMANS = {} - -# A talisman that will indicate a direction when activated. -class Talisman - - def initialize(entrance_altar_position) - @locate_position = entrance_altar_position - end - - def get_message(position) - return 'Your talisman glows brightly.' if position.is_within_distance(@locate_position, 10) - - direction = (position.y > @locate_position.y ? 'North' : 'South') + '-' - direction += (position.x > @locate_position.x ? 'East' : 'West') - - "The talisman pulls toward the #{direction}." - end - -end - -# Intercepts the item option message. -on :message, :fourth_item_option do |player, message| - talisman = TALISMANS[message.id] - - unless talisman.nil? - player.send_message(talisman.get_message(player.position)) - message.terminate - end -end - -# Appends a talisman to the list. -def talisman(name, hash) - fail 'Hash must contain an id and an altar position.' unless hash.has_keys?(:id, :altar) - id, altar_position = hash[:id], Position.new(*hash[:altar]) - - TALISMANS[id] = Talisman.new(altar_position) -end - -talisman :air_talisman, id: 1438, altar: [2985, 3292] -talisman :earth_talisman, id: 1440, altar: [3306, 3474] -talisman :fire_talisman, id: 1442, altar: [3313, 3255] -talisman :water_talisman, id: 1444, altar: [3185, 3165] -talisman :body_talisman, id: 1446, altar: [3053, 3445] -talisman :mind_talisman, id: 1448, altar: [2982, 3514] -talisman :chaos_talisman, id: 1452, altar: [3059, 3590] -talisman :cosmic_talisman, id: 1454, altar: [2408, 4377] -talisman :death_talisman, id: 1456, altar: [0, 0] -talisman :law_talisman, id: 1458, altar: [2858, 3381] -talisman :nature_talisman, id: 1462, altar: [2869, 3019] diff --git a/game/data/plugins/skill/runecraft/tiara.rb b/game/data/plugins/skill/runecraft/tiara.rb deleted file mode 100644 index 06701f262..000000000 --- a/game/data/plugins/skill/runecraft/tiara.rb +++ /dev/null @@ -1,167 +0,0 @@ -require 'java' - -java_import 'org.apollo.game.message.impl.ConfigMessage' -java_import 'org.apollo.game.model.entity.EquipmentConstants' -java_import 'org.apollo.game.action.DistancedAction' - -# The hash of tiaras. -TIARAS_BY_ALTAR = {} -TIARAS_BY_ID = {} -TIARAS_BY_TALISMAN = {} - -# A tiara will make an altar accessible with a single click. -class Tiara - attr_reader :altar, :bitshift, :tiara_id, :experience, :talisman - - def initialize(tiara_id, altar, talisman, bitshift, experience) - @tiara_id = tiara_id - @name = name_of(:item, tiara_id) - @altar = altar - @talisman = talisman - @bitshift = bitshift - @experience = experience - end - - # Sends a config message to change the altar object. - def send_config(player) - player.send(ConfigMessage.new(CHANGE_ALTAR_OBJECT_CONFIG, 1 << @bitshift)) - end - -end - -private - -# The id of the altar change config. -CHANGE_ALTAR_OBJECT_CONFIG = 491 - -# The id of the blank tiara. -TIARA_ITEM_ID = 5525 - -# Sends an empty altar config. -def send_empty_config(player) - player.send(ConfigMessage.new(CHANGE_ALTAR_OBJECT_CONFIG, 0)) -end - -# Sets the correct config upon login, if the player is wearing a tiara. -on :login do |_event, player| - hat = player.equipment.get(EquipmentConstants::HAT) - - unless hat.nil? - tiara = TIARAS_BY_ID[hat] - tiara.nil? ? send_empty_config(player) : tiara.send_config - end -end - -# Intercepts the SecondObjectAction message to support left-click access to the altar when wielding -# the correct tiara. -on :message, :second_object_action do |player, message| - object_id = message.id - tiara = TIARAS_BY_ALTAR[object_id] - next if tiara.nil? - - hat = player.equipment.get(EquipmentConstants::HAT) - - if !hat.nil? && hat.id == tiara.tiara_id - altar = ENTRANCE_ALTARS[tiara.altar] - message.terminate - - unless altar.nil? - player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position)) - end - end -end - -# Intercepts the SecondItemAction message to allow for config sending. -on :message, :second_item_option do |player, message| - tiara = TIARAS_BY_ID[message.id] - - unless tiara.nil? - tiara.send_config(player) - message.terminate - end -end - -# Intercepts the FirstItemAction message to allow for config sending. -on :message, :first_item_action do |player, message| - tiara = TIARAS_BY_ID[message.id] - - unless tiara.nil? - send_empty_config(player) - message.terminate - end -end - -# Intercepts the ItemOnObject message to create the tiara. -on :message, :item_on_object do |player, message| - tiara, altar = TIARAS_BY_TALISMAN[message.id], CRAFTING_ALTARS[message.object_id] - return if tiara.nil? || altar.nil? - - player.start_action(CreateTiaraAction.new(player, message.position, tiara, altar)) - message.terminate -end - -# An action lets the player create a tiara when it comes within the specified distance of a -# specified position. -# noinspection JRubyImplementInterfaceInspection -class CreateTiaraAction < DistancedAction - - # Creates the CreateTiaraAction. - def initialize(player, position, tiara, altar) - super(0, true, player, position, 2) - @player = player - @tiara = tiara - @altar = altar - end - - def execute_action - inventory = @player.inventory - - if inventory.contains_all(TIARA_ITEM_ID, @tiara.talisman) - if @tiara.altar == @altar.entrance_altar - inventory.remove(@tiara.talisman, TIARA_ITEM_ID) - inventory.add(@tiara.tiara_id) - - @player.skill_set.add_experience(RUNECRAFT_SKILL_ID, @tiara.experience) - @player.play_animation(RUNECRAFTING_ANIMATION) - @player.play_graphic(RUNECRAFTING_GRAPHIC) - else - @player.send_message('You can\'t use that talisman on this altar.') - end - else - @player.send_message('You need to have a talisman and blank tiara to enchant a tiara.') - end - - stop - end - - def equals(other) - get_class == other.get_class && @player == other.player && @tiara == other.tiara - end - -end - -# Appends a tiara to the list. -def tiara(_name, hash) - unless hash.has_keys?(:altar, :bitshift, :experience, :talisman, :tiara_id) - fail 'Hash must contain a tiara id, altar id, talisman id, a bitshift number, and experience.' - end - - tiara_id, altar, talisman = hash[:tiara_id], hash[:altar], hash[:talisman] - bitshift, experience = hash[:bitshift], hash[:experience] - - tiara = Tiara.new(tiara_id, altar, talisman, bitshift, experience) - TIARAS_BY_TALISMAN[talisman] = TIARAS_BY_ID[tiara_id] = TIARAS_BY_ALTAR[altar] = tiara -end - -tiara :air_tiara, tiara_id: 5527, altar: 2452, talisman: 1438, bitshift: 0, experience: 25 -tiara :mind_tiara, tiara_id: 5529, altar: 2453, talisman: 1448, bitshift: 1, experience: 27.5 -tiara :water_tiara, tiara_id: 5531, altar: 2454, talisman: 1444, bitshift: 2, experience: 30 -tiara :body_tiara, tiara_id: 5533, altar: 2457, talisman: 1446, bitshift: 5, experience: 37.5 -tiara :earth_tiara, tiara_id: 5535, altar: 2455, talisman: 1440, bitshift: 3, experience: 32.5 -tiara :fire_tiara, tiara_id: 5537, altar: 2456, talisman: 1442, bitshift: 4, experience: 35 -tiara :cosmic_tiara, tiara_id: 5539, altar: 2458, talisman: 1454, bitshift: 6, experience: 40 -tiara :nature_tiara, tiara_id: 5541, altar: 2460, talisman: 1462, bitshift: 8, experience: 45 -tiara :chaos_tiara, tiara_id: 5543, altar: 2461, talisman: 1452, bitshift: 9, experience: 42.5 -tiara :law_tiara, tiara_id: 5545, altar: 2459, talisman: 1458, bitshift: 7, experience: 47.5 -tiara :death_tiara, tiara_id: 5548, altar: 2462, talisman: 1456, bitshift: 10, experience: 50 -# TODO: there are 2 other altars, which probably just aren't spawned on the map diff --git a/game/data/plugins/util/command.rb b/game/data/plugins/util/command.rb deleted file mode 100644 index ad20d0681..000000000 --- a/game/data/plugins/util/command.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'java' - -java_import 'org.apollo.cache.def.ItemDefinition' -java_import 'org.apollo.cache.def.NpcDefinition' -java_import 'org.apollo.cache.def.ObjectDefinition' - -# Checks whether the amount of arguments provided is correct, sending the player the specified -# message if not. -def valid_arg_length(args, length, player, message) - valid = length.is_a?(Range) ? length.include?(args.length) : length == args.length - - player.send_message(message) unless valid - valid -end - -# Returns the name of the Object, Npc, or Item with the specified id. -def name_of(type, id) - types = [:object, :item, :npc] - unless types.include?(type) - fail "Invalid type of #{type} specified, must be one of #{types}" - end - - Kernel.const_get("#{type.capitalize}Definition").lookup(id).name.to_s -end - -# Monkey-patches Hash to add a has_keys? method. -class Hash - - def has_keys?(*keys) - keys.all? { |key| self.key?(key) } - end - -end - -# Monkey-patches Player to add a level? method. -class Player - - # Returns whether or not the player's current level is greater than or equal to the specified - # level. - def level?(skill, level) - skill_set.get_skill(skill).current_level >= level - end - -end diff --git a/game/data/plugins/util/name_lookup.rb b/game/data/plugins/util/name_lookup.rb deleted file mode 100644 index c966a6d60..000000000 --- a/game/data/plugins/util/name_lookup.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'java' - -# Looks up the id of the npc with the specified name. -def lookup_npc(name) - lookup_entity(:npc, name) -end - -# Looks up the id of the item with the specified name. -def lookup_item(name) - lookup_entity(:item, name) -end - -# Looks up the id of the object with the specified name. -def lookup_object(name) - lookup_entity(:object, name) -end - -# Looks up the id of an entity of the specified type (either :npc, :item, or :object) -def lookup_entity(type, name) - type = type.to_s - name = name.to_s.gsub('_', ' ') - - cached = NAME_CACHE[type + name] - return cached unless cached.nil? - - id = name[name.rindex(' ') + 1, name.length - 1].to_i if name.include?(' ') - id = find_entities(type, name, 1).first if id.nil? || id.zero? - - fail "The #{type} called #{name} could not be identified." if id.nil? - - NAME_CACHE[type + name] = id - id -end - -# Finds entities with the specified type (e.g. npc) and name, returning possible ids as an array. -def find_entities(type, name, limit = 5) - ids = [] - name.downcase! - - Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition| - break if (ids.length == limit) - ids << definition.id.to_i if definition.name.to_s.downcase == name - end - - ids -end - -private - -NAME_CACHE = {} # Primitive, caching all may not be desirable. diff --git a/game/data/plugins/util/plugin.xml b/game/data/plugins/util/plugin.xml deleted file mode 100644 index bc4b98154..000000000 --- a/game/data/plugins/util/plugin.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - util - 1 - Util - Adds utility methods for plugins. - - Major - - - - - - - diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java index 1e0967e83..474ade619 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java @@ -4,19 +4,19 @@ public class IfMoveSubMessage extends Message { - private final int fromComponent; - private final int toComponent; + private final int fromPackedInterface; + private final int toPackedInterface; - public IfMoveSubMessage(int fromComponent, int toComponent) { - this.fromComponent = fromComponent; - this.toComponent = toComponent; + public IfMoveSubMessage(int fromPackedInterface, int toPackedInterface) { + this.fromPackedInterface = fromPackedInterface; + this.toPackedInterface = toPackedInterface; } - public int getFromComponent() { - return fromComponent; + public int getFromPackedInterface() { + return fromPackedInterface; } - public int getToComponent() { - return toComponent; + public int getToPackedInterface() { + return toPackedInterface; } } diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java index 19c6fc9fd..090a0474b 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java @@ -13,7 +13,7 @@ public final class IfOpenSubMessage extends Message { /** * The parent interface. */ - private final int parentComponent; + private final int packedParentInterface; /** * The type of the interface. @@ -28,12 +28,12 @@ public final class IfOpenSubMessage extends Message { /** * Creates the message with the specified interface id. * - * @param parentComponent the parent component + * @param packedParentInterface the parent component * @param type the type * @param id the id */ - public IfOpenSubMessage(int parentComponent, ClientInterfaceType type, int id) { - this.parentComponent = parentComponent; + public IfOpenSubMessage(int packedParentInterface, ClientInterfaceType type, int id) { + this.packedParentInterface = packedParentInterface; this.type = type; this.id = id; } @@ -52,8 +52,8 @@ public int getId() { * * @return the parent component */ - public int getParentComponent() { - return parentComponent; + public int getPackedParentInterface() { + return packedParentInterface; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetEventMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetEventMessage.java new file mode 100644 index 000000000..f891d38d5 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetEventMessage.java @@ -0,0 +1,35 @@ +package org.apollo.game.message.impl.encode; + +import kotlin.ranges.IntRange; +import org.apollo.game.model.inter.InterfaceEvent; +import org.apollo.net.message.Message; + +import java.util.EnumSet; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetEventMessage extends Message { + + private final int packedInterface; + private final IntRange range; + private final EnumSet events; + + public IfSetEventMessage(int packedInterface, IntRange range, EnumSet events) { + this.packedInterface = packedInterface; + this.range = range; + this.events = events; + } + + public int getPackedInterface() { + return packedInterface; + } + + public IntRange getRange() { + return range; + } + + public EnumSet getEvents() { + return events; + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 0ce8a6d1a..ea4f657a1 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -23,10 +23,7 @@ import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; -import org.apollo.game.release.r181.encoders.ui.ConfigMessageEncoder; -import org.apollo.game.release.r181.encoders.ui.IfMoveSubMessageEncoder; -import org.apollo.game.release.r181.encoders.ui.IfOpenSubMessageEncoder; -import org.apollo.game.release.r181.encoders.ui.IfOpenTopMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.*; import org.apollo.net.meta.PacketMetaDataGroup; import org.apollo.net.release.Release; @@ -153,6 +150,7 @@ private void init() { register(IfOpenTopMessage.class, new IfOpenTopMessageEncoder()); register(IfOpenSubMessage.class, new IfOpenSubMessageEncoder()); register(IfMoveSubMessage.class, new IfMoveSubMessageEncoder()); + register(IfSetEventMessage.class, new IfSetEventMessageEncoder()); register(ServerChatMessage.class, new ServerChatMessageEncoder()); register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java index 5a6d166e0..ee1181866 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java @@ -12,8 +12,8 @@ public class IfMoveSubMessageEncoder extends MessageEncoder { @Override public GamePacket encode(IfMoveSubMessage message) { GamePacketBuilder builder = new GamePacketBuilder(82, PacketType.FIXED); - builder.put(DataType.INT, message.getToComponent()); - builder.put(DataType.INT, message.getFromComponent()); + builder.put(DataType.INT, message.getToPackedInterface()); + builder.put(DataType.INT, message.getFromPackedInterface()); return builder.toGamePacket(); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java index 235cc08db..321101323 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java @@ -10,7 +10,7 @@ public class IfOpenSubMessageEncoder extends MessageEncoder { public GamePacket encode(IfOpenSubMessage message) { GamePacketBuilder builder = new GamePacketBuilder(77, PacketType.FIXED); builder.put(DataType.BYTE, DataTransformation.ADD, message.getType().ordinal()); - builder.put(DataType.INT, DataOrder.MIDDLE, message.getParentComponent()); + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedParentInterface()); builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); return builder.toGamePacket(); } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java new file mode 100644 index 000000000..9748c23b7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.encoders.ui; + +import it.unimi.dsi.fastutil.ints.IntCollection; +import org.apollo.game.message.impl.encode.IfSetEventMessage; +import org.apollo.game.model.inter.InterfaceEvent; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +import java.util.stream.Collectors; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetEventMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetEventMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(48, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.LITTLE, message.getEvents().stream().mapToInt(InterfaceEvent::getMask).sum()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getRange().getEndInclusive()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, message.getRange().getStart()); + + return builder.toGamePacket(); + } +} diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java index be888724c..5a5483b8d 100644 --- a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java @@ -29,20 +29,22 @@ protected void encode(ChannelHandlerContext ctx, OnDemandResponse response, Byte buf.writeByte(compression); int bytes = container.readableBytes(); - if (bytes > 508) - bytes = 508; + if (bytes > 508) bytes = 508; buf.writeBytes(container.readBytes(bytes)); - for (;;) { + for (; ; ) { bytes = container.readableBytes(); - if (bytes == 0) + if (bytes == 0) { break; - else if (bytes > 511) - bytes = 511; + } else if (bytes > 511) bytes = 511; buf.writeByte(0xFF); - buf.writeBytes(container.readBytes(bytes)); + + final var payload = container.readBytes(bytes); + buf.writeBytes(payload); + + payload.release(); } } } \ No newline at end of file From 060053eb6d16b394f51e20f91a68aaf9ac786f26 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 22 Mar 2020 14:46:28 -0400 Subject: [PATCH 26/63] Added SetPlayerActionMessageEncoder message. Added KeepAliveMessageDecoder message. --- .../decoder/rsenum/EnumDefinitionDecoder.java | 2 +- .../plugin/entity/actions/src/playerAction.kt | 2 +- .../entity/actions/test/PlayerActionTests.kt | 2 +- .../impl/decode/EventMouseMoveMessage.java | 31 +++++++ .../{ => encode}/SetPlayerActionMessage.java | 2 +- .../apollo/game/release/r181/Release181.java | 19 ++++- .../r181/decoders/EventMouseMoveDecoder.java | 85 +++++++++++++++++++ .../obj/SpamPacketMessageDecoder.java | 3 +- .../player/SetPlayerActionMessageEncoder.java | 23 +++++ 9 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/message/impl/decode/EventMouseMoveMessage.java rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/SetPlayerActionMessage.java (97%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/EventMouseMoveDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/SetPlayerActionMessageEncoder.java diff --git a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java index f690ec9b2..f2405b880 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java @@ -9,7 +9,7 @@ import org.apollo.cache.def.EnumDefinition; /** - * Decodes item data from the {@code obj.dat} file into {@link EnumDefinition}s. + * Decodes archive two folder eight into {@link EnumDefinition}s. * * @author Cjay0091 */ diff --git a/game/plugin/entity/actions/src/playerAction.kt b/game/plugin/entity/actions/src/playerAction.kt index d08b77974..f20c8f090 100644 --- a/game/plugin/entity/actions/src/playerAction.kt +++ b/game/plugin/entity/actions/src/playerAction.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.entity.actions import java.util.* -import org.apollo.game.message.impl.SetPlayerActionMessage +import org.apollo.game.message.impl.encode.SetPlayerActionMessage import org.apollo.game.model.entity.Player fun Player.enableAction(action: PlayerActionType) { diff --git a/game/plugin/entity/actions/test/PlayerActionTests.kt b/game/plugin/entity/actions/test/PlayerActionTests.kt index 153345d0b..03c2423c4 100644 --- a/game/plugin/entity/actions/test/PlayerActionTests.kt +++ b/game/plugin/entity/actions/test/PlayerActionTests.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.entity.actions import io.mockk.verify -import org.apollo.game.message.impl.SetPlayerActionMessage +import org.apollo.game.message.impl.encode.SetPlayerActionMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.api.annotations.TestMock diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/EventMouseMoveMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/EventMouseMoveMessage.java new file mode 100644 index 000000000..b9e6641f9 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/EventMouseMoveMessage.java @@ -0,0 +1,31 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class EventMouseMoveMessage extends Message { + + private final int x; + private final int y; + private final int dt; + + public EventMouseMoveMessage(int x, int y, int dt) { + this.x = x; + this.y = y; + this.dt = dt; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getDt() { + return dt; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetPlayerActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SetPlayerActionMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/SetPlayerActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/SetPlayerActionMessage.java index 4db7ceefc..1bb17453f 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetPlayerActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SetPlayerActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index ea4f657a1..d48ca9bc4 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -22,6 +22,7 @@ import org.apollo.game.release.r181.encoders.UpdateWeightMessageEncoder; import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; +import org.apollo.game.release.r181.encoders.player.SetPlayerActionMessageEncoder; import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; import org.apollo.game.release.r181.encoders.ui.*; import org.apollo.net.meta.PacketMetaDataGroup; @@ -147,20 +148,22 @@ private void init() { * Server */ + register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); + register(IfOpenTopMessage.class, new IfOpenTopMessageEncoder()); register(IfOpenSubMessage.class, new IfOpenSubMessageEncoder()); register(IfMoveSubMessage.class, new IfMoveSubMessageEncoder()); register(IfSetEventMessage.class, new IfSetEventMessageEncoder()); - register(ServerChatMessage.class, new ServerChatMessageEncoder()); register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); - register(ConfigMessage.class, new ConfigMessageEncoder()); register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); + register(ConfigMessage.class, new ConfigMessageEncoder()); + register(ServerChatMessage.class, new ServerChatMessageEncoder()); /** * Client @@ -218,7 +221,6 @@ private void init() { register(75, new SeventhPlayerActionMessageDecoder()); register(50, new EightPlayerActionMessageDecoder()); - /** * NPC */ @@ -243,13 +245,22 @@ private void init() { * Floor Items */ - register(38, new ReportAbuseMessageDecoder()); register(73, new FocusUpdateMessageDecoder()); register(60, new CommandMessageDecoder()); register(41, new MouseClickedMessageDecoder()); register(22, new KeepAliveMessageDecoder()); + /** + * Misc + */ + { + //register(34, new EventMouseMoveDecoder()); TODO this later for now using spam + register(34, new SpamPacketMessageDecoder()); + } + register(49, new KeepAliveMessageDecoder()); + + //TODO register completed client prot here. } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/EventMouseMoveDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/EventMouseMoveDecoder.java new file mode 100644 index 000000000..75e32932f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/EventMouseMoveDecoder.java @@ -0,0 +1,85 @@ +package org.apollo.game.release.r181.decoders; + +import org.apollo.game.message.impl.decode.EventMouseMoveMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class EventMouseMoveDecoder extends MessageDecoder { + @Override + public EventMouseMoveMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int length = packet.getLength(); + + int count1 = (int) reader.getUnsigned(DataType.BYTE); + int count2 = (int) reader.getUnsigned(DataType.BYTE); + + int dt = 0; + int dx = 0xFFFF; + int dy = 0xFFFF; + + if (length == Short.BYTES) { + int packed = (int) reader.getSigned(DataType.BYTE); + dy = packed & 0x3F; + dx = (packed >> 6) & 0x3F; + dt = (packed >> 12) & 0xF; + } else if (length == Byte.BYTES + Short.BYTES) { + dt = (int) reader.getSigned(DataType.BYTE); + int packed = (int) reader.getSigned(DataType.SHORT); + dy = packed & 0xFF; + dx = (packed >> 8) & 0xFF; + } else if (length == Byte.BYTES + Integer.BYTES) { + dt = (int) reader.getSigned(DataType.BYTE); + int packed = (int) reader.getSigned(DataType.INT); + dx = packed & 0xFF; + dy = (packed >> 16) & 0xFF; + } else if (length == Short.BYTES + Integer.BYTES) { + dt = (int) reader.getSigned(DataType.SHORT); + int packed = (int) reader.getSigned(DataType.INT); + dx = packed & 0xFF; + dy = (packed >> 16) & 0xFF; + } else { + //throw new IllegalStateException("Length of " + length + " condition has been accessed."); + } + + //System.out.println(count1 + " " + " " + count2 + " " + dt + " " + dx + " " + dy); + + + /** + * if (dt < 8 && dx >= -32 && dx <= 31 && dy >= -32 && dy <= 31) { + * dx += 32; + * dy += 32; + * + * frame.payload.writeShort(dy + (dx << 6) + (dt << 12)); + * } else if (dt < 32 && dx >= -128 && dx <= 127 && dy >= -128 && dy <= 127) { + * dx += 128; + * dy += 128; + * + * frame.payload.writeByte(dt + 128); + * frame.payload.writeShort(dy + (dx << 8)); + * } else if (dt < 32) { + * frame.payload.writeByte(192 + dt); + * + * if (-1 == x || -1 == y) { + * frame.payload.writeInt(-2147483648); + * } else { + * frame.payload.writeInt(x | y << 16); + * } + * } else { + * frame.payload.writeShort((dt & 0x1fff) + 57344); + * if (-1 == x || -1 == y) { + * frame.payload.writeInt(-2147483648); + * } else { + * frame.payload.writeInt(x | y << 16); + * } + * } + */ + + return new EventMouseMoveMessage(dx, dy, dt); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java index 3ecb0120b..3a93b9f1a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java @@ -1,5 +1,6 @@ package org.apollo.game.release.r181.decoders.obj; +import io.netty.buffer.ByteBufUtil; import org.apollo.game.message.impl.SpamPacketMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageDecoder; @@ -13,7 +14,7 @@ public final class SpamPacketMessageDecoder extends MessageDecoder { + @Override + public GamePacket encode(SetPlayerActionMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(66, PacketType.VARIABLE_BYTE); + builder.put(DataType.BYTE, DataTransformation.ADD, message.isPrimaryAction() ? 0 : 1); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getSlot()); + builder.putString(message.getText()); + return builder.toGamePacket(); + } +} From 948fad1d2f2636e78d6a1d28d4c248e8fd381c2d Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 22 Mar 2020 19:26:18 -0400 Subject: [PATCH 27/63] Inventory messages are complete. --- .../game/plugin/shops/OpenShopAction.kt | 10 ++-- .../game/plugin/shops/ShopInterfaces.kt | 19 +++----- .../apollo/game/plugin/shops/Shops.plugin.kts | 12 ++--- .../message/handler/BankMessageHandler.java | 6 +-- .../ItemOnItemVerificationHandler.java | 4 +- .../ItemOnObjectVerificationHandler.java | 2 +- .../handler/ItemVerificationHandler.java | 4 +- .../handler/SwitchItemMessageHandler.java | 4 +- ...e.java => UpdateInventoryFullMessage.java} | 34 +++++++++++++- ...ava => UpdateInventoryPartialMessage.java} | 36 +++++++++++++-- .../impl/decode/MapBuildCompleteMessage.java | 9 ++++ .../impl/{ => decode}/SpamPacketMessage.java | 2 +- .../org/apollo/game/model/entity/Player.java | 27 ++++++----- .../game/model/inter/bank/BankConstants.java | 17 ++++--- .../inv/SynchronizationInventoryListener.java | 33 +++++++++---- .../apollo/game/release/r181/Release181.java | 27 ++++++++--- .../r181/decoders/ArrowKeyMessageDecoder.java | 2 +- .../r181/decoders/CommandMessageDecoder.java | 2 +- .../decoders/FocusUpdateMessageDecoder.java | 2 +- .../decoders/KeepAliveMessageDecoder.java | 2 +- .../decoders/MouseClickedMessageDecoder.java | 2 +- .../ClosedInterfaceMessageDecoder.java | 2 +- .../EnteredAmountMessageDecoder.java | 2 +- .../map/MapRebuildCompleteDecoder.java | 15 ++++++ .../{ => map}/WalkMessageDecoder.java | 4 +- .../npc/FifthNpcActionMessageDecoder.java | 4 +- .../npc/FirstNpcActionMessageDecoder.java | 4 +- .../npc/FourthNpcActionMessageDecoder.java | 4 +- .../npc/SecondNpcActionMessageDecoder.java | 4 +- .../npc/SixthNpcActionMessageDecoder.java | 4 +- .../npc/ThirdNpcActionMessageDecoder.java | 4 +- .../obj/FifthObjectActionMessageDecoder.java | 4 +- .../obj/FirstObjectActionMessageDecoder.java | 4 +- .../obj/FourthObjectActionMessageDecoder.java | 4 +- .../obj/SecondObjectActionMessageDecoder.java | 4 +- .../obj/SixthObjectActionMessageDecoder.java | 4 +- .../obj/SpamPacketMessageDecoder.java | 6 +-- .../obj/ThirdObjectActionMessageDecoder.java | 4 +- .../player/ReportAbuseMessageDecoder.java | 4 +- .../EightPlayerActionMessageDecoder.java | 4 +- .../FifthPlayerActionMessageDecoder.java | 4 +- .../FirstPlayerActionMessageDecoder.java | 4 +- .../FourthPlayerActionMessageDecoder.java | 4 +- .../SecondPlayerActionMessageDecoder.java | 4 +- .../SeventhPlayerActionMessageDecoder.java | 4 +- .../SixthPlayerActionMessageDecoder.java | 4 +- .../ThirdPlayerActionMessageDecoder.java | 4 +- .../social/PrivateChatMessageDecoder.java | 2 +- .../friends/AddFriendMessageDecoder.java | 2 +- .../friends/RemoveFriendMessageDecoder.java | 2 +- .../ignores/AddIgnoreMessageDecoder.java | 2 +- .../ignores/RemoveIgnoreMessageDecoder.java | 2 +- .../UpdateRunEnergyMessageEncoder.java | 2 +- .../encoders/UpdateSkillMessageEncoder.java | 2 +- .../encoders/UpdateWeightMessageEncoder.java | 2 +- .../npc/NpcSynchronizationMessageEncoder.java | 2 +- .../region/RebuildNormalMessageEncoder.java | 2 +- .../encoders/ui/ConfigMessageEncoder.java | 2 +- .../UpdateContainerFullMessageEncoder.java | 46 +++++++++++++++++++ .../UpdateContainerPartialMessageEncoder.java | 46 +++++++++++++++++++ .../ItemOnItemVerificationHandlerTests.java | 4 +- 61 files changed, 345 insertions(+), 142 deletions(-) rename game/src/main/java/org/apollo/game/message/impl/{UpdateItemsMessage.java => UpdateInventoryFullMessage.java} (56%) rename game/src/main/java/org/apollo/game/message/impl/{UpdateSlottedItemsMessage.java => UpdateInventoryPartialMessage.java} (55%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/decode/MapBuildCompleteMessage.java rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/SpamPacketMessage.java (92%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/map/MapRebuildCompleteDecoder.java rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/WalkMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/npc/FifthNpcActionMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/npc/FirstNpcActionMessageDecoder.java (88%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/npc/FourthNpcActionMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/npc/SecondNpcActionMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/npc/SixthNpcActionMessageDecoder.java (89%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/npc/ThirdNpcActionMessageDecoder.java (88%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/obj/FifthObjectActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/obj/FirstObjectActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/obj/FourthObjectActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/obj/SecondObjectActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/obj/SixthObjectActionMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/obj/SpamPacketMessageDecoder.java (74%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/obj/ThirdObjectActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/ReportAbuseMessageDecoder.java (90%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/EightPlayerActionMessageDecoder.java (87%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/FifthPlayerActionMessageDecoder.java (89%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/FirstPlayerActionMessageDecoder.java (87%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/FourthPlayerActionMessageDecoder.java (88%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/SecondPlayerActionMessageDecoder.java (89%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/SeventhPlayerActionMessageDecoder.java (87%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/SixthPlayerActionMessageDecoder.java (89%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{ => map}/player/actions/ThirdPlayerActionMessageDecoder.java (89%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt b/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt index 6718cdcab..f6a5fe9e9 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt @@ -2,7 +2,6 @@ package org.apollo.game.plugin.shops import org.apollo.game.action.DistancedAction import org.apollo.game.message.handler.ItemVerificationHandler -import org.apollo.game.message.impl.SetWidgetTextMessage import org.apollo.game.model.entity.Mob import org.apollo.game.model.entity.Player import org.apollo.game.model.inter.InterfaceListener @@ -23,10 +22,9 @@ class OpenShopAction( mob.interactingMob = operator val closeListener = addInventoryListeners(mob, shop.inventory) - mob.send(SetWidgetTextMessage(ShopInterfaces.SHOP_NAME, shop.name)) - mob.interfaceSet.openModal(closeListener, ShopInterfaces.SHOP_WINDOW); - mob.interfaceSet.openTopLevel(ShopInterfaces.INVENTORY_SIDEBAR, TopLevelPosition.INVENTORY_TAB) + mob.interfaceSet.openModal(closeListener, ShopInterfaces.SHOP_INTERFACE); + mob.interfaceSet.openTopLevel(ShopInterfaces.INVENTORY_INTERFACE, TopLevelPosition.INVENTORY_TAB) stop() } @@ -35,8 +33,8 @@ class OpenShopAction( * [InterfaceListener] that removes them when the interface is closed. */ private fun addInventoryListeners(player: Player, shop: Inventory): InterfaceListener { - val invListener = SynchronizationInventoryListener(player, ShopInterfaces.INVENTORY_CONTAINER) - val shopListener = SynchronizationInventoryListener(player, ShopInterfaces.SHOP_CONTAINER) + val invListener = SynchronizationInventoryListener(player, ShopInterfaces.INVENTORY_INTERFACE, ShopInterfaces.INVENTORY_COMPONENT, SynchronizationInventoryListener.INVENTORY_INVENTORY) + val shopListener = SynchronizationInventoryListener(player, ShopInterfaces.SHOP_INTERFACE, ShopInterfaces.SHOP_COMPONENT, ShopInterfaces.SHOP_CONTAINER_ID) player.inventory.addListener(invListener) player.inventory.forceRefresh() diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt b/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt index 4a678bd8f..1f3ef6ce0 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt @@ -8,26 +8,19 @@ internal object ShopInterfaces { /** * The container interface id for the player's inventory. */ - const val INVENTORY_CONTAINER = 3823 - - /** - * The sidebar id for the inventory, when a Shop window is open. - */ - const val INVENTORY_SIDEBAR = 3822 - - /** - * The shop window interface id. - */ - const val SHOP_WINDOW = 3824 + const val INVENTORY_INTERFACE = 301 + const val INVENTORY_COMPONENT = 0 /** * The container interface id for the shop's inventory. */ - const val SHOP_CONTAINER = 3900 + const val SHOP_INTERFACE = 300 + const val SHOP_COMPONENT = 16 + const val SHOP_CONTAINER_ID = 16 /** * The id of the text widget that displays a shop's name. */ - const val SHOP_NAME = 3901 + const val SHOP_NAME_CLIENTSCRIPT = 1074 } \ No newline at end of file diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts index 4d3be298d..9fdeab311 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts @@ -9,8 +9,8 @@ import org.apollo.game.scheduling.ScheduledTask fun Mob.shop(): Shop? = SHOPS[definition.id] start { world -> - ItemVerificationHandler.addInventory(ShopInterfaces.SHOP_CONTAINER) { it.interactingMob?.shop()?.inventory } - ItemVerificationHandler.addInventory(ShopInterfaces.INVENTORY_CONTAINER, PlayerInventorySupplier) + ItemVerificationHandler.addInventory(ShopInterfaces.SHOP_INTERFACE) { it.interactingMob?.shop()?.inventory } + ItemVerificationHandler.addInventory(ShopInterfaces.INVENTORY_INTERFACE, PlayerInventorySupplier) world.schedule(object : ScheduledTask(Shop.RESTOCK_INTERVAL, false) { override fun execute() = SHOPS.values.distinct().forEach(Shop::restock) @@ -30,16 +30,16 @@ on { NpcActionMessage::class } on { ItemActionMessage::class } - .where { interfaceId == ShopInterfaces.SHOP_CONTAINER || interfaceId == ShopInterfaces.INVENTORY_CONTAINER } + .where { interfaceId == ShopInterfaces.SHOP_INTERFACE || interfaceId == ShopInterfaces.INVENTORY_INTERFACE } .then { player -> - if (ShopInterfaces.SHOP_WINDOW !in player.interfaceSet) { + if (ShopInterfaces.SHOP_INTERFACE !in player.interfaceSet) { return@then } val shop = player.interactingMob?.shop() ?: return@then when (interfaceId) { - ShopInterfaces.INVENTORY_CONTAINER -> shop.buy(player, slot, option) - ShopInterfaces.SHOP_CONTAINER -> shop.sell(player, slot, option) + ShopInterfaces.INVENTORY_INTERFACE -> shop.buy(player, slot, option) + ShopInterfaces.SHOP_INTERFACE -> shop.sell(player, slot, option) else -> error("Supposedly unreacheable case.") } diff --git a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java index f06362ba8..abb7aca73 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java @@ -52,11 +52,11 @@ public BankMessageHandler(World world) { @Override public void handle(Player player, ItemActionMessage message) { if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { - if (message.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) { + //if (message.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) { deposit(player, message); - } else if (message.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) { + } else if (message.getInterfaceId() == BankConstants.INVENTORY_INTERFACE) { withdraw(player, message); - } + // } } } diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java index 019a23e32..9ea3098e0 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java @@ -30,13 +30,13 @@ public void handle(Player player, ItemOnItemMessage message) { switch (message.getInterfaceId()) { case SynchronizationInventoryListener.INVENTORY_ID: - case BankConstants.SIDEBAR_INVENTORY_ID: + case BankConstants.BANK_CONTAINER_COMPONENT: inventory = player.getInventory(); break; case SynchronizationInventoryListener.EQUIPMENT_ID: inventory = player.getEquipment(); break; - case BankConstants.BANK_INVENTORY_ID: + case BankConstants.INVENTORY_INTERFACE: inventory = player.getBank(); break; default: diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java index 89a9260c0..4ce595a30 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java @@ -33,7 +33,7 @@ public ItemOnObjectVerificationHandler(World world) { @Override public void handle(Player player, ItemOnObjectMessage message) { - if (message.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID && message.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) { + if (message.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID && message.getInterfaceId() != BankConstants.INVENTORY_INTERFACE) { message.terminate(); return; } diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java index 666e250e2..ebd86f2b7 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java @@ -44,9 +44,9 @@ public interface InventorySupplier { static { inventories.put(SynchronizationInventoryListener.INVENTORY_ID, Player::getInventory); - inventories.put(BankConstants.SIDEBAR_INVENTORY_ID, Player::getInventory); + inventories.put(BankConstants.INVENTORY_INTERFACE, Player::getInventory); inventories.put(SynchronizationInventoryListener.EQUIPMENT_ID, Player::getEquipment); - inventories.put(BankConstants.BANK_INVENTORY_ID, Player::getBank); + inventories.put(BankConstants.BANK_WINDOW_ID, Player::getBank); } /** diff --git a/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java index 5cfd0766d..84a379ad9 100644 --- a/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java @@ -31,13 +31,13 @@ public void handle(Player player, SwitchItemMessage message) { switch (message.getInterfaceId()) { case SynchronizationInventoryListener.INVENTORY_ID: - case BankConstants.SIDEBAR_INVENTORY_ID: + case BankConstants.INVENTORY_INTERFACE: inventory = player.getInventory(); break; case SynchronizationInventoryListener.EQUIPMENT_ID: inventory = player.getEquipment(); break; - case BankConstants.BANK_INVENTORY_ID: + case BankConstants.BANK_WINDOW_ID: inventory = player.getBank(); insertPermitted = true; break; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateItemsMessage.java b/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryFullMessage.java similarity index 56% rename from game/src/main/java/org/apollo/game/message/impl/UpdateItemsMessage.java rename to game/src/main/java/org/apollo/game/message/impl/UpdateInventoryFullMessage.java index 662c0a253..a5b77eec2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateItemsMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryFullMessage.java @@ -8,13 +8,23 @@ * * @author Graham */ -public final class UpdateItemsMessage extends Message { +public final class UpdateInventoryFullMessage extends Message { /** * The interface id. */ private final int interfaceId; + /** + * The component. + */ + private final int component; + + /** + * The id of this inventory. + */ + private final int inventory; + /** * The items. */ @@ -26,8 +36,10 @@ public final class UpdateItemsMessage extends Message { * @param interfaceId The interface id. * @param items The items. */ - public UpdateItemsMessage(int interfaceId, Item[] items) { + public UpdateInventoryFullMessage(int interfaceId, int component, int inventory, Item[] items) { this.interfaceId = interfaceId; + this.component = component; + this.inventory = inventory; this.items = items; } @@ -40,6 +52,24 @@ public int getInterfaceId() { return interfaceId; } + /** + * Gets the component. + * + * @return The component. + */ + public int getComponent() { + return component; + } + + /** + * Gets container id. + * + * @return the container id + */ + public int getInventory() { + return inventory; + } + /** * Gets the items. * diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateSlottedItemsMessage.java b/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryPartialMessage.java similarity index 55% rename from game/src/main/java/org/apollo/game/message/impl/UpdateSlottedItemsMessage.java rename to game/src/main/java/org/apollo/game/message/impl/UpdateInventoryPartialMessage.java index e0848096a..4805b08c5 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateSlottedItemsMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryPartialMessage.java @@ -8,13 +8,23 @@ * * @author Graham */ -public final class UpdateSlottedItemsMessage extends Message { +public final class UpdateInventoryPartialMessage extends Message { /** * The interface id. */ private final int interfaceId; + /** + * The component. + */ + private final int component; + + /** + * The id of this container. + */ + private final int containerId; + /** * The slotted items. */ @@ -24,10 +34,12 @@ public final class UpdateSlottedItemsMessage extends Message { * Creates the update item in interface message. * * @param interfaceId The interface id. - * @param items The slotted items. + * @param items The slotted items. */ - public UpdateSlottedItemsMessage(int interfaceId, SlottedItem... items) { + public UpdateInventoryPartialMessage(int interfaceId, int containerId, int component, SlottedItem... items) { this.interfaceId = interfaceId; + this.component = component; + this.containerId = containerId; this.items = items; } @@ -40,6 +52,24 @@ public int getInterfaceId() { return interfaceId; } + /** + * Gets the component. + * + * @return The component. + */ + public int getComponent() { + return component; + } + + /** + * Gets container id. + * + * @return the container id + */ + public int getContainerId() { + return containerId; + } + /** * Gets an array of slotted items. * diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/MapBuildCompleteMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MapBuildCompleteMessage.java new file mode 100644 index 000000000..302042b57 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MapBuildCompleteMessage.java @@ -0,0 +1,9 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class MapBuildCompleteMessage extends Message { +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SpamPacketMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/SpamPacketMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/SpamPacketMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/SpamPacketMessage.java index e554f4000..1514ee5dc 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SpamPacketMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/SpamPacketMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 1238a81ce..b79e3984e 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -215,9 +215,9 @@ private static int nextAppearanceTicket() { /** * Creates the Player. * - * @param world The {@link World} containing the Player. + * @param world The {@link World} containing the Player. * @param credentials The player's credentials. - * @param position The initial position. + * @param position The initial position. */ public Player(World world, PlayerCredentials credentials, Position position) { super(world, position); @@ -640,8 +640,10 @@ public void logout() { * Opens this player's bank. */ public void openBank() { - InventoryListener invListener = new SynchronizationInventoryListener(this, BankConstants.SIDEBAR_INVENTORY_ID); - InventoryListener bankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID); + InventoryListener invListener = new SynchronizationInventoryListener(this, BankConstants.INVENTORY_INTERFACE, + BankConstants.BANK_INVENTORY_COMPONENT, SynchronizationInventoryListener.INVENTORY_INVENTORY); + InventoryListener bankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_WINDOW_ID, + BankConstants.BANK_CONTAINER_COMPONENT, BankConstants.BANK_INVENTORY); inventory.addListener(invListener); bank.addListener(bankListener); @@ -650,7 +652,7 @@ public void openBank() { InterfaceListener interListener = new BankInterfaceListener(this, invListener, bankListener); interfaceSet.openModal(interListener, BankConstants.BANK_WINDOW_ID); - interfaceSet.openTopLevel(BankConstants.SIDEBAR_INVENTORY_ID, TopLevelPosition.INVENTORY_TAB); + interfaceSet.openTopLevel(BankConstants.INVENTORY_INTERFACE, TopLevelPosition.INVENTORY_TAB); } /** @@ -926,7 +928,7 @@ public void setTradePrivacy(PrivacyState tradePrivacy) { * Sets whether or not the player is withdrawing notes from the bank. * * @param withdrawingNotes Whether or not the player is withdrawing noted - * items. + * items. */ public void setWithdrawingNotes(boolean withdrawingNotes) { this.withdrawingNotes = withdrawingNotes; @@ -965,7 +967,7 @@ public void teleport(Position position) { @Override public String toString() { return MoreObjects.toStringHelper(this).add("username", getUsername()).add("privilege", privilegeLevel) - .toString(); + .toString(); } /** @@ -998,19 +1000,17 @@ private void init() { */ private void initInventories() { InventoryListener fullInventory = new FullInventoryListener(this, FullInventoryListener.FULL_INVENTORY_MESSAGE); - InventoryListener fullBank = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE); InventoryListener appearance = new AppearanceInventoryListener(this); InventoryListener syncInventory = new SynchronizationInventoryListener(this, - SynchronizationInventoryListener.INVENTORY_ID); - InventoryListener syncBank = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID); + SynchronizationInventoryListener.INVENTORY_ID, SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, + SynchronizationInventoryListener.INVENTORY_INVENTORY); InventoryListener syncEquipment = new SynchronizationInventoryListener(this, - SynchronizationInventoryListener.EQUIPMENT_ID); + SynchronizationInventoryListener.EQUIPMENT_ID, SynchronizationInventoryListener.EQUIPMENT_CONTAINER_COMPONENT, + SynchronizationInventoryListener.EQUIPMENT_CONTAINER); inventory.addListener(syncInventory); inventory.addListener(fullInventory); - bank.addListener(syncBank); - bank.addListener(fullBank); equipment.addListener(syncEquipment); equipment.addListener(appearance); } @@ -1022,5 +1022,4 @@ private void initSkills() { skillSet.addListener(new SynchronizationSkillListener(this)); skillSet.addListener(new LevelUpSkillListener(this)); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java b/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java index b1731d6d7..2e6050055 100644 --- a/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java +++ b/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java @@ -10,22 +10,27 @@ public final class BankConstants { /** * The bank inventory id. */ - public static final int BANK_INVENTORY_ID = 5382; + public static final int INVENTORY_INTERFACE = 15; + + /** + * The bank inventory component. + */ + public static final int BANK_INVENTORY_COMPONENT = 3; /** * The bank window id. */ - public static final int BANK_WINDOW_ID = 5292; + public static final int BANK_WINDOW_ID = 12; /** - * The sidebar id. + * The bank window component. */ - public static final int SIDEBAR_ID = 2005; + public static final int BANK_CONTAINER_COMPONENT = -1; /** - * The sidebar inventory id. + * The inventory id for banks. */ - public static final int SIDEBAR_INVENTORY_ID = 2006; + public static final int BANK_INVENTORY = 95; /** * Default private constructor to prevent instantiation. diff --git a/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java b/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java index 9e46970c5..df06ffa86 100644 --- a/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java +++ b/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java @@ -1,7 +1,7 @@ package org.apollo.game.model.inv; -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; +import org.apollo.game.message.impl.UpdateInventoryFullMessage; +import org.apollo.game.message.impl.UpdateInventoryPartialMessage; import org.apollo.game.model.Item; import org.apollo.game.model.entity.Player; @@ -15,18 +15,32 @@ public final class SynchronizationInventoryListener extends InventoryAdapter { /** * The equipment interface id. */ - public static final int EQUIPMENT_ID = 1688; + public static final int EQUIPMENT_ID = 387; + public static final int EQUIPMENT_CONTAINER_COMPONENT = -1; + public static final int EQUIPMENT_CONTAINER = 94; /** * The inventory interface id. */ - public static final int INVENTORY_ID = 3214; + public static final int INVENTORY_ID = 149; + public static final int INVENTORY_CONTAINER_COMPONENT = 0; + public static final int INVENTORY_INVENTORY = 93; /** * The interface id. */ private final int interfaceId; + /** + * The interface id. + */ + private final int component; + + /** + * The interface id. + */ + private final int inventory; + /** * The player. */ @@ -35,22 +49,25 @@ public final class SynchronizationInventoryListener extends InventoryAdapter { /** * Creates the synchronization inventory listener. * - * @param player The player. + * @param player The player. * @param interfaceId The interface id. */ - public SynchronizationInventoryListener(Player player, int interfaceId) { + public SynchronizationInventoryListener(Player player, int interfaceId, int component, int inventory) { this.player = player; this.interfaceId = interfaceId; + this.component = component; + this.inventory = inventory; } @Override public void itemsUpdated(Inventory inventory) { - player.send(new UpdateItemsMessage(interfaceId, inventory.getItems())); + player.send(new UpdateInventoryFullMessage(interfaceId, component, this.inventory, inventory.getItems())); } @Override public void itemUpdated(Inventory inventory, int slot, Item item) { - player.send(new UpdateSlottedItemsMessage(interfaceId, new SlottedItem(slot, item))); + player.send( + new UpdateInventoryPartialMessage(interfaceId, component, this.inventory, new SlottedItem(slot, item))); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index d48ca9bc4..9adf8f56e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -2,15 +2,19 @@ import org.apollo.game.message.impl.NpcSynchronizationMessage; import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.game.message.impl.UpdateInventoryFullMessage; +import org.apollo.game.message.impl.UpdateInventoryPartialMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.interfaces.ClosedInterfaceMessageDecoder; import org.apollo.game.release.r181.decoders.interfaces.DisplayStatusMessageDecoder; import org.apollo.game.release.r181.decoders.interfaces.EnteredAmountMessageDecoder; -import org.apollo.game.release.r181.decoders.npc.*; -import org.apollo.game.release.r181.decoders.obj.*; -import org.apollo.game.release.r181.decoders.player.ReportAbuseMessageDecoder; -import org.apollo.game.release.r181.decoders.player.actions.*; +import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; +import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; +import org.apollo.game.release.r181.decoders.map.npc.*; +import org.apollo.game.release.r181.decoders.map.obj.*; +import org.apollo.game.release.r181.decoders.map.player.*; +import org.apollo.game.release.r181.decoders.map.player.actions.*; import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; import org.apollo.game.release.r181.decoders.social.PrivateChatMessageDecoder; import org.apollo.game.release.r181.decoders.social.friends.AddFriendMessageDecoder; @@ -25,6 +29,8 @@ import org.apollo.game.release.r181.encoders.player.SetPlayerActionMessageEncoder; import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; import org.apollo.game.release.r181.encoders.ui.*; +import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerFullMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerPartialMessageEncoder; import org.apollo.net.meta.PacketMetaDataGroup; import org.apollo.net.release.Release; @@ -155,6 +161,9 @@ private void init() { register(IfMoveSubMessage.class, new IfMoveSubMessageEncoder()); register(IfSetEventMessage.class, new IfSetEventMessageEncoder()); + register(UpdateInventoryPartialMessage.class, new UpdateContainerPartialMessageEncoder()); + register(UpdateInventoryFullMessage.class, new UpdateContainerFullMessageEncoder()); + register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); @@ -251,12 +260,18 @@ private void init() { register(41, new MouseClickedMessageDecoder()); register(22, new KeepAliveMessageDecoder()); + /** + * Map + */ + register(76, new MapRebuildCompleteDecoder()); + /** * Misc */ { - //register(34, new EventMouseMoveDecoder()); TODO this later for now using spam - register(34, new SpamPacketMessageDecoder()); + //TODO these if they are relevant. + register(34, new SpamPacketMessageDecoder()); // register(34, new EventMouseMoveDecoder()); + register(4, new SpamPacketMessageDecoder()); // register(34, new LoginInfoMessageDecoder()); } register(49, new KeepAliveMessageDecoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java index cf4d7f0a2..f8568c907 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java @@ -7,7 +7,7 @@ /** * A {@link MessageDecoder} for the {@link ArrowKeyMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class ArrowKeyMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java index 4b3516031..5626fbcd7 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the {@link CommandMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class CommandMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java index e724fe7c4..2267019e7 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java @@ -9,7 +9,7 @@ /** * A {@link MessageDecoder} for the {@link FocusUpdateMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FocusUpdateMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java index d7b9df27f..e9c42fb8f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java @@ -7,7 +7,7 @@ /** * A {@link MessageDecoder} for the {@link KeepAliveMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class KeepAliveMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java index 3ca5de7c1..bfa999059 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java @@ -9,7 +9,7 @@ /** * A {@link MessageDecoder} for the {@link MouseClickedMessage} * - * @author Stuart + * @author Khaled Abdeljaber */ public final class MouseClickedMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java index 180c19f05..c99daa4be 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java @@ -7,7 +7,7 @@ /** * A {@link MessageDecoder} for the {@link ClosedInterfaceMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class ClosedInterfaceMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java index 78dadf2c6..8c4fe2dca 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java @@ -9,7 +9,7 @@ /** * A {@link MessageDecoder} for the {@link EnteredAmountMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class EnteredAmountMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/MapRebuildCompleteDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/MapRebuildCompleteDecoder.java new file mode 100644 index 000000000..156fc46ad --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/MapRebuildCompleteDecoder.java @@ -0,0 +1,15 @@ +package org.apollo.game.release.r181.decoders.map; + +import org.apollo.game.message.impl.decode.MapBuildCompleteMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class MapRebuildCompleteDecoder extends MessageDecoder { + @Override + public MapBuildCompleteMessage decode(GamePacket packet) { + return new MapBuildCompleteMessage(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/WalkMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java index 228def9ba..436cbc1f0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/WalkMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders; +package org.apollo.game.release.r181.decoders.map; import org.apollo.game.message.impl.WalkMessage; import org.apollo.game.model.Position; @@ -11,7 +11,7 @@ /** * A {@link MessageDecoder} for the {@link WalkMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class WalkMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FifthNpcActionMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FifthNpcActionMessageDecoder.java index bc0fd8097..51beb3c06 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FifthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FifthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npc; +package org.apollo.game.release.r181.decoders.map.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * A {@link MessageDecoder} for the fifth {@link NpcActionMessage}. * - * @author Stuart + * @author Khaled Abdeljaber */ public final class FifthNpcActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FirstNpcActionMessageDecoder.java similarity index 88% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npc/FirstNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FirstNpcActionMessageDecoder.java index 6339afa6f..b9b81d6f8 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FirstNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FirstNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npc; +package org.apollo.game.release.r181.decoders.map.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; @@ -7,7 +7,7 @@ /** * The {@link MessageDecoder} for the first {@link NpcActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FirstNpcActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FourthNpcActionMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FourthNpcActionMessageDecoder.java index 7c25b14cd..b10905bf0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/FourthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FourthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npc; +package org.apollo.game.release.r181.decoders.map.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * A {@link MessageDecoder} for the fourth {@link NpcActionMessage}. * - * @author Stuart + * @author Khaled Abdeljaber */ public final class FourthNpcActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SecondNpcActionMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npc/SecondNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SecondNpcActionMessageDecoder.java index 5a04e08d2..b6670d0c5 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SecondNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npc; +package org.apollo.game.release.r181.decoders.map.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * The {@link MessageDecoder} for the {@link NpcActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SecondNpcActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SixthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SixthNpcActionMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npc/SixthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SixthNpcActionMessageDecoder.java index c571cea08..563f415bb 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/SixthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SixthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npc; +package org.apollo.game.release.r181.decoders.map.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * A {@link MessageDecoder} for the sixth {@link NpcActionMessage}. * - * @author Stuart + * @author Khaled Abdeljaber */ public final class SixthNpcActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/ThirdNpcActionMessageDecoder.java similarity index 88% rename from game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/ThirdNpcActionMessageDecoder.java index b6ec15629..1ec4717a5 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/npc/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/ThirdNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.npc; +package org.apollo.game.release.r181.decoders.map.npc; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; @@ -7,7 +7,7 @@ /** * The {@link MessageDecoder} for the third {@link NpcActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class ThirdNpcActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FifthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FifthObjectActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/decoders/obj/FifthObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FifthObjectActionMessageDecoder.java index 8a8e3552d..a9d3eb3fb 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FifthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FifthObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.obj; +package org.apollo.game.release.r181.decoders.map.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the fifth {@link ObjectActionMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class FifthObjectActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java index 62b98c6e3..669d956a2 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FirstObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.obj; +package org.apollo.game.release.r181.decoders.map.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the first {@link ObjectActionMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class FirstObjectActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FourthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/decoders/obj/FourthObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java index d1fae7a44..3826f0e58 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/FourthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.obj; +package org.apollo.game.release.r181.decoders.map.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the fourth {@link ObjectActionMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class FourthObjectActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java index 45494e99c..8ba1f5a6a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SecondObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.obj; +package org.apollo.game.release.r181.decoders.map.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -11,7 +11,7 @@ /** * A {@link MessageDecoder} for the second {@link ObjectActionMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class SecondObjectActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SixthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SixthObjectActionMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/decoders/obj/SixthObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SixthObjectActionMessageDecoder.java index 2b4852fa3..816e85a6c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SixthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SixthObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.obj; +package org.apollo.game.release.r181.decoders.map.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -11,7 +11,7 @@ /** * A {@link MessageDecoder} for the sixth {@link ObjectActionMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class SixthObjectActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SpamPacketMessageDecoder.java similarity index 74% rename from game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SpamPacketMessageDecoder.java index 3a93b9f1a..28371c878 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/SpamPacketMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SpamPacketMessageDecoder.java @@ -1,14 +1,14 @@ -package org.apollo.game.release.r181.decoders.obj; +package org.apollo.game.release.r181.decoders.map.obj; import io.netty.buffer.ByteBufUtil; -import org.apollo.game.message.impl.SpamPacketMessage; +import org.apollo.game.message.impl.decode.SpamPacketMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageDecoder; /** * A {@link MessageDecoder} for the {@link SpamPacketMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SpamPacketMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/decoders/obj/ThirdObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java index ff3e377bf..335c1369c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/obj/ThirdObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.obj; +package org.apollo.game.release.r181.decoders.map.obj; import org.apollo.game.message.impl.ObjectActionMessage; import org.apollo.game.model.Position; @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the third {@link ObjectActionMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class ThirdObjectActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/ReportAbuseMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java similarity index 90% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/ReportAbuseMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java index 0043478d6..8a052006c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/ReportAbuseMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player; +package org.apollo.game.release.r181.decoders.map.player; import org.apollo.game.message.impl.ReportAbuseMessage; import org.apollo.net.codec.game.DataType; @@ -9,7 +9,7 @@ /** * A {@link MessageDecoder} for the {@link ReportAbuseMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class ReportAbuseMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/EightPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/EightPlayerActionMessageDecoder.java similarity index 87% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/EightPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/EightPlayerActionMessageDecoder.java index 5e4a8fb60..1333a6b76 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/EightPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/EightPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; @@ -7,7 +7,7 @@ /** * A {@link MessageDecoder} for the eight {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class EightPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FifthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FifthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java index ea1d432df..8441cad89 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FifthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * A {@link MessageDecoder} for the fifth {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FifthPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java similarity index 87% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java index 7a3791e2b..b9348c6f0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FirstPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; @@ -7,7 +7,7 @@ /** * A {@link MessageDecoder} for the first {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FirstPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FourthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java similarity index 88% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FourthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java index ee01de133..4b08e3691 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/FourthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; @@ -7,7 +7,7 @@ /** * A {@link MessageDecoder} for the fourth {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FourthPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SecondPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SecondPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java index 9d3143f38..8ea783238 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SecondPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * A {@link MessageDecoder} for the second {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SecondPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SeventhPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java similarity index 87% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SeventhPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java index 8986a5bfa..90621a95f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SeventhPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.*; @@ -7,7 +7,7 @@ /** * A {@link MessageDecoder} for the seventh {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SeventhPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SixthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SixthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java index 3957a08d8..b024cb83d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/SixthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * A {@link MessageDecoder} for the sixth {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SixthPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java index 1f6843f96..20f0b7242 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/player/actions/ThirdPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.player.actions; +package org.apollo.game.release.r181.decoders.map.player.actions; import org.apollo.game.message.impl.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; @@ -10,7 +10,7 @@ /** * A {@link MessageDecoder} for the third {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class ThirdPlayerActionMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java index 52489cbc2..06da4ccf3 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java @@ -9,7 +9,7 @@ /** * A {@link MessageDecoder} for the {@link PrivateChatMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class PrivateChatMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java index a46869bdc..94524e3c7 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the {@link AddFriendMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class AddFriendMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java index 912f85142..bdca80254 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the {@link RemoveFriendMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class RemoveFriendMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java index 5e7b5ecea..8936b091d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the {@link AddIgnoreMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class AddIgnoreMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java index d07858d49..ccad2f811 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the {@link RemoveIgnoreMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class RemoveIgnoreMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java index f15e767cf..189974670 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java @@ -10,7 +10,7 @@ /** * A {@link MessageEncoder} for the {@link UpdateRunEnergyMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public class UpdateRunEnergyMessageEncoder extends MessageEncoder { @Override diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java index 78338db89..5f8e708c0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java @@ -9,7 +9,7 @@ /** * A {@link MessageEncoder} for the {@link UpdateSkillMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public class UpdateSkillMessageEncoder extends MessageEncoder { @Override diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java index d53bc7992..a93164a90 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java @@ -10,7 +10,7 @@ /** * A {@link MessageEncoder} for the {@link UpdateWeightMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public class UpdateWeightMessageEncoder extends MessageEncoder { @Override diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java index a50c91778..c53833f36 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java @@ -18,7 +18,7 @@ /** * A {@link MessageEncoder} for the {@link NpcSynchronizationMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class NpcSynchronizationMessageEncoder extends MessageEncoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java index 622e87c76..b81fde458 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java @@ -8,7 +8,7 @@ /** * A {@link MessageEncoder} for the {@link RebuildNormalMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class RebuildNormalMessageEncoder extends MessageEncoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java index e7610a062..00176bb15 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java @@ -11,7 +11,7 @@ * A {@link MessageEncoder} for the {@link ConfigMessage}. * * @author Chris Fletcher - * @author Major + * @author Khaled Abdeljaber */ public final class ConfigMessageEncoder extends MessageEncoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java new file mode 100644 index 000000000..f832f1b5e --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java @@ -0,0 +1,46 @@ +package org.apollo.game.release.r181.encoders.ui.container; + +import org.apollo.game.message.impl.UpdateInventoryFullMessage; +import org.apollo.game.model.Item; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateInventoryFullMessage}. + * + * @author Khaled Abdeljaber + */ +public final class UpdateContainerFullMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(UpdateInventoryFullMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(70, PacketType.VARIABLE_SHORT); + + Item[] items = message.getItems(); + + builder.put(DataType.INT, message.getInterfaceId() << 16 | message.getComponent()); + builder.put(DataType.SHORT, message.getInventory()); + builder.put(DataType.SHORT, items.length); + + for (Item item : items) { + int id = item == null ? -1 : item.getId(); + int amount = item == null ? 0 : item.getAmount(); + + builder.put(DataType.SHORT, id + 1); + + if (amount > 254) { + builder.put(DataType.BYTE, 0xFF); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, amount); + } else { + builder.put(DataType.BYTE, amount); + } + } + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java new file mode 100644 index 000000000..805bc1b58 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java @@ -0,0 +1,46 @@ +package org.apollo.game.release.r181.encoders.ui.container; + +import org.apollo.game.message.impl.UpdateInventoryPartialMessage; +import org.apollo.game.model.Item; +import org.apollo.game.model.inv.SlottedItem; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateInventoryPartialMessage}. + * + * @author Khaled Abdeljaber + */ +public final class UpdateContainerPartialMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(UpdateInventoryPartialMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(44, PacketType.VARIABLE_SHORT); + SlottedItem[] items = message.getSlottedItems(); + + builder.put(DataType.INT, message.getInterfaceId() << 16 | message.getComponent()); + builder.put(DataType.SHORT, message.getContainerId()); + + for (SlottedItem slottedItem : items) { + builder.putSmart(slottedItem.getSlot()); + + Item item = slottedItem.getItem(); + int id = item == null ? -1 : item.getId(); + int amount = item == null ? 0 : item.getAmount(); + + builder.put(DataType.SHORT, id + 1); + + if (amount > 254) { + builder.put(DataType.BYTE, 255); + builder.put(DataType.INT, amount); + } else { + builder.put(DataType.BYTE, amount); + } + } + + return builder.toGamePacket(); + } +} diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java index dab17277e..abcbc847d 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java @@ -38,8 +38,8 @@ public void terminateWithNoTargetItem() throws Exception { when(player.getInventory()).thenReturn(inventory); - ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.SIDEBAR_INVENTORY_ID, 4151, 1, - BankConstants.SIDEBAR_INVENTORY_ID, 4152, 2); + ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.INVENTORY_INTERFACE, 4151, 1, + BankConstants.INVENTORY_INTERFACE, 4152, 2); itemOnItemVerificationHandler.handle(player, itemOnItemMessage); From ac27c8ecf552b8ecd57c39aa41cee6f169fd462c Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 24 Mar 2020 19:22:25 -0400 Subject: [PATCH 28/63] Item-interface interactions complete. --- game/data/messages.xml | 2 +- .../testing/junit/api/interactions/player.kt | 4 +- game/plugin/emote-tab/src/EmoteTab.plugin.kts | 8 +- game/plugin/logout/src/logout.plugin.kts | 2 +- game/plugin/logout/test/LogoutTests.kt | 4 +- game/plugin/run/src/run.plugin.kts | 6 +- .../skills/prayer/src/Prayer.plugin.kts | 8 +- .../handler/BankButtonMessageHandler.java | 14 +-- .../message/handler/BankMessageHandler.java | 2 +- .../handler/DialogueButtonHandler.java | 10 +- .../message/handler/EquipItemHandler.java | 3 +- .../ItemOnItemVerificationHandler.java | 2 +- .../handler/ItemVerificationHandler.java | 2 +- .../handler/SwitchItemMessageHandler.java | 2 +- .../game/message/impl/ButtonMessage.java | 35 ------ .../game/message/impl/IfActionMessage.java | 108 ++++++++++++++++++ .../message/impl/InventoryItemMessage.java | 24 +++- .../game/message/impl/ItemActionMessage.java | 12 +- .../game/message/impl/ItemOnItemMessage.java | 14 ++- .../message/impl/ItemOnObjectMessage.java | 14 +-- .../game/message/impl/ItemOptionMessage.java | 7 +- .../game/message/impl/MagicOnItemMessage.java | 4 +- .../org/apollo/game/model/entity/Player.java | 8 +- .../game/model/inter/bank/BankConstants.java | 8 +- .../bank/BankDepositEnterAmountListener.java | 2 +- .../bank/BankWithdrawEnterAmountListener.java | 2 +- .../apollo/game/release/r181/Release181.java | 29 ++++- .../ClosedInterfaceMessageDecoder.java | 2 +- .../DisplayStatusMessageDecoder.java | 2 +- .../EnteredAmountMessageDecoder.java | 2 +- .../ui/if1/FifthIf1ActionMessageDecoder.java | 21 ++++ .../ui/if1/FirstIf1ActionMessageDecoder.java | 21 ++++ .../ui/if1/FourthIf1ActionMessageDecoder.java | 21 ++++ .../ui/if1/SecondIf1ActionMessageDecoder.java | 21 ++++ .../ui/if1/ThirdIf1ActionMessageDecoder.java | 21 ++++ .../ui/if3/If3ActionMessageDecoder.java | 28 +++++ .../ui/opheld/FifthOpHeldMessageDecoder.java | 21 ++++ .../ui/opheld/FirstOpHeldMessageDecoder.java | 24 ++++ .../ui/opheld/FourthOpHeldMessageDecoder.java | 21 ++++ .../ui/opheld/SecondOpHeldMessageDecoder.java | 21 ++++ .../ui/opheld/SixthOpHeldMessageDecoder.java | 21 ++++ .../ui/opheld/ThirdOpHeldMessageDecoder.java | 21 ++++ .../game/plugin/kotlin/KotlinPluginScript.kt | 8 +- .../game/plugin/kotlin/message/ButtonClick.kt | 20 ++-- .../ItemOnItemVerificationHandlerTests.java | 4 +- .../ItemOnObjectVerificationHandlerTests.java | 27 +++-- 46 files changed, 525 insertions(+), 138 deletions(-) delete mode 100644 game/src/main/java/org/apollo/game/message/impl/ButtonMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/IfActionMessage.java rename game/src/main/java/org/apollo/game/release/r181/decoders/{interfaces => ui}/ClosedInterfaceMessageDecoder.java (89%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{interfaces => ui}/DisplayStatusMessageDecoder.java (93%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{interfaces => ui}/EnteredAmountMessageDecoder.java (92%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java diff --git a/game/data/messages.xml b/game/data/messages.xml index 271f2d438..fd3463757 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -1,6 +1,6 @@ - org.apollo.game.message.impl.ButtonMessage + org.apollo.game.message.impl.IfActionMessage org.apollo.game.message.handler.DialogueButtonHandler org.apollo.game.message.handler.BankButtonMessageHandler diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt index 6956df95e..dffff1dc1 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt @@ -15,8 +15,8 @@ import org.apollo.game.model.entity.obj.GameObject * Send an [ItemOptionMessage] for the given [id], [option], [slot], and [interfaceId], simulating a * player interacting with an item. */ -fun Player.interactWithItem(id: Int, option: Int, slot: Int? = null, interfaceId: Int? = null) { - send(ItemOptionMessage(option, interfaceId ?: -1, id, slot ?: inventory.slotOf(id))) +fun Player.interactWithItem(id: Int, option: Int, slot: Int? = null, interfaceId: Int? = null, componentId: Int? = null) { + send(ItemOptionMessage(option, interfaceId ?: -1, componentId ?: -1, id, slot ?: inventory.slotOf(id))) } /** diff --git a/game/plugin/emote-tab/src/EmoteTab.plugin.kts b/game/plugin/emote-tab/src/EmoteTab.plugin.kts index 0f546e818..0fe5bb66c 100644 --- a/game/plugin/emote-tab/src/EmoteTab.plugin.kts +++ b/game/plugin/emote-tab/src/EmoteTab.plugin.kts @@ -1,7 +1,7 @@ -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.IfActionMessage -on { ButtonMessage::class } - .where { widgetId in Emote.MAP } +on { IfActionMessage::class } + .where { componentId in Emote.MAP } .then { player -> - player.playAnimation(Emote.fromButton(widgetId)!!.animation) + player.playAnimation(Emote.fromButton(componentId)!!.animation) } \ No newline at end of file diff --git a/game/plugin/logout/src/logout.plugin.kts b/game/plugin/logout/src/logout.plugin.kts index 0243b091f..c5fe4db13 100644 --- a/game/plugin/logout/src/logout.plugin.kts +++ b/game/plugin/logout/src/logout.plugin.kts @@ -1,5 +1,5 @@ val LOGOUT_BUTTON_ID = 2458 on_button(LOGOUT_BUTTON_ID) - .where { widgetId == LOGOUT_BUTTON_ID } + .where { componentId == LOGOUT_BUTTON_ID } .then { it.logout() } \ No newline at end of file diff --git a/game/plugin/logout/test/LogoutTests.kt b/game/plugin/logout/test/LogoutTests.kt index 9a8cb9c66..7a5f19be5 100644 --- a/game/plugin/logout/test/LogoutTests.kt +++ b/game/plugin/logout/test/LogoutTests.kt @@ -1,5 +1,5 @@ import io.mockk.verify -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.IfActionMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.api.annotations.TestMock @@ -18,7 +18,7 @@ class LogoutTests { @Test fun `The player should be logged out when they click the logout button`() { - player.send(ButtonMessage(LOGOUT_BUTTON_ID)) + player.send(IfActionMessage(LOGOUT_BUTTON_ID, 0, 0, 0, 0)) verify { player.logout() } } diff --git a/game/plugin/run/src/run.plugin.kts b/game/plugin/run/src/run.plugin.kts index fa65f0495..05a80d4a6 100644 --- a/game/plugin/run/src/run.plugin.kts +++ b/game/plugin/run/src/run.plugin.kts @@ -1,10 +1,10 @@ -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.IfActionMessage val WALK_BUTTON_ID = 152 val RUN_BUTTON_ID = 153 -on { ButtonMessage::class } - .where { widgetId == WALK_BUTTON_ID || widgetId == RUN_BUTTON_ID } +on { IfActionMessage::class } + .where { componentId == WALK_BUTTON_ID || componentId == RUN_BUTTON_ID } .then { it.toggleRunning() } \ No newline at end of file diff --git a/game/plugin/skills/prayer/src/Prayer.plugin.kts b/game/plugin/skills/prayer/src/Prayer.plugin.kts index 2338d8332..3aca62a45 100644 --- a/game/plugin/skills/prayer/src/Prayer.plugin.kts +++ b/game/plugin/skills/prayer/src/Prayer.plugin.kts @@ -1,6 +1,6 @@ import Bone.Companion.isBone import Prayer.Companion.isPrayerButton -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.IfActionMessage import org.apollo.game.message.impl.ItemOptionMessage import org.apollo.game.model.event.impl.LogoutEvent import org.apollo.game.plugin.api.prayer @@ -11,10 +11,10 @@ on_player_event { LogoutEvent::class } playerPrayers.removeAll(it) } -on { ButtonMessage::class } - .where { widgetId.isPrayerButton() } +on { IfActionMessage::class } + .where { componentId.isPrayerButton() } .then { player -> - val prayer = Prayer.forButton(widgetId)!! + val prayer = Prayer.forButton(componentId)!! val level = prayer.level if (level > player.prayer.current) { diff --git a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java index d10aba0b0..c92425b57 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java @@ -1,20 +1,20 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ButtonMessage; +import org.apollo.game.message.impl.IfActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; /** - * A {@link MessageHandler} that responds to {@link ButtonMessage}s for withdrawing items as notes. + * A {@link MessageHandler} that responds to {@link IfActionMessage}s for withdrawing items as notes. * * @author Graham */ -public final class BankButtonMessageHandler extends MessageHandler { +public final class BankButtonMessageHandler extends MessageHandler { /** * Creates the BankButtonMessageHandler. * - * @param world The {@link World} the {@link ButtonMessage} occurred in. + * @param world The {@link World} the {@link IfActionMessage} occurred in. */ public BankButtonMessageHandler(World world) { super(world); @@ -31,10 +31,10 @@ public BankButtonMessageHandler(World world) { private static final int WITHDRAW_AS_NOTE = 5386; @Override - public void handle(Player player, ButtonMessage message) { - if (message.getWidgetId() == WITHDRAW_AS_ITEM) { + public void handle(Player player, IfActionMessage message) { + if (message.getComponentId() == WITHDRAW_AS_ITEM) { player.setWithdrawingNotes(false); - } else if (message.getWidgetId() == WITHDRAW_AS_NOTE) { + } else if (message.getComponentId() == WITHDRAW_AS_NOTE) { player.setWithdrawingNotes(true); } } diff --git a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java index abb7aca73..d91c2fe65 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java @@ -51,7 +51,7 @@ public BankMessageHandler(World world) { @Override public void handle(Player player, ItemActionMessage message) { - if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { + if (player.getInterfaceSet().contains(BankConstants.WINDOW_ID)) { //if (message.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) { deposit(player, message); } else if (message.getInterfaceId() == BankConstants.INVENTORY_INTERFACE) { diff --git a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java index fc6be4342..6e68ca0ad 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ButtonMessage; +import org.apollo.game.message.impl.IfActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.game.model.inter.ServerInterfaceType; @@ -11,21 +11,21 @@ * * @author Chris Fletcher */ -public final class DialogueButtonHandler extends MessageHandler { +public final class DialogueButtonHandler extends MessageHandler { /** * Creates the DialogueButtonHandler. * - * @param world The {@link World} the {@link ButtonMessage} occurred in. + * @param world The {@link World} the {@link IfActionMessage} occurred in. */ public DialogueButtonHandler(World world) { super(world); } @Override - public void handle(Player player, ButtonMessage message) { + public void handle(Player player, IfActionMessage message) { if (player.getInterfaceSet().contains(ServerInterfaceType.DIALOGUE)) { - boolean terminate = player.getInterfaceSet().buttonClicked(message.getWidgetId()); + boolean terminate = player.getInterfaceSet().buttonClicked(message.getComponentId()); if (terminate) { message.terminate(); diff --git a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java index 5ef5131fc..2eb978660 100644 --- a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java @@ -50,7 +50,6 @@ public void handle(Player player, ItemOptionMessage message) { int equippingId = equipping.getId(); EquipmentDefinition definition = EquipmentDefinition.lookup(equippingId); - if (definition == null) { return; } else if (!hasRequirements(player, definition)) { @@ -120,7 +119,7 @@ private void handleTwoHanded(Inventory inventory, Inventory equipment, int inven equipment.reset(SHIELD); equipment.set(WEAPON, inventory.reset(inventorySlot)); - + if (shield != null) { inventory.add(shield); } diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java index 9ea3098e0..443b5d269 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java @@ -30,7 +30,7 @@ public void handle(Player player, ItemOnItemMessage message) { switch (message.getInterfaceId()) { case SynchronizationInventoryListener.INVENTORY_ID: - case BankConstants.BANK_CONTAINER_COMPONENT: + case BankConstants.CONTAINER_COMPONENT: inventory = player.getInventory(); break; case SynchronizationInventoryListener.EQUIPMENT_ID: diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java index ebd86f2b7..5377357ff 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java @@ -46,7 +46,7 @@ public interface InventorySupplier { inventories.put(SynchronizationInventoryListener.INVENTORY_ID, Player::getInventory); inventories.put(BankConstants.INVENTORY_INTERFACE, Player::getInventory); inventories.put(SynchronizationInventoryListener.EQUIPMENT_ID, Player::getEquipment); - inventories.put(BankConstants.BANK_WINDOW_ID, Player::getBank); + inventories.put(BankConstants.WINDOW_ID, Player::getBank); } /** diff --git a/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java index 84a379ad9..9c7113c07 100644 --- a/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java @@ -37,7 +37,7 @@ public void handle(Player player, SwitchItemMessage message) { case SynchronizationInventoryListener.EQUIPMENT_ID: inventory = player.getEquipment(); break; - case BankConstants.BANK_WINDOW_ID: + case BankConstants.WINDOW_ID: inventory = player.getBank(); insertPermitted = true; break; diff --git a/game/src/main/java/org/apollo/game/message/impl/ButtonMessage.java b/game/src/main/java/org/apollo/game/message/impl/ButtonMessage.java deleted file mode 100644 index f98d3ae3b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/ButtonMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent by the client when a player clicks a button. - * - * @author Graham - */ -public final class ButtonMessage extends Message { - - /** - * The widget id. - */ - private final int widgetId; - - /** - * Creates the button message. - * - * @param widgetId The widget id. - */ - public ButtonMessage(int widgetId) { - this.widgetId = widgetId; - } - - /** - * Gets the widget id. - * - * @return The widget id. - */ - public int getWidgetId() { - return widgetId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/IfActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/IfActionMessage.java new file mode 100644 index 000000000..98d9cc3c3 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/IfActionMessage.java @@ -0,0 +1,108 @@ +package org.apollo.game.message.impl; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent by the client when a player clicks a button. + * + * @author Khaled Abdeljaber + */ +public class IfActionMessage extends Message { + + /** + * The option that was pressed. + */ + private final int action; + + /** + * The interface id. + */ + private final int interfaceId; + + /** + * The component id. + */ + private final int componentId; + + /** + * The slot of the item. + */ + private final int slot; + + /** + * The item id. + */ + private final int itemId; + + /** + * Instantiates a new If action message. + * + * @param action the action + * @param interfaceId the interface id + * @param componentId the component id + * @param slot the slot + * @param itemId the item id + */ + public IfActionMessage(int action, int interfaceId, int componentId, int slot, int itemId) { + this.action = action; + this.interfaceId = interfaceId; + this.componentId = componentId; + this.slot = slot; + this.itemId = itemId; + } + + /** + * Gets action. + * + * @return the action + */ + public int getAction() { + return action; + } + + /** + * Gets interface id. + * + * @return the interface id + */ + public int getInterfaceId() { + return interfaceId; + } + + /** + * Gets component id. + * + * @return the component id + */ + public int getComponentId() { + return componentId; + } + + /** + * Gets slot. + * + * @return the slot + */ + public int getSlot() { + return slot; + } + + /** + * Gets item id. + * + * @return the item id + */ + public int getItemId() { + return itemId; + } + + public int getId() { + return interfaceId << 16 | componentId; + } + + + @Override + public String toString() { + return "IfActionMessage{" + "action=" + action + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", slot=" + slot + ", itemId=" + itemId + '}'; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java index 969435ba8..cd47e6a0f 100644 --- a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java @@ -22,6 +22,11 @@ public abstract class InventoryItemMessage extends Message { */ private final int interfaceId; + /** + * The component id. + */ + private final int componentId; + /** * The option number (1-5 if present). */ @@ -35,14 +40,15 @@ public abstract class InventoryItemMessage extends Message { /** * Creates the InventoryItemMessage. * - * @param option The option number, if applicable. + * @param option The option number, if applicable. * @param interfaceId The interface id. - * @param id The id. - * @param slot The slot. + * @param id The id. + * @param slot The slot. */ - protected InventoryItemMessage(OptionalInt option, int interfaceId, int id, int slot) { + protected InventoryItemMessage(OptionalInt option, int interfaceId, int componentId, int id, int slot) { this.option = option; this.interfaceId = interfaceId; + this.componentId = componentId; this.id = id; this.slot = slot; } @@ -65,6 +71,11 @@ public final int getInterfaceId() { return interfaceId; } + + public int getComponentId() { + return componentId; + } + /** * Gets the option number. * @@ -93,4 +104,9 @@ public final boolean hasOption() { return option.isPresent(); } + + @Override + public String toString() { + return "InventoryItemMessage{" + "id=" + id + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", option=" + option + ", slot=" + slot + '}'; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java index 6fd9996a4..586058d64 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java @@ -16,13 +16,15 @@ public final class ItemActionMessage extends InventoryItemMessage { /** * Creates the ItemActionMessage. * - * @param option The option number. + * @param option The option number. * @param interfaceId The interface id. - * @param id The id. - * @param slot The slot. + * @param componentId The component id. + * @param id The id. + * @param slot The slot. */ - public ItemActionMessage(int option, int interfaceId, int id, int slot) { - super(OptionalInt.of(option), interfaceId, id, slot); + public ItemActionMessage(int option, int interfaceId, int componentId, int id, int slot) { + super(OptionalInt.of(option), interfaceId, componentId, id, slot); } + } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java index 017b2e6ce..9b133ad46 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java @@ -19,6 +19,11 @@ public final class ItemOnItemMessage extends InventoryItemMessage { */ private final int targetInterface; + /** + * The component id of the target item. + */ + private final int targetComponentId; + /** * The slot of the target item. */ @@ -34,9 +39,10 @@ public final class ItemOnItemMessage extends InventoryItemMessage { * @param targetId The id of the target item. * @param targetSlot The slot of the target item. */ - public ItemOnItemMessage(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId, int targetSlot) { - super(OptionalInt.empty(), usedInterface, usedId, usedSlot); + public ItemOnItemMessage(int usedInterface, int usedComponentId, int usedId, int usedSlot, int targetInterface, int targetComponentId, int targetId, int targetSlot) { + super(OptionalInt.empty(), usedInterface, usedComponentId, usedId, usedSlot); this.targetInterface = targetInterface; + this.targetComponentId = targetComponentId; this.targetSlot = targetSlot; this.targetId = targetId; } @@ -59,6 +65,10 @@ public int getTargetInterfaceId() { return targetInterface; } + public int getTargetComponentId() { + return targetComponentId; + } + /** * Gets the slot of the target item. * diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java index fabc2854e..fa0c67673 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java @@ -26,14 +26,14 @@ public final class ItemOnObjectMessage extends InventoryItemMessage { * Creates an item on object message. * * @param interfaceId The interface id. - * @param itemId The item id. - * @param itemSlot The slot the item is in. - * @param objectId The object id. - * @param x The x coordinate. - * @param y The y coordinate. + * @param itemId The item id. + * @param itemSlot The slot the item is in. + * @param objectId The object id. + * @param x The x coordinate. + * @param y The y coordinate. */ - public ItemOnObjectMessage(int interfaceId, int itemId, int itemSlot, int objectId, int x, int y) { - super(OptionalInt.empty(), interfaceId, itemId, itemSlot); + public ItemOnObjectMessage(int interfaceId, int componentId, int itemId, int itemSlot, int objectId, int x, int y) { + super(OptionalInt.empty(), interfaceId, componentId, itemId, itemSlot); this.objectId = objectId; position = new Position(x, y); } diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java index 370451f56..cab880b28 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java @@ -7,7 +7,7 @@ * Note that the actual message sent by the client is one of the five item option messages, but this is the message that * should be intercepted (and the option verified). * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class ItemOptionMessage extends InventoryItemMessage { @@ -19,8 +19,7 @@ public final class ItemOptionMessage extends InventoryItemMessage { * @param id The id. * @param slot The slot. */ - public ItemOptionMessage(int option, int interfaceId, int id, int slot) { - super(OptionalInt.of(option), interfaceId, id, slot); + public ItemOptionMessage(int option, int interfaceId, int componentId, int id, int slot) { + super(OptionalInt.of(option), interfaceId, componentId, id, slot); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java index 521060901..47ecb6e47 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java @@ -22,8 +22,8 @@ public final class MagicOnItemMessage extends InventoryItemMessage { * @param slot The item slot. * @param spell The spell id. */ - public MagicOnItemMessage(int interfaceId, int id, int slot, int spell) { - super(OptionalInt.empty(), interfaceId, id, slot); + public MagicOnItemMessage(int interfaceId, int componentId, int id, int slot, int spell) { + super(OptionalInt.empty(), interfaceId, componentId, id, slot); this.spell = spell; } diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index b79e3984e..3be450867 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -641,9 +641,9 @@ public void logout() { */ public void openBank() { InventoryListener invListener = new SynchronizationInventoryListener(this, BankConstants.INVENTORY_INTERFACE, - BankConstants.BANK_INVENTORY_COMPONENT, SynchronizationInventoryListener.INVENTORY_INVENTORY); - InventoryListener bankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_WINDOW_ID, - BankConstants.BANK_CONTAINER_COMPONENT, BankConstants.BANK_INVENTORY); + BankConstants.INVENTORY_COMPONENT, SynchronizationInventoryListener.INVENTORY_INVENTORY); + InventoryListener bankListener = new SynchronizationInventoryListener(this, BankConstants.WINDOW_ID, + BankConstants.CONTAINER_COMPONENT, BankConstants.INVENTORY); inventory.addListener(invListener); bank.addListener(bankListener); @@ -651,7 +651,7 @@ public void openBank() { bank.forceRefresh(); InterfaceListener interListener = new BankInterfaceListener(this, invListener, bankListener); - interfaceSet.openModal(interListener, BankConstants.BANK_WINDOW_ID); + interfaceSet.openModal(interListener, BankConstants.WINDOW_ID); interfaceSet.openTopLevel(BankConstants.INVENTORY_INTERFACE, TopLevelPosition.INVENTORY_TAB); } diff --git a/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java b/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java index 2e6050055..34c5594d0 100644 --- a/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java +++ b/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java @@ -15,22 +15,22 @@ public final class BankConstants { /** * The bank inventory component. */ - public static final int BANK_INVENTORY_COMPONENT = 3; + public static final int INVENTORY_COMPONENT = 3; /** * The bank window id. */ - public static final int BANK_WINDOW_ID = 12; + public static final int WINDOW_ID = 12; /** * The bank window component. */ - public static final int BANK_CONTAINER_COMPONENT = -1; + public static final int CONTAINER_COMPONENT = -1; /** * The inventory id for banks. */ - public static final int BANK_INVENTORY = 95; + public static final int INVENTORY = 95; /** * Default private constructor to prevent instantiation. diff --git a/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java b/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java index fe7662271..fbd0a1a38 100644 --- a/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java +++ b/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java @@ -40,7 +40,7 @@ public BankDepositEnterAmountListener(Player player, int slot, int id) { @Override public void amountEntered(int amount) { - if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { + if (player.getInterfaceSet().contains(BankConstants.WINDOW_ID)) { BankUtils.deposit(player, slot, id, amount); } } diff --git a/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java b/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java index e0134aa61..4db6ad0bf 100644 --- a/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java +++ b/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java @@ -40,7 +40,7 @@ public BankWithdrawEnterAmountListener(Player player, int slot, int id) { @Override public void amountEntered(int amount) { - if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { + if (player.getInterfaceSet().contains(BankConstants.WINDOW_ID)) { BankUtils.withdraw(player, slot, id, amount); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 9adf8f56e..71bd8975c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -6,14 +6,11 @@ import org.apollo.game.message.impl.UpdateInventoryPartialMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; -import org.apollo.game.release.r181.decoders.interfaces.ClosedInterfaceMessageDecoder; -import org.apollo.game.release.r181.decoders.interfaces.DisplayStatusMessageDecoder; -import org.apollo.game.release.r181.decoders.interfaces.EnteredAmountMessageDecoder; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; import org.apollo.game.release.r181.decoders.map.npc.*; import org.apollo.game.release.r181.decoders.map.obj.*; -import org.apollo.game.release.r181.decoders.map.player.*; +import org.apollo.game.release.r181.decoders.map.player.ReportAbuseMessageDecoder; import org.apollo.game.release.r181.decoders.map.player.actions.*; import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; import org.apollo.game.release.r181.decoders.social.PrivateChatMessageDecoder; @@ -21,6 +18,12 @@ import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.RemoveIgnoreMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.ClosedInterfaceMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.DisplayStatusMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.EnteredAmountMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.if1.*; +import org.apollo.game.release.r181.decoders.ui.if3.If3ActionMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.opheld.*; import org.apollo.game.release.r181.encoders.UpdateRunEnergyMessageEncoder; import org.apollo.game.release.r181.encoders.UpdateSkillMessageEncoder; import org.apollo.game.release.r181.encoders.UpdateWeightMessageEncoder; @@ -213,6 +216,24 @@ private void init() { register(35, new DisplayStatusMessageDecoder()); register(20, new ClosedInterfaceMessageDecoder()); + final var if3 = new int[]{68, 21, 48, 19, 40, 66, 85, 14, 84, 0}; + for (int index = 0; index < if3.length; index++) { + register(if3[index], new If3ActionMessageDecoder(index + 1)); + } + + register(46, new FirstIf1ActionMessageDecoder()); + register(26, new SecondIf1ActionMessageDecoder()); + register(65, new ThirdIf1ActionMessageDecoder()); + register(64, new FourthIf1ActionMessageDecoder()); + register(32, new FifthIf1ActionMessageDecoder()); + + register(87, new FirstOpHeldMessageDecoder()); + register(98, new SecondOpHeldMessageDecoder()); + register(72, new ThirdOpHeldMessageDecoder()); + register(7, new FourthOpHeldMessageDecoder()); + register(58, new FifthOpHeldMessageDecoder()); + register(24, new SixthOpHeldMessageDecoder()); + /** * Resume Inputs */ diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java index c99daa4be..e95d71f35 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/ClosedInterfaceMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.interfaces; +package org.apollo.game.release.r181.decoders.ui; import org.apollo.game.message.impl.ClosedInterfaceMessage; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/DisplayStatusMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/DisplayStatusMessageDecoder.java similarity index 93% rename from game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/DisplayStatusMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/ui/DisplayStatusMessageDecoder.java index e435a9246..c6fa98b1f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/DisplayStatusMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/DisplayStatusMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.interfaces; +package org.apollo.game.release.r181.decoders.ui; import org.apollo.game.message.impl.decode.DisplayStatusMessage; import org.apollo.game.model.inter.DisplayMode; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/EnteredAmountMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/ui/EnteredAmountMessageDecoder.java index 8c4fe2dca..39368bf98 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/interfaces/EnteredAmountMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/EnteredAmountMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.interfaces; +package org.apollo.game.release.r181.decoders.ui; import org.apollo.game.message.impl.EnteredAmountMessage; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java new file mode 100644 index 000000000..a97476c96 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FifthIf1ActionMessageDecoder extends MessageDecoder { + @Override + public IfActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int item = (int) reader.getUnsigned(DataType.SHORT); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT); + + return new IfActionMessage(5, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java new file mode 100644 index 000000000..0d1f76188 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FirstIf1ActionMessageDecoder extends MessageDecoder { + @Override + public IfActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int item = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + + return new IfActionMessage(1, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java new file mode 100644 index 000000000..47f970853 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FourthIf1ActionMessageDecoder extends MessageDecoder { + @Override + public IfActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int item = (int) reader.getUnsigned(DataType.SHORT); + + return new IfActionMessage(4, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java new file mode 100644 index 000000000..8ac87f1e8 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SecondIf1ActionMessageDecoder extends MessageDecoder { + @Override + public IfActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int item = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + + return new IfActionMessage(2, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java new file mode 100644 index 000000000..7811ab208 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class ThirdIf1ActionMessageDecoder extends MessageDecoder { + @Override + public IfActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int item = (int) reader.getUnsigned(DataType.SHORT); + + return new IfActionMessage(3, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java new file mode 100644 index 000000000..0a9a14b28 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java @@ -0,0 +1,28 @@ +package org.apollo.game.release.r181.decoders.ui.if3; + +import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class If3ActionMessageDecoder extends MessageDecoder { + + private final int action; + + public If3ActionMessageDecoder(int action) { + this.action = action; + } + + @Override + public IfActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT); + int slot = (int) reader.getUnsigned(DataType.SHORT); + int item = (int) reader.getUnsigned(DataType.SHORT); + + return new IfActionMessage(action, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java new file mode 100644 index 000000000..465a74670 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FifthOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int interfacePacked = (int) reader.getUnsigned(DataType.INT); + int itemId = (int) reader.getUnsigned(DataType.SHORT); + int slot = (int) reader.getUnsigned(DataType.SHORT); + + return new ItemActionMessage(5, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java new file mode 100644 index 000000000..be9ac7abe --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FirstOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT); + + return new ItemActionMessage(1, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java new file mode 100644 index 000000000..f42281d20 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FourthOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int interfacePacked = (int) reader.getUnsigned(DataType.INT); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ItemActionMessage(4, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java new file mode 100644 index 000000000..a526eb650 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SecondOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ItemActionMessage(2, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java new file mode 100644 index 000000000..b7caff005 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SixthOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + return new ItemActionMessage(6, -1, -1, itemId, -1); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java new file mode 100644 index 000000000..70ca40cca --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class ThirdOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ItemActionMessage(3, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt index 37bdfdfca..90e0643f9 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt @@ -2,7 +2,7 @@ package org.apollo.game.plugin.kotlin import org.apollo.game.command.CommandListener import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.IfActionMessage import org.apollo.game.model.World import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.event.Event @@ -86,11 +86,11 @@ abstract class KotlinPluginScript(var world: World, val context: PluginContext) } /** - * Create a [ButtonMessage] [MessageHandler] for the given [id]. + * Create a [IfActionMessage] [MessageHandler] for the given [id]. */ @Deprecated("Use new on(Type) listener") - fun on_button(id: Int): KotlinPlayerHandlerProxyTrait { - return on { ButtonMessage::class }.where { widgetId == id } + fun on_button(id: Int): KotlinPlayerHandlerProxyTrait { + return on { IfActionMessage::class }.where { componentId == id } } fun start(callback: (World) -> Unit) { diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt index 1b62dbf1f..86230b0b8 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.kotlin.message import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.IfActionMessage import org.apollo.game.model.World import org.apollo.game.model.entity.Player import org.apollo.game.plugin.kotlin.KotlinPluginScript @@ -10,7 +10,7 @@ import org.apollo.game.plugin.kotlin.PlayerContext import org.apollo.game.plugin.kotlin.PredicateContext /** - * Registers a listener for [ButtonMessage]s that occur on the given [button] id. + * Registers a listener for [IfActionMessage]s that occur on the given [button] id. * * ``` * on(ButtonClick, button = 416) { @@ -28,20 +28,20 @@ fun KotlinPluginScript.on( class ButtonClick(override val player: Player, val button: Int) : PlayerContext { - companion object : MessageListenable() { + companion object : MessageListenable() { + + override val type = IfActionMessage::class - override val type = ButtonMessage::class - override fun createHandler( world: World, predicateContext: ButtonPredicateContext?, callback: ButtonClick.() -> Unit - ): MessageHandler { - return object : MessageHandler(world) { + ): MessageHandler { + return object : MessageHandler(world) { - override fun handle(player: Player, message: ButtonMessage) { - if (predicateContext == null || predicateContext.button == message.widgetId) { - val context = ButtonClick(player, message.widgetId) + override fun handle(player: Player, message: IfActionMessage) { + if (predicateContext == null || predicateContext.button == message.componentId) { + val context = ButtonClick(player, message.componentId) context.callback() } } diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java index abcbc847d..df2c8bda7 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java @@ -38,8 +38,8 @@ public void terminateWithNoTargetItem() throws Exception { when(player.getInventory()).thenReturn(inventory); - ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.INVENTORY_INTERFACE, 4151, 1, - BankConstants.INVENTORY_INTERFACE, 4152, 2); + ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.INVENTORY_INTERFACE, BankConstants.INVENTORY_COMPONENT, 4151, 1, + BankConstants.INVENTORY_INTERFACE, BankConstants.INVENTORY_COMPONENT, 4152, 2); itemOnItemVerificationHandler.handle(player, itemOnItemMessage); diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java index b86fe0376..9d3c1e197 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java @@ -27,8 +27,7 @@ import static org.powermock.api.mockito.PowerMockito.*; @RunWith(PowerMockRunner.class) -@PrepareForTest({Player.class, World.class, Region.class, RegionRepository.class, ObjectDefinition.class, - ItemDefinition.class}) +@PrepareForTest({Player.class, World.class, Region.class, RegionRepository.class, ObjectDefinition.class, ItemDefinition.class}) public final class ItemOnObjectVerificationHandlerTests { @Before @@ -62,13 +61,15 @@ public void terminateIfInvalidItem() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 1, - 1, objectPosition.getX(), objectPosition.getY()); + ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, 4151, 1, 1, objectPosition.getX(), + objectPosition.getY()); ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world); itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage); - assertTrue("ObjectVerificationHandler: message not terminated valid item given!", itemOnObjectMessage.terminated()); + assertTrue("ObjectVerificationHandler: message not terminated valid item given!", + itemOnObjectMessage.terminated()); } @Test @@ -92,13 +93,15 @@ public void terminateIfInvalidSlot() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 30, - 1, objectPosition.getX(), objectPosition.getY()); + ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, 4151, 30, 1, objectPosition.getX(), + objectPosition.getY()); ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world); itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage); - assertTrue("ObjectVerificationHandler: message not terminated when no valid slot given!", itemOnObjectMessage.terminated()); + assertTrue("ObjectVerificationHandler: message not terminated when no valid slot given!", + itemOnObjectMessage.terminated()); } @Test @@ -123,12 +126,14 @@ public void terminateIfObjectOutOfRange() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 1, - 1, objectPosition.getX(), objectPosition.getY()); + ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, 4151, 1, 1, objectPosition.getX(), + objectPosition.getY()); ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world); itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage); - assertTrue("ObjectVerificationHandler: message not terminated when object out of range!", itemOnObjectMessage.terminated()); + assertTrue("ObjectVerificationHandler: message not terminated when object out of range!", + itemOnObjectMessage.terminated()); } } \ No newline at end of file From ef75cdaf7bd7f7dd144bd5457e02d033fa8d61ba Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 24 Mar 2020 23:04:17 -0400 Subject: [PATCH 29/63] Ground items interactions complete. --- .../message/impl/decode/OpItemMessage.java | 89 +++++++++++++++++++ .../org/apollo/game/model/entity/Player.java | 8 +- .../apollo/game/release/r181/Release181.java | 8 ++ .../map/item/FifthOpItemMessageDecoder.java | 22 +++++ .../map/item/FirstOpItemMessageDecoder.java | 22 +++++ .../map/item/FourthOpItemMessageDecoder.java | 22 +++++ .../map/item/SecondOpItemMessageDecoder.java | 22 +++++ .../map/item/ThirdOpItemMessageDecoder.java | 22 +++++ .../ui/opheld/FifthOpHeldMessageDecoder.java | 2 +- .../ui/opheld/SecondOpHeldMessageDecoder.java | 4 +- .../ui/opheld/SixthOpHeldMessageDecoder.java | 7 +- .../ui/opheld/ThirdOpHeldMessageDecoder.java | 4 +- 12 files changed, 220 insertions(+), 12 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/message/impl/decode/OpItemMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FifthOpItemMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FirstOpItemMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FourthOpItemMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/map/item/SecondOpItemMessageDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/map/item/ThirdOpItemMessageDecoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/OpItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/OpItemMessage.java new file mode 100644 index 000000000..15eced808 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/OpItemMessage.java @@ -0,0 +1,89 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +/** + * The type Op item message. + */ +public class OpItemMessage extends Message { + + /** + * The option. + */ + private final int option; + /** + * The item id. + */ + private final int id; + /** + * The position of the item. + */ + private final int x, y; + + /** + * The movement type. + */ + private final int movementType; + + /** + * Instantiates a new option item message. + * + * @param id the item id + * @param x the x + * @param y the y + * @param movementType the movement type + */ + public OpItemMessage(int option, int id, int x, int y, int movementType) { + this.option = option; + this.id = id; + this.x = x; + this.y = y; + this.movementType = movementType; + } + + + /** + * Gets option. + * + * @return the option + */ + public int getOption() { + return option; + } + + /** + * Gets item. + * + * @return the item + */ + public int getId() { + return id; + } + + /** + * Gets x. + * + * @return the x + */ + public int getX() { + return x; + } + + /** + * Gets y. + * + * @return the y + */ + public int getY() { + return y; + } + + /** + * Is movement type. + * + * @return the type of movement. + */ + public int getMovementType() { + return movementType; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 3be450867..77c1abafd 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -223,6 +223,8 @@ public Player(World world, PlayerCredentials credentials, Position position) { super(world, position); this.credentials = credentials; + inventory.add(4155, 1); + init(); } @@ -1003,10 +1005,12 @@ private void initInventories() { InventoryListener appearance = new AppearanceInventoryListener(this); InventoryListener syncInventory = new SynchronizationInventoryListener(this, - SynchronizationInventoryListener.INVENTORY_ID, SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, + SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, SynchronizationInventoryListener.INVENTORY_INVENTORY); InventoryListener syncEquipment = new SynchronizationInventoryListener(this, - SynchronizationInventoryListener.EQUIPMENT_ID, SynchronizationInventoryListener.EQUIPMENT_CONTAINER_COMPONENT, + SynchronizationInventoryListener.EQUIPMENT_ID, + SynchronizationInventoryListener.EQUIPMENT_CONTAINER_COMPONENT, SynchronizationInventoryListener.EQUIPMENT_CONTAINER); inventory.addListener(syncInventory); diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 71bd8975c..ec17d9659 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -8,6 +8,7 @@ import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; +import org.apollo.game.release.r181.decoders.map.item.*; import org.apollo.game.release.r181.decoders.map.npc.*; import org.apollo.game.release.r181.decoders.map.obj.*; import org.apollo.game.release.r181.decoders.map.player.ReportAbuseMessageDecoder; @@ -234,6 +235,13 @@ private void init() { register(58, new FifthOpHeldMessageDecoder()); register(24, new SixthOpHeldMessageDecoder()); + + register(5, new FirstOpItemMessageDecoder()); + register(74, new SecondOpItemMessageDecoder()); + register(6, new ThirdOpItemMessageDecoder()); + register(29, new FourthOpItemMessageDecoder()); + register(51, new FifthOpItemMessageDecoder()); + /** * Resume Inputs */ diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FifthOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FifthOpItemMessageDecoder.java new file mode 100644 index 000000000..700fc9b5c --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FifthOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FifthOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int movementType = (int) reader.getUnsigned(DataType.BYTE); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT); + + return new OpItemMessage(5, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FirstOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FirstOpItemMessageDecoder.java new file mode 100644 index 000000000..2a272d27b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FirstOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FirstOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int movementType = (int) reader.getUnsigned(DataType.BYTE); + + return new OpItemMessage(1, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FourthOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FourthOpItemMessageDecoder.java new file mode 100644 index 000000000..11e52140f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FourthOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FourthOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT,DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int x = (int) reader.getUnsigned(DataType.SHORT); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + + return new OpItemMessage(4, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/SecondOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/SecondOpItemMessageDecoder.java new file mode 100644 index 000000000..2065252a5 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/SecondOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SecondOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT); + int movementType = (int) reader.getUnsigned(DataType.BYTE); + + return new OpItemMessage(2, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/ThirdOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/ThirdOpItemMessageDecoder.java new file mode 100644 index 000000000..e711907ab --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/ThirdOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class ThirdOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + + return new OpItemMessage(3, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java index 465a74670..6e0f50c4d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java @@ -13,8 +13,8 @@ public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int interfacePacked = (int) reader.getUnsigned(DataType.INT); - int itemId = (int) reader.getUnsigned(DataType.SHORT); int slot = (int) reader.getUnsigned(DataType.SHORT); + int itemId = (int) reader.getUnsigned(DataType.SHORT); return new ItemActionMessage(5, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java index a526eb650..408f33537 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java @@ -12,9 +12,9 @@ public class SecondOpHeldMessageDecoder extends MessageDecoder> 16, interfacePacked & 0xFFFF, itemId, slot); } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java index b7caff005..dc86dbae1 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java @@ -1,10 +1,7 @@ package org.apollo.game.release.r181.decoders.ui.opheld; import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** @@ -15,7 +12,7 @@ public class SixthOpHeldMessageDecoder extends MessageDecoder public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int itemId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); return new ItemActionMessage(6, -1, -1, itemId, -1); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java index 70ca40cca..70e65d941 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java @@ -12,9 +12,9 @@ public class ThirdOpHeldMessageDecoder extends MessageDecoder public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int itemId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); return new ItemActionMessage(3, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); } From 62bd614eb0086da5b9a020c9c31c26a99ed128bd Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 24 Mar 2020 23:17:14 -0400 Subject: [PATCH 30/63] Moved around some decoder messages. --- game/data/messages.xml | 16 ++++----- .../testing/junit/api/interactions/player.kt | 5 +-- .../consumables/src/consumables.plugin.kts | 2 +- .../apollo/game/plugin/shops/Shops.plugin.kts | 2 +- .../skills/herblore/src/Herblore.plugin.kts | 4 +-- .../skills/prayer/src/Prayer.plugin.kts | 2 +- .../runecrafting/src/Runecrafting.plugin.kts | 3 ++ .../message/handler/BankMessageHandler.java | 2 +- .../ClosedInterfaceMessageHandler.java | 2 +- .../message/handler/EquipItemHandler.java | 2 +- .../ItemOnItemVerificationHandler.java | 2 +- .../ItemOnObjectVerificationHandler.java | 2 +- .../handler/ItemVerificationHandler.java | 2 +- .../MagicOnMobVerificationHandler.java | 2 +- .../handler/PlayerDesignMessageHandler.java | 2 +- .../PlayerDesignVerificationHandler.java | 2 +- .../handler/RemoveEquippedItemHandler.java | 2 +- .../message/impl/MouseClickedMessage.java | 1 + .../{ => decode}/ClosedInterfaceMessage.java | 2 +- .../impl/{ => decode}/FocusUpdateMessage.java | 2 +- .../{ => decode}/InventoryItemMessage.java | 2 +- .../impl/{ => decode}/ItemActionMessage.java | 2 +- .../impl/{ => decode}/ItemOnItemMessage.java | 2 +- .../impl/{ => decode}/ItemOnNpcMessage.java | 2 +- .../{ => decode}/ItemOnObjectMessage.java | 2 +- .../impl/{ => decode}/ItemOptionMessage.java | 2 +- .../impl/{ => decode}/MagicOnItemMessage.java | 4 ++- .../impl/{ => decode}/MagicOnMobMessage.java | 2 +- .../impl/{ => decode}/MagicOnNpcMessage.java | 2 +- .../{ => decode}/MagicOnPlayerMessage.java | 2 +- .../{ => decode}/PlayerDesignMessage.java | 2 +- .../apollo/game/release/r181/Release181.java | 3 ++ .../decoders/FocusUpdateMessageDecoder.java | 2 +- .../player/PlayerDesignMessageDecoder.java | 35 +++++++++++++++++++ .../ui/ClosedInterfaceMessageDecoder.java | 2 +- .../ui/opheld/FifthOpHeldMessageDecoder.java | 2 +- .../ui/opheld/FirstOpHeldMessageDecoder.java | 2 +- .../ui/opheld/FourthOpHeldMessageDecoder.java | 2 +- .../ui/opheld/SecondOpHeldMessageDecoder.java | 2 +- .../ui/opheld/SixthOpHeldMessageDecoder.java | 2 +- .../ui/opheld/ThirdOpHeldMessageDecoder.java | 2 +- .../ItemOnItemVerificationHandlerTests.java | 2 +- .../ItemOnObjectVerificationHandlerTests.java | 2 +- 43 files changed, 93 insertions(+), 48 deletions(-) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ClosedInterfaceMessage.java (82%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/FocusUpdateMessage.java (93%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/InventoryItemMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ItemActionMessage.java (94%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ItemOnItemMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ItemOnNpcMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ItemOnObjectMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ItemOptionMessage.java (94%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/MagicOnItemMessage.java (87%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/MagicOnMobMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/MagicOnNpcMessage.java (90%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/MagicOnPlayerMessage.java (90%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/PlayerDesignMessage.java (93%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/map/player/PlayerDesignMessageDecoder.java diff --git a/game/data/messages.xml b/game/data/messages.xml index fd3463757..9db866791 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -20,7 +20,7 @@ - org.apollo.game.message.impl.ClosedInterfaceMessage + org.apollo.game.message.impl.decode.ClosedInterfaceMessage org.apollo.game.message.handler.ClosedInterfaceMessageHandler @@ -44,7 +44,7 @@ - org.apollo.game.message.impl.ItemActionMessage + org.apollo.game.message.impl.decode.ItemActionMessage org.apollo.game.message.handler.ItemVerificationHandler org.apollo.game.message.handler.RemoveEquippedItemHandler @@ -52,33 +52,33 @@ - org.apollo.game.message.impl.ItemOnItemMessage + org.apollo.game.message.impl.decode.ItemOnItemMessage org.apollo.game.message.handler.ItemVerificationHandler org.apollo.game.message.handler.ItemOnItemVerificationHandler - org.apollo.game.message.impl.ItemOnObjectMessage + org.apollo.game.message.impl.decode.ItemOnObjectMessage org.apollo.game.message.handler.ItemOnObjectVerificationHandler - org.apollo.game.message.impl.ItemOptionMessage + org.apollo.game.message.impl.decode.ItemOptionMessage org.apollo.game.message.handler.ItemVerificationHandler org.apollo.game.message.handler.EquipItemHandler - org.apollo.game.message.impl.MagicOnItemMessage + org.apollo.game.message.impl.decode.MagicOnItemMessage org.apollo.game.message.handler.ItemVerificationHandler - org.apollo.game.message.impl.MagicOnMobMessage + org.apollo.game.message.impl.decode.MagicOnMobMessage org.apollo.game.message.handler.MagicOnMobVerificationHandler @@ -102,7 +102,7 @@ - org.apollo.game.message.impl.PlayerDesignMessage + org.apollo.game.message.impl.decode.PlayerDesignMessage org.apollo.game.message.handler.PlayerDesignVerificationHandler org.apollo.game.message.handler.PlayerDesignMessageHandler diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt index dffff1dc1..6ac0ce138 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt @@ -1,6 +1,6 @@ package org.apollo.game.plugin.testing.junit.api.interactions -import org.apollo.game.message.impl.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemOptionMessage import org.apollo.game.message.impl.NpcActionMessage import org.apollo.game.message.impl.ObjectActionMessage import org.apollo.game.message.impl.PlayerActionMessage @@ -16,7 +16,8 @@ import org.apollo.game.model.entity.obj.GameObject * player interacting with an item. */ fun Player.interactWithItem(id: Int, option: Int, slot: Int? = null, interfaceId: Int? = null, componentId: Int? = null) { - send(ItemOptionMessage(option, interfaceId ?: -1, componentId ?: -1, id, slot ?: inventory.slotOf(id))) + send(ItemOptionMessage(option, interfaceId ?: -1, componentId + ?: -1, id, slot ?: inventory.slotOf(id))) } /** diff --git a/game/plugin/consumables/src/consumables.plugin.kts b/game/plugin/consumables/src/consumables.plugin.kts index 1711d43eb..435d4954e 100644 --- a/game/plugin/consumables/src/consumables.plugin.kts +++ b/game/plugin/consumables/src/consumables.plugin.kts @@ -1,6 +1,6 @@ import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncAction -import org.apollo.game.message.impl.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemOptionMessage import org.apollo.game.model.Animation import org.apollo.game.model.entity.Player import org.apollo.net.message.Message diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts index 9fdeab311..948fec2c7 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts @@ -1,7 +1,7 @@ package org.apollo.game.plugin.shops import org.apollo.game.message.handler.ItemVerificationHandler -import org.apollo.game.message.impl.ItemActionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.message.impl.NpcActionMessage import org.apollo.game.model.entity.Mob import org.apollo.game.scheduling.ScheduledTask diff --git a/game/plugin/skills/herblore/src/Herblore.plugin.kts b/game/plugin/skills/herblore/src/Herblore.plugin.kts index f575a6532..01f266783 100644 --- a/game/plugin/skills/herblore/src/Herblore.plugin.kts +++ b/game/plugin/skills/herblore/src/Herblore.plugin.kts @@ -5,8 +5,8 @@ import Herb.Companion.isIdentified import Herb.Companion.isUnidentified import Ingredient.Companion.isIngredient import UnfinishedPotion.Companion.isUnfinished -import org.apollo.game.message.impl.ItemOnItemMessage -import org.apollo.game.message.impl.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemOnItemMessage +import org.apollo.game.message.impl.decode.ItemOptionMessage on { ItemOptionMessage::class } .where { option == IdentifyHerbAction.IDENTIFY_OPTION && id.isUnidentified() } diff --git a/game/plugin/skills/prayer/src/Prayer.plugin.kts b/game/plugin/skills/prayer/src/Prayer.plugin.kts index 3aca62a45..f1e65ff24 100644 --- a/game/plugin/skills/prayer/src/Prayer.plugin.kts +++ b/game/plugin/skills/prayer/src/Prayer.plugin.kts @@ -1,7 +1,7 @@ import Bone.Companion.isBone import Prayer.Companion.isPrayerButton import org.apollo.game.message.impl.IfActionMessage -import org.apollo.game.message.impl.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemOptionMessage import org.apollo.game.model.event.impl.LogoutEvent import org.apollo.game.plugin.api.prayer diff --git a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts index 6cca23a6a..116b2db4f 100644 --- a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts +++ b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts @@ -1,6 +1,9 @@ package org.apollo.game.plugin.skill.runecrafting import org.apollo.game.message.impl.* +import org.apollo.game.message.impl.decode.ItemActionMessage +import org.apollo.game.message.impl.decode.ItemOnObjectMessage +import org.apollo.game.message.impl.decode.ItemOptionMessage import org.apollo.game.message.impl.encode.ConfigMessage import org.apollo.game.model.entity.EquipmentConstants import org.apollo.game.model.event.impl.LoginEvent diff --git a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java index d91c2fe65..a851fc470 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.game.model.inter.EnterAmountListener; diff --git a/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java index 8ce62adc0..ec1d40b5b 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ClosedInterfaceMessage; +import org.apollo.game.message.impl.decode.ClosedInterfaceMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java index 2eb978660..17ce9f456 100644 --- a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.ItemOptionMessage; +import org.apollo.game.message.impl.decode.ItemOptionMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java index 443b5d269..b993c1838 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ItemOnItemMessage; +import org.apollo.game.message.impl.decode.ItemOnItemMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java index 4ce595a30..4a4d70710 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ItemOnObjectMessage; +import org.apollo.game.message.impl.decode.ItemOnObjectMessage; import org.apollo.game.model.Item; import org.apollo.game.model.Position; import org.apollo.game.model.World; diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java index 5377357ff..7bf075c5e 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.InventoryItemMessage; +import org.apollo.game.message.impl.decode.InventoryItemMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java index 7df2ba757..7afa661be 100644 --- a/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.MagicOnMobMessage; +import org.apollo.game.message.impl.decode.MagicOnMobMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.Mob; diff --git a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java index b078be2bd..24f43b0ff 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.game.message.impl.PlayerDesignMessage; +import org.apollo.game.message.impl.decode.PlayerDesignMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java index 3fd3bde06..33b2c568f 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PlayerDesignMessage; +import org.apollo.game.message.impl.decode.PlayerDesignMessage; import org.apollo.game.model.Appearance; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java index 6884dd262..e6260bdbd 100644 --- a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java b/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java index 6636535fd..576f79054 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.decode.FocusUpdateMessage; import org.apollo.net.message.Message; /** diff --git a/game/src/main/java/org/apollo/game/message/impl/ClosedInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ClosedInterfaceMessage.java similarity index 82% rename from game/src/main/java/org/apollo/game/message/impl/ClosedInterfaceMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ClosedInterfaceMessage.java index cc6ff1417..7975ea1df 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ClosedInterfaceMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ClosedInterfaceMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/FocusUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/FocusUpdateMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/FocusUpdateMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/FocusUpdateMessage.java index 3dbe7544b..f75cff9e3 100644 --- a/game/src/main/java/org/apollo/game/message/impl/FocusUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/FocusUpdateMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java index cd47e6a0f..8951baa94 100644 --- a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java index 586058d64..0e55bd87e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java index 9b133ad46..af903ea62 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import java.util.OptionalInt; diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnNpcMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnNpcMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/ItemOnNpcMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemOnNpcMessage.java index 67e61827d..565a02c95 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnNpcMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnNpcMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnObjectMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemOnObjectMessage.java index fa0c67673..62f00b3ea 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnObjectMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.Position; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOptionMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemOptionMessage.java index cab880b28..e075b84e4 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOptionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import java.util.OptionalInt; diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java similarity index 87% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java index 47ecb6e47..110f2c0ca 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java @@ -1,4 +1,6 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; + +import org.apollo.game.message.impl.decode.InventoryItemMessage; import java.util.OptionalInt; diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnMobMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnMobMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnMobMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnMobMessage.java index fabdc16b8..44f86919d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnMobMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnMobMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import com.google.common.base.MoreObjects; import org.apollo.game.model.entity.EntityType; diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnNpcMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnNpcMessage.java similarity index 90% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnNpcMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnNpcMessage.java index 09d6c607f..6491d995e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnNpcMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnNpcMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.entity.EntityType; diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnPlayerMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnPlayerMessage.java similarity index 90% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnPlayerMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnPlayerMessage.java index c7fb0c58a..d21483ab5 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnPlayerMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnPlayerMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.entity.EntityType; diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerDesignMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerDesignMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/PlayerDesignMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PlayerDesignMessage.java index e3e34b3e5..5d0f90095 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerDesignMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerDesignMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.Appearance; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index ec17d9659..1af4cceac 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -11,6 +11,7 @@ import org.apollo.game.release.r181.decoders.map.item.*; import org.apollo.game.release.r181.decoders.map.npc.*; import org.apollo.game.release.r181.decoders.map.obj.*; +import org.apollo.game.release.r181.decoders.map.player.PlayerDesignMessageDecoder; import org.apollo.game.release.r181.decoders.map.player.ReportAbuseMessageDecoder; import org.apollo.game.release.r181.decoders.map.player.actions.*; import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; @@ -259,6 +260,8 @@ private void init() { register(75, new SeventhPlayerActionMessageDecoder()); register(50, new EightPlayerActionMessageDecoder()); + register(12, new PlayerDesignMessageDecoder()); + /** * NPC */ diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java index 2267019e7..c5514eb79 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.FocusUpdateMessage; +import org.apollo.game.message.impl.decode.FocusUpdateMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/PlayerDesignMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/PlayerDesignMessageDecoder.java new file mode 100644 index 000000000..1ee34426f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/PlayerDesignMessageDecoder.java @@ -0,0 +1,35 @@ +package org.apollo.game.release.r181.decoders.map.player; + +import org.apollo.game.message.impl.decode.PlayerDesignMessage; +import org.apollo.game.model.Appearance; +import org.apollo.game.model.entity.setting.Gender; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class PlayerDesignMessageDecoder extends MessageDecoder { + + @Override + public PlayerDesignMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int genderIntValue = (int) reader.getUnsigned(DataType.BYTE); + + int[] style = new int[7]; + for (int i = 0; i < style.length; i++) { + style[i] = (int) reader.getUnsigned(DataType.BYTE); + } + + int[] color = new int[5]; + for (int i = 0; i < color.length; i++) { + color[i] = (int) reader.getUnsigned(DataType.BYTE); + } + + Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE; + + return new PlayerDesignMessage(new Appearance(gender, style, color)); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java index e95d71f35..62cf6cdf5 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui; -import org.apollo.game.message.impl.ClosedInterfaceMessage; +import org.apollo.game.message.impl.decode.ClosedInterfaceMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java index 6e0f50c4d..46f476e4f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.opheld; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java index be9ac7abe..900557b1e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.opheld; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.net.codec.game.DataOrder; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java index f42281d20..27cc16acf 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.opheld; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java index 408f33537..c1a9cfcb1 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.opheld; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java index dc86dbae1..e9f127103 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.opheld; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java index 70e65d941..2695f723a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.opheld; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java index df2c8bda7..8cddd76d0 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.ItemDefinition; -import org.apollo.game.message.impl.ItemOnItemMessage; +import org.apollo.game.message.impl.decode.ItemOnItemMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java index 9d3c1e197..99de9f0c4 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java @@ -2,7 +2,7 @@ import org.apollo.cache.def.ItemDefinition; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ItemOnObjectMessage; +import org.apollo.game.message.impl.decode.ItemOnObjectMessage; import org.apollo.game.model.Item; import org.apollo.game.model.Position; import org.apollo.game.model.World; From 48e3fc49c2df62f3c23bd1715aafb1afe788da0f Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Thu, 26 Mar 2020 00:17:08 -0400 Subject: [PATCH 31/63] Did a ton of encoder messages for interfaces. --- .../message/impl/DialogueContinueMessage.java | 2 +- .../impl/DisplayTabInterfaceMessage.java | 2 +- .../impl/OpenDialogueInterfaceMessage.java | 35 -------- .../impl/OpenDialogueOverlayMessage.java | 35 -------- .../impl/OpenInterfaceSidebarMessage.java | 51 ------------ .../game/message/impl/OpenOverlayMessage.java | 35 -------- .../game/message/impl/OpenSidebarMessage.java | 35 -------- .../impl/SetWidgetItemModelMessage.java | 67 --------------- .../impl/SetWidgetNpcModelMessage.java | 51 ------------ .../impl/SetWidgetPlayerModelMessage.java | 35 -------- .../message/impl/TakeTileItemMessage.java | 52 ------------ .../impl/decode/InventoryItemMessage.java | 2 +- .../impl/decode/ItemActionMessage.java | 2 +- .../impl/decode/ItemOnItemMessage.java | 2 +- .../impl/decode/MagicOnItemMessage.java | 2 +- .../message/impl/encode/ConfigMessage.java | 2 +- .../impl/encode/IfClearItemsMessage.java | 35 ++++++++ .../impl/encode/IfSetAngleMessage.java | 83 +++++++++++++++++++ .../IfSetAnimMessage.java} | 18 ++-- .../impl/encode/IfSetColourMessage.java | 65 +++++++++++++++ .../IfSetHideMessage.java} | 25 +++--- .../message/impl/encode/IfSetItemMessage.java | 68 +++++++++++++++ .../IfSetModelMessage.java} | 16 ++-- .../impl/encode/IfSetModelRotateMessage.java | 67 +++++++++++++++ .../impl/encode/IfSetNpcHeadMessage.java | 52 ++++++++++++ .../impl/encode/IfSetPlayerHeadMessage.java | 36 ++++++++ .../impl/encode/IfSetPositionMessage.java | 55 ++++++++++++ .../impl/encode/IfSetScrollPosMessage.java | 44 ++++++++++ .../IfSetTextMessage.java} | 17 ++-- .../MobResetAnimsMessage.java} | 4 +- .../impl/encode/RunClientScriptMessage.java | 41 +++++++++ .../org/apollo/game/model/entity/Player.java | 3 +- .../apollo/game/model/inter/InterfaceSet.java | 29 +------ .../apollo/game/release/r181/Release181.java | 24 ++++-- .../FifthNpcActionMessageDecoder.java | 2 +- .../FirstNpcActionMessageDecoder.java | 2 +- .../FourthNpcActionMessageDecoder.java | 2 +- .../SecondNpcActionMessageDecoder.java | 2 +- .../SixthNpcActionMessageDecoder.java | 2 +- .../ThirdNpcActionMessageDecoder.java | 2 +- .../encoders/region/MobResetAnimsEncoder.java | 19 +++++ .../encoders/ui/ConfigMessageEncoder.java | 1 - .../r181/encoders/ui/IfClearItemsEncoder.java | 21 +++++ .../r181/encoders/ui/IfSetAngleEncoder.java | 24 ++++++ .../r181/encoders/ui/IfSetAnimEncoder.java | 24 ++++++ .../r181/encoders/ui/IfSetColourEncoder.java | 20 +++++ .../encoders/ui/IfSetEventMessageEncoder.java | 3 - .../r181/encoders/ui/IfSetHiddenEncoder.java | 24 ++++++ .../r181/encoders/ui/IfSetItemEncoder.java | 25 ++++++ .../r181/encoders/ui/IfSetModelEncoder.java | 21 +++++ .../encoders/ui/IfSetModelRotateEncoder.java | 22 +++++ .../r181/encoders/ui/IfSetNpcHeadEncoder.java | 21 +++++ .../encoders/ui/IfSetPlayerHeadEncoder.java | 24 ++++++ .../encoders/ui/IfSetPositionEncoder.java | 22 +++++ .../encoders/ui/IfSetScrollPosEncoder.java | 21 +++++ .../r181/encoders/ui/IfSetTextEncoder.java | 24 ++++++ .../encoders/ui/RunClientScriptEncoder.java | 39 +++++++++ 57 files changed, 973 insertions(+), 486 deletions(-) delete mode 100644 game/src/main/java/org/apollo/game/message/impl/OpenDialogueInterfaceMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/OpenDialogueOverlayMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/OpenInterfaceSidebarMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/OpenOverlayMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/OpenSidebarMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/SetWidgetItemModelMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/SetWidgetNpcModelMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/SetWidgetPlayerModelMessage.java delete mode 100644 game/src/main/java/org/apollo/game/message/impl/TakeTileItemMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetAngleMessage.java rename game/src/main/java/org/apollo/game/message/impl/{SetWidgetModelAnimationMessage.java => encode/IfSetAnimMessage.java} (59%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetColourMessage.java rename game/src/main/java/org/apollo/game/message/impl/{SetWidgetVisibilityMessage.java => encode/IfSetHideMessage.java} (50%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java rename game/src/main/java/org/apollo/game/message/impl/{SetWidgetModelMessage.java => encode/IfSetModelMessage.java} (58%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelRotateMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetNpcHeadMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetPlayerHeadMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetPositionMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java rename game/src/main/java/org/apollo/game/message/impl/{SetWidgetTextMessage.java => encode/IfSetTextMessage.java} (57%) rename game/src/main/java/org/apollo/game/message/impl/{MobAnimationResetMessage.java => encode/MobResetAnimsMessage.java} (59%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/RunClientScriptMessage.java rename game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/{ => actions}/FifthNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/{ => actions}/FirstNpcActionMessageDecoder.java (91%) rename game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/{ => actions}/FourthNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/{ => actions}/SecondNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/{ => actions}/SixthNpcActionMessageDecoder.java (92%) rename game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/{ => actions}/ThirdNpcActionMessageDecoder.java (91%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/MobResetAnimsEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAngleEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetColourEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelRotateEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetNpcHeadEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPlayerHeadEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPositionEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/ui/RunClientScriptEncoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java b/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java index 8a95ab16c..755c0450e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java @@ -6,7 +6,7 @@ * A {@link Message} sent by the client when the player clicks the "Click here to continue" button on a dialogue * interface. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class DialogueContinueMessage extends Message { diff --git a/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java index 4a6f7ccb0..4715ac061 100644 --- a/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java @@ -5,7 +5,7 @@ /** * A {@link Message} sent to the client to change the currently displayed tab interface. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class DisplayTabInterfaceMessage extends Message { diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenDialogueInterfaceMessage.java deleted file mode 100644 index d68083e8b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueInterfaceMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that opens a dialogue interface (an interface that appears in the chat box). - * - * @author Chris Fletcher - */ -public final class OpenDialogueInterfaceMessage extends Message { - - /** - * The interface id. - */ - private final int interfaceId; - - /** - * Creates a new message with the specified interface id. - * - * @param interfaceId The interface id. - */ - public OpenDialogueInterfaceMessage(int interfaceId) { - this.interfaceId = interfaceId; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getInterfaceId() { - return interfaceId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueOverlayMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenDialogueOverlayMessage.java deleted file mode 100644 index c54521a63..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueOverlayMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that opens a dialogue interface (an interface that appears in the chat box). - * - * @author Chris Fletcher - */ -public final class OpenDialogueOverlayMessage extends Message { - - /** - * The interface id. - */ - private final int interfaceId; - - /** - * Creates a new message with the specified interface id. - * - * @param interfaceId The interface id. - */ - public OpenDialogueOverlayMessage(int interfaceId) { - this.interfaceId = interfaceId; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getInterfaceId() { - return interfaceId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceSidebarMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceSidebarMessage.java deleted file mode 100644 index 68f9ae57c..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceSidebarMessage.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to open an interface and a sidebar. - * - * @author Graham - */ -public final class OpenInterfaceSidebarMessage extends Message { - - /** - * The interface id. - */ - private final int interfaceId; - - /** - * The sidebar id. - */ - private final int sidebarId; - - /** - * Creates the OpenInterfaceSidebarMessage. - * - * @param interfaceId The interface id. - * @param sidebarId The sidebar id. - */ - public OpenInterfaceSidebarMessage(int interfaceId, int sidebarId) { - this.interfaceId = interfaceId; - this.sidebarId = sidebarId; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getInterfaceId() { - return interfaceId; - } - - /** - * Gets the sidebar id. - * - * @return The sidebar id. - */ - public int getSidebarId() { - return sidebarId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenOverlayMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenOverlayMessage.java deleted file mode 100644 index b304d343b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenOverlayMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to open an overlay interface. - * - * @author Major - */ -public final class OpenOverlayMessage extends Message { - - /** - * The overlay id. - */ - private final int overlayId; - - /** - * Creates the OpenSidebarMessage. - * - * @param overlayId The overlay id. - */ - public OpenOverlayMessage(int overlayId) { - this.overlayId = overlayId; - } - - /** - * Gets the overlay id. - * - * @return The overlay id. - */ - public int getOverlayId() { - return overlayId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenSidebarMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenSidebarMessage.java deleted file mode 100644 index 5d1548f28..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenSidebarMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to open a sidebar interface. - * - * @author Major - */ -public final class OpenSidebarMessage extends Message { - - /** - * The sidebar id. - */ - private final int sidebarId; - - /** - * Creates the OpenSidebarMessage. - * - * @param sidebarId The sidebar id. - */ - public OpenSidebarMessage(int sidebarId) { - this.sidebarId = sidebarId; - } - - /** - * Gets the sidebar id. - * - * @return The sidebar id. - */ - public int getSidebarId() { - return sidebarId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetItemModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/SetWidgetItemModelMessage.java deleted file mode 100644 index 58f344867..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetItemModelMessage.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to set a widget's displayed item model. - * - * @author Chris Fletcher - */ -public final class SetWidgetItemModelMessage extends Message { - - /** - * The interface's id. - */ - private final int interfaceId; - - /** - * The model's (item) id. - */ - private final int modelId; - - /** - * The zoom level. - */ - private final int zoom; - - /** - * Creates a new set interface item model message. - * - * @param interfaceId The interface's id. - * @param modelId The model's (item) id. - * @param zoom The zoom level. - */ - public SetWidgetItemModelMessage(int interfaceId, int modelId, int zoom) { - this.interfaceId = interfaceId; - this.modelId = modelId; - this.zoom = zoom; - } - - /** - * Gets the interface's id. - * - * @return The id. - */ - public int getInterfaceId() { - return interfaceId; - } - - /** - * Gets the model's (item) id. - * - * @return The id. - */ - public int getModelId() { - return modelId; - } - - /** - * Gets the zoom level. - * - * @return The zoom. - */ - public int getZoom() { - return zoom; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetNpcModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/SetWidgetNpcModelMessage.java deleted file mode 100644 index 10c95fd69..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetNpcModelMessage.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to set a widget's displayed npc model. - * - * @author Chris Fletcher - */ -public final class SetWidgetNpcModelMessage extends Message { - - /** - * The interface's id. - */ - private final int interfaceId; - - /** - * The model's (NPC) id. - */ - private final int modelId; - - /** - * Creates a new set interface NPC model message. - * - * @param interfaceId The interface's id. - * @param modelId The model's (NPC) id. - */ - public SetWidgetNpcModelMessage(int interfaceId, int modelId) { - this.interfaceId = interfaceId; - this.modelId = modelId; - } - - /** - * Gets the interface's id. - * - * @return The id. - */ - public int getInterfaceId() { - return interfaceId; - } - - /** - * Gets the model's (NPC) id. - * - * @return The id. - */ - public int getModelId() { - return modelId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetPlayerModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/SetWidgetPlayerModelMessage.java deleted file mode 100644 index a6a898419..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetPlayerModelMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to set a widget's displayed player model. - * - * @author Chris Fletcher - */ -public final class SetWidgetPlayerModelMessage extends Message { - - /** - * The interface's id. - */ - private final int interfaceId; - - /** - * Creates a new set interface player model message. - * - * @param interfaceId The interface's id. - */ - public SetWidgetPlayerModelMessage(int interfaceId) { - this.interfaceId = interfaceId; - } - - /** - * Gets the interface's id. - * - * @return The id. - */ - public int getInterfaceId() { - return interfaceId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/TakeTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/TakeTileItemMessage.java deleted file mode 100644 index 5c3bdc139..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/TakeTileItemMessage.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.model.Position; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent by the client to pick up an item on a tile. - * - * @author Major - */ -public final class TakeTileItemMessage extends Message { - - /** - * The id of the item. - */ - private final int id; - - /** - * The position of the tile. - */ - private final Position position; - - /** - * Creates a new take tile item message. - * - * @param id The id of the item. - * @param position The position of the tile. - */ - public TakeTileItemMessage(int id, Position position) { - this.id = id; - this.position = position; - } - - /** - * Gets the id of the item. - * - * @return The id. - */ - public int getId() { - return id; - } - - /** - * Gets the position of the tile. - * - * @return The position. - */ - public Position getPosition() { - return position; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java index 8951baa94..ae3603037 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java @@ -8,7 +8,7 @@ /** * A {@link Message} that represents some sort of action on an item in an inventory. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public abstract class InventoryItemMessage extends Message { diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java index 0e55bd87e..cf34daabd 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java @@ -9,7 +9,7 @@ * sent by the client is one of the five item action messages, but this is the message that should be intercepted (and * the option verified). * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class ItemActionMessage extends InventoryItemMessage { diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java index af903ea62..4314f1f89 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java @@ -5,7 +5,7 @@ /** * A {@link InventoryItemMessage} sent by the client when a player uses one inventory item on another. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class ItemOnItemMessage extends InventoryItemMessage { diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java index 110f2c0ca..9d45b0dc7 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java @@ -7,7 +7,7 @@ /** * A {@link InventoryItemMessage} sent by the client when a player casts a spell on an inventory item. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class MagicOnItemMessage extends InventoryItemMessage { diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java index 3d0d572d8..bae719eac 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java @@ -5,7 +5,7 @@ /** * A {@link Message} sent to the client to adjust a certain config or attribute setting. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class ConfigMessage extends Message { diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java new file mode 100644 index 000000000..819464c6f --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java @@ -0,0 +1,35 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed item model. + * + * @author Khaled Abdeljaber + */ +public final class IfClearItemsMessage extends Message { + + /** + * The interface's id. + */ + private final int interfacePacked; + + /** + * Creates a new set interface item model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + */ + public IfClearItemsMessage(int interfaceId, int componentId) { + this.interfacePacked = interfaceId << 16 | componentId; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getInterfacePacked() { + return interfacePacked; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAngleMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAngleMessage.java new file mode 100644 index 000000000..96bc0539f --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAngleMessage.java @@ -0,0 +1,83 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set angle message. + * + * @author Khaled Abdeljaber + */ +public class IfSetAngleMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * The zoom. + */ + private final int zoom; + + /** + * The rotation in the x axis. + */ + private final int rotationX; + + /** + * The rotation in the y axis. + */ + private final int rotationY; + + /** + * Instantiates a new If set angle message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param zoom the zoom. + * @param rotationX the rotationX + * @param rotationY the rotationY + */ + public IfSetAngleMessage(int interfaceId, int componentId, int zoom, int rotationX, int rotationY) { + this.packedInterface = interfaceId << 16 | componentId; + this.zoom = zoom; + this.rotationX = rotationX; + this.rotationY = rotationY; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets zoom. + * + * @return the zoom + */ + public int getZoom() { + return zoom; + } + + /** + * Gets rotation x. + * + * @return the rotation x + */ + public int getRotationX() { + return rotationX; + } + + /** + * Gets rotation y. + * + * @return the rotation y + */ + public int getRotationY() { + return rotationY; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelAnimationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java similarity index 59% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetModelAnimationMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java index b8a104b46..70abd30d2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelAnimationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java @@ -1,13 +1,13 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; /** * A {@link Message} sent to the client to set a widget's displayed mob's animation. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ -public final class SetWidgetModelAnimationMessage extends Message { +public final class IfSetAnimMessage extends Message { /** * The model's animation id. @@ -17,16 +17,16 @@ public final class SetWidgetModelAnimationMessage extends Message { /** * The interface id. */ - private final int interfaceId; + private final int interfacePacked; /** * Creates a new set interface npc model's animation message. * - * @param interfaceId The interface id. + * @param interfacePacked The interface id. * @param animation The model's animation id. */ - public SetWidgetModelAnimationMessage(int interfaceId, int animation) { - this.interfaceId = interfaceId; + public IfSetAnimMessage(int interfacePacked, int componentId, int animation) { + this.interfacePacked = interfacePacked << 16 | componentId; this.animation = animation; } @@ -44,8 +44,8 @@ public int getAnimation() { * * @return The interface id. */ - public int getInterfaceId() { - return interfaceId; + public int getInterfacePacked() { + return interfacePacked; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetColourMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetColourMessage.java new file mode 100644 index 000000000..665d34193 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetColourMessage.java @@ -0,0 +1,65 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set angle message. + * + * @author Khaled Abdeljaber + */ +public class IfSetColourMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * The packed colors. + */ + private final int packedColours; + + /** + * Instantiates a new If set colour message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param packedColours the packed colours + */ + public IfSetColourMessage(int interfaceId, int componentId, int packedColours) { + this.packedInterface = interfaceId << 16 | componentId; + this.packedColours = packedColours; + } + + /** + * Instantiates a new If set colour message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param red the red + * @param green the green + * @param blue the blue + */ + public IfSetColourMessage(int interfaceId, int componentId, int red, int green, int blue) { + this.packedInterface = interfaceId << 16 | componentId; + this.packedColours = red << 10 | green << 5 | blue; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets packed colours. + * + * @return the packed colours + */ + public int getPackedColours() { + return packedColours; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetVisibilityMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java similarity index 50% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetVisibilityMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java index 361c79489..6a224374c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetVisibilityMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -6,14 +6,14 @@ * A {@link Message} sent to the client that changes the state of a hidden widget component (e.g. the special attack bar * on the weapon tab). * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ -public final class SetWidgetVisibilityMessage extends Message { +public final class IfSetHideMessage extends Message { /** * The component id. */ - private final int component; + private final int interfacePacked; /** * Visible flag. @@ -23,21 +23,22 @@ public final class SetWidgetVisibilityMessage extends Message { /** * Creates the interface component state message. * - * @param component The compononent id. - * @param visible The flag for showing or hiding the component. + * @param interfaceId The interface id. + * @param componentId The compononent id. + * @param visible The flag for showing or hiding the component. */ - public SetWidgetVisibilityMessage(int component, boolean visible) { - this.component = component; + public IfSetHideMessage(int interfaceId, int componentId, boolean visible) { + this.interfacePacked = interfaceId << 16 | componentId; this.visible = visible; } /** - * Gets the id of the interface component. + * Gets the packed interface. * - * @return The component id. + * @return The packed interface. */ - public int getWidgetId() { - return component; + public int getInterfacePacked() { + return interfacePacked; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java new file mode 100644 index 000000000..09100d701 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java @@ -0,0 +1,68 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed item model. + * + * @author Khaled Abdeljaber + */ +public final class IfSetItemMessage extends Message { + + /** + * The interface's id. + */ + private final int interfacePacked; + + /** + * The item id. + */ + private final int item; + + /** + * The zoom level. + */ + private final int amount; + + /** + * Creates a new set interface item model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + * @param item The model's (item) id. + * @param amount The zoom level. + */ + public IfSetItemMessage(int interfaceId, int componentId, int item, int amount) { + this.interfacePacked = interfaceId << 16 | componentId; + this.item = item; + this.amount = amount; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getInterfacePacked() { + return interfacePacked; + } + + /** + * Gets the model's (item) id. + * + * @return The id. + */ + public int getItem() { + return item; + } + + /** + * Gets the zoom level. + * + * @return The zoom. + */ + public int getAmount() { + return amount; + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java similarity index 58% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetModelMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java index f343a8651..b45edcdd0 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -7,7 +7,7 @@ * * @author Major */ -public final class SetWidgetModelMessage extends Message { +public final class IfSetModelMessage extends Message { /** * The model id. @@ -17,16 +17,16 @@ public final class SetWidgetModelMessage extends Message { /** * The interface id. */ - private final int interfaceId; + private final int interfacePacked; /** * Creates a new SetWidgetModelMessage. * - * @param interfaceId The interface id. + * @param interfacePacked The interface id. * @param model The model id. */ - public SetWidgetModelMessage(int interfaceId, int model) { - this.interfaceId = interfaceId; + public IfSetModelMessage(int interfacePacked, int componentId, int model) { + this.interfacePacked = interfacePacked << 16 | componentId; this.model = model; } @@ -44,8 +44,8 @@ public int getModel() { * * @return The interface id. */ - public int getInterfaceId() { - return interfaceId; + public int getInterfacePacked() { + return interfacePacked; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelRotateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelRotateMessage.java new file mode 100644 index 000000000..96f6abe5f --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelRotateMessage.java @@ -0,0 +1,67 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set model rotate message. + * + * @author Khaled Abdeljaber + */ +public class IfSetModelRotateMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * The rotation in the x-axis. + */ + private final int rotationX; + + /** + * The rotation in the y-axis. + */ + private final int rotationY; + + /** + * Instantiates a new If set model rotate message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param rotationX the rotation x + * @param rotationY the rotation y + */ + public IfSetModelRotateMessage(int interfaceId, int componentId, int rotationX, int rotationY) { + this.packedInterface = interfaceId << 16 | componentId; + this.rotationX = rotationX; + this.rotationY = rotationY; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets rotation x. + * + * @return the rotation x + */ + public int getRotationX() { + return rotationX; + } + + /** + * Gets rotation y. + * + * @return the rotation y + */ + public int getRotationY() { + return rotationY; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetNpcHeadMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetNpcHeadMessage.java new file mode 100644 index 000000000..aebfddb4e --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetNpcHeadMessage.java @@ -0,0 +1,52 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed npc model. + * + * @author Khaled Abdeljaber + */ +public final class IfSetNpcHeadMessage extends Message { + + /** + * The interface's id. + */ + private final int packedInterface; + + /** + * The model's (NPC) id. + */ + private final int npcId; + + /** + * Creates a new set interface NPC model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + * @param npcId The model's (NPC) id. + */ + public IfSetNpcHeadMessage(int interfaceId, int componentId, int npcId) { + this.packedInterface = interfaceId << 16 | componentId; + this.npcId = npcId; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets the model's (NPC) id. + * + * @return The id. + */ + public int getNpcId() { + return npcId; + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPlayerHeadMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPlayerHeadMessage.java new file mode 100644 index 000000000..cc5b08080 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPlayerHeadMessage.java @@ -0,0 +1,36 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed player model. + * + * @author Khaled Abdeljaber + */ +public final class IfSetPlayerHeadMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * Creates a new set interface player model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + */ + public IfSetPlayerHeadMessage(int interfaceId, int componentId) { + this.packedInterface = interfaceId << 16 | componentId; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getPackedInterface() { + return packedInterface; + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPositionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPositionMessage.java new file mode 100644 index 000000000..847f131a8 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPositionMessage.java @@ -0,0 +1,55 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set position message. + * + * @author Khaled Abdeljaber + */ +public class IfSetPositionMessage extends Message { + + private final int packedInterface; + private final int x, y; + + /** + * Instantiates a new If set position message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param x the x + * @param y the y + */ + public IfSetPositionMessage(int interfaceId, int componentId, int x, int y) { + this.packedInterface = interfaceId << 16 | componentId; + this.x = x; + this.y = y; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets x. + * + * @return the x + */ + public int getX() { + return x; + } + + /** + * Gets y. + * + * @return the y + */ + public int getY() { + return y; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java new file mode 100644 index 000000000..80867d0ec --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java @@ -0,0 +1,44 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set scroll pos message. + * + * @author Khaled Abdeljaber + */ +public class IfSetScrollPosMessage extends Message { + + private final int interfacePacked; + private final int scrollPosition; + + /** + * Instantiates a new If set scroll pos message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param scrollPosition the scroll position + */ + public IfSetScrollPosMessage(int interfaceId, int componentId, int scrollPosition) { + this.interfacePacked = interfaceId << 16 | componentId; + this.scrollPosition = scrollPosition; + } + + /** + * Gets interface packed. + * + * @return the interface packed + */ + public int getInterfacePacked() { + return interfacePacked; + } + + /** + * Gets scroll position. + * + * @return the scroll position + */ + public int getScrollPosition() { + return scrollPosition; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetTextMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java similarity index 57% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetTextMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java index 5c407103f..1a64897da 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetTextMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -7,12 +7,12 @@ * * @author Graham */ -public final class SetWidgetTextMessage extends Message { +public final class IfSetTextMessage extends Message { /** * The interface's id. */ - private final int interfaceId; + private final int interfacePacked; /** * The text. @@ -23,10 +23,11 @@ public final class SetWidgetTextMessage extends Message { * Creates the set interface text message. * * @param interfaceId The interface's id. - * @param text The interface's text. + * @param componentId The component id. + * @param text The interface's text. */ - public SetWidgetTextMessage(int interfaceId, String text) { - this.interfaceId = interfaceId; + public IfSetTextMessage(int interfaceId, int componentId, String text) { + this.interfacePacked = interfaceId << 16 | componentId; this.text = text; } @@ -35,8 +36,8 @@ public SetWidgetTextMessage(int interfaceId, String text) { * * @return The interface id. */ - public int getInterfaceId() { - return interfaceId; + public int getInterfacePacked() { + return interfacePacked; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/MobAnimationResetMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/MobResetAnimsMessage.java similarity index 59% rename from game/src/main/java/org/apollo/game/message/impl/MobAnimationResetMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/MobResetAnimsMessage.java index 4bb1a74ba..e8cc6047e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MobAnimationResetMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/MobResetAnimsMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -7,6 +7,6 @@ * * @author Major */ -public final class MobAnimationResetMessage extends Message { +public final class MobResetAnimsMessage extends Message { } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/RunClientScriptMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RunClientScriptMessage.java new file mode 100644 index 000000000..0fe551447 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RunClientScriptMessage.java @@ -0,0 +1,41 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class RunClientScriptMessage extends Message { + + private final int id; + private final Object[] params; + + /** + * Instantiates a new Run client script message. + * + * @param id the id + * @param params the params + */ + public RunClientScriptMessage(int id, Object... params) { + this.id = id; + this.params = params; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Get params object [ ]. + * + * @return the object [ ] + */ + public Object[] getParams() { + return params; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 77c1abafd..f7af3c5c0 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -5,6 +5,7 @@ import org.apollo.game.message.impl.*; import org.apollo.game.message.impl.encode.ConfigMessage; import org.apollo.game.message.impl.encode.RebuildNormalMessage; +import org.apollo.game.message.impl.encode.IfSetTextMessage; import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; @@ -770,7 +771,7 @@ public void sendQuestInterface(List text) { Preconditions.checkArgument(size <= lines, "List contains too much text to display on this interface."); for (int pos = 0; pos < lines; pos++) { - send(new SetWidgetTextMessage(InterfaceConstants.QUEST_TEXT[pos], pos < size ? text.get(pos) : "")); + //send(new IfSetTextMessage(InterfaceConstants.QUEST_TEXT[pos], - pos < size ? text.get(pos) : "")); } interfaceSet.openModal(InterfaceConstants.QUEST_INTERFACE); } diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java index 9b614260f..783db21bd 100644 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java @@ -4,8 +4,6 @@ import org.apollo.game.message.handler.MessageHandlerChain; import org.apollo.game.message.impl.CloseInterfaceMessage; import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; import org.apollo.game.message.impl.encode.IfMoveSubMessage; import org.apollo.game.message.impl.encode.IfOpenSubMessage; import org.apollo.game.message.impl.encode.IfOpenTopMessage; @@ -160,7 +158,7 @@ public void openDialogue(DialogueListener listener, int dialogueId) { this.listener = Optional.ofNullable(listener); interfaces.put(ServerInterfaceType.DIALOGUE, dialogueId); - player.send(new OpenDialogueInterfaceMessage(dialogueId)); + //player.send(new OpenDialogueInterfaceMessage(dialogueId)); } /** @@ -172,31 +170,6 @@ public void openDialogue(int dialogueId) { openDialogue(null, dialogueId); } - /** - * Opens a dialogue overlay interface. - * - * @param listener The {@link DialogueListener}. - * @param dialogueId The dialogue id. - */ - public void openDialogueOverlay(DialogueListener listener, int dialogueId) { - closeAndNotify(); - - dialogueListener = Optional.ofNullable(listener); - this.listener = Optional.ofNullable(listener); - - interfaces.put(ServerInterfaceType.DIALOGUE, dialogueId); - player.send(new OpenDialogueOverlayMessage(dialogueId)); - } - - /** - * Opens a dialogue overlay. - * - * @param dialogueId The dialogue id. - */ - public void openDialogueOverlay(int dialogueId) { - openDialogueOverlay(null, dialogueId); - } - /** * Opens the enter amount dialogue. * diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 1af4cceac..4328c9896 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,15 +1,13 @@ package org.apollo.game.release.r181; -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.UpdateInventoryFullMessage; -import org.apollo.game.message.impl.UpdateInventoryPartialMessage; +import org.apollo.game.message.impl.*; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; +import org.apollo.game.release.r181.encoders.region.MobResetAnimsEncoder; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; import org.apollo.game.release.r181.decoders.map.item.*; -import org.apollo.game.release.r181.decoders.map.npc.*; +import org.apollo.game.release.r181.decoders.map.npc.actions.*; import org.apollo.game.release.r181.decoders.map.obj.*; import org.apollo.game.release.r181.decoders.map.player.PlayerDesignMessageDecoder; import org.apollo.game.release.r181.decoders.map.player.ReportAbuseMessageDecoder; @@ -161,10 +159,26 @@ private void init() { register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); + register(MobResetAnimsMessage.class, new MobResetAnimsEncoder()); + register(IfOpenTopMessage.class, new IfOpenTopMessageEncoder()); register(IfOpenSubMessage.class, new IfOpenSubMessageEncoder()); register(IfMoveSubMessage.class, new IfMoveSubMessageEncoder()); register(IfSetEventMessage.class, new IfSetEventMessageEncoder()); + register(IfClearItemsMessage.class, new IfClearItemsEncoder()); + register(IfSetAngleMessage.class, new IfSetAngleEncoder()); + register(IfSetAnimMessage.class, new IfSetAnimEncoder()); + register(IfSetColourMessage.class, new IfSetColourEncoder()); + register(IfSetHideMessage.class, new IfSetHiddenEncoder()); + register(IfSetItemMessage.class, new IfSetItemEncoder()); + register(IfSetModelMessage.class, new IfSetModelEncoder()); + register(IfSetModelRotateMessage.class, new IfSetModelRotateEncoder()); + register(IfSetNpcHeadMessage.class, new IfSetNpcHeadEncoder()); + register(IfSetPlayerHeadMessage.class, new IfSetPlayerHeadEncoder()); + register(IfSetPositionMessage.class, new IfSetPositionEncoder()); + register(IfSetScrollPosMessage.class, new IfSetScrollPosEncoder()); + register(IfSetTextMessage.class, new IfSetTextEncoder()); + register(RunClientScriptMessage.class, new RunClientScriptEncoder()); register(UpdateInventoryPartialMessage.class, new UpdateContainerPartialMessageEncoder()); register(UpdateInventoryFullMessage.class, new UpdateContainerFullMessageEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FifthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java index 51beb3c06..5b2efe6e3 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FifthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.map.npc; +package org.apollo.game.release.r181.decoders.map.npc.actions; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FirstNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java index b9b81d6f8..7ad4dc30c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FirstNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.map.npc; +package org.apollo.game.release.r181.decoders.map.npc.actions; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FourthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java index b10905bf0..800dfa73a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/FourthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.map.npc; +package org.apollo.game.release.r181.decoders.map.npc.actions; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SecondNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java index b6670d0c5..0f68c280d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.map.npc; +package org.apollo.game.release.r181.decoders.map.npc.actions; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SixthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SixthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java index 563f415bb..9026ea48c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/SixthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.map.npc; +package org.apollo.game.release.r181.decoders.map.npc.actions; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/ThirdNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java index 1ec4717a5..c2c3b72bb 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r181.decoders.map.npc; +package org.apollo.game.release.r181.decoders.map.npc.actions; import org.apollo.game.message.impl.NpcActionMessage; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/MobResetAnimsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/MobResetAnimsEncoder.java new file mode 100644 index 000000000..63f9d1725 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/MobResetAnimsEncoder.java @@ -0,0 +1,19 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.MobResetAnimsMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class MobResetAnimsEncoder extends MessageEncoder { + + @Override + public GamePacket encode(MobResetAnimsMessage message) { + final var builder = new GamePacketBuilder(28, PacketType.FIXED); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java index 00176bb15..65c93c14b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java @@ -10,7 +10,6 @@ /** * A {@link MessageEncoder} for the {@link ConfigMessage}. * - * @author Chris Fletcher * @author Khaled Abdeljaber */ public final class ConfigMessageEncoder extends MessageEncoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java new file mode 100644 index 000000000..5e3c6bf08 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfClearItemsMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfClearItemsEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfClearItemsMessage message) { + final var builder = new GamePacketBuilder(7, PacketType.FIXED); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getInterfacePacked()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAngleEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAngleEncoder.java new file mode 100644 index 000000000..aef9cdc38 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAngleEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetAngleMessage; +import org.apollo.game.message.impl.encode.IfSetNpcHeadMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetAngleEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetAngleMessage message) { + final var builder = new GamePacketBuilder(50, PacketType.FIXED); + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getRotationX()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getZoom()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getRotationY()); + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java new file mode 100644 index 000000000..90d86bada --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetAnimMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetAnimEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetAnimMessage message) { + final var builder = new GamePacketBuilder(61, PacketType.FIXED); + + builder.put(DataType.SHORT, message.getAnimation()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getInterfacePacked()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetColourEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetColourEncoder.java new file mode 100644 index 000000000..d8ab6e002 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetColourEncoder.java @@ -0,0 +1,20 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetColourMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetColourEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetColourMessage message) { + final var builder = new GamePacketBuilder(24, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getPackedColours()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java index 9748c23b7..852381a83 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java @@ -1,14 +1,11 @@ package org.apollo.game.release.r181.encoders.ui; -import it.unimi.dsi.fastutil.ints.IntCollection; import org.apollo.game.message.impl.encode.IfSetEventMessage; import org.apollo.game.model.inter.InterfaceEvent; import org.apollo.net.codec.game.*; import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; -import java.util.stream.Collectors; - /** * @author Khaled Abdeljaber */ diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java new file mode 100644 index 000000000..667359884 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetHideMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetHiddenEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetHideMessage message) { + final var builder = new GamePacketBuilder(21, PacketType.FIXED); + + builder.put(DataType.INT, message.getInterfacePacked()); + builder.put(DataType.BYTE, DataOrder.INVERSED_MIDDLE, message.isVisible() ? 0 : 1); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java new file mode 100644 index 000000000..ddfe2045f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java @@ -0,0 +1,25 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetItemMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetItemEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetItemMessage message) { + final var builder = new GamePacketBuilder(11, PacketType.FIXED); + + builder.put(DataType.INT, message.getInterfacePacked()); + builder.put(DataType.SHORT, message.getItem()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getAmount()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java new file mode 100644 index 000000000..f2add0f44 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetModelMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetModelEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetModelMessage message) { + final var builder = new GamePacketBuilder(31, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.MIDDLE, message.getInterfacePacked()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getModel()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelRotateEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelRotateEncoder.java new file mode 100644 index 000000000..2f48fbe29 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelRotateEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetModelRotateMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetModelRotateEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetModelRotateMessage message) { + final var builder = new GamePacketBuilder(41, PacketType.FIXED); + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getRotationY()); + builder.put(DataType.SHORT, DataOrder.LITTLE, message.getRotationX()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetNpcHeadEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetNpcHeadEncoder.java new file mode 100644 index 000000000..08c23035b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetNpcHeadEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetNpcHeadMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetNpcHeadEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetNpcHeadMessage message) { + final var builder = new GamePacketBuilder(35, PacketType.FIXED); + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getNpcId()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPlayerHeadEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPlayerHeadEncoder.java new file mode 100644 index 000000000..bac7e76b2 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPlayerHeadEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetItemMessage; +import org.apollo.game.message.impl.encode.IfSetPlayerHeadMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetPlayerHeadEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetPlayerHeadMessage message) { + final var builder = new GamePacketBuilder(30, PacketType.FIXED); + + builder.put(DataType.INT, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPositionEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPositionEncoder.java new file mode 100644 index 000000000..6d9be4c59 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPositionEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetPositionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetPositionEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetPositionMessage message) { + final var builder = new GamePacketBuilder(59, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getY()); + builder.put(DataType.SHORT, message.getX()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java new file mode 100644 index 000000000..c773e9fa6 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetScrollPosMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetScrollPosEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetScrollPosMessage message) { + final var builder = new GamePacketBuilder(76, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.MIDDLE, message.getInterfacePacked()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getScrollPosition()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java new file mode 100644 index 000000000..778321e32 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetTextMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetTextEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetTextMessage message) { + final var builder = new GamePacketBuilder(19, PacketType.VARIABLE_SHORT); + + builder.put(DataType.INT, message.getInterfacePacked()); + builder.putString(message.getText()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/RunClientScriptEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/RunClientScriptEncoder.java new file mode 100644 index 000000000..1aa24a130 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/RunClientScriptEncoder.java @@ -0,0 +1,39 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.RunClientScriptMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class RunClientScriptEncoder extends MessageEncoder { + @Override + public GamePacket encode(RunClientScriptMessage message) { + final var builder = new GamePacketBuilder(62, PacketType.VARIABLE_SHORT); + final var id = message.getId(); + final var params = message.getParams(); + + final var signature = new StringBuilder(); + final var internal = new GamePacketBuilder(); + for (int i = params.length - 1; i >= 0; i--) { + Object param = params[i]; + if (param instanceof String) { + signature.append("s"); + internal.putString((String) param); + } else { + signature.append("i"); + internal.put(DataType.INT, (Number) param); + } + } + + builder.putString(signature.toString()); + builder.putBytes(internal); + builder.put(DataType.INT, id); + + return builder.toGamePacket(); + } +} From a9ea8d27b1b5d4302bc41684f8aed68bb5faa4ae Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Thu, 26 Mar 2020 00:28:47 -0400 Subject: [PATCH 32/63] Standard field names. --- .../message/impl/encode/IfClearItemsMessage.java | 8 ++++---- .../game/message/impl/encode/IfSetAnimMessage.java | 12 ++++++------ .../game/message/impl/encode/IfSetHideMessage.java | 8 ++++---- .../game/message/impl/encode/IfSetItemMessage.java | 8 ++++---- .../game/message/impl/encode/IfSetModelMessage.java | 12 ++++++------ .../message/impl/encode/IfSetScrollPosMessage.java | 8 ++++---- .../game/message/impl/encode/IfSetTextMessage.java | 8 ++++---- .../ui/opheld/FifthOpHeldMessageDecoder.java | 4 ++-- .../ui/opheld/FirstOpHeldMessageDecoder.java | 4 ++-- .../ui/opheld/FourthOpHeldMessageDecoder.java | 4 ++-- .../ui/opheld/SecondOpHeldMessageDecoder.java | 4 ++-- .../ui/opheld/ThirdOpHeldMessageDecoder.java | 4 ++-- .../r181/encoders/ui/IfClearItemsEncoder.java | 2 +- .../release/r181/encoders/ui/IfSetAnimEncoder.java | 2 +- .../release/r181/encoders/ui/IfSetHiddenEncoder.java | 2 +- .../release/r181/encoders/ui/IfSetItemEncoder.java | 2 +- .../release/r181/encoders/ui/IfSetModelEncoder.java | 2 +- .../r181/encoders/ui/IfSetScrollPosEncoder.java | 2 +- .../release/r181/encoders/ui/IfSetTextEncoder.java | 2 +- 19 files changed, 49 insertions(+), 49 deletions(-) diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java index 819464c6f..1dfae19af 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java @@ -12,7 +12,7 @@ public final class IfClearItemsMessage extends Message { /** * The interface's id. */ - private final int interfacePacked; + private final int packedInterface; /** * Creates a new set interface item model message. @@ -21,7 +21,7 @@ public final class IfClearItemsMessage extends Message { * @param componentId The component id. */ public IfClearItemsMessage(int interfaceId, int componentId) { - this.interfacePacked = interfaceId << 16 | componentId; + this.packedInterface = interfaceId << 16 | componentId; } /** @@ -29,7 +29,7 @@ public IfClearItemsMessage(int interfaceId, int componentId) { * * @return The id. */ - public int getInterfacePacked() { - return interfacePacked; + public int getPackedInterface() { + return packedInterface; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java index 70abd30d2..4a3edf830 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java @@ -17,16 +17,16 @@ public final class IfSetAnimMessage extends Message { /** * The interface id. */ - private final int interfacePacked; + private final int packedInterface; /** * Creates a new set interface npc model's animation message. * - * @param interfacePacked The interface id. + * @param packedInterface The interface id. * @param animation The model's animation id. */ - public IfSetAnimMessage(int interfacePacked, int componentId, int animation) { - this.interfacePacked = interfacePacked << 16 | componentId; + public IfSetAnimMessage(int packedInterface, int componentId, int animation) { + this.packedInterface = packedInterface << 16 | componentId; this.animation = animation; } @@ -44,8 +44,8 @@ public int getAnimation() { * * @return The interface id. */ - public int getInterfacePacked() { - return interfacePacked; + public int getPackedInterface() { + return packedInterface; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java index 6a224374c..332bcffb9 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java @@ -13,7 +13,7 @@ public final class IfSetHideMessage extends Message { /** * The component id. */ - private final int interfacePacked; + private final int packedInterface; /** * Visible flag. @@ -28,7 +28,7 @@ public final class IfSetHideMessage extends Message { * @param visible The flag for showing or hiding the component. */ public IfSetHideMessage(int interfaceId, int componentId, boolean visible) { - this.interfacePacked = interfaceId << 16 | componentId; + this.packedInterface = interfaceId << 16 | componentId; this.visible = visible; } @@ -37,8 +37,8 @@ public IfSetHideMessage(int interfaceId, int componentId, boolean visible) { * * @return The packed interface. */ - public int getInterfacePacked() { - return interfacePacked; + public int getPackedInterface() { + return packedInterface; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java index 09100d701..b51d912b1 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java @@ -12,7 +12,7 @@ public final class IfSetItemMessage extends Message { /** * The interface's id. */ - private final int interfacePacked; + private final int packedInterface; /** * The item id. @@ -33,7 +33,7 @@ public final class IfSetItemMessage extends Message { * @param amount The zoom level. */ public IfSetItemMessage(int interfaceId, int componentId, int item, int amount) { - this.interfacePacked = interfaceId << 16 | componentId; + this.packedInterface = interfaceId << 16 | componentId; this.item = item; this.amount = amount; } @@ -43,8 +43,8 @@ public IfSetItemMessage(int interfaceId, int componentId, int item, int amount) * * @return The id. */ - public int getInterfacePacked() { - return interfacePacked; + public int getPackedInterface() { + return packedInterface; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java index b45edcdd0..249e15569 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java @@ -17,16 +17,16 @@ public final class IfSetModelMessage extends Message { /** * The interface id. */ - private final int interfacePacked; + private final int packedInterface; /** * Creates a new SetWidgetModelMessage. * - * @param interfacePacked The interface id. + * @param packedInterface The interface id. * @param model The model id. */ - public IfSetModelMessage(int interfacePacked, int componentId, int model) { - this.interfacePacked = interfacePacked << 16 | componentId; + public IfSetModelMessage(int packedInterface, int componentId, int model) { + this.packedInterface = packedInterface << 16 | componentId; this.model = model; } @@ -44,8 +44,8 @@ public int getModel() { * * @return The interface id. */ - public int getInterfacePacked() { - return interfacePacked; + public int getPackedInterface() { + return packedInterface; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java index 80867d0ec..7672b56e9 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java @@ -9,7 +9,7 @@ */ public class IfSetScrollPosMessage extends Message { - private final int interfacePacked; + private final int packedInterface; private final int scrollPosition; /** @@ -20,7 +20,7 @@ public class IfSetScrollPosMessage extends Message { * @param scrollPosition the scroll position */ public IfSetScrollPosMessage(int interfaceId, int componentId, int scrollPosition) { - this.interfacePacked = interfaceId << 16 | componentId; + this.packedInterface = interfaceId << 16 | componentId; this.scrollPosition = scrollPosition; } @@ -29,8 +29,8 @@ public IfSetScrollPosMessage(int interfaceId, int componentId, int scrollPositio * * @return the interface packed */ - public int getInterfacePacked() { - return interfacePacked; + public int getPackedInterface() { + return packedInterface; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java index 1a64897da..c5a18e483 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java @@ -12,7 +12,7 @@ public final class IfSetTextMessage extends Message { /** * The interface's id. */ - private final int interfacePacked; + private final int packedInterface; /** * The text. @@ -27,7 +27,7 @@ public final class IfSetTextMessage extends Message { * @param text The interface's text. */ public IfSetTextMessage(int interfaceId, int componentId, String text) { - this.interfacePacked = interfaceId << 16 | componentId; + this.packedInterface = interfaceId << 16 | componentId; this.text = text; } @@ -36,8 +36,8 @@ public IfSetTextMessage(int interfaceId, int componentId, String text) { * * @return The interface id. */ - public int getInterfacePacked() { - return interfacePacked; + public int getPackedInterface() { + return packedInterface; } /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java index 46f476e4f..e240824b2 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java @@ -12,10 +12,10 @@ public class FifthOpHeldMessageDecoder extends MessageDecoder public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int interfacePacked = (int) reader.getUnsigned(DataType.INT); + int packedInterface = (int) reader.getUnsigned(DataType.INT); int slot = (int) reader.getUnsigned(DataType.SHORT); int itemId = (int) reader.getUnsigned(DataType.SHORT); - return new ItemActionMessage(5, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + return new ItemActionMessage(5, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java index 900557b1e..fe3331260 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java @@ -16,9 +16,9 @@ public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.MIDDLE); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.MIDDLE); int slot = (int) reader.getUnsigned(DataType.SHORT); - return new ItemActionMessage(1, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + return new ItemActionMessage(1, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java index 27cc16acf..fc9e7931c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java @@ -13,9 +13,9 @@ public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfacePacked = (int) reader.getUnsigned(DataType.INT); + int packedInterface = (int) reader.getUnsigned(DataType.INT); int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - return new ItemActionMessage(4, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + return new ItemActionMessage(4, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java index c1a9cfcb1..bdc3c683d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java @@ -13,9 +13,9 @@ public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int itemId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - return new ItemActionMessage(2, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + return new ItemActionMessage(2, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java index 2695f723a..e293ccac6 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java @@ -12,10 +12,10 @@ public class ThirdOpHeldMessageDecoder extends MessageDecoder public ItemActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int interfacePacked = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - return new ItemActionMessage(3, interfacePacked >> 16, interfacePacked & 0xFFFF, itemId, slot); + return new ItemActionMessage(3, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java index 5e3c6bf08..ef2c16706 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java @@ -15,7 +15,7 @@ public class IfClearItemsEncoder extends MessageEncoder { @Override public GamePacket encode(IfClearItemsMessage message) { final var builder = new GamePacketBuilder(7, PacketType.FIXED); - builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getInterfacePacked()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); return builder.toGamePacket(); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java index 90d86bada..a37ec4da0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java @@ -17,7 +17,7 @@ public GamePacket encode(IfSetAnimMessage message) { final var builder = new GamePacketBuilder(61, PacketType.FIXED); builder.put(DataType.SHORT, message.getAnimation()); - builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getInterfacePacked()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); return builder.toGamePacket(); } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java index 667359884..c12eebb62 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java @@ -16,7 +16,7 @@ public class IfSetHiddenEncoder extends MessageEncoder { public GamePacket encode(IfSetHideMessage message) { final var builder = new GamePacketBuilder(21, PacketType.FIXED); - builder.put(DataType.INT, message.getInterfacePacked()); + builder.put(DataType.INT, message.getPackedInterface()); builder.put(DataType.BYTE, DataOrder.INVERSED_MIDDLE, message.isVisible() ? 0 : 1); return builder.toGamePacket(); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java index ddfe2045f..fa794a197 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java @@ -16,7 +16,7 @@ public class IfSetItemEncoder extends MessageEncoder { public GamePacket encode(IfSetItemMessage message) { final var builder = new GamePacketBuilder(11, PacketType.FIXED); - builder.put(DataType.INT, message.getInterfacePacked()); + builder.put(DataType.INT, message.getPackedInterface()); builder.put(DataType.SHORT, message.getItem()); builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getAmount()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java index f2add0f44..7d55be395 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java @@ -13,7 +13,7 @@ public class IfSetModelEncoder extends MessageEncoder { public GamePacket encode(IfSetModelMessage message) { final var builder = new GamePacketBuilder(31, PacketType.FIXED); - builder.put(DataType.INT, DataOrder.MIDDLE, message.getInterfacePacked()); + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedInterface()); builder.put(DataType.SHORT, DataTransformation.ADD, message.getModel()); return builder.toGamePacket(); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java index c773e9fa6..c7631620d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java @@ -13,7 +13,7 @@ public class IfSetScrollPosEncoder extends MessageEncoder public GamePacket encode(IfSetScrollPosMessage message) { final var builder = new GamePacketBuilder(76, PacketType.FIXED); - builder.put(DataType.INT, DataOrder.MIDDLE, message.getInterfacePacked()); + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedInterface()); builder.put(DataType.SHORT, DataTransformation.ADD, message.getScrollPosition()); return builder.toGamePacket(); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java index 778321e32..bb98355b7 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java @@ -16,7 +16,7 @@ public class IfSetTextEncoder extends MessageEncoder { public GamePacket encode(IfSetTextMessage message) { final var builder = new GamePacketBuilder(19, PacketType.VARIABLE_SHORT); - builder.put(DataType.INT, message.getInterfacePacked()); + builder.put(DataType.INT, message.getPackedInterface()); builder.putString(message.getText()); return builder.toGamePacket(); From 0f7a35e7c4cc0a81c7f0a31bbe2aac2703fa6f9d Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Thu, 26 Mar 2020 17:01:59 -0400 Subject: [PATCH 33/63] Added logout message and set flag message. Updated logout.plugin.kts to work properly. --- game/plugin/logout/src/logout.plugin.kts | 13 ++++-- .../impl/encode/SetMapFlagMessage.java | 42 +++++++++++++++++++ .../apollo/game/release/r181/Release181.java | 6 +++ .../r181/encoders/game/LogoutEncoder.java | 18 ++++++++ .../encoders/region/SetMapFlagEncoder.java | 22 ++++++++++ 5 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/SetMapFlagMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/SetMapFlagEncoder.java diff --git a/game/plugin/logout/src/logout.plugin.kts b/game/plugin/logout/src/logout.plugin.kts index c5fe4db13..d0832db84 100644 --- a/game/plugin/logout/src/logout.plugin.kts +++ b/game/plugin/logout/src/logout.plugin.kts @@ -1,5 +1,10 @@ -val LOGOUT_BUTTON_ID = 2458 +import org.apollo.game.message.impl.IfActionMessage -on_button(LOGOUT_BUTTON_ID) - .where { componentId == LOGOUT_BUTTON_ID } - .then { it.logout() } \ No newline at end of file +val LOGOUT_COMPONENT = 8 +val LOGOUT_INTERFACE = 182 + +on { IfActionMessage::class } + .where { interfaceId == LOGOUT_INTERFACE && componentId == LOGOUT_COMPONENT } + .then { player -> + player.logout() + } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/SetMapFlagMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SetMapFlagMessage.java new file mode 100644 index 000000000..43675c8e1 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SetMapFlagMessage.java @@ -0,0 +1,42 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type Set map flag message. + * + * @author Khaled Abdeljaber + */ +public class SetMapFlagMessage extends Message { + + private byte x, y; + + /** + * Instantiates a new Set map flag message. + * + * @param x the x. + * @param y the y. + */ + public SetMapFlagMessage(byte x, byte y) { + this.x = x; + this.y = y; + } + + /** + * Gets x. + * + * @return the x + */ + public byte getX() { + return x; + } + + /** + * Gets y. + * + * @return the y + */ + public byte getY() { + return y; + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 4328c9896..f655966e5 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -2,8 +2,10 @@ import org.apollo.game.message.impl.*; import org.apollo.game.message.impl.encode.*; +import org.apollo.game.model.event.impl.LogoutEvent; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; +import org.apollo.game.release.r181.encoders.game.LogoutEncoder; import org.apollo.game.release.r181.encoders.region.MobResetAnimsEncoder; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; import org.apollo.game.release.r181.decoders.map.item.*; @@ -31,6 +33,7 @@ import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.player.SetPlayerActionMessageEncoder; import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; +import org.apollo.game.release.r181.encoders.region.SetMapFlagEncoder; import org.apollo.game.release.r181.encoders.ui.*; import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerFullMessageEncoder; import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerPartialMessageEncoder; @@ -157,7 +160,10 @@ private void init() { * Server */ + register(LogoutMessage.class, new LogoutEncoder()); + register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); + register(SetMapFlagMessage.class, new SetMapFlagEncoder()); register(MobResetAnimsMessage.class, new MobResetAnimsEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java new file mode 100644 index 000000000..46ce77985 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java @@ -0,0 +1,18 @@ +package org.apollo.game.release.r181.encoders.game; + +import org.apollo.game.message.impl.LogoutMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class LogoutEncoder extends MessageEncoder { + @Override + public GamePacket encode(LogoutMessage message) { + final var builder = new GamePacketBuilder(1, PacketType.FIXED); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SetMapFlagEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SetMapFlagEncoder.java new file mode 100644 index 000000000..59326813b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SetMapFlagEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.SetMapFlagMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class SetMapFlagEncoder extends MessageEncoder { + + @Override + public GamePacket encode(SetMapFlagMessage message) { + final var builder = new GamePacketBuilder(67, PacketType.FIXED); + builder.put(DataType.BYTE, message.getY()); + builder.put(DataType.BYTE, message.getX()); + return builder.toGamePacket(); + } +} From 8d3c198a96b906d6efaed51b0998c5e927ee03a2 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Thu, 26 Mar 2020 17:31:21 -0400 Subject: [PATCH 34/63] Added logout message and set flag message. Updated logout.plugin.kts to work properly. --- game/plugin/logout/src/logout.plugin.kts | 12 ++++------ .../message/{ButtonClick.kt => IfAction.kt} | 23 ++++++++++--------- 2 files changed, 17 insertions(+), 18 deletions(-) rename game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/{ButtonClick.kt => IfAction.kt} (63%) diff --git a/game/plugin/logout/src/logout.plugin.kts b/game/plugin/logout/src/logout.plugin.kts index d0832db84..ecbf73708 100644 --- a/game/plugin/logout/src/logout.plugin.kts +++ b/game/plugin/logout/src/logout.plugin.kts @@ -1,10 +1,8 @@ -import org.apollo.game.message.impl.IfActionMessage +import org.apollo.game.model.inter.TopLevelPosition +import org.apollo.game.plugin.kotlin.message.* val LOGOUT_COMPONENT = 8 -val LOGOUT_INTERFACE = 182 -on { IfActionMessage::class } - .where { interfaceId == LOGOUT_INTERFACE && componentId == LOGOUT_COMPONENT } - .then { player -> - player.logout() - } \ No newline at end of file +on(IfAction, inter = TopLevelPosition.LOGOUT_TAB.interfaceId, comp = LOGOUT_COMPONENT) { + player.logout() +} \ No newline at end of file diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt similarity index 63% rename from game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt rename to game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt index 86230b0b8..82d9200f5 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt @@ -19,29 +19,30 @@ import org.apollo.game.plugin.kotlin.PredicateContext * ``` */ fun KotlinPluginScript.on( - listenable: ButtonClick.Companion, - button: Int, - callback: ButtonClick.() -> Unit + listenable: IfAction.Companion, + inter: Int, + comp: Int, + callback: IfAction.() -> Unit ) { - registerListener(listenable, ButtonPredicateContext(button), callback) + registerListener(listenable, IfActionPredicateContext(inter, comp), callback) } -class ButtonClick(override val player: Player, val button: Int) : PlayerContext { +class IfAction(override val player: Player) : PlayerContext { - companion object : MessageListenable() { + companion object : MessageListenable() { override val type = IfActionMessage::class override fun createHandler( world: World, - predicateContext: ButtonPredicateContext?, - callback: ButtonClick.() -> Unit + predicateContext: IfActionPredicateContext?, + callback: IfAction.() -> Unit ): MessageHandler { return object : MessageHandler(world) { override fun handle(player: Player, message: IfActionMessage) { - if (predicateContext == null || predicateContext.button == message.componentId) { - val context = ButtonClick(player, message.componentId) + if (predicateContext == null || predicateContext.inter == message.interfaceId && predicateContext.comp == message.componentId) { + val context = IfAction(player) context.callback() } } @@ -53,4 +54,4 @@ class ButtonClick(override val player: Player, val button: Int) : PlayerContext } -class ButtonPredicateContext(val button: Int) : PredicateContext \ No newline at end of file +class IfActionPredicateContext(val inter: Int, val comp: Int) : PredicateContext \ No newline at end of file From 677e994bc410ba282ba959178b9c6ef0fd2bfc4d Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Thu, 26 Mar 2020 20:44:13 -0400 Subject: [PATCH 35/63] Action support for clicks. --- game/plugin/logout/src/logout.plugin.kts | 3 ++- .../apollo/game/plugin/kotlin/message/IfAction.kt | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/game/plugin/logout/src/logout.plugin.kts b/game/plugin/logout/src/logout.plugin.kts index ecbf73708..af6fa53af 100644 --- a/game/plugin/logout/src/logout.plugin.kts +++ b/game/plugin/logout/src/logout.plugin.kts @@ -1,5 +1,6 @@ import org.apollo.game.model.inter.TopLevelPosition -import org.apollo.game.plugin.kotlin.message.* +import org.apollo.game.plugin.kotlin.message.IfAction +import org.apollo.game.plugin.kotlin.message.on val LOGOUT_COMPONENT = 8 diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt index 82d9200f5..7b4def248 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt @@ -22,9 +22,10 @@ fun KotlinPluginScript.on( listenable: IfAction.Companion, inter: Int, comp: Int, + action: Int = 1, callback: IfAction.() -> Unit ) { - registerListener(listenable, IfActionPredicateContext(inter, comp), callback) + registerListener(listenable, IfActionPredicateContext(inter, comp, action), callback) } class IfAction(override val player: Player) : PlayerContext { @@ -41,10 +42,13 @@ class IfAction(override val player: Player) : PlayerContext { return object : MessageHandler(world) { override fun handle(player: Player, message: IfActionMessage) { - if (predicateContext == null || predicateContext.inter == message.interfaceId && predicateContext.comp == message.componentId) { - val context = IfAction(player) - context.callback() + if (predicateContext == null || predicateContext.inter != message.interfaceId || + predicateContext.comp != message.componentId || predicateContext.action != message.action) { + return; } + + val context = IfAction(player) + context.callback() } } @@ -54,4 +58,4 @@ class IfAction(override val player: Player) : PlayerContext { } -class IfActionPredicateContext(val inter: Int, val comp: Int) : PredicateContext \ No newline at end of file +class IfActionPredicateContext(val inter: Int, val comp: Int, val action: Int) : PredicateContext \ No newline at end of file From 8a3db745792aba06e4e93d869e7d7af2ada52a49 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Thu, 26 Mar 2020 22:45:54 -0400 Subject: [PATCH 36/63] Moved a ton of messages. --- game/data/messages.xml | 10 +++--- .../testing/junit/api/interactions/player.kt | 6 ++-- game/plugin/bank/src/bank.plugin.kts | 4 +-- .../private-messaging/src/friends.plugin.kts | 2 +- .../private-messaging/src/ignores.plugin.kts | 4 +-- game/plugin/dummy/src/dummy.plugin.kts | 2 +- game/plugin/emote-tab/src/EmoteTab.plugin.kts | 2 +- .../actions/src/PlayerActions.plugin.kts | 2 +- game/plugin/logout/test/LogoutTests.kt | 2 +- .../navigation/door/src/door.plugin.kts | 2 +- game/plugin/run/src/run.plugin.kts | 2 +- .../apollo/game/plugin/shops/Shops.plugin.kts | 2 +- .../plugin/skills/fishing/Fishing.plugin.kts | 2 +- .../mining/src/ExpiredProspectingAction.kt | 2 +- .../skills/mining/src/Mining.plugin.kts | 2 +- game/plugin/skills/mining/src/MiningAction.kt | 2 +- .../skills/mining/src/ProspectingAction.kt | 2 +- .../skills/prayer/src/Prayer.plugin.kts | 2 +- .../runecrafting/src/Runecrafting.plugin.kts | 2 +- .../woodcutting/src/Woodcutting.plugin.kts | 2 +- .../handler/BankButtonMessageHandler.java | 2 +- .../handler/DialogueButtonHandler.java | 2 +- .../handler/NpcActionVerificationHandler.java | 2 +- .../ObjectActionVerificationHandler.java | 2 +- .../PlayerActionVerificationHandler.java | 2 +- .../handler/PlayerDesignMessageHandler.java | 2 +- .../message/handler/WalkMessageHandler.java | 2 +- .../impl/DisplayCrossbonesMessage.java | 35 ------------------- .../impl/{ => decode}/AddFriendMessage.java | 2 +- .../impl/{ => decode}/AddIgnoreMessage.java | 2 +- .../impl/{ => decode}/IfActionMessage.java | 2 +- .../impl/{ => decode}/KeepAliveMessage.java | 2 +- .../{ => decode}/MouseClickedMessage.java | 2 +- .../impl/{ => decode}/NpcActionMessage.java | 2 +- .../{ => decode}/ObjectActionMessage.java | 2 +- .../{ => decode}/PlayerActionMessage.java | 2 +- .../{ => decode}/RemoveFriendMessage.java | 2 +- .../{ => decode}/RemoveIgnoreMessage.java | 2 +- .../impl/{ => decode}/WalkMessage.java | 2 +- .../{ => encode}/CloseInterfaceMessage.java | 2 +- .../impl/{ => encode}/LogoutMessage.java | 2 +- .../NpcSynchronizationMessage.java | 2 +- .../UpdateInventoryFullMessage.java | 2 +- .../UpdateInventoryPartialMessage.java | 2 +- .../org/apollo/game/model/entity/Player.java | 5 +-- .../apollo/game/model/inter/InterfaceSet.java | 2 +- .../inv/SynchronizationInventoryListener.java | 4 +-- .../apollo/game/release/r181/Release181.java | 1 - .../decoders/KeepAliveMessageDecoder.java | 2 +- .../decoders/MouseClickedMessageDecoder.java | 2 +- .../r181/decoders/map/WalkMessageDecoder.java | 2 +- .../actions/FifthNpcActionMessageDecoder.java | 2 +- .../actions/FirstNpcActionMessageDecoder.java | 2 +- .../FourthNpcActionMessageDecoder.java | 2 +- .../SecondNpcActionMessageDecoder.java | 2 +- .../actions/SixthNpcActionMessageDecoder.java | 2 +- .../actions/ThirdNpcActionMessageDecoder.java | 2 +- .../obj/FifthObjectActionMessageDecoder.java | 2 +- .../obj/FirstObjectActionMessageDecoder.java | 2 +- .../obj/FourthObjectActionMessageDecoder.java | 2 +- .../obj/SecondObjectActionMessageDecoder.java | 2 +- .../obj/SixthObjectActionMessageDecoder.java | 2 +- .../obj/ThirdObjectActionMessageDecoder.java | 2 +- .../EightPlayerActionMessageDecoder.java | 2 +- .../FifthPlayerActionMessageDecoder.java | 2 +- .../FirstPlayerActionMessageDecoder.java | 2 +- .../FourthPlayerActionMessageDecoder.java | 2 +- .../SecondPlayerActionMessageDecoder.java | 2 +- .../SeventhPlayerActionMessageDecoder.java | 2 +- .../SixthPlayerActionMessageDecoder.java | 2 +- .../ThirdPlayerActionMessageDecoder.java | 2 +- .../friends/AddFriendMessageDecoder.java | 2 +- .../friends/RemoveFriendMessageDecoder.java | 2 +- .../ignores/AddIgnoreMessageDecoder.java | 2 +- .../ignores/RemoveIgnoreMessageDecoder.java | 2 +- .../ui/if1/FifthIf1ActionMessageDecoder.java | 2 +- .../ui/if1/FirstIf1ActionMessageDecoder.java | 2 +- .../ui/if1/FourthIf1ActionMessageDecoder.java | 2 +- .../ui/if1/SecondIf1ActionMessageDecoder.java | 2 +- .../ui/if1/ThirdIf1ActionMessageDecoder.java | 2 +- .../ui/if3/If3ActionMessageDecoder.java | 2 +- .../r181/encoders/game/LogoutEncoder.java | 2 +- .../npc/NpcSynchronizationMessageEncoder.java | 2 +- .../UpdateContainerFullMessageEncoder.java | 2 +- .../UpdateContainerPartialMessageEncoder.java | 2 +- .../org/apollo/game/session/GameSession.java | 2 +- .../sync/task/NpcSynchronizationTask.java | 2 +- .../game/plugin/kotlin/KotlinPluginScript.kt | 2 +- .../game/plugin/kotlin/message/IfAction.kt | 2 +- .../kotlin/message/action/obj/ObjectAction.kt | 2 +- .../ObjectActionVerificationHandlerTests.java | 2 +- 91 files changed, 98 insertions(+), 137 deletions(-) delete mode 100644 game/src/main/java/org/apollo/game/message/impl/DisplayCrossbonesMessage.java rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/AddFriendMessage.java (93%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/AddIgnoreMessage.java (93%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/IfActionMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/KeepAliveMessage.java (92%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/MouseClickedMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/NpcActionMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ObjectActionMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/PlayerActionMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/RemoveFriendMessage.java (93%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/RemoveIgnoreMessage.java (93%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/WalkMessage.java (95%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/CloseInterfaceMessage.java (81%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/LogoutMessage.java (80%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/NpcSynchronizationMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/UpdateInventoryFullMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/UpdateInventoryPartialMessage.java (96%) diff --git a/game/data/messages.xml b/game/data/messages.xml index 9db866791..501ca7b85 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -1,6 +1,6 @@ - org.apollo.game.message.impl.IfActionMessage + org.apollo.game.message.impl.decode.IfActionMessage org.apollo.game.message.handler.DialogueButtonHandler org.apollo.game.message.handler.BankButtonMessageHandler @@ -84,19 +84,19 @@ - org.apollo.game.message.impl.NpcActionMessage + org.apollo.game.message.impl.decode.NpcActionMessage org.apollo.game.message.handler.NpcActionVerificationHandler - org.apollo.game.message.impl.ObjectActionMessage + org.apollo.game.message.impl.decode.ObjectActionMessage org.apollo.game.message.handler.ObjectActionVerificationHandler - org.apollo.game.message.impl.PlayerActionMessage + org.apollo.game.message.impl.decode.PlayerActionMessage org.apollo.game.message.handler.PlayerActionVerificationHandler @@ -115,7 +115,7 @@ - org.apollo.game.message.impl.WalkMessage + org.apollo.game.message.impl.decode.WalkMessage org.apollo.game.message.handler.WalkMessageHandler diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt index 6ac0ce138..c3ae2d845 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt @@ -1,9 +1,9 @@ package org.apollo.game.plugin.testing.junit.api.interactions import org.apollo.game.message.impl.decode.ItemOptionMessage -import org.apollo.game.message.impl.NpcActionMessage -import org.apollo.game.message.impl.ObjectActionMessage -import org.apollo.game.message.impl.PlayerActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage +import org.apollo.game.message.impl.decode.PlayerActionMessage import org.apollo.game.model.Direction import org.apollo.game.model.Position import org.apollo.game.model.entity.Entity diff --git a/game/plugin/bank/src/bank.plugin.kts b/game/plugin/bank/src/bank.plugin.kts index 0aef5ac18..cadc55364 100644 --- a/game/plugin/bank/src/bank.plugin.kts +++ b/game/plugin/bank/src/bank.plugin.kts @@ -1,6 +1,6 @@ import org.apollo.game.action.DistancedAction -import org.apollo.game.message.impl.NpcActionMessage -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.entity.Npc import org.apollo.game.model.entity.Player diff --git a/game/plugin/chat/private-messaging/src/friends.plugin.kts b/game/plugin/chat/private-messaging/src/friends.plugin.kts index 6ac357d72..91aa3c8f9 100644 --- a/game/plugin/chat/private-messaging/src/friends.plugin.kts +++ b/game/plugin/chat/private-messaging/src/friends.plugin.kts @@ -1,4 +1,4 @@ -import org.apollo.game.message.impl.AddFriendMessage +import org.apollo.game.message.impl.decode.AddFriendMessage import org.apollo.game.message.impl.SendFriendMessage import org.apollo.game.model.entity.setting.PrivacyState diff --git a/game/plugin/chat/private-messaging/src/ignores.plugin.kts b/game/plugin/chat/private-messaging/src/ignores.plugin.kts index 47b0f29fe..1afbed3b9 100644 --- a/game/plugin/chat/private-messaging/src/ignores.plugin.kts +++ b/game/plugin/chat/private-messaging/src/ignores.plugin.kts @@ -1,5 +1,5 @@ -import org.apollo.game.message.impl.AddIgnoreMessage -import org.apollo.game.message.impl.RemoveIgnoreMessage +import org.apollo.game.message.impl.decode.AddIgnoreMessage +import org.apollo.game.message.impl.decode.RemoveIgnoreMessage on { AddIgnoreMessage::class } .then { it.addIgnore(username) } diff --git a/game/plugin/dummy/src/dummy.plugin.kts b/game/plugin/dummy/src/dummy.plugin.kts index 75dee6f19..1be2d49ff 100644 --- a/game/plugin/dummy/src/dummy.plugin.kts +++ b/game/plugin/dummy/src/dummy.plugin.kts @@ -1,6 +1,6 @@ import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Animation import org.apollo.game.model.Position import org.apollo.game.model.entity.* diff --git a/game/plugin/emote-tab/src/EmoteTab.plugin.kts b/game/plugin/emote-tab/src/EmoteTab.plugin.kts index 0fe5bb66c..ec8029187 100644 --- a/game/plugin/emote-tab/src/EmoteTab.plugin.kts +++ b/game/plugin/emote-tab/src/EmoteTab.plugin.kts @@ -1,4 +1,4 @@ -import org.apollo.game.message.impl.IfActionMessage +import org.apollo.game.message.impl.decode.IfActionMessage on { IfActionMessage::class } .where { componentId in Emote.MAP } diff --git a/game/plugin/entity/actions/src/PlayerActions.plugin.kts b/game/plugin/entity/actions/src/PlayerActions.plugin.kts index 675a8a53e..ca519cb8d 100644 --- a/game/plugin/entity/actions/src/PlayerActions.plugin.kts +++ b/game/plugin/entity/actions/src/PlayerActions.plugin.kts @@ -1,6 +1,6 @@ package org.apollo.game.plugin.entity.actions -import org.apollo.game.message.impl.PlayerActionMessage +import org.apollo.game.message.impl.decode.PlayerActionMessage import org.apollo.game.model.event.impl.LoginEvent on { PlayerActionMessage::class } diff --git a/game/plugin/logout/test/LogoutTests.kt b/game/plugin/logout/test/LogoutTests.kt index 7a5f19be5..e238c8133 100644 --- a/game/plugin/logout/test/LogoutTests.kt +++ b/game/plugin/logout/test/LogoutTests.kt @@ -1,5 +1,5 @@ import io.mockk.verify -import org.apollo.game.message.impl.IfActionMessage +import org.apollo.game.message.impl.decode.IfActionMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.api.annotations.TestMock diff --git a/game/plugin/navigation/door/src/door.plugin.kts b/game/plugin/navigation/door/src/door.plugin.kts index d91ceee9a..0f0e882df 100644 --- a/game/plugin/navigation/door/src/door.plugin.kts +++ b/game/plugin/navigation/door/src/door.plugin.kts @@ -1,5 +1,5 @@ -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.plugin.navigation.door.Door import org.apollo.plugin.navigation.door.OpenDoorAction diff --git a/game/plugin/run/src/run.plugin.kts b/game/plugin/run/src/run.plugin.kts index 05a80d4a6..b856ccd8b 100644 --- a/game/plugin/run/src/run.plugin.kts +++ b/game/plugin/run/src/run.plugin.kts @@ -1,4 +1,4 @@ -import org.apollo.game.message.impl.IfActionMessage +import org.apollo.game.message.impl.decode.IfActionMessage val WALK_BUTTON_ID = 152 val RUN_BUTTON_ID = 153 diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts index 948fec2c7..88d525e12 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts @@ -2,7 +2,7 @@ package org.apollo.game.plugin.shops import org.apollo.game.message.handler.ItemVerificationHandler import org.apollo.game.message.impl.decode.ItemActionMessage -import org.apollo.game.message.impl.NpcActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage import org.apollo.game.model.entity.Mob import org.apollo.game.scheduling.ScheduledTask diff --git a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts index 597058bbe..8dbb8b4fc 100644 --- a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts +++ b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts @@ -1,6 +1,6 @@ package org.apollo.game.plugin.skills.fishing -import org.apollo.game.message.impl.NpcActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage // TODO: moving fishing spots, seaweed and caskets, evil bob diff --git a/game/plugin/skills/mining/src/ExpiredProspectingAction.kt b/game/plugin/skills/mining/src/ExpiredProspectingAction.kt index 41f3229e6..e0d54ee59 100644 --- a/game/plugin/skills/mining/src/ExpiredProspectingAction.kt +++ b/game/plugin/skills/mining/src/ExpiredProspectingAction.kt @@ -1,6 +1,6 @@ import java.util.* import org.apollo.game.action.DistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.entity.Player diff --git a/game/plugin/skills/mining/src/Mining.plugin.kts b/game/plugin/skills/mining/src/Mining.plugin.kts index 8b3f61d1e..3d4b62272 100644 --- a/game/plugin/skills/mining/src/Mining.plugin.kts +++ b/game/plugin/skills/mining/src/Mining.plugin.kts @@ -1,4 +1,4 @@ -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.plugin.skills.mining.Ore on { ObjectActionMessage::class } diff --git a/game/plugin/skills/mining/src/MiningAction.kt b/game/plugin/skills/mining/src/MiningAction.kt index 0f159b388..35f55ec3b 100644 --- a/game/plugin/skills/mining/src/MiningAction.kt +++ b/game/plugin/skills/mining/src/MiningAction.kt @@ -1,7 +1,7 @@ import java.util.* import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.api.* import org.apollo.game.plugin.skills.mining.Ore diff --git a/game/plugin/skills/mining/src/ProspectingAction.kt b/game/plugin/skills/mining/src/ProspectingAction.kt index 10bf83a11..dc11d9d7a 100644 --- a/game/plugin/skills/mining/src/ProspectingAction.kt +++ b/game/plugin/skills/mining/src/ProspectingAction.kt @@ -1,7 +1,7 @@ import java.util.Objects import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.entity.Player import org.apollo.game.plugin.api.Definitions diff --git a/game/plugin/skills/prayer/src/Prayer.plugin.kts b/game/plugin/skills/prayer/src/Prayer.plugin.kts index f1e65ff24..0d3e55675 100644 --- a/game/plugin/skills/prayer/src/Prayer.plugin.kts +++ b/game/plugin/skills/prayer/src/Prayer.plugin.kts @@ -1,6 +1,6 @@ import Bone.Companion.isBone import Prayer.Companion.isPrayerButton -import org.apollo.game.message.impl.IfActionMessage +import org.apollo.game.message.impl.decode.IfActionMessage import org.apollo.game.message.impl.decode.ItemOptionMessage import org.apollo.game.model.event.impl.LogoutEvent import org.apollo.game.plugin.api.prayer diff --git a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts index 116b2db4f..aca103496 100644 --- a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts +++ b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts @@ -1,9 +1,9 @@ package org.apollo.game.plugin.skill.runecrafting -import org.apollo.game.message.impl.* import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.message.impl.decode.ItemOnObjectMessage import org.apollo.game.message.impl.decode.ItemOptionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.message.impl.encode.ConfigMessage import org.apollo.game.model.entity.EquipmentConstants import org.apollo.game.model.event.impl.LoginEvent diff --git a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts index f0d962395..ada430864 100644 --- a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts +++ b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts @@ -3,7 +3,7 @@ import java.util.concurrent.TimeUnit import org.apollo.game.GameConstants import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.World import org.apollo.game.model.entity.Player diff --git a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java index c92425b57..a325f434b 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java index 6e68ca0ad..e882e12de 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.game.model.inter.ServerInterfaceType; diff --git a/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java index 32f5cefcd..fcc2a7465 100644 --- a/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.NpcDefinition; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; diff --git a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java index 34852d93f..1780b469e 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.Region; diff --git a/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java index d94fcc7cd..a90b3ce3d 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java index 24f43b0ff..6af73d60e 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.CloseInterfaceMessage; import org.apollo.game.message.impl.decode.PlayerDesignMessage; +import org.apollo.game.message.impl.encode.CloseInterfaceMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java index 21140d843..ac16470f6 100644 --- a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.WalkMessage; +import org.apollo.game.message.impl.decode.WalkMessage; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/impl/DisplayCrossbonesMessage.java b/game/src/main/java/org/apollo/game/message/impl/DisplayCrossbonesMessage.java deleted file mode 100644 index 83c5ca329..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/DisplayCrossbonesMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to display crossbones when the player enters a multi-combat zone. - * - * @author Major - */ -public final class DisplayCrossbonesMessage extends Message { - - /** - * Whether or not the crossbones should be displayed. - */ - private final boolean display; - - /** - * Creates a display crossbones message. - * - * @param display Whether or not the crossbones should be displayed. - */ - public DisplayCrossbonesMessage(boolean display) { - this.display = display; - } - - /** - * Indicates whether the crossbones will be displayed. - * - * @return {@code true} if the crossbones will be displayed, otherwise {@code false}. - */ - public boolean isDisplayed() { - return display; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/AddFriendMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/AddFriendMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/AddFriendMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/AddFriendMessage.java index 7e968f28f..3a2df488a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/AddFriendMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/AddFriendMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/AddIgnoreMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/AddIgnoreMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/AddIgnoreMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/AddIgnoreMessage.java index b631e7fb4..30cdbf38a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/AddIgnoreMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/AddIgnoreMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/IfActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/IfActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java index 98d9cc3c3..316e4cb76 100644 --- a/game/src/main/java/org/apollo/game/message/impl/IfActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/KeepAliveMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/KeepAliveMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/KeepAliveMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/KeepAliveMessage.java index 4a0af63f8..7af86975c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/KeepAliveMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/KeepAliveMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MouseClickedMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MouseClickedMessage.java index 576f79054..4e555604d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MouseClickedMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.message.impl.decode.FocusUpdateMessage; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/NpcActionMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/NpcActionMessage.java index a952a012f..30cefa749 100644 --- a/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/NpcActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ObjectActionMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ObjectActionMessage.java index da4bb950e..8da6ac0af 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ObjectActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.Position; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerActionMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PlayerActionMessage.java index 9004cc885..93b988625 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveFriendMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveFriendMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/RemoveFriendMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/RemoveFriendMessage.java index b44b42fee..94ca060b2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveFriendMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveFriendMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveIgnoreMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveIgnoreMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/RemoveIgnoreMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/RemoveIgnoreMessage.java index 664826028..a8acc5d24 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveIgnoreMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveIgnoreMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java similarity index 95% rename from game/src/main/java/org/apollo/game/message/impl/WalkMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java index f37d290b2..e24ed6904 100644 --- a/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import com.google.common.base.Preconditions; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/message/impl/CloseInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/CloseInterfaceMessage.java similarity index 81% rename from game/src/main/java/org/apollo/game/message/impl/CloseInterfaceMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/CloseInterfaceMessage.java index ee0a31a0e..1c7419e86 100644 --- a/game/src/main/java/org/apollo/game/message/impl/CloseInterfaceMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/CloseInterfaceMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/LogoutMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/LogoutMessage.java similarity index 80% rename from game/src/main/java/org/apollo/game/message/impl/LogoutMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/LogoutMessage.java index b153fcf4e..fa53f013c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/LogoutMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/LogoutMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/NpcSynchronizationMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/NpcSynchronizationMessage.java index e31985ccd..f9e9cf618 100644 --- a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/NpcSynchronizationMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.entity.Npc; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryFullMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryFullMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/UpdateInventoryFullMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryFullMessage.java index a5b77eec2..0d1ca637a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryFullMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryFullMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Item; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryPartialMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/UpdateInventoryPartialMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java index 4805b08c5..260ec9566 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateInventoryPartialMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.inv.SlottedItem; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index f7af3c5c0..467a5b24b 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -3,10 +3,7 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import org.apollo.game.message.impl.*; -import org.apollo.game.message.impl.encode.ConfigMessage; -import org.apollo.game.message.impl.encode.RebuildNormalMessage; -import org.apollo.game.message.impl.encode.IfSetTextMessage; -import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; +import org.apollo.game.message.impl.encode.*; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; import org.apollo.game.model.World; diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java index 783db21bd..765bc613d 100644 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java @@ -2,8 +2,8 @@ import org.apollo.cache.def.EnumDefinition; import org.apollo.game.message.handler.MessageHandlerChain; -import org.apollo.game.message.impl.CloseInterfaceMessage; import org.apollo.game.message.impl.EnterAmountMessage; +import org.apollo.game.message.impl.encode.CloseInterfaceMessage; import org.apollo.game.message.impl.encode.IfMoveSubMessage; import org.apollo.game.message.impl.encode.IfOpenSubMessage; import org.apollo.game.message.impl.encode.IfOpenTopMessage; diff --git a/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java b/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java index df06ffa86..89c26f015 100644 --- a/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java +++ b/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java @@ -1,7 +1,7 @@ package org.apollo.game.model.inv; -import org.apollo.game.message.impl.UpdateInventoryFullMessage; -import org.apollo.game.message.impl.UpdateInventoryPartialMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryFullMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryPartialMessage; import org.apollo.game.model.Item; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index f655966e5..d1190a8d6 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -2,7 +2,6 @@ import org.apollo.game.message.impl.*; import org.apollo.game.message.impl.encode.*; -import org.apollo.game.model.event.impl.LogoutEvent; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; import org.apollo.game.release.r181.encoders.game.LogoutEncoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java index e9c42fb8f..38fed7ef1 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.KeepAliveMessage; +import org.apollo.game.message.impl.decode.KeepAliveMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java index bfa999059..da6f2eac1 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.MouseClickedMessage; +import org.apollo.game.message.impl.decode.MouseClickedMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java index 436cbc1f0..80d31cb34 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map; -import org.apollo.game.message.impl.WalkMessage; +import org.apollo.game.message.impl.decode.WalkMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java index 5b2efe6e3..7f0876fa5 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java index 7ad4dc30c..52721ad4c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java index 800dfa73a..059cada2c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java index 0f68c280d..e7b7bd7a1 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java index 9026ea48c..604865e0b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java index c2c3b72bb..bb0773250 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FifthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FifthObjectActionMessageDecoder.java index a9d3eb3fb..687ed24bc 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FifthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FifthObjectActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java index 669d956a2..a48272586 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java index 3826f0e58..9cfef7a3a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java index 8ba1f5a6a..525b52814 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SixthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SixthObjectActionMessageDecoder.java index 816e85a6c..ed52d2c48 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SixthObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SixthObjectActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java index 335c1369c..7ff2de0e7 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/EightPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/EightPlayerActionMessageDecoder.java index 1333a6b76..fb731259f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/EightPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/EightPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java index 8441cad89..ba7ed47f8 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java index b9348c6f0..a8ef0731a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java index 4b08e3691..747d13b87 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java index 8ea783238..6c5ce5988 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java index 90621a95f..19ad4970f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java index b024cb83d..26f404258 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java index 20f0b7242..9a1de457e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java index 94524e3c7..c494f86df 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.social.friends; -import org.apollo.game.message.impl.AddFriendMessage; +import org.apollo.game.message.impl.decode.AddFriendMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java index bdca80254..8080be596 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.social.friends; -import org.apollo.game.message.impl.RemoveFriendMessage; +import org.apollo.game.message.impl.decode.RemoveFriendMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java index 8936b091d..0a46ff564 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.social.ignores; -import org.apollo.game.message.impl.AddIgnoreMessage; +import org.apollo.game.message.impl.decode.AddIgnoreMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java index ccad2f811..353a62123 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.social.ignores; -import org.apollo.game.message.impl.RemoveIgnoreMessage; +import org.apollo.game.message.impl.decode.RemoveIgnoreMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java index a97476c96..c30361619 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java index 0d1f76188..427b97649 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java index 47f970853..255cb7de7 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java index 8ac87f1e8..c66a7f42f 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java index 7811ab208..7f97a9777 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java index 0a9a14b28..98fa314e9 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.ui.if3; -import org.apollo.game.message.impl.IfActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java index 46ce77985..657746b4e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.game; -import org.apollo.game.message.impl.LogoutMessage; +import org.apollo.game.message.impl.encode.LogoutMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; import org.apollo.net.meta.PacketType; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java index c53833f36..f0a37459c 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.npc; -import org.apollo.game.message.impl.NpcSynchronizationMessage; +import org.apollo.game.message.impl.encode.NpcSynchronizationMessage; import org.apollo.game.model.Animation; import org.apollo.game.model.Direction; import org.apollo.game.model.Graphic; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java index f832f1b5e..aa791c295 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.ui.container; -import org.apollo.game.message.impl.UpdateInventoryFullMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryFullMessage; import org.apollo.game.model.Item; import org.apollo.net.codec.game.DataOrder; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java index 805bc1b58..b555323f9 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.ui.container; -import org.apollo.game.message.impl.UpdateInventoryPartialMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryPartialMessage; import org.apollo.game.model.Item; import org.apollo.game.model.inv.SlottedItem; import org.apollo.net.codec.game.DataType; diff --git a/game/src/main/java/org/apollo/game/session/GameSession.java b/game/src/main/java/org/apollo/game/session/GameSession.java index c61a3db89..3591930f7 100644 --- a/game/src/main/java/org/apollo/game/session/GameSession.java +++ b/game/src/main/java/org/apollo/game/session/GameSession.java @@ -6,7 +6,7 @@ import org.apollo.ServerContext; import org.apollo.game.GameConstants; import org.apollo.game.message.handler.MessageHandlerChainSet; -import org.apollo.game.message.impl.LogoutMessage; +import org.apollo.game.message.impl.encode.LogoutMessage; import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java index f0cfc4a91..80fc44ee0 100644 --- a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java @@ -1,6 +1,6 @@ package org.apollo.game.sync.task; -import org.apollo.game.message.impl.NpcSynchronizationMessage; +import org.apollo.game.message.impl.encode.NpcSynchronizationMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionCoordinates; diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt index 90e0643f9..b25859fa9 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt @@ -2,7 +2,7 @@ package org.apollo.game.plugin.kotlin import org.apollo.game.command.CommandListener import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.IfActionMessage +import org.apollo.game.message.impl.decode.IfActionMessage import org.apollo.game.model.World import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.event.Event diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt index 7b4def248..7c3526c50 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.kotlin.message import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.IfActionMessage +import org.apollo.game.message.impl.decode.IfActionMessage import org.apollo.game.model.World import org.apollo.game.model.entity.Player import org.apollo.game.plugin.kotlin.KotlinPluginScript diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt index 2bb0b7902..69d11c83a 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt @@ -2,7 +2,7 @@ package org.apollo.game.plugin.kotlin.message.action.obj import org.apollo.cache.def.ObjectDefinition import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.World import org.apollo.game.model.entity.EntityType import org.apollo.game.model.entity.Player diff --git a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java index ab9c14860..ecc61dd6c 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.Region; From 1cd9a1711a13021a86003ea552ff4258667719d7 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 4 Apr 2020 22:45:53 -0400 Subject: [PATCH 37/63] GPI nearly complete. Still need masks. Going to clean up the code more. It's written in order to reduce the number of loops and the number of comparisons. --- game/src/main/java/org/apollo/Server.java | 3 + .../message/handler/WalkMessageHandler.java | 12 +- .../impl/PlayerSynchronizationMessage.java | 108 +------ .../game/message/impl/decode/WalkMessage.java | 29 +- .../java/org/apollo/game/model/World.java | 4 +- .../org/apollo/game/model/WorldConstants.java | 2 +- .../org/apollo/game/model/area/Region.java | 13 + .../org/apollo/game/model/entity/Mob.java | 6 +- .../game/model/entity/MobRepository.java | 2 +- .../r181/decoders/map/WalkMessageDecoder.java | 4 +- .../PlayerSynchronizationMessageEncoder.java | 61 ++++ .../org/apollo/game/session/LoginSession.java | 22 +- .../game/sync/ParallelClientSynchronizer.java | 2 + .../AddHighResolutionPlayer.java} | 8 +- .../seg/player/AddLowResolutionPlayer.java | 24 ++ .../sync/task/PlayerSynchronizationTask.java | 304 ++++++++++++++---- .../apollo/net/codec/login/LoginDecoder.java | 1 - 17 files changed, 390 insertions(+), 215 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java rename game/src/main/java/org/apollo/game/sync/seg/{AddPlayerSegment.java => player/AddHighResolutionPlayer.java} (72%) create mode 100644 game/src/main/java/org/apollo/game/sync/seg/player/AddLowResolutionPlayer.java diff --git a/game/src/main/java/org/apollo/Server.java b/game/src/main/java/org/apollo/Server.java index f0b206f43..cf9af3a1a 100644 --- a/game/src/main/java/org/apollo/Server.java +++ b/game/src/main/java/org/apollo/Server.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; /** @@ -48,6 +49,8 @@ public final class Server { * @param args The command-line arguments passed to the application. */ public static void main(String[] args) { + Arrays.stream(LogManager.getLogManager().getLogger("").getHandlers()).forEach(h -> h.setLevel(Level.ALL)); + Stopwatch stopwatch = Stopwatch.createStarted(); try { diff --git a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java index ac16470f6..aa2d81209 100644 --- a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java @@ -25,18 +25,10 @@ public WalkMessageHandler(World world) { @Override public void handle(Player player, WalkMessage message) { WalkingQueue queue = player.getWalkingQueue(); + queue.setRunning(message.isRunning() || player.isRunning()); - Position[] steps = message.getSteps(); - for (int index = 0; index < steps.length; index++) { - Position step = steps[index]; - if (index == 0) { - queue.addFirstStep(step); - } else { - queue.addStep(step); - } - } + queue.addFirstStep(new Position(message.getX(), message.getY(), player.getPosition().getHeight())); - queue.setRunning(message.isRunning() || player.isRunning()); player.getInterfaceSet().close(); if (queue.size() > 0) { diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java index 45c5cfdf1..e2bf02503 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java @@ -6,114 +6,8 @@ import java.util.List; -/** - * A {@link Message} sent to the client to synchronize players. - * - * @author Graham - */ public final class PlayerSynchronizationMessage extends Message { - /** - * The Position in the last known region. - */ - private final Position lastKnownRegion; - - /** - * The number of local players. - */ - private final int localPlayers; - - /** - * The player's position. - */ - private final Position position; - - /** - * A flag indicating if the region has changed. - */ - private final boolean regionChanged; - - /** - * The current player's synchronization segment. - */ - private final SynchronizationSegment segment; - - /** - * A list of segments. - */ - private final List segments; - - /** - * Creates the player synchronization message. - * - * @param lastKnownRegion The last known region. - * @param position The player's current position. - * @param regionChanged A flag indicating if the region has changed. - * @param segment The current player's synchronization segment. - * @param localPlayers The number of local players. - * @param segments A list of segments. - */ - public PlayerSynchronizationMessage(Position lastKnownRegion, Position position, boolean regionChanged, SynchronizationSegment segment, int localPlayers, List segments) { - this.lastKnownRegion = lastKnownRegion; - this.position = position; - this.regionChanged = regionChanged; - this.segment = segment; - this.localPlayers = localPlayers; - this.segments = segments; - } - - /** - * Gets the last known region. - * - * @return The last known region. - */ - public Position getLastKnownRegion() { - return lastKnownRegion; - } - - /** - * Gets the number of local players. - * - * @return The number of local players. - */ - public int getLocalPlayers() { - return localPlayers; + public PlayerSynchronizationMessage() { } - - /** - * Gets the player's position. - * - * @return The player's position. - */ - public Position getPosition() { - return position; - } - - /** - * Gets the current player's segment. - * - * @return The current player's segment. - */ - public SynchronizationSegment getSegment() { - return segment; - } - - /** - * Gets the synchronization segments. - * - * @return The segments. - */ - public List getSegments() { - return segments; - } - - /** - * Checks if the region has changed. - * - * @return {@code true} if so, {@code false} if not. - */ - public boolean hasRegionChanged() { - return regionChanged; - } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java index e24ed6904..206ee156a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java @@ -19,27 +19,38 @@ public final class WalkMessage extends Message { /** * The steps. */ - private final Position[] steps; + private int x, y; /** * Creates the message. * - * @param steps The steps array. + * @param x The absolute x-axis position. + * @param y The absolute y-axis position. * @param run The run flag. */ - public WalkMessage(Position[] steps, boolean run) { - Preconditions.checkArgument(steps.length >= 0, "Number of steps cannot be negative."); - this.steps = steps; + public WalkMessage(int x, int y, boolean run) { + this.x = x; + this.y = y; this.run = run; } + + /** + * Gets x. + * + * @return the x + */ + public int getX() { + return x; + } + /** - * Gets the steps array. + * Gets y. * - * @return An array of steps. + * @return the y */ - public Position[] getSteps() { - return steps; + public int getY() { + return y; } /** diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index 955daed7b..c11d1ce79 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -300,7 +300,7 @@ public void register(Player player) { playerRepository.add(player); players.put(NameUtil.encodeBase37(username), player); - logger.finest("Registered player: " + player + " [count=" + playerRepository.size() + "]"); + System.out.println("Registered player: " + player + " [count=" + playerRepository.size() + "]"); } /** @@ -360,7 +360,7 @@ public void unregister(final Player player) { region.removeEntity(player); playerRepository.remove(player); - logger.finest("Unregistered player: " + player + " [count=" + playerRepository.size() + "]"); + System.out.println("Unregistered player: " + player + " [count=" + playerRepository.size() + "]"); } /** diff --git a/game/src/main/java/org/apollo/game/model/WorldConstants.java b/game/src/main/java/org/apollo/game/model/WorldConstants.java index b76c47e35..563b7b442 100644 --- a/game/src/main/java/org/apollo/game/model/WorldConstants.java +++ b/game/src/main/java/org/apollo/game/model/WorldConstants.java @@ -15,7 +15,7 @@ public final class WorldConstants { /** * The maximum number of players. */ - public static final int MAXIMUM_PLAYERS = 2000; + public static final int MAXIMUM_PLAYERS = 2048; /** * Default private constructor to prevent instantiation by other classes. diff --git a/game/src/main/java/org/apollo/game/model/area/Region.java b/game/src/main/java/org/apollo/game/model/area/Region.java index cdb726a6f..f53870701 100644 --- a/game/src/main/java/org/apollo/game/model/area/Region.java +++ b/game/src/main/java/org/apollo/game/model/area/Region.java @@ -242,6 +242,19 @@ public Set getEntities(Position position) { return (set == null) ? ImmutableSet.of() : ImmutableSet.copyOf(set); } + /** + * Gets a shallow copy of the {@link Set} of {@link Entity} objects of the specified type. The returned + * type will be immutable. + * + * @param type The type of entity. + * @return The Set. Will be immutable. + */ + @SuppressWarnings("unchecked") + public Stream getEntities(EntityType type) { + return (Stream) entities.values().stream().flatMap(Collection::stream) + .filter(entity -> entity.getEntityType() == type); + } + /** * Gets a shallow copy of the {@link Set} of {@link Entity}s with the specified {@link EntityType}(s). The returned * type will be immutable. Type will be inferred from the call, so ensure that the Entity type and the reference diff --git a/game/src/main/java/org/apollo/game/model/entity/Mob.java b/game/src/main/java/org/apollo/game/model/entity/Mob.java index 9277777f4..6cbf4ec66 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Mob.java +++ b/game/src/main/java/org/apollo/game/model/entity/Mob.java @@ -1,5 +1,7 @@ package org.apollo.game.model.entity; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import org.apollo.cache.def.NpcDefinition; import org.apollo.game.action.Action; import org.apollo.game.model.*; @@ -62,7 +64,7 @@ public abstract class Mob extends Entity { /** * This mob's list of local players. */ - private final List localPlayers = new ArrayList<>(); + private final IntSet localPlayers = new IntOpenHashSet(); /** * This mob's set of synchronization blocks. @@ -301,7 +303,7 @@ public final List getLocalNpcList() { * * @return The list. */ - public final List getLocalPlayerList() { + public final IntSet getLocalPlayerList() { return localPlayers; } diff --git a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java index bb911b15a..8ae57194a 100644 --- a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java +++ b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java @@ -160,7 +160,7 @@ public boolean full() { */ @SuppressWarnings("unchecked") public T get(int index) { - if (index < 1 || index >= capacity() + 1) { + if (index < 1) { throw new IndexOutOfBoundsException("Mob index is out of bounds."); } return (T) mobs[index - 1]; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java index 80d31cb34..7c3e99edd 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java @@ -24,9 +24,7 @@ public WalkMessage decode(GamePacket packet) { int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); long type = reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); - Position[] positions = new Position[1]; - positions[0] = new Position(x, y); - return new WalkMessage(positions, type == 1); + return new WalkMessage(x, y, type == 1); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java new file mode 100644 index 000000000..d5e829d0d --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java @@ -0,0 +1,61 @@ +package org.apollo.game.release.r181.encoders.player; + +import org.apollo.cache.def.EquipmentDefinition; +import org.apollo.game.message.impl.PlayerSynchronizationMessage; +import org.apollo.game.model.Animation; +import org.apollo.game.model.Appearance; +import org.apollo.game.model.Direction; +import org.apollo.game.model.Graphic; +import org.apollo.game.model.Item; +import org.apollo.game.model.Position; +import org.apollo.game.model.entity.EquipmentConstants; +import org.apollo.game.model.entity.setting.Gender; +import org.apollo.game.model.inv.Inventory; +import org.apollo.game.sync.block.AnimationBlock; +import org.apollo.game.sync.block.AppearanceBlock; +import org.apollo.game.sync.block.ChatBlock; +import org.apollo.game.sync.block.ForceChatBlock; +import org.apollo.game.sync.block.ForceMovementBlock; +import org.apollo.game.sync.block.GraphicBlock; +import org.apollo.game.sync.block.HitUpdateBlock; +import org.apollo.game.sync.block.InteractingMobBlock; +import org.apollo.game.sync.block.SecondaryHitUpdateBlock; +import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.sync.block.TurnToPositionBlock; +import org.apollo.game.sync.seg.player.AddHighResolutionPlayer; +import org.apollo.game.sync.seg.MovementSegment; +import org.apollo.game.sync.seg.SegmentType; +import org.apollo.game.sync.seg.SynchronizationSegment; +import org.apollo.game.sync.seg.TeleportSegment; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link PlayerSynchronizationMessage}. + * + * @author Graham + * @author Major + */ +public final class PlayerSynchronizationMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(PlayerSynchronizationMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(90, PacketType.VARIABLE_SHORT); + builder.switchToBitAccess(); + + GamePacketBuilder blockBuilder = new GamePacketBuilder(); + + + //low-rez-movement + //low-rez- + + // high-rez-movement + + return builder.toGamePacket(); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/session/LoginSession.java b/game/src/main/java/org/apollo/game/session/LoginSession.java index fc7afa8f1..0ad5bc71b 100644 --- a/game/src/main/java/org/apollo/game/session/LoginSession.java +++ b/game/src/main/java/org/apollo/game/session/LoginSession.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.security.SecureRandom; +import java.util.NoSuchElementException; import java.util.Optional; /** @@ -134,16 +135,21 @@ public void sendLoginSuccess(Player player) { Release release = context.getRelease(); - channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release)); - channel.pipeline() - .addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom())); + try { + channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release)); + channel.pipeline() + .addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom())); - channel.pipeline().addBefore("handler", "gameDecoder", - new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease())); - channel.pipeline().addAfter("gameDecoder", "messageDecoder", new GameMessageDecoder(release)); + channel.pipeline().addAfter("gameEncoder", "gameDecoder", + new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease())); + channel.pipeline().addAfter("gameDecoder", "messageDecoder", new GameMessageDecoder(release)); + + channel.pipeline().remove("loginDecoder"); + channel.pipeline().remove("loginEncoder"); + } catch (NoSuchElementException ex) { + + } - channel.pipeline().remove("loginDecoder"); - channel.pipeline().remove("loginEncoder"); } /** diff --git a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java index edc966de6..4395c3c0b 100644 --- a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java @@ -69,12 +69,14 @@ public void synchronize(MobRepository players, MobRepository npcs) } phaser.arriveAndAwaitAdvance(); + long duration = System.currentTimeMillis(); phaser.bulkRegister(playerCount); for (Player player : players) { SynchronizationTask task = new PlayerSynchronizationTask(player); executor.submit(new PhasedSynchronizationTask(phaser, task)); } phaser.arriveAndAwaitAdvance(); + System.out.println("Took " + (System.currentTimeMillis() - duration) + " milliseconds"); phaser.bulkRegister(playerCount); for (Player player : players) { diff --git a/game/src/main/java/org/apollo/game/sync/seg/AddPlayerSegment.java b/game/src/main/java/org/apollo/game/sync/seg/player/AddHighResolutionPlayer.java similarity index 72% rename from game/src/main/java/org/apollo/game/sync/seg/AddPlayerSegment.java rename to game/src/main/java/org/apollo/game/sync/seg/player/AddHighResolutionPlayer.java index a48884c3e..707e1fe3f 100644 --- a/game/src/main/java/org/apollo/game/sync/seg/AddPlayerSegment.java +++ b/game/src/main/java/org/apollo/game/sync/seg/player/AddHighResolutionPlayer.java @@ -1,14 +1,16 @@ -package org.apollo.game.sync.seg; +package org.apollo.game.sync.seg.player; import org.apollo.game.model.Position; import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.sync.seg.SegmentType; +import org.apollo.game.sync.seg.SynchronizationSegment; /** * A {@link SynchronizationSegment} which adds a player. * * @author Graham */ -public final class AddPlayerSegment extends SynchronizationSegment { +public final class AddHighResolutionPlayer extends SynchronizationSegment { /** * The index. @@ -27,7 +29,7 @@ public final class AddPlayerSegment extends SynchronizationSegment { * @param index The player's index. * @param position The position. */ - public AddPlayerSegment(SynchronizationBlockSet blockSet, int index, Position position) { + public AddHighResolutionPlayer(SynchronizationBlockSet blockSet, int index, Position position) { super(blockSet); this.index = index; this.position = position; diff --git a/game/src/main/java/org/apollo/game/sync/seg/player/AddLowResolutionPlayer.java b/game/src/main/java/org/apollo/game/sync/seg/player/AddLowResolutionPlayer.java new file mode 100644 index 000000000..4b0a1d3a4 --- /dev/null +++ b/game/src/main/java/org/apollo/game/sync/seg/player/AddLowResolutionPlayer.java @@ -0,0 +1,24 @@ +package org.apollo.game.sync.seg.player; + +import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.sync.seg.SegmentType; +import org.apollo.game.sync.seg.SynchronizationSegment; + +/** + * @author Khaled Abdeljaber + */ +public class AddLowResolutionPlayer extends SynchronizationSegment { + /** + * Creates the segment. + * + * @param blockSet The block set. + */ + public AddLowResolutionPlayer(SynchronizationBlockSet blockSet) { + super(blockSet); + } + + @Override + public SegmentType getType() { + return SegmentType.REMOVE_MOB; + } +} diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index 069a0ce64..b327684b9 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -1,23 +1,16 @@ package org.apollo.game.sync.task; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import org.apollo.game.message.impl.PlayerSynchronizationMessage; import org.apollo.game.model.Position; -import org.apollo.game.model.area.Region; -import org.apollo.game.model.area.RegionCoordinates; -import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.Player; import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; import org.apollo.game.sync.block.SynchronizationBlock; import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.seg.*; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacketBuilder; /** * A {@link SynchronizationTask} which synchronizes the specified {@link Player} . @@ -42,6 +35,26 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { */ private final Player player; + private byte[] skipped = new byte[2048]; + + private Int2IntOpenHashMap externalPositions = new Int2IntOpenHashMap(2048); + + private final GamePacketBuilder[] builders = new GamePacketBuilder[4]; + private final GamePacketBuilder blockBuilder = new GamePacketBuilder(); + + /** + * Contains packed location update data. + */ + private static final int[][] PACKED_LOCATION_UPDATE1 = new int[][] { { 0, 3, 5 }, { 1, -1, 6 }, { 2, 4, 7 } }; + /** + * Contains packed location update data. + */ + private static final int[][] PACKED_LOCATION_UPDATE2 = new int[][] { { 0, 3, 5 }, { 1, -1, 6 }, { 2, 4, 7 } }; + /** + * Contains packed location update data. + */ + private static final int[][] PACKED_LOCATION_UPDATE3 = new int[][] { { 0, 5, 7, 9, 11 }, { 1, -1, -1, -1, 12 }, { 2, -1, -1, -1, 13 }, { 3, -1, -1, -1, 14 }, { 4, 6, 8, 10, 15 } }; + /** * Creates the {@link PlayerSynchronizationTask} for the specified {@link Player}. * @@ -53,84 +66,238 @@ public PlayerSynchronizationTask(Player player) { @Override public void run() { - Position lastKnownRegion = player.getLastKnownRegion(); - boolean regionChanged = player.hasRegionChanged(); - int[] appearanceTickets = player.getAppearanceTickets(); + final var counts = new short[4]; + for (int index = 0; index < builders.length; index++) { + builders[index] = new GamePacketBuilder(); + } - SynchronizationBlockSet blockSet = player.getBlockSet(); + final var oldLocalPlayers = player.getLocalPlayerList(); + final var distance = player.getViewingDistance(); + final var appearanceTickets = player.getAppearanceTickets(); + final var position = player.getPosition(); + final var repo = player.getWorld().getPlayerRepository(); + final var repository = player.getWorld().getRegionRepository(); + final var current = repository.fromPosition(position); + final var regions = current.getSurrounding(); + regions.add(current.getCoordinates()); - if (blockSet.contains(ChatBlock.class)) { - blockSet = blockSet.clone(); - blockSet.remove(ChatBlock.class); + + for (int index = 0; index < builders.length; index++) { + builders[index].switchToBitAccess(); + } + + final var players = new IntOpenHashSet(250); + for (var coordinates : regions) { + var region = repository.get(coordinates); + region.getEntities(EntityType.PLAYER).forEach(player -> players.add(player.getIndex())); + } + + for (var index = 1; index < 2048; index++) { + final var firstPass = (skipped[index - 1] & 0x1) == 0; + final var other = repo.get(index); + final var nsn = other != null && oldLocalPlayers.contains(index) ? firstPass ? 0 : 1 : firstPass ? 2 : 3; + final var low = nsn == 2 || nsn == 3; + + skipBody(nsn, counts[nsn]); + counts[nsn] = 0; + + if (low) { + if (players.contains(index)) { + SynchronizationBlockSet blockSet = other.getBlockSet(); + if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, + other.getAppearanceTicket())) { + blockSet = blockSet.clone(); + blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); + } + oldLocalPlayers.add(index); + addPlayer(nsn, index, other.getPosition(), blockSet); + } else { + if (other == null) { + lowrez(nsn, index, null); + } else { + lowrez(nsn, index, other.getPosition()); + } + } + } else { + SynchronizationBlockSet blockSet = other.getBlockSet(); + if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, + other.getAppearanceTicket())) { + blockSet = blockSet.clone(); + blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); + } + + if (!players.contains(index) || !other.getPosition().isWithinDistance(position, distance)) { + oldLocalPlayers.remove(index); + highrez(nsn, other, false); + } else { + oldLocalPlayers.add(index); + highrez(nsn, other, true); + } + } + + skipped[index] >>= 1; } - Position position = player.getPosition(); + for (var nsn = 0; nsn < builders.length; nsn++) { + skipFooter(nsn, counts[nsn]); + } - SynchronizationSegment segment = (player.isTeleporting() || player.hasRegionChanged()) ? - new TeleportSegment(blockSet, position) : new MovementSegment(blockSet, player.getDirections()); + //player.send(new PlayerSynchronizationMessage(builders)); + } - List localPlayers = player.getLocalPlayerList(); - int oldCount = localPlayers.size(); + private void addPlayer(int nsn, int index, Position position, SynchronizationBlockSet blockSet) { + final var main = builders[nsn]; + main.putBits(2, 0); - List segments = new ArrayList<>(); - int distance = player.getViewingDistance(); + final var lastPosition = externalPositions.getOrDefault(index, -1); + if (lastPosition != position.hashCode()) { + main.putBit(1); + lowrez(nsn, index, position); + } else { + main.putBit(0); + } - for (Iterator iterator = localPlayers.iterator(); iterator.hasNext(); ) { - Player other = iterator.next(); + main.putBits(13, position.getY() << 13 | position.getX()); + main.putBits(13, position.getY()); + flagBlockUpdate(nsn, blockSet); + } - if (removeable(position, distance, other)) { - iterator.remove(); - segments.add(new RemoveMobSegment()); + private void lowrez(int nsn, int index, Position position) { + final var main = builders[nsn]; + final var lastPosition = externalPositions.getOrDefault(index, -1); + if (lastPosition == -1) { + return; + } + final var currentPosition = position.hashCode(); + if (lastPosition != currentPosition) { + externalPositions.put(index, currentPosition); + + final var lastY = lastPosition & 0xFF; + final var lastX = lastPosition >> 8 & 0xFF; + final var lastPlane = lastPosition >> 16; + + final var currentY = currentPosition & 0xFF; + final var currentX = currentPosition >> 8 & 0xFF; + final var currentPlane = currentPosition >> 16; + + final var yOffset = currentY - lastY; + final var xOffset = currentX - lastX; + final var planeOffset = (currentPlane - lastPlane) & 0x3; + + if (currentX == lastX && currentY == lastY) { + main.putBits(2, 1); + main.putBits(2, planeOffset); + } else if (Math.abs(xOffset) <= 1 && Math.abs(yOffset) <= 1) { + main.putBits(2, 2); + main.putBits(5, + (PACKED_LOCATION_UPDATE1[xOffset + 1][yOffset + 1] & 0x7) + ((planeOffset & 0x3) << 3)); } else { - segments.add(new MovementSegment(other.getBlockSet(), other.getDirections())); + main.putBits(2, 3); + main.putBits(18, ((xOffset & 0xFF) << 8) + (yOffset & 0xFF) + ((planeOffset & 0x3) << 16)); } + } else { + main.putBits(2, 0); } + } - int added = 0, count = localPlayers.size(); + private void flagBlockUpdate(int nsn, SynchronizationBlockSet blockSet) { + final var buffer = builders[nsn]; + if (blockSet.size() == 0) { + buffer.putBit(0); + return; + } - RegionRepository repository = player.getWorld().getRegionRepository(); - Region current = repository.fromPosition(position); + buffer.putBit(1); + if (blockSet.contains(AppearanceBlock.class)) { + int flag = 0; - Set regions = current.getSurrounding(); - regions.add(current.getCoordinates()); + //accumulate flag here. - Stream players = regions.stream().map(repository::get) - .flatMap(region -> region.getEntities(EntityType.PLAYER)); + if (flag >= 0xFF) { + flag |= 0x8; + } - Iterator iterator = players.iterator(); + blockBuilder.put(DataType.BYTE, flag); - while (iterator.hasNext()) { - if (count >= MAXIMUM_LOCAL_PLAYERS) { - player.flagExcessivePlayers(); - break; - } else if (added >= NEW_PLAYERS_PER_CYCLE) { - break; + if (flag >= 0xFF) { + blockBuilder.put(DataType.BYTE, flag >> 8); } - Player other = iterator.next(); - Position local = other.getPosition(); - - if (other != player && local.isWithinDistance(position, distance) && !localPlayers.contains(other)) { - localPlayers.add(other); - count++; - added++; + // write the blocks here. - blockSet = other.getBlockSet(); + } + } - int index = other.getIndex(); + private void highrez(int nsn, Player other, boolean remove) { + final var main = builders[nsn]; + final var directions = other.getDirections(); + final var nextUpdateType = other.isTeleporting() ? 3 : directions.length; + final var position = other.getPosition(); - if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, other.getAppearanceTicket())) { - blockSet = blockSet.clone(); - blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); - } + SynchronizationBlockSet blockSet = other.getBlockSet(); + if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(other.getAppearanceTickets(), + other.getIndex() - 1, other.getAppearanceTicket())) { + blockSet = blockSet.clone(); + blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); + } - segments.add(new AddPlayerSegment(blockSet, index, local)); + flagBlockUpdate(nsn, blockSet); + main.putBits(2, nextUpdateType); + + if (remove) { + main.putBit(1); + lowrez(nsn, other.getIndex(), position); + } else if (nextUpdateType == 1) { + main.putBits(3, directions[0].toInteger()); + } else if (nextUpdateType == 2) { + main.putBits(4, directions[1].toInteger()); + } else if (nextUpdateType == 3) { + final var nextUpdateDeltaX = player.getPosition().getX() - position.getX(); + final var nextUpdateDeltaY = player.getPosition().getY() - position.getY(); + final var nextUpdateDeltaPlane = player.getPosition().getHeight() - position.getHeight(); + if (Math.abs(nextUpdateDeltaX) < 16 && Math.abs(nextUpdateDeltaY) < 16) { + main.putBits(12, + ((nextUpdateDeltaX & 0x1f) << 5) + (nextUpdateDeltaY & 0x1f) + ((nextUpdateDeltaPlane & 0x3) << 10)); + } else { + main.putBits(1, 1); + main.putBits(30, + ((nextUpdateDeltaX & 0x3FFF) << 14) + (nextUpdateDeltaY & 0x3FFF) + ((nextUpdateDeltaPlane & 0x3) << 28)); } } + } - PlayerSynchronizationMessage message = new PlayerSynchronizationMessage(lastKnownRegion, position, - regionChanged, segment, oldCount, segments); - player.send(message); + private void skipBody(int nsn, int skips) { + final var builder = builders[nsn]; + if (skips != 0) { + builder.putBit(0); + skip(builder, skips - 1); + } + builder.putBit(1); + } + + private void skipFooter(int nsn, int skips) { + final var builder = builders[nsn]; + if (skips == 0) { + return; + } + builder.putBit(0); + skip(builder, skips - 1); + builder.switchToByteAccess(); + } + + private void skip(GamePacketBuilder builder, int skips) { + if (skips < 1) { + builder.putBits(2, 0); + } else if (skips < 32) { + builder.putBits(2, 1); + builder.putBits(5, skips); + } else if (skips < 256) { + builder.putBits(2, 2); + builder.putBits(8, skips); + } else { + builder.putBits(2, 3); + builder.putBits(11, skips); + } } /** @@ -138,10 +305,10 @@ public void run() { * the specified appearance ticket array. * * @param appearanceTickets The appearance tickets. - * @param index The index of the Player. - * @param appearanceTicket The current appearance ticket for the Player. + * @param index The index of the Player. + * @param appearanceTicket The current appearance ticket for the Player. * @return {@code true} if the specified Player has a cached appearance - * otherwise {@code false}. + * otherwise {@code false}. */ private boolean hasCachedAppearance(int[] appearanceTickets, int index, int appearanceTicket) { if (appearanceTickets[index] != appearanceTicket) { @@ -156,16 +323,17 @@ private boolean hasCachedAppearance(int[] appearanceTickets, int index, int appe * Returns whether or not the specified {@link Player} should be removed. * * @param position The {@link Position} of the Player being updated. - * @param other The Player being tested. + * @param other The Player being tested. * @return {@code true} iff the specified Player should be removed. */ - private boolean removeable(Position position, int distance, Player other) { + private boolean removable(Position position, int distance, Player other) { if (other.isTeleporting() || !other.isActive()) { return true; } Position otherPosition = other.getPosition(); - return otherPosition.getLongestDelta(position) > distance || !otherPosition.isWithinDistance(position, distance); + return otherPosition.getLongestDelta(position) > distance || !otherPosition + .isWithinDistance(position, distance); } } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java index 7438127b9..f5d83bdfa 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java @@ -190,7 +190,6 @@ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List Date: Fri, 10 Apr 2020 16:12:21 -0400 Subject: [PATCH 38/63] GPI nearly complete. Still need masks. Going to clean up the code more. It's written in order to reduce the number of loops and the number of comparisons. --- .../impl/PlayerSynchronizationMessage.java | 21 +- .../game/model/entity/MobRepository.java | 8 +- .../org/apollo/game/model/entity/Player.java | 6 + .../game/model/entity/PlayerUpdateInfo.java | 32 ++ .../apollo/game/release/r181/Release181.java | 2 + .../r181/decoders/map/WalkMessageDecoder.java | 1 - .../PlayerSynchronizationMessageEncoder.java | 22 +- .../org/apollo/game/session/LoginSession.java | 2 +- .../sync/task/PlayerSynchronizationTask.java | 288 +++++++++--------- .../net/codec/game/GamePacketBuilder.java | 8 +- 10 files changed, 228 insertions(+), 162 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java index e2bf02503..26bc24b31 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java @@ -1,13 +1,24 @@ package org.apollo.game.message.impl; -import org.apollo.game.model.Position; -import org.apollo.game.sync.seg.SynchronizationSegment; +import org.apollo.net.codec.game.GamePacketBuilder; import org.apollo.net.message.Message; -import java.util.List; - public final class PlayerSynchronizationMessage extends Message { - public PlayerSynchronizationMessage() { + + private final GamePacketBuilder[] nsnBuilders; + private final GamePacketBuilder blockBuilder; + + public PlayerSynchronizationMessage(GamePacketBuilder[] nsnBuilders, GamePacketBuilder blockBuilder) { + this.nsnBuilders = nsnBuilders; + this.blockBuilder = blockBuilder; + } + + public GamePacketBuilder[] getNsnBuilders() { + return nsnBuilders; + } + + public GamePacketBuilder getBlockBuilder() { + return blockBuilder; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java index 8ae57194a..310c087d0 100644 --- a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java +++ b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java @@ -124,7 +124,7 @@ public boolean add(T mob) { } mobs[index] = mob; - mob.setIndex(index + 1); + mob.setIndex(index); size++; return true; @@ -160,10 +160,10 @@ public boolean full() { */ @SuppressWarnings("unchecked") public T get(int index) { - if (index < 1) { + if (index < 0) { throw new IndexOutOfBoundsException("Mob index is out of bounds."); } - return (T) mobs[index - 1]; + return (T) mobs[index]; } @Override @@ -193,7 +193,7 @@ private void remove(int index) { throw new IllegalArgumentException("MobRepository index mismatch, cannot remove Mob."); } - mobs[index - 1] = null; + mobs[index] = null; mob.setIndex(-1); size--; } diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 467a5b24b..1c7b2a8e1 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -105,6 +105,8 @@ private static int nextAppearanceTicket() { */ private final Deque queuedMessages = new ArrayDeque<>(); + private final PlayerUpdateInfo playerUpdateInfo = new PlayerUpdateInfo(); + /** * The player's appearance. */ @@ -300,6 +302,10 @@ public boolean friendsWith(String username) { return friends.contains(username.toLowerCase()); } + public PlayerUpdateInfo getPlayerUpdateInfo() { + return playerUpdateInfo; + } + /** * Gets the player's appearance. * diff --git a/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java b/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java new file mode 100644 index 000000000..83410e8e7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java @@ -0,0 +1,32 @@ +package org.apollo.game.model.entity; + +import org.apollo.net.codec.game.GamePacketBuilder; + +/** + * @author Khaled Abdeljaber + */ +public class PlayerUpdateInfo { + + private byte[] skipped = new byte[2048]; + private int[] externalPositions = new int[2048]; + + public PlayerUpdateInfo() { + + } + + public byte getSkip(int index) { + return skipped[index]; + } + + public void setSkip(int index, byte value) { + skipped[index] = value; + } + + public void setExternalPositions(int index, int value) { + externalPositions[index] = value; + } + + public int getExternalPosition(int index) { + return externalPositions[index]; + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index d1190a8d6..674641426 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -5,6 +5,7 @@ import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; import org.apollo.game.release.r181.encoders.game.LogoutEncoder; +import org.apollo.game.release.r181.encoders.player.PlayerSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.region.MobResetAnimsEncoder; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; import org.apollo.game.release.r181.decoders.map.item.*; @@ -194,6 +195,7 @@ private void init() { register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); + register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); register(ServerChatMessage.class, new ServerChatMessageEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java index 7c3e99edd..c9ce47cb0 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java @@ -19,7 +19,6 @@ public final class WalkMessageDecoder extends MessageDecoder { public WalkMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); long type = reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java index d5e829d0d..1afbdaa87 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java @@ -1,5 +1,6 @@ package org.apollo.game.release.r181.encoders.player; +import io.netty.buffer.Unpooled; import org.apollo.cache.def.EquipmentDefinition; import org.apollo.game.message.impl.PlayerSynchronizationMessage; import org.apollo.game.model.Animation; @@ -45,17 +46,14 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncodergetEntities(EntityType.PLAYER).forEach(player -> players.add(player.getIndex())); + var region = repoRegion.get(coordinates); + var players = region.getEntities(EntityType.PLAYER); + var iterator = players.iterator(); + while (iterator.hasNext()) { + if (toAdd.size() + localPlayers.size() >= MAXIMUM_LOCAL_PLAYERS) { + player.flagExcessivePlayers(); + break outer; + } + + final var other = iterator.next(); + final var index = other.getIndex(); + if (index != player.getIndex() && other.getPosition() + .isWithinDistance(position, distance) && !localPlayers.contains(index)) { + toAdd.add(index); + } + } } - for (var index = 1; index < 2048; index++) { - final var firstPass = (skipped[index - 1] & 0x1) == 0; - final var other = repo.get(index); - final var nsn = other != null && oldLocalPlayers.contains(index) ? firstPass ? 0 : 1 : firstPass ? 2 : 3; + for (var index = 0; index < 2048; index++) { + final var firstPass = (info.getSkip(index) & 0x1) == 0; + final var other = repoPlayer.get(index); + final var nsn = other != null && (localPlayers.contains(index) || player + .getIndex() == index) ? firstPass ? 0 : 1 : firstPass ? 2 : 3; final var low = nsn == 2 || nsn == 3; - skipBody(nsn, counts[nsn]); - counts[nsn] = 0; - if (low) { - if (players.contains(index)) { + if (toAdd.contains(index)) { SynchronizationBlockSet blockSet = other.getBlockSet(); - if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, + if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index, other.getAppearanceTicket())) { blockSet = blockSet.clone(); blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); } - oldLocalPlayers.add(index); - addPlayer(nsn, index, other.getPosition(), blockSet); + addPlayer(info, nsn, index, other.getPosition(), blockSet); } else { if (other == null) { - lowrez(nsn, index, null); + lowrez(nsn, index, info, null); } else { - lowrez(nsn, index, other.getPosition()); + lowrez(nsn, index, info, other.getPosition()); } } } else { SynchronizationBlockSet blockSet = other.getBlockSet(); - if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, + if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index, other.getAppearanceTicket())) { blockSet = blockSet.clone(); blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); } - if (!players.contains(index) || !other.getPosition().isWithinDistance(position, distance)) { - oldLocalPlayers.remove(index); - highrez(nsn, other, false); - } else { - oldLocalPlayers.add(index); - highrez(nsn, other, true); + final var remove = toRemove.contains(index); + if (remove) { + localPlayers.remove(index); } + highrez(info, nsn, other, remove); } - skipped[index] >>= 1; + info.setSkip(index, (byte) (info.getSkip(index) >> 1)); } - for (var nsn = 0; nsn < builders.length; nsn++) { - skipFooter(nsn, counts[nsn]); + for (var nsn = 0; nsn < nsnBuilders.length; nsn++) { + skipFooter(info, nsn, counts[nsn]); } - //player.send(new PlayerSynchronizationMessage(builders)); + player.send(new PlayerSynchronizationMessage(nsnBuilders, blockBuilder)); } - private void addPlayer(int nsn, int index, Position position, SynchronizationBlockSet blockSet) { - final var main = builders[nsn]; + private void addPlayer(PlayerUpdateInfo info, int nsn, int index, Position position, + SynchronizationBlockSet blockSet) { + final var main = nsnBuilders[nsn]; main.putBits(2, 0); - final var lastPosition = externalPositions.getOrDefault(index, -1); - if (lastPosition != position.hashCode()) { + if (info.getExternalPosition(index) != position.hashCode()) { main.putBit(1); - lowrez(nsn, index, position); + lowrez(nsn, index, info, position); } else { main.putBit(0); } - main.putBits(13, position.getY() << 13 | position.getX()); - main.putBits(13, position.getY()); - flagBlockUpdate(nsn, blockSet); + main.putBits(26, position.getY() << 13 | position.getX()); + flagBlockUpdate(nsn, info, blockSet); } - private void lowrez(int nsn, int index, Position position) { - final var main = builders[nsn]; - final var lastPosition = externalPositions.getOrDefault(index, -1); - if (lastPosition == -1) { - return; - } - final var currentPosition = position.hashCode(); - if (lastPosition != currentPosition) { - externalPositions.put(index, currentPosition); - - final var lastY = lastPosition & 0xFF; - final var lastX = lastPosition >> 8 & 0xFF; - final var lastPlane = lastPosition >> 16; - - final var currentY = currentPosition & 0xFF; - final var currentX = currentPosition >> 8 & 0xFF; - final var currentPlane = currentPosition >> 16; - - final var yOffset = currentY - lastY; - final var xOffset = currentX - lastX; - final var planeOffset = (currentPlane - lastPlane) & 0x3; - - if (currentX == lastX && currentY == lastY) { - main.putBits(2, 1); - main.putBits(2, planeOffset); - } else if (Math.abs(xOffset) <= 1 && Math.abs(yOffset) <= 1) { - main.putBits(2, 2); - main.putBits(5, - (PACKED_LOCATION_UPDATE1[xOffset + 1][yOffset + 1] & 0x7) + ((planeOffset & 0x3) << 3)); - } else { - main.putBits(2, 3); - main.putBits(18, ((xOffset & 0xFF) << 8) + (yOffset & 0xFF) + ((planeOffset & 0x3) << 16)); - } - } else { - main.putBits(2, 0); - } - } - - private void flagBlockUpdate(int nsn, SynchronizationBlockSet blockSet) { - final var buffer = builders[nsn]; - if (blockSet.size() == 0) { - buffer.putBit(0); - return; - } - - buffer.putBit(1); - if (blockSet.contains(AppearanceBlock.class)) { - int flag = 0; - - //accumulate flag here. - - if (flag >= 0xFF) { - flag |= 0x8; - } - - blockBuilder.put(DataType.BYTE, flag); - - if (flag >= 0xFF) { - blockBuilder.put(DataType.BYTE, flag >> 8); - } - - // write the blocks here. - - } - } - - private void highrez(int nsn, Player other, boolean remove) { - final var main = builders[nsn]; + private void highrez(PlayerUpdateInfo info, int nsn, Player other, boolean remove) { + final var main = nsnBuilders[nsn]; final var directions = other.getDirections(); final var nextUpdateType = other.isTeleporting() ? 3 : directions.length; final var position = other.getPosition(); @@ -241,12 +190,12 @@ private void highrez(int nsn, Player other, boolean remove) { blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); } - flagBlockUpdate(nsn, blockSet); + flagBlockUpdate(nsn, info, blockSet); main.putBits(2, nextUpdateType); if (remove) { main.putBit(1); - lowrez(nsn, other.getIndex(), position); + lowrez(nsn, other.getIndex(), info, position); } else if (nextUpdateType == 1) { main.putBits(3, directions[0].toInteger()); } else if (nextUpdateType == 2) { @@ -266,8 +215,72 @@ private void highrez(int nsn, Player other, boolean remove) { } } - private void skipBody(int nsn, int skips) { - final var builder = builders[nsn]; + private void lowrez(int nsn, int index, PlayerUpdateInfo info, Position position) { + final var main = nsnBuilders[nsn]; + final var lastPosition = info.getExternalPosition(index); + if (position != null) { + final var currentPosition = position.hashCode(); + if (lastPosition != currentPosition) { + info.setExternalPositions(index, currentPosition); + + final var lastY = lastPosition & 0xFF; + final var lastX = lastPosition >> 8 & 0xFF; + final var lastPlane = lastPosition >> 16; + + final var currentY = currentPosition & 0xFF; + final var currentX = currentPosition >> 8 & 0xFF; + final var currentPlane = currentPosition >> 16; + + final var yOffset = currentY - lastY; + final var xOffset = currentX - lastX; + final var planeOffset = (currentPlane - lastPlane) & 0x3; + + if (currentX == lastX && currentY == lastY) { + main.putBits(2, 1); + main.putBits(2, planeOffset); + } else if (Math.abs(xOffset) <= 1 && Math.abs(yOffset) <= 1) { + main.putBits(2, 2); + main.putBits(5, + (PACKED_LOCATION_UPDATE1[xOffset + 1][yOffset + 1] & 0x7) + ((planeOffset & 0x3) << 3)); + } else { + main.putBits(2, 3); + main.putBits(18, ((xOffset & 0xFF) << 8) + (yOffset & 0xFF) + ((planeOffset & 0x3) << 16)); + } + return; + } + } + + main.putBits(2, 0); + } + + private void flagBlockUpdate(int nsn, PlayerUpdateInfo info, SynchronizationBlockSet blockSet) { + final var buffer = nsnBuilders[nsn]; + if (blockSet.size() == 0) { + buffer.putBit(0); + return; + } + + buffer.putBit(1); + + var flag = 0; + //accumulate flag here. + + if (flag >= 0xFF) { + flag |= 0x8; + } + + blockBuilder.put(DataType.BYTE, flag); + + if (flag >= 0xFF) { + blockBuilder.put(DataType.BYTE, flag >> 8); + } + + // write the blocks here. + + } + + private void skipBody(PlayerUpdateInfo info, int nsn, int skips) { + final var builder = nsnBuilders[nsn]; if (skips != 0) { builder.putBit(0); skip(builder, skips - 1); @@ -275,9 +288,10 @@ private void skipBody(int nsn, int skips) { builder.putBit(1); } - private void skipFooter(int nsn, int skips) { - final var builder = builders[nsn]; + private void skipFooter(PlayerUpdateInfo info, int nsn, int skips) { + final var builder = nsnBuilders[nsn]; if (skips == 0) { + builder.switchToByteAccess(); return; } builder.putBit(0); @@ -327,7 +341,7 @@ private boolean hasCachedAppearance(int[] appearanceTickets, int index, int appe * @return {@code true} iff the specified Player should be removed. */ private boolean removable(Position position, int distance, Player other) { - if (other.isTeleporting() || !other.isActive()) { + if (other == null || other.isTeleporting() || !other.isActive()) { return true; } diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java index 0b1e1f0db..9e08c783b 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java @@ -1,6 +1,7 @@ package org.apollo.net.codec.game; import io.netty.buffer.ByteBuf; +import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.Unpooled; import org.apollo.net.meta.PacketType; @@ -225,7 +226,7 @@ public void putBit(int value) { public void putBits(int numBits, int value) { Preconditions.checkArgument(numBits >= 1 && numBits <= 32, "Number of bits must be between 1 and 32 inclusive."); - checkBitAccess(); + //checkBitAccess(); int bytePos = bitIndex >> 3; int bitOffset = 8 - (bitIndex & 7); @@ -431,6 +432,10 @@ public void switchToByteAccess() { buffer.writerIndex((bitIndex + 7) / 8); } + public void addComposite(CompositeByteBuf composite) { + composite.addComponent(buffer); + } + /** * Creates a {@link GamePacket} based on the current contents of this builder. * @@ -444,5 +449,4 @@ public GamePacket toGamePacket() { return new GamePacket(opcode, type, buffer); } - } \ No newline at end of file From f96ef85edc625c714b5c88521368ed22047ba2a1 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 00:02:37 -0400 Subject: [PATCH 39/63] Gpi done. Added flags.ER --- .../message/handler/WalkMessageHandler.java | 3 +- .../impl/PlayerSynchronizationMessage.java | 17 +- .../game/message/impl/PublicChatMessage.java | 27 +- .../impl/encode/RebuildNormalMessage.java | 35 +- .../java/org/apollo/game/model/Position.java | 4 + .../org/apollo/game/model/entity/Mob.java | 27 +- .../game/model/entity/MobRepository.java | 12 +- .../org/apollo/game/model/entity/Player.java | 20 +- .../game/model/entity/PlayerUpdateInfo.java | 88 +- .../apollo/game/release/r181/Release181.java | 2 +- .../npc/NpcSynchronizationMessageEncoder.java | 3 +- .../PlayerSynchronizationMessageEncoder.java | 42 +- .../region/RebuildNormalMessageEncoder.java | 12 +- .../game/sync/block/AnimationBlock.java | 1 + .../game/sync/block/AppearanceBlock.java | 9 +- .../org/apollo/game/sync/block/ChatBlock.java | 9 + .../game/sync/block/ForceChatBlock.java | 2 + .../game/sync/block/ForceMovementBlock.java | 1 + .../apollo/game/sync/block/GraphicBlock.java | 1 + .../game/sync/block/HitUpdateBlock.java | 2 + .../game/sync/block/InteractingMobBlock.java | 2 + .../game/sync/block/MovementTypeBlock.java | 71 ++ .../sync/block/SecondaryHitUpdateBlock.java | 2 + .../game/sync/block/SynchronizationBlock.java | 8 +- .../block/TemporaryMovementTypeBlock.java | 17 + .../apollo/game/sync/block/TitleBlock.java | 40 + .../game/sync/block/TransformBlock.java | 2 + .../game/sync/block/TurnToPositionBlock.java | 28 +- .../sync/task/PlayerSynchronizationTask.java | 911 +++++++++++++----- .../task/PrePlayerSynchronizationTask.java | 25 +- .../game/model/entity/MobRepositoryTests.java | 16 +- 31 files changed, 1053 insertions(+), 386 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/sync/block/MovementTypeBlock.java create mode 100644 game/src/main/java/org/apollo/game/sync/block/TemporaryMovementTypeBlock.java create mode 100644 game/src/main/java/org/apollo/game/sync/block/TitleBlock.java diff --git a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java index aa2d81209..b2208e83f 100644 --- a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java @@ -27,7 +27,8 @@ public void handle(Player player, WalkMessage message) { WalkingQueue queue = player.getWalkingQueue(); queue.setRunning(message.isRunning() || player.isRunning()); - queue.addFirstStep(new Position(message.getX(), message.getY(), player.getPosition().getHeight())); + player.teleport(new Position(message.getX(), message.getY(), player.getPosition().getHeight())); + //queue.addFirstStep(new Position(message.getX(), message.getY(), player.getPosition().getHeight())); player.getInterfaceSet().close(); diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java index 26bc24b31..522c2e672 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java @@ -1,24 +1,19 @@ package org.apollo.game.message.impl; +import org.apollo.game.model.entity.PlayerUpdateInfo; import org.apollo.net.codec.game.GamePacketBuilder; import org.apollo.net.message.Message; public final class PlayerSynchronizationMessage extends Message { - private final GamePacketBuilder[] nsnBuilders; - private final GamePacketBuilder blockBuilder; + private final GamePacketBuilder info; - public PlayerSynchronizationMessage(GamePacketBuilder[] nsnBuilders, GamePacketBuilder blockBuilder) { - this.nsnBuilders = nsnBuilders; - this.blockBuilder = blockBuilder; + public PlayerSynchronizationMessage(GamePacketBuilder info) { + this.info = info; } - public GamePacketBuilder[] getNsnBuilders() { - return nsnBuilders; - } - - public GamePacketBuilder getBlockBuilder() { - return blockBuilder; + public GamePacketBuilder getInfo() { + return info; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java index 7df576e9f..8ebefaad3 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java @@ -9,6 +9,10 @@ */ public final class PublicChatMessage extends ChatMessage { + public enum PublicChatType { + NONE, QUICKCHAT, CLANCHAT + } + /** * The text color. */ @@ -19,18 +23,25 @@ public final class PublicChatMessage extends ChatMessage { */ private final int effects; + /** + * The type of public chat. + */ + private final PublicChatType type; + /** * Creates a new chat message. * - * @param message The message. + * @param message The message. * @param compressedMessage The compressed message. - * @param color The text color. - * @param effects The text effects. + * @param color The text color. + * @param effects The text effects. + * @param type The chat type. */ - public PublicChatMessage(String message, byte[] compressedMessage, int color, int effects) { + public PublicChatMessage(String message, byte[] compressedMessage, int color, int effects, PublicChatType type) { super(message, compressedMessage); this.color = color; this.effects = effects; + this.type = type; } /** @@ -51,4 +62,12 @@ public int getTextEffects() { return effects; } + /** + * Gets the chat type. + * + * @return the type of public chat. + */ + public PublicChatType getType() { + return type; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java index 6abd49d43..74dbacc5d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java @@ -2,6 +2,9 @@ import org.apollo.cache.map.XteaRepository; import org.apollo.game.model.Position; +import org.apollo.game.model.entity.MobRepository; +import org.apollo.game.model.entity.Player; +import org.apollo.game.model.entity.PlayerUpdateInfo; import org.apollo.net.message.Message; /** @@ -21,10 +24,20 @@ public final class RebuildNormalMessage extends Message { */ private final int index; + /** + * The update information of the player. + */ + private PlayerUpdateInfo info; + /** * The repository containing xteas. */ - private final XteaRepository repository; + private final XteaRepository xteaRepository; + + /** + * The repository containing players. + */ + private final MobRepository playerRepository; /** * If the player has a last known region. @@ -35,13 +48,15 @@ public final class RebuildNormalMessage extends Message { * Creates the region changed message. * * @param position The position of the region. - * @param repository the repository + * @param xteaRepository the repository * @param hasLastKnownRegion if the player has been in a region. */ - public RebuildNormalMessage(Position position, int index, XteaRepository repository, boolean hasLastKnownRegion) { + public RebuildNormalMessage(Position position, int index, PlayerUpdateInfo info, MobRepository playerRepository, XteaRepository xteaRepository, boolean hasLastKnownRegion) { this.position = position; this.index = index; - this.repository = repository; + this.info = info; + this.xteaRepository = xteaRepository; + this.playerRepository = playerRepository; this.hasLastKnownRegion = hasLastKnownRegion; } @@ -64,13 +79,17 @@ public int getIndex() { return index; } + public PlayerUpdateInfo getInfo() { + return info; + } + /** * Gets repository. * * @return the repository */ - public XteaRepository getRepository() { - return repository; + public XteaRepository getXteaRepository() { + return xteaRepository; } /** @@ -81,4 +100,8 @@ public XteaRepository getRepository() { public boolean isHasLastKnownRegion() { return hasLastKnownRegion; } + + public MobRepository getPlayerRepository() { + return playerRepository; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/Position.java b/game/src/main/java/org/apollo/game/model/Position.java index 5c38f0e29..58aede0cb 100644 --- a/game/src/main/java/org/apollo/game/model/Position.java +++ b/game/src/main/java/org/apollo/game/model/Position.java @@ -239,4 +239,8 @@ public String toString() { return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight()) .add("map", getRegionCoordinates()).toString(); } + + public int get18BitHash() { + return (getY() >> 13) + ((getX() >> 13) << 8) + (getHeight() << 16); + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/Mob.java b/game/src/main/java/org/apollo/game/model/entity/Mob.java index 6cbf4ec66..0c9e23c1e 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Mob.java +++ b/game/src/main/java/org/apollo/game/model/entity/Mob.java @@ -1,7 +1,7 @@ package org.apollo.game.model.entity; -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; -import it.unimi.dsi.fastutil.ints.IntSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import it.unimi.dsi.fastutil.objects.ObjectSet; import org.apollo.cache.def.NpcDefinition; import org.apollo.game.action.Action; import org.apollo.game.model.*; @@ -64,7 +64,7 @@ public abstract class Mob extends Entity { /** * This mob's list of local players. */ - private final IntSet localPlayers = new IntOpenHashSet(); + private final ObjectSet localPlayers = new ObjectOpenHashSet<>(); /** * This mob's set of synchronization blocks. @@ -96,6 +96,11 @@ public abstract class Mob extends Entity { */ private Position facingPosition = position; + /** + * The old position of this mob. + */ + private Position oldPosition = position; + /** * This mob's first movement direction. */ @@ -215,6 +220,15 @@ public final Inventory getEquipment() { return equipment; } + + public Position getOldPosition() { + return oldPosition; + } + + public void setOldPosition(Position oldPosition) { + this.oldPosition = oldPosition; + } + /** * Gets the {@link Position} this mob is facing towards. * @@ -303,7 +317,7 @@ public final List getLocalNpcList() { * * @return The list. */ - public final IntSet getLocalPlayerList() { + public final ObjectSet getLocalPlayerList() { return localPlayers; } @@ -486,6 +500,8 @@ public void setLastDirection(Direction lastDirection) { public final void setPosition(Position position) { if (!position.equals(this.position) && world.submit(new MobPositionUpdateEvent(this, position))) { Position old = this.position; + setOldPosition(old); + RegionRepository repository = world.getRegionRepository(); Region current = repository.fromPosition(old), next = repository.fromPosition(position); @@ -587,7 +603,7 @@ public void teleport(Position position) { */ public final void turnTo(Position position) { facingPosition = position; - blockSet.add(SynchronizationBlock.createTurnToPositionBlock(position)); + blockSet.add(SynchronizationBlock.createTurnToPositionBlock(getPosition(), position)); } /** @@ -597,5 +613,4 @@ private void init() { world.schedule(new SkillNormalizationTask(this)); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java index 310c087d0..496deb038 100644 --- a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java +++ b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java @@ -1,10 +1,10 @@ package org.apollo.game.model.entity; -import com.google.common.base.Preconditions; - import java.util.Iterator; import java.util.NoSuchElementException; +import com.google.common.base.Preconditions; + /** * A {@link MobRepository} is a repository of {@link Mob}s that are currently active in the game world. * @@ -124,7 +124,7 @@ public boolean add(T mob) { } mobs[index] = mob; - mob.setIndex(index); + mob.setIndex(index + 1); size++; return true; @@ -160,10 +160,10 @@ public boolean full() { */ @SuppressWarnings("unchecked") public T get(int index) { - if (index < 0) { + if (index < 1 || index >= capacity() + 1) { throw new IndexOutOfBoundsException("Mob index is out of bounds."); } - return (T) mobs[index]; + return (T) mobs[index - 1]; } @Override @@ -193,7 +193,7 @@ private void remove(int index) { throw new IllegalArgumentException("MobRepository index mismatch, cannot remove Mob."); } - mobs[index] = null; + mobs[index - 1] = null; mob.setIndex(-1); size--; } diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 1c7b2a8e1..7bf01c408 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -2,8 +2,13 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import org.apollo.game.message.impl.*; -import org.apollo.game.message.impl.encode.*; +import org.apollo.game.message.impl.IgnoreListMessage; +import org.apollo.game.message.impl.SendFriendMessage; +import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.game.message.impl.encode.ConfigMessage; +import org.apollo.game.message.impl.encode.LogoutMessage; +import org.apollo.game.message.impl.encode.RebuildNormalMessage; +import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; import org.apollo.game.model.World; @@ -105,7 +110,7 @@ private static int nextAppearanceTicket() { */ private final Deque queuedMessages = new ArrayDeque<>(); - private final PlayerUpdateInfo playerUpdateInfo = new PlayerUpdateInfo(); + private final PlayerUpdateInfo updateInfo = new PlayerUpdateInfo(); /** * The player's appearance. @@ -302,8 +307,8 @@ public boolean friendsWith(String username) { return friends.contains(username.toLowerCase()); } - public PlayerUpdateInfo getPlayerUpdateInfo() { - return playerUpdateInfo; + public PlayerUpdateInfo getUpdateInfo() { + return updateInfo; } /** @@ -730,7 +735,8 @@ public void send(Message message) { * Sends the initial messages. */ public void sendInitialMessages(DisplayMode mode) { - send(new RebuildNormalMessage(position, index, world.getRegionRepository().getXteaRepository(), false)); + send(new RebuildNormalMessage(position, index, updateInfo, world.getPlayerRepository(), + world.getRegionRepository().getXteaRepository(), false)); interfaceSet.openTop(mode); for (TopLevelPosition position : TopLevelPosition.values()) { @@ -747,6 +753,8 @@ public void sendInitialMessages(DisplayMode mode) { updateAppearance(); + send(new ConfigMessage(1737, 1 << 31)); + inventory.forceRefresh(); equipment.forceRefresh(); bank.forceRefresh(); diff --git a/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java b/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java index 83410e8e7..70cc382ac 100644 --- a/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java +++ b/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java @@ -1,5 +1,7 @@ package org.apollo.game.model.entity; +import org.apollo.game.model.Position; +import org.apollo.game.model.World; import org.apollo.net.codec.game.GamePacketBuilder; /** @@ -7,26 +9,84 @@ */ public class PlayerUpdateInfo { - private byte[] skipped = new byte[2048]; - private int[] externalPositions = new int[2048]; + public static final int NEW_PLAYERS_PER_CYCLE = 40; + public static final int MAXIMUM_LOCAL_PLAYERS = 0xFF; - public PlayerUpdateInfo() { + /** + *

Activity flags are used to determine whether the player was updated this cycle, or skipped entirely due + * to inactivity. The method is used to group together inactive & active players respectively, allowing the + * server to skip larger amounts of players due to probability, effectively saving bandwidth in the long run, + * as every skipping call writes a number of bits on its own.

+ */ + public byte[] activityFlags; - } + /** + *

The indexes of the players currently in our viewport.

+ */ + public int[] localIndexes; + /** + *

The indexes of the players currently outside our viewport.

+ */ + public int[] externalIndexes; + /** + *

The players currently in our viewport.

+ */ + public Player[] localPlayers; - public byte getSkip(int index) { - return skipped[index]; - } + /** + *

The amount of players currently outside our viewport.

+ */ + public int externalIndexesCount; + /** + *

The amount of players currently inside our viewport.

+ */ + public int localIndexesCount; - public void setSkip(int index, byte value) { - skipped[index] = value; - } + /** + *

The secondary per-player basis buffer for masks.

+ */ + public GamePacketBuilder smallMaskBuffer; + /** + *

The primary buffer for masks.

+ */ + public GamePacketBuilder largeMaskBuffer; + /** + *

The primary buffer of GPI.

+ */ + public GamePacketBuilder buffer; - public void setExternalPositions(int index, int value) { - externalPositions[index] = value; + /** + * Whether or not the viewport is limited to 255 players. + */ + public boolean limitedMode; + + public PlayerUpdateInfo() { + activityFlags = new byte[2048]; + activityFlags = new byte[2048]; + localPlayers = new Player[2048]; + localIndexes = new int[2048]; + externalIndexes = new int[2048]; + smallMaskBuffer = new GamePacketBuilder(); + largeMaskBuffer = new GamePacketBuilder(); + buffer = new GamePacketBuilder(); } - public int getExternalPosition(int index) { - return externalPositions[index]; + public void init(MobRepository repo, int index, Position position, GamePacketBuilder builder) { + builder.switchToBitAccess(); + + final var player = repo.get(index); + builder.putBits(30, position.hashCode()); + localPlayers[player.getIndex()] = player; + localIndexes[localIndexesCount++] = player.getIndex(); + for (var playerIndex = 1; playerIndex < 2048; playerIndex++) { + if (playerIndex == player.getIndex()) { + continue; + } + final var other = repo.get(playerIndex); + builder.putBits(18, other == null ? 0 : other.getPosition().get18BitHash()); + externalIndexes[externalIndexesCount++] = playerIndex; + } + + builder.switchToByteAccess(); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 674641426..55ee57b7d 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -194,7 +194,7 @@ private void init() { register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); - register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); + //register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java index f0a37459c..2273f93cf 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java @@ -7,6 +7,7 @@ import org.apollo.game.model.Position; import org.apollo.game.model.entity.Player; import org.apollo.game.sync.block.*; +import org.apollo.game.sync.block.TransformBlock; import org.apollo.game.sync.seg.AddNpcSegment; import org.apollo.game.sync.seg.MovementSegment; import org.apollo.game.sync.seg.SegmentType; @@ -302,7 +303,7 @@ private static void putTransformBlock(TransformBlock block, GamePacketBuilder bu * @param builder The builder. */ private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position position = block.getPosition(); + Position position = block.getTurnPosition(); builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, position.getX() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java index 1afbdaa87..8bf300232 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java @@ -1,39 +1,7 @@ package org.apollo.game.release.r181.encoders.player; -import io.netty.buffer.Unpooled; -import org.apollo.cache.def.EquipmentDefinition; import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Item; -import org.apollo.game.model.Position; -import org.apollo.game.model.entity.EquipmentConstants; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.game.model.inv.Inventory; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.ForceMovementBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.player.AddHighResolutionPlayer; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; /** @@ -46,14 +14,6 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder titles; + + TitleBlock(Title single, Title... others) { + this.titles = new EnumMap<>(TitlePosition.class); + titles.put(single.position, single.text); + + for (var title : others) { + this.titles.put(title.position, title.text); + } + } + + public EnumMap getTitles() { + return titles; + } +} diff --git a/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java b/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java index 56020b206..bc91270f1 100644 --- a/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java @@ -1,5 +1,7 @@ package org.apollo.game.sync.block; +import org.apollo.game.sync.block.SynchronizationBlock; + /** * The transform {@link SynchronizationBlock}. Only npcs can utilise this block. * diff --git a/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java b/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java index a9f94f29e..a25423973 100644 --- a/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java @@ -1,6 +1,7 @@ package org.apollo.game.sync.block; import org.apollo.game.model.Position; +import org.apollo.game.sync.block.SynchronizationBlock; /** * The turn to position {@link SynchronizationBlock}. Both players and npcs can utilise this block. @@ -9,18 +10,33 @@ */ public final class TurnToPositionBlock extends SynchronizationBlock { + /** + * The position of the mob. + */ + private final Position mobPosition; + /** * The position to turn to. */ - private final Position position; + private final Position turnPosition; /** * Creates the turn to position block. * - * @param position The position to turn to. + * @param turnPosition The position to turn to. + */ + TurnToPositionBlock(Position mobPosition, Position turnPosition) { + this.mobPosition = mobPosition; + this.turnPosition = turnPosition; + } + + /** + * Gets the {@link Position} of the mob. + * + * @return The position of the mob. */ - TurnToPositionBlock(Position position) { - this.position = position; + public Position getMobPosition() { + return mobPosition; } /** @@ -28,8 +44,8 @@ public final class TurnToPositionBlock extends SynchronizationBlock { * * @return The position to turn to. */ - public Position getPosition() { - return position; + public Position getTurnPosition() { + return turnPosition; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index e620cc795..a79a0b36f 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -1,317 +1,755 @@ package org.apollo.game.sync.task; -import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import it.unimi.dsi.fastutil.objects.ObjectSet; +import org.apollo.cache.def.EquipmentDefinition; import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Position; +import org.apollo.game.model.*; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.EntityType; +import org.apollo.game.model.entity.EquipmentConstants; import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.PlayerUpdateInfo; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.SynchronizationBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.model.entity.setting.Gender; +import org.apollo.game.model.inv.Inventory; +import org.apollo.game.sync.block.*; +import org.apollo.game.sync.block.TitleBlock; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.util.BufferUtil; +import org.jetbrains.annotations.NotNull; + +import static org.apollo.game.model.entity.PlayerUpdateInfo.MAXIMUM_LOCAL_PLAYERS; /** * A {@link SynchronizationTask} which synchronizes the specified {@link Player} . * - * @author Graham + * @author Kris + * @author Dragonkk + * @author Cjay0091 */ public final class PlayerSynchronizationTask extends SynchronizationTask { - /** - * The maximum amount of local players. - */ - private static final int MAXIMUM_LOCAL_PLAYERS = 255; - - /** - * The maximum number of players to load per cycle. This prevents the update packet from becoming too large (the - * client uses a 5000 byte buffer) and also stops old spec PCs from crashing when they login or teleport. - */ - private static final int NEW_PLAYERS_PER_CYCLE = 20; - - /** - * Contains packed location update data. - */ - private static final int[][] PACKED_LOCATION_UPDATE1 = new int[][]{{0, 3, 5}, {1, -1, 6}, {2, 4, 7}}; - /** - * Contains packed location update data. - */ - private static final int[][] PACKED_LOCATION_UPDATE3 = new int[][]{{0, 5, 7, 9, 11}, {1, -1, -1, -1, 12}, {2, -1, -1, -1, 13}, {3, -1, -1, -1, 14}, {4, 6, 8, 10, 15}}; + private static final int[][] PACKED_LOCATION_UPDATE2 = new int[][]{{0, 3, 5}, {1, -1, 6}, {2, 4, 7}}; - /** - * The Player. - */ private final Player player; + private final PlayerUpdateInfo info; + private final World world; + private final ObjectSet limitedPlayers; - private final GamePacketBuilder[] nsnBuilders = new GamePacketBuilder[4]; - private final GamePacketBuilder blockBuilder = new GamePacketBuilder(); + private ObjectOpenHashSet added; - /** - * Creates the {@link PlayerSynchronizationTask} for the specified {@link Player}. - * - * @param player The Player. - */ public PlayerSynchronizationTask(Player player) { this.player = player; - for (int index = 0; index < nsnBuilders.length; index++) { - nsnBuilders[index] = new GamePacketBuilder(); - } + this.info = player.getUpdateInfo(); + this.world = player.getWorld(); + + this.limitedPlayers = player.getLocalPlayerList(); + this.added = new ObjectOpenHashSet<>(); } @Override public void run() { - final var counts = new short[4]; + info.buffer = new GamePacketBuilder(79, PacketType.VARIABLE_SHORT); + info.largeMaskBuffer = new GamePacketBuilder(); + limitedPlayers.clear(); + prefetch(); + processLocalPlayers(true); + processLocalPlayers(false); + processOutsidePlayers(true); + processOutsidePlayers(false); + info.buffer.putBytes(info.largeMaskBuffer); + info.localIndexesCount = 0; + info.externalIndexesCount = 0; + for (var playerIndex = 1; playerIndex < 2048; playerIndex++) { + info.activityFlags[playerIndex] >>= 1; + if (info.localPlayers[playerIndex] == null) { + info.externalIndexes[info.externalIndexesCount++] = playerIndex; + } else { + info.localIndexes[info.localIndexesCount++] = playerIndex; + } + } + player.send(new PlayerSynchronizationMessage(info.buffer)); + } - final var localPlayers = player.getLocalPlayerList(); - final var distance = player.getViewingDistance(); - final var appearanceTickets = player.getAppearanceTickets(); + /** + * Prefetches a list of players closest to us when there are more than 255 players in the viewport. + * TODO: Convert the LocationMap to function at the chunk level. No reason to separate them. + */ + private void prefetch() { + limitedPlayers.clear(); - final var repoPlayer = player.getWorld().getPlayerRepository(); - final var repoRegion = player.getWorld().getRegionRepository(); + // Process which players need to be added. + final var position = player.getPosition(); + RegionRepository repository = world.getRegionRepository(); + Region current = repository.fromPosition(position); - final var current = repoRegion.fromPosition(player.getPosition()); final var regions = current.getSurrounding(); regions.add(current.getCoordinates()); - final var info = player.getPlayerUpdateInfo(); - - for (var builder : nsnBuilders) { - builder.switchToBitAccess(); - } - - // Determine which local players need to be removed. - final var toRemove = new IntOpenHashSet(); - final var position = player.getPosition(); - for (var iterator = localPlayers.iterator(); iterator.hasNext(); ) { - final var index = iterator.nextInt(); - final var remove = removable(position, distance, repoPlayer.get(index)); - if (remove) { - toRemove.add(index); - } - } - - // Determine which local players need to be added. - final var toAdd = new IntOpenHashSet(); - outer: - for (var coordinates : regions) { - var region = repoRegion.get(coordinates); + regions.stream().map(repository::get).forEach(region -> { var players = region.getEntities(EntityType.PLAYER); var iterator = players.iterator(); while (iterator.hasNext()) { - if (toAdd.size() + localPlayers.size() >= MAXIMUM_LOCAL_PLAYERS) { + if (limitedPlayers.size() >= MAXIMUM_LOCAL_PLAYERS) { player.flagExcessivePlayers(); - break outer; + break; } - final var other = iterator.next(); - final var index = other.getIndex(); - if (index != player.getIndex() && other.getPosition() - .isWithinDistance(position, distance) && !localPlayers.contains(index)) { - toAdd.add(index); + Player other = iterator.next(); + Position local = other.getPosition(); + + if (player != other && other.isActive() && local + .isWithinDistance(position, player.getViewingDistance())) { + limitedPlayers.add(other); } } - } + }); + } - for (var index = 0; index < 2048; index++) { - final var firstPass = (info.getSkip(index) & 0x1) == 0; - final var other = repoPlayer.get(index); - final var nsn = other != null && (localPlayers.contains(index) || player - .getIndex() == index) ? firstPass ? 0 : 1 : firstPass ? 2 : 3; - final var low = nsn == 2 || nsn == 3; - - if (low) { - if (toAdd.contains(index)) { - SynchronizationBlockSet blockSet = other.getBlockSet(); - if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index, - other.getAppearanceTicket())) { - blockSet = blockSet.clone(); - blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); - } - addPlayer(info, nsn, index, other.getPosition(), blockSet); + /** + * @param p the player being removed. + * @param playerIndex the index of the player being removed. If the player needs to be removed and the index + * isn't -1, we also putBits the necessary information in the buffer. + * @return whether or not the requested player needs to be removed from the local players list. + */ + private boolean remove(@NotNull final Player p, final int playerIndex) { + if (p == player) { + return false; + } + if (!limitedPlayers.contains(p)) { + if (playerIndex != -1) { + info.buffer.putBits(1, 1); + info.buffer.putBits(1, 0); + info.buffer.putBits(2, 0); + final var hash = p.getPosition().get18BitHash(); + final var previousHash = p.getOldPosition().get18BitHash(); + if (hash == previousHash) { + info.buffer.putBits(1, 0); } else { - if (other == null) { - lowrez(nsn, index, info, null); - } else { - lowrez(nsn, index, info, other.getPosition()); - } - } - } else { - SynchronizationBlockSet blockSet = other.getBlockSet(); - if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index, - other.getAppearanceTicket())) { - blockSet = blockSet.clone(); - blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); + info.buffer.putBits(1, 1); + updatePositionMultiplier(previousHash, hash); } + info.localPlayers[playerIndex] = null; + } + return true; + } + return false; + } - final var remove = toRemove.contains(index); - if (remove) { - localPlayers.remove(index); + /** + * @param p the player being added. + * @param playerIndex the index of the player being added. If the player needs to be added and the index isn't + * -1, we also putBits the necessary information in the buffer. + * @return whether or not the requested player needs to be added to the local players list. + */ + private boolean add(final Player p, final int playerIndex) { + if (limitedPlayers.contains(p)) { + if (playerIndex != -1) { + info.buffer.putBits(1, 1); + info.buffer.putBits(2, 0); + final var hash = p.getPosition().get18BitHash(); + final var previousHash = p.getOldPosition().get18BitHash(); + if (hash == previousHash) { + info.buffer.putBits(1, 0); + } else { + info.buffer.putBits(1, 1); + updatePositionMultiplier(previousHash, hash); + } + info.buffer.putBits(13, p.getPosition().getX()); + info.buffer.putBits(13, p.getPosition().getY()); + + final var blockSet = getBlockSet(p); + final var updateMasks = blockSet.size() > 0; + info.buffer.putBits(1, updateMasks ? 1 : 0); + if (updateMasks) { + appendUpdateBlock(p, blockSet, true); } - highrez(info, nsn, other, remove); + info.localPlayers[p.getIndex()] = p; + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); } - - info.setSkip(index, (byte) (info.getSkip(index) >> 1)); + return true; } + return false; + } - for (var nsn = 0; nsn < nsnBuilders.length; nsn++) { - skipFooter(info, nsn, counts[nsn]); + /** + * Appends the position changes of the requested player. As of right now, the last if-block is never reached as + * the offsets can never exceed value 1. + * + * @param lastPosition the last position multiplier transmitted to the client. + * @param currentPosition the current position multiplier. + */ + private void updatePositionMultiplier(final int lastPosition, final int currentPosition) { + final var lastY = lastPosition & 0xFF; + final var lastX = lastPosition >> 8 & 0xFF; + final var lastPlane = lastPosition >> 16; + + final var currentY = currentPosition & 0xFF; + final var currentX = currentPosition >> 8 & 0xFF; + final var currentPlane = currentPosition >> 16; + + final var yOffset = currentY - lastY; + final var xOffset = currentX - lastX; + final var planeOffset = (currentPlane - lastPlane) & 0x3; + + if (currentX == lastX && currentY == lastY) { + info.buffer.putBits(2, 1); + info.buffer.putBits(2, planeOffset); + } else if (Math.abs(xOffset) <= 1 && Math.abs(yOffset) <= 1) { + info.buffer.putBits(2, 2); + info.buffer.putBits(2, planeOffset); + info.buffer.putBits(3, + PACKED_LOCATION_UPDATE2[xOffset + 1][yOffset + 1]);// Utils.getMoveDirection(xOffset, yOffset)); + } else { + info.buffer.putBits(2, 3); + info.buffer.putBits(2, planeOffset); + info.buffer.putBits(8, xOffset & 0xFF); + info.buffer.putBits(8, yOffset & 0xFF); } - - player.send(new PlayerSynchronizationMessage(nsnBuilders, blockBuilder)); } - private void addPlayer(PlayerUpdateInfo info, int nsn, int index, Position position, - SynchronizationBlockSet blockSet) { - final var main = nsnBuilders[nsn]; - main.putBits(2, 0); - - if (info.getExternalPosition(index) != position.hashCode()) { - main.putBit(1); - lowrez(nsn, index, info, position); - } else { - main.putBit(0); + /** + * Processes the players outside of our viewport; either adds, updates or skips them if necessary to do so. + * + * @param inactivePlayers whether or not we loop the inactive or active players. + */ + private void processOutsidePlayers(final boolean inactivePlayers) { + info.buffer.switchToBitAccess(); + + var skip = 0; + for (var i = 0; i < info.externalIndexesCount; i++) { + final var playerIndex = info.externalIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[playerIndex]) == 0)) { + continue; + } + if (skip > 0) { + skip--; + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + continue; + } + final var p = world.getPlayerRepository().get(playerIndex); + if (!add(p, playerIndex)) { + final var hash = p == null ? 0 : p.getPosition().get18BitHash(); + final var previousHash = p == null ? 0 : p.getOldPosition().get18BitHash(); + if (hash != previousHash) { + info.buffer.putBits(1, 1); + updatePositionMultiplier(previousHash, hash); + } else { + info.buffer.putBits(1, 0); + skip(skip += getSkippedExternalPlayers(i, inactivePlayers)); + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + } + } } + info.buffer.switchToByteAccess(); - main.putBits(26, position.getY() << 13 | position.getX()); - flagBlockUpdate(nsn, info, blockSet); + if (skip != 0) { + throw new IllegalStateException(inactivePlayers ? "NSN2" : "NSN3"); + } } - private void highrez(PlayerUpdateInfo info, int nsn, Player other, boolean remove) { - final var main = nsnBuilders[nsn]; - final var directions = other.getDirections(); - final var nextUpdateType = other.isTeleporting() ? 3 : directions.length; - final var position = other.getPosition(); - - SynchronizationBlockSet blockSet = other.getBlockSet(); - if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(other.getAppearanceTickets(), - other.getIndex() - 1, other.getAppearanceTicket())) { - blockSet = blockSet.clone(); - blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); - } - - flagBlockUpdate(nsn, info, blockSet); - main.putBits(2, nextUpdateType); - - if (remove) { - main.putBit(1); - lowrez(nsn, other.getIndex(), info, position); - } else if (nextUpdateType == 1) { - main.putBits(3, directions[0].toInteger()); - } else if (nextUpdateType == 2) { - main.putBits(4, directions[1].toInteger()); - } else if (nextUpdateType == 3) { - final var nextUpdateDeltaX = player.getPosition().getX() - position.getX(); - final var nextUpdateDeltaY = player.getPosition().getY() - position.getY(); - final var nextUpdateDeltaPlane = player.getPosition().getHeight() - position.getHeight(); - if (Math.abs(nextUpdateDeltaX) < 16 && Math.abs(nextUpdateDeltaY) < 16) { - main.putBits(12, - ((nextUpdateDeltaX & 0x1f) << 5) + (nextUpdateDeltaY & 0x1f) + ((nextUpdateDeltaPlane & 0x3) << 10)); - } else { - main.putBits(1, 1); - main.putBits(30, - ((nextUpdateDeltaX & 0x3FFF) << 14) + (nextUpdateDeltaY & 0x3FFF) + ((nextUpdateDeltaPlane & 0x3) << 28)); + /** + * @param index the current index in the loop. + * @param inactivePlayers whether we check inactive or active players. + * @return the amount of external players we can skip. + */ + private int getSkippedExternalPlayers(final int index, final boolean inactivePlayers) { + int skip = 0; + for (var i = index + 1; i < info.externalIndexesCount; i++) { + final var externalIndex = info.externalIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[externalIndex]) == 0)) { + continue; } + final var externalPlayer = world.getPlayerRepository().get(externalIndex); + final var externalHash = externalPlayer == null ? 0 : externalPlayer.getPosition().get18BitHash(); + final var previousExternalHash = externalPlayer == null ? 0 : externalPlayer.getOldPosition() + .get18BitHash(); + if (add(externalPlayer, -1) || externalHash != previousExternalHash) { + break; + } + skip++; } + return skip; } - private void lowrez(int nsn, int index, PlayerUpdateInfo info, Position position) { - final var main = nsnBuilders[nsn]; - final var lastPosition = info.getExternalPosition(index); - if (position != null) { - final var currentPosition = position.hashCode(); - if (lastPosition != currentPosition) { - info.setExternalPositions(index, currentPosition); - - final var lastY = lastPosition & 0xFF; - final var lastX = lastPosition >> 8 & 0xFF; - final var lastPlane = lastPosition >> 16; - - final var currentY = currentPosition & 0xFF; - final var currentX = currentPosition >> 8 & 0xFF; - final var currentPlane = currentPosition >> 16; - - final var yOffset = currentY - lastY; - final var xOffset = currentX - lastX; - final var planeOffset = (currentPlane - lastPlane) & 0x3; - - if (currentX == lastX && currentY == lastY) { - main.putBits(2, 1); - main.putBits(2, planeOffset); - } else if (Math.abs(xOffset) <= 1 && Math.abs(yOffset) <= 1) { - main.putBits(2, 2); - main.putBits(5, - (PACKED_LOCATION_UPDATE1[xOffset + 1][yOffset + 1] & 0x7) + ((planeOffset & 0x3) << 3)); + /** + * Processes the players inside of our viewport; either removes, updates or skips them if necessary to do so. + * + * @param inactivePlayers whether or not we loop the inactive or active players. + */ + private void processLocalPlayers(final boolean inactivePlayers) { + info.buffer.switchToBitAccess(); + + var skip = 0; + for (var i = 0; i < info.localIndexesCount; i++) { + final var playerIndex = info.localIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[playerIndex]) != 0)) { + continue; + } + if (skip > 0) { + skip--; + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + continue; + } + final var p = info.localPlayers[playerIndex]; + + if (!remove(p, playerIndex)) { + final var directions = p.getDirections(); + final var blockSet = getBlockSet(p); + var update = blockSet.size() > 0; + if (update) { + appendUpdateBlock(p, blockSet, false); + } + + final var teleported = p.isTeleporting(); + if (teleported || directions.length > 0) { + info.buffer.putBits(1, 1); + info.buffer.putBits(1, update ? 1 : 0); + info.buffer.putBits(2, 3); + final var location = p.getPosition(); + final var lastLocation = p.getOldPosition(); + final var xOffset = location.getX() - lastLocation.getX(); + final var yOffset = location.getY() - lastLocation.getY(); + final var planeOffset = location.getHeight() - lastLocation.getHeight(); + if (Math.abs(xOffset) < 16 && Math.abs(yOffset) < 16) { + info.buffer.putBits(1, 0); + info.buffer.putBits(2, planeOffset & 0x3); + info.buffer.putBits(5, xOffset & 0x1F); + info.buffer.putBits(5, yOffset & 0x1F); + } else { + info.buffer.putBits(1, 1); + info.buffer.putBits(2, planeOffset & 0x3); + info.buffer.putBits(14, xOffset & 0x3FFF); + info.buffer.putBits(14, yOffset & 0x3FFF); + } + } else if (update) { + info.buffer.putBits(1, 1); + info.buffer.putBits(1, 1); + info.buffer.putBits(2, 0); } else { - main.putBits(2, 3); - main.putBits(18, ((xOffset & 0xFF) << 8) + (yOffset & 0xFF) + ((planeOffset & 0x3) << 16)); + info.buffer.putBits(1, 0); + skip(skip += getSkippedLocalPlayers(i, inactivePlayers)); + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); } - return; } } + info.buffer.switchToByteAccess(); - main.putBits(2, 0); + if (skip != 0) { + throw new IllegalStateException(inactivePlayers ? "NSN0" : "NSN1"); + } } - private void flagBlockUpdate(int nsn, PlayerUpdateInfo info, SynchronizationBlockSet blockSet) { - final var buffer = nsnBuilders[nsn]; - if (blockSet.size() == 0) { - buffer.putBit(0); - return; + /** + * @param index the current index in the loop. + * @param inactivePlayers whether we check inactive or active players. + * @return the amount of local players we can skip. + */ + private int getSkippedLocalPlayers(final int index, final boolean inactivePlayers) { + int skip = 0; + for (var i = index + 1; i < info.localIndexesCount; i++) { + final var localIndex = info.localIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[localIndex]) != 0)) { + continue; + } + + final var p = info.localPlayers[localIndex]; + if (remove(p, -1)) { + break; + } + + final var directions = p.getDirections(); + if (directions.length > 0) { + break; + } + + final var blockSet = getBlockSet(p); + if (blockSet.size() > 0) { + break; + } + skip++; } + return skip; + } - buffer.putBit(1); + /** + * Write the amount of players skipped into the buffer. + * + * @param count the amount of players skipped. + */ + private void skip(final int count) { + if (count == 0) { + info.buffer.putBits(2, 0); + } else if (count < 32) { + info.buffer.putBits(2, 1); + info.buffer.putBits(5, count); + } else if (count < 256) { + info.buffer.putBits(2, 2); + info.buffer.putBits(8, count); + } else { + info.buffer.putBits(2, 3); + info.buffer.putBits(11, count); + } + } + /** + * Appends the update block into the small mask buffer, and then into the large mask buffer. + * + * @param p the player whose block is being written. + * @param blockSet + * @param added whether or not the player was added to the viewport during this cycle. + */ + private void appendUpdateBlock(final Player p, SynchronizationBlockSet blockSet, final boolean added) { var flag = 0; - //accumulate flag here. + + if (blockSet.contains(HitUpdateBlock.class)) { + flag |= 0x40; + } + if (blockSet.contains(GraphicBlock.class)) { + flag |= 0x200; + } + if (blockSet.contains(TemporaryMovementTypeBlock.class)) { + flag |= 0x1000; + } + if (blockSet.contains(ForceMovementBlock.class)) { + flag |= 0x400; + } + if (blockSet.contains(ForceChatBlock.class)) { + flag |= 0x20; + } + if (blockSet.contains(TurnToPositionBlock.class)) { + flag |= 0x4; + } + if (blockSet.contains(AppearanceBlock.class)) { + flag |= 0x1; + } + if (blockSet.contains(InteractingMobBlock.class)) { + flag |= 0x2; + } + if (blockSet.contains(MovementTypeBlock.class)) { + flag |= 0x800; + } + if (blockSet.contains(ChatBlock.class)) { + flag |= 0x10; + } + if (blockSet.contains(TitleBlock.class)) { + flag |= 0x4; + } + if (blockSet.contains(AnimationBlock.class)) { + flag |= 0x80; + } if (flag >= 0xFF) { flag |= 0x8; } - blockBuilder.put(DataType.BYTE, flag); + info.largeMaskBuffer.put(DataType.BYTE, flag); if (flag >= 0xFF) { - blockBuilder.put(DataType.BYTE, flag >> 8); + info.largeMaskBuffer.put(DataType.BYTE, flag >> 8); } - // write the blocks here. - + if (blockSet.contains(HitUpdateBlock.class)) { + putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(GraphicBlock.class)) { + putGraphicBlock(blockSet.get(GraphicBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(TemporaryMovementTypeBlock.class)) { + putTemporaryMovementTypeBlock(blockSet.get(TemporaryMovementTypeBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(ForceMovementBlock.class)) { + putForceMovementBlock(blockSet.get(ForceMovementBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(ForceChatBlock.class)) { + putForceChatBlock(blockSet.get(ForceChatBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(TurnToPositionBlock.class)) { + putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(AppearanceBlock.class)) { + putAppearanceBlock(blockSet.get(AppearanceBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(InteractingMobBlock.class)) { + putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(MovementTypeBlock.class)) { + putMovementTypeBlock(blockSet.get(MovementTypeBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(ChatBlock.class)) { + putChatBlock(blockSet.get(ChatBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(TitleBlock.class)) { + putTitleBlock(blockSet.get(TitleBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(AnimationBlock.class)) { + putAnimationBlock(blockSet.get(AnimationBlock.class), info.largeMaskBuffer); + } } - private void skipBody(PlayerUpdateInfo info, int nsn, int skips) { - final var builder = nsnBuilders[nsn]; - if (skips != 0) { - builder.putBit(0); - skip(builder, skips - 1); + /** + * Puts an Appearance block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { + Appearance appearance = block.getAppearance(); + ByteBuf playerProperties = Unpooled.buffer(); + + playerProperties.writeByte(appearance.getGender().toInteger()); + playerProperties.writeByte(block.isSkulled() ? 1 : -1); + playerProperties.writeByte(block.getHeadIcon()); + + if (block.appearingAsNpc()) { + playerProperties.writeShort(0xFFFF); + playerProperties.writeShort(block.getNpcId()); + } else { + Inventory equipment = block.getEquipment(); + int[] style = appearance.getStyle(); + Item item, chest, helm; + + for (int slot = 0; slot < 4; slot++) { + if ((item = equipment.get(slot)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeByte(0); + } + } + + if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) { + playerProperties.writeShort(0x200 + chest.getId()); + } else { + playerProperties.writeShort(0x100 + style[2]); + } + + if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeByte(0); + } + + if (chest != null) { + EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId()); + if (def != null && !def.isFullBody()) { + playerProperties.writeShort(0x100 + style[3]); + } else { + playerProperties.writeByte(0); + } + } else { + playerProperties.writeShort(0x100 + style[3]); + } + + if ((item = equipment.get(EquipmentConstants.LEGS)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeShort(0x100 + style[5]); + } + + if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { + EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId()); + if (def != null && !def.isFullHat() && !def.isFullMask()) { + playerProperties.writeShort(0x100 + style[0]); + } else { + playerProperties.writeByte(0); + } + } else { + playerProperties.writeShort(0x100 + style[0]); + } + + if ((item = equipment.get(EquipmentConstants.HANDS)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeShort(0x100 + style[4]); + } + + if ((item = equipment.get(EquipmentConstants.FEET)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeShort(0x100 + style[6]); + } + + EquipmentDefinition def = null; + if (helm != null) { + def = EquipmentDefinition.lookup(helm.getId()); + } + if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { + playerProperties.writeByte(0); + } else { + playerProperties.writeShort(0x100 + style[1]); + } + } + + int[] colors = appearance.getColors(); + for (int color : colors) { + playerProperties.writeByte(color); + } + + playerProperties.writeShort(0x328); // stand + playerProperties.writeShort(0x337); // stand turn + playerProperties.writeShort(0x333); // walk + playerProperties.writeShort(0x334); // turn 180 + playerProperties.writeShort(0x335); // turn 90 cw + playerProperties.writeShort(0x336); // turn 90 ccw + playerProperties.writeShort(0x338); // run + + BufferUtil.writeString(playerProperties, block.getName()); + playerProperties.writeByte(block.getCombatLevel()); + playerProperties.writeShort(0);//block.getSkillLevel()); + playerProperties.writeByte(0); + + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, playerProperties.writableBytes()); + for (int index = 0; index < playerProperties.writableBytes(); index++) { + builder.put(DataType.BYTE, DataTransformation.ADD, playerProperties.getByte(index)); } - builder.putBit(1); } - private void skipFooter(PlayerUpdateInfo info, int nsn, int skips) { - final var builder = nsnBuilders[nsn]; - if (skips == 0) { - builder.switchToByteAccess(); - return; + /** + * Puts a chat block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) { + byte[] bytes = block.getCompressedMessage(); + + builder.put(DataType.SHORT, DataTransformation.ADD, block.getTextEffects() << 8 | block.getTextColor()); + builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType().ordinal()); + builder.put(DataType.BYTE, bytes.length); + builder.putBytes(bytes); + } + + /** + * Puts a force chat block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { + builder.putString(block.getMessage()); + } + + /** + * + */ + private static void putTitleBlock(TitleBlock block, GamePacketBuilder builder) { + var titles = block.getTitles(); + for (var positions : TitleBlock.TitlePosition.values()) { + builder.putString(titles.getOrDefault(positions, "")); } - builder.putBit(0); - skip(builder, skips - 1); - builder.switchToByteAccess(); } - private void skip(GamePacketBuilder builder, int skips) { - if (skips < 1) { - builder.putBits(2, 0); - } else if (skips < 32) { - builder.putBits(2, 1); - builder.putBits(5, skips); - } else if (skips < 256) { - builder.putBits(2, 2); - builder.putBits(8, skips); - } else { - builder.putBits(2, 3); - builder.putBits(11, skips); + /** + * Puts a force movement block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialX()); + builder.put(DataType.BYTE, DataTransformation.ADD, block.getInitialY()); + builder.put(DataType.BYTE, DataTransformation.ADD, block.getFinalX()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalY()); + builder.put(DataType.SHORT, DataTransformation.ADD, block.getTravelDurationX()); + builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTravelDurationY()); + builder.put(DataType.SHORT, block.getDirection().toInteger()); + } + + /** + * Puts a movement type block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putMovementTypeBlock(MovementTypeBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.ADD, block.getMode().getClientValue()); + } + + /** + * Puts a temporary movement type block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putTemporaryMovementTypeBlock(TemporaryMovementTypeBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.ADD, block.getMode().getClientValue()); + } + + /** + * Puts a graphic block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { + Graphic graphic = block.getGraphic(); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, graphic.getId()); + builder.put(DataType.INT, DataOrder.MIDDLE, + graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay() & 0x0000FFFF); + } + + /** + * Puts a hit update block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { + + } + + /** + * Puts an interacting mob block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { + builder.put(DataType.SHORT, DataTransformation.ADD, block.getIndex()); + } + + /** + * Puts a turn to position block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { + var mobPosition = block.getMobPosition(); + var turnPosition = block.getTurnPosition(); + + builder.put(DataType.SHORT, ((int) (Math.atan2(turnPosition.getX() - mobPosition.getX(), + turnPosition.getY() - mobPosition.getY()) * 2607.5945876176133)) & 0x3fff); + } + + /** + * Puts an Animation block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { + Animation animation = block.getAnimation(); + builder.put(DataType.SHORT, animation.getId()); + builder.put(DataType.BYTE, animation.getDelay()); + } + + private SynchronizationBlockSet getBlockSet(Player p) { + var blockSet = p.getBlockSet(); + if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(player.getAppearanceTickets(), + p.getIndex() - 1, p.getAppearanceTicket())) { + blockSet = blockSet.clone(); + blockSet.add(SynchronizationBlock.createAppearanceBlock(p)); } + return blockSet; } /** @@ -329,25 +767,6 @@ private boolean hasCachedAppearance(int[] appearanceTickets, int index, int appe appearanceTickets[index] = appearanceTicket; return false; } - return true; } - - /** - * Returns whether or not the specified {@link Player} should be removed. - * - * @param position The {@link Position} of the Player being updated. - * @param other The Player being tested. - * @return {@code true} iff the specified Player should be removed. - */ - private boolean removable(Position position, int distance, Player other) { - if (other == null || other.isTeleporting() || !other.isActive()) { - return true; - } - - Position otherPosition = other.getPosition(); - return otherPosition.getLongestDelta(position) > distance || !otherPosition - .isWithinDistance(position, distance); - } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 6490a060e..20a3ea335 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -42,12 +42,12 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask { /** * Creates the {@link PrePlayerSynchronizationTask} for the specified {@link Player}. * - * @param player The Player. + * @param player The Player. * @param encodes The Map containing Region encodes. * @param updates The {@link Map} containing {@link Region} updates. */ public PrePlayerSynchronizationTask(Player player, Map> encodes, - Map> updates) { + Map> updates) { this.player = player; this.updates = updates; this.encodes = encodes; @@ -55,7 +55,7 @@ public PrePlayerSynchronizationTask(Player player, Map= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1 - || deltaY <= Position.MAX_DISTANCE || deltaY >= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1; + return deltaX <= Position.MAX_DISTANCE || deltaX >= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1 || deltaY <= Position.MAX_DISTANCE || deltaY >= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1; } /** * Sends the updates for a {@link Region} * - * @param position The {@link Position} of the last known region. + * @param position The {@link Position} of the last known region. * @param differences The {@link Set} of {@link RegionCoordinates} of Regions that changed. - * @param full The {@link Set} of {@link RegionCoordinates} of Regions that require a full update. + * @param full The {@link Set} of {@link RegionCoordinates} of Regions that require a full update. */ private void sendUpdates(Position position, Set differences, Set full) { RegionRepository repository = player.getWorld().getRegionRepository(); int height = position.getHeight(); for (RegionCoordinates coordinates : differences) { - Set messages = updates.computeIfAbsent(coordinates, - coords -> repository.get(coords).getUpdates(height)); + Set messages = updates + .computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(height)); if (!messages.isEmpty()) { player.send(new GroupedRegionUpdateMessage(position, coordinates, messages)); @@ -127,8 +128,8 @@ private void sendUpdates(Position position, Set differences, } for (RegionCoordinates coordinates : full) { - Set messages = encodes.computeIfAbsent(coordinates, - coords -> repository.get(coords).encode(height)); + Set messages = encodes + .computeIfAbsent(coordinates, coords -> repository.get(coords).encode(height)); if (!messages.isEmpty()) { player.send(new ClearRegionMessage(position, coordinates)); diff --git a/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java b/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java index a66cc09c8..8772ce659 100644 --- a/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java @@ -1,16 +1,18 @@ package org.apollo.game.model.entity; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; import java.util.Iterator; import java.util.NoSuchElementException; -import static org.junit.Assert.*; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; /** * Tests the {@link MobRepository} class. From d00c6b446e1a5fe5021de25dcb529d6766439736 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 00:03:05 -0400 Subject: [PATCH 40/63] Fixes compiler error on chat (somehow didn't get versioned) --- .../game/message/handler/PublicChatMessageHandlerTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java index e0791c8b2..3a39a5bcf 100644 --- a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java @@ -26,7 +26,8 @@ public void terminateIfMuted() throws Exception { when(player.isMuted()).thenReturn(true); - PublicChatMessage publicChatMessage = new PublicChatMessage("Test", "Test".getBytes(), 0, 0); + PublicChatMessage publicChatMessage = new PublicChatMessage("Test", "Test".getBytes(), + 0, 0, PublicChatMessage.PublicChatType.NONE); handler.handle(player, publicChatMessage); assertTrue("PublicChatMessageHandler: player can send messages when muted", publicChatMessage.terminated()); From 028663d1f31abaa01fc550a691b71e77729c6b65 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 10:42:52 -0400 Subject: [PATCH 41/63] Teleport happens post-tick. DistanceAction no longer relies on client feedback. --- game/plugin/cmd/src/graphic-cmd.plugin.kts | 15 ++++++ game/plugin/skills/woodcutting/build.gradle | 2 + game/plugin/skills/woodcutting/src/Tree.kt | 2 +- .../woodcutting/src/Woodcutting.plugin.kts | 5 +- .../apollo/game/action/DistancedAction.java | 23 ++++++--- .../org/apollo/game/model/entity/Mob.java | 51 ++++++++++--------- .../org/apollo/game/model/entity/Player.java | 4 +- .../model/entity/path/ManhattanHeuristic.java | 2 +- .../sync/task/PlayerSynchronizationTask.java | 19 +++++-- .../sync/task/PostNpcSynchronizationTask.java | 2 +- .../task/PostPlayerSynchronizationTask.java | 2 +- .../task/PrePlayerSynchronizationTask.java | 8 ++- 12 files changed, 88 insertions(+), 47 deletions(-) create mode 100644 game/plugin/cmd/src/graphic-cmd.plugin.kts diff --git a/game/plugin/cmd/src/graphic-cmd.plugin.kts b/game/plugin/cmd/src/graphic-cmd.plugin.kts new file mode 100644 index 000000000..c8f1b87c6 --- /dev/null +++ b/game/plugin/cmd/src/graphic-cmd.plugin.kts @@ -0,0 +1,15 @@ +import org.apollo.game.model.Graphic +import org.apollo.game.model.entity.setting.PrivilegeLevel + +on_command("graphic", PrivilegeLevel.MODERATOR) + .then { player -> + arguments.firstOrNull() + ?.let(String::toIntOrNull) + ?.let(::Graphic) + ?.let { + player.playGraphic(it) + return@then + } + + player.sendMessage("Invalid syntax - ::graphic [graphic-id]") + } \ No newline at end of file diff --git a/game/plugin/skills/woodcutting/build.gradle b/game/plugin/skills/woodcutting/build.gradle index 4d96c9f57..14387cb16 100644 --- a/game/plugin/skills/woodcutting/build.gradle +++ b/game/plugin/skills/woodcutting/build.gradle @@ -5,6 +5,8 @@ dependencies { implementation project(':cache') implementation project(':net') implementation project(':util') + implementation project(':game:plugin:entity:pathing') + implementation project(':game:plugin:entity:actions') implementation project(':game:plugin:api') testImplementation project(':game:plugin-testing') } diff --git a/game/plugin/skills/woodcutting/src/Tree.kt b/game/plugin/skills/woodcutting/src/Tree.kt index 51a274a0e..2343e53bb 100644 --- a/game/plugin/skills/woodcutting/src/Tree.kt +++ b/game/plugin/skills/woodcutting/src/Tree.kt @@ -32,7 +32,7 @@ enum class Tree( private val NORMAL_OBJECTS = hashSetOf( 1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1330, 1331, 1332, 1365, 1383, 1384, 2409, 3033, 3034, 3035, 3036, 3881, 3882, - 3883, 5902, 5903, 5904, 10041 + 3883, 5902, 5903, 5904, 10041, 9734 ) private val ACHEY_OBJECTS = hashSetOf(2023) diff --git a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts index ada430864..36dba94bb 100644 --- a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts +++ b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts @@ -1,5 +1,3 @@ - -import java.util.concurrent.TimeUnit import org.apollo.game.GameConstants import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction @@ -11,6 +9,9 @@ import org.apollo.game.model.entity.obj.GameObject import org.apollo.game.plugin.api.* import org.apollo.game.plugin.skills.woodcutting.Axe import org.apollo.game.plugin.skills.woodcutting.Tree +import org.apollo.plugin.entity.pathing.walkBehind +import org.apollo.plugin.entity.pathing.walkTo +import java.util.concurrent.TimeUnit // TODO Accurate chopping rates, e.g. https://twitter.com/JagexKieren/status/713403124464107520 diff --git a/game/src/main/java/org/apollo/game/action/DistancedAction.java b/game/src/main/java/org/apollo/game/action/DistancedAction.java index dd009fe12..5cefdb747 100644 --- a/game/src/main/java/org/apollo/game/action/DistancedAction.java +++ b/game/src/main/java/org/apollo/game/action/DistancedAction.java @@ -2,6 +2,10 @@ import org.apollo.game.model.Position; import org.apollo.game.model.entity.Mob; +import org.apollo.game.model.entity.path.AStarPathfindingAlgorithm; +import org.apollo.game.model.entity.path.Heuristic; +import org.apollo.game.model.entity.path.ManhattanHeuristic; +import org.apollo.game.model.entity.path.SimplePathfindingAlgorithm; /** * An @{link Action} which fires when a distance requirement is met. @@ -58,13 +62,18 @@ public DistancedAction(int delay, boolean immediate, T mob, Position position, i public final void execute() { if (reached) { // Don't check again in case the player has moved away since it was reached executeAction(); - // TODO checking the walking queue size is a really cheap fix, and relies on the client not - // being edited... this class needs to be completely re-written. - } else if (mob.getPosition().isWithinDistance(position, distance) && mob.getWalkingQueue().size() == 0) { - reached = true; - setDelay(delay); - if (immediate) { - executeAction(); + } else if (mob.getWalkingQueue().size() == 0) { + if (mob.getPosition().isWithinDistance(position, distance)) { + reached = true; + setDelay(delay); + if (immediate) { + executeAction(); + } + } else { + var pathfinder = new AStarPathfindingAlgorithm(mob.getWorld().getCollisionManager(), new ManhattanHeuristic()); + var path = pathfinder.find(mob.getPosition(), position); + + path.forEach(mob.getWalkingQueue()::addStep); } } } diff --git a/game/src/main/java/org/apollo/game/model/entity/Mob.java b/game/src/main/java/org/apollo/game/model/entity/Mob.java index 0c9e23c1e..84fda4d5e 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Mob.java +++ b/game/src/main/java/org/apollo/game/model/entity/Mob.java @@ -117,9 +117,9 @@ public abstract class Mob extends Entity { private Direction secondDirection = Direction.NONE; /** - * Indicates whether this mob is currently teleporting or not. + * The position to teleport to. */ - private boolean teleporting; + private Position teleportPosition; /** * Creates the Mob. @@ -385,15 +385,6 @@ public final boolean isActive() { return index != -1; } - /** - * Checks if this mob is currently teleporting. - * - * @return {@code true} if so, {@code false} if not. - */ - public final boolean isTeleporting() { - return teleporting; - } - /** * Makes this mob perform the specified {@link Animation}. * @@ -500,7 +491,6 @@ public void setLastDirection(Direction lastDirection) { public final void setPosition(Position position) { if (!position.equals(this.position) && world.submit(new MobPositionUpdateEvent(this, position))) { Position old = this.position; - setOldPosition(old); RegionRepository repository = world.getRegionRepository(); Region current = repository.fromPosition(old), next = repository.fromPosition(position); @@ -512,15 +502,6 @@ public final void setPosition(Position position) { } } - /** - * Sets whether this mob is teleporting or not. - * - * @param teleporting {@code true} if the mob is teleporting, {@code false} if not. - */ - public final void setTeleporting(boolean teleporting) { - this.teleporting = teleporting; - } - /** * Forces this mob to shout a message. Only messages said by a player can be shown in the chat box. * @@ -587,15 +568,35 @@ public final void stopGraphic() { * Teleports this mob to the specified {@link Position}, setting the appropriate flags and clearing the walking * queue. * - * @param position The position. + * @param teleportPosition The position. */ - public void teleport(Position position) { - setPosition(position); - teleporting = true; + public void teleport(Position teleportPosition) { + this.teleportPosition = teleportPosition; walkingQueue.clear(); stopAction(); } + /** + * Checks if this mob is currently teleporting. + * + * @return {@code true} if so, {@code false} if not. + */ + public final boolean isTeleporting() { + return teleportPosition != null; + } + + /** + * The {@link Position} to teleport to. + * @return The teleport position. + */ + public Position getTeleportPosition() { + return teleportPosition; + } + + public void resetTeleportPosition() { + this.teleportPosition = null; + } + /** * Turns this mob to face the specified {@link Position}. * diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 7bf01c408..2027a024e 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -970,8 +970,8 @@ public void shout(String message, boolean chatOnly) { } @Override - public void teleport(Position position) { - super.teleport(position); + public void teleport(Position teleportPosition) { + super.teleport(teleportPosition); if (interfaceSet.size() > 0) { interfaceSet.close(); diff --git a/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java b/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java index 67ff7d1f8..b171c04d2 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java @@ -7,7 +7,7 @@ * * @author Major */ -final class ManhattanHeuristic extends Heuristic { +public final class ManhattanHeuristic extends Heuristic { @Override public int estimate(Position current, Position goal) { diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index a79a0b36f..d44ee2333 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -16,7 +16,6 @@ import org.apollo.game.model.entity.setting.Gender; import org.apollo.game.model.inv.Inventory; import org.apollo.game.sync.block.*; -import org.apollo.game.sync.block.TitleBlock; import org.apollo.net.codec.game.DataOrder; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; @@ -638,7 +637,10 @@ private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder bu } /** + * Puts a title block into the specified builder. * + * @param block The block. + * @param builder The builder. */ private static void putTitleBlock(TitleBlock block, GamePacketBuilder builder) { var titles = block.getTitles(); @@ -666,7 +668,7 @@ private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBu /** * Puts a movement type block into the specified builder. * - * @param block The block. + * @param block The block. * @param builder The builder. */ private static void putMovementTypeBlock(MovementTypeBlock block, GamePacketBuilder builder) { @@ -676,7 +678,7 @@ private static void putMovementTypeBlock(MovementTypeBlock block, GamePacketBuil /** * Puts a temporary movement type block into the specified builder. * - * @param block The block. + * @param block The block. * @param builder The builder. */ private static void putTemporaryMovementTypeBlock(TemporaryMovementTypeBlock block, GamePacketBuilder builder) { @@ -726,8 +728,15 @@ private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacket var mobPosition = block.getMobPosition(); var turnPosition = block.getTurnPosition(); - builder.put(DataType.SHORT, ((int) (Math.atan2(turnPosition.getX() - mobPosition.getX(), - turnPosition.getY() - mobPosition.getY()) * 2607.5945876176133)) & 0x3fff); + int srcX = (mobPosition.getX() * 512) + (1 * 256); + int srcY = (mobPosition.getY() * 512) + (1 * 256); + int dstX = (turnPosition.getX() * 512) + (1 * 256); + int dstY = (turnPosition.getY() * 512) + (1 * 256); + int deltaX = srcX - dstX; + int deltaY = srcY - dstY; + + builder.put(DataType.SHORT, deltaX != 0 || deltaY != 0 ? (int) (Math + .atan2(deltaX, deltaY) * 2607.5945876176133) & 0x3FFF : 0); } /** diff --git a/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java index 311c483a1..dd0f4ef97 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java @@ -25,7 +25,7 @@ public PostNpcSynchronizationTask(Npc npc) { @Override public void run() { - npc.setTeleporting(false); + npc.resetTeleportPosition(); npc.resetBlockSet(); } diff --git a/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java index baa4ecb35..c80239af4 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java @@ -25,7 +25,7 @@ public PostPlayerSynchronizationTask(Player player) { @Override public void run() { - player.setTeleporting(false); + player.resetTeleportPosition(); player.setRegionChanged(false); player.resetBlockSet(); diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 20a3ea335..029c41691 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -55,12 +55,16 @@ public PrePlayerSynchronizationTask(Player player, Map Date: Sun, 12 Apr 2020 11:20:16 -0400 Subject: [PATCH 42/63] Added tutorial island wood and oak tree identifiers. Directions have client rotations now. --- game/plugin/skills/woodcutting/src/Tree.kt | 4 +-- .../woodcutting/src/Woodcutting.plugin.kts | 2 -- .../java/org/apollo/game/model/Direction.java | 34 +++++++++++++------ .../sync/task/PlayerSynchronizationTask.java | 14 ++------ 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/game/plugin/skills/woodcutting/src/Tree.kt b/game/plugin/skills/woodcutting/src/Tree.kt index 2343e53bb..279a965dd 100644 --- a/game/plugin/skills/woodcutting/src/Tree.kt +++ b/game/plugin/skills/woodcutting/src/Tree.kt @@ -32,11 +32,11 @@ enum class Tree( private val NORMAL_OBJECTS = hashSetOf( 1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1330, 1331, 1332, 1365, 1383, 1384, 2409, 3033, 3034, 3035, 3036, 3881, 3882, - 3883, 5902, 5903, 5904, 10041, 9734 + 3883, 5902, 5903, 5904, 10041, 9730 ) private val ACHEY_OBJECTS = hashSetOf(2023) -private val OAK_OBJECTS = hashSetOf(1281, 3037) +private val OAK_OBJECTS = hashSetOf(1281, 3037, 9734) private val WILLOW_OBJECTS = hashSetOf(5551, 5552, 5553) private val TEAK_OBJECTS = hashSetOf(9036) private val MAPLE_OBJECTS = hashSetOf(1307, 4674) diff --git a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts index 36dba94bb..58f051f8e 100644 --- a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts +++ b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts @@ -9,8 +9,6 @@ import org.apollo.game.model.entity.obj.GameObject import org.apollo.game.plugin.api.* import org.apollo.game.plugin.skills.woodcutting.Axe import org.apollo.game.plugin.skills.woodcutting.Tree -import org.apollo.plugin.entity.pathing.walkBehind -import org.apollo.plugin.entity.pathing.walkTo import java.util.concurrent.TimeUnit // TODO Accurate chopping rates, e.g. https://twitter.com/JagexKieren/status/713403124464107520 diff --git a/game/src/main/java/org/apollo/game/model/Direction.java b/game/src/main/java/org/apollo/game/model/Direction.java index d1a13ffbd..de386244f 100644 --- a/game/src/main/java/org/apollo/game/model/Direction.java +++ b/game/src/main/java/org/apollo/game/model/Direction.java @@ -10,47 +10,47 @@ public enum Direction { /** * No movement. */ - NONE(-1), + NONE(-1, -1), /** * North west movement. */ - NORTH_WEST(0), + NORTH_WEST(0, 768), /** * North movement. */ - NORTH(1), + NORTH(1, 1024), /** * North east movement. */ - NORTH_EAST(2), + NORTH_EAST(2, 1280), /** * West movement. */ - WEST(3), + WEST(3, 512), /** * East movement. */ - EAST(4), + EAST(4, 1536), /** * South west movement. */ - SOUTH_WEST(5), + SOUTH_WEST(5, 256), /** * South movement. */ - SOUTH(6), + SOUTH(6, 0), /** * South east movement. */ - SOUTH_EAST(7); + SOUTH_EAST(7, 1792); /** * An empty direction array. @@ -151,13 +151,19 @@ public static Direction[] diagonalComponents(Direction direction) { */ private final int intValue; + /** + * The direction as a JAG-Rotation. + */ + private final int clientValue; + /** * Creates the direction. * * @param intValue The direction as an integer. */ - Direction(int intValue) { + Direction(int intValue, int clientValue) { this.intValue = intValue; + this.clientValue = clientValue; } /** @@ -246,6 +252,14 @@ public int toInteger() { return intValue; } + /** + * The client value for the given direction. + * @return The client value. + */ + public int getClientValue() { + return clientValue; + } + /** * Gets the direction as an integer as used orientation in the client maps (WNES as opposed to NESW). * diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index d44ee2333..ab77786a3 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -725,18 +725,8 @@ private static void putInteractingMobBlock(InteractingMobBlock block, GamePacket * @param builder The builder. */ private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - var mobPosition = block.getMobPosition(); - var turnPosition = block.getTurnPosition(); - - int srcX = (mobPosition.getX() * 512) + (1 * 256); - int srcY = (mobPosition.getY() * 512) + (1 * 256); - int dstX = (turnPosition.getX() * 512) + (1 * 256); - int dstY = (turnPosition.getY() * 512) + (1 * 256); - int deltaX = srcX - dstX; - int deltaY = srcY - dstY; - - builder.put(DataType.SHORT, deltaX != 0 || deltaY != 0 ? (int) (Math - .atan2(deltaX, deltaY) * 2607.5945876176133) & 0x3FFF : 0); + var direction = Direction.between(block.getMobPosition(), block.getTurnPosition()); + builder.put(DataType.SHORT, direction.getClientValue()); } /** From 15833bfa3478477ea8635a54c0d674e5c43bd84d Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 11:36:23 -0400 Subject: [PATCH 43/63] Fixes title mask flag. --- .../apollo/game/sync/task/PlayerSynchronizationTask.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index ab77786a3..4f029a942 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -439,7 +439,7 @@ private void appendUpdateBlock(final Player p, SynchronizationBlockSet blockSet, flag |= 0x10; } if (blockSet.contains(TitleBlock.class)) { - flag |= 0x4; + flag |= 0x100; } if (blockSet.contains(AnimationBlock.class)) { flag |= 0x80; @@ -725,8 +725,8 @@ private static void putInteractingMobBlock(InteractingMobBlock block, GamePacket * @param builder The builder. */ private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - var direction = Direction.between(block.getMobPosition(), block.getTurnPosition()); - builder.put(DataType.SHORT, direction.getClientValue()); + var direction = Direction.between(block.getTurnPosition(), block.getMobPosition()); + builder.put(DataType.SHORT, DataOrder.LITTLE, direction.getClientValue()); } /** From bbc0e13dc47a5bc0da7d0d8bcd4aae29b55638f7 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 12:54:43 -0400 Subject: [PATCH 44/63] Keyboard event added. --- .../apollo/game/action/DistancedAction.java | 7 +- .../impl/decode/EventKeyboardMessage.java | 77 +++++++++++++++++++ .../model/entity/path/ChebyshevHeuristic.java | 2 +- .../apollo/game/release/r181/Release181.java | 3 +- .../r181/decoders/EventKeyboardDecoder.java | 29 +++++++ .../sync/task/PlayerSynchronizationTask.java | 2 +- .../net/codec/game/GamePacketReader.java | 2 +- 7 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/message/impl/decode/EventKeyboardMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/EventKeyboardDecoder.java diff --git a/game/src/main/java/org/apollo/game/action/DistancedAction.java b/game/src/main/java/org/apollo/game/action/DistancedAction.java index 5cefdb747..4d3622fc5 100644 --- a/game/src/main/java/org/apollo/game/action/DistancedAction.java +++ b/game/src/main/java/org/apollo/game/action/DistancedAction.java @@ -2,10 +2,7 @@ import org.apollo.game.model.Position; import org.apollo.game.model.entity.Mob; -import org.apollo.game.model.entity.path.AStarPathfindingAlgorithm; -import org.apollo.game.model.entity.path.Heuristic; -import org.apollo.game.model.entity.path.ManhattanHeuristic; -import org.apollo.game.model.entity.path.SimplePathfindingAlgorithm; +import org.apollo.game.model.entity.path.*; /** * An @{link Action} which fires when a distance requirement is met. @@ -70,7 +67,7 @@ public final void execute() { executeAction(); } } else { - var pathfinder = new AStarPathfindingAlgorithm(mob.getWorld().getCollisionManager(), new ManhattanHeuristic()); + var pathfinder = new AStarPathfindingAlgorithm(mob.getWorld().getCollisionManager(), new ChebyshevHeuristic()); var path = pathfinder.find(mob.getPosition(), position); path.forEach(mob.getWalkingQueue()::addStep); diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/EventKeyboardMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/EventKeyboardMessage.java new file mode 100644 index 000000000..dd759d91e --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/EventKeyboardMessage.java @@ -0,0 +1,77 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +/** + * The type Event keyboard message. + * + * @author Khaled Abdeljaber + */ +public class EventKeyboardMessage extends Message { + + /** + * The event that occurs on a keyboard press. + */ + public static class EventKeyboard { + /** + * The key pressed. + */ + private int key; + + /** + * The duration in milliseconds. + */ + private Duration duration; + + /** + * Instantiates a new Event keyboard. + * @param key the key + * @param duration the duration + */ + public EventKeyboard(int key, Duration duration) { + this.key = key; + this.duration = duration; + } + + /** + * Gets key. + * + * @return the key + */ + public int getKey() { + return key; + } + + /** + * Gets duration. + * + * @return the duration + */ + public Duration getDuration() { + return duration; + } + } + + private final EventKeyboard[] events; + + /** + * Instantiates a new Event keyboard message. + * + * @param events the events + */ + public EventKeyboardMessage(EventKeyboard... events) { + this.events = events; + } + + /** + * Gets events. + * + * @return the events + */ + public EventKeyboard[] getEvents() { + return events; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java b/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java index 00e8065f9..f9660c0c0 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java @@ -7,7 +7,7 @@ * * @author Major */ -final class ChebyshevHeuristic extends Heuristic { +public final class ChebyshevHeuristic extends Heuristic { @Override public int estimate(Position current, Position goal) { diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 55ee57b7d..f631d7e00 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -194,7 +194,7 @@ private void init() { register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); - //register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); + register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); @@ -268,6 +268,7 @@ private void init() { * Resume Inputs */ register(17, new EnteredAmountMessageDecoder()); + register(67, new EventKeyboardDecoder()); /** * Player diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/EventKeyboardDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/EventKeyboardDecoder.java new file mode 100644 index 000000000..d377274b9 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/EventKeyboardDecoder.java @@ -0,0 +1,29 @@ +package org.apollo.game.release.r181.decoders; + +import org.apollo.game.message.impl.decode.EventKeyboardMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +import java.time.Duration; + +/** + * @author Khaled Abdeljaber + */ +public class EventKeyboardDecoder extends MessageDecoder { + @Override + public EventKeyboardMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + final var events = new EventKeyboardMessage.EventKeyboard[reader.getLength() / 4]; + for (int index = 0; index < events.length; index++) { + var keyPressed = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); + var duration = reader.getUnsigned(DataType.TRI_BYTE); + events[index] = new EventKeyboardMessage.EventKeyboard((int) keyPressed, Duration.ofMillis(duration)); + } + + return new EventKeyboardMessage(events); + } +} diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index 4f029a942..b39d92268 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -725,7 +725,7 @@ private static void putInteractingMobBlock(InteractingMobBlock block, GamePacket * @param builder The builder. */ private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - var direction = Direction.between(block.getTurnPosition(), block.getMobPosition()); + var direction = Direction.between(block.getMobPosition(), block.getTurnPosition()); builder.put(DataType.SHORT, DataOrder.LITTLE, direction.getClientValue()); } diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java index 0f8bae99b..4dab2488b 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java @@ -237,7 +237,7 @@ public void getBytesReverse(DataTransformation transformation, byte[] bytes) { */ public int getLength() { checkByteAccess(); - return buffer.writableBytes(); + return buffer.readableBytes(); } /** From ac00bc286f385ea48eb49154c4d885844b6858f4 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 13:46:57 -0400 Subject: [PATCH 45/63] ChatFilterSettingsMessage added. PublicChatDecoder updated. Public chat is now working. --- .../message/impl/PrivacyOptionMessage.java | 34 +---------- .../game/message/impl/PublicChatMessage.java | 13 +++- .../encode/ChatFilterSettingsMessage.java | 60 +++++++++++++++++++ .../org/apollo/game/model/entity/Player.java | 6 +- .../apollo/game/release/r181/Release181.java | 14 ++--- .../decoders/social/PublicChatDecoder.java | 36 +++++++++++ .../social/ChatFilterSettingsEncoder.java | 23 +++++++ .../sync/task/PlayerSynchronizationTask.java | 3 - 8 files changed, 141 insertions(+), 48 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ChatFilterSettingsEncoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java index 0a606664c..b6f75e365 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.encode.ChatFilterSettingsMessage; import org.apollo.game.model.entity.setting.PrivacyState; import org.apollo.net.message.Message; @@ -10,17 +11,7 @@ * @author Kyle Stevenson * @author Major */ -public final class PrivacyOptionMessage extends Message { - - /** - * The privacy state of the player's chat. - */ - private final PrivacyState chatPrivacy; - - /** - * The privacy state of the player's friend chat. - */ - private final PrivacyState friendPrivacy; +public final class PrivacyOptionMessage extends ChatFilterSettingsMessage { /** * The privacy state of the player's trade chat. @@ -35,29 +26,10 @@ public final class PrivacyOptionMessage extends Message { * @param tradePrivacy The privacy state of the player's trade chat. */ public PrivacyOptionMessage(int chatPrivacy, int friendPrivacy, int tradePrivacy) { - this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true); - this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false); + super(chatPrivacy, friendPrivacy); this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false); } - /** - * Gets the chat {@link PrivacyState}. - * - * @return The privacy state. - */ - public PrivacyState getChatPrivacy() { - return chatPrivacy; - } - - /** - * Gets the friend {@link PrivacyState}. - * - * @return The privacy state. - */ - public PrivacyState getFriendPrivacy() { - return friendPrivacy; - } - /** * Gets the trade {@link PrivacyState}. * diff --git a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java index 8ebefaad3..8fe68a94a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java @@ -10,7 +10,18 @@ public final class PublicChatMessage extends ChatMessage { public enum PublicChatType { - NONE, QUICKCHAT, CLANCHAT + NONE, QUICKCHAT, CLANCHAT; + + static final PublicChatType[] VALUES = values(); + + public static PublicChatType of(int ordinal) { + for (var value : VALUES) { + if (value.ordinal() == ordinal) { + return value; + } + } + return NONE; + } } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java new file mode 100644 index 000000000..3825adb4d --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java @@ -0,0 +1,60 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.setting.PrivacyState; +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class ChatFilterSettingsMessage extends Message { + + /** + * The privacy state of the player's chat. + */ + private final PrivacyState chatPrivacy; + + /** + * The privacy state of the player's friend chat. + */ + private final PrivacyState friendPrivacy; + + /** + * Creates a privacy option message. + * + * @param chatPrivacy The privacy state of the player's chat. + * @param friendPrivacy The privacy state of the player's friend chat. + */ + public ChatFilterSettingsMessage(int chatPrivacy, int friendPrivacy) { + this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true); + this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false); + } + + /** + * Creates a privacy option message. + * + * @param chatPrivacy The privacy state of the player's chat. + * @param friendPrivacy The privacy state of the player's friend chat. + */ + public ChatFilterSettingsMessage(PrivacyState chatPrivacy, PrivacyState friendPrivacy) { + this.chatPrivacy = chatPrivacy; + this.friendPrivacy = chatPrivacy; + } + + /** + * Gets the chat {@link PrivacyState}. + * + * @return The privacy state. + */ + public PrivacyState getChatPrivacy() { + return chatPrivacy; + } + + /** + * Gets the friend {@link PrivacyState}. + * + * @return The privacy state. + */ + public PrivacyState getFriendPrivacy() { + return friendPrivacy; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 2027a024e..03cef267d 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -5,10 +5,7 @@ import org.apollo.game.message.impl.IgnoreListMessage; import org.apollo.game.message.impl.SendFriendMessage; import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.encode.ConfigMessage; -import org.apollo.game.message.impl.encode.LogoutMessage; -import org.apollo.game.message.impl.encode.RebuildNormalMessage; -import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; +import org.apollo.game.message.impl.encode.*; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; import org.apollo.game.model.World; @@ -754,6 +751,7 @@ public void sendInitialMessages(DisplayMode mode) { updateAppearance(); send(new ConfigMessage(1737, 1 << 31)); + send(new ChatFilterSettingsMessage(chatPrivacy, friendPrivacy)); inventory.forceRefresh(); equipment.forceRefresh(); diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index f631d7e00..c17a78869 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -4,6 +4,7 @@ import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; +import org.apollo.game.release.r181.decoders.social.PublicChatDecoder; import org.apollo.game.release.r181.encoders.game.LogoutEncoder; import org.apollo.game.release.r181.encoders.player.PlayerSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.region.MobResetAnimsEncoder; @@ -194,7 +195,7 @@ private void init() { register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); - register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); + //register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); register(ConfigMessage.class, new ConfigMessageEncoder()); @@ -205,23 +206,19 @@ private void init() { */ /** - * Friends List + * Social */ register(88, new AddFriendMessageDecoder()); register(54, new RemoveFriendMessageDecoder()); - /** - * Ignores List - */ register(90, new AddIgnoreMessageDecoder()); register(28, new RemoveIgnoreMessageDecoder()); - /** - * Private Message - */ register(25, new PrivateChatMessageDecoder()); register(15, new PrivacyOptionMessageDecoder()); + register(97, new PublicChatDecoder()); + /** * Movement */ @@ -257,7 +254,6 @@ private void init() { register(58, new FifthOpHeldMessageDecoder()); register(24, new SixthOpHeldMessageDecoder()); - register(5, new FirstOpItemMessageDecoder()); register(74, new SecondOpItemMessageDecoder()); register(6, new ThirdOpItemMessageDecoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java new file mode 100644 index 000000000..8e2c8b4e2 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java @@ -0,0 +1,36 @@ +package org.apollo.game.release.r181.decoders.social; + +import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; +import org.apollo.util.TextUtil; + +/** + * @author Khaled Abdeljaber + */ +public class PublicChatDecoder extends MessageDecoder { + @Override + public PublicChatMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + final var type = PublicChatMessage.PublicChatType.of((int) reader.getUnsigned(DataType.BYTE)); + final var color = (int) reader.getUnsigned(DataType.BYTE); + final var effects = (int) reader.getUnsigned(DataType.BYTE); + + final var length = packet.getLength() - 3; + + final var originalCompressed = new byte[length]; + reader.getBytes(originalCompressed); + + String uncompressed = TextUtil.decompress(originalCompressed, length); + uncompressed = TextUtil.filterInvalidCharacters(uncompressed); + uncompressed = TextUtil.capitalize(uncompressed); + + final var recompressed = new byte[length]; + TextUtil.compress(uncompressed, recompressed); // in case invalid data gets sent, this effectively verifies it + + return new PublicChatMessage(uncompressed, recompressed, color, effects, type); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ChatFilterSettingsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ChatFilterSettingsEncoder.java new file mode 100644 index 000000000..29fb40319 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ChatFilterSettingsEncoder.java @@ -0,0 +1,23 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.encode.ChatFilterSettingsMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class ChatFilterSettingsEncoder extends MessageEncoder { + + @Override + public GamePacket encode(ChatFilterSettingsMessage message) { + var builder = new GamePacketBuilder(80, PacketType.FIXED); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getFriendPrivacy().toInteger(true)); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getChatPrivacy().toInteger(true)); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index b39d92268..f98cfd57e 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -42,15 +42,12 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { private final World world; private final ObjectSet limitedPlayers; - private ObjectOpenHashSet added; - public PlayerSynchronizationTask(Player player) { this.player = player; this.info = player.getUpdateInfo(); this.world = player.getWorld(); this.limitedPlayers = player.getLocalPlayerList(); - this.added = new ObjectOpenHashSet<>(); } @Override From c858ac465339829fb5dc6e2cfeaca7ef3c79387c Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 20:26:19 -0400 Subject: [PATCH 46/63] Removed item option, we should have one consistent message for that. --- game/data/messages.xml | 13 +++------- .../testing/junit/api/interactions/player.kt | 6 ++--- .../consumables/src/consumables.plugin.kts | 4 +-- .../skills/herblore/src/Herblore.plugin.kts | 4 +-- .../skills/prayer/src/Prayer.plugin.kts | 4 +-- .../runecrafting/src/Runecrafting.plugin.kts | 5 ++-- .../message/handler/EquipItemHandler.java | 13 +++++----- .../impl/decode/InventoryItemMessage.java | 10 ++++---- .../impl/decode/ItemActionMessage.java | 22 ++++++++-------- .../impl/decode/ItemOptionMessage.java | 25 ------------------- 10 files changed, 38 insertions(+), 68 deletions(-) delete mode 100644 game/src/main/java/org/apollo/game/message/impl/decode/ItemOptionMessage.java diff --git a/game/data/messages.xml b/game/data/messages.xml index 501ca7b85..947fcd004 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -43,14 +43,6 @@ org.apollo.game.message.handler.EnteredAmountMessageHandler
- - org.apollo.game.message.impl.decode.ItemActionMessage - - org.apollo.game.message.handler.ItemVerificationHandler - org.apollo.game.message.handler.RemoveEquippedItemHandler - org.apollo.game.message.handler.BankMessageHandler - - org.apollo.game.message.impl.decode.ItemOnItemMessage @@ -65,10 +57,13 @@ - org.apollo.game.message.impl.decode.ItemOptionMessage + org.apollo.game.message.impl.decode.ItemActionMessage org.apollo.game.message.handler.ItemVerificationHandler org.apollo.game.message.handler.EquipItemHandler + org.apollo.game.message.handler.ItemVerificationHandler + org.apollo.game.message.handler.RemoveEquippedItemHandler + org.apollo.game.message.handler.BankMessageHandler diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt index c3ae2d845..4e1b78f80 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt @@ -1,6 +1,6 @@ package org.apollo.game.plugin.testing.junit.api.interactions -import org.apollo.game.message.impl.decode.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.message.impl.decode.NpcActionMessage import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.message.impl.decode.PlayerActionMessage @@ -12,11 +12,11 @@ import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.obj.GameObject /** - * Send an [ItemOptionMessage] for the given [id], [option], [slot], and [interfaceId], simulating a + * Send an [ItemActionMessage] for the given [id], [option], [slot], and [interfaceId], simulating a * player interacting with an item. */ fun Player.interactWithItem(id: Int, option: Int, slot: Int? = null, interfaceId: Int? = null, componentId: Int? = null) { - send(ItemOptionMessage(option, interfaceId ?: -1, componentId + send(ItemActionMessage(option, interfaceId ?: -1, componentId ?: -1, id, slot ?: inventory.slotOf(id))) } diff --git a/game/plugin/consumables/src/consumables.plugin.kts b/game/plugin/consumables/src/consumables.plugin.kts index 435d4954e..fda1d0846 100644 --- a/game/plugin/consumables/src/consumables.plugin.kts +++ b/game/plugin/consumables/src/consumables.plugin.kts @@ -1,12 +1,12 @@ import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncAction -import org.apollo.game.message.impl.decode.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.model.Animation import org.apollo.game.model.entity.Player import org.apollo.net.message.Message import org.apollo.plugin.consumables.* -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == 1 && isConsumable(id) } .then { ConsumeAction.start(this, it, lookupConsumable(id), slot) diff --git a/game/plugin/skills/herblore/src/Herblore.plugin.kts b/game/plugin/skills/herblore/src/Herblore.plugin.kts index 01f266783..6bf648449 100644 --- a/game/plugin/skills/herblore/src/Herblore.plugin.kts +++ b/game/plugin/skills/herblore/src/Herblore.plugin.kts @@ -6,9 +6,9 @@ import Herb.Companion.isUnidentified import Ingredient.Companion.isIngredient import UnfinishedPotion.Companion.isUnfinished import org.apollo.game.message.impl.decode.ItemOnItemMessage -import org.apollo.game.message.impl.decode.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == IdentifyHerbAction.IDENTIFY_OPTION && id.isUnidentified() } .then { player -> val unidentified = Herb[id]!! diff --git a/game/plugin/skills/prayer/src/Prayer.plugin.kts b/game/plugin/skills/prayer/src/Prayer.plugin.kts index 0d3e55675..1fcfdef0e 100644 --- a/game/plugin/skills/prayer/src/Prayer.plugin.kts +++ b/game/plugin/skills/prayer/src/Prayer.plugin.kts @@ -1,7 +1,7 @@ import Bone.Companion.isBone import Prayer.Companion.isPrayerButton import org.apollo.game.message.impl.decode.IfActionMessage -import org.apollo.game.message.impl.decode.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.model.event.impl.LogoutEvent import org.apollo.game.plugin.api.prayer @@ -27,7 +27,7 @@ on { IfActionMessage::class } terminate() } -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == BuryBoneAction.BURY_OPTION && id.isBone() } .then { player -> val bone = Bone[id]!! diff --git a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts index aca103496..12e90cbce 100644 --- a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts +++ b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts @@ -1,8 +1,7 @@ package org.apollo.game.plugin.skill.runecrafting -import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.message.impl.decode.ItemOnObjectMessage -import org.apollo.game.message.impl.decode.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.message.impl.encode.ConfigMessage import org.apollo.game.model.entity.EquipmentConstants @@ -59,7 +58,7 @@ on { ItemOnObjectMessage::class } terminate() } -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == 4 } .then { val talisman = Talisman.findById(id) ?: return@then diff --git a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java index 17ce9f456..f4cfc3248 100644 --- a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java @@ -1,7 +1,8 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.decode.ItemOptionMessage; +import org.apollo.game.message.impl.decode.InventoryItemMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -21,7 +22,7 @@ * @author Graham * @author Ryley */ -public final class EquipItemHandler extends MessageHandler { +public final class EquipItemHandler extends MessageHandler { /** * The option used when equipping an item. @@ -31,14 +32,14 @@ public final class EquipItemHandler extends MessageHandler { /** * Creates the EquipItemHandler. * - * @param world The {@link World} the {@link ItemOptionMessage} occurred in. + * @param world The {@link World} the {@link ItemActionMessage} occurred in. */ public EquipItemHandler(World world) { super(world); } @Override - public void handle(Player player, ItemOptionMessage message) { + public void handle(Player player, InventoryItemMessage message) { if (message.getInterfaceId() != INVENTORY_ID || message.getOption() != EQUIP_OPTION) { return; } @@ -106,9 +107,9 @@ public void handle(Player player, ItemOptionMessage message) { * @param weapon The weapon the {@link Player} currently has equipped. * @param shield The shield the {@link Player} currently has equipped. * @param player The {@link Player} equipping the item. - * @param message The {@link ItemOptionMessage} sent by the client. + * @param message The {@link ItemActionMessage} sent by the client. */ - private void handleTwoHanded(Inventory inventory, Inventory equipment, int inventorySlot, Item weapon, Item shield, Player player, ItemOptionMessage message) { + private void handleTwoHanded(Inventory inventory, Inventory equipment, int inventorySlot, Item weapon, Item shield, Player player, InventoryItemMessage message) { int slotsRequired = weapon != null && shield != null ? 1 : 0; if (inventory.freeSlots() < slotsRequired) { diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java index ae3603037..004b946b0 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java @@ -15,27 +15,27 @@ public abstract class InventoryItemMessage extends Message { /** * The item id. */ - private final int id; + protected final int id; /** * The interface id. */ - private final int interfaceId; + protected final int interfaceId; /** * The component id. */ - private final int componentId; + protected final int componentId; /** * The option number (1-5 if present). */ - private final OptionalInt option; + protected final OptionalInt option; /** * The item's slot. */ - private final int slot; + protected final int slot; /** * Creates the InventoryItemMessage. diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java index cf34daabd..bcaed00ab 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java @@ -1,30 +1,30 @@ package org.apollo.game.message.impl.decode; -import org.apollo.net.message.Message; - import java.util.OptionalInt; /** - * A {@link Message} sent by the client that represents some sort of action on an item. Note that the actual message - * sent by the client is one of the five item action messages, but this is the message that should be intercepted (and - * the option verified). + * An {@link InventoryItemMessage} sent by the client when an item's option is clicked (e.g. equip, eat, drink, etc). + * Note that the actual message sent by the client is one of the five item option messages, but this is the message that + * should be intercepted (and the option verified). * * @author Khaled Abdeljaber */ public final class ItemActionMessage extends InventoryItemMessage { /** - * Creates the ItemActionMessage. + * Creates the ItemOptionMessage. * - * @param option The option number. + * @param option The option number. * @param interfaceId The interface id. - * @param componentId The component id. - * @param id The id. - * @param slot The slot. + * @param id The id. + * @param slot The slot. */ public ItemActionMessage(int option, int interfaceId, int componentId, int id, int slot) { super(OptionalInt.of(option), interfaceId, componentId, id, slot); } - + @Override + public String toString() { + return "ItemActionMessage{" + "id=" + id + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", option=" + option + ", slot=" + slot + '}'; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/ItemOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOptionMessage.java deleted file mode 100644 index e075b84e4..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/decode/ItemOptionMessage.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.message.impl.decode; - -import java.util.OptionalInt; - -/** - * An {@link InventoryItemMessage} sent by the client when an item's option is clicked (e.g. equip, eat, drink, etc). - * Note that the actual message sent by the client is one of the five item option messages, but this is the message that - * should be intercepted (and the option verified). - * - * @author Khaled Abdeljaber - */ -public final class ItemOptionMessage extends InventoryItemMessage { - - /** - * Creates the ItemOptionMessage. - * - * @param option The option number. - * @param interfaceId The interface id. - * @param id The id. - * @param slot The slot. - */ - public ItemOptionMessage(int option, int interfaceId, int componentId, int id, int slot) { - super(OptionalInt.of(option), interfaceId, componentId, id, slot); - } -} \ No newline at end of file From 5037fff58a68a1fdbc12cd51fc8037dab65d7567 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 20:43:13 -0400 Subject: [PATCH 47/63] Fixes issue with inventory and component id being swapped. Fixes issue where we send amount when item is being removed in UpdateContainerPartialMessageEncoder --- .../message/impl/encode/UpdateInventoryPartialMessage.java | 2 +- .../ui/container/UpdateContainerPartialMessageEncoder.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java index 260ec9566..741782246 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java @@ -36,7 +36,7 @@ public final class UpdateInventoryPartialMessage extends Message { * @param interfaceId The interface id. * @param items The slotted items. */ - public UpdateInventoryPartialMessage(int interfaceId, int containerId, int component, SlottedItem... items) { + public UpdateInventoryPartialMessage(int interfaceId, int component, int containerId, SlottedItem... items) { this.interfaceId = interfaceId; this.component = component; this.containerId = containerId; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java index b555323f9..4c5536fc9 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java @@ -33,6 +33,10 @@ public GamePacket encode(UpdateInventoryPartialMessage message) { builder.put(DataType.SHORT, id + 1); + if (id == -1) { + continue; + } + if (amount > 254) { builder.put(DataType.BYTE, 255); builder.put(DataType.INT, amount); From 88928e98a276692a2217847d40cf98efa7c2ceb4 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sun, 12 Apr 2020 21:53:26 -0400 Subject: [PATCH 48/63] Removed some debug statements from GPI. Moved equipment handler to an IfActionMessage --- game/data/messages.xml | 2 +- .../message/handler/RemoveEquippedItemHandler.java | 11 ++++++----- .../game/message/impl/decode/IfActionMessage.java | 14 +++++++------- .../game/sync/ParallelClientSynchronizer.java | 2 -- .../apollo/game/plugin/kotlin/message/IfAction.kt | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/game/data/messages.xml b/game/data/messages.xml index 947fcd004..1198cb5d5 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -4,6 +4,7 @@ org.apollo.game.message.handler.DialogueButtonHandler org.apollo.game.message.handler.BankButtonMessageHandler + org.apollo.game.message.handler.RemoveEquippedItemHandler @@ -62,7 +63,6 @@ org.apollo.game.message.handler.ItemVerificationHandler org.apollo.game.message.handler.EquipItemHandler org.apollo.game.message.handler.ItemVerificationHandler - org.apollo.game.message.handler.RemoveEquippedItemHandler org.apollo.game.message.handler.BankMessageHandler diff --git a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java index e6260bdbd..49f62426a 100644 --- a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.decode.ItemActionMessage; +import org.apollo.game.message.impl.decode.IfActionMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -13,20 +13,21 @@ * @author Graham * @author Major */ -public final class RemoveEquippedItemHandler extends MessageHandler { +public final class RemoveEquippedItemHandler extends MessageHandler { /** * Creates the RemoveEquippedItemHandler. * - * @param world The {@link World} the {@link ItemActionMessage} occurred in. + * @param world The {@link World} the {@link IfActionMessage} occurred in. */ public RemoveEquippedItemHandler(World world) { super(world); } @Override - public void handle(Player player, ItemActionMessage message) { - if (message.getOption() == 1 && message.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { + public void handle(Player player, IfActionMessage message) { + if (message.getOption() == 1 + && message.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { Inventory inventory = player.getInventory(); Inventory equipment = player.getEquipment(); diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java index 316e4cb76..a07e3889d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java @@ -12,7 +12,7 @@ public class IfActionMessage extends Message { /** * The option that was pressed. */ - private final int action; + private final int option; /** * The interface id. @@ -37,14 +37,14 @@ public class IfActionMessage extends Message { /** * Instantiates a new If action message. * - * @param action the action + * @param option the action * @param interfaceId the interface id * @param componentId the component id * @param slot the slot * @param itemId the item id */ - public IfActionMessage(int action, int interfaceId, int componentId, int slot, int itemId) { - this.action = action; + public IfActionMessage(int option, int interfaceId, int componentId, int slot, int itemId) { + this.option = option; this.interfaceId = interfaceId; this.componentId = componentId; this.slot = slot; @@ -56,8 +56,8 @@ public IfActionMessage(int action, int interfaceId, int componentId, int slot, i * * @return the action */ - public int getAction() { - return action; + public int getOption() { + return option; } /** @@ -103,6 +103,6 @@ public int getId() { @Override public String toString() { - return "IfActionMessage{" + "action=" + action + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", slot=" + slot + ", itemId=" + itemId + '}'; + return "IfActionMessage{" + "action=" + option + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", slot=" + slot + ", itemId=" + itemId + '}'; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java index 4395c3c0b..edc966de6 100644 --- a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java @@ -69,14 +69,12 @@ public void synchronize(MobRepository players, MobRepository npcs) } phaser.arriveAndAwaitAdvance(); - long duration = System.currentTimeMillis(); phaser.bulkRegister(playerCount); for (Player player : players) { SynchronizationTask task = new PlayerSynchronizationTask(player); executor.submit(new PhasedSynchronizationTask(phaser, task)); } phaser.arriveAndAwaitAdvance(); - System.out.println("Took " + (System.currentTimeMillis() - duration) + " milliseconds"); phaser.bulkRegister(playerCount); for (Player player : players) { diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt index 7c3526c50..30b5c96ca 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt @@ -43,7 +43,7 @@ class IfAction(override val player: Player) : PlayerContext { override fun handle(player: Player, message: IfActionMessage) { if (predicateContext == null || predicateContext.inter != message.interfaceId || - predicateContext.comp != message.componentId || predicateContext.action != message.action) { + predicateContext.comp != message.componentId || predicateContext.action != message.option) { return; } From deb1a175d547518900e62b187538d54548010dd4 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 13 Apr 2020 08:04:51 -0400 Subject: [PATCH 49/63] Zone packets, add and remove object messages. --- .../message/impl/RemoveTileItemMessage.java | 1 + .../message/impl/SendProjectileMessage.java | 1 + .../impl/SendPublicTileItemMessage.java | 1 + .../message/impl/SendTileItemMessage.java | 1 + .../message/impl/UpdateTileItemMessage.java | 1 + .../AddObjectMessage.java} | 10 +++---- .../GroupedRegionUpdateMessage.java | 2 +- .../{ => encode}/RegionUpdateMessage.java | 2 +- .../{ => encode}/RemoveObjectMessage.java | 2 +- .../UpdateZoneFullFollowsMessage.java} | 6 ++--- .../UpdateZonePartialFollowsMessage.java} | 6 ++--- .../org/apollo/game/model/area/Region.java | 2 +- .../area/update/ItemUpdateOperation.java | 2 +- .../area/update/ObjectUpdateOperation.java | 8 +++--- .../update/ProjectileUpdateOperation.java | 2 +- .../model/area/update/UpdateOperation.java | 2 +- .../apollo/game/release/r181/Release181.java | 10 ++++--- .../encoders/region/AddObjectEncoder.java | 23 ++++++++++++++++ .../region/GroupedRegionUpdateEncoder.java | 16 +++++++++++ .../encoders/region/RemoveObjectEncoder.java | 23 ++++++++++++++++ .../region/UpdateZoneFullFollowsEncoder.java | 27 +++++++++++++++++++ .../UpdateZonePartialFollowsEncoder.java | 27 +++++++++++++++++++ .../game/sync/ParallelClientSynchronizer.java | 2 +- .../sync/SequentialClientSynchronizer.java | 2 +- .../task/PrePlayerSynchronizationTask.java | 8 +++--- 25 files changed, 156 insertions(+), 31 deletions(-) rename game/src/main/java/org/apollo/game/message/impl/{SendObjectMessage.java => encode/AddObjectMessage.java} (86%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/GroupedRegionUpdateMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/RegionUpdateMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/RemoveObjectMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ClearRegionMessage.java => encode/UpdateZoneFullFollowsMessage.java} (84%) rename game/src/main/java/org/apollo/game/message/impl/{SetUpdatedRegionMessage.java => encode/UpdateZonePartialFollowsMessage.java} (84%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/AddObjectEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveObjectEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZoneFullFollowsEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialFollowsEncoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java index 6dffea068..421aed567 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Item; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java index bf60f8e51..94052c0a8 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.entity.Projectile; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java index da6c20a3d..66246f8cc 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Item; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java index d8911a068..d703338a3 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Item; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java index ef923f928..6f3808dfc 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Item; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/SendObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java similarity index 86% rename from game/src/main/java/org/apollo/game/message/impl/SendObjectMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java index bd9dc8a5b..b5ba7c254 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.obj.GameObject; import org.apollo.net.message.Message; @@ -8,7 +8,7 @@ * * @author Major */ -public final class SendObjectMessage extends RegionUpdateMessage { +public final class AddObjectMessage extends RegionUpdateMessage { /** * The id of the object. @@ -36,7 +36,7 @@ public final class SendObjectMessage extends RegionUpdateMessage { * @param object The {@link GameObject} to send. * @param positionOffset The offset of the object's position from the region's central position. */ - public SendObjectMessage(GameObject object, int positionOffset) { + public AddObjectMessage(GameObject object, int positionOffset) { id = object.getId(); this.positionOffset = positionOffset; type = object.getType(); @@ -45,8 +45,8 @@ public SendObjectMessage(GameObject object, int positionOffset) { @Override public boolean equals(Object obj) { - if (obj instanceof SendObjectMessage) { - SendObjectMessage other = (SendObjectMessage) obj; + if (obj instanceof AddObjectMessage) { + AddObjectMessage other = (AddObjectMessage) obj; if (id != other.id || type != other.type) { return false; } diff --git a/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/GroupedRegionUpdateMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/GroupedRegionUpdateMessage.java index 8a6feab1b..d51325197 100644 --- a/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/GroupedRegionUpdateMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.area.RegionCoordinates; diff --git a/game/src/main/java/org/apollo/game/message/impl/RegionUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/RegionUpdateMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java index 6775d01e9..17e99c22c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RegionUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/RemoveObjectMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java index 00557bc3d..8ee4dca48 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.obj.GameObject; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ClearRegionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZoneFullFollowsMessage.java similarity index 84% rename from game/src/main/java/org/apollo/game/message/impl/ClearRegionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateZoneFullFollowsMessage.java index 9506a87f9..c8e64f3a4 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ClearRegionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZoneFullFollowsMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.area.RegionCoordinates; @@ -9,7 +9,7 @@ * * @author Major */ -public final class ClearRegionMessage extends Message { +public final class UpdateZoneFullFollowsMessage extends Message { /** * The Position of the Player. @@ -27,7 +27,7 @@ public final class ClearRegionMessage extends Message { * @param player The {@link Position} of the Player this {@link Message} is being sent to. * @param region The {@link RegionCoordinates} of the Region being cleared. */ - public ClearRegionMessage(Position player, RegionCoordinates region) { + public UpdateZoneFullFollowsMessage(Position player, RegionCoordinates region) { this.player = player; this.region = new Position(region.getAbsoluteX(), region.getAbsoluteY()); } diff --git a/game/src/main/java/org/apollo/game/message/impl/SetUpdatedRegionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialFollowsMessage.java similarity index 84% rename from game/src/main/java/org/apollo/game/message/impl/SetUpdatedRegionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialFollowsMessage.java index cc7fdf9e0..4093266ca 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetUpdatedRegionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialFollowsMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.area.RegionCoordinates; @@ -9,7 +9,7 @@ * * @author Major */ -public final class SetUpdatedRegionMessage extends Message { +public final class UpdateZonePartialFollowsMessage extends Message { /** * The Position of the Player. @@ -27,7 +27,7 @@ public final class SetUpdatedRegionMessage extends Message { * @param player The {@link Position} of the Player this {@link Message} is being sent to. * @param region The {@link RegionCoordinates} of the Region being set. */ - public SetUpdatedRegionMessage(Position player, RegionCoordinates region) { + public UpdateZonePartialFollowsMessage(Position player, RegionCoordinates region) { this.player = player; this.region = new Position(region.getAbsoluteX(), region.getAbsoluteY()); } diff --git a/game/src/main/java/org/apollo/game/model/area/Region.java b/game/src/main/java/org/apollo/game/model/area/Region.java index f53870701..56ffc148b 100644 --- a/game/src/main/java/org/apollo/game/model/area/Region.java +++ b/game/src/main/java/org/apollo/game/model/area/Region.java @@ -3,7 +3,7 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Direction; import org.apollo.game.model.Position; import org.apollo.game.model.area.collision.CollisionMatrix; diff --git a/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java index 05f690e61..a5ccee4ad 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java @@ -1,6 +1,6 @@ package org.apollo.game.model.area.update; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.message.impl.RemoveTileItemMessage; import org.apollo.game.message.impl.SendPublicTileItemMessage; import org.apollo.game.model.area.EntityUpdateType; diff --git a/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java index b0f6d370f..c8014b0e3 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java @@ -1,8 +1,8 @@ package org.apollo.game.model.area.update; -import org.apollo.game.message.impl.RegionUpdateMessage; -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.game.message.impl.SendObjectMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RemoveObjectMessage; +import org.apollo.game.message.impl.encode.AddObjectMessage; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.obj.GameObject; @@ -27,7 +27,7 @@ public ObjectUpdateOperation(Region region, EntityUpdateType type, GameObject ob @Override protected RegionUpdateMessage add(int offset) { - return new SendObjectMessage(entity, offset); + return new AddObjectMessage(entity, offset); } @Override diff --git a/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java index af755956b..095839a8b 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java @@ -1,6 +1,6 @@ package org.apollo.game.model.area.update; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.message.impl.SendProjectileMessage; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; diff --git a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java index b6dc74159..63c26befe 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java @@ -1,7 +1,7 @@ package org.apollo.game.model.area.update; import com.google.common.base.Preconditions; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index c17a78869..9a74601fc 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -7,7 +7,7 @@ import org.apollo.game.release.r181.decoders.social.PublicChatDecoder; import org.apollo.game.release.r181.encoders.game.LogoutEncoder; import org.apollo.game.release.r181.encoders.player.PlayerSynchronizationMessageEncoder; -import org.apollo.game.release.r181.encoders.region.MobResetAnimsEncoder; +import org.apollo.game.release.r181.encoders.region.*; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; import org.apollo.game.release.r181.decoders.map.item.*; import org.apollo.game.release.r181.decoders.map.npc.actions.*; @@ -33,8 +33,6 @@ import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.player.SetPlayerActionMessageEncoder; -import org.apollo.game.release.r181.encoders.region.RebuildNormalMessageEncoder; -import org.apollo.game.release.r181.encoders.region.SetMapFlagEncoder; import org.apollo.game.release.r181.encoders.ui.*; import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerFullMessageEncoder; import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerPartialMessageEncoder; @@ -190,6 +188,12 @@ private void init() { register(UpdateInventoryPartialMessage.class, new UpdateContainerPartialMessageEncoder()); register(UpdateInventoryFullMessage.class, new UpdateContainerFullMessageEncoder()); + register(AddObjectMessage.class, new AddObjectEncoder()); + register(RemoveObjectMessage.class, new RemoveObjectEncoder()); + + register(UpdateZoneFullFollowsMessage.class, new UpdateZoneFullFollowsEncoder()); + register(UpdateZonePartialFollowsMessage.class, new UpdateZonePartialFollowsEncoder()); + register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddObjectEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddObjectEncoder.java new file mode 100644 index 000000000..4364d738d --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddObjectEncoder.java @@ -0,0 +1,23 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.AddObjectMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class AddObjectEncoder extends MessageEncoder { + @Override + public GamePacket encode(AddObjectMessage message) { + final var builder = new GamePacketBuilder(6, PacketType.FIXED); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getType() << 2 | message.getOrientation()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java new file mode 100644 index 000000000..76667ca2e --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java @@ -0,0 +1,16 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.GroupedRegionUpdateMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class GroupedRegionUpdateEncoder extends MessageEncoder { + @Override + public GamePacket encode(GroupedRegionUpdateMessage message) { + + return null; + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveObjectEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveObjectEncoder.java new file mode 100644 index 000000000..e734b57be --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveObjectEncoder.java @@ -0,0 +1,23 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.RemoveObjectMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class RemoveObjectEncoder extends MessageEncoder { + + @Override + public GamePacket encode(RemoveObjectMessage message) { + final var builder = new GamePacketBuilder(13, PacketType.FIXED); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getType() << 2 | message.getOrientation()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getPositionOffset()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZoneFullFollowsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZoneFullFollowsEncoder.java new file mode 100644 index 000000000..1ccc03887 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZoneFullFollowsEncoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.UpdateZoneFullFollowsMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class UpdateZoneFullFollowsEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateZoneFullFollowsMessage message) { + final var builder = new GamePacketBuilder(25, PacketType.FIXED); + + final var player = message.getPlayerPosition(); + final var region = message.getRegionPosition(); + + builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalY(player)); + builder.put(DataType.BYTE, region.getLocalX(player)); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialFollowsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialFollowsEncoder.java new file mode 100644 index 000000000..56db7cdd9 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialFollowsEncoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.UpdateZonePartialFollowsMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class UpdateZonePartialFollowsEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateZonePartialFollowsMessage message) { + final var builder = new GamePacketBuilder(64, PacketType.FIXED); + + final var player = message.getPlayerPosition(); + final var region = message.getRegionPosition(); + + builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player)); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java index edc966de6..9ea94eb5f 100644 --- a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java @@ -1,6 +1,6 @@ package org.apollo.game.sync; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; diff --git a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java index e5309d3d7..e35efd601 100644 --- a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java @@ -1,6 +1,6 @@ package org.apollo.game.sync; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 029c41691..ced678c7c 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -1,8 +1,8 @@ package org.apollo.game.sync.task; -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.UpdateZoneFullFollowsMessage; +import org.apollo.game.message.impl.encode.GroupedRegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.message.impl.encode.RebuildNormalMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; @@ -136,7 +136,7 @@ private void sendUpdates(Position position, Set differences, .computeIfAbsent(coordinates, coords -> repository.get(coords).encode(height)); if (!messages.isEmpty()) { - player.send(new ClearRegionMessage(position, coordinates)); + player.send(new UpdateZoneFullFollowsMessage(position, coordinates)); player.send(new GroupedRegionUpdateMessage(position, coordinates, messages)); } } From c9f5e733847ad3a0a5055089cd081728a26a7842 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 13 Apr 2020 18:47:04 -0400 Subject: [PATCH 50/63] Added proper priorities and the UpdateZonePartialEnclosedEncoder. --- .../message/impl/RemoveTileItemMessage.java | 2 +- .../message/impl/SendProjectileMessage.java | 2 +- .../impl/SendPublicTileItemMessage.java | 2 +- .../message/impl/SendTileItemMessage.java | 2 +- .../message/impl/UpdateTileItemMessage.java | 2 +- .../message/impl/encode/AddObjectMessage.java | 2 +- .../impl/encode/RegionUpdateMessage.java | 12 +--- .../impl/encode/RemoveObjectMessage.java | 2 +- ... => UpdateZonePartialEnclosedMessage.java} | 6 +- .../apollo/game/release/r181/Release181.java | 2 + .../region/GroupedRegionUpdateEncoder.java | 6 +- .../UpdateZonePartialEnclosedEncoder.java | 56 +++++++++++++++++++ .../task/PrePlayerSynchronizationTask.java | 6 +- 13 files changed, 75 insertions(+), 27 deletions(-) rename game/src/main/java/org/apollo/game/message/impl/encode/{GroupedRegionUpdateMessage.java => UpdateZonePartialEnclosedMessage.java} (86%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialEnclosedEncoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java index 421aed567..210c17552 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java @@ -78,7 +78,7 @@ public int hashCode() { @Override public int priority() { - return HIGH_PRIORITY; + return 7; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java index 94052c0a8..a10c10764 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java @@ -70,6 +70,6 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 1; } } diff --git a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java index 66246f8cc..9bb6bae03 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java @@ -94,7 +94,7 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 7; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java index d703338a3..59c59c327 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java @@ -77,7 +77,7 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 8; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java index 6f3808dfc..82f1915f0 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java @@ -104,7 +104,7 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 0; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java index b5ba7c254..9ab0d958f 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java @@ -103,7 +103,7 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 9; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java index 17e99c22c..9fc168db5 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java @@ -3,7 +3,7 @@ import org.apollo.net.message.Message; /** - * A {@link Message} that can be grouped with other Messages as part of a {@link GroupedRegionUpdateMessage}. + * A {@link Message} that can be grouped with other Messages as part of a {@link UpdateZonePartialEnclosedMessage}. *

* This is a utility class for Messages that can be grouped, as is not encoded directly. * @@ -11,16 +11,6 @@ */ public abstract class RegionUpdateMessage extends Message implements Comparable { - /** - * The integer value indicating this RegionUpdateMessage is a high-priority message. - */ - protected static final int HIGH_PRIORITY = 0; - - /** - * The integer value indicating this RegionUpdateMessage is a low-priority message. - */ - protected static final int LOW_PRIORITY = 1; - @Override public final int compareTo(RegionUpdateMessage other) { return Integer.compare(priority(), other.priority()); diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java index 8ee4dca48..9ddb32ca2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java @@ -83,7 +83,7 @@ public int hashCode() { @Override public int priority() { - return HIGH_PRIORITY; + return 6; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/GroupedRegionUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialEnclosedMessage.java similarity index 86% rename from game/src/main/java/org/apollo/game/message/impl/encode/GroupedRegionUpdateMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialEnclosedMessage.java index d51325197..5839e0198 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/GroupedRegionUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialEnclosedMessage.java @@ -11,7 +11,7 @@ * * @author Major */ -public final class GroupedRegionUpdateMessage extends Message { +public final class UpdateZonePartialEnclosedMessage extends Message { /** * The last known region Position of the Player. @@ -35,8 +35,8 @@ public final class GroupedRegionUpdateMessage extends Message { * @param coordinates The {@link RegionCoordinates} of the Region being updated. * @param messages The {@link Set} of {@link RegionUpdateMessage}s. */ - public GroupedRegionUpdateMessage(Position lastKnownRegion, RegionCoordinates coordinates, - Set messages) { + public UpdateZonePartialEnclosedMessage(Position lastKnownRegion, RegionCoordinates coordinates, + Set messages) { this.lastKnownRegion = lastKnownRegion; region = new Position(coordinates.getAbsoluteX(), coordinates.getAbsoluteY()); this.messages = messages; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 9a74601fc..7c00fb4d6 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -191,6 +191,8 @@ private void init() { register(AddObjectMessage.class, new AddObjectEncoder()); register(RemoveObjectMessage.class, new RemoveObjectEncoder()); + + register(UpdateZonePartialEnclosedMessage.class, new UpdateZonePartialEnclosedEncoder(this)); register(UpdateZoneFullFollowsMessage.class, new UpdateZoneFullFollowsEncoder()); register(UpdateZonePartialFollowsMessage.class, new UpdateZonePartialFollowsEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java index 76667ca2e..2015a9978 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java @@ -1,15 +1,15 @@ package org.apollo.game.release.r181.encoders.region; -import org.apollo.game.message.impl.encode.GroupedRegionUpdateMessage; +import org.apollo.game.message.impl.encode.UpdateZonePartialEnclosedMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageEncoder; /** * @author Khaled Abdeljaber */ -public class GroupedRegionUpdateEncoder extends MessageEncoder { +public class GroupedRegionUpdateEncoder extends MessageEncoder { @Override - public GamePacket encode(GroupedRegionUpdateMessage message) { + public GamePacket encode(UpdateZonePartialEnclosedMessage message) { return null; } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialEnclosedEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialEnclosedEncoder.java new file mode 100644 index 000000000..76b5b04ac --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialEnclosedEncoder.java @@ -0,0 +1,56 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.UpdateZonePartialEnclosedMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.model.Position; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; +import org.apollo.net.release.Release; + +/** + * A {@link MessageEncoder} for the {@link UpdateZonePartialEnclosedMessage}. + * + * @author Major + */ +public final class UpdateZonePartialEnclosedEncoder extends MessageEncoder { + + /** + * The Release containing the MessageEncoders for the RegionUpdateMessages. + */ + private final Release release; + + /** + * Creates the GroupedRegionUpdateMessageEncoder. + * + * @param release The {@link Release} containing the {@link MessageEncoder}s for the {@link RegionUpdateMessage}s. + */ + public UpdateZonePartialEnclosedEncoder(Release release) { + this.release = release; + } + + @Override + public GamePacket encode(UpdateZonePartialEnclosedMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(17, PacketType.VARIABLE_SHORT); + Position base = message.getLastKnownRegion(), region = message.getRegionPosition(); + + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(base)); + builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(base)); + + for (RegionUpdateMessage update : message.getMessages()) { + @SuppressWarnings("unchecked") + MessageEncoder encoder = (MessageEncoder) release + .getMessageEncoder(update.getClass()); + + GamePacket packet = encoder.encode(update); + builder.put(DataType.BYTE, update.priority()); + builder.putBytes(packet.content()); + } + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index ced678c7c..8570612c8 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -1,7 +1,7 @@ package org.apollo.game.sync.task; import org.apollo.game.message.impl.encode.UpdateZoneFullFollowsMessage; -import org.apollo.game.message.impl.encode.GroupedRegionUpdateMessage; +import org.apollo.game.message.impl.encode.UpdateZonePartialEnclosedMessage; import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.message.impl.encode.RebuildNormalMessage; import org.apollo.game.model.Position; @@ -127,7 +127,7 @@ private void sendUpdates(Position position, Set differences, .computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(height)); if (!messages.isEmpty()) { - player.send(new GroupedRegionUpdateMessage(position, coordinates, messages)); + player.send(new UpdateZonePartialEnclosedMessage(position, coordinates, messages)); } } @@ -137,7 +137,7 @@ private void sendUpdates(Position position, Set differences, if (!messages.isEmpty()) { player.send(new UpdateZoneFullFollowsMessage(position, coordinates)); - player.send(new GroupedRegionUpdateMessage(position, coordinates, messages)); + player.send(new UpdateZonePartialEnclosedMessage(position, coordinates, messages)); } } } From 0c92c9f68639200bb239770176827ebd83bd6a9d Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 13 Apr 2020 20:29:10 -0400 Subject: [PATCH 51/63] Finished supported map zone packets. --- game/data/messages.xml | 2 +- .../handler/CommandMessageHandler.java | 2 +- .../handler/PublicChatMessageHandler.java | 2 +- .../PublicChatVerificationHandler.java | 2 +- .../game/message/impl/PrivateChatMessage.java | 1 + .../message/impl/SendTileItemMessage.java | 83 ------------------- .../impl/{ => decode}/ChatMessage.java | 2 +- .../impl/{ => decode}/CommandMessage.java | 2 +- .../{ => decode}/PrivacyOptionMessage.java | 2 +- .../impl/{ => decode}/PublicChatMessage.java | 2 +- .../impl/{ => decode}/ReportAbuseMessage.java | 2 +- .../AddTileItemMessage.java} | 13 ++- .../PlayerSynchronizationMessage.java | 2 +- .../{ => encode}/RemoveTileItemMessage.java | 3 +- .../impl/{ => encode}/ServerChatMessage.java | 2 +- .../{ => encode}/UpdateTileItemMessage.java | 3 +- .../area/update/ItemUpdateOperation.java | 6 +- .../org/apollo/game/model/entity/Player.java | 2 +- .../game/model/inv/FullInventoryListener.java | 2 +- .../apollo/game/release/r181/Release181.java | 8 +- .../r181/decoders/CommandMessageDecoder.java | 2 +- .../map/player/ReportAbuseMessageDecoder.java | 2 +- .../social/PrivacyOptionMessageDecoder.java | 2 +- .../decoders/social/PublicChatDecoder.java | 2 +- .../game/ServerChatMessageEncoder.java | 2 +- .../PlayerSynchronizationMessageEncoder.java | 2 +- .../encoders/region/AddTileItemEncoder.java | 21 +++++ .../region/RemoveTileItemEncoder.java | 21 +++++ .../region/SendProjectileMessageEncoder.java | 37 +++++++++ .../region/UpdateTileItemEncoder.java | 24 ++++++ .../org/apollo/game/sync/block/ChatBlock.java | 2 +- .../game/sync/block/SynchronizationBlock.java | 2 +- .../sync/task/PlayerSynchronizationTask.java | 3 +- .../PublicChatMessageHandlerTests.java | 2 +- 34 files changed, 143 insertions(+), 124 deletions(-) delete mode 100644 game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ChatMessage.java (95%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/CommandMessage.java (91%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/PrivacyOptionMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/PublicChatMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => decode}/ReportAbuseMessage.java (96%) rename game/src/main/java/org/apollo/game/message/impl/{SendPublicTileItemMessage.java => encode/AddTileItemMessage.java} (80%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/PlayerSynchronizationMessage.java (89%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/RemoveTileItemMessage.java (94%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/ServerChatMessage.java (97%) rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/UpdateTileItemMessage.java (95%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/AddTileItemEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveTileItemEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateTileItemEncoder.java diff --git a/game/data/messages.xml b/game/data/messages.xml index 1198cb5d5..f7a22b12b 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -27,7 +27,7 @@ - org.apollo.game.message.impl.CommandMessage + org.apollo.game.message.impl.decode.CommandMessage org.apollo.game.message.handler.CommandMessageHandler diff --git a/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java index e90fc59b4..c1fecbca9 100644 --- a/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.game.command.Command; -import org.apollo.game.message.impl.CommandMessage; +import org.apollo.game.message.impl.decode.CommandMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java index 9930e5838..2a7bdde19 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.game.sync.block.SynchronizationBlock; diff --git a/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java index c5e06aa33..9d582ceb8 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java index b7e9aaa5e..fe863411c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.decode.ChatMessage; import org.apollo.net.message.Message; /** diff --git a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java deleted file mode 100644 index 59c59c327..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.message.impl.encode.RegionUpdateMessage; -import org.apollo.game.model.Item; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that adds an item to a tile. - * - * @author Major - */ -public final class SendTileItemMessage extends RegionUpdateMessage { - - /** - * The item to add to the tile. - */ - private final Item item; - - /** - * The position offset - */ - private final int positionOffset; - - /** - * Creates the SendTileItemMessage. - * - * @param item The item to add to the tile. - * @param positionOffset The offset from the 'base' position. - */ - public SendTileItemMessage(Item item, int positionOffset) { - this.item = item; - this.positionOffset = positionOffset; - } - - /** - * Gets the id of the item. - * - * @return The id. - */ - public int getId() { - return item.getId(); - } - - /** - * Gets the amount of the item. - * - * @return The amount. - */ - public int getAmount() { - return item.getAmount(); - } - - /** - * Gets the offset from the 'base' position. - * - * @return The offset. - */ - public int getPositionOffset() { - return positionOffset; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof SendTileItemMessage) { - SendTileItemMessage other = (SendTileItemMessage) obj; - return item.equals(other.item) && positionOffset == other.positionOffset; - } - - return false; - } - - @Override - public int hashCode() { - final int prime = 31; - return item.hashCode() * prime + positionOffset; - } - - @Override - public int priority() { - return 8; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ChatMessage.java similarity index 95% rename from game/src/main/java/org/apollo/game/message/impl/ChatMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ChatMessage.java index 7be4dd931..207f543e7 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ChatMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/CommandMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/CommandMessage.java similarity index 91% rename from game/src/main/java/org/apollo/game/message/impl/CommandMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/CommandMessage.java index 4149c015e..613f7ac5d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/CommandMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/CommandMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java index b6f75e365..047c783cf 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.message.impl.encode.ChatFilterSettingsMessage; import org.apollo.game.model.entity.setting.PrivacyState; diff --git a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PublicChatMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PublicChatMessage.java index 8fe68a94a..49515326e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PublicChatMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ReportAbuseMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ReportAbuseMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/ReportAbuseMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ReportAbuseMessage.java index 03e877c46..f56c11bf2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ReportAbuseMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ReportAbuseMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/AddTileItemMessage.java similarity index 80% rename from game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/AddTileItemMessage.java index 9bb6bae03..f5bf47204 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/AddTileItemMessage.java @@ -1,6 +1,5 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; -import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Item; import org.apollo.net.message.Message; @@ -9,7 +8,7 @@ * * @author Major */ -public final class SendPublicTileItemMessage extends RegionUpdateMessage { +public final class AddTileItemMessage extends RegionUpdateMessage { /** * The index of the player who dropped the item. @@ -33,7 +32,7 @@ public final class SendPublicTileItemMessage extends RegionUpdateMessage { * @param index The index of the player who dropped the item. * @param positionOffset The offset from the 'base' position. */ - public SendPublicTileItemMessage(Item item, int index, int positionOffset) { + public AddTileItemMessage(Item item, int index, int positionOffset) { this.item = item; this.index = index; this.positionOffset = positionOffset; @@ -41,8 +40,8 @@ public SendPublicTileItemMessage(Item item, int index, int positionOffset) { @Override public boolean equals(Object obj) { - if (obj instanceof SendPublicTileItemMessage) { - SendPublicTileItemMessage other = (SendPublicTileItemMessage) obj; + if (obj instanceof AddTileItemMessage) { + AddTileItemMessage other = (AddTileItemMessage) obj; return item.equals(other.item) && index == other.index && positionOffset == other.positionOffset; } @@ -94,7 +93,7 @@ public int hashCode() { @Override public int priority() { - return 7; + return 8; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/PlayerSynchronizationMessage.java similarity index 89% rename from game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/PlayerSynchronizationMessage.java index 522c2e672..a102d5df3 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/PlayerSynchronizationMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.PlayerUpdateInfo; import org.apollo.net.codec.game.GamePacketBuilder; diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveTileItemMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/RemoveTileItemMessage.java index 210c17552..31ec98cd4 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveTileItemMessage.java @@ -1,6 +1,5 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; -import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Item; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ServerChatMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/ServerChatMessage.java index 993a47e6a..b6249a28c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ServerChatMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import com.google.common.base.Strings; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateTileItemMessage.java similarity index 95% rename from game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateTileItemMessage.java index 82f1915f0..ab411527c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateTileItemMessage.java @@ -1,6 +1,5 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; -import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Item; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java index a5ccee4ad..ade6d5bc5 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java @@ -1,8 +1,8 @@ package org.apollo.game.model.area.update; import org.apollo.game.message.impl.encode.RegionUpdateMessage; -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.game.message.impl.SendPublicTileItemMessage; +import org.apollo.game.message.impl.encode.RemoveTileItemMessage; +import org.apollo.game.message.impl.encode.AddTileItemMessage; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.GroundItem; @@ -27,7 +27,7 @@ public ItemUpdateOperation(Region region, EntityUpdateType type, GroundItem item @Override protected RegionUpdateMessage add(int offset) { - return new SendPublicTileItemMessage(entity.getItem(), entity.getOwnerIndex(), offset); + return new AddTileItemMessage(entity.getItem(), entity.getOwnerIndex(), offset); } @Override diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 03cef267d..a8e67c7dd 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -4,7 +4,7 @@ import com.google.common.base.Preconditions; import org.apollo.game.message.impl.IgnoreListMessage; import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.game.message.impl.encode.ServerChatMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; diff --git a/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java b/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java index ab0cf0123..4cb7679af 100644 --- a/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java +++ b/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java @@ -1,6 +1,6 @@ package org.apollo.game.model.inv; -import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.game.message.impl.encode.ServerChatMessage; import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 7c00fb4d6..c49a39ee7 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181; -import org.apollo.game.message.impl.*; +import org.apollo.game.message.impl.SendProjectileMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; @@ -31,7 +31,6 @@ import org.apollo.game.release.r181.encoders.UpdateSkillMessageEncoder; import org.apollo.game.release.r181.encoders.UpdateWeightMessageEncoder; import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; -import org.apollo.game.release.r181.encoders.npc.NpcSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.player.SetPlayerActionMessageEncoder; import org.apollo.game.release.r181.encoders.ui.*; import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerFullMessageEncoder; @@ -190,7 +189,10 @@ private void init() { register(AddObjectMessage.class, new AddObjectEncoder()); register(RemoveObjectMessage.class, new RemoveObjectEncoder()); - + register(AddTileItemMessage.class, new AddTileItemEncoder()); + register(UpdateTileItemMessage.class, new UpdateTileItemEncoder()); + register(RemoveTileItemMessage.class, new RemoveTileItemEncoder()); + register(SendProjectileMessage.class, new SendProjectileMessageEncoder()); register(UpdateZonePartialEnclosedMessage.class, new UpdateZonePartialEnclosedEncoder(this)); register(UpdateZoneFullFollowsMessage.class, new UpdateZoneFullFollowsEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java index 5626fbcd7..5f10ea073 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.CommandMessage; +import org.apollo.game.message.impl.decode.CommandMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java index 8a052006c..8aad575ea 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.map.player; -import org.apollo.game.message.impl.ReportAbuseMessage; +import org.apollo.game.message.impl.decode.ReportAbuseMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java index 79b4c55e5..e2ee3cf36 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.social; -import org.apollo.game.message.impl.PrivacyOptionMessage; +import org.apollo.game.message.impl.decode.PrivacyOptionMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java index 8e2c8b4e2..91a5e3bcf 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders.social; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java index c66bf16ad..3b964d7ff 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.game; -import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.game.message.impl.encode.ServerChatMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java index 8bf300232..c7b43a466 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.player; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; +import org.apollo.game.message.impl.encode.PlayerSynchronizationMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageEncoder; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddTileItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddTileItemEncoder.java new file mode 100644 index 000000000..3be28037e --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddTileItemEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.AddTileItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class AddTileItemEncoder extends MessageEncoder { + + @Override + public GamePacket encode(AddTileItemMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(26); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getAmount()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveTileItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveTileItemEncoder.java new file mode 100644 index 000000000..fcece05b2 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveTileItemEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.AddTileItemMessage; +import org.apollo.game.message.impl.encode.RemoveTileItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class RemoveTileItemEncoder extends MessageEncoder { + + @Override + public GamePacket encode(RemoveTileItemMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(14); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java new file mode 100644 index 000000000..7e54ae2ab --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java @@ -0,0 +1,37 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.SendProjectileMessage; +import org.apollo.game.model.Position; +import org.apollo.game.model.entity.Projectile; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + * A {@link MessageEncoder} for the {@link SendProjectileMessage}. + */ +public final class SendProjectileMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(SendProjectileMessage message) { + Projectile projectile = message.getProjectile(); + Position source = projectile.getPosition(); + Position destination = projectile.getDestination(); + + GamePacketBuilder builder = new GamePacketBuilder(11); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, projectile.getEndHeight()); + builder.put(DataType.SHORT, projectile.getLifetime()); + builder.put(DataType.SHORT, DataTransformation.ADD, projectile.getGraphic()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, projectile.getStartHeight()); + builder.put(DataType.SHORT, DataOrder.LITTLE, projectile.getTarget()); + builder.put(DataType.BYTE, projectile.getPitch()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, projectile.getOffset()); + builder.put(DataType.SHORT, DataOrder.LITTLE, projectile.getDelay()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + builder.put(DataType.BYTE, DataTransformation.ADD, destination.getY() - source.getY()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, destination.getX() - source.getX()); + + return builder.toGamePacket(); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateTileItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateTileItemEncoder.java new file mode 100644 index 000000000..c6cce658f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateTileItemEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.UpdateTileItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateTileItemMessage}. + * + * @author Khaled Abdeljaber + */ +public final class UpdateTileItemEncoder extends MessageEncoder { + + @Override + public GamePacket encode(UpdateTileItemMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(15); + builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getAmount()); + builder.put(DataType.SHORT, DataOrder.LITTLE, message.getPreviousAmount()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java b/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java index f1f163dd8..fcbe1a6c5 100644 --- a/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java @@ -1,6 +1,6 @@ package org.apollo.game.sync.block; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.entity.setting.PrivilegeLevel; import org.apollo.game.sync.block.SynchronizationBlock; diff --git a/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java b/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java index 4554f2442..def3cd12c 100644 --- a/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java @@ -1,6 +1,6 @@ package org.apollo.game.sync.block; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.Animation; import org.apollo.game.model.Direction; import org.apollo.game.model.Graphic; diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index f98cfd57e..b698c794f 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -2,10 +2,9 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import it.unimi.dsi.fastutil.objects.ObjectSet; import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; +import org.apollo.game.message.impl.encode.PlayerSynchronizationMessage; import org.apollo.game.model.*; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionRepository; diff --git a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java index 3a39a5bcf..da7074b6f 100644 --- a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.junit.Test; From a15165bc31baae8bd850d6aa68282eb4a0b8cff1 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 14 Apr 2020 22:23:27 -0400 Subject: [PATCH 52/63] Added unsupported map zone packets. --- .../message/impl/encode/AreaSoundMessage.java | 70 +++++++++++ .../impl/encode/ObjectAnimationMessage.java | 74 ++++++++++++ .../{ => encode}/SendProjectileMessage.java | 3 +- .../message/impl/encode/SpotAnimMessage.java | 70 +++++++++++ .../area/update/AreaSoundUpdateOperation.java | 36 ++++++ .../ObjectAnimationUpdateOperation.java | 33 ++++++ .../update/ProjectileUpdateOperation.java | 2 +- .../area/update/SpotAnimUpdateOperation.java | 35 ++++++ .../apollo/game/model/entity/AreaSound.java | 104 ++++++++++++++++ .../apollo/game/model/entity/EntityType.java | 23 +++- .../org/apollo/game/model/entity/Sound.java | 66 +++++++++++ .../apollo/game/model/entity/SpotAnim.java | 112 ++++++++++++++++++ .../model/entity/obj/ObjectAnimation.java | 70 +++++++++++ .../apollo/game/release/r181/Release181.java | 5 +- .../encoders/region/AreaSoundEncoder.java | 22 ++++ .../region/GroupedRegionUpdateEncoder.java | 16 --- .../encoders/region/ObjectAnimEncoder.java | 27 +++++ .../region/SendProjectileMessageEncoder.java | 2 +- .../r181/encoders/region/SpotAnimEncoder.java | 22 ++++ 19 files changed, 768 insertions(+), 24 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/AreaSoundMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/ObjectAnimationMessage.java rename game/src/main/java/org/apollo/game/message/impl/{ => encode}/SendProjectileMessage.java (93%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/SpotAnimMessage.java create mode 100644 game/src/main/java/org/apollo/game/model/area/update/AreaSoundUpdateOperation.java create mode 100644 game/src/main/java/org/apollo/game/model/area/update/ObjectAnimationUpdateOperation.java create mode 100644 game/src/main/java/org/apollo/game/model/area/update/SpotAnimUpdateOperation.java create mode 100644 game/src/main/java/org/apollo/game/model/entity/AreaSound.java create mode 100644 game/src/main/java/org/apollo/game/model/entity/Sound.java create mode 100644 game/src/main/java/org/apollo/game/model/entity/SpotAnim.java create mode 100644 game/src/main/java/org/apollo/game/model/entity/obj/ObjectAnimation.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/AreaSoundEncoder.java delete mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/ObjectAnimEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/region/SpotAnimEncoder.java diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/AreaSoundMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/AreaSoundMessage.java new file mode 100644 index 000000000..42a15f6a0 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/AreaSoundMessage.java @@ -0,0 +1,70 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.AreaSound; + +import java.util.Objects; + +/** + * The type Area sound message. + * + * @author Khaled Abdeljaber + */ +public class AreaSoundMessage extends RegionUpdateMessage { + + /** + * The sound. + */ + private final AreaSound sound; + + /** + * The position offset. + */ + private final int positionOffset; + + /** + * Instantiates a new Area sound message. + * + * @param sound the sound + * @param positionOffset the position offset + */ + public AreaSoundMessage(AreaSound sound, int positionOffset) { + this.sound = sound; + this.positionOffset = positionOffset; + } + + /** + * Gets sound. + * + * @return the sound + */ + public AreaSound getSound() { + return sound; + } + + /** + * Gets position offset. + * + * @return the position offset + */ + public int getPositionOffset() { + return positionOffset; + } + + @Override + public int priority() { + return 5; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AreaSoundMessage that = (AreaSoundMessage) o; + return positionOffset == that.positionOffset && sound.equals(that.sound); + } + + @Override + public int hashCode() { + return Objects.hash(sound, positionOffset); + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/ObjectAnimationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ObjectAnimationMessage.java new file mode 100644 index 000000000..277fed83f --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ObjectAnimationMessage.java @@ -0,0 +1,74 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.Animation; +import org.apollo.game.model.entity.obj.GameObject; +import org.apollo.game.model.entity.obj.ObjectAnimation; + +import java.util.Objects; + +/** + * The type Object animation message. + * + * @author Khaled Abdeljaber + */ +public class ObjectAnimationMessage extends RegionUpdateMessage { + + private final ObjectAnimation objectAnimation; + private final int positionOffset; + + /** + * Instantiates a new Object anim message. + * + * @param objectAnimation the object animation + * @param positionOffset the position offset + */ + public ObjectAnimationMessage(ObjectAnimation objectAnimation, int positionOffset) { + this.objectAnimation = objectAnimation; + this.positionOffset = positionOffset; + } + + /** + * Gets object. + * + * @return the object + */ + public GameObject getObject() { + return objectAnimation.getObject(); + } + + /** + * Gets animation. + * + * @return the animation + */ + public Animation getAnimation() { + return objectAnimation.getAnimation(); + } + + /** + * Gets position offset. + * + * @return the position offset + */ + public int getPositionOffset() { + return positionOffset; + } + + @Override + public int priority() { + return 4; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ObjectAnimationMessage that = (ObjectAnimationMessage) o; + return positionOffset == that.positionOffset && objectAnimation.equals(that.objectAnimation); + } + + @Override + public int hashCode() { + return Objects.hash(objectAnimation, positionOffset); + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SendProjectileMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/SendProjectileMessage.java index a10c10764..816a97c98 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SendProjectileMessage.java @@ -1,6 +1,5 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; -import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.entity.Projectile; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/SpotAnimMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SpotAnimMessage.java new file mode 100644 index 000000000..f7c8ed921 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SpotAnimMessage.java @@ -0,0 +1,70 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.SpotAnim; + +import java.util.Objects; + +/** + * The type Spot anim message. + * + * @author Khaled Abdeljaber + */ +public class SpotAnimMessage extends RegionUpdateMessage { + + /** + * The graphic. + */ + private final SpotAnim spotAnim; + + /** + * The position offset. + */ + private final int positionOffset; + + /** + * Instantiates a new Spot anim message. + * + * @param spotAnim the anim + * @param positionOffset the position offset + */ + public SpotAnimMessage(SpotAnim spotAnim, int positionOffset) { + this.spotAnim = spotAnim; + this.positionOffset = positionOffset; + } + + /** + * Gets anim. + * + * @return the anim + */ + public SpotAnim getSpotAnim() { + return spotAnim; + } + + /** + * Gets position offset. + * + * @return the position offset + */ + public int getPositionOffset() { + return positionOffset; + } + + @Override + public int priority() { + return 3; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SpotAnimMessage that = (SpotAnimMessage) o; + return positionOffset == that.positionOffset && spotAnim.equals(that.spotAnim); + } + + @Override + public int hashCode() { + return Objects.hash(spotAnim, positionOffset); + } +} diff --git a/game/src/main/java/org/apollo/game/model/area/update/AreaSoundUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/AreaSoundUpdateOperation.java new file mode 100644 index 000000000..fc23fc5d7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/area/update/AreaSoundUpdateOperation.java @@ -0,0 +1,36 @@ +package org.apollo.game.model.area.update; + +import org.apollo.game.message.impl.encode.AreaSoundMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.entity.AreaSound; +import org.apollo.game.model.entity.SpotAnim; + +/** + * @author Khaled Abdeljaber + */ +public class AreaSoundUpdateOperation extends UpdateOperation { + + /** + * Creates the UpdateOperation. + * + * @param region The region in which the UpdateOperation occurred. Must not be {@code null}. + * @param type The type of {@link EntityUpdateType}. Must not be {@code null}. + * @param entity The {@link Entity} being added or removed. Must not be {@code null}. + */ + public AreaSoundUpdateOperation(Region region, EntityUpdateType type, AreaSound entity) { + super(region, type, entity); + } + + @Override + protected RegionUpdateMessage add(int offset) { + return new AreaSoundMessage(entity, offset); + } + + @Override + protected RegionUpdateMessage remove(int offset) { + throw new IllegalStateException("Area sounds cannot be removed."); + } +} + diff --git a/game/src/main/java/org/apollo/game/model/area/update/ObjectAnimationUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ObjectAnimationUpdateOperation.java new file mode 100644 index 000000000..388f1dd62 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/area/update/ObjectAnimationUpdateOperation.java @@ -0,0 +1,33 @@ +package org.apollo.game.model.area.update; + +import org.apollo.game.message.impl.encode.ObjectAnimationMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.entity.obj.ObjectAnimation; + +/** + * @author Khaled Abdeljaber + */ +public class ObjectAnimationUpdateOperation extends UpdateOperation { + /** + * Creates the UpdateOperation. + * + * @param region The region in which the UpdateOperation occurred. Must not be {@code null}. + * @param type The type of {@link EntityUpdateType}. Must not be {@code null}. + * @param entity The {@link Entity} being added or removed. Must not be {@code null}. + */ + public ObjectAnimationUpdateOperation(Region region, EntityUpdateType type, ObjectAnimation entity) { + super(region, type, entity); + } + + @Override + protected RegionUpdateMessage add(int offset) { + return new ObjectAnimationMessage(entity, offset); + } + + @Override + protected RegionUpdateMessage remove(int offset) { + throw new IllegalStateException("Object animations cannot be removed."); + } +} diff --git a/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java index 095839a8b..f5c876f74 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java @@ -1,7 +1,7 @@ package org.apollo.game.model.area.update; import org.apollo.game.message.impl.encode.RegionUpdateMessage; -import org.apollo.game.message.impl.SendProjectileMessage; +import org.apollo.game.message.impl.encode.SendProjectileMessage; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.Projectile; diff --git a/game/src/main/java/org/apollo/game/model/area/update/SpotAnimUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/SpotAnimUpdateOperation.java new file mode 100644 index 000000000..f726a39da --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/area/update/SpotAnimUpdateOperation.java @@ -0,0 +1,35 @@ +package org.apollo.game.model.area.update; + +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.SpotAnimMessage; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.entity.SpotAnim; +import org.apollo.game.model.entity.obj.GameObject; + +/** + * @author Khaled Abdeljaber + */ +public class SpotAnimUpdateOperation extends UpdateOperation { + + /** + * Creates the UpdateOperation. + * + * @param region The region in which the UpdateOperation occurred. Must not be {@code null}. + * @param type The type of {@link EntityUpdateType}. Must not be {@code null}. + * @param entity The {@link Entity} being added or removed. Must not be {@code null}. + */ + public SpotAnimUpdateOperation(Region region, EntityUpdateType type, SpotAnim entity) { + super(region, type, entity); + } + + @Override + protected RegionUpdateMessage add(int offset) { + return new SpotAnimMessage(entity, offset); + } + + @Override + protected RegionUpdateMessage remove(int offset) { + throw new IllegalStateException("SpotAnims cannot be removed."); + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/AreaSound.java b/game/src/main/java/org/apollo/game/model/entity/AreaSound.java new file mode 100644 index 000000000..7aa773a05 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/AreaSound.java @@ -0,0 +1,104 @@ +package org.apollo.game.model.entity; + +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.update.AreaSoundUpdateOperation; +import org.apollo.game.model.area.update.GroupableEntity; +import org.apollo.game.model.area.update.UpdateOperation; + +import java.util.Objects; + +/** + * The type Area sound. + * + * @author Khaled Abdeljaber + */ +public class AreaSound extends Entity implements GroupableEntity { + + /** + * The sound. + */ + private final Sound sound; + + /** + * The radius the sound encompasses. + */ + private final int area; + + /** + * Instantiates a new Area sound. + * + * @param world the world + * @param position the position + * @param sound the sound + * @param area the area + */ + AreaSound(World world, Position position, Sound sound, int area) { + super(world, position); + this.position = position; + this.sound = sound; + this.area = area; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return sound.getId(); + } + + /** + * Gets volume. + * + * @return the volume + */ + public int getVolume() { + return sound.getVolume(); + } + + /** + * Gets delay. + * + * @return the delay + */ + public int getDelay() { + return sound.getDelay(); + } + + @Override + public EntityType getEntityType() { + return EntityType.AREA_SOUND; + } + + @Override + public int getLength() { + return area; + } + + @Override + public int getWidth() { + return area; + } + + @Override + public UpdateOperation toUpdateOperation(Region region, EntityUpdateType type) { + return new AreaSoundUpdateOperation(region, type, this); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AreaSound areaSound = (AreaSound) o; + return area == areaSound.area && sound.equals(areaSound.sound); + } + + @Override + public int hashCode() { + return Objects.hash(sound, area); + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/EntityType.java b/game/src/main/java/org/apollo/game/model/entity/EntityType.java index 3628ccd7a..536afd6ab 100644 --- a/game/src/main/java/org/apollo/game/model/entity/EntityType.java +++ b/game/src/main/java/org/apollo/game/model/entity/EntityType.java @@ -27,17 +27,34 @@ public enum EntityType { */ PLAYER, + /** + * A GameObject that is loaded statically (i.e. from the game resources) at start-up. + */ + STATIC_OBJECT, + /** * A projectile (e.g. an arrow). */ PROJECTILE, /** - * A GameObject that is loaded statically (i.e. from the game resources) at start-up. + * A sound that is heard within an area. */ - STATIC_OBJECT; + AREA_SOUND, /** + * A graphic that is played within an area. + */ + SPOT_ANIM, + + /** + * A graphic that is heard within an area. + */ + OBJECT_ANIMATION + + ; + + /** * Returns whether or not this EntityType is for a Mob. * * @return {@code true} if this EntityType is for a Mob, otherwise {@code false}. @@ -52,6 +69,6 @@ public boolean isMob() { * @return {@code true} if this EntityType is short-lived. */ public boolean isTransient() { - return this == PROJECTILE; + return this == PROJECTILE || this == AREA_SOUND || this == SPOT_ANIM || this == OBJECT_ANIMATION; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/Sound.java b/game/src/main/java/org/apollo/game/model/entity/Sound.java new file mode 100644 index 000000000..3dd8242a4 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/Sound.java @@ -0,0 +1,66 @@ +package org.apollo.game.model.entity; + +import org.apollo.net.message.Message; + +/** + * The type Sound. + * + * @author Khaled Abdeljaber + */ +public class Sound extends Message { + + /** + * The identifier of the sound. + */ + private final int id; + + /** + * The volume of the sound. + */ + private final int volume; + + /** + * The delay of the sound in client ticks. + */ + private final int delay; + + /** + * Instantiates a new Sound. + * + * @param id the id + * @param volume the volume + * @param delay the delay + */ + public Sound(int id, int volume, int delay) { + this.id = id; + this.volume = volume; + this.delay = delay; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Gets volume. + * + * @return the volume + */ + public int getVolume() { + return volume; + } + + /** + * Gets delay. + * + * @return the delay + */ + public int getDelay() { + return delay; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/SpotAnim.java b/game/src/main/java/org/apollo/game/model/entity/SpotAnim.java new file mode 100644 index 000000000..e0dcfdf62 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/SpotAnim.java @@ -0,0 +1,112 @@ +package org.apollo.game.model.entity; + +import com.google.common.base.Preconditions; +import org.apollo.cache.map.Tile; +import org.apollo.game.model.Graphic; +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.update.GroupableEntity; +import org.apollo.game.model.area.update.ProjectileUpdateOperation; +import org.apollo.game.model.area.update.SpotAnimUpdateOperation; +import org.apollo.game.model.area.update.UpdateOperation; + +import java.util.Objects; + +/** + * The type Spot anim. + * + * @author Khaled Abdeljaber + */ +public class SpotAnim extends Entity implements GroupableEntity { + + /** + * The graphic for this spot anim. + */ + private final Graphic graphic; + + /** + * Instantiates a new Spot anim. + * + * @param world the world + * @param position the position + * @param graphic the graphic + */ + public SpotAnim(World world, Position position, Graphic graphic) { + super(world, position); + this.graphic = graphic; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return graphic.getId(); + } + + /** + * Gets height. + * + * @return the height + */ + public int getHeight() { + return graphic.getHeight(); + } + + /** + * Gets delay. + * + * @return the delay + */ + public int getDelay() { + return graphic.getDelay(); + } + + + @Override + public UpdateOperation toUpdateOperation(Region region, EntityUpdateType type) { + Preconditions.checkArgument(type == EntityUpdateType.ADD, "Spotanims cannot be removed from the client"); + + return new SpotAnimUpdateOperation(region, type, this); + } + + @Override + public EntityType getEntityType() { + return EntityType.SPOT_ANIM; + } + + @Override + public int getLength() { + return 1; + } + + @Override + public int getWidth() { + return 1; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SpotAnim spotAnim = (SpotAnim) o; + return graphic.equals(spotAnim.graphic); + } + + @Override + public int hashCode() { + return Objects.hash(graphic); + } + + /** + * Gets graphic. + * + * @return the graphic + */ + public Graphic getGraphic() { + return graphic; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/obj/ObjectAnimation.java b/game/src/main/java/org/apollo/game/model/entity/obj/ObjectAnimation.java new file mode 100644 index 000000000..20d567ea5 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/obj/ObjectAnimation.java @@ -0,0 +1,70 @@ +package org.apollo.game.model.entity.obj; + +import org.apollo.game.model.Animation; +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.update.GroupableEntity; +import org.apollo.game.model.area.update.ObjectAnimationUpdateOperation; +import org.apollo.game.model.area.update.UpdateOperation; +import org.apollo.game.model.entity.Entity; +import org.apollo.game.model.entity.EntityType; + +import java.util.Objects; + +/** + * @author Khaled Abdeljaber + */ +public class ObjectAnimation extends Entity implements GroupableEntity { + + private final GameObject object; + private final Animation animation; + + public ObjectAnimation(World world, Position position, GameObject object, Animation animation) { + super(world, position); + this.object = object; + this.animation = animation; + } + + public GameObject getObject() { + return object; + } + + public Animation getAnimation() { + return animation; + } + + @Override + public UpdateOperation toUpdateOperation(Region region, EntityUpdateType type) { + return new ObjectAnimationUpdateOperation(region, type, this); + } + + @Override + public EntityType getEntityType() { + return EntityType.OBJECT_ANIMATION; + } + + @Override + public int getLength() { + return object.getLength(); + } + + @Override + public int getWidth() { + return object.getWidth(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ObjectAnimation that = (ObjectAnimation) o; + return object.equals(that.object) && animation.equals(that.animation); + } + + @Override + public int hashCode() { + return Objects.hash(object, animation); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index c49a39ee7..0b0412f7b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181; -import org.apollo.game.message.impl.SendProjectileMessage; +import org.apollo.game.message.impl.encode.SendProjectileMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; @@ -192,6 +192,9 @@ private void init() { register(AddTileItemMessage.class, new AddTileItemEncoder()); register(UpdateTileItemMessage.class, new UpdateTileItemEncoder()); register(RemoveTileItemMessage.class, new RemoveTileItemEncoder()); + register(AreaSoundMessage.class, new AreaSoundEncoder()); + register(SpotAnimMessage.class, new SpotAnimEncoder()); + register(ObjectAnimationMessage.class, new ObjectAnimEncoder()); register(SendProjectileMessage.class, new SendProjectileMessageEncoder()); register(UpdateZonePartialEnclosedMessage.class, new UpdateZonePartialEnclosedEncoder(this)); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/AreaSoundEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AreaSoundEncoder.java new file mode 100644 index 000000000..8c9406410 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AreaSoundEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.AreaSoundMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class AreaSoundEncoder extends MessageEncoder { + @Override + public GamePacket encode(AreaSoundMessage message) { + final var sound = message.getSound(); + final var builder = new GamePacketBuilder(12, PacketType.FIXED); + builder.put(DataType.BYTE, sound.getLength() << 4 | sound.getVolume()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, sound.getDelay()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, sound.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java deleted file mode 100644 index 2015a9978..000000000 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/region/GroupedRegionUpdateEncoder.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.apollo.game.release.r181.encoders.region; - -import org.apollo.game.message.impl.encode.UpdateZonePartialEnclosedMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.release.MessageEncoder; - -/** - * @author Khaled Abdeljaber - */ -public class GroupedRegionUpdateEncoder extends MessageEncoder { - @Override - public GamePacket encode(UpdateZonePartialEnclosedMessage message) { - - return null; - } -} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/ObjectAnimEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/ObjectAnimEncoder.java new file mode 100644 index 000000000..643bdf33f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/ObjectAnimEncoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.ObjectAnimationMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class ObjectAnimEncoder extends MessageEncoder { + + @Override + public GamePacket encode(ObjectAnimationMessage message) { + final var animation = message.getAnimation(); + final var object = message.getObject(); + final var builder = new GamePacketBuilder(49, PacketType.FIXED); + + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, object.getType() << 2 | object.getOrientation()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getPositionOffset()); + builder.put(DataType.SHORT, animation.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java index 7e54ae2ab..33852de48 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.region; -import org.apollo.game.message.impl.SendProjectileMessage; +import org.apollo.game.message.impl.encode.SendProjectileMessage; import org.apollo.game.model.Position; import org.apollo.game.model.entity.Projectile; import org.apollo.net.codec.game.*; diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SpotAnimEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SpotAnimEncoder.java new file mode 100644 index 000000000..90bffb3cc --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SpotAnimEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.SpotAnimMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class SpotAnimEncoder extends MessageEncoder { + @Override + public GamePacket encode(SpotAnimMessage message) { + final var spotAnim = message.getSpotAnim(); + final var builder = new GamePacketBuilder(8, PacketType.FIXED); + builder.put(DataType.SHORT, spotAnim.getId()); + builder.put(DataType.BYTE, DataTransformation.ADD, spotAnim.getHeight()); + builder.put(DataType.SHORT, DataTransformation.ADD, spotAnim.getDelay()); + builder.put(DataType.SHORT, message.getPositionOffset()); + return builder.toGamePacket(); + } +} From d56d3756045cf9c20ec7b63435fd2e3d155a231f Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 14 Apr 2020 22:59:08 -0400 Subject: [PATCH 53/63] Fixes issue with crash when changing regions. --- game/data/messages.xml | 2 +- .../encoders/region/RebuildNormalMessageEncoder.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/game/data/messages.xml b/game/data/messages.xml index f7a22b12b..8928dc983 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -14,7 +14,7 @@ - org.apollo.game.message.impl.PublicChatMessage + org.apollo.game.message.impl.decode.PublicChatMessage org.apollo.game.message.handler.PublicChatVerificationHandler org.apollo.game.message.handler.PublicChatMessageHandler diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java index 71b7118f2..9a497ce02 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java @@ -5,6 +5,8 @@ import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; +import java.util.Arrays; + /** * A {@link MessageEncoder} for the {@link RebuildNormalMessage}. * @@ -41,15 +43,15 @@ public GamePacket encode(RebuildNormalMessage message) { .getCentralRegionY() + 6) / 8); mapY++) { if (force || (mapY != 49 && mapY != 149 && mapY != 147 && mapX != 50 && (mapX != 49 || mapY != 47))) { int[] keys = message.getXteaRepository().get(mapX, mapY); - for (int i = 0; i < 4; i++) - map.put(DataType.INT, keys[i]); + for (int key : keys) { + map.put(DataType.INT, key); + } } } } - builder.put(DataType.SHORT, map.getLength() / Integer.BYTES); + builder.put(DataType.SHORT, map.getLength() / (Integer.BYTES * 4)); builder.putBytes(map); return builder.toGamePacket(); } - } \ No newline at end of file From 4cbe7000bb38a214e9da1db1a6175cefacafd9ce Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 14 Apr 2020 23:40:59 -0400 Subject: [PATCH 54/63] Adds more packets to queue, previous limit was 25 packets. Osrs can handle 3000. --- .../org/apollo/cache/map/XteaRepository.java | 3 ++- game/data/login.xml | 2 +- game/plugin/cmd/src/skill-cmd.plugin.kts | 3 ++- game/plugin/skills/woodcutting/src/Tree.kt | 2 +- .../java/org/apollo/game/GameConstants.java | 2 +- .../org/apollo/game/model/entity/SkillSet.java | 18 ++++++++++-------- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cache/src/main/java/org/apollo/cache/map/XteaRepository.java b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java index 423b58736..fed8db659 100644 --- a/cache/src/main/java/org/apollo/cache/map/XteaRepository.java +++ b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java @@ -11,6 +11,7 @@ public class XteaRepository implements Runnable { private static final Gson GSON = new Gson(); + private static final int[] DEFAULT = {0, 0, 0, 0}; public static class Xtea { private final int region; @@ -52,7 +53,7 @@ public void run() { } public int[] get(int region) { - return xteas.getOrDefault(region, null); + return xteas.getOrDefault(region, DEFAULT); } public int[] get(int x, int y) { diff --git a/game/data/login.xml b/game/data/login.xml index b170b7bce..e05b01b88 100644 --- a/game/data/login.xml +++ b/game/data/login.xml @@ -1,3 +1,3 @@ - org.apollo.game.io.player.DummyPlayerSerializer + org.apollo.game.io.player.BinaryPlayerSerializer \ No newline at end of file diff --git a/game/plugin/cmd/src/skill-cmd.plugin.kts b/game/plugin/cmd/src/skill-cmd.plugin.kts index b95ed0181..1e6cccafd 100644 --- a/game/plugin/cmd/src/skill-cmd.plugin.kts +++ b/game/plugin/cmd/src/skill-cmd.plugin.kts @@ -2,6 +2,7 @@ import com.google.common.primitives.Doubles import com.google.common.primitives.Ints import org.apollo.game.model.entity.Skill import org.apollo.game.model.entity.SkillSet +import org.apollo.game.model.entity.SkillSet.SKILL_COUNT import org.apollo.game.model.entity.setting.PrivilegeLevel /** @@ -38,7 +39,7 @@ on_command("level", PrivilegeLevel.ADMINISTRATOR) return@then } - if (skillId !in 0..20 || level !in 1..99) { + if (skillId !in 0..SKILL_COUNT || level !in 1..99) { player.sendMessage(invalidSyntax) return@then } diff --git a/game/plugin/skills/woodcutting/src/Tree.kt b/game/plugin/skills/woodcutting/src/Tree.kt index 279a965dd..5978d0b9a 100644 --- a/game/plugin/skills/woodcutting/src/Tree.kt +++ b/game/plugin/skills/woodcutting/src/Tree.kt @@ -37,7 +37,7 @@ private val NORMAL_OBJECTS = hashSetOf( private val ACHEY_OBJECTS = hashSetOf(2023) private val OAK_OBJECTS = hashSetOf(1281, 3037, 9734) -private val WILLOW_OBJECTS = hashSetOf(5551, 5552, 5553) +private val WILLOW_OBJECTS = hashSetOf(10819) private val TEAK_OBJECTS = hashSetOf(9036) private val MAPLE_OBJECTS = hashSetOf(1307, 4674) private val MAHOGANY_OBJECTS = hashSetOf(9034) diff --git a/game/src/main/java/org/apollo/game/GameConstants.java b/game/src/main/java/org/apollo/game/GameConstants.java index b765cba2a..b3516da37 100644 --- a/game/src/main/java/org/apollo/game/GameConstants.java +++ b/game/src/main/java/org/apollo/game/GameConstants.java @@ -10,7 +10,7 @@ public final class GameConstants { /** * The maximum amount of messages to process per pulse (per session). */ - public static final int MESSAGES_PER_PULSE = 25; + public static final int MESSAGES_PER_PULSE = 3000; /** * The delay between consecutive pulses, in milliseconds. diff --git a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java index 95345a8b3..91495acd6 100644 --- a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java +++ b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java @@ -21,14 +21,15 @@ public final class SkillSet { public static final double MAXIMUM_EXP = 200_000_000; /** - * The minimum amounts of experience required for the levels. + * The number of skills. */ - private static final int[] EXPERIENCE_FOR_LEVEL = new int[100]; + public static final int SKILL_COUNT = 23; /** - * The number of skills. + * The minimum amounts of experience required for the levels. */ - private static final int SKILL_COUNT = 21; + private static final int[] EXPERIENCE_FOR_LEVEL = new int[100]; + static { int points = 0, output = 0; @@ -57,7 +58,8 @@ public static int getExperienceForLevel(int level) { * @return The minimum level. */ public static int getLevelForExperience(double experience) { - Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, "Experience must be between 0 and " + MAXIMUM_EXP + ", inclusive."); + Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, + "Experience must be between 0 and " + MAXIMUM_EXP + ", inclusive."); for (int level = 1; level <= 98; level++) { if (experience < EXPERIENCE_FOR_LEVEL[level + 1]) { return level; @@ -97,7 +99,7 @@ public SkillSet() { /** * Adds experience to the specified skill. * - * @param id The skill id. + * @param id The skill id. * @param experience The amount of experience. */ public void addExperience(int id, double experience) { @@ -258,7 +260,7 @@ public void setCurrentLevel(int skill, int level) { /** * Sets the experience level of the specified skill. * - * @param skill The skill. + * @param skill The skill. * @param experience The experience. */ public void setExperience(int skill, double experience) { @@ -280,7 +282,7 @@ public void setMaximumLevel(int skill, int level) { /** * Sets a {@link Skill}. * - * @param id The id. + * @param id The id. * @param skill The skill. */ public void setSkill(int id, Skill skill) { From 7b5b158b3caaa35229aab9be942e06b20a0a613a Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 20 Apr 2020 00:32:15 -0400 Subject: [PATCH 55/63] Adds huffman codec class to properly compress/decompress mesasges. Half of social stuff done, adding friends communication between them. --- .../org/apollo/cache/def/HuffmanCodec.java | 117 +++++++++++++++++ .../private-messaging/src/friends.plugin.kts | 14 ++- .../src/messaging.plugin.kts | 2 +- .../game/fs/decoder/HuffmanCodecDecoder.java | 118 ++++++++++++++++++ .../game/fs/decoder/WorldMapDecoder.java | 10 +- .../impl/ForwardPrivateChatMessage.java | 6 +- .../game/message/impl/SendFriendMessage.java | 86 ++++++++----- .../impl/encode/FriendListUnlockMessage.java | 10 ++ .../java/org/apollo/game/model/World.java | 4 +- .../org/apollo/game/model/entity/Player.java | 18 ++- .../apollo/game/release/r181/Release181.java | 9 ++ .../social/PrivateChatMessageDecoder.java | 12 +- .../decoders/social/PublicChatDecoder.java | 6 +- .../ForwardPrivateChatMessageEncoder.java | 39 ++++++ .../social/FriendListUnlockEncoder.java | 18 +++ .../social/SendFriendMessageEncoder.java | 33 +++++ .../main/java/org/apollo/util/TextUtil.java | 81 +----------- .../java/org/apollo/util/TextUtilTests.java | 14 --- 18 files changed, 440 insertions(+), 157 deletions(-) create mode 100644 cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java create mode 100644 game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/FriendListUnlockMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/social/FriendListUnlockEncoder.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendMessageEncoder.java diff --git a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java new file mode 100644 index 000000000..77f3aad05 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java @@ -0,0 +1,117 @@ +package org.apollo.cache.def; + +/** + * @author Khaled Abdeljaber + */ +public final class HuffmanCodec { + + private static HuffmanCodec codec; + + public static void init(int[] codes, byte[] codeWeights, int[] tree) { + codec = new HuffmanCodec(codes, codeWeights, tree); + } + + public static String decompress(byte[] compressed) { + return codec.decompress_(compressed); + } + + public static byte[] compress(String str, int length) { + return codec.compress_(str, length); + } + + public static byte[] compress(String str) { + return codec.compress_(str, str.length()); + } + + /** + * The codes of the huffman. + */ + private final int[] codes; + + /** + * The frequencies of the codes. + */ + private final byte[] codeWeights; + + /** + * The indicies of the tree. + */ + private final int[] tree; + + public HuffmanCodec(int[] codes, byte[] codeWeights, int[] tree) { + this.codes = codes; + this.codeWeights = codeWeights; + this.tree = tree; + } + + /** + * Decompress a string. + * + * @param compressed the compressed string. + * @return the decompressed string. + */ + String decompress_(byte[] compressed) { + if (compressed.length == 0) return ""; + + var len = compressed[0] & 0xFF; + var off = 1; + StringBuilder builder = new StringBuilder(); + + var index = 0; + for (; ; ) { + var compressedByte = compressed[off++]; + for (var mask = 0x80; mask != 0; mask >>= 1) { + if ((compressedByte & mask) == 0) { + index++; + } else { + index = tree[index]; + } + + var chr = tree[index]; + if (chr < 0) { + builder.append((char) ((chr & 0xFF) ^ 0xFF)); + if (builder.length() >= len) return builder.toString(); + + index = 0; + } + } + } + } + + /** + * Compress a string. + * + * @param str the str + * @return the length + */ + byte[] compress_(String str, int compressedLength) { + var len = str.length(); + var compressed = new byte[compressedLength]; + + var key = 0; + var bitPos = 8; + var off = 0; + compressed[0] = (byte) len; + for (var i = 0; i < len; i++) { + var chr = str.charAt(i) & 0xFF; + var mask = codes[chr]; + var size = codeWeights[chr]; + + off = bitPos >> 3; + var remainder = bitPos & 0x7; + key &= (-remainder >> 31); + bitPos += size; + var end = (((remainder + size) - 1) >> 3) + off; + + remainder += 24; + compressed[off] = (byte) (key |= (mask >>> remainder)); + + for (var j = 0; j < 4 && off < end; j++) { + remainder -= 8; + compressed[++off] = (byte) (key = mask >>> remainder); + } + } + + return compressed; + } +} diff --git a/game/plugin/chat/private-messaging/src/friends.plugin.kts b/game/plugin/chat/private-messaging/src/friends.plugin.kts index 91aa3c8f9..14b58fa46 100644 --- a/game/plugin/chat/private-messaging/src/friends.plugin.kts +++ b/game/plugin/chat/private-messaging/src/friends.plugin.kts @@ -1,6 +1,12 @@ -import org.apollo.game.message.impl.decode.AddFriendMessage import org.apollo.game.message.impl.SendFriendMessage +import org.apollo.game.message.impl.SendFriendMessage.FriendMessageComponent +import org.apollo.game.message.impl.decode.AddFriendMessage import org.apollo.game.model.entity.setting.PrivacyState +import org.apollo.game.model.event.impl.LoginEvent + +on_player_event { LoginEvent::class }.then { + player.sendUserLists(); +} on { AddFriendMessage::class } .then { @@ -9,13 +15,13 @@ on { AddFriendMessage::class } val friend = it.world.getPlayer(username) if (friend == null || friend.friendPrivacy == PrivacyState.OFF) { - it.send(SendFriendMessage(username, 0)) + it.send(SendFriendMessage(FriendMessageComponent(username, 0))) return@then } else { - it.send(SendFriendMessage(username, friend.worldId)) + it.send(SendFriendMessage(FriendMessageComponent(username, friend.worldId))) } if (friend.friendsWith(it.username) && it.friendPrivacy != PrivacyState.OFF) { - friend.send(SendFriendMessage(it.username, it.worldId)) + friend.send(SendFriendMessage(FriendMessageComponent(it.username, it.worldId))) } } diff --git a/game/plugin/chat/private-messaging/src/messaging.plugin.kts b/game/plugin/chat/private-messaging/src/messaging.plugin.kts index d9fd21e92..36137640d 100644 --- a/game/plugin/chat/private-messaging/src/messaging.plugin.kts +++ b/game/plugin/chat/private-messaging/src/messaging.plugin.kts @@ -9,7 +9,7 @@ on { PrivateChatMessage::class } val friend = it.world.getPlayer(username) if (interactionPermitted(it, friend)) { - friend.send(ForwardPrivateChatMessage(it.username, it.privilegeLevel, compressedMessage)) + friend.send(ForwardPrivateChatMessage(it.username, it.privilegeLevel, message)) } } diff --git a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java new file mode 100644 index 000000000..35e492287 --- /dev/null +++ b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java @@ -0,0 +1,118 @@ +package org.apollo.game.fs.decoder; + +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.def.HuffmanCodec; +import org.apollo.cache.map.MapFile; + +/** + * The type Huffman codec decoder. + */ +public class HuffmanCodecDecoder implements Runnable { + + /** + * The {@link Cache}. + */ + private final Cache cache; + + /** + * Create a new {@link WorldMapDecoder}. + * + * @param cache The {@link Cache} to load {@link MapFile}s. from. + */ + public HuffmanCodecDecoder(Cache cache) { + this.cache = cache; + } + + @Override + public void run() { + final var fs = cache.getArchive(10); + final var group = fs.findFolderByName("huffman"); + final var file = group.findRSFileByID(0); + + buildHuffman(file.getData()); + } + + /** + * Builds the huffman fields. + * @param data the data containing the weights of the huffman. + */ + private void buildHuffman(CacheBuffer data) { + data.setPosition(0); + + var nextCodes = new int[33]; + var codes = new int[data.getRemaining()]; + var tree = new int[8]; + var codeFrequencies = data.getBuffer(); + + int largestVistedIndex = 0; + while (data.getRemaining() > 0) { + var position = data.getPosition(); + var len = data.readByte(); + if (len == 0) { + continue; + } + + var next = 0; + var lenBit = 1 << 32 - len; + var code = nextCodes[len]; + codes[position] = code; + if ((code & lenBit) != 0) { + next = nextCodes[len - 1]; + } else { + next = code | lenBit; + + for (var index = len - 1; index >= 1; --index) { + var nextCode = nextCodes[index]; + if (nextCode != code) { + break; + } + + var nextLenBit = 1 << 32 - index; + if ((nextCode & nextLenBit) != 0) { + nextCodes[index] = nextCodes[index - 1]; + break; + } + + nextCodes[index] = nextCode | nextLenBit; + } + } + + nextCodes[len] = next; + + for (var index = len + 1; index <= 32; index++) { + if (code == nextCodes[index]) { + nextCodes[index] = next; + } + } + + var treeIndex = 0; + for (var shift = 0; shift < len; shift++) { + var bit = Integer.MIN_VALUE >>> shift; + if ((code & bit) != 0) { + if (tree[treeIndex] == 0) { + tree[treeIndex] = largestVistedIndex; + } + + treeIndex = tree[treeIndex]; + } else { + ++treeIndex; + } + + if (treeIndex >= tree.length) { + var nextTree = new int[tree.length * 2]; + System.arraycopy(tree, 0, nextTree, 0, tree.length); + + tree = nextTree; + } + } + + tree[treeIndex] = ~position; + if (treeIndex >= largestVistedIndex) { + largestVistedIndex = treeIndex + 1; + } + } + + HuffmanCodec.init(codes, codeFrequencies, tree); + } +} diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java index 6b8d9ae3f..3c26b82fd 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java @@ -1,6 +1,5 @@ package org.apollo.game.fs.decoder; -import org.apollo.cache.Cache; import org.apollo.cache.map.*; import org.apollo.game.model.Position; import org.apollo.game.model.area.collision.CollisionManager; @@ -25,11 +24,6 @@ public final class WorldMapDecoder implements Runnable { */ private static final int BRIDGE_TILE = 0x2; - /** - * The {@link Cache}. - */ - private Cache fs; - /** * The {@link CollisionManager} to notify of bridged / blocked tiles. */ @@ -38,11 +32,9 @@ public final class WorldMapDecoder implements Runnable { /** * Create a new {@link WorldMapDecoder}. * - * @param fs The {@link Cache} to load {@link MapFile}s. from. * @param collisionManager The {@link CollisionManager} to register tiles with. */ - public WorldMapDecoder(Cache fs, CollisionManager collisionManager) { - this.fs = fs; + public WorldMapDecoder(CollisionManager collisionManager) { this.collisionManager = collisionManager; } diff --git a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java index a2a82b6ca..f78ae8d8e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java @@ -23,7 +23,7 @@ public final class ForwardPrivateChatMessage extends Message { /** * The message. */ - private final byte[] message; + private final String message; /** * Creates a new forward private message message. @@ -32,7 +32,7 @@ public final class ForwardPrivateChatMessage extends Message { * @param level The {@link PrivilegeLevel} of the player sending the message. * @param message The compressed message. */ - public ForwardPrivateChatMessage(String username, PrivilegeLevel level, byte[] message) { + public ForwardPrivateChatMessage(String username, PrivilegeLevel level, String message) { this.username = username; privilege = level; this.message = message; @@ -61,7 +61,7 @@ public PrivilegeLevel getSenderPrivilege() { * * @return The message. */ - public byte[] getCompressedMessage() { + public String getCompressedMessage() { return message; } diff --git a/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java index b86353c1a..b57854879 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java @@ -10,50 +10,78 @@ public final class SendFriendMessage extends Message { /** - * The username of the friend. + * The type Friend message component. */ - private final String username; + public static final class FriendMessageComponent { + /** + * The username of the friend. + */ + private final String username; - /** - * The world id the friend is in. - */ - private final int world; + /** + * The world id the friend is in. + */ + private final int world; - /** - * Creates a new send friend message. - * - * @param username The username of the friend. - * @param world The world the friend is in. - */ - public SendFriendMessage(String username, int world) { - this.username = username; - this.world = world; + /** + * Creates a new send friend message. + * + * @param username The username of the friend. + * @param world The world the friend is in. + */ + public FriendMessageComponent(String username, int world) { + this.username = username; + this.world = world; + } + + /** + * Gets the username of the friend. + * + * @return The username. + */ + public String getUsername() { + return username; + } + + /** + * Gets the world id the friend is in. + * + * @return The world id. + */ + public int getWorld() { + return world; + } + + /** + * Gets the encoded world id to be sent to the client. + * + * @return The encoded world id. + */ + public int getEncodedWorld() { + return world; + } } /** - * Gets the username of the friend. - * - * @return The username. + * The components that build the message. */ - public String getUsername() { - return username; - } + private final FriendMessageComponent[] components; /** - * Gets the world id the friend is in. + * Instantiates a new Send friend message. * - * @return The world id. + * @param components the components */ - public int getWorld() { - return world; + public SendFriendMessage(FriendMessageComponent... components) { + this.components = components; } /** - * Gets the encoded world id to be sent to the client. + * Get components friend message component [ ]. * - * @return The encoded world id. + * @return the friend message component [ ] */ - public int getEncodedWorld() { - return world == 0 ? 0 : world + 9; + public FriendMessageComponent[] getComponents() { + return components; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/FriendListUnlockMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/FriendListUnlockMessage.java new file mode 100644 index 000000000..d0f03d6f6 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/FriendListUnlockMessage.java @@ -0,0 +1,10 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class FriendListUnlockMessage extends Message { + +} diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index c11d1ce79..ac8cd9b42 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -10,6 +10,7 @@ import org.apollo.cache.map.MapIndexDecoder; import org.apollo.cache.map.XteaRepository; import org.apollo.game.command.CommandDispatcher; +import org.apollo.game.fs.decoder.HuffmanCodecDecoder; import org.apollo.game.fs.decoder.SynchronousDecoder; import org.apollo.game.fs.decoder.WorldMapDecoder; import org.apollo.game.fs.decoder.WorldObjectsDecoder; @@ -232,8 +233,9 @@ public void init(int release, Cache cache, PluginManager manager) throws Excepti firstStageDecoder.block(); SynchronousDecoder secondStageDecoder = new SynchronousDecoder( + new HuffmanCodecDecoder(cache), new WorldObjectsDecoder(cache, this), - new WorldMapDecoder(cache, collisionManager) + new WorldMapDecoder(collisionManager) ); secondStageDecoder.block(); diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index a8e67c7dd..e650a8f1b 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -4,7 +4,7 @@ import com.google.common.base.Preconditions; import org.apollo.game.message.impl.IgnoreListMessage; import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.encode.ServerChatMessage; +import org.apollo.game.message.impl.SendFriendMessage.FriendMessageComponent; import org.apollo.game.message.impl.encode.*; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; @@ -225,8 +225,7 @@ public Player(World world, PlayerCredentials credentials, Position position) { super(world, position); this.credentials = credentials; - inventory.add(4155, 1); - + addFriend("Cjaytest"); init(); } @@ -793,10 +792,17 @@ public void sendUserLists() { send(new IgnoreListMessage(ignores)); } - for (String username : friends) { - int worldId = world.isPlayerOnline(username) ? world.getPlayer(username).worldId : 0; - send(new SendFriendMessage(username, worldId)); + send(new FriendListUnlockMessage()); + + FriendMessageComponent[] components = new FriendMessageComponent[friends.size()]; + for (int index = 0; index < components.length; index++) { + var username = friends.get(index); + var worldId = world.isPlayerOnline(username) ? world.getPlayer(username).worldId : 0; + + components[index] = new FriendMessageComponent(username, worldId); } + send(new SendFriendMessage(components)); + } /** diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 0b0412f7b..112e32ce2 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,5 +1,7 @@ package org.apollo.game.release.r181; +import org.apollo.game.message.impl.ForwardPrivateChatMessage; +import org.apollo.game.message.impl.SendFriendMessage; import org.apollo.game.message.impl.encode.SendProjectileMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; @@ -7,6 +9,9 @@ import org.apollo.game.release.r181.decoders.social.PublicChatDecoder; import org.apollo.game.release.r181.encoders.game.LogoutEncoder; import org.apollo.game.release.r181.encoders.player.PlayerSynchronizationMessageEncoder; +import org.apollo.game.release.r181.encoders.player.social.ForwardPrivateChatMessageEncoder; +import org.apollo.game.release.r181.encoders.player.social.FriendListUnlockEncoder; +import org.apollo.game.release.r181.encoders.player.social.SendFriendMessageEncoder; import org.apollo.game.release.r181.encoders.region.*; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; import org.apollo.game.release.r181.decoders.map.item.*; @@ -211,6 +216,10 @@ private void init() { register(ConfigMessage.class, new ConfigMessageEncoder()); register(ServerChatMessage.class, new ServerChatMessageEncoder()); + register(SendFriendMessage.class, new SendFriendMessageEncoder()); + register(FriendListUnlockMessage.class, new FriendListUnlockEncoder()); + register(ForwardPrivateChatMessage.class, new ForwardPrivateChatMessageEncoder()); + /** * Client diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java index 06da4ccf3..17ddef05e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java @@ -1,5 +1,6 @@ package org.apollo.game.release.r181.decoders.social; +import org.apollo.cache.def.HuffmanCodec; import org.apollo.game.message.impl.PrivateChatMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -18,19 +19,16 @@ public PrivateChatMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); String username = reader.getString(); - int length = packet.getLength() - Long.BYTES; - byte[] originalCompressed = new byte[length]; + final var length = reader.getLength(); + final var originalCompressed = new byte[length]; reader.getBytes(originalCompressed); - String decompressed = TextUtil.decompress(originalCompressed, length); + String decompressed = HuffmanCodec.decompress(originalCompressed); decompressed = TextUtil.filterInvalidCharacters(decompressed); decompressed = TextUtil.capitalize(decompressed); - byte[] recompressed = new byte[length]; - TextUtil.compress(decompressed, recompressed); - - return new PrivateChatMessage(decompressed, recompressed, username); + return new PrivateChatMessage(decompressed, username); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java index 91a5e3bcf..8fee5ad2a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java @@ -1,5 +1,6 @@ package org.apollo.game.release.r181.decoders.social; +import org.apollo.cache.def.HuffmanCodec; import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -24,12 +25,11 @@ public PublicChatMessage decode(GamePacket packet) { final var originalCompressed = new byte[length]; reader.getBytes(originalCompressed); - String uncompressed = TextUtil.decompress(originalCompressed, length); + String uncompressed = HuffmanCodec.decompress(originalCompressed); uncompressed = TextUtil.filterInvalidCharacters(uncompressed); uncompressed = TextUtil.capitalize(uncompressed); - final var recompressed = new byte[length]; - TextUtil.compress(uncompressed, recompressed); // in case invalid data gets sent, this effectively verifies it + final var recompressed = HuffmanCodec.compress(uncompressed, length); // in case invalid data gets sent, this effectively verifies it return new PublicChatMessage(uncompressed, recompressed, color, effects, type); } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java new file mode 100644 index 000000000..25e66b6f4 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java @@ -0,0 +1,39 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.apollo.game.message.impl.ForwardPrivateChatMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; +import org.apollo.util.NameUtil; + +/** + * A {@link MessageEncoder} for the {@link ForwardPrivateChatMessage}. + * + * @author Major + */ +public final class ForwardPrivateChatMessageEncoder extends MessageEncoder { + + /** + * The amount of messages sent globally, offset by a random variable x, {@code 0 <= x < 100,000,000}. + */ + private static AtomicInteger messageCounter = new AtomicInteger((int) (Math.random() * 100_000_000)); + + @Override + public GamePacket encode(ForwardPrivateChatMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(10, PacketType.VARIABLE_SHORT); + + builder.putString(message.getSenderUsername()); + long count = messageCounter.incrementAndGet(); + builder.put(DataType.SHORT, count >> 16); + builder.put(DataType.TRI_BYTE, count & 0xFFFFFF); + builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger()); + builder.putString(message.getCompressedMessage()); + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/FriendListUnlockEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/FriendListUnlockEncoder.java new file mode 100644 index 000000000..70b13faf9 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/FriendListUnlockEncoder.java @@ -0,0 +1,18 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.encode.FriendListUnlockMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class FriendListUnlockEncoder extends MessageEncoder { + @Override + public GamePacket encode(FriendListUnlockMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(29, PacketType.FIXED); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendMessageEncoder.java new file mode 100644 index 000000000..05fc38000 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendMessageEncoder.java @@ -0,0 +1,33 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.SendFriendMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public final class SendFriendMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(SendFriendMessage message) { + final var builder = new GamePacketBuilder(58, PacketType.VARIABLE_SHORT); + final var components = message.getComponents(); + + for (var component : components) { + builder.put(DataType.BYTE, 0); // Friend Chat Rank + builder.putString(component.getUsername()); // Displayname + builder.putString(""); // Previous Displayname + builder.put(DataType.SHORT, component.getEncodedWorld()); + builder.put(DataType.BYTE, 0); // Friend Chat Rank + builder.put(DataType.BYTE, 0); // Some set of attributes, sorts the list somehow. + builder.putString(""); // Note + } + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/util/src/main/java/org/apollo/util/TextUtil.java b/util/src/main/java/org/apollo/util/TextUtil.java index af262f34b..4c6ccc7f3 100644 --- a/util/src/main/java/org/apollo/util/TextUtil.java +++ b/util/src/main/java/org/apollo/util/TextUtil.java @@ -11,10 +11,7 @@ public final class TextUtil { * An array of characters ordered by frequency - the elements with lower indices (generally) appear more often in * chat messages. */ - public static final char[] FREQUENCY_ORDERED_CHARS = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', - 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', - '=', '\243', '$', '%', '"', '[', ']' }; + public static final char[] FREQUENCY_ORDERED_CHARS = {' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', '=', '\243', '$', '%', '"', '[', ']'}; /** * Capitalizes the string correctly. @@ -43,53 +40,6 @@ public static String capitalize(String string) { return builder.toString(); } - /** - * Compresses the input text ({@code in}) and places the result in the {@code out} array. - * - * @param in The input text. - * @param out The output array. - * @return The number of bytes written to the output array. - */ - public static int compress(String in, byte[] out) { - if (in.length() > 80) { - in = in.substring(0, 80); - } - in = in.toLowerCase(); - - int carry = -1; - int outPos = 0; - for (int inPos = 0; inPos < in.length(); inPos++) { - char c = in.charAt(inPos); - int tblPos = 0; - for (int i = 0; i < FREQUENCY_ORDERED_CHARS.length; i++) { - if (c == FREQUENCY_ORDERED_CHARS[i]) { - tblPos = i; - break; - } - } - if (tblPos > 12) { - tblPos += 195; - } - if (carry == -1) { - if (tblPos < 13) { - carry = tblPos; - } else { - out[outPos++] = (byte) tblPos; - } - } else if (tblPos < 13) { - out[outPos++] = (byte) ((carry << 4) + tblPos); - carry = -1; - } else { - out[outPos++] = (byte) ((carry << 4) + (tblPos >> 4)); - carry = tblPos & 0xF; - } - } - if (carry != -1) { - out[outPos++] = (byte) (carry << 4); - } - return outPos; - } - /** * Filters invalid characters from the specified string. * @@ -109,35 +59,6 @@ public static String filterInvalidCharacters(String str) { return builder.toString(); } - /** - * Uncompresses the compressed data ({@code in}) with the length ({@code len}) and returns the uncompressed - * {@link String}. - * - * @param in The compressed input data. - * @param len The length. - * @return The uncompressed {@link String}. - */ - public static String decompress(byte[] in, int len) { - byte[] out = new byte[4096]; - int outPos = 0; - int carry = -1; - - for (int i = 0; i < len * 2; i++) { - int tblPos = in[i / 2] >> 4 - 4 * (i % 2) & 0xF; - if (carry == -1) { - if (tblPos < 13) { - out[outPos++] = (byte) FREQUENCY_ORDERED_CHARS[tblPos]; - } else { - carry = tblPos; - } - } else { - out[outPos++] = (byte) FREQUENCY_ORDERED_CHARS[(carry << 4) + tblPos - 195]; - carry = -1; - } - } - return new String(out, 0, outPos); - } - /** * Default private constructor to prevent instantiation. */ diff --git a/util/src/test/java/org/apollo/util/TextUtilTests.java b/util/src/test/java/org/apollo/util/TextUtilTests.java index b7b637dc4..174b6e8d7 100644 --- a/util/src/test/java/org/apollo/util/TextUtilTests.java +++ b/util/src/test/java/org/apollo/util/TextUtilTests.java @@ -23,20 +23,6 @@ public void testCapitalize() { assertEquals("Test", TextUtil.capitalize("test")); } - /** - * Tests the {@link TextUtil#compress} and {@link TextUtil#decompress} methods. - */ - @Test - public void testCompression() { - String str = "hello, world!"; - - byte[] compressed = new byte[128]; - int len = TextUtil.compress(str, compressed); - String uncompressed = TextUtil.decompress(compressed, len); - - assertEquals(str, uncompressed); - } - /** * Tests the {@link TextUtil#filterInvalidCharacters(String)} method. */ From 4af53e97173dfda2739e39296fe9092cee157225 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Mon, 20 Apr 2020 00:45:05 -0400 Subject: [PATCH 56/63] Fixes problem that broke pub chat. Still need to fix compression for private chat. --- .../main/java/org/apollo/cache/def/HuffmanCodec.java | 2 +- .../chat/private-messaging/src/messaging.plugin.kts | 2 +- .../game/message/impl/ForwardPrivateChatMessage.java | 6 +++--- .../decoders/social/PrivateChatMessageDecoder.java | 5 ++++- .../social/ForwardPrivateChatMessageEncoder.java | 10 ++++++---- .../game/sync/task/PlayerSynchronizationTask.java | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java index 77f3aad05..113a6739a 100644 --- a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java +++ b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java @@ -86,7 +86,7 @@ String decompress_(byte[] compressed) { */ byte[] compress_(String str, int compressedLength) { var len = str.length(); - var compressed = new byte[compressedLength]; + var compressed = new byte[compressedLength + 1]; var key = 0; var bitPos = 8; diff --git a/game/plugin/chat/private-messaging/src/messaging.plugin.kts b/game/plugin/chat/private-messaging/src/messaging.plugin.kts index 36137640d..d9fd21e92 100644 --- a/game/plugin/chat/private-messaging/src/messaging.plugin.kts +++ b/game/plugin/chat/private-messaging/src/messaging.plugin.kts @@ -9,7 +9,7 @@ on { PrivateChatMessage::class } val friend = it.world.getPlayer(username) if (interactionPermitted(it, friend)) { - friend.send(ForwardPrivateChatMessage(it.username, it.privilegeLevel, message)) + friend.send(ForwardPrivateChatMessage(it.username, it.privilegeLevel, compressedMessage)) } } diff --git a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java index f78ae8d8e..a2a82b6ca 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java @@ -23,7 +23,7 @@ public final class ForwardPrivateChatMessage extends Message { /** * The message. */ - private final String message; + private final byte[] message; /** * Creates a new forward private message message. @@ -32,7 +32,7 @@ public final class ForwardPrivateChatMessage extends Message { * @param level The {@link PrivilegeLevel} of the player sending the message. * @param message The compressed message. */ - public ForwardPrivateChatMessage(String username, PrivilegeLevel level, String message) { + public ForwardPrivateChatMessage(String username, PrivilegeLevel level, byte[] message) { this.username = username; privilege = level; this.message = message; @@ -61,7 +61,7 @@ public PrivilegeLevel getSenderPrivilege() { * * @return The message. */ - public String getCompressedMessage() { + public byte[] getCompressedMessage() { return message; } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java index 17ddef05e..b2e752d8b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java @@ -28,7 +28,10 @@ public PrivateChatMessage decode(GamePacket packet) { decompressed = TextUtil.filterInvalidCharacters(decompressed); decompressed = TextUtil.capitalize(decompressed); - return new PrivateChatMessage(decompressed, username); + final var recompressed = HuffmanCodec + .compress(decompressed, length); // in case invalid data gets sent, this effectively verifies it + + return new PrivateChatMessage(decompressed, recompressed, username); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java index 25e66b6f4..1f7d05afe 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java @@ -1,14 +1,13 @@ package org.apollo.game.release.r181.encoders.player.social; -import java.util.concurrent.atomic.AtomicInteger; - import org.apollo.game.message.impl.ForwardPrivateChatMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; + +import java.util.concurrent.atomic.AtomicInteger; /** * A {@link MessageEncoder} for the {@link ForwardPrivateChatMessage}. @@ -31,7 +30,10 @@ public GamePacket encode(ForwardPrivateChatMessage message) { builder.put(DataType.SHORT, count >> 16); builder.put(DataType.TRI_BYTE, count & 0xFFFFFF); builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger()); - builder.putString(message.getCompressedMessage()); + + final var compressed = message.getCompressedMessage(); + builder.putSmart(compressed.length); + builder.putBytes(compressed); return builder.toGamePacket(); } diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index b698c794f..2298705ce 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -618,7 +618,7 @@ private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) { builder.put(DataType.SHORT, DataTransformation.ADD, block.getTextEffects() << 8 | block.getTextColor()); builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger()); builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType().ordinal()); - builder.put(DataType.BYTE, bytes.length); + builder.putSmart(bytes.length); builder.putBytes(bytes); } From 4bddfe2044fc78fe9432f912447113eadaec32c5 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 21 Apr 2020 23:39:17 -0400 Subject: [PATCH 57/63] Fixes issue with HuffmanCodec --- .../org/apollo/cache/def/HuffmanCodec.java | 117 ++++++++++++++---- .../game/fs/decoder/HuffmanCodecDecoder.java | 8 +- .../io/player/BinaryPlayerSerializer.java | 2 +- .../social/PrivateChatMessageDecoder.java | 7 +- .../decoders/social/PublicChatDecoder.java | 7 +- 5 files changed, 101 insertions(+), 40 deletions(-) diff --git a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java index 113a6739a..c9347e893 100644 --- a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java +++ b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java @@ -7,8 +7,8 @@ public final class HuffmanCodec { private static HuffmanCodec codec; - public static void init(int[] codes, byte[] codeWeights, int[] tree) { - codec = new HuffmanCodec(codes, codeWeights, tree); + public static void init(int[] codes, byte[] codeLengths, int[] tree) { + codec = new HuffmanCodec(codes, codeLengths, tree); } public static String decompress(byte[] compressed) { @@ -19,10 +19,6 @@ public static byte[] compress(String str, int length) { return codec.compress_(str, length); } - public static byte[] compress(String str) { - return codec.compress_(str, str.length()); - } - /** * The codes of the huffman. */ @@ -31,16 +27,16 @@ public static byte[] compress(String str) { /** * The frequencies of the codes. */ - private final byte[] codeWeights; + private final byte[] codeLengths; /** * The indicies of the tree. */ private final int[] tree; - public HuffmanCodec(int[] codes, byte[] codeWeights, int[] tree) { + public HuffmanCodec(int[] codes, byte[] codeLengths, int[] tree) { this.codes = codes; - this.codeWeights = codeWeights; + this.codeLengths = codeLengths; this.tree = tree; } @@ -85,33 +81,104 @@ String decompress_(byte[] compressed) { * @return the length */ byte[] compress_(String str, int compressedLength) { - var len = str.length(); - var compressed = new byte[compressedLength + 1]; + var uncompressedLength = str.length(); + var dest = new byte[compressedLength]; - var key = 0; var bitPos = 8; - var off = 0; - compressed[0] = (byte) len; - for (var i = 0; i < len; i++) { - var chr = str.charAt(i) & 0xFF; - var mask = codes[chr]; - var size = codeWeights[chr]; - - off = bitPos >> 3; + dest[0] = (byte) uncompressedLength; + if (uncompressedLength >= 0xFF) { + bitPos += 8; + dest[1] = (byte) ((uncompressedLength >> 16) & 0xFF); + } + + var key = 0; + for (var i = 0; i < uncompressedLength; i++) { + var character = lookup(str.charAt(i)) & 0xFF; + var code = codes[character]; + var length = codeLengths[character]; + + var off = bitPos >> 3; var remainder = bitPos & 0x7; + var end = off + (length + remainder - 1 >> 3); + key &= (-remainder >> 31); - bitPos += size; - var end = (((remainder + size) - 1) >> 3) + off; + bitPos += length; remainder += 24; - compressed[off] = (byte) (key |= (mask >>> remainder)); + dest[off] = (byte) (key |= code >>> remainder); for (var j = 0; j < 4 && off < end; j++) { remainder -= 8; - compressed[++off] = (byte) (key = mask >>> remainder); + if (j == 3) { + dest[++off] = (byte) (key = code << -remainder); + } else { + dest[++off] = (byte) (key = code >>> remainder); + } } } - return compressed; + return dest; + } + + private static byte lookup(char character) { + if (character > 0 && character < 128 || character >= 160 && character <= 255) { + return (byte) character; + } else if (character == 8364) { + return -128; + } else if (character == 8218) { + return -126; + } else if (character == 402) { + return -125; + } else if (character == 8222) { + return -124; + } else if (character == 8230) { + return -123; + } else if (character == 8224) { + return -122; + } else if (character == 8225) { + return -121; + } else if (character == 710) { + return -120; + } else if (character == 8240) { + return -119; + } else if (character == 352) { + return -118; + } else if (character == 8249) { + return -117; + } else if (character == 338) { + return -116; + } else if (character == 381) { + return -114; + } else if (character == 8216) { + return -111; + } else if (character == 8217) { + return -110; + } else if (character == 8220) { + return -109; + } else if (character == 8221) { + return -108; + } else if (character == 8226) { + return -107; + } else if (character == 8211) { + return -106; + } else if (character == 8212) { + return -105; + } else if (character == 732) { + return -104; + } else if (character == 8482) { + return -103; + } else if (character == 353) { + return -102; + } else if (character == 8250) { + return -101; + } else if (character == 339) { + return -100; + } else if (character == 382) { + return -98; + } else if (character == 376) { + return -97; + } else { + return 63; + } } } diff --git a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java index 35e492287..69895a64a 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java @@ -45,7 +45,7 @@ private void buildHuffman(CacheBuffer data) { var tree = new int[8]; var codeFrequencies = data.getBuffer(); - int largestVistedIndex = 0; + var largestVisitedIndex = 0; while (data.getRemaining() > 0) { var position = data.getPosition(); var len = data.readByte(); @@ -91,7 +91,7 @@ private void buildHuffman(CacheBuffer data) { var bit = Integer.MIN_VALUE >>> shift; if ((code & bit) != 0) { if (tree[treeIndex] == 0) { - tree[treeIndex] = largestVistedIndex; + tree[treeIndex] = largestVisitedIndex; } treeIndex = tree[treeIndex]; @@ -108,8 +108,8 @@ private void buildHuffman(CacheBuffer data) { } tree[treeIndex] = ~position; - if (treeIndex >= largestVistedIndex) { - largestVistedIndex = treeIndex + 1; + if (treeIndex >= largestVisitedIndex) { + largestVisitedIndex = treeIndex + 1; } } diff --git a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java index 6391d7144..e42899f15 100644 --- a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java +++ b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java @@ -99,7 +99,7 @@ public PlayerLoaderResponse loadPlayer(PlayerCredentials credentials) throws IOE } Player player = new Player(world, credentials, new Position(x, y, height)); - player.setPrivilegeLevel(privilege); + player.setPrivilegeLevel(PrivilegeLevel.ADMINISTRATOR); player.setMembers(members); player.setChatPrivacy(chatPrivacy); player.setFriendPrivacy(friendPrivacy); diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java index b2e752d8b..9c3b4f5ec 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java @@ -20,17 +20,14 @@ public PrivateChatMessage decode(GamePacket packet) { String username = reader.getString(); - final var length = reader.getLength(); - final var originalCompressed = new byte[length]; + final var originalCompressed = new byte[reader.getLength()]; reader.getBytes(originalCompressed); String decompressed = HuffmanCodec.decompress(originalCompressed); decompressed = TextUtil.filterInvalidCharacters(decompressed); decompressed = TextUtil.capitalize(decompressed); - final var recompressed = HuffmanCodec - .compress(decompressed, length); // in case invalid data gets sent, this effectively verifies it - + final var recompressed = HuffmanCodec.compress(decompressed); return new PrivateChatMessage(decompressed, recompressed, username); } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java index 8fee5ad2a..a9b7434ea 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java @@ -20,17 +20,14 @@ public PublicChatMessage decode(GamePacket packet) { final var color = (int) reader.getUnsigned(DataType.BYTE); final var effects = (int) reader.getUnsigned(DataType.BYTE); - final var length = packet.getLength() - 3; - - final var originalCompressed = new byte[length]; + final var originalCompressed = new byte[packet.getLength() - 3]; reader.getBytes(originalCompressed); String uncompressed = HuffmanCodec.decompress(originalCompressed); uncompressed = TextUtil.filterInvalidCharacters(uncompressed); uncompressed = TextUtil.capitalize(uncompressed); - final var recompressed = HuffmanCodec.compress(uncompressed, length); // in case invalid data gets sent, this effectively verifies it - + final var recompressed = HuffmanCodec.compress(uncompressed); // in case invalid data gets sent, this effectively verifies it return new PublicChatMessage(uncompressed, recompressed, color, effects, type); } } From 04ab087782a59502c868b6da76d1f8db309d1142 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 21 Apr 2020 23:43:11 -0400 Subject: [PATCH 58/63] Fixes codec issues. --- .../org/apollo/game/fs/decoder/HuffmanCodecDecoder.java | 8 ++++---- .../r181/decoders/social/PrivateChatMessageDecoder.java | 7 +++++-- .../release/r181/decoders/social/PublicChatDecoder.java | 7 +++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java index 69895a64a..35e492287 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java @@ -45,7 +45,7 @@ private void buildHuffman(CacheBuffer data) { var tree = new int[8]; var codeFrequencies = data.getBuffer(); - var largestVisitedIndex = 0; + int largestVistedIndex = 0; while (data.getRemaining() > 0) { var position = data.getPosition(); var len = data.readByte(); @@ -91,7 +91,7 @@ private void buildHuffman(CacheBuffer data) { var bit = Integer.MIN_VALUE >>> shift; if ((code & bit) != 0) { if (tree[treeIndex] == 0) { - tree[treeIndex] = largestVisitedIndex; + tree[treeIndex] = largestVistedIndex; } treeIndex = tree[treeIndex]; @@ -108,8 +108,8 @@ private void buildHuffman(CacheBuffer data) { } tree[treeIndex] = ~position; - if (treeIndex >= largestVisitedIndex) { - largestVisitedIndex = treeIndex + 1; + if (treeIndex >= largestVistedIndex) { + largestVistedIndex = treeIndex + 1; } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java index 9c3b4f5ec..b2e752d8b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java @@ -20,14 +20,17 @@ public PrivateChatMessage decode(GamePacket packet) { String username = reader.getString(); - final var originalCompressed = new byte[reader.getLength()]; + final var length = reader.getLength(); + final var originalCompressed = new byte[length]; reader.getBytes(originalCompressed); String decompressed = HuffmanCodec.decompress(originalCompressed); decompressed = TextUtil.filterInvalidCharacters(decompressed); decompressed = TextUtil.capitalize(decompressed); - final var recompressed = HuffmanCodec.compress(decompressed); + final var recompressed = HuffmanCodec + .compress(decompressed, length); // in case invalid data gets sent, this effectively verifies it + return new PrivateChatMessage(decompressed, recompressed, username); } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java index a9b7434ea..8fee5ad2a 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java @@ -20,14 +20,17 @@ public PublicChatMessage decode(GamePacket packet) { final var color = (int) reader.getUnsigned(DataType.BYTE); final var effects = (int) reader.getUnsigned(DataType.BYTE); - final var originalCompressed = new byte[packet.getLength() - 3]; + final var length = packet.getLength() - 3; + + final var originalCompressed = new byte[length]; reader.getBytes(originalCompressed); String uncompressed = HuffmanCodec.decompress(originalCompressed); uncompressed = TextUtil.filterInvalidCharacters(uncompressed); uncompressed = TextUtil.capitalize(uncompressed); - final var recompressed = HuffmanCodec.compress(uncompressed); // in case invalid data gets sent, this effectively verifies it + final var recompressed = HuffmanCodec.compress(uncompressed, length); // in case invalid data gets sent, this effectively verifies it + return new PublicChatMessage(uncompressed, recompressed, color, effects, type); } } From 79ac1a80f47d092c7e2481354ec1c7ec157fe4f1 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 21 Apr 2020 23:44:25 -0400 Subject: [PATCH 59/63] Fixes issue with HuffmanCodec --- .../src/main/java/org/apollo/cache/def/HuffmanCodec.java | 4 ++-- .../org/apollo/game/fs/decoder/HuffmanCodecDecoder.java | 8 ++++---- .../r181/decoders/social/PrivateChatMessageDecoder.java | 7 ++----- .../release/r181/decoders/social/PublicChatDecoder.java | 7 ++----- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java index c9347e893..ff95824b7 100644 --- a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java +++ b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java @@ -15,8 +15,8 @@ public static String decompress(byte[] compressed) { return codec.decompress_(compressed); } - public static byte[] compress(String str, int length) { - return codec.compress_(str, length); + public static byte[] compress(String str) { + return codec.compress_(str, str.length() + 1); } /** diff --git a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java index 35e492287..69895a64a 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java @@ -45,7 +45,7 @@ private void buildHuffman(CacheBuffer data) { var tree = new int[8]; var codeFrequencies = data.getBuffer(); - int largestVistedIndex = 0; + var largestVisitedIndex = 0; while (data.getRemaining() > 0) { var position = data.getPosition(); var len = data.readByte(); @@ -91,7 +91,7 @@ private void buildHuffman(CacheBuffer data) { var bit = Integer.MIN_VALUE >>> shift; if ((code & bit) != 0) { if (tree[treeIndex] == 0) { - tree[treeIndex] = largestVistedIndex; + tree[treeIndex] = largestVisitedIndex; } treeIndex = tree[treeIndex]; @@ -108,8 +108,8 @@ private void buildHuffman(CacheBuffer data) { } tree[treeIndex] = ~position; - if (treeIndex >= largestVistedIndex) { - largestVistedIndex = treeIndex + 1; + if (treeIndex >= largestVisitedIndex) { + largestVisitedIndex = treeIndex + 1; } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java index b2e752d8b..9c3b4f5ec 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivateChatMessageDecoder.java @@ -20,17 +20,14 @@ public PrivateChatMessage decode(GamePacket packet) { String username = reader.getString(); - final var length = reader.getLength(); - final var originalCompressed = new byte[length]; + final var originalCompressed = new byte[reader.getLength()]; reader.getBytes(originalCompressed); String decompressed = HuffmanCodec.decompress(originalCompressed); decompressed = TextUtil.filterInvalidCharacters(decompressed); decompressed = TextUtil.capitalize(decompressed); - final var recompressed = HuffmanCodec - .compress(decompressed, length); // in case invalid data gets sent, this effectively verifies it - + final var recompressed = HuffmanCodec.compress(decompressed); return new PrivateChatMessage(decompressed, recompressed, username); } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java index 8fee5ad2a..a9b7434ea 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PublicChatDecoder.java @@ -20,17 +20,14 @@ public PublicChatMessage decode(GamePacket packet) { final var color = (int) reader.getUnsigned(DataType.BYTE); final var effects = (int) reader.getUnsigned(DataType.BYTE); - final var length = packet.getLength() - 3; - - final var originalCompressed = new byte[length]; + final var originalCompressed = new byte[packet.getLength() - 3]; reader.getBytes(originalCompressed); String uncompressed = HuffmanCodec.decompress(originalCompressed); uncompressed = TextUtil.filterInvalidCharacters(uncompressed); uncompressed = TextUtil.capitalize(uncompressed); - final var recompressed = HuffmanCodec.compress(uncompressed, length); // in case invalid data gets sent, this effectively verifies it - + final var recompressed = HuffmanCodec.compress(uncompressed); // in case invalid data gets sent, this effectively verifies it return new PublicChatMessage(uncompressed, recompressed, color, effects, type); } } From ba28a23d28d4c1209649286426091f2f7fd9d1f2 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Wed, 22 Apr 2020 00:40:28 -0400 Subject: [PATCH 60/63] Friends list interactions complete. --- game/data/messages.xml | 8 +++ .../src/messaging.plugin.kts | 6 ++- .../handler/PrivacyOptionMessageHandler.java | 32 ++++++++++++ ...essage.java => MessagePrivateMessage.java} | 8 +-- .../impl/decode/PrivacyOptionMessage.java | 12 ++--- .../encode/ChatFilterSettingsMessage.java | 24 ++++----- .../encode/MessagePrivateEchoMessage.java | 50 +++++++++++++++++++ .../encode/SetPrivateChatFilterMessage.java | 33 ++++++++++++ .../org/apollo/game/model/entity/Player.java | 4 +- .../apollo/game/release/r181/Release181.java | 21 ++++---- .../social/PrivacyOptionMessageDecoder.java | 8 +-- .../social/ChatFilterSettingsEncoder.java | 2 +- .../social/MessagePrivateEchoEncoder.java | 26 ++++++++++ ...ncoder.java => MessagePrivateEncoder.java} | 9 ++-- .../social/SetPrivateChatFilterEncoder.java | 20 ++++++++ 15 files changed, 218 insertions(+), 45 deletions(-) create mode 100644 game/src/main/java/org/apollo/game/message/handler/PrivacyOptionMessageHandler.java rename game/src/main/java/org/apollo/game/message/impl/{ForwardPrivateChatMessage.java => MessagePrivateMessage.java} (81%) create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/MessagePrivateEchoMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/encode/SetPrivateChatFilterMessage.java create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEchoEncoder.java rename game/src/main/java/org/apollo/game/release/r181/encoders/player/social/{ForwardPrivateChatMessageEncoder.java => MessagePrivateEncoder.java} (76%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SetPrivateChatFilterEncoder.java diff --git a/game/data/messages.xml b/game/data/messages.xml index 8928dc983..88b609c30 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -20,6 +20,14 @@ org.apollo.game.message.handler.PublicChatMessageHandler + + + org.apollo.game.message.impl.decode.PrivacyOptionMessage + + org.apollo.game.message.handler.PrivacyOptionMessageHandler + + + org.apollo.game.message.impl.decode.ClosedInterfaceMessage diff --git a/game/plugin/chat/private-messaging/src/messaging.plugin.kts b/game/plugin/chat/private-messaging/src/messaging.plugin.kts index d9fd21e92..0f0c91c90 100644 --- a/game/plugin/chat/private-messaging/src/messaging.plugin.kts +++ b/game/plugin/chat/private-messaging/src/messaging.plugin.kts @@ -1,5 +1,6 @@ -import org.apollo.game.message.impl.ForwardPrivateChatMessage +import org.apollo.game.message.impl.MessagePrivateMessage import org.apollo.game.message.impl.PrivateChatMessage +import org.apollo.game.message.impl.encode.MessagePrivateEchoMessage import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.setting.PrivacyState.OFF import org.apollo.game.model.entity.setting.PrivacyState.ON @@ -9,7 +10,8 @@ on { PrivateChatMessage::class } val friend = it.world.getPlayer(username) if (interactionPermitted(it, friend)) { - friend.send(ForwardPrivateChatMessage(it.username, it.privilegeLevel, compressedMessage)) + it.send(MessagePrivateEchoMessage(friend.username, compressedMessage)) + friend.send(MessagePrivateMessage(it.username, it.privilegeLevel, compressedMessage)) } } diff --git a/game/src/main/java/org/apollo/game/message/handler/PrivacyOptionMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/PrivacyOptionMessageHandler.java new file mode 100644 index 000000000..61ca56f11 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/handler/PrivacyOptionMessageHandler.java @@ -0,0 +1,32 @@ +package org.apollo.game.message.handler; + +import org.apollo.game.message.impl.decode.PrivacyOptionMessage; +import org.apollo.game.message.impl.encode.ChatFilterSettingsMessage; +import org.apollo.game.message.impl.encode.SetPrivateChatFilterMessage; +import org.apollo.game.model.World; +import org.apollo.game.model.entity.Player; + +/** + * @author Khaled Abdeljaber + */ +public class PrivacyOptionMessageHandler extends MessageHandler { + + /** + * Creates the MessageListener. + * + * @param world The {@link World} the {@link PrivacyOptionMessage} occurred in. + */ + public PrivacyOptionMessageHandler(World world) { + super(world); + } + + @Override + public void handle(Player player, PrivacyOptionMessage message) { + var chat = message.getChatPrivacy(); + var friend = message.getFriendPrivacy(); + var trade = message.getTradePrivacy(); + + player.send(new ChatFilterSettingsMessage(chat, trade)); + player.send(new SetPrivateChatFilterMessage(friend)); + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/MessagePrivateMessage.java similarity index 81% rename from game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java rename to game/src/main/java/org/apollo/game/message/impl/MessagePrivateMessage.java index a2a82b6ca..c26d54263 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/MessagePrivateMessage.java @@ -8,7 +8,7 @@ * * @author Major */ -public final class ForwardPrivateChatMessage extends Message { +public final class MessagePrivateMessage extends Message { /** * The username of the player sending the message. @@ -29,12 +29,12 @@ public final class ForwardPrivateChatMessage extends Message { * Creates a new forward private message message. * * @param username The username of the player sending the message. - * @param level The {@link PrivilegeLevel} of the player sending the message. + * @param privilege The {@link PrivilegeLevel} of the player sending the message. * @param message The compressed message. */ - public ForwardPrivateChatMessage(String username, PrivilegeLevel level, byte[] message) { + public MessagePrivateMessage(String username, PrivilegeLevel privilege, byte[] message) { this.username = username; - privilege = level; + this.privilege = privilege; this.message = message; } diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java index 047c783cf..bcfd10d69 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java @@ -16,7 +16,7 @@ public final class PrivacyOptionMessage extends ChatFilterSettingsMessage { /** * The privacy state of the player's trade chat. */ - private final PrivacyState tradePrivacy; + private final PrivacyState friendPrivacy; /** * Creates a privacy option message. @@ -26,17 +26,17 @@ public final class PrivacyOptionMessage extends ChatFilterSettingsMessage { * @param tradePrivacy The privacy state of the player's trade chat. */ public PrivacyOptionMessage(int chatPrivacy, int friendPrivacy, int tradePrivacy) { - super(chatPrivacy, friendPrivacy); - this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false); + super(chatPrivacy, tradePrivacy); + this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false); } /** - * Gets the trade {@link PrivacyState}. + * Gets the friend {@link PrivacyState}. * * @return The privacy state. */ - public PrivacyState getTradePrivacy() { - return tradePrivacy; + public PrivacyState getFriendPrivacy() { + return friendPrivacy; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java index 3825adb4d..964307015 100644 --- a/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java @@ -16,28 +16,28 @@ public class ChatFilterSettingsMessage extends Message { /** * The privacy state of the player's friend chat. */ - private final PrivacyState friendPrivacy; + private final PrivacyState tradePrivacy; /** * Creates a privacy option message. * - * @param chatPrivacy The privacy state of the player's chat. - * @param friendPrivacy The privacy state of the player's friend chat. + * @param chatPrivacy The privacy state of the player's chat. + * @param tradePrivacy The privacy state of the player's trade chat. */ - public ChatFilterSettingsMessage(int chatPrivacy, int friendPrivacy) { + public ChatFilterSettingsMessage(int chatPrivacy, int tradePrivacy) { this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true); - this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false); + this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false); } /** * Creates a privacy option message. * - * @param chatPrivacy The privacy state of the player's chat. - * @param friendPrivacy The privacy state of the player's friend chat. + * @param chatPrivacy The privacy state of the player's chat. + * @param tradePrivacy The privacy state of the player's trade chat. */ - public ChatFilterSettingsMessage(PrivacyState chatPrivacy, PrivacyState friendPrivacy) { + public ChatFilterSettingsMessage(PrivacyState chatPrivacy, PrivacyState tradePrivacy) { this.chatPrivacy = chatPrivacy; - this.friendPrivacy = chatPrivacy; + this.tradePrivacy = tradePrivacy; } /** @@ -50,11 +50,11 @@ public PrivacyState getChatPrivacy() { } /** - * Gets the friend {@link PrivacyState}. + * Gets the trade {@link PrivacyState}. * * @return The privacy state. */ - public PrivacyState getFriendPrivacy() { - return friendPrivacy; + public PrivacyState getTradePrivacy() { + return tradePrivacy; } } diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/MessagePrivateEchoMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/MessagePrivateEchoMessage.java new file mode 100644 index 000000000..798ec767d --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/MessagePrivateEchoMessage.java @@ -0,0 +1,50 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type Message private message. + * + * @author Khaled Abdeljaber + */ +public class MessagePrivateEchoMessage extends Message { + + /** + * The username of the player sending the message. + */ + private final String username; + + /** + * The message. + */ + private final byte[] message; + + /** + * Creates a new forward private message message. + * + * @param username The username of the player sending the message. + * @param message The compressed message. + */ + public MessagePrivateEchoMessage(String username, byte[] message) { + this.username = username; + this.message = message; + } + + /** + * Gets username. + * + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * Get message byte [ ]. + * + * @return the byte [ ] + */ + public byte[] getMessage() { + return message; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/SetPrivateChatFilterMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SetPrivateChatFilterMessage.java new file mode 100644 index 000000000..0794a3516 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SetPrivateChatFilterMessage.java @@ -0,0 +1,33 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.setting.PrivacyState; +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class SetPrivateChatFilterMessage extends Message { + + /** + * The privacy state of the player's trade chat. + */ + private final PrivacyState friendPrivacy; + + /** + * Creates a privacy option message. + * + * @param friendPrivacy The privacy state of the player's friend chat. + */ + public SetPrivateChatFilterMessage(PrivacyState friendPrivacy) { + this.friendPrivacy = friendPrivacy; + } + + /** + * Gets the friend {@link PrivacyState}. + * + * @return The privacy state. + */ + public PrivacyState getFriendPrivacy() { + return friendPrivacy; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index e650a8f1b..eabd8f28d 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -29,6 +29,7 @@ import org.apollo.game.sync.block.SynchronizationBlock; import org.apollo.net.message.Message; import org.apollo.util.CollectionUtil; +import org.apollo.util.TextUtil; import org.apollo.util.security.PlayerCredentials; import java.util.*; @@ -751,6 +752,7 @@ public void sendInitialMessages(DisplayMode mode) { send(new ConfigMessage(1737, 1 << 31)); send(new ChatFilterSettingsMessage(chatPrivacy, friendPrivacy)); + send(new ChatFilterSettingsMessage(chatPrivacy, friendPrivacy)); inventory.forceRefresh(); equipment.forceRefresh(); @@ -799,7 +801,7 @@ public void sendUserLists() { var username = friends.get(index); var worldId = world.isPlayerOnline(username) ? world.getPlayer(username).worldId : 0; - components[index] = new FriendMessageComponent(username, worldId); + components[index] = new FriendMessageComponent(TextUtil.capitalize(username), worldId); } send(new SendFriendMessage(components)); diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index 112e32ce2..ef9ae13bd 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -1,18 +1,10 @@ package org.apollo.game.release.r181; -import org.apollo.game.message.impl.ForwardPrivateChatMessage; +import org.apollo.game.message.impl.MessagePrivateMessage; import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.encode.SendProjectileMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; -import org.apollo.game.release.r181.decoders.social.PublicChatDecoder; -import org.apollo.game.release.r181.encoders.game.LogoutEncoder; -import org.apollo.game.release.r181.encoders.player.PlayerSynchronizationMessageEncoder; -import org.apollo.game.release.r181.encoders.player.social.ForwardPrivateChatMessageEncoder; -import org.apollo.game.release.r181.encoders.player.social.FriendListUnlockEncoder; -import org.apollo.game.release.r181.encoders.player.social.SendFriendMessageEncoder; -import org.apollo.game.release.r181.encoders.region.*; import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; import org.apollo.game.release.r181.decoders.map.item.*; import org.apollo.game.release.r181.decoders.map.npc.actions.*; @@ -22,6 +14,7 @@ import org.apollo.game.release.r181.decoders.map.player.actions.*; import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; import org.apollo.game.release.r181.decoders.social.PrivateChatMessageDecoder; +import org.apollo.game.release.r181.decoders.social.PublicChatDecoder; import org.apollo.game.release.r181.decoders.social.friends.AddFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; @@ -35,8 +28,12 @@ import org.apollo.game.release.r181.encoders.UpdateRunEnergyMessageEncoder; import org.apollo.game.release.r181.encoders.UpdateSkillMessageEncoder; import org.apollo.game.release.r181.encoders.UpdateWeightMessageEncoder; +import org.apollo.game.release.r181.encoders.game.LogoutEncoder; import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; +import org.apollo.game.release.r181.encoders.player.PlayerSynchronizationMessageEncoder; import org.apollo.game.release.r181.encoders.player.SetPlayerActionMessageEncoder; +import org.apollo.game.release.r181.encoders.player.social.*; +import org.apollo.game.release.r181.encoders.region.*; import org.apollo.game.release.r181.encoders.ui.*; import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerFullMessageEncoder; import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerPartialMessageEncoder; @@ -218,7 +215,11 @@ private void init() { register(ServerChatMessage.class, new ServerChatMessageEncoder()); register(SendFriendMessage.class, new SendFriendMessageEncoder()); register(FriendListUnlockMessage.class, new FriendListUnlockEncoder()); - register(ForwardPrivateChatMessage.class, new ForwardPrivateChatMessageEncoder()); + register(MessagePrivateMessage.class, new MessagePrivateEncoder()); + register(MessagePrivateEchoMessage.class, new MessagePrivateEchoEncoder()); + + register(SetPrivateChatFilterMessage.class, new SetPrivateChatFilterEncoder()); + register(ChatFilterSettingsMessage.class, new ChatFilterSettingsEncoder()); /** diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java index e2ee3cf36..63827762e 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java @@ -17,11 +17,11 @@ public final class PrivacyOptionMessageDecoder extends MessageDecoder { + + @Override + public GamePacket encode(MessagePrivateEchoMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(38, PacketType.VARIABLE_SHORT); + + builder.putString(message.getUsername()); + builder.putBytes(message.getMessage()); + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEncoder.java similarity index 76% rename from game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEncoder.java index 1f7d05afe..39b8b73d1 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ForwardPrivateChatMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEncoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.encoders.player.social; -import org.apollo.game.message.impl.ForwardPrivateChatMessage; +import org.apollo.game.message.impl.MessagePrivateMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; @@ -10,11 +10,11 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * A {@link MessageEncoder} for the {@link ForwardPrivateChatMessage}. + * A {@link MessageEncoder} for the {@link MessagePrivateMessage}. * * @author Major */ -public final class ForwardPrivateChatMessageEncoder extends MessageEncoder { +public final class MessagePrivateEncoder extends MessageEncoder { /** * The amount of messages sent globally, offset by a random variable x, {@code 0 <= x < 100,000,000}. @@ -22,7 +22,7 @@ public final class ForwardPrivateChatMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(SetPrivateChatFilterMessage message) { + final var builder = new GamePacketBuilder(68, PacketType.FIXED); + builder.put(DataType.BYTE, message.getFriendPrivacy().toInteger(true)); + return builder.toGamePacket(); + } +} From e393743923586fec545727d6956bbdaabcf2d4f8 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Wed, 22 Apr 2020 18:15:42 -0400 Subject: [PATCH 61/63] Ignores list complete. --- .../private-messaging/src/friends.plugin.kts | 38 ++++++++---- .../private-messaging/src/ignores.plugin.kts | 19 ++++-- .../game/message/impl/IgnoreListMessage.java | 37 ------------ .../message/impl/UpdateIgnoreListMessage.java | 60 +++++++++++++++++++ .../org/apollo/game/model/entity/Player.java | 31 ++++++---- .../apollo/game/release/r181/Release181.java | 4 +- ...ageEncoder.java => SendFriendEncoder.java} | 2 +- .../social/UpdateIgnoreListEncoder.java | 30 ++++++++++ 8 files changed, 154 insertions(+), 67 deletions(-) delete mode 100644 game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java create mode 100644 game/src/main/java/org/apollo/game/message/impl/UpdateIgnoreListMessage.java rename game/src/main/java/org/apollo/game/release/r181/encoders/player/social/{SendFriendMessageEncoder.java => SendFriendEncoder.java} (92%) create mode 100644 game/src/main/java/org/apollo/game/release/r181/encoders/player/social/UpdateIgnoreListEncoder.java diff --git a/game/plugin/chat/private-messaging/src/friends.plugin.kts b/game/plugin/chat/private-messaging/src/friends.plugin.kts index 14b58fa46..c8dab95c1 100644 --- a/game/plugin/chat/private-messaging/src/friends.plugin.kts +++ b/game/plugin/chat/private-messaging/src/friends.plugin.kts @@ -1,27 +1,39 @@ import org.apollo.game.message.impl.SendFriendMessage import org.apollo.game.message.impl.SendFriendMessage.FriendMessageComponent import org.apollo.game.message.impl.decode.AddFriendMessage +import org.apollo.game.message.impl.decode.RemoveFriendMessage import org.apollo.game.model.entity.setting.PrivacyState import org.apollo.game.model.event.impl.LoginEvent +import org.apollo.game.model.inter.TopLevelPosition +import org.apollo.game.plugin.kotlin.message.IfAction +import org.apollo.game.plugin.kotlin.message.on + +on(IfAction, inter = TopLevelPosition.FRIENDS_TAB.interfaceId, comp = 1) { + player.interfaceSet.openTopLevel(432, TopLevelPosition.FRIENDS_TAB) +} + on_player_event { LoginEvent::class }.then { player.sendUserLists(); } -on { AddFriendMessage::class } - .then { - it.addFriend(username) +on { AddFriendMessage::class }.then { + it.addFriend(username) - val friend = it.world.getPlayer(username) + val friend = it.world.getPlayer(username) - if (friend == null || friend.friendPrivacy == PrivacyState.OFF) { - it.send(SendFriendMessage(FriendMessageComponent(username, 0))) - return@then - } else { - it.send(SendFriendMessage(FriendMessageComponent(username, friend.worldId))) - } + if (friend == null || friend.friendPrivacy == PrivacyState.OFF) { + it.send(SendFriendMessage(FriendMessageComponent(username, 0))) + return@then + } else { + it.send(SendFriendMessage(FriendMessageComponent(username, friend.worldId))) + } - if (friend.friendsWith(it.username) && it.friendPrivacy != PrivacyState.OFF) { - friend.send(SendFriendMessage(FriendMessageComponent(it.username, it.worldId))) - } + if (friend.friendsWith(it.username) && it.friendPrivacy != PrivacyState.OFF) { + friend.send(SendFriendMessage(FriendMessageComponent(it.username, it.worldId))) } +} +on { RemoveFriendMessage::class }.then { + it.removeFriend(username) +} + diff --git a/game/plugin/chat/private-messaging/src/ignores.plugin.kts b/game/plugin/chat/private-messaging/src/ignores.plugin.kts index 1afbed3b9..d07feddd1 100644 --- a/game/plugin/chat/private-messaging/src/ignores.plugin.kts +++ b/game/plugin/chat/private-messaging/src/ignores.plugin.kts @@ -1,8 +1,19 @@ +import org.apollo.game.message.impl.UpdateIgnoreListMessage import org.apollo.game.message.impl.decode.AddIgnoreMessage import org.apollo.game.message.impl.decode.RemoveIgnoreMessage +import org.apollo.game.model.inter.TopLevelPosition +import org.apollo.game.plugin.kotlin.message.IfAction +import org.apollo.game.plugin.kotlin.message.on -on { AddIgnoreMessage::class } - .then { it.addIgnore(username) } +on(IfAction, inter = 432, comp = 1) { + player.interfaceSet.openTopLevel(TopLevelPosition.FRIENDS_TAB) +} -on { RemoveIgnoreMessage::class } - .then { it.removeIgnore(username) } \ No newline at end of file +on { AddIgnoreMessage::class }.then { + it.addIgnore(username) + it.send(UpdateIgnoreListMessage(UpdateIgnoreListMessage.IgnoreMessageComponent(username))) +} + +on { RemoveIgnoreMessage::class }.then { + it.removeIgnore(username) +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java b/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java deleted file mode 100644 index 127f735d1..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -import java.util.List; - -/** - * A {@link Message} sent to the client that updates the ignored user list. - * - * @author Major - */ -public final class IgnoreListMessage extends Message { - - /** - * The list of ignored player usernames. - */ - private final List usernames; - - /** - * Creates a new ignore list message. - * - * @param usernames The {@link List} of usernames to send. - */ - public IgnoreListMessage(List usernames) { - this.usernames = usernames; - } - - /** - * Gets the list of ignored usernames. - * - * @return The usernames. - */ - public List getUsernames() { - return usernames; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateIgnoreListMessage.java b/game/src/main/java/org/apollo/game/message/impl/UpdateIgnoreListMessage.java new file mode 100644 index 000000000..50c0a5f23 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/UpdateIgnoreListMessage.java @@ -0,0 +1,60 @@ +package org.apollo.game.message.impl; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client that updates the ignored user list. + * + * @author Major + */ +public final class UpdateIgnoreListMessage extends Message { + + public static final class IgnoreMessageComponent { + /** + * The username of the ignored player. + */ + private final String username; + + /** + * Creates a new ignore player message. + * + * @param username The ignored player's username. + */ + public IgnoreMessageComponent(String username) { + this.username = username; + } + + /** + * Gets the username of the ignored player. + * + * @return The username. + */ + public String getUsername() { + return username; + } + + } + + /** + * The components that build the message. + */ + private final IgnoreMessageComponent[] components; + + /** + * Instantiates a new Send friend message. + * + * @param components the components + */ + public UpdateIgnoreListMessage(IgnoreMessageComponent... components) { + this.components = components; + } + + /** + * Get components friend message component [ ]. + * + * @return the friend message component [ ] + */ + public IgnoreMessageComponent[] getComponents() { + return components; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index eabd8f28d..1b7b5811d 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -2,9 +2,10 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import org.apollo.game.message.impl.IgnoreListMessage; import org.apollo.game.message.impl.SendFriendMessage; import org.apollo.game.message.impl.SendFriendMessage.FriendMessageComponent; +import org.apollo.game.message.impl.UpdateIgnoreListMessage; +import org.apollo.game.message.impl.UpdateIgnoreListMessage.IgnoreMessageComponent; import org.apollo.game.message.impl.encode.*; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; @@ -790,21 +791,29 @@ public void sendQuestInterface(List text) { * Sends the friend and ignore user lists. */ public void sendUserLists() { - if (!ignores.isEmpty()) { - send(new IgnoreListMessage(ignores)); - } - send(new FriendListUnlockMessage()); + { + final var components = new IgnoreMessageComponent[ignores.size()]; + for (int index = 0; index < components.length; index++) { + var username = ignores.get(index); - FriendMessageComponent[] components = new FriendMessageComponent[friends.size()]; - for (int index = 0; index < components.length; index++) { - var username = friends.get(index); - var worldId = world.isPlayerOnline(username) ? world.getPlayer(username).worldId : 0; + components[index] = new IgnoreMessageComponent(username); + } - components[index] = new FriendMessageComponent(TextUtil.capitalize(username), worldId); + send(new UpdateIgnoreListMessage(components)); } - send(new SendFriendMessage(components)); + send(new FriendListUnlockMessage()); + { + final var components = new FriendMessageComponent[friends.size()]; + for (int index = 0; index < components.length; index++) { + var username = friends.get(index); + var worldId = world.isPlayerOnline(username) ? world.getPlayer(username).worldId : 0; + + components[index] = new FriendMessageComponent(username, worldId); + } + send(new SendFriendMessage(components)); + } } /** diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index ef9ae13bd..a8c96d4d3 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -2,6 +2,7 @@ import org.apollo.game.message.impl.MessagePrivateMessage; import org.apollo.game.message.impl.SendFriendMessage; +import org.apollo.game.message.impl.UpdateIgnoreListMessage; import org.apollo.game.message.impl.encode.*; import org.apollo.game.release.r181.decoders.*; import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; @@ -213,8 +214,9 @@ private void init() { register(ConfigMessage.class, new ConfigMessageEncoder()); register(ServerChatMessage.class, new ServerChatMessageEncoder()); - register(SendFriendMessage.class, new SendFriendMessageEncoder()); + register(SendFriendMessage.class, new SendFriendEncoder()); register(FriendListUnlockMessage.class, new FriendListUnlockEncoder()); + register(UpdateIgnoreListMessage.class, new UpdateIgnoreListEncoder()); register(MessagePrivateMessage.class, new MessagePrivateEncoder()); register(MessagePrivateEchoMessage.class, new MessagePrivateEchoEncoder()); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendEncoder.java similarity index 92% rename from game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendEncoder.java index 05fc38000..ee829cce3 100644 --- a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendEncoder.java @@ -10,7 +10,7 @@ /** * @author Khaled Abdeljaber */ -public final class SendFriendMessageEncoder extends MessageEncoder { +public final class SendFriendEncoder extends MessageEncoder { @Override public GamePacket encode(SendFriendMessage message) { diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/UpdateIgnoreListEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/UpdateIgnoreListEncoder.java new file mode 100644 index 000000000..1b8ef9a4a --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/UpdateIgnoreListEncoder.java @@ -0,0 +1,30 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.UpdateIgnoreListMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public final class UpdateIgnoreListEncoder extends MessageEncoder { + + @Override + public GamePacket encode(UpdateIgnoreListMessage message) { + final var builder = new GamePacketBuilder(32, PacketType.VARIABLE_SHORT); + final var components = message.getComponents(); + + for (var component : components) { + builder.put(DataType.BYTE, 0x0); // If you're updating this player or something + builder.putString(component.getUsername()); // Display name + builder.putString(""); // Previous display name + builder.putString("");// Notes, not used in osrs + } + + return builder.toGamePacket(); + } + +} \ No newline at end of file From bfb2619d7cb1d6df6f25fa152d5823aeea4efef8 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Sat, 25 Apr 2020 23:10:13 -0400 Subject: [PATCH 62/63] All the changes that sfix has asked for. --- cache/build.gradle | 2 +- .../decoder/ObjectDefinitionDecoder.java | 14 +- .../decoder/rsenum/EnumDefinitionDecoder.java | 8 +- .../org/apollo/cache/def/EnumDefinition.java | 14 +- .../apollo/cache/def/ObjectDefinition.java | 50 +- .../org/apollo/cache/map/XteaRepository.java | 10 +- game/build.gradle | 1 - game/data/messages.xml | 2 +- game/data/plugins/.rubocop.yml | 36 ++ game/data/plugins/areas/actions.rb | 49 ++ game/data/plugins/areas/areas.rb | 108 ++++ game/data/plugins/areas/plugin.xml | 15 + game/data/plugins/bank/bank.rb | 47 ++ game/data/plugins/bank/plugin.xml | 14 + game/data/plugins/bootstrap.rb | 239 ++++++++ game/data/plugins/chat/privacy/plugin.xml | 16 + game/data/plugins/chat/privacy/privacy.rb | 12 + .../plugins/chat/private-messaging/friend.rb | 102 ++++ .../plugins/chat/private-messaging/ignore.rb | 9 + .../chat/private-messaging/messaging.rb | 23 + .../plugins/chat/private-messaging/plugin.xml | 16 + game/data/plugins/cmd/animate/animate.rb | 20 + game/data/plugins/cmd/animate/plugin.xml | 14 + game/data/plugins/cmd/bank/bank.rb | 6 + game/data/plugins/cmd/bank/plugin.xml | 14 + game/data/plugins/cmd/item/item.rb | 45 ++ game/data/plugins/cmd/item/plugin.xml | 14 + game/data/plugins/cmd/lookup/lookup.rb | 69 +++ game/data/plugins/cmd/lookup/plugin.xml | 16 + game/data/plugins/cmd/messaging/broadcast.rb | 12 + game/data/plugins/cmd/messaging/plugin.xml | 15 + game/data/plugins/cmd/npc/plugin.xml | 14 + game/data/plugins/cmd/npc/spawn.rb | 68 +++ game/data/plugins/cmd/punishment/plugin.xml | 14 + game/data/plugins/cmd/punishment/punish.rb | 53 ++ game/data/plugins/cmd/skill/plugin.xml | 15 + game/data/plugins/cmd/skill/skill.rb | 44 ++ game/data/plugins/cmd/teleport/plugin.xml | 14 + game/data/plugins/cmd/teleport/teleport.rb | 20 + game/data/plugins/combat/plugin.xml | 17 + game/data/plugins/combat/wilderness.rb | 66 ++ game/data/plugins/consumables/consumable.rb | 79 +++ game/data/plugins/consumables/drink.rb | 76 +++ game/data/plugins/consumables/food.rb | 221 +++++++ game/data/plugins/consumables/plugin.xml | 17 + game/data/plugins/consumables/potions.rb | 136 +++++ game/data/plugins/dialogue/dialogue.rb | 567 ++++++++++++++++++ game/data/plugins/dialogue/emotes.rb | 31 + game/data/plugins/dialogue/plugin.xml | 17 + game/data/plugins/dummy/dummy.rb | 51 ++ game/data/plugins/dummy/plugin.xml | 14 + game/data/plugins/emote-tab/emote_tab.rb | 57 ++ game/data/plugins/emote-tab/plugin.xml | 14 + .../plugins/entity/attributes/attributes.rb | 79 +++ .../data/plugins/entity/attributes/plugin.xml | 14 + .../plugins/entity/mob/extension/extension.rb | 20 + .../plugins/entity/mob/extension/plugin.xml | 15 + .../plugins/entity/mob/following/following.rb | 58 ++ .../plugins/entity/mob/following/plugin.xml | 16 + .../plugins/entity/mob/walk-to/plugin.xml | 16 + .../plugins/entity/mob/walk-to/walk_to.rb | 83 +++ .../data/plugins/entity/spawning/npc-spawn.rb | 197 ++++++ game/data/plugins/entity/spawning/plugin.xml | 16 + game/data/plugins/location/al-kharid/npcs.rb | 89 +++ .../plugins/location/al-kharid/plugin.xml | 16 + game/data/plugins/location/edgeville/npcs.rb | 45 ++ .../plugins/location/edgeville/plugin.xml | 17 + game/data/plugins/location/falador/npcs.rb | 157 +++++ game/data/plugins/location/falador/plugin.xml | 16 + game/data/plugins/location/lumbridge/npcs.rb | 16 + .../plugins/location/lumbridge/plugin.xml | 16 + .../plugins/location/tutorial-island/guide.rb | 158 +++++ .../location/tutorial-island/instructions.rb | 141 +++++ .../plugins/location/tutorial-island/npcs.rb | 40 ++ .../location/tutorial-island/plugin.xml | 24 + .../location/tutorial-island/stages.rb | 16 + .../location/tutorial-island/survival.rb | 154 +++++ .../plugins/location/tutorial-island/utils.rb | 30 + game/data/plugins/location/varrock/npcs.rb | 258 ++++++++ game/data/plugins/location/varrock/plugin.xml | 18 + game/data/plugins/location/varrock/shops.rb | 44 ++ game/data/plugins/logout/logout.rb | 5 + game/data/plugins/logout/plugin.xml | 14 + .../data/plugins/navigation/door/constants.rb | 44 ++ game/data/plugins/navigation/door/door.rb | 54 ++ game/data/plugins/navigation/door/plugin.xml | 16 + game/data/plugins/navigation/door/util.rb | 83 +++ game/data/plugins/player-action/action.rb | 61 ++ game/data/plugins/player-action/login.rb | 6 + game/data/plugins/player-action/plugin.xml | 15 + game/data/plugins/quest/plugin.xml | 16 + game/data/plugins/quest/repository.rb | 132 ++++ game/data/plugins/run/plugin.xml | 16 + game/data/plugins/run/run.rb | 10 + game/data/plugins/shops/currency.rb | 35 ++ game/data/plugins/shops/plugin.xml | 20 + game/data/plugins/shops/shop.rb | 28 + game/data/plugins/shops/shop_item.rb | 20 + game/data/plugins/shops/shops.rb | 301 ++++++++++ game/data/plugins/skill/fishing/fish.rb | 41 ++ game/data/plugins/skill/fishing/fishing.rb | 120 ++++ game/data/plugins/skill/fishing/plugin.xml | 20 + game/data/plugins/skill/fishing/spot.rb | 26 + game/data/plugins/skill/fishing/tool.rb | 60 ++ game/data/plugins/skill/herblore/herb.rb | 95 +++ game/data/plugins/skill/herblore/herblore.rb | 102 ++++ .../data/plugins/skill/herblore/ingredient.rb | 251 ++++++++ game/data/plugins/skill/herblore/plugin.xml | 18 + game/data/plugins/skill/herblore/potion.rb | 372 ++++++++++++ game/data/plugins/skill/magic/alchemy.rb | 81 +++ game/data/plugins/skill/magic/convert.rb | 89 +++ game/data/plugins/skill/magic/element.rb | 107 ++++ game/data/plugins/skill/magic/enchant.rb | 106 ++++ game/data/plugins/skill/magic/magic.rb | 172 ++++++ game/data/plugins/skill/magic/plugin.xml | 20 + game/data/plugins/skill/magic/teleport.rb | 101 ++++ game/data/plugins/skill/mining/gem.rb | 20 + game/data/plugins/skill/mining/mining.rb | 155 +++++ game/data/plugins/skill/mining/ore.rb | 95 +++ game/data/plugins/skill/mining/pickaxe.rb | 33 + game/data/plugins/skill/mining/plugin.xml | 24 + game/data/plugins/skill/mining/respawn.rb | 16 + game/data/plugins/skill/prayer/bury.rb | 89 +++ game/data/plugins/skill/prayer/plugin.xml | 18 + game/data/plugins/skill/prayer/prayers.rb | 88 +++ game/data/plugins/skill/runecraft/altar.rb | 129 ++++ game/data/plugins/skill/runecraft/plugin.xml | 21 + game/data/plugins/skill/runecraft/rune.rb | 52 ++ .../data/plugins/skill/runecraft/runecraft.rb | 58 ++ game/data/plugins/skill/runecraft/talisman.rb | 54 ++ game/data/plugins/skill/runecraft/tiara.rb | 167 ++++++ game/data/plugins/util/command.rb | 44 ++ game/data/plugins/util/name_lookup.rb | 50 ++ game/data/plugins/util/plugin.xml | 15 + game/plugin/emote-tab/src/EmoteTab.plugin.kts | 4 +- game/plugin/logout/test/LogoutTests.kt | 4 +- game/plugin/run/src/run.plugin.kts | 4 +- .../skills/prayer/src/Prayer.plugin.kts | 4 +- game/plugin/skills/woodcutting/build.gradle | 1 - game/src/main/java/org/apollo/Server.java | 22 +- .../main/java/org/apollo/ServiceManager.java | 4 +- .../org/apollo/game/GamePulseHandler.java | 4 +- .../game/command/CommandDispatcher.java | 4 +- .../game/command/CreditsCommandListener.java | 7 +- .../game/fs/decoder/SynchronousDecoder.java | 10 +- .../game/io/EquipmentDefinitionParser.java | 9 +- .../game/io/MessageHandlerChainSetParser.java | 6 +- .../apollo/game/io/PluginMetaDataParser.java | 10 +- .../io/player/BinaryPlayerSerializer.java | 38 +- .../game/io/player/PlayerLoaderResponse.java | 5 +- .../apollo/game/login/PlayerLoaderWorker.java | 6 +- .../apollo/game/login/PlayerSaverWorker.java | 6 +- .../handler/BankButtonMessageHandler.java | 10 +- .../message/handler/BankMessageHandler.java | 2 - .../handler/DialogueButtonHandler.java | 8 +- .../message/handler/MessageHandlerChain.java | 7 +- .../handler/MessageHandlerChainSet.java | 6 +- .../ObjectActionVerificationHandler.java | 6 +- .../handler/RemoveEquippedItemHandler.java | 8 +- .../message/impl/DialogueContinueMessage.java | 2 +- .../impl/DisplayTabInterfaceMessage.java | 2 +- ...fActionMessage.java => ButtonMessage.java} | 4 +- .../org/apollo/game/model/Appearance.java | 3 +- .../main/java/org/apollo/game/model/Item.java | 3 +- .../java/org/apollo/game/model/Position.java | 5 +- .../java/org/apollo/game/model/World.java | 16 +- .../org/apollo/game/model/area/Region.java | 7 +- .../game/model/area/RegionCoordinates.java | 3 +- .../game/model/area/RegionRepository.java | 11 +- .../model/area/update/UpdateOperation.java | 3 +- .../org/apollo/game/model/entity/Mob.java | 14 +- .../org/apollo/game/model/entity/Npc.java | 7 +- .../org/apollo/game/model/entity/Player.java | 32 +- .../apollo/game/model/entity/SkillSet.java | 9 +- .../game/model/entity/WalkingQueue.java | 5 + .../game/model/entity/attr/AttributeMap.java | 5 +- .../model/entity/obj/DynamicGameObject.java | 6 +- .../game/model/entity/obj/GameObject.java | 5 +- .../path/AStarPathfindingAlgorithm.java | 11 +- .../model/entity/path/ManhattanHeuristic.java | 2 +- .../apollo/game/model/entity/path/Node.java | 7 +- .../entity/path/PathfindingAlgorithm.java | 10 +- .../path/SimplePathfindingAlgorithm.java | 10 +- .../game/model/event/EventListenerChain.java | 4 +- .../apollo/game/model/inter/InterfaceSet.java | 15 +- .../game/plugin/KotlinPluginEnvironment.java | 12 +- .../org/apollo/game/plugin/PluginManager.java | 8 +- .../ui/if1/FifthIf1ActionMessageDecoder.java | 8 +- .../ui/if1/FirstIf1ActionMessageDecoder.java | 8 +- .../ui/if1/FourthIf1ActionMessageDecoder.java | 8 +- .../ui/if1/SecondIf1ActionMessageDecoder.java | 8 +- .../ui/if1/ThirdIf1ActionMessageDecoder.java | 8 +- .../ui/if3/If3ActionMessageDecoder.java | 8 +- .../org/apollo/game/scheduling/Scheduler.java | 6 +- .../game/scheduling/impl/NpcMovementTask.java | 11 +- .../org/apollo/game/service/GameService.java | 18 +- .../org/apollo/game/service/LoginService.java | 13 +- .../apollo/game/session/ApolloHandler.java | 8 +- .../org/apollo/game/session/GameSession.java | 11 +- .../org/apollo/game/session/LoginSession.java | 13 +- .../game/sync/ParallelClientSynchronizer.java | 9 +- .../sync/SequentialClientSynchronizer.java | 17 +- .../game/sync/block/AnimationBlock.java | 1 - .../game/sync/block/AppearanceBlock.java | 1 - .../org/apollo/game/sync/block/ChatBlock.java | 1 - .../game/sync/block/ForceChatBlock.java | 2 - .../game/sync/block/ForceMovementBlock.java | 1 - .../apollo/game/sync/block/GraphicBlock.java | 1 - .../game/sync/block/HitUpdateBlock.java | 2 - .../game/sync/block/InteractingMobBlock.java | 2 - .../sync/block/SecondaryHitUpdateBlock.java | 2 - .../game/sync/block/TransformBlock.java | 2 - .../game/sync/block/TurnToPositionBlock.java | 1 - .../apollo/game/sync/seg/MovementSegment.java | 3 +- .../sync/task/NpcSynchronizationTask.java | 12 +- .../sync/task/PlayerSynchronizationTask.java | 5 +- .../org/apollo/game/action/ActionCoroutine.kt | 4 +- .../game/plugin/kotlin/KotlinPluginScript.kt | 8 +- .../game/plugin/kotlin/message/IfAction.kt | 14 +- .../ItemOnItemVerificationHandlerTests.java | 3 +- .../ItemOnObjectVerificationHandlerTests.java | 1 + .../ObjectActionVerificationHandlerTests.java | 7 +- .../PublicChatMessageHandlerTests.java | 4 +- .../game/model/entity/SkillSetTests.java | 2 +- .../game/model/entity/WalkingQueueTests.java | 1 + .../model/entity/attr/AttributeTests.java | 5 +- .../net/codec/game/GamePacketBuilder.java | 7 +- .../net/codec/handshake/HandshakeDecoder.java | 8 +- 228 files changed, 8509 insertions(+), 332 deletions(-) create mode 100644 game/data/plugins/.rubocop.yml create mode 100644 game/data/plugins/areas/actions.rb create mode 100644 game/data/plugins/areas/areas.rb create mode 100644 game/data/plugins/areas/plugin.xml create mode 100644 game/data/plugins/bank/bank.rb create mode 100644 game/data/plugins/bank/plugin.xml create mode 100644 game/data/plugins/bootstrap.rb create mode 100644 game/data/plugins/chat/privacy/plugin.xml create mode 100644 game/data/plugins/chat/privacy/privacy.rb create mode 100644 game/data/plugins/chat/private-messaging/friend.rb create mode 100644 game/data/plugins/chat/private-messaging/ignore.rb create mode 100644 game/data/plugins/chat/private-messaging/messaging.rb create mode 100644 game/data/plugins/chat/private-messaging/plugin.xml create mode 100644 game/data/plugins/cmd/animate/animate.rb create mode 100644 game/data/plugins/cmd/animate/plugin.xml create mode 100644 game/data/plugins/cmd/bank/bank.rb create mode 100644 game/data/plugins/cmd/bank/plugin.xml create mode 100644 game/data/plugins/cmd/item/item.rb create mode 100644 game/data/plugins/cmd/item/plugin.xml create mode 100644 game/data/plugins/cmd/lookup/lookup.rb create mode 100644 game/data/plugins/cmd/lookup/plugin.xml create mode 100644 game/data/plugins/cmd/messaging/broadcast.rb create mode 100644 game/data/plugins/cmd/messaging/plugin.xml create mode 100644 game/data/plugins/cmd/npc/plugin.xml create mode 100644 game/data/plugins/cmd/npc/spawn.rb create mode 100644 game/data/plugins/cmd/punishment/plugin.xml create mode 100644 game/data/plugins/cmd/punishment/punish.rb create mode 100644 game/data/plugins/cmd/skill/plugin.xml create mode 100644 game/data/plugins/cmd/skill/skill.rb create mode 100644 game/data/plugins/cmd/teleport/plugin.xml create mode 100644 game/data/plugins/cmd/teleport/teleport.rb create mode 100644 game/data/plugins/combat/plugin.xml create mode 100644 game/data/plugins/combat/wilderness.rb create mode 100644 game/data/plugins/consumables/consumable.rb create mode 100644 game/data/plugins/consumables/drink.rb create mode 100644 game/data/plugins/consumables/food.rb create mode 100644 game/data/plugins/consumables/plugin.xml create mode 100644 game/data/plugins/consumables/potions.rb create mode 100644 game/data/plugins/dialogue/dialogue.rb create mode 100644 game/data/plugins/dialogue/emotes.rb create mode 100644 game/data/plugins/dialogue/plugin.xml create mode 100644 game/data/plugins/dummy/dummy.rb create mode 100644 game/data/plugins/dummy/plugin.xml create mode 100644 game/data/plugins/emote-tab/emote_tab.rb create mode 100644 game/data/plugins/emote-tab/plugin.xml create mode 100644 game/data/plugins/entity/attributes/attributes.rb create mode 100644 game/data/plugins/entity/attributes/plugin.xml create mode 100644 game/data/plugins/entity/mob/extension/extension.rb create mode 100644 game/data/plugins/entity/mob/extension/plugin.xml create mode 100644 game/data/plugins/entity/mob/following/following.rb create mode 100644 game/data/plugins/entity/mob/following/plugin.xml create mode 100644 game/data/plugins/entity/mob/walk-to/plugin.xml create mode 100644 game/data/plugins/entity/mob/walk-to/walk_to.rb create mode 100644 game/data/plugins/entity/spawning/npc-spawn.rb create mode 100644 game/data/plugins/entity/spawning/plugin.xml create mode 100644 game/data/plugins/location/al-kharid/npcs.rb create mode 100644 game/data/plugins/location/al-kharid/plugin.xml create mode 100644 game/data/plugins/location/edgeville/npcs.rb create mode 100644 game/data/plugins/location/edgeville/plugin.xml create mode 100644 game/data/plugins/location/falador/npcs.rb create mode 100644 game/data/plugins/location/falador/plugin.xml create mode 100644 game/data/plugins/location/lumbridge/npcs.rb create mode 100644 game/data/plugins/location/lumbridge/plugin.xml create mode 100644 game/data/plugins/location/tutorial-island/guide.rb create mode 100644 game/data/plugins/location/tutorial-island/instructions.rb create mode 100644 game/data/plugins/location/tutorial-island/npcs.rb create mode 100644 game/data/plugins/location/tutorial-island/plugin.xml create mode 100644 game/data/plugins/location/tutorial-island/stages.rb create mode 100644 game/data/plugins/location/tutorial-island/survival.rb create mode 100644 game/data/plugins/location/tutorial-island/utils.rb create mode 100644 game/data/plugins/location/varrock/npcs.rb create mode 100644 game/data/plugins/location/varrock/plugin.xml create mode 100644 game/data/plugins/location/varrock/shops.rb create mode 100644 game/data/plugins/logout/logout.rb create mode 100644 game/data/plugins/logout/plugin.xml create mode 100644 game/data/plugins/navigation/door/constants.rb create mode 100644 game/data/plugins/navigation/door/door.rb create mode 100644 game/data/plugins/navigation/door/plugin.xml create mode 100644 game/data/plugins/navigation/door/util.rb create mode 100644 game/data/plugins/player-action/action.rb create mode 100644 game/data/plugins/player-action/login.rb create mode 100644 game/data/plugins/player-action/plugin.xml create mode 100644 game/data/plugins/quest/plugin.xml create mode 100644 game/data/plugins/quest/repository.rb create mode 100644 game/data/plugins/run/plugin.xml create mode 100644 game/data/plugins/run/run.rb create mode 100644 game/data/plugins/shops/currency.rb create mode 100644 game/data/plugins/shops/plugin.xml create mode 100644 game/data/plugins/shops/shop.rb create mode 100644 game/data/plugins/shops/shop_item.rb create mode 100644 game/data/plugins/shops/shops.rb create mode 100644 game/data/plugins/skill/fishing/fish.rb create mode 100644 game/data/plugins/skill/fishing/fishing.rb create mode 100644 game/data/plugins/skill/fishing/plugin.xml create mode 100644 game/data/plugins/skill/fishing/spot.rb create mode 100644 game/data/plugins/skill/fishing/tool.rb create mode 100644 game/data/plugins/skill/herblore/herb.rb create mode 100644 game/data/plugins/skill/herblore/herblore.rb create mode 100644 game/data/plugins/skill/herblore/ingredient.rb create mode 100644 game/data/plugins/skill/herblore/plugin.xml create mode 100644 game/data/plugins/skill/herblore/potion.rb create mode 100644 game/data/plugins/skill/magic/alchemy.rb create mode 100644 game/data/plugins/skill/magic/convert.rb create mode 100644 game/data/plugins/skill/magic/element.rb create mode 100644 game/data/plugins/skill/magic/enchant.rb create mode 100644 game/data/plugins/skill/magic/magic.rb create mode 100644 game/data/plugins/skill/magic/plugin.xml create mode 100644 game/data/plugins/skill/magic/teleport.rb create mode 100644 game/data/plugins/skill/mining/gem.rb create mode 100644 game/data/plugins/skill/mining/mining.rb create mode 100644 game/data/plugins/skill/mining/ore.rb create mode 100644 game/data/plugins/skill/mining/pickaxe.rb create mode 100644 game/data/plugins/skill/mining/plugin.xml create mode 100644 game/data/plugins/skill/mining/respawn.rb create mode 100644 game/data/plugins/skill/prayer/bury.rb create mode 100644 game/data/plugins/skill/prayer/plugin.xml create mode 100644 game/data/plugins/skill/prayer/prayers.rb create mode 100644 game/data/plugins/skill/runecraft/altar.rb create mode 100644 game/data/plugins/skill/runecraft/plugin.xml create mode 100644 game/data/plugins/skill/runecraft/rune.rb create mode 100644 game/data/plugins/skill/runecraft/runecraft.rb create mode 100644 game/data/plugins/skill/runecraft/talisman.rb create mode 100644 game/data/plugins/skill/runecraft/tiara.rb create mode 100644 game/data/plugins/util/command.rb create mode 100644 game/data/plugins/util/name_lookup.rb create mode 100644 game/data/plugins/util/plugin.xml rename game/src/main/java/org/apollo/game/message/impl/decode/{IfActionMessage.java => ButtonMessage.java} (92%) diff --git a/cache/build.gradle b/cache/build.gradle index 755407a6b..95d2e1f72 100644 --- a/cache/build.gradle +++ b/cache/build.gradle @@ -8,7 +8,7 @@ dependencies { implementation group: 'org.tukaani', name: 'xz', version: '1.8' implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.1' implementation group: 'org.apache.ant', name: 'ant', version: '1.10.7' - implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.0.rc1' test.useJUnitPlatform() testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion diff --git a/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java index 8684efc83..2e0a735b3 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java @@ -176,16 +176,16 @@ private ObjectDefinition decode(int id, CacheBuffer buffer) { definition.getMorphisms()[1 + length] = model; } else if (opcode == 78) { - definition.setF2117(buffer.readUShort()); - definition.setF2118(buffer.readUByte()); + definition.setSound(buffer.readUShort()); + definition.setSoundRadius(buffer.readUByte()); } else if (opcode == 79) { - definition.setF2119(buffer.readUShort()); - definition.setF2120(buffer.readUShort()); - definition.setF2118(buffer.readUByte()); + definition.setSoundDelayMinDuration(buffer.readUShort()); + definition.setSoundDelayMaxDuration(buffer.readUShort()); + definition.setSoundRadius(buffer.readUByte()); final int count = buffer.readUByte(); - definition.setF2121(new int[count]); + definition.setSounds(new int[count]); for (int i = 0; i < count; i++) - definition.getF2121()[i] = buffer.readUShort(); + definition.getSounds()[i] = buffer.readUShort(); } else if (opcode == 81) { definition.setAdjustValue(buffer.readUByte() * 256); } else if (opcode == 82) { diff --git a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java index f2405b880..35b79c436 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java @@ -1,13 +1,13 @@ package org.apollo.cache.decoder.rsenum; -import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.apollo.cache.Archive; import org.apollo.cache.Cache; import org.apollo.cache.CacheBuffer; import org.apollo.cache.RSFile; import org.apollo.cache.def.EnumDefinition; +import java.util.HashMap; + /** * Decodes archive two folder eight into {@link EnumDefinition}s. * @@ -65,14 +65,14 @@ private EnumDefinition decode(int id, CacheBuffer buffer) { def.setDefaultInt(buffer.readInt()); } else if (opcode == 5) { final var size = buffer.readUShort(); - final var values = new Int2ObjectOpenHashMap(size); + final var values = new HashMap(size); for (int index = 0; index < size; index++) { values.put(buffer.readInt(), buffer.readString()); } def.setStringValues(values); } else if (opcode == 6) { final var size = buffer.readUShort(); - final var values = new Int2IntOpenHashMap(size); + final var values = new HashMap(size); for (int index = 0; index < size; index++) { values.put(buffer.readInt(), buffer.readInt()); } diff --git a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java index ea5ccba49..bcbaadfaa 100644 --- a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java @@ -1,8 +1,6 @@ package org.apollo.cache.def; import com.google.common.base.Preconditions; -import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.apollo.cache.decoder.rsenum.ScriptVarType; import java.util.HashMap; @@ -60,8 +58,8 @@ public static EnumDefinition lookup(int id) { private ScriptVarType valType = ScriptVarType.INTEGER; private int defaultInt = 0; private String defaultString = ""; - private Int2IntOpenHashMap intValues; - private Int2ObjectOpenHashMap stringValues; + private HashMap intValues; + private HashMap stringValues; /** * Creates a new enum definition. @@ -122,19 +120,19 @@ public void setDefaultString(String defaultString) { this.defaultString = defaultString; } - public Int2IntOpenHashMap getIntValues() { + public HashMap getIntValues() { return intValues; } - public void setIntValues(Int2IntOpenHashMap intValues) { + public void setIntValues(HashMap intValues) { this.intValues = intValues; } - public Int2ObjectOpenHashMap getStringValues() { + public HashMap getStringValues() { return stringValues; } - public void setStringValues(Int2ObjectOpenHashMap stringValues) { + public void setStringValues(HashMap stringValues) { this.stringValues = stringValues; } } diff --git a/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java b/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java index 0738b967c..7cbe6f7e0 100644 --- a/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java @@ -140,11 +140,11 @@ public static ObjectDefinition lookup(int id) { private int varbit; private int varp; private int[] morphisms; - private int f2117; - private int f2118; - private int f2119; - private int f2120; - private int[] f2121; + private int sound; + private int soundRadius; + private int soundDelayMinDuration; + private int soundDelayMaxDuration; + private int[] sounds; private boolean members; private int mapSceneType; private int[] animations; @@ -562,44 +562,44 @@ public void setMorphisms(int[] morphisms) { this.morphisms = morphisms; } - public int getF2117() { - return f2117; + public int getSound() { + return sound; } - public void setF2117(int f2117) { - this.f2117 = f2117; + public void setSound(int f2117) { + this.sound = f2117; } - public int getF2118() { - return f2118; + public int getSoundRadius() { + return soundRadius; } - public void setF2118(int f2118) { - this.f2118 = f2118; + public void setSoundRadius(int soundRadius) { + this.soundRadius = soundRadius; } - public int getF2119() { - return f2119; + public int getSoundDelayMinDuration() { + return soundDelayMinDuration; } - public void setF2119(int f2119) { - this.f2119 = f2119; + public void setSoundDelayMinDuration(int soundDelayMinDuration) { + this.soundDelayMinDuration = soundDelayMinDuration; } - public int getF2120() { - return f2120; + public int getSoundDelayMaxDuration() { + return soundDelayMaxDuration; } - public void setF2120(int f2120) { - this.f2120 = f2120; + public void setSoundDelayMaxDuration(int soundDelayMaxDuration) { + this.soundDelayMaxDuration = soundDelayMaxDuration; } - public int[] getF2121() { - return f2121; + public int[] getSounds() { + return sounds; } - public void setF2121(int[] f2121) { - this.f2121 = f2121; + public void setSounds(int[] sounds) { + this.sounds = sounds; } public boolean isMembers() { diff --git a/cache/src/main/java/org/apollo/cache/map/XteaRepository.java b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java index fed8db659..389ffebf0 100644 --- a/cache/src/main/java/org/apollo/cache/map/XteaRepository.java +++ b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java @@ -1,23 +1,22 @@ package org.apollo.cache.map; -import com.google.gson.Gson; +import com.fasterxml.jackson.annotation.JsonProperty; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; import java.io.IOException; -import java.nio.file.Files; public class XteaRepository implements Runnable { - private static final Gson GSON = new Gson(); private static final int[] DEFAULT = {0, 0, 0, 0}; public static class Xtea { private final int region; private final int[] keys; - public Xtea(int region, int[] keys) { + public Xtea(@JsonProperty("region") int region, @JsonProperty("keys") int[] keys) { this.region = region; this.keys = keys; } @@ -43,7 +42,8 @@ public XteaRepository(int release) { public void run() { File file = new File("./data/fs/" + release + "/xtea.json"); try { - var xteas = GSON.fromJson(Files.newBufferedReader(file.toPath()), Xtea[].class); + var mapper = new ObjectMapper(); + var xteas = mapper.readValue(file, Xtea[].class); for (var xtea : xteas) { this.xteas.put(xtea.region, xtea.getKeys()); } diff --git a/game/build.gradle b/game/build.gradle index 87dcf5253..1a451eb99 100644 --- a/game/build.gradle +++ b/game/build.gradle @@ -19,7 +19,6 @@ dependencies { implementation group: 'com.google.guava', name: 'guava', version: guavaVersion implementation group: 'io.github.classgraph', name: 'classgraph', version: classGraphVersion implementation group: 'com.lambdaworks', name: 'scrypt', version: scryptVersion - implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.1' test.useJUnitPlatform() testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion diff --git a/game/data/messages.xml b/game/data/messages.xml index 88b609c30..516924e74 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -1,6 +1,6 @@ - org.apollo.game.message.impl.decode.IfActionMessage + org.apollo.game.message.impl.decode.ButtonMessage org.apollo.game.message.handler.DialogueButtonHandler org.apollo.game.message.handler.BankButtonMessageHandler diff --git a/game/data/plugins/.rubocop.yml b/game/data/plugins/.rubocop.yml new file mode 100644 index 000000000..b0a58ae30 --- /dev/null +++ b/game/data/plugins/.rubocop.yml @@ -0,0 +1,36 @@ +Metrics/AbcSize: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Metrics/LineLength: + Max: 100 + +Metrics/MethodLength: + Max: 30 + +Metrics/PerceivedComplexity: + Enabled: false + +Style/CaseIndentation: + IndentOneStep: true + +Style/EmptyLinesAroundBlockBody: + Enabled: false + +Style/EmptyLinesAroundClassBody: + Enabled: false + +Style/EmptyLinesAroundModuleBody: + Enabled: false + +Style/GlobalVars: + Enabled: false + +Style/MethodName: # Disabled so we can override Java methods without rubocop complaining + Enabled: false + +Style/ParallelAssignment: + Enabled: false + diff --git a/game/data/plugins/areas/actions.rb b/game/data/plugins/areas/actions.rb new file mode 100644 index 000000000..aeaaa6eae --- /dev/null +++ b/game/data/plugins/areas/actions.rb @@ -0,0 +1,49 @@ +require 'java' + +java_import 'org.apollo.game.message.impl.DisplayCrossbonesMessage' +java_import 'org.apollo.game.model.entity.Player' + +# Registers an area action. +def area_action(name, &block) + AREA_ACTIONS[name] = action = AreaAction.new + action.instance_eval(&block) +end + +AREA_ACTIONS = {} + +private + +# An action that is called when a player enters or exits an area. +class AreaAction + + # Sets the block to be called when the player enters the area. + def on_entry(&block) + @on_enter = block + end + + # Sets the block to be called while the player is in the area. + def while_in(&block) + @while_in = block + end + + # Sets the block to be called when the player exits the area. + def on_exit(&block) + @on_exit = block + end + + # Called when the player has entered an area this action is registered to. + def entered(player, position) + @on_enter.call(player, position) unless @on_enter.nil? + end + + # Called while the player is in area this action is registered to. + def inside(player, position) + @while_in.call(player, position) unless @while_in.nil? + end + + # Called when the player has exited an area this action is registered to. + def exited(player, position) + @on_exit.call(player, position) unless @on_exit.nil? + end + +end diff --git a/game/data/plugins/areas/areas.rb b/game/data/plugins/areas/areas.rb new file mode 100644 index 000000000..33a32bd89 --- /dev/null +++ b/game/data/plugins/areas/areas.rb @@ -0,0 +1,108 @@ +require 'java' + +java_import 'org.apollo.game.model.Position' +java_import 'org.apollo.game.model.entity.EntityType' +java_import 'org.apollo.game.model.entity.Player' + +# Creates a new area and registers it with the supplied coordinates. +def area(hash) + failure_message = 'Hash must contain a name, coordinates, and actions pair.' + fail failure_message unless hash.has_keys?(:name, :coordinates, :actions) + + name, coordinates, actions = hash[:name], hash[:coordinates], hash[:actions] + + actions = [actions] if actions.is_a?(Symbol) + actions.map! { |action| AREA_ACTIONS[action] } + @areas << Area.new(name, coordinates, actions) +end + +private + +# A map of coordinates (as an array) to areas. +@areas = [] + +# An area of the game world. +class Area + + def initialize(name, coordinates, actions) + @name = name + @coordinates = coordinates + @actions = actions + end + + def min_x # TODO: better data structure and methods than this + @coordinates[0] + end + + def min_y + @coordinates[1] + end + + def max_x + @coordinates[2] + end + + def max_y + @coordinates[3] + end + + def height + @coordinates[4] + end + + # Called when the player has entered the area. + def entered(player, position) + @actions.each { |action| action.entered(player, position) } + end + + # Called when the player has moved, but is still inside the area (and was in the area before). + def inside(player, position) + @actions.each { |action| action.inside(player, position) } + end + + # Called when the player has exited the area. + def exited(player, position) + @actions.each { |action| action.exited(player, position) } + end + +end + +on :login do |event| + player = event.player + + @areas.each do |area| + area.entered(player) if player.position.inside(area) + end +end + +# Listen for the MobPositionUpdateEvent and update the area listeners if appropriate. +on :mob_position_update do |event| + mob = event.mob + next unless mob.entity_type == EntityType::PLAYER + + old = mob.position + updated = event.next + @areas.each do |area| + was_inside = old.inside(area) + next_inside = updated.inside(area) + + if was_inside + next_inside ? area.inside(mob, updated) : area.exited(mob, updated) + else + area.entered(mob, updated) if next_inside + end + end +end + +# The existing Position class. +class Position + + # Returns whether or not this Position is inside the specified Area. + def inside(area) + return false if x < area.min_x || x > area.max_x || y < area.min_y || y > area.max_y + z = area.height + + z.nil? || z == height + end + +end diff --git a/game/data/plugins/areas/plugin.xml b/game/data/plugins/areas/plugin.xml new file mode 100644 index 000000000..2c18bb322 --- /dev/null +++ b/game/data/plugins/areas/plugin.xml @@ -0,0 +1,15 @@ + + + areas + 0.9 + Areas + Adds support for areas. + + Major + + + + + + + diff --git a/game/data/plugins/bank/bank.rb b/game/data/plugins/bank/bank.rb new file mode 100644 index 000000000..6383f9b77 --- /dev/null +++ b/game/data/plugins/bank/bank.rb @@ -0,0 +1,47 @@ +require 'java' + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.model.inter.bank.BankUtils' + +BANK_BOOTH_ID = 2213 +BANK_BOOTH_SIZE = 1 + +# The npcs with a 'bank' menu action. +BANKER_NPCS = [166, 494, 495, 496, 497, 498, 499, 1036, 1360, 1702, 2163, 2164, 2354, 2355, 2568, + 2569, 2570] + +# A distanced action to open a new bank. +class BankAction < DistancedAction + attr_reader :position + + def initialize(mob, position) + super(0, true, mob, position, BANK_BOOTH_SIZE) + @position = position + end + + def executeAction + mob.turn_to(@position) + BankUtils.open_bank(mob) + stop + end + + def equals(other) + get_class == other.get_class && @position == other.position + end +end + +# Intercepts the object action message +on :message, :second_object_action do |player, message| + if message.id == BANK_BOOTH_ID + player.start_action(BankAction.new(player, message.position)) + message.terminate + end +end + +on :message, :second_npc_action do |player, message| + npc = $world.npc_repository.get(message.index) + if BANKER_NPCS.include?(npc.id) + player.start_action(BankAction.new(player, npc.position)) + message.terminate + end +end diff --git a/game/data/plugins/bank/plugin.xml b/game/data/plugins/bank/plugin.xml new file mode 100644 index 000000000..894f4cf69 --- /dev/null +++ b/game/data/plugins/bank/plugin.xml @@ -0,0 +1,14 @@ + + + bank + 1 + Bank + Opens the bank interface when players select 'use-quickly' on a bank booth. + + Graham + + + + + + diff --git a/game/data/plugins/bootstrap.rb b/game/data/plugins/bootstrap.rb new file mode 100644 index 000000000..f36c1493a --- /dev/null +++ b/game/data/plugins/bootstrap.rb @@ -0,0 +1,239 @@ +# A script bootstrapper for the rest of the plugins, which wraps Apollo's +# verbose Java-style API in a Ruby-style API. + +# ********************************** WARNING ********************************** +# * If you do not really understand what this is for, do not edit it without * +# * creating a backup! Many plugins rely on the behaviour of this script, and * +# * will break if you mess it up. * +# * * +# * This is actually part of the core server and in an ideal world shouldn't * +# * be changed. * +# ***************************************************************************** + +require 'java' + +java_import 'org.apollo.game.command.CommandListener' +java_import 'org.apollo.game.message.handler.MessageHandler' +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.entity.Player' +java_import 'org.apollo.game.model.event.EventListener' +java_import 'org.apollo.game.model.event.PlayerEvent' +java_import 'org.apollo.game.model.event.impl.LoginEvent' +java_import 'org.apollo.game.model.event.ProxyEvent' +java_import 'org.apollo.game.model.event.ProxyEventListener' +java_import 'org.apollo.game.model.entity.setting.PrivilegeLevel' +java_import 'org.apollo.game.scheduling.ScheduledTask' +java_import 'org.apollo.game.plugin.PluginContext' + +# Alias the privilege levels. +RIGHTS_ADMIN = PrivilegeLevel::ADMINISTRATOR +RIGHTS_MOD = PrivilegeLevel::MODERATOR +RIGHTS_STANDARD = PrivilegeLevel::STANDARD + +# Extends the (Ruby) String class with a method to convert a lower case, +# underscore delimited string to camel-case. +class String + + # Converts a ruby snake_case string to camel-case. + def camelize + gsub(/(?:^|_)(.)/) { $1.upcase } + end + +end + +# A CommandListener that executes a Proc object with two arguments: the player and the command. +class ProcCommandListener < CommandListener + + # Creates the ProcCommandListener. + def initialize(rights, block) + super(rights) + @block = block + end + + # Executes the block listening for the command. + def execute(player, command) + @block.call(player, command) + end + +end + +# A LogoutListener that executes a Proc object with the player argument. +class ProcEventListener + java_implements EventListener + + # Creates the ProcEventListener. + def initialize(block) + super() + @block = block + end + + # Executes the block handling the Event. + def handle(event) + args = [event] + args << event.player if event.is_a?(PlayerEvent) + @block.call(*args) + end + +end + +# A MessageHandler which executes a Proc object with two arguments: the player and the message. +class ProcMessageHandler < MessageHandler + + # Creates the ProcMessageHandler. + def initialize(block, option) + super($world) + @block = block + @option = option + end + + # Handles the message. + def handle(player, message) + @block.call(player, message) if @option == 0 || @option == message.option + end + +end + +# A ScheduledTask which executes a Proc object with one argument (itself). +class ProcScheduledTask < ScheduledTask + + # Creates the ProcScheduledTask. + def initialize(delay, immediate, block) + super(delay, immediate) + @block = block + end + + # Executes the block. + def execute + @block.call(self) + end + +end + +# Schedules a ScheduledTask. Can be used in two ways: passing an existing +# ScheduledTask object or passing a block along with one or two parameters: the +# delay (in pulses) and, optionally, the immediate flag. +# +# If the immediate flag is not given, it defaults to false. +# +# The ScheduledTask object is passed to the block so that methods such as +# setDelay and stop can be called. execute MUST NOT be called - if it is, the +# behaviour is undefined (and most likely it'll be bad). +def schedule(*args, &block) + if block_given? + fail 'Invalid combination of arguments.' unless (1..2).include?(args.length) + delay = args[0] + + immediate = args.length == 2 ? args[1] : false + $world.schedule(ProcScheduledTask.new(delay, immediate, block)) + elsif args.length == 1 + $world.schedule(args[0]) + else + fail 'Invalid combination of arguments.' + end +end + +@@proxy_listener = ProxyEventListener.new +$world.listen_for(ProxyEvent.java_class, @@proxy_listener) + +# Defines some sort of action to take upon an message. The following types of message are currently +# valid: +# +# * :command +# * :message +# * :button +# * Any valid Event, as a symbol in ruby snake_case form. +# +# A command takes one or two arguments (the command name and optionally the minimum rights level to +# use it). The minimum rights level defaults to STANDARD. The block should have two arguments: +# player and command. +# +# An message takes no arguments. The block should have two arguments: the player and the message +# object. +# +# A button takes one argument (the id). The block should have one argument: the player who clicked +# the button. +def on(type, *args, &block) + case type + when :command then on_command(args, block) + when :message then on_message(args, block) + when :button then on_button(args, block) + else + class_name = type.to_s.camelize.concat('Event') + + begin + type = Java::JavaClass.for_name("org.apollo.game.model.event.impl.#{class_name}") + rescue + @@proxy_listener.add(class_name, ProcEventListener.new(block)) + return + end + + $world.listen_for(type, ProcEventListener.new(block)) + end +end + +# Contains extension methods for World. +module WorldExtensions + + # Overrides World#submit, providing special-case behaviour for Events defined in Ruby, which + # need to be wrapped in a ProxyEvent, until https://github.com/jruby/jruby/issues/2359 is + # resolved. + def submit(event) + if event.java_class.name.end_with?(".Event", ".PlayerEvent") + event = ProxyEvent.new(event.class.name, event) + end + + super(event) + end + +end + +# Prepend the methods defined in WorldExtensions to World. +class World + prepend WorldExtensions +end + +private + +# Defines an action to be taken upon a button press. +def on_button(args, proc) + fail 'Button must have one argument.' unless args.length == 1 + + id = args[0].to_i + + on :message, :button do |player, message| + proc.call(player) if message.widget_id == id + end +end + +# Defines an action to be taken upon a message. +# The message can either be a symbol with the lowercase underscored class name, or the class itself. +def on_message(args, proc) + fail 'Message must have one or two arguments.' unless (1..2).include?(args.length) + + numbers = %w(first second third fourth fifth) + message = args[0].to_s + option = 0 + + (0...numbers.length).each do |index| + number = numbers[index] + + if message.start_with?(number) + option = index + 1 + message = message[number.length + 1, message.length] + break + end + end + + class_name = message.camelize.concat('Message') + message = Java::JavaClass.for_name("org.apollo.game.message.impl.#{class_name}") + + $ctx.add_message_handler(message, ProcMessageHandler.new(proc, option)) +end + +# Defines an action to be taken upon a command. +def on_command(args, proc) + fail 'Command message must have one or two arguments.' unless (1..2).include?(args.length) + + rights = args.length == 2 ? args[1] : RIGHTS_STANDARD + $world.command_dispatcher.register(args[0].to_s, ProcCommandListener.new(rights, proc)) +end diff --git a/game/data/plugins/chat/privacy/plugin.xml b/game/data/plugins/chat/privacy/plugin.xml new file mode 100644 index 000000000..1df608af7 --- /dev/null +++ b/game/data/plugins/chat/privacy/plugin.xml @@ -0,0 +1,16 @@ + + + chat-privacy + 1 + Chat privacy + Adds chat privacy support. + + Major + + + + + + private-messaging + + \ No newline at end of file diff --git a/game/data/plugins/chat/privacy/privacy.rb b/game/data/plugins/chat/privacy/privacy.rb new file mode 100644 index 000000000..67c90d580 --- /dev/null +++ b/game/data/plugins/chat/privacy/privacy.rb @@ -0,0 +1,12 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.setting.PrivacyState' +java_import 'org.apollo.game.message.impl.SendFriendMessage' + +on :message, :privacy_option do |player, message| + player.chat_privacy = message.chat_privacy + player.friend_privacy = message.friend_privacy + player.trade_privacy = message.trade_privacy + + update_friends(player, message.friend_privacy == PrivacyState::OFF ? 0 : player.world_id) +end diff --git a/game/data/plugins/chat/private-messaging/friend.rb b/game/data/plugins/chat/private-messaging/friend.rb new file mode 100644 index 000000000..67ae6c287 --- /dev/null +++ b/game/data/plugins/chat/private-messaging/friend.rb @@ -0,0 +1,102 @@ +require 'java' + +java_import 'org.apollo.game.message.impl.FriendServerStatusMessage' +java_import 'org.apollo.game.message.impl.IgnoreListMessage' +java_import 'org.apollo.game.message.impl.SendFriendMessage' +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.entity.setting.ServerStatus' +java_import 'org.apollo.game.model.entity.setting.PrivacyState' +java_import 'org.apollo.game.model.entity.Player' + +# Processes an add friend message, updating the logged-in status of the player (and the person they +# added) if necessary. +on :message, :add_friend do |player, message| + friend_username = message.username + player_username = player.username + + player.add_friend(friend_username) + friend = $world.get_player(friend_username) + + if friend.nil? # the friend the player added is offline + player.send(SendFriendMessage.new(friend_username, 0)) + elsif friend.friends_with(player_username) + + # player's private chat state is not off, so notify the friend + unless player.friend_privacy == PrivacyState::OFF + friend.send(SendFriendMessage.new(player_username, player.world_id)) + end + + # new friend's private chat state is not off, so notify the player + unless friend.friend_privacy == PrivacyState::OFF + player.send(SendFriendMessage.new(friend_username, friend.world_id)) + end + elsif friend.friend_privacy == PrivacyState::ON + # new friend doesn't have the player added but their private chat state is on, so inform the + # player of the world they are on. + player.send(SendFriendMessage.new(friend_username, friend.world_id)) + end +end + +# Processes a remove friend message, updating the logged-in status of the player if necessary. +on :message, :remove_friend do |player, message| + friend_username = message.username + player_username = player.username + + player.remove_friend(friend_username) + if $world.is_player_online(friend_username) + friend = $world.get_player(friend_username) + + remove = friend.friends_with(player_username) && player.friend_privacy != PrivacyState::ON + friend.send(SendFriendMessage.new(player_username, 0)) if remove + end +end + +# Update the friend server status and send the friend/ignore lists of the player logging in. +on :login do |_event, player| + player.send(FriendServerStatusMessage.new(ServerStatus::CONNECTING)) + player.send(IgnoreListMessage.new(player.ignored_usernames)) if player.ignored_usernames.size > 0 + + username = player.username + world = $world + iterator = player.friend_usernames.iterator + + # Iterate the player's friend list and notify the player that they are online if they are + while iterator.has_next + friend_username = iterator.next + friend = world.get_player(friend_username) + friend_world_id = (friend.nil? || !viewable?(friend, username)) ? 0 : friend.world_id + + player.send(SendFriendMessage.new(friend_username, friend_world_id)) + end + + player.send(FriendServerStatusMessage.new(ServerStatus::ONLINE)) + update_friends(player, player.world_id) +end + +# Notifies the player's friends that the player has logged out. +on :logout do |_event, player| + update_friends(player, 0) +end + +# Notifies the currently logged in players that the specified player has logged into the specified +# world, unless the newly logged-in player has their friend privacy state set to 'off'. +def update_friends(player, world = 0) + privacy = player.friend_privacy + + iterator = $world.player_repository.iterator + username = player.username + + while iterator.has_next + other = iterator.next + next if !other.friends_with(username) || other == player + + world = viewable?(player, other.username) ? world : 0 + other.send(SendFriendMessage.new(username, world)) + end +end + +# Checks if the specified player can be viewed by the player with the specified other username +def viewable?(player, other_username) + privacy = player.friend_privacy + privacy != PrivacyState::OFF && player.friends_with(other_username) || privacy == PrivacyState::ON +end diff --git a/game/data/plugins/chat/private-messaging/ignore.rb b/game/data/plugins/chat/private-messaging/ignore.rb new file mode 100644 index 000000000..a903c9f83 --- /dev/null +++ b/game/data/plugins/chat/private-messaging/ignore.rb @@ -0,0 +1,9 @@ +on :message, :add_ignore do |player, message| + username = message.username + player.add_ignore(username) +end + +on :message, :remove_ignore do |player, message| + username = message.username + player.remove_ignore(username) +end diff --git a/game/data/plugins/chat/private-messaging/messaging.rb b/game/data/plugins/chat/private-messaging/messaging.rb new file mode 100644 index 000000000..d1138bfcb --- /dev/null +++ b/game/data/plugins/chat/private-messaging/messaging.rb @@ -0,0 +1,23 @@ +require 'java' + +java_import 'org.apollo.game.message.impl.ForwardPrivateChatMessage' +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.entity.setting.PrivacyState' + +on :message, :private_chat do |player, message| + friend = $world.get_player(message.username) + + if interaction_permitted(player, friend) + chat = message.compressed_chat + friend.send(ForwardPrivateChatMessage.new(player.username, player.privilege_level, chat)) + end +end + +# Checks if the sender is permitted to interact with the friend they have added: +def interaction_permitted(sender, friend) + username = sender.username + return false if friend.nil? || friend.has_ignored(username) + + privacy = friend.friend_privacy + friend.friends_with(username) ? (privacy != PrivacyState::OFF) : (privacy == PrivacyState::ON) +end diff --git a/game/data/plugins/chat/private-messaging/plugin.xml b/game/data/plugins/chat/private-messaging/plugin.xml new file mode 100644 index 000000000..a327a2dc5 --- /dev/null +++ b/game/data/plugins/chat/private-messaging/plugin.xml @@ -0,0 +1,16 @@ + + + private-messaging + 1 + Private Messaging + Adds friend and ignore list support, and private messaging. + + Major + + + + + + + + \ No newline at end of file diff --git a/game/data/plugins/cmd/animate/animate.rb b/game/data/plugins/cmd/animate/animate.rb new file mode 100644 index 000000000..7e8c0c724 --- /dev/null +++ b/game/data/plugins/cmd/animate/animate.rb @@ -0,0 +1,20 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Graphic' + +# Makes the player perform the animation with the specified id. +on :command, :animate, RIGHTS_MOD do |player, command| + args = command.arguments + next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::animate [animation-id]') + + player.play_animation(Animation.new(args[0].to_i)) +end + +# Makes the player perform the graphic with the specified id. +on :command, :graphic, RIGHTS_MOD do |player, command| + args = command.arguments + next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::graphic [graphic-id]') + + player.play_graphic(Graphic.new(args[0].to_i)) +end diff --git a/game/data/plugins/cmd/animate/plugin.xml b/game/data/plugins/cmd/animate/plugin.xml new file mode 100644 index 000000000..8f08c8659 --- /dev/null +++ b/game/data/plugins/cmd/animate/plugin.xml @@ -0,0 +1,14 @@ + + + cmd-animate + 1 + Animate Commands + Adds animation-related commands. + + Major + + + + + + diff --git a/game/data/plugins/cmd/bank/bank.rb b/game/data/plugins/cmd/bank/bank.rb new file mode 100644 index 000000000..3946b783b --- /dev/null +++ b/game/data/plugins/cmd/bank/bank.rb @@ -0,0 +1,6 @@ +require 'java' + +# Opens the player's bank. +on :command, :bank, RIGHTS_ADMIN do |player, _command| + player.open_bank +end diff --git a/game/data/plugins/cmd/bank/plugin.xml b/game/data/plugins/cmd/bank/plugin.xml new file mode 100644 index 000000000..23d7d0db2 --- /dev/null +++ b/game/data/plugins/cmd/bank/plugin.xml @@ -0,0 +1,14 @@ + + + cmd-bank + 1 + Bank Command + Adds a ::bank command. + + Graham + + + + + + \ No newline at end of file diff --git a/game/data/plugins/cmd/item/item.rb b/game/data/plugins/cmd/item/item.rb new file mode 100644 index 000000000..9d22ce045 --- /dev/null +++ b/game/data/plugins/cmd/item/item.rb @@ -0,0 +1,45 @@ +require 'java' + +java_import 'org.apollo.cache.def.ItemDefinition' + +# Adds the specified item to the player's inventory. +on :command, :item, RIGHTS_ADMIN do |player, command| + args = command.arguments + next unless valid_arg_length(args, (1..2), player, 'Invalid syntax - ::item [id] [amount]') + + id = args[0].to_i + amount = args.length == 2 ? args[1].to_i : 1 + + if id < 0 || id >= ItemDefinition.count + player.send_message('The item id you specified is out of bounds!') + next + end + + player.inventory.add(id, amount) +end + +# Removes the specified item from the player's inventory. +on :command, :remove, RIGHTS_MOD do |player, command| + args = command.arguments + next unless valid_arg_length(args, (1..2), player, 'Invalid syntax - ::remove [id] [amount]') + + id = args[0].to_i + amount = args.length == 2 ? args[1].to_i : 1 + + if id < 0 || id >= ItemDefinition.count + player.send_message('The item id you specified is out of bounds!') + next + end + + player.inventory.remove(id, amount) +end + +# Clears the player's inventory. +on :command, :empty, RIGHTS_MOD do |player, _command| + player.inventory.clear +end + +# Gives the player 1,000 of each rune. +on :command, :runes, RIGHTS_ADMIN do |player, _command| + (554..566).each { |item| player.inventory.add(item, 1000) } +end diff --git a/game/data/plugins/cmd/item/plugin.xml b/game/data/plugins/cmd/item/plugin.xml new file mode 100644 index 000000000..2a7976fd9 --- /dev/null +++ b/game/data/plugins/cmd/item/plugin.xml @@ -0,0 +1,14 @@ + + + cmd-item + 1 + Item Commands + Adds ::item, ::remove and ::empty commands. + + Graham + + + + + + \ No newline at end of file diff --git a/game/data/plugins/cmd/lookup/lookup.rb b/game/data/plugins/cmd/lookup/lookup.rb new file mode 100644 index 000000000..5851c0ada --- /dev/null +++ b/game/data/plugins/cmd/lookup/lookup.rb @@ -0,0 +1,69 @@ +require 'java' + +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.cache.def.ItemDefinition' +java_import 'org.apollo.cache.def.NpcDefinition' +java_import 'org.apollo.cache.def.ObjectDefinition' +java_import 'org.apollo.game.model.entity.Entity' +java_import 'org.apollo.game.model.entity.Player' + +on :command, :lookup, RIGHTS_ADMIN do |player, command| + args = command.arguments.to_a + message = 'Invalid syntax - ::lookup [npc/object/item] [name]' + next unless valid_arg_length(args, (1..10), player, message) + + type = args.shift.downcase + limit = args.first.to_i == 0 ? 5 : args.shift.to_i + name = args.join(' ').downcase + + if %w(npc object item).index(type).nil? + player.send_message('Invalid syntax - ::lookup [npc/object/item] [name]') + next + end + + ids = find_entities(type, name, limit).join(', ') + + message = ids.empty? ? "Could not find an #{type} called #{name}." : + "Possible ids for \"#{name}\" are: #{ids}." + player.send_message(message) +end + +# Sends the user a message with information about the item with the specified id. +on :command, :iteminfo, RIGHTS_ADMIN do |player, command| + args = command.arguments + next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::iteminfo [item id]') + + id = args[0].to_i + definition = ItemDefinition.lookup(id) + members = definition.is_members_only ? 'members' : 'not members' + + player.send_message("Item #{id} is called #{definition.name}, is #{members} only, and has a "\ + "team of #{definition.team}.") + player.send_message("Its description is \"#{definition.description}\".") +end + +# Sends the user a message with information about the npc with the specified id. +on :command, :npcinfo, RIGHTS_ADMIN do |player, command| + args = command.arguments + next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::npcinfo [npc id]') + + id = args[0].to_i + definition = NpcDefinition.lookup(id) + is_combative = definition.has_combat_level ? "has a combat level of #{definition.combat_level}" : + 'does not have a combat level' + + player.send_message("Npc #{id} is called #{definition.name} and #{is_combative}.") + player.send_message("Its description is \"#{definition.description}\".") +end + +# Sends the user a message with information about the object with the specified id. +on :command, :objectinfo, RIGHTS_ADMIN do |player, command| + args = command.arguments + next unless valid_arg_length(args, 1, player, 'Invalid syntax - ::objectinfo [object id]') + + id = args[0].to_i + definition = ObjectDefinition.lookup(id) + player.send_message("Object #{id} is called #{definition.name} and its description is "\ + "\"#{definition.description}\".") + player.send_message("Its width is #{definition.width} and its length is #{definition.length}.") +end diff --git a/game/data/plugins/cmd/lookup/plugin.xml b/game/data/plugins/cmd/lookup/plugin.xml new file mode 100644 index 000000000..e4d84e4b3 --- /dev/null +++ b/game/data/plugins/cmd/lookup/plugin.xml @@ -0,0 +1,16 @@ + + + cmd-lookup + 1 + Lookup Command + Adds a ::lookup command. + + Major + + + + + + util + + \ No newline at end of file diff --git a/game/data/plugins/cmd/messaging/broadcast.rb b/game/data/plugins/cmd/messaging/broadcast.rb new file mode 100644 index 000000000..ddace7419 --- /dev/null +++ b/game/data/plugins/cmd/messaging/broadcast.rb @@ -0,0 +1,12 @@ +require 'java' + +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.entity.Player' + +# Adds a command to broadcast a message to every player on the server. +on :command, :broadcast, RIGHTS_ADMIN do |player, command| + message = command.arguments.to_a.join(' ') + broadcast = "[Broadcast] #{player.get_username.capitalize}: #{message}" + + $world.player_repository.each { |other| other.send_message(broadcast) } +end diff --git a/game/data/plugins/cmd/messaging/plugin.xml b/game/data/plugins/cmd/messaging/plugin.xml new file mode 100644 index 000000000..546062c0c --- /dev/null +++ b/game/data/plugins/cmd/messaging/plugin.xml @@ -0,0 +1,15 @@ + + + message + 1 + Messaging commands + Adds various message-related commands, such as enabling the server-side chat filter or broadcasting a message. + + Major + xEliqa + + + + + + diff --git a/game/data/plugins/cmd/npc/plugin.xml b/game/data/plugins/cmd/npc/plugin.xml new file mode 100644 index 000000000..4cca1a6ef --- /dev/null +++ b/game/data/plugins/cmd/npc/plugin.xml @@ -0,0 +1,14 @@ + + + cmd-npc + 1 + Npc Commands + Adds npc-related commands. + + Major + + + + + + \ No newline at end of file diff --git a/game/data/plugins/cmd/npc/spawn.rb b/game/data/plugins/cmd/npc/spawn.rb new file mode 100644 index 000000000..57cd88e1c --- /dev/null +++ b/game/data/plugins/cmd/npc/spawn.rb @@ -0,0 +1,68 @@ +require 'java' + +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.Position' +java_import 'org.apollo.game.model.entity.Npc' + +# An array of npcs that cannot be spawned. +blacklist = [] + +# Spawns a non-blacklisted npc in the specified position, or the player's position if both 'x' and +# 'y' are not supplied. +on :command, :spawn, RIGHTS_ADMIN do |player, command| + args = command.arguments + unless [1, 3, 4].include?(args.length) && (id = args[0].to_i) > -1 + player.send_message('Invalid syntax - ::spawn [npc id] [optional-x] [optional-y] [optional-z]') + return + end + + if blacklist.include?(id) + player.send_message("Sorry, npc #{id} is blacklisted!") + return + end + + if args.length == 1 + position = player.position + else + height = args.length == 4 ? args[3].to_i : player.position.height + position = Position.new(args[1].to_i, args[2].to_i, height) + end + + $world.register(Npc.new($world, id, position)) +end + +# Mass spawns npcs around the player. +on :command, :mass, RIGHTS_ADMIN do |player, command| + args = command.arguments + unless args.length == 2 && (id = args[0].to_i) > -1 && (1..5).include?(range = args[1].to_i) + player.send_message('Invalid syntax - ::spawn [npc id] [range (1-5)]') + return + end + + if blacklist.include?(id) + player.send_message("Sorry, npc #{id} is blacklisted!") + return + end + + center_position = player.position + + min_x = center_position.x - range + min_y = center_position.y - range + max_x = center_position.x + range + max_y = center_position.y + range + z = center_position.height + + (min_x..max_x).each do |x| + (min_y..max_y).each do |y| + $world.register(Npc.new($world, id, Position.new(x, y, z))) + end + end + + player.send_message("Mass spawning npcs with id #{id}.") +end + +# Unregisters all npcs from the world npc repository. +on :command, :clearnpcs, RIGHTS_ADMIN do |player, _command| + $world.npc_repository.each { |npc| $world.unregister(npc) } + player.send_message('Unregistered all npcs from the world.') +end diff --git a/game/data/plugins/cmd/punishment/plugin.xml b/game/data/plugins/cmd/punishment/plugin.xml new file mode 100644 index 000000000..a5c7a7e0e --- /dev/null +++ b/game/data/plugins/cmd/punishment/plugin.xml @@ -0,0 +1,14 @@ + + + punishment + 1 + Punishment commands + Adds various punishment commands, such as banning or muting a player. + + lare96 + + + + + + \ No newline at end of file diff --git a/game/data/plugins/cmd/punishment/punish.rb b/game/data/plugins/cmd/punishment/punish.rb new file mode 100644 index 000000000..e6c236f3b --- /dev/null +++ b/game/data/plugins/cmd/punishment/punish.rb @@ -0,0 +1,53 @@ +require 'java' + +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.entity.Player' + +# Adds a command to mute a player. Admins cannot be muted. +on :command, :mute, RIGHTS_MOD do |player, command| + name = command.arguments.to_a.join(' ') + on_player = $world.get_player(name) + + if validate(player, on_player) + on_player.muted = true + on_player.send_message('You have just been muted.') + player.send_message("You have just muted #{on_player.get_username}.") + end +end + +# Adds a command to unmute a player. +on :command, :unmute, RIGHTS_MOD do |player, command| + name = command.arguments.to_a.join(' ') + on_player = $world.get_player(name) + + if validate(player, on_player) + on_player.muted = false + on_player.send_message('You are no longer muted.') + player.send_message("You have just unmuted #{on_player.get_username}.") + end +end + +# Adds a command to ban a player. Admins cannot be banned. +on :command, :ban, RIGHTS_ADMIN do |player, command| + name = command.arguments.to_a.join(' ') + on_player = $world.get_player(name) + + if validate(player, on_player) + on_player.banned = true + on_player.logout # TODO force logout + player.send_message("You have just banned #{on_player.get_username}.") + end +end + +# Ensures the player isn't nil, and that they aren't an Administrator. +def validate(player, on_player) + if on_player.nil? + player.send_message('That player does not exist.') + return false + elsif on_player.get_privilege_level == RIGHTS_ADMIN + player.send_message('You cannot perform this action on Administrators.') + return false + end + + true +end diff --git a/game/data/plugins/cmd/skill/plugin.xml b/game/data/plugins/cmd/skill/plugin.xml new file mode 100644 index 000000000..519ff15b0 --- /dev/null +++ b/game/data/plugins/cmd/skill/plugin.xml @@ -0,0 +1,15 @@ + + + cmd-skill + 1 + Skill Commands + Adds skill-related commands. + + Graham + Major + + + + + + diff --git a/game/data/plugins/cmd/skill/skill.rb b/game/data/plugins/cmd/skill/skill.rb new file mode 100644 index 000000000..466fc19c1 --- /dev/null +++ b/game/data/plugins/cmd/skill/skill.rb @@ -0,0 +1,44 @@ +require 'java' +java_import 'org.apollo.game.model.entity.SkillSet' +java_import 'org.apollo.game.model.entity.Skill' + +# Maximises the player's skill set. +on :command, :max, RIGHTS_ADMIN do |player, _command| + skills = player.skill_set + + (0...skills.size).each do |skill| + skills.add_experience(skill, SkillSet::MAXIMUM_EXP) + end +end + +# Levels the specified skill to the specified level, optionally updating the current level as well. +on :command, :level, RIGHTS_ADMIN do |player, command| + args = command.arguments + unless (2..3).include?(args.length) && (0..20).include?(skill_id = args[0].to_i) && + (1..99).include?(level = args[1].to_i) + player.send_message('Invalid syntax - ::level [skill-id] [level]') + next + end + + experience = SkillSet.get_experience_for_level(level) + current = level + + if args.length == 3 && args[2].to_s == 'old' + skill = player.skill_set.skill(skill_id) + current = skill.current_level + end + + player.skill_set.set_skill(skill_id, Skill.new(experience, current, level)) +end + +# Adds the specified amount of experience to the specified skill. +on :command, :xp, RIGHTS_ADMIN do |player, command| + args = command.arguments + unless args.length == 2 && (0..20).include?(skill_id = args[0].to_i) && + (experience = args[1].to_i) >= 0 + player.send_message('Invalid syntax - ::xp [skill-id] [experience]') + return + end + + player.skill_set.add_experience(skill_id, experience) +end diff --git a/game/data/plugins/cmd/teleport/plugin.xml b/game/data/plugins/cmd/teleport/plugin.xml new file mode 100644 index 000000000..be9346a49 --- /dev/null +++ b/game/data/plugins/cmd/teleport/plugin.xml @@ -0,0 +1,14 @@ + + + cmd-teleport + 1 + Teleport Commands + Adds ::pos and ::tele commands. + + Graham + + + + + + diff --git a/game/data/plugins/cmd/teleport/teleport.rb b/game/data/plugins/cmd/teleport/teleport.rb new file mode 100644 index 000000000..671a92cf9 --- /dev/null +++ b/game/data/plugins/cmd/teleport/teleport.rb @@ -0,0 +1,20 @@ +require 'java' + +java_import 'org.apollo.game.model.Position' + +# Sends the player's position. +on :command, :pos, RIGHTS_MOD do |player, _command| + player.send_message("You are at: #{player.position}.") +end + +# Teleports the player to the specified position. +on :command, :tele, RIGHTS_ADMIN do |player, command| + args = command.arguments + next unless valid_arg_length(args, (2..3), player, 'Invalid syntax - ::tele [x] [y] [optional-z]') + + x = args[0].to_i + y = args[1].to_i + z = args.length == 3 ? args[2].to_i : player.position.height + + player.teleport(Position.new(x, y, z)) if (0..4).include?(z) +end diff --git a/game/data/plugins/combat/plugin.xml b/game/data/plugins/combat/plugin.xml new file mode 100644 index 000000000..b236b6b22 --- /dev/null +++ b/game/data/plugins/combat/plugin.xml @@ -0,0 +1,17 @@ + + + combat + 1 + Combat + Manages combat between game characters. + + Ryley + + + + + + attributes + areas + + diff --git a/game/data/plugins/combat/wilderness.rb b/game/data/plugins/combat/wilderness.rb new file mode 100644 index 000000000..e62989e47 --- /dev/null +++ b/game/data/plugins/combat/wilderness.rb @@ -0,0 +1,66 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.Player' +java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' +java_import 'org.apollo.game.message.impl.OpenOverlayMessage' + +declare_attribute(:wilderness_level, 0, :transient) + +# Constants constants related to the wilderness +module WildernessConstants + + # The wilderness level overlay interface id + OVERLAY_INTERFACE_ID = 197 + + # The wilderness level string id + LEVEL_STRING_ID = 199 + +end + +# Determines the wilderness level for the specified position +def wilderness_level(position) + ((position.y - 3520) / 8).ceil + 1 +end + +area_action :wilderness_level do + on_entry do |player, position| + player.wilderness_level = wilderness_level(position) + player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID) + + id = WildernessConstants::LEVEL_STRING_ID + player.send(SetWidgetTextMessage.new(id, "Level: #{player.wilderness_level}")) + show_action(player, ATTACK_ACTION) + end + + while_in do |player, position| + current = player.wilderness_level + updated = wilderness_level(position) + + if current != updated + player.wilderness_level = updated + + id = WildernessConstants::LEVEL_STRING_ID + player.send(SetWidgetTextMessage.new(id, "Level: #{player.wilderness_level}")) + end + end + + on_exit do |player, position| + player.wilderness_level = 0 + player.interface_set.close + + player.send(OpenOverlayMessage.new(-1)) + hide_action(player, ATTACK_ACTION) + end +end + +# Monkey patch the existing player class to add method of checking whether or not a player is +# within the wilderness +class Player + + def in_wilderness + wilderness_level > 0 + end + +end + +area name: :wilderness, coordinates: [2945, 3522, 3390, 3972, 0], actions: :wilderness_level diff --git a/game/data/plugins/consumables/consumable.rb b/game/data/plugins/consumables/consumable.rb new file mode 100644 index 000000000..a0748d4f9 --- /dev/null +++ b/game/data/plugins/consumables/consumable.rb @@ -0,0 +1,79 @@ +require 'java' + +# A map of item ids to consumables. +CONSUMABLES = {} + +# The id of the food consumption animation. +CONSUME_ANIMATION_ID = 829 + +# Contains the different types of consumables +module ConsumableType + FOOD = 1 + POTION = 2 + DRINK = 3 +end + +# An item that can be consumed to produce a skill effect. +class Consumable + attr_reader :name, :id, :sound, :delay, :type + + def initialize(name, id, sound, delay, type) + @name = name.to_s.gsub(/_/, ' ') + @id = id + @sound = sound + @delay = delay + @type = type + end + + def consume(_player) + # Override to provide specific functionality. + end + +end + +# Appends a consumable to the map, with its id as the key. +def append_consumable(consumable) + CONSUMABLES[consumable.id] = consumable +end + +# An Action used for food consumption. +class ConsumeAction < Action + attr_reader :consumable + + def initialize(player, slot, consumable) + super(2, true, player) + @consumable = consumable + @slot = slot + @executions = 0 + end + + def execute + if @executions == 0 + mob.inventory.reset(@slot) + @consumable.consume(mob) + + mob.play_animation(Animation.new(CONSUME_ANIMATION_ID)) + end + + @executions += 1 + + if @executions >= @consumable.delay + stop + end + end + + def equals(other) + get_class == other.get_class && mob == other.mob && @consumable.type == other.consumable.type + end + +end + +# Intercepts the first item option message and consumes the consumable, if necessary. +on :message, :first_item_option do |player, message| + consumable = CONSUMABLES[message.id] + + unless consumable.nil? + player.start_action(ConsumeAction.new(player, message.slot, consumable)) + message.terminate + end +end diff --git a/game/data/plugins/consumables/drink.rb b/game/data/plugins/consumables/drink.rb new file mode 100644 index 000000000..4f0d5fe22 --- /dev/null +++ b/game/data/plugins/consumables/drink.rb @@ -0,0 +1,76 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.entity.Skill' +java_import 'org.apollo.game.model.entity.Player' + +private + +# The id the of the sound made when drinking something. +#TODO change sound if this id is incorrect +DRINK_SOUND = 334 + +# Represents something drinkable, such as a jug of wine or a nettle tea. +class Drink < Consumable + + def initialize(name, id, restoration, replace, delay) + super(name, id, DRINK_SOUND, delay, ConsumableType::DRINK) + @restoration = restoration + @replace = replace + end + + # Restore the appropriate amount of hitpoints when consumed. + def consume(player) + hitpoints = player.skill_set.skill(Skill::HITPOINTS) + hitpoints_current = player.skill_set.get_current_level(Skill::HITPOINTS) + new_curr = [hitpoints.current_level + @restoration, hitpoints.maximum_level].min + + player.inventory.add(@replace) unless @replace == -1 + + player.send_message("You drink the #{name}.") + player.send_message('It heals some health.') if new_curr > hitpoints_current + + skill = Skill.new(hitpoints.experience, new_curr, hitpoints.maximum_level) + player.skill_set.set_skill(Skill::HITPOINTS, skill) + end + +end + +# The default delay before the consumable is drunk. +DEFAULT_DELAY = 3 + +# Appends a drink item to the list of consumables. +def drink(hash) + unless hash.has_keys?(:name, :id, :restoration) + fail 'Hash must contain a name, id, and a restoration value.' + end + + name, id, restoration = hash[:name], hash[:id], hash[:restoration]; + replace = hash[:replace] || -1 + delay = hash[:delay] || DEFAULT_DELAY # TODO: ?? + + append_consumable(Drink.new(name, id, restoration, replace, delay)) +end + +# Wine +drink name: :jug_of_wine, id: 1993, restoration: 11 + +# Hot Drinks +drink name: :nettle_tea, id: 4239, restoration: 3 +drink name: :nettle_tea, id: 4240, restoration: 3 + +# Gnome Cocktails +drink name: :fruit_blast, id: 2034, restoration: 9 +drink name: :fruit_blast, id: 2084, restoration: 9 +drink name: :pineapple_punch, id: 2036, restoration: 9 +drink name: :pineapple_punch, id: 2048, restoration: 9 +drink name: :wizard_blizzard, id: 2040, restoration: 5 # -4 attack, +5 strength also +drink name: :wizard_blizzard, id: 2054, restoration: 5 # -4 attack, +5 strength also +drink name: :short_green_guy, id: 2038, restoration: 5 # -4 attack, +5 strength also +drink name: :short_green_guy, id: 2080, restoration: 5 # -4 attack, +5 strength also +drink name: :drunk_dragon, id: 2032, restoration: 5 # -4 attack, +6 strength also +drink name: :drunk_dragon, id: 2092, restoration: 5 # -4 attack, +6 strength also +drink name: :chocolate_saturday, id: 2030, restoration: 7 # -4 attack, +6 strength also +drink name: :chocolate_saturday, id: 2074, restoration: 7 # -4 attack, +6 strength also +drink name: :blurberry_special, id: 2028, restoration: 7 # -4 attack, +6 strength also +drink name: :blurberry_special, id: 2064, restoration: 7 # -4 attack, +6 strength also diff --git a/game/data/plugins/consumables/food.rb b/game/data/plugins/consumables/food.rb new file mode 100644 index 000000000..a128c4286 --- /dev/null +++ b/game/data/plugins/consumables/food.rb @@ -0,0 +1,221 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.entity.Skill' +java_import 'org.apollo.game.model.entity.Player' + +private + +# The id the of the sound made when eating food. +EAT_FOOD_SOUND = 317 + +# Represents an edible piece of food, such as bread or fish. +# TODO: delay eating times +class Food < Consumable + + def initialize(name, id, restoration, replace, delay) + super(name, id, EAT_FOOD_SOUND, delay, ConsumableType::FOOD) + @restoration = restoration + @replace = replace + end + + # Restore the appropriate amount of hitpoints when consumed. + def consume(player) + hitpoints = player.skill_set.skill(Skill::HITPOINTS) + hitpoints_current = player.skill_set.get_current_level(Skill::HITPOINTS) + new_curr = [hitpoints.current_level + @restoration, hitpoints.maximum_level].min + + player.inventory.add(@replace) unless @replace == -1 + + player.send_message("You eat the #{name}.") + player.send_message('It heals some health.') if new_curr > hitpoints_current + + skill = Skill.new(hitpoints.experience, new_curr, hitpoints.maximum_level) + player.skill_set.set_skill(Skill::HITPOINTS, skill) + end + +end + +# The default delay before a piece of food is eaten +DEFAULT_DELAY = 3 + +# Appends a food item to the list of consumables. +def food(hash) + unless hash.has_keys?(:name, :id, :restoration) + fail 'Hash must contain a name, id, and a restoration value.' + end + + name, id, restoration = hash[:name], hash[:id], hash[:restoration]; + replace = hash[:replace] || -1 + delay = hash[:delay] || DEFAULT_DELAY # TODO: ?? + + append_consumable(Food.new(name, id, restoration, replace, delay)) +end + +# TODO: special effects +food name: :cooked_slimy_eel, id: 3381, restoration: 6 # this has a chance to heal 6 to 10 hp +food name: :thin_snail_meat, id: 3369, restoration: 5 # this has a chance to heal 5 to 7 hp +food name: :fat_snail_meat, id: 3373, restoration: 2 # this has a chance to heal 7 to 9 hp +food name: :watermelon_slice, id: 5984, restoration: 0 # this heals 5% of player's life +food name: :cooked_karambwan, id: 3146, restoration: 0 # poisons player(50) +food name: :spider_on_stick, id: 6297, restoration: 7 # heals between 7 and 10 +food name: :spider_on_shaft, id: 6299, restoration: 7 # heals between 7 and 10 + +# Meats/Fish +food name: :anchovies, id: 319, restoration: 1 +food name: :crab_meat, id: 7521, restoration: 2, replace: 7523 +food name: :crab_meat, id: 7523, restoration: 2, replace: 7524 +food name: :crab_meat, id: 7524, restoration: 2, replace: 7525 +food name: :crab_meat, id: 7525, restoration: 2, replace: 7526 +food name: :crab_meat, id: 7526, restoration: 2 +food name: :shrimp, id: 315, restoration: 3 +food name: :sardine, id: 325, restoration: 3 +food name: :cooked_meat, id: 2142, restoration: 3 +food name: :cooked_chicken, id: 2140, restoration: 3 +food name: :ugthanki_meat, id: 1861, restoration: 3 +food name: :karambwanji, id: 3151, restoration: 3 +food name: :cooked_rabbit, id: 3228, restoration: 5 +food name: :herring, id: 347, restoration: 6 +food name: :trout, id: 333, restoration: 7 +food name: :cod, id: 339, restoration: 7 +food name: :mackeral, id: 355, restoration: 7 +food name: :roast_rabbit, id: 7223, restoration: 7 +food name: :pike, id: 351, restoration: 8 +food name: :lean_snail_meat, id: 3371, restoration: 8 +food name: :salmon, id: 329, restoration: 9 +food name: :tuna, id: 361, restoration: 10 +food name: :lobster, id: 379, restoration: 12 +food name: :bass, id: 365, restoration: 13 +food name: :swordfish, id: 373, restoration: 14 +food name: :cooked_jubbly, id: 7568, restoration: 15 +food name: :monkfish, id: 7946, restoration: 16 +food name: :cooked_karambwan, id: 3144, restoration: 18, delay: 0 +food name: :shark, id: 385, restoration: 20 +food name: :sea_turtle, id: 397, restoration: 21 +food name: :manta_ray, id: 391, restoration: 22 + +# Breads/Wraps +food name: :bread, id: 2309, restoration: 5 +food name: :oomlie_wrap, id: 2343, restoration: 14 +food name: :ugthanki_kebab, id: 1883, restoration: 19 + +# Fruits +food name: :banana, id: 1963, restoration: 2 +food name: :sliced_banana, id: 3162, restoration: 2 +food name: :lemon, id: 2102, restoration: 2 +food name: :lemon_chunks, id: 2104, restoration: 2 +food name: :lemon_slices, id: 2106, restoration: 2 +food name: :lime, id: 2120, restoration: 2 +food name: :lime_chunks, id: 2122, restoration: 2 +food name: :lime_slices, id: 2124, restoration: 2 +food name: :strawberry, id: 5504, restoration: 5 +food name: :papaya_fruit, id: 5972, restoration: 8 +food name: :pineapple_chunks, id: 2116, restoration: 2 +food name: :pineapple_ring, id: 2118, restoration: 2 +food name: :orange, id: 2108, restoration: 2 +food name: :orange_rings, id: 2110, restoration: 2 +food name: :orange_slices, id: 2112, restoration: 2 + +# Pies +# TODO: pie special effects (e.g. fish pie raises fishing level) +food name: :redberry_pie, id: 2325, restoration: 5, replace: 2333, delay: 1 +food name: :redberry_pie, id: 2333, restoration: 5, delay: 1 + +food name: :meat_pie, id: 2327, restoration: 6, replace: 2331, delay: 1 +food name: :meat_pie, id: 2331, restoration: 6, delay: 1 + +food name: :apple_pie, id: 2323, restoration: 7, replace: 2335, delay: 1 +food name: :apple_pie, id: 2335, restoration: 7, delay: 1 + +food name: :fish_pie, id: 7188, restoration: 6, replace: 7190, delay: 1 +food name: :fish_pie, id: 7190, restoration: 6, delay: 1 + +food name: :admiral_pie, id: 7198, restoration: 8, replace: 7200, delay: 1 +food name: :admiral_pie, id: 7200, restoration: 8, delay: 1 + +food name: :wild_pie, id: 7208, restoration: 11, replace: 7210, delay: 1 +food name: :wild_pie, id: 7210, restoration: 11, delay: 1 + +food name: :summer_pie, id: 7218, restoration: 11, replace: 7220, delay: 1 +food name: :summer_pie, id: 7220, restoration: 11, delay: 1 + +# Stews +food name: :stew, id: 2003, restoration: 11 +food name: :banana_stew, id: 4016, restoration: 11 +food name: :curry, id: 2011, restoration: 19 + +# Pizzas +food name: :plain_pizza, id: 2289, restoration: 7, replace: 2291 +food name: :plain_pizza, id: 2291, restoration: 7 + +food name: :meat_pizza, id: 2293, restoration: 8, replace: 2295 +food name: :meat_pizza, id: 2295, restoration: 8 + +food name: :anchovy_pizza, id: 2297, restoration: 9, replace: 2299 +food name: :anchovy_pizza, id: 2299, restoration: 9 + +food name: :pineapple_pizza, id: 2301, restoration: 11, replace: 2303 +food name: :pineapple_pizza, id: 2303, restoration: 11 + +# Cakes +food name: :fishcake, id: 7530, restoration: 11 + +food name: :cake, id: 1891, restoration: 4, replace: 1893 +food name: :cake, id: 1893, restoration: 4, replace: 1895 +food name: :cake, id: 1895, restoration: 4 + +food name: :chocolate_cake, id: 1897, restoration: 5, replace: 1899 +food name: :chocolate_cake, id: 1899, restoration: 5, replace: 1901 +food name: :chocolate_cake, id: 1901, restoration: 5 + +# Vegetables +food name: :potato, id: 1942, restoration: 1 +food name: :spinach_roll, id: 1969, restoration: 2 +food name: :baked_potato, id: 6701, restoration: 4 +food name: :sweetcorn, id: 5988, restoration: 10 +food name: :sweetcorn_bowl, id: 7088, restoration: 13 +food name: :potato_with_butter, id: 6703, restoration: 14 +food name: :chili_potato, id: 7054, restoration: 14 +food name: :potato_with_cheese, id: 6705, restoration: 16 +food name: :egg_potato, id: 7056, restoration: 16 +food name: :mushroom_potato, id: 7058, restoration: 20 +food name: :tuna_potato, id: 7060, restoration: 22 + +# Dairy +food name: :cheese, id: 1985, restoration: 2 +food name: :pot_of_cream, id: 2130, restoration: 1 + +# Gnome Food +food name: :toads_legs, id: 2152, restoration: 3 + +# Gnome Bowls +food name: :worm_hole, id: 2191, restoration: 12 +food name: :worm_hole, id: 2233, restoration: 12 +food name: :vegetable_ball, id: 2195, restoration: 12 +food name: :vegetable_ball, id: 2235, restoration: 12 +food name: :tangled_toads_legs, id: 2187, restoration: 15 +food name: :tangled_toads_legs, id: 2231, restoration: 15 +food name: :chocolate_bomb, id: 2185, restoration: 15 +food name: :chocolate_bomb, id: 2229, restoration: 15 + +# Gnome Crunchies +food name: :toad_crunchies, id: 2217, restoration: 7 +food name: :toad_crunchies, id: 2243, restoration: 7 +food name: :spicy_crunchies, id: 2213, restoration: 7 +food name: :spicy_crunchies, id: 2241, restoration: 7 +food name: :worm_crunchies, id: 2205, restoration: 8 +food name: :worm_crunchies, id: 2237, restoration: 8 +food name: :chocchip_crunchies, id: 2209, restoration: 7 +food name: :chocchip_crunchies, id: 2239, restoration: 7 + +# Gnome Battas +food name: :fruit_batta, id: 2225, restoration: 11 +food name: :fruit_batta, id: 2277, restoration: 11 +food name: :toad_batta, id: 2221, restoration: 11 +food name: :toad_batta, id: 2255, restoration: 11 +food name: :worm_batta, id: 2219, restoration: 11 +food name: :worm_batta, id: 2253, restoration: 11 +food name: :vegetable_batta, id: 2227, restoration: 11 +food name: :vegetable_batta, id: 2281, restoration: 11 +food name: :cheese_tom_batta, id: 2223, restoration: 11 +food name: :cheese_tom_batta, id: 2259, restoration: 11 diff --git a/game/data/plugins/consumables/plugin.xml b/game/data/plugins/consumables/plugin.xml new file mode 100644 index 000000000..50f2ea90c --- /dev/null +++ b/game/data/plugins/consumables/plugin.xml @@ -0,0 +1,17 @@ + + + consumables + 0.1 + Consumables + Adds support for consumables (e.g. potions, food). + + Major + Ryley + + + + + + + + \ No newline at end of file diff --git a/game/data/plugins/consumables/potions.rb b/game/data/plugins/consumables/potions.rb new file mode 100644 index 000000000..c3efe8fbb --- /dev/null +++ b/game/data/plugins/consumables/potions.rb @@ -0,0 +1,136 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.Skill' + +private + +# Contains potion-related constants. +module Constants + + # The id of the sound made when drinking a potion. + DRINK_POTION_SOUND = 334 + + # The id of an empty vial. + EMPTY_VIAL_ID = 229 + + # The delay between drinking potions + POTION_DELAY = 2 +end + +# A drinkable potion. +class Potion < Consumable + + def initialize(id, name, doses) + super(name, id, Constants::DRINK_POTION_SOUND, Constants::POTION_DELAY, ConsumableType::POTION) + @doses = doses + end + + def consume(player) + index = @doses.find_index(id) + 1 + + if index != @doses.length # Consumable removes the old potion for us, so don't do it here. + player.inventory.add(@doses[index]) + player.send_message("You drink some of your #{name} potion.") + + remaining = "You have #{@doses.length - index} dose#{'s' unless index == 3} of potion left." + player.send_message(remaining) + else + player.send_message('You drink the last of your potion.') + player.inventory.add(Constants::EMPTY_VIAL_ID) + end + + drink(player) + end + + def drink(_player) + # Override to provide functionality + end + +end + +# A potion that can be consumed to boost the current skill level of a stat (or stats). +class BoostingPotion < Potion + + def initialize(id, name, doses, skills, boost) + super(id, name, doses) + @skill_ids = skills.is_a?(Array) ? skills : [skills] + @boost = boost + end + + def drink(player) + @skill_ids.each do |id| + skill = player.skill_set.skill(id) + max = skill.maximum_level + level = [skill.current_level, max].min + + new_current = @boost.call(max, level).floor + player.skill_set.set_skill(id, Skill.new(skill.experience, new_current, max)) + end + end + +end + +# Returns the parameters for the potion, as an array. Fails if any of the specified keys do not +# exist. +def get_parameters(hash, keys) + fail "Hash must contain the following keys: #{keys.join(', ')}." unless hash.has_keys?(*keys) + + keys.map { |key| hash[key] } +end + +# Appends a potion to the list of consumables. +def potion(hash) + class_name = 'Potion' + keys = [:name, :doses] + + unless (hash.size == 2) + keys << :skills << :boost + class_name.prepend('Boosting') + end + + parameters = get_parameters(hash, keys) + doses = hash[:doses] + doses.each { |dose| append_consumable(Object.const_get(class_name).new(dose, *parameters)) } +end + +# Some frequently-used boosts and skills +# Lambda parameters are | maximum_skill_level, current_skill_level | +basic_combat_boost = ->(_, level) { level * 1.10 + 3 } +super_combat_boost = ->(_, level) { level * 1.15 + 5 } +non_combat_boost = ->(_, level) { level + 3 } + +ATTACK, STRENGTH, DEFENCE = Skill::ATTACK, Skill::STRENGTH, Skill::DEFENCE +MAGIC, RANGED, PRAYER = Skill::MAGIC, Skill::RANGED, Skill::PRAYER + +all_skills = (Skill::ATTACK..Skill::RUNECRAFT).to_a +combat_skills = [ATTACK, STRENGTH, DEFENCE, MAGIC, RANGED] + +# Boosting potions: +# Note that the order of the elements must be: :name, :doses, :skills, :boost. +potion name: :attack, doses: [2428, 121, 123, 125], skills: ATTACK, boost: basic_combat_boost +potion name: :strength, doses: [113, 115, 117, 119], skills: STRENGTH, boost: basic_combat_boost +potion name: :defence, doses: [2432, 133, 135, 137], skills: DEFENCE, boost: basic_combat_boost + +potion name: :agility, doses: [3032, 3034, 3036, 3038], skills: Skill::AGILITY, + boost: non_combat_boost +potion name: :fishing, doses: [2438, 151, 153, 155], skills: Skill::FISHING, + boost: non_combat_boost +potion name: :prayer, doses: [2434, 139, 141, 143], skills: Skill::PRAYER, + boost: ->(_, level) { level / 4 + 7 } + +potion name: :restore, doses: [2430, 127, 129, 131], skills: combat_skills, + boost: ->(_, level) { [level * 1.3 + 10, max].min } +potion name: :super_restore, doses: [3024, 3026, 3028, 3030], skills: all_skills, + boost: ->(_, level) { [level * 1.25 + 8, max].min } + +potion name: :super_attack, doses: [2436, 145, 147, 149], skills: ATTACK, boost: super_combat_boost +potion name: :super_strength, doses: [2440, 157, 159, 161], skills: STRENGTH, + boost: super_combat_boost +potion name: :super_defence, doses: [2442, 163, 165, 167], skills: DEFENCE, + boost: super_combat_boost + +potion name: :ranging, doses: [2444, 169, 171, 173], skills: RANGED, + boost: ->(_, level) { level * 1.10 + 4 } + +potion name: :magic, doses: [3040, 3042, 3044, 3046], skills: MAGIC, + boost: ->(_, level) { level + 4 } diff --git a/game/data/plugins/dialogue/dialogue.rb b/game/data/plugins/dialogue/dialogue.rb new file mode 100644 index 000000000..d0fe5c2f2 --- /dev/null +++ b/game/data/plugins/dialogue/dialogue.rb @@ -0,0 +1,567 @@ +require 'java' + +java_import 'org.apollo.game.model.inter.dialogue.DialogueAdapter' +java_import 'org.apollo.game.message.impl.CloseInterfaceMessage' +java_import 'org.apollo.game.message.impl.SetWidgetItemModelMessage' +java_import 'org.apollo.game.message.impl.SetWidgetNpcModelMessage' +java_import 'org.apollo.game.message.impl.SetWidgetPlayerModelMessage' +java_import 'org.apollo.game.message.impl.SetWidgetModelAnimationMessage' +java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' +java_import 'org.apollo.game.action.DistancedAction' + +# The map of conversation names to Conversations. +CONVERSATIONS = {} + +# Declares a conversation. +def conversation(name, &block) + conversation = Conversation.new(name) + conversation.instance_eval(&block) + + raise "Conversation named #{name} already exists." if CONVERSATIONS.has_key?(name) + CONVERSATIONS[name] = conversation +end + +# A distanced action which opens the dialogue when getting into interaction distance of the given npc +class OpenDialogueAction < DistancedAction + attr_reader :player, :npc, :dialogue + + def initialize(player, npc, dialogue) + super(0, true, player, npc.position, 1) + + @player = player + @npc = npc + @dialogue = dialogue + end + + def executeAction + @player.set_interacting_mob(@npc) + send_dialogue(@player, @dialogue) + stop + end + + def equals(other) + return (@npc == other.npc && @dialogue == other.dialogue) + end + +end + +# A conversation held between two entities. +class Conversation + + # Creates the Conversation. + def initialize(name) + @dialogues = {} + @starters = [] + @name = name + end + + # Defines a dialogue, with the specified name and block. + def dialogue(name, &block) + raise 'Dialogues must have a name and block.' if (name.nil? || block.nil?) + + dialogue = Dialogue.new(name, self) + dialogue.instance_eval(&block) + dialogue.wrap + + raise "Conversations #{@name} already has a dialogue named #{name}." if @dialogues.has_key?(name) + @dialogues[name] = dialogue + + if ((@dialogues.empty? || dialogue.has_precondition?) && dialogue.type == :npc_speech) + npc_index = dialogue.npc + raise 'Npc cannot be null when opening a dialogue.' if npc_index.nil? + @starters << dialogue + + on :message, :first_npc_action do |player, message| + npc = $world.npc_repository.get(message.index) + if npc_index == npc.id + @starters.each do |start| + if dialogue.precondition(player) + player.start_action(OpenDialogueAction.new(player, npc, dialogue)) + message.terminate + break + end + end + end + end + end + end + + # Gets part of a conversation (i.e. a dialogue). + def part(name) + raise "Conversation #{@name} does not contain a dialogue called #{name}." unless @dialogues.has_key?(name) + @dialogues[name] + end + +end + +# Declares an emote, with the specified name and id. +def declare_emote(name, id) + EMOTES[name] = id +end + + +# Sends the dialogue from the specified Conversation with the specified name. +def get_dialogue(conversation, name) + CONVERSATIONS[conversation].part(name) +end + + +# Sends the specified dialogue. +def send_dialogue(player, dialogue) + type = dialogue.type + action = dialogue.action + action.call(player) unless action.nil? + + case type + when :message_with_item then send_item_dialogue(player, dialogue) + when :message_with_model then send_model_dialogue(player, dialogue) + when :npc_speech then send_npc_dialogue(player, dialogue) + when :options then send_options_dialogue(player, dialogue) + when :player_speech then send_player_dialogue(player, dialogue) + when :text + if dialogue.has_continue? then send_text_dialogue(player, dialogue) else send_statement_dialogue(player, dialogue) end + else raise "Unrecognised dialogue type #{type}." + end +end + +private + +# The hash of emote names to ids. +EMOTES = {} + +# The maximum amount of lines of text that can be displayed on a dialogue. +MAXIMUM_LINE_COUNT = 4 + +# The maximum amount of options that can be displayed on a dialogue. +MAXIMUM_OPTION_COUNT = 5 + +# The maximum width of a line, in pixels, for a dialogue with media. +MAXIMUM_MEDIA_LINE_WIDTH = 350 + +# The maximum width of a line, in pixels, for a dialogue with no media. +MAXIMUM_LINE_WIDTH = 430 + +# The possible types of a dialogue. +DIALOGUE_TYPES = [ :message_with_item, :message_with_model, :npc_speech, :options, :player_speech, :text ] + +# A type of dialogue. +class Dialogue + attr_reader :emote, :name, :media, :options, :text, :title, :type + + # Initializes the Dialogue. + def initialize(name, conversation) + @name = name.to_s + @conversation = conversation + @text = [] + @options = [] + end + + # An action that is executed when the dialogue is displayed. + def action(&block) + @action = block unless block.nil? + @action + end + + # Closes the dialogue interface when the player clicks the 'Click here to continue...' text. + def close(&block) + continue(:close => true, &block) + end + + # Defines the event that occurs when a player clicks the 'Click here to continue...' text. + def continue(type=nil, &block) + raise 'Cannot add a continue event on a dialogue with options.' if (@type == :options) + raise 'Must declare either a type or a block for a continue event.' if (type.nil? && block.nil?) + + action = decode_next_dialogue(type) unless type.nil? + @options[0] = ->(player) { action.call(player) unless type.nil?; block.call(player) unless block.nil? } + end + + # Sets the emote performed by the dialogue head. + def emote(emote=nil) + unless emote.nil? + raise 'Can only perform an emote on :player_speech or :npc_speech dialogues.' unless [ :npc_speech, :player_speech ].include?(@type) + @emote = emote.kind_of?(Symbol) ? EMOTES[emote] : emote + end + + @emote + end + + # Returns whether or not this Dialogue has a continue option. + def has_continue? + !@options.empty? + end + + # Returns whether or not this dialogue has a precondition. + def has_precondition? + !@precondition.nil? + end + + # Gets the media of this dialogue. + def media() + case @type + when :message_with_item then @item + when :npc_speech then @npc + when :message_with_model then @model + else raise "Cannot get media for #{@type}." + end + end + + # Sets the id of the item displayed. + def item(item=nil, scale=100) + unless item.nil? + raise 'Can only display an item on :message_with_item dialogues.' unless @type == :message_with_item + @item = lookup_item(item) + @item_scale = scale + end + + @item + end + + # Gets the scale of the item. + def item_scale + @item_scale + end + + # Sets the id of the model displayed. + def model(model=nil) + unless model.nil? + raise 'Can only display a model on :message_with_model dialogues.' unless @type == :message_with_model + @model = model + end + + @model + end + + # Sets the id of the npc displayed. + def npc(npc=nil) + unless npc.nil? + raise 'Can only display an npc on :npc_speech dialogues.' unless @type == :npc_speech + @npc = lookup_npc(npc) + end + @npc + end + + # Defines an option, displaying the specified message. + def option(message, type) + raise 'Can only display options on an :options dialogue.' unless @type == :options + raise "Cannot display more than #{MAXIMUM_OPTION_COUNT} options on a dialogue." unless @options.size < MAXIMUM_OPTION_COUNT + + @options[text.size] = decode_next_dialogue(type) + @text << message + end + + # Gets the array of options. + def options + @options.dup + end + + # Sets the precondition of this dialogue. + def precondition(player=nil, &block) + @precondition = block unless block.nil? + @precondition.call(player) unless player.nil? + end + + # Appends a message to the text list. + def text(*message) + @text.concat(message) unless message.nil? + @text + end + + # Sets the title of the dialogue. + def title(title=nil) + @title = title unless title.nil? + @title + end + + # Sets the type of dialogue. + def type(type=nil) + unless type.nil? + verify_dialogue_type(type) + @type = type + end + + @type + end + + # Wraps text in this Dialogue, inserting extra Dialogues in the chain if necessary. + def wrap # TODO redo this + next if @type == :options + lines = [] + maximum_lines = MAXIMUM_LINE_COUNT + + text = @text.first + segments = segment_text(text) + + if (segments.size <= maximum_lines) + lines = segments.clone + @text = @text[1..-1] + insert_copy(@text) if @text.size > 0 + else + lines = segments.first(maximum_lines).clone + segments = [ segments.drop(maximum_lines).join() ] + insert_copy(segments << @text[1..-1].join()) + end + + @text = lines + end + + protected + + # Copies the value of every variable from the specified Dialogue, optionally updating the text array. + def copy_from(dialogue, text=nil) + @emote = dialogue.emote + @item = dialogue.item + @model = dialogue.model + @npc = dialogue.npc + @options = dialogue.options + @text = if text.nil? then dialogue.text.dup else text.dup end + @type = dialogue.type + end + + private + + def segment_text(text) + maximum_width = (@type == :text) ? MAXIMUM_LINE_WIDTH : MAXIMUM_MEDIA_LINE_WIDTH + + segments = [] + index = 0; width = 0; space = 0 + + while index < text.length + char = text[index] + space = index if char == ' ' + width += get_width(char) + index += 1 + + if (width >= maximum_width) + segments << text[0..space] + text = text[(space + 1)..-1] + width = index = space = 0 + end + end + segments << text if ! text.empty? + + segments + end + + # Inserts a copy of this Dialogue into the chain, but with different text. + def insert_copy(text) + name = @name + index = name.index('-auto-inserted-') + + id = if index.nil? then 0 else name[name.rindex('-')..-1].to_i + 1 end + index ||= -1 + name = "#{name[0..index]}-auto-inserted-#{id}" + + dialogue = Dialogue.new(name, @conversation) + dialogue.copy_from(self, text.dup) + dialogue.wrap() + + @options[0] = ->(player) { send_dialogue(player, dialogue) } + end + + # Decodes the next dialogue interface from the hash, returning a proc. + def decode_next_dialogue(hash) + hash.each_pair do |key, value| + case key + when :disabled then return ->(player) { } + when :close then return ->(player) { player.send(CloseInterfaceMessage.new) } + when :dialogue then return ->(player) { send_dialogue(player, @conversation.part(value)) } + else raise "Unrecognised dialogue continue type #{key}." + end + end + end + +end + +# The dialogue interface ids for dialogues that only display text, but with no 'Click here to continue...' message. +STATEMENT_DIALOGUE_IDS = [ 12788, 12790, 12793, 12797, 6179 ] # TODO + +# The dialogue interface ids for dialogues that display an item and text, ordered by line count. +ITEM_DIALOGUE_IDS = [ 306, 310, 315, 321 ] + +# The dialogue interface ids for dialogues that only display text, ordered by line count. +TEXT_DIALOGUE_IDS = [ 356, 359, 363, 368, 374 ] + +# The dialogue interface ids for dialogues that display the head of the player, ordered by line count. +PLAYER_DIALOGUE_IDS = [ 968, 973, 979, 986 ] + +# The dialogue interface ids for dialogues that display the head of an npc, ordered by line count. +NPC_DIALOGUE_IDS = [ 4882, 4887, 4893, 4900 ] + +# The dialogue interface ids for option dialogues, ordered by (option_count - 1) +OPTIONS_DIALOGUE_IDS = [ 2459, 2469, 2480, 2492 ] + + + +## TODO separate this into different Dialogue types ## + +# Sends a dialogue displaying an item model and text. +def send_item_dialogue(player, dialogue) + text = dialogue.text + dialogue_id = ITEM_DIALOGUE_IDS[text.size - 1] + player.send(SetWidgetItemModelMessage.new(dialogue_id + 1, dialogue.item, dialogue.item_scale)) + + indices = [ dialogue_id + 1 + 2, dialogue_id + 1 + 1, dialogue_id + 1 + 4, dialogue_id + 1 + 5 ] + + text.each_with_index { |line, index| set_text(player, indices[index], line) } + player.interface_set.open_dialogue(ContinueDialogueAdapter.new(player, dialogue.options[0]), dialogue_id) +end + +# Sends a dialogue displaying only text, with no 'Click here to continue...' button. +def send_statement_dialogue(player, dialogue) + text = dialogue.text + dialogue_id = STATEMENT_DIALOGUE_IDS[text.size] + + set_text(player, dialogue_id + 1, dialogue.title) + text.each_with_index { |line, index| set_text(player, dialogue_id + 2 + index, line) } + player.interface_set.open_dialogue_overlay(dialogue_id) +end + +# Sends a dialogue displaying only text. +def send_text_dialogue(player, dialogue) + text = dialogue.text + dialogue_id = TEXT_DIALOGUE_IDS[text.size - 1] + + text.each_with_index { |line, index| set_text(player, dialogue_id + 1 + index, line) } + player.interface_set.open_dialogue(ContinueDialogueAdapter.new(player, dialogue.options[0]), dialogue_id) +end + +# Sends a dialogue displaying the player's head. +def send_player_dialogue(player, dialogue) + emote = dialogue.emote + + send_generic_dialogue player, dialogue, player.username, PLAYER_DIALOGUE_IDS do |id| + player.send(SetWidgetPlayerModelMessage.new(id + 1)) + player.send(SetWidgetModelAnimationMessage.new(id + 1, emote)) unless emote.nil? + end +end + +# Sends a dialogue displaying the head of an npc. +def send_npc_dialogue(player, dialogue) + npc = dialogue.npc + emote = dialogue.emote + name = NpcDefinition.lookup(npc).name.to_s + name = "" if (name.nil? || name == "null") + + send_generic_dialogue player, dialogue, name, NPC_DIALOGUE_IDS do |id| + player.send(SetWidgetNpcModelMessage.new(id + 1, npc)) + player.send(SetWidgetModelAnimationMessage.new(id + 1, emote)) unless emote.nil? + end +end + +# Sends a dialogue displaying an event. +def send_generic_dialogue(player, dialogue, title, ids, &event) + text = dialogue.text + dialogue_id = ids[text.size - 1] + event.call(dialogue_id) if block_given? + + set_text(player, dialogue_title_id(dialogue_id), title) + + text.each_with_index { |line, index| set_text(player, dialogue_text_id(dialogue_id, index), line) } + player.interface_set.open_dialogue(ContinueDialogueAdapter.new(player, dialogue.options[0]), dialogue_id) +end + + +# Sends an options dialogue interface. +def send_options_dialogue(player, dialogue) + options = dialogue.options + size = options.size + raise 'Illegal options count: must be between 2 and 5, inclusive.' unless (2..5).include?(size) + + text = dialogue.text + dialogue_id = OPTIONS_DIALOGUE_IDS[size - 1] + + question = dialogue.title + set_text(player, dialogue_question_id(dialogue_id), question) + + text.each_with_index { |line, index| set_text(player, dialogue_option_id(dialogue_id, index), line) } + player.interface_set.open_dialogue(OptionDialogueAdapter.new(player, options), dialogue_id) +end + + +# A DialogueAdapter for dialogues with a 'Click here to continue...' message. +class ContinueDialogueAdapter < DialogueAdapter + + # Creates the ContinueDialogueAdadpter. + def initialize(player, continue) + super() + @player = player + @continue = continue + end + + # Executes the 'continue' lambda when the player clicks the 'Click here to continue...' message. + def continued() + @continue.call(@player) + end + +end + + +# A DialogueAdapter for dialogues with a set of options that can be selected. +class OptionDialogueAdapter < DialogueAdapter + + # Creates the OptionDialogueAdadpter. + def initialize(player, options) + super() + @player = player + @options = options.dup + end + + # Executes an option. + def button_clicked(button) + option = OPTIONS_DIALOGUE_IDS.find_index(button) + options[option].call(@player) + end + +end + + +# Gets the widget id of the question, for an options dialogue interface. +def dialogue_question_id(id) + id + 1 +end + +# Gets the widget id of a dialogue option. +def dialogue_option_id(id, option) + id + 1 + option +end + +# Gets the widget id of a dialogue text line. +def dialogue_text_id(id, line) + id + 3 + line +end + +# Gets the widget id of a dialogue title. +def dialogue_title_id(id) + id + 2 +end + +# Sets the text of a widget. +def set_text(player, id, message) + player.send(SetWidgetTextMessage.new(id, message)) +end + +# Verifies that the dialogue type exists. +def verify_dialogue_type(type) + raise "Unrecognised dialogue type #{type}, expected one of #{DIALOGUE_TYPES}." unless DIALOGUE_TYPES.include?(type) +end + +# The spacing of each character glyph, for the font used for dialogue. TODO decode the font from the cache. +GLYPH_SPACING = [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 7, 14, 9, 12, 12, 4, 5, + 5, 10, 8, 4, 8, 4, 7, 9, 7, 9, 8, 8, 8, 9, 7, 9, 9, 4, 5, 7, + 9, 7, 9, 14, 9, 8, 8, 8, 7, 7, 9, 8, 6, 8, 8, 7, 10, 9, 9, 8, + 9, 8, 8, 6, 9, 8, 10, 8, 8, 8, 6, 7, 6, 9, 10, 5, 8, 8, 7, 8, + 8, 7, 8, 8, 4, 7, 7, 4, 10, 8, 8, 8, 8, 6, 8, 6, 8, 8, 9, 8, + 8, 8, 6, 4, 6, 12, 3, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 8, 11, 8, 8, 4, 8, 7, 12, 6, 7, 9, 5, 12, 5, 6, 10, 6, 6, 6, + 8, 8, 4, 5, 5, 6, 7, 11, 11, 11, 9, 9, 9, 9, 9, 9, 9, 13, 8, 8, + 8, 8, 8, 4, 4, 5, 4, 8, 9, 9, 9, 9, 9, 9, 8, 10, 9, 9, 9, 9, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 13, 6, 8, 8, 8, 8, 4, 4, 5, 4, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 ] + +# Gets the width of a single character. +def get_width(char) + return GLYPH_SPACING[char.ord] +end diff --git a/game/data/plugins/dialogue/emotes.rb b/game/data/plugins/dialogue/emotes.rb new file mode 100644 index 000000000..77eea3e4b --- /dev/null +++ b/game/data/plugins/dialogue/emotes.rb @@ -0,0 +1,31 @@ +# Declares all of the possible emotes +declare_emote(:calm, 588) +declare_emote(:anxious, 589) +declare_emote(:calm_talk, 590) +declare_emote(:default, 591) +declare_emote(:evil, 592) +declare_emote(:bad, 593) +declare_emote(:wicked, 594) +declare_emote(:annoyed, 595) +declare_emote(:distressed, 596) +declare_emote(:afflicted, 597) +declare_emote(:almost_crying, 598) +declare_emote(:drunk_left, 600) +declare_emote(:drunk_right, 601) +declare_emote(:not_interested, 602) +declare_emote(:sleepy, 603) +declare_emote(:plain_evil, 604) +declare_emote(:laugh, 605) +declare_emote(:snigger, 606) +declare_emote(:have_fun, 607) +declare_emote(:guffaw, 608) +declare_emote(:evil_laugh, 609) +declare_emote(:sad, 610) +declare_emote(:more_sad, 611) +declare_emote(:on_one_hand, 612) +declare_emote(:nearly_crying, 613) +declare_emote(:angry, 614) +declare_emote(:furious, 615) +declare_emote(:enraged, 616) +declare_emote(:mad, 617) + diff --git a/game/data/plugins/dialogue/plugin.xml b/game/data/plugins/dialogue/plugin.xml new file mode 100644 index 000000000..95a7402f5 --- /dev/null +++ b/game/data/plugins/dialogue/plugin.xml @@ -0,0 +1,17 @@ + + + dialogue + 0.1 + Dialogue + Adds dialogue support. + + Major + + + + + + + util + + \ No newline at end of file diff --git a/game/data/plugins/dummy/dummy.rb b/game/data/plugins/dummy/dummy.rb new file mode 100644 index 000000000..f602f32ae --- /dev/null +++ b/game/data/plugins/dummy/dummy.rb @@ -0,0 +1,51 @@ +require 'java' + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.model.Animation' + +DUMMY_ID = 823 +DUMMY_SIZE = 1 +PUNCH_ANIMATION = Animation.new(422) +ANIMATION_PULSES = 0 +LEVEL_THRESHOLD = 8 +EXP_PER_HIT = 5 + +# A DistancedAction for attacking a training dummy. +class DummyAction < DistancedAction + attr_reader :position + + def initialize(mob, position) + super(ANIMATION_PULSES, true, mob, position, DUMMY_SIZE) + + @position = position + @started = false + end + + def executeAction + if @started + skills = mob.skill_set + + if (skills.skill(Skill::ATTACK).maximum_level >= LEVEL_THRESHOLD) + mob.send_message('There is nothing more you can learn from hitting a dummy.') + else + skills.add_experience(Skill::ATTACK, EXP_PER_HIT) + end + + stop + else + @started = true + + mob.send_message('You hit the dummy.') + mob.turn_to(position) + mob.play_animation(PUNCH_ANIMATION) + end + end + + def equals(other) + get_class == other.get_class && @position == other.position + end +end + +on :message, :second_object_action do |player, message| + player.start_action(DummyAction.new(player, message.position)) if message.id == DUMMY_ID +end diff --git a/game/data/plugins/dummy/plugin.xml b/game/data/plugins/dummy/plugin.xml new file mode 100644 index 000000000..2bf4f8d31 --- /dev/null +++ b/game/data/plugins/dummy/plugin.xml @@ -0,0 +1,14 @@ + + + dummy + 1 + Dummies + Allows low-level players to train on dummies. + + Graham + + + + + + diff --git a/game/data/plugins/emote-tab/emote_tab.rb b/game/data/plugins/emote-tab/emote_tab.rb new file mode 100644 index 000000000..6bf3bbdc1 --- /dev/null +++ b/game/data/plugins/emote-tab/emote_tab.rb @@ -0,0 +1,57 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' + +# Animation constants. +ANGRY = Animation.new(859) +BECKON = Animation.new(864) +BLOW_KISS = Animation.new(1368) +BOW = Animation.new(858) +CHEER = Animation.new(862) +CLAP = Animation.new(865) +CLIMB_ROPE = Animation.new(1130) +CRY = Animation.new(860) +DANCE = Animation.new(866) +GLASS_BOX = Animation.new(1131) +GLASS_WALL = Animation.new(1128) +GOBLIN_BOW = Animation.new(2127) +GOBLIN_DANCE = Animation.new(2128) +HEAD_BANG = Animation.new(2108) +JIG = Animation.new(2106) +JOY_JUMP = Animation.new(2109) +LAUGH = Animation.new(861) +LEAN = Animation.new(1129) +NO = Animation.new(856) +PANIC = Animation.new(2105) +RASPBERRY = Animation.new(2110) +SALUTE = Animation.new(2112) +SHRUG = Animation.new(2113) +SPIN = Animation.new(2107) +THINKING = Animation.new(857) +WAVE = Animation.new(863) +YAWN = Animation.new(2111) +YES = Animation.new(855) + +# A map of buttons to animations. +ANIMATIONS = { + 162 => THINKING, 6_503 => CLIMB_ROPE, 169 => NO, + 164 => BOW, 13_384 => GOBLIN_DANCE, 161 => CRY, + 170 => LAUGH, 171 => CHEER, 163 => WAVE, + 167 => BECKON, 3_362 => PANIC, 172 => CLAP, + 166 => DANCE, 13_363 => JIG, 13_364 => SPIN, + 13_365 => HEAD_BANG, 6_506 => LEAN, 165 => ANGRY, + 13_368 => YAWN, 13_366 => JOY_JUMP, 667 => GLASS_BOX, + 13_367 => RASPBERRY, 13_369 => SALUTE, 13_370 => SHRUG, + 11_100 => BLOW_KISS, 666 => GLASS_WALL, 168 => YES, + 13_383 => GOBLIN_BOW +} + +# Intercept the button message. +on :message, :button do |player, message| + anim = ANIMATIONS[message.widget_id] + + unless anim.nil? + player.play_animation(anim) + message.terminate + end +end diff --git a/game/data/plugins/emote-tab/plugin.xml b/game/data/plugins/emote-tab/plugin.xml new file mode 100644 index 000000000..6485d83c1 --- /dev/null +++ b/game/data/plugins/emote-tab/plugin.xml @@ -0,0 +1,14 @@ + + + emote-tab + 1 + Emote Tab + Adds emote tab functionality. + + Major + + + + + + diff --git a/game/data/plugins/entity/attributes/attributes.rb b/game/data/plugins/entity/attributes/attributes.rb new file mode 100644 index 000000000..d16a00aac --- /dev/null +++ b/game/data/plugins/entity/attributes/attributes.rb @@ -0,0 +1,79 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.Mob' +java_import 'org.apollo.game.model.entity.Npc' +java_import 'org.apollo.game.model.entity.Player' +java_import 'org.apollo.game.model.entity.attr.Attribute' +java_import 'org.apollo.game.model.entity.attr.AttributeDefinition' +java_import 'org.apollo.game.model.entity.attr.AttributeMap' +java_import 'org.apollo.game.model.entity.attr.AttributePersistence' +java_import 'org.apollo.game.model.entity.attr.AttributeType' +java_import 'org.apollo.game.model.entity.attr.BooleanAttribute' +java_import 'org.apollo.game.model.entity.attr.NumericalAttribute' +java_import 'org.apollo.game.model.entity.attr.StringAttribute' + +# Declares an attribute and adds its definition. +def declare_attribute(name, default, persistence = :transient) + if Player.method_defined?(name) || Mob.method_defined?(name) || Npc.method_defined?(name) + fail "Attribute #{name} clashes with an existing variable." + end + + definition = AttributeDefinition.new(default, get_persistence(persistence), get_type(default)) + AttributeMap::define(name.to_s, definition) +end + +private + +# The existing Mob class. +class Mob + + # Overrides method_missing to implement the functionality. + def method_missing(symbol, *args) + name = symbol.to_s.strip + + if name[-1] == '=' + fail "Expected argument count of 1, received #{args.length}" unless args.length == 1 + + name = name[0...-1].strip # Drop the equals and trim whitespace. + set_attribute(name, to_attribute(args[0])) + elsif AttributeMap::get_definition(name).nil? + super(symbol, *args) + else + attribute = get_attribute(name) + value = attribute.value + (attribute.type == AttributeType::SYMBOL) ? value.to_sym : value + end + end + +end + +# Gets the appropriate attribute for the specified value. +def to_attribute(value) + case value + when String, Symbol then return StringAttribute.new(value.to_s, value.is_a?(Symbol)) + when Integer, Float then return NumericalAttribute.new(value) + when TrueClass, FalseClass then return BooleanAttribute.new(value) + else fail "Undefined attribute type #{value.class}." + end +end + +# Gets the attribute type of the specified value. +def get_type(value) + case value + when String then return AttributeType::STRING + when Symbol then return AttributeType::SYMBOL + when Integer then return AttributeType::LONG + when Float then return AttributeType::DOUBLE + when TrueClass, FalseClass then return AttributeType::BOOLEAN + else fail "Undefined attribute type #{value.class}." + end +end + +# Gets the Persistence type of the specified value. +def get_persistence(persistence) + unless [:persistent, :transient].include?(persistence) + fail "Undefined persistence type #{persistence}." + end + + (persistence == :persistent) ? AttributePersistence::PERSISTENT : AttributePersistence::TRANSIENT +end diff --git a/game/data/plugins/entity/attributes/plugin.xml b/game/data/plugins/entity/attributes/plugin.xml new file mode 100644 index 000000000..ea11bba46 --- /dev/null +++ b/game/data/plugins/entity/attributes/plugin.xml @@ -0,0 +1,14 @@ + + + attributes + 0.9 + Attributes + Adds an attribute system for entites. + + Major + + + + + + \ No newline at end of file diff --git a/game/data/plugins/entity/mob/extension/extension.rb b/game/data/plugins/entity/mob/extension/extension.rb new file mode 100644 index 000000000..11e20c0d7 --- /dev/null +++ b/game/data/plugins/entity/mob/extension/extension.rb @@ -0,0 +1,20 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.Mob' + +module MobExtension + MOB_EXTENSIONS = [] + + def self.register(extension) + fail 'Provided extension object is not a module' unless extension.is_a?(Module) + + new_mixins = extension.public_instance_methods + current_mixins = MOB_EXTENSIONS.map { |e| {e.to_s => e.public_instance_methods} } + + current_mixins.each do |ext, methods| + methods.each {|m| fail "Extension #{ext} already provides method #{m}" if new_mixins.include?(m) } + end + + Mob.include(extension) + end +end \ No newline at end of file diff --git a/game/data/plugins/entity/mob/extension/plugin.xml b/game/data/plugins/entity/mob/extension/plugin.xml new file mode 100644 index 000000000..e2c7d250e --- /dev/null +++ b/game/data/plugins/entity/mob/extension/plugin.xml @@ -0,0 +1,15 @@ + + + mob-extension + 0.1 + Mob Extensions + Adds support for extending Mobs with new functionality + + Gary Tierney + + + + + + + \ No newline at end of file diff --git a/game/data/plugins/entity/mob/following/following.rb b/game/data/plugins/entity/mob/following/following.rb new file mode 100644 index 000000000..0ca139c40 --- /dev/null +++ b/game/data/plugins/entity/mob/following/following.rb @@ -0,0 +1,58 @@ +on :message, :walk do |player, msg| + player.reset_interacting_mob +end + +on :message, :player_action do |player, msg| + ## todo: need a better way of mapping option numbers to their purpose + player.follow($world.player_repository.get(msg.index)) if msg.option == 3 +end + +## +# A MobExtension for making a Mob trail behind, or chase a given mob. +module FollowingMobExtension + ## + # Follow a mob and trail behind them. + def follow(mob) + do_follow(self, mob, behind: true) + end + + ## + # Chase a mob (with the intention of getting in front of them), also optionally + # stopping within a projectile distance when at a position where a projectile can + # reach the target. + def chase(mob, projectile_distance: nil) + do_follow(self, mob, front: true, projectile_distance: projectile_distance) + end +end + +MobExtension::register(FollowingMobExtension) + +private + +def do_follow(source, mob, behind: false, front: false, projectile_distance: nil) + source.interacting_mob = mob + + schedule 0, true do |task| + # stop the task unless we're still interacting with the other mob. + unless self.interacting_mob.eql? mob + task.stop + next + end + + next unless source.walking_queue.size <= 1 + + distance = mob.position.get_distance(source.position) + + unless projectile_distance.nil? + next if distance <= projectile_distance && + $world.collision_manager.raycast(source.position, mob.position) + end + + if distance > 15 + reset_interacting_mob + end + + walk_to(mob, behind: behind, front: front) + end +end + diff --git a/game/data/plugins/entity/mob/following/plugin.xml b/game/data/plugins/entity/mob/following/plugin.xml new file mode 100644 index 000000000..b4480d882 --- /dev/null +++ b/game/data/plugins/entity/mob/following/plugin.xml @@ -0,0 +1,16 @@ + + + mob-following + 1 + Following + Adds following for mobs. + + Steve Soltys + + + + + + mob-walk-to + + diff --git a/game/data/plugins/entity/mob/walk-to/plugin.xml b/game/data/plugins/entity/mob/walk-to/plugin.xml new file mode 100644 index 000000000..676560e80 --- /dev/null +++ b/game/data/plugins/entity/mob/walk-to/plugin.xml @@ -0,0 +1,16 @@ + + + mob-walk-to + 0.1 + Mob path generation + Adds a mixin for making mobs walk to another entity. + + Gary Tierney + + + + + + mob-extension + + \ No newline at end of file diff --git a/game/data/plugins/entity/mob/walk-to/walk_to.rb b/game/data/plugins/entity/mob/walk-to/walk_to.rb new file mode 100644 index 000000000..6381172f1 --- /dev/null +++ b/game/data/plugins/entity/mob/walk-to/walk_to.rb @@ -0,0 +1,83 @@ +java_import 'org.apollo.game.model.entity.path.AStarPathfindingAlgorithm' +java_import 'org.apollo.game.model.entity.path.EuclideanHeuristic' +java_import 'org.apollo.game.model.entity.path.SimplePathfindingAlgorithm' +java_import 'org.apollo.game.model.entity.obj.GameObject' +java_import 'org.apollo.game.model.entity.Mob' +java_import 'org.apollo.game.model.entity.Player' +java_import 'org.apollo.game.model.entity.EntityType' +java_import 'org.apollo.game.model.Direction' + +## +# A pathfinder used for simple following (i.e.: An NPC attacking a player). +SIMPLE_PATH_FINDER = SimplePathfindingAlgorithm.new($world.collision_manager) + +## +# A pathfinder used for precise following (i.e.: A player attacking another player). +FOLLOW_PATH_FINDER = AStarPathfindingAlgorithm.new($world.collision_manager, EuclideanHeuristic.new) + +## +# The directions that we use as a random offset when not walking to the facing direction. +OFFSET_DIRECTIONS = Direction::NESW.to_a + +module WalkToMobExtension + def walk_to(entity, front: false, behind: false) + if [front, behind].count { |option| option == true } > 1 + fail 'Can only specify one of "front" or "behind"' + end + + position = self.position + target_position = entity.position + target_distance = position.get_distance(target_position) + target_offset = walk_to_offset(entity) + target_offset_direction = OFFSET_DIRECTIONS.sample + target_facing_direction = walk_to_facing_direction(entity) + + unless target_facing_direction.nil? + if front + target_offset_direction = target_facing_direction + elsif behind + target_offset_direction = target_facing_direction.opposite + end + end + + target_offset_position = target_position.step(target_offset, target_offset_direction) + return if target_offset_position.eql?(position) + + pathfinder = FOLLOW_PATH_FINDER + path = pathfinder.find(position, target_offset_position) + path.each { |tile| self.walking_queue.add_step(tile) } + end +end + +MobExtension::register(WalkToMobExtension) + +private + +## +# Gets the number of tiles away from an entity's actual origin that we can +# walk to. +def walk_to_offset(entity) + case entity.entity_type + when EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT + return max(entity.definition.width, entity.definition.length) + 1 + when EntityType::NPC + return entity.definition.size + 1 + when EntityType::PLAYER + return 1 + else + fail "walk_to_offset called with invalid entity type: #{type.to_s}" + end +end + +## +# Gets the direction that an entity is facing, so a mob can walk up infront of them. +def walk_to_facing_direction(entity) + case entity.entity_type + when EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT + return Direction::WNES[entity.orientation] + when EntityType::NPC, EntityType::PLAYER + return entity.last_direction + else + fail "walk_to_offset called with invalid entity type: #{type.to_s}" + end +end \ No newline at end of file diff --git a/game/data/plugins/entity/spawning/npc-spawn.rb b/game/data/plugins/entity/spawning/npc-spawn.rb new file mode 100644 index 000000000..e90fcb848 --- /dev/null +++ b/game/data/plugins/entity/spawning/npc-spawn.rb @@ -0,0 +1,197 @@ +require 'java' + +java_import 'org.apollo.cache.def.NpcDefinition' +java_import 'org.apollo.game.action.Action' +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Graphic' +java_import 'org.apollo.game.model.Position' +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.entity.Npc' + +# Information about npc spawning +# +# Npcs are passed to spawn npc as a hash. Every key and every non-integer value must be a Symbol. +# Every hash must implement the following: +# :name - the name of the npc. If this npc shares its name with another, append the specific id +# after the name (e.g. :woman_4) +# :x - the x coordinate where the npc will spawn. +# :y - the y coordinate where the npc will spawn. +# Optional arguments are as follows: +# :face - the direction the npc should face when it spawns. Supported options are :north, +# :north_east, :east, :south_east, :south, :south_west, :west, and :north_west +# :bounds - the rectangular bound that the npc can wander about in. Order is +# [bottom-left x-coordinate, bottom-left y-coordinate, top-right x-coordinate, +# top-right y-coordinate] +# :delta_bounds - the rectangular bound that the npc can wander about in, as a difference from +# the spawn point. Order is [x-delta, y-delta]. Should not be used with :bounds. +# :spawn_animation - the animation that will be played when the npc spawns. +# :spawn_graphic - the graphic that will be played when the npc spawns. + +# Spawns an npc with the properties specified in the hash. +def spawn_npc(hash) + unless (hash.key?(:name) || hash.key?(:id)) && hash.has_keys?(:x, :y) + fail 'A name (or id), x coordinate, and y coordinate must be specified to spawn an npc.' + end + + npc = get_npc(hash) + spawn(npc, hash) + npc +end + +# Spawns the specified npc and applies the properties in the hash. +def spawn(npc, hash) + unless hash.empty? + hash = decode_hash(npc.position, hash) + apply_decoded_hash(npc, hash) + end + + $world.register(npc) +end + +# Returns an npc with the id and position specified by the hash. +def get_npc(hash) + id = lookup_npc(hash.delete(:name)) + + z = hash.delete(:z) + position = Position.new(hash.delete(:x), hash.delete(:y), z.nil? ? 0 : z) + Npc.new($world, id, position) +end + +# Applies a decoded hash (one aquired using parse_hash) to the specified npc. +def apply_decoded_hash(npc, hash) + hash.each do |key, value| + case key + when :face then npc.turn_to(value) + when :boundary then npc.boundaries = value + when :spawn_animation then npc.play_animation(Animation.new(value)) + when :spawn_graphic then npc.play_graphic(Graphic.new(value)) + else fail "Unrecognised key #{key} - value #{value}." + end + end +end + +# Parses the remaining key-value pairs in the hash. +def decode_hash(position, hash) + decoded = {} + + hash.each do |key, value| + case key + when :face + decoded[:face] = direction_to_position(value, position) + when :delta_bounds + fail ':delta_bounds must have two values.' unless value.length == 2 + dx, dy, x, y, z = value[0], value[1], position.x, position.y, position.height + fail 'Delta values cannot be less than 0.' if dx < 0 || dy < 0 + + decoded[:boundary] = [Position.new(x - dx, y - dy, z), Position.new(x + dx, y + dy, z)] + when :bounds + fail ':bounds must have four values.' unless value.length == 4 + min_x, min_y, max_x, max_y = value[0], value[1], value[2], value[3] + + decoded[:boundary] = [Position.new(min_x, min_y), Position.new(max_x, max_y)] + when :spawn_animation then decoded[:spawn_animation] = Animation.new(value) + when :spawn_graphic then decoded[:spawn_graphic] = Graphic.new(value) + else fail "Unrecognised key #{key} - value #{value}." + end + end + + decoded +end + +# Returns a position that an entity at the specified position should be facing towards if they are +# looking in the specified direction. +def direction_to_position(direction, position) + x, y, z = position.x, position.y, position.height + + case direction + when :north then return Position.new(x, y + 1, z) + when :north_east then return Position.new(x + 1, y + 1, z) + when :east then return Position.new(x + 1, y, z) + when :south_east then return Position.new(x + 1, y - 1, z) + when :south then return Position.new(x, y - 1, z) + when :south_west then return Position.new(x - 1, y - 1, z) + when :west then return Position.new(x - 1, y, z) + when :north_west then return Position.new(x - 1, y + 1, z) + else return position + end +end + +# An action that spawns an npc temporarily, before executing an action. +class TemporaryNpcAction < Action + attr_reader :executions, :combative + + def initialize(delay, immediate, hash) + super(delay, immediate, get_npc(hash)) + + @executions = 0 + @hash = hash + end + + def execute + if @executions == 0 + spawn(mob, @hash) + execute_spawn_action + else + execute_action + end + + @executions += 1 + end + + def execute_action + # Override to provide functionality. + end + + def execute_spawn_action + # Overridden to provide functionality for when the npc spawns. + end + +end + +# A random event that spawns and executes some sort of action. +class RandomEvent < TemporaryNpcAction + + def initialize(delay, immediate, hash, combative, target) + super(delay, immediate, hash) + + @combative = combative + @target = target + end + + def execute_spawn_action + mob.turn_to(target.position) + mob.update_interacting_mob(target.index) + end + +end + +# Adds a random event to the array. +def register_random_event(event) + RANDOM_EVENTS << event +end + +# Contains random event npcs +RANDOM_EVENTS = [] + +# Spawns a random event for the specified player. +def send_random_event(player) + position = player.position + npc_position = Position.new(position.x + 1, position.y, position.height) + # TODO: Find an unoccupied tile instead of the assumption that (x + 1) is traversable!! + + spawn_random_event(npc_position, false) +end + +# Spawns a random event in the specified position. +# If 'combat' is false, only non-combat events will be spawned. +def spawn_random_event(_position, _combat) + event = RANDOM_EVENTS[rand(RANDOM_EVENTS.size)] + attempts = 0 + + while event.combative && attempts < 5 + event = RANDOM_EVENTS[rand(RANDOM_EVENTS.size)] + attempts += 1 + end + + event.execute unless attempts == 5 # 5 iterations is plenty, just give up at this point +end diff --git a/game/data/plugins/entity/spawning/plugin.xml b/game/data/plugins/entity/spawning/plugin.xml new file mode 100644 index 000000000..ac3b0b799 --- /dev/null +++ b/game/data/plugins/entity/spawning/plugin.xml @@ -0,0 +1,16 @@ + + + entity-spawning + 0.1 + Entity Spawning + Adds support for easy ruby entity spawning. + + Major + + + + + + util + + \ No newline at end of file diff --git a/game/data/plugins/location/al-kharid/npcs.rb b/game/data/plugins/location/al-kharid/npcs.rb new file mode 100644 index 000000000..daa55d89f --- /dev/null +++ b/game/data/plugins/location/al-kharid/npcs.rb @@ -0,0 +1,89 @@ +# Generic npcs + +spawn_npc name: :man, x: 3276, y: 3186 +spawn_npc name: :man, x: 3282, y: 3197 +spawn_npc name: :man_3, x: 3301, y: 3200 +spawn_npc name: :man_3, x: 3300, y: 3208 +spawn_npc name: :man_2, x: 3297, y: 3196 +spawn_npc name: :man_16, x: 3294, y: 3204 +spawn_npc name: :spider_61, x: 3319, y: 3145 +spawn_npc name: :spider_61, x: 3319, y: 3140 +spawn_npc name: :spider_61, x: 3323, y: 3138 +spawn_npc name: :scorpion, x: 3282, y: 3149 + +# Camels +spawn_npc name: :cam_the_camel, x: 3295, y: 3232 +spawn_npc name: :elly_the_camel, x: 3312, y: 3210 +spawn_npc name: :camel, x: 3285, y: 3198 +spawn_npc name: :ollie_the_camel, x: 3291, y: 3209 +spawn_npc name: :al_the_camel, x: 3275, y: 3162 + +# Quest npc +spawn_npc name: :osman, x: 3286, y: 3180, face: :east +spawn_npc name: :hassan, x: 3302, y: 3163 +spawn_npc name: :father_reen, x: 3272, y: 3158 +spawn_npc name: :man_663, x: 3297, y: 3287 + +# Boarder guards + +spawn_npc name: 'border_guard', x: 3268, y: 3226, face: :north +spawn_npc name: 'border_guard', x: 3267, y: 3226, face: :north +spawn_npc name: 'border_guard', x: 3268, y: 3229, face: :south +spawn_npc name: 'border_guard', x: 3267, y: 3229, face: :south + +# Palace guards + +spawn_npc name: 'Al-Kharid warrior', x: 3285, y: 3174 +spawn_npc name: 'Al-Kharid warrior', x: 3283, y: 3168 +spawn_npc name: 'Al-Kharid warrior', x: 3285, y: 3169 +spawn_npc name: 'Al-Kharid warrior', x: 3290, y: 3162 +spawn_npc name: 'Al-Kharid warrior', x: 3295, y: 3162 +spawn_npc name: 'Al-Kharid warrior', x: 3295, y: 3170 +spawn_npc name: 'Al-Kharid warrior', x: 3300, y: 3175 +spawn_npc name: 'Al-Kharid warrior', x: 3300, y: 3171 +spawn_npc name: 'Al-Kharid warrior', x: 3301, y: 3168 + +# Shanty pass +spawn_npc name: :shantay_guard, x: 3301, y: 3120 +spawn_npc name: :shantay_guard, x: 3302, y: 3126 +spawn_npc name: :shantay_guard, x: 3306, y: 3126 +spawn_npc name: :shantay_guard_838, x: 3303, y: 3118, face: :north + +# Mine + +spawn_npc name: :scorpion, x: 3296, y: 3294 +spawn_npc name: :scorpion, x: 3298, y: 3280 +spawn_npc name: :scorpion, x: 3299, y: 3299 +spawn_npc name: :scorpion, x: 3299, y: 3309 +spawn_npc name: :scorpion, x: 3300, y: 3287 +spawn_npc name: :scorpion, x: 3300, y: 3315 +spawn_npc name: :scorpion, x: 3301, y: 3305 +spawn_npc name: :scorpion, x: 3301, y: 3312 + +# Functional npcs + +spawn_npc name: :gnome_pilot, x: 3279, y: 3213 + +spawn_npc name: :banker_496, x: 3267, y: 3164, face: :east +spawn_npc name: :banker_497, x: 3267, y: 3166, face: :east +spawn_npc name: :banker_496, x: 3267, y: 3167, face: :east +spawn_npc name: :banker_497, x: 3267, y: 3168, face: :east +spawn_npc name: :banker_496, x: 3267, y: 3169, face: :east + +spawn_npc name: :gem_trader, x: 3287, y: 3210 +spawn_npc name: :zeke, x: 3289, y: 3189 +spawn_npc name: :shantay, x: 3304, y: 3124 + +spawn_npc name: :rug_merchant_2296, x: 3311, y: 3109, face: :west +spawn_npc name: :ranael, x: 3315, y: 3163, face: :north + +spawn_npc name: :shop_assistant_525, x: 3315, y: 3178, face: :north +spawn_npc name: :shop_keeper_524, x: 3315, y: 3180, face: :west +spawn_npc name: :louie_legs, x: 3316, y: 3175, face: :west +spawn_npc name: :ellis, x: 3274, y: 3192 +spawn_npc name: :dommik, x: 3321, y: 3193 + +spawn_npc name: :tool_leprechaun, x: 3319, y: 3204 +spawn_npc name: :ali_morrisane, x: 3304, y: 3211, face: :east +spawn_npc name: :silk_trader, x: 3300, y: 3203 +spawn_npc name: :karim, x: 3273, y: 3180 diff --git a/game/data/plugins/location/al-kharid/plugin.xml b/game/data/plugins/location/al-kharid/plugin.xml new file mode 100644 index 000000000..64a10ed92 --- /dev/null +++ b/game/data/plugins/location/al-kharid/plugin.xml @@ -0,0 +1,16 @@ + + + location-al-kharid + 0.1 + Al-Kharid + Adds functionality to Al-Kharid. + + Major + + + + + + entity-spawning + + \ No newline at end of file diff --git a/game/data/plugins/location/edgeville/npcs.rb b/game/data/plugins/location/edgeville/npcs.rb new file mode 100644 index 000000000..d73ad2b6e --- /dev/null +++ b/game/data/plugins/location/edgeville/npcs.rb @@ -0,0 +1,45 @@ +# Generic npcs + +spawn_npc name: :man, x: 3095, y: 3508 +spawn_npc name: :man, x: 3095, y: 3511 +spawn_npc name: :man, x: 3098, y: 3509 +spawn_npc name: :man_2, x: 3093, y: 3511 +spawn_npc name: :man_3, x: 3097, y: 3508 +spawn_npc name: :man_3, x: 3092, y: 3508 +spawn_npc name: :man_3, x: 3097, y: 3512 + +spawn_npc name: :guard, x: 3086, y: 3516 +spawn_npc name: :guard, x: 3094, y: 3518 +spawn_npc name: :guard, x: 3108, y: 3514 +spawn_npc name: :guard, x: 3110, y: 3514 +spawn_npc name: :guard, x: 3113, y: 3514 +spawn_npc name: :guard, x: 3113, y: 3516 + +spawn_npc name: :sheep_43, x: 3050, y: 3516 +spawn_npc name: :sheep_43, x: 3051, y: 3514 +spawn_npc name: :sheep_43, x: 3056, y: 3517 +spawn_npc name: :ram_3673, x: 3048, y: 3515 + +spawn_npc name: :monk, x: 3044, y: 3491 +spawn_npc name: :monk, x: 3045, y: 3483 +spawn_npc name: :monk, x: 3045, y: 3497 +spawn_npc name: :monk, x: 3050, y: 3490 +spawn_npc name: :monk, x: 3054, y: 3490 +spawn_npc name: :monk, x: 3058, y: 3497 + +# Functional npcs + +spawn_npc name: :richard, x: 3098, y: 3516 +spawn_npc name: :doris, x: 3079, y: 3491 +spawn_npc name: :brother_jered, x: 3045, y: 3488 +spawn_npc name: :brother_althric, x: 3054, y: 3504 +spawn_npc name: :abbot_langley, x: 3059, y: 3484 +spawn_npc name: :oziach, x: 3067, y: 3518, face: :east +spawn_npc name: :shop_keeper_528, x: 3079, y: 3509 +spawn_npc name: :shop_assistant_529, x: 3082, y: 3513 + +spawn_npc name: :banker, x: 3096, y: 3489, face: :west +spawn_npc name: :banker_495, x: 3096, y: 3491, face: :west +spawn_npc name: :banker_495, x: 3096, y: 3492, face: :north +spawn_npc name: :banker, x: 3098, y: 3492, face: :north +spawn_npc name: :mage_of_zamorak, x: 3106, y: 3560 diff --git a/game/data/plugins/location/edgeville/plugin.xml b/game/data/plugins/location/edgeville/plugin.xml new file mode 100644 index 000000000..5874d0a2e --- /dev/null +++ b/game/data/plugins/location/edgeville/plugin.xml @@ -0,0 +1,17 @@ + + + location-edgeville + 0.1 + Edgeville + Adds functionality to Edgeville. + + xEliqa + Major + + + + + + entity-spawning + + \ No newline at end of file diff --git a/game/data/plugins/location/falador/npcs.rb b/game/data/plugins/location/falador/npcs.rb new file mode 100644 index 000000000..9d55c2e19 --- /dev/null +++ b/game/data/plugins/location/falador/npcs.rb @@ -0,0 +1,157 @@ +# Generic npcs + +spawn_npc name: :chicken, x: 2965, y: 3345 + +spawn_npc name: :duck, x: 2988, y: 3383 +spawn_npc name: :duck, x: 2992, y: 3383 +spawn_npc name: :duck, x: 2993, y: 3385 + +spawn_npc name: :drunken_man, x: 2957, y: 3368, z: 1 + +spawn_npc name: :dwarf_118, x: 3023, y: 3334 +spawn_npc name: :dwarf_118, x: 3027, y: 3341 +spawn_npc name: :dwarf_118, x: 3012, y: 3341 +spawn_npc name: :dwarf_118, x: 3017, y: 3346, z: 1 +spawn_npc name: :dwarf_118, x: 3011, y: 3341, z: 1 + +spawn_npc name: :dwarf_121, x: 3027, y: 3341 +spawn_npc name: :dwarf_382, x: 3017, y: 3340 +spawn_npc name: :dwarf_3294, x: 3022, y: 3338 +spawn_npc name: :dwarf_3295, x: 3021, y: 3341 + +spawn_npc name: :gardener, x: 2998, y: 3385 +spawn_npc name: :gardener, x: 3019, y: 3369 +spawn_npc name: :gardener_3234, x: 3016, y: 3386 + +spawn_npc name: :guard, x: 2965, y: 3394 +spawn_npc name: :guard, x: 2964, y: 3396 +spawn_npc name: :guard, x: 2966, y: 3397 +spawn_npc name: :guard, x: 2964, y: 3384 +spawn_npc name: :guard, x: 2963, y: 3380 +spawn_npc name: :guard, x: 3006, y: 3325 +spawn_npc name: :guard, x: 3008, y: 3320 +spawn_npc name: :guard, x: 3006, y: 3322 +spawn_npc name: :guard, x: 3038, y: 3356 + +spawn_npc name: :guard_10, x: 2942, y: 3375 +spawn_npc name: :guard_10, x: 3040, y: 3352 + +spawn_npc name: :guard_3230, x: 2967, y: 3395 +spawn_npc name: :guard_3230, x: 2966, y: 3392 +spawn_npc name: :guard_3230, x: 2963, y: 3376 +spawn_npc name: :guard_3230, x: 2954, y: 3382 +spawn_npc name: :guard_3231, x: 2950, y: 3377 +spawn_npc name: :guard_3231, x: 2968, y: 3381 + +spawn_npc name: :guard_3231, x: 3033, y: 3389, z: 1 +spawn_npc name: :guard_3231, x: 3041, y: 3388, z: 1 +spawn_npc name: :guard_3231, x: 3048, y: 3389, z: 1 +spawn_npc name: :guard_3231, x: 3056, y: 3389, z: 1 +spawn_npc name: :guard_3231, x: 3062, y: 3386, z: 1 +spawn_npc name: :guard_3231, x: 3058, y: 3329, z: 1 +spawn_npc name: :guard_3231, x: 3050, y: 3329, z: 1 +spawn_npc name: :guard_3231, x: 3038, y: 3329, z: 1 +spawn_npc name: :guard_3231, x: 3029, y: 3329, z: 1 + +spawn_npc name: :swan, x: 2960, y: 3359 +spawn_npc name: :swan, x: 2963, y: 3360 +spawn_npc name: :swan, x: 2968, y: 3359 +spawn_npc name: :swan, x: 2971, y: 3360 +spawn_npc name: :swan, x: 2976, y: 3358 +spawn_npc name: :swan, x: 2989, y: 3384 + +spawn_npc name: :man_3223, x: 2991, y: 3365 +spawn_npc name: :man_3225, x: 3037, y: 3345, z: 1 + +spawn_npc name: :white_knight, x: 2983, y: 3343 +spawn_npc name: :white_knight, x: 2981, y: 3334 +spawn_npc name: :white_knight, x: 2988, y: 3335 +spawn_npc name: :white_knight, x: 2996, y: 3342 +spawn_npc name: :white_knight, x: 2960, y: 3340 +spawn_npc name: :white_knight, x: 2962, y: 3336 +spawn_npc name: :white_knight, x: 2974, y: 3342 +spawn_npc name: :white_knight, x: 2972, y: 3345 +spawn_npc name: :white_knight, x: 2977, y: 3348 + +spawn_npc name: :white_knight_3348, x: 2971, y: 3340 +spawn_npc name: :white_knight_3348, x: 2978, y: 3350 + +spawn_npc name: :white_knight, x: 2964, y: 3330, z: 1 +spawn_npc name: :white_knight, x: 2968, y: 3334, z: 1 +spawn_npc name: :white_knight, x: 2969, y: 3339, z: 1 +spawn_npc name: :white_knight, x: 2978, y: 3332, z: 1 +spawn_npc name: :white_knight, x: 2958, y: 3340, z: 1 +spawn_npc name: :white_knight, x: 2960, y: 3343, z: 1 + +spawn_npc name: :white_knight_3348, x: 2987, y: 3334, z: 1 +spawn_npc name: :white_knight_3348, x: 2983, y: 3336, z: 1 +spawn_npc name: :white_knight_3348, x: 2987, y: 3334, z: 1 +spawn_npc name: :white_knight_3348, x: 2979, y: 3348, z: 1 +spawn_npc name: :white_knight_3348, x: 2964, y: 3337, z: 1 + +spawn_npc name: :white_knight_3349, x: 2989, y: 3344, z: 1 + +spawn_npc name: :white_knight, x: 2985, y: 3342, z: 2 +spawn_npc name: :white_knight_3348, x: 2979, y: 3348, z: 2 +spawn_npc name: :white_knight_3348, x: 2974, y: 3329, z: 2 +spawn_npc name: :white_knight_3348, x: 2982, y: 3341, z: 2 + +spawn_npc name: :white_knight_3349, x: 2990, y: 3341, z: 2 +spawn_npc name: :white_knight_3349, x: 2971, y: 3330, z: 2 +spawn_npc name: :white_knight_3349, x: 2965, y: 3350, z: 2 +spawn_npc name: :white_knight_3349, x: 2965, y: 3329, z: 2 + +spawn_npc name: :white_knight_3350, x: 2961, y: 3347, z: 2 + +spawn_npc name: :white_knight_3349, x: 2962, y: 3339, z: 3 + +spawn_npc name: :white_knight_3350, x: 2960, y: 3336, z: 3 +spawn_npc name: :white_knight_3350, x: 2984, y: 3349, z: 3 + +spawn_npc name: :woman_3226, x: 2991, y: 3384 + +# Functional npcs + +spawn_npc name: :apprentice_workman_3235, x: 2971, y: 3369, z: 1 + +spawn_npc name: :banker_495, x: 2945, y: 3366, face: :north +spawn_npc name: :banker_495, x: 2946, y: 3366, face: :north +spawn_npc name: :banker_495, x: 2947, y: 3366, face: :north +spawn_npc name: :banker_495, x: 2948, y: 3366, face: :north + +spawn_npc name: :banker, x: 2949, y: 3366, face: :north +spawn_npc name: :banker, x: 3015, y: 3353, face: :north +spawn_npc name: :banker, x: 3014, y: 3353, face: :north +spawn_npc name: :banker, x: 3013, y: 3353, face: :north +spawn_npc name: :banker, x: 3012, y: 3353, face: :north +spawn_npc name: :banker, x: 3011, y: 3353, face: :north +spawn_npc name: :banker, x: 3010, y: 3353, face: :north + +spawn_npc name: :cassie, x: 2976, y: 3383 +spawn_npc name: :emily, x: 2954, y: 3372 +spawn_npc name: :flynn, x: 2950, y: 3387 + +spawn_npc name: :hairdresser, x: 2944, y: 3380 + +spawn_npc name: :herquin, x: 2945, y: 3335 + +spawn_npc name: :heskel, x: 3007, y: 3374 +spawn_npc name: :kaylee, x: 2957, y: 3372 + +spawn_npc name: :tina, x: 2955, y: 3371, z: 1 +spawn_npc name: :tool_leprechaun, x: 3005, y: 3370 + +spawn_npc name: :squire, x: 2977, y: 3343 +spawn_npc name: :sir_tiffy_cashien, x: 2997, y: 3373, face: :north +spawn_npc name: :sir_amik_varze, x: 2960, y: 3336, z: 2 +spawn_npc name: :sir_vyvin, x: 2983, y: 3335, z: 2 + +spawn_npc name: :shop_asssistant_525, x: 2955, y: 3389 +spawn_npc name: :shop_keeper_524, x: 2957, y: 3387 + +spawn_npc name: :wayne, x: 2972, y: 3312 + +spawn_npc name: :workman_3236, x: 2975, y: 3369, z: 1 + +spawn_npc name: :wyson_the_gardener, x: 3028, y: 3381 + diff --git a/game/data/plugins/location/falador/plugin.xml b/game/data/plugins/location/falador/plugin.xml new file mode 100644 index 000000000..147cf4635 --- /dev/null +++ b/game/data/plugins/location/falador/plugin.xml @@ -0,0 +1,16 @@ + + + location-falador + 0.1 + Falador + Adds functionality to Falador. + + Wizard Jesse + + + + + + entity-spawning + + \ No newline at end of file diff --git a/game/data/plugins/location/lumbridge/npcs.rb b/game/data/plugins/location/lumbridge/npcs.rb new file mode 100644 index 000000000..29e6df298 --- /dev/null +++ b/game/data/plugins/location/lumbridge/npcs.rb @@ -0,0 +1,16 @@ + +# Generic npcs + +spawn_npc name: :woman_4, x: 3232, y: 3207 # southernmost house +spawn_npc name: :man_1, x: 3231, y: 3237 # house by willow tree +spawn_npc name: :man_2, x: 3224, y: 3240 # house by willow tree +spawn_npc name: :woman_5, x: 3229, y: 2329 # house by willow tree + +# Functional npcs + +spawn_npc name: :hans, x: 3221, y: 3221 +spawn_npc name: :father_aereck, x: 3243, y: 3210 +spawn_npc name: :bob, x: 3231, y: 3203 +spawn_npc name: :shop_keeper, x: 3212, y: 3247 +spawn_npc name: :shop_assistant, x: 3211, y: 3245 +spawn_npc name: :lumbridge_guide, x: 3232, y: 3229 diff --git a/game/data/plugins/location/lumbridge/plugin.xml b/game/data/plugins/location/lumbridge/plugin.xml new file mode 100644 index 000000000..22ea2f94d --- /dev/null +++ b/game/data/plugins/location/lumbridge/plugin.xml @@ -0,0 +1,16 @@ + + + location-lumbridge + 0.1 + Lumbridge + Adds functionality to Lumbridge. + + Major + + + + + + entity-spawning + + \ No newline at end of file diff --git a/game/data/plugins/location/tutorial-island/guide.rb b/game/data/plugins/location/tutorial-island/guide.rb new file mode 100644 index 000000000..74778a484 --- /dev/null +++ b/game/data/plugins/location/tutorial-island/guide.rb @@ -0,0 +1,158 @@ +require 'java' + +java_import 'org.apollo.game.message.impl.HintIconMessage' +java_import 'org.apollo.game.message.impl.MobHintIconMessage' +java_import 'org.apollo.game.message.impl.PositionHintIconMessage' +java_import 'org.apollo.game.message.impl.SwitchTabInterfaceMessage' +java_import 'org.apollo.game.model.entity.EntityType' +java_import 'org.apollo.game.model.Position' + +private + +# Contains constants used during the Runescape Guide part of Tutorial Island. +module GuideConstants + + # The Runescape Guide Npc. + RUNESCAPE_GUIDE = spawn_npc name: :runescape_guide, x: 3093, y: 3107 + + # The character design interface id. + CHARACTER_DESIGN_INTERFACE = 3559 + + # The id of the door of the house new players spawn in. + DOOR_ID = 3014 + + # The Position of the door of the house new players spawn in. + DOOR_POSITION = Position.new(3098, 3107) + + # The HintIconMessage sent to display a hint arrow above the door of the house new players spawn + # in. + DOOR_HINT = PositionHintIconMessage.new(HintIconMessage::Type::WEST, DOOR_POSITION, 120) + + # The ids of tabs that are displayed when the player has yet to start the tutorial. + INITIAL_TABS = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2449, 904, -1, -1].freeze + + # The HintIconMessage sent to remove a hint arrow from above the door. + RESET_DOOR_HINT = PositionHintIconMessage.reset + + # The HintIconMessage sent to remove a hint arrow from an Npc. + RESET_NPC_HINT = MobHintIconMessage.reset(EntityType::NPC) + +end + +# Sends the appropriate data to the client when the player logs in to the game. +on :login do |_event, player| + if player.in_tutorial_island && player.privilege_level != RIGHTS_ADMIN + TutorialInstructions.show_instruction(player) + + GuideConstants::INITIAL_TABS.each_with_index do |tab, index| + player.send(SwitchTabInterfaceMessage.new(index, tab)) + end + + if player.tutorial_island_progress == :not_started + player.interface_set.open_window(GuideConstants::CHARACTER_DESIGN_INTERFACE) + player.send(MobHintIconMessage.create(GuideConstants::RUNESCAPE_GUIDE)) + end + end +end + +# The conversation with the Runescape Guide, when on tutorial island. +conversation :tutorial_runescape_guide do + + # The first dialogue of the Runescape Guide, greeting the Player. + dialogue :greetings do + type :npc_speech + npc :runescape_guide + emote :calm + + precondition { |player| player.tutorial_island_progress == :not_started } + + text 'Greetings! I see you are a new arrival to this land. My job is to welcome all new '\ + 'visitors. So welcome!' + + continue dialogue: :talk_to_people do |player| + player.tutorial_island_progress = :talk_to_people + end + end + + # The Guide welcomes back the Player if they speak to him after they have already gone through + # the conversation once. + dialogue :welcome_back do + type :npc_speech + npc :runescape_guide + emote :calm + + precondition { |player| player.tutorial_island_progress != :not_started } + + text 'Welcome back.' + + continue dialogue: :talk_to_people + end + + # The Guide tells Players to speak to people in order to succeed. + dialogue :talk_to_people do + type :npc_speech + npc :runescape_guide + emote :calm + + text 'You have already learned the first thing you need to succeed in this world: talking to '\ + 'people!', + 'You will find many inhabitants of this world have useful things to say to you. By '\ + 'clicking on them with your mouse you can talk to them.', + 'I would also suggest reading through some of the supporting information on the website.'\ + ' There you can find maps, a bestiary, and much more.' + + continue dialogue: :go_through_door + end + + # The Guide tells Players to go through the door, advancing the tutorial progress if this is the + # first time the Player has heard this. + dialogue :go_through_door do + type :npc_speech + npc :runescape_guide + emote :calm + + text 'To continue the tutorial go through that door over there, and speak to your first '\ + 'instructor.' + + close do |player| + if player.tutorial_island_progress < :runescape_guide_finished + player.send(GuideConstants::RESET_NPC_HINT) + + player.send(GuideConstants::DOOR_HINT) + player.tutorial_island_progress = :runescape_guide_finished + end + + TutorialInstructions.show_instruction(player) + end + end + + # The dialogue displayed if the player attempts to leave the Runescape Guide's house before they + # have spoken to him. + dialogue :talk_to_guide do + type :text + + text 'You need to talk to the Runescape Guide before you are allowed to proceed through this '\ + 'door.' + + close do |player| + TutorialInstructions.show_instruction(player) + end + end + +end + +on :open_door do |event, player| + door = event.door + + if player.in_tutorial_island && door.position.equals(GuideConstants::DOOR_POSITION) + if player.tutorial_island_progress < :runescape_guide_finished + send_dialogue(player, get_dialogue(:tutorial_runescape_guide, :talk_to_guide)) + event.terminate + elsif player.tutorial_island_progress == :runescape_guide_finished + player.tutorial_island_progress = :moving_around + player.send(GuideConstants::RESET_DOOR_HINT) + TutorialInstructions.show_instruction(player) + end + end +end + diff --git a/game/data/plugins/location/tutorial-island/instructions.rb b/game/data/plugins/location/tutorial-island/instructions.rb new file mode 100644 index 000000000..a9526937b --- /dev/null +++ b/game/data/plugins/location/tutorial-island/instructions.rb @@ -0,0 +1,141 @@ + + +# Contains members related to the instructions issues during tutorial island. +module TutorialInstructions + + # Sends the appropriate instruction to the player. + def self.show_instruction(player) + instructions = CONVERSATIONS[:tutorial_island_instructions] + progress = player.tutorial_island_progress.name + name = case progress + # The Runescape Guide instructions. + when :not_started then :getting_started + when :runescape_guide_finished then :scenery + when :moving_around then :moving_around + + # The Survival Guide instructions. + when :given_axe then :viewing_items + when :cut_tree then :cut_tree + when :cutting_tree then :please_wait + + else raise "No dialogue for current stage #{progress} exists." + end + + dialogue = instructions.part(name) + send_dialogue(player, dialogue) + end + + # The one-sided 'conversation' of instruction instructions. + conversation :tutorial_island_instructions do + + # The initial instruction displayed when the player logs in, before they have spoken to the + # guide. + dialogue :getting_started do + type :text + + title 'Getting started' + text 'To start the tutorial, use your left mouse button to click on the Runescape Guide in '\ + 'this room. He is indicated by a flashing yellow arrow above his head. If you can\'t '\ + 'see him, use your keyboard\'s arrow keys to rotate the view.' + end + + # The instruction displayed after the player has spoken to the Runescape Guide. + dialogue :scenery do + type :text + + title 'Interacting with scenery' + text 'You can interact with many items of the scenery by simply clicking on them. Right '\ + 'clicking will also give more options. Click on the door indicated with the yellow '\ + 'arrow to go through to the next area and speak with your next instructor.' + end + + + # The instruction displayed after the player has left the initial building. + dialogue :moving_around do + type :text + + title 'Moving around' + text 'Follow the path to find the next instructor. Clicking on the ground will walk you to '\ + 'that point. Talk to the survival expert by the pond to continue the tutorial. '\ + 'Remember you can rotate the view by pressing the arrow keys.' + end + + # The instruction displayed after the player has been given the tinderbox and bronze axe by the + # Survival Guide. + dialogue :viewing_items do + type :text + + title 'Viewing the items you were given' + text 'Click on the flashing backpack icon to the right side of the main window to view your '\ + 'inventory. Your inventory is a list of everything you have in your backpack.' + end + + # The instruction displayed if the player tries to cut a tree before having the axe. + dialogue :try_cut_tree do + type :text + + title 'Follow the guide\'s instructions' + text 'You cannot cut down this tree, you must first follow the guide\'s instructions.' + end + + # The instruction displayed before the player has begun to cut the tree. + dialogue :cut_tree do + type :text + + title 'Cut down a tree' + text 'You can click on the backpack icon at any time to view the items that you currently '\ + 'have in your inventory. You will see that you now have an axe in your inventory. '\ + 'Use this to get some logs by clicking on the indicated tree.' + end + + # The instruction displayed when the player begins to cut the tree. + dialogue :please_wait do + type :text + + title 'Please wait...' + text 'Your character is now attempting to cut down the tree. Sit back for a moment whilst '\ + 'he does all the hard work.' # TODO: she instead of he if applicable + end + + # The instruction displayed after the player has successfully cut logs from the tree. + dialogue :make_a_fire do + type :text + + title 'Making a fire' + text 'Well done! You managed to cut some logs from the tree! Next, use the tinderbox in '\ + 'your inventory to light the logs. First click on the tinderbox to \'use\' it.'\ + 'Then click on the logs in your inventory to light them.' + end + + # The instruction displayed when the player begins to light the fire. + dialogue :lighting_fire do + type :text + + title 'Please wait...' + # TODO: she instead of he if applicable + text 'Your character is now attempting to light the logs. Sit back for a moment whilst he '\ + 'does all the hard work.' + end + + # The instruction displayed when the has lit the logs. + dialogue :gained_experience do + type :text + + text 'You gained some experience.'\ + 'Click on the flashing bar graph icon near the inventory button to see your skill '\ + 'stats.' + end + + # The dialogue displayed when the Player has clicked the flashing skill tab icon. + dialogue :skill_stats do + type :text + + title 'Your skill stats.' + text 'Here you will see how good your skills are. As you move your mouse over any of the '\ + 'icons in this panel, the small yellow popup box will show you the exact amount of '\ + 'experience you have and how much is needed to get to the next level. Speak to the '\ + 'Survival Expert to continue.' + end + end + +end diff --git a/game/data/plugins/location/tutorial-island/npcs.rb b/game/data/plugins/location/tutorial-island/npcs.rb new file mode 100644 index 000000000..264784782 --- /dev/null +++ b/game/data/plugins/location/tutorial-island/npcs.rb @@ -0,0 +1,40 @@ + +# Functional npcs + +# 'Above-ground' npcs + +spawn_npc name: :master_chef, x: 3076, y: 3085 +spawn_npc name: :quest_guide, x: 3086, y: 3122, face: :north +spawn_npc name: :financial_advisor, x: 3127, y: 3124, face: :west +spawn_npc name: :brother_brace, x: 3124, y: 3107, face: :east +spawn_npc name: :magic_instructor, x: 3140, y: 3085 + +# 'Below-ground' npcs +# Note: They aren't actually on a different plane, they're just in a different location that +# pretends to be underground. + +spawn_npc name: :mining_instructor, x: 3081, y: 9504 +spawn_npc name: :combat_instructor, x: 3104, y: 9506 + +# Non-humanoid npcs + +spawn_npc name: :fishing_spot_316, x: 3102, y: 3093 + +spawn_npc name: :chicken, x: 3140, y: 3095 +spawn_npc name: :chicken, x: 3140, y: 3093 +spawn_npc name: :chicken, x: 3138, y: 3092 +spawn_npc name: :chicken, x: 3137, y: 3094 +spawn_npc name: :chicken, x: 3138, y: 3095 + +# 'Below-ground' npcs +# Note: They aren't actually on a different plane, they're just in a different location that +# pretends to be underground. + +spawn_npc name: :giant_rat_87, x: 3105, y: 9514 +spawn_npc name: :giant_rat_87, x: 3105, y: 9517 +spawn_npc name: :giant_rat_87, x: 3106, y: 9514 +spawn_npc name: :giant_rat_87, x: 3104, y: 9514 +spawn_npc name: :giant_rat_87, x: 3105, y: 9519 +spawn_npc name: :giant_rat_87, x: 3109, y: 9516 +spawn_npc name: :giant_rat_87, x: 3108, y: 9520 +spawn_npc name: :giant_rat_87, x: 3102, y: 9517 diff --git a/game/data/plugins/location/tutorial-island/plugin.xml b/game/data/plugins/location/tutorial-island/plugin.xml new file mode 100644 index 000000000..72537461c --- /dev/null +++ b/game/data/plugins/location/tutorial-island/plugin.xml @@ -0,0 +1,24 @@ + + + location-tutorial-island + 0.1 + Tutorial Island + Adds functionality to Tutorial island. + + Major + + + + + + + + + + + dialogue + door + entity-spawning + quest + + diff --git a/game/data/plugins/location/tutorial-island/stages.rb b/game/data/plugins/location/tutorial-island/stages.rb new file mode 100644 index 000000000..b5ac6ccab --- /dev/null +++ b/game/data/plugins/location/tutorial-island/stages.rb @@ -0,0 +1,16 @@ + +private + +# The array of stages in tutorial island. +@stages = [] + +# The stages that are used when interacting with the Runescape Guide. +RUNESCAPE_GUIDE = [:not_started, :talk_to_people, :go_through_door, :runescape_guide_finished, + :moving_around].freeze +@stages.concat(RUNESCAPE_GUIDE) + +# The stages that are used when interacting with the Survival Expert. +SURVIVAL_EXPERT = [:given_axe, :cut_tree, :cutting_tree].freeze +@stages.concat(SURVIVAL_EXPERT) + +quest :tutorial_island, @stages diff --git a/game/data/plugins/location/tutorial-island/survival.rb b/game/data/plugins/location/tutorial-island/survival.rb new file mode 100644 index 000000000..a5d47554b --- /dev/null +++ b/game/data/plugins/location/tutorial-island/survival.rb @@ -0,0 +1,154 @@ +require 'java' + +java_import 'org.apollo.game.message.impl.FlashTabInterfaceMessage' +java_import 'org.apollo.game.message.impl.FlashingTabClickedMessage' +java_import 'org.apollo.game.message.impl.SwitchTabInterfaceMessage' + +private + +# Contains Survival Expert-related constants. +module SurvivalConstants + + # The Survival Expert Npc. + @survival_expert = spawn_npc name: :survival_expert, x: 3104, y: 3095, face: :north + + # The inventory tab index. + INVENTORY_TAB_INDEX = 3 + + # The inventory tab id. + INVENTORY_TAB_ID = 3213 + + # The id of the tree the Player will cut down. + TREE_ID = 3033 + + # The id of the bronze axe. + BRONZE_AXE = lookup_item(:bronze_axe) + + # The id of the tinderbox. + TINDERBOX = lookup_item(:tinderbox) + +end + +# The conversation with the Survival Expert, when on tutorial island. +conversation :tutorial_survival_expert do + + dialogue :introduction do + type :npc_speech + npc :survival_expert + + precondition { |player| player.tutorial_island_progress == :moving_around } + + text 'Hello there, newcomer. My name is Brynna. My job is to teach you a few survival tips and'\ + ' tricks. First off we\'re going to start with the most basic survival skill of all: '\ + 'making a fire.' + + close { |player| add_survival_items(player) } + end + + dialogue :hello_again do + type :npc_speech + npc :survival_expert + + precondition { |player| player.tutorial_island_progress == :moving_around } + + text 'Hello again. I\'m here to teach you a few survival tips and tricks. First off we\'re '\ + 'going to start with the most basic survival skill of all: making a fire.' + + close { |player| add_survival_items(player) } + end + + # The dialogue displayed when the Survival Expert gives the player a bronze axe. + dialogue :give_bronze_axe do + type :message_with_item + item :bronze_axe + + text 'The Survival Expert gives you a bronze axe!' + + close { |player| TutorialInstructions.show_instruction(player) } + end + + # The dialogue displayed when the Survival Expert gives the player a tinderbox. + dialogue :give_tinderbox do + type :message_with_item + item :tinderbox + + text 'The Survival Expert gives you a tinderbox!' + + close { |player| TutorialInstructions.show_instruction(player) } + end + + # The dialogue displayed when the Survival Expert gives the player both a bronze axe and a + # tinderbox. + dialogue :give_axe_and_tinderbox do + type :message_with_item + item :bronze_axe + # TODO: the tinderbox is also displayed - find this dialogue id. Scale looks like the default + # http://i.imgur.com/i1abN5X.png + + text 'The Survival Expert gives you a tinderbox and a bronze axe!' + + close do |player| + if player.tutorial_island_progress < :given_axe + player.tutorial_island_progress = :given_axe + + index = SurvivalConstants::INVENTORY_TAB_INDEX + player.send(SwitchTabInterfaceMessage.new(index, SurvivalConstants::INVENTORY_TAB_ID)) + player.send(FlashTabInterfaceMessage.new(index)) + end + + TutorialInstructions.show_instruction(player) + end + end + + # The dialogue displayed when the player has succesfully cut down a tree. + dialogue :get_logs do + type :message_with_item + item :logs + + text 'You get some logs.' + close { |player| TutorialInstructions.show_instruction(player) } + end + +end + +# Add the survival items (bronze axe and tinderbox) to the inventory of the player, if they do not +# already have them. +def add_survival_items(player) + inventory = player.inventory + + unless inventory.contains(SurvivalConstants::BRONZE_AXE) + inventory.add(SurvivalConstants::BRONZE_AXE) + dialogue = :give_bronze_axe + end + + unless inventory.contains(SurvivalConstants::TINDERBOX) + inventory.add(SurvivalConstants::TINDERBOX) + dialogue = (dialogue == :give_bronze_axe) ? :give_axe_and_tinderbox : :give_tinderbox + end + + send_dialogue(player, get_dialogue(:tutorial_survival_expert, dialogue)) +end + +# Intercept the FirstObjectActionMessage to send tutorial-only events if the player is chopping +# down a tree. +on :message, :first_object_action do |player, message| + if player.in_tutorial_island && message.id == SurvivalConstants::TREE_ID + progress = player.tutorial_island_progress + + if progress < :cut_tree + send_dialogue(player, get_dialogue(:tutorial_island_instructions, :try_cut_tree)) + elsif player.tutorial_island_progress == :cut_tree + # Don't break the chain, so that the Woodcutting event actually happens. + player.tutorial_island_progress = :cutting_tree + end + end +end + +# Intercept the FlashingTabClickedMessage to update the player's progress, if applicable. +on :message, :flashing_tab_clicked do |player, message| + if player.in_tutorial_island && message.tab == SurvivalConstants::INVENTORY_TAB_INDEX && + player.tutorial_island_progress == :given_axe + player.tutorial_island_progress = :cut_tree + message.terminate + end +end diff --git a/game/data/plugins/location/tutorial-island/utils.rb b/game/data/plugins/location/tutorial-island/utils.rb new file mode 100644 index 000000000..7a873b873 --- /dev/null +++ b/game/data/plugins/location/tutorial-island/utils.rb @@ -0,0 +1,30 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.Player' + +# Declare the tutorial island progress attribute. +declare_attribute(:tutorial_island_progress, :not_started, :persistent) + +# The existing player class. +class Player + + # Returns whether or not this Player is currently on tutorial island. + def in_tutorial_island + x = position.x + y = position.y + above_ground(x, y) || below_ground(x, y) + end + +end + +private + +# Returns whether or not the specified coordinate pair is above ground on tutorial island. +def above_ground(x, y) + x >= 3053 && x <= 3156 && y >= 3056 && y <= 3136 +end + +# Returns whether or not the specified coordinate pair is 'below' ground on tutorial island. +def below_ground(x, y) + x >= 3072 && x <= 3118 && y >= 9492 && y <= 9535 +end diff --git a/game/data/plugins/location/varrock/npcs.rb b/game/data/plugins/location/varrock/npcs.rb new file mode 100644 index 000000000..0bd4c84ed --- /dev/null +++ b/game/data/plugins/location/varrock/npcs.rb @@ -0,0 +1,258 @@ +# Generic Npc + +spawn_npc name: :barbarian_woman, x: 3222, y: 3399 + +spawn_npc name: :bear_106, x: 3289, y: 3351 + +spawn_npc name: :black_knight, x: 3238, y: 3514 +spawn_npc name: :black_knight, x: 3227, y: 3518 +spawn_npc name: :black_knight, x: 3279, y: 3502 + +spawn_npc name: :dark_wizard_174, x: 3230, y: 3366 +spawn_npc name: :dark_wizard_174, x: 3228, y: 3368 +spawn_npc name: :dark_wizard_174, x: 3225, y: 3367 +spawn_npc name: :dark_wizard_174, x: 3226, y: 3365 +spawn_npc name: :dark_wizard_174, x: 3226, y: 3372 +spawn_npc name: :dark_wizard_174, x: 3231, y: 3371 + +spawn_npc name: :dark_wizard_172, x: 3229, y: 3372 +spawn_npc name: :dark_wizard_172, x: 3224, y: 3370 +spawn_npc name: :dark_wizard_172, x: 3228, y: 3366 +spawn_npc name: :dark_wizard_172, x: 3232, y: 3368 +spawn_npc name: :dark_wizard_172, x: 3226, y: 3369 + +spawn_npc name: :giant_rat_87, x: 3292, y: 3375 +spawn_npc name: :giant_rat_87, x: 3265, y: 3384 +spawn_npc name: :giant_rat_87, x: 3267, y: 3381 + +spawn_npc name: :guard_368, x: 3263, y: 3407, face: :south + +spawn_npc name: :jeremy_clerksin, x: 3253, y: 3477 +spawn_npc name: :martina_scorsby, x: 3256, y: 3481 + +spawn_npc name: :man, x: 3281, y: 3500 +spawn_npc name: :man, x: 3193, y: 3394 +spawn_npc name: :man, x: 3159, y: 3429 +spawn_npc name: :man, x: 3245, y: 3394 +spawn_npc name: :man, x: 3283, y: 3492, z: 1 + +spawn_npc name: :man_2, x: 3263, y: 3400 +spawn_npc name: :man_3, x: 3227, y: 3395, z: 1 +spawn_npc name: :man_3, x: 3231, y: 3399, z: 1 + +spawn_npc name: :mugger, x: 3251, y: 3390 +spawn_npc name: :mugger, x: 3177, y: 3363 + +spawn_npc name: :tramp_2792, x: 3228, y: 3410 + +spawn_npc name: :woman, x: 3221, y: 3396 +spawn_npc name: :woman_5, x: 3279, y: 3497 +spawn_npc name: :woman_25, x: 3278, y: 3492 + +spawn_npc name: :thief, x: 3285, y: 3500 +spawn_npc name: :thief, x: 3234, y: 3389 +spawn_npc name: :thief, x: 3188, y: 3383 +spawn_npc name: :thief, x: 3184, y: 3390 +spawn_npc name: :thief, x: 3188, y: 3394 + +spawn_npc name: :unicorn, x: 3286, y: 3342 +spawn_npc name: :unicorn, x: 3279, y: 3345 + + +# North Guards + +spawn_npc name: :guard, x: 3244, y: 3500 +spawn_npc name: :guard, x: 3247, y: 3503 + +# East Guards + +spawn_npc name: :guard, x: 3271, y: 3431 +spawn_npc name: :guard, x: 3270, y: 3425 +spawn_npc name: :guard, x: 3274, y: 3421 +spawn_npc name: :guard, x: 3274, y: 3427 + +# South Guards + +spawn_npc name: :guard, x: 3210, y: 3382 +spawn_npc name: :guard, x: 3212, y: 3380 +spawn_npc name: :guard, x: 3207, y: 3376 + +# West Guards + +spawn_npc name: :guard, x: 3174, y: 3427 +spawn_npc name: :guard, x: 3176, y: 3430 +spawn_npc name: :guard, x: 3176, y: 3427 +spawn_npc name: :guard, x: 3180, y: 3399 +spawn_npc name: :guard, x: 3175, y: 3415, z: 1 +spawn_npc name: :guard, x: 3174, y: 3403, z: 1 + +# Varrock Palace + +spawn_npc name: :guard, x: 3210, y: 3461 +spawn_npc name: :guard, x: 3211, y: 3465 +spawn_npc name: :guard, x: 3214, y: 3462 +spawn_npc name: :guard, x: 3216, y: 3464 +spawn_npc name: :guard, x: 3220, y: 3461 +spawn_npc name: :guard, x: 3206, y: 3461 +spawn_npc name: :guard, x: 3204, y: 3495 +spawn_npc name: :guard, x: 3204, y: 3495, z: 1 +spawn_npc name: :guard, x: 3205, y: 3492, z: 1 +spawn_npc name: :guard, x: 3203, y: 3492, z: 1 +spawn_npc name: :guard, x: 3205, y: 3497, z: 1 +spawn_npc name: :guard, x: 3221, y: 3471, z: 2 +spawn_npc name: :guard, x: 3214, y: 3474, z: 2 +spawn_npc name: :guard, x: 3215, y: 3471, z: 2 +spawn_npc name: :guard, x: 3211, y: 3471, z: 2 +spawn_npc name: :guard, x: 3209, y: 3473, z: 2 +spawn_npc name: :guard, x: 3212, y: 3475, z: 2 +spawn_npc name: :guard, x: 3207, y: 3477, z: 2 +spawn_npc name: :guard, x: 3203, y: 3476, z: 2 +spawn_npc name: :guard, x: 3205, y: 3479, z: 2 +spawn_npc name: :guard, x: 3203, y: 3483, z: 2 +spawn_npc name: :guard, x: 3221, y: 3485, z: 2 + +spawn_npc name: :monk_of_zamorak_189, x: 3213, y: 3476 + +spawn_npc name: :warrior_woman, x: 3203, y: 3490 +spawn_npc name: :warrior_woman, x: 3205, y: 3493 + +# Varrock/Lumbridge Pen + +spawn_npc name: :swan, x: 3261, y: 3354 +spawn_npc name: :swan, x: 3260, y: 3356 + +spawn_npc name: :ram_3673, x: 3238, y: 3346 +spawn_npc name: :ram_3673, x: 3248, y: 3352 +spawn_npc name: :ram_3673, x: 3260, y: 3348 + +spawn_npc name: :sheep_42, x: 3263, y: 3347 +spawn_npc name: :sheep_42, x: 3268, y: 3350 +spawn_npc name: :sheep_42, x: 3252, y: 3352 +spawn_npc name: :sheep_42, x: 3243, y: 3344 +spawn_npc name: :sheep_42, x: 3235, y: 3347 + +spawn_npc name: :sheep_3579, x: 3234, y: 3344 +spawn_npc name: :sheep_3579, x: 3241, y: 3347 +spawn_npc name: :sheep_3579, x: 3257, y: 3350 + +# Champions Guild + +spawn_npc name: :chicken, x: 3195, y: 3359 +spawn_npc name: :chicken, x: 3198, y: 3356 +spawn_npc name: :chicken, x: 3195, y: 3355 + +spawn_npc name: :chicken_1017, x: 3196, y: 3353 +spawn_npc name: :chicken_1017, x: 3197, y: 3356 + +spawn_npc name: :evil_chicken, x: 3198, y: 3359 + +# Function Npc + +spawn_npc name: :apothecary, x: 3196, y: 3403 + +spawn_npc name: :captain_rovin, x: 3204, y: 3496, z: 2 + +spawn_npc name: :curator, x: 3256, y: 3447 + +spawn_npc name: :dimintheis, x: 3280, y: 3403 + +spawn_npc name: :dr_harlow, x: 3224, y: 3398 + +spawn_npc name: :ellamaria, x: 3228, y: 3475 + +spawn_npc name: :father_lawrence, x: 3253, y: 3484 + +spawn_npc name: :guidors_wife_342, x: 3280, y: 3382 + +spawn_npc name: :guidor, x: 3284, y: 3381, face: :south + +spawn_npc name: :guild_master, x: 3189, y: 3360 + +spawn_npc name: :gypsy, x: 3203, y: 3423 + +spawn_npc name: :hooknosed_jack, x: 3268, y: 3400 + +spawn_npc name: :jonny_the_beard, x: 3223, y: 3395 + +spawn_npc name: :johnathon, x: 3278, y: 3503, z: 1 + +spawn_npc name: :katrine, x: 3185, y: 3386 + +spawn_npc name: :king_roald, x: 3223, y: 3473 + +spawn_npc name: :master_farmer, x: 3243, y: 3349 + +spawn_npc name: :pox, x: 3267, y: 3399 + +spawn_npc name: :reldo, x: 3210, y: 3492 + +spawn_npc name: :romeo, x: 3211, y: 3423 + +spawn_npc name: :shilop, x: 3221, y: 3435 + +spawn_npc name: :sir_prysin, x: 3204, y: 3472 + +spawn_npc name: :tarquin, x: 3203, y: 3344, face: :south + +spawn_npc name: :tool_leprechaun, x: 3182, y: 3355 +spawn_npc name: :tool_leprechaun, x: 3229, y: 3455, face: :north + +spawn_npc name: :tramp_641, x: 3207, y: 3392 + +spawn_npc name: :wilough, x: 3222, y: 3437 + +# Shop Npc + +spawn_npc name: :aubury, x: 3253, y: 3401 + +spawn_npc name: :baraek, x: 3217, y: 3434 + +spawn_npc name: :bartender, x: 3226, y: 3400 +spawn_npc name: :bartender_1921, x: 3277, y: 3487 + +spawn_npc name: :fancy_dress_shop_owner, x: 3281, y: 3398 + +spawn_npc name: :horvik, x: 3229, y: 3438 + +spawn_npc name: :lowe, x: 3233, y: 3421 + +spawn_npc name: :scavvo, x: 3192, y: 3353, z: 1 + +spawn_npc name: :shop_keeper_551, x: 3206, y: 3399 +spawn_npc name: :shop_assistant_552, x: 3207, y: 3396 + +spawn_npc name: :shop_keeper_522, x: 3216, y: 3414 +spawn_npc name: :shop_assistant_523, x: 3216, y: 3417 + +spawn_npc name: :tea_seller, x: 3271, y: 3411 + +spawn_npc name: :thessalia, x: 3206, y: 3417 + +spawn_npc name: :zaff, x: 3203, y: 3434 + +# Juliet House + +spawn_npc name: :draul_leptoc, x: 3228, y: 3475 +spawn_npc name: :juliet, x: 3159, y: 3425, z: 1 +spawn_npc name: :phillipa, x: 3160, y: 3429, z: 1 + +# Gertrude House + +spawn_npc name: :gertrude, x: 3153, y: 3413 +spawn_npc name: :kanel, x: 3155, y: 3405, face: :east +spawn_npc name: :philop, x: 3150, y: 3405, face: :south + +# Small Bank + +spawn_npc name: :banker_495, x: 3252, y: 3418, face: :north +spawn_npc name: :banker_494, x: 3253, y: 3418, face: :north +spawn_npc name: :banker_494, x: 3254, y: 3418, face: :north +spawn_npc name: :banker_494, x: 3256, y: 3418, face: :north + +# Big Bank + +spawn_npc name: :banker_494, x: 3187, y: 3436, face: :west +spawn_npc name: :banker_495, x: 3187, y: 3438, face: :west +spawn_npc name: :banker_494, x: 3187, y: 3440, face: :west +spawn_npc name: :banker_495, x: 3187, y: 3442, face: :west +spawn_npc name: :banker_494, x: 3187, y: 3444, face: :west diff --git a/game/data/plugins/location/varrock/plugin.xml b/game/data/plugins/location/varrock/plugin.xml new file mode 100644 index 000000000..2e74c9fb7 --- /dev/null +++ b/game/data/plugins/location/varrock/plugin.xml @@ -0,0 +1,18 @@ + + + location-varrock + 0.1 + Varrock + Adds functionality to Varrock. + + Wizard Jesse + + + + + + + entity-spawning + shops + + \ No newline at end of file diff --git a/game/data/plugins/location/varrock/shops.rb b/game/data/plugins/location/varrock/shops.rb new file mode 100644 index 000000000..37970e7b2 --- /dev/null +++ b/game/data/plugins/location/varrock/shops.rb @@ -0,0 +1,44 @@ + +create_shop npcs: :aubury, name: "Aubury's Rune Shop.", items: [ + [:fire_rune, 5_000], [:water_rune, 5_000], [:air_rune, 5_000], [:earth_rune, 5_000], + [:mind_rune, 5_000], [:body_rune, 5_000 ], [:chaos_rune, 250], [:death_rune, 250 ] +] + +create_shop npcs: :lowe, name: "Lowe's Archery Emporium", items: [ + [:bronze_arrow, 2_000], [:iron_arrow, 1_500], [:steel_arrow, 1_000], + [:mithril_arrow, 800], [:adamant_arrow, 600], [:shortbow, 4], [:longbow, 4], + [:oak_shortbow, 3], [:oak_longbow, 3], [:willow_shortbow, 2], [:willow_longbow, 2], + [:maple_shortbow, 1], [:maple_longbow, 1], [:crossbow, 2] +] + +create_shop npcs: :horvik, buys: :all, name: "Horvik's Armour Shop.", items: [ + [:bronze_chainbody, 5], [:iron_chainbody, 3], [:steel_chainbody, 3], + [:mithril_chainbody, 1], [:bronze_platebody, 3], [:iron_platebody, 1], + [:steel_platebody, 1], [:black_platebody, 1], [:mithril_platebody, 1], + [:iron_platelegs, 1], [:studded_body, 1], [:studded_chaps, 1] +] + +create_shop npcs: :thessalia, name: "Thessalia's Fine Clothes.", items: [ + [:white_apron, 3], [:leather_body, 12], [:leather_gloves, 10], [:leather_boots, 10], + [:brown_apron, 1], [:pink_skirt, 5], [:black_skirt, 3], [:blue_skirt, 2], [:cape, 4], + [:silk, 5], [:priest_gown_428, 3], [:priest_gown_426, 3] +] + +create_shop npcs: [:shop_keeper_522, :shop_assistant_523], buys: :all, + name: 'Varrock General Store', items: [ + [:pot, 5], [:jug, 2], [:shears, 2], [:bucket, 3], [:bowl, 2], [:cake_tin, 2], + [:tinderbox, 2], [:chisel, 2], [:hammer, 5], [:newcomer_map, 5] +] + +create_shop npcs: [:shop_keeper_551, :shop_assistant_552], name: 'Varrock Swordshop', items: [ + [:bronze_sword, 5], [:iron_sword, 4], [:steel_sword, 4], [:black_sword, 3], + [:mithril_sword, 3], [:adamant_sword, 2], [:bronze_longsword, 4], [:iron_longsword, 3], + [:steel_longsword, 3], [:black_longsword, 2], [:mithril_longsword, 2], + [:adamant_longsword, 1], [:bronze_dagger, 10], [:iron_dagger, 6], [:steel_dagger, 5], + [:black_dagger, 4], [:mithril_dagger, 3], [:adamant_dagger, 2] +] + +create_shop npcs: :zaff, name: "Zaff's Superior Staffs!", items: [ + [:battlestaff, 5], [:staff, 5], [:magic_staff, 5], [:staff_of_air, 2], + [:staff_of_water, 2], [:staff_of_earth, 2], [:staff_of_fire, 2] +] diff --git a/game/data/plugins/logout/logout.rb b/game/data/plugins/logout/logout.rb new file mode 100644 index 000000000..388834686 --- /dev/null +++ b/game/data/plugins/logout/logout.rb @@ -0,0 +1,5 @@ +LOGOUT_BUTTON_ID = 2458 + +on :button, LOGOUT_BUTTON_ID do |player| + player.logout +end diff --git a/game/data/plugins/logout/plugin.xml b/game/data/plugins/logout/plugin.xml new file mode 100644 index 000000000..6246ec704 --- /dev/null +++ b/game/data/plugins/logout/plugin.xml @@ -0,0 +1,14 @@ + + + logout + 1 + Logout Button + Adds the logout button. + + Graham + + + + + + diff --git a/game/data/plugins/navigation/door/constants.rb b/game/data/plugins/navigation/door/constants.rb new file mode 100644 index 000000000..291d76083 --- /dev/null +++ b/game/data/plugins/navigation/door/constants.rb @@ -0,0 +1,44 @@ +require 'set' + +# Contains door-related constants. +module DoorConstants + + # TODO: GameObjectOrientation enumeration in Apollo's core? + # The orientation of a door. + module Orientation + WEST = 0 + NORTH = 1 + EAST = 2 + SOUTH = 3 + end + + # The size of a door object. + DOOR_SIZE = 1 + + # Door object ids that have a hinge on the left side. + LEFT_HINGE_DOORS = Set.new [1516, 1536, 1533] + + # Door object ids that have a hinge on the right side. + RIGHT_HINGE_DOORS = Set.new [1519, 1530, 4465, 4467, 3014, 3017, 3018, 3019] + + # The hash of orientations that a door will translate to when opened. + ORIENTATIONS = { + + # Orientations for doors that have a hinge on the left side. + left_side_hinge: { + Orientation::NORTH => Orientation::WEST, + Orientation::SOUTH => Orientation::EAST, + Orientation::WEST => Orientation::SOUTH, + Orientation::EAST => Orientation::NORTH + }, + + # Orientations for doors that have a hinge on the right side. + right_side_hinge: { + Orientation::NORTH => Orientation::EAST, + Orientation::SOUTH => Orientation::WEST, + Orientation::WEST => Orientation::NORTH, + Orientation::EAST => Orientation::SOUTH + } + } + +end diff --git a/game/data/plugins/navigation/door/door.rb b/game/data/plugins/navigation/door/door.rb new file mode 100644 index 000000000..e0ee818b7 --- /dev/null +++ b/game/data/plugins/navigation/door/door.rb @@ -0,0 +1,54 @@ + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.model.event.Event' + +private + +# A distanced action which opens a door. +class OpenDoorAction < DistancedAction + include DoorConstants + + attr_reader :door + + def initialize(mob, door) + super(0, true, mob, door.position, DOOR_SIZE) + @door = door + end + + def executeAction + if $world.submit(OpenDoorEvent.new(mob, @door)) + mob.turn_to(@door.position) + DoorUtil.toggle(@door) + end + + stop + end + + def equals(other) + get_class == other.get_class && @door == other.door + end + +end + +# A PlayerEvent that is fired when a player attempts to open a door. +class OpenDoorEvent < PlayerEvent + attr_reader :door + + def initialize(player, door) + super(player) + @door = door + end + +end + + +# Listens for FirstObjectActions performed on doors. +on :message, :first_object_action do |player, message| + id = message.id + + if DoorUtil.door?(id) + door = DoorUtil.get_door_object(message.position, id) + player.start_action(OpenDoorAction.new(player, door)) unless door.nil? + end +end + diff --git a/game/data/plugins/navigation/door/plugin.xml b/game/data/plugins/navigation/door/plugin.xml new file mode 100644 index 000000000..4b5f435fe --- /dev/null +++ b/game/data/plugins/navigation/door/plugin.xml @@ -0,0 +1,16 @@ + + + door + 1 + Doors + Adds support for doors throughout the game. + + Shiver + + + + + + + + \ No newline at end of file diff --git a/game/data/plugins/navigation/door/util.rb b/game/data/plugins/navigation/door/util.rb new file mode 100644 index 000000000..4e17bad09 --- /dev/null +++ b/game/data/plugins/navigation/door/util.rb @@ -0,0 +1,83 @@ +require 'java' + +java_import 'org.apollo.game.model.Position' +java_import 'org.apollo.game.model.area.Region' +java_import 'org.apollo.game.model.entity.Entity' +java_import 'org.apollo.game.model.entity.obj.DynamicGameObject' + +# Contains door-related utility methods. +module DoorUtil + include DoorConstants + + # A hash containing currently toggled door objects mapped to the original door objects. + TOGGLED_DOORS = {} + + # Translates a door's position in the direction of its orientation. + def self.translate_door_position(door) + position = door.position + + case door.orientation + when Orientation::WEST + Position.new(position.x - 1, position.y, position.height) + when Orientation::EAST + Position.new(position.x + 1, position.y, position.height) + when Orientation::NORTH + Position.new(position.x, position.y + 1, position.height) + when Orientation::SOUTH + Position.new(position.x, position.y - 1, position.height) + else fail "Unsupported orientation #{door.orientation}." + end + end + + # Translates the orientation of a door to a toggled position. + def self.translate_door_orientation(door) + object_id = door.id + orientation = door.orientation + + if RIGHT_HINGE_DOORS.include?(object_id) + return ORIENTATIONS[:right_side_hinge][orientation] + elsif LEFT_HINGE_DOORS.include?(object_id) + return ORIENTATIONS[:left_side_hinge][orientation] + end + + fail 'Given object was not registered as a door.' + end + + # Toggles the given door. + def self.toggle(door) + region = $world.region_repository.from_position(door.position) + region.remove_entity(door) + + if TOGGLED_DOORS.include?(door) + original_door = TOGGLED_DOORS.delete(door) + + original_region = $world.region_repository.from_position(original_door.position) + original_region.add_entity(original_door) + else + position = translate_door_position(door) + orientation = translate_door_orientation(door) + type = door.type + + toggled_door = DynamicGameObject.create_public($world, door.id, position, type, orientation) + + toggled_region = $world.region_repository.from_position(position) + toggled_region.add_entity(toggled_door) + + TOGGLED_DOORS[toggled_door] = door + end + end + + # Gets the door object at the given position, if it exists. + def self.get_door_object(position, object_id) + region = $world.region_repository.from_position(position) + objects = region.get_entities(position, EntityType::DYNAMIC_OBJECT, EntityType::STATIC_OBJECT) + objects.each { |game_object| return game_object if game_object.id == object_id } + nil + end + + # Checks if the given game object id is a door. + def self.door?(object_id) + RIGHT_HINGE_DOORS.include?(object_id) || LEFT_HINGE_DOORS.include?(object_id) + end + +end diff --git a/game/data/plugins/player-action/action.rb b/game/data/plugins/player-action/action.rb new file mode 100644 index 000000000..1752d659f --- /dev/null +++ b/game/data/plugins/player-action/action.rb @@ -0,0 +1,61 @@ +require 'java' + +java_import 'org.apollo.game.message.impl.SetPlayerActionMessage' +java_import 'org.apollo.game.model.entity.Player' + +# A right-click action for a Player. +class PlayerAction + attr_reader :slot, :primary, :name + + def initialize(slot, primary, name) + index = [:first, :second, :third, :fourth, :fifth].find_index(slot) + fail "Unsupported action slot #{slot}." if index.nil? + + @slot = index + @primary = primary + @name = name + end + +end + +ATTACK_ACTION = PlayerAction.new(:second, true, 'Attack') +CHALLENGE_ACTION = PlayerAction.new(:second, true, 'Challenge') +FOLLOW_ACTION = PlayerAction.new(:fourth, true, 'Follow') +TRADE_ACTION = PlayerAction.new(:fifth, true, 'Trade with') + +# Shows multiple context menu action for the specified player +def show_actions(player, *actions) + fail 'Must specify at least one action.' if actions.nil? + + actions.each do |action| + player.add_action(action) + player.send(SetPlayerActionMessage.new(action.name, action.slot, action.primary)) + end +end + +# Shows a single context menu action for the specified player +def show_action(player, action) + show_actions(player, action) +end + +# Hides a context menu action for the specified player +def hide_action(player, action) + player.send(SetPlayerActionMessage.new('null', action.slot, action.primary)) +end + +# Monkey-patch Player to provide action utility methods. +class Player + + def actions + @actions ||= {} + end + + def add_action(action) + actions[action.slot] = action.name + end + + def action?(action) + actions[action.slot] == action.name + end + +end diff --git a/game/data/plugins/player-action/login.rb b/game/data/plugins/player-action/login.rb new file mode 100644 index 000000000..b2aaf85d1 --- /dev/null +++ b/game/data/plugins/player-action/login.rb @@ -0,0 +1,6 @@ +java_import 'org.apollo.game.model.entity.Player' + +on :login do |_event, player| + show_action(player, TRADE_ACTION) + show_action(player, FOLLOW_ACTION) +end diff --git a/game/data/plugins/player-action/plugin.xml b/game/data/plugins/player-action/plugin.xml new file mode 100644 index 000000000..48263a9f3 --- /dev/null +++ b/game/data/plugins/player-action/plugin.xml @@ -0,0 +1,15 @@ + + + player-action + 1 + Player actions + Manages player right click actions + + Ryley + + + + + + + diff --git a/game/data/plugins/quest/plugin.xml b/game/data/plugins/quest/plugin.xml new file mode 100644 index 000000000..b92ef5b3c --- /dev/null +++ b/game/data/plugins/quest/plugin.xml @@ -0,0 +1,16 @@ + + + quest + 0.9 + Quest + Adds + + Major + + + + + + attributes + + \ No newline at end of file diff --git a/game/data/plugins/quest/repository.rb b/game/data/plugins/quest/repository.rb new file mode 100644 index 000000000..21375570d --- /dev/null +++ b/game/data/plugins/quest/repository.rb @@ -0,0 +1,132 @@ + +# Defines a quest with the specified name. +def quest(name, stage_names) + stages = {} + stage_names.each_with_index { |stage, index| stages[stage] = QuestStage.new(stage, index, name) } + + QUESTS[name] = Quest.new(name, stages) +end + +private + +# The repository of quests. +QUESTS = {} + +# An ingame Quest. +class Quest + attr_reader :name + + # Creates the Quest. + def initialize(name, stages) + fail "Quest name must be a symbol, received '#{name}'." unless name.is_a?(Symbol) + @name = name + @stages = stages + end + + # Gets the finishing quest stage (i.e. the stage that indicates the Player has completed the + # quest). + def final_stage + @stages.last + end + + # Gets the starting quest stage. + def initial_stage + @stages.first + end + + # Gets the QuestStage with the specified name. + def stage(name) + stage = @stages[name] + fail "No stage named #{name} exists in #{@name}." if stage.nil? + stage + end + +end + +# A stage in a quest, indicating the progress of a Player. +class QuestStage + attr_reader :name, :index + + # Creates the QuestProgress. + def initialize(name, index, quest, log_text = nil) + @name = name + @index = index + @quest = quest + @log_text = log_text + end + + # Returns whether or no this quest stage should be logged. + def logged + !@log_text.nil? + end + + # Gets the log text for this stage. + def log_text + fail 'Cannot get the log text from an unlogged quest stage.' unless logged + @log_text + end + + # Defines the equality operator. + def ==(other) + @index == index_of(other) + end + + # Defines the not equal operator. + def !=(other) + @index != index_of(other) + end + + # Defines the greater than or equal to operator. + def >=(other) + @index >= index_of(other) + end + + # Defines the greater than operator. + def >(other) + @index > index_of(other) + end + + # Defines the less than operator. + def <(other) + @index < index_of(other) + end + + # Defines the less than or equal to operator. + def <=(other) + @index <= index_of(other) + end + + private + + # Gets the index of the QuestStage with the specified name. + def index_of(name) + QUESTS[@quest].stage(name).index + end + +end + +# Define method_missing for player +class Player + + # Override method_missing to return a QuestStage if the method name indicates quest. + def method_missing(symbol, *args) + unless args.nil? + arg = args[0] + args[0] = arg.name if arg.is_a?(QuestStage) + end + + result = super(symbol, *args) + string = symbol.to_s + + if string.end_with?('_progress') + name = string[0..-10] # Cut the '_progress' from the end + quest = QUESTS[name.to_sym] + fail "No Quest with the name '#{name}' exists." if quest.nil? + + result = quest.stage(result) + end + + result + end + +end diff --git a/game/data/plugins/run/plugin.xml b/game/data/plugins/run/plugin.xml new file mode 100644 index 000000000..6594f2bbf --- /dev/null +++ b/game/data/plugins/run/plugin.xml @@ -0,0 +1,16 @@ + + + run + 1 + Running + Adds support for running via the options interface. + + Major + + + + + + attributes + + \ No newline at end of file diff --git a/game/data/plugins/run/run.rb b/game/data/plugins/run/run.rb new file mode 100644 index 000000000..8b1063518 --- /dev/null +++ b/game/data/plugins/run/run.rb @@ -0,0 +1,10 @@ +WALK_BUTTON_ID = 152 +RUN_BUTTON_ID = 153 + +on :button, WALK_BUTTON_ID do |player| + player.toggle_running +end + +on :button, RUN_BUTTON_ID do |player| + player.toggle_running +end diff --git a/game/data/plugins/shops/currency.rb b/game/data/plugins/shops/currency.rb new file mode 100644 index 000000000..b0c9a5fc4 --- /dev/null +++ b/game/data/plugins/shops/currency.rb @@ -0,0 +1,35 @@ +require 'java' + +java_import 'org.apollo.cache.def.ItemDefinition' + +# A currency that can be used to purchase items in a Shop. +class Currency + attr_reader :name + + # Creates the Currency. + def initialize(id, name = ItemDefinition.lookup(id).name) + fail 'Currency must have a name.' if name.nil? + @id = id + @name = name.to_s + end + + # Adds the specified amount of this `Currency` to the specified `Player`'s inventory. + def add(player, amount) + player.inventory.add(@id, amount) + end + + # Removes the specified amount of this `Currency` from the specified `Player`'s inventory. + def remove(player, amount) + player.inventory.remove(@id, amount) + end + + # Gets the amount of this Currency in the specified player's inventory. + def total(player) + player.inventory.get_amount(@id) + end + + def sell_value(id) + (ItemDefinition.lookup(id).value * 0.60).floor + end + +end diff --git a/game/data/plugins/shops/plugin.xml b/game/data/plugins/shops/plugin.xml new file mode 100644 index 000000000..e8d682317 --- /dev/null +++ b/game/data/plugins/shops/plugin.xml @@ -0,0 +1,20 @@ + + + shops + 0.1 + Shops + Adds shop support. + + Stuart + Major + + + + + + + + + util + + diff --git a/game/data/plugins/shops/shop.rb b/game/data/plugins/shops/shop.rb new file mode 100644 index 000000000..d455d27df --- /dev/null +++ b/game/data/plugins/shops/shop.rb @@ -0,0 +1,28 @@ +require 'java' + +java_import 'org.apollo.game.model.inv.Inventory' + +# A shop containing items that can be sold. +class Shop + attr_reader :buys, :currency, :items, :inventory, :name, :npc_options + + def initialize(name, items, currency, options, buys) + @name = name + @items = items + @currency = currency + @buys = buys + @npc_options = options + @inventory = Inventory.new(DEFAULT_CAPACITY, Inventory::StackMode::STACK_ALWAYS) + + items.each { |item| @inventory.add(item.id, item.amount) } + end + +end + +private + +# The `Currency` used by default. +DEFAULT_CURRENCY = Currency.new(995, 'coins') + +# The default capacity of a shop. +DEFAULT_CAPACITY = 30 diff --git a/game/data/plugins/shops/shop_item.rb b/game/data/plugins/shops/shop_item.rb new file mode 100644 index 000000000..a761702ce --- /dev/null +++ b/game/data/plugins/shops/shop_item.rb @@ -0,0 +1,20 @@ +require 'java' + +java_import 'org.apollo.cache.def.ItemDefinition' + +java_import 'org.apollo.game.model.Item' + +# An Item in a Shop. +class ShopItem + attr_reader :amount, :cost, :id, :name + + # Creates the ShopItem. + def initialize(id, amount, cost = nil) + definition = ItemDefinition.lookup(id) + @id = id + @amount = amount + @cost = cost.nil? ? definition.value : cost + @name = definition.name + end + +end diff --git a/game/data/plugins/shops/shops.rb b/game/data/plugins/shops/shops.rb new file mode 100644 index 000000000..3229ed660 --- /dev/null +++ b/game/data/plugins/shops/shops.rb @@ -0,0 +1,301 @@ +require 'java' + +java_import 'org.apollo.cache.def.ItemDefinition' + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.message.impl.SetWidgetTextMessage' +java_import 'org.apollo.game.message.handler.ItemVerificationHandler' +java_import 'org.apollo.game.model.inv.SynchronizationInventoryListener' +java_import 'org.apollo.game.model.inter.InterfaceListener' + +# The hash of npc ids to Shops. +SHOPS = {} + +# Creates the Shop from the specified Hash. +def create_shop(hash) + unless hash.has_keys?(:items, :name, :npcs) + fail 'Shop name, npcs, and items must be specified to create a shop.' + end + + npcs, name = hash[:npcs], hash[:name] + npcs = [npcs] unless npcs.is_a?(Array) + currency = hash[:currency] || DEFAULT_CURRENCY + + options = hash[:npc_options] || [1] + buys = hash[:buys] || :own + + items = hash.delete(:items).collect { |data| ShopItem.new(lookup_item(data[0]), data[1]) } + shop = Shop.new(name, items, currency, options, buys) + + npcs.map { |name| lookup_npc(name) }.each { |npc| SHOPS[npc] = shop } +end + +private + +# The sidebar id for the inventory, when a Shop window is open. +INVENTORY_SIDEBAR = 3822 + +# The container id for the above inventory, when a Shop window is open. +INVENTORY_CONTAINER = 3823 + +# The Shop interface id. +SHOP_INTERFACE = 3824 + +# The container id for the Shop interface. +SHOP_CONTAINER = 3900 + +# The widget that displays the shop name. +SHOP_NAME_WIDGET = 3901 + +# The delay before a Shop is opened when the Player is in range of the Npc, in ticks. +SHOP_OPEN_DELAY = 0 + +# The distance, in tiles, the Player must reach before a Shop can be opened. +SHOP_DISTANCE = 1 + +# An `InventorySupplier` for a `Shop`. +class ShopInventorySupplier + java_implements ItemVerificationHandler::InventorySupplier + + def getInventory(player) + shop = player.open_shop + shop == -1 ? nil : SHOPS[shop].inventory + end + +end + +# An `InventorySupplier` for a `Player` with the shop window open. +class PlayerInventorySupplier + java_implements ItemVerificationHandler::InventorySupplier + + def getInventory(player) + player.open_shop == -1 ? nil : player.inventory + end + +end + +ItemVerificationHandler.add_inventory(SHOP_CONTAINER, ShopInventorySupplier.new) +ItemVerificationHandler.add_inventory(INVENTORY_CONTAINER, PlayerInventorySupplier.new) + +# A DistancedAction causing a Player to open a shop. +class OpenShopAction < DistancedAction + attr_reader :player, :npc, :shop + + # Creates the OpenShopAction. + def initialize(player, npc, shop) + super(SHOP_OPEN_DELAY, true, player, npc.position, 1) + @npc = npc + @shop = shop + end + + # Executes this DistancedAction, opening the shop. + def executeAction + mob.interacting_mob = @npc + open_shop(mob, @npc.id) + stop + end + + # Returns whether or not this DistancedAction is equal to the specified Object. + def equals(other) + get_class == other.get_class && @npc == other.npc && @shop == other.shop + end + +end + +# An InterfaceListener for when a Shop is closed. +class ShopCloseInterfaceListener + java_implements InterfaceListener + + # Creates the ShopCloseInterfaceListener. + def initialize(player, inventory_listener, shop_listener) + @player = player + @inventory_listener = inventory_listener + @shop_listener = shop_listener + end + + # Executed when the Shop interface is closed. + def interface_closed + @player.inventory.remove_listener(@inventory_listener) + SHOPS[@player.open_shop].inventory.remove_listener(@shop_listener) + + @player.open_shop = -1 + @player.reset_interacting_mob + end + +end + +# Intercept the npc action message. +on :message, :first_npc_action do |player, message| + npc = $world.npc_repository.get(message.index) + + if SHOPS.key?(npc.id) + shop = SHOPS[npc.id] + + valid = shop.npc_options.empty? || shop.npc_options.include?(message.option) + player.start_action(OpenShopAction.new(player, npc, SHOPS[npc.id])) if valid + end +end + +# Opens the Shop registered to the specified npc. +def open_shop(player, npc) + shop = SHOPS[npc] + fail "No shop registered to npc #{npc} exists." if shop.nil? + + player.open_shop = npc + + inventory_listener = SynchronizationInventoryListener.new(player, INVENTORY_CONTAINER) + shop_listener = SynchronizationInventoryListener.new(player, SHOP_CONTAINER) + + player_inventory, shop_inventory = player.inventory, shop.inventory + + player_inventory.add_listener(inventory_listener) + player_inventory.force_refresh + + shop_inventory.add_listener(shop_listener) + shop_inventory.force_refresh + + player.send(SetWidgetTextMessage.new(SHOP_NAME_WIDGET, shop.name)) + + listener = ShopCloseInterfaceListener.new(player, inventory_listener, shop_listener) + player.interface_set.open_window_with_sidebar(listener, SHOP_INTERFACE, INVENTORY_SIDEBAR) +end + +# Intercept the Item action. +on :message, :item_action do |player, message| + interface = message.interface_id + + if player.open_shop == -1 || !SHOPS.key?(player.open_shop) + message.terminate + next + end + + if interface != INVENTORY_CONTAINER && interface != SHOP_CONTAINER + message.terminate + next + end + + shop = SHOPS[player.open_shop] + inventory = shop.inventory + currency = shop.currency + slot = message.slot + + player_inventory = player.inventory + + if interface == INVENTORY_CONTAINER + id = message.id + contains = inventory.contains(id) + + if !shop.buys == :none || shop.buys == :own && !contains + player.send_message('You can\'t sell this item to this shop.') + message.terminate + next + end + + if !contains && inventory.free_slots == 0 + player.send_message('The shop is currently full at the moment.') + message.terminate + next + end + + item = player_inventory.get(slot) + value = currency.sell_value(id) + + option = message.option + if option == 1 + player.send_message("#{item.definition.name}: shop will buy for #{value} #{currency.name}.") + next + end + + sell_amount = case option + when 2 then 1 + when 3 then 5 + when 4 then 10 + else next + end + + available = player_inventory.get_amount(id) + sell_amount = available if sell_amount > available + + total_value = (value * sell_amount).floor + + player_inventory.remove(id, sell_amount) + inventory.add(id, sell_amount) + currency.add(player, total_value) if total_value > 0 + + message.terminate + elsif interface == SHOP_CONTAINER + buy(shop, player, message, currency) + end +end + +# Buys the item from the `Shop`. +def buy(shop, player, message, currency) + inventory, slot = shop.inventory, message.slot + shop_item, invent_item = shop.items[slot], inventory.get(slot) + + id = shop_item.id + + option = message.option + if option == 1 + player.send_message("#{shop_item.name}: currently costs #{shop_item.cost} #{currency.name}.") + return + end + + buy_amount = case option + when 2 then 1 + when 3 then 5 + when 4 then 10 + else next + end + + no_stock = false + if buy_amount > invent_item.amount + buy_amount = invent_item.amount + no_stock = true + end + + player_inventory = player.inventory + has_item = player_inventory.get_amount(id) == 0 + + definition = invent_item.definition + space_required = if definition.stackable && has_item then 0 + elsif !definition.stackable then buy_amount + else 1 + end + + free_slots = player_inventory.free_slots + not_enough_space = false + + if space_required > free_slots + not_enough_space = true + buy_amount = free_slots + end + + total_currency = shop.currency.total(player) + too_poor = false + total_cost = buy_amount * shop_item.cost + + if total_cost > total_currency + buy_amount = (total_currency / shop_item.cost).floor + too_poor = true + end + + if buy_amount > 0 + currency.remove(player, buy_amount * shop_item.cost) + player_inventory.add(id, buy_amount) + + keep = invent_item.amount == buy_amount && shop.buys == :own + keep ? inventory.set(slot, Item.new(id, 0)) : inventory.remove(id, buy_amount) + end + + warning = if too_poor then "You don't have enough #{currency.name}." + elsif no_stock then 'The shop has run out of stock.' + elsif not_enough_space then 'You don\'t have enough inventory space.' + end + + player.send_message(warning) unless warning.nil? + message.terminate +end + +# Declares the open_shop attribute, which contains the id of the currently open shop. +declare_attribute(:open_shop, -1) diff --git a/game/data/plugins/skill/fishing/fish.rb b/game/data/plugins/skill/fishing/fish.rb new file mode 100644 index 000000000..0abd571c1 --- /dev/null +++ b/game/data/plugins/skill/fishing/fish.rb @@ -0,0 +1,41 @@ + +# The hash of names to fish. +CATCHABLE_FISH = {} + +# A fish that can be caught. +class Fish + attr_reader :id, :level, :experience, :name + + # Creates the Fish. + def initialize(id, level, experience) + @id = id + @level = level + @experience = experience + @name = name_of(:item, id) + end + +end + +# Appends a Fish to the hash. +def append_fish(name, hash) + unless hash.has_keys?(:id, :level, :experience) + fail 'Hash must contain an id, level, and experience.' + end + + CATCHABLE_FISH[name] = Fish.new(hash[:id], hash[:level], hash[:experience]) +end + +append_fish :shrimp, id: 317, level: 1, experience: 10 +append_fish :sardine, id: 327, level: 5, experience: 20 +append_fish :herring, id: 345, level: 10, experience: 30 +append_fish :anchovy, id: 321, level: 15, experience: 40 +append_fish :mackerel, id: 353, level: 16, experience: 20 +append_fish :trout, id: 335, level: 20, experience: 50 +append_fish :cod, id: 341, level: 23, experience: 45 +append_fish :pike, id: 349, level: 25, experience: 60 +append_fish :salmon, id: 331, level: 30, experience: 70 +append_fish :tuna, id: 359, level: 35, experience: 80 +append_fish :lobster, id: 377, level: 40, experience: 90 +append_fish :bass, id: 363, level: 46, experience: 100 +append_fish :swordfish, id: 371, level: 50, experience: 100 +append_fish :shark, id: 383, level: 76, experience: 110 diff --git a/game/data/plugins/skill/fishing/fishing.rb b/game/data/plugins/skill/fishing/fishing.rb new file mode 100644 index 000000000..244a88000 --- /dev/null +++ b/game/data/plugins/skill/fishing/fishing.rb @@ -0,0 +1,120 @@ +require 'java' + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.entity.Skill' + +# An action that causes a mob to fish at a spot. +class FishingAction < DistancedAction + attr_reader :position, :options, :spot, :started, :tool + + # Creates the FishingAction. + def initialize(mob, position, spot, option) + super(4, true, mob, position, 1) + @position = position + @spot = spot + @tool = spot.tools[option - 1] + + @options = (option == 1) ? spot.first_fish : spot.second_fish + @minimum_level = @options.map(&:level).min + end + + # Returns whether or not a catch is successful. + def successful_catch(level, requirement) + [level - requirement + 5, 30].min > rand(40) + end + + # Starts the fishing process. + def start_fishing + @started = true + mob.send_message(tool.message) + end + + # Executes the action. + def executeAction + skills = mob.skill_set + fishing_level = skills.get_skill(Skill::FISHING).current_level + mob.turn_to(position) + + if @minimum_level > fishing_level + mob.send_message("You need a fishing level of #{@minimum_level} to fish at this spot.") + stop + return + end + + inventory = mob.inventory + if inventory.free_slots.zero? + inventory.force_capacity_exceeded + stop + return + end + + unless inventory.contains(@tool.id) + mob.send_message("You need a #{@tool.name.downcase} to fish at this spot.") + stop + return + end + + bait = find_bait + if bait == -1 + mob.send_message("You need #{name_of(:item, bait).downcase}s to fish at this spot.") + stop + return + end + + if @started + options = @options.reject { |fish| fish.level > fishing_level } + # Player may level up mid-action so reject here, not at initialisation. + fish = options.sample # TODO: it's a ~70/30 chance, not 50/50 + + if successful_catch(fishing_level, fish.level) + inventory.remove(bait) unless bait.nil? + inventory.add(fish.id) + + name = fish.name + mob.send_message("You catch #{name.end_with?('s') ? 'some' : 'a'} #{name.downcase}.") + skills.add_experience(Skill::FISHING, fish.experience) + + if find_bait == -1 + mob.send_message("You need more #{name_of(:item, bait).downcase}s to fish at this spot.") + stop + return + end + end + else + start_fishing + end + + mob.play_animation(@tool.animation) + end + + # Finds the id of the first piece of bait in the player's inventory, or nil if no bait is + # required, or -1 if the player's inventory does not contain any valid bait. + def find_bait + baits = @tool.bait + baits.empty? ? nil : baits.find(-1) { |bait| mob.inventory.contains(bait) } + end + + # Stops this action. + def stop + super + mob.stop_animation + end + + def equals(other) + get_class == other.get_class && @spot == other.spot && @position == other.position && + @options == @other.options + end + +end + +# Intercepts the NpcAction message to determine whether or not a clicked npc was a fishing spot. +on :message, :npc_action do |player, message| + npc = $world.npc_repository.get(message.index) + spot = FISHING_SPOTS[npc.id] + + unless spot.nil? + player.start_action(FishingAction.new(player, npc.position, spot, message.option)) + message.terminate + end +end diff --git a/game/data/plugins/skill/fishing/plugin.xml b/game/data/plugins/skill/fishing/plugin.xml new file mode 100644 index 000000000..64f84d785 --- /dev/null +++ b/game/data/plugins/skill/fishing/plugin.xml @@ -0,0 +1,20 @@ + + + skill-fishing + 1 + Fishing + Adds the fishing skill. + + Linux + Major + + + + + + + + + util + + \ No newline at end of file diff --git a/game/data/plugins/skill/fishing/spot.rb b/game/data/plugins/skill/fishing/spot.rb new file mode 100644 index 000000000..c1875ab1e --- /dev/null +++ b/game/data/plugins/skill/fishing/spot.rb @@ -0,0 +1,26 @@ + +# The hash of fishing spots. +FISHING_SPOTS = {} + +# A Fishing spot. +class Spot + attr_reader :tools, :first_fish, :second_fish + + # Creates the fishing spot. + def initialize(tools, first_fish, second_fish) + @tools = tools.map { |id| FISHING_TOOLS[id] } + @first_fish = first_fish.map { |fish| CATCHABLE_FISH[fish] } + @second_fish = second_fish.map { |fish| CATCHABLE_FISH[fish] } + end + +end + +# Appends a fishing spot to the hash. +def append_spot(id, spot) + FISHING_SPOTS[id] = spot +end + +append_spot(309, Spot.new([:fly_fishing_rod, :fishing_rod], [:trout, :salmon], [:pike])) +append_spot(312, Spot.new([:lobster_cage, :harpoon], [:lobster], [:tuna, :swordfish])) +append_spot(313, Spot.new([:big_net, :harpoon], [:mackerel, :cod], [:bass, :shark])) +append_spot(316, Spot.new([:small_net, :fishing_rod], [:shrimp, :anchovy], [:sardine, :herring])) diff --git a/game/data/plugins/skill/fishing/tool.rb b/game/data/plugins/skill/fishing/tool.rb new file mode 100644 index 000000000..8f3b105cb --- /dev/null +++ b/game/data/plugins/skill/fishing/tool.rb @@ -0,0 +1,60 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' + +# The hash of fishing tool names to Tools. +FISHING_TOOLS = {} + +# A fishing tool. +class Tool + attr_reader :animation, :bait, :id, :message, :name + + # Creates the tool. + def initialize(id, animation, message, bait) + @id = id + @bait = bait + @animation = Animation.new(animation) + @message = message + + @name = name_of(:item, id) + end + +end + +private + +# Appends a tool with the specified name to the hash. +def tool(name, hash) + unless hash.has_keys?(:id, :animation, :message) + fail 'Hash must contain an id, animation, and message.' + end + + bait = hash[:bait] || [] + FISHING_TOOLS[name] = Tool.new(hash[:id], hash[:animation], hash[:message], bait) +end + +# The harpoon fishing animation id. +HARPOON_ANIMATION = 618 + +# The cage fishing animation id. +CAGE_ANIMATION = 619 + +# The net fishing animation id. +NET_ANIMATION = 620 + +# The rod fishing animation id. +ROD_ANIMATION = 622 + +# TODO: The other feathers that can be used +FISHING_ROD_BAIT = [313] +FLY_FISHING_ROD_BAIT = [314] + +tool :lobster_cage, id: 301, animation: CAGE_ANIMATION, message: 'You attempt to catch a lobster...' +tool :small_net, id: 303, animation: NET_ANIMATION, message: 'You cast out your net...' +tool :big_net, id: 305, animation: NET_ANIMATION, message: 'You cast out your net...' +tool :harpoon, id: 311, animation: HARPOON_ANIMATION, message: 'You start harpooning fish...' + +tool :fishing_rod, id: 307, animation: ROD_ANIMATION, message: 'You attempt to catch a fish...', + bait: FISHING_ROD_BAIT +tool :fly_fishing_rod, id: 309, animation: ROD_ANIMATION, message: 'You attempt to catch a fish...', + bait: FLY_FISHING_ROD_BAIT diff --git a/game/data/plugins/skill/herblore/herb.rb b/game/data/plugins/skill/herblore/herb.rb new file mode 100644 index 000000000..30a10bf4b --- /dev/null +++ b/game/data/plugins/skill/herblore/herb.rb @@ -0,0 +1,95 @@ +require 'java' + +java_import 'org.apollo.game.action.Action' +java_import 'org.apollo.util.LanguageUtil' + +# A herb is an ingredient that requires identification before being used. +class Herb < Ingredient + include HerbloreMethod + + attr_reader :unidentified, :level, :experience + + def initialize(item_id, unidentified, level, experience) + super item_id + + @unidentified = unidentified + @level = level + @experience = experience + end + + def invoke(player, _id, slot) + item = player.inventory.get(slot) + player.start_action(HerbIdentificationAction.new(player, self, slot, item)) + end +end + +# An action that makes a player identify a herb. +class HerbIdentificationAction < Action + attr_reader :herb, :slot, :item, :pulses + + def initialize(player, herb, slot, item) + super(0, true, player) + + @herb = herb + @slot = slot + @item = item + @pulses = 0 + end + + def execute + if @pulses == 0 + unless check_skill(mob, @herb.level, 'identify this herb') + stop + return + end + end + + execute_action + @pulses += 1 + end + + def execute_action + player = mob + inventory = player.inventory + + if inventory.remove_slot(@slot, 1) == 1 + identified = @herb.item + + inventory.add(identified) + + article = LanguageUtil.getIndefiniteArticle(identified.definition.name) + player.skill_set.add_experience(Skill::HERBLORE, @herb.experience) + player.send_message("This herb is #{article} #{identified.definition.name}.") + end + + stop + end + + def equals(other) + get_class == other.get_class && slot == other.slot && herb == other.herb + end +end + +# Appends a herb to the InventoryItemMessage interception. +def append_herb(item_id, unidentified, level, experience) + herb = Herb.new(item_id, unidentified, level, experience) + append_herblore_item(herb, unidentified) + herb +end + +# Herbs + +GUAM_LEAF = append_herb(249, 199, 1, 2.5) +MARRENTILL = append_herb(251, 201, 5, 3.8) +TARROMIN = append_herb(253, 203, 11, 5) +HARRALANDER = append_herb(255, 205, 20, 6.3) +RANARR = append_herb(257, 207, 25, 7.5) +TOADFLAX = append_herb(2998, 3049, 30, 8) +IRIT_LEAF = append_herb(259, 209, 40, 8.8) +AVANTOE = append_herb(261, 211, 48, 10) +KWUARM = append_herb(263, 213, 54, 11.3) +SNAPDRAGON = append_herb(3000, 3051, 59, 11.8) +CADANTINE = append_herb(265, 215, 65, 12.5) +LANTADYME = append_herb(2481, 2485, 67, 13.1) +DWARF_WEED = append_herb(267, 217, 70, 13.8) +TORSTOL = append_herb(269, 219, 75, 15) diff --git a/game/data/plugins/skill/herblore/herblore.rb b/game/data/plugins/skill/herblore/herblore.rb new file mode 100644 index 000000000..8ce822da3 --- /dev/null +++ b/game/data/plugins/skill/herblore/herblore.rb @@ -0,0 +1,102 @@ +# Thanks to Sillhouette for posting +# a large amount of Herblore skill data which has been thankfully used in this plugin. + +require 'java' + +java_import 'org.apollo.game.message.impl.SetWidgetItemModelMessage' +java_import 'org.apollo.game.model.entity.Skill' + +HERBLORE_DIALOGUE = 4429 + +HERBLORE_ITEM = {} +HERBLORE_ITEM_ON_ITEM = {} + +DRINK_ITEM = {} + +# A module which describes an invocable method of the Herblore skill. +module HerbloreMethod + def self.new + fail 'You cannot instantiate this module!' + end + + def invoke(_player, _primary, _secondary) + fail 'You must implement the invocation of HerbloreMethod!' + end +end + +# The ItemOnItemMessage listener for all Herblore-related functions. +on :message, :item_on_item do |player, message| + primary = message.id + secondary = message.target_id + hash = HERBLORE_ITEM_ON_ITEM[primary] + + if hash.nil? + secondary = message.id + primary = message.target_id + hash = HERBLORE_ITEM_ON_ITEM[primary] + end + + unless hash.nil? + method = hash[secondary] + unless method.nil? + method.invoke(player, primary, secondary) + message.terminate + end + end +end + +# The ItemOptionMessage listener for all Herblore-related functions. +on :message, :first_item_option do |player, message| + id = message.id + method = HERBLORE_ITEM[id] + + unless method.nil? + method.invoke(player, id, message.slot) + message.terminate + end + method = DRINK_ITEM[id] + + unless method.nil? + method.invoke(player, id, message.slot) + message.terminate + end +end + +# Utility for adding the various Herblore methods to the handled constant arrays. +def append_herblore_item(method, key, secondary = -1) + if secondary == -1 + HERBLORE_ITEM[key] = method + else + hash = HERBLORE_ITEM_ON_ITEM[key] + hash = {} if hash.nil? + + hash[secondary] = method + HERBLORE_ITEM_ON_ITEM[key] = hash + end +end + +# Utility method for checking if a player's inventory has a of the specified id, with optionally +# the specified amount (1 by default), at the specified slot. +def check_slot(player, slot, id, amount = 1) + item = player.inventory.get(slot) + !item.nil? && item.id == id && item.amount >= amount +end + +# Utility method for checking if a player's Herblore (maximum) level is at the required level. Also +# informs the player if this is not the case with use of the action variable, like so: +# "You need a Herblore level of at least #{required.to_s} to #{action}." +def check_skill(player, required, action) + if required > player.skill_set.get_skill(Skill::HERBLORE).current_level + player.send_message("You need a Herblore level of at least #{required} to #{action}.") + return false + end + + true +end + +# Opens a 'make' dialogue for the specified player, displaying the specified item. Optionally, a +# listener can be used for the dialogue. +def open_dialogue(player, item, listener = nil) + player.send(SetWidgetItemModelMessage.new(1746, item, 170)) + player.interface_set.open_dialogue(listener, HERBLORE_DIALOGUE) +end diff --git a/game/data/plugins/skill/herblore/ingredient.rb b/game/data/plugins/skill/herblore/ingredient.rb new file mode 100644 index 000000000..f01bfef8f --- /dev/null +++ b/game/data/plugins/skill/herblore/ingredient.rb @@ -0,0 +1,251 @@ +require 'java' + +java_import 'org.apollo.game.action.Action' +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Item' +java_import 'org.apollo.game.model.inter.EnterAmountListener' +java_import 'org.apollo.game.model.inter.dialogue.DialogueAdapter' + +GRINDING_ANIM = Animation.new(364) +PESTLE_MORTAR = 233 + +# An ingredient which can be used for making (unfinished) potions. +class Ingredient + attr_reader :item_id, :item + + def initialize(item) + @item_id = item + @item = Item.new(item) # Share item instances. + end + + # Checks if the specified player has the specified amount of this ingredient. Optionally, they + # can immediately be removed if that amount was indeed found. + def check_remove(player, amount, remove) + inventory = player.inventory + counter = 0 + + inventory.items.each do |inv_item| + break unless counter < amount + next if inv_item.nil? + + id = inv_item.id + inventory_amount = inv_item.amount + + if id == @item_id + if inventory_amount >= amount + inventory.remove(@item_id, amount) if remove + return true + else + counter += inventory_amount + end + end + end + + if counter >= amount + inventory.remove(@item_id, amount) if remove + return true + end + + false + end +end + +# An ingredient which needs to be grinded before being usable for Herblore. +class GroundIngredient < Ingredient + include HerbloreMethod + + attr_reader :raw + + def initialize(item_id, raw) + super(item_id) + @raw = raw + end + + def invoke(player, _pestle_mortar, _ingredient) + action = GrindingAction.new(player, self) + listener = GrindingDialogueListener.new(player, action) + + open_dialogue(player, @item_id, listener) + end +end + +# A DialogueAdapter used for grinding ingredients. It is also used as an EnterAmountListener for +# the amount of grinding actions. +class GrindingDialogueListener < DialogueAdapter + include EnterAmountListener + + attr_reader :player, :action + + def initialize(player, action) + super() + @player = player + @action = action + end + + # Called when a button has been clicked whilst the dialogue was opened. + def buttonClicked(button) + amount = get_amount(button) + return false if amount == 0 + + interfaces = @player.interface_set + interfaces.close + + if amount == -1 + interfaces.open_enter_amount_dialogue(self) + return true + end + + amount = player.inventory.get_amount(@action.ingredient.raw) if amount == -2 + execute(amount) + end + + # Called when an amount of grinding actions has been entered. + def amountEntered(amount) + execute(amount) if amount > 0 + end + + # Called to set the action(s) in motion. + def execute(amount) + @action.set_amount(amount) + @player.start_action(@action) + end + + # Gets the amount of actions based on the specified button id. + def get_amount(button) + case button + when 2799 then return 1 + when 2798 then return 5 + when 1748 then return -1 + when 1747 then return -2 + else return 0 + end + end +end + +# An action which makes the player grind one or more GrindedIngredients from their 'raw' form. +class GrindingAction < Action + attr_reader :ingredient, :amount, :pulses, :slot, :listener + + def initialize(player, ingredient) + super(0, true, player) + + @ingredient = ingredient + @pulses = 0 + end + + def execute + grind + @pulses += 1 + end + + # Performs the grinding action once the materials have been checked. + def grind + if @pulses == 0 + mob.play_animation GRINDING_ANIM + elsif @pulses == 1 + unless gather_materials + stop + return + end + + player = mob + inventory = player.inventory + item = inventory.get(@slot) + + name = item.definition.name.downcase + player.send_message("You grind the #{name} to dust.") + + inventory.reset(@slot) + inventory.add(@ingredient.item) + + set_delay(1) + elsif @pulses == 2 + mob.stop_animation + continue + end + end + + # Checks if the player has the required materials to perform the (next) action. + def gather_materials + items = mob.inventory.items + + pst_mrt = false + ingr = false + raw = @ingredient.raw + (0...items.length).each do |slot| + item = items[slot] + next if item.nil? + + id = item.id + if id == PESTLE_MORTAR && !pst_mrt + pst_mrt = true + elsif id == raw && !ingr + ingr = true + @slot = slot + end + + return true if pst_mrt && ingr + end + + mob.send_message("You do not have any more #{name_of(raw).downcase}s.") + false + end + + # Either invokes the stop() method in Action to shut it down + # or continues to the next ingredient. + def continue + @amount -= 1 + + if @amount > 0 + set_delay(0) + @pulses = -1 + else + stop + end + end + + # Sets the amount of actions. + def set_amount(amount) + @amount = amount + end + + def stop + super + mob.inventory.remove_listener(@listener) unless listener.nil? + end + + def equals(other) + get_class == other.get_class && @ingredient == other.ingredient + end +end + +# Appends a ground ingredient to the ItemOnItemMessage listener interception. +def append_ground(id, raw) + ground = GroundIngredient.new(id, raw) + append_herblore_item(ground, PESTLE_MORTAR, raw) + ground +end + +# Normal ingredients +EYE_NEWT = Ingredient.new(221) +RED_SPIDERS_EGGS = Ingredient.new(223) +LIMPWURT_ROOT = Ingredient.new(225) +SNAPE_GRASS = Ingredient.new(231) +WHITE_BERRIES = Ingredient.new(239) +WINE_ZAMORAK = Ingredient.new(245) +JANGERBERRIES = Ingredient.new(247) +TOADS_LEGS = Ingredient.new(2152) +MORT_MYRE_FUNGI = Ingredient.new(2970) +POTATO_CACTUS = Ingredient.new(3138) +PHOENIX_FEATHER = Ingredient.new(4621) +FROG_SPAWN = Ingredient.new(5004) +PAPAYA_FRUIT = Ingredient.new(5972) +POISON_IVY_BERRIES = Ingredient.new(6018) +YEW_ROOTS = Ingredient.new(6049) +MAGIC_ROOTS = Ingredient.new(6051) + +# Ground ingredients +UNICORN_HORN_DUST = append_ground(235, 237) +DRAGON_SCALE_DUST = append_ground(241, 243) +CHOCOLATE_DUST = append_ground(1975, 1973) +CRUSHED_NEST = append_ground(6693, 5075) diff --git a/game/data/plugins/skill/herblore/plugin.xml b/game/data/plugins/skill/herblore/plugin.xml new file mode 100644 index 000000000..748712be0 --- /dev/null +++ b/game/data/plugins/skill/herblore/plugin.xml @@ -0,0 +1,18 @@ + + + skill-herblore + 0.9 + Herblore + Adds the Herblore skill. + + Chris Fletcher + Major + + + + + + + + + \ No newline at end of file diff --git a/game/data/plugins/skill/herblore/potion.rb b/game/data/plugins/skill/herblore/potion.rb new file mode 100644 index 000000000..706feafab --- /dev/null +++ b/game/data/plugins/skill/herblore/potion.rb @@ -0,0 +1,372 @@ +require 'java' + +java_import 'org.apollo.game.action.Action' +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Item' +java_import 'org.apollo.game.model.entity.Skill' +java_import 'org.apollo.game.model.inter.EnterAmountListener' +java_import 'org.apollo.game.model.inter.dialogue.DialogueAdapter' + +private + +WATER_VIAL_ID = 227 +EMPTY_VIAL_ID = 229 + +MIXING_ANIM = Animation.new(363) + +# Represents an unfinished potion which can be invoked as a HerbloreMethod and used as an +# ingredient. +class UnfinishedPotion < Ingredient + include HerbloreMethod + + attr_reader :herb, :level + + def initialize(item_id, herb, level) + super(item_id) + @herb = herb + @level = level + end + + def invoke(player, _primary, _secondary) + action = UnfinishedMixingAction.new(player, self) + listener = UnfinishedMixingDialogueListener.new(player, action) + + open_dialogue(player, @item_id, listener) + end + +end + +# Represents a finished potion which can be invoked as a HerbloreMethod. +class FinishedPotion + include HerbloreMethod + + attr_reader :item, :ingredients, :level, :experience + + def initialize(item, ingredients, level, experience) + @item = Item.new(item) + @ingredients = ingredients + @level = level + @experience = experience + end + + def invoke(player, primary, secondary) + action = FinishedMixingAction.new(player, primary, secondary, self) + listener = FinishedMixingDialogueListener.new(player, action) + + open_dialogue(player, @item.id, listener) + end +end + +# A DialogueAdapter used for mixing potions. It is also used as an EnterAmountListener for the +# amount of mixing actions. +class MixingDialogueListener < DialogueAdapter + include EnterAmountListener + + attr_reader :player, :action + + def initialize(player, action) + super() + + @player = player + @action = action + end + + # Called when a button has been clicked whilst the dialogue was opened. + def buttonClicked(button) + amount = get_amount(button) + + return false if amount == 0 + + interfaces = @player.interface_set + interfaces.close + + if amount == -1 + interfaces.open_enter_amount_dialogue(self) + return true + end + + amount = calculate_maximum if amount == -2 + + execute(amount) + true + end + + # Called when an amount of mixing actions has been entered. + def amountEntered(amount) + execute(amount) if amount > 0 + end + + # Called to set the action(s) in motion. + def execute(amount) + @action.set_amount(amount) + @player.start_action(@action) + end + + def calculate_maximum(_code) + # Override for potion-specific amount calculation. + end + + # Gets the amount of actions based on the specified button id. + def get_amount(button) + case button + when 2799 then return 1 + when 2798 then return 5 + when 1748 then return -1 + when 1747 then return -2 + else return 0 + end + end + +end + +# A MixingDialogueListener used for mixing unfinished potions. +class UnfinishedMixingDialogueListener < MixingDialogueListener + + def calculate_maximum + inventory = @player.inventory + + amount = inventory.get_amount(WATER_VIAL_ID) + return 0 if amount <= 0 + + herbs = inventory.get_amount(@action.potion.herb.item.id) + [herbs, amount].min + end + +end + +# A MixingDialogueListener used for mixing finished potions. +class FinishedMixingDialogueListener < MixingDialogueListener + + def calculate_maximum + inventory = @player.inventory + + amount = inventory.capacity + @action.potion.ingredients.each do |ingredient| + item_amount = inventory.get_amount(ingredient.item.id) + amount = item_amount if amount > item_amount + end + + amount + end + +end + +# An Action which handles the none-finished-dependent mixing. +class MixingAction < Action + attr_reader :potion, :amount, :started, :pulses, :action, :listener + + def initialize(player, potion, action) + super(1, true, player) + + @potion = potion + @started = false + @pulses = 0 + @action = action + @action.freeze + end + + def execute + if @pulses == 0 + unless @started + unless check_skill(mob, @potion.level, @action) + stop + return + end + + @started = true + end + + unless gather_materials + stop + return + end + end + + mob.play_animation(MIXING_ANIM) + execute_action + + @amount -= 1 + @amount > 0 ? @pulses = 0 : stop + end + + def stop + super() + mob.inventory.remove_listener(@listener) unless @listener.nil? + end + + def execute_action + # Override for action execution. + end + + def gather_materials + # Override for ingredient checking and gathering + false + end + + # Sets the amount of actions. + def set_amount(amount) + @amount = amount + end + + def equals(other) + get_class == other.get_class && @potion == other.potion + end +end + +# A MixingAction which handles the execution of making UnfinishedPotions. +class UnfinishedMixingAction < MixingAction + attr_reader :slots + + def initialize(player, potion) + super(player, potion, 'use this herb.') + end + + def execute_action + name = @potion.herb.item.definition.name + player = mob + inventory = player.inventory + + created = name.sub(/ leaf$/, '') + message = "You put the #{name} in the water to make an unfinished #{created} potion." + player.send_message(message) + + @slots.each do |slot, amount| + unless inventory.remove_slot(slot, amount) + stop + return + end + end + + inventory.add(@potion.item) + end + + def gather_materials + @slots = {} + inventory = mob.inventory + + vial_slot = inventory.slot_of(WATER_VIAL_ID) + if vial_slot == -1 + mob.send_message('You do not have any more vials of water.') + return false + end + + item = @potion.herb.item + herb_slot = inventory.slot_of(item.id) + if herb_slot == -1 + mob.send_message("You do not have any more #{item.definition.name}.") + return false + end + + @slots[vial_slot] = 1 + @slots[herb_slot] = 1 + + true + end + +end + +# A MixingAction which handles the execution of making FinishedPotions. +class FinishedMixingAction < MixingAction + attr_reader :unfinished, :ingredient, :slots + + def initialize(player, unfinished, ingredient, potion) + super(player, potion, 'mix this potion') + @unfinished = unfinished + @ingredient = ingredient + end + + def execute_action + ingredient = name_of(:item, @ingredient).downcase + name = @potion.item.definition.name.sub('(3)', '') + + name = "#{LanguageUtil.get_indefinite_article(name)} #{name}" + mob.send_message("You add the #{ingredient} to the mixture to make #{name}.") + mob.skill_set.add_experience(Skill::HERBLORE, @potion.experience) + + inventory = mob.inventory + + @slots.each do |slot, amount| + unless inventory.remove_slot(slot, amount) # TODO: will this remove stuff incorrectly? + stop + return + end + end + + inventory.add(@potion.item) + end + + def gather_materials + @slots = {} + inventory = mob.inventory + + vial_slot = inventory.slot_of(@unfinished) + if vial_slot == -1 + mob.send_message('You do not have enough unfinished potions.') + return false + end + + ingredient_slot = inventory.slot_of(@ingredient) + if ingredient_slot == -1 + mob.send_message('You do not have enough ingredients.') + return false + end + + @slots[vial_slot] = 1 + @slots[ingredient_slot] = 1 + + true + end + +end + +# Appends a finished potion to the ItemOnItemMessage handling interception. +def finished_potion(item, unfinished, ingredient, level, experience) + potion = FinishedPotion.new(item, [unfinished, ingredient], level, experience) + append_herblore_item(potion, unfinished.item_id, ingredient.item_id) + potion +end + +# Appends an unfinished potion to the ItemOnItemMessage handling interception. +def unfinished_potion(item, herb, level) + potion = UnfinishedPotion.new(item, herb, level) + append_herblore_item(potion, herb.item_id, WATER_VIAL_ID) + potion +end + +# Unfinished potions +UNF_GUAM = unfinished_potion(91, GUAM_LEAF, 1) # 3 +UNF_MARRENTILL = unfinished_potion(93, MARRENTILL, 5) +UNF_TARROMIN = unfinished_potion(95, TARROMIN, 12) +UNF_HARRALANDER = unfinished_potion(97, HARRALANDER, 22) +UNF_RANARR = unfinished_potion(99, RANARR, 30) +UNF_TOADFLAX = unfinished_potion(3002, TOADFLAX, 34) +UNF_IRIT = unfinished_potion(101, IRIT_LEAF, 45) +UNF_AVANTOE = unfinished_potion(103, AVANTOE, 50) +UNF_KWUARM = unfinished_potion(105, KWUARM, 55) +UNF_SNAPDRAGON = unfinished_potion(3004, SNAPDRAGON, 63) +UNF_CADANTINE = unfinished_potion(107, CADANTINE, 66) +UNF_LANTADYME = unfinished_potion(2483, LANTADYME, 69) +UNF_DWARF_WEED = unfinished_potion(109, DWARF_WEED, 72) +UNF_TORSTOL = unfinished_potion(111, TORSTOL, 78) + +# Finished potions +ATTACK_POT = finished_potion(121, UNF_GUAM, EYE_NEWT, 1, 25) # 3 +ANTIPOISON_POT = finished_potion(175, UNF_MARRENTILL, UNICORN_HORN_DUST, 5, 37.5) +STRENGTH_POT = finished_potion(115, UNF_TARROMIN, LIMPWURT_ROOT, 12, 50) +RESTORE_POT = finished_potion(127, UNF_HARRALANDER, RED_SPIDERS_EGGS, 18, 62.5) +ENERGY_POT = finished_potion(3010, UNF_HARRALANDER, CHOCOLATE_DUST, 26, 67.5) +DEFENCE_POT = finished_potion(133, UNF_RANARR, WHITE_BERRIES, 30, 75) +AGILITY_POT = finished_potion(3034, UNF_TOADFLAX, TOADS_LEGS, 34, 80) +PRAYER_POT = finished_potion(139, UNF_RANARR, SNAPE_GRASS, 38, 87.5) +SUPER_ATTACK_POT = finished_potion(145, UNF_IRIT, EYE_NEWT, 45, 100) +SUPER_ANTIPOISON_POT = finished_potion(181, UNF_IRIT, UNICORN_HORN_DUST, 48, 106.3) +FISHING_POT = finished_potion(151, UNF_AVANTOE, SNAPE_GRASS, 50, 112.5) +SUPER_ENERGY_POT = finished_potion(3018, UNF_AVANTOE, MORT_MYRE_FUNGI, 52, 117.5) +SUPER_STRENGTH_POT = finished_potion(157, UNF_KWUARM, LIMPWURT_ROOT, 55, 125) +WEAPON_POISON = finished_potion(187, UNF_KWUARM, DRAGON_SCALE_DUST, 60, 137.5) +SUPER_RESTORE_POT = finished_potion(3026, UNF_SNAPDRAGON, RED_SPIDERS_EGGS, 63, 142.5) +SUPER_DEFENCE_POT = finished_potion(163, UNF_CADANTINE, WHITE_BERRIES, 66, 150) +ANTIFIRE_POT = finished_potion(2428, UNF_LANTADYME, DRAGON_SCALE_DUST, 69, 157.5) +RANGING_POT = finished_potion(169, UNF_DWARF_WEED, WINE_ZAMORAK, 72, 162.5) +MAGIC_POT = finished_potion(3042, UNF_LANTADYME, POTATO_CACTUS, 76, 172.5) +ZAMORAK_BREW = finished_potion(189, UNF_TORSTOL, JANGERBERRIES, 78, 175) diff --git a/game/data/plugins/skill/magic/alchemy.rb b/game/data/plugins/skill/magic/alchemy.rb new file mode 100644 index 000000000..755a04d5a --- /dev/null +++ b/game/data/plugins/skill/magic/alchemy.rb @@ -0,0 +1,81 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Graphic' +java_import 'org.apollo.game.model.entity.Skill' + +ALCHEMY_SPELLS = {} + +ILLEGAL_ALCH_ITEMS = [995] + +# A spell that alchemises an item. +class AlchemySpell < Spell + attr_reader :animation, :graphic, :multiplier, :experience, :delay + + def initialize(level, elements, experience, animation, graphic, multiplier, delay) + super(level, elements, experience) + @animation = animation + @graphic = graphic + @multiplier = multiplier + @delay = delay + end + +end + +# An Action that performs an AlchemySpell. +class AlchemyAction < ItemSpellAction + + def initialize(player, alchemy, slot, item) + super(player, alchemy, slot, item) + end + + def illegal_item? + ILLEGAL_ALCH_ITEMS.include?(@item.id) + end + + def execute_action + if @pulses == 0 + mob.play_animation(@spell.animation) + mob.play_graphic(@spell.graphic) + + inventory = mob.inventory + gold = (item.definition.value * @spell.multiplier) + + inventory.remove(inventory.get(@slot).id, 1) + inventory.add(995, gold) + + mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) + set_delay(@spell.delay) + elsif @pulses == 1 + mob.stop_animation + mob.stop_graphic + stop + end + end + +end + +private + +# The height of the graphic. +GRAPHIC_HEIGHT = 100 + +# Inserts an `AlchemySpell` into the hash of available alchemy spells. +def alchemy(_name, hash) + unless hash.has_keys?(:button, :level, :fires, :animation, :graphic, :multiplier, :experience, :delay) + fail 'Hash must have button, level, fires, animation, graphic, multiplier, experience, delay keys.' + end + + id, multiplier = hash[:button], hash[:multiplier] + level, experience = hash[:level], hash[:experience] + + runes = { NATURE => 1, FIRE => hash[:fires] } + animation = Animation.new(hash[:animation]) + graphic = Graphic.new(hash[:graphic], 0, GRAPHIC_HEIGHT) + delay = hash[:delay] + + ALCHEMY_SPELLS[id] = AlchemySpell.new(level, runes, experience, animation, graphic, multiplier, delay) +end + +alchemy :low_level, button: 1_162, level: 21, fires: 3, animation: 712, graphic: 112, multiplier: 0.4, experience: 31, delay: 2 +alchemy :high_level, button: 1_178, level: 55, fires: 5, animation: 713, graphic: 113, multiplier: 0.6, experience: 65, delay: 3 diff --git a/game/data/plugins/skill/magic/convert.rb b/game/data/plugins/skill/magic/convert.rb new file mode 100644 index 000000000..65c2284bf --- /dev/null +++ b/game/data/plugins/skill/magic/convert.rb @@ -0,0 +1,89 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Graphic' +java_import 'org.apollo.game.model.Item' +java_import 'org.apollo.game.model.entity.Skill' + +CONVERT_SPELLS = {} +BONES_ID = 526 + +CONVERT_ANIM = Animation.new(722) +CONVERT_GRAPHIC = Graphic.new(141, 0, 100) + +# A `Spell` for converting items. +class ConvertSpell < Spell + attr_reader :reward + + def initialize(level, elements, experience, reward) + super(level, elements, experience) + @reward = Item.new(reward) + end + +end + +# A `SpellAction` for a `ConvertSpell`. +class ConvertingAction < SpellAction + attr_reader :slots + + def initialize(player, spell, slots) + super(player, spell) + @slots = slots + end + + def execute_action + if @pulses == 0 + mob.play_animation(CONVERT_ANIM) + mob.play_graphic(CONVERT_GRAPHIC) + + inventory = mob.inventory + firing = (@slots.length * 2) < inventory.capacity + + inventory.stop_firing_events unless firing # In case of many changes, wait with firing events + + reward = @spell.reward + @slots.each { |slot| inventory.set(slot, reward) } + + unless firing + inventory.start_firing_events + inventory.force_refresh + end + + mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) + set_delay(2) + elsif @pulses == 1 + mob.stop_animation + mob.stop_graphic + stop + end + end + +end + +def bone_slots(player) + inventory = player.inventory + items = inventory.items + size = inventory.size + + counter = 0 + slots = [] + + (0...inventory.capacity).each do |slot| + break unless counter <= size + + item = items[slot] + slots << slot if !item.nil? && item.id == BONES_ID + + counter += 1 + end + + slots +end + +def convert(_name, button, level, elements, experience, reward) + CONVERT_SPELLS[button] = ConvertSpell.new(level, elements, experience, reward) +end + +convert :bones_to_bananas, 1159, 15, { NATURE => 1, WATER => 2, EARTH => 2 }, 25, 1963 +convert :bones_to_peaches, 15877, 60, { NATURE => 2, WATER => 4, EARTH => 4 }, 35.5, 6883 + diff --git a/game/data/plugins/skill/magic/element.rb b/game/data/plugins/skill/magic/element.rb new file mode 100644 index 000000000..46d3a352f --- /dev/null +++ b/game/data/plugins/skill/magic/element.rb @@ -0,0 +1,107 @@ +require 'java' + +java_import 'org.apollo.game.model.entity.EquipmentConstants' + +AIR_ELEMENTS = {} +WATER_ELEMENTS = {} +EARTH_ELEMENTS = {} +FIRE_ELEMENTS = {} + +AIR_RUNE = 556 +WATER_RUNE = 555 +EARTH_RUNE = 557 +FIRE_RUNE = 554 + +MIND_RUNE = 558 +CHAOS_RUNE = 562 +DEATH_RUNE = 560 +BLOOD_RUNE = 565 + +COSMIC_RUNE = 564 +LAW_RUNE = 563 +NATURE_RUNE = 561 +SOUL_RUNE = 566 + +MIST_RUNE = 4695 +DUST_RUNE = 4696 +SMOKE_RUNE = 4697 +MUD_RUNE = 4698 +STEAM_RUNE = 4694 +LAVA_RUNE = 4699 + +# An element of a spell. +class Element + attr_reader :runes, :staffs, :name + + def initialize(runes, staffs, name = 'Null') + @runes = runes + @staffs = staffs + @name = name + end + + def check_remove(player, amount, remove) + weapon = player.equipment.get(EquipmentConstants::WEAPON) + unless @staffs.nil? || weapon.nil? + @staffs.each { |staff| return true if weapon.id == staff } + end + + inventory = player.inventory + + found = {} + counter = 0 + + inventory.items.each do |item| + break unless counter < amount + next if item.nil? + + amt = item.amount + @runes.each do |rune| + break unless counter < amount + + id = item.id + if id == rune + if amt >= amount + inventory.remove(id, amount) if remove + return true + else + found[id] = amt + counter += amt + end + end + end + end + + if counter >= amount + found.each { |id, amt| inventory.remove(id, amt) } if remove + return true + end + + false + end + +end + +AIR_RUNES = [556, 4695, 4696, 4697] +WATER_RUNES = [555, 4695, 4698, 4694] +EARTH_RUNES = [557, 4696, 4697, 4698] +FIRE_RUNES = [554, 4697, 4694, 4699] + +AIR_STAFFS = [1381, 1397, 1405] +WATER_STAFFS = [1383, 1395, 1403] +EARTH_STAFFS = [1385, 1399, 1407, 3053, 3054] +FIRE_STAFFS = [1387, 1393, 1401, 3053, 3054] + +AIR = Element.new(AIR_RUNES, AIR_STAFFS, 'Air rune') +WATER = Element.new(WATER_RUNES, WATER_STAFFS, 'Water rune') +EARTH = Element.new(EARTH_RUNES, EARTH_STAFFS, 'Earth rune') +FIRE = Element.new(FIRE_RUNES, FIRE_STAFFS, 'Fire rune') + +MIND = Element.new([MIND_RUNE], nil, 'Mind rune') +CHAOS = Element.new([CHAOS_RUNE], nil, 'Chaos rune') +DEATH = Element.new([DEATH_RUNE], nil, 'Death rune') +BLOOD = Element.new([BLOOD_RUNE], nil, 'Blood rune') + +COSMIC = Element.new([COSMIC_RUNE], nil, 'Cosmic rune') +LAW = Element.new([LAW_RUNE], nil, 'Law rune') +NATURE = Element.new([NATURE_RUNE], nil, 'Nature rune') +SOUL = Element.new([SOUL_RUNE], nil, 'Soul rune') diff --git a/game/data/plugins/skill/magic/enchant.rb b/game/data/plugins/skill/magic/enchant.rb new file mode 100644 index 000000000..319726cbc --- /dev/null +++ b/game/data/plugins/skill/magic/enchant.rb @@ -0,0 +1,106 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Graphic' +java_import 'org.apollo.game.model.Item' + +ENCHANT_SPELLS = {} +ENCHANT_ITEMS = {} + +RING_GFX = Graphic.new(238, 0, 100) +RING_ANIM = Animation.new(931) + +LOW_NECK_GFX = Graphic.new(114, 0, 100) +LOW_NECK_ANIM = Animation.new(719) + +MED_NECK_GFX = Graphic.new(115, 0, 100) +MED_NECK_ANIM = Animation.new(720) + +HIGH_NECK_GFX = Graphic.new(116, 0, 100) +HIGH_NECK_ANIM = Animation.new(721) + +ONYX_NECK_GFX = Graphic.new(452, 0, 100) + +# A `Spell` for enchanting an item. +class EnchantSpell < Spell + attr_reader :button, :animation, :graphic, :delay + + def initialize(button, level, elements, animation, graphic, delay, experience) + super(level, elements, experience) + @button = button + @animation = animation + @graphic = graphic + @delay = delay + end + +end + +# A `SpellAction` for an `EnchantSpell`. +class EnchantAction < ItemSpellAction + attr_reader :reward + + def initialize(player, enchant, slot, item, reward) + super(player, enchant, slot, item) + @reward = Item.new(reward) + end + + def illegal_item? + ENCHANT_ITEMS[@item.id].nil? + end + + def execute_action + if @pulses == 0 + mob.play_animation(@spell.animation) + mob.play_graphic(@spell.graphic) + + mob.inventory.set(@slot, @reward) + mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) + + set_delay(@spell.delay) + elsif @pulses == 1 + mob.stop_animation + mob.stop_graphic + stop + end + end + +end + +def enchant(button, level, elements, item, animation, graphic, delay, experience, reward) + enchant = EnchantSpell.new(button, level, elements, animation, graphic, delay, experience) + ENCHANT_SPELLS[item] = enchant + ENCHANT_ITEMS[item] = reward +end + +SAPPHIRE_ELEMENTS = { COSMIC => 1, WATER => 1 } +EMERALD_ELEMENTS = { COSMIC => 1, AIR => 1 } +RUBY_ELEMENTS = { COSMIC => 1, FIRE => 5 } +DIAMOND_ELEMENTS = { COSMIC => 1, EARTH => 10 } +DSTONE_ELEMENTS = { COSMIC => 1, EARTH => 15, WATER => 15 } +ONYX_ELEMENTS = { COSMIC => 1, FIRE => 20, EARTH => 20 } + +# Sapphire +enchant 1155, 7, SAPPHIRE_ELEMENTS, 1637, RING_ANIM, RING_GFX, 2, 17.5, 2550 # Ring +enchant 1155, 7, SAPPHIRE_ELEMENTS, 1656, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 17.5, 3853 # Necklace +enchant 1155, 7, SAPPHIRE_ELEMENTS, 1692, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 17.5, 1727 # Amulet + +# Emerald +enchant 1165, 27, EMERALD_ELEMENTS, 1639, RING_ANIM, RING_GFX, 2, 37, 2552 # Ring +enchant 1165, 27, EMERALD_ELEMENTS, 1658, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 37, 5521 # Necklace +enchant 1165, 27, EMERALD_ELEMENTS, 1696, LOW_NECK_ANIM, LOW_NECK_GFX, 1, 37, 1729 # Amulet + +# Ruby +enchant 1176, 49, RUBY_ELEMENTS, 1641, RING_ANIM, RING_GFX, 2, 59, 2568 # Ring +enchant 1176, 49, RUBY_ELEMENTS, 1698, MED_NECK_ANIM, MED_NECK_GFX, 2, 59, 1725 # Amulet + +# Diamond +enchant 1180, 57, DIAMOND_ELEMENTS, 1643, RING_ANIM, RING_GFX, 2, 67, 2570 # Ring +enchant 1180, 57, DIAMOND_ELEMENTS, 1700, MED_NECK_ANIM, MED_NECK_GFX, 2, 67, 1731 # Amulet + +# Dragonstone +enchant 1187, 68, DSTONE_ELEMENTS, 1645, RING_ANIM, RING_GFX, 2, 78, 2572 # Ring +enchant 1187, 68, DSTONE_ELEMENTS, 1702, HIGH_NECK_ANIM, HIGH_NECK_GFX, 3, 78, 1712 # Amulet + +# Onyx +enchant 6003, 87, ONYX_ELEMENTS, 6575, RING_ANIM, RING_GFX, 2, 97, 6583 # Ring +enchant 6003, 87, ONYX_ELEMENTS, 6581, HIGH_NECK_ANIM, ONYX_NECK_GFX, 2, 97, 6585 # Amulet diff --git a/game/data/plugins/skill/magic/magic.rb b/game/data/plugins/skill/magic/magic.rb new file mode 100644 index 000000000..71ddcfb49 --- /dev/null +++ b/game/data/plugins/skill/magic/magic.rb @@ -0,0 +1,172 @@ +require 'java' + +java_import 'org.apollo.game.action.Action' +java_import 'org.apollo.game.message.impl.DisplayTabInterfaceMessage' +java_import 'org.apollo.game.model.entity.EquipmentConstants' +java_import 'org.apollo.game.model.entity.Skill' +java_import 'org.apollo.cache.def.ItemDefinition' + +# A `Message` to display the magic spellbook. +DISPLAY_SPELLBOOK = DisplayTabInterfaceMessage.new(6) + +# A spell that can be cast. +class Spell + attr_reader :level, :elements, :experience + + def initialize(level, elements, experience) + @level = level + @elements = elements + @experience = experience + end + +end + +# An `Action` for casting a `Spell`. +class SpellAction < Action + attr_reader :spell, :pulses + + def initialize(mob, spell) + super(0, true, mob) + @spell = spell + @pulses = 0 + end + + def illegal_item? + false + end + + def execute + if @pulses == 0 + unless check_skill + stop + return + end + if illegal_item? + mob.send_message('You cannot use that spell on this item!') + stop + return false + end + unless process_elements + stop + return + end + end + execute_action + @pulses += 1 + end + + def execute_action + stop + end + + def check_skill + required = @spell.level + if required > mob.skill_set.getSkill(Skill::MAGIC).current_level + mob.send_message("You need a Magic level of at least #{required} to cast this spell.") + return false + end + + true + end + + def process_elements + elements = @spell.elements + + elements.each do |element, amount| + unless element.check_remove(mob, amount, false) + mob.send_message("You do not have enough #{element.name.split.map(&:capitalize) * ' '}s to cast this spell.") + return false + end + end + + elements.each { |element, amount| element.check_remove(mob, amount, true) } + true + end + + def equals(other) + get_class == other.get_class + end + +end + +# A `SpellAction` that verifies an input `Item` is legal. +class ItemSpellAction < SpellAction + attr_reader :slot, :item + + def initialize(mob, spell, slot, item) + super(mob, spell) + @slot = slot + @item = item + end + + # We override SpellAction#execute to implement an illegal item check (e.g. coins for alchemy) + def execute + if @pulses == 0 + id = @item.id + + mob.send(DISPLAY_SPELLBOOK) + + # TODO: There has to be a better way to do this. + @spell.elements.each do |element, amount| + element.runes.each do |rune| + if id == rune && !element.check_remove(mob, amount + 1, false) + mob.send_message("You do not have enough #{element.name.split.map(&:capitalize) * ' '}s to cast this spell.") + stop + return false + end + end + end + + end + + super + end + +end + +# Intercepts the magic on item message. +on :message, :magic_on_item do |player, message| + spell = message.spell_id + + alchemy = ALCHEMY_SPELLS[spell] + unless alchemy.nil? + slot = message.slot + item = player.inventory.get(slot) + player.start_action(AlchemyAction.new(player, alchemy, slot, item)) + message.terminate + else + enchant = ENCHANT_SPELLS[message.id] + + if !enchant.nil? && enchant.button == spell + slot = message.slot + item = player.inventory.get(slot) + player.start_action(EnchantAction.new(player, enchant, slot, item, ENCHANT_ITEMS[item.id])) + message.terminate + end + end +end + +# Intercepts the button message +on :message, :button do |player, message| + button = message.widget_id + + tele = TELEPORT_SPELLS[button] + unless tele.nil? + player.start_action(TeleportingAction.new(player, tele)) + message.terminate + end + + conv = CONVERT_SPELLS[button] + unless conv.nil? + slots = bone_slots(player) + + if slots.length == 0 + player.send_message("You can't convert these bones!") + else + player.start_action(ConvertingAction.new(player, conv, slots)) + end + + message.terminate + end + +end diff --git a/game/data/plugins/skill/magic/plugin.xml b/game/data/plugins/skill/magic/plugin.xml new file mode 100644 index 000000000..24e3cede4 --- /dev/null +++ b/game/data/plugins/skill/magic/plugin.xml @@ -0,0 +1,20 @@ + + + skill-magic + 1 + Magic + Adds the Magic skill. + + Chris Fletcher + Major + + + + + + + + + + + \ No newline at end of file diff --git a/game/data/plugins/skill/magic/teleport.rb b/game/data/plugins/skill/magic/teleport.rb new file mode 100644 index 000000000..a62411ecf --- /dev/null +++ b/game/data/plugins/skill/magic/teleport.rb @@ -0,0 +1,101 @@ +# Thanks to phl0w for providing +# the correct destination coordinates of the ancient teleports. + +require 'java' + +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Graphic' +java_import 'org.apollo.game.model.Position' +java_import 'org.apollo.game.model.entity.Skill' + +TELEPORT_SPELLS = {} + +MODERN_TELE_ANIM = Animation.new(714) +MODERN_TELE_GRAPHIC = Graphic.new(111, 5, 100) + +ANCIENT_TELE_END_GRAPHIC = Graphic.new(455) +ANCIENT_TELE_ANIM = Animation.new(1979) +ANCIENT_TELE_GRAPHIC = Graphic.new(392) + +# A `Spell` that teleports a `Player` to another `Position`. +class TeleportSpell < Spell + attr_reader :ancient, :destination, :experience, :name + + def initialize(ancient, level, elements, destination, experience, name) + super(level, elements, experience) + @ancient = ancient + @destination = destination + @name = name + end + +end + +# A `SpellAction` for a `TeleportSpell`. +class TeleportingAction < SpellAction + + def initialize(mob, spell) + super(mob, spell) + end + + def execute_action + @spell.ancient ? execute_ancient : execute_modern + end + + def execute_modern + if @pulses == 0 + mob.play_animation(MODERN_TELE_ANIM) + mob.play_graphic(MODERN_TELE_GRAPHIC) + elsif @pulses == 3 + mob.stop_graphic + mob.stop_animation + mob.teleport(@spell.destination) + mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) + stop + end + end + + def execute_ancient + if @pulses == 0 + mob.play_graphic(ANCIENT_TELE_GRAPHIC) + mob.play_animation(ANCIENT_TELE_ANIM) + set_delay(2) + elsif @pulses == 2 + mob.stop_graphic + mob.stop_animation + mob.teleport(@spell.destination) + mob.skill_set.add_experience(Skill::MAGIC, @spell.experience) + stop + end + end + +end + +def tele(ancient = false, button, level, elements, x, y, experience, name) + position = Position.new(x, y) + TELEPORT_SPELLS[button] = TeleportSpell.new(ancient, level, elements, position, experience, name) +end + +def ancient_tele(*args) + tele(true, *args) +end + +# Modern teleports +tele 1_164, 25, { LAW => 1, AIR => 3, FIRE => 1 }, 3213, 3424, 35, 'Varrock' +tele 1_167, 31, { LAW => 1, AIR => 3, EARTH => 1 }, 3222, 3219, 41, 'Lumbridge' +tele 1_170, 37, { LAW => 1, AIR => 3, WATER => 1 }, 2965, 3379, 47, 'Falador' +tele 1_174, 45, { LAW => 1, AIR => 5 }, 2757, 3478, 55.5, 'Camelot' +tele 1_540, 51, { LAW => 2, WATER => 2 }, 2662, 3306, 61, 'Ardougne' +tele 1_541, 58, { LAW => 2, EARTH => 2 }, 2549, 3114, 68, 'the Watchtower' +tele 7_455, 61, { LAW => 2, FIRE => 2 }, 2871, 3590, 68, 'Trollheim' +tele 18_470, 64, { Element.new([1963], nil, 'Banana') => 1, LAW => 2, WATER => 2, FIRE => 2 }, + 2_754, 2_785, 76, 'Ape Atoll' + +# Ancient teleports +ancient_tele 13_035, 54, { LAW => 2, FIRE => 1, AIR => 1 }, 3098, 9882, 64, 'Paddewwa' +ancient_tele 13_045, 60, { LAW => 2, SOUL => 2 }, 3320, 3338, 70, 'Senntisten' +ancient_tele 13_053, 66, { LAW => 2, BLOOD => 1 }, 3493, 3472, 76, 'Kharyll' +ancient_tele 13_061, 72, { LAW => 2, WATER => 4 }, 3003, 3470, 82, 'Lassar' +ancient_tele 13_069, 78, { LAW => 2, FIRE => 3, AIR => 2 }, 2966, 3_696, 88, 'Dareeyak' +ancient_tele 13_079, 84, { LAW => 2, SOUL => 2 }, 3163, 3664, 94, 'Carrallangar' +ancient_tele 13_087, 90, { LAW => 2, BLOOD => 2 }, 3287, 3883, 100, 'Annakarl' +ancient_tele 13_095, 96, { LAW => 2, WATER => 8 }, 2972, 3873, 106, 'Ghorrock' diff --git a/game/data/plugins/skill/mining/gem.rb b/game/data/plugins/skill/mining/gem.rb new file mode 100644 index 000000000..6d2255d3a --- /dev/null +++ b/game/data/plugins/skill/mining/gem.rb @@ -0,0 +1,20 @@ +GEMSTONES = {} + +# A gemstone that can be received when mining. +class Gemstone + attr_reader :id, :chance + + def initialize(id, chance) + @id = id + @chance = chance + end +end + +def gem(gem) + GEMSTONES[gem.id] = gem +end + +gem(Gemstone.new(1623, 0)) # uncut sapphire +gem(Gemstone.new(1605, 0)) # uncut emerald +gem(Gemstone.new(1619, 0)) # uncut ruby +gem(Gemstone.new(1617, 0)) # uncut diamond diff --git a/game/data/plugins/skill/mining/mining.rb b/game/data/plugins/skill/mining/mining.rb new file mode 100644 index 000000000..076577a1d --- /dev/null +++ b/game/data/plugins/skill/mining/mining.rb @@ -0,0 +1,155 @@ +require 'java' + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.model.entity.EquipmentConstants' +java_import 'org.apollo.game.model.entity.Skill' + +PROSPECT_PULSES = 3 +ORE_SIZE = 1 + +# TODO: finish implementing this +# A `DistancedAction` for mining ore. +class MiningAction < DistancedAction + attr_reader :position, :ore, :counter, :started + + def initialize(mob, position, ore) + super(0, true, mob, position, ORE_SIZE) + @position = position + @ore = ore + @started = false + @counter = 0 + end + + def find_pickaxe + weapon = mob.equipment.get(EquipmentConstants::WEAPON) + PICKAXE_IDS.each do |id| + return PICKAXES[id] if (!weapon.nil? && weapon.id == id) || mob.inventory.contains(id) + end + + nil + end + + # starts the mining animation, sets counters/flags and turns the mob to + # the ore + def start_mine(pickaxe) + @started = true + mob.send_message('You swing your pick at the rock.') + mob.play_animation(pickaxe.animation) + @counter = pickaxe.pulses + end + + def executeAction + skills = mob.skill_set + level = skills.get_skill(Skill::MINING).current_level + pickaxe = find_pickaxe + mob.turn_to(@position) + + # verify the mob can mine with their pickaxe + if pickaxe.nil? || level < pickaxe.level + mob.send_message('You do not have a pickaxe for which you have the level to use.') + stop + return + end + + # verify the mob can mine the ore + if ore.level > level + mob.send_message('You do not have the required level to mine this rock.') + stop + return + end + + # check if we need to kick start things + if @started + # count down and check if we can have a chance at some ore now + if @counter == 0 + # TODO: calculate the chance that the player can actually get the rock + + if mob.inventory.add(ore.id) + name = name_of(@ore.id).sub(/ ore$/, '').downcase + + mob.send_message("You manage to mine some #{name}.") + skills.add_experience(Skill::MINING, ore.exp) + # TODO: expire the rock + end + + stop + end + + @counter -= 1 + else + start_mine(pickaxe) + end + end + + def equals(other) + get_class == other.get_class && @position == other.position && @ore == other.ore + end + +end + +# A `DistancedAction` for a rock with no available ore. +class ExpiredProspectingAction < DistancedAction + attr_reader :position + + def initialize(mob, position) + super(0, true, mob, position, ORE_SIZE) + end + + def executeAction + mob.send_message('There is currently no ore available in this rock.') + stop + end + + def equals(other) + get_class == other.get_class && @position == other.position + end + +end + +# A `DistancedAction` for prospecting a rock. +class ProspectingAction < DistancedAction + attr_reader :position, :ore + + def initialize(mob, position, ore) + super(PROSPECT_PULSES, true, mob, position, ORE_SIZE) + @position = position + @ore = ore + @started = false + end + + def executeAction + if @started + ore_def = ItemDefinition.lookup(@ore.id) + name = ore_def.name.sub(/ ore$/, '').downcase + + mob.send_message("This rock contains #{name}.") + stop + else + @started = true + + mob.send_message('You examine the rock for ores...') + mob.turn_to(@position) + end + end + + def equals(other) + get_class == other.get_class && @position == other.position && @ore == other.ore + end + +end + +on :message, :first_object_action do |mob, message| + ore = ORES[message.id] + + mob.start_action(MiningAction.new(mob, message.position, ore)) unless ore.nil? +end + +on :message, :second_object_action do |mob, message| + ore = ORES[message.id] + + if !ore.nil? + mob.start_action(ProspectingAction.new(mob, message.position, ore)) + elsif !EXPIRED_ORES[message.id].nil? + mob.start_action(ExpiredProspectingAction.new(mob, message.position)) + end +end diff --git a/game/data/plugins/skill/mining/ore.rb b/game/data/plugins/skill/mining/ore.rb new file mode 100644 index 000000000..34b0a2f94 --- /dev/null +++ b/game/data/plugins/skill/mining/ore.rb @@ -0,0 +1,95 @@ +# Thanks to Mikey` for helping +# to find some of the item/object IDs, minimum levels and experiences. +# +# Thanks to Clifton for helping +# to find some of the expired object IDs. + +ORES = {} +EXPIRED_ORES = {} + +# An ore that can be mined. +class Ore + attr_reader :id, :objects, :level, :exp, :respawn + + def initialize(id, objects, level, exp, respawn) + @id = id + @objects = objects + @level = level + @exp = exp + @respawn = respawn + end +end + +def append_ore(ore) + ore.objects.each do |obj, expired_obj| + ORES[obj] = ore + EXPIRED_ORES[expired_obj] = true + end +end + +CLAY_OBJECTS = { + 2180 => 450, 2109 => 451, 14_904 => 14_896, 14_905 => 14_897 +} + +COPPER_OBJECTS = { + 11_960 => 11_555, 11_961 => 11_556, 11_962 => 11_557, 11_936 => 11_552, + 11_937 => 11_553, 11_938 => 11_554, 2090 => 450, 2091 => 451, + 14_906 => 14_898, 14_907 => 14_899, 14_856 => 14_832, 14_857 => 14_833, + 14_858 => 14_834 +} + +TIN_OBJECTS = { + 11_597 => 11_555, 11_958 => 11_556, 11_959 => 11_557, 11_933 => 11_552, + 11_934 => 11_553, 11_935 => 11_554, 2094 => 450, 2095 => 451, + 14_092 => 14_894, 14_903 => 14_895 +} + +IRON_OBJECTS = { + 11_954 => 11_555, 11_955 => 11_556, 11_956 => 11_557, 2092 => 450, + 2093 => 451, 14_900 => 14_892, 14_901 => 14_893, 14_913 => 14_915, + 14_914 => 14_916 +} + +COAL_OBJECTS = { + 11_963 => 11_555, 11_964 => 11_556, 11_965 => 11_557, 11_930 => 11_552, + 11_931 => 11_553, 11_932 => 11_554, 2096 => 450, 2097 => 451, + 14_850 => 14_832, 14_851 => 14_833, 14_852 => 14_834 +} + +SILVER_OBJECTS = { + 11_948 => 11_555, 11_949 => 11_556, 11_950 => 11_557, 2100 => 450, 2101 => 451 +} + +GOLD_OBJECTS = { + 11_951 => 11_555, 11_952 => 11_556, 11_953 => 11_557, 2098 => 450, 2099 => 451 +} + +MITHRIL_OBJECTS = { + 11_945 => 11_555, 11_946 => 11_556, 11_947 => 11_557, 11_942 => 11_552, + 11_943 => 11_553, 11_944 => 11_554, 2102 => 450, 2103 => 451, + 14_853 => 14_832, 14_854 => 14_833, 14_855 => 14_834 +} + +ADAMANT_OBJECTS = { + 11_939 => 11_552, 11_940 => 11_553, 11_941 => 11_554, 2104 => 450, + 2105 => 451, 14_862 => 14_832, 14_863 => 14_833, 14_864 => 14_834 +} + +RUNITE_OBJECTS = { + 2106 => 450, 2107 => 451, 14_859 => 14_832, 14_860 => 14_833, + 14_861 => 14_834 +} + +append_ore Ore.new 434, CLAY_OBJECTS, 1, 5, 3 # clay +append_ore Ore.new 436, COPPER_OBJECTS, 1, 17.5, 6 # copper ore +append_ore Ore.new 438, TIN_OBJECTS, 1, 17.5, 6 # tin ore +append_ore Ore.new 440, IRON_OBJECTS, 15, 35, 16 # iron ore +append_ore Ore.new 453, COAL_OBJECTS, 30, 50, 100 # coal +append_ore Ore.new 444, GOLD_OBJECTS, 40, 65, 200 # gold ore +append_ore Ore.new 442, SILVER_OBJECTS, 20, 40, 200 # silver ore +append_ore Ore.new 447, MITHRIL_OBJECTS, 55, 80, 400 # mithril ore +append_ore Ore.new 449, ADAMANT_OBJECTS, 70, 95, 800 # adamant ore +append_ore Ore.new 451, RUNITE_OBJECTS, 85, 125, 2500 # runite ore + +# TODO: rune essence object id = 2491 +# level 1, exp 5, rune ess = 1436, pure ess = 7936 diff --git a/game/data/plugins/skill/mining/pickaxe.rb b/game/data/plugins/skill/mining/pickaxe.rb new file mode 100644 index 000000000..5c99ba3c8 --- /dev/null +++ b/game/data/plugins/skill/mining/pickaxe.rb @@ -0,0 +1,33 @@ +require 'java' + +java_import 'org.apollo.game.model.Animation' + +PICKAXES = {} +PICKAXE_IDS = [] + +# A pickaxe that can be mined with. +class Pickaxe + attr_reader :id, :level, :animation, :pulses + + def initialize(id, level, animation, pulses) + @id = id + @level = level + @animation = Animation.new(animation) + @pulses = pulses + end +end + +def append_pickaxe(pickaxe) + PICKAXES[pickaxe.id] = pickaxe + PICKAXE_IDS << pickaxe.id # tacky way of keeping things in order +end + +# NOTE: ADD LOWER LEVEL PICKAXES FIRST +append_pickaxe(Pickaxe.new(1265, 1, 625, 8)) # bronze pickaxe +append_pickaxe(Pickaxe.new(1267, 1, 626, 7)) # iron pickaxe +append_pickaxe(Pickaxe.new(1269, 1, 627, 6)) # steel pickaxe +append_pickaxe(Pickaxe.new(1273, 21, 629, 5)) # mithril pickaxe +append_pickaxe(Pickaxe.new(1271, 31, 628, 4)) # adamant pickaxe +append_pickaxe(Pickaxe.new(1275, 41, 624, 3)) # rune pickaxe + +PICKAXE_IDS.reverse! diff --git a/game/data/plugins/skill/mining/plugin.xml b/game/data/plugins/skill/mining/plugin.xml new file mode 100644 index 000000000..5e68d2453 --- /dev/null +++ b/game/data/plugins/skill/mining/plugin.xml @@ -0,0 +1,24 @@ + + + skill-mining + 1 + Mining + Adds the mining skill. + + Graham + Mikey` + WH:II:DOW + Requa + Clifton + + + + + + + + + + util + + \ No newline at end of file diff --git a/game/data/plugins/skill/mining/respawn.rb b/game/data/plugins/skill/mining/respawn.rb new file mode 100644 index 000000000..137fd7b69 --- /dev/null +++ b/game/data/plugins/skill/mining/respawn.rb @@ -0,0 +1,16 @@ +# Calculates the number of pulses it takes for an ore to respawn based on the +# number of players currently online. +# +# The 'base' argument is the number of pulses it takes with no players online. +# The 'players' argument is the number of players currently logged into the +# current world. +# +# The base times can be found on this website: +# http://runescape.salmoneus.net/mining.html#respawn +# +# These must be converted to pulses (seconds * 10 / 6) to work with this +# function. The rest of the mining plugin rounds the base respawn times in +# pulses down where appropriate. +def respawn_pulses(base, players) + base - players * base / ($world.player_repository.size * 2) +end diff --git a/game/data/plugins/skill/prayer/bury.rb b/game/data/plugins/skill/prayer/bury.rb new file mode 100644 index 000000000..2d3b6bc72 --- /dev/null +++ b/game/data/plugins/skill/prayer/bury.rb @@ -0,0 +1,89 @@ +require 'java' + +java_import 'org.apollo.game.action.Action' +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.entity.Skill' + +BURY_BONE_ANIMATION = Animation.new(827) +BONES = {} + +# A bone with an id and experience value. +class Bone + attr_reader :id, :experience + + def initialize(id, experience) + @id = id + @experience = experience + end + +end + +# An action where a bone in a player's inventory is buried. +class BuryBoneAction < Action + attr_reader :slot, :bone + + def initialize(mob, slot, bone) + super(1, true, mob) + @slot = slot + @bone = bone + @executions = 0 + end + + def execute + if @executions == 0 + mob.send_message('You dig a hole in the ground...') + mob.play_animation(BURY_BONE_ANIMATION) + @executions += 1 + elsif @executions == 1 + if mob.inventory.get(@slot).id == @bone.id + mob.send_message('You bury the bones.') + mob.inventory.reset(@slot) + mob.skill_set.add_experience(Skill::PRAYER, @bone.experience) + end + stop + end + end + + def equals(other) + get_class == other.get_class + end + +end + +# Intercepts the first item option message. +on :message, :first_item_option do |player, message| + bone = BONES[message.id] + + unless bone.nil? + player.start_action(BuryBoneAction.new(player, message.slot, bone)) + message.terminate + end +end + +# Appends a bone to the array +def append_bone(hash) + fail 'Hash must contain an id and an experience value.' unless hash.has_keys?(:id, :experience) + id = hash[:id] + BONES[id] = Bone.new(id, hash[:experience]) +end + +append_bone name: :regular_bones, id: 526, experience: 5 +append_bone name: :burnt_bones, id: 528, experience: 5 +append_bone name: :bat_bones, id: 530, experience: 4 +append_bone name: :big_bones, id: 532, experience: 45 +append_bone name: :babydragon_bones, id: 534, experience: 30 +append_bone name: :dragon_bones, id: 536, experience: 72 +append_bone name: :wolf_bones, id: 2859, experience: 14 +append_bone name: :shaikahan_bones, id: 3123, experience: 25 +append_bone name: :jogre_bones, id: 3125, experience: 15 +append_bone name: :burnt_zogre_bones, id: 3127, experience: 25 +append_bone name: :monkey_bones, id: 3179, experience: 14 # smallish +append_bone name: :monkey_bones, id: 3180, experience: 14 # medium +append_bone name: :monkey_bones, id: 3181, experience: 14 # quite large +append_bone name: :monkey_bones, id: 3182, experience: 14 # quite large +append_bone name: :monkey_bones, id: 3183, experience: 14 # small +append_bone name: :shaking_bones, id: 3187, experience: 14 +append_bone name: :zogre_bones, id: 4812, experience: 23 +append_bone name: :fayrg_bones, id: 4830, experience: 84 +append_bone name: :raurg_bones, id: 4832, experience: 96 +append_bone name: :ourg_bones, id: 4834, experience: 140 diff --git a/game/data/plugins/skill/prayer/plugin.xml b/game/data/plugins/skill/prayer/plugin.xml new file mode 100644 index 000000000..edbeb4415 --- /dev/null +++ b/game/data/plugins/skill/prayer/plugin.xml @@ -0,0 +1,18 @@ + + + skill-prayer + 0.9 + Prayer + Adds the Prayer skill. + + Major + 010253 + + + + + + + attributes + + \ No newline at end of file diff --git a/game/data/plugins/skill/prayer/prayers.rb b/game/data/plugins/skill/prayer/prayers.rb new file mode 100644 index 000000000..7f185ce6a --- /dev/null +++ b/game/data/plugins/skill/prayer/prayers.rb @@ -0,0 +1,88 @@ + +java_import 'org.apollo.game.message.impl.ConfigMessage' + +# Declares the active prayer attribute. +declare_attribute(:active_prayer, -1, :persistent) + +# The hash of button ids to prayers. +PRAYERS = {} + +# Intercept the ButtonMessage to toggle a prayer. +on :message, :button do |player, message| + button = message.widget_id + prayer = PRAYERS[button] + + unless prayer.nil? + if prayer.level > player.skill_set.get_maximum_level(Skill::PRAYER) + update_setting(player, prayer, :off) + next + end + + player.send_message('after level check') + previous = player.active_prayer + + update_setting(player, PRAYERS[previous], :off) unless previous == -1 + + if previous != button + player.send_message("Previous: #{previous}, new: #{button}.") + update_setting(player, prayer, :on) + player.active_prayer = button + end + end +end + +private + +# A Prayer that can be activated by a player. +class Prayer + attr_reader :name, :level, :button, :setting, :drain + + def initialize(name, level, button, setting, drain) + @name = name + @level = level + @button = button + @setting = setting + @drain = drain + end + +end + +def update_setting(player, prayer, state) + value = (state == :on) ? 1 : 0 + player.send_message("Toggling prayer #{prayer.name}, state: #{state}.") + player.send(ConfigMessage.new(prayer.setting, value)) +end + +# Appends a Prayer to the hash. +def append_prayer(name, hash) + unless hash.has_keys?(:level, :button, :setting, :drain) + fail 'Error: prayer hash hash must contain a level, button, setting, and drain.' + end + + button = hash[:button] + PRAYERS[button] = Prayer.new(name, hash[:level], button, hash[:setting], hash[:drain]) +end + +# Don't deal with the actual effect here to avoid mess (TODO do it, but with attributes?). +append_prayer :thick_skin, level: 1, button: 5609, setting: 83, drain: 0.01 +append_prayer :burst_of_strength, level: 4, button: 5610, setting: 84, drain: 0.01 +append_prayer :clarity_of_thought, level: 7, button: 5611, setting: 85, drain: 0.01 +append_prayer :rock_skin, level: 10, button: 5612, setting: 86, drain: 0.04 +append_prayer :superhuman_strength, level: 13, button: 5613, setting: 87, drain: 0.04 +append_prayer :improved_reflexes, level: 16, button: 5614, setting: 88, drain: 0.04 + +append_prayer :rapid_restore, level: 19, button: 5615, setting: 89, drain: 0.01 +append_prayer :rapid_heal, level: 22, button: 5615, setting: 90, drain: 0.01 +append_prayer :protect_item, level: 25, button: 5617, setting: 91, drain: 0.01 + +append_prayer :steel_skin, level: 28, button: 5618, setting: 92, drain: 0.1 +append_prayer :ultimate_strength, level: 31, button: 5619, setting: 93, drain: 0.1 +append_prayer :incredible_reflexes, level: 34, button: 5620, setting: 94, drain: 0.1 + +append_prayer :protect_from_magic, level: 37, button: 5621, setting: 95, drain: 0.15 +append_prayer :protect_from_missiles, level: 40, button: 5622, setting: 96, drain: 0.15 +append_prayer :protect_from_melee, level: 43, button: 5623, setting: 97, drain: 0.15 + +append_prayer :retribution, level: 46, button: 683, setting: 98, drain: 0.15 +append_prayer :redemption, level: 49, button: 684, setting: 99, drain: 0.15 +append_prayer :smite, level: 52, button: 685, setting: 100, drain: 0.2 diff --git a/game/data/plugins/skill/runecraft/altar.rb b/game/data/plugins/skill/runecraft/altar.rb new file mode 100644 index 000000000..04ac395de --- /dev/null +++ b/game/data/plugins/skill/runecraft/altar.rb @@ -0,0 +1,129 @@ +require 'java' + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.model.Position' + +PORTALS = {} +ENTRANCE_ALTARS = {} +CRAFTING_ALTARS = {} + +# Represents a runecrafting altar. +class Altar + attr_reader :entrance_altar, :crafting, :portal_id, :entrance, :exit, :crafting_centre + + def initialize(entrance_altar, crafting, portal_id, entrance_position, exit_position, + crafting_centre) + @entrance_altar = entrance_altar + @altar = crafting + @portal_id = portal_id + @entrance_position = entrance_position + @exit_position = exit_position + @crafting_centre = crafting_centre + end + +end + +# Intercepts the item on object message. +on :message, :item_on_object do |player, message| + talisman = TALISMANS[message.id] + altar = ENTRANCE_ALTARS[message.object_id] + + unless talisman.nil? || altar.nil? + player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position)) + message.terminate + end +end + +# Intercepts the first object action message. +on :message, :object_action do |player, message| + if message.option == 1 + object_id = message.id + + if PORTALS.key?(object_id) + altar = PORTALS[object_id] + entrance = altar.entrance_position + + player.start_action(TeleportAction.new(player, entrance, 1, altar.exit_position)) + message.terminate + elsif RUNES.key?(object_id) + rune = RUNES[object_id] + altar = CRAFTING_ALTARS[object_id] + + player.start_action(RunecraftingAction.new(player, rune, altar.crafting_centre)) + message.terminate + end + end +end + +# An action that causes a mob to teleport when it comes within the specified distance of a +# specified position. +class TeleportAction < DistancedAction + attr_reader :teleport_position + + def initialize(mob, position, distance, teleport_position) + super(0, true, mob, position, distance) + @teleport_position = teleport_position + end + + def executeAction + mob.teleport(@teleport_position) + stop + end + + def equals(other) + get_class == other.get_class && mob == other.mob && + @teleport_position == other.teleport_position + end + +end + +# Appends an altar to the list. +def altar(name, hash) + unless hash.has_keys?(:entrance_altar, :crafting, :portal, :entrance, :exit, :altar_centre) + fail "#{name} is missing one of: entrance altar id, crafting altar id, entrance portal position, "\ + "and altar centre position." + end + + entrance_altar, crafting = hash[:entrance_altar], hash[:crafting] + portal_id = hash[:portal] + + entrance = Position.new(*hash[:entrance]) + exit_position = Position.new(*hash[:exit]) + centre = Position.new(*hash[:altar_centre]) + + altar = Altar.new(entrance_altar, crafting, portal_id, entrance, exit_position, centre) + PORTALS[portal_id] = ENTRANCE_ALTARS[entrance_altar] = CRAFTING_ALTARS[crafting] = altar +end + +altar :air, entrance_altar: 2452, crafting: 2478, portal: 2465, + entrance: [2841, 4829], exit: [2983, 3292], altar_centre: [2844, 4834] + +altar :mind, entrance_altar: 2453, crafting: 2479, portal: 2466, + entrance: [2793, 4828], exit: [2980, 3514], altar_centre: [2786, 4841] + +altar :water, entrance_altar: 2454, crafting: 2480, portal: 2467, + entrance: [2726, 4832], exit: [3187, 3166], altar_centre: [2716, 4836] + +altar :earth, entrance_altar: 2455, crafting: 2481, portal: 2468, + entrance: [2655, 4830], exit: [3304, 3474], altar_centre: [2658, 4841] + +altar :fire, entrance_altar: 2456, crafting: 2482, portal: 2469, + entrance: [2574, 4849], exit: [3311, 3256], altar_centre: [2585, 4838] + +altar :body, entrance_altar: 2457, crafting: 2483, portal: 2470, + entrance: [2524, 4825], exit: [3051, 3445], altar_centre: [2525, 4832] + +altar :cosmic, entrance_altar: 2458, crafting: 2484, portal: 2471, + entrance: [2142, 4813], exit: [2408, 4379], altar_centre: [2142, 4833] + +altar :law, entrance_altar: 2459, crafting: 2485, portal: 2472, + entrance: [2464, 4818], exit: [2858, 3379], altar_centre: [2464, 4832] + +altar :nature, entrance_altar: 2460, crafting: 2486, portal: 2473, + entrance: [2400, 4835], exit: [2867, 3019], altar_centre: [2400, 4841] + +altar :chaos, entrance_altar: 2461, crafting: 2487, portal: 2474, + entrance: [2268, 4842], exit: [3058, 3591], altar_centre: [2271, 4842] + +altar :death, entrance_altar: 2462, crafting: 2488, portal: 2475, + entrance: [2208, 4830], exit: [3222, 3222], altar_centre: [2205, 4836] diff --git a/game/data/plugins/skill/runecraft/plugin.xml b/game/data/plugins/skill/runecraft/plugin.xml new file mode 100644 index 000000000..bdd1f063d --- /dev/null +++ b/game/data/plugins/skill/runecraft/plugin.xml @@ -0,0 +1,21 @@ + + + skill-runecraft + 0.9 + Runecraft + Adds the Runecraft skill. + + Major + BugCrusher + + + + + + + + + + util + + \ No newline at end of file diff --git a/game/data/plugins/skill/runecraft/rune.rb b/game/data/plugins/skill/runecraft/rune.rb new file mode 100644 index 000000000..37260f9b9 --- /dev/null +++ b/game/data/plugins/skill/runecraft/rune.rb @@ -0,0 +1,52 @@ +require 'java' + +# The hash of runes. +RUNES = {} + +# Represents a rune that can be crafted. +class Rune + attr_reader :name, :id, :level, :experience + + def initialize(id, level, experience, multiplier) + @id = id + @name = name_of(:item, id) + @level = level + @experience = experience + @multiplier = multiplier + end + + def equals(other) + get_class == other.get_class && id == other.id + end + + def multiplier(level) + @multiplier.call(level) + end + +end + +# Appends a rune to the list. +def rune(name, hash) + unless hash.has_keys?(:altar, :id, :level, :reward) + fail "#{name} is missing one of id, altar, level, or reward." + end + + id, altar, level, experience = hash[:id], hash[:altar], hash[:level], hash[:reward] + bonus = hash[:bonus] || ->(_) { 1 } + + RUNES[altar] = Rune.new(id, level, experience, bonus) +end + +rune :air, altar: 2478, id: 556, level: 1, reward: 5, bonus: ->(level) { (level / 11).floor + 1 } +rune :mind, altar: 2479, id: 558, level: 1, reward: 5.5, bonus: ->(level) { (level / 14).floor + 1 } +rune :water, altar: 2480, id: 555, level: 5, reward: 6, bonus: ->(level) { (level / 19).floor + 1 } +rune :earth, altar: 2481, id: 557, level: 9, reward: 6.5, + bonus: ->(level) { (level / 26).floor + 1 } +rune :fire, altar: 2482, id: 554, level: 14, reward: 7, bonus: ->(level) { (level / 35).floor + 1 } +rune :body, altar: 2483, id: 559, level: 20, reward: 7.5, + bonus: ->(level) { (level / 46).floor + 1 } +rune :cosmic, altar: 2484, id: 564, level: 27, reward: 8, bonus: ->(level) { level >= 59 ? 2 : 1 } +rune :chaos, altar: 2487, id: 562, level: 35, reward: 8.5, bonus: ->(level) { level >= 74 ? 2 : 1 } +rune :nature, altar: 2486, id: 561, level: 44, reward: 9, bonus: ->(level) { level >= 91 ? 2 : 1 } +rune :law, altar: 2485, id: 563, level: 54, reward: 9.5 +rune :death, altar: 2488, id: 560, level: 65, reward: 10 diff --git a/game/data/plugins/skill/runecraft/runecraft.rb b/game/data/plugins/skill/runecraft/runecraft.rb new file mode 100644 index 000000000..bce1b0594 --- /dev/null +++ b/game/data/plugins/skill/runecraft/runecraft.rb @@ -0,0 +1,58 @@ +require 'java' + +java_import 'org.apollo.game.action.DistancedAction' +java_import 'org.apollo.game.model.Animation' +java_import 'org.apollo.game.model.Graphic' +java_import 'org.apollo.game.model.entity.Skill' + +RUNECRAFTING_ANIMATION = Animation.new(791) +RUNECRAFTING_GRAPHIC = Graphic.new(186, 0, 100) + +RUNE_ESSENCE_ID = 1436 + +# An action when the player crafts a rune. +class RunecraftingAction < DistancedAction + attr_reader :player, :rune + + def initialize(player, rune, object_position) + super(1, true, player, object_position, 3) + @player = player + @rune = rune + @position = object_position + @executions = 0 + end + + def executeAction + runecrafting_level = @player.skill_set.get_skill(Skill::RUNECRAFT).current_level + + if runecrafting_level < @rune.level + @player.send_message("You need a runecrafting level of #{@rune.level} to craft this rune.") + stop + elsif !@player.inventory.contains(RUNE_ESSENCE_ID) + @player.send_message('You need rune essence to craft runes.') + stop + elsif @executions == 0 + @player.turn_to(@position) + @player.play_animation(RUNECRAFTING_ANIMATION) + @player.play_graphic(RUNECRAFTING_GRAPHIC) + @executions += 1 + elsif @executions == 1 + inventory = @player.inventory + removed = inventory.remove(RUNE_ESSENCE_ID, inventory.get_amount(RUNE_ESSENCE_ID)) + + added = removed * @rune.multiplier(runecrafting_level) + inventory.add(@rune.id, added) + + name = added > 1 ? 'some ' + @rune.name + 's' : 'an ' + @rune.name + @player.send_message("You craft the rune essence into #{name}.") + + @player.skill_set.add_experience(Skill::RUNECRAFT, removed * @rune.experience) + stop + end + end + + def equals(other) + get_class == other.get_class && @player == other.player && @rune == other.rune + end + +end diff --git a/game/data/plugins/skill/runecraft/talisman.rb b/game/data/plugins/skill/runecraft/talisman.rb new file mode 100644 index 000000000..16b6c6e8f --- /dev/null +++ b/game/data/plugins/skill/runecraft/talisman.rb @@ -0,0 +1,54 @@ +require 'java' + +java_import 'org.apollo.game.model.Position' + +# The list of talismans. +TALISMANS = {} + +# A talisman that will indicate a direction when activated. +class Talisman + + def initialize(entrance_altar_position) + @locate_position = entrance_altar_position + end + + def get_message(position) + return 'Your talisman glows brightly.' if position.is_within_distance(@locate_position, 10) + + direction = (position.y > @locate_position.y ? 'North' : 'South') + '-' + direction += (position.x > @locate_position.x ? 'East' : 'West') + + "The talisman pulls toward the #{direction}." + end + +end + +# Intercepts the item option message. +on :message, :fourth_item_option do |player, message| + talisman = TALISMANS[message.id] + + unless talisman.nil? + player.send_message(talisman.get_message(player.position)) + message.terminate + end +end + +# Appends a talisman to the list. +def talisman(name, hash) + fail 'Hash must contain an id and an altar position.' unless hash.has_keys?(:id, :altar) + id, altar_position = hash[:id], Position.new(*hash[:altar]) + + TALISMANS[id] = Talisman.new(altar_position) +end + +talisman :air_talisman, id: 1438, altar: [2985, 3292] +talisman :earth_talisman, id: 1440, altar: [3306, 3474] +talisman :fire_talisman, id: 1442, altar: [3313, 3255] +talisman :water_talisman, id: 1444, altar: [3185, 3165] +talisman :body_talisman, id: 1446, altar: [3053, 3445] +talisman :mind_talisman, id: 1448, altar: [2982, 3514] +talisman :chaos_talisman, id: 1452, altar: [3059, 3590] +talisman :cosmic_talisman, id: 1454, altar: [2408, 4377] +talisman :death_talisman, id: 1456, altar: [0, 0] +talisman :law_talisman, id: 1458, altar: [2858, 3381] +talisman :nature_talisman, id: 1462, altar: [2869, 3019] diff --git a/game/data/plugins/skill/runecraft/tiara.rb b/game/data/plugins/skill/runecraft/tiara.rb new file mode 100644 index 000000000..06701f262 --- /dev/null +++ b/game/data/plugins/skill/runecraft/tiara.rb @@ -0,0 +1,167 @@ +require 'java' + +java_import 'org.apollo.game.message.impl.ConfigMessage' +java_import 'org.apollo.game.model.entity.EquipmentConstants' +java_import 'org.apollo.game.action.DistancedAction' + +# The hash of tiaras. +TIARAS_BY_ALTAR = {} +TIARAS_BY_ID = {} +TIARAS_BY_TALISMAN = {} + +# A tiara will make an altar accessible with a single click. +class Tiara + attr_reader :altar, :bitshift, :tiara_id, :experience, :talisman + + def initialize(tiara_id, altar, talisman, bitshift, experience) + @tiara_id = tiara_id + @name = name_of(:item, tiara_id) + @altar = altar + @talisman = talisman + @bitshift = bitshift + @experience = experience + end + + # Sends a config message to change the altar object. + def send_config(player) + player.send(ConfigMessage.new(CHANGE_ALTAR_OBJECT_CONFIG, 1 << @bitshift)) + end + +end + +private + +# The id of the altar change config. +CHANGE_ALTAR_OBJECT_CONFIG = 491 + +# The id of the blank tiara. +TIARA_ITEM_ID = 5525 + +# Sends an empty altar config. +def send_empty_config(player) + player.send(ConfigMessage.new(CHANGE_ALTAR_OBJECT_CONFIG, 0)) +end + +# Sets the correct config upon login, if the player is wearing a tiara. +on :login do |_event, player| + hat = player.equipment.get(EquipmentConstants::HAT) + + unless hat.nil? + tiara = TIARAS_BY_ID[hat] + tiara.nil? ? send_empty_config(player) : tiara.send_config + end +end + +# Intercepts the SecondObjectAction message to support left-click access to the altar when wielding +# the correct tiara. +on :message, :second_object_action do |player, message| + object_id = message.id + tiara = TIARAS_BY_ALTAR[object_id] + next if tiara.nil? + + hat = player.equipment.get(EquipmentConstants::HAT) + + if !hat.nil? && hat.id == tiara.tiara_id + altar = ENTRANCE_ALTARS[tiara.altar] + message.terminate + + unless altar.nil? + player.start_action(TeleportAction.new(player, message.position, 2, altar.entrance_position)) + end + end +end + +# Intercepts the SecondItemAction message to allow for config sending. +on :message, :second_item_option do |player, message| + tiara = TIARAS_BY_ID[message.id] + + unless tiara.nil? + tiara.send_config(player) + message.terminate + end +end + +# Intercepts the FirstItemAction message to allow for config sending. +on :message, :first_item_action do |player, message| + tiara = TIARAS_BY_ID[message.id] + + unless tiara.nil? + send_empty_config(player) + message.terminate + end +end + +# Intercepts the ItemOnObject message to create the tiara. +on :message, :item_on_object do |player, message| + tiara, altar = TIARAS_BY_TALISMAN[message.id], CRAFTING_ALTARS[message.object_id] + return if tiara.nil? || altar.nil? + + player.start_action(CreateTiaraAction.new(player, message.position, tiara, altar)) + message.terminate +end + +# An action lets the player create a tiara when it comes within the specified distance of a +# specified position. +# noinspection JRubyImplementInterfaceInspection +class CreateTiaraAction < DistancedAction + + # Creates the CreateTiaraAction. + def initialize(player, position, tiara, altar) + super(0, true, player, position, 2) + @player = player + @tiara = tiara + @altar = altar + end + + def execute_action + inventory = @player.inventory + + if inventory.contains_all(TIARA_ITEM_ID, @tiara.talisman) + if @tiara.altar == @altar.entrance_altar + inventory.remove(@tiara.talisman, TIARA_ITEM_ID) + inventory.add(@tiara.tiara_id) + + @player.skill_set.add_experience(RUNECRAFT_SKILL_ID, @tiara.experience) + @player.play_animation(RUNECRAFTING_ANIMATION) + @player.play_graphic(RUNECRAFTING_GRAPHIC) + else + @player.send_message('You can\'t use that talisman on this altar.') + end + else + @player.send_message('You need to have a talisman and blank tiara to enchant a tiara.') + end + + stop + end + + def equals(other) + get_class == other.get_class && @player == other.player && @tiara == other.tiara + end + +end + +# Appends a tiara to the list. +def tiara(_name, hash) + unless hash.has_keys?(:altar, :bitshift, :experience, :talisman, :tiara_id) + fail 'Hash must contain a tiara id, altar id, talisman id, a bitshift number, and experience.' + end + + tiara_id, altar, talisman = hash[:tiara_id], hash[:altar], hash[:talisman] + bitshift, experience = hash[:bitshift], hash[:experience] + + tiara = Tiara.new(tiara_id, altar, talisman, bitshift, experience) + TIARAS_BY_TALISMAN[talisman] = TIARAS_BY_ID[tiara_id] = TIARAS_BY_ALTAR[altar] = tiara +end + +tiara :air_tiara, tiara_id: 5527, altar: 2452, talisman: 1438, bitshift: 0, experience: 25 +tiara :mind_tiara, tiara_id: 5529, altar: 2453, talisman: 1448, bitshift: 1, experience: 27.5 +tiara :water_tiara, tiara_id: 5531, altar: 2454, talisman: 1444, bitshift: 2, experience: 30 +tiara :body_tiara, tiara_id: 5533, altar: 2457, talisman: 1446, bitshift: 5, experience: 37.5 +tiara :earth_tiara, tiara_id: 5535, altar: 2455, talisman: 1440, bitshift: 3, experience: 32.5 +tiara :fire_tiara, tiara_id: 5537, altar: 2456, talisman: 1442, bitshift: 4, experience: 35 +tiara :cosmic_tiara, tiara_id: 5539, altar: 2458, talisman: 1454, bitshift: 6, experience: 40 +tiara :nature_tiara, tiara_id: 5541, altar: 2460, talisman: 1462, bitshift: 8, experience: 45 +tiara :chaos_tiara, tiara_id: 5543, altar: 2461, talisman: 1452, bitshift: 9, experience: 42.5 +tiara :law_tiara, tiara_id: 5545, altar: 2459, talisman: 1458, bitshift: 7, experience: 47.5 +tiara :death_tiara, tiara_id: 5548, altar: 2462, talisman: 1456, bitshift: 10, experience: 50 +# TODO: there are 2 other altars, which probably just aren't spawned on the map diff --git a/game/data/plugins/util/command.rb b/game/data/plugins/util/command.rb new file mode 100644 index 000000000..ad20d0681 --- /dev/null +++ b/game/data/plugins/util/command.rb @@ -0,0 +1,44 @@ +require 'java' + +java_import 'org.apollo.cache.def.ItemDefinition' +java_import 'org.apollo.cache.def.NpcDefinition' +java_import 'org.apollo.cache.def.ObjectDefinition' + +# Checks whether the amount of arguments provided is correct, sending the player the specified +# message if not. +def valid_arg_length(args, length, player, message) + valid = length.is_a?(Range) ? length.include?(args.length) : length == args.length + + player.send_message(message) unless valid + valid +end + +# Returns the name of the Object, Npc, or Item with the specified id. +def name_of(type, id) + types = [:object, :item, :npc] + unless types.include?(type) + fail "Invalid type of #{type} specified, must be one of #{types}" + end + + Kernel.const_get("#{type.capitalize}Definition").lookup(id).name.to_s +end + +# Monkey-patches Hash to add a has_keys? method. +class Hash + + def has_keys?(*keys) + keys.all? { |key| self.key?(key) } + end + +end + +# Monkey-patches Player to add a level? method. +class Player + + # Returns whether or not the player's current level is greater than or equal to the specified + # level. + def level?(skill, level) + skill_set.get_skill(skill).current_level >= level + end + +end diff --git a/game/data/plugins/util/name_lookup.rb b/game/data/plugins/util/name_lookup.rb new file mode 100644 index 000000000..c966a6d60 --- /dev/null +++ b/game/data/plugins/util/name_lookup.rb @@ -0,0 +1,50 @@ +require 'java' + +# Looks up the id of the npc with the specified name. +def lookup_npc(name) + lookup_entity(:npc, name) +end + +# Looks up the id of the item with the specified name. +def lookup_item(name) + lookup_entity(:item, name) +end + +# Looks up the id of the object with the specified name. +def lookup_object(name) + lookup_entity(:object, name) +end + +# Looks up the id of an entity of the specified type (either :npc, :item, or :object) +def lookup_entity(type, name) + type = type.to_s + name = name.to_s.gsub('_', ' ') + + cached = NAME_CACHE[type + name] + return cached unless cached.nil? + + id = name[name.rindex(' ') + 1, name.length - 1].to_i if name.include?(' ') + id = find_entities(type, name, 1).first if id.nil? || id.zero? + + fail "The #{type} called #{name} could not be identified." if id.nil? + + NAME_CACHE[type + name] = id + id +end + +# Finds entities with the specified type (e.g. npc) and name, returning possible ids as an array. +def find_entities(type, name, limit = 5) + ids = [] + name.downcase! + + Kernel.const_get("#{type.capitalize}Definition").definitions.each do |definition| + break if (ids.length == limit) + ids << definition.id.to_i if definition.name.to_s.downcase == name + end + + ids +end + +private + +NAME_CACHE = {} # Primitive, caching all may not be desirable. diff --git a/game/data/plugins/util/plugin.xml b/game/data/plugins/util/plugin.xml new file mode 100644 index 000000000..bc4b98154 --- /dev/null +++ b/game/data/plugins/util/plugin.xml @@ -0,0 +1,15 @@ + + + util + 1 + Util + Adds utility methods for plugins. + + Major + + + + + + + diff --git a/game/plugin/emote-tab/src/EmoteTab.plugin.kts b/game/plugin/emote-tab/src/EmoteTab.plugin.kts index ec8029187..5f71fc51e 100644 --- a/game/plugin/emote-tab/src/EmoteTab.plugin.kts +++ b/game/plugin/emote-tab/src/EmoteTab.plugin.kts @@ -1,6 +1,6 @@ -import org.apollo.game.message.impl.decode.IfActionMessage +import org.apollo.game.message.impl.decode.ButtonMessage -on { IfActionMessage::class } +on { ButtonMessage::class } .where { componentId in Emote.MAP } .then { player -> player.playAnimation(Emote.fromButton(componentId)!!.animation) diff --git a/game/plugin/logout/test/LogoutTests.kt b/game/plugin/logout/test/LogoutTests.kt index e238c8133..8862d96b1 100644 --- a/game/plugin/logout/test/LogoutTests.kt +++ b/game/plugin/logout/test/LogoutTests.kt @@ -1,5 +1,5 @@ import io.mockk.verify -import org.apollo.game.message.impl.decode.IfActionMessage +import org.apollo.game.message.impl.decode.ButtonMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.api.annotations.TestMock @@ -18,7 +18,7 @@ class LogoutTests { @Test fun `The player should be logged out when they click the logout button`() { - player.send(IfActionMessage(LOGOUT_BUTTON_ID, 0, 0, 0, 0)) + player.send(ButtonMessage(LOGOUT_BUTTON_ID, 0, 0, 0, 0)) verify { player.logout() } } diff --git a/game/plugin/run/src/run.plugin.kts b/game/plugin/run/src/run.plugin.kts index b856ccd8b..5e6e8388e 100644 --- a/game/plugin/run/src/run.plugin.kts +++ b/game/plugin/run/src/run.plugin.kts @@ -1,9 +1,9 @@ -import org.apollo.game.message.impl.decode.IfActionMessage +import org.apollo.game.message.impl.decode.ButtonMessage val WALK_BUTTON_ID = 152 val RUN_BUTTON_ID = 153 -on { IfActionMessage::class } +on { ButtonMessage::class } .where { componentId == WALK_BUTTON_ID || componentId == RUN_BUTTON_ID } .then { it.toggleRunning() diff --git a/game/plugin/skills/prayer/src/Prayer.plugin.kts b/game/plugin/skills/prayer/src/Prayer.plugin.kts index 1fcfdef0e..3d83976a4 100644 --- a/game/plugin/skills/prayer/src/Prayer.plugin.kts +++ b/game/plugin/skills/prayer/src/Prayer.plugin.kts @@ -1,6 +1,6 @@ import Bone.Companion.isBone import Prayer.Companion.isPrayerButton -import org.apollo.game.message.impl.decode.IfActionMessage +import org.apollo.game.message.impl.decode.ButtonMessage import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.model.event.impl.LogoutEvent import org.apollo.game.plugin.api.prayer @@ -11,7 +11,7 @@ on_player_event { LogoutEvent::class } playerPrayers.removeAll(it) } -on { IfActionMessage::class } +on { ButtonMessage::class } .where { componentId.isPrayerButton() } .then { player -> val prayer = Prayer.forButton(componentId)!! diff --git a/game/plugin/skills/woodcutting/build.gradle b/game/plugin/skills/woodcutting/build.gradle index 14387cb16..f849bad10 100644 --- a/game/plugin/skills/woodcutting/build.gradle +++ b/game/plugin/skills/woodcutting/build.gradle @@ -5,7 +5,6 @@ dependencies { implementation project(':cache') implementation project(':net') implementation project(':util') - implementation project(':game:plugin:entity:pathing') implementation project(':game:plugin:entity:actions') implementation project(':game:plugin:api') testImplementation project(':game:plugin-testing') diff --git a/game/src/main/java/org/apollo/Server.java b/game/src/main/java/org/apollo/Server.java index cf9af3a1a..017ed88a6 100644 --- a/game/src/main/java/org/apollo/Server.java +++ b/game/src/main/java/org/apollo/Server.java @@ -1,5 +1,16 @@ package org.apollo; +import java.io.IOException; +import java.net.BindException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.LogManager; +import java.util.logging.Logger; + import com.google.common.base.Stopwatch; import com.google.common.collect.Sets; import io.netty.bootstrap.ServerBootstrap; @@ -20,17 +31,6 @@ import org.apollo.net.ServiceChannelInitializer; import org.apollo.net.release.Release; -import java.io.IOException; -import java.net.BindException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.LogManager; -import java.util.logging.Logger; - /** * The core class of the Apollo server. * diff --git a/game/src/main/java/org/apollo/ServiceManager.java b/game/src/main/java/org/apollo/ServiceManager.java index a329806f1..539fb60d6 100644 --- a/game/src/main/java/org/apollo/ServiceManager.java +++ b/game/src/main/java/org/apollo/ServiceManager.java @@ -1,12 +1,12 @@ package org.apollo; +import java.util.logging.Logger; + import org.apollo.game.model.World; import org.apollo.game.service.GameService; import org.apollo.game.service.LoginService; import org.apollo.game.service.UpdateService; -import java.util.logging.Logger; - /** * A class which manages {@link Service}s. * diff --git a/game/src/main/java/org/apollo/game/GamePulseHandler.java b/game/src/main/java/org/apollo/game/GamePulseHandler.java index da1ed1ec3..fc53f6c51 100644 --- a/game/src/main/java/org/apollo/game/GamePulseHandler.java +++ b/game/src/main/java/org/apollo/game/GamePulseHandler.java @@ -1,10 +1,10 @@ package org.apollo.game; -import org.apollo.game.service.GameService; - import java.util.logging.Level; import java.util.logging.Logger; +import org.apollo.game.service.GameService; + /** * A class which handles the logic for each pulse of the {@link GameService}. * diff --git a/game/src/main/java/org/apollo/game/command/CommandDispatcher.java b/game/src/main/java/org/apollo/game/command/CommandDispatcher.java index 130957c6f..70c76962c 100644 --- a/game/src/main/java/org/apollo/game/command/CommandDispatcher.java +++ b/game/src/main/java/org/apollo/game/command/CommandDispatcher.java @@ -1,11 +1,11 @@ package org.apollo.game.command; -import org.apollo.game.model.entity.Player; - import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.apollo.game.model.entity.Player; + /** * A class that dispatches {@link Command}s to {@link CommandListener}s. * diff --git a/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java b/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java index 4279a847d..d00ef4452 100644 --- a/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java +++ b/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java @@ -1,12 +1,13 @@ package org.apollo.game.command; -import com.google.common.collect.ImmutableSet; -import org.apollo.game.model.entity.Player; - import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.apollo.game.model.entity.Player; + +import com.google.common.collect.ImmutableSet; + /** * Implements a {@code ::credits} command that lists the authors of all plugins used in the server. * diff --git a/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java index df667c85b..f17be7143 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/SynchronousDecoder.java @@ -1,12 +1,16 @@ package org.apollo.game.fs.decoder; -import org.apollo.util.ThreadUtil; - import java.util.Arrays; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.apollo.util.ThreadUtil; + /** * A composite decoder that executes each child in parallel. * diff --git a/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java b/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java index 862e11d44..19a79e71b 100644 --- a/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java +++ b/game/src/main/java/org/apollo/game/io/EquipmentDefinitionParser.java @@ -1,8 +1,13 @@ package org.apollo.game.io; -import org.apollo.cache.def.EquipmentDefinition; +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UncheckedIOException; -import java.io.*; +import org.apollo.cache.def.EquipmentDefinition; /** * A class that parses the {@code data/equipment-[release].dat} file to create an array of {@link diff --git a/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java b/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java index 9ec1241a9..56f711387 100644 --- a/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java +++ b/game/src/main/java/org/apollo/game/io/MessageHandlerChainSetParser.java @@ -1,5 +1,8 @@ package org.apollo.game.io; +import java.io.IOException; +import java.io.InputStream; + import org.apollo.game.message.handler.MessageHandler; import org.apollo.game.message.handler.MessageHandlerChain; import org.apollo.game.message.handler.MessageHandlerChainSet; @@ -9,9 +12,6 @@ import org.apollo.util.xml.XmlParser; import org.xml.sax.SAXException; -import java.io.IOException; -import java.io.InputStream; - /** * A class that parses the {@code messages.xml} file to produce {@link MessageHandlerChainSet}s. * diff --git a/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java b/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java index 26626a8dc..d7c58121e 100644 --- a/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java +++ b/game/src/main/java/org/apollo/game/io/PluginMetaDataParser.java @@ -1,15 +1,15 @@ package org.apollo.game.io; -import org.apollo.game.plugin.PluginMetaData; -import org.apollo.util.xml.XmlNode; -import org.apollo.util.xml.XmlParser; -import org.xml.sax.SAXException; - import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Objects; +import org.apollo.game.plugin.PluginMetaData; +import org.apollo.util.xml.XmlNode; +import org.apollo.util.xml.XmlParser; +import org.xml.sax.SAXException; + /** * A class that parses {@code plugin.xml} files into {@link PluginMetaData} objects. * diff --git a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java index e42899f15..b66797191 100644 --- a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java +++ b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java @@ -1,6 +1,21 @@ package org.apollo.game.io.player; -import com.lambdaworks.crypto.SCryptUtil; +import java.io.BufferedInputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + import org.apollo.game.model.Appearance; import org.apollo.game.model.Item; import org.apollo.game.model.Position; @@ -8,20 +23,25 @@ import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.Skill; import org.apollo.game.model.entity.SkillSet; -import org.apollo.game.model.entity.attr.*; -import org.apollo.game.model.entity.setting.*; +import org.apollo.game.model.entity.attr.Attribute; +import org.apollo.game.model.entity.attr.AttributeMap; +import org.apollo.game.model.entity.attr.AttributePersistence; +import org.apollo.game.model.entity.attr.AttributeType; +import org.apollo.game.model.entity.attr.BooleanAttribute; +import org.apollo.game.model.entity.attr.NumericalAttribute; +import org.apollo.game.model.entity.attr.StringAttribute; +import org.apollo.game.model.entity.setting.Gender; +import org.apollo.game.model.entity.setting.MembershipStatus; +import org.apollo.game.model.entity.setting.PrivacyState; +import org.apollo.game.model.entity.setting.PrivilegeLevel; +import org.apollo.game.model.entity.setting.ScreenBrightness; import org.apollo.game.model.inv.Inventory; import org.apollo.net.codec.login.LoginConstants; import org.apollo.util.NameUtil; import org.apollo.util.StreamUtil; import org.apollo.util.security.PlayerCredentials; -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.Map.Entry; +import com.lambdaworks.crypto.SCryptUtil; /** * A {@link PlayerSerializer} implementation that uses a binary file to store player data. diff --git a/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java b/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java index 003115510..eb763bd38 100644 --- a/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java +++ b/game/src/main/java/org/apollo/game/io/player/PlayerLoaderResponse.java @@ -1,10 +1,11 @@ package org.apollo.game.io.player; -import com.google.common.base.Preconditions; +import java.util.Optional; + import org.apollo.game.model.entity.Player; import org.apollo.net.codec.login.LoginConstants; -import java.util.Optional; +import com.google.common.base.Preconditions; /** * A response for the {@link PlayerSerializer#loadPlayer} call. diff --git a/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java b/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java index 1101fabe1..6513d9ede 100644 --- a/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java +++ b/game/src/main/java/org/apollo/game/login/PlayerLoaderWorker.java @@ -1,14 +1,14 @@ package org.apollo.game.login; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apollo.game.io.player.PlayerLoaderResponse; import org.apollo.game.io.player.PlayerSerializer; import org.apollo.game.session.LoginSession; import org.apollo.net.codec.login.LoginConstants; import org.apollo.net.codec.login.LoginRequest; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * A class which processes a single login request. * diff --git a/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java b/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java index c1ea211a3..6590566c7 100644 --- a/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java +++ b/game/src/main/java/org/apollo/game/login/PlayerSaverWorker.java @@ -1,12 +1,12 @@ package org.apollo.game.login; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apollo.game.io.player.PlayerSerializer; import org.apollo.game.model.entity.Player; import org.apollo.game.session.GameSession; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * A class which processes a single save request. * diff --git a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java index a325f434b..689161b07 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java @@ -1,20 +1,20 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; /** - * A {@link MessageHandler} that responds to {@link IfActionMessage}s for withdrawing items as notes. + * A {@link MessageHandler} that responds to {@link ButtonMessage}s for withdrawing items as notes. * * @author Graham */ -public final class BankButtonMessageHandler extends MessageHandler { +public final class BankButtonMessageHandler extends MessageHandler { /** * Creates the BankButtonMessageHandler. * - * @param world The {@link World} the {@link IfActionMessage} occurred in. + * @param world The {@link World} the {@link ButtonMessage} occurred in. */ public BankButtonMessageHandler(World world) { super(world); @@ -31,7 +31,7 @@ public BankButtonMessageHandler(World world) { private static final int WITHDRAW_AS_NOTE = 5386; @Override - public void handle(Player player, IfActionMessage message) { + public void handle(Player player, ButtonMessage message) { if (message.getComponentId() == WITHDRAW_AS_ITEM) { player.setWithdrawingNotes(false); } else if (message.getComponentId() == WITHDRAW_AS_NOTE) { diff --git a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java index a851fc470..6162b383f 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java @@ -52,11 +52,9 @@ public BankMessageHandler(World world) { @Override public void handle(Player player, ItemActionMessage message) { if (player.getInterfaceSet().contains(BankConstants.WINDOW_ID)) { - //if (message.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) { deposit(player, message); } else if (message.getInterfaceId() == BankConstants.INVENTORY_INTERFACE) { withdraw(player, message); - // } } } diff --git a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java index e882e12de..01f01f0cc 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.game.model.inter.ServerInterfaceType; @@ -11,19 +11,19 @@ * * @author Chris Fletcher */ -public final class DialogueButtonHandler extends MessageHandler { +public final class DialogueButtonHandler extends MessageHandler { /** * Creates the DialogueButtonHandler. * - * @param world The {@link World} the {@link IfActionMessage} occurred in. + * @param world The {@link World} the {@link ButtonMessage} occurred in. */ public DialogueButtonHandler(World world) { super(world); } @Override - public void handle(Player player, IfActionMessage message) { + public void handle(Player player, ButtonMessage message) { if (player.getInterfaceSet().contains(ServerInterfaceType.DIALOGUE)) { boolean terminate = player.getInterfaceSet().buttonClicked(message.getComponentId()); diff --git a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java index d38395f8a..b82178b1b 100644 --- a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java +++ b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChain.java @@ -1,11 +1,12 @@ package org.apollo.game.message.handler; -import com.google.common.base.MoreObjects; +import java.util.ArrayList; +import java.util.List; + import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; -import java.util.ArrayList; -import java.util.List; +import com.google.common.base.MoreObjects; /** * A chain of {@link MessageHandler}s diff --git a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java index fa02222ee..11c466e12 100644 --- a/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java +++ b/game/src/main/java/org/apollo/game/message/handler/MessageHandlerChainSet.java @@ -1,13 +1,13 @@ package org.apollo.game.message.handler; -import org.apollo.game.model.entity.Player; -import org.apollo.net.message.Message; - import java.util.ArrayDeque; import java.util.Deque; import java.util.HashMap; import java.util.Map; +import org.apollo.game.model.entity.Player; +import org.apollo.net.message.Message; + /** * A group of {@link MessageHandlerChain}s classified by the {@link Message} type. * diff --git a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java index 1780b469e..546ff58d9 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java @@ -1,5 +1,8 @@ package org.apollo.game.message.handler; +import java.util.List; +import java.util.Set; + import org.apollo.cache.def.ObjectDefinition; import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; @@ -9,9 +12,6 @@ import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.obj.GameObject; -import java.util.List; -import java.util.Set; - /** * A verification {@link MessageHandler} for the {@link ObjectActionMessage}. * diff --git a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java index 49f62426a..c38643e66 100644 --- a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -13,19 +13,19 @@ * @author Graham * @author Major */ -public final class RemoveEquippedItemHandler extends MessageHandler { +public final class RemoveEquippedItemHandler extends MessageHandler { /** * Creates the RemoveEquippedItemHandler. * - * @param world The {@link World} the {@link IfActionMessage} occurred in. + * @param world The {@link World} the {@link ButtonMessage} occurred in. */ public RemoveEquippedItemHandler(World world) { super(world); } @Override - public void handle(Player player, IfActionMessage message) { + public void handle(Player player, ButtonMessage message) { if (message.getOption() == 1 && message.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { Inventory inventory = player.getInventory(); diff --git a/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java b/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java index 755c0450e..8a95ab16c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/DialogueContinueMessage.java @@ -6,7 +6,7 @@ * A {@link Message} sent by the client when the player clicks the "Click here to continue" button on a dialogue * interface. * - * @author Khaled Abdeljaber + * @author Chris Fletcher */ public final class DialogueContinueMessage extends Message { diff --git a/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java index 4715ac061..4a6f7ccb0 100644 --- a/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/DisplayTabInterfaceMessage.java @@ -5,7 +5,7 @@ /** * A {@link Message} sent to the client to change the currently displayed tab interface. * - * @author Khaled Abdeljaber + * @author Chris Fletcher */ public final class DisplayTabInterfaceMessage extends Message { diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ButtonMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ButtonMessage.java index a07e3889d..6e46e9746 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/IfActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ButtonMessage.java @@ -7,7 +7,7 @@ * * @author Khaled Abdeljaber */ -public class IfActionMessage extends Message { +public class ButtonMessage extends Message { /** * The option that was pressed. @@ -43,7 +43,7 @@ public class IfActionMessage extends Message { * @param slot the slot * @param itemId the item id */ - public IfActionMessage(int option, int interfaceId, int componentId, int slot, int itemId) { + public ButtonMessage(int option, int interfaceId, int componentId, int slot, int itemId) { this.option = option; this.interfaceId = interfaceId; this.componentId = componentId; diff --git a/game/src/main/java/org/apollo/game/model/Appearance.java b/game/src/main/java/org/apollo/game/model/Appearance.java index 7069b37b7..12febc757 100644 --- a/game/src/main/java/org/apollo/game/model/Appearance.java +++ b/game/src/main/java/org/apollo/game/model/Appearance.java @@ -1,8 +1,9 @@ package org.apollo.game.model; -import com.google.common.base.Preconditions; import org.apollo.game.model.entity.setting.Gender; +import com.google.common.base.Preconditions; + /** * Represents the appearance of a player. * diff --git a/game/src/main/java/org/apollo/game/model/Item.java b/game/src/main/java/org/apollo/game/model/Item.java index eb972b350..22e0661b5 100644 --- a/game/src/main/java/org/apollo/game/model/Item.java +++ b/game/src/main/java/org/apollo/game/model/Item.java @@ -1,8 +1,9 @@ package org.apollo.game.model; +import org.apollo.cache.def.ItemDefinition; + import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import org.apollo.cache.def.ItemDefinition; /** * Represents a single item. diff --git a/game/src/main/java/org/apollo/game/model/Position.java b/game/src/main/java/org/apollo/game/model/Position.java index 58aede0cb..1ffeee8f7 100644 --- a/game/src/main/java/org/apollo/game/model/Position.java +++ b/game/src/main/java/org/apollo/game/model/Position.java @@ -1,10 +1,11 @@ package org.apollo.game.model; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionCoordinates; +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + /** * Represents a position in the world. * diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index ac8cd9b42..c56d61dee 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -1,5 +1,8 @@ package org.apollo.game.model; +import java.util.*; +import java.util.logging.Logger; + import com.google.common.base.Preconditions; import org.apollo.Service; import org.apollo.cache.Cache; @@ -19,7 +22,11 @@ import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.game.model.area.collision.CollisionUpdateListener; -import org.apollo.game.model.entity.*; +import org.apollo.game.model.entity.Entity; +import org.apollo.game.model.entity.EntityType; +import org.apollo.game.model.entity.MobRepository; +import org.apollo.game.model.entity.Npc; +import org.apollo.game.model.entity.Player; import org.apollo.game.model.event.Event; import org.apollo.game.model.event.EventListener; import org.apollo.game.model.event.EventListenerChainSet; @@ -29,9 +36,6 @@ import org.apollo.game.scheduling.impl.NpcMovementTask; import org.apollo.util.NameUtil; -import java.util.*; -import java.util.logging.Logger; - /** * The world class is a singleton which contains objects like the {@link MobRepository} for players and NPCs. It should * only contain things relevant to the in-game world and not classes which deal with I/O and such (these may be better @@ -302,7 +306,7 @@ public void register(Player player) { playerRepository.add(player); players.put(NameUtil.encodeBase37(username), player); - System.out.println("Registered player: " + player + " [count=" + playerRepository.size() + "]"); + logger.finest("Registered player: " + player + " [count=" + playerRepository.size() + "]"); } /** @@ -362,7 +366,7 @@ public void unregister(final Player player) { region.removeEntity(player); playerRepository.remove(player); - System.out.println("Unregistered player: " + player + " [count=" + playerRepository.size() + "]"); + logger.finest("Unregistered player: " + player + " [count=" + playerRepository.size() + "]"); } /** diff --git a/game/src/main/java/org/apollo/game/model/area/Region.java b/game/src/main/java/org/apollo/game/model/area/Region.java index 56ffc148b..a59c14f8c 100644 --- a/game/src/main/java/org/apollo/game/model/area/Region.java +++ b/game/src/main/java/org/apollo/game/model/area/Region.java @@ -13,7 +13,12 @@ import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.obj.DynamicGameObject; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java b/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java index 7e803a88d..61a9b3613 100644 --- a/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java +++ b/game/src/main/java/org/apollo/game/model/area/RegionCoordinates.java @@ -1,8 +1,9 @@ package org.apollo.game.model.area; -import com.google.common.base.MoreObjects; import org.apollo.game.model.Position; +import com.google.common.base.MoreObjects; + /** * An immutable class representing the coordinates of a region, where the coordinates ({@code x, y}) are the top-left of * the region. diff --git a/game/src/main/java/org/apollo/game/model/area/RegionRepository.java b/game/src/main/java/org/apollo/game/model/area/RegionRepository.java index c19b5308e..0df8871d1 100644 --- a/game/src/main/java/org/apollo/game/model/area/RegionRepository.java +++ b/game/src/main/java/org/apollo/game/model/area/RegionRepository.java @@ -1,15 +1,16 @@ package org.apollo.game.model.area; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import org.apollo.cache.map.XteaRepository; -import org.apollo.game.model.Position; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apollo.cache.map.XteaRepository; +import org.apollo.game.model.Position; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; + /** * A repository of {@link Region}s, backed by a {@link HashMap} of {@link RegionCoordinates} that correspond to their * appropriate regions. diff --git a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java index 63c26befe..5ef41a550 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java @@ -1,6 +1,5 @@ package org.apollo.game.model.area.update; -import com.google.common.base.Preconditions; import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.EntityUpdateType; @@ -9,6 +8,8 @@ import org.apollo.game.model.entity.Entity; import org.apollo.net.message.Message; +import com.google.common.base.Preconditions; + /** * An type that is contained in the snapshot of a {@link Region}, which consists of an {@link Entity} being added, * removed, or moved. diff --git a/game/src/main/java/org/apollo/game/model/entity/Mob.java b/game/src/main/java/org/apollo/game/model/entity/Mob.java index 84fda4d5e..4e9b52094 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Mob.java +++ b/game/src/main/java/org/apollo/game/model/entity/Mob.java @@ -1,10 +1,12 @@ package org.apollo.game.model.entity; -import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; -import it.unimi.dsi.fastutil.objects.ObjectSet; import org.apollo.cache.def.NpcDefinition; import org.apollo.game.action.Action; -import org.apollo.game.model.*; +import org.apollo.game.model.Animation; +import org.apollo.game.model.Direction; +import org.apollo.game.model.Graphic; +import org.apollo.game.model.Position; +import org.apollo.game.model.World; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.attr.Attribute; @@ -22,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.HashSet; /** * A living entity in the world, such as a player or npc. @@ -64,7 +68,7 @@ public abstract class Mob extends Entity { /** * This mob's list of local players. */ - private final ObjectSet localPlayers = new ObjectOpenHashSet<>(); + private final Set localPlayers = new HashSet<>(); /** * This mob's set of synchronization blocks. @@ -317,7 +321,7 @@ public final List getLocalNpcList() { * * @return The list. */ - public final ObjectSet getLocalPlayerList() { + public final Set getLocalPlayerList() { return localPlayers; } diff --git a/game/src/main/java/org/apollo/game/model/entity/Npc.java b/game/src/main/java/org/apollo/game/model/entity/Npc.java index 15cdd7980..07556a873 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Npc.java +++ b/game/src/main/java/org/apollo/game/model/entity/Npc.java @@ -1,13 +1,14 @@ package org.apollo.game.model.entity; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; +import java.util.Optional; + import org.apollo.cache.def.NpcDefinition; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.sync.block.SynchronizationBlock; -import java.util.Optional; +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; /** * A {@link Mob} that is not controlled by a player. diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 1b7b5811d..66808574c 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -1,5 +1,13 @@ package org.apollo.game.model.entity; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import org.apollo.game.message.impl.SendFriendMessage; @@ -11,7 +19,12 @@ import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.WorldConstants; -import org.apollo.game.model.entity.attr.*; +import org.apollo.game.model.entity.attr.Attribute; +import org.apollo.game.model.entity.attr.AttributeDefinition; +import org.apollo.game.model.entity.attr.AttributeMap; +import org.apollo.game.model.entity.attr.AttributePersistence; +import org.apollo.game.model.entity.attr.NumericalAttribute; +import org.apollo.game.model.entity.attr.BooleanAttribute; import org.apollo.game.model.entity.obj.DynamicGameObject; import org.apollo.game.model.entity.setting.MembershipStatus; import org.apollo.game.model.entity.setting.PrivacyState; @@ -19,23 +32,28 @@ import org.apollo.game.model.entity.setting.ScreenBrightness; import org.apollo.game.model.event.impl.LoginEvent; import org.apollo.game.model.event.impl.LogoutEvent; -import org.apollo.game.model.inter.*; +import org.apollo.game.model.inter.InterfaceConstants; +import org.apollo.game.model.inter.InterfaceListener; +import org.apollo.game.model.inter.InterfaceSet; +import org.apollo.game.model.inter.DisplayMode; +import org.apollo.game.model.inter.TopLevelPosition; import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inter.bank.BankInterfaceListener; -import org.apollo.game.model.inv.*; +import org.apollo.game.model.inv.AppearanceInventoryListener; +import org.apollo.game.model.inv.FullInventoryListener; +import org.apollo.game.model.inv.Inventory; import org.apollo.game.model.inv.Inventory.StackMode; +import org.apollo.game.model.inv.InventoryConstants; +import org.apollo.game.model.inv.InventoryListener; +import org.apollo.game.model.inv.SynchronizationInventoryListener; import org.apollo.game.model.skill.LevelUpSkillListener; import org.apollo.game.model.skill.SynchronizationSkillListener; import org.apollo.game.session.GameSession; import org.apollo.game.sync.block.SynchronizationBlock; import org.apollo.net.message.Message; import org.apollo.util.CollectionUtil; -import org.apollo.util.TextUtil; import org.apollo.util.security.PlayerCredentials; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; - /** * A {@link Mob} that a user is controlling. * diff --git a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java index 91495acd6..ac2571643 100644 --- a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java +++ b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java @@ -1,13 +1,14 @@ package org.apollo.game.model.entity; -import com.google.common.base.Preconditions; -import com.google.common.primitives.Ints; -import org.apollo.game.model.skill.SkillListener; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apollo.game.model.skill.SkillListener; + +import com.google.common.base.Preconditions; +import com.google.common.primitives.Ints; + /** * Represents the set of the player's skills. * diff --git a/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java b/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java index 36f51dd25..7db2579d9 100644 --- a/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java +++ b/game/src/main/java/org/apollo/game/model/entity/WalkingQueue.java @@ -5,11 +5,16 @@ import org.apollo.game.model.World; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionRepository; +import org.apollo.game.model.area.collision.CollisionFlag; import org.apollo.game.model.area.collision.CollisionManager; +import org.apollo.game.model.area.collision.CollisionMatrix; import java.util.ArrayDeque; +import java.util.Arrays; import java.util.Deque; import java.util.Queue; +import java.util.logging.Logger; +import java.util.stream.Collectors; /** * A queue of {@link Direction}s which a {@link Mob} will follow. diff --git a/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java b/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java index b9da4176c..c521e7b79 100644 --- a/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java +++ b/game/src/main/java/org/apollo/game/model/entity/attr/AttributeMap.java @@ -1,10 +1,11 @@ package org.apollo.game.model.entity.attr; -import com.google.common.base.Preconditions; - import java.util.HashMap; import java.util.Map; + +import com.google.common.base.Preconditions; + /** * A {@link Map} wrapper used to store {@link Attribute}s and their {@link AttributeDefinition definitions}. * diff --git a/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java b/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java index e2f91fc67..91a071d0c 100644 --- a/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java +++ b/game/src/main/java/org/apollo/game/model/entity/obj/DynamicGameObject.java @@ -1,13 +1,13 @@ package org.apollo.game.model.entity.obj; +import java.util.HashSet; +import java.util.Set; + import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.Player; -import java.util.HashSet; -import java.util.Set; - /** * A {@link GameObject} that is loaded dynamically, usually for specific Players. * diff --git a/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java b/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java index 105b66294..1ceb76897 100644 --- a/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java +++ b/game/src/main/java/org/apollo/game/model/entity/obj/GameObject.java @@ -1,9 +1,8 @@ package org.apollo.game.model.entity.obj; -import com.google.common.base.MoreObjects; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.model.Direction; import org.apollo.game.model.Position; +import org.apollo.game.model.Direction; import org.apollo.game.model.World; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; @@ -12,6 +11,8 @@ import org.apollo.game.model.entity.Entity; import org.apollo.game.model.entity.Player; +import com.google.common.base.MoreObjects; + import static org.apollo.game.model.entity.obj.ObjectType.RECTANGULAR_CORNER; import static org.apollo.game.model.entity.obj.ObjectType.TRIANGULAR_CORNER; diff --git a/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java b/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java index b7606cbb8..2b8482f52 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/AStarPathfindingAlgorithm.java @@ -1,11 +1,18 @@ package org.apollo.game.model.entity.path; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.Set; + import org.apollo.game.model.Direction; import org.apollo.game.model.Position; import org.apollo.game.model.area.collision.CollisionManager; -import java.util.*; - /** * A {@link PathfindingAlgorithm} that utilises the A* algorithm to find a solution. *

diff --git a/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java b/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java index b171c04d2..67ff7d1f8 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/ManhattanHeuristic.java @@ -7,7 +7,7 @@ * * @author Major */ -public final class ManhattanHeuristic extends Heuristic { +final class ManhattanHeuristic extends Heuristic { @Override public int estimate(Position current, Position goal) { diff --git a/game/src/main/java/org/apollo/game/model/entity/path/Node.java b/game/src/main/java/org/apollo/game/model/entity/path/Node.java index 83dfbf321..8be1d9aea 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/Node.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/Node.java @@ -1,11 +1,12 @@ package org.apollo.game.model.entity.path; -import com.google.common.base.MoreObjects; -import org.apollo.game.model.Position; - import java.util.NoSuchElementException; import java.util.Optional; +import org.apollo.game.model.Position; + +import com.google.common.base.MoreObjects; + /** * A Node representing a weighted {@link Position}. * diff --git a/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java b/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java index 6b5041503..dddf426e6 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/PathfindingAlgorithm.java @@ -1,13 +1,17 @@ package org.apollo.game.model.entity.path; -import com.google.common.base.Preconditions; +import java.util.Deque; +import java.util.Optional; + import org.apollo.game.model.Direction; import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.game.model.entity.EntityType; -import java.util.Deque; -import java.util.Optional; +import com.google.common.base.Preconditions; /** * An algorithm used to find a path between two {@link Position}s. diff --git a/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java b/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java index 2ac023e0b..421315f83 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/SimplePathfindingAlgorithm.java @@ -1,13 +1,15 @@ package org.apollo.game.model.entity.path; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Position; -import org.apollo.game.model.area.collision.CollisionManager; - import java.util.ArrayDeque; import java.util.Deque; import java.util.Optional; +import org.apollo.game.model.Direction; +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.RegionRepository; +import org.apollo.game.model.area.collision.CollisionManager; + /** * A very simple pathfinding algorithm that simply walks in the direction of the target until it either reaches it or is * blocked. diff --git a/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java b/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java index 2abb3c3fc..feb49670e 100644 --- a/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java +++ b/game/src/main/java/org/apollo/game/model/event/EventListenerChain.java @@ -1,10 +1,10 @@ package org.apollo.game.model.event; -import com.google.common.base.MoreObjects; - import java.util.ArrayList; import java.util.List; +import com.google.common.base.MoreObjects; + /** * A chain of {@link EventListener}s. * diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java index 765bc613d..aa23aa38d 100644 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java @@ -1,5 +1,9 @@ package org.apollo.game.model.inter; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + import org.apollo.cache.def.EnumDefinition; import org.apollo.game.message.handler.MessageHandlerChain; import org.apollo.game.message.impl.EnterAmountMessage; @@ -10,10 +14,7 @@ import org.apollo.game.model.entity.Player; import org.apollo.game.model.event.impl.CloseInterfacesEvent; import org.apollo.game.model.inter.dialogue.DialogueListener; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; +import org.apollo.game.model.inv.InventoryListener; /** * Represents the set of interfaces the player has open. @@ -221,9 +222,9 @@ public void openTop(DisplayMode mode) { final var oldEnumMap = EnumDefinition.lookup(this.mode.getTopLevelEnum()).getIntValues(); final var newEnumMap = EnumDefinition.lookup(mode.getTopLevelEnum()).getIntValues(); - for (var newComponent : newEnumMap.int2IntEntrySet()) { - int key = newComponent.getIntKey(); - int to = newComponent.getIntValue(); + for (var newComponent : newEnumMap.entrySet()) { + int key = newComponent.getKey(); + int to = newComponent.getValue(); if (to == -1) { continue; } diff --git a/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java b/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java index d1db4cea9..7e8d61fa7 100644 --- a/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java +++ b/game/src/main/java/org/apollo/game/plugin/KotlinPluginEnvironment.java @@ -1,5 +1,11 @@ package org.apollo.game.plugin; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Logger; + import io.github.classgraph.ClassGraph; import io.github.classgraph.ClassInfo; import io.github.classgraph.ClassInfoList; @@ -7,12 +13,6 @@ import org.apollo.game.model.World; import org.apollo.game.plugin.kotlin.KotlinPluginScript; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.logging.Logger; - public class KotlinPluginEnvironment implements PluginEnvironment { private static final Logger logger = Logger.getLogger(KotlinPluginEnvironment.class.getName()); diff --git a/game/src/main/java/org/apollo/game/plugin/PluginManager.java b/game/src/main/java/org/apollo/game/plugin/PluginManager.java index 054f8464f..5471cb697 100644 --- a/game/src/main/java/org/apollo/game/plugin/PluginManager.java +++ b/game/src/main/java/org/apollo/game/plugin/PluginManager.java @@ -1,9 +1,5 @@ package org.apollo.game.plugin; -import org.apollo.game.io.PluginMetaDataParser; -import org.apollo.game.model.World; -import org.xml.sax.SAXException; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -12,6 +8,10 @@ import java.util.function.Function; import java.util.stream.Collectors; +import org.apollo.game.io.PluginMetaDataParser; +import org.apollo.game.model.World; +import org.xml.sax.SAXException; + /** * A class which manages plugins. * diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java index c30361619..ab38bc72b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java @@ -1,21 +1,21 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * @author Khaled Abdeljaber */ -public class FifthIf1ActionMessageDecoder extends MessageDecoder { +public class FifthIf1ActionMessageDecoder extends MessageDecoder { @Override - public IfActionMessage decode(GamePacket packet) { + public ButtonMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int item = (int) reader.getUnsigned(DataType.SHORT); int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.MIDDLE); int slot = (int) reader.getUnsigned(DataType.SHORT); - return new IfActionMessage(5, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + return new ButtonMessage(5, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java index 427b97649..bd72741bb 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java @@ -1,21 +1,21 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * @author Khaled Abdeljaber */ -public class FirstIf1ActionMessageDecoder extends MessageDecoder { +public class FirstIf1ActionMessageDecoder extends MessageDecoder { @Override - public IfActionMessage decode(GamePacket packet) { + public ButtonMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); int item = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new IfActionMessage(1, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + return new ButtonMessage(1, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java index 255cb7de7..e46f5ea72 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java @@ -1,21 +1,21 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * @author Khaled Abdeljaber */ -public class FourthIf1ActionMessageDecoder extends MessageDecoder { +public class FourthIf1ActionMessageDecoder extends MessageDecoder { @Override - public IfActionMessage decode(GamePacket packet) { + public ButtonMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int packedInterface = (int) reader.getUnsigned(DataType.INT); int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); int item = (int) reader.getUnsigned(DataType.SHORT); - return new IfActionMessage(4, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + return new ButtonMessage(4, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java index c66a7f42f..bf5289589 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java @@ -1,21 +1,21 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * @author Khaled Abdeljaber */ -public class SecondIf1ActionMessageDecoder extends MessageDecoder { +public class SecondIf1ActionMessageDecoder extends MessageDecoder { @Override - public IfActionMessage decode(GamePacket packet) { + public ButtonMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); int item = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new IfActionMessage(2, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + return new ButtonMessage(2, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java index 7f97a9777..68206a24b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java @@ -1,21 +1,21 @@ package org.apollo.game.release.r181.decoders.ui.if1; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * @author Khaled Abdeljaber */ -public class ThirdIf1ActionMessageDecoder extends MessageDecoder { +public class ThirdIf1ActionMessageDecoder extends MessageDecoder { @Override - public IfActionMessage decode(GamePacket packet) { + public ButtonMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); int item = (int) reader.getUnsigned(DataType.SHORT); - return new IfActionMessage(3, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + return new ButtonMessage(3, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java index 98fa314e9..f0eee9d1b 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java @@ -1,13 +1,13 @@ package org.apollo.game.release.r181.decoders.ui.if3; -import org.apollo.game.message.impl.decode.IfActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * @author Khaled Abdeljaber */ -public class If3ActionMessageDecoder extends MessageDecoder { +public class If3ActionMessageDecoder extends MessageDecoder { private final int action; @@ -16,13 +16,13 @@ public If3ActionMessageDecoder(int action) { } @Override - public IfActionMessage decode(GamePacket packet) { + public ButtonMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int packedInterface = (int) reader.getUnsigned(DataType.INT); int slot = (int) reader.getUnsigned(DataType.SHORT); int item = (int) reader.getUnsigned(DataType.SHORT); - return new IfActionMessage(action, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + return new ButtonMessage(action, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); } } diff --git a/game/src/main/java/org/apollo/game/scheduling/Scheduler.java b/game/src/main/java/org/apollo/game/scheduling/Scheduler.java index 380af33dd..f81913949 100644 --- a/game/src/main/java/org/apollo/game/scheduling/Scheduler.java +++ b/game/src/main/java/org/apollo/game/scheduling/Scheduler.java @@ -2,7 +2,11 @@ import org.apollo.util.CollectionUtil; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Queue; /** * A class which manages {@link ScheduledTask}s. diff --git a/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java b/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java index 22283a6bb..66342f313 100644 --- a/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java +++ b/game/src/main/java/org/apollo/game/scheduling/impl/NpcMovementTask.java @@ -1,14 +1,21 @@ package org.apollo.game.scheduling.impl; -import com.google.common.base.Preconditions; +import java.util.Comparator; +import java.util.Deque; +import java.util.PriorityQueue; +import java.util.Queue; +import java.util.Random; + import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.game.model.entity.Npc; import org.apollo.game.model.entity.WalkingQueue; import org.apollo.game.model.entity.path.SimplePathfindingAlgorithm; import org.apollo.game.scheduling.ScheduledTask; -import java.util.*; +import com.google.common.base.Preconditions; /** * A {@link ScheduledTask} that causes {@link Npc}s to randomly walk around in their boundary. diff --git a/game/src/main/java/org/apollo/game/service/GameService.java b/game/src/main/java/org/apollo/game/service/GameService.java index 95a9fd6d0..5046519bf 100644 --- a/game/src/main/java/org/apollo/game/service/GameService.java +++ b/game/src/main/java/org/apollo/game/service/GameService.java @@ -1,5 +1,14 @@ package org.apollo.game.service; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + import org.apollo.Service; import org.apollo.game.GameConstants; import org.apollo.game.GamePulseHandler; @@ -19,15 +28,6 @@ import org.apollo.util.xml.XmlParser; import org.xml.sax.SAXException; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - /** * The {@link GameService} class schedules and manages the execution of the {@link GamePulseHandler} class. * diff --git a/game/src/main/java/org/apollo/game/service/LoginService.java b/game/src/main/java/org/apollo/game/service/LoginService.java index 906b6f018..0f7a4053d 100644 --- a/game/src/main/java/org/apollo/game/service/LoginService.java +++ b/game/src/main/java/org/apollo/game/service/LoginService.java @@ -1,5 +1,12 @@ package org.apollo.game.service; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + import org.apollo.Service; import org.apollo.game.io.player.PlayerLoaderResponse; import org.apollo.game.io.player.PlayerSerializer; @@ -17,12 +24,6 @@ import org.apollo.util.xml.XmlParser; import org.xml.sax.SAXException; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - /** * The {@link LoginService} manages {@link LoginRequest}s. * diff --git a/game/src/main/java/org/apollo/game/session/ApolloHandler.java b/game/src/main/java/org/apollo/game/session/ApolloHandler.java index 13adc56fb..7c8629de2 100644 --- a/game/src/main/java/org/apollo/game/session/ApolloHandler.java +++ b/game/src/main/java/org/apollo/game/session/ApolloHandler.java @@ -7,14 +7,16 @@ import io.netty.handler.codec.http.HttpRequest; import io.netty.util.Attribute; import io.netty.util.AttributeKey; +import io.netty.util.ReferenceCountUtil; + +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apollo.ServerContext; import org.apollo.net.codec.handshake.HandshakeConstants; import org.apollo.net.codec.handshake.HandshakeMessage; import org.apollo.net.codec.jaggrab.JagGrabRequest; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * An implementation of {@link ChannelInboundHandlerAdapter} which handles incoming upstream events from Netty. * diff --git a/game/src/main/java/org/apollo/game/session/GameSession.java b/game/src/main/java/org/apollo/game/session/GameSession.java index 3591930f7..e7d3b298f 100644 --- a/game/src/main/java/org/apollo/game/session/GameSession.java +++ b/game/src/main/java/org/apollo/game/session/GameSession.java @@ -3,6 +3,12 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apollo.ServerContext; import org.apollo.game.GameConstants; import org.apollo.game.message.handler.MessageHandlerChainSet; @@ -10,11 +16,6 @@ import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * A game session. * diff --git a/game/src/main/java/org/apollo/game/session/LoginSession.java b/game/src/main/java/org/apollo/game/session/LoginSession.java index 21baee05a..97b844504 100644 --- a/game/src/main/java/org/apollo/game/session/LoginSession.java +++ b/game/src/main/java/org/apollo/game/session/LoginSession.java @@ -2,9 +2,17 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; + +import java.io.IOException; +import java.security.SecureRandom; +import java.util.NoSuchElementException; +import java.util.Optional; + import org.apollo.ServerContext; import org.apollo.game.io.player.PlayerLoaderResponse; +import org.apollo.game.model.World.RegistrationStatus; import org.apollo.game.model.entity.Player; import org.apollo.game.service.GameService; import org.apollo.game.service.LoginService; @@ -18,11 +26,6 @@ import org.apollo.net.release.Release; import org.apollo.util.security.IsaacRandomPair; -import java.io.IOException; -import java.security.SecureRandom; -import java.util.NoSuchElementException; -import java.util.Optional; - /** * A login session. * diff --git a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java index 9ea94eb5f..d14bef5c0 100644 --- a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java @@ -6,7 +6,14 @@ import org.apollo.game.model.entity.Npc; import org.apollo.game.model.entity.Player; import org.apollo.game.service.GameService; -import org.apollo.game.sync.task.*; +import org.apollo.game.sync.task.NpcSynchronizationTask; +import org.apollo.game.sync.task.PhasedSynchronizationTask; +import org.apollo.game.sync.task.PlayerSynchronizationTask; +import org.apollo.game.sync.task.PostNpcSynchronizationTask; +import org.apollo.game.sync.task.PostPlayerSynchronizationTask; +import org.apollo.game.sync.task.PreNpcSynchronizationTask; +import org.apollo.game.sync.task.PrePlayerSynchronizationTask; +import org.apollo.game.sync.task.SynchronizationTask; import org.apollo.util.ThreadUtil; import java.util.Map; diff --git a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java index e35efd601..ec4f38c26 100644 --- a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java @@ -1,16 +1,23 @@ package org.apollo.game.sync; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; import org.apollo.game.model.entity.Player; import org.apollo.game.service.GameService; -import org.apollo.game.sync.task.*; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import org.apollo.game.sync.task.NpcSynchronizationTask; +import org.apollo.game.sync.task.PlayerSynchronizationTask; +import org.apollo.game.sync.task.PostNpcSynchronizationTask; +import org.apollo.game.sync.task.PostPlayerSynchronizationTask; +import org.apollo.game.sync.task.PreNpcSynchronizationTask; +import org.apollo.game.sync.task.PrePlayerSynchronizationTask; +import org.apollo.game.sync.task.SynchronizationTask; /** * An implementation of {@link ClientSynchronizer} which runs in a single thread (the {@link GameService} thread from diff --git a/game/src/main/java/org/apollo/game/sync/block/AnimationBlock.java b/game/src/main/java/org/apollo/game/sync/block/AnimationBlock.java index 0c3310660..4e476acc7 100644 --- a/game/src/main/java/org/apollo/game/sync/block/AnimationBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/AnimationBlock.java @@ -1,7 +1,6 @@ package org.apollo.game.sync.block; import org.apollo.game.model.Animation; -import org.apollo.game.sync.block.SynchronizationBlock; /** * The animation {@link SynchronizationBlock}. Both npcs and players can utilise this block. diff --git a/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java b/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java index a356f0a24..7dd1a9a8f 100644 --- a/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java @@ -2,7 +2,6 @@ import org.apollo.game.model.Appearance; import org.apollo.game.model.inv.Inventory; -import org.apollo.game.sync.block.SynchronizationBlock; /** * The appearance {@link SynchronizationBlock}. Only players can utilise this block. diff --git a/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java b/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java index fcbe1a6c5..b443f5a0e 100644 --- a/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java @@ -2,7 +2,6 @@ import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.entity.setting.PrivilegeLevel; -import org.apollo.game.sync.block.SynchronizationBlock; /** * The chat {@link SynchronizationBlock}. Only players can utilise this block. diff --git a/game/src/main/java/org/apollo/game/sync/block/ForceChatBlock.java b/game/src/main/java/org/apollo/game/sync/block/ForceChatBlock.java index ea6c9665e..7dae2b8a0 100644 --- a/game/src/main/java/org/apollo/game/sync/block/ForceChatBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/ForceChatBlock.java @@ -1,7 +1,5 @@ package org.apollo.game.sync.block; -import org.apollo.game.sync.block.SynchronizationBlock; - /** * The force chat {@link SynchronizationBlock}. Both players and npcs can utilise this block. It is not possible to add * colour or effect (e.g. wave or scroll) to this block. diff --git a/game/src/main/java/org/apollo/game/sync/block/ForceMovementBlock.java b/game/src/main/java/org/apollo/game/sync/block/ForceMovementBlock.java index bed94fd66..874fe9d1d 100644 --- a/game/src/main/java/org/apollo/game/sync/block/ForceMovementBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/ForceMovementBlock.java @@ -2,7 +2,6 @@ import org.apollo.game.model.Direction; import org.apollo.game.model.Position; -import org.apollo.game.sync.block.SynchronizationBlock; /** * The Force Movement {@link SynchronizationBlock}. Only players can utilise this block. diff --git a/game/src/main/java/org/apollo/game/sync/block/GraphicBlock.java b/game/src/main/java/org/apollo/game/sync/block/GraphicBlock.java index b0e95f144..c263c54eb 100644 --- a/game/src/main/java/org/apollo/game/sync/block/GraphicBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/GraphicBlock.java @@ -1,7 +1,6 @@ package org.apollo.game.sync.block; import org.apollo.game.model.Graphic; -import org.apollo.game.sync.block.SynchronizationBlock; /** * The graphic {@link SynchronizationBlock}. Both players and npcs can utilise this block. diff --git a/game/src/main/java/org/apollo/game/sync/block/HitUpdateBlock.java b/game/src/main/java/org/apollo/game/sync/block/HitUpdateBlock.java index 1175d3b93..b51d4c27e 100644 --- a/game/src/main/java/org/apollo/game/sync/block/HitUpdateBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/HitUpdateBlock.java @@ -1,7 +1,5 @@ package org.apollo.game.sync.block; -import org.apollo.game.sync.block.SynchronizationBlock; - /** * The hit update {@link SynchronizationBlock}. Both npcs and players can utilise this block. * diff --git a/game/src/main/java/org/apollo/game/sync/block/InteractingMobBlock.java b/game/src/main/java/org/apollo/game/sync/block/InteractingMobBlock.java index 9e12e911c..875988dbb 100644 --- a/game/src/main/java/org/apollo/game/sync/block/InteractingMobBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/InteractingMobBlock.java @@ -1,7 +1,5 @@ package org.apollo.game.sync.block; -import org.apollo.game.sync.block.SynchronizationBlock; - /** * The interacting mob {@link SynchronizationBlock}. Both players and npcs can utilise this block. * diff --git a/game/src/main/java/org/apollo/game/sync/block/SecondaryHitUpdateBlock.java b/game/src/main/java/org/apollo/game/sync/block/SecondaryHitUpdateBlock.java index 87535d5de..46c579e62 100644 --- a/game/src/main/java/org/apollo/game/sync/block/SecondaryHitUpdateBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/SecondaryHitUpdateBlock.java @@ -1,7 +1,5 @@ package org.apollo.game.sync.block; -import org.apollo.game.sync.block.SynchronizationBlock; - /** * The secondary hit update {@link SynchronizationBlock}. This is used for when multiple attacks happen at once (for * example, the dragon-dagger special attack). Both players and npcs can utilise this block. diff --git a/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java b/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java index bc91270f1..56020b206 100644 --- a/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/TransformBlock.java @@ -1,7 +1,5 @@ package org.apollo.game.sync.block; -import org.apollo.game.sync.block.SynchronizationBlock; - /** * The transform {@link SynchronizationBlock}. Only npcs can utilise this block. * diff --git a/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java b/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java index a25423973..a81df5403 100644 --- a/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java @@ -1,7 +1,6 @@ package org.apollo.game.sync.block; import org.apollo.game.model.Position; -import org.apollo.game.sync.block.SynchronizationBlock; /** * The turn to position {@link SynchronizationBlock}. Both players and npcs can utilise this block. diff --git a/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java b/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java index 6a89c328c..b0ddf203c 100644 --- a/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java +++ b/game/src/main/java/org/apollo/game/sync/seg/MovementSegment.java @@ -1,9 +1,10 @@ package org.apollo.game.sync.seg; -import com.google.common.base.Preconditions; import org.apollo.game.model.Direction; import org.apollo.game.sync.block.SynchronizationBlockSet; +import com.google.common.base.Preconditions; + /** * A {@link SynchronizationSegment} where a mob is moved (or doesn't move!). * diff --git a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java index 80fc44ee0..7824dba9e 100644 --- a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java @@ -1,5 +1,11 @@ package org.apollo.game.sync.task; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + import org.apollo.game.message.impl.encode.NpcSynchronizationMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; @@ -13,12 +19,6 @@ import org.apollo.game.sync.seg.RemoveMobSegment; import org.apollo.game.sync.seg.SynchronizationSegment; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - /** * A {@link SynchronizationTask} which synchronizes npcs with the specified {@link Player}. * diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index 2298705ce..81c61b9b5 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -2,7 +2,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import it.unimi.dsi.fastutil.objects.ObjectSet; import org.apollo.cache.def.EquipmentDefinition; import org.apollo.game.message.impl.encode.PlayerSynchronizationMessage; import org.apollo.game.model.*; @@ -23,6 +22,8 @@ import org.apollo.util.BufferUtil; import org.jetbrains.annotations.NotNull; +import java.util.Set; + import static org.apollo.game.model.entity.PlayerUpdateInfo.MAXIMUM_LOCAL_PLAYERS; /** @@ -39,7 +40,7 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { private final Player player; private final PlayerUpdateInfo info; private final World world; - private final ObjectSet limitedPlayers; + private final Set limitedPlayers; public PlayerSynchronizationTask(Player player) { this.player = player; diff --git a/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt b/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt index 3c817e9ca..9f1bd9fd9 100644 --- a/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt +++ b/game/src/main/kotlin/org/apollo/game/action/ActionCoroutine.kt @@ -1,12 +1,12 @@ package org.apollo.game.action -import kotlinx.coroutines.suspendCancellableCoroutine import java.util.concurrent.CancellationException import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicReference -import kotlin.coroutines.* import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn +import kotlinx.coroutines.suspendCancellableCoroutine +import kotlin.coroutines.* typealias ActionPredicate = () -> Boolean typealias ActionBlock = suspend ActionCoroutine.() -> Unit diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt index b25859fa9..e1b8cf6c6 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt @@ -2,7 +2,7 @@ package org.apollo.game.plugin.kotlin import org.apollo.game.command.CommandListener import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.decode.IfActionMessage +import org.apollo.game.message.impl.decode.ButtonMessage import org.apollo.game.model.World import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.event.Event @@ -86,11 +86,11 @@ abstract class KotlinPluginScript(var world: World, val context: PluginContext) } /** - * Create a [IfActionMessage] [MessageHandler] for the given [id]. + * Create a [ButtonMessage] [MessageHandler] for the given [id]. */ @Deprecated("Use new on(Type) listener") - fun on_button(id: Int): KotlinPlayerHandlerProxyTrait { - return on { IfActionMessage::class }.where { componentId == id } + fun on_button(id: Int): KotlinPlayerHandlerProxyTrait { + return on { ButtonMessage::class }.where { componentId == id } } fun start(callback: (World) -> Unit) { diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt index 30b5c96ca..2ec4bb687 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.kotlin.message import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.decode.IfActionMessage +import org.apollo.game.message.impl.decode.ButtonMessage import org.apollo.game.model.World import org.apollo.game.model.entity.Player import org.apollo.game.plugin.kotlin.KotlinPluginScript @@ -10,7 +10,7 @@ import org.apollo.game.plugin.kotlin.PlayerContext import org.apollo.game.plugin.kotlin.PredicateContext /** - * Registers a listener for [IfActionMessage]s that occur on the given [button] id. + * Registers a listener for [ButtonMessage]s that occur on the given [button] id. * * ``` * on(ButtonClick, button = 416) { @@ -30,18 +30,18 @@ fun KotlinPluginScript.on( class IfAction(override val player: Player) : PlayerContext { - companion object : MessageListenable() { + companion object : MessageListenable() { - override val type = IfActionMessage::class + override val type = ButtonMessage::class override fun createHandler( world: World, predicateContext: IfActionPredicateContext?, callback: IfAction.() -> Unit - ): MessageHandler { - return object : MessageHandler(world) { + ): MessageHandler { + return object : MessageHandler(world) { - override fun handle(player: Player, message: IfActionMessage) { + override fun handle(player: Player, message: ButtonMessage) { if (predicateContext == null || predicateContext.inter != message.interfaceId || predicateContext.comp != message.componentId || predicateContext.action != message.option) { return; diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java index 8cddd76d0..aa975a2e5 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java @@ -8,12 +8,13 @@ import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inv.Inventory; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.powermock.api.mockito.PowerMockito.*; @RunWith(PowerMockRunner.class) diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java index 99de9f0c4..edb7ab7df 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java @@ -12,6 +12,7 @@ import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.obj.StaticGameObject; +import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inv.Inventory; import org.apollo.game.model.inv.SynchronizationInventoryListener; import org.junit.Before; diff --git a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java index ecc61dd6c..52bab2e3f 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java @@ -1,5 +1,6 @@ package org.apollo.game.message.handler; +import org.apollo.cache.def.ItemDefinition; import org.apollo.cache.def.ObjectDefinition; import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; @@ -19,8 +20,10 @@ import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertTrue; -import static org.powermock.api.mockito.PowerMockito.*; +import static org.junit.Assert.*; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) @PrepareForTest({World.class, Player.class, ObjectDefinition.class, RegionRepository.class, Region.class}) diff --git a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java index da7074b6f..161dc7356 100644 --- a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java @@ -9,8 +9,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import static org.junit.Assert.assertTrue; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.junit.Assert.*; +import static org.powermock.api.mockito.PowerMockito.*; @RunWith(PowerMockRunner.class) diff --git a/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java b/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java index 03f8ba3a3..32019becc 100644 --- a/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/SkillSetTests.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; /** * Tests the {@link SkillSet} class. diff --git a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java index 96a0a4c83..a7ee6e2da 100644 --- a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java @@ -3,6 +3,7 @@ import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.area.collision.CollisionManager; import org.apollo.util.security.PlayerCredentials; import org.junit.Test; diff --git a/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java b/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java index ee065b4a8..bbd656f8f 100644 --- a/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/attr/AttributeTests.java @@ -1,11 +1,12 @@ package org.apollo.game.model.entity.attr; -import com.google.common.primitives.Longs; +import java.nio.charset.StandardCharsets; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import java.nio.charset.StandardCharsets; +import com.google.common.primitives.Longs; /** * Tests for different {@link Attribute}s. diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java index 9e08c783b..f66d242b2 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java @@ -1,7 +1,6 @@ package org.apollo.net.codec.game; import io.netty.buffer.ByteBuf; -import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.Unpooled; import org.apollo.net.meta.PacketType; @@ -226,7 +225,7 @@ public void putBit(int value) { public void putBits(int numBits, int value) { Preconditions.checkArgument(numBits >= 1 && numBits <= 32, "Number of bits must be between 1 and 32 inclusive."); - //checkBitAccess(); + checkBitAccess(); int bytePos = bitIndex >> 3; int bitOffset = 8 - (bitIndex & 7); @@ -432,10 +431,6 @@ public void switchToByteAccess() { buffer.writerIndex((bitIndex + 7) / 8); } - public void addComposite(CompositeByteBuf composite) { - composite.addComponent(buffer); - } - /** * Creates a {@link GamePacket} based on the current contents of this builder. * diff --git a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java index a0d4b6bab..f950c7e23 100644 --- a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java @@ -3,16 +3,16 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; -import org.apollo.net.codec.login.LoginConstants; + +import java.util.List; +import java.util.logging.Logger; + import org.apollo.net.codec.login.LoginDecoder; import org.apollo.net.codec.login.LoginEncoder; import org.apollo.net.codec.update.OnDemandInfoEncoder; import org.apollo.net.codec.update.OnDemandResponseEncoder; import org.apollo.net.codec.update.UpdateDecoder; -import java.util.List; -import java.util.logging.Logger; - /** * A {@link ByteToMessageDecoder} which decodes the handshake and makes changes to the pipeline as appropriate for the * selected service. From ba35a57ebfdccd4d422fc2601feb4fb89ab7e180 Mon Sep 17 00:00:00 2001 From: Khaled Jaber Date: Tue, 12 May 2020 19:25:15 -0400 Subject: [PATCH 63/63] Code review pass #2 osrs-proposal --- ...Message.java => KeyboardEventMessage.java} | 19 +++++---- ...essage.java => MouseMoveEventMessage.java} | 4 +- .../apollo/game/release/r181/Release181.java | 2 +- ...Decoder.java => KeyboardEventDecoder.java} | 12 +++--- ...ecoder.java => MouseMoveEventDecoder.java} | 8 ++-- .../codec/update/OnDemandResponseEncoder.java | 39 ++++++++++++------- .../main/java/org/apollo/util/BufferUtil.java | 2 +- 7 files changed, 48 insertions(+), 38 deletions(-) rename game/src/main/java/org/apollo/game/message/impl/decode/{EventKeyboardMessage.java => KeyboardEventMessage.java} (68%) rename game/src/main/java/org/apollo/game/message/impl/decode/{EventMouseMoveMessage.java => MouseMoveEventMessage.java} (76%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{EventKeyboardDecoder.java => KeyboardEventDecoder.java} (64%) rename game/src/main/java/org/apollo/game/release/r181/decoders/{EventMouseMoveDecoder.java => MouseMoveEventDecoder.java} (91%) diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/EventKeyboardMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/KeyboardEventMessage.java similarity index 68% rename from game/src/main/java/org/apollo/game/message/impl/decode/EventKeyboardMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/KeyboardEventMessage.java index dd759d91e..7e0194689 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/EventKeyboardMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/KeyboardEventMessage.java @@ -3,19 +3,18 @@ import org.apollo.net.message.Message; import java.time.Duration; -import java.util.concurrent.TimeUnit; /** * The type Event keyboard message. * * @author Khaled Abdeljaber */ -public class EventKeyboardMessage extends Message { +public class KeyboardEventMessage extends Message { /** * The event that occurs on a keyboard press. */ - public static class EventKeyboard { + public static class KeyboardEvent { /** * The key pressed. */ @@ -24,16 +23,16 @@ public static class EventKeyboard { /** * The duration in milliseconds. */ - private Duration duration; + private long duration; /** * Instantiates a new Event keyboard. * @param key the key * @param duration the duration */ - public EventKeyboard(int key, Duration duration) { + public KeyboardEvent(int key, Duration duration) { this.key = key; - this.duration = duration; + this.duration = duration.toMillis(); } /** @@ -50,19 +49,19 @@ public int getKey() { * * @return the duration */ - public Duration getDuration() { + public long getDuration() { return duration; } } - private final EventKeyboard[] events; + private final KeyboardEvent[] events; /** * Instantiates a new Event keyboard message. * * @param events the events */ - public EventKeyboardMessage(EventKeyboard... events) { + public KeyboardEventMessage(KeyboardEvent... events) { this.events = events; } @@ -71,7 +70,7 @@ public EventKeyboardMessage(EventKeyboard... events) { * * @return the events */ - public EventKeyboard[] getEvents() { + public KeyboardEvent[] getEvents() { return events; } } diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/EventMouseMoveMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MouseMoveEventMessage.java similarity index 76% rename from game/src/main/java/org/apollo/game/message/impl/decode/EventMouseMoveMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MouseMoveEventMessage.java index b9e6641f9..856d1865a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/decode/EventMouseMoveMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MouseMoveEventMessage.java @@ -5,13 +5,13 @@ /** * @author Khaled Abdeljaber */ -public class EventMouseMoveMessage extends Message { +public class MouseMoveEventMessage extends Message { private final int x; private final int y; private final int dt; - public EventMouseMoveMessage(int x, int y, int dt) { + public MouseMoveEventMessage(int x, int y, int dt) { this.x = x; this.y = y; this.dt = dt; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java index a8c96d4d3..b018aeb92 100644 --- a/game/src/main/java/org/apollo/game/release/r181/Release181.java +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -287,7 +287,7 @@ private void init() { * Resume Inputs */ register(17, new EnteredAmountMessageDecoder()); - register(67, new EventKeyboardDecoder()); + register(67, new KeyboardEventDecoder()); /** * Player diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/EventKeyboardDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/KeyboardEventDecoder.java similarity index 64% rename from game/src/main/java/org/apollo/game/release/r181/decoders/EventKeyboardDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/KeyboardEventDecoder.java index d377274b9..46290c8f6 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/EventKeyboardDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/KeyboardEventDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.decode.EventKeyboardMessage; +import org.apollo.game.message.impl.decode.KeyboardEventMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -12,18 +12,18 @@ /** * @author Khaled Abdeljaber */ -public class EventKeyboardDecoder extends MessageDecoder { +public class KeyboardEventDecoder extends MessageDecoder { @Override - public EventKeyboardMessage decode(GamePacket packet) { + public KeyboardEventMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - final var events = new EventKeyboardMessage.EventKeyboard[reader.getLength() / 4]; + final var events = new KeyboardEventMessage.KeyboardEvent[reader.getLength() / 4]; for (int index = 0; index < events.length; index++) { var keyPressed = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); var duration = reader.getUnsigned(DataType.TRI_BYTE); - events[index] = new EventKeyboardMessage.EventKeyboard((int) keyPressed, Duration.ofMillis(duration)); + events[index] = new KeyboardEventMessage.KeyboardEvent((int) keyPressed, Duration.ofMillis(duration)); } - return new EventKeyboardMessage(events); + return new KeyboardEventMessage(events); } } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/EventMouseMoveDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseMoveEventDecoder.java similarity index 91% rename from game/src/main/java/org/apollo/game/release/r181/decoders/EventMouseMoveDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/MouseMoveEventDecoder.java index 75e32932f..bd72b2ee8 100644 --- a/game/src/main/java/org/apollo/game/release/r181/decoders/EventMouseMoveDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseMoveEventDecoder.java @@ -1,6 +1,6 @@ package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.decode.EventMouseMoveMessage; +import org.apollo.game.message.impl.decode.MouseMoveEventMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -9,9 +9,9 @@ /** * @author Khaled Abdeljaber */ -public class EventMouseMoveDecoder extends MessageDecoder { +public class MouseMoveEventDecoder extends MessageDecoder { @Override - public EventMouseMoveMessage decode(GamePacket packet) { + public MouseMoveEventMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int length = packet.getLength(); @@ -80,6 +80,6 @@ public EventMouseMoveMessage decode(GamePacket packet) { * } */ - return new EventMouseMoveMessage(dx, dy, dt); + return new MouseMoveEventMessage(dx, dy, dt); } } diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java index 5a5483b8d..e6f41474b 100644 --- a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java @@ -8,10 +8,29 @@ /** * A {@link MessageToMessageEncoder} for the 'on-demand' protocol. * - * @author Graham */ public final class OnDemandResponseEncoder extends MessageToByteEncoder { + /** + * Flag which denotes the request is async. + */ + private static final int PREFTECH = 0x80; + + /** + * The maximum number of bytes the initial payload can have. Includes the header. + */ + private static final int ENTRY_PAYLOAD_START = 508; + + /** + * The maximum number of bytes per entry. + */ + private static final int ENTRY_PAYLOAD = 511; + + /** + * Marks the beginning of the entry. + */ + private static final int ENTRY_DELIMITER = 0xFF; + @Override protected void encode(ChannelHandlerContext ctx, OnDemandResponse response, ByteBuf buf) { int fs = response.getFs(); @@ -23,23 +42,15 @@ protected void encode(ChannelHandlerContext ctx, OnDemandResponse response, Byte int compression = container.readUnsignedByte(); if (response.getPriority() == OnDemandRequest.Priority.LOW) { - compression |= 0x80; + compression |= PREFTECH; } buf.writeByte(compression); + buf.writeBytes(container.readBytes(Math.min(ENTRY_PAYLOAD_START, container.readableBytes()))); - int bytes = container.readableBytes(); - if (bytes > 508) bytes = 508; - - buf.writeBytes(container.readBytes(bytes)); - - for (; ; ) { - bytes = container.readableBytes(); - if (bytes == 0) { - break; - } else if (bytes > 511) bytes = 511; - - buf.writeByte(0xFF); + int bytes; + while ((bytes = Math.min(ENTRY_PAYLOAD, container.readableBytes())) != 0) { + buf.writeByte(ENTRY_DELIMITER); final var payload = container.readBytes(bytes); buf.writeBytes(payload); diff --git a/util/src/main/java/org/apollo/util/BufferUtil.java b/util/src/main/java/org/apollo/util/BufferUtil.java index f8276e13f..171029439 100644 --- a/util/src/main/java/org/apollo/util/BufferUtil.java +++ b/util/src/main/java/org/apollo/util/BufferUtil.java @@ -129,7 +129,7 @@ public static void writeString(ByteBuffer buffer, String str) { public static final int STRING_TERMINATOR = 0; /** - * Charset that Jagex uses. + * Charset that Runescape uses. */ public static final Charset CHARSET = Charset.forName("Windows-1252");