Seen a few of these so decided to release this.
What you are adding:
This system basically groups a certain number of coordinates and gives it a name (makes an area).
e.g. It would draw a shape or a group of shapes around a certain area like Wizards Tower (see below) and all the tiles inside that shape are now part of that area. A single shape is used for wizards tower but for areas like Lumbridge you'd use a polygon to mark the Lumbridge area, then a rectangle to mark the chest room down the kitchen and both these groups of tiles will be part of an 'area' called Lumbridge.
Here's a picture of what you're adding, and how it works:
Code:
package org.fb.game.world.area;
import java.util.LinkedList;
import java.util.List;
import org.fb.game.entity.character.player.Player;
public abstract class Area {
private List<Player> players = new LinkedList<Player>();
public abstract Area update();
public abstract String name();
public abstract Shape[] shapes();
public abstract boolean member();
public abstract Environment environment();
public List<Player> players() {
return players;
}
public enum Environment {
NORMAL,
DESERT,
GODWARS;
}
}
Code:
package org.frostblades.game.world.area;
import java.util.ArrayList;
import java.util.List;
import org.frostblades.GameServer;
import org.frostblades.engine.GameEngine;
import org.frostblades.engine.task.Task;
import org.frostblades.game.Location;
import org.frostblades.game.entity.character.player.Player;
import org.frostblades.game.world.area.impl.Alkharid;
import org.frostblades.game.world.area.impl.Falador;
import org.frostblades.game.world.area.impl.Lumbridge;
import org.frostblades.game.world.area.impl.Varrock;
import org.frostblades.utils.Utils;
public class AreaManager {
private static List<Area> areas;
public static void init() {
try {
areas(new ArrayList<Area>());
areas().add(new Varrock());
areas().add(new Falador());
areas().add(new Lumbridge());
areas().add(new Alkharid());
} catch (Exception e) {
GameServer.get().logger().error(e);
}
}
public static Area get(final Location location) {
try {
Area current = null;
boolean found = false;
for (Area area : areas()) {
for (Shape shape : area.shapes()) {
if (shape.inside(location)) {
current = area;
found = true;
break;
}
}
if (!found)
continue;
return current;
}
} catch (Exception e) {
GameServer.get().logger().error(e);
}
return null;
}
public static void update(final Player player, final Area area) {
if (player.getBoneDelay() > Utils.currentTimeMillis())
return;
player.packets().sendIComponentText(1073, 10, "<col=ffffff>You have reached");
player.packets().sendIComponentText(1073, 11, "<col=ffcff00>" + area.name());
player.interfaceManager().sendTab(player.interfaceManager().hasRezizableScreen() ? 1 : 11, 1073);
GameEngine.get().addTask(new Task(3) {
@Override
public void execute() {
player.packets().closeInterface(player.interfaceManager().hasRezizableScreen() ? 1 : 11);
stop();
}
});
}
public static List<Area> areas() {
return areas;
}
public static void areas(List<Area> list) {
areas = list;
}
}
Code:
package org.frostblades.game.world.area;
import org.frostblades.game.Location;
public abstract class Shape {
private Location[] areas;
private ShapeType type;
public abstract boolean inside(Location location);
public Location[] areas() {
return areas;
}
public Shape areas(Location[] areas) {
this.areas = areas;
return this;
}
public ShapeType type() {
return type;
}
public Shape type(ShapeType type) {
this.type = type;
return this;
}
public enum ShapeType {
RECTANGLE, POLYGON;
}
}
Code:
package org.frostblades.game.world.area.shapes;
import org.frostblades.game.Location;
import org.frostblades.game.world.area.Shape;
public class Rectangle extends Shape {
public Rectangle(Location northEast, Location southWest) {
areas(new Location[] { northEast, southWest }).type(ShapeType.RECTANGLE);
}
@Override
public boolean inside(Location location) {
if (areas()[0].x() < location.x() || areas()[1].x() > location.x())
return false;
if (areas()[0].y() < location.y() || areas()[1].y() > location.y())
return false;
return true;
}
}
Code:
package org.frostblades.game.world.area.shapes;
import org.frostblades.game.Location;
import org.frostblades.game.world.area.Shape;
public class Polygon extends Shape {
private int sides;
private int[][] points;
public Polygon(Location[] points) {
sides(points.length).areas(points).type(ShapeType.POLYGON);
points(new int[sides][2]);
for (int i = 0; i < sides; i++) {
points()[i][0] = points[i].x();
points()[i][1] = points[i].y();
}
}
@Override
public boolean inside(Location location) {
boolean inside = false;
int y = location.y(), x = location.x();
for (int i = 0, j = sides() - 1; i < sides(); j = i++) {
if ((points()[i][1] < y && points()[j][1] >= y) || (points()[j][1] < y && points()[i][1] >= y)) {
if (points()[i][0] + (y - points()[i][1]) / (points()[j][1] - points()[i][1]) * (points()[j][0] - points()[i][0]) < x) {
inside = !inside;
}
}
}
return inside;
}
public int sides() {
return sides;
}
public Shape sides(int sides) {
this.sides = sides;
return this;
}
public int[][] points() {
return points;
}
public Shape points(int[][] points) {
this.points = points;
return this;
}
}
Here's some pre-marked shapes for you to test.
https://mega.co.nz/#!DMBVnD5D!FKL1Ei...iuGD49f-0Sfvq0
Uses:
Originally Posted by
Vip3r
Originally Posted by
Vip3r
It's a shape array. You can have more than one shape, e.g. if you wanted to make a pvp world you can make one Area called 'safe' where you would have multiple 'shapes' which all contribute to this one area.
You would set the environment to 'safe' and add its effect there.