diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index 1e4c8622..b196c938 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -429,8 +429,11 @@ "onDamageIFrames" : 30 }, "idleData": { - "idleAnimation" : "Idle1", - "firstPersonIdleAnimation" : "Idle" + "animation": { + "nameFirstPerson" : "Idle", + "nameThirdPerson" : "Idle1", + "priorityCategory" : "IDLE" + } }, "modelPath" : "Models/creatures/person2/person2_1.glb", "viewModelData" : { diff --git a/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java b/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java index 389a7425..03557d1e 100644 --- a/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java +++ b/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java @@ -166,7 +166,7 @@ public class StateTransitionUtil { state.startedAnimation = false; } else if(state.animation != null && (!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(animation))){ //play animation for state - poseActor.playAnimation(animation, true); + poseActor.playAnimation(animation); poseActor.incrementAnimationTime(0.0001); state.startedAnimation = true; } else if(state.animation == null && state.onComplete != null){ diff --git a/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java b/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java index eea42176..c4b82494 100644 --- a/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java +++ b/src/main/java/electrosphere/entity/state/attack/ServerAttackTree.java @@ -267,7 +267,7 @@ public class ServerAttackTree implements BehaviorTree { case ATTACK: { if(entityPoseActor != null && currentMove != null){ if(!entityPoseActor.isPlayingAnimation() || !entityPoseActor.isPlayingAnimation(currentMove.getAnimationAttack())){ - entityPoseActor.playAnimation(currentMove.getAnimationAttack(),true); + entityPoseActor.playAnimation(currentMove.getAnimationAttack()); entityPoseActor.incrementAnimationTime(0.0001); } } diff --git a/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java b/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java index 78ed47a9..6aa7ef59 100644 --- a/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java +++ b/src/main/java/electrosphere/entity/state/idle/ClientIdleTree.java @@ -2,7 +2,6 @@ package electrosphere.entity.state.idle; import electrosphere.net.synchronization.BehaviorTreeIdEnums; -import electrosphere.entity.state.AnimationPriorities; import electrosphere.entity.state.attack.ClientAttackTree; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; import electrosphere.entity.state.movement.AirplaneMovementTree; @@ -94,14 +93,17 @@ public class ClientIdleTree implements BehaviorTree { if(entityActor != null){ if( idleData != null && - (!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(idleData.getIdleAnimation())) && - (Globals.assetManager.fetchModel(entityActor.getModelPath()) != null && Globals.assetManager.fetchModel(entityActor.getModelPath()).getAnimation(idleData.getIdleAnimation()) != null) + (!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(idleData.getAnimation())) && + ( + Globals.assetManager.fetchModel(entityActor.getModelPath()) != null && + Globals.assetManager.fetchModel(entityActor.getModelPath()).getAnimation(idleData.getAnimation().getNameThirdPerson()) != null + ) ){ - entityActor.playAnimation(idleData.getIdleAnimation(),AnimationPriorities.getValue(AnimationPriorities.IDLE)); + entityActor.playAnimation(idleData.getAnimation(),true); entityActor.incrementAnimationTime(0.0001); } - FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, idleData.getFirstPersonIdleAnimation(), AnimationPriorities.getValue(AnimationPriorities.IDLE)); + FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, idleData.getAnimation()); } break; case NOT_IDLE: diff --git a/src/main/java/electrosphere/entity/state/idle/ServerIdleTree.java b/src/main/java/electrosphere/entity/state/idle/ServerIdleTree.java index 99e0c1f3..379f795d 100644 --- a/src/main/java/electrosphere/entity/state/idle/ServerIdleTree.java +++ b/src/main/java/electrosphere/entity/state/idle/ServerIdleTree.java @@ -2,7 +2,6 @@ package electrosphere.entity.state.idle; import electrosphere.net.synchronization.FieldIdEnums; -import electrosphere.entity.state.AnimationPriorities; import electrosphere.entity.state.attack.ClientAttackTree.AttackTreeState; import electrosphere.entity.state.attack.ServerAttackTree; import electrosphere.entity.state.idle.ClientIdleTree.IdleTreeState; @@ -15,12 +14,12 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.game.data.creature.type.IdleData; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.parser.net.message.SynchronizationMessage; import electrosphere.net.synchronization.BehaviorTreeIdEnums; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; -import electrosphere.renderer.anim.Animation; import electrosphere.server.datacell.utils.DataCellSearchUtils; import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; import electrosphere.server.poseactor.PoseActor; @@ -39,15 +38,19 @@ public class ServerIdleTree implements BehaviorTree { Entity parent; + //The idle data + IdleData idleData; + CopyOnWriteArrayList networkMessageQueue = new CopyOnWriteArrayList(); /** * Creates a server idle tree * @param e The entity to attach it to */ - public ServerIdleTree(Entity e){ + public ServerIdleTree(Entity e, IdleData idleData){ state = IdleTreeState.IDLE; parent = e; + this.idleData = idleData; } /** @@ -60,19 +63,30 @@ public class ServerIdleTree implements BehaviorTree { return state; } + /** + * Starts idling + */ public void start(){ - //TODO: check if can start moving - state = IdleTreeState.IDLE; + setState(IdleTreeState.IDLE); } + /** + * Interrupts the idle animation + */ public void interrupt(){ - state = IdleTreeState.NOT_IDLE; + setState(IdleTreeState.NOT_IDLE); } + /** + * Stops the idle animation + */ public void stop(){ - state = IdleTreeState.NOT_IDLE; + setState(IdleTreeState.NOT_IDLE); } + /** + * Simulates the idle tree + */ public void simulate(float deltaTime){ PoseActor poseActor = EntityUtils.getPoseActor(parent); @@ -91,9 +105,9 @@ public class ServerIdleTree implements BehaviorTree { case IDLE: if(poseActor != null){ if( - (!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(Animation.ANIMATION_IDLE_1)) + (!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(idleData.getAnimation())) ){ - poseActor.playAnimation(Animation.ANIMATION_IDLE_1,AnimationPriorities.getValue(AnimationPriorities.IDLE)); + poseActor.playAnimation(idleData.getAnimation()); poseActor.incrementAnimationTime(0.0001); } } @@ -156,8 +170,8 @@ public class ServerIdleTree implements BehaviorTree { * @param entity The entity to attach to * @param tree The behavior tree to attach */ - public static ServerIdleTree attachTree(Entity parent){ - ServerIdleTree rVal = new ServerIdleTree(parent); + public static ServerIdleTree attachTree(Entity parent, IdleData idleData){ + ServerIdleTree rVal = new ServerIdleTree(parent, idleData); //put manual code here (setting params, etc) diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index d9cd9b32..ce333325 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -673,7 +673,9 @@ public class CreatureUtils { ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.LIFE_STATE); } //idle tree & generic stuff all creatures have - ServerIdleTree.attachTree(rVal); + if(rawType.getIdleData() != null){ + ServerIdleTree.attachTree(rVal, rawType.getIdleData()); + } CreatureUtils.setFacingVector(rVal, MathUtils.getOriginVector()); rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); diff --git a/src/main/java/electrosphere/entity/types/object/ObjectUtils.java b/src/main/java/electrosphere/entity/types/object/ObjectUtils.java index c4974e59..a206e3b4 100644 --- a/src/main/java/electrosphere/entity/types/object/ObjectUtils.java +++ b/src/main/java/electrosphere/entity/types/object/ObjectUtils.java @@ -18,7 +18,6 @@ import electrosphere.entity.state.gravity.ClientGravityTree; import electrosphere.entity.state.gravity.ServerGravityTree; import electrosphere.entity.state.hitbox.HitboxCollectionState; import electrosphere.entity.state.idle.ClientIdleTree; -import electrosphere.entity.state.idle.ServerIdleTree; import electrosphere.entity.state.inventory.ClientInventoryState; import electrosphere.entity.state.inventory.InventoryUtils; import electrosphere.entity.state.inventory.ServerInventoryState; @@ -198,8 +197,6 @@ public class ObjectUtils { if(rawType.getHitboxData() != null){ HitboxCollectionState.attachHitboxState(realm.getHitboxManager(), true, rVal, rawType.getHitboxData()); } - //idle tree & generic stuff all objects have - ServerIdleTree.attachTree(rVal); //required for synchronization manager diff --git a/src/main/java/electrosphere/game/data/creature/type/IdleData.java b/src/main/java/electrosphere/game/data/creature/type/IdleData.java index caec317a..2c945258 100644 --- a/src/main/java/electrosphere/game/data/creature/type/IdleData.java +++ b/src/main/java/electrosphere/game/data/creature/type/IdleData.java @@ -1,30 +1,21 @@ package electrosphere.game.data.creature.type; +import electrosphere.game.data.common.TreeDataAnimation; + /** * Data about how the creature will behave when in idle state */ public class IdleData { //the animation that plays when the creature is idle - String idleAnimation; - - //the animation that plays when the creature idles in first person - String firstPersonIdleAnimation; + TreeDataAnimation animation; /** - * the animation that plays when the creature is idle - * @return + * The animation that plays when the creature is idle + * @return The animation */ - public String getIdleAnimation(){ - return idleAnimation; - } - - /** - * the animation that plays when the creature idles in first person - * @return - */ - public String getFirstPersonIdleAnimation(){ - return firstPersonIdleAnimation; + public TreeDataAnimation getAnimation(){ + return animation; } } diff --git a/src/main/java/electrosphere/server/poseactor/PoseActor.java b/src/main/java/electrosphere/server/poseactor/PoseActor.java index ff2eee5b..5655665a 100644 --- a/src/main/java/electrosphere/server/poseactor/PoseActor.java +++ b/src/main/java/electrosphere/server/poseactor/PoseActor.java @@ -169,15 +169,10 @@ public class PoseActor { * @param animation The animation data * @param isThirdPerson true if is third person, false if is first person */ - public void playAnimation(TreeDataAnimation animation, boolean isThirdPerson){ + public void playAnimation(TreeDataAnimation animation){ //Get the animation's name - String animationName = ""; - if(isThirdPerson){ - animationName = animation.getNameThirdPerson(); - } else { - animationName = animation.getNameFirstPerson(); - } + String animationName = animation.getNameThirdPerson(); //Get the animation's priority int priority = AnimationPriorities.getValue(AnimationPriorities.DEFAULT); @@ -202,12 +197,9 @@ public class PoseActor { } } - if(group != null && isThirdPerson == true){ + if(group != null){ boneMask.addAll(group.getBoneNamesThirdPerson()); } - if(group != null && isThirdPerson == false){ - boneMask.addAll(group.getBoneNamesFirstPerson()); - } } } else if(this.boneGroups == null){ LoggerInterface.loggerRenderer.WARNING("Trying to play animation on pose actor that uses bone groups, but the actor's bone group isn't defined!");