From c73eebc934b2d935bf3d49bdd137a2d98cb3f4eb Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 21 May 2017 11:57:44 -0400 Subject: [PATCH] runelite-api: add PlayerComposition and KitType enum --- .../main/java/net/runelite/api/Player.java | 7 +- .../net/runelite/api/PlayerComposition.java | 68 +++++++++++++++++++ .../java/net/runelite/api/kit/KitType.java | 53 +++++++++++++++ .../runelite/rs/api/PlayerComposition.java | 3 - 4 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/PlayerComposition.java create mode 100644 runelite-api/src/main/java/net/runelite/api/kit/KitType.java diff --git a/runelite-api/src/main/java/net/runelite/api/Player.java b/runelite-api/src/main/java/net/runelite/api/Player.java index ef7057956c..07ed351c6e 100644 --- a/runelite-api/src/main/java/net/runelite/api/Player.java +++ b/runelite-api/src/main/java/net/runelite/api/Player.java @@ -22,7 +22,6 @@ * (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 net.runelite.api; public class Player extends Actor @@ -49,5 +48,9 @@ public class Player extends Actor { return player.getCombatLevel(); } -} + public PlayerComposition getPlayerComposition() + { + return new PlayerComposition(player.getComposition()); + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/PlayerComposition.java b/runelite-api/src/main/java/net/runelite/api/PlayerComposition.java new file mode 100644 index 0000000000..c4e4f7b3a0 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/PlayerComposition.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017, Adam + * 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 net.runelite.api; + +import net.runelite.api.kit.KitType; + +public class PlayerComposition +{ + private final net.runelite.rs.api.PlayerComposition playerComposition; + + public PlayerComposition(net.runelite.rs.api.PlayerComposition playerComposition) + { + this.playerComposition = playerComposition; + } + + /** + * Get equipment ids. If id is >= 256 && < 512 then subtract 256 and the id is a kit definition. + * If the id is >= 512 then subtract 512 and the id is an item id. + * + * @return + */ + public int[] getEquipmentIds() + { + return playerComposition.getEquipmentIds(); + } + + public int getEquipmentId(KitType type) + { + int id = getEquipmentIds()[type.getIndex()]; + if (id < 512) + { + return -1; // not an item + } + return id - 512; + } + + public int getKitId(KitType type) + { + int id = getEquipmentIds()[type.getIndex()]; + if (id < 256 || id >= 512) + { + return -1; // not a kit + } + return id - 256; + } +} diff --git a/runelite-api/src/main/java/net/runelite/api/kit/KitType.java b/runelite-api/src/main/java/net/runelite/api/kit/KitType.java new file mode 100644 index 0000000000..5b608c0700 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/kit/KitType.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, Adam + * 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 net.runelite.api.kit; + +public enum KitType +{ + CAPE(1), + AMULET(2), + WEAPON(3), + TORSO(4), + SHIELD(5), + LEGS(7), + HEAD(8), + HANDS(9), + BOOTS(10), + JAW(11); + + /** index into player composition equipment ids + */ + private final int index; + + private KitType(int index) + { + this.index = index; + } + + public int getIndex() + { + return index; + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/PlayerComposition.java b/runescape-api/src/main/java/net/runelite/rs/api/PlayerComposition.java index f049a71713..41899de8dc 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/PlayerComposition.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/PlayerComposition.java @@ -32,9 +32,6 @@ public interface PlayerComposition @Import("isFemale") boolean isFemale(); - @Import("equipment") - int[] getEquipment(); - @Import("bodyPartColours") int[] getBodyPartColours();