1 16 17 package com.buchuki.ensmer.builtin; 18 19 import com.buchuki.ensmer.*; 20 import com.buchuki.ensmer.input.event.semantic.*; 21 import com.buchuki.ensmer.object.Backend; 22 import java.io.Serializable ; 23 import javax.vecmath.*; 24 25 30 public class Teleport extends Backend { 31 32 37 public Teleport() { 38 final AreaManager man = EnsmerManager.instance().getAreaManager(); 39 man.addObjectListener(new ObjectListener() { 40 public void objectStateChanged(ObjectEvent event) { 41 if (event.getObject() == teleportIdentifier && 42 event.getAction() == ObjectEvent.EventType.OBJECT_DESTROYED) { 43 man.getArea(man.getAreaIDForObject(getId())).destroyObject(getId()); 44 } 45 } 46 }); 47 } 48 49 54 public Teleport(Serializable data) { 55 this(); 56 teleportIdentifier = (Long ) data; 57 } 58 59 65 public void setTeleportObject(Long id) { 66 this.teleportIdentifier = id; 67 fireChangeEvent(); 68 } 69 70 75 public Long getTeleportObject(Long id) { 76 return teleportIdentifier; 77 } 78 79 84 public Serializable getSerializable() { 85 return teleportIdentifier; 86 } 87 88 91 public void doTeleport() { 92 AreaManager man = EnsmerManager.instance().getAreaManager(); 93 Area area = man.getArea(man.getAreaIDForObject(teleportIdentifier)); 94 if (area != man.getCurrentArea()) { 95 man.setCurrentArea(area.getAreaID()); 96 } 97 Matrix4f objectPos = area.getObjectPosition(teleportIdentifier); 98 Matrix4f userPos = EnsmerManager.instance().getInterfaceManager().getViewPosition(); 99 Vector3f addition = new Vector3f(0f, 0f, 3f); 100 userPos.transform(addition); 101 Vector3f objPosVec = new Vector3f(); 102 objectPos.get(objPosVec); 103 objPosVec.add(addition); 104 userPos.setTranslation(objPosVec); 105 EnsmerManager.instance().getUserManager().setAbsoluteUserPosition(userPos); 106 EnsmerManager.instance().getUserManager().getInputManager().systemMode(); 107 } 108 109 112 private Long teleportIdentifier; 113 114 } 115 | Popular Tags |