mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-05 08:39:04 +00:00
Cleanup part 1 (#213)
* Clean up part 1 - Removed lots of dead code - Removed unncessary files not in use - Cleaned up small bits of code - Removed a few warnings - Server.java ---> GameEngine.java - Constants.java ---> GameConstants.java * Cape Dye Rewrote cape dying * Packaging - redone ----> com.rebotted * PacketSender/clean up - ActionSender ---> PacketSender - Moved many more packets to packetsender - Cleaned up more dead code * Merge Client/Player - Merged Client.java with Player.java (both were doing same thing so redundant to have both) - Removed some more dead code - Tidy a few small things up * Quests/more clean up - Removed more dead code - Made quests static in order to clean them up a bit * More cleanup - Removed some more of the dead quest code - Correcting naming of some of the shop variables
This commit is contained in:
committed by
Daniel Ginovker
parent
3d1ae1b288
commit
d876a923b9
@@ -0,0 +1,38 @@
|
||||
package com.rebotted.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,366 @@
|
||||
package com.rebotted.world;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.rebotted.event.CycleEvent;
|
||||
import com.rebotted.event.CycleEventContainer;
|
||||
import com.rebotted.event.CycleEventHandler;
|
||||
import com.rebotted.game.players.Client;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.game.players.PlayerHandler;
|
||||
import com.rebotted.util.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 = 20;
|
||||
|
||||
/**
|
||||
* holds all the objects
|
||||
*/
|
||||
private static List<GlobalDrop> globalDrops = new ArrayList<GlobalDrop>();
|
||||
|
||||
private static Set<GlobalDrop> spawnedDrops = new HashSet<>();
|
||||
|
||||
/**
|
||||
* loads the items
|
||||
*/
|
||||
public static void initialize() {
|
||||
String Data;
|
||||
BufferedReader Checker;
|
||||
try {
|
||||
Checker = new BufferedReader(new FileReader("./data/cfg/globaldrops.txt"));
|
||||
while ((Data = Checker.readLine()) != null) {
|
||||
if (Data.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
String[] args = Data.split(":");
|
||||
if(args.length == 5) {
|
||||
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4])));
|
||||
} else {
|
||||
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])));
|
||||
}
|
||||
}
|
||||
Checker.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Misc.println("Loaded " + globalDrops.size() + " global drops.");
|
||||
|
||||
for (Player player : PlayerHandler.players) {
|
||||
Client player2 = (Client) player;
|
||||
if(player2 != null) {
|
||||
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
|
||||
@Override
|
||||
public void execute(CycleEventContainer container) {
|
||||
for (GlobalDrop drop : globalDrops) {
|
||||
if (drop.isTaken() && drop.isSpawned()) {
|
||||
if (System.currentTimeMillis() - drop.getTakenAt() >= TIME_TO_RESPAWN * 1000) {
|
||||
drop.setTaken(false);
|
||||
if (player2.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
|
||||
player2.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
|
||||
spawnedDrops.add(drop);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void read() {
|
||||
String Data;
|
||||
BufferedReader Checker;
|
||||
try {
|
||||
Checker = new BufferedReader(new FileReader("./data/cfg/globaldrops.txt"));
|
||||
while ((Data = Checker.readLine()) != null) {
|
||||
if (Data.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
String[] args = Data.split(":");
|
||||
if(args.length == 5) {
|
||||
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4])));
|
||||
} else {
|
||||
globalDrops.add(new GlobalDrop(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3])));
|
||||
}
|
||||
}
|
||||
Checker.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See if a drop exists at the given place
|
||||
*
|
||||
* @param a
|
||||
* item id
|
||||
* @param b
|
||||
* x cord
|
||||
* @param c
|
||||
* y cord
|
||||
* @return return the statement
|
||||
*/
|
||||
private static GlobalDrop itemExists(int a, int b, int c) {
|
||||
for (GlobalDrop drop : globalDrops) {
|
||||
if (drop.getId() == a && drop.getX() == b && drop.getY() == c) {
|
||||
return drop;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean itemExists(int a, int b, int c, boolean yes) {
|
||||
for (GlobalDrop drop : spawnedDrops) {
|
||||
if (drop.getId() == a && drop.getX() == b && drop.getY() == c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick up an item at the given location
|
||||
*
|
||||
* @param player2
|
||||
* the Player
|
||||
* @param a
|
||||
* item id
|
||||
* @param b
|
||||
* cord x
|
||||
* @param c
|
||||
* cord y
|
||||
*/
|
||||
public static void pickup(Player player2, int a, int b, int c) {
|
||||
GlobalDrop drop = itemExists(a, b, c);
|
||||
if (drop == null) {
|
||||
return;
|
||||
}
|
||||
if (drop.isTaken()) {
|
||||
return;
|
||||
}
|
||||
if (player2.getItemAssistant().freeSlots() > 0) {
|
||||
player2.getItemAssistant().addItem(drop.getId(), drop.getAmount());
|
||||
drop.setTakenAt(System.currentTimeMillis());
|
||||
drop.setTaken(true);
|
||||
for (Player player : PlayerHandler.players) {
|
||||
Client cl = (Client) player;
|
||||
if (cl != null) {
|
||||
cl.getPacketSender().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
|
||||
spawnedDrops.remove(drop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all the items when a player changes region
|
||||
*
|
||||
* @param Player
|
||||
* the Player
|
||||
*/
|
||||
public static void load(Client player) {
|
||||
for (GlobalDrop drop : globalDrops) {
|
||||
if (!drop.isTaken() && !drop.isSpawned() && !itemExists(drop.getId(), drop.getX(), drop.getY(), true) && player.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
|
||||
player.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
|
||||
spawnedDrops.add(drop);
|
||||
drop.setSpawned(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset(Player c) {
|
||||
for(GlobalDrop drop : globalDrops) {
|
||||
if(c.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
|
||||
c.getPacketSender().removeGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount());
|
||||
}
|
||||
}
|
||||
spawnedDrops.clear();
|
||||
globalDrops.clear();
|
||||
read();
|
||||
for (GlobalDrop drop : globalDrops) {
|
||||
if (!drop.isTaken() && !drop.isSpawned() && !itemExists(drop.getId(), drop.getX(), drop.getY(), true) && c.distanceToPoint(drop.getX(), drop.getY()) <= 60) {
|
||||
c.getPacketSender().createGroundItem(drop.getId(), drop.getX(), drop.getY(), drop.getAmount(), drop.getHeight());
|
||||
spawnedDrops.add(drop);
|
||||
drop.setSpawned(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds each drops data
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
static class GlobalDrop {
|
||||
|
||||
/**
|
||||
* cord x
|
||||
*/
|
||||
int itemX;
|
||||
/**
|
||||
* cord y
|
||||
*/
|
||||
int itemY;
|
||||
|
||||
private int height;
|
||||
/**
|
||||
* item id
|
||||
*/
|
||||
int id;
|
||||
/**
|
||||
* item amount
|
||||
*/
|
||||
int amount;
|
||||
/**
|
||||
* has the item been taken
|
||||
*/
|
||||
boolean taken = false;
|
||||
|
||||
private boolean spawned = false;
|
||||
|
||||
/**
|
||||
* Time it was taken at
|
||||
*/
|
||||
long takenAt;
|
||||
|
||||
/**
|
||||
* Sets the drop arguments
|
||||
*
|
||||
* @param pickAxe
|
||||
* item id
|
||||
* @param b
|
||||
* item amount
|
||||
* @param player
|
||||
* cord x
|
||||
* @param d
|
||||
* cord y
|
||||
*/
|
||||
|
||||
public GlobalDrop(int id, int amount, int itemX, int itemY) {
|
||||
this.id = id;
|
||||
this.amount = amount;
|
||||
this.itemX = itemX;
|
||||
this.itemY = itemY;
|
||||
}
|
||||
|
||||
public GlobalDrop(int id, int amount, int itemX, int itemY, int height) {
|
||||
this.id = id;
|
||||
this.amount = amount;
|
||||
this.itemX = itemX;
|
||||
this.itemY = itemY;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* get cord x
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public int getX() {
|
||||
return itemX;
|
||||
}
|
||||
|
||||
/**
|
||||
* get cord x
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public int getY() {
|
||||
return itemY;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the item id
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the item amount
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* has the drop already been taken?
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public boolean isTaken() {
|
||||
return taken;
|
||||
}
|
||||
|
||||
/**
|
||||
* set if or not the drop has been taken
|
||||
*
|
||||
* @param a
|
||||
* true yes false no
|
||||
*/
|
||||
public void setTaken(boolean a) {
|
||||
taken = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the time it was picked up
|
||||
*
|
||||
* @param a
|
||||
* the a
|
||||
*/
|
||||
public void setTakenAt(long a) {
|
||||
takenAt = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the time it was taken at
|
||||
*
|
||||
* @return return the statement
|
||||
*/
|
||||
public long getTakenAt() {
|
||||
return takenAt;
|
||||
}
|
||||
|
||||
public boolean isSpawned() {
|
||||
return spawned;
|
||||
}
|
||||
|
||||
public void setSpawned(boolean spawned) {
|
||||
this.spawned = spawned;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,425 @@
|
||||
package com.rebotted.world;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.rebotted.GameConstants;
|
||||
import com.rebotted.game.items.GroundItem;
|
||||
import com.rebotted.game.items.ItemAssistant;
|
||||
import com.rebotted.game.items.ItemList;
|
||||
import com.rebotted.game.players.Client;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.game.players.PlayerHandler;
|
||||
import com.rebotted.util.GameLogger;
|
||||
import com.rebotted.util.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 < GameConstants.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(Player c) {
|
||||
for (GroundItem i : items) {
|
||||
if (c != null) {
|
||||
if (c.getItemAssistant().tradeable(i.getItemId())
|
||||
|| i.getName().equalsIgnoreCase(c.playerName)) {
|
||||
if (c.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) {
|
||||
if (i.hideTicks > 0
|
||||
&& i.getName().equalsIgnoreCase(c.playerName)) {
|
||||
c.getPacketSender().removeGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
c.getPacketSender().createGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
}
|
||||
if (i.hideTicks == 0) {
|
||||
c.getPacketSender().removeGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
c.getPacketSender().createGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void process() {
|
||||
ArrayList<GroundItem> toRemove = new ArrayList<GroundItem>();
|
||||
for (int j = 0; j < items.size(); j++) {
|
||||
if (items.get(j) != null) {
|
||||
GroundItem i = items.get(j);
|
||||
if (i.hideTicks > 0) {
|
||||
i.hideTicks--;
|
||||
}
|
||||
if (i.hideTicks == 1) { // item can now be seen by others
|
||||
i.hideTicks = 0;
|
||||
createGlobalItem(i);
|
||||
i.removeTicks = HIDE_TICKS;
|
||||
}
|
||||
if (i.removeTicks > 0) {
|
||||
i.removeTicks--;
|
||||
}
|
||||
if (i.removeTicks == 1) {
|
||||
i.removeTicks = 0;
|
||||
toRemove.add(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int j = 0; j < toRemove.size(); j++) {
|
||||
GroundItem i = toRemove.get(j);
|
||||
removeGlobalItem(i, i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the ground item
|
||||
**/
|
||||
public int[][] brokenBarrows = { { 4708, 4860 }, { 4710, 4866 },
|
||||
{ 4712, 4872 }, { 4714, 4878 }, { 4716, 4884 }, { 4720, 4896 },
|
||||
{ 4718, 4890 }, { 4720, 4896 }, { 4722, 4902 }, { 4732, 4932 },
|
||||
{ 4734, 4938 }, { 4736, 4944 }, { 4738, 4950 }, { 4724, 4908 },
|
||||
{ 4726, 4914 }, { 4728, 4920 }, { 4730, 4926 }, { 4745, 4956 },
|
||||
{ 4747, 4926 }, { 4749, 4968 }, { 4751, 4994 }, { 4753, 4980 },
|
||||
{ 4755, 4986 }, { 4757, 4992 }, { 4759, 4998 } };
|
||||
|
||||
public void createGroundItem(Player c, int itemId, int itemX, int itemY, int itemAmount, int playerId) {
|
||||
if (itemId > 0) {
|
||||
if (itemId >= 2412 && itemId <= 2414) {
|
||||
c.getPacketSender().sendMessage("The cape vanishes as it touches the ground.");
|
||||
return;
|
||||
}
|
||||
if (itemId > 4705 && itemId < 4760) {
|
||||
for (int[] brokenBarrow : brokenBarrows) {
|
||||
if (brokenBarrow[0] == itemId) {
|
||||
itemId = brokenBarrow[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!com.rebotted.game.items.Item.itemStackable[itemId] && itemAmount > 0) {
|
||||
for (int j = 0; j < itemAmount; j++) {
|
||||
c.getPacketSender().createGroundItem(itemId, itemX, itemY, 1);
|
||||
GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), 1, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
|
||||
addItem(item);
|
||||
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
|
||||
if (c.isDead == false && itemId != 526) {
|
||||
if (c.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(c.playerName, "dropitem", c.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + c.absX + " absY: " + c.absY + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.getPacketSender().createGroundItem(itemId, itemX, itemY, itemAmount);
|
||||
GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), itemAmount, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);
|
||||
addItem(item);
|
||||
String itemName = ItemAssistant.getItemName(itemId).toLowerCase();
|
||||
if (c.isDead == false && itemId != 526) {
|
||||
if (c.getPlayerAssistant().isPlayer()) {
|
||||
GameLogger.writeLog(c.playerName, "dropitem", c.playerName + " dropped " + itemAmount + " " + itemName + " absX: " + c.absX + " absY: " + c.absY + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows items for everyone who is within 60 squares
|
||||
**/
|
||||
public void createGlobalItem(GroundItem i) {
|
||||
for (Player p : PlayerHandler.players) {
|
||||
if (p != null) {
|
||||
Client person = (Client) p;
|
||||
if (person != null) {
|
||||
if (person.playerId != i.getItemController()) {
|
||||
if (!person.getItemAssistant().tradeable(i.getItemId())
|
||||
&& person.playerId != i.getItemController()) {
|
||||
continue;
|
||||
}
|
||||
if (person.distanceToPoint(i.getItemX(), i.getItemY()) <= 60) {
|
||||
person.getPacketSender().createGroundItem(
|
||||
i.getItemId(), i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removing the ground item
|
||||
**/
|
||||
|
||||
public void removeGroundItem(Player c, int itemId, int itemX, int itemY, boolean add) {
|
||||
for (GroundItem i : items) {
|
||||
if (i.getItemId() == itemId && i.getItemX() == itemX
|
||||
&& i.getItemY() == itemY) {
|
||||
if (i.hideTicks > 0
|
||||
&& i.getName().equalsIgnoreCase(c.playerName)) {
|
||||
if (add) {
|
||||
if (!c.getItemAssistant().specialCase(itemId)) {
|
||||
if (c.getItemAssistant().addItem(i.getItemId(),
|
||||
i.getItemAmount())) {
|
||||
removeControllersItem(i, c, i.getItemId(),
|
||||
i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
removeControllersItem(i, c, i.getItemId(),
|
||||
i.getItemX(), i.getItemY(),
|
||||
i.getItemAmount());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
removeControllersItem(i, c, i.getItemId(),
|
||||
i.getItemX(), i.getItemY(), i.getItemAmount());
|
||||
break;
|
||||
}
|
||||
} else if (i.hideTicks <= 0) {
|
||||
if (add) {
|
||||
if (c.getItemAssistant().addItem(i.getItemId(),
|
||||
i.getItemAmount())) {
|
||||
removeGlobalItem(i, i.getItemId(), i.getItemX(),
|
||||
i.getItemY(), i.getItemAmount());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
removeGlobalItem(i, i.getItemId(), i.getItemX(),
|
||||
i.getItemY(), i.getItemAmount());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove item for just the item controller (item not global yet)
|
||||
**/
|
||||
|
||||
public void removeControllersItem(GroundItem i, Player c, int itemId,
|
||||
int itemX, int itemY, int itemAmount) {
|
||||
c.getPacketSender().removeGroundItem(itemId, itemX, itemY,
|
||||
itemAmount);
|
||||
removeItem(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove item for 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.getPacketSender().removeGroundItem(itemId,
|
||||
itemX, itemY, itemAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
removeItem(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Item List
|
||||
**/
|
||||
|
||||
public ItemList ItemList[] = new ItemList[GameConstants.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 (com.rebotted.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");
|
||||
token3 = token2_2.split("\t");
|
||||
if (token.equals("item")) {
|
||||
int[] Bonuses = new int[12];
|
||||
for (int i = 0; i < 12; i++) {
|
||||
if (token3[6 + i] != null) {
|
||||
Bonuses[i] = Integer.parseInt(token3[6 + i]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
newItemList(Integer.parseInt(token3[0]),
|
||||
token3[1].replaceAll("_", " "),
|
||||
token3[2].replaceAll("_", " "),
|
||||
Double.parseDouble(token3[4]),
|
||||
Double.parseDouble(token3[4]),
|
||||
Double.parseDouble(token3[6]), Bonuses);
|
||||
}
|
||||
} else {
|
||||
if (line.equals("[ENDOFITEMLIST]")) {
|
||||
try {
|
||||
characterfile.close();
|
||||
} catch (IOException e) {}
|
||||
//return true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
line = characterfile.readLine();
|
||||
} catch (IOException ioexception1) {
|
||||
EndOfFile = true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
characterfile.close();
|
||||
} catch (IOException ioexception) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,347 @@
|
||||
package com.rebotted.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 com.rebotted.GameEngine;
|
||||
import com.rebotted.game.content.skills.core.Mining;
|
||||
import com.rebotted.game.content.skills.core.Woodcutting;
|
||||
import com.rebotted.game.objects.Objects;
|
||||
import com.rebotted.game.players.Client;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.game.players.PlayerHandler;
|
||||
import com.rebotted.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");
|
||||
}
|
||||
|
||||
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;
|
||||
GameEngine.objectHandler.placeObject(OBJECT);
|
||||
}
|
||||
|
||||
|
||||
public void createAnObject(Player 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);
|
||||
}
|
||||
GameEngine.objectHandler.placeObject(OBJECT);
|
||||
}
|
||||
|
||||
public void createAnObject(Player player, 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);
|
||||
}
|
||||
GameEngine.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);
|
||||
}
|
||||
GameEngine.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(Player 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(o.getObjectId())) {
|
||||
c.getPacketSender().object(o.getObjectId(), o.getObjectX(), o.getObjectY(), 0, o.getObjectFace(), o.getObjectType());
|
||||
}
|
||||
}
|
||||
if (c.heightLevel == o.getObjectHeight() && !Woodcutting.playerTrees(c, o.getObjectId()) && !Mining.rockExists(o.getObjectId()) && o.objectTicks == 0 && c.distanceToPoint(o.getObjectX(), o.getObjectY()) <= 60) {
|
||||
c.getPacketSender().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.heightLevel == o.getObjectHeight()
|
||||
&& o.objectTicks == 0) {
|
||||
if (person.distanceToPoint(o.getObjectX(),
|
||||
o.getObjectY()) <= 60) {
|
||||
removeAllObjects(o);
|
||||
globalObjects.add(o);
|
||||
person.getPacketSender().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) {
|
||||
//Using Iterator for concurrency
|
||||
globalObjects.removeIf(s -> s.getObjectX() == o.getObjectX() &&
|
||||
s.getObjectY() == o.getObjectY() &&
|
||||
s.getObjectHeight() == o.getObjectHeight());
|
||||
}
|
||||
|
||||
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);
|
||||
GameEngine.objectHandler.placeObject(obby1);
|
||||
GameEngine.objectHandler.placeObject(obby2);
|
||||
GameEngine.objectHandler.placeObject(obby3);
|
||||
GameEngine.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,287 @@
|
||||
package com.rebotted.world;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.rebotted.GameEngine;
|
||||
import com.rebotted.event.CycleEvent;
|
||||
import com.rebotted.event.CycleEventContainer;
|
||||
import com.rebotted.event.CycleEventHandler;
|
||||
import com.rebotted.game.content.quests.QuestAssistant;
|
||||
import com.rebotted.game.globalworldobjects.DoubleGates;
|
||||
import com.rebotted.game.objects.Object;
|
||||
import com.rebotted.game.objects.Objects;
|
||||
import com.rebotted.game.objects.impl.FlourMill;
|
||||
import com.rebotted.game.players.Client;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.game.players.PlayerHandler;
|
||||
import com.rebotted.util.Misc;
|
||||
import com.rebotted.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 Player 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.getPacketSender().object(objectId, objectX, objectY, objectH, face, objectType);
|
||||
container.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
|
||||
}
|
||||
}, ticks);
|
||||
}
|
||||
|
||||
public static void singleGateTicks(final Player 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;
|
||||
}
|
||||
GameEngine.objectHandler.placeObject(new Objects(-1, x1, y1, objectH, face, 0, 0));
|
||||
GameEngine.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 Player 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;
|
||||
}
|
||||
GameEngine.objectHandler.placeObject(new Objects(-1, x1, y1, objectH, face, 0, 0));
|
||||
GameEngine.objectHandler.placeObject(new Objects(-1, x2, y2, objectH, face, 0, 0));
|
||||
GameEngine.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.getPacketSender().object(-1, x, y, 0, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateObject(Object o) {
|
||||
for (Player player : PlayerHandler.players) {
|
||||
if (player != null) {
|
||||
Client c = (Client) player;
|
||||
if (loadForPlayer(o, c)) {
|
||||
c.getPacketSender().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.getPacketSender().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(Player c) {
|
||||
if (c == null) {
|
||||
return;
|
||||
}
|
||||
for (Object o : objects) {
|
||||
if (loadForPlayer(o, c)) {
|
||||
c.getPacketSender().object(o.objectId, o.objectX, o.objectY, o.face, o.type);
|
||||
}
|
||||
}
|
||||
loadCustomSpawns(c);
|
||||
}
|
||||
|
||||
public void loadCustomSpawns(Player c) {
|
||||
c.getPacketSender().checkObjectSpawn(2474, 3233, 9312, 0, 10);
|
||||
if (c.rope == true) {
|
||||
c.getPacketSender().object(3828, 3227, 3108, 0, 0, 10);
|
||||
Region.addObject(3828, 3227, 3108, 0, 10, 0, false);
|
||||
}
|
||||
if (c.rope2 == true) {
|
||||
c.getPacketSender().object(3828, 3509, 9497, 2, 0, 10);
|
||||
Region.addObject(3828, 3509, 9497, 2, 10, 0, false);
|
||||
}
|
||||
if (c.questPoints >= QuestAssistant.MAXIMUM_QUESTPOINTS) {
|
||||
c.getPacketSender().checkObjectSpawn(2403, 3219, 9623, 3, 10);// RFD
|
||||
} else {
|
||||
c.getPacketSender().checkObjectSpawn(-1, 3219, 9623, 3, 10);// RFD
|
||||
}
|
||||
// CHEST
|
||||
if (c.flourAmount > 0 && c.heightLevel == 0) {
|
||||
c.getPacketSender().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, Player 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 com.rebotted.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 com.rebotted.world;
|
||||
|
||||
import com.rebotted.game.npcs.Npc;
|
||||
import com.rebotted.game.npcs.NpcSize;
|
||||
import com.rebotted.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 com.rebotted.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 com.rebotted.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 com.rebotted.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,316 @@
|
||||
package com.rebotted.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 isUnshootable() {
|
||||
return aBoolean757;
|
||||
}
|
||||
|
||||
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,416 @@
|
||||
package com.rebotted.world.clip;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import com.rebotted.game.players.Client;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.util.Misc;
|
||||
|
||||
public class PathFinder {
|
||||
|
||||
private static final PathFinder pathFinder = new PathFinder();
|
||||
|
||||
public static PathFinder getPathFinder() {
|
||||
return pathFinder;
|
||||
}
|
||||
|
||||
public void findRoute(Player player, int destX, int destY, boolean moveNear,
|
||||
int xLength, int yLength) {
|
||||
if (destX == player.getLocalX() && destY == player.getLocalY() && !moveNear) {
|
||||
player.getPacketSender().sendMessage("ERROR!");
|
||||
return;
|
||||
}
|
||||
destX = destX - 8 * player.getMapRegionX();
|
||||
destY = destY - 8 * player.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 = player.getLocalX();
|
||||
int curY = player.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 = player.getMapRegionX() * 8 + curX;
|
||||
int curAbsY = player.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, player.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, player.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, player.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, player.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,
|
||||
player.heightLevel) & 0x128010e) == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY, player.heightLevel) & 0x1280108) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY - 1, player.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,
|
||||
player.heightLevel) & 0x1280138) == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY, player.heightLevel) & 0x1280108) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY + 1, player.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,
|
||||
player.heightLevel) & 0x1280183) == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY, player.heightLevel) & 0x1280180) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY - 1, player.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,
|
||||
player.heightLevel) & 0x12801e0) == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY, player.heightLevel) & 0x1280180) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY + 1, player.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 != player.getLocalX()
|
||||
|| curY != player.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--;
|
||||
}
|
||||
}
|
||||
player.resetWalkingQueue();
|
||||
int size = tail--;
|
||||
int pathX = player.getMapRegionX() * 8 + tileQueueX.get(tail);
|
||||
int pathY = player.getMapRegionY() * 8 + tileQueueY.get(tail);
|
||||
player.addToWalkingQueue(localize(pathX, player.getMapRegionX()),
|
||||
localize(pathY, player.getMapRegionY()));
|
||||
for (int i = 1; i < size; i++) {
|
||||
tail--;
|
||||
pathX = player.getMapRegionX() * 8 + tileQueueX.get(tail);
|
||||
pathY = player.getMapRegionY() * 8 + tileQueueY.get(tail);
|
||||
player.addToWalkingQueue(localize(pathX, player.getMapRegionX()),
|
||||
localize(pathY, player.getMapRegionY()));
|
||||
}
|
||||
}
|
||||
|
||||
public int getRegionCoordinate(int x) {
|
||||
return (x >> 3) - 6;
|
||||
}
|
||||
|
||||
public int getLocalCoordinate(int x) {
|
||||
return x - 8 * getRegionCoordinate(x);
|
||||
}
|
||||
|
||||
public boolean accessible(int x, int y, int heightLevel, int destX, int destY) {
|
||||
destX = destX - 8 * getRegionCoordinate(x);
|
||||
destY = destY - 8 * getRegionCoordinate(y);
|
||||
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 = getLocalCoordinate(x);
|
||||
int curY = getLocalCoordinate(y);
|
||||
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 = getRegionCoordinate(x) * 8 + curX;
|
||||
int curAbsY = getRegionCoordinate(y) * 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, 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, 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, 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, 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,
|
||||
heightLevel) & 0x128010e) == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY, heightLevel) & 0x1280108) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY - 1, 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,
|
||||
heightLevel) & 0x1280138) == 0
|
||||
&& (Region.getClipping(curAbsX - 1, curAbsY, heightLevel) & 0x1280108) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY + 1, 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,
|
||||
heightLevel) & 0x1280183) == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY, heightLevel) & 0x1280180) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY - 1, 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,
|
||||
heightLevel) & 0x12801e0) == 0
|
||||
&& (Region.getClipping(curAbsX + 1, curAbsY, heightLevel) & 0x1280180) == 0
|
||||
&& (Region.getClipping(curAbsX, curAbsY + 1, heightLevel) & 0x1280120) == 0) {
|
||||
tileQueueX.add(curX + 1);
|
||||
tileQueueY.add(curY + 1);
|
||||
via[curX + 1][curY + 1] = 12;
|
||||
cost[curX + 1][curY + 1] = thisCost;
|
||||
}
|
||||
}
|
||||
return foundPath;
|
||||
}
|
||||
|
||||
public static boolean isProjectilePathClear(int x0, int y0, int z, int x1, int y1) {
|
||||
int deltaX = x1 - x0;
|
||||
int deltaY = y1 - y0;
|
||||
|
||||
double error = 0;
|
||||
final double deltaError = Math.abs(
|
||||
(deltaY) / (deltaX == 0
|
||||
? ((double) deltaY)
|
||||
: ((double) deltaX)));
|
||||
|
||||
int x = x0;
|
||||
int y = y0;
|
||||
|
||||
int pX = x;
|
||||
int pY = y;
|
||||
|
||||
boolean incrX = x0 < x1;
|
||||
boolean incrY = y0 < y1;
|
||||
|
||||
while (true) {
|
||||
if (x != x1) {
|
||||
x += (incrX ? 1 : -1);
|
||||
}
|
||||
|
||||
if (y != y1) {
|
||||
error += deltaError;
|
||||
|
||||
if (error >= 0.5) {
|
||||
y += (incrY ? 1 : -1);
|
||||
error -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!shootable(x, y, z, pX, pY)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (incrX && incrY
|
||||
&& x >= x1 && y >= y1) {
|
||||
break;
|
||||
} else if (!incrX && !incrY
|
||||
&& x <= x1 && y <= y1) {
|
||||
break;
|
||||
} else if (!incrX && incrY
|
||||
&& x <= x1 && y >= y1) {
|
||||
break;
|
||||
} else if (incrX && !incrY
|
||||
&& x >= x1 && y <= y1) {
|
||||
break;
|
||||
}
|
||||
|
||||
pX = x;
|
||||
pY = y;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean shootable(int x, int y, int z, int px, int py) {
|
||||
if (x == px && y == py) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int[] delta1 = Misc.delta(x, y, px, py);
|
||||
int[] delta2 = Misc.delta(px, py, x, y);
|
||||
|
||||
int dir = Misc.directionFromDelta(delta1[0], delta1[1]);
|
||||
int dir2 = Misc.directionFromDelta(delta2[0], delta2[1]);
|
||||
|
||||
if (dir == -1 || dir2 == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Region.canMove(x, y, z, dir) && Region.canMove(px, py, z, dir2)
|
||||
|| Region.canShoot(x, y, z, dir) && Region.canShoot(px, py, z, dir2);
|
||||
}
|
||||
|
||||
public int localize(int x, int mapRegion) {
|
||||
return x - 8 * mapRegion;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,826 @@
|
||||
package com.rebotted.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 com.rebotted.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 Objects getObject(int id, int x, int y, int z) {
|
||||
Region r = getRegion(x, y);
|
||||
if (r == null)
|
||||
return null;
|
||||
for (Objects o : r.realObjects) {
|
||||
if (o.objectId == id) {
|
||||
if (o.objectX == x && o.objectY == y && o.objectHeight == z) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private void addProjectileClip(int x, int y, int height, int shift) {
|
||||
int regionAbsX = (id >> 8) * 64;
|
||||
int regionAbsY = (id & 0xff) * 64;
|
||||
if (projectileClips[height] == null) {
|
||||
projectileClips[height] = new int[64][64];
|
||||
}
|
||||
projectileClips[height][x - regionAbsX][y - regionAbsY] |= shift;
|
||||
}
|
||||
|
||||
public static boolean canMove(int x, int y, int z, int direction) {
|
||||
if (direction == 6) {
|
||||
if ((Region.getClipping(x, y - 1, z) & 0x1280102) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == 3) {
|
||||
if ((Region.getClipping(x - 1, y, z) & 0x1280108) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == 1) {
|
||||
if ((Region.getClipping(x, y + 1, z) & 0x1280120) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == 4) {
|
||||
if ((Region.getClipping(x + 1, y, z) & 0x1280180) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == 5) {
|
||||
if ((Region.getClipping(x - 1, y - 1, z) & 0x128010e) == 0
|
||||
&& (Region.getClipping(x - 1, y, z) & 0x1280108) == 0
|
||||
&& (Region.getClipping(x, y - 1, z) & 0x1280102) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == 0) {
|
||||
if ((Region.getClipping(x - 1, y + 1, z) & 0x1280138) == 0
|
||||
&& (Region.getClipping(x - 1, y, z) & 0x1280108) == 0
|
||||
&& (Region.getClipping(x, y + 1, z) & 0x1280120) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == 7) {
|
||||
if ((Region.getClipping(x + 1, y - 1, z) & 0x1280183) == 0
|
||||
&& (Region.getClipping(x + 1, y, z) & 0x1280180) == 0
|
||||
&& (Region.getClipping(x, y - 1, z) & 0x1280102) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == 2) {
|
||||
if ((Region.getClipping(x + 1, y + 1, z) & 0x12801e0) == 0
|
||||
&& (Region.getClipping(x + 1, y, z) & 0x1280180) == 0
|
||||
&& (Region.getClipping(x, y + 1, z) & 0x1280120) == 0) {
|
||||
return true;
|
||||
}
|
||||
} else if (direction == -1) {
|
||||
throw new IllegalArgumentException("Invalid direction: " + direction);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean canShoot(int x, int y, int z, int direction) {
|
||||
if (direction == 0) {
|
||||
return !projectileBlockedNorthWest(x, y, z) && !projectileBlockedNorth(x, y, z)
|
||||
&& !projectileBlockedWest(x, y, z);
|
||||
} else if (direction == 1) {
|
||||
return !projectileBlockedNorth(x, y, z);
|
||||
} else if (direction == 2) {
|
||||
return !projectileBlockedNorthEast(x, y, z) && !projectileBlockedNorth(x, y, z)
|
||||
&& !projectileBlockedEast(x, y, z);
|
||||
} else if (direction == 3) {
|
||||
return !projectileBlockedWest(x, y, z);
|
||||
} else if (direction == 4) {
|
||||
return !projectileBlockedEast(x, y, z);
|
||||
} else if (direction == 5) {
|
||||
return !projectileBlockedSouthWest(x, y, z) && !projectileBlockedSouth(x, y, z)
|
||||
&& !projectileBlockedWest(x, y, z);
|
||||
} else if (direction == 6) {
|
||||
return !projectileBlockedSouth(x, y, z);
|
||||
} else if (direction == 7) {
|
||||
return !projectileBlockedSouthEast(x, y, z) && !projectileBlockedSouth(x, y, z)
|
||||
&& !projectileBlockedEast(x, y, z);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedNorth(int x, int y, int z) {
|
||||
return (getProjectileClipping(x, y + 1, z) & 0x1280120) != 0;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedEast(int x, int y, int z) {
|
||||
return (getProjectileClipping(x + 1, y, z) & 0x1280180) != 0;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedSouth(int x, int y, int z) {
|
||||
return (getProjectileClipping(x, y - 1, z) & 0x1280102) != 0;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedWest(int x, int y, int z) {
|
||||
return (getProjectileClipping(x - 1, y, z) & 0x1280108) != 0;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedNorthEast(int x, int y, int z) {
|
||||
return (getProjectileClipping(x + 1, y + 1, z) & 0x12801e0) != 0;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedNorthWest(int x, int y, int z) {
|
||||
return (getProjectileClipping(x - 1, y + 1, z) & 0x1280138) != 0;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedSouthEast(int x, int y, int z) {
|
||||
return (getProjectileClipping(x + 1, y - 1, z) & 0x1280183) != 0;
|
||||
}
|
||||
|
||||
public static boolean projectileBlockedSouthWest(int x, int y, int z) {
|
||||
return (getProjectileClipping(x - 1, y - 1, z) & 0x128010e) != 0;
|
||||
}
|
||||
|
||||
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 int getProjectileClip(int x, int y, int height) {
|
||||
int regionAbsX = (id >> 8) * 64;
|
||||
int regionAbsY = (id & 0xff) * 64;
|
||||
if (projectileClips[height] == null) {
|
||||
return 0;
|
||||
}
|
||||
return projectileClips[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 void addProjectileClipping(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.addProjectileClip(x, y, height, shift);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Region[] regions;
|
||||
private final int id;
|
||||
private final int[][][] clips = new int[4][][];
|
||||
private final int[][][] projectileClips = 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 addProjectileClippingForVariableObject(int x, int y, int height,
|
||||
int type, int direction, boolean flag) {
|
||||
if (type == 0) {
|
||||
if (direction == 0) {
|
||||
addProjectileClipping(x, y, height, 128);
|
||||
addProjectileClipping(x - 1, y, height, 8);
|
||||
} else if (direction == 1) {
|
||||
addProjectileClipping(x, y, height, 2);
|
||||
addProjectileClipping(x, y + 1, height, 32);
|
||||
} else if (direction == 2) {
|
||||
addProjectileClipping(x, y, height, 8);
|
||||
addProjectileClipping(x + 1, y, height, 128);
|
||||
} else if (direction == 3) {
|
||||
addProjectileClipping(x, y, height, 32);
|
||||
addProjectileClipping(x, y - 1, height, 2);
|
||||
}
|
||||
} else if (type == 1 || type == 3) {
|
||||
if (direction == 0) {
|
||||
addProjectileClipping(x, y, height, 1);
|
||||
addProjectileClipping(x - 1, y, height, 16);
|
||||
} else if (direction == 1) {
|
||||
addProjectileClipping(x, y, height, 4);
|
||||
addProjectileClipping(x + 1, y + 1, height, 64);
|
||||
} else if (direction == 2) {
|
||||
addProjectileClipping(x, y, height, 16);
|
||||
addProjectileClipping(x + 1, y - 1, height, 1);
|
||||
} else if (direction == 3) {
|
||||
addProjectileClipping(x, y, height, 64);
|
||||
addProjectileClipping(x - 1, y - 1, height, 4);
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (direction == 0) {
|
||||
addProjectileClipping(x, y, height, 130);
|
||||
addProjectileClipping(x - 1, y, height, 8);
|
||||
addProjectileClipping(x, y + 1, height, 32);
|
||||
} else if (direction == 1) {
|
||||
addProjectileClipping(x, y, height, 10);
|
||||
addProjectileClipping(x, y + 1, height, 32);
|
||||
addProjectileClipping(x + 1, y, height, 128);
|
||||
} else if (direction == 2) {
|
||||
addProjectileClipping(x, y, height, 40);
|
||||
addProjectileClipping(x + 1, y, height, 128);
|
||||
addProjectileClipping(x, y - 1, height, 2);
|
||||
} else if (direction == 3) {
|
||||
addProjectileClipping(x, y, height, 160);
|
||||
addProjectileClipping(x, y - 1, height, 2);
|
||||
addProjectileClipping(x - 1, y, height, 8);
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
if (type == 0) {
|
||||
if (direction == 0) {
|
||||
addProjectileClipping(x, y, height, 65536);
|
||||
addProjectileClipping(x - 1, y, height, 4096);
|
||||
} else if (direction == 1) {
|
||||
addProjectileClipping(x, y, height, 1024);
|
||||
addProjectileClipping(x, y + 1, height, 16384);
|
||||
} else if (direction == 2) {
|
||||
addProjectileClipping(x, y, height, 4096);
|
||||
addProjectileClipping(x + 1, y, height, 65536);
|
||||
} else if (direction == 3) {
|
||||
addProjectileClipping(x, y, height, 16384);
|
||||
addProjectileClipping(x, y - 1, height, 1024);
|
||||
}
|
||||
}
|
||||
if (type == 1 || type == 3) {
|
||||
if (direction == 0) {
|
||||
addProjectileClipping(x, y, height, 512);
|
||||
addProjectileClipping(x - 1, y + 1, height, 8192);
|
||||
} else if (direction == 1) {
|
||||
addProjectileClipping(x, y, height, 2048);
|
||||
addProjectileClipping(x + 1, y + 1, height, 32768);
|
||||
} else if (direction == 2) {
|
||||
addProjectileClipping(x, y, height, 8192);
|
||||
addProjectileClipping(x + 1, y + 1, height, 512);
|
||||
} else if (direction == 3) {
|
||||
addProjectileClipping(x, y, height, 32768);
|
||||
addProjectileClipping(x - 1, y - 1, height, 2048);
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (direction == 0) {
|
||||
addProjectileClipping(x, y, height, 66560);
|
||||
addProjectileClipping(x - 1, y, height, 4096);
|
||||
addProjectileClipping(x, y + 1, height, 16384);
|
||||
} else if (direction == 1) {
|
||||
addProjectileClipping(x, y, height, 5120);
|
||||
addProjectileClipping(x, y + 1, height, 16384);
|
||||
addProjectileClipping(x + 1, y, height, 65536);
|
||||
} else if (direction == 2) {
|
||||
addProjectileClipping(x, y, height, 20480);
|
||||
addProjectileClipping(x + 1, y, height, 65536);
|
||||
addProjectileClipping(x, y - 1, height, 1024);
|
||||
} else if (direction == 3) {
|
||||
addProjectileClipping(x, y, height, 81920);
|
||||
addProjectileClipping(x, y - 1, height, 1024);
|
||||
addProjectileClipping(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addProjectileClippingForSolidObject(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++) {
|
||||
addProjectileClipping(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);
|
||||
if (ObjectDef.getObjectDef(objectId).isUnshootable()) {
|
||||
addProjectileClipping(x, y, height, 0x200000);
|
||||
}
|
||||
}
|
||||
} else if (type >= 9) {
|
||||
if (ObjectDef.getObjectDef(objectId).aBoolean767()) {
|
||||
addClippingForSolidObject(x, y, height, xLength, yLength,
|
||||
ObjectDef.getObjectDef(objectId).solid());
|
||||
if (ObjectDef.getObjectDef(objectId).isUnshootable()) {
|
||||
addProjectileClippingForSolidObject(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());
|
||||
if (ObjectDef.getObjectDef(objectId).isUnshootable()) {
|
||||
addProjectileClippingForVariableObject(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 int getProjectileClipping(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.getProjectileClip(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