mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 00:31:51 +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,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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user