| |
---|
| | private Character() { |
---|
| | // JSONDecode時の呼び出し用 |
---|
| | } |
---|
| | |
---|
| | // public Character(String accountURI, String name, Position3D position, Angle angle, CharacterModel model) { |
---|
| | // setAccountURI(accountURI); |
---|
| | // setName(name); |
---|
| | // setPosition(position); |
---|
| | // setAngle(angle); |
---|
| | // setModel(model); |
---|
| | // updateAreaURI(); |
---|
| | // } |
---|
| | // public Character(String accountURI, String name, Position3D position, Angle |
---|
| | // angle, CharacterModel model) { |
---|
| | // setAccountURI(accountURI); |
---|
| | // setName(name); |
---|
| | // setPosition(position); |
---|
| | // setAngle(angle); |
---|
| | // setModel(model); |
---|
| | // updateAreaURI(); |
---|
| | // } |
---|
| | |
---|
| | public Character(String instanceId, String accountURI, String name, Position3D position, Angle angle, |
---|
| | CharacterModel model) { |
---|
| | setAccountURI(accountURI); |
---|
| |
---|
| | |
---|
| | private String findAreaURI(Instance instance) { |
---|
| | // キャラクターのポジションを用いてどのエリア内にいるかを判定して当該エリアのURIに更新する |
---|
| | for (String areaId : instance.getAreaIdSet()) { |
---|
| | if (isInTheArea(instance.getArea(areaId))) { |
---|
| | int subStringStartIndex = areaURI.length() - Character.UNIQUE_ID_LENGTH; |
---|
| | Area area = instance.getArea(areaId); |
---|
| | if (area.isSurroundingPosition(position)) { |
---|
| | int subStringStartIndex = areaURI.length() - Area.UNIQUE_ID_LENGTH; |
---|
| | StringBuilder newAreaURI = new StringBuilder(); |
---|
| | return newAreaURI.append(areaURI.substring(0, subStringStartIndex)).append(areaId).toString(); |
---|
| | } |
---|
| | } |
---|
| | throw new IllegalStateException("Character is in the unknown area."); |
---|
| | } |
---|
| | |
---|
| | private boolean isInTheArea(Area area) { |
---|
| | for (Plain plain : area.getRegion()) { |
---|
| | // ここに 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; |
---|
| | } |
---|
| | |
---|
| | private void updateAreaURI() { |
---|
| | String[] areaURISplit = areaURI.split("/"); // ……/instances/{instanceId}/areas/{areaId} |
---|
| | int splitSize = areaURISplit.length; |
---|
| | String instanceId = areaURISplit[splitSize - 3]; |
---|
| | String previousAreaId = areaURISplit[splitSize - 1]; |
---|
| | Instance instance = Instances.getInstance().getInstance(instanceId); |
---|
| | Area previousArea = instance.getArea(previousAreaId); |
---|
| | if (!isInTheArea(previousArea)) { |
---|
| | // キャラクターのポジションを用いてどのエリア内にいるかを判定して当該エリアのURIに更新する |
---|
| | setAreaURI(findAreaURI(instance)); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | public Item destroyItem(String itemId) { |
---|
| | return itemMap.remove(itemId); |
---|
| | } |
---|
| | } |
---|
| | |