From ceb4786228909c2e12c485cadf29da8cb1ed67b3 Mon Sep 17 00:00:00 2001 From: austin Date: Sun, 28 Jul 2024 13:35:34 -0400 Subject: [PATCH] Data cleanup --- assets/Data/creatures/human.json | 32 +- .../entity/btree/StateTransitionUtil.java | 352 ++++++------------ .../entity/state/AnimationPriorities.java | 6 + .../entity/state/block/ClientBlockTree.java | 12 +- .../entity/state/block/ServerBlockTree.java | 9 +- .../entity/state/life/ClientLifeTree.java | 7 +- .../entity/state/life/ServerLifeTree.java | 4 +- .../entity/state/movement/FallTree.java | 34 +- .../entity/state/movement/ServerFallTree.java | 3 +- .../groundmove/ServerGroundMovementTree.java | 1 - .../entity/types/creature/CreatureUtils.java | 8 +- .../game/data/common/TreeDataAnimation.java | 60 +++ .../game/data/common/TreeDataAudio.java | 21 ++ .../game/data/common/TreeDataState.java | 47 +++ .../game/data/creature/type/Animation.java | 24 -- .../game/data/creature/type/CreatureType.java | 14 + .../game/data/creature/type/HealthSystem.java | 41 +- .../game/data/creature/type/SprintSystem.java | 14 +- .../data/creature/type/attack/AttackMove.java | 14 +- .../creature/type/bonegroups/BoneGroup.java | 36 ++ .../type/movement/FallMovementSystem.java | 48 +-- .../type/movement/GroundMovementSystem.java | 26 +- .../type/movement/JumpMovementSystem.java | 10 +- 23 files changed, 412 insertions(+), 411 deletions(-) create mode 100644 src/main/java/electrosphere/game/data/common/TreeDataAnimation.java create mode 100644 src/main/java/electrosphere/game/data/common/TreeDataAudio.java create mode 100644 src/main/java/electrosphere/game/data/common/TreeDataState.java delete mode 100644 src/main/java/electrosphere/game/data/creature/type/Animation.java create mode 100644 src/main/java/electrosphere/game/data/creature/type/bonegroups/BoneGroup.java diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index b2bc4a1c..9feeed0e 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -183,21 +183,25 @@ }, { "type" : "FALL", - "animationFall" : { - "name" : "Fall", - "length" : 1, - "loops" : true + "fallState" : { + "firstPersonAnimation" : { + "name" : "Fall", + "priority": 4 + }, + "thirdPersonAnimation" : { + "name" : "Fall", + "priority": 4 + } }, - "animationFirstPersonFall" : { - "name" : "Fall" - }, - "animationLand" : { - "name" : "Land", - "length" : 1, - "loops" : true - }, - "animationFirstPersonLand" : { - "name" : "Land" + "landState" : { + "firstPersonAnimation" : { + "name" : "Land", + "priority": 4 + }, + "thirdPersonAnimation" : { + "name" : "Land", + "priority": 4 + } } } ], diff --git a/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java b/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java index 905ac992..bf23a6cc 100644 --- a/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java +++ b/src/main/java/electrosphere/entity/btree/StateTransitionUtil.java @@ -7,6 +7,10 @@ import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; +import electrosphere.game.data.common.TreeDataAnimation; +import electrosphere.game.data.common.TreeDataAudio; +import electrosphere.game.data.common.TreeDataState; +import electrosphere.logger.LoggerInterface; import electrosphere.renderer.actor.Actor; import electrosphere.server.poseactor.PoseActor; @@ -79,7 +83,7 @@ public class StateTransitionUtil { } } if(state == null){ - throw new IllegalArgumentException("Trying to simulate state that is not registered with this util object"); + LoggerInterface.loggerEngine.DEBUG("Skipping state " + stateEnum + " because there is not a state registered to that enum value!"); } else { if(this.isServer){ simulateServerState(this.parent,state); @@ -98,49 +102,43 @@ public class StateTransitionUtil { Actor actor = EntityUtils.getActor(parent); if(actor != null){ //determine the third person animation to play - String animationToPlay = state.thirdPersonAnimation; - if(animationToPlay == null && state.getThirdPersonAnimation != null){ - animationToPlay = state.getThirdPersonAnimation.get(); - } + String thirdPersonAnimation = state.getThirdPersonAnimation(); //determine the first person animation to play - String firstPersonAnimation = state.firstPersonAnimation; - if(firstPersonAnimation == null && state.getFirstPersonAnimation != null){ - firstPersonAnimation = state.getFirstPersonAnimation.get(); - } + String firstPersonAnimation = state.getFirstPersonAnimation(); //Main simulation - if(!actor.isPlayingAnimation() && state.onComplete != null && state.startedAnimation == true){ + if(!actor.isPlayingAnimation() && state.onComplete != null && state.startedAnimation == true && thirdPersonAnimation != null){ //state transition if this isn't set to loop state.onComplete.run(); state.startedAnimation = false; - } else if(!actor.isPlayingAnimation() || !actor.isPlayingAnimation(animationToPlay)){ + } else if(!actor.isPlayingAnimation() || !actor.isPlayingAnimation(thirdPersonAnimation)){ //play animation, audio, etc, for state - if(parent == Globals.playerEntity && !Globals.controlHandler.cameraIsThirdPerson()){ + if(parent == Globals.playerEntity && !Globals.controlHandler.cameraIsThirdPerson() && thirdPersonAnimation != null){ //first person //play first person audio - if(state.audioPath != null){ - Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioPath, VirtualAudioSourceType.CREATURE, false); + if(state.audioData != null && state.audioData.getAudioPath() != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false); } } else { //play third person audio - if(state.audioPath != null){ - Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioPath, VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent)); + if(state.audioData != null && state.audioData.getAudioPath() != null){ + Globals.virtualAudioSourceManager.createVirtualAudioSource(state.audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent)); } } - actor.playAnimation(animationToPlay,state.animPriority); + actor.playAnimation(thirdPersonAnimation,state.getAnimationPriority()); actor.incrementAnimationTime(0.0001); state.startedAnimation = true; - } else if(animationToPlay == null && state.onComplete != null){ + } else if(thirdPersonAnimation == null && state.onComplete != null){ state.onComplete.run(); state.startedAnimation = false; } if(firstPersonAnimation != null){ - FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, firstPersonAnimation, state.animPriority); + FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, firstPersonAnimation, state.getAnimationPriority()); } } } @@ -154,23 +152,20 @@ public class StateTransitionUtil { PoseActor poseActor = EntityUtils.getPoseActor(parent); if(poseActor != null){ //determine the third person animation to play - String animationToPlay = state.thirdPersonAnimation; - if(animationToPlay == null && state.getThirdPersonAnimation != null){ - animationToPlay = state.getThirdPersonAnimation.get(); - } + String thirdPersonAnimation = state.getThirdPersonAnimation(); //Main simulation - if(!poseActor.isPlayingAnimation() && state.onComplete != null && state.startedAnimation == true){ + if(!poseActor.isPlayingAnimation() && state.onComplete != null && state.startedAnimation == true && thirdPersonAnimation != null){ //state transition if this isn't set to loop state.onComplete.run(); state.startedAnimation = false; - } else if(animationToPlay != null && (!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(animationToPlay))){ + } else if(thirdPersonAnimation != null && (!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(thirdPersonAnimation))){ //play animation for state - poseActor.playAnimation(animationToPlay,state.animPriority); + poseActor.playAnimation(thirdPersonAnimation,state.getAnimationPriority()); poseActor.incrementAnimationTime(0.0001); state.startedAnimation = true; - } else if(animationToPlay == null && state.onComplete != null){ + } else if(thirdPersonAnimation == null && state.onComplete != null){ state.onComplete.run(); state.startedAnimation = false; } @@ -188,20 +183,20 @@ public class StateTransitionUtil { //the priority of this animation in particular int animPriority; - //T1he animation to play in first person - String firstPersonAnimation; + //The animation to play in first person + TreeDataAnimation firstPersonAnimation; //Gets the first person animation's name Supplier getFirstPersonAnimation; //The animation to play in third person - String thirdPersonAnimation; + TreeDataAnimation thirdPersonAnimation; //Gets the third person animation's name Supplier getThirdPersonAnimation; - //The audio path - String audioPath; + //The audio data + TreeDataAudio audioData; //The function to fire on completion (ie to transition to the next state) Runnable onComplete; @@ -209,150 +204,93 @@ public class StateTransitionUtil { //Tracks whether the animation has been played or not boolean startedAnimation = false; + /** + * Gets the animation to play for third person + * @return The animation's name + */ + String getThirdPersonAnimation(){ + String toPlay = null; + if(thirdPersonAnimation != null){ + toPlay = thirdPersonAnimation.getName(); + } + if(getThirdPersonAnimation != null){ + toPlay = getThirdPersonAnimation.get(); + } + return toPlay; + } + + /** + * Gets the animation to play for first person + * @return The animation's name + */ + String getFirstPersonAnimation(){ + String toPlay = null; + if(firstPersonAnimation != null){ + toPlay = firstPersonAnimation.getName(); + } + if(getFirstPersonAnimation != null){ + toPlay = getFirstPersonAnimation.get(); + } + return toPlay; + } + + /** + * Gets the animation priority + * @return The animation priority + */ + int getAnimationPriority(){ + int priority = this.animPriority; + if(thirdPersonAnimation != null && thirdPersonAnimation.getPriority() != null){ + priority = thirdPersonAnimation.getPriority(); + } + return priority; + } + /** * Constructor */ private StateTransitionUtilItem( Object stateEnum, - int animPriority, - String firstPersonAnimation, - Supplier getFirstPersonAnimation, - String thirdPersonAnimation, - Supplier getThirdPersonAnimation, - String audioPath, + TreeDataAnimation firstPersonAnimation, + TreeDataAnimation thirdPersonAnimation, + TreeDataAudio audioData, Runnable onComplete ){ this.stateEnum = stateEnum; - this.animPriority = animPriority; this.firstPersonAnimation = firstPersonAnimation; - this.getFirstPersonAnimation = getFirstPersonAnimation; this.thirdPersonAnimation = thirdPersonAnimation; - this.getThirdPersonAnimation = getThirdPersonAnimation; - this.audioPath = audioPath; + this.audioData = audioData; this.onComplete = onComplete; } /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param firstPersonAnimation The animation to play in first person. If this is null, it will not play any animation in first person - * @param getFirstPersonAnimation The supplier for a first person animation name. If it is null, it will not play any animation in first person - * @param thirdPersonAnimation The animation to play in third person. If this is null, it will not play any animation in third person - * @param getThirdPersonAnimation The supplier for a third person animation name. If it is null, it will not play any animation in the third person - * @param audioPath The path to an audio file to play on starting the animation. If null, no audio will be played - * @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop + * Constructor for supplier type */ - public static StateTransitionUtilItem create( + private StateTransitionUtilItem( Object stateEnum, int animPriority, - String firstPersonAnimation, Supplier getFirstPersonAnimation, - String thirdPersonAnimation, Supplier getThirdPersonAnimation, - String audioPath, + TreeDataAudio audioData, Runnable onComplete - ){ - return new StateTransitionUtilItem( - stateEnum, - animPriority, - firstPersonAnimation, - getFirstPersonAnimation, - thirdPersonAnimation, - getThirdPersonAnimation, - audioPath, - onComplete - ); + ){ + this.stateEnum = stateEnum; + this.animPriority = animPriority; + this.getFirstPersonAnimation = getFirstPersonAnimation; + this.getThirdPersonAnimation = getThirdPersonAnimation; + this.audioData = audioData; + this.onComplete = onComplete; } /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param firstPersonAnimation The animation to play in first person. If this is null, it will not play any animation in first person - * @param thirdPersonAnimation The animation to play in third person. If this is null, it will not play any animation in third person - * @param audioPath The path to an audio file to play on starting the animation. If null, no audio will be played - * @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop - */ - public static StateTransitionUtilItem create( - Object stateEnum, - int animPriority, - String firstPersonAnimation, - String thirdPersonAnimation, - String audioPath, - Runnable onComplete - ){ - return create( - stateEnum, - animPriority, - firstPersonAnimation, - null, - thirdPersonAnimation, - null, - audioPath, - onComplete - ); - } - - /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param firstPersonAnimation The animation to play in first person. If this is null, it will not play any animation in first person - * @param thirdPersonAnimation The animation to play in third person. If this is null, it will not play any animation in third person - * @param audioPath The path to an audio file to play on starting the animation. If null, no audio will be played - */ - public static StateTransitionUtilItem create( - Object stateEnum, - int animPriority, - String firstPersonAnimation, - String thirdPersonAnimation, - String audioPath - ){ - return create( - stateEnum, - animPriority, - firstPersonAnimation, - null, - thirdPersonAnimation, - null, - audioPath, - null - ); - } - - /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param thirdPersonAnimation The animation to play in third person. If this is null, it will not play any animation in third person - * @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop - */ - public static StateTransitionUtilItem create( - Object stateEnum, - int animPriority, - String thirdPersonAnimation, - Runnable onComplete - ){ - return create( - stateEnum, - animPriority, - null, - null, - thirdPersonAnimation, - null, - null, - onComplete - ); - } - - /** - * Constructor + * Constructor for a supplier-based approach. This takes suppliers that will provide animation data on demand. + * This decouples the animations from the initialization of the tree. + * The intended usecase is if the animation could change based on some state in the tree. * @param stateEnum The enum value for this state * @param animPriority The priority of this state's animations * @param getFirstPersonAnimation The supplier for a first person animation name. If it is null, it will not play any animation in first person * @param getThirdPersonAnimation The supplier for a third person animation name. If it is null, it will not play any animation in the third person - * @param audioPath The path to an audio file to play on starting the animation. If null, no audio will be played + * @param audioData The path to an audio file to play on starting the animation. If null, no audio will be played * @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop */ public static StateTransitionUtilItem create( @@ -360,119 +298,41 @@ public class StateTransitionUtil { int animPriority, Supplier getFirstPersonAnimation, Supplier getThirdPersonAnimation, - String audioPath, + TreeDataAudio audioData, Runnable onComplete ){ return new StateTransitionUtilItem( stateEnum, animPriority, - null, getFirstPersonAnimation, - null, getThirdPersonAnimation, - audioPath, + audioData, onComplete ); } /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param getFirstPersonAnimation The supplier for a first person animation name. If it is null, it will not play any animation in first person - * @param getThirdPersonAnimation The supplier for a third person animation name. If it is null, it will not play any animation in the third person - * @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop + * Creates a state transition based on tree data for the state + * @param stateEnum The enum value for this state in particular in the tree + * @param treeData The tree data for this state + * @return The item for the transition util */ public static StateTransitionUtilItem create( Object stateEnum, - int animPriority, - Supplier getFirstPersonAnimation, - Supplier getThirdPersonAnimation, + TreeDataState treeData, Runnable onComplete - ){ - return new StateTransitionUtilItem( - stateEnum, - animPriority, - null, - getFirstPersonAnimation, - null, - getThirdPersonAnimation, - null, - onComplete - ); - } - - /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param getThirdPersonAnimation The supplier for a third person animation name. If it is null, it will not play any animation in the third person - * @param onComplete !!Must transition to the next state!! Fires when the animation completes. If not supplied, animations and autio will loop - */ - public static StateTransitionUtilItem create( - Object stateEnum, - int animPriority, - Supplier getThirdPersonAnimation, - Runnable onComplete - ){ - return new StateTransitionUtilItem( - stateEnum, - animPriority, - null, - null, - null, - getThirdPersonAnimation, - null, - onComplete - ); - } - - /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param getThirdPersonAnimation The supplier for a third person animation name. If it is null, it will not play any animation in the third person - */ - public static StateTransitionUtilItem create( - Object stateEnum, - int animPriority, - Supplier getThirdPersonAnimation - ){ - return new StateTransitionUtilItem( - stateEnum, - animPriority, - null, - null, - null, - getThirdPersonAnimation, - null, - null - ); - } - - /** - * Constructor - * @param stateEnum The enum value for this state - * @param animPriority The priority of this state's animations - * @param getFirstPersonAnimation The supplier for a first person animation name. If it is null, it will not play any animation in first person - * @param getThirdPersonAnimation The supplier for a third person animation name. If it is null, it will not play any animation in the third person - */ - public static StateTransitionUtilItem create( - Object stateEnum, - int animPriority, - Supplier getFirstPersonAnimation, - Supplier getThirdPersonAnimation - ){ - return new StateTransitionUtilItem( - stateEnum, - animPriority, - null, - getFirstPersonAnimation, - null, - getThirdPersonAnimation, - null, - null - ); + ){ + StateTransitionUtilItem rVal = null; + if(treeData != null){ + rVal = new StateTransitionUtilItem( + stateEnum, + treeData.getFirstPersonAnimation(), + treeData.getThirdPersonAnimation(), + treeData.getAudioData(), + onComplete + ); + } + return rVal; } diff --git a/src/main/java/electrosphere/entity/state/AnimationPriorities.java b/src/main/java/electrosphere/entity/state/AnimationPriorities.java index 919aac9d..a7c63dec 100644 --- a/src/main/java/electrosphere/entity/state/AnimationPriorities.java +++ b/src/main/java/electrosphere/entity/state/AnimationPriorities.java @@ -42,4 +42,10 @@ public class AnimationPriorities { // public static final int IDLE = 10; + + // + //50 + // + public static final int DEFAULT = 50; + } diff --git a/src/main/java/electrosphere/entity/state/block/ClientBlockTree.java b/src/main/java/electrosphere/entity/state/block/ClientBlockTree.java index 84dd01ce..3e53acba 100644 --- a/src/main/java/electrosphere/entity/state/block/ClientBlockTree.java +++ b/src/main/java/electrosphere/entity/state/block/ClientBlockTree.java @@ -58,19 +58,25 @@ public class ClientBlockTree implements BehaviorTree { BlockState.WIND_UP, AnimationPriorities.BLOCK, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpFirstPersonAnimation();}, - () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAnimation();} + () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAnimation();}, + null, + null ), StateTransitionUtilItem.create( BlockState.BLOCKING, AnimationPriorities.BLOCK, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainFirstPersonAnimation();}, - () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();} + () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();}, + null, + null ), StateTransitionUtilItem.create( BlockState.COOLDOWN, AnimationPriorities.BLOCK, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownFirstPersonAnimation();}, - () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAnimation();} + () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAnimation();}, + null, + null ), }); } diff --git a/src/main/java/electrosphere/entity/state/block/ServerBlockTree.java b/src/main/java/electrosphere/entity/state/block/ServerBlockTree.java index a0362c39..d22d672e 100644 --- a/src/main/java/electrosphere/entity/state/block/ServerBlockTree.java +++ b/src/main/java/electrosphere/entity/state/block/ServerBlockTree.java @@ -51,18 +51,25 @@ public class ServerBlockTree implements BehaviorTree { StateTransitionUtilItem.create( BlockState.WIND_UP, AnimationPriorities.BLOCK, + null, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAnimation();}, + null, () -> {this.setState(BlockState.BLOCKING);} ), StateTransitionUtilItem.create( BlockState.BLOCKING, AnimationPriorities.BLOCK, - () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();} + null, + () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();}, + null, + null ), StateTransitionUtilItem.create( BlockState.COOLDOWN, AnimationPriorities.BLOCK, + null, () -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAnimation();}, + null, () -> {this.setState(BlockState.NOT_BLOCKING);} ), }); diff --git a/src/main/java/electrosphere/entity/state/life/ClientLifeTree.java b/src/main/java/electrosphere/entity/state/life/ClientLifeTree.java index 14b36243..c4f75f0c 100644 --- a/src/main/java/electrosphere/entity/state/life/ClientLifeTree.java +++ b/src/main/java/electrosphere/entity/state/life/ClientLifeTree.java @@ -5,7 +5,6 @@ import electrosphere.net.synchronization.BehaviorTreeIdEnums; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.btree.StateTransitionUtil; import electrosphere.entity.btree.StateTransitionUtil.StateTransitionUtilItem; -import electrosphere.entity.state.AnimationPriorities; import electrosphere.game.data.creature.type.HealthSystem; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.Entity; @@ -120,10 +119,8 @@ public class ClientLifeTree implements BehaviorTree { stateTransitionUtil = StateTransitionUtil.create(parent, false, new StateTransitionUtilItem[]{ StateTransitionUtilItem.create( LifeStateEnum.DYING, - AnimationPriorities.DEATH, - healthSystem.getDyingFirstPersonAnimation(), - healthSystem.getDyingThirdPersonAnimation(), - healthSystem.getAudioPath() + healthSystem.getDyingState(), + () -> {} ) }); } diff --git a/src/main/java/electrosphere/entity/state/life/ServerLifeTree.java b/src/main/java/electrosphere/entity/state/life/ServerLifeTree.java index b6963ab4..3ba53696 100644 --- a/src/main/java/electrosphere/entity/state/life/ServerLifeTree.java +++ b/src/main/java/electrosphere/entity/state/life/ServerLifeTree.java @@ -13,7 +13,6 @@ import electrosphere.net.parser.net.message.SynchronizationMessage; import electrosphere.server.datacell.utils.DataCellSearchUtils; import electrosphere.engine.Globals; -import electrosphere.entity.state.AnimationPriorities; import electrosphere.entity.state.life.ClientLifeTree.LifeStateEnum; import electrosphere.game.data.creature.type.HealthSystem; import electrosphere.net.synchronization.annotation.SyncedField; @@ -177,8 +176,7 @@ public class ServerLifeTree implements BehaviorTree { stateTransitionUtil = StateTransitionUtil.create(parent, true, new StateTransitionUtilItem[]{ StateTransitionUtilItem.create( LifeStateEnum.DYING, - AnimationPriorities.DEATH, - this.healthSystem.getDyingThirdPersonAnimation(), + this.healthSystem.getDyingState(), () -> { this.setState(LifeStateEnum.DEAD); } diff --git a/src/main/java/electrosphere/entity/state/movement/FallTree.java b/src/main/java/electrosphere/entity/state/movement/FallTree.java index 95dd6075..19575488 100644 --- a/src/main/java/electrosphere/entity/state/movement/FallTree.java +++ b/src/main/java/electrosphere/entity/state/movement/FallTree.java @@ -5,6 +5,8 @@ import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; +import electrosphere.entity.btree.StateTransitionUtil; +import electrosphere.entity.btree.StateTransitionUtil.StateTransitionUtilItem; import electrosphere.entity.state.AnimationPriorities; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; import electrosphere.game.data.creature.type.movement.FallMovementSystem; @@ -35,26 +37,30 @@ public class FallTree implements BehaviorTree { //the related jump tree JumpTree jumpTree; + //The state transition util + StateTransitionUtil stateTransitionUtil; + public FallTree(Entity parent, FallMovementSystem fallMovementSystem){ this.parent = parent; this.fallMovementSystem = fallMovementSystem; + stateTransitionUtil = StateTransitionUtil.create( + parent, + false, + new StateTransitionUtilItem[]{ + StateTransitionUtilItem.create( + FallState.ACTIVE, + fallMovementSystem.getFallState(), + null + ) + } + ); } @Override public void simulate(float deltaTime) { - Actor entityActor = EntityUtils.getActor(parent); switch(state){ case ACTIVE: - if(entityActor != null){ - if( - !entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(fallMovementSystem.getAnimationFall().getName()) && - (jumpTree == null || !jumpTree.isJumping()) - ){ - entityActor.playAnimation(fallMovementSystem.getAnimationFall().getName(),AnimationPriorities.FALL); - entityActor.incrementAnimationTime(0.0001); - } - FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, fallMovementSystem.getAnimationFirstPersonFall().getName(), AnimationPriorities.FALL); - } + stateTransitionUtil.simulate(FallState.ACTIVE); break; case INACTIVE: break; @@ -85,12 +91,12 @@ public class FallTree implements BehaviorTree { Actor entityActor = EntityUtils.getActor(parent); if(entityActor != null){ if( - !entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(fallMovementSystem.getAnimationLand().getName()) + !entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(fallMovementSystem.getLandState().getThirdPersonAnimation().getName()) ){ - entityActor.playAnimation(fallMovementSystem.getAnimationLand().getName(),AnimationPriorities.LAND); + entityActor.playAnimation(fallMovementSystem.getLandState().getThirdPersonAnimation().getName(),AnimationPriorities.LAND); entityActor.incrementAnimationTime(0.0001); } - FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, fallMovementSystem.getAnimationFirstPersonLand().getName(), AnimationPriorities.LAND); + FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, fallMovementSystem.getLandState().getFirstPersonAnimation().getName(), AnimationPriorities.LAND); } } } diff --git a/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java b/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java index 6213665d..73c39cd1 100644 --- a/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java +++ b/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java @@ -5,6 +5,7 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.AnimationPriorities; +import electrosphere.game.data.creature.type.movement.FallMovementSystem; import electrosphere.server.poseactor.PoseActor; public class ServerFallTree implements BehaviorTree { @@ -23,7 +24,7 @@ public class ServerFallTree implements BehaviorTree { ServerJumpTree jumpTree; - public ServerFallTree(Entity parent){ + public ServerFallTree(Entity parent, FallMovementSystem fallMovementSystem){ this.parent = parent; } diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java index 62fad03b..0881cb3d 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java @@ -1,7 +1,6 @@ package electrosphere.entity.state.movement.groundmove; -import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; import electrosphere.net.synchronization.FieldIdEnums; import electrosphere.net.parser.net.message.SynchronizationMessage; diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index f020d479..c1f40ab8 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -474,13 +474,7 @@ public class CreatureUtils { // Falling case FallMovementSystem.FALL_MOVEMENT_SYSTEM: FallMovementSystem fallMovementSystem = (FallMovementSystem)movementSystem; - ServerFallTree fallTree = new ServerFallTree(rVal); - if(fallMovementSystem.getAnimationFall()!=null){ - fallTree.setAnimationFall(fallMovementSystem.getAnimationFall().getName()); - } - if(fallMovementSystem.getAnimationLand()!=null){ - fallTree.setAnimationLand(fallMovementSystem.getAnimationLand().getName()); - } + ServerFallTree fallTree = new ServerFallTree(rVal,fallMovementSystem); if(CreatureUtils.serverGetEntityMovementTree(rVal) != null && CreatureUtils.serverGetEntityMovementTree(rVal) instanceof ClientGroundMovementTree){ ((ServerGroundMovementTree)CreatureUtils.serverGetEntityMovementTree(rVal)).setServerFallTree(fallTree); } diff --git a/src/main/java/electrosphere/game/data/common/TreeDataAnimation.java b/src/main/java/electrosphere/game/data/common/TreeDataAnimation.java new file mode 100644 index 00000000..ad44d54b --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/TreeDataAnimation.java @@ -0,0 +1,60 @@ +package electrosphere.game.data.common; + +/** + * Data about an animation + */ +public class TreeDataAnimation { + + /** + * The name of the animation if it exists, null otherwise + */ + String name; + + /** + * The length of the animation in frames if it exists, null otherwise + */ + int length; + + /** + * If boolean, should loop if it exists, null otherwise + */ + boolean loops; + + /** + * The priority for this animation in particular + */ + Integer priority; + + /** + * Gets the name of the animation + * @return The name of the animation + */ + public String getName() { + return name; + } + + /** + * Gets the length of the animation in frames + * @return The length in number of frames + */ + public int getLength() { + return length; + } + + /** + * Gets whether the animation loops or not + * @return true if loops, false otherwise + */ + public boolean isLoops() { + return loops; + } + + /** + * Gets the priority for this animation + * @return The priority + */ + public Integer getPriority(){ + return priority; + } + +} diff --git a/src/main/java/electrosphere/game/data/common/TreeDataAudio.java b/src/main/java/electrosphere/game/data/common/TreeDataAudio.java new file mode 100644 index 00000000..5949d410 --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/TreeDataAudio.java @@ -0,0 +1,21 @@ +package electrosphere.game.data.common; + +/** + * Audio data to use when running a given tree state + */ +public class TreeDataAudio { + + /** + * The path to the audio file to play if it exists, null otherwise + */ + String audioPath; + + + /** + * Gets the audio path + */ + public String getAudioPath(){ + return audioPath; + } + +} diff --git a/src/main/java/electrosphere/game/data/common/TreeDataState.java b/src/main/java/electrosphere/game/data/common/TreeDataState.java new file mode 100644 index 00000000..99429df9 --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/TreeDataState.java @@ -0,0 +1,47 @@ +package electrosphere.game.data.common; + +/** + * A simple tree state + */ +public class TreeDataState { + + /** + * The animation to play for the tree's state when in first person + */ + TreeDataAnimation firstPersonAnimation; + + /** + * The animation to play for the tree's state when in third person + */ + TreeDataAnimation thirdPersonAnimation; + + /** + * The audio to play when running this state of the tree + */ + TreeDataAudio audioData; + + /** + * Gets the first person animation data + * @return The first person animation data if it exists, null otherwise + */ + public TreeDataAnimation getFirstPersonAnimation(){ + return firstPersonAnimation; + } + + /** + * Gets the third person animation data + * @return The third person animation data if it exists, null otherwise + */ + public TreeDataAnimation getThirdPersonAnimation(){ + return thirdPersonAnimation; + } + + /** + * Gets the audio data + * @return The audio data if it exists, null otherwise + */ + public TreeDataAudio getAudioData(){ + return audioData; + } + +} diff --git a/src/main/java/electrosphere/game/data/creature/type/Animation.java b/src/main/java/electrosphere/game/data/creature/type/Animation.java deleted file mode 100644 index f99c850f..00000000 --- a/src/main/java/electrosphere/game/data/creature/type/Animation.java +++ /dev/null @@ -1,24 +0,0 @@ -package electrosphere.game.data.creature.type; - -/** - * Data about an animation - */ -public class Animation { - - String name; - int length; - boolean loops; - - public String getName() { - return name; - } - - public int getLength() { - return length; - } - - public boolean isLoops() { - return loops; - } - -} diff --git a/src/main/java/electrosphere/game/data/creature/type/CreatureType.java b/src/main/java/electrosphere/game/data/creature/type/CreatureType.java index 58cadf70..8c22a7f7 100644 --- a/src/main/java/electrosphere/game/data/creature/type/CreatureType.java +++ b/src/main/java/electrosphere/game/data/creature/type/CreatureType.java @@ -6,6 +6,7 @@ import electrosphere.game.data.creature.type.ai.AITreeData; import electrosphere.game.data.creature.type.attack.AttackMove; import electrosphere.game.data.creature.type.attack.AttackMoveResolver; import electrosphere.game.data.creature.type.block.BlockSystem; +import electrosphere.game.data.creature.type.bonegroups.BoneGroup; import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.creature.type.movement.MovementSystem; import electrosphere.game.data.creature.type.rotator.RotatorSystem; @@ -103,6 +104,11 @@ public class CreatureType { */ AttackMoveResolver attackMoveResolver; + /** + * The list of bone groups for this creature + */ + List boneGroups; + /** * Gets the id for this creature type * @return The id @@ -246,6 +252,14 @@ public class CreatureType { public List getAITrees(){ return aiTrees; } + + /** + * Gets the list of bone groups for this creature + * @return The list of bone groups + */ + public List getBoneGroups(){ + return boneGroups; + } } diff --git a/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java b/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java index 1c8cf200..ec255071 100644 --- a/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/HealthSystem.java @@ -1,5 +1,7 @@ package electrosphere.game.data.creature.type; +import electrosphere.game.data.common.TreeDataState; + /** * Data about the health of a creature */ @@ -11,14 +13,10 @@ public class HealthSystem { //the number of iframes on taking damage int onDamageIFrames; - //the third person animation to play when the entity is dying - String dyingThirdPersonAnimation; - - //the first person animation to play when the entity is dying - String dyingFirstPersonAnimation; - - //The audio file to play when the entity dies - String audioPath; + /** + * The dying state + */ + TreeDataState dyingState; /** * Gets the maximum health @@ -37,27 +35,11 @@ public class HealthSystem { } /** - * Gets the animation to play in third person when the entity is dying - * @return The animation + * Gets the dying state data + * @return The dying state data */ - public String getDyingThirdPersonAnimation(){ - return dyingThirdPersonAnimation; - } - - /** - * Gets the animation to play in first person when the entity is dying - * @return The animation - */ - public String getDyingFirstPersonAnimation(){ - return dyingFirstPersonAnimation; - } - - /** - * Gets the audio path to play when the entity is dying - * @return The audio path - */ - public String getAudioPath(){ - return audioPath; + public TreeDataState getDyingState(){ + return dyingState; } /** @@ -67,8 +49,7 @@ public class HealthSystem { HealthSystem rVal = new HealthSystem(); rVal.maxHealth = maxHealth; rVal.onDamageIFrames = onDamageIFrames; - rVal.dyingThirdPersonAnimation = dyingThirdPersonAnimation; - rVal.dyingFirstPersonAnimation = dyingFirstPersonAnimation; + rVal.dyingState = dyingState; return rVal; } diff --git a/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java b/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java index 17c53143..b4b1fe43 100644 --- a/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java @@ -1,24 +1,26 @@ package electrosphere.game.data.creature.type; +import electrosphere.game.data.common.TreeDataAnimation; + /** * Sprint data */ public class SprintSystem { - Animation animationStartUp; - Animation animationMain; - Animation animationWindDown; + TreeDataAnimation animationStartUp; + TreeDataAnimation animationMain; + TreeDataAnimation animationWindDown; float maxVelocity; int staminaMax; - public Animation getAnimationStartUp() { + public TreeDataAnimation getAnimationStartUp() { return animationStartUp; } - public Animation getAnimationMain() { + public TreeDataAnimation getAnimationMain() { return animationMain; } - public Animation getAnimationWindDown() { + public TreeDataAnimation getAnimationWindDown() { return animationWindDown; } diff --git a/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java b/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java index db02674f..2e911035 100644 --- a/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java +++ b/src/main/java/electrosphere/game/data/creature/type/attack/AttackMove.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type.attack; -import electrosphere.game.data.creature.type.Animation; +import electrosphere.game.data.common.TreeDataAnimation; /** * Data about a single attack move this creature is capable of @@ -20,9 +20,9 @@ public class AttackMove { String holdAnimationName; String attackAnimationName; - Animation animationFirstPersonWindup; - Animation animationFirstPersonHold; - Animation animationFirstPersonAttack; + TreeDataAnimation animationFirstPersonWindup; + TreeDataAnimation animationFirstPersonHold; + TreeDataAnimation animationFirstPersonAttack; /* Damage stuff @@ -92,7 +92,7 @@ public class AttackMove { * Gets the animation data for the 1st person windup * @return the animation data */ - public Animation getAnimationFirstPersonWindup(){ + public TreeDataAnimation getAnimationFirstPersonWindup(){ return animationFirstPersonWindup; } @@ -100,7 +100,7 @@ public class AttackMove { * Gets the animation data for the 1st person hold * @return the animation data */ - public Animation getAnimationFirstPersonHold(){ + public TreeDataAnimation getAnimationFirstPersonHold(){ return animationFirstPersonHold; } @@ -108,7 +108,7 @@ public class AttackMove { * Gets the animation data for the 1st person attack * @return the animation data */ - public Animation getAnimationFirstPersonAttack(){ + public TreeDataAnimation getAnimationFirstPersonAttack(){ return animationFirstPersonAttack; } diff --git a/src/main/java/electrosphere/game/data/creature/type/bonegroups/BoneGroup.java b/src/main/java/electrosphere/game/data/creature/type/bonegroups/BoneGroup.java new file mode 100644 index 00000000..d2066450 --- /dev/null +++ b/src/main/java/electrosphere/game/data/creature/type/bonegroups/BoneGroup.java @@ -0,0 +1,36 @@ +package electrosphere.game.data.creature.type.bonegroups; + +import java.util.List; + +/** + * Groups of bones that can be used for functions (ie priority on animations, hitbox data macros, etc) + */ +public class BoneGroup { + + /** + * The id for the bone group + */ + String id; + + /** + * The list of names of bones that are within this group + */ + List boneNames; + + /** + * Gets the id of the bone group + * @return The bone group id + */ + public String getId(){ + return id; + } + + /** + * Gets the list of names of bones in the group + * @return The list of names of bones + */ + public List getBoneNames(){ + return boneNames; + } + +} diff --git a/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java b/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java index 2e6b86fc..eba48065 100644 --- a/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/movement/FallMovementSystem.java @@ -1,54 +1,40 @@ package electrosphere.game.data.creature.type.movement; -import electrosphere.game.data.creature.type.Animation; +import electrosphere.game.data.common.TreeDataState; /** * Data about a falling movement system */ public class FallMovementSystem implements MovementSystem { + /** + * The name of this movement system type in particular + */ public static final String FALL_MOVEMENT_SYSTEM = "FALL"; + //The type of movement syste, String type; - //Fall data - Animation animationFall; - Animation animationFirstPersonFall; + //Falling data + TreeDataState fallState; - //landing data - Animation animationLand; - Animation animationFirstPersonLand; + //Landing data + TreeDataState landState; /** - * Gets the animation to play in 3rd person when the creature is falling - * @return the animation data + * Gets the fall state data + * @return The fall state data */ - public Animation getAnimationFall(){ - return animationFall; + public TreeDataState getFallState(){ + return fallState; } /** - * Gets the animation to play in 1st person when the creature is falling - * @return the animation data + * Gets the land state data + * @return The land state data */ - public Animation getAnimationFirstPersonFall(){ - return animationFirstPersonFall; - } - - /** - * Gets the animation to play in 3rd person when the creature is landing - * @return the animation data - */ - public Animation getAnimationLand(){ - return animationLand; - } - - /** - * Gets the animation to play in 1st person when the creature is landing - * @return the animation data - */ - public Animation getAnimationFirstPersonLand(){ - return animationFirstPersonLand; + public TreeDataState getLandState(){ + return landState; } @Override diff --git a/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java b/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java index a6e7cbdb..d7390b1f 100644 --- a/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/movement/GroundMovementSystem.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type.movement; -import electrosphere.game.data.creature.type.Animation; +import electrosphere.game.data.common.TreeDataAnimation; import electrosphere.game.data.creature.type.SprintSystem; /** @@ -19,16 +19,16 @@ public class GroundMovementSystem implements MovementSystem { float maxVelocity; //startup data - Animation animationStartup; - Animation animationFirstPersonStartup; + TreeDataAnimation animationStartup; + TreeDataAnimation animationFirstPersonStartup; //loop data - Animation animationLoop; - Animation animationFirstPersonLoop; + TreeDataAnimation animationLoop; + TreeDataAnimation animationFirstPersonLoop; //wind down data - Animation animationWindDown; - Animation animationFirstPersonWindDown; + TreeDataAnimation animationWindDown; + TreeDataAnimation animationFirstPersonWindDown; //sprint data SprintSystem sprintSystem; @@ -54,7 +54,7 @@ public class GroundMovementSystem implements MovementSystem { * Gets the animation to play in 3rd person for startup * @return The animation data */ - public Animation getAnimationStartup() { + public TreeDataAnimation getAnimationStartup() { return animationStartup; } @@ -62,7 +62,7 @@ public class GroundMovementSystem implements MovementSystem { * Gets the animation to play in 1st person for startup * @return The animation data */ - public Animation getAnimationFirstPersonStartup(){ + public TreeDataAnimation getAnimationFirstPersonStartup(){ return animationFirstPersonStartup; } @@ -70,7 +70,7 @@ public class GroundMovementSystem implements MovementSystem { * Gets the animation to loop in 3rd person * @return The animation data */ - public Animation getAnimationLoop() { + public TreeDataAnimation getAnimationLoop() { return animationLoop; } @@ -78,7 +78,7 @@ public class GroundMovementSystem implements MovementSystem { * Gets the animation to loop in 1st person * @return The animation data */ - public Animation getAnimationFirstPersonLoop(){ + public TreeDataAnimation getAnimationFirstPersonLoop(){ return animationFirstPersonLoop; } @@ -86,7 +86,7 @@ public class GroundMovementSystem implements MovementSystem { * Gets the animation to play in 3rd person to wind down * @return The animation data */ - public Animation getAnimationWindDown() { + public TreeDataAnimation getAnimationWindDown() { return animationWindDown; } @@ -94,7 +94,7 @@ public class GroundMovementSystem implements MovementSystem { * Gets the animation to play in 1st person to wind down * @return The animation data */ - public Animation getAnimationFirstPersonWindDown(){ + public TreeDataAnimation getAnimationFirstPersonWindDown(){ return animationFirstPersonWindDown; } diff --git a/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java b/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java index 601f9c82..d5d0cf28 100644 --- a/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/movement/JumpMovementSystem.java @@ -1,6 +1,6 @@ package electrosphere.game.data.creature.type.movement; -import electrosphere.game.data.creature.type.Animation; +import electrosphere.game.data.common.TreeDataAnimation; public class JumpMovementSystem implements MovementSystem { @@ -8,8 +8,8 @@ public class JumpMovementSystem implements MovementSystem { String type; - Animation animationJump; - Animation animationFirstPersonJump; + TreeDataAnimation animationJump; + TreeDataAnimation animationFirstPersonJump; int jumpFrames; float jumpForce; @@ -22,11 +22,11 @@ public class JumpMovementSystem implements MovementSystem { return jumpForce; } - public Animation getAnimationJump(){ + public TreeDataAnimation getAnimationJump(){ return animationJump; } - public Animation getAnimationFirstPersonJump(){ + public TreeDataAnimation getAnimationFirstPersonJump(){ return animationFirstPersonJump; }