package cactusServer.entities; import cactusServer.models.Instances; import framework.model3D.Position3D; import net.arnx.jsonic.JSONHint; public class Player extends Entity { private String instanceURI; private String characterURI; private String areaURI; private Position3D position; private Angle angle; private CameraState cameraState; private EmoteState emoteState; @JSONHint(ignore = true) public static final int UNIQUE_ID_LENGTH = 12; private Player() { // JSONDecode時の呼び出し用 } public Player(String instanceURI, String characterURI, CameraState cameraState, EmoteState.EmoteType animationClassToStart) { setInstanceURI(instanceURI); setCharacterURI(characterURI); setCameraState(cameraState); setEmoteState(new EmoteState(animationClassToStart)); readCharacterData(characterURI); } private Character getCharacter(String characterURI) { String[] characterURISplit = characterURI.split("/"); // ……/instances/{instanceId}/characters/{characterId} int splitSize = characterURISplit.length; String characterId = characterURISplit[splitSize - 1]; String instanceId = characterURISplit[splitSize - 3]; return Instances.getInstance().getInstance(instanceId).getCharacter(characterId); } private void readCharacterData(String characterURI) { Character character = getCharacter(characterURI); setPosition(character.getPosition()); setAngle(character.getAngle()); setAreaURI(character.getAreaURI()); } public String getInstanceURI() { return instanceURI; } public String getCharacterURI() { return characterURI; } public String getAreaURI() { return areaURI; } public Position3D getPosition() { return position; } public Angle getAngle() { return angle; } public CameraState getCameraState() { return cameraState; } public EmoteState getEmoteState() { return emoteState; } public void setInstanceURI(String instanceURI) { this.instanceURI = instanceURI; } public void setCharacterURI(String characterURI) { this.characterURI = characterURI; } public void setAreaURI(String areaURI) { this.areaURI = areaURI; } public void setPosition(Position3D position) { this.position = position; } public void setAngle(Angle angle) { this.angle = angle; } public void setCameraState(CameraState cameraState) { this.cameraState = cameraState; } public void setEmoteState(EmoteState emoteState) { this.emoteState = emoteState; } public void setanimationClassToStart(EmoteState.EmoteType animationClassToStart) { setEmoteState(new EmoteState(animationClassToStart)); } public void updateEmoteType(EmoteState.EmoteType animationClassToStart) { this.emoteState.setEmoteType(animationClassToStart); } public void deletePlayer() { writeCharacterData(characterURI); } private void writeCharacterData(String characterURI) { Character character = getCharacter(characterURI); character.setPosition(position); character.setAngle(angle); character.setAreaURI(areaURI); } }