Renderer/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java
austin ceb4786228
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Data cleanup
2024-07-28 13:35:34 -04:00

104 lines
3.0 KiB
Java

package electrosphere.entity.state.movement;
import electrosphere.entity.Entity;
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 {
static enum FallState {
ACTIVE,
INACTIVE,
}
FallState state = FallState.INACTIVE;
String animationFall = "Armature|Fall";
String animationLand = "Armature|Land";
Entity parent;
ServerJumpTree jumpTree;
public ServerFallTree(Entity parent, FallMovementSystem fallMovementSystem){
this.parent = parent;
}
@Override
public void simulate(float deltaTime) {
PoseActor poseActor = EntityUtils.getPoseActor(parent);
switch(state){
case ACTIVE:
if(poseActor != null){
String animationToPlay = determineCorrectAnimation();
if(
!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(animationToPlay) &&
(jumpTree == null || !jumpTree.isJumping())
){
poseActor.playAnimation(animationToPlay,AnimationPriorities.FALL);
poseActor.incrementAnimationTime(0.0001);
}
}
break;
case INACTIVE:
break;
}
}
public void start(){
state = FallState.ACTIVE;
}
public boolean isFalling(){
return state == FallState.ACTIVE;
}
public void land(){
if(state != FallState.INACTIVE){
state = FallState.INACTIVE;
PoseActor poseActor = EntityUtils.getPoseActor(parent);
if(poseActor != null){
String animationToPlay = determineCorrectAnimation();
if(
!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(animationToPlay)
){
poseActor.playAnimation(animationToPlay,AnimationPriorities.LAND);
poseActor.incrementAnimationTime(0.0001);
}
}
}
}
public static ServerFallTree getFallTree(Entity parent){
return (ServerFallTree)parent.getData(EntityDataStrings.FALL_TREE);
}
String determineCorrectAnimation(){
switch(state){
case ACTIVE:
return animationFall;
case INACTIVE:
return animationLand;
default:
return animationLand;
}
}
public void setServerJumpTree(ServerJumpTree jumpTree){
this.jumpTree = jumpTree;
}
public void setAnimationFall(String animationName){
animationFall = animationName;
}
public void setAnimationLand(String animationName){
animationLand = animationName;
}
}