dual-hand equipping animation logic
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-08-04 16:18:35 -04:00
parent cacc8dc57f
commit 056e631240
18 changed files with 385 additions and 156 deletions

View File

@ -253,10 +253,33 @@
"equippedAnimation" : { "equippedAnimation" : {
"nameThirdPerson" : "Idle1", "nameThirdPerson" : "Idle1",
"nameFirstPerson" : "Idle", "nameFirstPerson" : "Idle",
"priorityCategory" : "MODIFIER_MAX", "priorityCategory" : "MODIFIER_HIGH",
"boneGroups" : ["handRight"] "boneGroups" : ["handRight"]
} }
}, },
{
"equipPointId" : "handsCombined",
"bone" : "Hand.R",
"firstPersonBone" : "hand.R",
"offsetVectorFirstPerson" : [-0.01,-0.05,-0.10],
"offsetVectorThirdPerson" : [0.02,-0.06,0],
"offsetRotationThirdPerson" : [-0.334,0.145,-0.28,0.89],
"offsetRotationFirstPerson" : [0.02,-0.977,-0.211,-0.005],
"canBlock" : true,
"equipClassWhitelist" : [
"tool",
"weapon2H",
"item"
],
"equippedAnimation" : {
"nameThirdPerson" : "HoldItemR2H",
"nameFirstPerson" : "HoldItemR2H",
"priorityCategory" : "MODIFIER_HIGH",
"boneGroups" : ["armLeft", "armRight", "handLeft", "handRight"]
},
"isCombinedPoint": true,
"subPoints" : ["handLeft","handRight"]
},
{ {
"equipPointId" : "Torso", "equipPointId" : "Torso",
"bone" : "Bone", "bone" : "Bone",
@ -301,6 +324,24 @@
"itemClassEquipped" : "weapon" "itemClassEquipped" : "weapon"
} }
] ]
},
{
"variantId": "block2H",
"mainAnimation" : {
"nameThirdPerson": "HoldItemR2HBlock",
"nameFirstPerson": "HoldItemR2HBlock",
"priorityCategory": "MOVEMENT_MODIFIER",
"boneGroups" : ["armLeft", "armRight", "handLeft", "handRight"]
},
"mainAudio" : {
"audioPath" : "Audio/weapons/swordUnsheath1.ogg"
},
"defaults" : [
{
"equipPoint" : "handsCombined",
"itemClassEquipped" : "weapon2H"
}
]
} }
] ]
}, },

View File

@ -78,7 +78,7 @@
] ]
}, },
"equipData": { "equipData": {
"equipClass" : "weapon" "equipClass" : "weapon2H"
}, },
"tokens" : [ "tokens" : [
"GRAVITY", "GRAVITY",

View File

@ -92,7 +92,7 @@ public class ClientSimulation {
// //
//update audio engine //update audio engine
Globals.profiler.beginCpuSample("audio engine update"); Globals.profiler.beginCpuSample("audio engine update");
if(Globals.audioEngine!=null){ if(Globals.audioEngine != null && Globals.audioEngine.initialized() && Globals.virtualAudioSourceManager != null){
Globals.audioEngine.update(); Globals.audioEngine.update();
Globals.virtualAudioSourceManager.update((float)Globals.timekeeper.getSimFrameTime()); Globals.virtualAudioSourceManager.update((float)Globals.timekeeper.getSimFrameTime());
} }

View File

@ -188,9 +188,9 @@ public class Main {
// } // }
//create the audio context //create the audio context
Globals.audioEngine = new AudioEngine();
if(Globals.RUN_CLIENT && !Globals.HEADLESS && Globals.RUN_AUDIO){ if(Globals.RUN_CLIENT && !Globals.HEADLESS && Globals.RUN_AUDIO){
Globals.virtualAudioSourceManager = new VirtualAudioSourceManager(); Globals.virtualAudioSourceManager = new VirtualAudioSourceManager();
Globals.audioEngine = new AudioEngine();
Globals.audioEngine.init(); Globals.audioEngine.init();
Globals.audioEngine.listAllDevices(); Globals.audioEngine.listAllDevices();
Globals.initDefaultAudioResources(); Globals.initDefaultAudioResources();

View File

@ -127,12 +127,12 @@ public class StateTransitionUtil {
if(parent == Globals.playerEntity && !Globals.controlHandler.cameraIsThirdPerson() && animation != null){ if(parent == Globals.playerEntity && !Globals.controlHandler.cameraIsThirdPerson() && animation != null){
//first person //first person
//play first person audio //play first person audio
if(audioData != null && audioData.getAudioPath() != null){ if(Globals.audioEngine.initialized() && audioData != null && audioData.getAudioPath() != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false); Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false);
} }
} else { } else {
//play third person audio //play third person audio
if(audioData != null && audioData.getAudioPath() != null){ if(Globals.audioEngine.initialized() && audioData != null && audioData.getAudioPath() != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent)); Globals.virtualAudioSourceManager.createVirtualAudioSource(audioData.getAudioPath(), VirtualAudioSourceType.CREATURE, false, EntityUtils.getPosition(parent));
} }
} }
@ -151,7 +151,7 @@ public class StateTransitionUtil {
//Play animation in first person //Play animation in first person
// //
if(animation != null){ if(animation != null){
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, animation); FirstPersonTree.conditionallyPlayAnimation(parent, animation);
} }
} }
} }
@ -303,21 +303,6 @@ public class StateTransitionUtil {
//Tracks whether the animation has been played or not //Tracks whether the animation has been played or not
boolean startedAnimation = false; boolean startedAnimation = false;
/**
* Gets the animation priority
* @return The animation priority
*/
int getAnimationPriority(){
int priority = AnimationPriorities.getValue(AnimationPriorities.DEFAULT);
if(animation != null && animation.getPriority() != null){
priority = animation.getPriority();
} else if(getAnimation != null && getAnimation.get().getPriority() != null){
priority = getAnimation.get().getPriority();
}
return priority;
}
/** /**
* Constructor * Constructor
*/ */

View File

@ -246,7 +246,7 @@ public class ClientAttackTree implements BehaviorTree {
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation( FirstPersonTree.conditionallyPlayAnimation(
Globals.firstPersonEntity, parent,
currentMove.getAnimationWindup() currentMove.getAnimationWindup()
); );
} }
@ -261,7 +261,7 @@ public class ClientAttackTree implements BehaviorTree {
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation( FirstPersonTree.conditionallyPlayAnimation(
Globals.firstPersonEntity, parent,
currentMove.getAnimationHold() currentMove.getAnimationHold()
); );
} }
@ -276,7 +276,7 @@ public class ClientAttackTree implements BehaviorTree {
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation( FirstPersonTree.conditionallyPlayAnimation(
Globals.firstPersonEntity, parent,
currentMove.getAnimationAttack() currentMove.getAnimationAttack()
); );
} }

View File

@ -8,6 +8,7 @@ import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.btree.StateTransitionUtil; import electrosphere.entity.btree.StateTransitionUtil;
import electrosphere.entity.btree.StateTransitionUtil.StateTransitionUtilItem; import electrosphere.entity.btree.StateTransitionUtil.StateTransitionUtilItem;
import electrosphere.game.data.creature.type.block.BlockSystem; import electrosphere.game.data.creature.type.block.BlockSystem;
import electrosphere.game.data.creature.type.block.BlockVariant;
import electrosphere.net.synchronization.BehaviorTreeIdEnums; import electrosphere.net.synchronization.BehaviorTreeIdEnums;
import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SyncedField;
@ -55,20 +56,62 @@ public class ClientBlockTree implements BehaviorTree {
this.stateTransitionUtil = StateTransitionUtil.create(parent, false, new StateTransitionUtilItem[]{ this.stateTransitionUtil = StateTransitionUtil.create(parent, false, new StateTransitionUtilItem[]{
StateTransitionUtilItem.create( StateTransitionUtilItem.create(
BlockState.WIND_UP, BlockState.WIND_UP,
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAnimation();}, () -> {
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getWindUpAudio();}, BlockVariant variant = this.blockSystem.getBlockVariant(this.currentBlockVariant);
if(variant == null){
return null;
} else {
return variant.getWindUpAnimation();
}
},
() -> {
BlockVariant variant = this.blockSystem.getBlockVariant(this.currentBlockVariant);
if(variant == null){
return null;
} else {
return variant.getWindUpAudio();
}
},
null null
), ),
StateTransitionUtilItem.create( StateTransitionUtilItem.create(
BlockState.BLOCKING, BlockState.BLOCKING,
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAnimation();}, () -> {
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getMainAudio();}, BlockVariant variant = this.blockSystem.getBlockVariant(this.currentBlockVariant);
if(variant == null){
return null;
} else {
return variant.getMainAnimation();
}
},
() -> {
BlockVariant variant = this.blockSystem.getBlockVariant(this.currentBlockVariant);
if(variant == null){
return null;
} else {
return variant.getMainAudio();
}
},
null null
), ),
StateTransitionUtilItem.create( StateTransitionUtilItem.create(
BlockState.COOLDOWN, BlockState.COOLDOWN,
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAnimation();}, () -> {
() -> {return this.blockSystem.getBlockVariant(this.currentBlockVariant).getCooldownAudio();}, BlockVariant variant = this.blockSystem.getBlockVariant(this.currentBlockVariant);
if(variant == null){
return null;
} else {
return variant.getCooldownAnimation();
}
},
() -> {
BlockVariant variant = this.blockSystem.getBlockVariant(this.currentBlockVariant);
if(variant == null){
return null;
} else {
return variant.getCooldownAudio();
}
},
null null
), ),
}); });

View File

@ -145,8 +145,8 @@ public class FirstPersonTree implements BehaviorTree {
* @param priority The priority of the animation * @param priority The priority of the animation
*/ */
public static void conditionallyPlayAnimation(Entity entity, String animationName, int priority){ public static void conditionallyPlayAnimation(Entity entity, String animationName, int priority){
if(entity != null && FirstPersonTree.hasTree(entity)){ if(entity != null && entity == Globals.playerEntity && FirstPersonTree.hasTree(Globals.firstPersonEntity)){
FirstPersonTree.getTree(entity).playAnimation(animationName, priority); FirstPersonTree.getTree(Globals.firstPersonEntity).playAnimation(animationName, priority);
} }
} }
@ -156,8 +156,8 @@ public class FirstPersonTree implements BehaviorTree {
* @param animationName the name of the animation * @param animationName the name of the animation
*/ */
public static void conditionallyPlayAnimation(Entity entity, TreeDataAnimation animation){ public static void conditionallyPlayAnimation(Entity entity, TreeDataAnimation animation){
if(entity != null && FirstPersonTree.hasTree(entity)){ if(entity != null && entity == Globals.playerEntity && FirstPersonTree.hasTree(Globals.firstPersonEntity)){
FirstPersonTree.getTree(entity).playAnimation(animation); FirstPersonTree.getTree(Globals.firstPersonEntity).playAnimation(animation);
} }
} }

View File

@ -16,10 +16,12 @@ import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags; import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.client.firstPerson.FirstPersonTree;
import electrosphere.entity.state.gravity.GravityUtils; import electrosphere.entity.state.gravity.GravityUtils;
import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.data.common.TreeDataAnimation;
import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.game.data.item.type.EquipWhitelist; import electrosphere.game.data.item.type.EquipWhitelist;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
@ -405,9 +407,23 @@ public class ClientEquipState implements BehaviorTree {
@Override @Override
public void simulate(float deltaTime) { public void simulate(float deltaTime) {
Actor thirdPersonActor = EntityUtils.getActor(parent);
//play animations for equip points that have items equipped
for(EquipPoint point : this.equipPoints){
if(this.hasEquippedAtPoint(point.getEquipPointId()) && point.getEquippedAnimation() != null){
TreeDataAnimation animation = point.getEquippedAnimation();
//play third person
if(!thirdPersonActor.isPlayingAnimation() || !thirdPersonActor.isPlayingAnimation(animation)){
if(animation != null){
thirdPersonActor.playAnimation(animation,true);
}
thirdPersonActor.incrementAnimationTime(0.0001);
}
//play first person
FirstPersonTree.conditionallyPlayAnimation(parent, animation);
}
}
} }

View File

@ -31,6 +31,7 @@ import electrosphere.game.data.creature.type.block.BlockSystem;
import electrosphere.game.data.creature.type.block.BlockVariant; import electrosphere.game.data.creature.type.block.BlockVariant;
import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.game.data.item.type.EquipWhitelist; import electrosphere.game.data.item.type.EquipWhitelist;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.parser.net.message.InventoryMessage; import electrosphere.net.parser.net.message.InventoryMessage;
import electrosphere.net.parser.net.message.NetworkMessage; import electrosphere.net.parser.net.message.NetworkMessage;
import electrosphere.net.server.player.Player; import electrosphere.net.server.player.Player;
@ -411,7 +412,11 @@ public class ServerEquipState implements BehaviorTree {
//TODO: refactor to allow sending more than one variant at a time //TODO: refactor to allow sending more than one variant at a time
//ie if you have two items equipped and you want to block with both //ie if you have two items equipped and you want to block with both
blockTree.setCurrentBlockVariant(blockVariant.getVariantId()); if(blockVariant != null){
blockTree.setCurrentBlockVariant(blockVariant.getVariantId());
} else {
LoggerInterface.loggerEngine.ERROR(new IllegalStateException("Equipped item to equip point that does not have assigned block variant!!"));
}
} }
} }
} }

View File

@ -93,7 +93,7 @@ public class ClientIdleTree implements BehaviorTree {
entityActor.playAnimation(idleData.getAnimation(),true); entityActor.playAnimation(idleData.getAnimation(),true);
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, idleData.getAnimation()); FirstPersonTree.conditionallyPlayAnimation(parent, idleData.getAnimation());
} }
break; break;
case NOT_IDLE: case NOT_IDLE:

View File

@ -8,6 +8,7 @@ import java.util.Map;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.logger.LoggerInterface;
public class RelationalInventoryState { public class RelationalInventoryState {
@ -80,6 +81,12 @@ public class RelationalInventoryState {
return null; return null;
} }
/**
* Checks if the inventory can equip the item to the given slot
* @param item The item
* @param slot The slot
* @return true if can equip, false otherwise
*/
public boolean canEquipItemToSlot(Entity item, String slot){ public boolean canEquipItemToSlot(Entity item, String slot){
String itemClass = ItemUtils.getEquipClass(item); String itemClass = ItemUtils.getEquipClass(item);
if(slotWhitelists.get(slot).contains(itemClass)){ if(slotWhitelists.get(slot).contains(itemClass)){
@ -88,8 +95,62 @@ public class RelationalInventoryState {
return false; return false;
} }
/**
* Gets an equip point from a given slot name
* @param slot The name of the slot
* @return The equip point
*/
public EquipPoint getEquipPointFromSlot(String slot){ public EquipPoint getEquipPointFromSlot(String slot){
return equipPoints.get(slot); return equipPoints.get(slot);
} }
/**
* Gets whether the item can equipped to a combined slot that contains the singular slot provided
* @param item The item
* @param slot The singular (non-combined) slot
* @return true if there is a combined slot that includes slot which can equip the item, false otherwise
*/
public boolean canEquipItemToCombinedSlot(Entity item, String slot){
String itemClass = ItemUtils.getEquipClass(item);
EquipPoint singlePoint = getEquipPointFromSlot(slot);
EquipPoint combinedPoint = null;
for(String currentPointNames : this.equipPoints.keySet()){
EquipPoint currentPoint = this.equipPoints.get(currentPointNames);
if(currentPoint.isCombinedPoint() && currentPoint.getSubPoints().contains(singlePoint.getEquipPointId())){
combinedPoint = currentPoint;
break;
}
}
if(combinedPoint != null){
for(String equipClassWhitelisted : combinedPoint.getEquipClassWhitelist()){
if(equipClassWhitelisted.equalsIgnoreCase(itemClass) && !equipClassWhitelisted.equals(itemClass)){
String message = "Combined equip point passed over because the item class for the equip point does not match the item's defined item class\n" +
"However, the difference is only in capitalization! Equip point defined class:" + equipClassWhitelisted + " Item-defined class:" + itemClass;
;
LoggerInterface.loggerEngine.WARNING(message);
}
}
if(combinedPoint.getEquipClassWhitelist().contains(itemClass)){
return true;
}
}
return false;
}
/**
* Gets the combined point that contains this point
* @param slot The singular (non-combined) slot
* @return The combined point if it exists, null otherwise
*/
public EquipPoint getCombinedPoint(String slot){
EquipPoint singlePoint = getEquipPointFromSlot(slot);
for(String currentPointNames : this.equipPoints.keySet()){
EquipPoint currentPoint = this.equipPoints.get(currentPointNames);
if(currentPoint.isCombinedPoint() && currentPoint.getSubPoints().contains(singlePoint.getEquipPointId())){
return currentPoint;
}
}
return null;
}
} }

View File

@ -97,7 +97,7 @@ public class FallTree implements BehaviorTree {
entityActor.playAnimation(fallMovementSystem.getLandState().getAnimation().getNameThirdPerson(),AnimationPriorities.getValue(AnimationPriorities.MOVEMENT_MODIFIER)); entityActor.playAnimation(fallMovementSystem.getLandState().getAnimation().getNameThirdPerson(),AnimationPriorities.getValue(AnimationPriorities.MOVEMENT_MODIFIER));
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, fallMovementSystem.getLandState().getAnimation()); FirstPersonTree.conditionallyPlayAnimation(parent, fallMovementSystem.getLandState().getAnimation());
} }
} }
} }

View File

@ -298,7 +298,7 @@ public class ClientGroundMovementTree implements BehaviorTree {
entityActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT)); entityActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT));
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, groundMovementData.getAnimationStartup().getNameFirstPerson(), AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT)); FirstPersonTree.conditionallyPlayAnimation(parent, groundMovementData.getAnimationStartup().getNameFirstPerson(), AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT));
} }
//run startup code //run startup code
velocity = velocity + acceleration * (float)Globals.timekeeper.getSimFrameTime(); velocity = velocity + acceleration * (float)Globals.timekeeper.getSimFrameTime();
@ -332,7 +332,7 @@ public class ClientGroundMovementTree implements BehaviorTree {
entityActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT)); entityActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT));
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, groundMovementData.getAnimationLoop().getNameFirstPerson(), AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT)); FirstPersonTree.conditionallyPlayAnimation(parent, groundMovementData.getAnimationLoop().getNameFirstPerson(), AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT));
} }
if(velocity != maxNaturalVelocity){ if(velocity != maxNaturalVelocity){
velocity = maxNaturalVelocity; velocity = maxNaturalVelocity;
@ -360,7 +360,7 @@ public class ClientGroundMovementTree implements BehaviorTree {
entityActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT)); entityActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT));
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, groundMovementData.getAnimationWindDown().getNameFirstPerson(), AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT)); FirstPersonTree.conditionallyPlayAnimation(parent, groundMovementData.getAnimationWindDown().getNameFirstPerson(), AnimationPriorities.getValue(AnimationPriorities.CORE_MOVEMENT));
} }
//velocity stuff //velocity stuff
velocity = velocity - acceleration * (float)Globals.timekeeper.getSimFrameTime(); velocity = velocity - acceleration * (float)Globals.timekeeper.getSimFrameTime();

View File

@ -96,7 +96,7 @@ public class ClientJumpTree implements BehaviorTree {
entityActor.playAnimation(jumpData.getAnimationJump().getNameThirdPerson(),AnimationPriorities.getValue(AnimationPriorities.MOVEMENT_MODIFIER)); entityActor.playAnimation(jumpData.getAnimationJump().getNameThirdPerson(),AnimationPriorities.getValue(AnimationPriorities.MOVEMENT_MODIFIER));
entityActor.incrementAnimationTime(0.0001); entityActor.incrementAnimationTime(0.0001);
} }
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, jumpData.getAnimationJump()); FirstPersonTree.conditionallyPlayAnimation(parent, jumpData.getAnimationJump());
} }
//stop body falling if it is //stop body falling if it is
DBody body = PhysicsEntityUtils.getDBody(parent); DBody body = PhysicsEntityUtils.getDBody(parent);

View File

@ -2,6 +2,8 @@ package electrosphere.game.data.creature.type.block;
import java.util.List; import java.util.List;
import electrosphere.logger.LoggerInterface;
/** /**
* Stores data related to an entity blocking attacks * Stores data related to an entity blocking attacks
*/ */
@ -10,6 +12,7 @@ public class BlockSystem {
//blocking with a weapon equipped in the right hand //blocking with a weapon equipped in the right hand
//NOTE: the names provided here should line up with the actual field names on this object //NOTE: the names provided here should line up with the actual field names on this object
public static final String BLOCK_VARIANT_WEAPON_RIGHT = "blockWeaponRight"; public static final String BLOCK_VARIANT_WEAPON_RIGHT = "blockWeaponRight";
public static final String BLOCK_VARIANT_WEAPON_2H = "block2H";
//the list of block variants //the list of block variants
List<BlockVariant> variants; List<BlockVariant> variants;
@ -45,6 +48,12 @@ public class BlockSystem {
public BlockVariant getVariantForPointWithItem(String equipPoint, String itemClass){ public BlockVariant getVariantForPointWithItem(String equipPoint, String itemClass){
for(BlockVariant variant : variants){ for(BlockVariant variant : variants){
for(VariantDefaults variantDefault : variant.getDefaults()){ for(VariantDefaults variantDefault : variant.getDefaults()){
if(variantDefault.itemClassEquipped.equalsIgnoreCase(itemClass) && !variantDefault.itemClassEquipped.equals(itemClass)){
String message = "Block variant passed over because the item class for the block variant does not match the item's defined item class\n" +
"However, the difference is only in capitalization! Block-variant defined class:" + variantDefault.itemClassEquipped + " Item-defined class:" + itemClass;
;
LoggerInterface.loggerEngine.WARNING(message);
}
if(variantDefault.equipPoint.equals(equipPoint) && variantDefault.itemClassEquipped.equals(itemClass)){ if(variantDefault.equipPoint.equals(equipPoint) && variantDefault.itemClassEquipped.equals(itemClass)){
return variant; return variant;
} }

View File

@ -39,6 +39,45 @@ public class EquipPoint {
//The animation to play when this equip point has an item equipped (ie if a hand is grasping something) //The animation to play when this equip point has an item equipped (ie if a hand is grasping something)
TreeDataAnimation equippedAnimation; TreeDataAnimation equippedAnimation;
/**
*
*
* COMBINED EQUIP POINTS
*
* The idea of a combined equip point is that it is a combination of multiple single equip points.
* Think of equipping an item in both the left and right hands of a character at once (ie a two handed sword).
*
*/
/**
* Indicates whether this is a conbined equip point or not
*/
boolean isCombinedPoint;
/**
* The list of points that are contained within a combined equip point
*/
List<String> subPoints;
/** /**
* Gets the equip point id * Gets the equip point id
* @return the id of the equip point * @return the id of the equip point
@ -152,5 +191,21 @@ public class EquipPoint {
public TreeDataAnimation getEquippedAnimation(){ public TreeDataAnimation getEquippedAnimation(){
return equippedAnimation; return equippedAnimation;
} }
/**
* Checks whether this is a combined equip point or not
* @return true if this is a combined equip point, false otherwise
*/
public boolean isCombinedPoint(){
return this.isCombinedPoint;
}
/**
* Gets the list of sub point ids that are contained within a combined point
* @return The list of sub point ids
*/
public List<String> getSubPoints(){
return this.subPoints;
}
} }

View File

@ -11,6 +11,7 @@ import electrosphere.entity.state.inventory.InventoryUtils;
import electrosphere.entity.state.inventory.RelationalInventoryState; import electrosphere.entity.state.inventory.RelationalInventoryState;
import electrosphere.entity.state.inventory.UnrelationalInventoryState; import electrosphere.entity.state.inventory.UnrelationalInventoryState;
import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.menu.WindowStrings; import electrosphere.menu.WindowStrings;
import electrosphere.menu.WindowUtils; import electrosphere.menu.WindowUtils;
import electrosphere.renderer.ui.elements.Div; import electrosphere.renderer.ui.elements.Div;
@ -275,128 +276,141 @@ public class MenuGeneratorsInventory {
List<String> slots = inventory.getSlots(); List<String> slots = inventory.getSlots();
int numSlots = slots.size(); int numSlots = slots.size();
EquipPoint equipPoint = null;
// int numRows = (numSlots / 2) + (numSlots % 2 == 1 ? 1 : 0); // int numRows = (numSlots / 2) + (numSlots % 2 == 1 ? 1 : 0);
int incrementer = 0; int incrementer = 0;
for(int i = 0; i < numSlots; i++){ for(int i = 0; i < numSlots; i++){
String texturePath = "Textures/icons/itemIconEmpty.png"; String texturePath = "Textures/icons/itemIconEmpty.png";
boolean hasItem = false; boolean hasItem = false;
if(inventory.getItemSlot(slots.get(i)) != null){ equipPoint = inventory.getEquipPointFromSlot(slots.get(i));
Entity currentItem = inventory.getItemSlot(slots.get(i)); if(!equipPoint.isCombinedPoint()){
//get texture path from item if(inventory.getItemSlot(slots.get(i)) != null){
texturePath = ItemUtils.getItemIcon(currentItem); Entity currentItem = inventory.getItemSlot(slots.get(i));
//flag that this isn't an empty slot //get texture path from item
hasItem = true; texturePath = ItemUtils.getItemIcon(currentItem);
} //flag that this isn't an empty slot
if(!Globals.assetManager.hasLoadedTexture(texturePath)){ hasItem = true;
Globals.assetManager.addTexturePathtoQueue(texturePath); }
} if(!Globals.assetManager.hasLoadedTexture(texturePath)){
int panelWidth = 50; Globals.assetManager.addTexturePathtoQueue(texturePath);
int panelHeight = 50; }
int posX = 20; int panelWidth = 50;
if((incrementer % 2) == 1){ int panelHeight = 50;
posX = posX + 400; int posX = 20;
} if((incrementer % 2) == 1){
int posY = 60 + (i / 2 * (panelHeight + slotSpacing)); posX = posX + 400;
int itemPosX = posX; }
int itemPosY = posY; int posY = 60 + (i / 2 * (panelHeight + slotSpacing));
ImagePanel panel = new ImagePanel(posX,posY,panelWidth,panelHeight,texturePath); int itemPosX = posX;
panel.setAbsolutePosition(true); int itemPosY = posY;
if(hasItem == true){ ImagePanel panel = new ImagePanel(posX,posY,panelWidth,panelHeight,texturePath);
int itemId = i; panel.setAbsolutePosition(true);
panel.setOnDragStart(new DragEventCallback() {public boolean execute(DragEvent event){ if(hasItem == true){
// System.out.println("Drag start"); int itemId = i;
Globals.dragSourceInventory = inventory; panel.setOnDragStart(new DragEventCallback() {public boolean execute(DragEvent event){
Globals.draggedItem = inventory.getItemSlot(slots.get(itemId)); // System.out.println("Drag start");
ContainerElement container = (ContainerElement)panel.getParent(); Globals.dragSourceInventory = inventory;
container.removeChild(panel); Globals.draggedItem = inventory.getItemSlot(slots.get(itemId));
WindowUtils.pushItemIconToItemWindow(panel); ContainerElement container = (ContainerElement)panel.getParent();
//play sound effect container.removeChild(panel);
if(Globals.virtualAudioSourceManager != null){ WindowUtils.pushItemIconToItemWindow(panel);
Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/inventoryGrabItem.ogg", VirtualAudioSourceType.UI, false); //play sound effect
} if(Globals.virtualAudioSourceManager != null){
return false; Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/inventoryGrabItem.ogg", VirtualAudioSourceType.UI, false);
}});
panel.setOnDrag(new DragEventCallback() {public boolean execute(DragEvent event){
// System.out.println("Drag");
panel.setPositionX(event.getCurrentX() - panelWidth / 2);
panel.setPositionY(event.getCurrentY() - panelHeight / 2);
return false;
}});
panel.setOnDragRelease(new DragEventCallback(){public boolean execute(DragEvent event){
if(panel.getParent() != div){
if(panel.getParent() != null){
ContainerElement container = (ContainerElement)panel.getParent();
container.removeChild(panel);
} }
div.addChild(panel); return false;
Globals.elementManager.fireEvent(event, panel.getAbsoluteX(), panel.getAbsoluteY()); }});
} panel.setOnDrag(new DragEventCallback() {public boolean execute(DragEvent event){
panel.setPositionX(div.getAbsoluteX() + itemPosX); // System.out.println("Drag");
panel.setPositionY(div.getAbsoluteY() + itemPosY); panel.setPositionX(event.getCurrentX() - panelWidth / 2);
return false; panel.setPositionY(event.getCurrentY() - panelHeight / 2);
}}); return false;
}});
} else { panel.setOnDragRelease(new DragEventCallback(){public boolean execute(DragEvent event){
int itemId = i; if(panel.getParent() != div){
panel.setOnDragRelease(new DragEventCallback(){public boolean execute(DragEvent event){ if(panel.getParent() != null){
// panel.setPositionX(posX); ContainerElement container = (ContainerElement)panel.getParent();
// panel.setPositionY(posY); container.removeChild(panel);
if(Globals.dragSourceInventory instanceof UnrelationalInventoryState){
UnrelationalInventoryState sourceInventory = (UnrelationalInventoryState) Globals.dragSourceInventory;
Entity item = Globals.draggedItem;
if(inventory.canEquipItemToSlot(item, slots.get(itemId))){
//fire equip event to equip state
ClientEquipState equipState = ClientEquipState.getEquipState(Globals.playerEntity);
equipState.commandAttemptEquip(item,inventory.getEquipPointFromSlot(slots.get(itemId)));
//play sound effect
if(Globals.virtualAudioSourceManager != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/inventorySlotItem.ogg", VirtualAudioSourceType.UI, false);
} }
div.addChild(panel);
Globals.elementManager.fireEvent(event, panel.getAbsoluteX(), panel.getAbsoluteY());
} }
//update ui panel.setPositionX(div.getAbsoluteX() + itemPosX);
Globals.dragSourceInventory = null; panel.setPositionY(div.getAbsoluteY() + itemPosY);
Globals.draggedItem = null; return false;
//clear item container ui }});
WindowUtils.cleanItemDraggingWindow();
//rerender both inventories } else {
//re-render inventory int itemId = i;
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGeneratorsInventory.createCharacterInventoryMenu(inventory)); panel.setOnDragRelease(new DragEventCallback(){public boolean execute(DragEvent event){
//re-render inventory // panel.setPositionX(posX);
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(sourceInventory.getId()), MenuGeneratorsInventory.createNaturalInventoryMenu(sourceInventory)); // panel.setPositionY(posY);
} if(Globals.dragSourceInventory instanceof UnrelationalInventoryState){
//now the fun begins :) UnrelationalInventoryState sourceInventory = (UnrelationalInventoryState) Globals.dragSourceInventory;
//if transfer item Entity item = Globals.draggedItem;
// remove item from current inventory if(inventory.canEquipItemToSlot(item, slots.get(itemId))){
// place item in new inventory //fire equip event to equip state
// trigger recreation of the menu ClientEquipState equipState = ClientEquipState.getEquipState(Globals.playerEntity);
//if drop item equipState.commandAttemptEquip(item,inventory.getEquipPointFromSlot(slots.get(itemId)));
// remove item from current inventory //play sound effect
// create item in world in front of character if(Globals.virtualAudioSourceManager != null){
// trigger recreation of the menu Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/inventorySlotItem.ogg", VirtualAudioSourceType.UI, false);
//if neither of above }
// replace item icon position to origin } else if(inventory.canEquipItemToCombinedSlot(item, slots.get(itemId))){
// System.out.println("Release drag"); EquipPoint combinedPoint = inventory.getCombinedPoint(slots.get(itemId));
//rebuild inventory windows //fire equip event to equip state
return false; ClientEquipState equipState = ClientEquipState.getEquipState(Globals.playerEntity);
}}); equipState.commandAttemptEquip(item,combinedPoint);
} //play sound effect
div.addChild(panel); if(Globals.virtualAudioSourceManager != null){
Globals.virtualAudioSourceManager.createVirtualAudioSource("/Audio/inventorySlotItem.ogg", VirtualAudioSourceType.UI, false);
}
}
//update ui
Globals.dragSourceInventory = null;
Globals.draggedItem = null;
//clear item container ui
WindowUtils.cleanItemDraggingWindow();
//rerender both inventories
//re-render inventory
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGeneratorsInventory.createCharacterInventoryMenu(inventory));
//re-render inventory
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(sourceInventory.getId()), MenuGeneratorsInventory.createNaturalInventoryMenu(sourceInventory));
}
//now the fun begins :)
//if transfer item
// remove item from current inventory
// place item in new inventory
// trigger recreation of the menu
//if drop item
// remove item from current inventory
// create item in world in front of character
// trigger recreation of the menu
//if neither of above
// replace item icon position to origin
// System.out.println("Release drag");
//rebuild inventory windows
return false;
}});
}
div.addChild(panel);
//create the slot text //create the slot text
posX = 80; posX = 80;
if((incrementer % 2) == 1){ if((incrementer % 2) == 1){
posX = posX + 190; posX = posX + 190;
} }
posY = posY + 15; posY = posY + 15;
Label slotText = new Label(0.7f); Label slotText = new Label(0.7f);
slotText.setText(slots.get(i)); slotText.setText(slots.get(i));
slotText.setPositionX(posX); slotText.setPositionX(posX);
slotText.setPositionY(posY); slotText.setPositionY(posY);
slotText.setAbsolutePosition(true); slotText.setAbsolutePosition(true);
div.addChild(slotText); div.addChild(slotText);
incrementer++; incrementer++;
}
} }
return rVal; return rVal;