Def cleanup (#585)

* Object definition cleanup

* Update ShopAssistant.java

* stackables

* notables

* unused files

* more junk

* almost done

* working

* moving old methods to deprecated

* update

* fixed pickpocket typos

* Update Pickpocket.java

* Remove redundant method. Fix stall stealing

* Documentation for deprecated methods

* WIP commit partial removal. Has test and dump classes

* Final cleanup

* Move definitions from data folder to cfg

* Temporarily moving definition loaders to GameEngine

This is until loading can be done asynchronously.

* Correct indentation.
This commit is contained in:
MatthewBishop
2023-02-05 17:30:29 -05:00
committed by GitHub
parent b2212d357e
commit eab153ee3f
98 changed files with 21771 additions and 285672 deletions
@@ -0,0 +1,46 @@
package com.rs2.game.items;
/**
* Methods which are set to be phased out but exist to maintain compatibility with the existing source code.
*
* @author Advocatus
*
*/
public class DeprecatedItems {
/**
* Gets the item id for a specific name. This is inefficient and is used for potion mixing. That code needs to be reworked.
* Tagging as {@link java.lang.Deprecated} until the rest of the code can be untangled. It is worth noting that it will only return
* the first matching item id which can cause unintended behavior and should be avoided.
*
* @param name The item name
* @return The item id or -1.
*/
@java.lang.Deprecated
public static int getItemId(String name) {
for (int i = 0; i < org.apollo.cache.def.ItemDefinition.count(); i++) {
org.apollo.cache.def.ItemDefinition def = org.apollo.cache.def.ItemDefinition.lookup(i);
if (def != null && def.getName() != null) {
if (def.getName().equalsIgnoreCase(name)) {
return def.getId();
}
}
}
return -1;
}
/**
* Temporary method which wraps around the ItemDefinition.lookup(id).getName(); This is utilized due to source specific behaviors.
* This should be phased out with discretion.
*
* @param id The id.
* @return The items name or "Unarmed"
*/
@java.lang.Deprecated
public static String getItemName(int id) {
if(org.apollo.cache.def.ItemDefinition.lookup(id) == null || org.apollo.cache.def.ItemDefinition.lookup(id).getName() == null)
return "Unarmed";
return org.apollo.cache.def.ItemDefinition.lookup(id).getName();
}
}
@@ -1,12 +1,14 @@
package com.rs2.game.items;
import org.apollo.cache.def.ItemDefinition;
public class GameItem {
public int id, amount;
public boolean stackable = false;
public GameItem(int id, int amount) {
if (ItemData.itemStackable[id]) {
if (ItemDefinition.lookup(id).isStackable()) {
stackable = true;
}
this.id = id;
@@ -1,5 +1,7 @@
package com.rs2.game.items;
import org.apollo.cache.def.ItemDefinition;
import com.rs2.GameConstants;
import com.rs2.GameEngine;
import com.rs2.game.players.Player;
@@ -88,7 +90,7 @@ public class Inventory {
}
public boolean add(int id, int amount) {
if (player.getItemAssistant().isStackable(id)) {
if (ItemDefinition.lookup(id).isStackable()) {
int allAmount = getStackedGroundAmount(id, amount, getCount(id));
if (allAmount > 0) {
GameEngine.itemHandler.createGroundItem(player, id, player.getX(), player
@@ -126,18 +128,6 @@ public class Inventory {
}
}
public boolean ownsItem(String itemName) {
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
if (GameEngine.itemHandler.itemList[i] != null) {
if (GameEngine.itemHandler.itemList[i].itemName
.equalsIgnoreCase(itemName)) {
return true;
}
}
}
return false;
}
public boolean playerHasItem(int item) {
return player.getItemAssistant().playerHasItem(item);
}
@@ -1,7 +1,5 @@
package com.rs2.game.items;
import com.rs2.GameEngine;
/**
* Represents a single item.
*
@@ -98,8 +96,4 @@ public class Item {
public boolean equals(Item item) {
return item.getId() == id && count == item.getCount();
}
public ItemList getDefinition() {
return GameEngine.itemHandler.itemList[id];
}
}
@@ -1,5 +1,7 @@
package com.rs2.game.items;
import org.apollo.cache.def.ItemDefinition;
import com.rs2.GameConstants;
import com.rs2.GameEngine;
import com.rs2.game.content.minigames.castlewars.CastleWars;
@@ -42,7 +44,7 @@ public class ItemAssistant {
deleteItem(itemId, 1);
clickTimer = System.currentTimeMillis();
player.getPacketSender().sendMessage(
"You find " + amount + " " + getItemName(item) + ".");
"You find " + amount + " " + DeprecatedItems.getItemName(item) + ".");
} else {
if (System.currentTimeMillis() - clickTimer > 1800) {
addItem(995, 100);
@@ -60,7 +62,7 @@ public class ItemAssistant {
public void destroyInterface(int itemId) {
itemId = player.droppedItem;
String itemName = getItemName(player.droppedItem);
String itemName = DeprecatedItems.getItemName(player.droppedItem);
String[][] info = {
{ "Are you sure you want to destroy this item?", "14174" },
{ "Yes.", "14175" }, { "No.", "14176" }, { "", "14177" },
@@ -74,7 +76,7 @@ public class ItemAssistant {
public void destroyItem(int itemId) {
itemId = player.droppedItem;
String itemName = getItemName(itemId);
String itemName = DeprecatedItems.getItemName(itemId);
deleteItem(itemId,getItemSlot(itemId), player.playerItemsN[getItemSlot(itemId)]);
player.getPacketSender().sendMessage("Your " + itemName + " vanishes as you destroy it.");
player.getPacketSender().closeAllWindows();
@@ -88,12 +90,12 @@ public class ItemAssistant {
}
public void addOrDropItem(int item, int amount) {
if (isStackable(item) && hasFreeSlots(1)) {
if (ItemDefinition.lookup(item).isStackable() && hasFreeSlots(1)) {
addItem(item, amount);
} else if (!hasFreeSlots(amount) && !isStackable(item)) {
} else if (!hasFreeSlots(amount) && !ItemDefinition.lookup(item).isStackable()) {
GameEngine.itemHandler.createGroundItem(player, item, player.getX(), player.getY(), amount, player.playerId);
player.getPacketSender().sendMessage("You have no inventory space, so the item(s) appear beneath you.");
} else if (isStackable(item) && !hasFreeSlots(1) && !playerHasItem(item)) {
} else if (ItemDefinition.lookup(item).isStackable() && !hasFreeSlots(1) && !playerHasItem(item)) {
GameEngine.itemHandler.createGroundItem(player, item, player.getX(), player.getY(), amount, player.playerId);
player.getPacketSender().sendMessage("You have no inventory space, so the item(s) appear beneath you.");
} else {
@@ -261,12 +263,12 @@ public class ItemAssistant {
public int getTotalCount(int itemID) {
int count = 0;
for (int j = 0; j < player.playerItems.length; j++) {
if (ItemData.itemIsNote[itemID + 1]) {
if (ItemDefinition.lookup(itemID + 1).isNote()) {
if (itemID + 2 == player.playerItems[j]) {
count += player.playerItemsN[j];
}
}
if (!ItemData.itemIsNote[itemID + 1]) {
if (!ItemDefinition.lookup(itemID + 1).isNote()) {
if (itemID + 1 == player.playerItems[j]) {
count += player.playerItemsN[j];
}
@@ -486,10 +488,10 @@ public class ItemAssistant {
return false;
}
if ((freeSlots() >= 1 || playerHasItem(item, 1))
&& ItemData.itemStackable[item] || freeSlots() > 0
&& !ItemData.itemStackable[item]) {
&& ItemDefinition.lookup(item).isStackable() || freeSlots() > 0
&& !ItemDefinition.lookup(item).isStackable()) {
for (int i = 0; i < player.playerItems.length; i++) {
if (player.playerItems[i] == item + 1 && ItemData.itemStackable[item]
if (player.playerItems[i] == item + 1 && ItemDefinition.lookup(item).isStackable()
&& player.playerItems[i] > 0) {
player.playerItems[i] = item + 1;
if (player.playerItemsN[i] + amount < GameConstants.MAXITEM_AMOUNT
@@ -559,17 +561,9 @@ public class ItemAssistant {
public void getBonus() {
for (int element : player.playerEquipment) {
if (element > -1) {
for (int j = 0; j < GameConstants.ITEM_LIMIT; j++) {
if (GameEngine.itemHandler.itemList[j] != null) {
if (GameEngine.itemHandler.itemList[j].itemId == element) {
for (int k = 0; k < player.playerBonus.length; k++) {
player.playerBonus[k] += GameEngine.itemHandler.itemList[j].Bonuses[k];
}
break;
}
}
}
int[] bonuses = ItemDefinitions.getBonus(element);
for (int k = 0; k < player.playerBonus.length; k++) {
player.playerBonus[k] += bonuses[k];
}
}
}
@@ -1201,7 +1195,7 @@ public class ItemAssistant {
player.getPacketSender().sendFrame70(specAmount >= 2 ? 500 : 0, 0, --barId);
player.getPacketSender().sendFrame70(specAmount >= 1 ? 500 : 0, 0, --barId);
updateSpecialBar();
sendWeapon(weapon, getItemName(weapon));
sendWeapon(weapon, DeprecatedItems.getItemName(weapon));
}
/**
@@ -1298,7 +1292,7 @@ public class ItemAssistant {
int targetSlot = ItemConstants.HAT;
boolean canWearItem = true;
if (player.playerItems[slot] == wearID + 1) {
getRequirements(getItemName(wearID).toLowerCase(), wearID);
getRequirements(DeprecatedItems.getItemName(wearID).toLowerCase(), wearID);
targetSlot = ItemData.targetSlots[wearID];
if (player.duelRule[11] && targetSlot == 0) {
@@ -1321,7 +1315,7 @@ public class ItemAssistant {
player.getPacketSender().sendMessage("Wearing bodies has been disabled in this duel!");
return false;
}
if (player.duelRule[16] && targetSlot == 5 || player.duelRule[16] && is2handed(getItemName(wearID).toLowerCase(), wearID)) {
if (player.duelRule[16] && targetSlot == 5 || player.duelRule[16] && is2handed(DeprecatedItems.getItemName(wearID).toLowerCase(), wearID)) {
player.getPacketSender().sendMessage("Wearing shield has been disabled in this duel!");
return false;
}
@@ -1448,7 +1442,7 @@ public class ItemAssistant {
int toEquipN = player.playerItemsN[slot];
int toRemove = player.playerEquipment[targetSlot];
int toRemoveN = player.playerEquipmentN[targetSlot];
if (toEquip == toRemove + 1 && ItemData.itemStackable[toRemove]) {
if (toEquip == toRemove + 1 && ItemDefinition.lookup(toRemove).isStackable()) {
deleteItem(toRemove, getItemSlot(toRemove), toEquipN);
player.playerEquipmentN[targetSlot] += toEquipN;
} else if (targetSlot != ItemConstants.SHIELD && targetSlot != ItemConstants.WEAPON) {
@@ -1457,7 +1451,7 @@ public class ItemAssistant {
player.playerEquipment[targetSlot] = toEquip - 1;
player.playerEquipmentN[targetSlot] = toEquipN;
} else if (targetSlot == ItemConstants.SHIELD) {
boolean wearing2h = is2handed(getItemName(player.playerEquipment[ItemConstants.WEAPON]).toLowerCase(), player.playerEquipment[ItemConstants.WEAPON]);
boolean wearing2h = is2handed(DeprecatedItems.getItemName(player.playerEquipment[ItemConstants.WEAPON]).toLowerCase(), player.playerEquipment[ItemConstants.WEAPON]);
if (wearing2h) {
// remove the weapon, add to inventory
toRemove = player.playerEquipment[player.playerWeapon];
@@ -1477,7 +1471,7 @@ public class ItemAssistant {
toRemove = -1;
toRemoveN = 0;
}
boolean is2h = is2handed(getItemName(wearID).toLowerCase(), wearID);
boolean is2h = is2handed(DeprecatedItems.getItemName(wearID).toLowerCase(), wearID);
boolean wearingShield = player.playerEquipment[ItemConstants.SHIELD] > 0;
boolean wearingWeapon = player.playerEquipment[ItemConstants.WEAPON] > 0;
if (is2h) {
@@ -1535,7 +1529,7 @@ public class ItemAssistant {
player.getOutStream().endFrameVarSizeWord();
player.flushOutStream();
}
sendWeapon(player.playerEquipment[player.playerWeapon], getItemName(player.playerEquipment[player.playerWeapon]));
sendWeapon(player.playerEquipment[player.playerWeapon], DeprecatedItems.getItemName(player.playerEquipment[player.playerWeapon]));
resetBonus();
getBonus();
writeBonus();
@@ -1571,7 +1565,7 @@ public class ItemAssistant {
player.getItemAssistant()
.sendWeapon(
player.playerEquipment[player.playerWeapon],
ItemAssistant
DeprecatedItems
.getItemName(player.playerEquipment[player.playerWeapon]));
resetBonus();
getBonus();
@@ -1607,7 +1601,7 @@ public class ItemAssistant {
player.playerEquipment[slot] = -1;
player.playerEquipmentN[slot] = 0;
sendWeapon(player.playerEquipment[ItemConstants.WEAPON],
getItemName(player.playerEquipment[ItemConstants.WEAPON]));
DeprecatedItems.getItemName(player.playerEquipment[ItemConstants.WEAPON]));
resetBonus();
getBonus();
writeBonus();
@@ -1648,7 +1642,7 @@ public class ItemAssistant {
player.playerEquipment[slot] = -1;
player.playerEquipmentN[slot] = 0;
sendWeapon(player.playerEquipment[player.playerWeapon],
getItemName(player.playerEquipment[player.playerWeapon]));
DeprecatedItems.getItemName(player.playerEquipment[player.playerWeapon]));
resetBonus();
getBonus();
writeBonus();
@@ -1815,11 +1809,11 @@ public class ItemAssistant {
if (player.playerItemsN[fromSlot] <= 0) {
return false;
}
if (!ItemData.itemIsNote[player.playerItems[fromSlot] - 1]) {
if (!ItemDefinition.lookup(player.playerItems[fromSlot] - 1).isNote()) {
if (player.playerItems[fromSlot] <= 0) {
return false;
}
if (ItemData.itemStackable[player.playerItems[fromSlot] - 1] || player.playerItemsN[fromSlot] > 1) {
if (ItemDefinition.lookup(player.playerItems[fromSlot] - 1).isStackable() || player.playerItemsN[fromSlot] > 1) {
int toBankSlot = 0;
boolean alreadyInBank = false;
for (int i = 0; i < ItemConstants.BANK_SIZE; i++) {
@@ -1942,11 +1936,11 @@ public class ItemAssistant {
return false;
}
}
} else if (ItemData.itemIsNote[player.playerItems[fromSlot] - 1] && !ItemData.itemIsNote[player.playerItems[fromSlot] - 2]) {
} else if (ItemDefinition.lookup(player.playerItems[fromSlot] - 1).isNote() && !ItemDefinition.lookup(player.playerItems[fromSlot] - 2).isNote()) {
if (player.playerItems[fromSlot] <= 0) {
return false;
}
if (ItemData.itemStackable[player.playerItems[fromSlot] - 1] || player.playerItemsN[fromSlot] > 1) {
if (ItemDefinition.lookup(player.playerItems[fromSlot] - 1).isStackable() || player.playerItemsN[fromSlot] > 1) {
int toBankSlot = 0;
boolean alreadyInBank = false;
for (int i = 0; i < ItemConstants.BANK_SIZE; i++) {
@@ -2112,7 +2106,7 @@ public class ItemAssistant {
}
if (!cantWithdrawCuzMaxStack) {
if (!player.takeAsNote) {
if (ItemData.itemStackable[player.bankItems[fromSlot] - 1]) {
if (ItemDefinition.lookup(player.bankItems[fromSlot] - 1).isStackable()) {
if (player.bankItemsN[fromSlot] > amount) {
if (addItem(player.bankItems[fromSlot] - 1, amount)) {
player.bankItemsN[fromSlot] -= amount;
@@ -2143,7 +2137,7 @@ public class ItemAssistant {
resetBank();
resetItems(5064);
}
} else if (player.takeAsNote && ItemData.itemIsNote[player.bankItems[fromSlot]]) {
} else if (player.takeAsNote && ItemDefinition.lookup(player.bankItems[fromSlot]).isNote()) {
if (player.bankItemsN[fromSlot] > amount) {
if (addItem(player.bankItems[fromSlot], amount)) {
player.bankItemsN[fromSlot] -= amount;
@@ -2160,7 +2154,7 @@ public class ItemAssistant {
}
} else {
player.getPacketSender().sendMessage("This item can't be withdrawn as a note.");
if (ItemData.itemStackable[player.bankItems[fromSlot] - 1]) {
if (ItemDefinition.lookup(player.bankItems[fromSlot] - 1).isStackable()) {
if (player.bankItemsN[fromSlot] > amount) {
if (addItem(player.bankItems[fromSlot] - 1, amount)) {
player.bankItemsN[fromSlot] -= amount;
@@ -2199,10 +2193,6 @@ public class ItemAssistant {
}
}
public boolean isStackable(int itemID) {
return ItemData.itemStackable[itemID];
}
/**
* Update Equip tab
**/
@@ -2500,7 +2490,7 @@ public class ItemAssistant {
for (int i = 0; i < player.playerItems.length; i ++) {
int _id = player.playerItems[i];
int _amt = player.playerItemsN[i];
if (_id <= 0 || (_id == itemID && isStackable(_id) && _amt + amount <= Integer.MAX_VALUE)) {
if (_id <= 0 || (_id == itemID && ItemDefinition.lookup(_id).isStackable() && _amt + amount <= Integer.MAX_VALUE)) {
freeS++;
}
}
@@ -2516,29 +2506,6 @@ public class ItemAssistant {
return -1;
}
public static String getItemName(int ItemID) {
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
if (GameEngine.itemHandler.itemList[i] != null) {
if (GameEngine.itemHandler.itemList[i].itemId == ItemID) {
return GameEngine.itemHandler.itemList[i].itemName;
}
}
}
return "Unarmed";
}
public int getItemId(String itemName) {
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
if (GameEngine.itemHandler.itemList[i] != null) {
if (GameEngine.itemHandler.itemList[i].itemName
.equalsIgnoreCase(itemName)) {
return GameEngine.itemHandler.itemList[i].itemId;
}
}
}
return -1;
}
public int getItemSlot(int ItemID) {
for (int i = 0; i < player.playerItems.length; i++) {
if (player.playerItems[i] - 1 == ItemID) {
@@ -2597,27 +2564,4 @@ public class ItemAssistant {
return false;
}
public int getUnnotedItem(int ItemID) {
int newId = ItemID - 1;
String NotedName = "";
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
if (GameEngine.itemHandler.itemList[i] != null) {
if (GameEngine.itemHandler.itemList[i].itemId == ItemID) {
NotedName = GameEngine.itemHandler.itemList[i].itemName;
}
}
}
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
if (GameEngine.itemHandler.itemList[i] != null) {
if (GameEngine.itemHandler.itemList[i].itemName == NotedName) {
if (GameEngine.itemHandler.itemList[i].itemDescription.startsWith("Swap this note at any bank for a") == false) {
newId = GameEngine.itemHandler.itemList[i].itemId;
break;
}
}
}
}
return newId;
}
}
@@ -4,8 +4,9 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apollo.cache.def.ItemDefinition;
import com.rs2.GameConstants;
import com.rs2.GameEngine;
public class ItemData {
@@ -148,7 +149,7 @@ public class ItemData {
"sallet", "Facemask", "Bearhead"};
public static boolean isFullBody(int itemId) {
String weapon = getItemName(itemId);
String weapon = ItemDefinition.lookup(itemId).getName();
if (weapon == null) {
return false;
}
@@ -161,7 +162,7 @@ public class ItemData {
}
public static boolean isFullHelm(int itemId) {
String weapon = getItemName(itemId);
String weapon = ItemDefinition.lookup(itemId).getName();
if (weapon == null) {
return false;
}
@@ -174,7 +175,7 @@ public class ItemData {
}
public static boolean isFullMask(int itemId) {
String weapon = getItemName(itemId);
String weapon = ItemDefinition.lookup(itemId).getName();
if (weapon == null) {
return false;
}
@@ -186,54 +187,11 @@ public class ItemData {
return false;
}
public static String getItemName(int id) {
for (ItemList element : GameEngine.itemHandler.itemList) {
if (element != null) {
if (element.itemId == id) {
return element.itemName;
}
}
}
return null;
}
public static boolean[] itemStackable = new boolean[GameConstants.ITEM_LIMIT];
public static boolean[] itemIsNote = new boolean[GameConstants.ITEM_LIMIT];
public static int[] targetSlots = new int[GameConstants.ITEM_LIMIT];
static {
int counter = 0;
int c;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/stackable.dat"));
while ((c = dataIn.read()) != -1) {
if (c == 0) {
itemStackable[counter] = false;
itemStackable[291] = true;
} else {
itemStackable[counter] = true;
}
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading stackabledata! Trace:");
e.printStackTrace();
}
counter = 0;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/notes.dat"));
while ((c = dataIn.read()) != -1) {
itemIsNote[counter] = c == 0;
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading notedata! Trace:");
e.printStackTrace();
}
counter = 0;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/equipment.dat"));
@@ -1,351 +0,0 @@
package com.rs2.game.items;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.commons.lang3.ArrayUtils;
import org.json.JSONObject;
public class ItemDefinition {
public static ItemDefinition getDefs()[] {
return definitions;
}
public ItemDefinition() {
name = null;
itemDescription = null;
shopValue = 0;
lowAlch = 0;
highAlch = 0;
isStackable = false;
isNoteable = false;
weight = 0;
bonuses = null;
stand = -1;
walk = -1;
run = -1;
turn90left = -1;
turn90right = -1;
turn180 = -1;
attack = -1;
block = -1;
id = -1;
}
public ItemDefinition(String iname, String idescription, int ishopvalue, int ilowalch, int ihighalch, boolean iisstackable, boolean iisnoteable,
int iweight, double[] ibonuses, int istand, int iwalk, int irun, int iturn90left, int iturn90right, int iturn180,
int iattack, int iblock, int iid) {
this.name = iname;
this.itemDescription = idescription;
this.shopValue = ishopvalue;
this.lowAlch = ilowalch;
this.highAlch = ihighalch;
this.isStackable = iisstackable;
this.isNoteable = iisnoteable;
this.weight = iweight;
this.bonuses = ibonuses;
this.stand = istand;
this.walk = iwalk;
this.run = irun;
this.turn90left = iturn90left;
this.turn90right = iturn90right;
this.turn180 = iturn180;
this.attack = iattack;
this.block = iblock;
this.id = iid;
}
private int id;
public int getId() {
return id;
}
/**
* Reads the definitions from the file.
*/
public static void read() {
ArrayList<ItemDefinition> definitionsAL = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader("./data/data/itemdef.json"))) {
String line;
while ((line = br.readLine()) != null) {
definitionsAL.add(fromString(line));
}
} catch (Exception e) {
e.printStackTrace();
}
definitions = Arrays.copyOf(definitionsAL.toArray(), definitionsAL.size(), ItemDefinition[].class);
}
/**
* The item definition cache.
*/
public static ItemDefinition[] definitions;
/**
* The total items read from the definitions.
*/
public static int total;
/**
* The item name.
*/
public String name;
/**
* Returns the name of the item.
* @return
*/
public static String getName(int id) {
return definitions[id].name;
}
/**
* The item description.
*/
public String itemDescription;
/**
* Returns the description of an item.
*/
public static String getDescription(int id) {
return definitions[id].itemDescription;
}
/**
* The item price.
*/
public int shopValue;
/**
* Returns the price of an item.
*/
public static int getPrice(int id) {
return definitions[id].shopValue;
}
/**
* The low alch value.
*/
public int lowAlch;
/**
* Returns the low alch value of an item.
*/
public static int getLow(int id) {
return definitions[id].lowAlch;
}
/**
* The high alch value.
*/
public int highAlch;
/**
* Returns the high alch value of an item.
*/
public static int getHigh(int id) {
return definitions[id].highAlch;
}
/**
* Can the item be stacked?
*/
public boolean isStackable;
/**
* Returns whether or not the item can be stacked.
*/
public static boolean canStack(int id) {
return definitions[id].isStackable;
}
/**
* Can the item be noted?
*/
public boolean isNoteable;
/**
* Returns whether or not the item can be noted.
*/
public static boolean canNote(int id) {
return definitions[id].isNoteable;
}
/**
* The weight of an item.
*/
public double weight;
/**
* Returns the weight of an item.
*/
public static double getWeight(int id) {
if (id >= 0 && id < definitions.length)
return definitions[id].weight;
System.out.println("WARNING: id " + id + " doesn't have a definition! 2.147kg is used as weight.");
return 2.147;
}
/**
* The bonuses of an item.
*/
public double[] bonuses;
/**
* Returns the array of bonuses for an item.
*/
public double[] getBonuses(int id) {
return definitions[id].bonuses;
}
/**
* The stand animation of an item.
*/
public int stand;
/**
* Returns the stand animation of an item.
*/
public static int getStand(int id) {
return definitions[id].stand;
}
/**
* The walk animation of an item.
*/
public int walk;
/**
* Returns the walk animation of an item.
*/
public static int getWalk(int id) {
return definitions[id].walk;
}
/**
* The run animation of an item.
*/
public int run;
/**
* Returns the run animation of an item.
*/
public static int getRun(int id) {
return definitions[id].run;
}
/**
* The 90-degree left turn animation of an item.
*/
public int turn90left;
/**
* Returns the 90-degree left turn animation of an item.
*/
public static int get90left(int id) {
return definitions[id].turn90left;
}
/**
* The 90-degree right turn animation of an item.
*/
public int turn90right;
/**
* Returns the 90-degree right turn animation of an item.
*/
public static int get90right(int id) {
return definitions[id].turn90right;
}
/**
* The 180-degree turn animation of an item.
*/
public int turn180;
/**
* Returns the 180-degree turn animation of an item.
*/
public static int get180(int id) {
return definitions[id].turn180;
}
/**
* The attack animation of an item.
*/
public int attack;
/**
* Returns the attack animation of an item
*/
public static int getAttack(int id) {
return definitions[id].attack;
}
/**
* The block animation of an item.
*/
public int block;
/**
* Returns the block animation of an item
*/
public static int getBlock(int id) {
return definitions[id].block;
}
public static ItemDefinition fromString(String idString) {
JSONObject jobj = new JSONObject(idString);
Object[] bonusObjArr = jobj.getJSONArray("bonuses").toList().toArray();
double[] pbonuses = ArrayUtils.toPrimitive(Arrays.copyOf(bonusObjArr, bonusObjArr.length, Double[].class));
return new ItemDefinition(jobj.getString("name"),
jobj.getString("itemDescription"),
jobj.getInt("shopValue"),
jobj.getInt("lowAlch"),
jobj.getInt("highAlch"),
jobj.getBoolean("isStackable"),
jobj.getBoolean("isNoteable"),
jobj.getInt("weight"),
pbonuses,
jobj.getInt("stand"),
jobj.getInt("walk"),
jobj.getInt("run"),
jobj.getInt("turn90left"),
jobj.getInt("turn90right"),
jobj.getInt("turn180"),
jobj.getInt("attack"),
jobj.getInt("block"),
jobj.getInt("id"));
}
@Override
public String toString() {
return "{" +
"name:\"" + name + '\"' +
", itemDescription:\"" + itemDescription + '\"' +
", shopValue:" + shopValue +
", lowAlch:" + lowAlch +
", highAlch:" + highAlch +
", isStackable:" + isStackable +
", isNoteable:" + isNoteable +
", weight:" + weight +
", bonuses:" + Arrays.toString(bonuses) +
", stand:" + stand +
", walk:" + walk +
", run:" + run +
", turn90left:" + turn90left +
", turn90right:" + turn90right +
", turn180:" + turn180 +
", attack:" + attack +
", block:" + block +
", id:" + id +
'}';
}
}
@@ -0,0 +1,112 @@
package com.rs2.game.items;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rs2.util.Misc;
/**
* Loads the bonuses and weights from a json file.
*
* @author Advocatus
*
*/
public class ItemDefinitions {
private static Map<Integer, Definition> defintions = new HashMap<>();
private static final int[] EMPTY_BONUSES = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/**
* Gets the array of bonuses associated with this item id.
*
* @param id The item id.
* @return The bonuses or an empty array.
*/
public static int[] getBonus(int id) {
Definition def = defintions.get(id);
return def != null && def.bonuses != null ? def.bonuses : EMPTY_BONUSES;
}
/**
* Gets the weight of the item.
*
* @param id The item id.
* @return The weight or 0.0 by default.
*/
public static double getWeight(int id) {
Definition def = defintions.get(id);
return def != null ? def.weight : 0.0;
}
public static void load() {
Gson gson = new Gson();
try {
Type collectionType = new TypeToken<ItemData[]>() {
}.getType();
ItemData[] data = gson.fromJson(new FileReader("./data/cfg/ItemDefinitions.json"), collectionType);
for (ItemData item : data) {
defintions.put(item.id, new Definition(item));
}
} catch (FileNotFoundException fileex) {
Misc.println("items.json: file not found.");
}
}
private static class Definition {
private double weight;
private int[] bonuses;
private Definition(ItemData item) {
this.weight = item.weight;
this.bonuses = item.bonuses != null ? item.bonuses.getBonuses() : null;
}
}
private static class ItemData {
private int id;
private double weight = 0.0;
private Bonuses bonuses;
}
private static class Bonuses {
int attackStab;
int attackSlash;
int attackCrush;
int attackMagic;
int attackRange;
int defenceStab;
int defenceSlash;
int defenceCrush;
int defenceMagic;
int defenceRange;
int strengthBonus;
int prayerBonus;
public int[] getBonuses() {
int[] bonuses = new int[12];
bonuses[0] = this.attackStab;
bonuses[1] = this.attackSlash;
bonuses[2] = this.attackCrush;
bonuses[3] = this.attackMagic;
bonuses[4] = this.attackRange;
bonuses[5] = this.defenceStab;
bonuses[6] = this.defenceSlash;
bonuses[7] = this.defenceCrush;
bonuses[8] = this.defenceMagic;
bonuses[9] = this.defenceRange;
bonuses[10] = this.strengthBonus;
bonuses[11] = this.prayerBonus;
return bonuses;
}
}
}
@@ -1,16 +0,0 @@
package com.rs2.game.items;
public class ItemList {
public int itemId;
public String itemName;
public String itemDescription;
public double ShopValue;
public double LowAlch;
public double HighAlch;
public int[] Bonuses = new int[100];
public ItemList(int _itemId) {
itemId = _itemId;
}
}
@@ -131,8 +131,8 @@ public class UseItem {
WeaponPoison.execute(player, itemUsed, useWith);
player.getGlassBlowing().ItemOnItem(itemUsed, useWith);
//CapeDye.execute(c, itemUsed, useWith);
if (ItemAssistant.getItemName(itemUsed).contains("(")
&& ItemAssistant.getItemName(useWith).contains("(")) {
if (DeprecatedItems.getItemName(itemUsed).contains("(")
&& DeprecatedItems.getItemName(useWith).contains("(")) {
player.getPotMixing().mixPotion2(itemUsed, useWith);
}
BattleStaffs.makeBattleStaff(player, itemUsed, useWith);
@@ -5,7 +5,7 @@ import com.rs2.game.players.Player;
/**
* @author somedude, credits to Galkon for item weights
*/
public class Weight extends ItemDefinition {
public class Weight {
/**
* Calculates the weight when doing actions
@@ -16,27 +16,28 @@ public class Weight extends ItemDefinition {
* - deleteitem, additem, equip, unequip.
*/
public static void calcWeight(Player c, int item, String action) {
double weight = ItemDefinitions.getWeight(item);
if (action.equalsIgnoreCase("deleteitem")) {
if (getWeight(item) > 99.20) {
c.weight -= getWeight(item) / 100;
if (weight > 99.20) {
c.weight -= weight / 100;
if (c.weight < 0) {
c.weight = 0.0;
}
c.getPacketSender().writeWeight((int) c.weight);
return;
}
c.weight -= getWeight(item) / 10;
c.weight -= weight / 10;
if (c.weight < 0) {
c.weight = 0.0;
}
c.getPacketSender().writeWeight((int) c.weight);
} else if (action.equalsIgnoreCase("additem")) {
if (getWeight(item) > 99.20) {
c.weight += getWeight(item) / 100;
if (weight > 99.20) {
c.weight += weight / 100;
c.getPacketSender().writeWeight((int) c.weight);
return;
}
c.weight += getWeight(item) / 10;
c.weight += weight / 10;
c.getPacketSender().writeWeight((int) c.weight);
}
}
@@ -1,12 +1,13 @@
package com.rs2.game.items.impl;
import com.rs2.GameConstants;
import com.rs2.game.items.ItemAssistant;
import com.rs2.game.items.ItemData;
import com.rs2.game.items.DeprecatedItems;
import com.rs2.game.players.Player;
import static com.rs2.game.content.StaticItemList.*;
import org.apollo.cache.def.ItemDefinition;
/**
* Dye.java
*
@@ -51,13 +52,13 @@ public enum Dye {
};
public static boolean blockDye(Player player, Dye dye, int itemUsed, int useWith) {
if (itemUsed == dye.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && ItemData.itemIsNote[useWith]) {
if (itemUsed == dye.getItemUsed() && DeprecatedItems.getItemName(useWith).equalsIgnoreCase("Cape") && ItemDefinition.lookup(useWith).isNote()) {
player.getPacketSender().sendMessage("You can't dye a noted cape.");
return true;
} else if (itemUsed == dye.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && useWith == dye.getReward() && !ItemData.itemIsNote[useWith]) {
} else if (itemUsed == dye.getItemUsed() && DeprecatedItems.getItemName(useWith).equalsIgnoreCase("Cape") && useWith == dye.getReward() && !ItemDefinition.lookup(useWith).isNote()) {
player.getPacketSender().sendMessage("That cape is already that color.");
return true;
} else if (itemUsed == dye.getItemUsed() && !ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape")) {
} else if (itemUsed == dye.getItemUsed() && !DeprecatedItems.getItemName(useWith).equalsIgnoreCase("Cape")) {
return true;
}
return false;
@@ -68,7 +69,7 @@ public enum Dye {
if (blockDye(player, cape, itemUsed, useWith)) {
return;
}
if (itemUsed == cape.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && !ItemData.itemIsNote[useWith] && useWith != cape.getReward()) {
if (itemUsed == cape.getItemUsed() && DeprecatedItems.getItemName(useWith).equalsIgnoreCase("Cape") && !ItemDefinition.lookup(useWith).isNote() && useWith != cape.getReward()) {
player.getItemAssistant().deleteItem(itemUsed, 1);
player.getItemAssistant().deleteItem(useWith, 1);
player.getItemAssistant().addItem(cape.getReward(), 1);
@@ -1,7 +1,7 @@
package com.rs2.game.items.impl;
import com.rs2.game.content.music.sound.SoundList;
import com.rs2.game.items.ItemAssistant;
import com.rs2.game.items.DeprecatedItems;
import com.rs2.game.players.Player;
/**
@@ -15,7 +15,7 @@ public class HandleEmpty {
}
public static int filledToEmpty(Player c, int id) {
String itemName = ItemAssistant.getItemName(id);
String itemName = DeprecatedItems.getItemName(id);
if (!itemName.contains("Ring") && !itemName.contains("necklace")) {
if (itemName.contains("(3)") || itemName.contains("(4)") || itemName.contains("(2)") || itemName.contains("(1)") || itemName.contains("Weapon poison")) {
if (id != 1712 && id != 1710 && id != 1708 && id != 1706) {
@@ -51,7 +51,7 @@ public class HandleEmpty {
}
public static void handleEmptyItem(Player c, int itemId, int giveItem) {
final String name = ItemAssistant.getItemName(itemId);
final String name = DeprecatedItems.getItemName(itemId);
c.getPacketSender().sendMessage("You empty your " + name + ".");
c.getItemAssistant().deleteItem(itemId, 1);
c.getItemAssistant().addItem(giveItem, 1);
@@ -1,6 +1,6 @@
package com.rs2.game.items.impl;
import com.rs2.game.items.ItemAssistant;
import com.rs2.game.items.DeprecatedItems;
import com.rs2.game.players.Player;
/**
@@ -16,8 +16,8 @@ public class PotionMixing {
}
public void mixPotion2(int id, int id2) {
String id11 = ItemAssistant.getItemName(id);
String id22 = ItemAssistant.getItemName(id2);
String id11 = DeprecatedItems.getItemName(id);
String id22 = DeprecatedItems.getItemName(id2);
if (id11.substring(0, id11.indexOf("(")).equalsIgnoreCase(
id22.substring(0, id22.indexOf("(")))) {
try {
@@ -38,9 +38,9 @@ public class PotionMixing {
c.getItemAssistant().deleteItem(id2,
c.getItemAssistant().getItemSlot(id2), 1);
c.getItemAssistant().addItem(
c.getItemAssistant().getItemId(item1), 1);
DeprecatedItems.getItemId(item1), 1);
c.getItemAssistant().addItem(
c.getItemAssistant().getItemId(item2), 1);
DeprecatedItems.getItemId(item2), 1);
} else {
amount1 = totalAmount;
String item1 = id11.substring(0, id11.indexOf("(") + 1)
@@ -50,7 +50,7 @@ public class PotionMixing {
c.getItemAssistant().deleteItem(id2,
c.getItemAssistant().getItemSlot(id2), 1);
c.getItemAssistant().addItem(
c.getItemAssistant().getItemId(item1), 1);
DeprecatedItems.getItemId(item1), 1);
c.getItemAssistant().addItem(229, 1);
}
} catch (Exception e) {
@@ -1,7 +1,8 @@
package com.rs2.game.items.impl;
import java.util.HashMap;
import com.rs2.game.items.ItemAssistant;
import com.rs2.game.items.DeprecatedItems;
import com.rs2.game.players.Player;
/**
@@ -135,7 +136,7 @@ public class WeaponPoison {
if (weapon != null) {
for (int element[] : weapon.getNewItemId()) {
if (itemUse == element[0]) {
player.getPacketSender().sendMessage("You make a " + ItemAssistant.getItemName(element[1]) + ".");
player.getPacketSender().sendMessage("You make a " + DeprecatedItems.getItemName(element[1]) + ".");
player.getItemAssistant().deleteItem(element[0], player.getItemAssistant().getItemSlot(element[0]), 1);
player.getItemAssistant().deleteItem(weapon.getItemId(), player.getItemAssistant().getItemSlot(weapon.getItemId()), 1);
player.getItemAssistant().addItem(VIAL, 1);