Code:
package com.rs.game;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import com.rs.Settings;
import com.rs.cache.Cache;
import com.rs.cache.loaders.ClientScriptMap;
import com.rs.cache.loaders.ObjectDefinitions;
import com.rs.cores.CoresManager;
import com.rs.game.item.FloorItem;
import com.rs.game.player.Player;
import com.rs.io.InputStream;
import com.rs.utils.ItemSpawns;
import com.rs.utils.Logger;
import com.rs.utils.MapArchiveKeys;
import com.rs.utils.NPCSpawns;
import com.rs.utils.ObjectSpawns;
import com.rs.utils.Utils;
import com.rs.game.RegionMap;
import com.rs.game.World;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
public class Region {
public static final int[] OBJECT_SLOTS = new int[] { 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3 };
public static final int OBJECT_SLOT_WALL = 0;
public static final int OBJECT_SLOT_WALL_DECORATION = 1;
public static final int OBJECT_SLOT_FLOOR = 2;
public static final int OBJECT_SLOT_FLOOR_DECORATION = 3;
protected int regionId;
protected RegionMap map;
protected RegionMap clipedOnlyMap;
protected List<Integer> playersIndexes;
protected List<Integer> npcsIndexes;
protected List<WorldObject> spawnedObjects;
protected List<WorldObject> removedOriginalObjects;
private List<FloorItem> groundItems;
protected WorldObject[][][][] objects;
private volatile int loadMapStage;
private boolean loadedNPCSpawns;
private boolean loadedObjectSpawns;
private boolean loadedItemSpawns;
private int[] musicIds;
public Region(int regionId) {
this.regionId = regionId;
this.spawnedObjects = new CopyOnWriteArrayList<WorldObject>();
this.removedOriginalObjects = new CopyOnWriteArrayList<WorldObject>();
loadMusicIds();
// indexes null by default cuz we dont want them on mem for regions that
// players cant go in
}
public void checkLoadMap() {
if (getLoadMapStage() == 0) {
setLoadMapStage(1);
CoresManager.slowExecutor.execute(new Runnable() {
@Override
public void run() {
try {
loadRegionMap();
setLoadMapStage(2);
if (!isLoadedObjectSpawns()) {
loadObjectSpawns();
setLoadedObjectSpawns(true);
}
if (!isLoadedNPCSpawns()) {
loadNPCSpawns();
setLoadedNPCSpawns(true);
}
if (!isLoadedItemSpawns()) {
loadItemSpawns();
setLoadedItemSpawns(true);
}
}
catch (Throwable e) {
Logger.handle(e);
}
}
});
}
}
private void loadNPCSpawns() {
NPCSpawns.loadNPCSpawns(regionId);
}
private void loadObjectSpawns() {
ObjectSpawns.loadObjectSpawns(regionId);
}
private void loadItemSpawns() {
ItemSpawns.loadItemSpawns(regionId);
}
public void addObject(WorldObject object, int plane, int localX, int localY) {
if (World.restrictedTiles != null) {
for (WorldTile restrictedTile : World.restrictedTiles) {
if (restrictedTile != null) {
int restX = restrictedTile.getX(), restY = restrictedTile
.getY();
int restPlane = restrictedTile.getPlane();
if (World.restrictedTiles.size() > 1) {
if (object.getX() == restX && object.getY() == restY
&& object.getPlane() == restPlane
&& World.restrictedTiles != null) {
World.spawnObject(
new WorldObject(-1, 10, 2, object.getX(),
object.getY(), object.getPlane()),
false);
return;
}
}
}
}
}
addMapObject(object, localX, localY);
if (objects == null)
objects = new WorldObject[4][64][64][];
WorldObject[] tileObjects = objects[plane][localX][localY];
if (tileObjects == null)
objects[plane][localX][localY] = new WorldObject[] { object };
else {
WorldObject[] newTileObjects = new WorldObject[tileObjects.length + 1];
newTileObjects[tileObjects.length] = object;
System.arraycopy(tileObjects, 0, newTileObjects, 0,
tileObjects.length);
objects[plane][localX][localY] = newTileObjects;
}
}
public void addMapObject(WorldObject object, int x, int y) {
if (map == null)
map = new RegionMap(regionId, false);
if (clipedOnlyMap == null)
clipedOnlyMap = new RegionMap(regionId, true);
int plane = object.getPlane();
int type = object.getType();
int rotation = object.getRotation();
if (x < 0 || y < 0 || x >= map.getMasks()[plane].length || y >= map.getMasks()[plane][x].length)
return;
ObjectDefinitions objectDefinition = ObjectDefinitions.getObjectDefinitions(object.getId()); // load
// here
if (type == 22 ? objectDefinition.getClipType() != 0 : objectDefinition.getClipType() == 0)
return;
if (type >= 0 && type <= 3) {
map.addWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(), true);
if (objectDefinition.isProjectileCliped())
clipedOnlyMap.addWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(), true);
} else if (type >= 9 && type <= 21) {
int sizeX;
int sizeY;
if (rotation != 1 && rotation != 3) {
sizeX = objectDefinition.getSizeX();
sizeY = objectDefinition.getSizeY();
} else {
sizeX = objectDefinition.getSizeY();
sizeY = objectDefinition.getSizeX();
}
map.addObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(), true);
if (objectDefinition.isProjectileCliped())
clipedOnlyMap.addObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(), true);
} else if (type == 22) {
// map.addFloor(plane, x, y);
}
}
/**
* Unload's map from memory.
*/
public void unloadMap() {
if (getLoadMapStage() == 2 && (playersIndexes == null || playersIndexes.isEmpty()) && (npcsIndexes == null || npcsIndexes.isEmpty())) {
objects = null;
map = null;
setLoadMapStage(0);
}
}
public RegionMap forceGetRegionMapClipedOnly() {
if (clipedOnlyMap == null)
clipedOnlyMap = new RegionMap(regionId, true);
return clipedOnlyMap;
}
public RegionMap forceGetRegionMap() {
if (map == null)
map = new RegionMap(regionId, false);
return map;
}
public RegionMap getRegionMap() {
return map;
}
public int getMask(int plane, int localX, int localY) {
if (map == null || getLoadMapStage() != 2)
return -1; // cliped tile
return map.getMasks()[plane][localX][localY];
}
public int getMaskClipedOnly(int plane, int localX, int localY) {
if (clipedOnlyMap == null || getLoadMapStage() != 2)
return -1; // cliped tile
return clipedOnlyMap.getMasks()[plane][localX][localY];
}
public void setMask(int plane, int localX, int localY, int mask) {
if (map == null || getLoadMapStage() != 2)
return; // cliped tile
if (localX >= 64 || localY >= 64 || localX < 0 || localY < 0) {
WorldTile tile = new WorldTile(map.getRegionX() + localX, map.getRegionY() + localY, plane);
int regionId = tile.getRegionId();
int newRegionX = (regionId >> 8) * 64;
int newRegionY = (regionId & 0xff) * 64;
World.getRegion(tile.getRegionId()).setMask(plane, tile.getX() - newRegionX, tile.getY() - newRegionY, mask);
return;
}
map.setMask(plane, localX, localY, mask);
}
public void clip(WorldObject object, int x, int y) {
if (map == null)
map = new RegionMap(regionId, false);
if (clipedOnlyMap == null)
clipedOnlyMap = new RegionMap(regionId, true);
int plane = object.getPlane();
int type = object.getType();
int rotation = object.getRotation();
if (x < 0 || y < 0 || x >= map.getMasks()[plane].length || y >= map.getMasks()[plane][x].length)
return;
ObjectDefinitions objectDefinition = ObjectDefinitions.getObjectDefinitions(object.getId()); // load
// here
if (type == 22 ? objectDefinition.getClipType() != 1 : objectDefinition.getClipType() == 0)
return;
if (type >= 0 && type <= 3) {
if(!objectDefinition.notCliped) //disabled those walls for now since theyre guard corners, temporary fix
map.addWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
if (objectDefinition.isProjectileCliped())
clipedOnlyMap.addWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
} else if (type >= 9 && type <= 21) {
int sizeX;
int sizeY;
if (rotation != 1 && rotation != 3) {
sizeX = objectDefinition.getSizeX();
sizeY = objectDefinition.getSizeY();
} else {
sizeX = objectDefinition.getSizeY();
sizeY = objectDefinition.getSizeX();
}
map.addObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
if (objectDefinition.isProjectileCliped())
clipedOnlyMap.addObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
} else if (type == 22) {
map.addFloor(plane, x, y); // dont ever fucking think about removing it..., some floor deco objects DOES BLOCK WALKING
}
}
public void unclip(int plane, int x, int y) {
if (map == null)
map = new RegionMap(regionId, false);
if (clipedOnlyMap == null)
clipedOnlyMap = new RegionMap(regionId, true);
map.setMask(plane, x, y, 0);
}
public void unclip(WorldObject object, int x, int y) {
if (map == null)
map = new RegionMap(regionId, false);
if (clipedOnlyMap == null)
clipedOnlyMap = new RegionMap(regionId, true);
int plane = object.getPlane();
int type = object.getType();
int rotation = object.getRotation();
if (x < 0 || y < 0 || x >= map.getMasks()[plane].length || y >= map.getMasks()[plane][x].length)
return;
ObjectDefinitions objectDefinition = ObjectDefinitions.getObjectDefinitions(object.getId()); // load
// here
if (type == 22 ? objectDefinition.getClipType() != 1 : objectDefinition.getClipType() == 0)
return;
if (type >= 0 && type <= 3) {
map.removeWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
if (objectDefinition.isProjectileCliped())
clipedOnlyMap.removeWall(plane, x, y, type, rotation, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
} else if (type >= 9 && type <= 21) {
int sizeX;
int sizeY;
if (rotation != 1 && rotation != 3) {
sizeX = objectDefinition.getSizeX();
sizeY = objectDefinition.getSizeY();
} else {
sizeX = objectDefinition.getSizeY();
sizeY = objectDefinition.getSizeX();
}
map.removeObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
if (objectDefinition.isProjectileCliped())
clipedOnlyMap.removeObject(plane, x, y, sizeX, sizeY, objectDefinition.isProjectileCliped(), !objectDefinition.notCliped);
} else if (type == 22) {
map.removeFloor(plane, x, y);
}
}
public void spawnObject(WorldObject object, int plane, int localX, int localY, boolean original) {
if (objects == null)
objects = new WorldObject[4][64][64][4];
int slot = OBJECT_SLOTS[object.getType()];
if (original) {
objects[plane][localX][localY][slot] = object;
clip(object, localX, localY);
} else {
WorldObject spawned = getSpawnedObjectWithSlot(plane, localX, localY, slot);
// found non original object on this slot. removing it since we
// replacing with a new non original
if (spawned != null) {
spawnedObjects.remove(spawned);
// unclips non orignal old object which had been cliped so can
// clip the new non original
unclip(spawned, localX, localY);
}
WorldObject removed = getRemovedObjectWithSlot(plane, localX, localY, slot);
// there was a original object removed. lets readd it
if (removed != null) {
object = removed;
removedOriginalObjects.remove(object);
// adding non original object to this place
} else if (objects[plane][localX][localY][slot] != object) {
spawnedObjects.add(object);
// unclips orignal old object which had been cliped so can clip
// the new non original
if (objects[plane][localX][localY][slot] != null)
unclip(objects[plane][localX][localY][slot], localX, localY);
} else if(spawned == null) {
if (Settings.DEBUG)
Logger.log(this, "Requested object to spawn is already spawned.(Shouldnt happen)");
return;
}
// clips spawned object(either original or non original)
clip(object, localX, localY);
for (Player p2 : World.getPlayers()) {
if (p2 == null || !p2.hasStarted() || p2.hasFinished() || !p2.getMapRegionsIds().contains(regionId))
continue;
p2.getPackets().sendSpawnedObject(object);
}
}
}
public void removeObject(WorldObject object, int plane, int localX, int localY) {
if (objects == null)
objects = new WorldObject[4][64][64][4];
int slot = OBJECT_SLOTS[object.getType()];
WorldObject removed = getRemovedObjectWithSlot(plane, localX, localY, slot);
if (removed != null) {
removedOriginalObjects.remove(object);
clip(removed, localX, localY);
}
WorldObject original = null;
// found non original object on this slot. removing it since we
// replacing with real one or none if none
WorldObject spawned = getSpawnedObjectWithSlot(plane, localX, localY, slot);
if (spawned != null) {
object = spawned;
spawnedObjects.remove(object);
unclip(object, localX, localY);
if (objects[plane][localX][localY][slot] != null) {// original
// unclips non original to clip original above
clip(objects[plane][localX][localY][slot], localX, localY);
original = objects[plane][localX][localY][slot];
}
// found original object on this slot. removing it since requested
} else if (objects[plane][localX][localY][slot] == object) { // removes original
unclip(object, localX, localY);
removedOriginalObjects.add(object);
} else {
if (Settings.DEBUG)
Logger.log(this, "Requested object to remove wasnt found.(Shouldnt happen)");
return;
}
for (Player p2 : World.getPlayers()) {
if (p2 == null || !p2.hasStarted() || p2.hasFinished() || !p2.getMapRegionsIds().contains(regionId))
continue;
if (original != null)
p2.getPackets().sendSpawnedObject(original);
else
p2.getPackets().sendDestroyObject(object);
}
}
public WorldObject getStandartObject(int plane, int x, int y) {
return getObjectWithSlot(plane, x, y, OBJECT_SLOT_FLOOR);
}
public WorldObject getObjectWithType(int plane, int x, int y, int type) {
WorldObject object = getObjectWithSlot(plane, x, y, OBJECT_SLOTS[type]);
return object != null && object.getType() == type ? object : null;
}
public WorldObject getObjectWithSlot(int plane, int x, int y, int slot) {
if (objects == null)
return null;
WorldObject o = getSpawnedObjectWithSlot(plane, x, y, slot);
if (o == null) {
if (getRemovedObjectWithSlot(plane, x, y, slot) != null)
return null;
return objects[plane][x][y][slot];
}
return o;
}
public WorldObject getSpawnedObjectWithSlot(int plane, int x, int y, int slot) {
for (WorldObject object : spawnedObjects) {
if (object.getXInRegion() == x && object.getYInRegion() == y && object.getPlane() == plane && OBJECT_SLOTS[object.getType()] == slot)
return object;
}
return null;
}
/**
* Gets the list of world objects in this region.
* @return The list of world objects.
*/
public List<WorldObject> getObjects() {
if (objects == null) {
return null;
}
List<WorldObject> list = new ArrayList<WorldObject>();
for (int z = 0; z < objects.length; z++) {
if (objects[z] == null) {
continue;
}
for (int x = 0; x < objects[z].length; x++) {
if (objects[z][x] == null) {
continue;
}
for (int y = 0; y < objects[z][x].length; y++) {
if (objects[z][x][y] == null) {
continue;
}
for (WorldObject o : objects[z][x][y]) {
if (o != null) {
list.add(o);
}
}
}
}
}
return list;
}
public WorldObject getRemovedObjectWithSlot(int plane, int x, int y, int slot) {
for (WorldObject object : removedOriginalObjects) {
if (object.getXInRegion() == x && object.getYInRegion() == y && object.getPlane() == plane && OBJECT_SLOTS[object.getType()] == slot)
return object;
}
return null;
}
public WorldObject[] getAllObjects(int plane, int x, int y) {
if (objects == null)
return null;
return objects[plane][x][y];
}
public List<WorldObject> getAllObjects() {
if (objects == null)
return null;
List<WorldObject> list = new ArrayList<WorldObject>();
for (int z = 0; z < 4; z++)
for (int x = 0; x < 64; x++)
for (int y = 0; y < 64; y++) {
if (objects[z][x][y] == null)
continue;
for (WorldObject o : objects[z][x][y])
if (o != null)
list.add(o);
}
return list;
}
public boolean containsObjectWithId(int plane, int x, int y, int id) {
WorldObject object = getObjectWithId(plane, x, y, id);
return object != null && object.getId() == id;
}
public WorldObject getObjectWithId(int plane, int x, int y, int id) {
if (objects == null)
return null;
for (WorldObject object : removedOriginalObjects) {
if (object.getId() == id && object.getXInRegion() == x && object.getYInRegion() == y && object.getPlane() == plane)
return null;
}
for (int i = 0; i < 4; i++) {
WorldObject object = objects[plane][x][y][i];
if (object != null && object.getId() == id) {
WorldObject spawned = getSpawnedObjectWithSlot(plane, x, y, OBJECT_SLOTS[object.getType()]);
return spawned == null ? object : null;
}
}
for (WorldObject object : spawnedObjects) {
if (object.getXInRegion() == x && object.getYInRegion() == y && object.getPlane() == plane && object.getId() == id)
return object;
}
return null;
}
public WorldObject getObjectWithId(int id, int plane) {
if (objects == null)
return null;
for (WorldObject object : spawnedObjects) {
if (object.getId() == id && object.getPlane() == plane)
return object;
}
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
for (int slot = 0; slot < objects[plane][x][y].length; slot++) {
WorldObject object = objects[plane][x][y][slot];
if (object != null && object.getId() == id)
return object;
}
}
}
return null;
}
public List<WorldObject> getSpawnedObjects() {
return spawnedObjects;
}
public List<WorldObject> getRemovedOriginalObjects() {
return removedOriginalObjects;
}
public void loadRegionMap() {
int regionX = (regionId >> 8) * 64;
int regionY = (regionId & 0xff) * 64;
int landArchiveId = Cache.STORE.getIndexes()[5].getArchiveId("l" + ((regionX >> 3) / 8) + "_" + ((regionY >> 3) / 8));
byte[] landContainerData = landArchiveId == -1 ? null : Cache.STORE.getIndexes()[5].getFile(landArchiveId, 0, MapArchiveKeys.getMapKeys(regionId));
int mapArchiveId = Cache.STORE.getIndexes()[5].getArchiveId("m" + ((regionX >> 3) / 8) + "_" + ((regionY >> 3) / 8));
byte[] mapContainerData = mapArchiveId == -1 ? null : Cache.STORE.getIndexes()[5].getFile(mapArchiveId, 0);
byte[][][] mapSettings = mapContainerData == null ? null : new byte[4][64][64];
if (mapContainerData != null) {
InputStream mapStream = new InputStream(mapContainerData);
for (int plane = 0; plane < 4; plane++) {
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
while (true) {
int value = mapStream.readUnsignedByte();
if (value == 0) {
break;
} else if (value == 1) {
mapStream.readByte();
break;
} else if (value <= 49) {
mapStream.readByte();
} else if (value <= 81) {
mapSettings[plane][x][y] = (byte) (value - 49);
}
}
}
}
}
for (int plane = 0; plane < 4; plane++) {
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
if ((mapSettings[plane][x][y] & 0x1) == 1) {
int realPlane = plane;
if ((mapSettings[1][x][y] & 2) == 2)
realPlane--;
if (realPlane >= 0)
forceGetRegionMap().addUnwalkable(realPlane, x, y);
}
}
}
}
}
else {
for (int plane = 0; plane < 4; plane++) {
for (int x = 0; x < 64; x++) {
for (int y = 0; y < 64; y++) {
forceGetRegionMap().addUnwalkable(plane, x, y);
}
}
}
}
if (landContainerData != null) {
InputStream landStream = new InputStream(landContainerData);
int objectId = -1;
int incr;
while ((incr = landStream.readSmart2()) != 0) {
objectId += incr;
int location = 0;
int incr2;
while ((incr2 = landStream.readUnsignedSmart()) != 0) {
location += incr2 - 1;
int localX = (location >> 6 & 0x3f);
int localY = (location & 0x3f);
int plane = location >> 12;
int objectData = landStream.readUnsignedByte();
int type = objectData >> 2;
int rotation = objectData & 0x3;
if (localX < 0 || localX >= 64 || localY < 0 || localY >= 64)
continue;
int objectPlane = plane;
if (mapSettings != null && (mapSettings[1][localX][localY] & 2) == 2)
objectPlane--;
if (objectPlane < 0 || objectPlane >= 4 || plane < 0 || plane >= 4)
continue;
spawnObject(new WorldObject(objectId, type, rotation, localX + regionX, localY + regionY, objectPlane), objectPlane, localX, localY, true);
}
}
}
if (Settings.DEBUG && landContainerData == null && landArchiveId != -1 && MapArchiveKeys.getMapKeys(regionId) != null)
Logger.log(this, "Missing xteas for region " + regionId + ".");
}
public int getRotation(int plane, int x, int y) {
return 0;
}
/**
* Get's ground item with specific id on the specific location in this
* region.
*/
public FloorItem getGroundItem(int id, WorldTile tile, Player player) {
if (groundItems == null)
return null;
for (FloorItem item : groundItems) {
if ((item.isInvisible()) && (item.hasOwner() && !player.getUsername().equals(item.getOwner())))
continue;
if (item.getId() == id && tile.getX() == item.getTile().getX() && tile.getY() == item.getTile().getY() && tile.getPlane() == item.getTile().getPlane())
return item;
}
return null;
}
/**
* Return's list of ground items that are currently loaded. List may be null
* if there's no ground items. Modifying given list is prohibited.
*
* @return
*/
public List<FloorItem> getGroundItems() {
return groundItems;
}
/**
* Return's list of ground items that are currently loaded. This method
* ensures that returned list is not null. Modifying given list is
* prohibited.
*
* @return
*/
public List<FloorItem> getGroundItemsSafe() {
if (groundItems == null)
groundItems = new CopyOnWriteArrayList<FloorItem>();
return groundItems;
}
public List<Integer> getPlayerIndexes() {
return playersIndexes;
}
public int getPlayerCount() {
return playersIndexes == null ? 0 : playersIndexes.size();
}
public List<Integer> getNPCsIndexes() {
return npcsIndexes;
}
public void addPlayerIndex(int index) {
// creates list if doesnt exist
if (playersIndexes == null)
playersIndexes = new CopyOnWriteArrayList<Integer>();
playersIndexes.add(index);
}
public void addNPCIndex(int index) {
// creates list if doesnt exist
if (npcsIndexes == null)
npcsIndexes = new CopyOnWriteArrayList<Integer>();
npcsIndexes.add(index);
}
public void removePlayerIndex(Integer index) {
if (playersIndexes == null) // removed region example cons or dung
return;
playersIndexes.remove(index);
}
public boolean removeNPCIndex(Object index) {
if (npcsIndexes == null) // removed region example cons or dung
return false;
return npcsIndexes.remove(index);
}
public void loadMusicIds() {
int musicId1 = getMusicId(getMusicName1(regionId));
if (musicId1 != -1) {
int musicId2 = getMusicId(getMusicName2(regionId));
if (musicId2 != -1) {
int musicId3 = getMusicId(getMusicName3(regionId));
if (musicId3 != -1)
musicIds = new int[] { musicId1, musicId2, musicId3 };
else
musicIds = new int[] { musicId1, musicId2 };
} else
musicIds = new int[] { musicId1 };
}
}
public int getRandomMusicId() {
if (musicIds == null)
return -1;
if (musicIds.length == 1)
return musicIds[0];
return musicIds[Utils.getRandom(musicIds.length - 1)];
}
public int getLoadMapStage() {
return loadMapStage;
}
public void setLoadMapStage(int loadMapStage) {
this.loadMapStage = loadMapStage;
}
public boolean isLoadedObjectSpawns() {
return loadedObjectSpawns;
}
public void setLoadedObjectSpawns(boolean loadedObjectSpawns) {
this.loadedObjectSpawns = loadedObjectSpawns;
}
public boolean isLoadedNPCSpawns() {
return loadedNPCSpawns;
}
public void setLoadedNPCSpawns(boolean loadedNPCSpawns) {
this.loadedNPCSpawns = loadedNPCSpawns;
}
public int getRegionId() {
return regionId;
}
public static final String getMusicName3(int regionId) {
switch (regionId) {
case 13152: // crucible
return "Steady";
case 13151: // crucible
return "Hunted";
case 12895: // crucible
return "Target";
case 12896: // crucible
return "I Can See You";
case 11575: // burthope
return "Spiritual";
case 18512:
case 18511:
case 19024:
return "Tzhaar City III";
case 18255: // fight pits
return "Tzhaar Supremacy III";
case 14948:
return "Dominion Lobby III";
default:
return null;
}
}
public static final String getMusicName2(int regionId) {
switch (regionId) {
case 12342: // edge
return "Stronger (What Doesn't Kill You)";
case 13152: // crucible
return "I Can See You";
case 13151: // crucible
return "You Will Know Me";
case 12895: // crucible
return "Steady";
case 12896: // crucible
return "Hunted";
case 12853:
return "Cellar Song";
case 11573: // taverley
return "Taverley Enchantment";
case 11575: // burthope
return "Taverley Adventure";
/*
* kalaboss
*/
case 13626:
case 13627:
case 13882:
case 13881:
return "Daemonheim Fremenniks";
case 18512:
case 18511:
case 19024:
return "Tzhaar City II";
case 18255: // fight pits
return "Tzhaar Supremacy II";
case 14948:
return "Dominion Lobby II";
default:
return null;
}
}
public static final String getMusicName1(int regionId) {
switch (regionId) {
case 8774: //taverly slayer dungeon
return "Taverley Lament";
case 11576:
return "Kingdom";
case 11320:
return "Tremble";
case 12616: //tarns lair
return "Undead Dungeon";
case 10388:
return "Cavern";
case 12107:
return "Into the Abyss";
case 11164:
return "The Slayer";
case 10908:
case 10907:
return "Masquerade";
case 4707:
case 4451:
case 5221:
case 5220:
case 5219:
case 4453:
case 4709:
return "Hunting Dragons";
case 12115:
return "Dimension X";
case 8527: //braindeath island
return "Aye Car Rum Ba";
case 8528: //braindeath mountain
return "Blistering Barnacles";
case 13206: //goblin mines under lumby
return "The Lost Tribe";
case 12949:
case 12950:
return "Cave of the Goblins";
case 12948:
return "The Power of Tears";
case 11416: //dramen tree
return "Underground";
case 14638: //mosleharms
return "In the Brine";
case 14637:
case 14894:
return "Life's a Beach!";
case 14494: //mosleharms cave
return "Little Cave of Horrors";
case 11673: //taverly dungeon musics
return "Courage";
case 11672:
return "Dunjun";
case 11417:
return "Arabique";
case 11671:
return "Royale";
case 13977:
return "Stillness";
case 13622:
return "Morytania";
case 13722:
return "Mausoleum";
case 10906:
return "Twilight";
case 12181: //Asgarnian Ice Dungeon's wyvern area
return "Woe of the Wyvern";
case 11925: //Asgarnian Ice Dungeon
return "Starlight";
case 13617: //abbey
return "Citharede Requiem";
case 13361: //desert verms
return "Valerio's Song";
case 13910: //The Tale of the Muspah cave entrance
case 13654:
return "Rest for the Weary";
case 13656: //The Tale of the Muspah cave ice verms area
return "The Muspah's Tomb";
case 11057: //brimhaven and arroundd
return "High Seas";
case 10802:
return "Jungly2";
case 10801:
return "Landlubber";
case 11058:
return "Jolly-R";
case 10901: //brimhaven dungeon entrance
return "Pathways";
case 10645: //brimhaven dungeon
case 10644:
case 10900:
return "7th Realm";
case 11315: //crandor
case 11314:
return "The Shadow";
case 11414: //karanja underground
case 11413:
return "Dangerous Road";
case 7505: //strongholf of security war
return "Dogs of War";
case 8017: //strongholf of security famine
return "Food for Thought";
case 8530: //strongholf of security pestile
return "Malady";
case 9297: //strongholf of security death
return "Dance of Death";
case 10040:
return "Lighthouse";
case 10140: // inside lighthouse
return "Out of the Deep";
case 9797:
return "Crystal Cave";
case 9541:
return "Faerie";
case 11927: // gamers grotto
return "Cave Background";
case 10301: // dz
return "Skyfall";
case 14646:// Port Phasmatys
return "The Other Side";
case 14746:// Ectofuntus
return "Phasmatys";
case 14747:// Port Phasmatys brewery
return "Brew Hoo Hoo";
case 15967:// Runespan
return "Runespan";
case 15711:// Runespan
return "Runearia";
case 15710:// Runespan
return "Runebreath";
case 13152: // crucible
return "Hunted";
case 13151: // crucible
return "Target";
case 12895: // crucible
return "I Can See You";
case 12896: // crucible
return "You Will Know Me";
case 12597:
return "Spirit";
case 13109:
return "Medieval";
case 13110:
return "Honkytonky Parade";
case 10658:
return "Espionage";
case 13899: // water altar
return "Zealot";
case 10039:
return "Legion";
case 11319: // warriors guild
return "Warriors' Guild";
case 11575: // burthope
return "Spiritual";
case 11573: // taverley
return "Taverley Ambience";
case 7473:
return "The Waiting Game";
case 18512:
case 18511:
case 19024:
return "Tzhaar City I";
case 18255: // fight pits
return "Tzhaar Supremacy I";
case 14672:
case 14671:
case 14415:
case 14416:
return "Living Rock";
case 11157: // Brimhaven Agility Arena
return "Aztec";
case 15446:
case 15957:
case 15958:
return "Dead and Buried";
case 12848:
return "Arabian3";
case 12954:
case 12442:
case 12441:
return "Scape Cave";
case 12185:
case 11929:
return "Dwarf Theme";
case 12184:
return "Workshop";
case 6992:
case 6993: // mole lair
return "The Mad Mole";
case 9776: // castle wars
return "Melodrama";
case 10029:
case 10285:
return "Jungle Hunt";
case 14231: // barrows under
return "Dangerous Way";
case 12856: // chaos temple
return "Faithless";
case 13104:
case 12847: // arround desert camp
case 13359:
case 13102:
return "Desert Voyage";
case 13103:
return "Lonesome";
case 12589: // granite mine
return "The Desert";
case 18517: //polipore dungeon
case 18516:
case 18773:
case 18775:
case 13407: // crucible entrance
case 13360: // dominion tower outside
return "";
case 14948:
return "Dominion Lobby I";
case 11836: // lava maze near kbd entrance
return "Attack3";
case 12091: // lava maze west
return "Wilderness2";
case 12092: // lava maze north
return "Wild Side";
case 9781:
return "Gnome Village";
case 11339: // air altar
return "Serene";
case 11083: // mind altar
return "Miracle Dance";
case 10827: // water altar
return "Zealot";
case 10571: // earth altar
return "Down to Earth";
case 10315: // fire altar
return "Quest";
case 8523: // cosmic altar
return "Stratosphere";
case 9035: // chaos altar
return "Complication";
case 8779: // death altar
return "La Mort";
case 10059: // body altar
return "Heart and Mind";
case 9803: // law altar
return "Righteousness";
case 9547: // nature altar
return "Understanding";
case 9804: // blood altar
return "Bloodbath";
case 13107:
return "Arabian2";
case 13105:
return "Al Kharid";
case 12342: // edge
return "Forever";
case 10806:
return "Overture";
case 10899:
return "Karamja Jam";
case 13623:
return "The Terrible Tower";
case 12374:
return "The Route of All Evil";
case 9802:
return "Undead Dungeon";
case 10809: // east rellekka
return "Borderland";
case 10553: // Rellekka
return "Rellekka";
case 10552: // south
return "Saga";
case 10296: // south west
return "Lullaby";
case 10828: // south east
return "Legend";
case 9275:
return "Volcanic Vikings";
case 11061:
case 11317:
return "Fishing";
case 9551:
return "TzHaar!";
case 12345:
return "Eruption";
case 12089:
return "Dark";
case 12446:
case 12445:
return "Wilderness";
case 12343:
return "Dangerous";
case 14131:
return "Dance of the Undead";
case 11844:
case 11588:
return "The Vacant Abyss";
case 13363: // duel arena hospital
return "Shine";
case 13362: // duel arena
return "Duel Arena";
case 12082: // port sarim
return "Sea Shanty2";
case 12081: // port sarim south
return "Tomorrow";
case 11602:
return "Strength of Saradomin";
case 12590:
return "Bandit Camp";
case 10329:
return "The Sound of Guthix";
case 9033:
return "Attack5";
// godwars
case 11603:
return "Zamorak Zoo";
case 11346:
return "Armadyl Alliance";
case 11347:
return "Armageddon";
case 13114:
return "Wilderness";
// black kngihts fortess
case 12086:
return "Knightmare";
// tzaar
case 9552:
return "Fire and Brimstone";
// kq
case 13972:
return "Insect Queen";
// clan wars free for all:
case 11094:
return "Clan Wars";
/*
* tutorial island
*/
case 12336:
return "Newbie Melody";
/*
* darkmeyer
*/
case 14644:
return "Darkmeyer";
/*
* kalaboss
*/
case 13626:
case 13627:
case 13882:
case 13881:
return "Daemonheim Entrance";
/*
* Lumbridge, falador and region.
*/
case 11574: // heroes guild
return "Splendour";
case 12851:
return "Autumn Voyage";
case 12338: // draynor and market
return "Unknown Land";
case 12339: // draynor up
return "Start";
case 12340: // draynor mansion
return "Spooky";
case 12850: // lumbry castle
return "Harmony";
case 12849: // east lumbridge swamp
return "Yesteryear";
case 12593: // at Lumbridge Swamp.
return "Book of Spells";
case 12594: // on the path between Lumbridge and Draynor.
return "Dream";
case 12595: // at the Lumbridge windmill area.
return "Flute Salad";
case 12854: // at Varrock Palace.
return "Adventure";
case 12853: // at varrock center
return "Garden";
case 12852: // varock mages
return "Expanse";
case 13108:
return "Still Night";
case 12083:
return "Wander";
case 11828:
return "Fanfare";
case 11829:
return "Scape Soft";
case 11577:
return "Mad Eadgar";
case 10293: // at the Fishing Guild.
return "Mellow";
case 11824:
return "Mudskipper Melody";
case 11570:
return "Wandar";
case 12341:
return "Barbarianims";
case 12855:
return "Crystal Sword";
case 12344:
return "Dark";
case 12599:
return "Doorways";
case 12598:
return "The Trade Parade";
case 11318:
return "Ice Melody";
case 12600:
return "Scape Wild";
case 10032: // west yannile:
return "Big Chords";
case 10288: // east yanille
return "Magic Dance";
case 11826: // Rimmington
return "Long Way Home";
case 11825: // rimmigton coast
return "Attention";
case 11827: // north rimmigton
return "Nightfall";
/*
* Camelot and region.
*/
case 11062:
case 10805:
return "Camelot";
case 10550:
return "Talking Forest";
case 10549:
return "Lasting";
case 10548:
return "Wonderous";
case 10547:
return "Baroque";
case 10291:
case 10292:
return "Knightly";
case 11571: // crafting guild
return "Miles Away";
case 11595: // ess mine
return "Rune Essence";
case 10294:
return "Theme";
case 12349:
return "Mage Arena";
case 13365: // digsite
return "Venture";
case 13364: // exams center
return "Medieval";
case 13878: // canifis
return "Village";
case 13877: // canafis south
return "Waterlogged";
/*
* Mobilies Armies.
*/
case 9516:
return "Command Centre";
case 12596: // champions guild
return "Greatness";
case 10804: // legends guild
return "Trinity";
case 11601:
return "Zaros Zeitgeist"; // zaros godwars
default:
return null;
}
}
private static final int getMusicId(String musicName) {
if (musicName == null)
return -1;
if (musicName.equals(""))
return -2;
if (musicName.equals("Skyfall"))
return 2000;
if (musicName.equals("Stronger (What Doesn't Kill You)"))
return 2001;
int musicIndex = (int) ClientScriptMap.getMap(1345).getKeyForValue(musicName);
return ClientScriptMap.getMap(1351).getIntValue(musicIndex);
}
public boolean isLoadedItemSpawns() {
return loadedItemSpawns;
}
public void setLoadedItemSpawns(boolean loadedItemSpawns) {
this.loadedItemSpawns = loadedItemSpawns;
}
public int getMusicId() {
if (musicIds == null)
return -1;
if (musicIds.length == 1)
return musicIds[0];
return musicIds[Utils.getRandom(musicIds.length - 1)];
}
public List<FloorItem> forceGetFloorItems() {
if (groundItems == null)
groundItems = new CopyOnWriteArrayList<FloorItem>();
return groundItems;
}
public List<FloorItem> getFloorItems() {
return groundItems;
}
public void removeObject(WorldObject object) {
if (spawnedObjects == null)
return;
spawnedObjects.remove(object);
}
public boolean containsObject(int id, WorldObject object) {
return World.getObjectWithId(new WorldTile(object.getPlane(), object.getX(),
object.getY()), id) != null;
}
}
and here my world class
Code:
package com.rs.game;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
//import com.rs.game.player.content.GrandExchange.Offers;
import com.rs.Launcher;
import com.rs.Settings;
import com.rs.cores.CoresManager;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.Hit.HitLook;
import com.rs.game.item.FloorItem;
import com.rs.game.item.Item;
import com.rs.game.minigames.GodWarsBosses;
import com.rs.game.minigames.WarriorsGuild;
import com.rs.game.minigames.ZarosGodwars;
import com.rs.game.minigames.clanwars.FfaZone;
import com.rs.game.minigames.clanwars.RequestController;
import com.rs.game.minigames.duel.DuelControler;
import com.rs.game.minigames.soulwars.SoulLobby;
import com.rs.game.minigames.soulwars.SoulWars;
import com.rs.game.mysql.DatabaseManager;
import com.rs.game.npc.NPC;
import com.rs.game.npc.corp.CorporealBeast;
import com.rs.game.npc.dragons.KingBlackDragon;
import com.rs.game.npc.glacor.Glacor;
import com.rs.game.npc.godwars.GodWarMinion;
import com.rs.game.npc.godwars.armadyl.GodwarsArmadylFaction;
import com.rs.game.npc.godwars.armadyl.KreeArra;
import com.rs.game.npc.godwars.bandos.GeneralGraardor;
import com.rs.game.npc.godwars.bandos.GodwarsBandosFaction;
import com.rs.game.npc.godwars.saradomin.CommanderZilyana;
import com.rs.game.npc.godwars.saradomin.GodwarsSaradominFaction;
import com.rs.game.npc.godwars.zammorak.GodwarsZammorakFaction;
import com.rs.game.npc.godwars.zammorak.KrilTstsaroth;
import com.rs.game.npc.godwars.zaros.Nex;
import com.rs.game.npc.godwars.zaros.NexMinion;
import com.rs.game.npc.kalph.KalphiteQueen;
import com.rs.game.npc.nomad.FlameVortex;
import com.rs.game.npc.nomad.Nomad;
import com.rs.game.npc.others.Bork;
import com.rs.game.npc.others.Elemental;
import com.rs.game.npc.others.ItemHunterNPC;
import com.rs.game.npc.others.LivingRock;
import com.rs.game.npc.others.Lucien;
import com.rs.game.npc.others.MasterOfFear;
import com.rs.game.npc.others.MercenaryMage;
import com.rs.game.npc.others.Revenant;
import com.rs.game.npc.others.TormentedDemon;
import com.rs.game.npc.others.Werewolf;
import com.rs.game.npc.slayer.GanodermicBeast;
import com.rs.game.npc.slayer.Strykewyrm;
import com.rs.game.player.OwnedObjectManager;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.player.actions.BoxAction.HunterNPC;
import com.rs.game.player.actions.objects.EvilTree;
import com.rs.game.player.content.ItemConstants;
import com.rs.game.player.content.LivingRockCavern;
import com.rs.game.player.content.PenguinEvent;
import com.rs.game.player.content.ShootingStar;
import com.rs.game.player.content.ShootingStars;
import com.rs.game.player.content.SinkHoles;
import com.rs.game.player.content.TriviaBot;
import com.rs.game.player.content.VoteRewards;
import com.rs.game.player.content.XPWell;
import com.rs.game.player.content.botanybay.BotanyBay;
import com.rs.game.player.controlers.StartTutorial;
import com.rs.game.player.controlers.Wilderness;
import com.rs.game.player.controlers.dung.RuneDungGame;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
import com.rs.utils.AntiFlood;
import com.rs.utils.IPBanL;
import com.rs.utils.IPMute;
import com.rs.utils.KillStreakRank;
import com.rs.utils.Logger;
import com.rs.utils.Misc;
import com.rs.utils.PkRank;
import com.rs.utils.ShopsHandler;
import com.rs.utils.Utils;
import java.util.ArrayList;
public final class World {
public static int exiting_delay;
public static long exiting_start;
private static DatabaseManager database = new DatabaseManager();
public static DatabaseManager database() {
return database;
}
private static final EntityList<Player> players = new EntityList<Player>(
Settings.PLAYERS_LIMIT);
private static final EntityList<NPC> npcs = new EntityList<NPC>(
Settings.NPCS_LIMIT);
private static final Map<Integer, Region> regions = Collections
.synchronizedMap(new HashMap<Integer, Region>());
// private static final Object lock = new Object();
public static final boolean containsObjectWithId(WorldTile tile, int id) {
return getRegion(tile.getRegionId()).containsObjectWithId(tile.getPlane(), tile.getXInRegion(), tile.getYInRegion(), id);
}
public static final WorldObject getObjectWithId(WorldTile tile, int id) {
return getRegion(tile.getRegionId()).getObjectWithId(tile.getPlane(), tile.getXInRegion(), tile.getYInRegion(), id);
}
public static NPC getNPC(int npcId) {
for (NPC npc : getNPCs()) {
if(npc.getId() == npcId) {
return npc;
}
}
return null;
}
private static BotanyBay botanyBay;
public static BotanyBay getBotanyBay() {
return botanyBay;
}
private static final void addShootingStarMessageEvent() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
if (ShootingStars.locationName != null
&& !ShootingStars.locationName.isEmpty())
World.sendWorldMessage(
"<col=FFFF00>A falling star is currently in "
+ Character
.toUpperCase(ShootingStars.locationName
.charAt(0))
+ ShootingStars.locationName
.substring(1), false);
} catch (Exception e) {
e.printStackTrace();
} catch (Error e) {
e.printStackTrace();
}
}
}, 0, 6, TimeUnit.MINUTES);
}
private static void growPatchesTask() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
for (Player player : players) {
if (player != null && player.getFarmings() != null && !player.hasFinished()) {
player.getFarmings().growAllPatches(player);
}
}
} catch (Throwable e) {
}
}
}, 5, 5, TimeUnit.MINUTES);
}
private static int wellAmount;
private static boolean wellActive = false;
public static int getWellAmount() {
return wellAmount;
}
public static void addWellAmount(String displayName, int amount) {
wellAmount += amount;
sendWorldMessage("<col=FF0000>" + displayName + " has contributed " + NumberFormat.getNumberInstance(Locale.US).format(amount) + " GP to the XP well! Progress now: " + ((World.getWellAmount() * 100) / Settings.WELL_MAX_AMOUNT) + "%!", false);
}
private static void setWellAmount(int amount) {
wellAmount = amount;
}
public static void resetWell() {
wellAmount = 0;
sendWorldMessage("<col=FF0000>The XP well has been reset!", false);
}
public static boolean isWellActive() {
return wellActive;
}
public static void setWellActive(boolean wellActive) {
World.wellActive = wellActive;
}
public static void loadWell() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("./data/well/data.txt"));
String line = null;
while ((line = reader.readLine()) != null) {
String[] args = line.split(" ");
if (args[0].contains("true")) {
World.setWellActive(true);
XPWell.taskTime = Integer.parseInt(args[1]);
XPWell.taskAmount = Integer.parseInt(args[1]);
XPWell.setWellTask();
} else {
setWellAmount(Integer.parseInt(args[1]));
}
}
}
public static final Player get(int index) {
for (Player player : getPlayers()) {
if (player == null)
continue;
if (player.definition().index() == index)
return player;
}
return null;
}
public static void spinPlate(final Player player) {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
if(player.spinTimer > 0) {
player.spinTimer--;
}
if(player.spinTimer == 1) {
if(Misc.random(2) == 1) {
player.setNextAnimation(new Animation(1906));
player.getInventory().deleteItem(4613, 1);
addGroundItem(new Item(4613, 1), new WorldTile(player.getX(), player.getY(), player.getPlane()), player, false, 180, true);
}
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 1000);
}
public static void addTime(final Player player) {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null || !player.isRunning())
continue;
player.onlinetime++;
player.afk();
player.afk--;
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 2000);
}
public static void depletePendant(final Player player) {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
if (player.pendantTime == 55)
player.sm("You have 5 more minutes until your pendant depletes.");
if (player.pendantTime == 60) {
player.getEquipment().getItems().set(2, new Item(24712, 1));
player.sm("Your pendant has been depleted of its power.");
}
if (player.getPendant().hasAmulet()) {
player.pendantTime++;
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 60000);
}
public static void startSmoke(final Player player) {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
if (player.getEquipment().getHatId() == 4164 || player.getEquipment().getHatId() == 13277 || player.getEquipment().getHatId() == 13263 || player.getEquipment().getHatId() == 14636 || player.getEquipment().getHatId() == 14637 || player.getEquipment().getHatId() == 15492
|| player.getEquipment().getHatId() == 15496 || player.getEquipment().getHatId() == 15497 || player.getEquipment().getHatId() == 22528 || player.getEquipment().getHatId() == 22530 || player.getEquipment().getHatId() == 22532 || player.getEquipment().getHatId() == 22534
|| player.getEquipment().getHatId() == 22536 || player.getEquipment().getHatId() == 22538 || player.getEquipment().getHatId() == 22540 || player.getEquipment().getHatId() == 22542 || player.getEquipment().getHatId() == 22544 || player.getEquipment().getHatId() == 22546
|| player.getEquipment().getHatId() == 22548 || player.getEquipment().getHatId() == 22550) {
player.getPackets().sendGameMessage("Your equipment protects you from the smoke.");
} else {
if (player.getHitpoints() > 120) {
player.applyHit(new Hit(player, 120, HitLook.REGULAR_DAMAGE));
player.getPackets().sendGameMessage("You take damage from the smoke.");
}
}
if (!player.isAtSmokeyArea()) {
cancel();
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 12000);
}
public static boolean killedTree;
public static boolean treeEvent;
public static void startEvilTree() {
WorldObject evilTree = new WorldObject(11922,
10, 0, 2456,
2835, 0);
final WorldObject deadTree = new WorldObject(12715,
10, 0, 2456,
2835, 0);
spawnObject(evilTree, true);
EvilTree.health = 5000;
treeEvent = true;
killedTree = false;
sendWorldMessage("<img=6><col=FFA500><shad=000000>An Evil Tree has appeared nearby Moblishing Armies, talk to a Spirit Tree to reach it!", false);
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
if (EvilTree.health <= 0) {
spawnTemporaryObject(deadTree, 600000, true);
killedTree = true;
sendWorldMessage("<img=6><col=FFA500><shad=000000>The Evil Tree has been defeated!", false);
executeTree();
cancel();
WorldTasksManager.schedule(new WorldTask() {
int loop = 0;
@Override
public void run() {
if (loop == 600) {
treeEvent = false;
killedTree = false;
cancel();
}
loop++;
}
}, 0, 1);
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 1000);
}
public static void executeTree() {
final int time = Misc.random(3600000, 7200000);
CoresManager.fastExecutor.schedule(new TimerTask() {
int loop = 0;
@Override
public void run() {
try {
if (loop == time) {
startEvilTree();
cancel();
}
loop++;
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 1);
}
private static void SoulWarsWaitTimer() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
for (int index = 0; index < SoulLobby.allWaiting.size(); index++) {
Player players = SoulLobby.allWaiting.get(index);
if(SoulLobby.minutes == 0 && SoulLobby.allWaiting.size() >=2 && SoulWars.startedGame == false) {
SoulWars.passPlayersToGame();
}else if (SoulLobby.minutes == 0 && SoulLobby.allWaiting.size() == 1) {
SoulWars.cantStart(players);
}
}
for (Player player : getPlayers()) {
if (SoulLobby.minutes == 0) {
SoulLobby.minutes = 5;
}
if (SoulWars.startedGame == true) {
player.getPackets().sendIComponentText(837, 8, "Players needed");
player.getPackets().sendIComponentText(837, 3, " -" );
player.getPackets().sendIComponentText(837, 5, " -");
player.getPackets().sendIComponentText(837, 9,
"New game: " + SoulWars.gameTime + " mins");
}
if (SoulWars.startedGame ==false) {
player.getPackets().sendIComponentText(837, 8, "Players needed");
player.getPackets().sendIComponentText(837, 3, "-" );
player.getPackets().sendIComponentText(837, 5, "-");
player.getPackets().sendIComponentText(837, 9,
"New game: " + SoulLobby.minutes + " mins");
}
}
}
}, 0L, 1000L);
}
@SuppressWarnings({ })
private static final void SwDepleat() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
if(SoulLobby.minutes > 0) {
SoulLobby.minutes--;
}
} catch (Exception e) {
e.printStackTrace();
} catch (Error e) {
e.printStackTrace();
}
}
}, 0, 1, TimeUnit.MINUTES);
}
@SuppressWarnings({ })
private static final void SwGameDepleat() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
if(SoulWars.gameTime >0) {
SoulWars.gameTime--;
}
} catch (Exception e) {
e.printStackTrace();
} catch (Error e) {
e.printStackTrace();
}
}
}, 0, 1, TimeUnit.MINUTES);// 5 min per message
}
public static void startDesert(final Player player) {
int mili = 90000;
if ((player.getEquipment().getHatId() == 6382 && (player.getEquipment().getChestId() == 6384 || player.getEquipment().getChestId() == 6388) && (player.getEquipment().getLegsId() == 6390 || player.getEquipment().getLegsId() == 6386))
|| (player.getEquipment().getChestId() == 1833 && player.getEquipment().getLegsId() == 1835 && player.getEquipment().getBootsId() == 1837)
|| ((player.getEquipment().getHatId() == 6392 || player.getEquipment().getHatId() == 6400) && (player.getEquipment().getChestId() == 6394 || player.getEquipment().getChestId() == 6402) && (player.getEquipment().getLegsId() == 6396 || player.getEquipment().getLegsId() == 6398 || player.getEquipment().getLegsId() == 6404 || player.getEquipment().getLegsId() == 6406))
|| (player.getEquipment().getChestId() == 1844 && player.getEquipment().getLegsId() == 1845 && player.getEquipment().getBootsId() == 1846)) {
mili = 120000;
}
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
if (!player.isAtDesertArea()) {
cancel();
}
for (int i = 0; i <= 28; i++) {
evaporate(player);
}
if (player.isAtDesertArea()) {
if (player.getInventory().containsItem(1823, 1)) {
player.setNextAnimation(new Animation(829));
player.getInventory().deleteItem(1823, 1);
player.getInventory().addItem(1825, 1);
player.getPackets().sendGameMessage("You drink from the waterskin.");
} else if (player.getInventory().containsItem(1825, 1)) {
player.setNextAnimation(new Animation(829));
player.getInventory().deleteItem(1825, 1);
player.getInventory().addItem(1827, 1);
player.getPackets().sendGameMessage("You drink from the waterskin.");
} else if (player.getInventory().containsItem(1827, 1)) {
player.setNextAnimation(new Animation(829));
player.getInventory().deleteItem(1827, 1);
player.getInventory().addItem(1829, 1);
player.getPackets().sendGameMessage("You drink from the waterskin.");
} else if (player.getInventory().containsItem(1829, 1)) {
player.setNextAnimation(new Animation(829));
player.getInventory().deleteItem(1829, 1);
player.getInventory().addItem(1831, 1);
player.getPackets().sendGameMessage("You drink from the waterskin.");
} else if (player.getInventory().containsItem(6794, 1)) {
player.setNextAnimation(new Animation(829));
player.getInventory().deleteItem(6794, 1);
player.getPackets().sendGameMessage("You eat one of your choc-ices.");
player.heal(70);
} else {
int damage = Misc.random(100, 300);
if (player.getEquipment().getShieldId() == 18346) {
player.applyHit(new Hit(player, (damage - 50), HitLook.REGULAR_DAMAGE));
} else {
player.applyHit(new Hit(player, damage, HitLook.REGULAR_DAMAGE));
}
player.getPackets().sendGameMessage("You take damage from the desert heat.");
}
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, mili);
}
public static void evaporate(final Player player) {
if (player.getInventory().containsItem(227, 1)) {
player.getInventory().deleteItem(227, 1);
player.getInventory().addItem(229, 1);
} else if (player.getInventory().containsItem(1921, 1)) {
player.getInventory().deleteItem(1921, 1);
player.getInventory().addItem(1923, 1);
} else if (player.getInventory().containsItem(1929, 1)) {
player.getInventory().deleteItem(1929, 1);
player.getInventory().addItem(1925, 1);
} else if (player.getInventory().containsItem(1937, 1)) {
player.getInventory().deleteItem(1937, 1);
player.getInventory().addItem(1935, 1);
} else if (player.getInventory().containsItem(4458, 1)) {
player.getInventory().deleteItem(4458, 1);
player.getInventory().addItem(1980, 1);
}
}
public static final void init() {
//addLogicPacketsTask();
SwDepleat();
SoulWarsWaitTimer();
addShootingStarMessageEvent();
SwGameDepleat();
if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) == 24) {
VoteRewards.chooseRandomVoter();
}
//spawnStar();
startEvilTree();
ServerMessages();
bossRaid();
penguinHS();
sinkHoles();
growPatchesTask();
autoEvent();
addTriviaBotTask();
addRestoreRunEnergyTask();
addDrainPrayerTask();
addRestoreHitPointsTask();
addRestoreSkillsTask();
addRestoreSpecialAttackTask();
addRestoreShopItemsTask();
addSummoningEffectTask();
addOwnedObjectsTask();
LivingRockCavern.init();
addListUpdateTask();
WarriorsGuild.init();
}
/*
* private static void addLogicPacketsTask() {
* CoresManager.fastExecutor.scheduleAtFixedRate(new TimerTask() {
*
* @Override public void run() { for(Player player : World.getPlayers()) {
* if(!player.hasStarted() || player.hasFinished()) continue;
* player.processLogicPackets(); } }
*
* }, 300, 300); }
*/
public static List<WorldTile> restrictedTiles = new ArrayList<WorldTile>();
public static void deleteObject(WorldTile tile){
restrictedTiles.add(tile);
}
public static int checkStaffOnline() {
int staffs = 0;
for (Player staff : getPlayers()) {
if (staff == null) {
continue;
}
if (staff.getRights() == 0) {
continue;
} else {
staffs++;
}
}
return staffs;
}
private static void addOwnedObjectsTask() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
OwnedObjectManager.processAll();
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 1, TimeUnit.SECONDS);
}
public static void ServerMessages() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
int message;
@Override
public void run() {
if (message == 1) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>Do not ask for staff, staff ranks are earned!", false);
System.out.println("[ServerMessages] Server Message sent successfully.");
/*} if (message == 2) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>Register on the forums at http://Zamron.net/forums", false);
*/System.out.println("[ServerMessages] Server Message sent successfully.");
/*} if (message == 3) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>We now have auto ::donate for ranks!", false);
*/System.out.println("[ServerMessages] Server Message sent successfully.");
} if (message == 4) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>To answer trivia questions, do ::answer (answer)!", false);
System.out.println("[ServerMessages] Server Message sent successfully.");
} if (message == 5) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>If you need any help, use your Submit Ticket tab!", false);
System.out.println("[ServerMessages] Server Message sent successfully.");
/*} if (message == 6) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>Don't forget to ::vote for epic rewards!", false);
*/ System.out.println("[ServerMessages] Server Message sent successfully.");
} if (message == 7) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>Help the server by advertising!", false);
System.out.println("[ServerMessages] Server Message sent successfully.");
/*} if (message == 8) {
sendWorldMessage("<img=6><col=FFA500><shad=000000>Need some support or the owner? Type the command ::support for live support!", false);
*/ System.out.println("[ServerMessages] Server Message sent successfully.");
message = 0;
}
message++;
}
},0, 2, TimeUnit.MINUTES);
}
public static int star = 0;
private static final void addListUpdateTask() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null || player.isDead()
|| !player.isRunning())
continue;
player.getPackets().sendIComponentText(751, 16, "Players Online: <col=00FF00>" + getPlayers().size());
if(!(player.getControlerManager().getControler() instanceof RuneDungGame) && player.isInDung()){
for (Item item : player.getInventory().getItems().toArray()) {
if (item == null) continue;
player.getInventory().deleteItem(item);
player.setNextWorldTile(new WorldTile(3450, 3718, 0));
}
for (Item item : player.getEquipment().getItems().toArray()) {
if (item == null) continue;
player.getEquipment().deleteItem(item.getId(), item.getAmount());
}
if (player.getFamiliar() != null) {
if (player.getFamiliar().getBob() != null)
player.getFamiliar().getBob().getBeastItems().clear();
player.getFamiliar().dissmissFamiliar(false);
}
player.setInDung(false);
}
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 10);
}
//Automated Events
public static boolean bandos;
public static boolean armadyl;
public static boolean zamorak;
public static boolean saradomin;
public static boolean dungeoneering;
public static boolean cannonball;
public static boolean doubleexp;
public static boolean nex;
public static boolean sunfreet;
public static boolean corp;
//public static boolean doubledrops;
public static boolean slayerpoints;
public static boolean moreprayer;
public static boolean quadcharms;
public static void autoEvent() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
bandos = false;
armadyl = false;
zamorak = false;
saradomin = false;
dungeoneering = false;
cannonball = false;
doubleexp = false;
nex = false;
sunfreet = false;
corp = false;
//doubledrops = false;
slayerpoints = false;
moreprayer = false;
quadcharms = false;
try {
int event = Misc.random(225);
if (event >= 1 && event <= 15) {
bandos = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Event at Bandos! No Kill Count required!", false);
} else if (event >= 16 && event <= 30) {
armadyl = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Event at Armadyl! No Kill Count required!", false);
} else if (event >= 31 && event <= 45) {
zamorak = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Event at Zamorak! No Kill Count required!", false);
} else if (event >= 46 && event <= 60) {
saradomin = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Event at Saradomin! No Kill Count required!", false);
} else if (event >= 61 && event <= 65) {
dungeoneering = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Dungeoneering event! Come explore Dungeons with Double EXP and Tokens!", false);
} else if (event >= 66 && event <= 75) {
cannonball = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] The furnaces have improved, make 2x the amount of Cannonballs!", false);
} else if (event == 76 || event == 80) {
doubleexp = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Double Exp", false);
} else if (event >= 81 && event <= 100) {
nex = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Event at Nex! Get your torva now!", false);
} else if (event >= 101 && event <= 120) {
sunfreet = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Event at Sunfreet! Get your riches now!", false);
} else if (event >= 121 && event <= 145) {
corp = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Event at Corp! Get your sigils now!", false);
/*} else if (event == 146) {
doubledrops = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Double Drops are now on, take advantage and gain double the wealth!", false);*/
} else if (event >= 147 && event <= 160) {
slayerpoints = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Double slayer points when completing a task!", false);
} else if (event >= 161 && event <= 180) {
moreprayer = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Double Prayer EXP!", false);
} else if (event >= 181 && event <= 190) {
quadcharms = true;
World.sendWorldMessage("<img=6><col=ff0000>[Event Manager] Monsters are now dropping quadruple the amounts of charms!", false);
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 3900000);
}
public static void killRaid() {
for (NPC n : World.getNPCs()) {
if (n == null || (n.getId() != 3064 && n.getId() != 10495 && n.getId() != 3450 && n.getId() != 3063 && n.getId() != 3058 && n.getId() != 4706 && n.getId() != 10769 && n.getId() != 10761 && n.getId() != 10717 && n.getId() != 15581 && n.getId() != 999 && n.getId() != 998 && n.getId() != 1000 && n.getId() != 14550 && n.getId() != 8335 && n.getId() != 2709 && n.getId() != 2710 && n.getId() != 2711 && n.getId() != 2712))
continue;
n.sendDeath(n);
}
}
public static void bossRaid() {
int time = Misc.random(3600000, 7200000);
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
int raid = Misc.random(6);
if (raid == 1) {
killRaid();
spawnNPC(3064, new WorldTile(3126, 3440, 0), -1, true, true);
spawnNPC(10495, new WorldTile(3129, 3438, 0), -1, true, true);
spawnNPC(10495, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(10495, new WorldTile(3127, 3437, 0), -1, true, true);
World.sendWorldMessage("<img=6><col=ff0000>[Boss Raid] Demons has just invaded North-West of home!", false);
} else if (raid == 2) {
killRaid();
spawnNPC(3063, new WorldTile(3126, 3440, 0), -1, true, true);
spawnNPC(3450, new WorldTile(3129, 3438, 0), -1, true, true);
spawnNPC(3450, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(3450, new WorldTile(3127, 3437, 0), -1, true, true);
World.sendWorldMessage("<img=6><col=ff0000>[Boss Raid] Jogres has just invaded North-West of home!", false);
} else if (raid == 3) {
killRaid();
spawnNPC(3058, new WorldTile(3126, 3431, 0), -1, true, true);
spawnNPC(4706, new WorldTile(3126, 3440, 0), -1, true, true);
spawnNPC(10769, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(10717, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(10761, new WorldTile(3127, 3437, 0), -1, true, true);
World.sendWorldMessage("<img=6><col=ff0000>[Boss Raid] Giants has just invaded North-West of home!", false);
} else if (raid == 4) {
killRaid();
spawnNPC(15581, new WorldTile(3126, 3431, 0), -1, true, true);
spawnNPC(999, new WorldTile(3126, 3440, 0), -1, true, true);
spawnNPC(998, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(1000, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(14550, new WorldTile(3127, 3437, 0), -1, true, true);
World.sendWorldMessage("<img=6><col=ff0000>[Boss Raid] The Party Demon has just invaded North-West of home!", false);
} else if (raid == 5) {
killRaid();
spawnNPC(8335, new WorldTile(3126, 3431, 0), -1, true, true);
spawnNPC(2712, new WorldTile(3126, 3440, 0), -1, true, true);
spawnNPC(2710, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(2711, new WorldTile(3127, 3434, 0), -1, true, true);
spawnNPC(2709, new WorldTile(3127, 3437, 0), -1, true, true);
World.sendWorldMessage("<img=6><col=ff0000>[Boss Raid] The Ultimate Mercenary Mage has just invaded North-West of home!", false);
} else {
World.sendWorldMessage("<img=6><col=ff0000>[Boss Raid] There are no current attacks on home!", false);
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, time);
}
public static void sinkHoles() {
final int time = Misc.random(3000000, 15000000);
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
SinkHoles.startEvent();
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, time);
}
public static void penguinHS() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player players : World.getPlayers()) {
if (players == null)
continue;
players.penguin = false;
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 8104)
continue;
n.sendDeath(n);
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 8105)
continue;
n.sendDeath(n);
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 8107)
continue;
n.sendDeath(n);
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 8108)
continue;
n.sendDeath(n);
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 8109)
continue;
n.sendDeath(n);
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 8110)
continue;
n.sendDeath(n);
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 14766)
continue;
n.sendDeath(n);
}
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 14415)
continue;
n.sendDeath(n);
}
PenguinEvent.startEvent();
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 2100000);
}
public static void crashedStar() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
star = 0;
World.sendWorldMessage("<img=6><col=ff0000>News: A Shooting Star has just struck Falador!", false);
World.spawnObject(new WorldObject(38660, 10, 0 , 3028, 3365, 0), true);
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 1200000);
}
public static void spawnStar() {
WorldTasksManager.schedule(new WorldTask() {
int loop;
@Override
public void run() {
if (loop == 1200) {
star = 0;
ShootingStar.spawnRandomStar();
}
loop++;
}
}, 0, 1);
}
public static void removeStarSprite(final Player player) {
WorldTasksManager.schedule(new WorldTask() {
int loop;
@Override
public void run() {
if (loop == 50) {
for (NPC n : World.getNPCs()) {
if (n == null || n.getId() != 8091)
continue;
n.sendDeath(n);
}
}
loop++;
}
}, 0, 1);
}
private static void addRestoreShopItemsTask() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
ShopsHandler.restoreShops();
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 30, TimeUnit.SECONDS);
}
/**
* Lobby Stuff
*/
private static final EntityList<Player> lobbyPlayers = new EntityList<Player>(Settings.PLAYERS_LIMIT);
public static final Player getLobbyPlayerByDisplayName(String username) {
String formatedUsername = Utils.formatPlayerNameForDisplay(username);
for (Player player : getLobbyPlayers()) {
if (player == null) {
continue;
}
if (player.getUsername().equalsIgnoreCase(formatedUsername)
|| player.getDisplayName().equalsIgnoreCase(formatedUsername)) {
return player;
}
}
return null;
}
public static final EntityList<Player> getLobbyPlayers() {
return lobbyPlayers;
}
public static final void addPlayer(Player player) {
players.add(player);
if (World.containsLobbyPlayer(player.getUsername())) {
World.removeLobbyPlayer(player);
AntiFlood.remove(player.getSession().getIP());
}
AntiFlood.add(player.getSession().getIP());
}
public static final void addLobbyPlayer(Player player) {
lobbyPlayers.add(player);
AntiFlood.add(player.getSession().getIP());
}
public static final boolean containsLobbyPlayer(String username) {
for (Player p2 : lobbyPlayers) {
if (p2 == null) {
continue;
}
if (p2.getUsername().equalsIgnoreCase(username)) {
return true;
}
}
return false;
}
public static void removeLobbyPlayer(Player player) {
for (Player p : lobbyPlayers) {
if (p.getUsername().equalsIgnoreCase(player.getUsername())) {
if (player.getCurrentFriendChat() != null) {
player.getCurrentFriendChat().leaveChat(player, true);
}
lobbyPlayers.remove(p);
}
}
AntiFlood.remove(player.getSession().getIP());
}
public static void removePlayer(Player player) {
for (Player p : players) {
if (p.getUsername().equalsIgnoreCase(player.getUsername())) {
players.remove(p);
}
}
AntiFlood.remove(player.getSession().getIP());
}
public static int checkWildernessPlayers() {
int pkers = 0;
for (Player pker : getPlayers()) {
if (pker == null) {
continue;
}
if (!Wilderness.isAtWild(pker)) {
continue;
} else {
pkers++;
}
}
return pkers;
}
private static final void addSummoningEffectTask() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null || player.getFamiliar() == null || player.isDead()
|| !player.hasFinished())
continue;
if (player.getFamiliar().getOriginalId() == 6814) {
player.heal(20);
player.setNextGraphics(new Graphics(1507));
}
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 15, TimeUnit.SECONDS);
}
private static final void addRestoreSpecialAttackTask() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null || player.isDead()
|| !player.isRunning())
continue;
player.getCombatDefinitions().restoreSpecialAttack();
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 30000);
}
private static boolean checkAgility;
public static Object deleteObject;
public static WorldTile lucienSpot = new WorldTile(3035, 3681, 0);
private static final void addTriviaBotTask() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
TriviaBot.Run();
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 400000);
}
private static final void addRestoreRunEnergyTask() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null
|| player.isDead()
|| !player.isRunning()
|| (checkAgility && player.getSkills()
.getLevel(Skills.AGILITY) < 70))
continue;
player.restoreRunEnergy();
}
checkAgility = !checkAgility;
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 1000);
}
private static final void addDrainPrayerTask() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null || player.isDead()
|| !player.isRunning())
continue;
player.getPrayer().processPrayerDrain();
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 600);
}
private static final void addRestoreHitPointsTask() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null || player.isDead()
|| !player.isRunning())
continue;
player.restoreHitPoints();
}
for (NPC npc : npcs) {
if (npc == null || npc.isDead() || npc.hasFinished())
continue;
npc.restoreHitPoints();
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 6000);
}
private static final void addRestoreSkillsTask() {
CoresManager.fastExecutor.schedule(new TimerTask() {
@Override
public void run() {
try {
for (Player player : getPlayers()) {
if (player == null || !player.isRunning())
continue;
int ammountTimes = player.getPrayer().usingPrayer(0, 8) ? 2
: 1;
if (player.isResting())
ammountTimes += 1;
boolean berserker = player.getPrayer()
.usingPrayer(1, 5);
for (int skill = 0; skill < 25; skill++) {
if (skill == Skills.SUMMONING)
continue;
for (int time = 0; time < ammountTimes; time++) {
int currentLevel = player.getSkills().getLevel(
skill);
int normalLevel = player.getSkills()
.getLevelForXp(skill);
if (currentLevel > normalLevel) {
if (skill == Skills.ATTACK
|| skill == Skills.STRENGTH
|| skill == Skills.DEFENCE
|| skill == Skills.RANGE
|| skill == Skills.MAGIC) {
if (berserker
&& Utils.getRandom(100) <= 15)
continue;
}
player.getSkills().set(skill,
currentLevel - 1);
} else if (currentLevel < normalLevel)
player.getSkills().set(skill,
currentLevel + 1);
else
break;
}
}
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, 0, 30000);
}
public static final Map<Integer, Region> getRegions() {
// synchronized (lock) {
return regions;
// }
}
public static final Region getRegion(int id) {
return getRegion(id, false);
}
public static final Region getRegion(int id, boolean load) {
// synchronized (lock) {
Region region = regions.get(id);
if (region == null) {
region = new Region(id);
regions.put(id, region);
}
if(load)
region.checkLoadMap();
return region;
// }
}
public static final void addNPC(NPC npc) {
npcs.add(npc);
}
public static final void removeNPC(NPC npc) {
npcs.remove(npc);
}
public static final NPC spawnNPC(int id, WorldTile tile,
int mapAreaNameHash, boolean canBeAttackFromOutOfArea,
boolean spawned) {
NPC n = null;
HunterNPC hunterNPCs = HunterNPC.forId(id);
if (hunterNPCs != null) {
if (id == hunterNPCs.getNpcId())
n = new ItemHunterNPC(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
}
else if (id >= 5533 && id <= 5558)
n = new Elemental(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 14301)
n = new Glacor(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea);
else if (id == 7134)
n = new Bork(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id >= 6026 && id <= 6045)
n = new Werewolf(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 9441)
n = new FlameVortex(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id >= 8832 && id <= 8834)
n = new LivingRock(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id >= 13465 && id <= 13481)
n = new Revenant(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 1158 || id == 1160)
n = new KalphiteQueen(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id >= 8528 && id <= 8532)
n = new Nomad(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6215 || id == 6211 || id == 3406 || id == 6216|| id == 6214 || id == 6215|| id == 6212 || id == 6219 || id == 6221 || id == 6218)
n = new GodwarsZammorakFaction(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6254 && id == 6259)
n = new GodwarsSaradominFaction(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6246 || id == 6236 || id == 6232 || id == 6240 || id == 6241 || id == 6242 || id == 6235 || id == 6234 || id == 6243 || id == 6236 || id == 6244 || id == 6237 || id == 6246 || id == 6238 || id == 6239 || id == 6230)
n = new GodwarsArmadylFaction(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6281 || id == 6282 || id == 6275 || id == 6279|| id == 9184 || id == 6268 || id == 6270 || id == 6274 || id == 6277 || id == 6276 || id == 6278)
n = new GodwarsBandosFaction(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6261 || id == 6263 || id == 6265)
n = GodWarsBosses.graardorMinions[(id - 6261) / 2] = new GodWarMinion(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6260)
n = new GeneralGraardor(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6222)
n = new KreeArra(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 6223 || id == 6225 || id == 6227)
n = GodWarsBosses.armadylMinions[(id - 6223) / 2] = new GodWarMinion(
id, tile, mapAreaNameHash, canBeAttackFromOutOfArea,
spawned);
else if (id == 6203)
n = new KrilTstsaroth(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 6204 || id == 6206 || id == 6208)
n = GodWarsBosses.zamorakMinions[(id - 6204) / 2] = new GodWarMinion(
id, tile, mapAreaNameHash, canBeAttackFromOutOfArea,
spawned);
else if (id == 50 || id == 2642)
n = new KingBlackDragon(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id >= 9462 && id <= 9467)
n = new Strykewyrm(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea);
else if (id == 6248 || id == 6250 || id == 6252)
n = GodWarsBosses.commanderMinions[(id - 6248) / 2] = new GodWarMinion(
id, tile, mapAreaNameHash, canBeAttackFromOutOfArea,
spawned);
else if (id == 6247)
n = new CommanderZilyana(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 8133)
n = new CorporealBeast(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 13447)
n = ZarosGodwars.nex = new Nex(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 13451)
n = ZarosGodwars.fumus = new NexMinion(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 13452)
n = ZarosGodwars.umbra = new NexMinion(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 13453)
n = ZarosGodwars.cruor = new NexMinion(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 13454)
n = ZarosGodwars.glacies = new NexMinion(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 14256)
n = new Lucien(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea,
spawned);
else if (id == 8335)
n = new MercenaryMage(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea,
spawned);
else if (id == 8349 || id == 8450 || id == 8451)
n = new TormentedDemon(id, tile, mapAreaNameHash,
canBeAttackFromOutOfArea, spawned);
else if (id == 15149)
n = new MasterOfFear(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else if (id == 14696)
n = new GanodermicBeast(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, spawned);
else
n = new NPC(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea,
spawned);
return n;
}
public static final NPC spawnNPC(int id, WorldTile tile,
int mapAreaNameHash, boolean canBeAttackFromOutOfArea) {
return spawnNPC(id, tile, mapAreaNameHash, canBeAttackFromOutOfArea, false);
}
/*
* check if the entity region changed because moved or teled then we update
* it
*/
public static final void updateEntityRegion(Entity entity) {
if (entity.hasFinished()) {
if (entity instanceof Player)
getRegion(entity.getLastRegionId()).removePlayerIndex(entity.getIndex());
else
getRegion(entity.getLastRegionId()).removeNPCIndex(entity.getIndex());
return;
}
int regionId = entity.getRegionId();
if (entity.getLastRegionId() != regionId) { // map region entity at
// changed
if (entity instanceof Player) {
if (entity.getLastRegionId() > 0)
getRegion(entity.getLastRegionId()).removePlayerIndex(
entity.getIndex());
Region region = getRegion(regionId);
region.addPlayerIndex(entity.getIndex());
Player player = (Player) entity;
int musicId = region.getMusicId();
if (musicId != -1)
player.getMusicsManager().checkMusic(musicId);
player.getControlerManager().moved();
if(player.hasStarted())
checkControlersAtMove(player);
} else {
if (entity.getLastRegionId() > 0)
getRegion(entity.getLastRegionId()).removeNPCIndex(
entity.getIndex());
getRegion(regionId).addNPCIndex(entity.getIndex());
}
entity.checkMultiArea();
entity.checkSmokeyArea();
entity.checkDesertArea();
entity.checkSinkArea();
entity.checkMorytaniaArea();
entity.setLastRegionId(regionId);
} else {
if (entity instanceof Player) {
Player player = (Player) entity;
player.getControlerManager().moved();
if(player.hasStarted())
checkControlersAtMove(player);
}
entity.checkMultiArea();
entity.checkSmokeyArea();
entity.checkDesertArea();
entity.checkSinkArea();
entity.checkMorytaniaArea();
}
}
private static void checkControlersAtMove(Player player) {
if (!(player.getControlerManager().getControler() instanceof RequestController)
&& RequestController.inWarRequest(player)) {
if (player.isPublicWildEnabled())
player.switchPvpModes();
player.getControlerManager().startControler("clan_wars_request");
} else if (DuelControler.isAtDuelArena(player)) {
if ( player.getControlerManager().getControler() instanceof StartTutorial
|| player.getControlerManager().getControler() instanceof Wilderness)
return;
player.getControlerManager().startControler("DuelControler");
} else if (FfaZone.inArea(player)) {
if (player.isPublicWildEnabled())
player.switchPvpModes();
player.getControlerManager().startControler("clan_wars_ffa");
} else if (player.isPublicWildEnabled()
&& player.getControlerManager().getControler() instanceof Wilderness == false) {
player.getControlerManager().startControler("Wilderness");
player.setCanPvp(true);
}
}
/*
* checks clip
*/
public static boolean canMoveNPC(int plane, int x, int y, int size) {
for (int tileX = x; tileX < x + size; tileX++)
for (int tileY = y; tileY < y + size; tileY++)
if (getMask(plane, tileX, tileY) != 0)
return false;
return true;
}
/*
* checks clip
*/
public static boolean isNotCliped(int plane, int x, int y, int size) {
for (int tileX = x; tileX < x + size; tileX++)
for (int tileY = y; tileY < y + size; tileY++)
if ((getMask(plane, tileX, tileY) & 2097152) != 0)
return false;
return true;
}
public static int getMask(int plane, int x, int y) {
WorldTile tile = new WorldTile(x, y, plane);
int regionId = tile.getRegionId();
Region region = getRegion(regionId);
if (region == null)
return -1;
int baseLocalX = x - ((regionId >> 8) * 64);
int baseLocalY = y - ((regionId & 0xff) * 64);
return region.getMask(tile.getPlane(), baseLocalX, baseLocalY);
}
public static void setMask(int plane, int x, int y, int mask) {
WorldTile tile = new WorldTile(x, y, plane);
int regionId = tile.getRegionId();
Region region = getRegion(regionId);
if (region == null)
return;
int baseLocalX = x - ((regionId >> 8) * 64);
int baseLocalY = y - ((regionId & 0xff) * 64);
region.setMask(tile.getPlane(), baseLocalX, baseLocalY, mask);
}
public static int getRotation(int plane, int x, int y) {
WorldTile tile = new WorldTile(x, y, plane);
int regionId = tile.getRegionId();
Region region = getRegion(regionId);
if (region == null)
return 0;
//int baseLocalX = x - ((regionId >> 8) * 64);
//int baseLocalY = y - ((regionId & 0xff) * 64);
//return region.getRotation(tile.getPlane(), baseLocalX, baseLocalY);
return 0;
}
private static int getClipedOnlyMask(int plane, int x, int y) {
WorldTile tile = new WorldTile(x, y, plane);
int regionId = tile.getRegionId();
Region region = getRegion(regionId);
if (region == null)
return -1;
int baseLocalX = x - ((regionId >> 8) * 64);
int baseLocalY = y - ((regionId & 0xff) * 64);
return region
.getMaskClipedOnly(tile.getPlane(), baseLocalX, baseLocalY);
}
public static final boolean checkProjectileStep(int plane, int x, int y,
int dir, int size) {
int xOffset = Utils.DIRECTION_DELTA_X[dir];
int yOffset = Utils.DIRECTION_DELTA_Y[dir];
/*
* int rotation = getRotation(plane,x+xOffset,y+yOffset); if(rotation !=
* 0) { dir += rotation; if(dir >= Utils.DIRECTION_DELTA_X.length) dir =
* dir - (Utils.DIRECTION_DELTA_X.length-1); xOffset =
* Utils.DIRECTION_DELTA_X[dir]; yOffset = Utils.DIRECTION_DELTA_Y[dir];
* }
*/
if (size == 1) {
int mask = getClipedOnlyMask(plane, x
+ Utils.DIRECTION_DELTA_X[dir], y
+ Utils.DIRECTION_DELTA_Y[dir]);
if (xOffset == -1 && yOffset == 0)
return (mask & 0x42240000) == 0;
if (xOffset == 1 && yOffset == 0)
return (mask & 0x60240000) == 0;
if (xOffset == 0 && yOffset == -1)
return (mask & 0x40a40000) == 0;
if (xOffset == 0 && yOffset == 1)
return (mask & 0x48240000) == 0;
if (xOffset == -1 && yOffset == -1) {
return (mask & 0x43a40000) == 0
&& (getClipedOnlyMask(plane, x - 1, y) & 0x42240000) == 0
&& (getClipedOnlyMask(plane, x, y - 1) & 0x40a40000) == 0;
}
if (xOffset == 1 && yOffset == -1) {
return (mask & 0x60e40000) == 0
&& (getClipedOnlyMask(plane, x + 1, y) & 0x60240000) == 0
&& (getClipedOnlyMask(plane, x, y - 1) & 0x40a40000) == 0;
}
if (xOffset == -1 && yOffset == 1) {
return (mask & 0x4e240000) == 0
&& (getClipedOnlyMask(plane, x - 1, y) & 0x42240000) == 0
&& (getClipedOnlyMask(plane, x, y + 1) & 0x48240000) == 0;
}
if (xOffset == 1 && yOffset == 1) {
return (mask & 0x78240000) == 0
&& (getClipedOnlyMask(plane, x + 1, y) & 0x60240000) == 0
&& (getClipedOnlyMask(plane, x, y + 1) & 0x48240000) == 0;
}
} else if (size == 2) {
if (xOffset == -1 && yOffset == 0)
return (getClipedOnlyMask(plane, x - 1, y) & 0x43a40000) == 0
&& (getClipedOnlyMask(plane, x - 1, y + 1) & 0x4e240000) == 0;
if (xOffset == 1 && yOffset == 0)
return (getClipedOnlyMask(plane, x + 2, y) & 0x60e40000) == 0
&& (getClipedOnlyMask(plane, x + 2, y + 1) & 0x78240000) == 0;
if (xOffset == 0 && yOffset == -1)
return (getClipedOnlyMask(plane, x, y - 1) & 0x43a40000) == 0
&& (getClipedOnlyMask(plane, x + 1, y - 1) & 0x60e40000) == 0;
if (xOffset == 0 && yOffset == 1)
return (getClipedOnlyMask(plane, x, y + 2) & 0x4e240000) == 0
&& (getClipedOnlyMask(plane, x + 1, y + 2) & 0x78240000) == 0;
if (xOffset == -1 && yOffset == -1)
return (getClipedOnlyMask(plane, x - 1, y) & 0x4fa40000) == 0
&& (getClipedOnlyMask(plane, x - 1, y - 1) & 0x43a40000) == 0
&& (getClipedOnlyMask(plane, x, y - 1) & 0x63e40000) == 0;
if (xOffset == 1 && yOffset == -1)
return (getClipedOnlyMask(plane, x + 1, y - 1) & 0x63e40000) == 0
&& (getClipedOnlyMask(plane, x + 2, y - 1) & 0x60e40000) == 0
&& (getClipedOnlyMask(plane, x + 2, y) & 0x78e40000) == 0;
if (xOffset == -1 && yOffset == 1)
return (getClipedOnlyMask(plane, x - 1, y + 1) & 0x4fa40000) == 0
&& (getClipedOnlyMask(plane, x - 1, y + 1) & 0x4e240000) == 0
&& (getClipedOnlyMask(plane, x, y + 2) & 0x7e240000) == 0;
if (xOffset == 1 && yOffset == 1)
return (getClipedOnlyMask(plane, x + 1, y + 2) & 0x7e240000) == 0
&& (getClipedOnlyMask(plane, x + 2, y + 2) & 0x78240000) == 0
&& (getClipedOnlyMask(plane, x + 1, y + 1) & 0x78e40000) == 0;
} else {
if (xOffset == -1 && yOffset == 0) {
if ((getClipedOnlyMask(plane, x - 1, y) & 0x43a40000) != 0
|| (getClipedOnlyMask(plane, x - 1, -1 + (y + size)) & 0x4e240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getClipedOnlyMask(plane, x - 1, y + sizeOffset) & 0x4fa40000) != 0)
return false;
} else if (xOffset == 1 && yOffset == 0) {
if ((getClipedOnlyMask(plane, x + size, y) & 0x60e40000) != 0
|| (getClipedOnlyMask(plane, x + size, y - (-size + 1)) & 0x78240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getClipedOnlyMask(plane, x + size, y + sizeOffset) & 0x78e40000) != 0)
return false;
} else if (xOffset == 0 && yOffset == -1) {
if ((getClipedOnlyMask(plane, x, y - 1) & 0x43a40000) != 0
|| (getClipedOnlyMask(plane, x + size - 1, y - 1) & 0x60e40000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getClipedOnlyMask(plane, x + sizeOffset, y - 1) & 0x63e40000) != 0)
return false;
} else if (xOffset == 0 && yOffset == 1) {
if ((getClipedOnlyMask(plane, x, y + size) & 0x4e240000) != 0
|| (getClipedOnlyMask(plane, x + (size - 1), y + size) & 0x78240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getClipedOnlyMask(plane, x + sizeOffset, y + size) & 0x7e240000) != 0)
return false;
} else if (xOffset == -1 && yOffset == -1) {
if ((getClipedOnlyMask(plane, x - 1, y - 1) & 0x43a40000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getClipedOnlyMask(plane, x - 1, y + (-1 + sizeOffset)) & 0x4fa40000) != 0
|| (getClipedOnlyMask(plane, sizeOffset - 1 + x,
y - 1) & 0x63e40000) != 0)
return false;
} else if (xOffset == 1 && yOffset == -1) {
if ((getClipedOnlyMask(plane, x + size, y - 1) & 0x60e40000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getClipedOnlyMask(plane, x + size, sizeOffset
+ (-1 + y)) & 0x78e40000) != 0
|| (getClipedOnlyMask(plane, x + sizeOffset, y - 1) & 0x63e40000) != 0)
return false;
} else if (xOffset == -1 && yOffset == 1) {
if ((getClipedOnlyMask(plane, x - 1, y + size) & 0x4e240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getClipedOnlyMask(plane, x - 1, y + sizeOffset) & 0x4fa40000) != 0
|| (getClipedOnlyMask(plane, -1 + (x + sizeOffset),
y + size) & 0x7e240000) != 0)
return false;
} else if (xOffset == 1 && yOffset == 1) {
if ((getClipedOnlyMask(plane, x + size, y + size) & 0x78240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getClipedOnlyMask(plane, x + sizeOffset, y + size) & 0x7e240000) != 0
|| (getClipedOnlyMask(plane, x + size, y
+ sizeOffset) & 0x78e40000) != 0)
return false;
}
}
return true;
}
public static final boolean checkWalkStep(int plane, int x, int y, int dir,
int size) {
int xOffset = Utils.DIRECTION_DELTA_X[dir];
int yOffset = Utils.DIRECTION_DELTA_Y[dir];
int rotation = getRotation(plane, x + xOffset, y + yOffset);
if (rotation != 0) {
for (int rotate = 0; rotate < (4 - rotation); rotate++) {
int fakeChunckX = xOffset;
int fakeChunckY = yOffset;
xOffset = fakeChunckY;
yOffset = 0 - fakeChunckX;
}
}
if (size == 1) {
int mask = getMask(plane, x + Utils.DIRECTION_DELTA_X[dir], y
+ Utils.DIRECTION_DELTA_Y[dir]);
if (xOffset == -1 && yOffset == 0)
return (mask & 0x42240000) == 0;
if (xOffset == 1 && yOffset == 0)
return (mask & 0x60240000) == 0;
if (xOffset == 0 && yOffset == -1)
return (mask & 0x40a40000) == 0;
if (xOffset == 0 && yOffset == 1)
return (mask & 0x48240000) == 0;
if (xOffset == -1 && yOffset == -1) {
return (mask & 0x43a40000) == 0
&& (getMask(plane, x - 1, y) & 0x42240000) == 0
&& (getMask(plane, x, y - 1) & 0x40a40000) == 0;
}
if (xOffset == 1 && yOffset == -1) {
return (mask & 0x60e40000) == 0
&& (getMask(plane, x + 1, y) & 0x60240000) == 0
&& (getMask(plane, x, y - 1) & 0x40a40000) == 0;
}
if (xOffset == -1 && yOffset == 1) {
return (mask & 0x4e240000) == 0
&& (getMask(plane, x - 1, y) & 0x42240000) == 0
&& (getMask(plane, x, y + 1) & 0x48240000) == 0;
}
if (xOffset == 1 && yOffset == 1) {
return (mask & 0x78240000) == 0
&& (getMask(plane, x + 1, y) & 0x60240000) == 0
&& (getMask(plane, x, y + 1) & 0x48240000) == 0;
}
} else if (size == 2) {
if (xOffset == -1 && yOffset == 0)
return (getMask(plane, x - 1, y) & 0x43a40000) == 0
&& (getMask(plane, x - 1, y + 1) & 0x4e240000) == 0;
if (xOffset == 1 && yOffset == 0)
return (getMask(plane, x + 2, y) & 0x60e40000) == 0
&& (getMask(plane, x + 2, y + 1) & 0x78240000) == 0;
if (xOffset == 0 && yOffset == -1)
return (getMask(plane, x, y - 1) & 0x43a40000) == 0
&& (getMask(plane, x + 1, y - 1) & 0x60e40000) == 0;
if (xOffset == 0 && yOffset == 1)
return (getMask(plane, x, y + 2) & 0x4e240000) == 0
&& (getMask(plane, x + 1, y + 2) & 0x78240000) == 0;
if (xOffset == -1 && yOffset == -1)
return (getMask(plane, x - 1, y) & 0x4fa40000) == 0
&& (getMask(plane, x - 1, y - 1) & 0x43a40000) == 0
&& (getMask(plane, x, y - 1) & 0x63e40000) == 0;
if (xOffset == 1 && yOffset == -1)
return (getMask(plane, x + 1, y - 1) & 0x63e40000) == 0
&& (getMask(plane, x + 2, y - 1) & 0x60e40000) == 0
&& (getMask(plane, x + 2, y) & 0x78e40000) == 0;
if (xOffset == -1 && yOffset == 1)
return (getMask(plane, x - 1, y + 1) & 0x4fa40000) == 0
&& (getMask(plane, x - 1, y + 1) & 0x4e240000) == 0
&& (getMask(plane, x, y + 2) & 0x7e240000) == 0;
if (xOffset == 1 && yOffset == 1)
return (getMask(plane, x + 1, y + 2) & 0x7e240000) == 0
&& (getMask(plane, x + 2, y + 2) & 0x78240000) == 0
&& (getMask(plane, x + 1, y + 1) & 0x78e40000) == 0;
} else {
if (xOffset == -1 && yOffset == 0) {
if ((getMask(plane, x - 1, y) & 0x43a40000) != 0
|| (getMask(plane, x - 1, -1 + (y + size)) & 0x4e240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getMask(plane, x - 1, y + sizeOffset) & 0x4fa40000) != 0)
return false;
} else if (xOffset == 1 && yOffset == 0) {
if ((getMask(plane, x + size, y) & 0x60e40000) != 0
|| (getMask(plane, x + size, y - (-size + 1)) & 0x78240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getMask(plane, x + size, y + sizeOffset) & 0x78e40000) != 0)
return false;
} else if (xOffset == 0 && yOffset == -1) {
if ((getMask(plane, x, y - 1) & 0x43a40000) != 0
|| (getMask(plane, x + size - 1, y - 1) & 0x60e40000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getMask(plane, x + sizeOffset, y - 1) & 0x63e40000) != 0)
return false;
} else if (xOffset == 0 && yOffset == 1) {
if ((getMask(plane, x, y + size) & 0x4e240000) != 0
|| (getMask(plane, x + (size - 1), y + size) & 0x78240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size - 1; sizeOffset++)
if ((getMask(plane, x + sizeOffset, y + size) & 0x7e240000) != 0)
return false;
} else if (xOffset == -1 && yOffset == -1) {
if ((getMask(plane, x - 1, y - 1) & 0x43a40000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getMask(plane, x - 1, y + (-1 + sizeOffset)) & 0x4fa40000) != 0
|| (getMask(plane, sizeOffset - 1 + x, y - 1) & 0x63e40000) != 0)
return false;
} else if (xOffset == 1 && yOffset == -1) {
if ((getMask(plane, x + size, y - 1) & 0x60e40000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getMask(plane, x + size, sizeOffset + (-1 + y)) & 0x78e40000) != 0
|| (getMask(plane, x + sizeOffset, y - 1) & 0x63e40000) != 0)
return false;
} else if (xOffset == -1 && yOffset == 1) {
if ((getMask(plane, x - 1, y + size) & 0x4e240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getMask(plane, x - 1, y + sizeOffset) & 0x4fa40000) != 0
|| (getMask(plane, -1 + (x + sizeOffset), y + size) & 0x7e240000) != 0)
return false;
} else if (xOffset == 1 && yOffset == 1) {
if ((getMask(plane, x + size, y + size) & 0x78240000) != 0)
return false;
for (int sizeOffset = 1; sizeOffset < size; sizeOffset++)
if ((getMask(plane, x + sizeOffset, y + size) & 0x7e240000) != 0
|| (getMask(plane, x + size, y + sizeOffset) & 0x78e40000) != 0)
return false;
}
}
return true;
}
public static final boolean containsPlayer(String username) {
for (Player p2 : players) {
if (p2 == null)
continue;
if (p2.getUsername().equals(username))
return true;
}
return false;
}
public static Player getPlayer(String username) {
for (Player player : getPlayers()) {
if (player == null)
continue;
if (player.getUsername().equals(username))
return player;
}
return null;
}
public static final Player getPlayerByDisplayName(String username) {
String formatedUsername = Utils.formatPlayerNameForDisplay(username);
for (Player player : getPlayers()) {
if (player == null)
continue;
if (player.getUsername().equalsIgnoreCase(formatedUsername)
|| player.getDisplayName().equalsIgnoreCase(formatedUsername))
return player;
}
return null;
}
public static final EntityList<Player> getPlayers() {
return players;
}
public static final EntityList<NPC> getNPCs() {
return npcs;
}
private World() {
}
public static final void safeShutdown(final boolean restart, int delay) {
if (exiting_start != 0)
return;
exiting_start = Utils.currentTimeMillis();
exiting_delay = delay;
for (Player player : World.getPlayers()) {
if (player == null || !player.hasStarted() || player.hasFinished())
continue;
player.getPackets().sendSystemUpdate(delay);
}
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
for (Player player : World.getPlayers()) {
if (player == null || !player.hasStarted())
continue;
player.realFinish();
player.getControlerManager().removeControlerWithoutCheck();
if (player.getControlerManager().getControler() instanceof RuneDungGame) {
player.getControlerManager().forceStop();
player.getControlerManager().removeControlerWithoutCheck();
player.lock(10);
for (Item item : player.getInventory().getItems().toArray()) {
if (item == null) continue;
player.getInventory().deleteItem(item);
player.setNextWorldTile(new WorldTile(3450, 3718, 0)); }
}
IPBanL.save();
IPMute.save();
PkRank.save();
KillStreakRank.save();
}
//Offers.saveOffers();
if (restart)
Launcher.restart();
else
Launcher.shutdown();
} catch (Throwable e) {
Logger.handle(e);
}
}
}, delay, TimeUnit.SECONDS);
}
/*
* by default doesnt changeClipData
*/
public static final void spawnTemporaryObject(final WorldObject object,
long time) {
spawnTemporaryObject(object, time, false);
}
public static final void spawnTemporaryObject(final WorldObject object,
long time, final boolean clip) {
spawnObject(object);
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
if (!World.isSpawnedObject(object))
return;
removeObject(object);
}
catch (Throwable e) {
Logger.handle(e);
}
}
}, time, TimeUnit.MILLISECONDS);
}
public static final boolean isSpawnedObject(WorldObject object) {
return getRegion(object.getRegionId()).getSpawnedObjects().contains(object);
}
public static final boolean removeTemporaryObject(final WorldObject object,
long time, final boolean clip) {
removeObject(object);
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
spawnObject(object);
}
catch (Throwable e) {
Logger.handle(e);
}
}
}, time, TimeUnit.MILLISECONDS);
return true;
}
public static final void removeObject(WorldObject object, boolean clip) {
getRegion(object.getRegionId()).removeObject(object, object.getPlane(), object.getXInRegion(), object.getYInRegion());
}
public static final WorldObject getObject(WorldTile tile) {
return getRegion(tile.getRegionId()).getStandartObject(tile.getPlane(), tile.getXInRegion(), tile.getYInRegion());
}
public static final WorldObject getObject(WorldTile tile, int type) {
return getRegion(tile.getRegionId()).getObjectWithType(tile.getPlane(), tile.getXInRegion(), tile.getYInRegion(), type);
}
public static final void spawnObject(WorldObject object, boolean clip) {
getRegion(object.getRegionId()).spawnObject(object, object.getPlane(), object.getXInRegion(), object.getYInRegion(), false);
}
public static final void spawnObjectSpawns(WorldObject object, boolean clip) {
getRegion(object.getRegionId()).spawnObject(object, object.getPlane(), object.getXInRegion(), object.getYInRegion(), true);
}
/* public static final void addGroundItem(final Item item, final WorldTile tile, final Player owner/*
* null
* for
* default
, boolean invisible, long hiddenTime/*
* default
* 3
* minutes
) {
addGroundItem(item, tile, owner, invisible, hiddenTime, 2, 150);
}
public static final FloorItem addGroundItem(final Item item, final WorldTile tile, final Player owner/*
* null
* for
* default
, boolean invisible, long hiddenTime/*
* default
* 3
* minutes
, int type) {
return addGroundItem(item, tile, owner, invisible, hiddenTime, type, 150);
}*/
/* public static final FloorItem addGroundItem(final Item item, final WorldTile tile, final Player owner, boolean invisible, long hiddenTime/*
, int type, final int publicTime) {
if (type != 2) {
if ((type == 0 && !ItemConstants.isTradeable(item)) || type == 1 && ItemConstants.isDestroy(item)) {
int price = item.getDefinitions().getValue();
if (price <= 0)
return null;
item.setId(995);
item.setAmount(price);
}
}
final FloorItem floorItem = new FloorItem(item, tile, owner, owner != null, invisible);
final Region region = getRegion(tile.getRegionId());
region.getGroundItemsSafe().add(floorItem);
if (invisible) {
if (owner != null)
owner.getPackets().sendGroundItem(floorItem);
// becomes visible after x time
if (hiddenTime != -1) {
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
turnPublic(floorItem, publicTime);
}
catch (Throwable e) {
Logger.handle(e);
}
}
}, hiddenTime, TimeUnit.SECONDS);
}
} else {
// visible
int regionId = tile.getRegionId();
for (Player player : players) {
if (player == null || !player.hasStarted() || player.hasFinished() || player.getPlane() != tile.getPlane() || !player.getMapRegionsIds().contains(regionId))
continue;
player.getPackets().sendGroundItem(floorItem);
}
// disapears after this time
if (publicTime != -1)
removeGroundItem(floorItem, publicTime);
}
return floorItem;
}*/
/* public static final void turnPublic(FloorItem floorItem, int publicTime) {
if (!floorItem.isInvisible())
return;
int regionId = floorItem.getTile().getRegionId();
final Region region = getRegion(regionId);
if (!region.getGroundItemsSafe().contains(floorItem))
return;
//Player realOwner = floorItem.hasOwner() ? World.getPlayer(floorItem.getOwner()) : null;
if (!ItemConstants.isTradeable(floorItem)) {
region.getGroundItemsSafe().remove(floorItem);
if (realOwner != null) {
if (realOwner.getMapRegionsIds().contains(regionId) && realOwner.getPlane() == floorItem.getTile().getPlane())
realOwner.getPackets().sendRemoveGroundItem(floorItem);
}
return;
}
floorItem.setInvisible(false);
for (Player player : players) {
// if (player == null || player == realOwner || !player.hasStarted() || player.hasFinished() || player.getPlane() != floorItem.getTile().getPlane() || !player.getMapRegionsIds().contains(regionId))
//continue;
player.getPackets().sendGroundItem(floorItem);
}
// disapears after this time
if (publicTime != -1)
removeGroundItem(floorItem, publicTime);
}*/
public static final void addGroundItem(final Item item, final WorldTile tile) {
final FloorItem floorItem = new FloorItem(item, tile, null, false,
false);
final Region region = getRegion(tile.getRegionId());
region.forceGetFloorItems().add(floorItem);
int regionId = tile.getRegionId();
for (Player player : players) {
if (player == null || !player.hasStarted() || player.hasFinished()
|| player.getPlane() != tile.getPlane()
|| !player.getMapRegionsIds().contains(regionId))
continue;
player.getPackets().sendGroundItem(floorItem);
}
}
public static final void addGroundItem(final Item item, final WorldTile tile, final Player owner, final boolean underGrave, long hiddenTime, boolean invisible) {
addGroundItem(item, tile, owner, underGrave, hiddenTime, invisible, false, 180);
}
public static final void addGroundItem(final Item item, final WorldTile tile, final Player owner, final boolean underGrave, long hiddenTime, boolean invisible, boolean intoGold) {
addGroundItem(item, tile, owner, underGrave, hiddenTime, invisible, intoGold, 180);
}
public static final void addGroundItem(final Item item,
final WorldTile tile, final Player owner/* null for default */,
final boolean underGrave, long hiddenTime/* default 3minutes */,
boolean invisible, boolean intoGold, final int publicTime) {
final FloorItem floorItem = new FloorItem(item, tile, owner,
owner == null ? false : underGrave, invisible);
final Region region = getRegion(tile.getRegionId());
region.forceGetFloorItems().add(floorItem);
if (invisible && hiddenTime != -1) {
if (owner != null)
owner.getPackets().sendGroundItem(floorItem);
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
if (!region.forceGetFloorItems().contains(floorItem))
return;
int regionId = tile.getRegionId();
if (underGrave || !ItemConstants.isTradeable(floorItem) || item.getName().contains("Leighton")) {
region.forceGetFloorItems().remove(floorItem);
if(owner != null) {
if (owner.getMapRegionsIds().contains(regionId) && owner.getPlane() == tile.getPlane())
owner.getPackets().sendRemoveGroundItem(floorItem);
}
return;
}
if (owner.getRights() ==2); {
region.forceGetFloorItems().remove(floorItem);
owner.sendMessage("Administrators are not allowed to drop items in-game.");
} //done :'3
floorItem.setInvisible(false);
for (Player player : players) {
if (player == null
|| player == owner
|| !player.hasStarted()
|| player.hasFinished()
|| player.getPlane() != tile.getPlane()
|| !player.getMapRegionsIds().contains(
regionId))
continue;
player.getPackets().sendGroundItem(floorItem);
}
removeGroundItem(floorItem, publicTime);
} catch (Throwable e) {
Logger.handle(e);
}
}
}, hiddenTime, TimeUnit.SECONDS);
return;
}
int regionId = tile.getRegionId();
for (Player player : players) {
if (player == null || !player.hasStarted() || player.hasFinished()
|| player.getPlane() != tile.getPlane()
|| !player.getMapRegionsIds().contains(regionId))
continue;
player.getPackets().sendGroundItem(floorItem);
}
removeGroundItem(floorItem, publicTime);
}
@Deprecated
public static final void addGroundItemForever(Item item, final WorldTile tile) {
int regionId = tile.getRegionId();
final FloorItem floorItem = new FloorItem(item, tile, true);
final Region region = getRegion(tile.getRegionId());
region.getGroundItemsSafe().add(floorItem);
for (Player player : players) {
if (player == null || !player.hasStarted() || player.hasFinished() || player.getPlane() != floorItem.getTile().getPlane() || !player.getMapRegionsIds().contains(regionId))
continue;
player.getPackets().sendGroundItem(floorItem);
}
}
public static final void updateGroundItem(Item item, final WorldTile tile, final Player owner) {
final FloorItem floorItem = World.getRegion(tile.getRegionId()).getGroundItem(item.getId(), tile, owner);
if (floorItem == null) {
addGroundItem(item, tile, owner, true, 360);
return;
}
floorItem.setAmount(floorItem.getAmount() + item.getAmount());
owner.getPackets().sendRemoveGroundItem(floorItem);
owner.getPackets().sendGroundItem(floorItem);
}
private static final void removeGroundItem(final FloorItem floorItem, long publicTime) {
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
int regionId = floorItem.getTile().getRegionId();
Region region = getRegion(regionId);
if (!region.getGroundItemsSafe().contains(floorItem))
return;
region.getGroundItemsSafe().remove(floorItem);
for (Player player : World.getPlayers()) {
if (player == null || !player.hasStarted() || player.hasFinished() || player.getPlane() != floorItem.getTile().getPlane() || !player.getMapRegionsIds().contains(regionId))
continue;
player.getPackets().sendRemoveGroundItem(floorItem);
}
}
catch (Throwable e) {
Logger.handle(e);
}
}
}, publicTime, TimeUnit.SECONDS);
}
public static final boolean removeGroundItem(Player player, FloorItem floorItem) {
return removeGroundItem(player, floorItem, true);
}
public static final boolean removeGroundItem(Player player, final FloorItem floorItem, boolean add) {
int regionId = floorItem.getTile().getRegionId();
Region region = getRegion(regionId);
if (!region.getGroundItemsSafe().contains(floorItem))
return false;
if (player.getInventory().getFreeSlots() == 0 && (!floorItem.getDefinitions().isStackable() || !player.getInventory().containsItem(floorItem.getId(), 1))) {
player.getPackets().sendGameMessage("Not enough space in your inventory.");
return false;
}
region.getGroundItemsSafe().remove(floorItem);
if (add)
player.getInventory().addItemMoneyPouch(new Item(floorItem.getId(), floorItem.getAmount()));
if (floorItem.isInvisible()) {
player.getPackets().sendRemoveGroundItem(floorItem);
return true;
} else {
for (Player p2 : World.getPlayers()) {
if (p2 == null || !p2.hasStarted() || p2.hasFinished() || p2.getPlane() != floorItem.getTile().getPlane() || !p2.getMapRegionsIds().contains(regionId))
continue;
p2.getPackets().sendRemoveGroundItem(floorItem);
}
if (floorItem.isForever()) {
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
addGroundItemForever(floorItem, floorItem.getTile());
}
catch (Throwable e) {
Logger.handle(e);
}
}
}, 60, TimeUnit.SECONDS);
}
return true;
}
}
public static final void sendObjectAnimation(WorldObject object, Animation animation) {
sendObjectAnimation(null, object, animation);
}
public static final void sendObjectAnimation(Entity creator, WorldObject object, Animation animation) {
if (creator == null) {
for (Player player : World.getPlayers()) {
if (player == null || !player.hasStarted()
|| player.hasFinished() || !player.withinDistance(object))
continue;
player.getPackets().sendObjectAnimation(object, animation);
}
} else {
for (int regionId : creator.getMapRegionsIds()) {
List<Integer> playersIndexes = getRegion(regionId)
.getPlayerIndexes();
if (playersIndexes == null)
continue;
for (Integer playerIndex : playersIndexes) {
Player player = players.get(playerIndex);
if (player == null || !player.hasStarted()
|| player.hasFinished()
|| !player.withinDistance(object))
continue;
player.getPackets().sendObjectAnimation(object, animation);
}
}
}
}
public static final void sendGraphics(Entity creator, Graphics graphics,
WorldTile tile) {
if (creator == null) {
for (Player player : World.getPlayers()) {
if (player == null || !player.hasStarted()
|| player.hasFinished() || !player.withinDistance(tile))
continue;
player.getPackets().sendGraphics(graphics, tile);
}
} else {
for (int regionId : creator.getMapRegionsIds()) {
List<Integer> playersIndexes = getRegion(regionId)
.getPlayerIndexes();
if (playersIndexes == null)
continue;
for (Integer playerIndex : playersIndexes) {
Player player = players.get(playerIndex);
if (player == null || !player.hasStarted()
|| player.hasFinished()
|| !player.withinDistance(tile))
continue;
player.getPackets().sendGraphics(graphics, tile);
}
}
}
}
public static final void sendProjectile(Entity shooter,
WorldTile startTile, WorldTile receiver, int gfxId,
int startHeight, int endHeight, int speed, int delay, int curve,
int startDistanceOffset) {
for (int regionId : shooter.getMapRegionsIds()) {
List<Integer> playersIndexes = getRegion(regionId)
.getPlayerIndexes();
if (playersIndexes == null)
continue;
for (Integer playerIndex : playersIndexes) {
Player player = players.get(playerIndex);
if (player == null
|| !player.hasStarted()
|| player.hasFinished()
|| (!player.withinDistance(shooter) && !player
.withinDistance(receiver)))
continue;
player.getPackets().sendProjectile(null, startTile, receiver,
gfxId, startHeight, endHeight, speed, delay, curve,
startDistanceOffset, 1);
}
}
}
public static final void sendProjectile(WorldTile shooter, Entity receiver,
int gfxId, int startHeight, int endHeight, int speed, int delay,
int curve, int startDistanceOffset) {
for (int regionId : receiver.getMapRegionsIds()) {
List<Integer> playersIndexes = getRegion(regionId)
.getPlayerIndexes();
if (playersIndexes == null)
continue;
for (Integer playerIndex : playersIndexes) {
Player player = players.get(playerIndex);
if (player == null
|| !player.hasStarted()
|| player.hasFinished()
|| (!player.withinDistance(shooter) && !player
.withinDistance(receiver)))
continue;
player.getPackets().sendProjectile(null, shooter, receiver,
gfxId, startHeight, endHeight, speed, delay, curve,
startDistanceOffset, 1);
}
}
}
public static final void sendProjectile(Entity shooter, WorldTile receiver,
int gfxId, int startHeight, int endHeight, int speed, int delay,
int curve, int startDistanceOffset) {
for (int regionId : shooter.getMapRegionsIds()) {
List<Integer> playersIndexes = getRegion(regionId)
.getPlayerIndexes();
if (playersIndexes == null)
continue;
for (Integer playerIndex : playersIndexes) {
Player player = players.get(playerIndex);
if (player == null
|| !player.hasStarted()
|| player.hasFinished()
|| (!player.withinDistance(shooter) && !player
.withinDistance(receiver)))
continue;
player.getPackets().sendProjectile(null, shooter, receiver,
gfxId, startHeight, endHeight, speed, delay, curve,
startDistanceOffset, shooter.getSize());
}
}
}
public static final void sendProjectile(Entity shooter, Entity receiver,
int gfxId, int startHeight, int endHeight, int speed, int delay,
int curve, int startDistanceOffset) {
for (int regionId : shooter.getMapRegionsIds()) {
List<Integer> playersIndexes = getRegion(regionId)
.getPlayerIndexes();
if (playersIndexes == null)
continue;
for (Integer playerIndex : playersIndexes) {
Player player = players.get(playerIndex);
if (player == null
|| !player.hasStarted()
|| player.hasFinished()
|| (!player.withinDistance(shooter) && !player
.withinDistance(receiver)))
continue;
int size = shooter.getSize();
player.getPackets().sendProjectile(
receiver,
new WorldTile(shooter.getCoordFaceX(size), shooter
.getCoordFaceY(size), shooter.getPlane()),
receiver, gfxId, startHeight, endHeight, speed, delay,
curve, startDistanceOffset, size);
}
}
}
public static final boolean isMultiArea(WorldTile tile) {
int destX = tile.getX();
int destY = tile.getY();
int regionId = tile.getRegionId();
return (destX >= 3462 && destX <= 3511 && destY >= 9481 && destY <= 9521 && tile.getPlane() == 0) //kalphite queen lair
|| (destX >= 4540 && destX <= 4799 && destY >= 5052 && destY <= 5183 && tile.getPlane() == 0) // thzaar city
|| (destX >= 1721 && destX <= 1791 && destY >= 5123 && destY <= 5249) // mole
|| (destX >= 3029 && destX <= 3374 && destY >= 3759 && destY <= 3903)//wild
|| (destX >= 2250 && destX <= 2280 && destY >= 4670 && destY <= 4720)
|| (destX >= 1363 && destX <= 1385 && destY >= 6613 && destY <= 6635)//Blink
|| (destX >= 2517 && destX <= 2538 && destY >= 5227 && destY <= 5243)//Yk
|| (destX >= 3198 && destX <= 3380 && destY >= 3904 && destY <= 3970)
|| (destX >= 3191 && destX <= 3326 && destY >= 3510 && destY <= 3759)
|| (destX >= 2987 && destX <= 3006 && destY >= 3912 && destY <= 3937)
|| (destX >= 2894 && destX <= 2948 && destY >= 4423 && destY <= 4479)
|| (destX >= 2245 && destX <= 2295 && destY >= 4675 && destY <= 4720)
|| (destX >= 2450 && destX <= 3520 && destY >= 9450 && destY <= 9550)
|| (destX >= 3006 && destX <= 3071 && destY >= 3602 && destY <= 3710)
|| (destX >= 3134 && destX <= 3192 && destY >= 3519 && destY <= 3646)
|| (destX >= 2815 && destX <= 2966 && destY >= 5240 && destY <= 5375)//wild
|| (destX >= 2840 && destX <= 2950 && destY >= 5190 && destY <= 5230) // godwars
|| (destX >= 3547 && destX <= 3555 && destY >= 9690 && destY <= 9699) // zaros
|| (destX >= 3834 && destY >= 4758 && destX <= 3814 && destY <= 4782)
|| (destX >= 3814 && destY >= 4782 && destX <= 3834 && destY <= 4758)
|| (destX >= 3841 && destY >= 4781 && destX <= 3814 && destY <= 4758)
|| (destX >= 3814 && destY >= 4758 && destX <= 3841 && destY <= 4781)
// godwars
|| KingBlackDragon.atKBD(tile) // King Black Dragon lair
|| TormentedDemon.atTD(tile) // Tormented demon's area
|| Bork.atBork(tile) // Bork's area
|| (destX >= 2970 && destX <= 3000 && destY >= 4365 && destY <= 4400)// corp
|| (destX >= 3195 && destX <= 3327 && destY >= 3520
&& destY <= 3970 || (destX >= 2376 && 5127 >= destY
&& destX <= 2422 && 5168 <= destY))
|| (destX >= 2374 && destY >= 5129 && destX <= 2424 && destY <= 5168) // pits
|| (destX >= 2864 && destY >= 2981 && destX <= 2878 && destY <= 2995) // boss raids
|| (destX >= 2622 && destY >= 5696 && destX <= 2573 && destY <= 5752) // torms
|| (destX >= 2368 && destY >= 3072 && destX <= 2431 && destY <= 3135) // castlewars
|| (destX >= 3780 && destY >= 3542 && destX <= 3834 && destY <= 3578) // Sunfreet
// out
|| (destX >= 2365 && destY >= 9470 && destX <= 2436 && destY <= 9532) // castlewars
|| (destX >= 2948 && destY >= 5537 && destX <= 3071 && destY <= 5631)
|| (destX >= 226 && destY >= 5408 && destX <= 187 && destY <= 5372) // pits
|| (destX >= 187 && destY >= 5372 && destX <= 226 && destY <= 5408) // pits
|| (destX >= 228 && destY >= 5370 && destX <= 186 && destY <= 5415) // pits
|| (destX >= 186 && destY >= 5415 && destX <= 228 && destY <= 5370) // pits
|| (destX >= 2756 && destY >= 5537 && destX <= 2879 && destY <= 5631) //Safe ffa
|| (destX >= 1490 && destX <= 1515 && destY >= 4696 && destY <= 4714) // chaos dwarf battlefield
|| (destX >= 3333 && destX <= 3383 && destY >= 9345 && destY <= 9450) //Smokey well 1
|| (destX >= 3072 && destX <= 3136 && destY >= 4287 && destY <= 4416) //Smokey well 2
|| (destX >= 3140 && destX <= 3331 && destY >= 5441 && destY <= 5568) //CHAOS TUNNELS
|| (destX >= 1986 && destX <= 2045 && destY >= 4162 && destY <= 4286) || regionId == 16729 //glacors
|| (destX >= 3261 && destX <= 3329 && destY >= 4287 && destY <= 4416) //smokey well 3
|| (destX >= 2483 && destX <= 2499 && destY >= 2847 && destY <= 2861) //Boss Raids
|| (tile.getX() >= 3011 && tile.getX() <= 3132 && tile.getY() >= 10052 && tile.getY() <= 10175
&& (tile.getY() >= 10066 || tile.getX() >= 3094)) //fortihrny dungeon
;
// in
// multi
}
public static boolean isRestrictedCannon(WorldTile tile) {
int destX = tile.getX();
int destY = tile.getY();
return ((destX >= 2250 && destX <= 2302 && destY >= 4673 && destY <= 4725) //King Black Dragon
|| (destX >= 3082 && destX <= 3122 && destY >= 5512 && destY <= 5560) //Bork
|| (destX >= 3462 && destX <= 3512 && destY >= 9473 && destY <= 9525) //Kalphite Queen
|| (destX >= 2894 && destX <= 2948 && destY >= 4423 && destY <= 4479) //Dagganoth Kings
|| (destX >= 2574 && destX <= 2634 && destY >= 5692 && destY <= 5759) //Tormented Demons
|| (destX >= 2969 && destX <= 3005 && destY >= 4357 && destY <= 4405) //Corporeal Beast
|| (destX >= 2898 && destX <= 2946 && destY >= 5181 && destY <= 5226) //Nex
|| (destX >= 2822 && destX <= 2936 && destY >= 5238 && destY <= 5379) //God Wars
|| (destX >= 2943 && destX <= 3561 && destY >= 3521 && destY <= 4052) //Wilderness
|| (destX >= 2518 && destX <= 2543 && destY >= 5226 && destY <= 5241) //Yklagor
|| (destX >= 2844 && destX <= 2868 && destY >= 9625 && destY <= 9650) //Sunfreet
|| (destX >= 1365 && destX <= 1387 && destY >= 6613 && destY <= 6636)) //Blink
;
}
public static final boolean isMorytaniaArea(WorldTile tile) {
int destX = tile.getX();
int destY = tile.getY();
return ((destX >= 3423 && destX <= 3463 && destY >= 3205 && destY <= 3268) //haunted mine
|| (destX >= 3464 && destX <= 3722 && destY >= 3160 && destY <= 3602) //Rest of mory
|| (destX >= 3413 && destX <= 3463 && destY >= 3206 && destY <= 3346) //Snail maze
|| (destX >= 3399 && destX <= 3463 && destY >= 3347 && destY <= 3450) //Part of swamp
|| (destX >= 3413 && destX <= 3463 && destY >= 3451 && destY <= 3467) //Part of swamp
|| (destX >= 3420 && destX <= 3463 && destY >= 3468 && destY <= 3607) //Part of swamp
|| (destX >= 3398 && destX <= 3463 && destY >= 3508 && destY <= 3607) //Part of upper part
|| (destX >= 3409 && destX <= 3419 && destY >= 3499 && destY <= 3507) //Part of upper part
|| (destX >= 3397 && destX <= 3660 && destY >= 9607 && destY <= 9852) //morytania underground
|| (destX >= 3466 && destX <= 3588 && destY >= 9857 && destY <= 9978) //werewolf agil, experiments
|| (destX >= 3643 && destX <= 3728 && destY >= 9847 && destY <= 9935) //Ectofun
|| (destX >= 2254 && destX <= 2287 && destY >= 5142 && destY <= 5162) //Drakan tomb
|| (destX >= 2686 && destX <= 2818 && destY >= 4416 && destY <= 4606) //haunted mine floors
|| (destX >= 3106 && destX <= 3218 && destY >= 4540 && destY <= 4680)) //Tarn's lair
;
}
public static final boolean isSmokeyArea(WorldTile tile) {
int destX = tile.getX();
int destY = tile.getY();
return ((destX >= 3199 && destX <= 3330 && destY >= 9341 && destY <= 9406) //Smoke dungeon
|| (destX >= 3333 && destX <= 3383 && destY >= 9345 && destY <= 9450) //Smokey well 1
|| (destX >= 3072 && destX <= 3136 && destY >= 4287 && destY <= 4416) //Smokey well 2
|| (destX >= 3261 && destX <= 3329 && destY >= 4287 && destY <= 4416)) //Smokey well 3
;
}
public static final boolean isDesertArea(WorldTile tile) {
int destX = tile.getX();
int destY = tile.getY();
return ((destX <= 3294 && destX >= 3133 && destY <= 3132 && destY >= 2614)
|| (destX <= 3566 && destX >= 3295 && destY <= 3115 && destY >= 2585)
|| (destX <= 3512 && destX >= 3315 && destY <= 3132 && destY >= 3110)
|| (destX <= 3355 && destX >= 3327 && destY <= 3156 && destY >= 3131))
;
}
public static final boolean isSinkArea(WorldTile tile) {
int destX = tile.getX();
int destY = tile.getY();
return ((destX <= 1613 && destX >= 1534 && destY <= 4425 && destY >= 4346))
;
}
public static final boolean isPvpArea(WorldTile tile) {
return (Wilderness.isAtWild(tile));
}
public static void destroySpawnedObject(WorldObject object, boolean clip) {
getRegion(object.getRegionId()).removeObject(object, object.getPlane(), object.getXInRegion(), object.getYInRegion());
}
public static void destroySpawnedObject(WorldObject object) {
getRegion(object.getRegionId()).removeObject(object, object.getPlane(), object.getXInRegion(), object.getYInRegion());
}
public static final void spawnTempGroundObject(final WorldObject object, final int replaceId, long time) {
spawnObject(object);
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
removeObject(object);
addGroundItem(new Item(replaceId), object, null, false, 180);
}
catch (Throwable e) {
Logger.handle(e);
}
}
}, time, TimeUnit.MILLISECONDS);
}
public static void sendWorldMessage(String message, boolean forStaff) {
for (Player p : World.getPlayers()) {
if (p == null || !p.isRunning() || p.isYellOff() || (forStaff && p.getRights() == 0))
continue;
p.getPackets().sendGameMessage(message);
}
}
public static final void sendProjectile(WorldObject object, WorldTile startTile,
WorldTile endTile, int gfxId, int startHeight, int endHeight, int speed, int delay,
int curve, int startOffset) {
for(Player pl : players) {
if(pl == null || !pl.withinDistance(object, 20))
continue;
pl.getPackets().sendProjectile(null, startTile, endTile, gfxId,
startHeight, endHeight, speed, delay, curve, startOffset, 1);
}
}
public static void deleteObject(int i, int j, boolean b) {
// TODO Auto-generated method stub
}
public static void spawnObject(int i, WorldTile worldTile, int j, boolean b) {
// TODO Auto-generated method stub
}
public static final void turnPublic(FloorItem floorItem, int publicTime) {
if (!floorItem.isInvisible())
return;
int regionId = floorItem.getTile().getRegionId();
final Region region = getRegion(regionId);
if (!region.getGroundItemsSafe().contains(floorItem))
return;
Player realOwner = floorItem.hasOwner() ? World.getPlayer(floorItem.getOwner()) : null;
if (!ItemConstants.isTradeable(floorItem)) {
region.getGroundItemsSafe().remove(floorItem);
if (realOwner != null) {
if (realOwner.getMapRegionsIds().contains(regionId) && realOwner.getPlane() == floorItem.getTile().getPlane())
realOwner.getPackets().sendRemoveGroundItem(floorItem);
}
return;
}
floorItem.setInvisible(false);
for (Player player : players) {
if (player == null || player == realOwner || !player.hasStarted() || player.hasFinished() || player.getPlane() != floorItem.getTile().getPlane() || !player.getMapRegionsIds().contains(regionId))
continue;
player.getPackets().sendGroundItem(floorItem);
}
// disapears after this time
if (publicTime != -1)
removeGroundItem(floorItem, publicTime);
}
public static final void addGroundItem(final Item item, final WorldTile tile, final Player owner/*
* null
* for
* default
*/, boolean invisible, long hiddenTime/*
* default
* 3
* minutes
*/) {
addGroundItem(item, tile, owner, invisible, hiddenTime, 2, 150);
}
public static final FloorItem addGroundItem(final Item item, final WorldTile tile, final Player owner/*
* null
* for
* default
*/, boolean invisible, long hiddenTime/*
* default
* 3
* minutes
*/, int type) {
return addGroundItem(item, tile, owner, invisible, hiddenTime, type, 150);
}
public static final boolean removeGroundItem1(Player player,
FloorItem floorItem) {
return removeGroundItem(player, floorItem, false);
}
/*
* type 0 - gold if not tradeable
* type 1 - gold if destroyable
* type 2 - no gold
*/
public static final FloorItem addGroundItem(final Item item, final WorldTile tile, final Player owner, boolean invisible, long hiddenTime/*
* default
* 3
* minutes
*/, int type, final int publicTime) {
/*if (type != 2) {
if ((type == 0 && !ItemConstants.isTradeable(item)) || type == 1 && ItemConstants.isDestroy(item)) {
int price = item.getDefinitions().getValue();
if (price <= 0)
return null;
item.setId(995);
item.setAmount(price);
}
}*/
final FloorItem floorItem = new FloorItem(item, tile, owner, owner != null, invisible);
final Region region = getRegion(tile.getRegionId());
region.getGroundItemsSafe().add(floorItem);
if (invisible) {
if (owner != null)
owner.getPackets().sendGroundItem(floorItem);
// becomes visible after x time
if (hiddenTime != -1) {
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
turnPublic(floorItem, publicTime);
}
catch (Throwable e) {
Logger.handle(e);
}
}
}, hiddenTime, TimeUnit.SECONDS);
}
} else {
// visible
int regionId = tile.getRegionId();
for (Player player : players) {
if (player == null || !player.hasStarted() || player.hasFinished() || player.getPlane() != tile.getPlane() || !player.getMapRegionsIds().contains(regionId))
continue;
if ((owner.isPker && !player.isPker) || (!owner.isPker && player.isPker))
continue;
player.getPackets().sendGroundItem(floorItem);
}
// disapears after this time
if (publicTime != -1)
removeGroundItem(floorItem, publicTime);
}
return floorItem;
}
public static final void spawnObject(WorldObject object) {
getRegion(object.getRegionId()).spawnObject(object, object.getPlane(), object.getXInRegion(), object.getYInRegion(), false);
}
public static final void removeObject(WorldObject object) {
getRegion(object.getRegionId()).removeObject(object, object.getPlane(), object.getXInRegion(), object.getYInRegion());
}
public static final WorldObject getObjectWithSlot(WorldTile tile, int slot) {
return getRegion(tile.getRegionId()).getObjectWithSlot(tile.getPlane(), tile.getXInRegion(), tile.getYInRegion(), slot);
}
public static boolean isTileFree(int plane, int x, int y, int size) {
for (int tileX = x; tileX < x + size; tileX++)
for (int tileY = y; tileY < y + size; tileY++)
if (!isFloorFree(plane, tileX, tileY) || !isWallsFree(plane, tileX, tileY))
return false;
return true;
}
public static boolean isFloorFree(int plane, int x, int y) {
return (getMask(plane, x, y) & (0x200000 |
0x40000 | 0x100)) == 0;
}
public static boolean isWallsFree(int plane, int x, int y) {
return (getMask(plane, x, y) & (0x4 |
0x1 | 0x10 |
0x40 | 0x8 |
0x2 | 0x20 | 0x80)) == 0;
}
public static void spawnNPC(NPC npc) {
spawnNPC(npc.getId(),
new WorldTile(npc.getX(), npc.getY(), npc.getPlane()), -1,
npc.canBeAttackFromOutOfArea());
}
public static final WorldObject getSpawnedObject(int x, int y, int plane) {
return getObject(new WorldTile(x, y, plane));
}
public static final WorldObject getRemovedOrginalObject(int plane, int x, int y, int type) {
return getRegion(new WorldTile(x,y,plane).getRegionId()).getRemovedObjectWithSlot(plane, x, y, type);
}
/*
* by default doesnt changeClipData
*/
public static final void spawnTemporaryObject(final WorldObject object,
long time, final boolean clip, final WorldObject actualObject) {
World.spawnObjectTemporary(object, time);
}
public static final void spawnObjectTemporary(final WorldObject object,
long time) {
spawnObject(object);
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
if (!World.isSpawnedObject(object))
return;
removeObject(object);
} catch (Throwable e) {
Logger.handle(e);
}
}
}, time, TimeUnit.MILLISECONDS);
}
/*
* by default doesnt changeClipData
*/
public static final void spawnTemporaryObject(final WorldObject object,
long time, final WorldObject actualObject) {
spawnTemporaryObject(object, time, false, actualObject);
}
public static final void removeItems(final FloorItem floorItem,
final int publicTime) {
int regionId = floorItem.getTile().getRegionId();
final Region region = getRegion(regionId);
if (!region.getGroundItemsSafe().contains(floorItem))
return;
// disapears after this time
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
World.removeGroundItem(floorItem, 0);
} catch (Throwable e) {
Logger.handle(e);
}
}
}, publicTime, TimeUnit.SECONDS);
}
public static final void spawnGroundItem(final Item item,
final WorldTile tile) {
World.removeAllGroundItem(item, tile);
World.addGroundItem(item, tile);
}
public static final void removeAllGroundItem(final Item item,
final WorldTile tile) {
final FloorItem floorItem = new FloorItem(item, tile, null, false,
false);
final Region region = getRegion(tile.getRegionId());
int getAmount = floorItem.getAmount();
for (Player player : players) {
for (int i = 0; i < getAmount; i++) {
region.forceGetFloorItems().remove(floorItem);
player.getPackets().sendRemoveGroundItem(floorItem);
}
}
}
public static final void createTemporaryConfig(final int config,
final int configType, long time, final Player player) {
for (Player p2 : players) {
if (p2 == null || !p2.hasStarted() || p2.hasFinished()
|| !p2.getMapRegionsIds().contains(player.getRegionId()))
continue;
p2.getPackets().sendConfigByFile(config, configType);
}
CoresManager.slowExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
for (Player p2 : players) {
if (p2 == null
|| !p2.hasStarted()
|| p2.hasFinished()
|| !p2.getMapRegionsIds().contains(
player.getRegionId()))
continue;
p2.getPackets().sendConfigByFile(config, 0);
}
} catch (Throwable e) {
Logger.handle(e);
}
}
}, time, TimeUnit.MILLISECONDS);
}
}