diff --git a/assets/Config/keybinds.json b/assets/Config/keybinds.json index 10ef1272..c5f2c4ad 100644 --- a/assets/Config/keybinds.json +++ b/assets/Config/keybinds.json @@ -126,6 +126,11 @@ "isKey": true, "isMouse": false, "keyValue": 340 + }, + "interact" : { + "isKey": true, + "isMouse": false, + "keyValue": 69 } } } \ No newline at end of file diff --git a/assets/Data/creatures.json b/assets/Data/creatures.json index 0ddfd2be..6e67a65d 100644 --- a/assets/Data/creatures.json +++ b/assets/Data/creatures.json @@ -84,7 +84,8 @@ "SENTIENT", "ATTACKER", "GRAVITY", - "TARGETABLE" + "TARGETABLE", + "CAN_EQUIP" ], "movementSystems" : [ { @@ -238,7 +239,8 @@ "SENTIENT", "ATTACKER", "GRAVITY", - "TARGETABLE" + "TARGETABLE", + "CAN_EQUIP" ], "movementSystems" : [ { diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index ae201b89..a0b32500 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -6,6 +6,7 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.AttackTree; +import electrosphere.entity.state.equip.EquipState; import electrosphere.entity.state.movement.GroundMovementTree; import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState; import electrosphere.entity.state.movement.SprintTree; @@ -46,6 +47,7 @@ public class ControlHandler { public static final String DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU = "inGameMainMenu"; public static final String DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR = "crosshairLock"; public static final String INPUT_CODE_SPRINT = "sprint"; + public static final String INPUT_CODE_INTERACT = "interact"; public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement"; public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement"; @@ -131,6 +133,7 @@ public class ControlHandler { handler.addControl(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU, new Control(true,false,GLFW_KEY_ESCAPE)); handler.addControl(DATA_STRING_INPUT_CODE_LOCK_CROSSHAIR, new Control(false,true,GLFW_MOUSE_BUTTON_RIGHT)); handler.addControl(INPUT_CODE_SPRINT, new Control(true,false,GLFW_KEY_LEFT_SHIFT)); + handler.addControl(INPUT_CODE_INTERACT, new Control(true,false,GLFW_KEY_E)); /* Map the menu navigation controls @@ -386,6 +389,28 @@ public class ControlHandler { } } + /* + Interact + */ + /* + Sprint + */ + if(controls.containsKey(INPUT_CODE_INTERACT)){ + if(controls.get(INPUT_CODE_INTERACT).isIsKey() && glfwGetKey(Globals.window, controls.get(INPUT_CODE_INTERACT).getKeyValue()) == GLFW_PRESS){ + if(controls.get(INPUT_CODE_INTERACT).isState() == false){ + if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE) && Crosshair.hasTarget()){ + EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE); + equipState.attemptEquip(Crosshair.getTarget()); + } + } + controls.get(INPUT_CODE_INTERACT).setState(true); + } else { + if(controls.get(INPUT_CODE_INTERACT).isState() == true){ + } + controls.get(INPUT_CODE_INTERACT).setState(false); + } + } + /* Attack */ diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index cdbcf211..74fb960f 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -173,6 +173,11 @@ public class EntityDataStrings { public static final String FOLIAGE_IS_FOLIAGE = "foliageIsFoliage"; public static final String FOLIAGE_TYPE = "foliageType"; + /* + Equip state + */ + public static final String EQUIP_STATE = "equipState"; + /* Entity categories */ diff --git a/src/main/java/electrosphere/entity/state/AttackTree.java b/src/main/java/electrosphere/entity/state/AttackTree.java index ea8ac9f5..69c65003 100644 --- a/src/main/java/electrosphere/entity/state/AttackTree.java +++ b/src/main/java/electrosphere/entity/state/AttackTree.java @@ -3,6 +3,7 @@ package electrosphere.entity.state; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; +import electrosphere.entity.state.equip.EquipState; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.game.data.creature.type.AttackMove; @@ -51,7 +52,7 @@ public class AttackTree { } public void start(String attackType){ - if(canAttack()){ + if(canAttack(attackType)){ parent.putData(EntityDataStrings.ATTACK_MOVE_TYPE_ACTIVE, attackType); AttackMove currentMove; switch(attackType){ @@ -277,11 +278,32 @@ public class AttackTree { networkMessageQueue.add(networkMessage); } - boolean canAttack(){ + boolean canAttack(String attackType){ boolean rVal = true; if(state != AttackTreeState.IDLE){ rVal = false; } + if(parent.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){ + EquipState equipState = (EquipState)parent.getData(EntityDataStrings.EQUIP_STATE); + if(equipState.hasEquipPrimary()){ + switch(attackType){ + case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND: + break; + default: + rVal = false; + break; + } + } else { + switch(attackType){ + case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND: + rVal = false; + break; + default: + rVal = false; + break; + } + } + } return rVal; } diff --git a/src/main/java/electrosphere/entity/state/equip/EquipState.java b/src/main/java/electrosphere/entity/state/equip/EquipState.java index dc638a21..a3090b17 100644 --- a/src/main/java/electrosphere/entity/state/equip/EquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/EquipState.java @@ -1,6 +1,8 @@ package electrosphere.entity.state.equip; import electrosphere.entity.Entity; +import electrosphere.entity.types.attach.AttachUtils; +import electrosphere.entity.types.item.ItemUtils; /** * @@ -12,12 +14,15 @@ public class EquipState { Entity equipPrimary; - public EquipState(Entity parent){ + String equipPrimaryBoneName; + + public EquipState(Entity parent, String equipPrimaryBoneName){ this.parent = parent; + this.equipPrimaryBoneName = equipPrimaryBoneName; } public boolean hasEquipPrimary(){ - return equipPrimary == null; + return equipPrimary != null; } public Entity getEquipPrimary() { @@ -28,5 +33,12 @@ public class EquipState { this.equipPrimary = equipPrimary; } + public void attemptEquip(Entity toEquip){ + if(!hasEquipPrimary() && ItemUtils.isItem(toEquip) && !AttachUtils.isAttached(toEquip)){ + equipPrimary = toEquip; + AttachUtils.attachEntityToEntityAtBone(parent, toEquip, equipPrimaryBoneName); + } + } + } diff --git a/src/main/java/electrosphere/entity/state/equip/EquipTree.java b/src/main/java/electrosphere/entity/state/equip/EquipTree.java deleted file mode 100644 index 2b6bd870..00000000 --- a/src/main/java/electrosphere/entity/state/equip/EquipTree.java +++ /dev/null @@ -1,9 +0,0 @@ -package electrosphere.entity.state.equip; - -/** - * - * @author amaterasu - */ -public class EquipTree { - -} diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 11d976fc..77a9f6e6 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -14,6 +14,7 @@ import electrosphere.entity.state.AttackTree; import electrosphere.entity.state.GravityTree; import electrosphere.entity.state.IdleTree; import electrosphere.entity.state.collidable.CollidableTree; +import electrosphere.entity.state.equip.EquipState; import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.entity.state.life.LifeState; import electrosphere.entity.state.movement.SprintTree; @@ -155,6 +156,9 @@ public class CreatureUtils { case "TARGETABLE": Globals.entityManager.registerTargetableEntity(rVal); break; + case "CAN_EQUIP": + rVal.putData(EntityDataStrings.EQUIP_STATE, new EquipState(rVal,"Bone.031")); + break; } } //add all attack moves diff --git a/src/main/java/electrosphere/game/client/targeting/crosshair/Crosshair.java b/src/main/java/electrosphere/game/client/targeting/crosshair/Crosshair.java index 12067f0b..1f003788 100644 --- a/src/main/java/electrosphere/game/client/targeting/crosshair/Crosshair.java +++ b/src/main/java/electrosphere/game/client/targeting/crosshair/Crosshair.java @@ -94,5 +94,9 @@ public class Crosshair { return EntityUtils.getPosition(currentTarget); } + public static Entity getTarget(){ + return currentTarget; + } + } diff --git a/src/main/java/electrosphere/net/server/ServerConnectionHandler.java b/src/main/java/electrosphere/net/server/ServerConnectionHandler.java index 4aa56d50..8670a67e 100644 --- a/src/main/java/electrosphere/net/server/ServerConnectionHandler.java +++ b/src/main/java/electrosphere/net/server/ServerConnectionHandler.java @@ -106,9 +106,9 @@ public class ServerConnectionHandler implements Runnable { newPlayerObject.setWorldY(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z)); Globals.dataCellManager.addPlayer(newPlayerObject); Globals.dataCellManager.movePlayer(newPlayerObject, Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x), Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z)); - //spawn player sword - Entity sword = ItemUtils.spawnBasicItem("Katana"); - AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031"); +// //spawn player sword +// Entity sword = ItemUtils.spawnBasicItem("Katana"); +// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.031"); //set controller id CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID); if(Globals.RUN_SERVER && Main.playerId == -1){