Newer
Older
CactusServer / src / main / java / cactusServer / entities / Area.java
package cactusServer.entities;

import java.util.HashSet;

import framework.model3D.Position3D;
import net.arnx.jsonic.JSONHint;

public class Area extends Entity {
	private String name;
	private Plain[] region; // 任意個の平面の方程式
	private HashSet<Allowed> permissions; // エリア内で可能なことの羅列
	@JSONHint(ignore = true)
	public static final int UNIQUE_ID_LENGTH = 12;

	private Area() {
		// JSONDecode時の呼び出し用
	}

	public Area(String name, Plain[] region, HashSet<Allowed> permissions) {
		setName(name);
		setRegion(region);
		setPermissions(permissions);
	}

	public String getName() {
		return name;
	}

	public Plain[] getRegion() {
		return region;
	}

	public Plain getRegion(int index) {
		return region[index];
	}

	public HashSet<Allowed> getPermissions() {
		return permissions;
	}

	public boolean isPermission(Allowed allowed) {
		return permissions.contains(allowed);
	}

	public boolean isSurroundingPosition(Position3D position) {
		for (Plain plain : region) {
			// ここで Plainのa,b,c,d と Characterのx,y,z を用いて, キャラクターが平面の裏にいるかどうかの判定を行う
			double equation = (plain.getA() * position.getX()) + (plain.getB() * position.getY())
					+ (plain.getC() * position.getZ()) + plain.getD();
			if (equation > 0) {
				return false;
			}
		}
		return true;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setRegion(Plain[] region) {
		this.region = region;
	}

	public void setPermissions(HashSet<Allowed> permissions) {
		this.permissions = permissions;
	}

	public void addPermission(Allowed allowed) {
		permissions.add(allowed);
	}

	public void removePermission(Allowed allowed) {
		permissions.remove(allowed);
	}

	public static enum Allowed {
		SHOOT, KILL;
	}
}