mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-05 00:31:57 +00:00
Convert item definitions into JSON form and fix shop prices (#367)
* Created itemdef.json with same content as itemdefs.gsu. Still need to read from it * Converted a lot of IDs, not all * All the runelocus shop items are in realshopvalues.json, all the old ones are in the regular json. Keeping this commit just in case something goes horribly, horribly wrong. * Verified shop values are correct
This commit is contained in:
@@ -16,7 +16,7 @@ import com.rebotted.game.content.minigames.castlewars.CastleWars;
|
||||
import com.rebotted.game.content.minigames.trawler.Trawler;
|
||||
import com.rebotted.game.globalworldobjects.Doors;
|
||||
import com.rebotted.game.globalworldobjects.DoubleDoors;
|
||||
import com.rebotted.game.items.ItemDefinitions;
|
||||
import com.rebotted.game.items.ItemDefinition;
|
||||
import com.rebotted.game.npcs.NpcHandler;
|
||||
import com.rebotted.game.players.Client;
|
||||
import com.rebotted.game.players.Player;
|
||||
@@ -135,7 +135,7 @@ public class GameEngine {
|
||||
Region.load();
|
||||
Doors.getSingleton().load();
|
||||
DoubleDoors.getSingleton().load();
|
||||
ItemDefinitions.read();
|
||||
ItemDefinition.read();
|
||||
GlobalDropsHandler.initialize();
|
||||
Connection.initialize();
|
||||
HostBlacklist.loadBlacklist();
|
||||
|
||||
+93
-86
@@ -1,17 +1,19 @@
|
||||
package com.rebotted.game.items;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ItemDefinitions {
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class ItemDefinition {
|
||||
|
||||
public static ItemDefinitions getDef()[] {
|
||||
public static ItemDefinition getDefs()[] {
|
||||
return definitions;
|
||||
}
|
||||
|
||||
public ItemDefinitions() {
|
||||
public ItemDefinition() {
|
||||
name = null;
|
||||
itemDescription = null;
|
||||
shopValue = 0;
|
||||
@@ -31,10 +33,33 @@ public class ItemDefinitions {
|
||||
block = -1;
|
||||
id = -1;
|
||||
}
|
||||
|
||||
private static int id;
|
||||
|
||||
public static int getId() {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -43,96 +68,28 @@ public class ItemDefinitions {
|
||||
* Reads the definitions from the file.
|
||||
*/
|
||||
public static void read() {
|
||||
try {
|
||||
DataInputStream in = new DataInputStream(new FileInputStream("./data/data/itemdef.gsu"));
|
||||
total = in.readShort();
|
||||
if(definitions == null)
|
||||
definitions = new ItemDefinitions[total];
|
||||
for(int j = 0; j < total; j++) {
|
||||
if(definitions[j] == null) {
|
||||
definitions[j] = new ItemDefinitions();
|
||||
}
|
||||
definitions[j].getValues(in);
|
||||
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 (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the stream values.
|
||||
* @param in
|
||||
*/
|
||||
private void getValues(DataInputStream in) {
|
||||
try {
|
||||
do {
|
||||
int opcode = in.readByte();
|
||||
if(opcode == 0)
|
||||
return;
|
||||
if(opcode == 1) {
|
||||
name = in.readUTF();
|
||||
} else if(opcode == 2) {
|
||||
itemDescription = in.readUTF();
|
||||
} else if(opcode == 3) {
|
||||
shopValue = in.readInt();
|
||||
} else if(opcode == 4) {
|
||||
lowAlch = in.readInt();
|
||||
} else if(opcode == 5) {
|
||||
highAlch = in.readInt();
|
||||
} else if(opcode == 6) {
|
||||
isStackable = true;
|
||||
} else if(opcode == 7) {
|
||||
isNoteable = true;
|
||||
} else if(opcode == 8) {
|
||||
weight = in.readDouble();
|
||||
} else if(opcode == 9) {
|
||||
int length = in.readShort();
|
||||
bonuses = new double[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
bonuses[index] = in.readDouble();
|
||||
}
|
||||
} else if(opcode == 10) {
|
||||
stand = in.readShort();
|
||||
} else if(opcode == 11) {
|
||||
walk = in.readShort();
|
||||
} else if(opcode == 12) {
|
||||
run = in.readShort();
|
||||
} else if(opcode == 13) {
|
||||
turn90left = in.readShort();
|
||||
} else if(opcode == 14) {
|
||||
turn90right = in.readShort();
|
||||
} else if(opcode == 15) {
|
||||
turn180 = in.readShort();
|
||||
} else if(opcode == 16) {
|
||||
attack = in.readShort();
|
||||
} else if(opcode == 17) {
|
||||
block = in.readShort();
|
||||
} else {
|
||||
System.out.println("Unrecognized opcode: " + opcode);
|
||||
}
|
||||
} while(true);
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
definitions = Arrays.copyOf(definitionsAL.toArray(), definitionsAL.size(), ItemDefinition[].class);
|
||||
}
|
||||
|
||||
/**
|
||||
* The item definition cache.
|
||||
*/
|
||||
public static ItemDefinitions definitions[];
|
||||
public static ItemDefinition[] definitions;
|
||||
|
||||
/**
|
||||
* The total items read from the definitions.
|
||||
*/
|
||||
public static int total;
|
||||
|
||||
/**
|
||||
* Returns the total item number.
|
||||
*/
|
||||
public static int getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* The item name.
|
||||
*/
|
||||
@@ -210,7 +167,7 @@ public class ItemDefinitions {
|
||||
* Can the item be noted?
|
||||
*/
|
||||
public boolean isNoteable;
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the item can be noted.
|
||||
*/
|
||||
@@ -341,4 +298,54 @@ public class ItemDefinitions {
|
||||
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 +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.rebotted.game.players.Player;
|
||||
/**
|
||||
* @author somedude, credits to Galkon for item weights
|
||||
*/
|
||||
public class Weight extends ItemDefinitions {
|
||||
public class Weight extends ItemDefinition {
|
||||
|
||||
/**
|
||||
* Calculates the weight when doing actions
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.rebotted.GameConstants;
|
||||
import com.rebotted.game.bots.BotHandler;
|
||||
import com.rebotted.game.items.Item;
|
||||
import com.rebotted.game.items.ItemAssistant;
|
||||
import com.rebotted.game.items.ItemDefinitions;
|
||||
import com.rebotted.game.items.ItemDefinition;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.game.players.PlayerHandler;
|
||||
import com.rebotted.util.GameLogger;
|
||||
@@ -100,8 +100,8 @@ public class ShopAssistant {
|
||||
double ShopValue = 1;
|
||||
double TotPrice = 0;
|
||||
double sellingRatio = isSelling ? 0.85 : 1;
|
||||
if (ItemDefinitions.getDef()[ItemID] != null) {
|
||||
ShopValue = ItemDefinitions.getDef()[ItemID].highAlch / 3.0 * 5.0 * sellingRatio;
|
||||
if (ItemDefinition.getDefs()[ItemID] != null) {
|
||||
ShopValue = ItemDefinition.getDefs()[ItemID].highAlch / 3.0 * 5.0 * sellingRatio;
|
||||
}
|
||||
|
||||
TotPrice = ShopValue;
|
||||
@@ -409,7 +409,7 @@ public class ShopAssistant {
|
||||
currency = 995;
|
||||
}
|
||||
|
||||
boolean isStackable = ItemDefinitions.getDef()[itemID].isStackable;
|
||||
boolean isStackable = ItemDefinition.getDefs()[itemID].isStackable;
|
||||
|
||||
if (!player.getItemAssistant().playerHasItem(currency) && isStackable && amount < inventoryAmount && player.getItemAssistant().freeSlots() <= 0) {
|
||||
player.getPacketSender().sendMessage("You don't have enough space in your inventory.");
|
||||
@@ -490,7 +490,7 @@ public class ShopAssistant {
|
||||
int notedItemID = getNoted(itemID);
|
||||
boolean isPlayerShop = ShopHandler.shopBModifier[player.shopId] == 0;
|
||||
// Items are stackable if from a player owned shop and notable
|
||||
boolean isStackable = ItemDefinitions.getDef()[itemID].isStackable || (isPlayerShop && getNoted(itemID) != itemID);
|
||||
boolean isStackable = ItemDefinition.getDefs()[itemID].isStackable || (isPlayerShop && getNoted(itemID) != itemID);
|
||||
int freeSlots = player.getItemAssistant().freeSlots();
|
||||
int storeQty = ShopHandler.getStock(shopID, itemID);
|
||||
if (amount > 0) {
|
||||
|
||||
Reference in New Issue
Block a user