mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-08 00:32:12 +00:00
init, thx MrExtremez
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package redone.world;
|
||||
|
||||
import redone.game.players.Client;
|
||||
|
||||
/**
|
||||
* @author Sanity
|
||||
*/
|
||||
|
||||
public class Clan {
|
||||
|
||||
public Clan(Client player, String name) {
|
||||
this.owner = player.playerName;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int[] members = new int[50];
|
||||
public String name;
|
||||
public String owner;
|
||||
public boolean lootshare;
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
package redone.world;
|
||||
|
||||
import redone.Connection;
|
||||
import redone.game.items.Item;
|
||||
import redone.game.players.Client;
|
||||
import redone.game.players.PlayerHandler;
|
||||
|
||||
/**
|
||||
* @author Sanity
|
||||
*/
|
||||
|
||||
public class ClanChatHandler {
|
||||
|
||||
public ClanChatHandler() {
|
||||
|
||||
}
|
||||
|
||||
public Clan[] clans = new Clan[100];
|
||||
|
||||
public void handleClanChat(Client player, String name) {
|
||||
for (int j = 0; j < clans.length; j++) {
|
||||
if (clans[j] != null) {
|
||||
if (clans[j].name.equalsIgnoreCase(name)) {
|
||||
addToClan(player.playerId, j);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
makeClan(player, name);
|
||||
}
|
||||
|
||||
public void makeClan(Client player, String name) {
|
||||
if (openClan() >= 0) {
|
||||
if (validName(name)) {
|
||||
player.clanId = openClan();
|
||||
clans[player.clanId] = new Clan(player, name);
|
||||
addToClan(player.playerId, player.clanId);
|
||||
} else {
|
||||
player.getActionSender().sendMessage("A clan with this name already exists.");
|
||||
}
|
||||
} else {
|
||||
player.getActionSender().sendMessage("Your clan chat request could not be completed.");
|
||||
}
|
||||
}
|
||||
|
||||
public void updateClanChat(int clanId) {
|
||||
for (int j = 0; j < clans[clanId].members.length; j++) {
|
||||
if (clans[clanId].members[j] <= 0)
|
||||
continue;
|
||||
if (PlayerHandler.players[clans[clanId].members[j]] != null) {
|
||||
Client c = (Client) PlayerHandler.players[clans[clanId].members[j]];
|
||||
c.getPlayerAssistant().sendFrame126("Talking in: " + clans[clanId].name,
|
||||
18139);
|
||||
c.getPlayerAssistant().sendFrame126("Owner: " + clans[clanId].owner, 18140);
|
||||
int slotToFill = 18144;
|
||||
for (int i = 0; i < clans[clanId].members.length; i++) {
|
||||
if (clans[clanId].members[i] > 0) {
|
||||
if (PlayerHandler.players[clans[clanId].members[i]] != null) {
|
||||
c.getPlayerAssistant().sendFrame126(PlayerHandler.players[clans[clanId].members[i]].playerName, slotToFill);
|
||||
slotToFill++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int k = slotToFill; k < 18244; k++)
|
||||
c.getPlayerAssistant().sendFrame126("", k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int openClan() {
|
||||
for (int j = 0; j < clans.length; j++) {
|
||||
if (clans[j] == null || clans[j].owner == "")
|
||||
return j;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean validName(String name) {
|
||||
for (int j = 0; j < clans.length; j++) {
|
||||
if (clans[j] != null) {
|
||||
if (clans[j].name.equalsIgnoreCase(name))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addToClan(int playerId, int clanId) {
|
||||
if (clans[clanId] != null) {
|
||||
for (int j = 0; j < clans[clanId].members.length; j++) {
|
||||
if (clans[clanId].members[j] <= 0) {
|
||||
clans[clanId].members[j] = playerId;
|
||||
PlayerHandler.players[playerId].clanId = clanId;
|
||||
// c.getActionSender().sendMessage("You have joined the clan chat: " +
|
||||
// clans[clanId].name);
|
||||
messageToClan(
|
||||
PlayerHandler.players[playerId].playerName
|
||||
+ " has joined the channel.", clanId);
|
||||
updateClanChat(clanId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void leaveClan(int playerId, int clanId) {
|
||||
if (clanId < 0) {
|
||||
Client c = (Client) PlayerHandler.players[playerId];
|
||||
c.getActionSender().sendMessage("You are not in a clan.");
|
||||
return;
|
||||
}
|
||||
if (clans[clanId] != null) {
|
||||
if (PlayerHandler.players[playerId].playerName
|
||||
.equalsIgnoreCase(clans[clanId].owner)) {
|
||||
messageToClan("The clan has been deleted by the owner.", clanId);
|
||||
destructClan(PlayerHandler.players[playerId].clanId);
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < clans[clanId].members.length; j++) {
|
||||
if (clans[clanId].members[j] == playerId) {
|
||||
clans[clanId].members[j] = -1;
|
||||
}
|
||||
}
|
||||
if (PlayerHandler.players[playerId] != null) {
|
||||
Client c = (Client) PlayerHandler.players[playerId];
|
||||
PlayerHandler.players[playerId].clanId = -1;
|
||||
c.getActionSender().sendMessage("You have left the clan.");
|
||||
c.getPlayerAssistant().clearClanChat();
|
||||
}
|
||||
updateClanChat(clanId);
|
||||
} else {
|
||||
Client c = (Client) PlayerHandler.players[playerId];
|
||||
PlayerHandler.players[playerId].clanId = -1;
|
||||
c.getActionSender().sendMessage("You are not in a clan.");
|
||||
}
|
||||
}
|
||||
|
||||
public void destructClan(int clanId) {
|
||||
if (clanId < 0)
|
||||
return;
|
||||
for (int j = 0; j < clans[clanId].members.length; j++) {
|
||||
if (clanId < 0)
|
||||
continue;
|
||||
if (clans[clanId].members[j] <= 0)
|
||||
continue;
|
||||
if (PlayerHandler.players[clans[clanId].members[j]] != null) {
|
||||
Client c = (Client) PlayerHandler.players[clans[clanId].members[j]];
|
||||
c.clanId = -1;
|
||||
c.getPlayerAssistant().clearClanChat();
|
||||
}
|
||||
}
|
||||
clans[clanId].members = new int[50];
|
||||
clans[clanId].owner = "";
|
||||
clans[clanId].name = "";
|
||||
}
|
||||
|
||||
public void messageToClan(String message, int clanId) {
|
||||
if (clanId < 0)
|
||||
return;
|
||||
for (int j = 0; j < clans[clanId].members.length; j++) {
|
||||
if (clans[clanId].members[j] < 0)
|
||||
continue;
|
||||
if (PlayerHandler.players[clans[clanId].members[j]] != null) {
|
||||
Client c = (Client) PlayerHandler.players[clans[clanId].members[j]];
|
||||
c.getActionSender().sendMessage("@red@" + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playerMessageToClan(Client c, int playerId, String message, int clanId) {
|
||||
if (Connection.isMuted(c)) {
|
||||
return;
|
||||
}
|
||||
if (clanId < 0)
|
||||
return;
|
||||
for (int j = 0; j < clans[clanId].members.length; j++) {
|
||||
if (clans[clanId].members[j] <= 0)
|
||||
continue;
|
||||
if (PlayerHandler.players[clans[clanId].members[j]] != null) {
|
||||
c = (Client) PlayerHandler.players[clans[clanId].members[j]];
|
||||
c.getActionSender().sendClan(PlayerHandler.players[playerId].playerName,
|
||||
message, clans[clanId].name,
|
||||
PlayerHandler.players[playerId].playerRights);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sendLootShareMessage(int clanId, String message) {
|
||||
if (clanId >= 0) {
|
||||
for (int j = 0; j < clans[clanId].members.length; j++) {
|
||||
if (clans[clanId].members[j] <= 0)
|
||||
continue;
|
||||
if (PlayerHandler.players[clans[clanId].members[j]] != null) {
|
||||
Client c = (Client) PlayerHandler.players[clans[clanId].members[j]];
|
||||
c.getActionSender().sendClan("Lootshare", message, clans[clanId].name, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleLootShare(Client c, int item, int amount) {
|
||||
sendLootShareMessage(c.clanId, c.playerName + " has received " + amount
|
||||
+ "x " + Item.getItemName(item) + ".");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package redone.world;
|
||||
|
||||
public final class GameObject {
|
||||
|
||||
private final int id;
|
||||
private final int type;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int face;
|
||||
|
||||
public GameObject(int id, int type, int x, int y, int face) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.face = face;
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int x() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int y() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getFace() {
|
||||
return face;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
package redone.world;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redone.event.CycleEvent;
|
||||
import redone.event.CycleEventContainer;
|
||||
import redone.event.CycleEventHandler;
|
||||
import redone.game.players.Client;
|
||||
import redone.game.players.Player;
|
||||
import redone.game.players.PlayerHandler;
|
||||
import redone.util.Misc;
|
||||
|
||||
/**
|
||||
* 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 = 30;
|
||||
|
||||
/**
|
||||
* holds all the objects
|
||||
*/
|
||||
private static List<GlobalDrop> globalDrops = new ArrayList<GlobalDrop>();
|
||||
|
||||
/**
|
||||
* 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(":");
|
||||
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();
|
||||
}
|
||||
Misc.println("Loaded " + globalDrops.size() + " global drops.");
|
||||
|
||||
for (Player player : PlayerHandler.players) {
|
||||
final Client client = (Client) player;
|
||||
if (client != null) {
|
||||
CycleEventHandler.getSingleton().addEvent(client, new CycleEvent() {
|
||||
@Override
|
||||
public void execute(CycleEventContainer container) {
|
||||
for (GlobalDrop drop : globalDrops) {
|
||||
if (drop.isTaken()) {
|
||||
if (System.currentTimeMillis() - drop.getTakenAt() >= TIME_TO_RESPAWN * 1000) {
|
||||
drop.setTaken(false);
|
||||
if (client.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
|
||||
client.getActionSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void stop() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick up an item at the given location
|
||||
*
|
||||
* @param client
|
||||
* the client
|
||||
* @param a
|
||||
* item id
|
||||
* @param b
|
||||
* cord x
|
||||
* @param c
|
||||
* cord y
|
||||
*/
|
||||
public static void pickup(Client client, int a, int b, int c) {
|
||||
GlobalDrop drop = itemExists(a, b, c);
|
||||
if (drop == null) {
|
||||
return;
|
||||
}
|
||||
if (drop.isTaken()) {
|
||||
return;
|
||||
}
|
||||
drop.setTakenAt(System.currentTimeMillis());
|
||||
drop.setTaken(true);
|
||||
if (client.getItemAssistant().freeSlots() > 0) {
|
||||
client.getItemAssistant().addItem(drop.getId(), drop.getAmount());
|
||||
}
|
||||
// TODO use the region manager for this...
|
||||
for (Player player : PlayerHandler.players) {
|
||||
Client cl = (Client) player;
|
||||
if (cl != null) {
|
||||
if (cl.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
|
||||
// cl.getItems().removeGroundItem(drop.getId(), drop.getX(),
|
||||
// drop.getY(), drop.getAmount());
|
||||
cl.getActionSender().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all the items when a player changes region
|
||||
*
|
||||
* @param client
|
||||
* the client
|
||||
*/
|
||||
public static void load(Client client) {
|
||||
for (GlobalDrop drop : globalDrops) {
|
||||
if (!drop.isTaken()) {
|
||||
if (client.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
|
||||
client.getActionSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds each drops data
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
static class GlobalDrop {
|
||||
|
||||
/**
|
||||
* cord x
|
||||
*/
|
||||
int x;
|
||||
/**
|
||||
* cord y
|
||||
*/
|
||||
int y;
|
||||
/**
|
||||
* item id
|
||||
*/
|
||||
int id;
|
||||
/**
|
||||
* item amount
|
||||
*/
|
||||
int amount;
|
||||
/**
|
||||
* has the item been taken
|
||||
*/
|
||||
boolean taken = false;
|
||||
/**
|
||||
* Time it was taken at
|
||||
*/
|
||||
long takenAt;
|
||||
|
||||
/**
|
||||
* Sets the drop arguments
|
||||
*
|
||||
* @param a
|
||||
* item id
|
||||
* @param b
|
||||
* item amount
|
||||
* @param c
|
||||
* cord x
|
||||
* @param d
|
||||
* cord y
|
||||
*/
|
||||
public GlobalDrop(int a, int b, int c, int d) {
|
||||
id = a;
|
||||
amount = b;
|
||||
x = c;
|
||||
y = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* get cord x
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* get cord x
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,435 @@
|
||||
package redone.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 redone.Constants;
|
||||
import redone.game.items.GroundItem;
|
||||
import redone.game.items.ItemAssistant;
|
||||
import redone.game.items.ItemList;
|
||||
import redone.game.players.Client;
|
||||
import redone.game.players.Player;
|
||||
import redone.game.players.PlayerHandler;
|
||||
import redone.util.GameLogger;
|
||||
import redone.util.Misc;
|
||||
|
||||
/**
|
||||
* Handles ground items
|
||||
**/
|
||||
|
||||
public class ItemHandler {
|
||||
|
||||
public List<GroundItem> items = new ArrayList<GroundItem>();
|
||||
public static final int HIDE_TICKS = 100;
|
||||
|
||||
public ItemHandler() {
|
||||
for (int i = 0; i < Constants.ITEM_LIMIT; i++) {
|
||||
ItemList[i] = null;
|
||||
}
|
||||
loadItemList("item.cfg");
|
||||
loadItemPrices("prices.txt");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds item to list
|
||||
**/
|
||||
public void addItem(GroundItem item) {
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes item from list
|
||||
**/
|
||||
public void removeItem(GroundItem item) {
|
||||
items.remove(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads any items if you enter a new region
|
||||
**/
|
||||
public void reloadItems(Client 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.getActionSender().removeGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
c.getActionSender().createGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
}
|
||||
if (i.hideTicks == 0) {
|
||||
c.getActionSender().removeGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
c.getActionSender().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 } };
|
||||
|
||||
public void createGroundItem(Client player, int itemId, int itemX, int itemY, int itemAmount, int playerId) {
|
||||
if (itemId > 0) {
|
||||
if (itemId >= 2412 && itemId <= 2414) {
|
||||
player.getActionSender().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 (player.isDead == false) {
|
||||
return;
|
||||
}
|
||||
if (!redone.game.items.Item.itemStackable[itemId] && itemAmount > 0) {
|
||||
for (int j = 0; j < itemAmount; j++) {
|
||||
player.getActionSender().createGroundItem(itemId, itemX, itemY, 1);
|
||||
GroundItem item = new GroundItem(itemId, itemX, itemY, player.getH(), 1, player.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
|
||||
addItem(item);
|
||||
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
|
||||
if (player.isDead == false && itemId != 526) {
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(player.playerName, "dropitem", player.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + player.absX + " absY: " + player.absY + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.getActionSender().createGroundItem(itemId, itemX, itemY, itemAmount);
|
||||
GroundItem item = new GroundItem(itemId, itemX, itemY, player.getH(), itemAmount, player.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
|
||||
addItem(item);
|
||||
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
|
||||
if (player.isDead == false && itemId != 526) {
|
||||
if (player.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(player.playerName, "dropitem", player.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + player.absX + " absY: " + player.absY + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getActionSender().createGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removing the ground item
|
||||
**/
|
||||
|
||||
public void removeGroundItem(Client 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove item for just the item controller (item not global yet)
|
||||
**/
|
||||
|
||||
public void removeControllersItem(GroundItem i, Client c, int itemId,
|
||||
int itemX, int itemY, int itemAmount) {
|
||||
c.getActionSender().removeGroundItem(itemId, itemX, itemY,
|
||||
itemAmount);
|
||||
removeItem(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove item for everyone within 60 squares
|
||||
**/
|
||||
|
||||
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.getActionSender().removeGroundItem(itemId,
|
||||
itemX, itemY, itemAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
removeItem(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Item List
|
||||
**/
|
||||
|
||||
public ItemList ItemList[] = new ItemList[Constants.ITEM_LIMIT];
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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 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 ItemList getItemList(int i) {
|
||||
for (redone.game.items.ItemList element : ItemList) {
|
||||
if (element != null) {
|
||||
if (element.itemId == i) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\t", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\t", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\t", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\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 ioexception) {
|
||||
}
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
line = characterfile.readLine();
|
||||
} catch (IOException ioexception1) {
|
||||
EndOfFile = true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
characterfile.close();
|
||||
} catch (IOException ioexception) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,353 @@
|
||||
package redone.world;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redone.Server;
|
||||
import redone.game.content.skills.core.Mining;
|
||||
import redone.game.content.skills.core.Woodcutting;
|
||||
import redone.game.objects.Objects;
|
||||
import redone.game.players.Client;
|
||||
import redone.game.players.Player;
|
||||
import redone.game.players.PlayerHandler;
|
||||
import redone.util.Misc;
|
||||
|
||||
/**
|
||||
* @author Sanity
|
||||
*/
|
||||
|
||||
public class ObjectHandler {
|
||||
|
||||
public List<Objects> globalObjects = new ArrayList<Objects>();
|
||||
|
||||
public static List<Objects> mapObjects = new ArrayList<Objects>();
|
||||
public static List<Objects> removedObjects = new ArrayList<Objects>();
|
||||
|
||||
public ObjectHandler() {
|
||||
loadGlobalObjects("./Data/cfg/global-objects.cfg");
|
||||
// Ladders.loadGlobalLadders("./Data/Ladders/AdvancedLadders.cfg");
|
||||
}
|
||||
|
||||
public Objects getObjectByPosition(int x, int y) {
|
||||
for (Objects o : globalObjects) {
|
||||
for(int j = 0; j < globalObjects.size(); j++) {
|
||||
globalObjects.get(j);
|
||||
globalObjects.get(j);
|
||||
if(o.objectX == x && o.objectY == y) {
|
||||
return globalObjects.get(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void createAnObject(int id, int x, int y, int face) {
|
||||
Objects OBJECT = new Objects(id, x, y, 0, face, 10, 0);
|
||||
if (id == -1) {
|
||||
removeObject(OBJECT);
|
||||
} else {
|
||||
addObject(OBJECT);
|
||||
}
|
||||
//Server.canLoadObjects = true;
|
||||
Server.objectHandler.placeObject(OBJECT);
|
||||
}
|
||||
|
||||
|
||||
public void createAnObject(Client c, int id, int x, int y) {
|
||||
Objects OBJECT = new Objects(id, x, y, c.heightLevel, 0, 10, 0);
|
||||
if (id == -1) {
|
||||
removeObject(OBJECT);
|
||||
} else {
|
||||
addObject(OBJECT);
|
||||
}
|
||||
Server.objectHandler.placeObject(OBJECT);
|
||||
}
|
||||
|
||||
public void createAnObject(Client c, int id, int x, int y, int face) {
|
||||
Objects OBJECT = new Objects(id, x, y, 0, face, 10, 0);
|
||||
if (id == -1) {
|
||||
removeObject(OBJECT);
|
||||
} else {
|
||||
addObject(OBJECT);
|
||||
}
|
||||
Server.objectHandler.placeObject(OBJECT);
|
||||
}
|
||||
|
||||
public void createAnObject(int id, int x, int y) {
|
||||
Objects OBJECT = new Objects(id, x, y, 0, 0, 10, 0);
|
||||
if (id == -1) {
|
||||
removeObject(OBJECT);
|
||||
} else {
|
||||
addObject(OBJECT);
|
||||
}
|
||||
Server.objectHandler.placeObject(OBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds object to list
|
||||
**/
|
||||
public void addObject(Objects object) {
|
||||
globalObjects.add(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes object from list
|
||||
**/
|
||||
public void removeObject(Objects object) {
|
||||
globalObjects.remove(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does object exist
|
||||
**/
|
||||
public Objects objectExists(int objectX, int objectY, int objectHeight) {
|
||||
for (Objects o : globalObjects) {
|
||||
if (o.getObjectX() == objectX && o.getObjectY() == objectY
|
||||
&& o.getObjectHeight() == objectHeight) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update objects when entering a new region or logging in
|
||||
**/
|
||||
public void updateObjects(Client c) {
|
||||
for (Objects o : globalObjects) {
|
||||
if (c != null) {
|
||||
if (c.heightLevel == 0 && o.objectTicks == 0 && c.distanceToPoint(o.getObjectX(), o.getObjectY()) <= 60) {
|
||||
if (Woodcutting.playerTrees(c, o.getObjectId()) || Mining.rockExists(c, o.getObjectId())) {
|
||||
c.getActionSender().object(o.getObjectId(), o.getObjectX(), o.getObjectY(), 0, o.getObjectFace(), o.getObjectType());
|
||||
}
|
||||
}
|
||||
if (c.heightLevel == o.getObjectHeight() && !Woodcutting.playerTrees(c, o.getObjectId()) && !Mining.rockExists(c, o.getObjectId()) && o.objectTicks == 0 && c.distanceToPoint(o.getObjectX(), o.getObjectY()) <= 60) {
|
||||
c.getActionSender().object(o.getObjectId(), o.getObjectX(), o.getObjectY(), c.heightLevel, o.getObjectFace(), o.getObjectType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object for anyone who is within 60 squares of the object
|
||||
**/
|
||||
public void placeObject(Objects o) {
|
||||
for (Player p : PlayerHandler.players) {
|
||||
if (p != null) {
|
||||
Client person = (Client) p;
|
||||
if (person != null) {
|
||||
if (person.heightLevel == o.getObjectHeight()
|
||||
&& o.objectTicks == 0) {
|
||||
if (person.distanceToPoint(o.getObjectX(),
|
||||
o.getObjectY()) <= 60) {
|
||||
removeAllObjects(o);
|
||||
globalObjects.add(o);
|
||||
person.getActionSender().object(
|
||||
o.getObjectId(), o.getObjectX(),
|
||||
o.getObjectY(), o.getObjectFace(),
|
||||
o.getObjectType());
|
||||
//Region.addObject(o.getObjectId(), o.getObjectX(), o.getObjectY(), o.getObjectHeight(), o.getObjectType(), o.getObjectFace(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllObjects(Objects o) {
|
||||
for (Objects s : globalObjects) {
|
||||
if (o.getObjectX() == o.objectX && o.getObjectY() == o.objectY
|
||||
&& s.getObjectHeight() == o.getObjectHeight()) {
|
||||
globalObjects.remove(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void process() {
|
||||
for (int j = 0; j < globalObjects.size(); j++) {
|
||||
if (globalObjects.get(j) != null) {
|
||||
Objects o = globalObjects.get(j);
|
||||
if (o.objectTicks > 0) {
|
||||
o.objectTicks--;
|
||||
}
|
||||
if (o.objectTicks == 1) {
|
||||
Objects deleteObject = objectExists(o.getObjectX(),
|
||||
o.getObjectY(), o.getObjectHeight());
|
||||
removeObject(deleteObject);
|
||||
o.objectTicks = 0;
|
||||
placeObject(o);
|
||||
removeObject(o);
|
||||
if (isObelisk(o.objectId)) {
|
||||
int index = getObeliskIndex(o.objectId);
|
||||
if (activated[index]) {
|
||||
activated[index] = false;
|
||||
teleportObelisk(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean loadGlobalObjects(String fileName) {
|
||||
String line = "";
|
||||
String token = "";
|
||||
String token2 = "";
|
||||
String token2_2 = "";
|
||||
String[] token3 = new String[10];
|
||||
boolean EndOfFile = false;
|
||||
BufferedReader objectFile = null;
|
||||
try {
|
||||
objectFile = new BufferedReader(new FileReader("./" + fileName));
|
||||
} catch (FileNotFoundException fileex) {
|
||||
Misc.println(fileName + ": file not found.");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
line = objectFile.readLine();
|
||||
} catch (IOException ioexception) {
|
||||
Misc.println(fileName + ": error loading file.");
|
||||
try {
|
||||
objectFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\t", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\t", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\t", "\t");
|
||||
token2_2 = token2_2.replaceAll("\t\t", "\t");
|
||||
token3 = token2_2.split("\t");
|
||||
if (token.equals("object")) {
|
||||
Objects object = new Objects(Integer.parseInt(token3[0]),
|
||||
Integer.parseInt(token3[1]),
|
||||
Integer.parseInt(token3[2]),
|
||||
Integer.parseInt(token3[3]),
|
||||
Integer.parseInt(token3[4]),
|
||||
Integer.parseInt(token3[5]), 0);
|
||||
addObject(object);
|
||||
}
|
||||
} else {
|
||||
if (line.equals("[ENDOFOBJECTLIST]")) {
|
||||
try {
|
||||
objectFile.close();
|
||||
} catch (IOException ioexception) {
|
||||
}
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
line = objectFile.readLine();
|
||||
} catch (IOException ioexception1) {
|
||||
EndOfFile = true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
objectFile.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final int IN_USE_ID = 14825;
|
||||
|
||||
public boolean isObelisk(int id) {
|
||||
for (int obeliskId : obeliskIds) {
|
||||
if (obeliskId == id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int[] obeliskIds = { 14829, 14830, 111235, 14828, 14826, 14831 };
|
||||
public int[][] obeliskCoords = { { 3154, 3618 }, { 3225, 3665 },
|
||||
{ 3033, 3730 }, { 3104, 3792 }, { 2978, 3864 }, { 3305, 3914 } };
|
||||
public boolean[] activated = { false, false, false, false, false, false };
|
||||
|
||||
public void startObelisk(int obeliskId) {
|
||||
int index = getObeliskIndex(obeliskId);
|
||||
if (index >= 0) {
|
||||
if (!activated[index]) {
|
||||
activated[index] = true;
|
||||
Objects obby1 = new Objects(14825, obeliskCoords[index][0],
|
||||
obeliskCoords[index][1], 0, -1, 10, 0);
|
||||
Objects obby2 = new Objects(14825, obeliskCoords[index][0] + 4,
|
||||
obeliskCoords[index][1], 0, -1, 10, 0);
|
||||
Objects obby3 = new Objects(14825, obeliskCoords[index][0],
|
||||
obeliskCoords[index][1] + 4, 0, -1, 10, 0);
|
||||
Objects obby4 = new Objects(14825, obeliskCoords[index][0] + 4,
|
||||
obeliskCoords[index][1] + 4, 0, -1, 10, 0);
|
||||
addObject(obby1);
|
||||
addObject(obby2);
|
||||
addObject(obby3);
|
||||
addObject(obby4);
|
||||
Server.objectHandler.placeObject(obby1);
|
||||
Server.objectHandler.placeObject(obby2);
|
||||
Server.objectHandler.placeObject(obby3);
|
||||
Server.objectHandler.placeObject(obby4);
|
||||
Objects obby5 = new Objects(obeliskIds[index],
|
||||
obeliskCoords[index][0], obeliskCoords[index][1], 0,
|
||||
-1, 10, 10);
|
||||
Objects obby6 = new Objects(obeliskIds[index],
|
||||
obeliskCoords[index][0] + 4, obeliskCoords[index][1],
|
||||
0, -1, 10, 10);
|
||||
Objects obby7 = new Objects(obeliskIds[index],
|
||||
obeliskCoords[index][0], obeliskCoords[index][1] + 4,
|
||||
0, -1, 10, 10);
|
||||
Objects obby8 = new Objects(obeliskIds[index],
|
||||
obeliskCoords[index][0] + 4,
|
||||
obeliskCoords[index][1] + 4, 0, -1, 10, 10);
|
||||
addObject(obby5);
|
||||
addObject(obby6);
|
||||
addObject(obby7);
|
||||
addObject(obby8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getObeliskIndex(int id) {
|
||||
for (int j = 0; j < obeliskIds.length; j++) {
|
||||
if (obeliskIds[j] == id) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void teleportObelisk(int port) {
|
||||
int random = Misc.random(5);
|
||||
while (random == port) {
|
||||
random = Misc.random(5);
|
||||
}
|
||||
for (Player player : PlayerHandler.players) {
|
||||
if (player != null) {
|
||||
Client c = (Client) player;
|
||||
if (Misc.goodDistance(c.getX(), c.getY(),
|
||||
obeliskCoords[port][0] + 2, obeliskCoords[port][1] + 2,
|
||||
1)) {
|
||||
c.getPlayerAssistant().startTeleport(
|
||||
obeliskCoords[random][0] + 2,
|
||||
obeliskCoords[random][1] + 2, 0, "null");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package redone.world;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import redone.Server;
|
||||
import redone.event.CycleEvent;
|
||||
import redone.event.CycleEventContainer;
|
||||
import redone.event.CycleEventHandler;
|
||||
import redone.game.content.quests.QuestAssistant;
|
||||
import redone.game.globalworldobjects.DoubleGates;
|
||||
import redone.game.objects.Object;
|
||||
import redone.game.objects.Objects;
|
||||
import redone.game.objects.impl.FlourMill;
|
||||
import redone.game.players.Client;
|
||||
import redone.game.players.Player;
|
||||
import redone.game.players.PlayerHandler;
|
||||
import redone.util.Misc;
|
||||
import redone.world.clip.Region;
|
||||
|
||||
/**
|
||||
* @author Sanity
|
||||
*/
|
||||
|
||||
public class ObjectManager {
|
||||
|
||||
public ArrayList<Object> objects = new ArrayList<Object>();
|
||||
private final ArrayList<Object> toRemove = new ArrayList<Object>();
|
||||
|
||||
public static void objectTicks(final Client player, final int objectId, final int objectX, final int objectY, final int objectH, final int face, final int objectType, int ticks) {
|
||||
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
|
||||
@Override
|
||||
public void execute(CycleEventContainer container) {
|
||||
player.getActionSender().object(objectId, objectX, objectY, objectH, face, objectType);
|
||||
container.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}, ticks);
|
||||
}
|
||||
|
||||
public static void singleGateTicks(final Client player, final int objectId, final int objectX, final int objectY, final int x1, final int y1, final int objectH, final int face, int ticks) {
|
||||
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
|
||||
@Override
|
||||
public void execute(CycleEventContainer container) {
|
||||
if (DoubleGates.gateAmount == 0) {
|
||||
container.stop();
|
||||
return;
|
||||
}
|
||||
Server.objectHandler.placeObject(new Objects(-1, x1, y1, objectH, face, 0, 0));
|
||||
Server.objectHandler.placeObject(new Objects(objectId, objectX, objectY, objectH, face, 0, 0));
|
||||
container.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (DoubleGates.gateAmount == 1) {
|
||||
DoubleGates.gateAmount = 0;
|
||||
}
|
||||
}
|
||||
}, ticks);
|
||||
}
|
||||
|
||||
public static void doubleGateTicks(final Client player, final int objectId, final int objectX, final int objectY, final int x1, final int y1, final int x2, final int y2, final int objectH, final int face, int ticks) {
|
||||
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
|
||||
@Override
|
||||
public void execute(CycleEventContainer container) {
|
||||
if (DoubleGates.gateAmount == 0) {
|
||||
container.stop();
|
||||
return;
|
||||
}
|
||||
Server.objectHandler.placeObject(new Objects(-1, x1, y1, objectH, face, 0, 0));
|
||||
Server.objectHandler.placeObject(new Objects(-1, x2, y2, objectH, face, 0, 0));
|
||||
Server.objectHandler.placeObject(new Objects(objectId, objectX, objectY, objectH, face, 0, 0));
|
||||
container.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (DoubleGates.gateAmount == 2) {
|
||||
DoubleGates.gateAmount = 1;
|
||||
} else if (DoubleGates.gateAmount == 1) {
|
||||
DoubleGates.gateAmount = 0;
|
||||
}
|
||||
}
|
||||
}, ticks);
|
||||
}
|
||||
|
||||
|
||||
public boolean objectExists(final int x, final int y) {
|
||||
for (Object o : objects) {
|
||||
if (o.objectX == x && o.objectY == y) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
for (final Object o : objects) {
|
||||
if (o.tick > 0) {
|
||||
o.tick--;
|
||||
} else {
|
||||
updateObject(o);
|
||||
toRemove.add(o);
|
||||
}
|
||||
}
|
||||
for (final Object o : toRemove) {
|
||||
/*if (o.objectId == 2732) {
|
||||
for (final Player player : PlayerHandler.players) {
|
||||
if (player != null) {
|
||||
final Client c = (Client) player;
|
||||
Server.itemHandler.createGroundItem(c, 592, o.objectX, o.objectY, 1, c.playerId);
|
||||
if (c.playerIsCooking) {
|
||||
Cooking.resetCooking(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (isObelisk(o.newId)) {
|
||||
final int index = getObeliskIndex(o.newId);
|
||||
if (activated[index]) {
|
||||
activated[index] = false;
|
||||
teleportObelisk(index);
|
||||
}
|
||||
}
|
||||
objects.remove(o);
|
||||
}
|
||||
toRemove.clear();
|
||||
}
|
||||
|
||||
public void removeObject(int x, int y) {
|
||||
for (Player player : PlayerHandler.players) {
|
||||
if (player != null) {
|
||||
Client c = (Client) player;
|
||||
c.getActionSender().object(-1, x, y, 0, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateObject(Object o) {
|
||||
for (Player player : PlayerHandler.players) {
|
||||
if (player != null) {
|
||||
Client c = (Client) player;
|
||||
c.getActionSender().object(o.newId, o.objectX, o.objectY,
|
||||
o.face, o.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void placeObject(Object o) {
|
||||
for (Player player : PlayerHandler.players) {
|
||||
if (player != null) {
|
||||
Client c = (Client) player;
|
||||
if (c.distanceToPoint(o.objectX, o.objectY) <= 60) {
|
||||
c.getActionSender().object(o.objectId, o.objectX,
|
||||
o.objectY, o.face, o.type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object getObject(int x, int y, int height) {
|
||||
for (Object o : objects) {
|
||||
if (o.objectX == x && o.objectY == y && o.height == height) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void loadObjects(Client c) {
|
||||
if (c == null) {
|
||||
return;
|
||||
}
|
||||
for (Object o : objects) {
|
||||
if (loadForPlayer(o, c)) {
|
||||
c.getActionSender().object(o.objectId, o.objectX, o.objectY, o.face, o.type);
|
||||
}
|
||||
}
|
||||
loadCustomSpawns(c);
|
||||
}
|
||||
|
||||
public void loadCustomSpawns(Client client) {
|
||||
client.getActionSender().checkObjectSpawn(2474, 3233, 9312, 0, 10);
|
||||
if (client.rope == true) {
|
||||
client.getActionSender().object(3828, 3227, 3108, 0, 0, 10);
|
||||
Region.addObject(3828, 3227, 3108, 0, 10, 0, false);
|
||||
}
|
||||
if (client.rope2 == true) {
|
||||
client.getActionSender().object(3828, 3509, 9497, 2, 0, 10);
|
||||
Region.addObject(3828, 3509, 9497, 2, 10, 0, false);
|
||||
}
|
||||
if (client.questPoints >= QuestAssistant.MAXIMUM_QUESTPOINTS) {
|
||||
client.getActionSender().checkObjectSpawn(2403, 3219, 9623, 3, 10);// RFD
|
||||
} else {
|
||||
client.getActionSender().checkObjectSpawn(-1, 3219, 9623, 3, 10);// RFD
|
||||
}
|
||||
// CHEST
|
||||
if (client.flourAmount > 0 && client.heightLevel == 0) {
|
||||
client.getActionSender().checkObjectSpawn(FlourMill.FULL_FLOUR_BIN, 3166, 3306, 0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
public final int IN_USE_ID = 14825;
|
||||
|
||||
public boolean isObelisk(int id) {
|
||||
for (int obeliskId : obeliskIds) {
|
||||
if (obeliskId == id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int[] obeliskIds = { 14829, 14830, 14827, 14828, 14826, 14831 };
|
||||
public int[][] obeliskCoords = { { 3154, 3618 }, { 3225, 3665 },
|
||||
{ 3033, 3730 }, { 3104, 3792 }, { 2978, 3864 }, { 3305, 3914 } };
|
||||
public boolean[] activated = { false, false, false, false, false, false };
|
||||
|
||||
public void startObelisk(int obeliskId) {
|
||||
int index = getObeliskIndex(obeliskId);
|
||||
if (index >= 0) {
|
||||
if (!activated[index]) {
|
||||
activated[index] = true;
|
||||
addObject(new Object(14825, obeliskCoords[index][0],
|
||||
obeliskCoords[index][1], 0, -1, 10, obeliskId, 16));
|
||||
addObject(new Object(14825, obeliskCoords[index][0] + 4,
|
||||
obeliskCoords[index][1], 0, -1, 10, obeliskId, 16));
|
||||
addObject(new Object(14825, obeliskCoords[index][0],
|
||||
obeliskCoords[index][1] + 4, 0, -1, 10, obeliskId, 16));
|
||||
addObject(new Object(14825, obeliskCoords[index][0] + 4,
|
||||
obeliskCoords[index][1] + 4, 0, -1, 10, obeliskId, 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getObeliskIndex(int id) {
|
||||
for (int j = 0; j < obeliskIds.length; j++) {
|
||||
if (obeliskIds[j] == id) {
|
||||
return j;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void teleportObelisk(int port) {
|
||||
int random = Misc.random(5);
|
||||
while (random == port) {
|
||||
random = Misc.random(5);
|
||||
}
|
||||
for (Player player : PlayerHandler.players) {
|
||||
if (player != null) {
|
||||
Client c = (Client) player;
|
||||
int xOffset = c.absX - obeliskCoords[port][0];
|
||||
int yOffset = c.absY - obeliskCoords[port][1];
|
||||
if (c.goodDistance(c.getX(), c.getY(),
|
||||
obeliskCoords[port][0] + 2, obeliskCoords[port][1] + 2,
|
||||
1)) {
|
||||
c.getPlayerAssistant().startTeleport2(
|
||||
obeliskCoords[random][0] + xOffset,
|
||||
obeliskCoords[random][1] + yOffset, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean loadForPlayer(Object o, Client c) {
|
||||
if (o == null || c == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height;
|
||||
}
|
||||
|
||||
public void addObject(Object o) {
|
||||
if (getObject(o.objectX, o.objectY, o.height) == null) {
|
||||
objects.add(o);
|
||||
placeObject(o);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package redone.world;
|
||||
|
||||
public class Tile {
|
||||
|
||||
private int[] pointer = new int[3];
|
||||
|
||||
public Tile(int x, int y, int z) {
|
||||
this.pointer[0] = x;
|
||||
this.pointer[1] = y;
|
||||
this.pointer[2] = z;
|
||||
}
|
||||
|
||||
public Tile(int x, int y) {
|
||||
this.pointer[0] = x;
|
||||
this.pointer[1] = y;
|
||||
}
|
||||
|
||||
public int[] getTile() {
|
||||
return pointer;
|
||||
}
|
||||
|
||||
public int getTileX() {
|
||||
return pointer[0];
|
||||
}
|
||||
|
||||
public int getTileY() {
|
||||
return pointer[1];
|
||||
}
|
||||
|
||||
public int getTileHeight() {
|
||||
return pointer[2];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package redone.world;
|
||||
|
||||
import redone.game.npcs.Npc;
|
||||
import redone.game.npcs.NpcSize;
|
||||
import redone.game.players.Client;
|
||||
|
||||
public class TileControl {
|
||||
|
||||
public static Tile generate(int x, int y, int z) {
|
||||
return new Tile(x, y, z);
|
||||
}
|
||||
|
||||
public static Tile[] getTiles(Client client) {
|
||||
|
||||
int size = 1, tileCount = 0;
|
||||
|
||||
Tile[] tiles = new Tile[size * size];
|
||||
|
||||
if (tiles.length == 1)
|
||||
tiles[0] = generate(client.absX, client.absY, client.heightLevel);
|
||||
else {
|
||||
for (int x = 0; x < size; x++)
|
||||
for (int y = 0; y < size; y++)
|
||||
tiles[tileCount++] = generate(client.absX + x, client.absY + y, client.heightLevel);
|
||||
}
|
||||
return tiles;
|
||||
}
|
||||
|
||||
public static Tile[] getTiles(Npc npc) {
|
||||
|
||||
int size = 1, tileCount = 0;
|
||||
|
||||
size = NpcSize.getNPCSize(npc.npcType);
|
||||
Tile[] tiles = new Tile[size * size];
|
||||
|
||||
if (tiles.length == 1)
|
||||
tiles[0] = generate(npc.absX, npc.absY, npc.heightLevel);
|
||||
else {
|
||||
for (int x = 0; x < size; x++)
|
||||
for (int y = 0; y < size; y++)
|
||||
tiles[tileCount++] = generate(npc.absX + x, npc.absY + y, npc.heightLevel);
|
||||
}
|
||||
return tiles;
|
||||
}
|
||||
|
||||
public static int calculateDistance(Client client, Client following) {
|
||||
|
||||
Tile[] tiles = getTiles(client);
|
||||
|
||||
int[] location = currentLocation(client);
|
||||
int[] pointer = new int[tiles.length];
|
||||
|
||||
int lowestCount = 20, count = 0;
|
||||
|
||||
for (Tile newTiles : tiles) {
|
||||
if (newTiles.getTile() == location)
|
||||
pointer[count++] = 0;
|
||||
else
|
||||
pointer[count++] = calculateDistance(newTiles, following);
|
||||
}
|
||||
for (int i = 0; i < pointer.length; i++)
|
||||
if (pointer[i] < lowestCount)
|
||||
lowestCount = pointer[i];
|
||||
|
||||
return lowestCount;
|
||||
}
|
||||
|
||||
public static int calculateDistance(Npc npc, Client following) {
|
||||
|
||||
Tile[] tiles = getTiles(npc);
|
||||
|
||||
int[] location = currentLocation(npc);
|
||||
int[] pointer = new int[tiles.length];
|
||||
|
||||
int lowestCount = 20, count = 0;
|
||||
|
||||
for (Tile newTiles : tiles) {
|
||||
if (newTiles.getTile() == location)
|
||||
pointer[count++] = 0;
|
||||
else
|
||||
pointer[count++] = calculateDistance(newTiles, following);
|
||||
}
|
||||
for (int i = 0; i < pointer.length; i++)
|
||||
if (pointer[i] < lowestCount)
|
||||
lowestCount = pointer[i];
|
||||
|
||||
return lowestCount;
|
||||
}
|
||||
|
||||
public static int calculateDistance(Client client, Npc npc) {
|
||||
|
||||
Tile[] tiles = getTiles(client);
|
||||
|
||||
int[] location = currentLocation(client);
|
||||
int[] pointer = new int[tiles.length];
|
||||
|
||||
int lowestCount = 20, count = 0;
|
||||
|
||||
for (Tile newTiles : tiles) {
|
||||
if (newTiles.getTile() == location)
|
||||
pointer[count++] = 0;
|
||||
else
|
||||
pointer[count++] = calculateDistance(newTiles, npc);
|
||||
}
|
||||
for (int i = 0; i < pointer.length; i++)
|
||||
if (pointer[i] < lowestCount)
|
||||
lowestCount = pointer[i];
|
||||
|
||||
return lowestCount;
|
||||
}
|
||||
|
||||
public static int calculateDistance(Tile location, Client other) {
|
||||
int X = Math.abs(location.getTile()[0] - other.absX);
|
||||
int Y = Math.abs(location.getTile()[1] - other.absY);
|
||||
return X > Y ? X : Y;
|
||||
}
|
||||
|
||||
public static int calculateDistance(Tile location, Npc other) {
|
||||
int X = Math.abs(location.getTile()[0] - other.absX);
|
||||
int Y = Math.abs(location.getTile()[1] - other.absY);
|
||||
return X > Y ? X : Y;
|
||||
}
|
||||
|
||||
public static int calculateDistance(int[] location, int[] other) {
|
||||
int X = Math.abs(location[0] - other[0]);
|
||||
int Y = Math.abs(location[1] - other[1]);
|
||||
return X > Y ? X : Y;
|
||||
}
|
||||
|
||||
public static int[] currentLocation(Client client) {
|
||||
int[] currentLocation = new int[3];
|
||||
if (client != null) {
|
||||
currentLocation[0] = client.absX;
|
||||
currentLocation[1] = client.absY;
|
||||
currentLocation[2] = client.heightLevel;
|
||||
}
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
public static int[] currentLocation(Npc npc) {
|
||||
int[] currentLocation = new int[3];
|
||||
if (npc != null) {
|
||||
currentLocation[0] = npc.absX;
|
||||
currentLocation[1] = npc.absY;
|
||||
currentLocation[2] = npc.heightLevel;
|
||||
}
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
public static int[] currentLocation(Tile tileLocation) {
|
||||
|
||||
int[] currentLocation = new int[3];
|
||||
|
||||
if (tileLocation != null) {
|
||||
currentLocation[0] = tileLocation.getTile()[0];
|
||||
currentLocation[1] = tileLocation.getTile()[1];
|
||||
currentLocation[2] = tileLocation.getTile()[2];
|
||||
}
|
||||
return currentLocation;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package redone.world.clip;
|
||||
|
||||
public class ByteStream {
|
||||
|
||||
private final byte[] buffer;
|
||||
private int offset;
|
||||
|
||||
public ByteStream(byte[] buffer) {
|
||||
this.buffer = buffer;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
public void skip(int length) {
|
||||
offset += length;
|
||||
}
|
||||
|
||||
public void setOffset(int position) {
|
||||
offset = position;
|
||||
}
|
||||
|
||||
public void setOffset(long position) {
|
||||
offset = (int) position;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return buffer.length;
|
||||
}
|
||||
|
||||
public byte getByte() {
|
||||
return buffer[offset++];
|
||||
}
|
||||
|
||||
public int getUByte() {
|
||||
return buffer[offset++] & 0xff;
|
||||
}
|
||||
|
||||
public int getShort() {
|
||||
int val = (getByte() << 8) + getByte();
|
||||
if (val > 32767) {
|
||||
val -= 0x10000;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public int getUShort() {
|
||||
return (getUByte() << 8) + getUByte();
|
||||
}
|
||||
|
||||
public int getInt() {
|
||||
return (getUByte() << 24) + (getUByte() << 16) + (getUByte() << 8)
|
||||
+ getUByte();
|
||||
}
|
||||
|
||||
public long getLong() {
|
||||
return (getUByte() << 56) + (getUByte() << 48) + (getUByte() << 40)
|
||||
+ (getUByte() << 32) + (getUByte() << 24) + (getUByte() << 16)
|
||||
+ (getUByte() << 8) + getUByte();
|
||||
}
|
||||
|
||||
public int getUSmart() {
|
||||
int i = buffer[offset] & 0xff;
|
||||
if (i < 128) {
|
||||
return getUByte();
|
||||
} else {
|
||||
return getUShort() - 32768;
|
||||
}
|
||||
}
|
||||
|
||||
public String getNString() {
|
||||
int i = offset;
|
||||
while (buffer[offset++] != 0) {
|
||||
;
|
||||
}
|
||||
return new String(buffer, i, offset - i - 1);
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
int i = offset;
|
||||
while (buffer[offset++] != 10) {
|
||||
;
|
||||
}
|
||||
byte abyte0[] = new byte[offset - i - 1];
|
||||
System.arraycopy(buffer, i, abyte0, i - i, offset - 1 - i);
|
||||
return abyte0;
|
||||
}
|
||||
|
||||
public byte[] read(int length) {
|
||||
byte[] b = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
b[i] = buffer[offset++];
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package redone.world.clip;
|
||||
|
||||
public final class ByteStreamExt {
|
||||
|
||||
public void skip(int length) {
|
||||
currentOffset += length;
|
||||
}
|
||||
|
||||
public ByteStreamExt(byte abyte0[]) {
|
||||
buffer = abyte0;
|
||||
currentOffset = 0;
|
||||
}
|
||||
|
||||
public int readUnsignedByte() {
|
||||
return buffer[currentOffset++] & 0xff;
|
||||
}
|
||||
|
||||
public byte readSignedByte() {
|
||||
return buffer[currentOffset++];
|
||||
}
|
||||
|
||||
public int readUnsignedWord() {
|
||||
currentOffset += 2;
|
||||
return ((buffer[currentOffset - 2] & 0xff) << 8)
|
||||
+ (buffer[currentOffset - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int readSignedWord() {
|
||||
currentOffset += 2;
|
||||
int i = ((buffer[currentOffset - 2] & 0xff) << 8)
|
||||
+ (buffer[currentOffset - 1] & 0xff);
|
||||
if (i > 32767) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int read3Bytes() {
|
||||
currentOffset += 3;
|
||||
return ((buffer[currentOffset - 3] & 0xff) << 16)
|
||||
+ ((buffer[currentOffset - 2] & 0xff) << 8)
|
||||
+ (buffer[currentOffset - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int readR3Bytes() {
|
||||
currentOffset += 3;
|
||||
return ((buffer[currentOffset - 1] & 0xff) << 16)
|
||||
+ ((buffer[currentOffset - 2] & 0xff) << 8)
|
||||
+ (buffer[currentOffset - 3] & 0xff);
|
||||
}
|
||||
|
||||
public int readDWord() {
|
||||
currentOffset += 4;
|
||||
return ((buffer[currentOffset - 4] & 0xff) << 24)
|
||||
+ ((buffer[currentOffset - 3] & 0xff) << 16)
|
||||
+ ((buffer[currentOffset - 2] & 0xff) << 8)
|
||||
+ (buffer[currentOffset - 1] & 0xff);
|
||||
}
|
||||
|
||||
public long readQWord() {
|
||||
long l = readDWord() & 0xffffffffL;
|
||||
long l1 = readDWord() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
|
||||
public String readString() {
|
||||
int i = currentOffset;
|
||||
while (buffer[currentOffset++] != 10) {
|
||||
;
|
||||
}
|
||||
return new String(buffer, i, currentOffset - i - 1);
|
||||
}
|
||||
|
||||
public String readNewString() {
|
||||
int i = currentOffset;
|
||||
while (buffer[currentOffset++] != 0) {
|
||||
;
|
||||
}
|
||||
return new String(buffer, i, currentOffset - i - 1);
|
||||
}
|
||||
|
||||
public byte[] readBytes() {
|
||||
int i = currentOffset;
|
||||
while (buffer[currentOffset++] != 10) {
|
||||
;
|
||||
}
|
||||
byte abyte0[] = new byte[currentOffset - i - 1];
|
||||
System.arraycopy(buffer, i, abyte0, i - i, currentOffset - 1 - i);
|
||||
return abyte0;
|
||||
}
|
||||
|
||||
public void readBytes(int i, int j, byte abyte0[]) {
|
||||
for (int l = j; l < j + i; l++) {
|
||||
abyte0[l] = buffer[currentOffset++];
|
||||
}
|
||||
}
|
||||
|
||||
public byte buffer[];
|
||||
public int currentOffset;
|
||||
|
||||
// removed useless static initializer
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package redone.world.clip;
|
||||
|
||||
public class MemoryArchive {
|
||||
|
||||
private final ByteStream cache;
|
||||
private final ByteStream index;
|
||||
private static final int INDEX_DATA_CHUNK_SIZE = 12;
|
||||
|
||||
public MemoryArchive(ByteStream cache, ByteStream index) {
|
||||
this.cache = cache;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public byte[] get(int dataIndex) {
|
||||
try {
|
||||
if (index.length() < dataIndex * INDEX_DATA_CHUNK_SIZE) {
|
||||
return null;
|
||||
}
|
||||
index.setOffset(dataIndex * INDEX_DATA_CHUNK_SIZE);
|
||||
long fileOffset = index.getLong();
|
||||
int fileSize = index.getInt();
|
||||
cache.setOffset(fileOffset);
|
||||
byte[] buffer = cache.read(fileSize);
|
||||
return buffer;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int contentSize() {
|
||||
return index.length() / 12;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
package redone.world.clip;
|
||||
|
||||
public final class ObjectDef {
|
||||
|
||||
public static ObjectDef getObjectDef(int i) {
|
||||
for (int j = 0; j < 20; j++) {
|
||||
if (cache[j].type == i) {
|
||||
return cache[j];
|
||||
}
|
||||
}
|
||||
|
||||
cacheIndex = (cacheIndex + 1) % 20;
|
||||
ObjectDef class46 = cache[cacheIndex];
|
||||
class46.type = i;
|
||||
class46.setDefaults();
|
||||
byte[] buffer = archive.get(i);
|
||||
if (buffer != null && buffer.length > 0) {
|
||||
class46.readValues(new ByteStreamExt(buffer));
|
||||
}
|
||||
return class46;
|
||||
}
|
||||
|
||||
private void setDefaults() {
|
||||
anIntArray773 = null;
|
||||
anIntArray776 = null;
|
||||
name = null;
|
||||
description = null;
|
||||
modifiedModelColors = null;
|
||||
originalModelColors = null;
|
||||
anInt744 = 1;
|
||||
anInt761 = 1;
|
||||
aBoolean767 = true;
|
||||
aBoolean757 = true;
|
||||
hasActions = false;
|
||||
aBoolean762 = false;
|
||||
aBoolean764 = false;
|
||||
anInt781 = -1;
|
||||
anInt775 = 16;
|
||||
actions = null;
|
||||
anInt746 = -1;
|
||||
anInt758 = -1;
|
||||
aBoolean779 = true;
|
||||
anInt768 = 0;
|
||||
aBoolean736 = false;
|
||||
anInt774 = -1;
|
||||
anInt749 = -1;
|
||||
childrenIDs = null;
|
||||
}
|
||||
|
||||
public static void loadConfig() {
|
||||
archive = new MemoryArchive(new ByteStream(getBuffer("loc.dat")),
|
||||
new ByteStream(getBuffer("loc.idx")));
|
||||
cache = new ObjectDef[20];
|
||||
for (int k = 0; k < 20; k++) {
|
||||
cache[k] = new ObjectDef();
|
||||
}
|
||||
System.out.println("[ObjectDef] DONE LOADING OBJECT CONFIGURATION");
|
||||
}
|
||||
|
||||
public static byte[] getBuffer(String s) {
|
||||
try {
|
||||
java.io.File f = new java.io.File("./Data/world/object/" + s);
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
byte[] buffer = new byte[(int) f.length()];
|
||||
java.io.DataInputStream dis = new java.io.DataInputStream(
|
||||
new java.io.FileInputStream(f));
|
||||
dis.readFully(buffer);
|
||||
dis.close();
|
||||
return buffer;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void readValues(ByteStreamExt stream) {
|
||||
int flag = -1;
|
||||
do {
|
||||
int type = stream.readUnsignedByte();
|
||||
if (type == 0) {
|
||||
break;
|
||||
}
|
||||
if (type == 1) {
|
||||
int len = stream.readUnsignedByte();
|
||||
if (len > 0) {
|
||||
if (anIntArray773 == null || lowMem) {
|
||||
anIntArray776 = new int[len];
|
||||
anIntArray773 = new int[len];
|
||||
for (int k1 = 0; k1 < len; k1++) {
|
||||
anIntArray773[k1] = stream.readUnsignedWord();
|
||||
anIntArray776[k1] = stream.readUnsignedByte();
|
||||
}
|
||||
} else {
|
||||
stream.currentOffset += len * 3;
|
||||
}
|
||||
}
|
||||
} else if (type == 2) {
|
||||
name = stream.readNewString();
|
||||
} else if (type == 5) {
|
||||
int len = stream.readUnsignedByte();
|
||||
if (len > 0) {
|
||||
if (anIntArray773 == null || lowMem) {
|
||||
anIntArray776 = null;
|
||||
anIntArray773 = new int[len];
|
||||
for (int l1 = 0; l1 < len; l1++) {
|
||||
anIntArray773[l1] = stream.readUnsignedWord();
|
||||
}
|
||||
} else {
|
||||
stream.currentOffset += len * 2;
|
||||
}
|
||||
}
|
||||
} else if (type == 14) {
|
||||
anInt744 = stream.readUnsignedByte();
|
||||
} else if (type == 15) {
|
||||
anInt761 = stream.readUnsignedByte();
|
||||
} else if (type == 17) {
|
||||
aBoolean767 = false;
|
||||
} else if (type == 18) {
|
||||
aBoolean757 = false;
|
||||
} else if (type == 19) {
|
||||
hasActions = stream.readUnsignedByte() == 1;
|
||||
} else if (type == 21) {
|
||||
aBoolean762 = true;
|
||||
} else if (type == 22) {
|
||||
} else if (type == 23) {
|
||||
aBoolean764 = true;
|
||||
} else if (type == 24) {
|
||||
anInt781 = stream.readUnsignedWord();
|
||||
if (anInt781 == 65535) {
|
||||
anInt781 = -1;
|
||||
}
|
||||
} else if (type == 27) {
|
||||
continue;
|
||||
} else if (type == 28) {
|
||||
anInt775 = stream.readUnsignedByte();
|
||||
} else if (type == 29) {
|
||||
stream.readSignedByte();
|
||||
} else if (type == 39) {
|
||||
stream.readSignedByte();
|
||||
} else if (type >= 30 && type < 39) {
|
||||
if (actions == null) {
|
||||
actions = new String[5];
|
||||
}
|
||||
actions[type - 30] = stream.readNewString();
|
||||
hasActions = true;
|
||||
if (actions[type - 30].equalsIgnoreCase("hidden")) {
|
||||
actions[type - 30] = null;
|
||||
}
|
||||
} else if (type == 40) {
|
||||
int i1 = stream.readUnsignedByte();
|
||||
modifiedModelColors = new int[i1];
|
||||
originalModelColors = new int[i1];
|
||||
for (int i2 = 0; i2 < i1; i2++) {
|
||||
modifiedModelColors[i2] = stream.readUnsignedWord();
|
||||
originalModelColors[i2] = stream.readUnsignedWord();
|
||||
}
|
||||
|
||||
} else if (type == 41) {
|
||||
int l = stream.readUnsignedByte();
|
||||
stream.skip(l * 4);
|
||||
} else if (type == 42) {
|
||||
int l = stream.readUnsignedByte();
|
||||
stream.skip(l);
|
||||
} else if (type == 60) {
|
||||
anInt746 = stream.readUnsignedWord();
|
||||
} else if (type == 62) {
|
||||
} else if (type == 64) {
|
||||
aBoolean779 = false;
|
||||
} else if (type == 65) {
|
||||
stream.readUnsignedWord();
|
||||
} else if (type == 66) {
|
||||
stream.readUnsignedWord();
|
||||
} else if (type == 67) {
|
||||
stream.readUnsignedWord();
|
||||
} else if (type == 68) {
|
||||
anInt758 = stream.readUnsignedWord();
|
||||
} else if (type == 69) {
|
||||
anInt768 = stream.readUnsignedByte();
|
||||
} else if (type == 70) {
|
||||
stream.readSignedWord();
|
||||
} else if (type == 71) {
|
||||
stream.readSignedWord();
|
||||
} else if (type == 72) {
|
||||
stream.readSignedWord();
|
||||
} else if (type == 73) {
|
||||
aBoolean736 = true;
|
||||
} else if (type == 74) {
|
||||
} else if (type == 75) {
|
||||
stream.readUnsignedByte();
|
||||
} else if (type == 77 || type == 92) {
|
||||
anInt774 = stream.readUnsignedWord();
|
||||
if (anInt774 == 65535) {
|
||||
anInt774 = -1;
|
||||
}
|
||||
anInt749 = stream.readUnsignedWord();
|
||||
if (anInt749 == 65535) {
|
||||
anInt749 = -1;
|
||||
}
|
||||
int endChild = -1;
|
||||
if (type == 92) {
|
||||
endChild = stream.readUnsignedWord();
|
||||
if (endChild == 65535) {
|
||||
endChild = -1;
|
||||
}
|
||||
}
|
||||
int j1 = stream.readUnsignedByte();
|
||||
childrenIDs = new int[j1 + 2];
|
||||
for (int j2 = 0; j2 <= j1; j2++) {
|
||||
childrenIDs[j2] = stream.readUnsignedWord();
|
||||
if (childrenIDs[j2] == 65535) {
|
||||
childrenIDs[j2] = -1;
|
||||
}
|
||||
}
|
||||
childrenIDs[j1 + 1] = endChild;
|
||||
} else if (type == 78) {
|
||||
stream.skip(3);
|
||||
} else if (type == 79) {
|
||||
stream.skip(5);
|
||||
int l = stream.readUnsignedByte();
|
||||
stream.skip(l * 2);
|
||||
} else if (type == 81) {
|
||||
stream.skip(1);
|
||||
} else if (type == 82 || type == 88 || type == 89 || type == 90
|
||||
|| type == 91 || type == 94 || type == 95 || type == 96
|
||||
|| type == 97) {
|
||||
continue;
|
||||
} else if (type == 93) {
|
||||
stream.skip(2);
|
||||
} else if (type == 249) {
|
||||
int l = stream.readUnsignedByte();
|
||||
for (int ii = 0; ii < l; ii++) {
|
||||
boolean b = stream.readUnsignedByte() == 1;
|
||||
stream.skip(3);
|
||||
if (b) {
|
||||
stream.readNewString();
|
||||
} else {
|
||||
stream.skip(4);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Unknown config: " + type);
|
||||
}
|
||||
} while (true);
|
||||
if (flag == -1) {
|
||||
hasActions = anIntArray773 != null
|
||||
&& (anIntArray776 == null || anIntArray776[0] == 10);
|
||||
if (actions != null) {
|
||||
hasActions = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ObjectDef() {
|
||||
type = -1;
|
||||
}
|
||||
|
||||
public boolean hasActions() {
|
||||
return hasActions;
|
||||
}
|
||||
|
||||
public boolean hasName() {
|
||||
return name != null && name.length() > 1;
|
||||
}
|
||||
|
||||
public boolean solid() {
|
||||
return aBoolean779;
|
||||
}
|
||||
|
||||
public int xLength() {
|
||||
return anInt744;
|
||||
}
|
||||
|
||||
public int yLength() {
|
||||
return anInt761;
|
||||
}
|
||||
|
||||
public boolean aBoolean767() {
|
||||
return aBoolean767;
|
||||
}
|
||||
|
||||
public boolean aBoolean736;
|
||||
public String name;
|
||||
public int anInt744;
|
||||
public int anInt746;
|
||||
private int[] originalModelColors;
|
||||
public int anInt749;
|
||||
public static boolean lowMem;
|
||||
public int type;
|
||||
public boolean aBoolean757;
|
||||
public int anInt758;
|
||||
public int childrenIDs[];
|
||||
public int anInt761;
|
||||
public boolean aBoolean762;
|
||||
public boolean aBoolean764;
|
||||
public boolean aBoolean767;
|
||||
public int anInt768;
|
||||
private static int cacheIndex;
|
||||
private int[] anIntArray773;
|
||||
public int anInt774;
|
||||
public int anInt775;
|
||||
private int[] anIntArray776;
|
||||
public byte description[];
|
||||
public boolean hasActions;
|
||||
public boolean aBoolean779;
|
||||
public int anInt781;
|
||||
private static ObjectDef[] cache;
|
||||
private int[] modifiedModelColors;
|
||||
public String actions[];
|
||||
private static MemoryArchive archive;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package redone.world.clip;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import redone.game.players.Client;
|
||||
|
||||
public class PathFinder {
|
||||
|
||||
private static final PathFinder pathFinder = new PathFinder();
|
||||
|
||||
public static PathFinder getPathFinder() {
|
||||
return pathFinder;
|
||||
}
|
||||
|
||||
public PathFinder() {
|
||||
}
|
||||
|
||||
public void findRoute(Client c, int destX, int destY, boolean moveNear,
|
||||
int xLength, int yLength) {
|
||||
if (destX == c.getLocalX() && destY == c.getLocalY() && !moveNear) {
|
||||
c.getActionSender().sendMessage("ERROR!");
|
||||
return;
|
||||
}
|
||||
destX = destX - 8 * c.getMapRegionX();
|
||||
destY = destY - 8 * c.getMapRegionY();
|
||||
int[][] via = new int[104][104];
|
||||
int[][] cost = new int[104][104];
|
||||
LinkedList<Integer> tileQueueX = new LinkedList<Integer>();
|
||||
LinkedList<Integer> tileQueueY = new LinkedList<Integer>();
|
||||
for (int xx = 0; xx < 104; xx++) {
|
||||
for (int yy = 0; yy < 104; yy++) {
|
||||
cost[xx][yy] = 99999999;
|
||||
}
|
||||
}
|
||||
int curX = c.getLocalX();
|
||||
int curY = c.getLocalY();
|
||||
via[curX][curY] = 99;
|
||||
cost[curX][curY] = 0;
|
||||
int tail = 0;
|
||||
tileQueueX.add(curX);
|
||||
tileQueueY.add(curY);
|
||||
boolean foundPath = false;
|
||||
int pathLength = 4000;
|
||||
while (tail != tileQueueX.size() && tileQueueX.size() < pathLength) {
|
||||
curX = tileQueueX.get(tail);
|
||||
curY = tileQueueY.get(tail);
|
||||
int curAbsX = c.getMapRegionX() * 8 + curX;
|
||||
int curAbsY = c.getMapRegionY() * 8 + curY;
|
||||
if (curX == destX && curY == destY) {
|
||||
foundPath = true;
|
||||
break;
|
||||
}
|
||||
tail = (tail + 1) % pathLength;
|
||||
int thisCost = cost[curX][curY] + 1;
|
||||
if (curY > 0
|
||||
&& via[curX][curY - 1] == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY - 1, c.heightLevel) & 0x1280102) == 0) {
|
||||
tileQueueX.add(curX);
|
||||
tileQueueY.add(curY - 1);
|
||||
via[curX][curY - 1] = 1;
|
||||
cost[curX][curY - 1] = thisCost;
|
||||
}
|
||||
if (curX > 0
|
||||
&& via[curX - 1][curY] == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY, c.heightLevel) & 0x1280108) == 0) {
|
||||
tileQueueX.add(curX - 1);
|
||||
tileQueueY.add(curY);
|
||||
via[curX - 1][curY] = 2;
|
||||
cost[curX - 1][curY] = thisCost;
|
||||
}
|
||||
if (curY < 104 - 1
|
||||
&& via[curX][curY + 1] == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY + 1, c.heightLevel) & 0x1280120) == 0) {
|
||||
tileQueueX.add(curX);
|
||||
tileQueueY.add(curY + 1);
|
||||
via[curX][curY + 1] = 4;
|
||||
cost[curX][curY + 1] = thisCost;
|
||||
}
|
||||
if (curX < 104 - 1
|
||||
&& via[curX + 1][curY] == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY, c.heightLevel) & 0x1280180) == 0) {
|
||||
tileQueueX.add(curX + 1);
|
||||
tileQueueY.add(curY);
|
||||
via[curX + 1][curY] = 8;
|
||||
cost[curX + 1][curY] = thisCost;
|
||||
}
|
||||
if (curX > 0
|
||||
&& curY > 0
|
||||
&& via[curX - 1][curY - 1] == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY - 1,
|
||||
c.heightLevel) & 0x128010e) == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY, c.heightLevel) & 0x1280108) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY - 1, c.heightLevel) & 0x1280102) == 0) {
|
||||
tileQueueX.add(curX - 1);
|
||||
tileQueueY.add(curY - 1);
|
||||
via[curX - 1][curY - 1] = 3;
|
||||
cost[curX - 1][curY - 1] = thisCost;
|
||||
}
|
||||
if (curX > 0
|
||||
&& curY < 104 - 1
|
||||
&& via[curX - 1][curY + 1] == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY + 1,
|
||||
c.heightLevel) & 0x1280138) == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY, c.heightLevel) & 0x1280108) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY + 1, c.heightLevel) & 0x1280120) == 0) {
|
||||
tileQueueX.add(curX - 1);
|
||||
tileQueueY.add(curY + 1);
|
||||
via[curX - 1][curY + 1] = 6;
|
||||
cost[curX - 1][curY + 1] = thisCost;
|
||||
}
|
||||
if (curX < 104 - 1
|
||||
&& curY > 0
|
||||
&& via[curX + 1][curY - 1] == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY - 1,
|
||||
c.heightLevel) & 0x1280183) == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY, c.heightLevel) & 0x1280180) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY - 1, c.heightLevel) & 0x1280102) == 0) {
|
||||
tileQueueX.add(curX + 1);
|
||||
tileQueueY.add(curY - 1);
|
||||
via[curX + 1][curY - 1] = 9;
|
||||
cost[curX + 1][curY - 1] = thisCost;
|
||||
}
|
||||
if (curX < 104 - 1
|
||||
&& curY < 104 - 1
|
||||
&& via[curX + 1][curY + 1] == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY + 1,
|
||||
c.heightLevel) & 0x12801e0) == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY, c.heightLevel) & 0x1280180) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY + 1, c.heightLevel) & 0x1280120) == 0) {
|
||||
tileQueueX.add(curX + 1);
|
||||
tileQueueY.add(curY + 1);
|
||||
via[curX + 1][curY + 1] = 12;
|
||||
cost[curX + 1][curY + 1] = thisCost;
|
||||
}
|
||||
}
|
||||
if (!foundPath) {
|
||||
if (moveNear) {
|
||||
int i_223_ = 1000;
|
||||
int thisCost = 100;
|
||||
int i_225_ = 10;
|
||||
for (int x = destX - i_225_; x <= destX + i_225_; x++) {
|
||||
for (int y = destY - i_225_; y <= destY + i_225_; y++) {
|
||||
if (x >= 0 && y >= 0 && x < 104 && y < 104
|
||||
&& cost[x][y] < 100) {
|
||||
int i_228_ = 0;
|
||||
if (x < destX) {
|
||||
i_228_ = destX - x;
|
||||
} else if (x > destX + xLength - 1) {
|
||||
i_228_ = x - (destX + xLength - 1);
|
||||
}
|
||||
int i_229_ = 0;
|
||||
if (y < destY) {
|
||||
i_229_ = destY - y;
|
||||
} else if (y > destY + yLength - 1) {
|
||||
i_229_ = y - (destY + yLength - 1);
|
||||
}
|
||||
int i_230_ = i_228_ * i_228_ + i_229_ * i_229_;
|
||||
if (i_230_ < i_223_ || i_230_ == i_223_
|
||||
&& cost[x][y] < thisCost) {
|
||||
i_223_ = i_230_;
|
||||
thisCost = cost[x][y];
|
||||
curX = x;
|
||||
curY = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i_223_ == 1000) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
tail = 0;
|
||||
tileQueueX.set(tail, curX);
|
||||
tileQueueY.set(tail++, curY);
|
||||
int l5;
|
||||
for (int j5 = l5 = via[curX][curY]; curX != c.getLocalX()
|
||||
|| curY != c.getLocalY(); j5 = via[curX][curY]) {
|
||||
if (j5 != l5) {
|
||||
l5 = j5;
|
||||
tileQueueX.set(tail, curX);
|
||||
tileQueueY.set(tail++, curY);
|
||||
}
|
||||
if ((j5 & 2) != 0) {
|
||||
curX++;
|
||||
} else if ((j5 & 8) != 0) {
|
||||
curX--;
|
||||
}
|
||||
if ((j5 & 1) != 0) {
|
||||
curY++;
|
||||
} else if ((j5 & 4) != 0) {
|
||||
curY--;
|
||||
}
|
||||
}
|
||||
c.resetWalkingQueue();
|
||||
int size = tail--;
|
||||
int pathX = c.getMapRegionX() * 8 + tileQueueX.get(tail);
|
||||
int pathY = c.getMapRegionY() * 8 + tileQueueY.get(tail);
|
||||
c.addToWalkingQueue(localize(pathX, c.getMapRegionX()),
|
||||
localize(pathY, c.getMapRegionY()));
|
||||
for (int i = 1; i < size; i++) {
|
||||
tail--;
|
||||
pathX = c.getMapRegionX() * 8 + tileQueueX.get(tail);
|
||||
pathY = c.getMapRegionY() * 8 + tileQueueY.get(tail);
|
||||
c.addToWalkingQueue(localize(pathX, c.getMapRegionX()),
|
||||
localize(pathY, c.getMapRegionY()));
|
||||
}
|
||||
}
|
||||
|
||||
public int localize(int x, int mapRegion) {
|
||||
return x - 8 * mapRegion;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,540 @@
|
||||
package redone.world.clip;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import redone.game.objects.Objects;
|
||||
|
||||
public class Region {
|
||||
|
||||
private ArrayList<Objects> realObjects = new ArrayList<Objects>();
|
||||
|
||||
public static Region getRegion(int x, int y) {
|
||||
int regionX = x >> 3;
|
||||
int regionY = y >> 3;
|
||||
int regionId = (regionX / 8 << 8) + regionY / 8;
|
||||
for (Region region : regions) {
|
||||
if (region.id() == regionId) {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean blockedShot(int x, int y, int z) {
|
||||
return (getClipping(x, y, z) & 0x20000) == 0;
|
||||
}
|
||||
|
||||
public static boolean objectExists(int id, int x, int y, int z) {
|
||||
Region r = getRegion(x, y);
|
||||
if (r == null)
|
||||
return false;
|
||||
for (Objects o : r.realObjects) {
|
||||
if (o.objectId == id) {
|
||||
if (o.objectX == x && o.objectY == y && o.objectHeight == z) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void addClip(int x, int y, int height, int shift) {
|
||||
int regionAbsX = (id >> 8) * 64;
|
||||
int regionAbsY = (id & 0xff) * 64;
|
||||
if (clips[height] == null) {
|
||||
clips[height] = new int[64][64];
|
||||
}
|
||||
clips[height][x - regionAbsX][y - regionAbsY] |= shift;
|
||||
}
|
||||
|
||||
public static boolean canMove(int startX, int startY, int endX, int endY, int height, int xLength, int yLength) {
|
||||
int diffX = endX - startX;
|
||||
int diffY = endY - startY;
|
||||
int max = Math.max(Math.abs(diffX), Math.abs(diffY));
|
||||
for (int ii = 0; ii < max; ii++) {
|
||||
int currentX = endX - diffX;
|
||||
int currentY = endY - diffY;
|
||||
for (int i = 0; i < xLength; i++) {
|
||||
for (int i2 = 0; i2 < yLength; i2++)
|
||||
if (diffX < 0 && diffY < 0) {
|
||||
if ((getClipping((currentX + i) - 1,
|
||||
(currentY + i2) - 1, height) & 0x128010e) != 0
|
||||
|| (getClipping((currentX + i) - 1, currentY
|
||||
+ i2, height) & 0x1280108) != 0
|
||||
|| (getClipping(currentX + i,
|
||||
(currentY + i2) - 1, height) & 0x1280102) != 0)
|
||||
return false;
|
||||
} else if (diffX > 0 && diffY > 0) {
|
||||
if ((getClipping(currentX + i + 1, currentY + i2 + 1,
|
||||
height) & 0x12801e0) != 0
|
||||
|| (getClipping(currentX + i + 1,
|
||||
currentY + i2, height) & 0x1280180) != 0
|
||||
|| (getClipping(currentX + i,
|
||||
currentY + i2 + 1, height) & 0x1280120) != 0)
|
||||
return false;
|
||||
} else if (diffX < 0 && diffY > 0) {
|
||||
if ((getClipping((currentX + i) - 1, currentY + i2 + 1,
|
||||
height) & 0x1280138) != 0
|
||||
|| (getClipping((currentX + i) - 1, currentY
|
||||
+ i2, height) & 0x1280108) != 0
|
||||
|| (getClipping(currentX + i,
|
||||
currentY + i2 + 1, height) & 0x1280120) != 0)
|
||||
return false;
|
||||
} else if (diffX > 0 && diffY < 0) {
|
||||
if ((getClipping(currentX + i + 1, (currentY + i2) - 1,
|
||||
height) & 0x1280183) != 0
|
||||
|| (getClipping(currentX + i + 1,
|
||||
currentY + i2, height) & 0x1280180) != 0
|
||||
|| (getClipping(currentX + i,
|
||||
(currentY + i2) - 1, height) & 0x1280102) != 0)
|
||||
return false;
|
||||
} else if (diffX > 0 && diffY == 0) {
|
||||
if ((getClipping(currentX + i + 1, currentY + i2,
|
||||
height) & 0x1280180) != 0)
|
||||
return false;
|
||||
} else if (diffX < 0 && diffY == 0) {
|
||||
if ((getClipping((currentX + i) - 1, currentY + i2,
|
||||
height) & 0x1280108) != 0)
|
||||
return false;
|
||||
} else if (diffX == 0 && diffY > 0) {
|
||||
if ((getClipping(currentX + i, currentY + i2 + 1,
|
||||
height) & 0x1280120) != 0)
|
||||
return false;
|
||||
} else if (diffX == 0
|
||||
&& diffY < 0
|
||||
&& (getClipping(currentX + i, (currentY + i2) - 1,
|
||||
height) & 0x1280102) != 0)
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (diffX < 0)
|
||||
diffX++;
|
||||
else if (diffX > 0)
|
||||
diffX--;
|
||||
if (diffY < 0)
|
||||
diffY++;
|
||||
else if (diffY > 0)
|
||||
diffY--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getClip(int x, int y, int height) {
|
||||
int regionAbsX = (id >> 8) * 64;
|
||||
int regionAbsY = (id & 0xff) * 64;
|
||||
if (clips[height] == null) {
|
||||
return 0;
|
||||
}
|
||||
return clips[height][x - regionAbsX][y - regionAbsY];
|
||||
}
|
||||
|
||||
private static void addClipping(int x, int y, int height, int shift) {
|
||||
int regionX = x >> 3;
|
||||
int regionY = y >> 3;
|
||||
int regionId = (regionX / 8 << 8) + regionY / 8;
|
||||
for (Region r : regions) {
|
||||
if (r.id() == regionId) {
|
||||
r.addClip(x, y, height, shift);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Region[] regions;
|
||||
private final int id;
|
||||
private final int[][][] clips = new int[4][][];
|
||||
private boolean members = false;
|
||||
|
||||
public Region(int id, boolean members) {
|
||||
this.id = id;
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean members() {
|
||||
return members;
|
||||
}
|
||||
|
||||
public static boolean isMembers(int x, int y, int height) {
|
||||
if (x >= 3272 && x <= 3320 && y >= 2752 && y <= 2809) {
|
||||
return false;
|
||||
}
|
||||
if (x >= 2640 && x <= 2677 && y >= 2638 && y <= 2679) {
|
||||
return false;
|
||||
}
|
||||
int regionX = x >> 3;
|
||||
int regionY = y >> 3;
|
||||
int regionId = (regionX / 8 << 8) + regionY / 8;
|
||||
for (Region r : regions) {
|
||||
if (r.id() == regionId) {
|
||||
return r.members();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void addClippingForVariableObject(int x, int y, int height,
|
||||
int type, int direction, boolean flag) {
|
||||
if (type == 0) {
|
||||
if (direction == 0) {
|
||||
addClipping(x, y, height, 128);
|
||||
addClipping(x - 1, y, height, 8);
|
||||
} else if (direction == 1) {
|
||||
addClipping(x, y, height, 2);
|
||||
addClipping(x, y + 1, height, 32);
|
||||
} else if (direction == 2) {
|
||||
addClipping(x, y, height, 8);
|
||||
addClipping(x + 1, y, height, 128);
|
||||
} else if (direction == 3) {
|
||||
addClipping(x, y, height, 32);
|
||||
addClipping(x, y - 1, height, 2);
|
||||
}
|
||||
} else if (type == 1 || type == 3) {
|
||||
if (direction == 0) {
|
||||
addClipping(x, y, height, 1);
|
||||
addClipping(x - 1, y, height, 16);
|
||||
} else if (direction == 1) {
|
||||
addClipping(x, y, height, 4);
|
||||
addClipping(x + 1, y + 1, height, 64);
|
||||
} else if (direction == 2) {
|
||||
addClipping(x, y, height, 16);
|
||||
addClipping(x + 1, y - 1, height, 1);
|
||||
} else if (direction == 3) {
|
||||
addClipping(x, y, height, 64);
|
||||
addClipping(x - 1, y - 1, height, 4);
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (direction == 0) {
|
||||
addClipping(x, y, height, 130);
|
||||
addClipping(x - 1, y, height, 8);
|
||||
addClipping(x, y + 1, height, 32);
|
||||
} else if (direction == 1) {
|
||||
addClipping(x, y, height, 10);
|
||||
addClipping(x, y + 1, height, 32);
|
||||
addClipping(x + 1, y, height, 128);
|
||||
} else if (direction == 2) {
|
||||
addClipping(x, y, height, 40);
|
||||
addClipping(x + 1, y, height, 128);
|
||||
addClipping(x, y - 1, height, 2);
|
||||
} else if (direction == 3) {
|
||||
addClipping(x, y, height, 160);
|
||||
addClipping(x, y - 1, height, 2);
|
||||
addClipping(x - 1, y, height, 8);
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
if (type == 0) {
|
||||
if (direction == 0) {
|
||||
addClipping(x, y, height, 65536);
|
||||
addClipping(x - 1, y, height, 4096);
|
||||
} else if (direction == 1) {
|
||||
addClipping(x, y, height, 1024);
|
||||
addClipping(x, y + 1, height, 16384);
|
||||
} else if (direction == 2) {
|
||||
addClipping(x, y, height, 4096);
|
||||
addClipping(x + 1, y, height, 65536);
|
||||
} else if (direction == 3) {
|
||||
addClipping(x, y, height, 16384);
|
||||
addClipping(x, y - 1, height, 1024);
|
||||
}
|
||||
}
|
||||
if (type == 1 || type == 3) {
|
||||
if (direction == 0) {
|
||||
addClipping(x, y, height, 512);
|
||||
addClipping(x - 1, y + 1, height, 8192);
|
||||
} else if (direction == 1) {
|
||||
addClipping(x, y, height, 2048);
|
||||
addClipping(x + 1, y + 1, height, 32768);
|
||||
} else if (direction == 2) {
|
||||
addClipping(x, y, height, 8192);
|
||||
addClipping(x + 1, y + 1, height, 512);
|
||||
} else if (direction == 3) {
|
||||
addClipping(x, y, height, 32768);
|
||||
addClipping(x - 1, y - 1, height, 2048);
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (direction == 0) {
|
||||
addClipping(x, y, height, 66560);
|
||||
addClipping(x - 1, y, height, 4096);
|
||||
addClipping(x, y + 1, height, 16384);
|
||||
} else if (direction == 1) {
|
||||
addClipping(x, y, height, 5120);
|
||||
addClipping(x, y + 1, height, 16384);
|
||||
addClipping(x + 1, y, height, 65536);
|
||||
} else if (direction == 2) {
|
||||
addClipping(x, y, height, 20480);
|
||||
addClipping(x + 1, y, height, 65536);
|
||||
addClipping(x, y - 1, height, 1024);
|
||||
} else if (direction == 3) {
|
||||
addClipping(x, y, height, 81920);
|
||||
addClipping(x, y - 1, height, 1024);
|
||||
addClipping(x - 1, y, height, 4096);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addClippingForSolidObject(int x, int y, int height,
|
||||
int xLength, int yLength, boolean flag) {
|
||||
int clipping = 256;
|
||||
if (flag) {
|
||||
clipping += 0x20000;
|
||||
}
|
||||
for (int i = x; i < x + xLength; i++) {
|
||||
for (int i2 = y; i2 < y + yLength; i2++) {
|
||||
addClipping(i, i2, height, clipping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addObject(int objectId, int x, int y, int height, int type, int direction, boolean startUp) {
|
||||
if (ObjectDef.getObjectDef(objectId) == null) {
|
||||
}
|
||||
int xLength;
|
||||
int yLength;
|
||||
if (direction != 1 && direction != 3) {
|
||||
xLength = ObjectDef.getObjectDef(objectId).xLength();
|
||||
yLength = ObjectDef.getObjectDef(objectId).yLength();
|
||||
} else {
|
||||
xLength = ObjectDef.getObjectDef(objectId).yLength();
|
||||
yLength = ObjectDef.getObjectDef(objectId).xLength();
|
||||
}
|
||||
if (type == 22) {
|
||||
if (ObjectDef.getObjectDef(objectId).hasActions()
|
||||
&& ObjectDef.getObjectDef(objectId).aBoolean767()) {
|
||||
addClipping(x, y, height, 0x200000);
|
||||
}
|
||||
} else if (type >= 9) {
|
||||
if (ObjectDef.getObjectDef(objectId).aBoolean767()) {
|
||||
addClippingForSolidObject(x, y, height, xLength, yLength,
|
||||
ObjectDef.getObjectDef(objectId).solid());
|
||||
}
|
||||
} else if (type >= 0 && type <= 3) {
|
||||
if (ObjectDef.getObjectDef(objectId).aBoolean767()) {
|
||||
addClippingForVariableObject(x, y, height, type, direction,
|
||||
ObjectDef.getObjectDef(objectId).solid());
|
||||
}
|
||||
}
|
||||
Region r = getRegion(x, y);
|
||||
if (r != null) {
|
||||
if (startUp)
|
||||
r.realObjects.add(new Objects(objectId, x, y, height, direction, type, 0));
|
||||
else if (!objectExists(objectId, x, y, height))
|
||||
r.realObjects.add(new Objects(objectId, x, y, height, direction, type, 0));
|
||||
}
|
||||
}
|
||||
|
||||
public static int getClipping(int x, int y, int height) {
|
||||
if (height > 3) {
|
||||
height = 0;
|
||||
}
|
||||
int regionX = x >> 3;
|
||||
int regionY = y >> 3;
|
||||
int regionId = (regionX / 8 << 8) + regionY / 8;
|
||||
for (Region r : regions) {
|
||||
if (r.id() == regionId) {
|
||||
return r.getClip(x, y, height);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean getClipping(int x, int y, int height, int moveTypeX,
|
||||
int moveTypeY) {
|
||||
try {
|
||||
if (height > 3) {
|
||||
height = 0;
|
||||
}
|
||||
int checkX = x + moveTypeX;
|
||||
int checkY = y + moveTypeY;
|
||||
if (moveTypeX == -1 && moveTypeY == 0) {
|
||||
return (getClipping(x, y, height) & 0x1280108) == 0;
|
||||
} else if (moveTypeX == 1 && moveTypeY == 0) {
|
||||
return (getClipping(x, y, height) & 0x1280180) == 0;
|
||||
} else if (moveTypeX == 0 && moveTypeY == -1) {
|
||||
return (getClipping(x, y, height) & 0x1280102) == 0;
|
||||
} else if (moveTypeX == 0 && moveTypeY == 1) {
|
||||
return (getClipping(x, y, height) & 0x1280120) == 0;
|
||||
} else if (moveTypeX == -1 && moveTypeY == -1) {
|
||||
return (getClipping(x, y, height) & 0x128010e) == 0
|
||||
&& (getClipping(checkX - 1, checkY, height) & 0x1280108) == 0
|
||||
&& (getClipping(checkX - 1, checkY, height) & 0x1280102) == 0;
|
||||
} else if (moveTypeX == 1 && moveTypeY == -1) {
|
||||
return (getClipping(x, y, height) & 0x1280183) == 0
|
||||
&& (getClipping(checkX + 1, checkY, height) & 0x1280180) == 0
|
||||
&& (getClipping(checkX, checkY - 1, height) & 0x1280102) == 0;
|
||||
} else if (moveTypeX == -1 && moveTypeY == 1) {
|
||||
return (getClipping(x, y, height) & 0x1280138) == 0
|
||||
&& (getClipping(checkX - 1, checkY, height) & 0x1280108) == 0
|
||||
&& (getClipping(checkX, checkY + 1, height) & 0x1280120) == 0;
|
||||
} else if (moveTypeX == 1 && moveTypeY == 1) {
|
||||
return (getClipping(x, y, height) & 0x12801e0) == 0
|
||||
&& (getClipping(checkX + 1, checkY, height) & 0x1280180) == 0
|
||||
&& (getClipping(checkX, checkY + 1, height) & 0x1280120) == 0;
|
||||
} else {
|
||||
System.out.println("[FATAL ERROR]: At getClipping: " + x + ", "
|
||||
+ y + ", " + height + ", " + moveTypeX + ", "
|
||||
+ moveTypeY);
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
try {
|
||||
File f = new File("./Data/world/map_index");
|
||||
byte[] buffer = new byte[(int) f.length()];
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream(f));
|
||||
dis.readFully(buffer);
|
||||
dis.close();
|
||||
ByteStream in = new ByteStream(buffer);
|
||||
int size = in.length() / 7;
|
||||
regions = new Region[size];
|
||||
int[] regionIds = new int[size];
|
||||
int[] mapGroundFileIds = new int[size];
|
||||
int[] mapObjectsFileIds = new int[size];
|
||||
boolean[] isMembers = new boolean[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
regionIds[i] = in.getUShort();
|
||||
mapGroundFileIds[i] = in.getUShort();
|
||||
mapObjectsFileIds[i] = in.getUShort();
|
||||
isMembers[i] = in.getUByte() == 0;
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
regions[i] = new Region(regionIds[i], isMembers[i]);
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
byte[] file1 = getBuffer(new File("./Data/world/map/"
|
||||
+ mapObjectsFileIds[i] + ".gz"));
|
||||
byte[] file2 = getBuffer(new File("./Data/world/map/"
|
||||
+ mapGroundFileIds[i] + ".gz"));
|
||||
if (file1 == null || file2 == null) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
loadMaps(regionIds[i], new ByteStream(file1),
|
||||
new ByteStream(file2));
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error loading map region: "
|
||||
+ regionIds[i]);
|
||||
}
|
||||
}
|
||||
System.out.println("[Region] DONE LOADING REGION CONFIGURATIONS");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadMaps(int regionId, ByteStream str1, ByteStream str2) {
|
||||
int absX = (regionId >> 8) * 64;
|
||||
int absY = (regionId & 0xff) * 64;
|
||||
int[][][] someArray = new int[4][64][64];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int i2 = 0; i2 < 64; i2++) {
|
||||
for (int i3 = 0; i3 < 64; i3++) {
|
||||
while (true) {
|
||||
int v = str2.getUByte();
|
||||
if (v == 0) {
|
||||
break;
|
||||
} else if (v == 1) {
|
||||
str2.skip(1);
|
||||
break;
|
||||
} else if (v <= 49) {
|
||||
str2.skip(1);
|
||||
} else if (v <= 81) {
|
||||
someArray[i][i2][i3] = v - 49;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int i2 = 0; i2 < 64; i2++) {
|
||||
for (int i3 = 0; i3 < 64; i3++) {
|
||||
if ((someArray[i][i2][i3] & 1) == 1) {
|
||||
int height = i;
|
||||
if ((someArray[1][i2][i3] & 2) == 2) {
|
||||
height--;
|
||||
}
|
||||
if (height >= 0 && height <= 3) {
|
||||
addClipping(absX + i2, absY + i3, height, 0x200000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int objectId = -1;
|
||||
int incr;
|
||||
while ((incr = str1.getUSmart()) != 0) {
|
||||
objectId += incr;
|
||||
int location = 0;
|
||||
int incr2;
|
||||
while ((incr2 = str1.getUSmart()) != 0) {
|
||||
location += incr2 - 1;
|
||||
int localX = location >> 6 & 0x3f;
|
||||
int localY = location & 0x3f;
|
||||
int height = location >> 12;
|
||||
int objectData = str1.getUByte();
|
||||
int type = objectData >> 2;
|
||||
int direction = objectData & 0x3;
|
||||
if (localX < 0 || localX >= 64 || localY < 0 || localY >= 64) {
|
||||
continue;
|
||||
}
|
||||
if ((someArray[1][localX][localY] & 2) == 2) {
|
||||
height--;
|
||||
}
|
||||
if (height >= 0 && height <= 3) {
|
||||
addObject(objectId, absX + localX, absY + localY, height,
|
||||
type, direction, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getBuffer(File f) throws Exception {
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
byte[] buffer = new byte[(int) f.length()];
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream(f));
|
||||
dis.readFully(buffer);
|
||||
dis.close();
|
||||
byte[] gzipInputBuffer = new byte[999999];
|
||||
int bufferlength = 0;
|
||||
GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(
|
||||
buffer));
|
||||
do {
|
||||
if (bufferlength == gzipInputBuffer.length) {
|
||||
System.out
|
||||
.println("Error inflating data.\nGZIP buffer overflow.");
|
||||
break;
|
||||
}
|
||||
int readByte = gzip.read(gzipInputBuffer, bufferlength,
|
||||
gzipInputBuffer.length - bufferlength);
|
||||
if (readByte == -1) {
|
||||
break;
|
||||
}
|
||||
bufferlength += readByte;
|
||||
} while (true);
|
||||
byte[] inflated = new byte[bufferlength];
|
||||
System.arraycopy(gzipInputBuffer, 0, inflated, 0, bufferlength);
|
||||
buffer = inflated;
|
||||
if (buffer.length < 10) {
|
||||
return null;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user