2011-05-13 04:24:42 -04:00
|
|
|
package org.moparscape.msc.gs.model;
|
2011-04-27 01:44:26 -04:00
|
|
|
|
2012-01-13 18:08:16 -05:00
|
|
|
import org.moparscape.msc.gs.model.definition.EntityHandler;
|
2012-01-14 01:54:38 -05:00
|
|
|
import org.moparscape.msc.gs.model.definition.entity.GameObjectDef;
|
|
|
|
import org.moparscape.msc.gs.model.definition.entity.GameObjectLoc;
|
|
|
|
import org.moparscape.msc.gs.model.definition.extra.DoorDef;
|
2011-04-27 01:44:26 -04:00
|
|
|
|
|
|
|
public class GameObject extends Entity {
|
2011-06-25 01:44:53 -04:00
|
|
|
/**
|
|
|
|
* Returns the ID of an item contained in the object.
|
|
|
|
*
|
|
|
|
* @author Konijn
|
|
|
|
*/
|
|
|
|
private int containsItem = -1;
|
|
|
|
/**
|
|
|
|
* The direction the object points in
|
|
|
|
*/
|
|
|
|
private int direction;
|
|
|
|
/**
|
|
|
|
* Location definition of the object
|
|
|
|
*/
|
2012-01-14 01:54:38 -05:00
|
|
|
private GameObjectLoc loc = null;
|
2011-06-25 01:44:53 -04:00
|
|
|
/**
|
|
|
|
* Set when the item has been destroyed to alert players
|
|
|
|
*/
|
|
|
|
private boolean removed = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of object
|
|
|
|
*/
|
|
|
|
private int type;
|
|
|
|
|
2012-01-14 01:54:38 -05:00
|
|
|
public GameObject(GameObjectLoc loc) {
|
2011-06-25 01:44:53 -04:00
|
|
|
direction = loc.direction;
|
|
|
|
type = loc.type;
|
|
|
|
this.loc = loc;
|
|
|
|
super.setID(loc.id);
|
|
|
|
super.setLocation(Point.location(loc.x, loc.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
public GameObject(Point location, int id, int direction, int type) {
|
2012-01-14 01:54:38 -05:00
|
|
|
this(new GameObjectLoc(id, location.getX(), location.getY(), direction,
|
2011-06-25 01:44:53 -04:00
|
|
|
type));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int containsItem() {
|
|
|
|
return containsItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void containsItem(int item) {
|
|
|
|
containsItem = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (o instanceof GameObject) {
|
|
|
|
GameObject go = (GameObject) o;
|
|
|
|
return go.getLocation().equals(getLocation())
|
|
|
|
&& go.getID() == getID()
|
|
|
|
&& go.getDirection() == getDirection()
|
|
|
|
&& go.getType() == getType();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getDirection() {
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
|
2012-01-14 01:54:38 -05:00
|
|
|
public DoorDef getDoorDef() {
|
2011-06-25 01:44:53 -04:00
|
|
|
return EntityHandler.getDoorDef(super.getID());
|
|
|
|
}
|
|
|
|
|
2012-01-14 01:54:38 -05:00
|
|
|
public GameObjectDef getGameObjectDef() {
|
2011-06-25 01:44:53 -04:00
|
|
|
return EntityHandler.getGameObjectDef(super.getID());
|
|
|
|
}
|
|
|
|
|
2012-01-14 01:54:38 -05:00
|
|
|
public GameObjectLoc getLoc() {
|
2011-06-25 01:44:53 -04:00
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isOn(int x, int y) {
|
|
|
|
int width, height;
|
|
|
|
if (type == 1) {
|
|
|
|
width = height = 1;
|
|
|
|
} else if (direction == 0 || direction == 4) {
|
|
|
|
width = getGameObjectDef().getWidth();
|
|
|
|
height = getGameObjectDef().getHeight();
|
|
|
|
} else {
|
|
|
|
height = getGameObjectDef().getWidth();
|
|
|
|
width = getGameObjectDef().getHeight();
|
|
|
|
}
|
|
|
|
if (type == 0) { // Object
|
|
|
|
return x >= getX() && x <= (getX() + width) && y >= getY()
|
|
|
|
&& y <= (getY() + height);
|
|
|
|
} else { // Door
|
|
|
|
return x == getX() && y == getY();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRemoved() {
|
|
|
|
return removed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isTelePoint() {
|
|
|
|
return EntityHandler.getObjectTelePoint(getLocation(), null) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void remove() {
|
|
|
|
removed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDirection(int direction) {
|
|
|
|
this.direction = direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setType(int type) {
|
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
return (type == 0 ? "GameObject" : "WallObject") + ":id = " + id
|
|
|
|
+ "; dir = " + direction + "; location = "
|
|
|
|
+ location.toString() + ";";
|
|
|
|
}
|
2011-04-27 01:44:26 -04:00
|
|
|
|
|
|
|
}
|