diff --git a/src/resources/common/ObjControllerOpcodes.java b/src/resources/common/ObjControllerOpcodes.java index 0317dfd0..64636512 100644 --- a/src/resources/common/ObjControllerOpcodes.java +++ b/src/resources/common/ObjControllerOpcodes.java @@ -27,12 +27,13 @@ public class ObjControllerOpcodes { public static final int DATA_TRANSFORM_WITH_PARENT = 0xF1000000; public static final int COMMAND_QUEUE_ENQUEUE = 0x16010000; public static final int COMMAND_QUEUE_REMOVE = 0x17010000; - public static final int HOVER_TARGET = 0x26010000; // lookAtTarget - public static final int TARGET_UPDATE = 0xC5040000; // intendedTarget + public static final int lookAtTarget = 0x26010000; + public static final int intendedTarget = 0xC5040000; public static final int OBJECT_MENU_REQUEST = 0x46010000; public static final int SECURE_TRADE = 0x15010000; public static final int BUFF_BUILDER_CHANGE = 0x5A020000; public static final int BUFF_BUILDER_END = 0x5B020000; public static final int MISSION_LIST_REQUEST = 0xF5000000; public static final int ChangeRoleIconChoice = 0x4D040000; + } diff --git a/src/resources/objects/creature/CreatureMessageBuilder.java b/src/resources/objects/creature/CreatureMessageBuilder.java index 8e917fe9..9ffad44b 100644 --- a/src/resources/objects/creature/CreatureMessageBuilder.java +++ b/src/resources/objects/creature/CreatureMessageBuilder.java @@ -256,8 +256,8 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { buffer.putInt(creature.getGuildId()); - buffer.putLong(0); // lookAtTarget 0x10 - buffer.putLong(creature.getTargetId()); // intendedTarget 0x11 + buffer.putLong(creature.getLookAtTarget()); // lookAtTarget 0x10 + buffer.putLong(creature.getIntendedTarget()); // intendedTarget 0x11 buffer.put(creature.getMoodId()); buffer.putInt(creature.getPerformanceCounter()); /* @@ -664,16 +664,22 @@ public class CreatureMessageBuilder extends ObjectMessageBuilder { } - public IoBuffer buildTargetDelta(long targetId) { - + public IoBuffer buildLookAtTargetDelta(long targetId) { IoBuffer buffer = bufferPool.allocate(8, false).order(ByteOrder.LITTLE_ENDIAN); buffer.putLong(targetId); int size = buffer.position(); buffer.flip(); buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 0x10, buffer, size + 4); - return buffer; - + } + + public IoBuffer buildIntendedTargetDelta(long targetId) { + IoBuffer buffer = bufferPool.allocate(8, false).order(ByteOrder.LITTLE_ENDIAN); + buffer.putLong(targetId); + int size = buffer.position(); + buffer.flip(); + buffer = createDelta("CREO", (byte) 6, (short) 1, (short) 0x11, buffer, size + 4); + return buffer; } public IoBuffer buildHealthDelta(int health) { diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 19d60409..5ef41fc8 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -56,7 +56,7 @@ import engine.resources.scene.Quaternion; import resources.objects.tangible.TangibleObject; import resources.objects.weapon.WeaponObject; -@Entity(version=0) +@Entity(version=1) public class CreatureObject extends TangibleObject implements IPersistent { @NotPersistent @@ -112,6 +112,7 @@ public class CreatureObject extends TangibleObject implements IPersistent { private String inviteSenderName; private long inviteCounter = 0; private int guildId = 0; + private long lookAtTarget = 0; private long targetId = 0; private byte moodId = 0; private int performanceCounter = 0; @@ -959,23 +960,43 @@ public class CreatureObject extends TangibleObject implements IPersistent { this.guildId = guildId; } } - - public long getTargetId() { + + public long getLookAtTarget() { + synchronized(objectMutex) { + return lookAtTarget; + } + } + + public void setLookAtTarget(long lookAtTarget) { + synchronized(objectMutex) { + this.lookAtTarget = lookAtTarget; + } + + notifyObservers(messageBuilder.buildLookAtTargetDelta(lookAtTarget), true); + } + + public long getIntendedTarget() { synchronized(objectMutex) { return targetId; } } - public void setTargetId(long targetId) { + public void setIntendedTarget(long intendedTarget) { synchronized(objectMutex) { - this.targetId = targetId; + this.targetId = intendedTarget; } - IoBuffer targetDelta = messageBuilder.buildTargetDelta(targetId); - notifyObservers(targetDelta, false); - + notifyObservers(messageBuilder.buildIntendedTargetDelta(intendedTarget), true); } - + + public long getTargetId() { + return getIntendedTarget(); + } + + public void setTargetId(long targetId) { + setIntendedTarget(targetId); + } + public long getInviteCounter() { synchronized(objectMutex) { return inviteCounter; diff --git a/src/services/SimulationService.java b/src/services/SimulationService.java index 5c9c06b7..98f4a230 100644 --- a/src/services/SimulationService.java +++ b/src/services/SimulationService.java @@ -437,7 +437,7 @@ public class SimulationService implements INetworkDispatch { }); - objControllerOpcodes.put(ObjControllerOpcodes.TARGET_UPDATE, new INetworkRemoteEvent() { + objControllerOpcodes.put(ObjControllerOpcodes.lookAtTarget, new INetworkRemoteEvent() { @Override public void handlePacket(IoSession session, IoBuffer data) throws Exception { @@ -460,19 +460,39 @@ public class SimulationService implements INetworkDispatch { TargetUpdate targetUpdate = new TargetUpdate(); targetUpdate.deserialize(data); - object.setTargetId(targetUpdate.getTargetId()); + object.setLookAtTarget(targetUpdate.getTargetId()); } - + }); - objControllerOpcodes.put(ObjControllerOpcodes.HOVER_TARGET, new INetworkRemoteEvent() { + objControllerOpcodes.put(ObjControllerOpcodes.intendedTarget, new INetworkRemoteEvent() { @Override public void handlePacket(IoSession session, IoBuffer data) throws Exception { + data.order(ByteOrder.LITTLE_ENDIAN); + + Client client = core.getClient(session); + + if(client == null) { + System.out.println("NULL Client"); + return; + } + + if(client.getParent() == null) { + System.out.println("NULL Object"); + return; + } + CreatureObject object = (CreatureObject) client.getParent(); + + TargetUpdate targetUpdate = new TargetUpdate(); + targetUpdate.deserialize(data); + + object.setIntendedTarget(targetUpdate.getTargetId()); + } - + }); }