[FEATURE] Data will now use json (#417)

* [FEATURE] Item data is now loaded from json

* [TASK] Renamed the old method into it's new use

* [TASK] Removed unused code

* [FEATURE] Added some more json's

* [CLEANUP] Code cleanup

* [FEATURE] NPC drops are now in json

* [CLEANUP] Removed testing class
This commit is contained in:
Sandro Coutinho
2020-08-13 17:50:04 +01:00
committed by GitHub
parent 09343c6a8c
commit 8a6cf6f1ae
33 changed files with 513556 additions and 22340 deletions
@@ -1,279 +1,317 @@
package com.rebotted.game.globalworldobjects;
import java.util.ArrayList;
import java.util.List;
import java.io.*;
import java.util.Scanner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rebotted.GameEngine;
import com.rebotted.game.objects.Objects;
import com.rebotted.game.players.Player;
import com.rebotted.util.DoorData;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Doors {
private static Doors singleton = null;
private static Doors singleton = null;
private List<Doors> doors = new ArrayList<Doors>();
private final List<Doors> doors = new ArrayList<>();
private File doorFile;
public static Doors getSingleton() {
if (singleton == null) {
singleton = new Doors(System.getProperty("user.dir") + "/data/doors.txt");
}
return singleton;
}
private File doorFile;
private Doors(String file){
doorFile = new File(file);
}
private Doors(int door, int x, int y, int z, int face, int type, int open) {
this.doorId = door;
this.originalId = door;
this.doorX = x;
this.doorY = y;
this.originalX = x;
this.originalY = y;
this.doorZ = z;
this.originalFace = face;
this.currentFace = face;
this.type = type;
this.open = open;
}
private Doors getDoor(int id, int x, int y, int z) {
for (Doors d : doors) {
if (d.doorId == id) {
if (d.doorX == x && d.doorY == y && d.doorZ == z) {
return d;
}
}
}
return null;
}
public static Doors getSingleton() {
if (singleton == null) {
singleton = new Doors(System.getProperty("user.dir") + "/data/doors.json");
}
return singleton;
}
public boolean handleDoor(Player player, int id, int x, int y, int z) {
Doors d = getDoor(id, x, y, z);
private Doors(String file) {
doorFile = new File(file);
}
if (d == null) {
//System.out.println("D: " + id + " null debug x: " + x + " y: " + y + ".");
return DoubleDoors.getSingleton().handleDoor(player, id, x, y, z);
}
private Doors(int door, int x, int y, int z, int face, int type, int open) {
this.doorId = door;
this.originalId = door;
this.doorX = x;
this.doorY = y;
this.originalX = x;
this.originalY = y;
this.doorZ = z;
this.originalFace = face;
this.currentFace = face;
this.type = type;
this.open = open;
}
//todo: improvment: if player manage to get to door then open the door.
if(player.distanceToPoint(x, y) > 1) {
//System.out.println("Door (single): " + id + " not in distance debug at x: " + x + " y: " + y + ".");
return false;
}
private Doors getDoor(int id, int x, int y, int z) {
for (Doors d : doors) {
if (d.doorId == id) {
if (d.doorX == x && d.doorY == y && d.doorZ == z) {
return d;
}
}
}
return null;
}
//Remove clipping for old door (gets added back in placeObject)
//Region.removeClipping(x, y, z);
public boolean handleDoor(Player player, int id, int x, int y, int z) {
Doors d = getDoor(id, x, y, z);
int xAdjustment = 0, yAdjustment = 0;
if (d.type == 0) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
yAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
yAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
yAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
yAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
} else if (d.type == 9) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
}
if (xAdjustment != 0 || yAdjustment != 0) {
Objects o = new Objects(-1, d.doorX, d.doorY, d.doorZ, 0, d.type, 0);
GameEngine.objectHandler.placeObject(o);
}
if (d.doorX == d.originalX && d.doorY == d.originalY) {
d.doorX += xAdjustment;
d.doorY += yAdjustment;
} else {
Objects o = new Objects(-1, d.doorX, d.doorY, d.doorZ, 0, d.type, 0);
GameEngine.objectHandler.placeObject(o);
d.doorX = d.originalX;
d.doorY = d.originalY;
}
if (d.doorId == d.originalId) {
if (d.open == 0) {
d.doorId += 1;
} else if (d.open == 1) {
d.doorId -= 1;
}
} else if (d.doorId != d.originalId) {
if (d.open == 0) {
d.doorId -= 1;
} else if (d.open == 1) {
d.doorId += 1;
}
}
GameEngine.objectHandler.placeObject(new Objects(d.doorId, d.doorX, d.doorY, d.doorZ, getNextFace(d), d.type, 0));
return true;
}
private int getNextFace(Doors d) {
int f = d.originalFace;
if (d.type == 0) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 3;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 0;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
}
}
} else if (d.type == 9) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 0;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
}
}
}
d.currentFace = f;
return f;
}
public void load() {
//long start = System.currentTimeMillis();
try {
singleton.processLineByLine();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//System.out.println("Loaded "+ doors.size() +" doors in "+ (System.currentTimeMillis() - start) +"ms.");
}
private final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(new FileReader(doorFile));
try {
while(scanner.hasNextLine()) {
processLine(scanner.nextLine());
}
} finally {
scanner.close();
}
}
protected void processLine(String line){
Scanner scanner = new Scanner(line);
scanner.useDelimiter(" ");
try {
while(scanner.hasNextLine()) {
int id = Integer.parseInt(scanner.next());
int x = Integer.parseInt(scanner.next());
int y = Integer.parseInt(scanner.next());
int f = Integer.parseInt(scanner.next());
int z = Integer.parseInt(scanner.next());
int t = Integer.parseInt(scanner.next());
doors.add(new Doors(id,x,y,z,f,t,alreadyOpen(id)?1:0));
}
} finally {
scanner.close();
}
}
private boolean alreadyOpen(int id) {
for (int i = 0; i < openDoors.length; i++) {
if (openDoors[i] == id) {
return true;
}
}
return false;
}
if (d == null) {
//System.out.println("D: " + id + " null debug x: " + x + " y: " + y + ".");
return DoubleDoors.getSingleton().handleDoor(player, id, x, y, z);
}
//todo: improvment: if player manage to get to door then open the door.
if (player.distanceToPoint(x, y) > 1) {
//System.out.println("Door (single): " + id + " not in distance debug at x: " + x + " y: " + y + ".");
return false;
}
//Remove clipping for old door (gets added back in placeObject)
//Region.removeClipping(x, y, z);
int xAdjustment = 0, yAdjustment = 0;
if (d.type == 0) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
yAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
yAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
yAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
yAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
} else if (d.type == 9) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
}
if (xAdjustment != 0 || yAdjustment != 0) {
Objects o = new Objects(-1, d.doorX, d.doorY, d.doorZ, 0, d.type, 0);
GameEngine.objectHandler.placeObject(o);
}
if (d.doorX == d.originalX && d.doorY == d.originalY) {
d.doorX += xAdjustment;
d.doorY += yAdjustment;
} else {
Objects o = new Objects(-1, d.doorX, d.doorY, d.doorZ, 0, d.type, 0);
GameEngine.objectHandler.placeObject(o);
d.doorX = d.originalX;
d.doorY = d.originalY;
}
if (d.doorId == d.originalId) {
if (d.open == 0) {
d.doorId += 1;
} else if (d.open == 1) {
d.doorId -= 1;
}
} else if (d.doorId != d.originalId) {
if (d.open == 0) {
d.doorId -= 1;
} else if (d.open == 1) {
d.doorId += 1;
}
}
GameEngine.objectHandler.placeObject(new Objects(d.doorId, d.doorX, d.doorY, d.doorZ, getNextFace(d), d.type, 0));
return true;
}
private int getNextFace(Doors d) {
int f = d.originalFace;
if (d.type == 0) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 3;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 0;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
}
} else if (d.type == 9) {
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 0;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
}
}
d.currentFace = f;
return f;
}
public void load() {
Gson gson = new Gson();
//long start = System.currentTimeMillis();
try {
Type collectionType = new TypeToken<DoorData[]>() {
}.getType();
DoorData[] doorData = gson.fromJson(new FileReader(doorFile), collectionType);
for (DoorData data : doorData) {
for (DoorData.Location location : data.getLocations()) {
doors.add(new Doors(data.getId(), location.getX(), location.getY(), location.getHeight(), data.getFace(), data.getType(), alreadyOpen(data.getId()) ? 1 : 0));
}
}
//singleton.writeJsonDump();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//System.out.println("Loaded "+ doors.size() +" doors in "+ (System.currentTimeMillis() - start) +" ms.");
}
private void writeJsonDump() throws FileNotFoundException {
try (Scanner scanner = new Scanner(new FileReader(doorFile))) {
while (scanner.hasNextLine()) {
processLine(scanner.nextLine());
}
}
}
protected void processLine(String line) {
JSONArray array = new JSONArray();
Scanner scanner = new Scanner(line);
scanner.useDelimiter(" ");
try {
while (scanner.hasNextLine()) {
int id = Integer.parseInt(scanner.next());
int x = Integer.parseInt(scanner.next());
int y = Integer.parseInt(scanner.next());
int face = Integer.parseInt(scanner.next());
int height = Integer.parseInt(scanner.next());
int type = Integer.parseInt(scanner.next());
JSONObject object = new JSONObject();
object.put("id", id);
JSONArray jsonArray = new JSONArray();
JSONObject object1 = new JSONObject();
object1.put("x", x);
object1.put("y", y);
object1.put("height", height);
jsonArray.put(0, object1);
object.put("location", jsonArray);
object.put("face", face);
object.put("type", type);
array.put(object);
}
} finally {
scanner.close();
try {
FileWriter fileWriter = new FileWriter("doors-dump.json");
fileWriter.write(array.toString());
System.out.println(array.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
private boolean alreadyOpen(int id) {
for (int openDoor : OPEN_DOORS) {
if (openDoor == id) {
return true;
}
}
return false;
}
private int doorId;
private int originalId;
private int doorX;
private int doorY;
private int originalX;
private int originalY;
private int doorZ;
private int originalFace;
private int currentFace;
private int type;
private int open;
private static final int[] OPEN_DOORS = {
1504, 1514, 1517, 1520, 1531,
1534, 2033, 2035, 2037, 2998,
3271, 4468, 4697, 6101, 6103,
6105, 6107, 6109, 6111, 6113,
6115, 6976, 6978, 8696, 8819,
10261, 10263, 10265, 11708, 11710,
11712, 11715, 11994, 12445, 13002,
};
private int doorId;
private int originalId;
private int doorX;
private int doorY;
private int originalX;
private int originalY;
private int doorZ;
private int originalFace;
private int currentFace;
private int type;
private int open;
private static int[] openDoors = {
1504, 1514, 1517, 1520, 1531,
1534, 2033, 2035, 2037, 2998,
3271, 4468, 4697, 6101,6103,
6105, 6107, 6109, 6111, 6113,
6115, 6976, 6978, 8696, 8819,
10261, 10263,10265,11708,11710,
11712,11715,11994,12445, 13002,
};
}
@@ -1,393 +1,429 @@
package com.rebotted.game.globalworldobjects;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rebotted.GameEngine;
import com.rebotted.game.objects.Objects;
import com.rebotted.game.players.Player;
import com.rebotted.util.DoorData;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*
* @author Killamess
*
*/
public class DoubleDoors {
private static DoubleDoors singleton = null;
private List<DoubleDoors> doors = new ArrayList<DoubleDoors>();
private static DoubleDoors singleton = null;
private File doorFile;
public static DoubleDoors getSingleton() {
if (singleton == null) {
singleton = new DoubleDoors("./data/doubledoors.txt");
}
return singleton;
}
private final List<DoubleDoors> doors = new ArrayList<>();
private DoubleDoors(String file){
doorFile = new File(file);
}
private DoubleDoors getDoor(int id, int x, int y, int z) {
for (DoubleDoors d : doors) {
if (d.doorId == id) {
if (d.x == x && d.y == y && d.z == z) {
return d;
}
}
}
return null;
}
public boolean handleDoor(Player player, int id, int x, int y, int z) {
DoubleDoors doorClicked = getDoor(id, x, y, z);
private File doorFile;
if (doorClicked == null) {
//System.out.println("Door: " + id + " null debug at x: " + x + " y: " + y + ".");
//GameEngine.objectHandler.placeObject(new Objects(-1, x, y, z, 0, 0, 0));
return true;
}
if (doorClicked.doorId > 15000) {
// System.out.println("Door: " + id + " clicking debug x: " + x + " y: " + y + ".");
return true; //nearly all of these are not opened
}
public static DoubleDoors getSingleton() {
if (singleton == null) {
singleton = new DoubleDoors(System.getProperty("user.dir") + "/data/doubledoors.json");
}
return singleton;
}
//Region.removeClipping(x, y, z);
private DoubleDoors(String file) {
doorFile = new File(file);
}
if (doorClicked.open == 0) {
if (doorClicked.originalFace == 0) {
DoubleDoors lowerDoor = getDoor(id - 3, x, y -1, z);
DoubleDoors upperDoor = getDoor(id + 3, x, y +1, z);
if (lowerDoor != null) {
changeLeftDoor(lowerDoor);
changeRightDoor(doorClicked);
} else if (upperDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(upperDoor);
}
} else if (doorClicked.originalFace == 1) {
DoubleDoors westDoor = getDoor(id - 3, x -1, y, z);
DoubleDoors eastDoor = getDoor(id + 3, x +1, y, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (eastDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(eastDoor);
}
} else if (doorClicked.originalFace == 2) {
DoubleDoors lowerDoor = getDoor(id - 3, x, y +1, z);
DoubleDoors upperDoor = getDoor(id + 3, x, y -1, z);
if (lowerDoor != null) {
changeLeftDoor(lowerDoor);
changeRightDoor(doorClicked);
} else if (upperDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(upperDoor);
}
} else if (doorClicked.originalFace == 3) {
DoubleDoors westDoor = getDoor(id + 3, x -1, y, z);
DoubleDoors eastDoor = getDoor(id - 3, x +1, y, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (eastDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(eastDoor);
}
}
} else if (doorClicked.open == 1) {
if (doorClicked.originalFace == 0) {
DoubleDoors westDoor = getDoor(id - 3, x -1, y, z);
DoubleDoors upperDoor = getDoor(id + 3, x +1, y, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (upperDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(upperDoor);
}
} else if (doorClicked.originalFace == 1) {
DoubleDoors northDoor = getDoor(id - 3, x, y + 1, z);
DoubleDoors southDoor = getDoor(id + 3, x, y -1, z);
if (northDoor != null) {
changeLeftDoor(northDoor);
changeRightDoor(doorClicked);
} else if (southDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(southDoor);
}
} else if (doorClicked.originalFace == 2) {
DoubleDoors westDoor = getDoor(id - 3, x -1, y, z);
DoubleDoors eastDoor = getDoor(id + 3, x, y -1, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (eastDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(eastDoor);
}
} else if (doorClicked.originalFace == 3) {
DoubleDoors northDoor = getDoor(id - 3, x, y + 1, z);
DoubleDoors southDoor = getDoor(id + 3, x, y -1, z);
if (northDoor != null) {
changeLeftDoor(northDoor);
changeRightDoor(doorClicked);
} else if (southDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(southDoor);
}
}
}
return true;
}
private DoubleDoors getDoor(int id, int x, int y, int z) {
for (DoubleDoors d : doors) {
if (d.doorId == id) {
if (d.x == x && d.y == y && d.z == z) {
return d;
}
}
}
return null;
}
public void changeLeftDoor(DoubleDoors d) {
int xAdjustment = 0, yAdjustment = 0;
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
yAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = +1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
yAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
yAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = -1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
if (xAdjustment != 0 || yAdjustment != 0) {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
}
if (d.x == d.originalX && d.y == d.originalY) {
d.x += xAdjustment;
d.y += yAdjustment;
} else {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
d.x = d.originalX;
d.y = d.originalY;
}
if (d.doorId == d.originalId) {
if (d.open == 0) {
d.doorId += 1;
} else if (d.open == 1) {
d.doorId -= 1;
}
} else if (d.doorId != d.originalId) {
if (d.open == 0) {
d.doorId = d.originalId;
} else if (d.open == 1) {
d.doorId = d.originalId;
}
}
GameEngine.objectHandler.placeObject(new Objects(d.doorId, d.x, d.y, d.z, getNextLeftFace(d), 0, 0));
}
private int getNextLeftFace(DoubleDoors d) {
int f = d.originalFace;
public boolean handleDoor(Player player, int id, int x, int y, int z) {
DoubleDoors doorClicked = getDoor(id, x, y, z);
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 0;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
}
}
d.currentFace = f;
return f;
}
public void changeRightDoor(DoubleDoors d) {
int xAdjustment = 0, yAdjustment = 0;
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
yAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = +1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
yAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = -1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
yAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
if (xAdjustment != 0 || yAdjustment != 0) {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
}
if (d.x == d.originalX && d.y == d.originalY) {
d.x += xAdjustment;
d.y += yAdjustment;
} else {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
d.x = d.originalX;
d.y = d.originalY;
}
if (d.doorId == d.originalId) {
if (d.open == 0) {
d.doorId += 1;
} else if (d.open == 1) {
d.doorId -= 1;
}
} else if (d.doorId != d.originalId) {
if (d.open == 0) {
d.doorId = d.originalId;
} else if (d.open == 1) {
d.doorId = d.originalId;
}
}
GameEngine.objectHandler.placeObject(new Objects(d.doorId, d.x, d.y, d.z, getNextRightFace(d), 0, 0));
}
private int getNextRightFace(DoubleDoors d) {
int f = d.originalFace;
if (doorClicked == null) {
//System.out.println("Door: " + id + " null debug at x: " + x + " y: " + y + ".");
//GameEngine.objectHandler.placeObject(new Objects(-1, x, y, z, 0, 0, 0));
return true;
}
if (doorClicked.doorId > 15000) {
// System.out.println("Door: " + id + " clicking debug x: " + x + " y: " + y + ".");
return true; //nearly all of these are not opened
}
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 3;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
//Region.removeClipping(x, y, z);
if (doorClicked.open == 0) {
if (doorClicked.originalFace == 0) {
DoubleDoors lowerDoor = getDoor(id - 3, x, y - 1, z);
DoubleDoors upperDoor = getDoor(id + 3, x, y + 1, z);
if (lowerDoor != null) {
changeLeftDoor(lowerDoor);
changeRightDoor(doorClicked);
} else if (upperDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(upperDoor);
}
} else if (doorClicked.originalFace == 1) {
DoubleDoors westDoor = getDoor(id - 3, x - 1, y, z);
DoubleDoors eastDoor = getDoor(id + 3, x + 1, y, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (eastDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(eastDoor);
}
} else if (doorClicked.originalFace == 2) {
DoubleDoors lowerDoor = getDoor(id - 3, x, y + 1, z);
DoubleDoors upperDoor = getDoor(id + 3, x, y - 1, z);
if (lowerDoor != null) {
changeLeftDoor(lowerDoor);
changeRightDoor(doorClicked);
} else if (upperDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(upperDoor);
}
} else if (doorClicked.originalFace == 3) {
DoubleDoors westDoor = getDoor(id + 3, x - 1, y, z);
DoubleDoors eastDoor = getDoor(id - 3, x + 1, y, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (eastDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(eastDoor);
}
}
} else if (doorClicked.open == 1) {
if (doorClicked.originalFace == 0) {
DoubleDoors westDoor = getDoor(id - 3, x - 1, y, z);
DoubleDoors upperDoor = getDoor(id + 3, x + 1, y, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (upperDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(upperDoor);
}
} else if (doorClicked.originalFace == 1) {
DoubleDoors northDoor = getDoor(id - 3, x, y + 1, z);
DoubleDoors southDoor = getDoor(id + 3, x, y - 1, z);
if (northDoor != null) {
changeLeftDoor(northDoor);
changeRightDoor(doorClicked);
} else if (southDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(southDoor);
}
} else if (doorClicked.originalFace == 2) {
DoubleDoors westDoor = getDoor(id - 3, x - 1, y, z);
DoubleDoors eastDoor = getDoor(id + 3, x, y - 1, z);
if (westDoor != null) {
changeLeftDoor(westDoor);
changeRightDoor(doorClicked);
} else if (eastDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(eastDoor);
}
} else if (doorClicked.originalFace == 3) {
DoubleDoors northDoor = getDoor(id - 3, x, y + 1, z);
DoubleDoors southDoor = getDoor(id + 3, x, y - 1, z);
if (northDoor != null) {
changeLeftDoor(northDoor);
changeRightDoor(doorClicked);
} else if (southDoor != null) {
changeLeftDoor(doorClicked);
changeRightDoor(southDoor);
}
}
}
return true;
}
public void changeLeftDoor(DoubleDoors d) {
int xAdjustment = 0, yAdjustment = 0;
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
yAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = +1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
yAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
yAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = -1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
if (xAdjustment != 0 || yAdjustment != 0) {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
}
if (d.x == d.originalX && d.y == d.originalY) {
d.x += xAdjustment;
d.y += yAdjustment;
} else {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
d.x = d.originalX;
d.y = d.originalY;
}
if (d.doorId == d.originalId) {
if (d.open == 0) {
d.doorId += 1;
} else if (d.open == 1) {
d.doorId -= 1;
}
} else if (d.doorId != d.originalId) {
if (d.open == 0) {
d.doorId = d.originalId;
} else if (d.open == 1) {
d.doorId = d.originalId;
}
}
GameEngine.objectHandler.placeObject(new Objects(d.doorId, d.x, d.y, d.z, getNextLeftFace(d), 0, 0));
}
private int getNextLeftFace(DoubleDoors d) {
int f = d.originalFace;
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 0;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
}
d.currentFace = f;
return f;
}
public void changeRightDoor(DoubleDoors d) {
int xAdjustment = 0, yAdjustment = 0;
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = -1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
yAdjustment = 1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
xAdjustment = +1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
yAdjustment = -1;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
xAdjustment = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
xAdjustment = -1;
} else if (d.originalFace == 2 && d.currentFace == 2) {
yAdjustment = -1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
xAdjustment = -1;
}
}
if (xAdjustment != 0 || yAdjustment != 0) {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
}
if (d.x == d.originalX && d.y == d.originalY) {
d.x += xAdjustment;
d.y += yAdjustment;
} else {
GameEngine.objectHandler.placeObject(new Objects(-1, d.x, d.y, d.z, 0, 0, 0));
d.x = d.originalX;
d.y = d.originalY;
}
if (d.doorId == d.originalId) {
if (d.open == 0) {
d.doorId += 1;
} else if (d.open == 1) {
d.doorId -= 1;
}
} else if (d.doorId != d.originalId) {
if (d.open == 0) {
d.doorId = d.originalId;
} else if (d.open == 1) {
d.doorId = d.originalId;
}
}
GameEngine.objectHandler.placeObject(new Objects(d.doorId, d.x, d.y, d.z, getNextRightFace(d), 0, 0));
}
private int getNextRightFace(DoubleDoors d) {
int f = d.originalFace;
if (d.open == 0) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 1;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 2;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 3;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace) {
f = d.originalFace;
}
}
d.currentFace = f;
return f;
}
private int doorId;
private int originalId;
private int open;
private int x;
private int y;
private int z;
private int originalX;
private int originalY;
private int currentFace;
private int originalFace;
public DoubleDoors(int id, int x, int y, int z, int f, int open) {
this.doorId = id;
this.originalId = id;
this.open = open;
this.x = x;
this.originalX = x;
this.y = y;
this.z = z;
this.originalY = y;
this.currentFace = f;
this.originalFace = f;
}
public boolean isOpenDoor(int id) {
for (int openDoor : OPEN_DOORS) {
if (id == openDoor || id + 3 == openDoor) {
return true;
}
}
return false;
}
//Have not found any others yet. Maybe only 1 type of double
//doors exist to operate.
private static final int[] OPEN_DOORS = {
1520, 1517
};
public void load() {
Gson gson = new Gson();
long start = System.currentTimeMillis();
try {
Type collectionType = new TypeToken<DoorData[]>() {
}.getType();
DoorData[] doorData = gson.fromJson(new FileReader(doorFile), collectionType);
for (DoorData data : doorData) {
for (DoorData.Location location : data.getLocations()) {
doors.add(new DoubleDoors(data.getId(), location.getX(), location.getY(), location.getHeight(), data.getFace(), isOpenDoor(data.getId()) ? 1 : 0));
}
}
//singleton.writeJsonDump();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
System.out.println("Loaded "+ doors.size() +" Double doors in "+ (System.currentTimeMillis() - start) +"ms.");
}
private void writeJsonDump() throws FileNotFoundException {
try (Scanner scanner = new Scanner(new FileReader(doorFile))) {
while (scanner.hasNextLine()) {
processLine(scanner.nextLine());
}
}
}
protected void processLine(String line) {
JSONArray array = new JSONArray();
Scanner scanner = new Scanner(line);
scanner.useDelimiter(" ");
try {
while (scanner.hasNextLine()) {
int id = Integer.parseInt(scanner.next());
int x = Integer.parseInt(scanner.next());
int y = Integer.parseInt(scanner.next());
int f = Integer.parseInt(scanner.next());
int z = Integer.parseInt(scanner.next());
JSONObject object = new JSONObject();
object.put("id", id);
JSONArray jsonArray = new JSONArray();
JSONObject object1 = new JSONObject();
object1.put("x", x);
object1.put("y", y);
object1.put("height", z);
jsonArray.put(0, object1);
object.put("locations", jsonArray);
object.put("face", f);
array.put(object);
}
} finally {
scanner.close();
try {
FileWriter fileWriter = new FileWriter("doubledoors-dump.json");
fileWriter.write(array.toString());
System.out.println(array.toString());
} catch (IOException e) {
e.printStackTrace();
}
} else if (d.open == 1) {
if (d.originalFace == 0 && d.currentFace == 0) {
f = 3;
} else if (d.originalFace == 1 && d.currentFace == 1) {
f = 0;
} else if (d.originalFace == 2 && d.currentFace == 2) {
f = 1;
} else if (d.originalFace == 3 && d.currentFace == 3) {
f = 2;
} else if (d.originalFace != d.currentFace){
f = d.originalFace;
}
}
d.currentFace = f;
return f;
}
private int doorId;
private int originalId;
private int open;
private int x;
private int y;
private int z;
private int originalX;
private int originalY;
private int currentFace;
private int originalFace;
public DoubleDoors(int id, int x, int y, int z, int f, int open) {
this.doorId = id;
this.originalId = id;
this.open = open;
this.x = x;
this.originalX = x;
this.y = y;
this.z = z;
this.originalY = y;
this.currentFace = f;
this.originalFace = f;
}
public boolean isOpenDoor(int id){
for (int i = 0; i < openDoors.length; i++) {
if (id == openDoors[i] || id + 3 == openDoors[i]) {
return true;
}
}
return false;
}
//Have not found any others yet. Maybe only 1 type of double
//doors exist to operate.
private static int[] openDoors = {
1520, 1517
};
public void load() {
//long start = System.currentTimeMillis();
try {
singleton.processLineByLine();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//System.out.println("Loaded "+ doors.size() +" Double doors in "+ (System.currentTimeMillis() - start) +"ms.");
}
private final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(new FileReader(doorFile));
try {
while(scanner.hasNextLine()) {
processLine(scanner.nextLine());
}
} finally {
scanner.close();
}
}
protected void processLine(String line){
Scanner scanner = new Scanner(line);
scanner.useDelimiter(" ");
try {
while(scanner.hasNextLine()) {
int id = Integer.parseInt(scanner.next());
int x = Integer.parseInt(scanner.next());
int y = Integer.parseInt(scanner.next());
int f = Integer.parseInt(scanner.next());
int z = Integer.parseInt(scanner.next());
doors.add(new DoubleDoors(id, x, y, z, f, isOpenDoor(id) ? 1 : 0));
}
} finally {
scanner.close();
}
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -2,6 +2,8 @@ package com.rebotted.game.npcs.drops;
import com.rebotted.util.Misc;
import java.util.Arrays;
public class ItemDrop {
public int item_id, chance;
public int[] amounts;
@@ -29,4 +31,13 @@ public class ItemDrop {
public int getAmount(){
return Misc.random(this.amounts[0], this.amounts[1]);
}
@Override
public String toString() {
return "ItemDrop{" +
"item_id=" + item_id +
", chance=" + chance +
", amounts=" + Arrays.toString(amounts) +
'}';
}
}
File diff suppressed because it is too large Load Diff
@@ -1,250 +1,97 @@
package com.rebotted.game.npcs.drops;
import com.google.gson.Gson;
import com.rebotted.GameEngine;
import com.rebotted.game.items.ItemList;
import com.rebotted.util.Misc;
import com.rebotted.util.NpcDrop;
import java.io.FileNotFoundException;
import java.io.FileReader;
/**
* Npc Drops Handler
* @author Andrew (Mr Extremez)
*
* @author Andrew (Mr Extremez), SandroC
*/
public class NPCDropsHandler {
private static NpcDrop[] npcDrops;
public static int // found on http://runescape.wikia.com/wiki/Drop_rate
ALWAYS = 0,
COINSRATE = 3,
COMMON = 32,
UNCOMMON = 64,
RARE = 256,
VERY_RARE = 512;
/*public static int // found on http://runescape.wikia.com/wiki/Drop rate
ALWAYS = 0,
COINSRATE = 3,
COMMON = 32,
UNCOMMON = 64,
RARE = 256,
VERY_RARE = 512;*/
/**
* Handles the npc drops for the npc names.
*
* @param NPCId
* @return
*/
public static final ItemDrop[] NPC_DROPS(String npc, int NPCId) {
if (npc.equals("man") || npc.equals("woman") || npc.equals("drunken_man")) {
return NPCDrops.man;
} else if (npc.equals("skeletal_wyvern")) {
return NPCDrops.wyvern;
} else if (npc.equals("dark_beast")) {
return NPCDrops.darkbeast;
} else if (npc.equals("shade")) {
return NPCDrops.shade;
} else if (npc.equals("watchman")) {
return NPCDrops.watchman;
} else if (npc.equals("river_troll")) {
return NPCDrops.rivertroll;
} else if (npc.equals("cave_crawler")) {
return NPCDrops.cavecrawler;
} else if (npc.equals("thief")) {
return NPCDrops.thief;
} else if (npc.equals("tzhaar-xil") || npc.equals("Tzhaar-Xil")) {
return NPCDrops.tzhaarxil;
} else if (npc.equals("tzhaar-ket") || npc.equals("Tzhaar-Ket")) {
return NPCDrops.tzhaarket;
} else if (npc.equals("tzhaar-hur") || npc.equals("Tzhaar-Hur")) {
return NPCDrops.tzhaarhur;
} else if (npc.equals("tzhaar-mej") || npc.equals("Tzhaar-Mej")) {
return NPCDrops.tzhaarmej;
} else if (npc.equals("tree_spirit")) {
return NPCDrops.treespirit;
} else if (npc.equals("unicorn")) {
return NPCDrops.unicorn;
} else if (npc.equals("evil_chicken")) {
return NPCDrops.evilchicken;
} else if (npc.equals("white_knight")) {
return NPCDrops.whiteknight;
} else if (npc.equals("black_knight")) {
return NPCDrops.blackknight;
} else if (npc.equals("bear")) {
return NPCDrops.bear;
} else if (npc.equals("jogre")) {
return NPCDrops.jogre;
} else if (npc.equals("ogre")) {
return NPCDrops.ogre;
} else if (npc.equals("chaos_druid")) {
return NPCDrops.chaosdruid;
} else if (npc.equals("jailer")) {
return NPCDrops.jailer;
} else if (npc.equals("fire_giant") || npc.equals("Fire_giant")) {
return NPCDrops.firegiant;
} else if (npc.equals("basilisk")) {
return NPCDrops.basilisk;
} else if (npc.equals("baby_blue_dragon") || npc.equals("baby_red_dragon") || npc.equals("baby_dragon")) {
return NPCDrops.babybluedragon;
} else if (npc.equals("red_dragon")) {
return NPCDrops.reddragon;
} else if (npc.equals("elf_warrior")) {
return NPCDrops.elfwarrior;
} else if (npc.equals("dagannoth")) {
return NPCDrops.dagannoth;
} else if (npc.equals("giant_mole")) {
return NPCDrops.giantmole;
} else if (npc.equals("dagannoth_supreme")) {
return NPCDrops.dagannothsupereme;
} else if (npc.equals("chaos_elemental")) {
return NPCDrops.chaoselemental;
} else if (npc.equals("dagannoth_prime")) {
return NPCDrops.dagannothprime;
} else if (npc.equals("dagannoth_rex")) {
return NPCDrops.daggannothrex;
} else if (npc.equals("monkey_guard")) {
return NPCDrops.monkeyguard;
} else if (npc.equals("monk")) {
return NPCDrops.monk;
} else if (npc.equals("abyssal_demon")) {
return NPCDrops.abyssaldemon;
} else if (npc.equals("pyrefiend")) {
return NPCDrops.pyrefiend;
} else if (npc.equals("aberrant_spectre")
|| npc.equals("aberrant_specter")
|| npc.equals("aberant_specter")) {
return NPCDrops.abberantspectre;
} else if (npc.equals("earth_warrior")) {
return NPCDrops.earthwarrior;
} else if (npc.equals("gargoyle")) {
return NPCDrops.gargoyle;
} else if (npc.equals("dust_devil") || npc.equals("dustdevil")) {
return NPCDrops.dustdevil;
} else if (npc.equals("cockatrice")) {
return NPCDrops.cockatrice;
} else if (npc.equals("infernal_mage")) {
return NPCDrops.infernalmage;
} else if (npc.equals("nechryael")) {
return NPCDrops.nechryael;
} else if (npc.equals("bloodveld")) {
return NPCDrops.bloodveld;
} else if (npc.equals("turoth")) {
return NPCDrops.turoth;
} else if (npc.equals("banshee")) {
return NPCDrops.banshee;
} else if (npc.equals("crawling_hand")) {
return NPCDrops.crawlinghand;
} else if (npc.equals("highwayman")) {
return NPCDrops.highwayman;
} else if (npc.equals("wild_dog") || npc.equals("battle_mage")) {
return NPCDrops.alwaysbones;
} else if (npc.equals("kalphite_queen")) {
return NPCDrops.kalphitequeen;
} else if (npc.equals("kalphite_worker")) {
return NPCDrops.kalphiteworker;
} else if (npc.equals("kalphite_soldier")) {
return NPCDrops.kalphitesoldier;
} else if (npc.equals("kalphite_guardian")) {
return NPCDrops.kalphiteguardian;
} else if (npc.equals("bat") || npc.equals("giant_bat")) {
return NPCDrops.bat;
} else if (npc.equals("bronze_dragon")) {
return NPCDrops.bronzedragon;
} else if (npc.equals("black_dragon")) {
return NPCDrops.blackdragon;
} else if (npc.equals("iron_dragon")) {
return NPCDrops.irondragon;
} else if (npc.equals("steel_dragon")) {
return NPCDrops.steeldragon;
} else if (npc.equals("moss_giant")) {
return NPCDrops.mossgiant;
} else if (npc.equals("greater_demon")) {
return NPCDrops.greaterdemon;
} else if (npc.equals("black_demon")) {
return NPCDrops.blackdemon;
} else if (npc.equals("dwarf")) {
return NPCDrops.dwarf;
} else if (npc.equals("jelly")) {
return NPCDrops.jelly;
} else if (npc.equals("rock_crab")) {
return NPCDrops.rockcrab;
} else if (npc.equals("rockslug")) {
return NPCDrops.rockslug;
} else if (npc.equals("king_black_dragon")) {
return NPCDrops.kingblackdragon;
} else if (npc.equals("green_dragon")) {
return NPCDrops.greendragon;
} else if (npc.equals("blue_dragon")) {
return NPCDrops.bluedragon;
} else if (npc.equals("goblin")) {
return NPCDrops.goblin;
} else if (npc.equals("lesser_demon") || npc.equals("Lesser_demon")
|| npc.equals("lesserdemon")) {
return NPCDrops.lesserdemon;
} else if (npc.equals("guard") || npc.equals("jail_guard")) {
return NPCDrops.guard;
} else if (npc.equals("al-kharid_warrior")) {
return NPCDrops.alkharidwarrior;
} else if (npc.equals("ice_warrior")) {
return NPCDrops.icewarrior;
} else if (npc.equals("kurask")) {
return NPCDrops.kurask;
} else if (npc.equals("ice_giant")) {
return NPCDrops.icegiant;
} else if (npc.equals("hobgoblin")) {
return NPCDrops.hobgoblin;
} else if (npc.equals("pirate")) {
return NPCDrops.pirate;
} else if (npc.equals("zombie")) {
return NPCDrops.zombie;
} else if (npc.equals("skeleton")) {
return NPCDrops.skeleton;
} else if (npc.equals("deadly_red_spider")) {
return NPCDrops.deadlyredspider;
} else if (npc.equals("rat")) {
return NPCDrops.rat;
} else if (npc.equals("imp")) {
return NPCDrops.imp;
} else if (npc.equals("cow") || npc.equals("cow_calf")) {
return NPCDrops.cow;
} else if (npc.equals("chicken") || npc.equals("rooster")) {
return NPCDrops.chicken;
} else if (npc.equals("hill_giant")) {
return NPCDrops.hillgiant;
} else if (npc.equals("giant_rat")) {
return NPCDrops.giantrat;
} else if (npc.equals("dark_wizard")) {
return NPCDrops.darkwizard;
} else {
return NPCDrops.DEFAULT;
}
}
public static void loadItemDropData() {
try {
npcDrops = new Gson().fromJson(new FileReader("./data/cfg/npcdrops.json"), NpcDrop[].class);
} catch (FileNotFoundException fileex) {
Misc.println("npcdrops.json: file not found.");
}
}
/**
* Gets the item name
*
* @param ItemID
* @return
*/
public static int i(String ItemName) {
return getItemId(ItemName);
}
/**
* Handles the npc drops for the npc id.
*
* @param npcId id of the npc
*
* @return Items dropped by that npc
*/
public static ItemDrop[] getNpcDrops(String npc, int npcId) {
for (NpcDrop npcDrop : npcDrops) {
if (npcDrop.getId() == npcId) {
return npcDrop.getItems();
}
}
/**
* Item name main method
*
* @param itemName
* @return
*/
public static int getItemId(String itemName) {
for (ItemList i : GameEngine.itemHandler.itemList) {
if (i != null) {
if (i.itemName.equalsIgnoreCase(itemName)) {
return i.itemId;
}
}
}
return -1;
}
return new ItemDrop[]{
new ItemDrop(i("bones"), 1, 0),
new ItemDrop(995, new int[]{ 1, 10 }, 3),
new ItemDrop(2677, 1, 512) };
}
/**
* Misc.random in shorter form
*
* @param random
* @return
*/
public static int r(int random) {
return Misc.random(random);
}
/**
* short version of getItemId
*
* @param itemName name of the item
*
* @return itemId
*/
public static int i(String itemName) {
return getItemId(itemName);
}
/**
* Item id main method
*
* @param itemName name of the item
*
* @return itemId
*/
public static int getItemId(String itemName) {
for (ItemList i : GameEngine.itemHandler.itemList) {
if (i != null) {
if (i.itemName.equalsIgnoreCase(itemName)) {
return i.itemId;
}
}
}
return -1;
}
/**
* Misc.random in shorter form
*
* @param max max number
*
* @return random number from 0->max
*/
public static int r(int max) {
return Misc.random(max);
}
}
@@ -1,249 +1,294 @@
package com.rebotted.game.shops;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rebotted.game.players.Client;
import com.rebotted.game.players.Player;
import com.rebotted.game.players.PlayerHandler;
import com.rebotted.util.Misc;
import com.rebotted.util.ShopData;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.lang.reflect.Type;
public class ShopHandler {
public static int MAX_SHOPS = 800;
public static int MAX_SHOP_ITEMS = 40;
public static int SHOW_DELAY = 1; // Restock 1 item every tick
public static int SPECIAL_DELAY = 60; // Remove overstocked items after 60 ticks
public static int totalshops = 0;
public static int[][] shopItems = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsN = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsDelay = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsSN = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[] shopItemsStandard = new int[MAX_SHOPS];
public static String[] shopName = new String[MAX_SHOPS];
public static int[] shopSModifier = new int[MAX_SHOPS];
public static int[] shopBModifier = new int[MAX_SHOPS];
public static long[][] shopItemsRestock = new long[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int MAX_SHOPS = 800;
public ShopHandler() {
for (int i = 0; i < MAX_SHOPS; i++) {
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
ResetItem(i, j);
shopItemsSN[i][j] = 0;
public static int MAX_SHOP_ITEMS = 40;
public static int SHOW_DELAY = 1; // Restock 1 item every tick
public static int SPECIAL_DELAY = 60; // Remove overstocked items after 60 ticks
public static int totalshops = 0;
public static int[][] shopItems = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsN = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsDelay = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[][] shopItemsSN = new int[MAX_SHOPS][MAX_SHOP_ITEMS];
public static int[] shopItemsStandard = new int[MAX_SHOPS];
public static String[] shopName = new String[MAX_SHOPS];
public static int[] shopSModifier = new int[MAX_SHOPS];
public static int[] shopBModifier = new int[MAX_SHOPS];
public static long[][] shopItemsRestock = new long[MAX_SHOPS][MAX_SHOP_ITEMS];
public ShopHandler() {
for (int i = 0; i < MAX_SHOPS; i++) {
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
ResetItem(i, j);
shopItemsSN[i][j] = 0;
}
shopItemsStandard[i] = 0;
shopSModifier[i] = 0;
shopBModifier[i] = 0;
shopName[i] = "";
}
totalshops = 0;
//writeShops("shops.cfg");
loadShops();
}
public static int restockTimeItem(int itemId) {
switch (itemId) {
default:
return 1000;
}
}
public void process() {
boolean DidUpdate = false;
for (int i = 1; i <= totalshops; i++) {
if (shopBModifier[i] == 0 || shopSModifier[i] == 0) {
continue;
}
shopItemsStandard[i] = 0;
shopSModifier[i] = 0;
shopBModifier[i] = 0;
shopName[i] = "";
}
totalshops = 0;
loadshops("shops.cfg");
}
public static int restockTimeItem(int itemId) {
switch(itemId) {
default:
return 1000;
}
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[i][j] > 0) {
if (shopItemsDelay[i][j] >= SHOW_DELAY) {
if (j <= shopItemsStandard[i] && shopItemsN[i][j] <= shopItemsSN[i][j]) {
if (shopItemsN[i][j] < shopItemsSN[i][j] && System.currentTimeMillis() - shopItemsRestock[i][j] > restockTimeItem(shopItems[i][j])) {
shopItemsN[i][j] += 1;
shopItemsDelay[i][j] = 1;
shopItemsDelay[i][j] = 0;
DidUpdate = true;
shopItemsRestock[i][j] = System.currentTimeMillis();
}
} else if (shopItemsDelay[i][j] >= SPECIAL_DELAY) {
DiscountItem(i, j);
shopItemsDelay[i][j] = 0;
DidUpdate = true;
}
refreshshop(i);
}
shopItemsDelay[i][j]++;
}
}
if (DidUpdate) {
for (int k = 1; k < PlayerHandler.players.length; k++) {
if (PlayerHandler.players[k] != null) {
if (PlayerHandler.players[k].isShopping && PlayerHandler.players[k].shopId == i) {
PlayerHandler.players[k].updateShop = true;
PlayerHandler.players[k].updateShop(i);
}
}
}
DidUpdate = false;
}
}
}
}
public void process() {
boolean DidUpdate = false;
for (int i = 1; i <= totalshops; i++) {
if (shopBModifier[i] == 0 || shopSModifier[i] == 0) continue;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[i][j] > 0) {
if (shopItemsDelay[i][j] >= SHOW_DELAY) {
if (j <= shopItemsStandard[i] && shopItemsN[i][j] <= shopItemsSN[i][j]) {
if (shopItemsN[i][j] < shopItemsSN[i][j] && System.currentTimeMillis() - shopItemsRestock[i][j] > restockTimeItem(shopItems[i][j])) {
shopItemsN[i][j] += 1;
shopItemsDelay[i][j] = 1;
shopItemsDelay[i][j] = 0;
DidUpdate = true;
shopItemsRestock[i][j] = System.currentTimeMillis();
}
} else if (shopItemsDelay[i][j] >= SPECIAL_DELAY) {
DiscountItem(i, j);
shopItemsDelay[i][j] = 0;
DidUpdate = true;
}
refreshshop(i);
}
shopItemsDelay[i][j]++;
}
}
if (DidUpdate) {
for (int k = 1; k < PlayerHandler.players.length; k++) {
if (PlayerHandler.players[k] != null) {
if (PlayerHandler.players[k].isShopping && PlayerHandler.players[k].shopId == i) {
PlayerHandler.players[k].updateShop = true;
PlayerHandler.players[k].updateShop(i);
}
}
}
DidUpdate = false;
}
}
}
private void DiscountItem(int shopID, int ArrayID) {
shopItemsN[shopID][ArrayID] -= 1;
if (shopItemsN[shopID][ArrayID] <= 0) {
shopItemsN[shopID][ArrayID] = 0;
if (shopItemsStandard[shopID] <= ArrayID)
private void DiscountItem(int shopID, int ArrayID) {
shopItemsN[shopID][ArrayID] -= 1;
if (shopItemsN[shopID][ArrayID] <= 0) {
shopItemsN[shopID][ArrayID] = 0;
if (shopItemsStandard[shopID] <= ArrayID) {
ResetItem(shopID, ArrayID);
}
}
private static void ResetItem(int shopID, int ArrayID) {
if (shopItemsStandard[shopID] > ArrayID) return;
shopItems[shopID][ArrayID] = 0;
shopItemsN[shopID][ArrayID] = 0;
shopItemsDelay[shopID][ArrayID] = 0;
}
public boolean loadshops(String FileName) {
String line = "";
String token = "";
String token2 = "";
String[] token3 = new String[(MAX_SHOP_ITEMS * 2)];
boolean EndOfFile = false;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./data/cfg/" + FileName));
} catch (FileNotFoundException fileex) {
Misc.println(FileName + ": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch (IOException ioexception) {
Misc.println(FileName + ": error loading file.");
}
while (EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token3 = token2.trim().split("\t+");
if (token.equals("shop")) {
int shopID = Integer.parseInt(token3[0]);
shopName[shopID] = token3[1].replaceAll("_", " ");
shopSModifier[shopID] = Integer.parseInt(token3[2]);
shopBModifier[shopID] = Integer.parseInt(token3[3]);
for (int i = 0; i < ((token3.length - 4) / 2); i++) {
int itemID = Integer.parseInt(token3[(4 + (i * 2))]);
int itemAmount = Integer.parseInt(token3[(5 + (i * 2))]);
if (itemID > 0) {
shopItems[shopID][i] = itemID + 1;
shopItemsN[shopID][i] = itemAmount;
shopItemsSN[shopID][i] = itemAmount;
shopItemsStandard[shopID]++;
} else {
break;
}
}
totalshops++;
}
} else {
if (line.equalsIgnoreCase("[ENDOFSHOPLIST]")) {
try {
characterfile.close();
} catch (IOException ioexception) {
}
}
}
try {
line = characterfile.readLine();
} catch (IOException ioexception1) {
EndOfFile = true;
}
}
private static void ResetItem(int shopID, int ArrayID) {
if (shopItemsStandard[shopID] > ArrayID) {
return;
}
shopItems[shopID][ArrayID] = 0;
shopItemsN[shopID][ArrayID] = 0;
shopItemsDelay[shopID][ArrayID] = 0;
}
public void loadShops() {
Gson gson = new Gson();
try {
Type collectionType = new TypeToken<ShopData[]>() {
}.getType();
ShopData[] data = gson.fromJson(new FileReader("./data/cfg/shops.json"), collectionType);
for (ShopData shop : data) {
int shopID = shop.getId();
shopName[shopID] = shop.getName();
shopSModifier[shopID] = shop.getSellModifier();
shopBModifier[shopID] = shop.getBuyModifier();
for (int i = 0; i < shop.getItems().length; i++) {
if (shop.getItems()[i].getItemId() > 0) {
shopItems[shopID][i] = shop.getItems()[i].getItemId() + 1;
shopItemsN[shopID][i] = shop.getItems()[i].getItemAmount();
shopItemsSN[shopID][i] = shop.getItems()[i].getItemAmount();
shopItemsStandard[shopID]++;
} else {
break;
}
}
totalshops++;
}
} catch (FileNotFoundException fileex) {
Misc.println("shops.json: file not found.");
}
}
public boolean writeShops(String FileName) {
String line = "";
String token = "";
String token2 = "";
String[] token3 = new String[(MAX_SHOP_ITEMS * 2)];
boolean EndOfFile = false;
BufferedReader characterfile = null;
JSONArray array = new JSONArray();
try {
characterfile = new BufferedReader(new FileReader("./data/cfg/" + FileName));
} catch (FileNotFoundException fileex) {
Misc.println(FileName + ": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch (IOException ioexception) {
Misc.println(FileName + ": error loading file.");
}
while (EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token3 = token2.trim().split("\t+");
if (token.equals("shop")) {
JSONObject object = new JSONObject();
object.put("id", Integer.parseInt(token3[0]));
object.put("name", token3[1].replace("_", " "));
object.put("sellModifier", Integer.parseInt(token3[2]));
object.put("buyModifier", Integer.parseInt(token3[3]));
JSONArray array1 = new JSONArray();
for (int i = 0; i < ((token3.length - 4) / 2); i++) {
JSONObject object1 = new JSONObject();
object1.put("itemId", Integer.parseInt(token3[(4 + (i * 2))]));
object1.put("itemAmount", Integer.parseInt(token3[(5 + (i * 2))]));
array1.put(array1.length(), object1);
}
object.put("items", array1);
array.put(object);
}
} else {
if (line.equalsIgnoreCase("[ENDOFSHOPLIST]")) {
try {
characterfile.close();
} catch (IOException ioexception) {
}
}
}
try {
line = characterfile.readLine();
} catch (IOException ioexception1) {
EndOfFile = true;
}
}
try {
characterfile.close();
FileWriter fileWriter = new FileWriter("shops-dump.json");
fileWriter.write(array.toString());
} catch (IOException ioexception) {
}
return false;
}
public static void createPlayerShop(Client player) {
int id = getEmptyshop();
player.shopId = id;
shopSModifier[id] = 0;
shopBModifier[id] = 0;
shopName[id] = player.properName + "'s Store";
for (int i = 0; i < MAX_SHOP_ITEMS; i++) {
shopItems[id][i] = player.bankItems[i];
shopItemsN[id][i] = player.bankItemsN[i];
shopItemsSN[id][i] = 0;
shopItemsDelay[id][i] = 0;
}
totalshops++;
}
private static int getEmptyshop() {
for (int i = 0; i < MAX_SHOPS; i++) {
if (shopName[i].equals("")) {
return i;
}
}
try {
characterfile.close();
} catch (IOException ioexception) {
}
return false;
}
}
return -1;
}
public static void createPlayerShop(Client player){
int id = getEmptyshop();
player.shopId = id;
shopSModifier[id] = 0;
shopBModifier[id] = 0;
shopName[id] = player.properName + "'s Store";
for (int i = 0; i < MAX_SHOP_ITEMS; i++){
shopItems[id][i] = player.bankItems[i];
shopItemsN[id][i] = player.bankItemsN[i];
shopItemsSN[id][i] = 0;
shopItemsDelay[id][i] = 0;
}
totalshops++;
}
public static void refreshshop(int shop_id) {
// We don't want to remove items that should be kept in stock
for (int j = shopItemsStandard[shop_id]; j < MAX_SHOP_ITEMS; j++) {
if (shopItemsN[shop_id][j] <= 0) {
ResetItem(shop_id, j);
int next = j + 1;
if (next < MAX_SHOP_ITEMS && shopItemsN[shop_id][next] > 0) {
shopItems[shop_id][j] = shopItems[shop_id][next];
shopItemsN[shop_id][j] = shopItemsN[shop_id][next];
shopItemsDelay[shop_id][j] = shopItemsDelay[shop_id][next];
ResetItem(shop_id, next);
}
}
}
}
private static int getEmptyshop(){
for (int i = 0; i < MAX_SHOPS; i++) {
if (shopName[i].equals("")) return i;
}
return -1;
}
public static int getStock(int shop_id, int item_id) {
item_id++;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[shop_id][j] == item_id) {
return shopItemsN[shop_id][j];
}
}
return -1;
}
public static void refreshshop(int shop_id){
// We don't want to remove items that should be kept in stock
for (int j = shopItemsStandard[shop_id]; j < MAX_SHOP_ITEMS; j++) {
if (shopItemsN[shop_id][j] <= 0) {
ResetItem(shop_id, j);
int next = j + 1;
if (next < MAX_SHOP_ITEMS && shopItemsN[shop_id][next] > 0) {
shopItems[shop_id][j] = shopItems[shop_id][next];
shopItemsN[shop_id][j] = shopItemsN[shop_id][next];
shopItemsDelay[shop_id][j] = shopItemsDelay[shop_id][next];
ResetItem(shop_id, next);
}
}
}
}
public static void buyItem(int shop_id, int item_id, int amount) {
item_id++;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[shop_id][j] == item_id) {
shopItemsN[shop_id][j] -= amount;
}
}
refreshshop(shop_id);
}
public static int getStock(int shop_id, int item_id){
item_id++;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[shop_id][j] == item_id) {
return shopItemsN[shop_id][j];
}
}
return -1;
}
public static void buyItem(int shop_id, int item_id, int amount){
item_id++;
for (int j = 0; j < MAX_SHOP_ITEMS; j++) {
if (shopItems[shop_id][j] == item_id) {
shopItemsN[shop_id][j] -= amount;
}
}
refreshshop(shop_id);
}
public static boolean playerOwnsStore(int shop_id, Player player){
return shopSModifier[shop_id] == 0 && shopBModifier[shop_id] == 0 && shopName[shop_id].equalsIgnoreCase(player.properName + "'s Store");
}
public static boolean playerOwnsStore(int shop_id, Player player) {
return shopSModifier[shop_id] == 0 && shopBModifier[shop_id] == 0 && shopName[shop_id].equalsIgnoreCase(player.properName + "'s Store");
}
}
@@ -0,0 +1,49 @@
package com.rebotted.util;
public class DoorData {
private final int id;
private final Location[] locations;
private final int face;
private final int type;
public DoorData(int id, Location[] locations, int face, int type) {
this.id = id;
this.locations = locations;
this.face = face;
this.type = type;
}
public int getId() {
return id;
}
public Location[] getLocations() {
return locations;
}
public int getFace() {
return face;
}
public int getType() {
return type;
}
public static class Location {
private int x;
private int y;
private int height;
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getHeight() {
return height;
}
}
}
@@ -0,0 +1,30 @@
package com.rebotted.util;
public class GlobalDropData {
private int id;
private int amount;
private int itemX;
private int itemY;
private int height;
public int getId() {
return id;
}
public int getAmount() {
return amount;
}
public int getItemX() {
return itemX;
}
public int getItemY() {
return itemY;
}
public int getHeight() {
return height;
}
}
@@ -0,0 +1,137 @@
package com.rebotted.util;
public class ItemData {
private final int id;
private final String name;
private final String examine;
private final Values[] values;
private final Bonuses[] bonuses;
public ItemData(int id, String name, String examine, Values[] values, Bonuses[] bonuses) {
this.id = id;
this.name = name;
this.examine = examine;
this.values = values;
this.bonuses = bonuses;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getExamine() {
return examine;
}
public Values getValues() {
return values[0];
}
public Bonuses getBonuses() {
return bonuses[0];
}
public static class Values {
int shopValue;
int lowAlch;
int highAlch;
public int getShopValue() {
return shopValue;
}
public int getLowAlch() {
return lowAlch;
}
public int getHighAlch() {
return highAlch;
}
}
public 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 getAttackStab() {
return attackStab;
}
public int getAttackSlash() {
return attackSlash;
}
public int getAttackCrush() {
return attackCrush;
}
public int getAttackMagic() {
return attackMagic;
}
public int getAttackRange() {
return attackRange;
}
public int getDefenceStab() {
return defenceStab;
}
public int getDefenceSlash() {
return defenceSlash;
}
public int getDefenceCrush() {
return defenceCrush;
}
public int getDefenceMagic() {
return defenceMagic;
}
public int getDefenceRange() {
return defenceRange;
}
public int getStrengthBonus() {
return strengthBonus;
}
public int getPrayerBonus() {
return prayerBonus;
}
public int[] getBonuses() {
int[] bonuses = new int[12];
bonuses[0] = this.getAttackStab();
bonuses[1] = this.getAttackSlash();
bonuses[2] = this.getAttackCrush();
bonuses[3] = this.getAttackMagic();
bonuses[4] = this.getAttackRange();
bonuses[5] = this.getDefenceStab();
bonuses[6] = this.getDefenceSlash();
bonuses[7] = this.getDefenceCrush();
bonuses[8] = this.getDefenceMagic();
bonuses[9] = this.getDefenceRange();
bonuses[10] = this.getStrengthBonus();
bonuses[11] = this.getPrayerBonus();
return bonuses;
}
}
}
@@ -0,0 +1,31 @@
package com.rebotted.util;
public class NpcData {
private final int id;
private final String name;
private final int combat;
private final int hitpoints;
public NpcData(int id, String name, int combat, int hitpoints) {
this.id = id;
this.name = name;
this.combat = combat;
this.hitpoints = hitpoints;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getCombat() {
return combat;
}
public int getHitpoints() {
return hitpoints;
}
}
@@ -0,0 +1,24 @@
package com.rebotted.util;
import com.rebotted.game.npcs.drops.ItemDrop;
/**
* @author SandroC
*/
public class NpcDrop {
private final int id;
private final ItemDrop[] items;
public NpcDrop(int id, ItemDrop[] items) {
this.id = id;
this.items = items;
}
public int getId() {
return id;
}
public ItemDrop[] getItems() {
return items;
}
}
@@ -0,0 +1,58 @@
package com.rebotted.util;
/**
* @author SandroC
*/
public class NpcSpawn {
private final int id;
private final int x;
private final int y;
private final int height;
private final int walk;
private final int maxHit;
private final int attack;
private final int strength;
public NpcSpawn(int id, int x, int y, int height, int walk, int maxHit, int attack, int strength) {
this.id = id;
this.x = x;
this.y = y;
this.height = height;
this.walk = walk;
this.maxHit = maxHit;
this.attack = attack;
this.strength = strength;
}
public int getId() {
return id;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getHeight() {
return height;
}
public int isWalk() {
return walk;
}
public int getMaxHit() {
return maxHit;
}
public int getAttack() {
return attack;
}
public int getStrength() {
return strength;
}
}
@@ -0,0 +1,53 @@
package com.rebotted.util;
/**
* @author SandroC
*/
public class ShopData {
private final int id;
private final String name;
private final int sellModifier;
private final int buyModifier;
private final ShopItems[] items;
public ShopData(int id, String name, int sellModifier, int buyModifier, ShopItems[] items) {
this.id = id;
this.name = name;
this.sellModifier = sellModifier;
this.buyModifier = buyModifier;
this.items = items;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getSellModifier() {
return sellModifier;
}
public int getBuyModifier() {
return buyModifier;
}
public ShopItems[] getItems() {
return items;
}
public static class ShopItems {
int itemId;
int itemAmount;
public int getItemId() {
return itemId;
}
public int getItemAmount() {
return itemAmount;
}
}
}
@@ -1,370 +1,376 @@
package com.rebotted.world;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.players.Client;
import com.rebotted.game.players.Player;
import com.rebotted.game.players.PlayerHandler;
import com.rebotted.util.GlobalDropData;
import com.rebotted.util.Misc;
import com.rebotted.util.ShopData;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Handles global drops which respawn after set amount of time when taken
*
*
* @author Stuart <RogueX>
*/
public class GlobalDropsHandler {
/**
* time in seconds it takes for the item to respawn
*/
private static final int TIME_TO_RESPAWN = 20;
/**
* time in seconds it takes for the item to respawn
*/
private static final int TIME_TO_RESPAWN = 20;
/**
* holds all the objects
*/
private static List<GlobalDrop> globalDrops = new ArrayList<GlobalDrop>();
private static Set<GlobalDrop> spawnedDrops = new HashSet<>();
/**
* holds all the objects
*/
private static final List<GlobalDrop> globalDrops = new ArrayList<>();
/**
* loads the items
*/
public static void initialize() {
String Data;
BufferedReader Checker;
try {
Checker = new BufferedReader(new FileReader("./data/cfg/globaldrops.txt"));
while ((Data = Checker.readLine()) != null) {
if (Data.startsWith("#")) {
continue;
}
String[] args = Data.split(":");
if(args.length == 5) {
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4])));
private static final Set<GlobalDrop> spawnedDrops = new HashSet<>();
/**
* loads the items
*/
public static void initialize() {
Gson gson = new Gson();
try {
Type collectionType = new TypeToken<GlobalDropData[]>() {
}.getType();
GlobalDropData[] globalDropData = gson.fromJson(new FileReader("./data/cfg/globaldrops.json"), collectionType);
for (GlobalDropData data : globalDropData) {
if (data.getHeight() > 0) {
globalDrops.add(new GlobalDrop(data.getId(), data.getAmount(), data.getItemX(), data.getItemY(), data.getHeight()));
} else {
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])));
globalDrops.add(new GlobalDrop(data.getId(), data.getAmount(), data.getItemX(), data.getItemY()));
}
}
Checker.close();
} catch (Exception e) {
e.printStackTrace();
}
Misc.println("Loaded " + globalDrops.size() + " global drops.");
} catch (Exception e) {
e.printStackTrace();
}
Misc.println("Loaded " + globalDrops.size() + " global drops.");
for (Player player : PlayerHandler.players) {
Client player2 = (Client) player;
if(player2 != null) {
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
for (GlobalDrop drop : globalDrops) {
if (drop.isTaken() && drop.isSpawned()) {
if (System.currentTimeMillis() - drop.getTakenAt() >= TIME_TO_RESPAWN * 1000) {
drop.setTaken(false);
if (player2.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
player2.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
spawnedDrops.add(drop);
}
for (Player player : PlayerHandler.players) {
Client player2 = (Client) player;
if (player2 != null) {
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
for (GlobalDrop drop : globalDrops) {
if (drop.isTaken() && drop.isSpawned()) {
if (System.currentTimeMillis() - drop.getTakenAt() >= TIME_TO_RESPAWN * 1000) {
drop.setTaken(false);
if (player2.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
player2.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
spawnedDrops.add(drop);
}
}
}
}
}
@Override
public void stop() {
}
}
}
}
}
}, 1);
}
}
}
public static void read() {
String Data;
BufferedReader Checker;
try {
Checker = new BufferedReader(new FileReader("./data/cfg/globaldrops.txt"));
while ((Data = Checker.readLine()) != null) {
if (Data.startsWith("#")) {
continue;
}
String[] args = Data.split(":");
if(args.length == 5) {
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4])));
} else {
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])));
}
}
Checker.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void stop() {
/**
* See if a drop exists at the given place
*
* @param a
* item id
* @param b
* x cord
* @param c
* y cord
* @return return the statement
*/
private static GlobalDrop itemExists(int a, int b, int c) {
for (GlobalDrop drop : globalDrops) {
if (drop.getId() == a && drop.getX() == b && drop.getY() == c) {
return drop;
}
}
return null;
}
public static boolean itemExists(int a, int b, int c, boolean yes) {
for (GlobalDrop drop : spawnedDrops) {
if (drop.getId() == a && drop.getX() == b && drop.getY() == c) {
return true;
}
}
return false;
}
}
}, 1);
}
}
}
/**
* Pick up an item at the given location
*
* @param player2
* the Player
* @param a
* item id
* @param b
* cord x
* @param c
* cord y
*/
public static void pickup(Player player, int a, int b, int c) {
GlobalDrop drop = itemExists(a, b, c);
if (drop == null) {
return;
}
if (drop.isTaken()) {
return;
}
if (player.getItemAssistant().freeSlots() < 1) {
if (!(player.getItemAssistant().playerHasItem(player.pItemId) && player.getItemAssistant().isStackable(player.pItemId))) {
player.getPacketSender().sendMessage("Not enough space in your inventory.");
return;
}
}
player.getItemAssistant().addItem(drop.getId(), drop.getAmount());
drop.setTakenAt(System.currentTimeMillis());
drop.setTaken(true);
for (Player playerLoop : PlayerHandler.players) {
Client cl = (Client) playerLoop;
if (cl != null) {
cl.getPacketSender().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
spawnedDrops.remove(drop);
}
}
}
public static void writeGlobalDropsDump() {
String Data;
BufferedReader Checker;
JSONArray array = new JSONArray();
try {
Checker = new BufferedReader(new FileReader("./data/cfg/globaldrops.txt"));
while ((Data = Checker.readLine()) != null) {
if (Data.startsWith("#")) {
continue;
}
String[] args = Data.split(":");
/**
* Loads all the items when a player changes region
*
* @param Player
* the Player
*/
public static void load(Client player) {
for (GlobalDrop drop : globalDrops) {
if (!drop.isTaken() && !drop.isSpawned() && !itemExists(drop.getId(), drop.getX(), drop.getY(), true) && player.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
player.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
spawnedDrops.add(drop);
drop.setSpawned(true);
}
}
}
public static void reset(Player c) {
for(GlobalDrop drop : globalDrops) {
if(c.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
c.getPacketSender().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
}
}
spawnedDrops.clear();
globalDrops.clear();
read();
for (GlobalDrop drop : globalDrops) {
if (!drop.isTaken() && !drop.isSpawned() && !itemExists(drop.getId(), drop.getX(), drop.getY(), true) && c.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
c.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
spawnedDrops.add(drop);
drop.setSpawned(true);
}
}
}
JSONObject object = new JSONObject();
/**
* Holds each drops data
*
* @author Stuart
*/
static class GlobalDrop {
object.put("id", Integer.parseInt(args[0]));
object.put("amount", args[1].replace("_", " "));
object.put("itemX", Integer.parseInt(args[2]));
object.put("itemY", Integer.parseInt(args[3]));
/**
* cord x
*/
int itemX;
/**
* cord y
*/
int itemY;
private int height;
/**
* item id
*/
int id;
/**
* item amount
*/
int amount;
/**
* has the item been taken
*/
boolean taken = false;
private boolean spawned = false;
if (args.length == 5) {
object.put("height", Integer.parseInt(args[4]));
}
/**
* Time it was taken at
*/
long takenAt;
array.put(object);
}
Checker.close();
/**
* Sets the drop arguments
*
* @param pickAxe
* item id
* @param b
* item amount
* @param player
* cord x
* @param d
* cord y
*/
public GlobalDrop(int id, int amount, int itemX, int itemY) {
this.id = id;
this.amount = amount;
this.itemX = itemX;
this.itemY = itemY;
}
public GlobalDrop(int id, int amount, int itemX, int itemY, int height) {
this.id = id;
this.amount = amount;
this.itemX = itemX;
this.itemY = itemY;
this.height = height;
}
FileWriter fileWriter = new FileWriter("globaldrops-dump.json");
fileWriter.write(array.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* get cord x
*
* @return return the statement
*/
public int getX() {
return itemX;
}
/**
* See if a drop exists at the given place
*
* @param a item id
* @param b x cord
* @param c y cord
*
* @return return the statement
*/
private static GlobalDrop itemExists(int a, int b, int c) {
for (GlobalDrop drop : globalDrops) {
if (drop.getId() == a && drop.getX() == b && drop.getY() == c) {
return drop;
}
}
return null;
}
/**
* get cord x
*
* @return return the statement
*/
public int getY() {
return itemY;
}
public static boolean itemExists(int a, int b, int c, boolean yes) {
for (GlobalDrop drop : spawnedDrops) {
if (drop.getId() == a && drop.getX() == b && drop.getY() == c) {
return true;
}
}
return false;
}
/**
* get the item id
*
* @return return the statement
*/
public int getId() {
return id;
}
/**
* Pick up an item at the given location
*
* @param player the Player
* @param a item id
* @param b cord x
* @param c cord y
*/
public static void pickup(Player player, int a, int b, int c) {
GlobalDrop drop = itemExists(a, b, c);
if (drop == null) {
return;
}
if (drop.isTaken()) {
return;
}
if (player.getItemAssistant().freeSlots() < 1) {
if (!(player.getItemAssistant().playerHasItem(player.pItemId) && player.getItemAssistant().isStackable(player.pItemId))) {
player.getPacketSender().sendMessage("Not enough space in your inventory.");
return;
}
}
player.getItemAssistant().addItem(drop.getId(), drop.getAmount());
drop.setTakenAt(System.currentTimeMillis());
drop.setTaken(true);
for (Player playerLoop : PlayerHandler.players) {
Client cl = (Client) playerLoop;
if (cl != null) {
cl.getPacketSender().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
spawnedDrops.remove(drop);
}
}
}
/**
* get the item amount
*
* @return return the statement
*/
public int getAmount() {
return amount;
}
/**
* Loads all the items when a player changes region
*
* @param player the Player
*/
public static void load(Client player) {
for (GlobalDrop drop : globalDrops) {
if (!drop.isTaken() && !drop.isSpawned() && !itemExists(drop.getId(), drop.getX(), drop.getY(), true) && player.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
player.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
spawnedDrops.add(drop);
drop.setSpawned(true);
}
}
}
/**
* has the drop already been taken?
*
* @return return the statement
*/
public boolean isTaken() {
return taken;
}
public static void reset(Player c) {
for (GlobalDrop drop : globalDrops) {
if (c.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
c.getPacketSender().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
}
}
spawnedDrops.clear();
globalDrops.clear();
initialize();
for (GlobalDrop drop : globalDrops) {
if (!drop.isTaken() && !drop.isSpawned() && !itemExists(drop.getId(), drop.getX(), drop.getY(), true) && c.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
c.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
spawnedDrops.add(drop);
drop.setSpawned(true);
}
}
}
/**
* set if or not the drop has been taken
*
* @param a
* true yes false no
*/
public void setTaken(boolean a) {
taken = a;
}
/**
* Holds each drops data
*
* @author Stuart
*/
static class GlobalDrop {
/**
* set the time it was picked up
*
* @param a
* the a
*/
public void setTakenAt(long a) {
takenAt = a;
}
/**
* cord x
*/
int itemX;
/**
* cord y
*/
int itemY;
/**
* get the time it was taken at
*
* @return return the statement
*/
public long getTakenAt() {
return takenAt;
}
private int height;
/**
* item id
*/
int id;
/**
* item amount
*/
int amount;
/**
* has the item been taken
*/
boolean taken = false;
public boolean isSpawned() {
return spawned;
}
private boolean spawned = false;
public void setSpawned(boolean spawned) {
this.spawned = spawned;
}
/**
* Time it was taken at
*/
long takenAt;
public int getHeight() {
return height;
}
/**
* Sets the drop arguments
*
* @param id item id
* @param amount item amount
* @param itemX cord x
* @param itemY cord y
*/
public void setHeight(int height) {
this.height = height;
}
public GlobalDrop(int id, int amount, int itemX, int itemY) {
this.id = id;
this.amount = amount;
this.itemX = itemX;
this.itemY = itemY;
}
}
public GlobalDrop(int id, int amount, int itemX, int itemY, int height) {
this.id = id;
this.amount = amount;
this.itemX = itemX;
this.itemY = itemY;
this.height = height;
}
/**
* get cord x
*
* @return return the statement
*/
public int getX() {
return itemX;
}
/**
* get cord x
*
* @return return the statement
*/
public int getY() {
return itemY;
}
/**
* get the item id
*
* @return return the statement
*/
public int getId() {
return id;
}
/**
* get the item amount
*
* @return return the statement
*/
public int getAmount() {
return amount;
}
/**
* has the drop already been taken?
*
* @return return the statement
*/
public boolean isTaken() {
return taken;
}
/**
* set if or not the drop has been taken
*
* @param a true yes false no
*/
public void setTaken(boolean a) {
taken = a;
}
/**
* set the time it was picked up
*
* @param a the a
*/
public void setTakenAt(long a) {
takenAt = a;
}
/**
* get the time it was taken at
*
* @return return the statement
*/
public long getTakenAt() {
return takenAt;
}
public boolean isSpawned() {
return spawned;
}
public void setSpawned(boolean spawned) {
this.spawned = spawned;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
}
@@ -1,14 +1,7 @@
package com.rebotted.world;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rebotted.GameConstants;
import com.rebotted.game.items.GroundItem;
import com.rebotted.game.items.ItemAssistant;
@@ -17,7 +10,16 @@ import com.rebotted.game.players.Client;
import com.rebotted.game.players.Player;
import com.rebotted.game.players.PlayerHandler;
import com.rebotted.util.GameLogger;
import com.rebotted.util.ItemData;
import com.rebotted.util.Misc;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* Handles ground items
@@ -25,400 +27,455 @@ import com.rebotted.util.Misc;
public class ItemHandler {
public List<GroundItem> items = new ArrayList<GroundItem>();
public static final int HIDE_TICKS = 100;
public List<GroundItem> items = new ArrayList<GroundItem>();
public static final int HIDE_TICKS = 100;
public ItemHandler() {
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
itemList[i] = null;
}
loadItemList("item.cfg");
}
public ItemHandler() {
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
itemList[i] = null;
}
//loadItemList("item.cfg");
loadItemListJson();
}
/**
* Adds item to list
**/
public void addItem(GroundItem item) {
items.add(item);
}
/**
* Adds item to list
**/
public void addItem(GroundItem item) {
items.add(item);
}
/**
* Removes item from list
**/
public void removeItem(GroundItem item) {
items.remove(item);
}
/**
* Removes item from list
**/
public void removeItem(GroundItem item) {
items.remove(item);
}
/**
* Item amount
**/
/**
* Item amount
**/
public int itemAmount(String name, int itemId, int itemX, int itemY) {
for(GroundItem i : items) {
if (i.hideTicks >= 1 && i.getName().equalsIgnoreCase(name)) {
if(i.getItemId() == itemId && i.getItemX() == itemX && i.getItemY() == itemY) {
return i.getItemAmount();
}
} else if (i.hideTicks < 1) {
if(i.getItemId() == itemId && i.getItemX() == itemX && i.getItemY() == itemY) {
return i.getItemAmount();
}
}
}
return 0;
}
/**
* Item exists
**/
public boolean itemExists(int itemId, int itemX, int itemY) {
for (GroundItem i : items) {
if (i.getItemId() == itemId && i.getItemX() == itemX
&& i.getItemY() == itemY) {
return true;
}
}
return false;
}
public int itemAmount(String name, int itemId, int itemX, int itemY) {
for (GroundItem i : items) {
if (i.hideTicks >= 1 && i.getName().equalsIgnoreCase(name)) {
if (i.getItemId() == itemId && i.getItemX() == itemX && i.getItemY() == itemY) {
return i.getItemAmount();
}
} else if (i.hideTicks < 1) {
if (i.getItemId() == itemId && i.getItemX() == itemX && i.getItemY() == itemY) {
return i.getItemAmount();
}
}
}
return 0;
}
/**
* Reloads any items if you enter a new region
**/
public void reloadItems(Player c) {
for (GroundItem i : items) {
if (c != null) {
if (c.getItemAssistant().tradeable(i.getItemId())
|| i.getName().equalsIgnoreCase(c.playerName)) {
if (c.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) {
if (i.hideTicks > 0
&& i.getName().equalsIgnoreCase(c.playerName)) {
c.getPacketSender().removeGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
c.getPacketSender().createGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
if (i.hideTicks == 0) {
c.getPacketSender().removeGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
c.getPacketSender().createGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
}
}
}
}
}
/**
* Item exists
**/
public boolean itemExists(int itemId, int itemX, int itemY) {
for (GroundItem i : items) {
if (i.getItemId() == itemId && i.getItemX() == itemX
&& i.getItemY() == itemY) {
return true;
}
}
return false;
}
public void process() {
ArrayList<GroundItem> toRemove = new ArrayList<GroundItem>();
for (int j = 0; j < items.size(); j++) {
if (items.get(j) != null) {
GroundItem i = items.get(j);
if (i.hideTicks > 0) {
i.hideTicks--;
}
if (i.hideTicks == 1) { // item can now be seen by others
i.hideTicks = 0;
createGlobalItem(i);
i.removeTicks = HIDE_TICKS;
}
if (i.removeTicks > 0) {
i.removeTicks--;
}
if (i.removeTicks == 1) {
i.removeTicks = 0;
toRemove.add(i);
}
/**
* Reloads any items if you enter a new region
**/
public void reloadItems(Player c) {
for (GroundItem i : items) {
if (c != null) {
if (c.getItemAssistant().tradeable(i.getItemId())
|| i.getName().equalsIgnoreCase(c.playerName)) {
if (c.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) {
if (i.hideTicks > 0
&& i.getName().equalsIgnoreCase(c.playerName)) {
c.getPacketSender().removeGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
c.getPacketSender().createGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
if (i.hideTicks == 0) {
c.getPacketSender().removeGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
c.getPacketSender().createGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
}
}
}
}
}
}
public void process() {
ArrayList<GroundItem> toRemove = new ArrayList<GroundItem>();
for (int j = 0; j < items.size(); j++) {
if (items.get(j) != null) {
GroundItem i = items.get(j);
if (i.hideTicks > 0) {
i.hideTicks--;
}
if (i.hideTicks == 1) { // item can now be seen by others
i.hideTicks = 0;
createGlobalItem(i);
i.removeTicks = HIDE_TICKS;
}
if (i.removeTicks > 0) {
i.removeTicks--;
}
if (i.removeTicks == 1) {
i.removeTicks = 0;
toRemove.add(i);
}
}
}
for (int j = 0; j < toRemove.size(); j++) {
GroundItem i = toRemove.get(j);
removeGlobalItem(i, i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
}
}
/**
* Creates the ground item
**/
public int[][] brokenBarrows = { { 4708, 4860 }, { 4710, 4866 },
{ 4712, 4872 }, { 4714, 4878 }, { 4716, 4884 }, { 4720, 4896 },
{ 4718, 4890 }, { 4720, 4896 }, { 4722, 4902 }, { 4732, 4932 },
{ 4734, 4938 }, { 4736, 4944 }, { 4738, 4950 }, { 4724, 4908 },
{ 4726, 4914 }, { 4728, 4920 }, { 4730, 4926 }, { 4745, 4956 },
{ 4747, 4926 }, { 4749, 4968 }, { 4751, 4994 }, { 4753, 4980 },
{ 4755, 4986 }, { 4757, 4992 }, { 4759, 4998 } };
for (int j = 0; j < toRemove.size(); j++) {
GroundItem i = toRemove.get(j);
removeGlobalItem(i, i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
}
public void createGroundItem(Player c, int itemId, int itemX, int itemY, int itemAmount, int playerId) {
if (itemId > 0) {
if (itemId >= 2412 && itemId <= 2414) {
c.getPacketSender().sendMessage("The cape vanishes as it touches the ground.");
return;
}
if (itemId > 4705 && itemId < 4760) {
for (int[] brokenBarrow : brokenBarrows) {
if (brokenBarrow[0] == itemId) {
itemId = brokenBarrow[1];
break;
}
}
}
if (!com.rebotted.game.items.ItemData.itemStackable[itemId] && itemAmount > 0) {
for (int j = 0; j < itemAmount; j++) {
c.getPacketSender().createGroundItem(itemId, itemX, itemY, 1);
GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), 1, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
addItem(item);
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
if (c.isDead == false && itemId != 526) {
if (c.getPlayerAssistant().isPlayer()) {
GameLogger.writeLog(c.playerName, "dropitem", c.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + c.absX + " absY: " + c.absY + "");
}
}
}
} else {
c.getPacketSender().createGroundItem(itemId, itemX, itemY, itemAmount);
GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), itemAmount, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
addItem(item);
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
if (c.isDead == false && itemId != 526) {
if (c.getPlayerAssistant().isPlayer()) {
GameLogger.writeLog(c.playerName, "dropitem", c.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + c.absX + " absY: " + c.absY + "");
}
}
}
}
}
/**
* Creates the ground item
**/
public int[][] brokenBarrows = { { 4708, 4860 }, { 4710, 4866 },
{ 4712, 4872 }, { 4714, 4878 }, { 4716, 4884 }, { 4720, 4896 },
{ 4718, 4890 }, { 4720, 4896 }, { 4722, 4902 }, { 4732, 4932 },
{ 4734, 4938 }, { 4736, 4944 }, { 4738, 4950 }, { 4724, 4908 },
{ 4726, 4914 }, { 4728, 4920 }, { 4730, 4926 }, { 4745, 4956 },
{ 4747, 4926 }, { 4749, 4968 }, { 4751, 4994 }, { 4753, 4980 },
{ 4755, 4986 }, { 4757, 4992 }, { 4759, 4998 } };
/**
* Shows items for everyone who is within 60 squares
**/
public void createGlobalItem(GroundItem i) {
for (Player p : PlayerHandler.players) {
if (p != null) {
Client person = (Client) p;
if (person != null) {
if (person.playerId != i.getItemController()) {
if (!person.getItemAssistant().tradeable(i.getItemId())
&& person.playerId != i.getItemController()) {
continue;
}
if (person.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) {
person.getPacketSender().createGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
}
}
}
}
}
public void createGroundItem(Player c, int itemId, int itemX, int itemY, int itemAmount, int playerId) {
if (itemId > 0) {
if (itemId >= 2412 && itemId <= 2414) {
c.getPacketSender().sendMessage("The cape vanishes as it touches the ground.");
return;
}
if (itemId > 4705 && itemId < 4760) {
for (int[] brokenBarrow : brokenBarrows) {
if (brokenBarrow[0] == itemId) {
itemId = brokenBarrow[1];
break;
}
}
}
if (!com.rebotted.game.items.ItemData.itemStackable[itemId] && itemAmount > 0) {
for (int j = 0; j < itemAmount; j++) {
c.getPacketSender().createGroundItem(itemId, itemX, itemY, 1);
GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), 1, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
addItem(item);
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
if (c.isDead == false && itemId != 526) {
if (c.getPlayerAssistant().isPlayer()) {
GameLogger.writeLog(c.playerName, "dropitem", c.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + c.absX + " absY: " + c.absY + "");
}
}
}
} else {
c.getPacketSender().createGroundItem(itemId, itemX, itemY, itemAmount);
GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), itemAmount, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
addItem(item);
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
if (c.isDead == false && itemId != 526) {
if (c.getPlayerAssistant().isPlayer()) {
GameLogger.writeLog(c.playerName, "dropitem", c.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + c.absX + " absY: " + c.absY + "");
}
}
}
}
}
/**
* Removing the ground item
**/
/**
* Shows items for everyone who is within 60 squares
**/
public void createGlobalItem(GroundItem i) {
for (Player p : PlayerHandler.players) {
if (p != null) {
Client person = (Client) p;
if (person != null) {
if (person.playerId != i.getItemController()) {
if (!person.getItemAssistant().tradeable(i.getItemId())
&& person.playerId != i.getItemController()) {
continue;
}
if (person.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) {
person.getPacketSender().createGroundItem(
i.getItemId(), i.getItemX(), i.getItemY(),
i.getItemAmount());
}
}
}
}
}
}
public void removeGroundItem(Player c, int itemId, int itemX, int itemY, boolean add) {
for (GroundItem i : items) {
if (i.getItemId() == itemId && i.getItemX() == itemX
&& i.getItemY() == itemY) {
if (i.hideTicks > 0
&& i.getName().equalsIgnoreCase(c.playerName)) {
if (add) {
if (!c.getItemAssistant().specialCase(itemId)) {
if (c.getItemAssistant().addItem(i.getItemId(),
i.getItemAmount())) {
removeControllersItem(i, c, i.getItemId(),
i.getItemX(), i.getItemY(),
i.getItemAmount());
break;
}
} else {
removeControllersItem(i, c, i.getItemId(),
i.getItemX(), i.getItemY(),
i.getItemAmount());
break;
}
} else {
removeControllersItem(i, c, i.getItemId(),
i.getItemX(), i.getItemY(), i.getItemAmount());
break;
}
} else if (i.hideTicks <= 0) {
if (add) {
if (c.getItemAssistant().addItem(i.getItemId(),
i.getItemAmount())) {
removeGlobalItem(i, i.getItemId(), i.getItemX(),
i.getItemY(), i.getItemAmount());
break;
}
} else {
removeGlobalItem(i, i.getItemId(), i.getItemX(),
i.getItemY(), i.getItemAmount());
break;
}
}
}
}
}
/**
* Removing the ground item
**/
/**
* Remove item for just the item controller (item not global yet)
**/
public void removeGroundItem(Player c, int itemId, int itemX, int itemY, boolean add) {
for (GroundItem i : items) {
if (i.getItemId() == itemId && i.getItemX() == itemX
&& i.getItemY() == itemY) {
if (i.hideTicks > 0
&& i.getName().equalsIgnoreCase(c.playerName)) {
if (add) {
if (!c.getItemAssistant().specialCase(itemId)) {
if (c.getItemAssistant().addItem(i.getItemId(),
i.getItemAmount())) {
removeControllersItem(i, c, i.getItemId(),
i.getItemX(), i.getItemY(),
i.getItemAmount());
break;
}
} else {
removeControllersItem(i, c, i.getItemId(),
i.getItemX(), i.getItemY(),
i.getItemAmount());
break;
}
} else {
removeControllersItem(i, c, i.getItemId(),
i.getItemX(), i.getItemY(), i.getItemAmount());
break;
}
} else if (i.hideTicks <= 0) {
if (add) {
if (c.getItemAssistant().addItem(i.getItemId(),
i.getItemAmount())) {
removeGlobalItem(i, i.getItemId(), i.getItemX(),
i.getItemY(), i.getItemAmount());
break;
}
} else {
removeGlobalItem(i, i.getItemId(), i.getItemX(),
i.getItemY(), i.getItemAmount());
break;
}
}
}
}
}
public void removeControllersItem(GroundItem i, Player c, int itemId,
int itemX, int itemY, int itemAmount) {
c.getPacketSender().removeGroundItem(itemId, itemX, itemY,
itemAmount);
removeItem(i);
}
/**
* Remove item for just the item controller (item not global yet)
**/
/**
* Remove item for everyone within 60 squares
**/
public void removeControllersItem(GroundItem i, Player c, int itemId,
int itemX, int itemY, int itemAmount) {
c.getPacketSender().removeGroundItem(itemId, itemX, itemY,
itemAmount);
removeItem(i);
}
public void removeGlobalItem(GroundItem i, int itemId, int itemX,
int itemY, int itemAmount) {
for (Player p : PlayerHandler.players) {
if (p != null) {
Client person = (Client) p;
if (person != null) {
if (person.distanceToPoint(itemX, itemY) <= 60) {
person.getPacketSender().removeGroundItem(itemId,
itemX, itemY, itemAmount);
}
}
}
}
removeItem(i);
}
/**
* Remove item for everyone within 60 squares
**/
/**
* Item List
**/
public void removeGlobalItem(GroundItem i, int itemId, int itemX,
int itemY, int itemAmount) {
for (Player p : PlayerHandler.players) {
if (p != null) {
Client person = (Client) p;
if (person != null) {
if (person.distanceToPoint(itemX, itemY) <= 60) {
person.getPacketSender().removeGroundItem(itemId,
itemX, itemY, itemAmount);
}
}
}
}
removeItem(i);
}
public ItemList itemList[] = new ItemList[GameConstants.ITEM_LIMIT];
/**
* Item List
**/
public void newItemList(int ItemId, String ItemName, String ItemDescription, double ShopValue, double LowAlch, double HighAlch, int Bonuses[]) {
// first, search for a free slot
int slot = -1;
for (int i = 0; i < 11740; i++) {
if (itemList[i] == null) {
slot = i;
break;
}
}
public ItemList itemList[] = new ItemList[GameConstants.ITEM_LIMIT];
if (slot == -1) {
return; // no free slot found
}
ItemList newItemList = new ItemList(ItemId);
newItemList.itemName = ItemName;
newItemList.itemDescription = ItemDescription;
newItemList.ShopValue = ShopValue;
newItemList.LowAlch = LowAlch;
newItemList.HighAlch = HighAlch;
newItemList.Bonuses = Bonuses;
itemList[slot] = newItemList;
}
public void newItemList(int ItemId, String ItemName, String ItemDescription, double ShopValue, double LowAlch, double HighAlch, int Bonuses[]) {
// first, search for a free slot
int slot = -1;
for (int i = 0; i < 11740; i++) {
if (itemList[i] == null) {
slot = i;
break;
}
}
public void loadItemPrices(String filename) {
try {
@SuppressWarnings("resource")
Scanner s = new Scanner(new File("./data/cfg/" + filename));
while (s.hasNextLine()) {
String[] line = s.nextLine().split(" ");
ItemList temp = getItemList(Integer.parseInt(line[0]));
if (temp != null) {
temp.ShopValue = Integer.parseInt(line[1]);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
if (slot == -1) {
return; // no free slot found
}
ItemList newItemList = new ItemList(ItemId);
newItemList.itemName = ItemName;
newItemList.itemDescription = ItemDescription;
newItemList.ShopValue = ShopValue;
newItemList.LowAlch = LowAlch;
newItemList.HighAlch = HighAlch;
newItemList.Bonuses = Bonuses;
itemList[slot] = newItemList;
}
public ItemList getItemList(int i) {
for (com.rebotted.game.items.ItemList element : itemList) {
if (element != null) {
if (element.itemId == i) {
return element;
}
}
}
return null;
}
public void loadItemPrices(String filename) {
try {
@SuppressWarnings("resource")
Scanner s = new Scanner(new File("./data/cfg/" + filename));
while (s.hasNextLine()) {
String[] line = s.nextLine().split(" ");
ItemList temp = getItemList(Integer.parseInt(line[0]));
if (temp != null) {
temp.ShopValue = Integer.parseInt(line[1]);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean loadItemList(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[10];
boolean EndOfFile = false;
BufferedReader characterfile = null;
try {
characterfile = new BufferedReader(new FileReader("./data/cfg/"
+ FileName));
} catch (FileNotFoundException fileex) {
Misc.println(FileName + ": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch (IOException ioexception) {
Misc.println(FileName + ": error loading file.");
// return false;
}
while (EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t+", "\t");
token3 = token2_2.split("\t");
if (token.equals("item")) {
int[] Bonuses = new int[12];
for (int i = 0; i < 12; i++) {
if (token3[6 + i] != null) {
Bonuses[i] = Integer.parseInt(token3[6 + i]);
} else {
break;
}
}
newItemList(Integer.parseInt(token3[0]),
token3[1].replaceAll("_", " "),
token3[2].replaceAll("_", " "),
Double.parseDouble(token3[4]),
Double.parseDouble(token3[4]),
Double.parseDouble(token3[6]), Bonuses);
}
} else {
if (line.equals("[ENDOFITEMLIST]")) {
try {
characterfile.close();
} catch (IOException e) {}
//return true;
}
}
try {
line = characterfile.readLine();
} catch (IOException ioexception1) {
EndOfFile = true;
}
}
try {
characterfile.close();
} catch (IOException ioexception) {
}
return false;
}
public ItemList getItemList(int i) {
for (com.rebotted.game.items.ItemList element : itemList) {
if (element != null) {
if (element.itemId == i) {
return element;
}
}
}
return null;
}
public void loadItemListJson() {
Gson gson = new Gson();
try {
Type collectionType = new TypeToken<ItemData[]>() {
}.getType();
ItemData[] data = gson.fromJson(new FileReader("./data/cfg/items.json"), collectionType);
for (ItemData item : data) {
newItemList(item.getId(),
item.getName(),
item.getExamine(),
item.getValues().getShopValue(),
item.getValues().getLowAlch(),
item.getValues().getHighAlch(),
item.getBonuses().getBonuses());
}
} catch (FileNotFoundException fileex) {
Misc.println("items.json: file not found.");
}
}
public boolean readCfgWriteJson(String FileName) {
String line = "";
String token = "";
String token2 = "";
String token2_2 = "";
String[] token3 = new String[10];
boolean EndOfFile = false;
BufferedReader characterfile = null;
JSONArray array = new JSONArray();
try {
characterfile = new BufferedReader(new FileReader("./data/cfg/"
+ FileName));
} catch (FileNotFoundException fileex) {
Misc.println(FileName + ": file not found.");
return false;
}
try {
line = characterfile.readLine();
} catch (IOException ioexception) {
Misc.println(FileName + ": error loading file.");
// return false;
}
while (EndOfFile == false && line != null) {
line = line.trim();
int spot = line.indexOf("=");
if (spot > -1) {
token = line.substring(0, spot);
token = token.trim();
token2 = line.substring(spot + 1);
token2 = token2.trim();
token2_2 = token2.replaceAll("\t+", "\t");
token3 = token2_2.split("\t");
if (token.equals("item")) {
int[] Bonuses = new int[12];
for (int i = 0; i < 12; i++) {
if (token3[6 + i] != null) {
Bonuses[i] = Integer.parseInt(token3[6 + i]);
} else {
break;
}
}
JSONObject object = new JSONObject();
object.put("id", token3[0]);
object.put("name", token3[1].replaceAll("_", " "));
object.put("examine", token3[2].replaceAll("_", " "));
JSONArray array1 = new JSONArray();
JSONObject object1 = new JSONObject();
object1.put("shopValue", token3[4]);
object1.put("lowAlch", token3[5]);
object1.put("highAlch", token3[6]);
array1.put(0, object1);
object.put("values", array1);
JSONArray array2 = new JSONArray();
JSONObject object2 = new JSONObject();
object2.put("attackStab", Bonuses[0]);
object2.put("attackSlash", Bonuses[1]);
object2.put("attackCrush", Bonuses[2]);
object2.put("attackMagic", Bonuses[3]);
object2.put("attackRange", Bonuses[4]);
object2.put("defenceStab", Bonuses[5]);
object2.put("defenceSlash", Bonuses[6]);
object2.put("defenceCrush", Bonuses[7]);
object2.put("defenceMagic", Bonuses[8]);
object2.put("defenceRange", Bonuses[9]);
object2.put("strengthBonus", Bonuses[10]);
object2.put("prayerBonus", Bonuses[11]);
array2.put(0, object2);
object.put("bonuses", array2);
array.put(object);
}
} else {
if (line.equals("[ENDOFITEMLIST]")) {
try {
FileWriter fileWriter = new FileWriter("item-dump.json");
fileWriter.write(array.toString());
characterfile.close();
} catch (IOException e) {
}
//return true;
}
}
try {
line = characterfile.readLine();
} catch (IOException ioexception1) {
EndOfFile = true;
}
}
try {
characterfile.close();
} catch (IOException ioexception) {
}
return false;
}
}