Complete item equip/dequip
This commit is contained in:
parent
d1c0791e48
commit
69c7ba3d39
@ -131,6 +131,11 @@
|
||||
"isKey": true,
|
||||
"isMouse": false,
|
||||
"keyValue": 69
|
||||
},
|
||||
"drop" : {
|
||||
"isKey": true,
|
||||
"isMouse": false,
|
||||
"keyValue": 89
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -24,10 +24,21 @@
|
||||
}
|
||||
],
|
||||
"tokens" : [
|
||||
"GRAVITY",
|
||||
"BLENDER_TRANSFORM",
|
||||
"WEAPON",
|
||||
"MELEE"
|
||||
]
|
||||
"MELEE",
|
||||
"TARGETABLE"
|
||||
],
|
||||
"collidable": {
|
||||
"type" : "CUBE",
|
||||
"dimension1" : 0.1,
|
||||
"dimension2" : 0.1,
|
||||
"dimension3" : 0.35,
|
||||
"offsetX" : 0,
|
||||
"offsetY" : 0.05,
|
||||
"offsetZ" : 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"name" : "Bow",
|
||||
|
||||
@ -48,6 +48,7 @@ public class ControlHandler {
|
||||
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 INPUT_CODE_DROP = "drop";
|
||||
|
||||
public static final String DATA_STRING_INPUT_CODE_MENU_INCREMENT = "menuIncrement";
|
||||
public static final String DATA_STRING_INPUT_CODE_MENU_DECREMENT = "menuDecrement";
|
||||
@ -134,6 +135,7 @@ public class ControlHandler {
|
||||
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));
|
||||
handler.addControl(INPUT_CODE_DROP, new Control(true,false,GLFW_KEY_Y));
|
||||
|
||||
/*
|
||||
Map the menu navigation controls
|
||||
@ -392,9 +394,6 @@ 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){
|
||||
@ -411,6 +410,25 @@ public class ControlHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Drop
|
||||
*/
|
||||
if(controls.containsKey(INPUT_CODE_DROP)){
|
||||
if(controls.get(INPUT_CODE_DROP).isIsKey() && glfwGetKey(Globals.window, controls.get(INPUT_CODE_DROP).getKeyValue()) == GLFW_PRESS){
|
||||
if(controls.get(INPUT_CODE_DROP).isState() == false){
|
||||
if(Globals.playerCharacter.getDataKeys().contains(EntityDataStrings.EQUIP_STATE)){
|
||||
EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.drop();
|
||||
}
|
||||
}
|
||||
controls.get(INPUT_CODE_DROP).setState(true);
|
||||
} else {
|
||||
if(controls.get(INPUT_CODE_DROP).isState() == true){
|
||||
}
|
||||
controls.get(INPUT_CODE_DROP).setState(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Attack
|
||||
*/
|
||||
|
||||
@ -617,9 +617,9 @@ public class LoadingThread extends Thread {
|
||||
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin");
|
||||
CollisionObjUtils.positionCharacter(goblin, new Vector3f(4, 0, 4));
|
||||
EntityUtils.getScale(goblin).set(0.005f);
|
||||
//give evil goblin sword
|
||||
Entity goblinSword = ItemUtils.spawnBasicItem("Katana");
|
||||
AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031");
|
||||
// //give evil goblin sword
|
||||
// Entity goblinSword = ItemUtils.spawnBasicItem("Katana");
|
||||
// AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031");
|
||||
// //attach ai to evil goblin
|
||||
// MindlessAttacker.attachToCreature(goblin);
|
||||
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
package electrosphere.entity.state.equip;
|
||||
|
||||
import electrosphere.collision.dispatch.CollisionObject;
|
||||
import electrosphere.dynamics.RigidBody;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.game.client.targeting.crosshair.Crosshair;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.main.Globals;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -37,6 +43,23 @@ public class EquipState {
|
||||
if(!hasEquipPrimary() && ItemUtils.isItem(toEquip) && !AttachUtils.isAttached(toEquip)){
|
||||
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);
|
||||
}
|
||||
Crosshair.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);
|
||||
}
|
||||
Crosshair.setTargetable(equipPrimary, true);
|
||||
equipPrimary = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +60,19 @@ public class AttachUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void detatchEntityFromEntityAtBone(Entity parent, Entity toAttach){
|
||||
Globals.entityManager.registerBoneAttachedEntity(toAttach);
|
||||
toAttach.removeData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED);
|
||||
toAttach.getDataKeys().remove(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED);
|
||||
toAttach.removeData(EntityDataStrings.ATTACH_PARENT);
|
||||
toAttach.getDataKeys().remove(EntityDataStrings.ATTACH_PARENT);
|
||||
toAttach.removeData(EntityDataStrings.ATTACH_TARGET_BONE);
|
||||
toAttach.getDataKeys().remove(EntityDataStrings.ATTACH_TARGET_BONE);
|
||||
if(parent.getDataKeys().contains(EntityDataStrings.ATTACH_CHILDREN_LIST)){
|
||||
getChildrenList(parent).remove(toAttach);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAttached(Entity e){
|
||||
return e.getDataKeys().contains(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED);
|
||||
}
|
||||
|
||||
@ -98,5 +98,13 @@ public class Crosshair {
|
||||
return currentTarget;
|
||||
}
|
||||
|
||||
public static void setTargetable(Entity target, boolean status){
|
||||
if(status){
|
||||
Globals.entityManager.getTargetables().add(target);
|
||||
} else {
|
||||
Globals.entityManager.getTargetables().remove(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -428,6 +428,13 @@ public class CollisionEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPhysicsObject(CollisionObject object){
|
||||
if(!collisionObject.contains(object)){
|
||||
collisionObject.add(object);
|
||||
world.addCollisionObject(object);
|
||||
}
|
||||
}
|
||||
|
||||
public void deregisterPhysicsObject(CollisionObject object){
|
||||
if(collisionObject.contains(object)){
|
||||
collisionObject.remove(object);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user