diff --git a/src/resources/datatables/Locomotion.java b/src/resources/datatables/Locomotion.java new file mode 100644 index 00000000..eceec58d --- /dev/null +++ b/src/resources/datatables/Locomotion.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package resources.datatables; + +public class Locomotion { + + public static final byte Invalid = -1; + public static final byte Standing = 0; + public static final byte Sneaking = 1; + public static final byte Walking = 2; + public static final byte Running = 3; + public static final byte Kneeling = 4; + public static final byte CrouchSneaking = 5; + public static final byte CrouchWalking = 6; + public static final byte Prone = 7; + public static final byte Crawling = 8; + public static final byte ClimbingStationary = 9; + public static final byte Climbing = 10; + public static final byte Hovering = 11; // + public static final byte Flying = 12; + public static final byte LyingDown = 13; + public static final byte Sitting = 14; + public static final byte SkillAnimating = 15; + public static final byte DrivingVehicle = 16; + public static final byte RidingCreature = 17; + public static final byte KnockedDown = 18; + public static final byte Incapacitated = 19; + public static final byte Dead = 20; + public static final byte Blocking = 21; + +} diff --git a/src/resources/objects/creature/CreatureObject.java b/src/resources/objects/creature/CreatureObject.java index 316045c5..40e15fc4 100644 --- a/src/resources/objects/creature/CreatureObject.java +++ b/src/resources/objects/creature/CreatureObject.java @@ -185,6 +185,8 @@ public class CreatureObject extends TangibleObject implements Serializable { @NotPersistent private transient SWGObject useTarget; + private byte locomotion = 0; + public CreatureObject(long objectID, Planet planet, Point3D position, Quaternion orientation, String Template) { super(objectID, planet, position, orientation, Template); messageBuilder = new CreatureMessageBuilder(this); @@ -381,20 +383,80 @@ public class CreatureObject extends TangibleObject implements Serializable { public void setPosture(byte posture) { synchronized(objectMutex) { - if (this.posture == 0x09) { + switch (posture) { + case resources.datatables.Posture.Invalid: + locomotion = -1; + break; + case resources.datatables.Posture.Upright: + locomotion = 0; + break; + case resources.datatables.Posture.Crouched: + locomotion = 4; + break; + case resources.datatables.Posture.Prone: + locomotion = 7; + break; + case resources.datatables.Posture.Sneaking: + locomotion = 1; + break; + case resources.datatables.Posture.Blocking: + locomotion = 21; + break; + case resources.datatables.Posture.Climbing: + locomotion = 9; + break; + case resources.datatables.Posture.Flying: + locomotion = 12; + break; + case resources.datatables.Posture.LyingDown: + locomotion = 13; + break; + case resources.datatables.Posture.Sitting: + locomotion = 14; + break; + case resources.datatables.Posture.SkillAnimating: + locomotion = 15; + break; + case resources.datatables.Posture.DrivingVehicle: + locomotion = 16; + break; + case resources.datatables.Posture.RidingCreature: + locomotion = 17; + break; + case resources.datatables.Posture.KnockedDown: + locomotion = 18; + break; + case resources.datatables.Posture.Incapacitated: + locomotion = 19; + break; + case resources.datatables.Posture.Dead: + locomotion = 20; + break; + } + } + + synchronized(objectMutex) { + if (this.posture == resources.datatables.Posture.SkillAnimating) { stopPerformance(); } - if(this.posture == posture) + + if (this.posture == posture) { return; + } + this.posture = posture; } - - Posture postureUpdate = new Posture(getObjectID(), posture); - ObjControllerMessage objController = new ObjControllerMessage(0x1B, postureUpdate); notifyObservers(messageBuilder.buildPostureDelta(posture), true); - notifyObservers(objController, true); - + notifyObservers(new ObjControllerMessage(0x1B, new Posture(getObjectID(), posture)), true); + } + + public byte getLocomotion() { + return locomotion; + } + + public void setLocomotion(byte locomotion) { + this.locomotion = locomotion; } public void startPerformance() { diff --git a/src/services/SimulationService.java b/src/services/SimulationService.java index f93defd4..6cc01567 100644 --- a/src/services/SimulationService.java +++ b/src/services/SimulationService.java @@ -85,6 +85,7 @@ import resources.objects.tangible.TangibleObject; import resources.common.*; import resources.common.collidables.AbstractCollidable; import resources.datatables.DisplayType; +import resources.datatables.Locomotion; import resources.datatables.Options; import resources.datatables.PlayerFlags; import resources.datatables.Posture; @@ -366,10 +367,61 @@ public class SimulationService implements INetworkDispatch { object.setMovementCounter(dataTransform.getMovementCounter()); creature.setMovementCounter(dataTransform.getMovementCounter()); } + + synchronized(creature.getMutex()) { + if (dataTransform.getSpeed() > 0.0f) { + switch (creature.getLocomotion()) { + case Locomotion.Prone: + creature.setLocomotion(Locomotion.Crawling); + break; + case Locomotion.ClimbingStationary: + creature.setLocomotion(Locomotion.Climbing); + break; + case Locomotion.Standing: + case Locomotion.Running: + case Locomotion.Walking: + if (dataTransform.getSpeed() >= (creature.getRunSpeed() * (creature.getSpeedMultiplierBase() + creature.getSpeedMultiplierMod()))) { + creature.setLocomotion(Locomotion.Running); + } else { + creature.setLocomotion(Locomotion.Walking); + } + + break; + case Locomotion.Sneaking: + case Locomotion.CrouchSneaking: + case Locomotion.CrouchWalking: + if (dataTransform.getSpeed() >= (creature.getRunSpeed() * (creature.getSpeedMultiplierBase() + creature.getSpeedMultiplierMod()))) { + creature.setLocomotion(Locomotion.CrouchSneaking); + } else { + creature.setLocomotion(Locomotion.CrouchWalking); + } + + break; + } + } else { + switch (creature.getLocomotion()) { + case Locomotion.Crawling: + creature.setLocomotion(Locomotion.Prone); + break; + case Locomotion.Climbing: + creature.setLocomotion(Locomotion.ClimbingStationary); + break; + case Locomotion.Running: + case Locomotion.Walking: + creature.setLocomotion(Locomotion.Standing); + break; + case Locomotion.CrouchSneaking: + case Locomotion.CrouchWalking: + creature.setLocomotion(Locomotion.Sneaking); + break; + } + } + } + if(object.getContainer() != null) { object.getContainer()._remove(object); add(object, newPos.x, newPos.z); - } + } //object.setParentId(0); //object.setParent(null); @@ -457,9 +509,8 @@ public class SimulationService implements INetworkDispatch { return; Point3D oldPos = object.getPosition(); Quaternion newOrientation = new Quaternion(dataTransform.getWOrientation(), dataTransform.getXOrientation(), dataTransform.getYOrientation(), dataTransform.getZOrientation()); - + UpdateTransformWithParentMessage utm = new UpdateTransformWithParentMessage(object.getObjectID(), dataTransform.getCellId(), dataTransform.getTransformedX(), dataTransform.getTransformedY(), dataTransform.getTransformedZ(), dataTransform.getMovementCounter(), (byte) dataTransform.getMovementAngle(), dataTransform.getSpeed()); - if(object.getContainer() != parent) { remove(object, oldPos.x, oldPos.z); @@ -476,10 +527,58 @@ public class SimulationService implements INetworkDispatch { checkForCollidables(object); object.setAttachment("lastValidPosition", object.getPosition()); - + + synchronized(object.getMutex()) { + if (dataTransform.getSpeed() > 0.0f) { + switch (object.getLocomotion()) { + case Locomotion.Prone: + object.setLocomotion(Locomotion.Crawling); + break; + case Locomotion.ClimbingStationary: + object.setLocomotion(Locomotion.Climbing); + break; + case Locomotion.Standing: + case Locomotion.Running: + case Locomotion.Walking: + if (dataTransform.getSpeed() >= (object.getRunSpeed() * (object.getSpeedMultiplierBase() + object.getSpeedMultiplierMod()))) { + object.setLocomotion(Locomotion.Running); + } else { + object.setLocomotion(Locomotion.Walking); + } + + break; + case Locomotion.Sneaking: + case Locomotion.CrouchSneaking: + case Locomotion.CrouchWalking: + if (dataTransform.getSpeed() >= (object.getRunSpeed() * (object.getSpeedMultiplierBase() + object.getSpeedMultiplierMod()))) { + object.setLocomotion(Locomotion.CrouchSneaking); + } else { + object.setLocomotion(Locomotion.CrouchWalking); + } + + break; + } + } else { + switch (object.getLocomotion()) { + case Locomotion.Crawling: + object.setLocomotion(Locomotion.Prone); + break; + case Locomotion.Climbing: + object.setLocomotion(Locomotion.ClimbingStationary); + break; + case Locomotion.Running: + case Locomotion.Walking: + object.setLocomotion(Locomotion.Standing); + break; + case Locomotion.CrouchSneaking: + case Locomotion.CrouchWalking: + object.setLocomotion(Locomotion.Sneaking); + break; + } + } + } } - - + }); swgOpcodes.put(Opcodes.ClientOpenContainerMessage, new INetworkRemoteEvent() { diff --git a/src/services/command/BaseSWGCommand.java b/src/services/command/BaseSWGCommand.java index 8ea09061..5025939d 100644 --- a/src/services/command/BaseSWGCommand.java +++ b/src/services/command/BaseSWGCommand.java @@ -50,8 +50,7 @@ public class BaseSWGCommand implements Cloneable { private float cooldown; private float executeTime; private float warmupTime; - //private Long[] invalidLocomotions; // Not tracked anywhere - private Byte[] invalidPostures; + private Byte[] invalidLocomotions; private Long[] invalidStates; public BaseSWGCommand(String commandName) { @@ -67,8 +66,8 @@ public class BaseSWGCommand implements Cloneable { "command_table", "command_table_ground", "command_table_space" }; for (int n = 0; n < tableArray.length; n++) { + List invalidLocomotions = new ArrayList(); List invalidStates = new ArrayList(); - List invalidPostures = new ArrayList(); DatatableVisitor visitor2 = ClientFileManager.loadFile("datatables/command/" + tableArray[n] + ".iff", DatatableVisitor.class); @@ -79,20 +78,11 @@ public class BaseSWGCommand implements Cloneable { characterAbility = (String) visitor2.getObject(i, 7); - if (!((Boolean) visitor2.getObject(i, 8-sub))) invalidPostures.add((byte) 0); - if (!((Boolean) visitor2.getObject(i, 9-sub))) invalidPostures.add((byte) 3); - if (!((Boolean) visitor2.getObject(i, 15-sub))) invalidPostures.add((byte) 2); - if (!((Boolean) visitor2.getObject(i, 18-sub))) invalidPostures.add((byte) 5); - if (!((Boolean) visitor2.getObject(i, 20-sub))) invalidPostures.add((byte) 6); - if (!((Boolean) visitor2.getObject(i, 21-sub))) invalidPostures.add((byte) 7); - if (!((Boolean) visitor2.getObject(i, 22-sub))) invalidPostures.add((byte) 8); - if (!((Boolean) visitor2.getObject(i, 23-sub))) invalidPostures.add((byte) 9); - if (!((Boolean) visitor2.getObject(i, 24-sub))) invalidPostures.add((byte) 10); - if (!((Boolean) visitor2.getObject(i, 25-sub))) invalidPostures.add((byte) 11); - if (!((Boolean) visitor2.getObject(i, 26-sub))) invalidPostures.add((byte) 12); - if (!((Boolean) visitor2.getObject(i, 27-sub))) invalidPostures.add((byte) 13); - if (!((Boolean) visitor2.getObject(i, 28-sub))) invalidPostures.add((byte) 14); - if (!((Boolean) visitor2.getObject(i, 29-sub))) invalidPostures.add((byte) 4); + for (int l = (8 - sub); l <= (29 - sub); l++) { + if (!((Boolean) visitor2.getObject(i, l))) { + invalidLocomotions.add((byte) (l - (8 - sub))); + } + } if (tableArray[n].startsWith("client_") || tableArray[n].startsWith("command_table_")) { sub += 1; @@ -164,7 +154,7 @@ public class BaseSWGCommand implements Cloneable { executeTime = (Float) visitor2.getObject(i, 87-sub); cooldown = (Float) visitor2.getObject(i, 88-sub); - this.invalidPostures = invalidPostures.toArray(new Byte[] { }); + this.invalidLocomotions = invalidLocomotions.toArray(new Byte[] { }); this.invalidStates = invalidStates.toArray(new Long[] { }); foundCommand = true; @@ -230,8 +220,8 @@ public class BaseSWGCommand implements Cloneable { this.characterAbility = characterAbility; } - public Byte[] getInvalidPostures() { - return invalidPostures; + public Byte[] getInvalidLocomotions() { + return invalidLocomotions; } public Long[] getInvalidStates() {