equipping networking partway
This commit is contained in:
parent
a957a3f0ca
commit
cf9588f24f
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -1,6 +1,5 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx32G -Xms100m",
|
||||
"files.watcherExclude": {
|
||||
"**/.git/objects/**": true,
|
||||
"**/node_modules/**": true
|
||||
|
||||
@ -85,7 +85,7 @@ void main(){
|
||||
float shadow = ShadowCalculation(FragPosLightSpace, normalize(-dLDirection), norm);
|
||||
|
||||
//calculate final color
|
||||
vec3 finalColor = textureColor * lightIntensity * max(shadow,0.9);
|
||||
vec3 finalColor = textureColor * lightIntensity * max(shadow,0.4);
|
||||
// vec3 lightAmount = CalcDirLight(norm, viewDir);
|
||||
// for(int i = 0; i < NR_POINT_LIGHTS; i++){
|
||||
// lightAmount += CalcPointLight(i, norm, FragPos, viewDir);
|
||||
|
||||
@ -13,8 +13,7 @@ uniform mat4 bones[MAX_BONES];
|
||||
uniform int numBones;
|
||||
uniform int hasBones;
|
||||
|
||||
void main()
|
||||
{
|
||||
void main(){
|
||||
mat4 BoneTransform = (bones[int(aIndex[0])] * aWeights[0]);
|
||||
BoneTransform = BoneTransform + (bones[int(aIndex[1])] * aWeights[1]);
|
||||
BoneTransform = BoneTransform + (bones[int(aIndex[2])] * aWeights[2]);
|
||||
|
||||
@ -16,6 +16,14 @@
|
||||
{
|
||||
"name" : "entityId",
|
||||
"type" : "FIXED_INT"
|
||||
},
|
||||
{
|
||||
"name" : "equipperId",
|
||||
"type" : "FIXED_INT"
|
||||
},
|
||||
{
|
||||
"name" : "containerType",
|
||||
"type" : "FIXED_INT"
|
||||
}
|
||||
],
|
||||
"messageTypes" : [
|
||||
@ -33,12 +41,41 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "equipItem",
|
||||
"messageName" : "clientRequestEquipItem",
|
||||
"data" : [
|
||||
"equipPointId",
|
||||
"entityId"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "serverCommandMoveItemContainer",
|
||||
"data" : [
|
||||
"entityId",
|
||||
"containerType",
|
||||
"equipPointId"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "serverCommandEquipItem",
|
||||
"data" : [
|
||||
"equipperId",
|
||||
"equipPointId",
|
||||
"entityId",
|
||||
"itemTemplate"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "serverCommandUnequipItem",
|
||||
"data" : [
|
||||
"equipperId",
|
||||
"equipPointId"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "clientRequestUnequipItem",
|
||||
"data" : [
|
||||
"equipPointId"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
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.ironsight.IronSightTree;
|
||||
@ -649,14 +650,10 @@ public class ControlHandler {
|
||||
mainGameControlList.add(controls.get(INPUT_CODE_INTERACT));
|
||||
controls.get(INPUT_CODE_INTERACT).setOnPress(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerEntity != null){
|
||||
if(Globals.playerEntity.containsKey(EntityDataStrings.EQUIP_STATE) && Crosshair.hasTarget()){
|
||||
if(EquipState.hasEquipState(Globals.playerEntity) && Crosshair.hasTarget()){
|
||||
if(InventoryUtils.hasNaturalInventory(Globals.playerEntity)){
|
||||
InventoryUtils.attemptStoreItem(Globals.playerEntity, 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());
|
||||
}
|
||||
}
|
||||
}});
|
||||
@ -667,9 +664,7 @@ public class ControlHandler {
|
||||
mainGameControlList.add(controls.get(INPUT_CODE_DROP));
|
||||
controls.get(INPUT_CODE_DROP).setOnPress(new ControlMethod(){public void execute(){
|
||||
if(Globals.playerEntity != null){
|
||||
if(Globals.playerEntity.containsKey(EntityDataStrings.EQUIP_STATE)){
|
||||
// EquipState equipState = (EquipState)Globals.playerCharacter.getData(EntityDataStrings.EQUIP_STATE);
|
||||
// equipState.drop();
|
||||
if(EquipState.hasEquipState(Globals.playerEntity)){
|
||||
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerEntity);
|
||||
if(inventory.getItems().size() > 0){
|
||||
Entity itemToDrop = inventory.getItems().get(0);
|
||||
|
||||
@ -164,6 +164,7 @@ public class EntityDataStrings {
|
||||
public static final String ITEM_WEAPON_CLASS = "itemWeaponClass";
|
||||
public static final String ITEM_WEAPON_DATA_RAW = "itemWeaponDataRaw";
|
||||
public static final String ITEM_IS_IN_INVENTORY = "itemIsInInventory";
|
||||
public static final String ITEM_CONTAINING_PARENT = "itemContainingParent";
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@ -110,10 +110,6 @@ public class EntityUtils {
|
||||
return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR);
|
||||
}
|
||||
|
||||
public static CollidableTree getCollidableTree(Entity e){
|
||||
return (CollidableTree)e.getData(EntityDataStrings.COLLIDABLE_TREE);
|
||||
}
|
||||
|
||||
public static void setVisible(Entity entity, boolean visible){
|
||||
entity.putData(EntityDataStrings.DATA_STRING_DRAW, visible);
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ public class AttackTree {
|
||||
Vector3d spawnPosition = new Vector3d(0,0,0);
|
||||
Quaternionf arrowRotation = new Quaternionf();
|
||||
String targetBone = null;
|
||||
EquipState equipState = (EquipState)parent.getData(EntityDataStrings.EQUIP_STATE);
|
||||
EquipState equipState = EquipState.getEquipState(parent);
|
||||
EquipPoint weaponPoint = null;
|
||||
if((weaponPoint = equipState.getEquipPoint(attackingPoint)) != null){
|
||||
targetBone = weaponPoint.getBone();
|
||||
@ -461,8 +461,8 @@ public class AttackTree {
|
||||
|
||||
String getAttackType(){
|
||||
String rVal = null;
|
||||
if(parent.containsKey(EntityDataStrings.EQUIP_STATE)){
|
||||
EquipState equipState = (EquipState)parent.getData(EntityDataStrings.EQUIP_STATE);
|
||||
if(EquipState.hasEquipState(parent)){
|
||||
EquipState equipState = EquipState.getEquipState(parent);
|
||||
for(String point : equipState.equippedPoints()){
|
||||
Entity item = equipState.getEquippedItemAtPoint(point);
|
||||
if(ItemUtils.isWeapon(item)){
|
||||
@ -496,8 +496,8 @@ public class AttackTree {
|
||||
rVal = true;
|
||||
}
|
||||
} else {
|
||||
if(parent.containsKey(EntityDataStrings.EQUIP_STATE)){
|
||||
EquipState equipState = (EquipState)parent.getData(EntityDataStrings.EQUIP_STATE);
|
||||
if(EquipState.hasEquipState(parent)){
|
||||
EquipState equipState = EquipState.getEquipState(parent);
|
||||
// if(equipState.hasEquipPrimary()){
|
||||
// switch(attackType){
|
||||
// case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND:
|
||||
|
||||
@ -208,7 +208,17 @@ public class CollidableTree {
|
||||
this.collidable = collidable;
|
||||
}
|
||||
|
||||
|
||||
public float getAngularVelocityMagnitude(){
|
||||
return angularVelocity.lengthSquared();
|
||||
}
|
||||
|
||||
public static boolean hasCollidableTree(Entity e){
|
||||
return e.containsKey(EntityDataStrings.COLLIDABLE_TREE);
|
||||
}
|
||||
|
||||
public static CollidableTree getCollidableTree(Entity e){
|
||||
return (CollidableTree)e.getData(EntityDataStrings.COLLIDABLE_TREE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -5,11 +5,17 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
|
||||
import electrosphere.collision.dispatch.CollisionObject;
|
||||
import electrosphere.dynamics.RigidBody;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.gravity.GravityUtils;
|
||||
import electrosphere.entity.state.inventory.InventoryUtils;
|
||||
import electrosphere.entity.state.inventory.RelationalInventoryState;
|
||||
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
@ -17,7 +23,12 @@ 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.game.server.datacell.ServerDataCell;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.InventoryMessage;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import electrosphere.net.server.player.Player;
|
||||
import electrosphere.net.server.protocol.InventoryProtocol;
|
||||
import electrosphere.renderer.actor.Actor;
|
||||
import electrosphere.renderer.actor.ActorMeshMask;
|
||||
|
||||
@ -42,13 +53,135 @@ public class EquipState {
|
||||
public List<String> equippedPoints(){
|
||||
return new LinkedList<String>(equipMap.keySet());
|
||||
}
|
||||
|
||||
public void attemptEquip(Entity toEquip, EquipPoint point){
|
||||
boolean hasEquipped = equipMap.containsKey(point.getEquipPointId());
|
||||
|
||||
public void commandAttemptEquip(Entity toEquip, EquipPoint point){
|
||||
boolean hasEquipped = hasEquippedAtPoint(point.getEquipPointId());
|
||||
boolean targetIsItem = ItemUtils.isItem(toEquip);
|
||||
boolean targetIsAttached = AttachUtils.isAttached(toEquip);
|
||||
boolean targetHasWhitelist = ItemUtils.hasEquipList(toEquip);
|
||||
String equipItemClass = ItemUtils.getEquipClass(toEquip);//somehow resolve from toEquip
|
||||
String equipItemClass = ItemUtils.getEquipClass(toEquip);
|
||||
List<String> pointEquipClassList = point.getEquipClassWhitelist();
|
||||
boolean itemIsInPointWhitelist = pointEquipClassList.contains(equipItemClass);
|
||||
if(!hasEquipped && targetIsItem && !targetIsAttached && itemIsInPointWhitelist){
|
||||
//if we're the server, perform the attempt, otherwise send packet to server requesting to equip
|
||||
if(Globals.RUN_SERVER){
|
||||
serverAttemptEquip(toEquip, point);
|
||||
} else {
|
||||
String pointName = point.getEquipPointId();
|
||||
int serverSideID = Globals.entityManager.mapClientToServerId(toEquip.getId());
|
||||
NetworkMessage requestPickupMessage = InventoryMessage.constructclientRequestEquipItemMessage(pointName, serverSideID);
|
||||
Globals.clientConnection.queueOutgoingMessage(requestPickupMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void serverAttemptEquip(Entity inInventoryEntity, EquipPoint point){
|
||||
boolean hasEquipped = hasEquippedAtPoint(point.getEquipPointId());
|
||||
boolean targetIsItem = ItemUtils.isItem(inInventoryEntity);
|
||||
boolean targetHasWhitelist = ItemUtils.hasEquipList(inInventoryEntity);
|
||||
String equipItemClass = ItemUtils.getEquipClass(inInventoryEntity);
|
||||
List<String> pointEquipClassList = point.getEquipClassWhitelist();
|
||||
boolean itemIsInPointWhitelist = pointEquipClassList.contains(equipItemClass);
|
||||
if(!hasEquipped && targetIsItem && itemIsInPointWhitelist){
|
||||
//hydrate inventory item
|
||||
String itemType = ItemUtils.getType(inInventoryEntity);
|
||||
Entity inWorldItem = ItemUtils.spawnBasicItem(itemType);
|
||||
//bind in world with in inventory
|
||||
ItemUtils.setRealWorldEntity(inInventoryEntity, inWorldItem);
|
||||
|
||||
if(targetHasWhitelist){
|
||||
//by attaching are we going to be replacing meshes?
|
||||
String parentCreatureId = CreatureUtils.getType(parent);
|
||||
List<EquipWhitelist> whitelist = ItemUtils.getEquipWhitelist(inWorldItem);
|
||||
for(EquipWhitelist whitelistItem : whitelist){
|
||||
if(whitelistItem.getCreatureId().equals(parentCreatureId)){
|
||||
//put in map
|
||||
equipMap.put(point.getEquipPointId(),inWorldItem);
|
||||
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, inWorldItem, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation()));
|
||||
//make uncollidable
|
||||
if(inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){
|
||||
CollisionObject rigidBody = (CollisionObject)inWorldItem.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||
Globals.collisionEngine.deregisterPhysicsObject(rigidBody);
|
||||
}
|
||||
//hide toEquip actor
|
||||
EntityUtils.setDraw(inWorldItem, false);
|
||||
//make untargetable
|
||||
Globals.entityManager.setTargetable(inWorldItem, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//since we're not replacing meshes we must be attaching to a bone
|
||||
equipMap.put(point.getEquipPointId(),inWorldItem);
|
||||
AttachUtils.attachEntityToEntityAtBone(parent, inWorldItem, point.getBone(), AttachUtils.getEquipPointRotationOffset(point.getOffsetRotation()));
|
||||
if(inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY) && inWorldItem.containsKey(EntityDataStrings.PHYSICS_COLLIDABLE)){
|
||||
CollisionObject rigidBody = (CollisionObject)inWorldItem.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||
Globals.collisionEngine.deregisterPhysicsObject(rigidBody);
|
||||
}
|
||||
Globals.entityManager.setTargetable(inWorldItem, false);
|
||||
GravityUtils.attemptDeactivateGravity(inWorldItem);
|
||||
}
|
||||
//we need to send two packets
|
||||
//1) Remove item from original inventory
|
||||
//2) Add item with ID to "equipped" inventory
|
||||
//let clients know of the updates if we're the server
|
||||
//get the parent (typically creature) that contains the in-inventory item
|
||||
Entity containingEntity = ItemUtils.getContainingParent(inInventoryEntity);
|
||||
//actually switch containers
|
||||
boolean parentHasNaturalInventory = InventoryUtils.hasNaturalInventory(parent);
|
||||
boolean parentHasEquipInventory = InventoryUtils.hasEquipInventory(parent);
|
||||
//make sure the switch is possible
|
||||
if(parentHasEquipInventory && parentHasNaturalInventory){
|
||||
//actually switch containers
|
||||
UnrelationalInventoryState naturalInventory = InventoryUtils.getNaturalInventory(parent);
|
||||
RelationalInventoryState equipInventory = InventoryUtils.getEquipInventory(parent);
|
||||
naturalInventory.removeItem(inInventoryEntity);
|
||||
equipInventory.addItem(point.getEquipPointId(), inInventoryEntity);
|
||||
}
|
||||
//if they're a player, let the player know that the item has moved container
|
||||
if(CreatureUtils.hasControllerPlayerId(containingEntity)){
|
||||
//get player
|
||||
int playerId = CreatureUtils.getControllerPlayerId(containingEntity);
|
||||
Player controllerPlayer = Globals.playerManager.getPlayerFromId(playerId);
|
||||
//tell the player they don't have the item anymore
|
||||
NetworkMessage inventoryMessage = InventoryMessage.constructserverCommandMoveItemContainerMessage(
|
||||
inInventoryEntity.getId(),
|
||||
InventoryProtocol.INVENTORY_TYPE_EQUIP,
|
||||
point.getEquipPointId()
|
||||
);
|
||||
controllerPlayer.addMessage(inventoryMessage);
|
||||
}
|
||||
//get the chunk the equipper is in, and broadcast to that chunk that they equipped the item
|
||||
//get datacell
|
||||
ServerDataCell dataCell = Globals.dataCellManager.getDataCellAtPoint(EntityUtils.getPosition(parent));
|
||||
//broadcast attach entity
|
||||
int equipperId = parent.getId();
|
||||
String equipPointId = point.getEquipPointId();
|
||||
int inWorldItemId = inWorldItem.getId();
|
||||
NetworkMessage attachMessage = InventoryMessage.constructserverCommandEquipItemMessage(equipperId, equipPointId, inWorldItemId, itemType);
|
||||
//actually send the packet
|
||||
dataCell.broadcastNetworkMessage(attachMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public void clientAttemptEquip(Entity toEquip, EquipPoint point){
|
||||
boolean hasEquipped = hasEquippedAtPoint(point.getEquipPointId());
|
||||
boolean targetIsItem = ItemUtils.isItem(toEquip);
|
||||
boolean targetIsAttached = AttachUtils.isAttached(toEquip);
|
||||
boolean targetHasWhitelist = ItemUtils.hasEquipList(toEquip);
|
||||
String equipItemClass = ItemUtils.getEquipClass(toEquip);
|
||||
List<String> pointEquipClassList = point.getEquipClassWhitelist();
|
||||
boolean itemIsInPointWhitelist = pointEquipClassList.contains(equipItemClass);
|
||||
if(!hasEquipped && targetIsItem && !targetIsAttached && itemIsInPointWhitelist){
|
||||
@ -94,6 +227,7 @@ public class EquipState {
|
||||
Globals.collisionEngine.deregisterPhysicsObject(rigidBody);
|
||||
}
|
||||
Globals.entityManager.setTargetable(toEquip, false);
|
||||
GravityUtils.attemptDeactivateGravity(toEquip);
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,6 +287,33 @@ public class EquipState {
|
||||
public Entity getEquippedItemAtPoint(String point){
|
||||
return equipMap.get(point);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity has an equip state
|
||||
* @param entity The entity to check
|
||||
* @return True if the entity contains an equip state, false otherwise
|
||||
*/
|
||||
public static boolean hasEquipState(Entity entity){
|
||||
return entity.containsKey(EntityDataStrings.EQUIP_STATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the equip state on the entity
|
||||
* @param entity The entity to retrieve equip state from
|
||||
* @return The equip state on the entity
|
||||
*/
|
||||
public static EquipState getEquipState(Entity entity){
|
||||
return (EquipState)entity.getData(EntityDataStrings.EQUIP_STATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the equip state on the entity
|
||||
* @param entity The entity to attach the equip state to
|
||||
* @param equipState The equip state to attach
|
||||
*/
|
||||
public static void setEquipState(Entity entity, EquipState equipState){
|
||||
entity.putData(EntityDataStrings.EQUIP_STATE, equipState);
|
||||
}
|
||||
|
||||
// public void drop(Entity entity){
|
||||
// if(hasEquipPrimary()){
|
||||
@ -166,7 +327,67 @@ public class EquipState {
|
||||
// }
|
||||
// }
|
||||
|
||||
public void unequipPoint(String pointId){
|
||||
public void commandAttemptUnequip(String pointId){
|
||||
boolean hasEquipped = hasEquippedAtPoint(pointId);
|
||||
if(hasEquipped){
|
||||
//if we're the server, perform the attempt, otherwise send packet to server requesting to equip
|
||||
if(Globals.RUN_SERVER){
|
||||
serverAttemptUnequip(pointId);
|
||||
} else {
|
||||
NetworkMessage requestUnequipMessage = InventoryMessage.constructclientRequestUnequipItemMessage(pointId);
|
||||
Globals.clientConnection.queueOutgoingMessage(requestUnequipMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts the unequip on the server
|
||||
* @param pointId The slot to attempt to unequip
|
||||
*/
|
||||
public void serverAttemptUnequip(String pointId){
|
||||
boolean hasNaturalInventory = InventoryUtils.hasNaturalInventory(parent);
|
||||
boolean hasEquipInventory = InventoryUtils.hasEquipInventory(parent);
|
||||
if(hasEquipInventory && hasNaturalInventory){
|
||||
UnrelationalInventoryState naturalInventory = InventoryUtils.getNaturalInventory(parent);
|
||||
RelationalInventoryState equipInventory = InventoryUtils.getEquipInventory(parent);
|
||||
//switch the inventory it's under
|
||||
Entity ejectedItem = equipInventory.getItemSlot(pointId);
|
||||
equipInventory.removeItemSlot(pointId);
|
||||
naturalInventory.addItem(ejectedItem);
|
||||
//destroy in world item
|
||||
transformUnequipPoint(pointId);
|
||||
//tell all clients to unequip the world item
|
||||
//get datacell
|
||||
ServerDataCell dataCell = Globals.dataCellManager.getDataCellAtPoint(EntityUtils.getPosition(parent));
|
||||
//broadcast attach entity
|
||||
NetworkMessage unequipMessage = InventoryMessage.constructserverCommandUnequipItemMessage(parent.getId(), pointId);
|
||||
//actually send the packet
|
||||
dataCell.broadcastNetworkMessage(unequipMessage);
|
||||
//if the parent is a player entity, tell the player about the updated inventory stuff
|
||||
if(CreatureUtils.hasControllerPlayerId(parent)){
|
||||
//get player
|
||||
int playerId = CreatureUtils.getControllerPlayerId(parent);
|
||||
Player controllerPlayer = Globals.playerManager.getPlayerFromId(playerId);
|
||||
//tell the player they don't have the item anymore
|
||||
NetworkMessage inventoryMessage = InventoryMessage.constructserverCommandMoveItemContainerMessage(
|
||||
ejectedItem.getId(),
|
||||
InventoryProtocol.INVENTORY_TYPE_NATURAL,
|
||||
pointId
|
||||
);
|
||||
controllerPlayer.addMessage(inventoryMessage);
|
||||
}
|
||||
}
|
||||
// if(ItemUtils.getRealWorldEntity(item) != null){
|
||||
// ItemUtils.destroyInWorldItem(ItemUtils.getRealWorldEntity(item));
|
||||
// }
|
||||
// // eject from equip state
|
||||
// InventoryUtils.attemptDestroyItem(Globals.playerEntity,item);
|
||||
// // add to unrelational
|
||||
// sourceInventory.tryRemoveItem(item);
|
||||
// inventory.addItem(item);
|
||||
}
|
||||
|
||||
public void transformUnequipPoint(String pointId){
|
||||
Entity equipped = equipMap.remove(pointId);
|
||||
if(equipped != null){
|
||||
boolean targetHasWhitelist = ItemUtils.hasEquipList(equipped);
|
||||
@ -209,6 +430,10 @@ public class EquipState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasEquippedAtPoint(String point){
|
||||
return equipMap.containsKey(point);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package electrosphere.entity.state.gravity;
|
||||
import electrosphere.collision.dispatch.CollisionObject;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.collidable.CollidableTree;
|
||||
import electrosphere.entity.state.collidable.Impulse;
|
||||
import electrosphere.entity.state.movement.FallTree;
|
||||
import electrosphere.entity.state.movement.JumpTree;
|
||||
@ -91,7 +92,11 @@ public class GravityTree {
|
||||
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||
Vector3f newPosition;
|
||||
javax.vecmath.Matrix4f bodyTransformMatrix;
|
||||
|
||||
CollidableTree collidableTree = null;
|
||||
if(CollidableTree.hasCollidableTree(parent)){
|
||||
collidableTree = CollidableTree.getCollidableTree(parent);
|
||||
}
|
||||
|
||||
//parse attached network messages
|
||||
// for(EntityMessage message : networkMessageQueue){
|
||||
// networkMessageQueue.remove(message);
|
||||
@ -111,6 +116,15 @@ public class GravityTree {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
//Basically if we're still spinning keep applying gravity
|
||||
boolean angularVelocityLow = true;
|
||||
if(collidableTree != null){
|
||||
if(collidableTree.getAngularVelocityMagnitude() > 0.0001){
|
||||
angularVelocityLow = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//state machine
|
||||
switch(state){
|
||||
|
||||
@ -4,8 +4,14 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.state.BehaviorTree;
|
||||
import electrosphere.entity.state.equip.EquipState;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.game.data.creature.type.equip.EquipPoint;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.menu.WindowStrings;
|
||||
import electrosphere.menu.WindowUtils;
|
||||
import electrosphere.net.parser.net.message.InventoryMessage;
|
||||
import electrosphere.net.server.protocol.InventoryProtocol;
|
||||
|
||||
/**
|
||||
* Principally used to handle network messages related to inventory and thread synchronization
|
||||
@ -39,7 +45,32 @@ public class InventoryState implements BehaviorTree {
|
||||
case REMOVEITEMFROMINVENTORY:
|
||||
InventoryUtils.attemptEjectItem(parent, Globals.entityManager.getEntityFromId(message.getentityId()));
|
||||
break;
|
||||
case EQUIPITEM:
|
||||
case CLIENTREQUESTEQUIPITEM:{
|
||||
//item to equip
|
||||
Entity target = Globals.entityManager.getEntityFromId(message.getentityId());
|
||||
//perform transform if it makes sense
|
||||
if(InventoryUtils.hasEquipInventory(parent) && InventoryUtils.hasNaturalInventory(parent) && EquipState.hasEquipState(parent)){
|
||||
EquipState equipState = EquipState.getEquipState(parent);
|
||||
EquipPoint point = equipState.getEquipPoint(message.getequipPointId());
|
||||
equipState.commandAttemptEquip(target, point);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CLIENTREQUESTUNEQUIPITEM:{
|
||||
//make sure can unequip
|
||||
if(InventoryUtils.hasEquipInventory(parent) && InventoryUtils.hasNaturalInventory(parent) && EquipState.hasEquipState(parent)){
|
||||
EquipState equipState = EquipState.getEquipState(parent);
|
||||
EquipPoint point = equipState.getEquipPoint(message.getequipPointId());
|
||||
if(equipState.hasEquippedAtPoint(message.getequipPointId())){
|
||||
equipState.commandAttemptUnequip(message.getequipPointId());
|
||||
//tell player
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SERVERCOMMANDUNEQUIPITEM:
|
||||
case SERVERCOMMANDEQUIPITEM:
|
||||
case SERVERCOMMANDMOVEITEMCONTAINER:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -56,9 +87,60 @@ public class InventoryState implements BehaviorTree {
|
||||
}
|
||||
break;
|
||||
case REMOVEITEMFROMINVENTORY:
|
||||
InventoryUtils.removeItemFromNaturalInventory(parent, Globals.entityManager.getEntityFromServerId(message.getentityId()));
|
||||
InventoryUtils.removeItemFromInventories(parent, Globals.entityManager.getEntityFromServerId(message.getentityId()));
|
||||
break;
|
||||
case EQUIPITEM:
|
||||
case SERVERCOMMANDMOVEITEMCONTAINER: {
|
||||
//this is a command to switch an item from one inventory to another (ie equip->natural or vice-versa)
|
||||
switch(message.getcontainerType()){
|
||||
case InventoryProtocol.INVENTORY_TYPE_EQUIP:
|
||||
Entity target = Globals.entityManager.getEntityFromId(Globals.entityManager.mapServerToClientId(message.getentityId()));
|
||||
boolean isInventoryItem = ItemUtils.itemIsInInventory(target);
|
||||
boolean parentHasNaturalInventory = InventoryUtils.hasNaturalInventory(parent);
|
||||
boolean parentHasEquipInventory = InventoryUtils.hasEquipInventory(parent);
|
||||
String equipPointId = message.getequipPointId();
|
||||
//check that we can do the transform
|
||||
if(isInventoryItem && parentHasEquipInventory && parentHasNaturalInventory){
|
||||
//switch containers
|
||||
UnrelationalInventoryState naturalInventory = InventoryUtils.getNaturalInventory(parent);
|
||||
RelationalInventoryState equipInventory = InventoryUtils.getEquipInventory(parent);
|
||||
naturalInventory.removeItem(target);
|
||||
equipInventory.addItem(equipPointId, target);
|
||||
}
|
||||
break;
|
||||
case InventoryProtocol.INVENTORY_TYPE_NATURAL:
|
||||
target = Globals.entityManager.getEntityFromId(Globals.entityManager.mapServerToClientId(message.getentityId()));
|
||||
isInventoryItem = ItemUtils.itemIsInInventory(target);
|
||||
parentHasNaturalInventory = InventoryUtils.hasNaturalInventory(parent);
|
||||
parentHasEquipInventory = InventoryUtils.hasEquipInventory(parent);
|
||||
equipPointId = message.getequipPointId();
|
||||
//check that we can do the transform
|
||||
if(isInventoryItem && parentHasEquipInventory && parentHasNaturalInventory){
|
||||
//switch containers
|
||||
UnrelationalInventoryState naturalInventory = InventoryUtils.getNaturalInventory(parent);
|
||||
RelationalInventoryState equipInventory = InventoryUtils.getEquipInventory(parent);
|
||||
naturalInventory.addItem(target);
|
||||
equipInventory.removeItemSlot(equipPointId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//once we've switched the items around, redraw the inventory to reflect the updated contents
|
||||
WindowUtils.attemptRedrawInventoryWindows();
|
||||
}
|
||||
break;
|
||||
case SERVERCOMMANDUNEQUIPITEM: {
|
||||
if(Globals.playerEntity != null && EquipState.hasEquipState(Globals.playerEntity)){
|
||||
//unequip the item
|
||||
EquipState equipState = EquipState.getEquipState(Globals.playerEntity);
|
||||
Entity entityInSlot = equipState.getEquippedItemAtPoint(message.getequipPointId());
|
||||
equipState.transformUnequipPoint(message.getequipPointId());
|
||||
//destroy the in-world manifestation of said item
|
||||
Globals.entityManager.deregisterEntity(entityInSlot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CLIENTREQUESTEQUIPITEM:
|
||||
case CLIENTREQUESTUNEQUIPITEM:
|
||||
case SERVERCOMMANDEQUIPITEM:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,11 +73,13 @@ public class InventoryUtils {
|
||||
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);
|
||||
Entity inventoryItem = ItemUtils.recreateContainerItem(item, creature);
|
||||
//destroy the item that was left over
|
||||
ItemUtils.destroyInWorldItem(item);
|
||||
//store item in inventory
|
||||
inventory.addItem(inventoryItem);
|
||||
//set item containing parent
|
||||
ItemUtils.setContainingParent(inventoryItem, creature);
|
||||
//if we are the server, immediately send required packets
|
||||
if(Globals.RUN_SERVER){
|
||||
ServerDataCell dataCell = Globals.dataCellManager.getDataCellAtPoint(EntityUtils.getPosition(item));
|
||||
@ -135,11 +137,13 @@ public class InventoryUtils {
|
||||
//TODO: optimize by directly creating the container item instead of first spawning regular item
|
||||
Entity spawnedItem = ItemUtils.spawnBasicItem(type);
|
||||
//convert to in-inventory
|
||||
Entity inventoryItem = ItemUtils.recreateContainerItem(spawnedItem);
|
||||
Entity inventoryItem = ItemUtils.recreateContainerItem(spawnedItem, parentContainer);
|
||||
//destroy the item that was left over
|
||||
ItemUtils.destroyInWorldItem(spawnedItem);
|
||||
//store item in inventory
|
||||
inventory.addItem(inventoryItem);
|
||||
//set item containing parent
|
||||
ItemUtils.setContainingParent(inventoryItem, parentContainer);
|
||||
//return
|
||||
return inventoryItem;
|
||||
}
|
||||
@ -149,11 +153,11 @@ public class InventoryUtils {
|
||||
|
||||
|
||||
/**
|
||||
* Attempts the transform to eject an item from an inventory, if this is the server it has added side effect of sending packets on success
|
||||
* [SERVER ONLY] Attempts the transform to eject an item from an inventory, if this is the server it has added side effect of sending packets on success
|
||||
* @param creature The creature to eject the item from
|
||||
* @param item The item to eject
|
||||
*/
|
||||
public static void attemptEjectItemTransform(Entity creature, Entity item){
|
||||
public static void serverAttemptEjectItemTransform(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);
|
||||
@ -175,23 +179,31 @@ public class InventoryUtils {
|
||||
Entity realWorldItem = ItemUtils.getRealWorldEntity(item);
|
||||
if(realWorldItem != null){
|
||||
//drop item
|
||||
EquipState equipState = (EquipState)creature.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.unequipPoint(inventory.getItemSlot(item));
|
||||
EquipState equipState = EquipState.getEquipState(creature);
|
||||
equipState.transformUnequipPoint(inventory.getItemSlot(item));
|
||||
// equipState.serverAttemptUnequip(inventory.getItemSlot(item));
|
||||
//
|
||||
//Tell clients to destroy the attached item
|
||||
Vector3d oldItemPos = EntityUtils.getPosition(realWorldItem);
|
||||
//get closest chunk
|
||||
ServerDataCell dataCell = Globals.dataCellManager.getDataCellAtPoint(oldItemPos);
|
||||
//broadcast destroy item
|
||||
NetworkMessage destroyMessage = InventoryMessage.constructserverCommandUnequipItemMessage(creature.getId(), inventory.getItemSlot(item));
|
||||
dataCell.broadcastNetworkMessage(destroyMessage);
|
||||
}
|
||||
//remove item from inventory
|
||||
inventory.tryRemoveItem(item);
|
||||
}
|
||||
//if server, tell player that the item is no longer in their inventory
|
||||
if(Globals.RUN_SERVER){
|
||||
//if the entity is a player entity
|
||||
if(CreatureUtils.hasControllerPlayerId(creature)){
|
||||
//get player
|
||||
int playerId = CreatureUtils.getControllerPlayerId(creature);
|
||||
Player controllerPlayer = Globals.playerManager.getPlayerFromId(playerId);
|
||||
//tell the player they don't have the item anymore
|
||||
controllerPlayer.addMessage(InventoryMessage.constructremoveItemFromInventoryMessage(item.getId()));
|
||||
}
|
||||
//
|
||||
//tell player that the item is no longer in their inventory
|
||||
if(CreatureUtils.hasControllerPlayerId(creature)){
|
||||
//get player
|
||||
int playerId = CreatureUtils.getControllerPlayerId(creature);
|
||||
Player controllerPlayer = Globals.playerManager.getPlayerFromId(playerId);
|
||||
//tell the player they don't have the item anymore
|
||||
controllerPlayer.addMessage(InventoryMessage.constructremoveItemFromInventoryMessage(item.getId()));
|
||||
}
|
||||
//
|
||||
//compose item into in-world entity
|
||||
Entity inWorldItem = ItemUtils.spawnBasicItem(ItemUtils.getType(item));
|
||||
//delete in container item
|
||||
@ -202,13 +214,12 @@ public class InventoryUtils {
|
||||
EntityUtils.getPosition(inWorldItem).set(dropSpot);
|
||||
//activate gravity
|
||||
GravityUtils.attemptActivateGravity(inWorldItem);
|
||||
//if server, add the item to closest data cell
|
||||
if(Globals.RUN_SERVER){
|
||||
//get closest chunk
|
||||
ServerDataCell dataCell = Globals.dataCellManager.getDataCellAtPoint(dropSpot);
|
||||
//add item
|
||||
Globals.dataCellManager.initializeServerSideEntity(inWorldItem, dataCell);
|
||||
}
|
||||
//
|
||||
//add the item to closest data cell
|
||||
//get closest chunk
|
||||
ServerDataCell dataCell = Globals.dataCellManager.getDataCellAtPoint(dropSpot);
|
||||
//add item
|
||||
Globals.dataCellManager.initializeServerSideEntity(inWorldItem, dataCell);
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +227,7 @@ public class InventoryUtils {
|
||||
public static void attemptEjectItem(Entity creature, Entity item){
|
||||
if(Globals.RUN_SERVER){
|
||||
//if we're the server, immediately attempt the transform
|
||||
attemptEjectItemTransform(creature,item);
|
||||
serverAttemptEjectItemTransform(creature,item);
|
||||
} else {
|
||||
//if we're the client, tell the server we want to try the transform
|
||||
NetworkMessage requestPickupMessage = InventoryMessage.constructremoveItemFromInventoryMessage(Globals.entityManager.mapClientToServerId(item.getId()));
|
||||
@ -225,12 +236,12 @@ public class InventoryUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* [CLIENT ONLY] Called when the server says to remove an item from natural inventory
|
||||
* [CLIENT ONLY] Called when the server says to remove an item from all inventories
|
||||
* Only does the remove, doesn't create the in-world item
|
||||
* @param creature The creature to remove the item from (likely to be player entity)
|
||||
* @param item The item to remove
|
||||
*/
|
||||
public static void removeItemFromNaturalInventory(Entity creature, Entity item){
|
||||
public static void removeItemFromInventories(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);
|
||||
@ -252,8 +263,8 @@ public class InventoryUtils {
|
||||
Entity realWorldItem = ItemUtils.getRealWorldEntity(item);
|
||||
if(realWorldItem != null){
|
||||
//drop item
|
||||
EquipState equipState = (EquipState)creature.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.unequipPoint(inventory.getItemSlot(item));
|
||||
EquipState equipState = EquipState.getEquipState(creature);
|
||||
equipState.transformUnequipPoint(inventory.getItemSlot(item));
|
||||
}
|
||||
//remove item from inventory
|
||||
inventory.tryRemoveItem(item);
|
||||
@ -261,36 +272,37 @@ public class InventoryUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//need creature so we can figure out where to drop the item
|
||||
public static void attemptDestroyItem(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 hasNaturalInventory = hasNaturalInventory(creature);
|
||||
boolean hasEquipInventory = hasEquipInventory(creature);
|
||||
if(creatureIsCreature && itemIsItem){
|
||||
if(hasNaturalInventory){
|
||||
//get inventory
|
||||
UnrelationalInventoryState inventory = getNaturalInventory(creature);
|
||||
//remove item from inventory
|
||||
inventory.removeItem(item);
|
||||
}
|
||||
if(hasEquipInventory){
|
||||
//get inventory
|
||||
RelationalInventoryState inventory = getEquipInventory(creature);
|
||||
//get real world item
|
||||
Entity realWorldItem = ItemUtils.getRealWorldEntity(item);
|
||||
if(realWorldItem != null){
|
||||
//drop item
|
||||
EquipState equipState = (EquipState)creature.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.unequipPoint(inventory.getItemSlot(item));
|
||||
}
|
||||
//remove item from inventory
|
||||
inventory.tryRemoveItem(item);
|
||||
}
|
||||
//delete in container item
|
||||
ItemUtils.destroyInInventoryItem(item);
|
||||
}
|
||||
}
|
||||
// public static void attemptDestroyItem(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 hasNaturalInventory = hasNaturalInventory(creature);
|
||||
// boolean hasEquipInventory = hasEquipInventory(creature);
|
||||
// if(creatureIsCreature && itemIsItem){
|
||||
// if(hasNaturalInventory){
|
||||
// //get inventory
|
||||
// UnrelationalInventoryState inventory = getNaturalInventory(creature);
|
||||
// //remove item from inventory
|
||||
// inventory.removeItem(item);
|
||||
// }
|
||||
// if(hasEquipInventory){
|
||||
// //get inventory
|
||||
// RelationalInventoryState inventory = getEquipInventory(creature);
|
||||
// //get real world item
|
||||
// Entity realWorldItem = ItemUtils.getRealWorldEntity(item);
|
||||
// if(realWorldItem != null){
|
||||
// //drop item
|
||||
// EquipState equipState = EquipState.getEquipState(creature);
|
||||
// equipState.transformUnequipPoint(inventory.getItemSlot(item));
|
||||
// }
|
||||
// //remove item from inventory
|
||||
// inventory.tryRemoveItem(item);
|
||||
// }
|
||||
// //delete in container item
|
||||
// ItemUtils.destroyInInventoryItem(item);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ public class CreatureUtils {
|
||||
}
|
||||
}
|
||||
if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){
|
||||
rVal.putData(EntityDataStrings.EQUIP_STATE, new EquipState(rVal,rawType.getEquipPoints()));
|
||||
EquipState.setEquipState(rVal, new EquipState(rVal,rawType.getEquipPoints()));
|
||||
rVal.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints()));
|
||||
}
|
||||
for(String token : rawType.getTokens()){
|
||||
@ -280,9 +280,6 @@ public class CreatureUtils {
|
||||
case "TARGETABLE":
|
||||
Globals.entityManager.registerTargetableEntity(rVal);
|
||||
break;
|
||||
case "CAN_EQUIP":
|
||||
// rVal.putData(EntityDataStrings.EQUIP_STATE, new EquipState(rVal,"MiddleLower.R"));
|
||||
break;
|
||||
case "INVENTORY":
|
||||
rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10));
|
||||
InventoryUtils.setInventoryState(rVal, InventoryState.createInventoryState(rVal));
|
||||
|
||||
@ -244,9 +244,29 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits an entity which represents the item inside a container
|
||||
* Sets the parent that contains this item
|
||||
* @param item The item entity
|
||||
* @param parent The parent which contains the item entity
|
||||
*/
|
||||
public static Entity recreateContainerItem(Entity item){
|
||||
public static void setContainingParent(Entity item, Entity parent){
|
||||
item.putData(EntityDataStrings.ITEM_CONTAINING_PARENT, parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent that contains the item
|
||||
* @param item The item
|
||||
* @return The parent that contains the item
|
||||
*/
|
||||
public static Entity getContainingParent(Entity item){
|
||||
return (Entity)item.getData(EntityDataStrings.ITEM_CONTAINING_PARENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits an entity which represents the item inside a container
|
||||
* @param item The item to recreate
|
||||
* @param containingParent The parent that contains the item
|
||||
*/
|
||||
public static Entity recreateContainerItem(Entity item, Entity containingParent){
|
||||
if(isItem(item)){
|
||||
Entity rVal = new Entity();
|
||||
if(getEquipWhitelist(item) != null){
|
||||
@ -256,6 +276,7 @@ public class ItemUtils {
|
||||
rVal.putData(EntityDataStrings.ITEM_EQUIP_CLASS, item.getData(EntityDataStrings.ITEM_EQUIP_CLASS));
|
||||
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
||||
rVal.putData(EntityDataStrings.ITEM_IS_IN_INVENTORY, true);
|
||||
ItemUtils.setContainingParent(rVal, containingParent);
|
||||
rVal.putData(EntityDataStrings.ITEM_TYPE, item.getData(EntityDataStrings.ITEM_TYPE));
|
||||
Globals.entityManager.registerEntity(rVal);
|
||||
return rVal;
|
||||
|
||||
@ -206,9 +206,9 @@ public class OpportunisticAttacker extends AI {
|
||||
|
||||
boolean hasWeapon(){
|
||||
boolean rVal = false;
|
||||
if(character.containsKey(EntityDataStrings.EQUIP_STATE)){
|
||||
if(EquipState.hasEquipState(character)){
|
||||
//TODO:fix hasWeapon
|
||||
EquipState equipState = (EquipState)character.getData(EntityDataStrings.EQUIP_STATE);
|
||||
EquipState equipState = EquipState.getEquipState(character);
|
||||
// if(equipState.hasEquipPrimary()){
|
||||
// rVal = true;
|
||||
// }
|
||||
@ -243,8 +243,8 @@ public class OpportunisticAttacker extends AI {
|
||||
}
|
||||
|
||||
void pickupWeapon(){
|
||||
if(character.containsKey(EntityDataStrings.EQUIP_STATE)){
|
||||
EquipState equipState = (EquipState)character.getData(EntityDataStrings.EQUIP_STATE);
|
||||
if(EquipState.hasEquipState(character)){
|
||||
EquipState equipState = EquipState.getEquipState(character);
|
||||
// if(!equipState.hasEquipPrimary()){
|
||||
// equipState.attemptEquip(target);
|
||||
// }
|
||||
|
||||
@ -110,7 +110,7 @@ public class MicroSimulation {
|
||||
}
|
||||
//tally collidables and offset position accordingly
|
||||
for(Entity currentCollidable : Globals.entityManager.getCollidables()){
|
||||
CollidableTree tree = EntityUtils.getCollidableTree(currentCollidable);
|
||||
CollidableTree tree = CollidableTree.getCollidableTree(currentCollidable);
|
||||
tree.simulate();
|
||||
}
|
||||
//targeting crosshair
|
||||
|
||||
@ -26,8 +26,8 @@ public class LoggerInterface {
|
||||
loggerGameLogic = new Logger(LogLevel.WARNING);
|
||||
loggerRenderer = new Logger(LogLevel.WARNING);
|
||||
loggerEngine = new Logger(LogLevel.WARNING);
|
||||
loggerAuth = new Logger(LogLevel.INFO);
|
||||
loggerDB = new Logger(LogLevel.INFO);
|
||||
loggerAuth = new Logger(LogLevel.WARNING);
|
||||
loggerDB = new Logger(LogLevel.WARNING);
|
||||
loggerStartup.INFO("Initialized loggers");
|
||||
}
|
||||
}
|
||||
|
||||
@ -479,46 +479,7 @@ public class MenuGenerators {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static Element worldItemDropCaptureWindow(){
|
||||
Window rVal = new Window(0,0,Globals.WINDOW_WIDTH,Globals.WINDOW_HEIGHT);
|
||||
Div div = new Div();
|
||||
div.setOnDragRelease(new DragEventCallback() {public boolean execute(DragEvent event){
|
||||
if(Globals.draggedItem != null){
|
||||
if(Globals.dragSourceInventory instanceof UnrelationalInventoryState){
|
||||
UnrelationalInventoryState inventory = (UnrelationalInventoryState) Globals.dragSourceInventory;
|
||||
//drop item
|
||||
InventoryUtils.attemptEjectItem(Globals.playerEntity,Globals.draggedItem);
|
||||
//clear ui
|
||||
WindowUtils.cleanItemDraggingWindow();
|
||||
String sourceWindowId = WindowUtils.getInventoryWindowID(inventory.getId());
|
||||
WindowUtils.replaceWindow(sourceWindowId,MenuGeneratorsInventory.createNaturalInventoryMenu(inventory));
|
||||
//null globals
|
||||
Globals.dragSourceInventory = null;
|
||||
Globals.draggedItem = null;
|
||||
return false;
|
||||
} else if(Globals.dragSourceInventory instanceof RelationalInventoryState){
|
||||
RelationalInventoryState inventory = (RelationalInventoryState) Globals.dragSourceInventory;
|
||||
//drop item
|
||||
InventoryUtils.attemptEjectItem(Globals.playerEntity,Globals.draggedItem);
|
||||
//clear ui
|
||||
WindowUtils.cleanItemDraggingWindow();
|
||||
String sourceWindowId = WindowStrings.WINDOW_CHARACTER;
|
||||
WindowUtils.replaceWindow(sourceWindowId,MenuGeneratorsInventory.createCharacterInventoryMenu(inventory));
|
||||
//null globals
|
||||
Globals.dragSourceInventory = null;
|
||||
Globals.draggedItem = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}});
|
||||
div.setPositionX(0);
|
||||
div.setPositionY(0);
|
||||
div.setWidth(Globals.WINDOW_WIDTH);
|
||||
div.setHeight(Globals.WINDOW_HEIGHT);
|
||||
rVal.addChild(div);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
public static Window createInGameMainMenu(){
|
||||
// int screenTop = Globals.WINDOW_HEIGHT - 150;
|
||||
|
||||
@ -20,6 +20,7 @@ import electrosphere.renderer.ui.elements.Label;
|
||||
import electrosphere.renderer.ui.events.ClickEvent;
|
||||
import electrosphere.renderer.ui.events.DragEvent;
|
||||
import electrosphere.renderer.ui.events.NavigationEvent;
|
||||
import electrosphere.renderer.ui.Element;
|
||||
import electrosphere.renderer.ui.Window;
|
||||
import electrosphere.renderer.ui.ClickableElement.ClickEventCallback;
|
||||
import electrosphere.renderer.ui.DraggableElement.DragEventCallback;
|
||||
@ -58,11 +59,17 @@ public class MenuGeneratorsInventory {
|
||||
if(Globals.dragSourceInventory instanceof UnrelationalInventoryState){
|
||||
UnrelationalInventoryState sourceInventory = (UnrelationalInventoryState)Globals.dragSourceInventory;
|
||||
//transfer item
|
||||
sourceInventory.removeItem(Globals.draggedItem);
|
||||
inventory.addItem(Globals.draggedItem);
|
||||
//null out global state
|
||||
Globals.dragSourceInventory = null;
|
||||
Globals.draggedItem = null;
|
||||
// sourceInventory.removeItem(Globals.draggedItem);
|
||||
// inventory.addItem(Globals.draggedItem);
|
||||
// //null out global state
|
||||
// Globals.dragSourceInventory = null;
|
||||
// Globals.draggedItem = null;
|
||||
Entity item = Globals.draggedItem;
|
||||
if(EquipState.hasEquipState(Globals.playerEntity) && InventoryUtils.hasEquipInventory(Globals.playerEntity)){
|
||||
RelationalInventoryState equipInventory = InventoryUtils.getEquipInventory(Globals.playerEntity);
|
||||
EquipState equipState = EquipState.getEquipState(Globals.playerEntity);
|
||||
equipState.commandAttemptUnequip(equipInventory.getItemSlot(item));
|
||||
}
|
||||
//clear item container ui
|
||||
WindowUtils.cleanItemDraggingWindow();
|
||||
//rerender both inventories
|
||||
@ -143,18 +150,14 @@ public class MenuGeneratorsInventory {
|
||||
if(Globals.dragSourceInventory instanceof RelationalInventoryState){
|
||||
RelationalInventoryState sourceInventory = (RelationalInventoryState) Globals.dragSourceInventory;
|
||||
Entity item = Globals.draggedItem;
|
||||
//destroy real world item
|
||||
if(ItemUtils.getRealWorldEntity(item) != null){
|
||||
ItemUtils.destroyInWorldItem(ItemUtils.getRealWorldEntity(item));
|
||||
if(EquipState.hasEquipState(Globals.playerEntity) && InventoryUtils.hasEquipInventory(Globals.playerEntity)){
|
||||
RelationalInventoryState equipInventory = InventoryUtils.getEquipInventory(Globals.playerEntity);
|
||||
EquipState equipState = EquipState.getEquipState(Globals.playerEntity);
|
||||
equipState.commandAttemptUnequip(equipInventory.getItemSlot(item));
|
||||
}
|
||||
//eject from equip state
|
||||
InventoryUtils.attemptDestroyItem(Globals.playerEntity,item);
|
||||
//add to unrelational
|
||||
sourceInventory.tryRemoveItem(item);
|
||||
inventory.addItem(item);
|
||||
//update ui
|
||||
Globals.dragSourceInventory = null;
|
||||
Globals.draggedItem = null;
|
||||
// Globals.dragSourceInventory = null;
|
||||
// Globals.draggedItem = null;
|
||||
//clear item container ui
|
||||
WindowUtils.cleanItemDraggingWindow();
|
||||
//rerender both inventories
|
||||
@ -310,17 +313,9 @@ public class MenuGeneratorsInventory {
|
||||
UnrelationalInventoryState sourceInventory = (UnrelationalInventoryState) Globals.dragSourceInventory;
|
||||
Entity item = Globals.draggedItem;
|
||||
if(inventory.canEquipItemToSlot(item, slots.get(itemId))){
|
||||
//transfer item
|
||||
sourceInventory.removeItem(item);
|
||||
inventory.addItem(slots.get(itemId), item);
|
||||
//hydrate inventory item
|
||||
Entity inWorldItem = ItemUtils.spawnBasicItem(ItemUtils.getType(item));
|
||||
//bind in world with in inventory
|
||||
ItemUtils.setRealWorldEntity(item, inWorldItem);
|
||||
//fire equip event to equip state
|
||||
EquipState equipState = (EquipState)Globals.playerEntity.getData(EntityDataStrings.EQUIP_STATE);
|
||||
equipState.attemptEquip(inWorldItem,inventory.getEquipPointFromSlot(slots.get(itemId)));
|
||||
GravityUtils.attemptDeactivateGravity(inWorldItem);
|
||||
EquipState equipState = EquipState.getEquipState(Globals.playerEntity);
|
||||
equipState.commandAttemptEquip(item,inventory.getEquipPointFromSlot(slots.get(itemId)));
|
||||
//play sound effect
|
||||
AudioUtils.playAudio("Audio/inventorySlotItem.ogg");
|
||||
}
|
||||
@ -369,4 +364,45 @@ public class MenuGeneratorsInventory {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static Element worldItemDropCaptureWindow(){
|
||||
Window rVal = new Window(0,0,Globals.WINDOW_WIDTH,Globals.WINDOW_HEIGHT);
|
||||
Div div = new Div();
|
||||
div.setOnDragRelease(new DragEventCallback() {public boolean execute(DragEvent event){
|
||||
if(Globals.draggedItem != null){
|
||||
if(Globals.dragSourceInventory instanceof UnrelationalInventoryState){
|
||||
UnrelationalInventoryState inventory = (UnrelationalInventoryState) Globals.dragSourceInventory;
|
||||
//drop item
|
||||
InventoryUtils.attemptEjectItem(Globals.playerEntity,Globals.draggedItem);
|
||||
//clear ui
|
||||
WindowUtils.cleanItemDraggingWindow();
|
||||
String sourceWindowId = WindowUtils.getInventoryWindowID(inventory.getId());
|
||||
WindowUtils.replaceWindow(sourceWindowId,MenuGeneratorsInventory.createNaturalInventoryMenu(inventory));
|
||||
//null globals
|
||||
Globals.dragSourceInventory = null;
|
||||
Globals.draggedItem = null;
|
||||
return false;
|
||||
} else if(Globals.dragSourceInventory instanceof RelationalInventoryState){
|
||||
RelationalInventoryState inventory = (RelationalInventoryState) Globals.dragSourceInventory;
|
||||
//drop item
|
||||
InventoryUtils.attemptEjectItem(Globals.playerEntity,Globals.draggedItem);
|
||||
//clear ui
|
||||
WindowUtils.cleanItemDraggingWindow();
|
||||
String sourceWindowId = WindowStrings.WINDOW_CHARACTER;
|
||||
WindowUtils.replaceWindow(sourceWindowId,MenuGeneratorsInventory.createCharacterInventoryMenu(inventory));
|
||||
//null globals
|
||||
Globals.dragSourceInventory = null;
|
||||
Globals.draggedItem = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}});
|
||||
div.setPositionX(0);
|
||||
div.setPositionY(0);
|
||||
div.setWidth(Globals.WINDOW_WIDTH);
|
||||
div.setHeight(Globals.WINDOW_HEIGHT);
|
||||
rVal.addChild(div);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package electrosphere.menu;
|
||||
|
||||
import electrosphere.entity.state.inventory.InventoryUtils;
|
||||
import electrosphere.entity.state.inventory.RelationalInventoryState;
|
||||
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.renderer.ui.ContainerElement;
|
||||
import electrosphere.renderer.ui.DrawableElement;
|
||||
@ -68,7 +71,29 @@ public class WindowUtils {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* [CLIENT ONLY] Attempts to redraw open player character inventory screens (ie when there's an inventory update over network)
|
||||
*/
|
||||
public static void attemptRedrawInventoryWindows(){
|
||||
//make sure we're client and the player entity exists
|
||||
if(Globals.RUN_CLIENT && Globals.playerEntity != null){
|
||||
//check equip inventory
|
||||
if(InventoryUtils.hasEquipInventory(Globals.playerEntity) && Globals.elementManager.containsWindow(WindowStrings.WINDOW_CHARACTER)){
|
||||
//redraw if necessary
|
||||
RelationalInventoryState inventory = InventoryUtils.getEquipInventory(Globals.playerEntity);
|
||||
WindowUtils.replaceWindow(WindowStrings.WINDOW_CHARACTER, MenuGeneratorsInventory.createCharacterInventoryMenu(inventory));
|
||||
}
|
||||
//check natural inventory
|
||||
if(InventoryUtils.hasNaturalInventory(Globals.playerEntity)){
|
||||
//we need to know the inventory to know which window to check as there can be multiple unrelational inventory screens open
|
||||
UnrelationalInventoryState inventory = InventoryUtils.getNaturalInventory(Globals.playerEntity);
|
||||
if(Globals.elementManager.containsWindow(WindowUtils.getInventoryWindowID(inventory.getId()))){
|
||||
//once we have the natural inventory, redraw
|
||||
WindowUtils.replaceWindow(WindowUtils.getInventoryWindowID(inventory.getId()), MenuGeneratorsInventory.createNaturalInventoryMenu(inventory));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -95,7 +120,7 @@ public class WindowUtils {
|
||||
}
|
||||
|
||||
static void initItemDropWindow(){
|
||||
Globals.elementManager.registerWindow(WindowStrings.WINDDOW_ITEM_DROP, MenuGenerators.worldItemDropCaptureWindow());
|
||||
Globals.elementManager.registerWindow(WindowStrings.WINDDOW_ITEM_DROP, MenuGeneratorsInventory.worldItemDropCaptureWindow());
|
||||
}
|
||||
|
||||
static void initItemDragContainerWindow(){
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
package electrosphere.net.client.protocol;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.state.equip.EquipState;
|
||||
import electrosphere.entity.state.inventory.InventoryState;
|
||||
import electrosphere.entity.state.inventory.InventoryUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.game.data.creature.type.equip.EquipPoint;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.InventoryMessage;
|
||||
@ -19,7 +22,25 @@ public class InventoryProtocol {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EQUIPITEM:
|
||||
case SERVERCOMMANDEQUIPITEM: {
|
||||
LoggerInterface.loggerNetworking.DEBUG("[CLIENT] EQUIP ITEM " + message.getentityId());
|
||||
//translate equipper id
|
||||
Entity equipper = Globals.entityManager.getEntityFromId(Globals.entityManager.mapServerToClientId(message.getequipperId()));
|
||||
//spawn in world id
|
||||
Entity inWorldEntity = ItemUtils.spawnBasicItem(message.getitemTemplate());
|
||||
if(inWorldEntity != null){
|
||||
//translate id
|
||||
Globals.entityManager.mapIdToId(inWorldEntity.getId(), message.getentityId());
|
||||
//grab equip state
|
||||
EquipState equipState = EquipState.getEquipState(equipper);
|
||||
//create entity from template in message
|
||||
//get equippoint
|
||||
String equipPointName = message.getequipPointId();
|
||||
EquipPoint equipPoint = equipState.getEquipPoint(equipPointName);
|
||||
//attach
|
||||
equipState.clientAttemptEquip(inWorldEntity, equipPoint);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REMOVEITEMFROMINVENTORY:
|
||||
LoggerInterface.loggerNetworking.DEBUG("[CLIENT] REMOVE ITEM FROM INVENTORY " + message.getentityId());
|
||||
@ -30,6 +51,29 @@ public class InventoryProtocol {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SERVERCOMMANDMOVEITEMCONTAINER:
|
||||
LoggerInterface.loggerNetworking.DEBUG("[CLIENT] MOVE ITEM INVENTORY " + message.getentityId());
|
||||
if(Globals.playerEntity != null){
|
||||
InventoryState inventoryState;
|
||||
if((inventoryState = InventoryUtils.getInventoryState(Globals.playerEntity))!=null){
|
||||
inventoryState.addNetworkMessage(message);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SERVERCOMMANDUNEQUIPITEM: {
|
||||
LoggerInterface.loggerNetworking.DEBUG("[CLIENT] UNEQUIP ITEM " + message.getentityId());
|
||||
if(Globals.playerEntity != null){
|
||||
InventoryState inventoryState;
|
||||
if((inventoryState = InventoryUtils.getInventoryState(Globals.playerEntity))!=null){
|
||||
inventoryState.addNetworkMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CLIENTREQUESTUNEQUIPITEM:
|
||||
case CLIENTREQUESTEQUIPITEM:
|
||||
//silently ignore
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,16 +102,16 @@ public class AuthMessage extends NetworkMessage {
|
||||
return false;
|
||||
}
|
||||
int passSize = 0;
|
||||
if(currentStreamLength < 6){
|
||||
if(currentStreamLength < 10){
|
||||
return false;
|
||||
} else {
|
||||
temporaryByteQueue.add(byteStream.get(2 + 0));
|
||||
temporaryByteQueue.add(byteStream.get(2 + 1));
|
||||
temporaryByteQueue.add(byteStream.get(2 + 2));
|
||||
temporaryByteQueue.add(byteStream.get(2 + 3));
|
||||
temporaryByteQueue.add(byteStream.get(6 + userSize + 0));
|
||||
temporaryByteQueue.add(byteStream.get(6 + userSize + 1));
|
||||
temporaryByteQueue.add(byteStream.get(6 + userSize + 2));
|
||||
temporaryByteQueue.add(byteStream.get(6 + userSize + 3));
|
||||
passSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||
}
|
||||
if(currentStreamLength < 6 + passSize){
|
||||
if(currentStreamLength < 10 + userSize + passSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -308,13 +308,13 @@ public class EntityMessage extends NetworkMessage {
|
||||
if(currentStreamLength < 14 + entitySubtypeSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 18){
|
||||
if(currentStreamLength < 22 + entitySubtypeSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 26){
|
||||
if(currentStreamLength < 30 + entitySubtypeSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 34){
|
||||
if(currentStreamLength < 38 + entitySubtypeSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -363,13 +363,13 @@ public class EntityMessage extends NetworkMessage {
|
||||
if(currentStreamLength < 10 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 14){
|
||||
if(currentStreamLength < 18 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 22){
|
||||
if(currentStreamLength < 26 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 30){
|
||||
if(currentStreamLength < 34 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -416,13 +416,13 @@ public class EntityMessage extends NetworkMessage {
|
||||
if(currentStreamLength < 10 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 14){
|
||||
if(currentStreamLength < 18 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 22){
|
||||
if(currentStreamLength < 26 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 30){
|
||||
if(currentStreamLength < 34 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -669,7 +669,7 @@ public class EntityMessage extends NetworkMessage {
|
||||
if(currentStreamLength < 10 + boneSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 10){
|
||||
if(currentStreamLength < 14 + boneSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -9,13 +9,19 @@ public class InventoryMessage extends NetworkMessage {
|
||||
public enum InventoryMessageType {
|
||||
ADDITEMTOINVENTORY,
|
||||
REMOVEITEMFROMINVENTORY,
|
||||
EQUIPITEM,
|
||||
CLIENTREQUESTEQUIPITEM,
|
||||
SERVERCOMMANDMOVEITEMCONTAINER,
|
||||
SERVERCOMMANDEQUIPITEM,
|
||||
SERVERCOMMANDUNEQUIPITEM,
|
||||
CLIENTREQUESTUNEQUIPITEM,
|
||||
}
|
||||
|
||||
InventoryMessageType messageType;
|
||||
String itemTemplate;
|
||||
String equipPointId;
|
||||
int entityId;
|
||||
int equipperId;
|
||||
int containerType;
|
||||
|
||||
InventoryMessage(InventoryMessageType messageType){
|
||||
this.type = MessageType.INVENTORY_MESSAGE;
|
||||
@ -50,6 +56,22 @@ public class InventoryMessage extends NetworkMessage {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public int getequipperId() {
|
||||
return equipperId;
|
||||
}
|
||||
|
||||
public void setequipperId(int equipperId) {
|
||||
this.equipperId = equipperId;
|
||||
}
|
||||
|
||||
public int getcontainerType() {
|
||||
return containerType;
|
||||
}
|
||||
|
||||
public void setcontainerType(int containerType) {
|
||||
this.containerType = containerType;
|
||||
}
|
||||
|
||||
static void stripPacketHeader(List<Byte> byteStream){
|
||||
byteStream.remove(0);
|
||||
byteStream.remove(0);
|
||||
@ -65,8 +87,16 @@ public class InventoryMessage extends NetworkMessage {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_EQUIPITEM:
|
||||
return InventoryMessage.canParseequipItemMessage(byteStream);
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTEQUIPITEM:
|
||||
return InventoryMessage.canParseclientRequestEquipItemMessage(byteStream);
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDMOVEITEMCONTAINER:
|
||||
return InventoryMessage.canParseserverCommandMoveItemContainerMessage(byteStream);
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDEQUIPITEM:
|
||||
return InventoryMessage.canParseserverCommandEquipItemMessage(byteStream);
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDUNEQUIPITEM:
|
||||
return InventoryMessage.canParseserverCommandUnequipItemMessage(byteStream);
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTUNEQUIPITEM:
|
||||
return InventoryMessage.canParseclientRequestUnequipItemMessage(byteStream);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -123,7 +153,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean canParseequipItemMessage(List<Byte> byteStream){
|
||||
public static boolean canParseclientRequestEquipItemMessage(List<Byte> byteStream){
|
||||
int currentStreamLength = byteStream.size();
|
||||
List<Byte> temporaryByteQueue = new LinkedList();
|
||||
int equipPointIdSize = 0;
|
||||
@ -139,10 +169,78 @@ public class InventoryMessage extends NetworkMessage {
|
||||
if(currentStreamLength < 6 + equipPointIdSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 10 + equipPointIdSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static InventoryMessage parseclientRequestEquipItemMessage(List<Byte> byteStream){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTEQUIPITEM);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static InventoryMessage constructclientRequestEquipItemMessage(String equipPointId,int entityId){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTEQUIPITEM);
|
||||
rVal.setequipPointId(equipPointId);
|
||||
rVal.setentityId(entityId);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean canParseserverCommandMoveItemContainerMessage(List<Byte> byteStream){
|
||||
int currentStreamLength = byteStream.size();
|
||||
List<Byte> temporaryByteQueue = new LinkedList();
|
||||
if(currentStreamLength < 6){
|
||||
return false;
|
||||
}
|
||||
int itemTemplateSize = 0;
|
||||
if(currentStreamLength < 10){
|
||||
return false;
|
||||
}
|
||||
int equipPointIdSize = 0;
|
||||
if(currentStreamLength < 14){
|
||||
return false;
|
||||
} else {
|
||||
temporaryByteQueue.add(byteStream.get(10 + 0));
|
||||
temporaryByteQueue.add(byteStream.get(10 + 1));
|
||||
temporaryByteQueue.add(byteStream.get(10 + 2));
|
||||
temporaryByteQueue.add(byteStream.get(10 + 3));
|
||||
equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||
}
|
||||
if(currentStreamLength < 14 + equipPointIdSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static InventoryMessage parseserverCommandMoveItemContainerMessage(List<Byte> byteStream){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDMOVEITEMCONTAINER);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
rVal.setcontainerType(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static InventoryMessage constructserverCommandMoveItemContainerMessage(int entityId,int containerType,String equipPointId){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDMOVEITEMCONTAINER);
|
||||
rVal.setentityId(entityId);
|
||||
rVal.setcontainerType(containerType);
|
||||
rVal.setequipPointId(equipPointId);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean canParseserverCommandEquipItemMessage(List<Byte> byteStream){
|
||||
int currentStreamLength = byteStream.size();
|
||||
List<Byte> temporaryByteQueue = new LinkedList();
|
||||
if(currentStreamLength < 6){
|
||||
return false;
|
||||
}
|
||||
int equipPointIdSize = 0;
|
||||
if(currentStreamLength < 10){
|
||||
return false;
|
||||
} else {
|
||||
@ -150,25 +248,43 @@ public class InventoryMessage extends NetworkMessage {
|
||||
temporaryByteQueue.add(byteStream.get(6 + 1));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 2));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 3));
|
||||
equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||
}
|
||||
if(currentStreamLength < 10 + equipPointIdSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 14 + equipPointIdSize){
|
||||
return false;
|
||||
}
|
||||
int itemTemplateSize = 0;
|
||||
if(currentStreamLength < 18){
|
||||
return false;
|
||||
} else {
|
||||
temporaryByteQueue.add(byteStream.get(14 + equipPointIdSize + 0));
|
||||
temporaryByteQueue.add(byteStream.get(14 + equipPointIdSize + 1));
|
||||
temporaryByteQueue.add(byteStream.get(14 + equipPointIdSize + 2));
|
||||
temporaryByteQueue.add(byteStream.get(14 + equipPointIdSize + 3));
|
||||
itemTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||
}
|
||||
if(currentStreamLength < 10 + itemTemplateSize){
|
||||
if(currentStreamLength < 18 + equipPointIdSize + itemTemplateSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static InventoryMessage parseequipItemMessage(List<Byte> byteStream){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.EQUIPITEM);
|
||||
public static InventoryMessage parseserverCommandEquipItemMessage(List<Byte> byteStream){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDEQUIPITEM);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setequipperId(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
rVal.setentityId(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
rVal.setitemTemplate(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static InventoryMessage constructequipItemMessage(String equipPointId,int entityId,String itemTemplate){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.EQUIPITEM);
|
||||
public static InventoryMessage constructserverCommandEquipItemMessage(int equipperId,String equipPointId,int entityId,String itemTemplate){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDEQUIPITEM);
|
||||
rVal.setequipperId(equipperId);
|
||||
rVal.setequipPointId(equipPointId);
|
||||
rVal.setentityId(entityId);
|
||||
rVal.setitemTemplate(itemTemplate);
|
||||
@ -176,6 +292,77 @@ public class InventoryMessage extends NetworkMessage {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean canParseserverCommandUnequipItemMessage(List<Byte> byteStream){
|
||||
int currentStreamLength = byteStream.size();
|
||||
List<Byte> temporaryByteQueue = new LinkedList();
|
||||
if(currentStreamLength < 6){
|
||||
return false;
|
||||
}
|
||||
int equipPointIdSize = 0;
|
||||
if(currentStreamLength < 10){
|
||||
return false;
|
||||
} else {
|
||||
temporaryByteQueue.add(byteStream.get(6 + 0));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 1));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 2));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 3));
|
||||
equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||
}
|
||||
if(currentStreamLength < 10 + equipPointIdSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static InventoryMessage parseserverCommandUnequipItemMessage(List<Byte> byteStream){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDUNEQUIPITEM);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setequipperId(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static InventoryMessage constructserverCommandUnequipItemMessage(int equipperId,String equipPointId){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.SERVERCOMMANDUNEQUIPITEM);
|
||||
rVal.setequipperId(equipperId);
|
||||
rVal.setequipPointId(equipPointId);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean canParseclientRequestUnequipItemMessage(List<Byte> byteStream){
|
||||
int currentStreamLength = byteStream.size();
|
||||
List<Byte> temporaryByteQueue = new LinkedList();
|
||||
int equipPointIdSize = 0;
|
||||
if(currentStreamLength < 6){
|
||||
return false;
|
||||
} else {
|
||||
temporaryByteQueue.add(byteStream.get(2 + 0));
|
||||
temporaryByteQueue.add(byteStream.get(2 + 1));
|
||||
temporaryByteQueue.add(byteStream.get(2 + 2));
|
||||
temporaryByteQueue.add(byteStream.get(2 + 3));
|
||||
equipPointIdSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||
}
|
||||
if(currentStreamLength < 6 + equipPointIdSize){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static InventoryMessage parseclientRequestUnequipItemMessage(List<Byte> byteStream){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTUNEQUIPITEM);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setequipPointId(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static InventoryMessage constructclientRequestUnequipItemMessage(String equipPointId){
|
||||
InventoryMessage rVal = new InventoryMessage(InventoryMessageType.CLIENTREQUESTUNEQUIPITEM);
|
||||
rVal.setequipPointId(equipPointId);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
void serialize(){
|
||||
byte[] intValues = new byte[8];
|
||||
@ -211,12 +398,12 @@ public class InventoryMessage extends NetworkMessage {
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
break;
|
||||
case EQUIPITEM:
|
||||
rawBytes = new byte[2+4+equipPointId.length()+4+4+itemTemplate.length()];
|
||||
case CLIENTREQUESTEQUIPITEM:
|
||||
rawBytes = new byte[2+4+equipPointId.length()+4];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_EQUIPITEM;
|
||||
rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTEQUIPITEM;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
@ -229,13 +416,93 @@ public class InventoryMessage extends NetworkMessage {
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[6+equipPointId.length()+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(itemTemplate.length());
|
||||
break;
|
||||
case SERVERCOMMANDMOVEITEMCONTAINER:
|
||||
rawBytes = new byte[2+4+4+4+equipPointId.length()];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDMOVEITEMCONTAINER;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(entityId);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(containerType);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[6+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[10+i] = intValues[i];
|
||||
}
|
||||
stringBytes = equipPointId.getBytes();
|
||||
for(int i = 0; i < equipPointId.length(); i++){
|
||||
rawBytes[14+i] = stringBytes[i];
|
||||
}
|
||||
break;
|
||||
case SERVERCOMMANDEQUIPITEM:
|
||||
rawBytes = new byte[2+4+4+equipPointId.length()+4+4+itemTemplate.length()];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDEQUIPITEM;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(equipperId);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[6+i] = intValues[i];
|
||||
}
|
||||
stringBytes = equipPointId.getBytes();
|
||||
for(int i = 0; i < equipPointId.length(); i++){
|
||||
rawBytes[10+i] = stringBytes[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(entityId);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[10+equipPointId.length()+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(itemTemplate.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[14+equipPointId.length()+i] = intValues[i];
|
||||
}
|
||||
stringBytes = itemTemplate.getBytes();
|
||||
for(int i = 0; i < itemTemplate.length(); i++){
|
||||
rawBytes[14+equipPointId.length()+i] = stringBytes[i];
|
||||
rawBytes[18+equipPointId.length()+i] = stringBytes[i];
|
||||
}
|
||||
break;
|
||||
case SERVERCOMMANDUNEQUIPITEM:
|
||||
rawBytes = new byte[2+4+4+equipPointId.length()];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDUNEQUIPITEM;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(equipperId);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[6+i] = intValues[i];
|
||||
}
|
||||
stringBytes = equipPointId.getBytes();
|
||||
for(int i = 0; i < equipPointId.length(); i++){
|
||||
rawBytes[10+i] = stringBytes[i];
|
||||
}
|
||||
break;
|
||||
case CLIENTREQUESTUNEQUIPITEM:
|
||||
rawBytes = new byte[2+4+equipPointId.length()];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_INVENTORY;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTUNEQUIPITEM;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(equipPointId.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
stringBytes = equipPointId.getBytes();
|
||||
for(int i = 0; i < equipPointId.length(); i++){
|
||||
rawBytes[6+i] = stringBytes[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -293,9 +293,29 @@ INVENTORY_MESSAGE,
|
||||
rVal = InventoryMessage.parseremoveItemFromInventoryMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_EQUIPITEM:
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTEQUIPITEM:
|
||||
if(InventoryMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = InventoryMessage.parseequipItemMessage(byteStream);
|
||||
rVal = InventoryMessage.parseclientRequestEquipItemMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDMOVEITEMCONTAINER:
|
||||
if(InventoryMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = InventoryMessage.parseserverCommandMoveItemContainerMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDEQUIPITEM:
|
||||
if(InventoryMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = InventoryMessage.parseserverCommandEquipItemMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_SERVERCOMMANDUNEQUIPITEM:
|
||||
if(InventoryMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = InventoryMessage.parseserverCommandUnequipItemMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.INVENTORY_MESSAGE_TYPE_CLIENTREQUESTUNEQUIPITEM:
|
||||
if(InventoryMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = InventoryMessage.parseclientRequestUnequipItemMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -132,7 +132,11 @@ Message categories
|
||||
*/
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_ADDITEMTOINVENTORY = 0;
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_REMOVEITEMFROMINVENTORY = 1;
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_EQUIPITEM = 2;
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTEQUIPITEM = 2;
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_SERVERCOMMANDMOVEITEMCONTAINER = 3;
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_SERVERCOMMANDEQUIPITEM = 4;
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_SERVERCOMMANDUNEQUIPITEM = 5;
|
||||
public static final byte INVENTORY_MESSAGE_TYPE_CLIENTREQUESTUNEQUIPITEM = 6;
|
||||
/*
|
||||
Inventory packet sizes
|
||||
*/
|
||||
|
||||
@ -1,15 +1,23 @@
|
||||
package electrosphere.net.server.protocol;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.state.equip.EquipState;
|
||||
import electrosphere.entity.state.inventory.InventoryUtils;
|
||||
import electrosphere.entity.state.inventory.UnrelationalInventoryState;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.game.data.creature.type.equip.EquipPoint;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.InventoryMessage;
|
||||
import electrosphere.net.server.ServerConnectionHandler;
|
||||
|
||||
public class InventoryProtocol {
|
||||
|
||||
public static final int INVENTORY_TYPE_EQUIP = 0;
|
||||
public static final int INVENTORY_TYPE_NATURAL = 1;
|
||||
|
||||
protected static void handleInventoryMessage(ServerConnectionHandler connectionHandler, InventoryMessage message){
|
||||
Entity characterEntity;
|
||||
Entity target;
|
||||
switch(message.getMessageSubtype()){
|
||||
case ADDITEMTOINVENTORY:
|
||||
@ -26,7 +34,24 @@ public class InventoryProtocol {
|
||||
InventoryUtils.getInventoryState(target).addNetworkMessage(message);
|
||||
}
|
||||
break;
|
||||
case EQUIPITEM:
|
||||
case CLIENTREQUESTEQUIPITEM:
|
||||
LoggerInterface.loggerNetworking.DEBUG("[SERVER] REQUEST EQUIP ITEM " + message.getentityId());
|
||||
target = Globals.entityManager.getEntityFromId(connectionHandler.getPlayerCharacterId());
|
||||
if(InventoryUtils.hasNaturalInventory(target)){
|
||||
InventoryUtils.getInventoryState(target).addNetworkMessage(message);
|
||||
}
|
||||
break;
|
||||
case CLIENTREQUESTUNEQUIPITEM:
|
||||
LoggerInterface.loggerNetworking.DEBUG("[SERVER] REQUEST UNEQUIP ITEM " + message.getentityId());
|
||||
target = Globals.entityManager.getEntityFromId(connectionHandler.getPlayerCharacterId());
|
||||
if(InventoryUtils.hasNaturalInventory(target)){
|
||||
InventoryUtils.getInventoryState(target).addNetworkMessage(message);
|
||||
}
|
||||
break;
|
||||
case SERVERCOMMANDUNEQUIPITEM:
|
||||
case SERVERCOMMANDMOVEITEMCONTAINER:
|
||||
case SERVERCOMMANDEQUIPITEM:
|
||||
//silently ignore
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -728,46 +728,10 @@ public class Mesh {
|
||||
//Until we switch to uniform buffer objects we will have to buffer lighting data here manually each time we draw
|
||||
//side note: :(
|
||||
if(Globals.renderingEngine.getLightManager() == null){
|
||||
|
||||
//this needs to get transformed by the view matrix and isn't
|
||||
Vector3f lightLoc = new Vector3f(0.2f,-1.0f,0.3f);
|
||||
float temp[] = new float[3];
|
||||
temp[0] = lightLoc.x;
|
||||
temp[1] = lightLoc.y;
|
||||
temp[2] = lightLoc.z;
|
||||
glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.direction"), temp);
|
||||
|
||||
temp[0] = 0.4f;
|
||||
temp[1] = 0.4f;
|
||||
temp[2] = 0.4f;
|
||||
glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.ambient"), temp);
|
||||
|
||||
temp[0] = 0.3f;
|
||||
temp[1] = 0.3f;
|
||||
temp[2] = 0.3f;
|
||||
glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.diffuse"), temp);
|
||||
|
||||
temp[0] = 0.1f;
|
||||
temp[1] = 0.1f;
|
||||
temp[2] = 0.1f;
|
||||
glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.specular"), temp);
|
||||
|
||||
temp[0] = 32f;
|
||||
glUniform1fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "material.shininess"), temp);
|
||||
|
||||
// GL20.glUniformMatrix4fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "model"), false, parent.modelMatrix.get(new float[16]));
|
||||
|
||||
//set in standard uniforms
|
||||
//
|
||||
// Vector3f cam_Loc = CameraEntityUtils.getCameraEye(Globals.playerCamera);//Globals.cameraVisible.pos_Center;
|
||||
// temp[0] = cam_Loc.x;
|
||||
// temp[1] = cam_Loc.y;
|
||||
// temp[2] = cam_Loc.z;
|
||||
// glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "viewPos"), temp);
|
||||
//don't buffer as the light manager hasn't initialized
|
||||
} else {
|
||||
LightManager lightManager = Globals.renderingEngine.getLightManager();
|
||||
lightManager.bindBuffer(Globals.renderingEngine.getActiveShader().shaderProgram);
|
||||
// GL20.glUniformMatrix4fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "model"), false, parent.modelMatrix.get(new float[16]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -874,43 +838,6 @@ public class Mesh {
|
||||
bufferAllUniforms();
|
||||
}
|
||||
|
||||
// if(shadowMapShader){
|
||||
// glUniformMatrix4fv(glGetUniformLocation(Globals.depthMapShaderProgramLoc, "model"), false, parent.modelMatrix.get(new float[16]));
|
||||
// glUniformMatrix4fv(glGetUniformLocation(Globals.depthMapShaderProgramLoc, "lightSpaceMatrix"), false, Globals.lightDepthMatrix.get(new float[16]));
|
||||
// }
|
||||
|
||||
// if(useLight){
|
||||
// //
|
||||
// //
|
||||
// //Testing Lights
|
||||
// //
|
||||
// //
|
||||
// float test_Light_Data[] = new float[3];
|
||||
// test_Light_Data[0] = 0.2f;
|
||||
// test_Light_Data[1] = -1.0f;
|
||||
// test_Light_Data[2] = 0.3f;
|
||||
// glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.direction"), test_Light_Data);
|
||||
|
||||
// test_Light_Data = new float[3];
|
||||
// test_Light_Data[0] = 0.3f;
|
||||
// test_Light_Data[1] = 0.3f;
|
||||
// test_Light_Data[2] = 0.3f;
|
||||
// glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.ambient"), test_Light_Data);
|
||||
|
||||
// test_Light_Data = new float[3];
|
||||
// test_Light_Data[0] = 0.5f;
|
||||
// test_Light_Data[1] = 0.5f;
|
||||
// test_Light_Data[2] = 0.5f;
|
||||
// glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "dirLight.diffuse"), test_Light_Data);
|
||||
|
||||
// Vector3f cam_Loc = CameraEntityUtils.getCameraEye(Globals.playerCamera);
|
||||
// test_Light_Data = new float[3];
|
||||
// test_Light_Data[0] = cam_Loc.x;
|
||||
// test_Light_Data[1] = cam_Loc.y;
|
||||
// test_Light_Data[2] = cam_Loc.z;
|
||||
// glUniform3fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "viewPos"), test_Light_Data);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
GL11.glDrawElements(GL_TRIANGLES, elementCount, GL_UNSIGNED_INT, 0);
|
||||
|
||||
@ -431,9 +431,6 @@ public class Model {
|
||||
|
||||
|
||||
public void drawForDepthBuffer(){
|
||||
// if(node_map != null && !node_map.isEmpty()){
|
||||
// update_node_transform(root_anim_node);
|
||||
// }
|
||||
Iterator<Mesh> mesh_Iterator = meshes.iterator();
|
||||
while(mesh_Iterator.hasNext()){
|
||||
Mesh currentMesh = mesh_Iterator.next();
|
||||
|
||||
@ -87,6 +87,7 @@ import static org.lwjgl.opengl.GL11.GL_ZERO;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR;
|
||||
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_COLOR;
|
||||
import static org.lwjgl.opengl.GL11.GL_ALWAYS;
|
||||
import static org.lwjgl.opengl.GL11.GL_FRONT;
|
||||
import static org.lwjgl.opengl.GL11.glDepthFunc;
|
||||
import static org.lwjgl.opengl.GL11.glDepthMask;
|
||||
import static org.lwjgl.opengl.GL11.glBindTexture;
|
||||
@ -98,6 +99,7 @@ import static org.lwjgl.opengl.GL11.glDrawArrays;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glFogf;
|
||||
import static org.lwjgl.opengl.GL11.glViewport;
|
||||
import static org.lwjgl.opengl.GL11.glCullFace;
|
||||
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
|
||||
import static org.lwjgl.opengl.GL13.GL_TEXTURE1;
|
||||
import static org.lwjgl.opengl.GL13.GL_TEXTURE2;
|
||||
@ -530,14 +532,13 @@ public class RenderingEngine {
|
||||
//set the viewport to shadow map size
|
||||
glViewport(0, 0, 4096, 4096);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
|
||||
Globals.renderingEngine.setActiveShader(lightDepthShaderProgram);
|
||||
|
||||
lightDepthBuffer.bind();
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
// glBindTexture(GL_TEXTURE_2D, woodTexture);
|
||||
// renderScene(simpleDepthShader);
|
||||
|
||||
float eyeX = -1.0f;
|
||||
float eyeY = 10.0f;
|
||||
@ -557,7 +558,7 @@ public class RenderingEngine {
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "lightSpaceMatrix"), false, Globals.lightDepthMatrix.get(new float[16]));
|
||||
|
||||
// glCullFace(GL_FRONT);
|
||||
// glCullFace(GL_FRONT);
|
||||
|
||||
//
|
||||
// D R A W A L L E N T I T I E S
|
||||
@ -570,7 +571,6 @@ public class RenderingEngine {
|
||||
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
|
||||
drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z)) &&
|
||||
currentEntity.containsKey(EntityDataStrings.DRAW_CAST_SHADOW)
|
||||
// && !currentEntity.containsKey(EntityDataStrings.TERRAIN_IS_TERRAIN)
|
||||
){
|
||||
//fetch actor
|
||||
Actor currentActor = EntityUtils.getActor(currentEntity);
|
||||
@ -584,10 +584,7 @@ public class RenderingEngine {
|
||||
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
|
||||
currentActor.applyModelMatrix(modelTransformMatrix);
|
||||
//draw
|
||||
// if(!currentEntity.getDataKeys().contains(EntityDataStrings.TERRAIN_IS_TERRAIN) && !currentEntity.getDataKeys().contains(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE)){
|
||||
currentActor.drawForDepthBuffer();
|
||||
// System.out.println(currentActor.modelPath);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@ -922,10 +919,6 @@ public class RenderingEngine {
|
||||
//
|
||||
// Outline normals
|
||||
//
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
glDepthMask(false);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
normalsOutlineFrambuffer.bind();
|
||||
ShaderProgram program = Globals.assetManager.fetchShader("Shaders/anime/outlineNormals.vs", null, "Shaders/anime/outlineNormals.fs");
|
||||
@ -1037,24 +1030,33 @@ public class RenderingEngine {
|
||||
Globals.renderingEngine.setActiveShader(screenTextureShaders);
|
||||
glBindVertexArray(screenTextureVAO);
|
||||
//aaa
|
||||
if(outputFramebuffer == 0){
|
||||
glBindTexture(GL_TEXTURE_2D, screenFramebuffer.getTexturePointer());
|
||||
} else if(outputFramebuffer == 1){
|
||||
glBindTexture(GL_TEXTURE_2D, lightDepthBuffer.getTexturePointer());
|
||||
} else if(outputFramebuffer == 2){
|
||||
glBindTexture(GL_TEXTURE_2D, volumeDepthBackfaceTexture.getTexturePointer());
|
||||
} else if(outputFramebuffer == 3){
|
||||
glBindTexture(GL_TEXTURE_2D, volumeDepthFrontfaceTexture.getTexturePointer());
|
||||
} else if(outputFramebuffer == 4){
|
||||
glBindTexture(GL_TEXTURE_2D, transparencyAccumulatorTexture.getTexturePointer());
|
||||
} else if(outputFramebuffer == 5){
|
||||
glBindTexture(GL_TEXTURE_2D, gameImageNormalsTexture.getTexturePointer());
|
||||
} else if(outputFramebuffer == 6){
|
||||
glBindTexture(GL_TEXTURE_2D, normalsOutlineTexture.getTexturePointer());
|
||||
} else if(outputFramebuffer == 7){
|
||||
Globals.renderingEngine.setActiveShader(drawChannel);
|
||||
glUniform1f(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "channel"),4);
|
||||
glBindTexture(GL_TEXTURE_2D, screenTextureDepth.getTexturePointer());
|
||||
switch(outputFramebuffer){
|
||||
case 0:
|
||||
glBindTexture(GL_TEXTURE_2D, screenFramebuffer.getTexturePointer());
|
||||
break;
|
||||
case 1:
|
||||
glBindTexture(GL_TEXTURE_2D, lightDepthBuffer.getTexturePointer());
|
||||
break;
|
||||
case 2:
|
||||
glBindTexture(GL_TEXTURE_2D, volumeDepthBackfaceTexture.getTexturePointer());
|
||||
break;
|
||||
case 3:
|
||||
glBindTexture(GL_TEXTURE_2D, volumeDepthFrontfaceTexture.getTexturePointer());
|
||||
break;
|
||||
case 4:
|
||||
glBindTexture(GL_TEXTURE_2D, transparencyAccumulatorTexture.getTexturePointer());
|
||||
break;
|
||||
case 5:
|
||||
glBindTexture(GL_TEXTURE_2D, gameImageNormalsTexture.getTexturePointer());
|
||||
break;
|
||||
case 6:
|
||||
glBindTexture(GL_TEXTURE_2D, normalsOutlineTexture.getTexturePointer());
|
||||
break;
|
||||
case 7:
|
||||
Globals.renderingEngine.setActiveShader(drawChannel);
|
||||
glUniform1f(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, "channel"),4);
|
||||
glBindTexture(GL_TEXTURE_2D, screenTextureDepth.getTexturePointer());
|
||||
break;
|
||||
}
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glBindVertexArray(0);
|
||||
|
||||
@ -58,6 +58,10 @@ public class ElementManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsWindow(String name){
|
||||
return elementMap.containsKey(name);
|
||||
}
|
||||
|
||||
public void pushWindowToFront(Window window){
|
||||
elementList.remove(window);
|
||||
elementList.add(window);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user