diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index 826735db..3e0b7e8e 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -55,7 +55,8 @@ "ATTACKER", "GRAVITY", "TARGETABLE", - "CAN_EQUIP" + "CAN_EQUIP", + "INVENTORY" ], "visualAttributes" : [], "movementSystems" : [ @@ -131,6 +132,50 @@ } ] }, + "equipPoints" : [ + { + "equipPointId" : "handLeft", + "bone" : "MiddleLower.L", + "offsetVector" : [], + "offsetRotation" : [], + "equipClassWhitelist" : [ + "tool", + "shield", + "item" + ] + }, + { + "equipPointId" : "handRight", + "bone" : "MiddleLower.R", + "offsetVector" : [], + "offsetRotation" : [], + "equipClassWhitelist" : [ + "tool", + "weapon", + "item" + ] + }, + { + "equipPointId" : "Torso", + "bone" : "Bone", + "offsetVector" : [], + "offsetRotation" : [], + "equipClassWhitelist" : [ + "armor", + "clothing" + ] + }, + { + "equipPointId" : "Legs", + "bone" : "Bone", + "offsetVector" : [], + "offsetRotation" : [], + "equipClassWhitelist" : [ + "armor", + "clothing" + ] + } + ], "collidable" : { "type" : "CYLINDER", "dimension1" : 0.1, diff --git a/assets/Data/items.json b/assets/Data/items.json index d022a782..e3513492 100644 --- a/assets/Data/items.json +++ b/assets/Data/items.json @@ -26,10 +26,10 @@ "tokens" : [ "GRAVITY", "BLENDER_TRANSFORM", - "WEAPON", "MELEE", "TARGETABLE" ], + "equipClass" : "weapon", "idleAnim" : "Sword|Idle", "collidable": { "type" : "CUBE", @@ -39,36 +39,18 @@ "offsetX" : 0, "offsetY" : 0.05, "offsetZ" : 0 - } + }, + "iconPath" : "Textures/icons/itemIconWeapon.png" }, { "itemId" : "Bow", "modelPath": "Models/bow1.fbx", "tokens" : [ "GRAVITY", - "WEAPON", "RANGED", "TARGETABLE" ], - "collidable": { - "type" : "CUBE", - "dimension1" : 0.1, - "dimension2" : 0.1, - "dimension3" : 0.35, - "offsetX" : 0, - "offsetY" : 0.05, - "offsetZ" : 0 - } - }, - - { - "itemId" : "shorts1", - "modelPath": "Models/itemEntityShorts.fbx", - "tokens" : [ - "GRAVITY", - "ARMOR", - "TARGETABLE" - ], + "equipClass" : "weapon", "collidable": { "type" : "CUBE", "dimension1" : 0.1, @@ -78,6 +60,27 @@ "offsetY" : 0.05, "offsetZ" : 0 }, + "iconPath" : "Textures/icons/itemIconWeapon.png" + }, + + { + "itemId" : "shorts1", + "modelPath": "Models/itemEntityShorts.fbx", + "tokens" : [ + "GRAVITY", + "TARGETABLE" + ], + "equipClass" : "clothing", + "collidable": { + "type" : "CUBE", + "dimension1" : 0.1, + "dimension2" : 0.1, + "dimension3" : 0.35, + "offsetX" : 0, + "offsetY" : 0.05, + "offsetZ" : 0 + }, + "iconPath" : "Textures/icons/itemIconItemGeneric.png", "equipWhitelist" : [ { "creatureId" : "human", @@ -100,6 +103,7 @@ "ARMOR", "TARGETABLE" ], + "equipClass" : "trait", "collidable": { "type" : "CUBE", "dimension1" : 0.1, @@ -109,6 +113,7 @@ "offsetY" : 0.05, "offsetZ" : 0 }, + "iconPath" : "Textures/icons/itemIconItemGeneric.png", "equipWhitelist" : [ { "creatureId" : "human", @@ -129,6 +134,7 @@ "ARMOR", "TARGETABLE" ], + "equipClass" : "clothing", "collidable": { "type" : "CUBE", "dimension1" : 0.1, @@ -138,6 +144,7 @@ "offsetY" : 0.05, "offsetZ" : 0 }, + "iconPath" : "Textures/icons/itemIconItemGeneric.png", "equipWhitelist" : [ { "creatureId" : "human", @@ -164,6 +171,7 @@ "ARMOR", "TARGETABLE" ], + "equipClass" : "clothing", "collidable": { "type" : "CUBE", "dimension1" : 0.1, @@ -173,6 +181,7 @@ "offsetY" : 0.05, "offsetZ" : 0 }, + "iconPath" : "Textures/icons/itemIconItemGeneric.png", "equipWhitelist" : [ { "creatureId" : "human", diff --git a/assets/Textures/icons/itemIconEmpty.png b/assets/Textures/icons/itemIconEmpty.png new file mode 100644 index 00000000..19e4625e Binary files /dev/null and b/assets/Textures/icons/itemIconEmpty.png differ diff --git a/assets/Textures/icons/itemIconItemGeneric.png b/assets/Textures/icons/itemIconItemGeneric.png new file mode 100644 index 00000000..a3c9be78 Binary files /dev/null and b/assets/Textures/icons/itemIconItemGeneric.png differ diff --git a/assets/Textures/icons/itemIconWeapon.png b/assets/Textures/icons/itemIconWeapon.png new file mode 100644 index 00000000..c60fc50f Binary files /dev/null and b/assets/Textures/icons/itemIconWeapon.png differ diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index d7862e53..c3a80db4 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -8,6 +8,8 @@ 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.inventory.InventoryUtils; +import electrosphere.entity.state.inventory.UnrelationalInventoryState; import electrosphere.entity.state.movement.GroundMovementTree; import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing; import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState; @@ -51,6 +53,7 @@ public class ControlHandler { public static final String INPUT_CODE_SPRINT = "sprint"; public static final String INPUT_CODE_INTERACT = "interact"; public static final String INPUT_CODE_DROP = "drop"; + public static final String INPUT_CODE_INVENTORY_OPEN = "inventoryOpen"; public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement"; public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement"; @@ -97,6 +100,9 @@ public class ControlHandler { public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_X = "menuTypeX"; public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_Y = "menuTypeY"; public static final String DATA_STRING_INPUT_CODE_MENU_TYPE_Z = "menuTypeZ"; + + public static final String INPUT_CODE_INVENTORY_CLOSE = "inventoryClose"; + public static final String INPUT_CODE_INVENTORY_ITEM_MANIPULATE = "inventoryItemManipulate"; public static enum ControlsState { @@ -104,6 +110,7 @@ public class ControlHandler { TITLE_MENU, MAIN_GAME, IN_GAME_MAIN_MENU, + INVENTORY, NO_INPUT, } @@ -117,6 +124,7 @@ public class ControlHandler { List mainGameDebugControlList = new LinkedList(); List menuNavigationControlList = new LinkedList(); List typingControlList = new LinkedList(); + List inventoryControlList = new LinkedList(); ControlHandler(){ controls = new HashMap(); @@ -145,6 +153,7 @@ public class ControlHandler { 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)); handler.addControl(INPUT_CODE_DROP, new Control(true,false,GLFW_KEY_Y)); + handler.addControl(INPUT_CODE_INVENTORY_OPEN, new Control(true,false,GLFW_KEY_I)); /* Map the menu navigation controls @@ -195,6 +204,12 @@ public class ControlHandler { handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_X, new Control(true,false,GLFW_KEY_X)); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Y, new Control(true,false,GLFW_KEY_Y)); handler.addControl(DATA_STRING_INPUT_CODE_MENU_TYPE_Z, new Control(true,false,GLFW_KEY_Z)); + + /* + Inventory controls + */ + handler.addControl(INPUT_CODE_INVENTORY_CLOSE, new Control(true,false,GLFW_KEY_I)); + handler.addControl(INPUT_CODE_INVENTORY_ITEM_MANIPULATE, new Control(false,true,GLFW_MOUSE_BUTTON_1)); /* set state @@ -248,6 +263,10 @@ public class ControlHandler { runHandlers(menuNavigationControlList); // pollMenuNavigationControls(); break; + + case INVENTORY: + runHandlers(inventoryControlList); + break; case NO_INPUT: break; @@ -261,6 +280,7 @@ public class ControlHandler { setInGameDebugControls(); setMenuNavigationControls(); setTypingControls(); + setInventoryControls(); } void setMainGameControls(){ @@ -541,8 +561,13 @@ public class ControlHandler { controls.get(INPUT_CODE_INTERACT).setOnPress(new ControlMethod(){public void execute(){ if(Globals.playerCharacter != null){ if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE) && Crosshair.hasTarget()){ - EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE); - equipState.attemptEquip(Crosshair.getTarget()); + if(InventoryUtils.hasNaturalInventory(Globals.playerCharacter)){ + InventoryUtils.attemptStoreItem(Globals.playerCharacter, Crosshair.getTarget()); + // UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerCharacter); + // inventory.addItem(Crosshair.getTarget()); + } + // EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE); + // // equipState.attemptEquip(Crosshair.getTarget()); } } }}); @@ -554,8 +579,13 @@ public class ControlHandler { controls.get(INPUT_CODE_DROP).setOnPress(new ControlMethod(){public void execute(){ if(Globals.playerCharacter != null){ if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){ - EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE); - equipState.drop(); + // EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE); + // equipState.drop(); + UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerCharacter); + if(inventory.getItems().size() > 0){ + Entity itemToDrop = inventory.getItems().get(0); + InventoryUtils.attemptEjectItem(Globals.playerCharacter,itemToDrop); + } } } }}); @@ -602,6 +632,20 @@ public class ControlHandler { Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU); }}); + /* + Open inventory + */ + mainGameControlList.add(controls.get(INPUT_CODE_INVENTORY_OPEN)); + controls.get(INPUT_CODE_INVENTORY_OPEN).setOnPress(new ControlMethod(){public void execute(){ + if(InventoryUtils.hasNaturalInventory(Globals.playerCharacter)){ + UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerCharacter); + Globals.currentMenu = MenuUtils.createNaturalInventoryMenu(inventory); + MenuUtils.makeMenuDrawable(Globals.currentMenu); + Globals.controlHandler.setHandlerState(ControlsState.INVENTORY); + Globals.controlHandler.showMouse(); + } + }}); + } void setInGameDebugControls(){ @@ -734,6 +778,23 @@ public class ControlHandler { // } } } + + void setInventoryControls(){ + /* + Close inventory + */ + inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_CLOSE)); + controls.get(INPUT_CODE_INVENTORY_CLOSE).setOnPress(new ControlMethod(){public void execute(){ + MenuTransition.backout(Globals.currentMenu); + }}); + /* + Item manipulation + */ + inventoryControlList.add(controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE)); + controls.get(INPUT_CODE_INVENTORY_ITEM_MANIPULATE).setOnPress(new ControlMethod(){public void execute(){ + + }}); + } public Control getControl(String controlName){ return controls.get(controlName); diff --git a/src/main/java/electrosphere/engine/assetmanager/AssetManager.java b/src/main/java/electrosphere/engine/assetmanager/AssetManager.java index 128f3461..44d89f43 100644 --- a/src/main/java/electrosphere/engine/assetmanager/AssetManager.java +++ b/src/main/java/electrosphere/engine/assetmanager/AssetManager.java @@ -160,6 +160,10 @@ public class AssetManager { texturesLoadedIntoMemory.put(rVal,t); return rVal; } + + public boolean hasLoadedTexture(String path){ + return texturesLoadedIntoMemory.containsKey(path); + } diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 3707fd9a..091fabc6 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -125,6 +125,8 @@ public class EntityDataStrings { public static final String COLLIDABLE_TREE = "collidableTree"; public static final String HITBOX_DATA = "hitboxData"; + public static final String HITBOX_ASSOCIATED_LIST = "hitboxAssociatedList"; + public static final String HURTBOX_ASSOCIATED_LIST = "hurtboxAssociatedList"; /* @@ -143,6 +145,7 @@ public class EntityDataStrings { public static final String ITEM_IS_WEAPON = "itemIsWeapon"; public static final String ITEM_IS_ARMOR = "itemIsArmor"; public static final String ITEM_EQUIP_WHITELIST = "itemEquipWhitelist"; + public static final String ITEM_ICON = "itemIcon"; /* @@ -186,6 +189,12 @@ public class EntityDataStrings { Equip state */ public static final String EQUIP_STATE = "equipState"; + public static final String EQUIP_INVENTORY = "equipInventory"; + + /* + Inventory in general + */ + public static final String NATURAL_INVENTORY = "inventoryNatural"; /* Entity categories diff --git a/src/main/java/electrosphere/entity/state/AttackTree.java b/src/main/java/electrosphere/entity/state/AttackTree.java index 21e46372..4cb9581c 100644 --- a/src/main/java/electrosphere/entity/state/AttackTree.java +++ b/src/main/java/electrosphere/entity/state/AttackTree.java @@ -190,11 +190,10 @@ public class AttackTree { if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){ List attachedEntities = (List)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST); for(Entity currentAttached : attachedEntities){ - if(currentAttached.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM)){ - for(Entity hitbox : Globals.hitboxManager.getAllHitboxes()){ - if(hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT) == currentAttached){ - HitboxUtils.getHitboxData(hitbox).setActive(true); - } + if(currentAttached.getDataKeys().contains(EntityDataStrings.HITBOX_ASSOCIATED_LIST)){ + List hitboxes = HitboxUtils.getHitboxAssociatedList(currentAttached); + for(Entity hitbox : hitboxes){ + HitboxUtils.getHitboxData(hitbox).setActive(true); } } } @@ -239,11 +238,10 @@ public class AttackTree { if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){ List attachedEntities = (List)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST); for(Entity currentAttached : attachedEntities){ - if(currentAttached.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM)){ - for(Entity hitbox : Globals.hitboxManager.getAllHitboxes()){ - if(hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT) == currentAttached){ - HitboxUtils.getHitboxData(hitbox).setActive(false); - } + if(currentAttached.getDataKeys().contains(EntityDataStrings.HITBOX_ASSOCIATED_LIST)){ + List hitboxes = HitboxUtils.getHitboxAssociatedList(currentAttached); + for(Entity hitbox : hitboxes){ + HitboxUtils.getHitboxData(hitbox).setActive(false); } } } @@ -305,24 +303,24 @@ public class AttackTree { } else { 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; - } - } + // 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/collidable/CollidableTree.java b/src/main/java/electrosphere/entity/state/collidable/CollidableTree.java index c2d98a38..0fe28b2a 100644 --- a/src/main/java/electrosphere/entity/state/collidable/CollidableTree.java +++ b/src/main/java/electrosphere/entity/state/collidable/CollidableTree.java @@ -4,7 +4,7 @@ import electrosphere.collision.dispatch.CollisionObject; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; -import electrosphere.entity.state.GravityTree; +import electrosphere.entity.state.gravity.GravityTree; import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.collidable.Collidable; import electrosphere.game.data.creature.type.CollidableTemplate; diff --git a/src/main/java/electrosphere/entity/state/equip/EquipState.java b/src/main/java/electrosphere/entity/state/equip/EquipState.java index 1fd82422..fff9ab5f 100644 --- a/src/main/java/electrosphere/entity/state/equip/EquipState.java +++ b/src/main/java/electrosphere/entity/state/equip/EquipState.java @@ -1,6 +1,9 @@ package electrosphere.entity.state.equip; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import electrosphere.collision.dispatch.CollisionObject; import electrosphere.dynamics.RigidBody; @@ -12,6 +15,7 @@ import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.client.targeting.crosshair.Crosshair; import electrosphere.game.collision.collidable.Collidable; +import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.item.type.EquipWhitelist; import electrosphere.main.Globals; import electrosphere.renderer.actor.Actor; @@ -24,36 +28,38 @@ import electrosphere.renderer.actor.ActorMeshMask; public class EquipState { Entity parent; + + List equipPoints = new LinkedList(); + Map equipMap = new HashMap(); - Entity equipPrimary; - - String equipPrimaryBoneName; - - public EquipState(Entity parent, String equipPrimaryBoneName){ + public EquipState(Entity parent, List equipPoints){ this.parent = parent; - this.equipPrimaryBoneName = equipPrimaryBoneName; - } - - public boolean hasEquipPrimary(){ - return equipPrimary != null; + for(EquipPoint point : equipPoints){ + this.equipPoints.add(point); + } } - public Entity getEquipPrimary() { - return equipPrimary; - } - - public void setEquipPrimary(Entity equipPrimary) { - this.equipPrimary = equipPrimary; + public List equippedPoints(){ + return new LinkedList(equipMap.keySet()); } - public void attemptEquip(Entity toEquip){ - if(!hasEquipPrimary() && ItemUtils.isItem(toEquip) && !AttachUtils.isAttached(toEquip)){ - if(ItemUtils.hasEquipList(toEquip)){ + public void attemptEquip(Entity toEquip, EquipPoint point){ + boolean hasEquipped = equipMap.containsKey(point.getEquipPointId()); + boolean targetIsItem = ItemUtils.isItem(toEquip); + boolean targetIsAttached = AttachUtils.isAttached(toEquip); + boolean targetHasWhitelist = ItemUtils.hasEquipList(toEquip); + String equipItemClass = "";//somehow resolve from toEquip + List pointEquipClassList = point.getEquipClassWhitelist(); + boolean itemIsInPointWhitelist = pointEquipClassList.contains(equipItemClass); + if(!hasEquipped && targetIsItem && !targetIsAttached && itemIsInPointWhitelist){ + if(targetHasWhitelist){ + //by attaching are we going to be replacing meshes? String parentCreatureId = CreatureUtils.getType(parent); List whitelist = ItemUtils.getEquipWhitelist(toEquip); for(EquipWhitelist whitelistItem : whitelist){ if(whitelistItem.getCreatureId().equals(parentCreatureId)){ - equipPrimary = toEquip; + //put in map + equipMap.put(point.getEquipPointId(),toEquip); String modelName = whitelistItem.getModel(); Globals.assetManager.addModelPathToQueue(modelName); Actor parentActor = EntityUtils.getActor(parent); @@ -66,7 +72,7 @@ public class EquipState { meshMask.queueMesh(modelName, toDraw); } //attach to parent bone - AttachUtils.attachEntityToEntityAtBone(parent, toEquip, equipPrimaryBoneName); + AttachUtils.attachEntityToEntityAtBone(parent, toEquip, point.getBone()); //make uncollidable if(toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ CollisionObject rigidBody = (CollisionObject)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); @@ -75,32 +81,79 @@ public class EquipState { //hide toEquip actor EntityUtils.setDraw(toEquip, false); //make untargetable - Globals.entityManager.setTargetable(equipPrimary, false); + Globals.entityManager.setTargetable(toEquip, false); break; } } } else { - equipPrimary = toEquip; - AttachUtils.attachEntityToEntityAtBone(parent, toEquip, equipPrimaryBoneName); + //since we're not replacing meshes we must be attaching to a bone + equipMap.put(point.getEquipPointId(),toEquip); + AttachUtils.attachEntityToEntityAtBone(parent, toEquip, point.getBone()); if(toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ CollisionObject rigidBody = (CollisionObject)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); Globals.collisionEngine.deregisterPhysicsObject(rigidBody); } - Globals.entityManager.setTargetable(equipPrimary, false); + Globals.entityManager.setTargetable(toEquip, false); } } + // if(!hasEquipPrimary() && ItemUtils.isItem(toEquip) && !AttachUtils.isAttached(toEquip)){ + // if(ItemUtils.hasEquipList(toEquip)){ + // String parentCreatureId = CreatureUtils.getType(parent); + // List whitelist = ItemUtils.getEquipWhitelist(toEquip); + // for(EquipWhitelist whitelistItem : whitelist){ + // if(whitelistItem.getCreatureId().equals(parentCreatureId)){ + // equipPrimary = toEquip; + // String modelName = whitelistItem.getModel(); + // Globals.assetManager.addModelPathToQueue(modelName); + // Actor parentActor = EntityUtils.getActor(parent); + // //queue meshes from display model to parent actor + // ActorMeshMask meshMask = parentActor.getMeshMask(); + // for(String toBlock : whitelistItem.getMeshMaskList()){ + // meshMask.blockMesh(modelName, toBlock); + // } + // for(String toDraw : whitelistItem.getMeshList()){ + // meshMask.queueMesh(modelName, toDraw); + // } + // //attach to parent bone + // AttachUtils.attachEntityToEntityAtBone(parent, toEquip, equipPrimaryBoneName); + // //make uncollidable + // if(toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ + // CollisionObject rigidBody = (CollisionObject)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); + // Globals.collisionEngine.deregisterPhysicsObject(rigidBody); + // } + // //hide toEquip actor + // EntityUtils.setDraw(toEquip, false); + // //make untargetable + // Globals.entityManager.setTargetable(equipPrimary, false); + // break; + // } + // } + // } else { + // equipPrimary = toEquip; + // AttachUtils.attachEntityToEntityAtBone(parent, toEquip, equipPrimaryBoneName); + // if(toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && toEquip.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ + // CollisionObject rigidBody = (CollisionObject)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); + // Globals.collisionEngine.deregisterPhysicsObject(rigidBody); + // } + // Globals.entityManager.setTargetable(equipPrimary, false); + // } + // } } - public void drop(){ - if(hasEquipPrimary()){ - AttachUtils.detatchEntityFromEntityAtBone(parent,equipPrimary); - if(equipPrimary.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && equipPrimary.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ - CollisionObject rigidBody = (CollisionObject)equipPrimary.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); - Globals.collisionEngine.registerPhysicsObject(rigidBody); - } - Globals.entityManager.setTargetable(equipPrimary, true); - equipPrimary = null; - } + // public void drop(Entity entity){ + // if(hasEquipPrimary()){ + // AttachUtils.detatchEntityFromEntityAtBone(parent,equipPrimary); + // if(equipPrimary.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && equipPrimary.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ + // CollisionObject rigidBody = (CollisionObject)equipPrimary.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); + // Globals.collisionEngine.registerPhysicsObject(rigidBody); + // } + // Globals.entityManager.setTargetable(equipPrimary, true); + // equipPrimary = null; + // } + // } + + public void unequipPoint(String pointId){ + equipMap.remove(pointId); } diff --git a/src/main/java/electrosphere/entity/state/GravityTree.java b/src/main/java/electrosphere/entity/state/gravity/GravityTree.java similarity index 99% rename from src/main/java/electrosphere/entity/state/GravityTree.java rename to src/main/java/electrosphere/entity/state/gravity/GravityTree.java index db2b3dbb..4faecbcc 100644 --- a/src/main/java/electrosphere/entity/state/GravityTree.java +++ b/src/main/java/electrosphere/entity/state/gravity/GravityTree.java @@ -1,4 +1,4 @@ -package electrosphere.entity.state; +package electrosphere.entity.state.gravity; import electrosphere.collision.dispatch.CollisionObject; import electrosphere.entity.Entity; diff --git a/src/main/java/electrosphere/entity/state/gravity/GravityUtils.java b/src/main/java/electrosphere/entity/state/gravity/GravityUtils.java new file mode 100644 index 00000000..0ee72b5c --- /dev/null +++ b/src/main/java/electrosphere/entity/state/gravity/GravityUtils.java @@ -0,0 +1,15 @@ +package electrosphere.entity.state.gravity; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; + +public class GravityUtils { + + public static void attemptActivateGravity(Entity target){ + if(target.getDataKeys().contains(EntityDataStrings.GRAVITY_ENTITY)){ + GravityTree tree = (GravityTree)target.getData(EntityDataStrings.GRAVITY_TREE); + tree.start(); + } + } + +} \ No newline at end of file diff --git a/src/main/java/electrosphere/entity/state/inventory/InventoryUtils.java b/src/main/java/electrosphere/entity/state/inventory/InventoryUtils.java new file mode 100644 index 00000000..e28afd36 --- /dev/null +++ b/src/main/java/electrosphere/entity/state/inventory/InventoryUtils.java @@ -0,0 +1,67 @@ +package electrosphere.entity.state.inventory; + +import org.joml.Vector3d; +import org.joml.Vector3f; + +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.state.gravity.GravityUtils; +import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.entity.types.item.ItemUtils; + +public class InventoryUtils { + + + public static boolean hasNaturalInventory(Entity target){ + return target.getDataKeys().contains(EntityDataStrings.NATURAL_INVENTORY); + } + + public static UnrelationalInventoryState getNaturalInventory(Entity target){ + return (UnrelationalInventoryState)target.getData(EntityDataStrings.NATURAL_INVENTORY); + } + + public static void attemptStoreItem(Entity creature, Entity item){ + boolean creatureIsCreature = CreatureUtils.isCreature(creature); + boolean itemIsItem = ItemUtils.isItem(item); + boolean hasInventory = hasNaturalInventory(creature); + if(creatureIsCreature && itemIsItem && hasInventory){ + //get inventory + //for the moment we're just gonna get natural inventory + //later we'll need to search through all creature inventories to find the item + UnrelationalInventoryState inventory = getNaturalInventory(creature); + //destroy in-world entity and create in-inventory item + //we're doing this so that we're not constantly sending networking messages for invisible entities attached to the player + Entity inventoryItem = ItemUtils.recreateContainerItem(item); + //destroy the item that was left over + ItemUtils.destroyInWorldItem(item); + //store item in inventory + inventory.addItem(inventoryItem); + } + } + + //need creature so we can figure out where to drop the item + public static void attemptEjectItem(Entity creature, Entity item){ + //verify creature is creature, item is item, inventory exists, and item is in inventory + boolean creatureIsCreature = CreatureUtils.isCreature(creature); + boolean itemIsItem = ItemUtils.isItem(item); + boolean hasInventory = hasNaturalInventory(creature); + if(creatureIsCreature && itemIsItem && hasInventory){ + //get inventory + UnrelationalInventoryState inventory = getNaturalInventory(creature); + //remove item from inventory + inventory.removeItem(item); + //compose item into in-world entity + Entity inWorldItem = ItemUtils.spawnBasicItem(ItemUtils.getType(item)); + //delete in container item + ItemUtils.destroyInInventoryItem(item); + //find "in front of creature" + Vector3d dropSpot = new Vector3d(EntityUtils.getPosition(creature)).add(CreatureUtils.getFacingVector(creature)); + //move in-world entity to in front of creature + EntityUtils.getPosition(inWorldItem).set(dropSpot); + //activate gravity + GravityUtils.attemptActivateGravity(inWorldItem); + } + } + +} diff --git a/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java b/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java index e729f7b0..250e2fed 100644 --- a/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java +++ b/src/main/java/electrosphere/entity/state/inventory/RelationalInventoryState.java @@ -1,22 +1,31 @@ package electrosphere.entity.state.inventory; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; import electrosphere.entity.Entity; +import electrosphere.game.data.creature.type.equip.EquipPoint; public class RelationalInventoryState { - int capacity; - Map items = new HashMap(); - public RelationalInventoryState(List slots){ + public static RelationalInventoryState buildRelationalInventoryStateFromStringList(List slots){ + RelationalInventoryState rVal = new RelationalInventoryState(); for(String slot : slots){ - items.put(slot,null); + rVal.items.put(slot,null); } + return rVal; + } + + public static RelationalInventoryState buildRelationalInventoryStateFromEquipList(List points){ + RelationalInventoryState rVal = new RelationalInventoryState(); + for(EquipPoint point : points){ + rVal.items.put(point.getEquipPointId(),null); + } + return rVal; } public void addItem(String slot, Entity item){ @@ -38,8 +47,8 @@ public class RelationalInventoryState { return items.containsKey(slot) ? items.get(slot) != null : false; } - public Set getSlots(){ - return items.keySet(); + public List getSlots(){ + return new LinkedList(items.keySet()); } } diff --git a/src/main/java/electrosphere/entity/state/inventory/UnrelationalInventoryState.java b/src/main/java/electrosphere/entity/state/inventory/UnrelationalInventoryState.java index 1b6ae14c..8bdfbf37 100644 --- a/src/main/java/electrosphere/entity/state/inventory/UnrelationalInventoryState.java +++ b/src/main/java/electrosphere/entity/state/inventory/UnrelationalInventoryState.java @@ -11,6 +11,10 @@ public class UnrelationalInventoryState { List items = new LinkedList(); + public UnrelationalInventoryState(int capacity){ + this.capacity = capacity; + } + public void addItem(Entity item){ items.add(item); } @@ -23,7 +27,9 @@ public class UnrelationalInventoryState { return items; } - + public int getCapacity(){ + return capacity; + } } diff --git a/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java index bea4b644..c8301598 100644 --- a/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/GroundMovementTree.java @@ -1,6 +1,8 @@ package electrosphere.entity.state.movement; import electrosphere.entity.state.collidable.Impulse; +import electrosphere.entity.state.gravity.GravityTree; +import electrosphere.entity.state.gravity.GravityUtils; import electrosphere.collision.dispatch.CollisionObject; import electrosphere.dynamics.RigidBody; import electrosphere.entity.CameraEntityUtils; @@ -10,8 +12,6 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.AttackTree; import electrosphere.entity.state.AttackTree.AttackTreeState; -import electrosphere.entity.state.GravityTree; -import electrosphere.entity.state.GravityTree; import electrosphere.entity.state.movement.SprintTree.SprintTreeState; import electrosphere.game.collision.CollisionEngine; import electrosphere.game.collision.PhysicsUtils; @@ -179,17 +179,17 @@ public class GroundMovementTree { case 0: state = MovementTreeState.STARTUP; // System.out.println("Set state STARTUP"); - activateGravityTree(); + GravityUtils.attemptActivateGravity(parent); break; case 1: state = MovementTreeState.MOVE; // System.out.println("Set state MOVE"); - activateGravityTree(); + GravityUtils.attemptActivateGravity(parent); break; case 2: state = MovementTreeState.SLOWDOWN; // System.out.println("Set state SLOWDOWN"); - activateGravityTree(); + GravityUtils.attemptActivateGravity(parent); break; case 3: state = MovementTreeState.IDLE; @@ -247,7 +247,7 @@ public class GroundMovementTree { // position.set(newPosition); rotation.set(movementQuaternion); - activateGravityTree(); + GravityUtils.attemptActivateGravity(parent); if(Globals.RUN_SERVER){ // Globals.server.broadcastMessage( @@ -323,7 +323,7 @@ public class GroundMovementTree { // position.set(newPosition); rotation.set(movementQuaternion); - activateGravityTree(); + GravityUtils.attemptActivateGravity(parent); if(Globals.RUN_SERVER){ // Globals.server.broadcastMessage( @@ -407,7 +407,7 @@ public class GroundMovementTree { // position.set(newPosition); rotation.set(movementQuaternion); - activateGravityTree(); + GravityUtils.attemptActivateGravity(parent); if(Globals.RUN_SERVER){ // Globals.server.broadcastMessage( @@ -474,13 +474,6 @@ public class GroundMovementTree { networkMessageQueue.add(networkMessage); } - public void activateGravityTree(){ - if(parent.getDataKeys().contains(EntityDataStrings.GRAVITY_ENTITY)){ - GravityTree tree = (GravityTree)parent.getData(EntityDataStrings.GRAVITY_TREE); - tree.start(); - } - } - public boolean canStartMoving(){ boolean rVal = true; if(parent.getDataKeys().contains(EntityDataStrings.ATTACK_TREE) && ((AttackTree)parent.getData(EntityDataStrings.ATTACK_TREE)).getState() != AttackTreeState.IDLE){ diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index c7b2b77e..d0e75c33 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -11,10 +11,12 @@ import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.game.data.creature.type.CreatureType; import electrosphere.game.data.creature.type.MovementSystem; 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.state.gravity.GravityTree; +import electrosphere.entity.state.inventory.RelationalInventoryState; +import electrosphere.entity.state.inventory.UnrelationalInventoryState; import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.entity.state.life.LifeState; import electrosphere.entity.state.movement.SprintTree; @@ -23,6 +25,7 @@ import electrosphere.game.collision.collidable.Collidable; import electrosphere.game.data.creature.type.CollidableTemplate; import electrosphere.game.data.creature.type.SprintSystem; import electrosphere.game.data.creature.type.attack.AttackMove; +import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.creature.type.visualattribute.AttributeVariant; import electrosphere.game.data.creature.type.visualattribute.VisualAttribute; import electrosphere.logger.LoggerInterface; @@ -36,6 +39,10 @@ import electrosphere.renderer.Model; import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.ActorUtils; import electrosphere.util.ModelLoader; + +import java.util.LinkedList; +import java.util.List; + import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; @@ -70,11 +77,19 @@ public class CreatureUtils { Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath()); Actor creatureActor = EntityUtils.getActor(rVal); for(HitboxData hitboxdata : rawType.getHitboxes()){ + List hitboxList = new LinkedList(); + List hurtboxList = new LinkedList(); if(hitboxdata.getType().equals("hit")){ - Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius())); + Entity hitbox = HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()); + Globals.hitboxManager.registerHitbox(hitbox); + hitboxList.add(hitbox); } else if(hitboxdata.getType().equals("hurt")){ - Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHurtbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius())); + Entity hurtbox = HitboxUtils.spawnRegularHurtbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()); + Globals.hitboxManager.registerHitbox(hurtbox); + hurtboxList.add(hurtbox); } + rVal.putData(EntityDataStrings.HITBOX_ASSOCIATED_LIST, hitboxList); + rVal.putData(EntityDataStrings.HURTBOX_ASSOCIATED_LIST, hurtboxList); } if(rawType.getCollidable() != null){ CollidableTemplate physicsTemplate = rawType.getCollidable(); @@ -136,6 +151,10 @@ public class CreatureUtils { break; } } + if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ + rVal.putData(EntityDataStrings.EQUIP_STATE, new EquipState(rVal,rawType.getEquipPoints())); + rVal.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); + } for(String token : rawType.getTokens()){ switch(token){ case "BLENDER_TRANSFORM": @@ -170,8 +189,11 @@ public class CreatureUtils { Globals.entityManager.registerTargetableEntity(rVal); break; case "CAN_EQUIP": - rVal.putData(EntityDataStrings.EQUIP_STATE, new EquipState(rVal,"MiddleLower.R")); + // rVal.putData(EntityDataStrings.EQUIP_STATE, new EquipState(rVal,"MiddleLower.R")); break; + case "INVENTORY": + rVal.putData(EntityDataStrings.NATURAL_INVENTORY,new UnrelationalInventoryState(10)); + break; } } //variants diff --git a/src/main/java/electrosphere/entity/types/hitbox/HitboxManager.java b/src/main/java/electrosphere/entity/types/hitbox/HitboxManager.java index e29a6dc0..dfe96211 100644 --- a/src/main/java/electrosphere/entity/types/hitbox/HitboxManager.java +++ b/src/main/java/electrosphere/entity/types/hitbox/HitboxManager.java @@ -12,7 +12,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class HitboxManager { - CopyOnWriteArrayList hitboxes = new CopyOnWriteArrayList(); + CopyOnWriteArrayList hitboxes = new CopyOnWriteArrayList(); long idIncrementer = 0; public HitboxManager(){ @@ -28,4 +28,8 @@ public class HitboxManager { public CopyOnWriteArrayList getAllHitboxes(){ return hitboxes; } + + public void deregisterHitbox(Entity hitbox){ + hitboxes.remove(hitbox); + } } diff --git a/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java b/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java index 4074dbea..e2e81b33 100644 --- a/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java +++ b/src/main/java/electrosphere/entity/types/hitbox/HitboxUtils.java @@ -9,6 +9,9 @@ import electrosphere.entity.state.life.LifeState; import electrosphere.entity.state.life.LifeUtils; import electrosphere.game.server.effects.ParticleEffects; import electrosphere.main.Globals; + +import java.util.List; + import org.joml.Matrix4f; import org.joml.Quaternionf; import org.joml.Vector3d; @@ -148,5 +151,13 @@ public class HitboxUtils { public static HitboxData getHitboxData(Entity e){ return (HitboxData)e.getData(EntityDataStrings.HITBOX_DATA); } + + public static List getHitboxAssociatedList(Entity e){ + return (List)e.getData(EntityDataStrings.HITBOX_ASSOCIATED_LIST); + } + + public static List getHurtboxAssociatedList(Entity e){ + return (List)e.getData(EntityDataStrings.HURTBOX_ASSOCIATED_LIST); + } } diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java index 417e12c5..8303f055 100644 --- a/src/main/java/electrosphere/entity/types/item/ItemUtils.java +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -4,10 +4,11 @@ import electrosphere.collision.dispatch.CollisionObject; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; -import electrosphere.entity.state.GravityTree; import electrosphere.entity.state.collidable.CollidableTree; +import electrosphere.entity.state.gravity.GravityTree; import electrosphere.entity.state.movement.GroundMovementTree; import electrosphere.entity.types.attach.AttachUtils; +import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.game.collision.PhysicsUtils; @@ -24,6 +25,7 @@ import electrosphere.renderer.Model; import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.ActorUtils; +import java.util.LinkedList; import java.util.List; import org.joml.Quaternionf; @@ -35,13 +37,20 @@ import org.joml.Vector3f; * @author amaterasu */ public class ItemUtils { + + static final String genericItemIconPath = "Textures/icons/itemIconItemGeneric.png"; + public static Entity spawnBasicItem(String name){ Item item = Globals.gameConfigCurrent.getItemMap().getItem(name); Entity rVal = EntityUtils.spawnDrawableEntity(item.getModelPath()); if(item.getHitboxes() != null){ + List hitboxList = new LinkedList(); for(HitboxData hitboxdata : item.getHitboxes()){ - Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius())); + Entity hitbox = HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()); + Globals.hitboxManager.registerHitbox(hitbox); + hitboxList.add(hitbox); } + rVal.putData(EntityDataStrings.HITBOX_ASSOCIATED_LIST,hitboxList); } if(item.getCollidable() != null){ CollidableTemplate physicsTemplate = item.getCollidable(); @@ -93,12 +102,6 @@ public class ItemUtils { case "TARGETABLE": Globals.entityManager.registerTargetableEntity(rVal); break; - case "WEAPON": - rVal.putData(EntityDataStrings.ITEM_IS_WEAPON, true); - break; - case "ARMOR": - rVal.putData(EntityDataStrings.ITEM_IS_ARMOR, true); - break; } } if(item.getEquipWhitelist() != null){ @@ -107,6 +110,11 @@ public class ItemUtils { if(item.getIdleAnim() != null){ rVal.putData(EntityDataStrings.ANIM_IDLE,item.getIdleAnim()); } + if(item.getIconPath() != null && !item.getIconPath().equals("")){ + rVal.putData(EntityDataStrings.ITEM_ICON,item.getIconPath()); + } else { + rVal.putData(EntityDataStrings.ITEM_ICON,genericItemIconPath); + } rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true); rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true); rVal.putData(EntityDataStrings.ITEM_TYPE, name); @@ -192,4 +200,52 @@ public class ItemUtils { return (List)item.getData(EntityDataStrings.ITEM_EQUIP_WHITELIST); } + /** + * Emits an entity which represents the item inside a container + */ + public static Entity recreateContainerItem(Entity item){ + if(isItem(item)){ + Entity rVal = new Entity(); + if(getEquipWhitelist(item) != null){ + rVal.putData(EntityDataStrings.ITEM_EQUIP_WHITELIST, getEquipWhitelist(item)); + } + rVal.putData(EntityDataStrings.ITEM_ICON,ItemUtils.getItemIcon(item)); + rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true); + rVal.putData(EntityDataStrings.ITEM_TYPE, item.getData(EntityDataStrings.ITEM_TYPE)); + Globals.entityManager.registerEntity(rVal); + return rVal; + } else { + return null; + } + } + + public static void destroyInWorldItem(Entity item){ + if(isItem(item)){ + //destroy physics + if(item.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && item.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ + //destroy physics + //this deregisters from all four & unhooks rigid bodies from the physics runtime + Globals.collisionEngine.destroyEntityThatHasPhysics(item); + //destroy hitboxes + List hitboxes = HitboxUtils.getHitboxAssociatedList(item); + if(hitboxes != null){ + for(Entity hitbox : hitboxes){ + Globals.hitboxManager.deregisterHitbox(hitbox); + HitboxUtils.getHitboxData(hitbox).setActive(false); + } + } + //destroy graphics + EntityUtils.cleanUpDrawableEntity(item); + } + } + } + + public static void destroyInInventoryItem(Entity item){ + Globals.entityManager.deregisterEntity(item); + } + + public static String getItemIcon(Entity item){ + return (String)item.getData(EntityDataStrings.ITEM_ICON); + } + } diff --git a/src/main/java/electrosphere/game/collision/CollisionEngine.java b/src/main/java/electrosphere/game/collision/CollisionEngine.java index d972ac25..4b9c8c25 100644 --- a/src/main/java/electrosphere/game/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/game/collision/CollisionEngine.java @@ -28,6 +28,7 @@ import electrosphere.entity.EntityUtils; import electrosphere.entity.state.collidable.Impulse; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.game.collision.collidable.Collidable; + import static electrosphere.main.Main.deltaTime; import java.util.ArrayList; import java.util.List; @@ -278,6 +279,10 @@ public class CollisionEngine { public List getPhysicsEntities(){ return physicsEntities; } + + public void deregisterPhysicsEntity(Entity physicsEntity){ + physicsEntities.remove(physicsEntity); + } public void registerDynamicPhysicsEntity(Entity dynamicEntity){ dynamicPhysicsEntities.add(dynamicEntity); @@ -466,5 +471,14 @@ public class CollisionEngine { structurePhysicsEntities.remove(e); } } + + public void destroyEntityThatHasPhysics(Entity e){ + //make uncollidable + if(e.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLISION_BODY) && e.getDataKeys().contains(EntityDataStrings.PHYSICS_COLLIDABLE)){ + CollisionObject rigidBody = (CollisionObject)e.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); + deregisterPhysicsObject(rigidBody); + } + deregisterCollidableEntity(e); + } } 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 c9a06d4e..17337ea8 100644 --- a/src/main/java/electrosphere/game/data/creature/type/CreatureType.java +++ b/src/main/java/electrosphere/game/data/creature/type/CreatureType.java @@ -3,6 +3,7 @@ package electrosphere.game.data.creature.type; import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.game.data.creature.type.attack.AttackMove; import electrosphere.game.data.creature.type.attack.AttackMoveResolver; +import electrosphere.game.data.creature.type.equip.EquipPoint; import electrosphere.game.data.creature.type.rotator.RotatorSystem; import electrosphere.game.data.creature.type.visualattribute.VisualAttribute; @@ -15,6 +16,7 @@ public class CreatureType { List visualAttributes; List movementSystems; RotatorSystem rotatorSystem; + List equipPoints; CollidableTemplate collidable; List attackMoves; HealthSystem healthSystem; @@ -67,6 +69,10 @@ public class CreatureType { return rotatorSystem; } + public List getEquipPoints(){ + return equipPoints; + } + public void setAttackMoveResolver(AttackMoveResolver resolver){ attackMoveResolver = resolver; } diff --git a/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java b/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java new file mode 100644 index 00000000..34ab1d7a --- /dev/null +++ b/src/main/java/electrosphere/game/data/creature/type/equip/EquipPoint.java @@ -0,0 +1,33 @@ +package electrosphere.game.data.creature.type.equip; + +import java.util.List; + +public class EquipPoint { + + String equipPointId; + String bone; + List offsetVector; + List offsetRotation; + List equipClassWhitelist; + + public String getEquipPointId(){ + return equipPointId; + } + + public String getBone(){ + return bone; + } + + public List getOffsetVector(){ + return offsetVector; + } + + public List getOffsetRotation(){ + return offsetRotation; + } + + public List getEquipClassWhitelist(){ + return equipClassWhitelist; + } + +} diff --git a/src/main/java/electrosphere/game/data/item/type/Item.java b/src/main/java/electrosphere/game/data/item/type/Item.java index 8ff8d26d..392f49e5 100644 --- a/src/main/java/electrosphere/game/data/item/type/Item.java +++ b/src/main/java/electrosphere/game/data/item/type/Item.java @@ -13,6 +13,7 @@ public class Item { CollidableTemplate collidable; List equipWhitelist; String idleAnim; + String iconPath; public String getItemId() { return itemId; @@ -42,5 +43,8 @@ public class Item { return idleAnim; } + public String getIconPath(){ + return iconPath; + } } diff --git a/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java b/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java index c6fed489..8184e30a 100644 --- a/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java +++ b/src/main/java/electrosphere/game/server/ai/creature/OpportunisticAttacker.java @@ -208,9 +208,9 @@ public class OpportunisticAttacker extends AI { boolean rVal = false; if(character.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){ EquipState equipState = (EquipState)character.getData(EntityDataStrings.EQUIP_STATE); - if(equipState.hasEquipPrimary()){ - rVal = true; - } + // if(equipState.hasEquipPrimary()){ + // rVal = true; + // } } return rVal; } @@ -244,9 +244,9 @@ public class OpportunisticAttacker extends AI { void pickupWeapon(){ if(character.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){ EquipState equipState = (EquipState)character.getData(EntityDataStrings.EQUIP_STATE); - if(!equipState.hasEquipPrimary()){ - equipState.attemptEquip(target); - } + // if(!equipState.hasEquipPrimary()){ + // equipState.attemptEquip(target); + // } } } diff --git a/src/main/java/electrosphere/game/simulation/MicroSimulation.java b/src/main/java/electrosphere/game/simulation/MicroSimulation.java index cdcbd7d5..d22ce1e2 100644 --- a/src/main/java/electrosphere/game/simulation/MicroSimulation.java +++ b/src/main/java/electrosphere/game/simulation/MicroSimulation.java @@ -5,11 +5,11 @@ import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.AttackTree; -import electrosphere.entity.state.GravityTree; import electrosphere.entity.state.IdleTree; import electrosphere.entity.state.movement.GroundMovementTree; import electrosphere.entity.state.ParticleTree; import electrosphere.entity.state.collidable.CollidableTree; +import electrosphere.entity.state.gravity.GravityTree; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.entity.types.item.ItemUtils; diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index 87c3beb8..8c2143b6 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -53,6 +53,7 @@ import electrosphere.game.server.pathfinding.NavMeshManager; import electrosphere.renderer.ui.Widget; import electrosphere.renderer.ui.WidgetManager; import electrosphere.renderer.ui.WidgetUtils; +import electrosphere.renderer.ui.WindowManager; import electrosphere.renderer.ui.font.FontUtils; import electrosphere.renderer.ui.font.RawFontMap; import electrosphere.renderer.ui.font.TextBox; @@ -275,6 +276,9 @@ public class Globals { //thread for loading different game states public static LoadingThread loadingThread; + //manages all windows to be drawn to the screen + public static WindowManager windowManager; + //manager for all widgets currently being drawn to screen public static WidgetManager widgetManager; diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index a4a60c86..61e29a7b 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -435,15 +435,17 @@ public class Main { mouse_lastX = (float) xpos; mouse_lastY = (float) ypos; - yaw = yaw + xoffset; - pitch = pitch - yoffset; + if(Globals.controlHandler != null && !Globals.controlHandler.isMouseVisible()){ + yaw = yaw + xoffset; + pitch = pitch - yoffset; - if (pitch > 100.0f) { - pitch = 100.0f; + if (pitch > 100.0f) { + pitch = 100.0f; + } + if (pitch < -99.0f) { + pitch = -99.0f; + } } - if (pitch < -99.0f) { - pitch = -99.0f; - } } diff --git a/src/main/java/electrosphere/menu/Menu.java b/src/main/java/electrosphere/menu/Menu.java index 15431ded..3023a605 100644 --- a/src/main/java/electrosphere/menu/Menu.java +++ b/src/main/java/electrosphere/menu/Menu.java @@ -27,6 +27,7 @@ public class Menu { OPTIONS_MAIN_MENU, IN_GAME_MAIN_MENU, TEST, + INVENTORY_NATURAL, } MenuType type; @@ -34,8 +35,8 @@ public class Menu { int option = 0; int optionMax = 0; - List widgetList = new ArrayList(); - List optionList = new ArrayList(); + List widgetList = new ArrayList(); + List optionList = new ArrayList(); public Menu(MenuType type){ this.type = type; diff --git a/src/main/java/electrosphere/menu/MenuTransition.java b/src/main/java/electrosphere/menu/MenuTransition.java index 348d50b2..dce34934 100644 --- a/src/main/java/electrosphere/menu/MenuTransition.java +++ b/src/main/java/electrosphere/menu/MenuTransition.java @@ -206,6 +206,12 @@ public class MenuTransition { Globals.currentMenu.dispose(); Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME); break; + case INVENTORY_NATURAL: + MenuUtils.makeMenuUndrawable(Globals.currentMenu); + Globals.currentMenu.dispose(); + Globals.controlHandler.setHandlerState(ControlsState.MAIN_GAME); + Globals.controlHandler.hideMouse(); + break; } } diff --git a/src/main/java/electrosphere/menu/MenuUtils.java b/src/main/java/electrosphere/menu/MenuUtils.java index d046d20d..296ee25b 100644 --- a/src/main/java/electrosphere/menu/MenuUtils.java +++ b/src/main/java/electrosphere/menu/MenuUtils.java @@ -1,5 +1,8 @@ package electrosphere.menu; +import electrosphere.entity.Entity; +import electrosphere.entity.state.inventory.UnrelationalInventoryState; +import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.server.saves.SaveUtils; import electrosphere.main.Globals; import electrosphere.menu.Menu.MenuType; @@ -128,10 +131,10 @@ public class MenuUtils { Window menuWindow = new Window(100, 100, 500, 500); //black texture background - ImagePanel imagePanel = new ImagePanel(0,0,width,height); - imagePanel.setWidth(width); - imagePanel.setHeight(height); - imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture)); + ImagePanel imagePanel = new ImagePanel(0,0,width,height,Globals.blackTexture); + // imagePanel.setWidth(width); + // imagePanel.setHeight(height); + // imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture)); menuWindow.addWidget(imagePanel); //label 1 (back) @@ -160,6 +163,55 @@ public class MenuUtils { rVal.addElement(WidgetUtils.createWindowTEST()); return rVal; } + + public static Menu createNaturalInventoryMenu(UnrelationalInventoryState inventory){ + Menu rVal = new Menu(MenuType.INVENTORY_NATURAL); + int screenTop = Globals.WINDOW_HEIGHT - 150; + int width = 500; + int height = 500; + int screenLeft = (Globals.WINDOW_WIDTH - width)/2; + Window menuWindow = new Window(100, 100, 500, 500); + + //black texture background + ImagePanel imagePanel = new ImagePanel(0,0,width,height,Globals.blackTexture); + // imagePanel.setWidth(width); + // imagePanel.setHeight(height); + // imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture)); + menuWindow.addWidget(imagePanel); + + //label 1 (inventory) + Label inventoryLabel = new Label(10,10,1.0f); + inventoryLabel.setText("INVENTORY"); + menuWindow.addWidget(inventoryLabel); + rVal.addOption(inventoryLabel); + + int columns = 8; + int columnWidth = 60; + int rowHeight = 60; + for(int i = 0; i < inventory.getCapacity(); i++){ + String texturePath = "Textures/icons/itemIconEmpty.png"; + if(i < inventory.getItems().size()){ + Entity currentItem = inventory.getItems().get(i); + //get texture path from item + texturePath = ItemUtils.getItemIcon(currentItem); + } + if(!Globals.assetManager.hasLoadedTexture(texturePath)){ + Globals.assetManager.addTexturePathtoQueue(texturePath); + } + ImagePanel panel = new ImagePanel((10 + i % columns * columnWidth),height - (110 + i / columns * rowHeight),50,50,texturePath); + // imagePanel.setWidth(width); + // imagePanel.setHeight(height); + // imagePanel.setTexture(Globals.assetManager.fetchTexture(Globals.blackTexture)); + menuWindow.addWidget(panel); + } + + + rVal.addElement(menuWindow); + Globals.widgetManager.registerWidget(menuWindow); +// rVal.addElement(WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 50, "BACK", true)); +// rVal.addOption( WidgetUtils.createVerticallyAlignedMinSizeTextBoxFromCharCount(40, 40, screenTop - 275, "QUIT", true)); + return rVal; + } public static void makeMenuDrawable(Menu m){ for(Widget w : m.widgetList){ diff --git a/src/main/java/electrosphere/renderer/ui/WindowManager.java b/src/main/java/electrosphere/renderer/ui/WindowManager.java new file mode 100644 index 00000000..64f31101 --- /dev/null +++ b/src/main/java/electrosphere/renderer/ui/WindowManager.java @@ -0,0 +1,38 @@ +package electrosphere.renderer.ui; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class WindowManager { + + + Map windowManager = new HashMap(); + List windowPriorityList = new LinkedList(); + + public void registerWindow(String windowName, Window window){ + windowManager.put(windowName,window); + windowPriorityList.add(window); + } + + public Window getWindow(String windowName){ + return windowManager.get(windowName); + } + + public void unregisterWindow(String windowName){ + Window toRemove = windowManager.remove(windowName); + if(toRemove != null){ + windowPriorityList.remove(toRemove); + } + } + + /** + * windows should be drawn in this order + * @return + */ + public List getWindowPriorityList(){ + return windowPriorityList; + } + +} diff --git a/src/main/java/electrosphere/renderer/ui/widgets/ImagePanel.java b/src/main/java/electrosphere/renderer/ui/widgets/ImagePanel.java index bf92dd67..730c75b6 100644 --- a/src/main/java/electrosphere/renderer/ui/widgets/ImagePanel.java +++ b/src/main/java/electrosphere/renderer/ui/widgets/ImagePanel.java @@ -21,16 +21,24 @@ import static org.lwjgl.opengl.GL30.glBindFramebuffer; */ public class ImagePanel extends Widget { + String texturePath; Material customMat = new Material(); + boolean hasLoadedTexture = false; Texture texture = null; Vector3f texPosition = new Vector3f(0,0,0); Vector3f texScale = new Vector3f(1,1,0); - public ImagePanel(int x, int y, int width, int height){ - texture = Globals.assetManager.fetchTexture("Textures/default_diffuse.png"); - customMat.setTexturePointer(texture.getTexturePointer()); + public ImagePanel(int x, int y, int width, int height, String texturePath){ + this.texturePath = texturePath; + texture = Globals.assetManager.fetchTexture(this.texturePath); + if(texture != null){ + customMat.setTexturePointer(texture.getTexturePointer()); + hasLoadedTexture = true; + } else { + customMat.setTexturePointer(Globals.assetManager.fetchTexture(Globals.blackTexture).getTexturePointer()); + } this.positionX = x; this.positionY = y; this.width = width; @@ -49,6 +57,13 @@ public class ImagePanel extends Widget { @Override public void draw(int parentFramebufferPointer, int parentWidth, int parentHeight) { + if(!hasLoadedTexture){ + texture = Globals.assetManager.fetchTexture(this.texturePath); + if(texture != null){ + customMat.setTexturePointer(texture.getTexturePointer()); + hasLoadedTexture = true; + } + } //this call binds the screen as the "texture" we're rendering to //have to call before actually rendering glBindFramebuffer(GL_FRAMEBUFFER, parentFramebufferPointer);