Overhaul spawning / creatures / items data
This commit is contained in:
parent
1c01ab1868
commit
ef6116646a
@ -1,39 +1,197 @@
|
|||||||
{
|
{
|
||||||
"creatures" : [
|
"creatures" : [
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"name" : "Human",
|
"name" : "Human",
|
||||||
"bodyParts" : [
|
"bodyParts" : [
|
||||||
{
|
{
|
||||||
"name" : "Head",
|
"name" : "Head",
|
||||||
"type" : "Head",
|
"type" : "Head"
|
||||||
"size" : 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name" : "Torso",
|
"name" : "Torso",
|
||||||
"type" : "Torso",
|
"type" : "Torso"
|
||||||
"size" : 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name" : "ArmLeft",
|
"name" : "ArmLeft",
|
||||||
"type" : "Arm",
|
"type" : "Arm"
|
||||||
"size" : 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name" : "ArmRight",
|
"name" : "ArmRight",
|
||||||
"type" : "Arm",
|
"type" : "Arm"
|
||||||
"size" : 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name" : "LegLeft",
|
"name" : "LegLeft",
|
||||||
"type" : "Leg",
|
"type" : "Leg"
|
||||||
"size" : 1
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name" : "LegRight",
|
"name" : "LegRight",
|
||||||
"type" : "Leg",
|
"type" : "Leg"
|
||||||
"size" : 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"hitboxes" : [
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.031",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.012",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.003",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.010",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.001",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.014",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone",
|
||||||
|
"radius": 0.08
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.014",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.019",
|
||||||
|
"radius": 0.04
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tokens" : [
|
||||||
|
"BLENDER_TRANSFORM",
|
||||||
|
"SENTIENT"
|
||||||
|
],
|
||||||
|
"movementSystems" : [
|
||||||
|
{
|
||||||
|
"type" : "GROUND",
|
||||||
|
"acceleration" : 0.001,
|
||||||
|
"maxVelocity" : 0.025
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"modelPath" : "/Models/person1walkanim.fbx"
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"name" : "Goblin",
|
||||||
|
"bodyParts" : [
|
||||||
|
{
|
||||||
|
"name" : "Head",
|
||||||
|
"type" : "Head"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "Torso",
|
||||||
|
"type" : "Torso"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "ArmLeft",
|
||||||
|
"type" : "Arm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "ArmRight",
|
||||||
|
"type" : "Arm"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "LegLeft",
|
||||||
|
"type" : "Leg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "LegRight",
|
||||||
|
"type" : "Leg"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"hitboxes" : [
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.031",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.012",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.003",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.010",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.001",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.014",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone",
|
||||||
|
"radius": 0.08
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.014",
|
||||||
|
"radius": 0.06
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hurt",
|
||||||
|
"bone": "Bone.019",
|
||||||
|
"radius": 0.04
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tokens" : [
|
||||||
|
"BLENDER_TRANSFORM",
|
||||||
|
"SENTIENT"
|
||||||
|
],
|
||||||
|
"movementSystems" : [
|
||||||
|
{
|
||||||
|
"type" : "GROUND",
|
||||||
|
"acceleration" : 0.001,
|
||||||
|
"maxVelocity" : 0.025
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"modelPath" : "Models/goblin1.fbx"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,96 +0,0 @@
|
|||||||
{
|
|
||||||
"types": [
|
|
||||||
{
|
|
||||||
"id" : 0,
|
|
||||||
"isCreature" : true,
|
|
||||||
"isItem" : false,
|
|
||||||
"modelPath" : "/Models/person1walkanim.fbx",
|
|
||||||
"hitboxes" : [
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.031",
|
|
||||||
"radius": 0.04
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.012",
|
|
||||||
"radius": 0.04
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.003",
|
|
||||||
"radius": 0.04
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.010",
|
|
||||||
"radius": 0.06
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.001",
|
|
||||||
"radius": 0.06
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.014",
|
|
||||||
"radius": 0.06
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone",
|
|
||||||
"radius": 0.08
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.014",
|
|
||||||
"radius": 0.06
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hurt",
|
|
||||||
"bone": "Bone.019",
|
|
||||||
"radius": 0.04
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id" : 1,
|
|
||||||
"isCreature" : true,
|
|
||||||
"isItem" : false,
|
|
||||||
"modelPath" : "",
|
|
||||||
"hitboxes" : []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id" : 2,
|
|
||||||
"isCreature" : false,
|
|
||||||
"isItem" : true,
|
|
||||||
"modelPath" : "/Models/katana1alt.fbx",
|
|
||||||
"hitboxes" : [
|
|
||||||
{
|
|
||||||
"type": "hit",
|
|
||||||
"bone": "Blade1",
|
|
||||||
"radius": 0.04
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hit",
|
|
||||||
"bone": "Blade2",
|
|
||||||
"radius": 0.04
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "hit",
|
|
||||||
"bone": "Blade3",
|
|
||||||
"radius": 0.04
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id" : 3,
|
|
||||||
"isCreature" : true,
|
|
||||||
"isItem" : false,
|
|
||||||
"modelPath" : "Models/goblin1.fbx",
|
|
||||||
"hitboxes" : [
|
|
||||||
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
37
assets/Data/items.json
Normal file
37
assets/Data/items.json
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"items" : [
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
"name" : "Katana",
|
||||||
|
"modelPath" : "/Models/katana1alt.fbx",
|
||||||
|
"hitboxes" : [
|
||||||
|
{
|
||||||
|
"type": "hit",
|
||||||
|
"bone": "Blade1",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hit",
|
||||||
|
"bone": "Blade2",
|
||||||
|
"radius": 0.04
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hit",
|
||||||
|
"bone": "Blade3",
|
||||||
|
"radius": 0.04
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tokens" : [
|
||||||
|
"BLENDER_TRANSFORM",
|
||||||
|
"WEAPON",
|
||||||
|
"MELEE"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -469,12 +469,12 @@ public class LoadingThread extends Thread {
|
|||||||
// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
|
// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity goblin = EntityUtils.spawnEntityFromEntityMap(3);
|
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin");
|
||||||
EntityUtils.getPosition(goblin).set(5, 0, 3);
|
EntityUtils.getPosition(goblin).set(5, 0, 3);
|
||||||
EntityUtils.getScale(goblin).set(0.005f);
|
EntityUtils.getScale(goblin).set(0.005f);
|
||||||
|
|
||||||
Entity sword = ItemUtils.spawnBasicItem(2);
|
Entity sword = ItemUtils.spawnBasicItem("Katana");
|
||||||
Entity testHomie = CreatureUtils.spawnBasicCreature(0, 0.1f, 0.5f);
|
Entity testHomie = CreatureUtils.spawnBasicCreature("Human");
|
||||||
EntityUtils.getScale(testHomie).set(0.005f);
|
EntityUtils.getScale(testHomie).set(0.005f);
|
||||||
EntityUtils.getPosition(testHomie).set(2,0,2);
|
EntityUtils.getPosition(testHomie).set(2,0,2);
|
||||||
AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");
|
AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");
|
||||||
|
|||||||
@ -7,7 +7,6 @@ package electrosphere.entity;
|
|||||||
|
|
||||||
import electrosphere.entity.state.MovementTree;
|
import electrosphere.entity.state.MovementTree;
|
||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.entity.types.creature.creaturemap.CreatureType;
|
|
||||||
import electrosphere.entity.types.item.ItemUtils;
|
import electrosphere.entity.types.item.ItemUtils;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
@ -88,21 +87,4 @@ public class EntityUtils {
|
|||||||
return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR);
|
return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entity spawnEntityFromEntityMap(int type){
|
|
||||||
Entity rVal = null;
|
|
||||||
CreatureType entityType = Globals.entityTypeMap.get(type);
|
|
||||||
if(entityType.isIsCreature()){
|
|
||||||
rVal = CreatureUtils.spawnBasicCreature(type, 0.001f, 0.05f);
|
|
||||||
}
|
|
||||||
if(entityType.isIsItem()){
|
|
||||||
rVal = ItemUtils.spawnBasicItem(type);
|
|
||||||
}
|
|
||||||
if(rVal == null){
|
|
||||||
System.err.println("ERROR!");
|
|
||||||
System.err.println("The entity you are trying to spawn (type=" + type + ") is neither a creature nor an item in the entity type map!");
|
|
||||||
System.err.println("Error occurred in spawnEntityFromEntityMap in EntityUtils");
|
|
||||||
}
|
|
||||||
return rVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,12 +4,15 @@ import electrosphere.entity.Entity;
|
|||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.state.MovementTree;
|
import electrosphere.entity.state.MovementTree;
|
||||||
import electrosphere.entity.types.creature.creaturemap.CreatureType;
|
import electrosphere.entity.types.hitbox.HitboxData;
|
||||||
import electrosphere.entity.types.creature.creaturemap.HitboxData;
|
|
||||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||||
|
import electrosphere.game.server.creature.type.CreatureType;
|
||||||
|
import electrosphere.game.server.creature.type.MovementSystem;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.main.Main;
|
import electrosphere.main.Main;
|
||||||
import electrosphere.net.parser.net.message.EntityMessage;
|
import electrosphere.net.parser.net.message.EntityMessage;
|
||||||
|
import electrosphere.renderer.Actor;
|
||||||
|
import electrosphere.renderer.ActorUtils;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
import electrosphere.util.ModelLoader;
|
import electrosphere.util.ModelLoader;
|
||||||
import org.joml.Quaternionf;
|
import org.joml.Quaternionf;
|
||||||
@ -40,8 +43,8 @@ public class CreatureUtils {
|
|||||||
// return rVal;
|
// return rVal;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static Entity spawnBasicCreature(int creatureId, float acceleration, float maxVelocity){
|
public static Entity spawnBasicCreature(String type){
|
||||||
CreatureType rawType = Globals.entityTypeMap.get(creatureId);
|
CreatureType rawType = Globals.creatureMap.getCreature(type);
|
||||||
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
|
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
|
||||||
for(HitboxData hitboxdata : rawType.getHitboxes()){
|
for(HitboxData hitboxdata : rawType.getHitboxes()){
|
||||||
if(hitboxdata.getType().equals("hit")){
|
if(hitboxdata.getType().equals("hit")){
|
||||||
@ -50,14 +53,29 @@ public class CreatureUtils {
|
|||||||
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHurtbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
|
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHurtbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
|
for(MovementSystem movementSystem : rawType.getMovementSystems()){
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, creatureId);
|
switch(movementSystem.getType()){
|
||||||
|
case "GROUND":
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new MovementTree(rVal));
|
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new MovementTree(rVal));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
|
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, maxVelocity);
|
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, movementSystem.getMaxVelocity());
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, acceleration);
|
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, movementSystem.getAcceleration());
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
|
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
|
||||||
Globals.entityManager.registerMoveableEntity(rVal);
|
Globals.entityManager.registerMoveableEntity(rVal);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(String token : rawType.getTokens()){
|
||||||
|
switch(token){
|
||||||
|
case "BLENDER_TRANSFORM":
|
||||||
|
Actor entityActor = EntityUtils.getActor(rVal);
|
||||||
|
entityActor.setAnimationScalar(0.4f);
|
||||||
|
EntityUtils.getScale(rVal).set(0.005f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
|
||||||
|
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +119,8 @@ public class CreatureUtils {
|
|||||||
getEntityMovementTree(e).addNetworkMessage(em);
|
getEntityMovementTree(e).addNetworkMessage(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCreatureType(Entity e){
|
public static String getType(Entity e){
|
||||||
return (int)e.getData(EntityDataStrings.DATA_STRING_CREATURE_TYPE);
|
return (String)e.getData(EntityDataStrings.DATA_STRING_CREATURE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getControllerPlayerId(Entity e){
|
public static int getControllerPlayerId(Entity e){
|
||||||
|
|||||||
@ -1,58 +0,0 @@
|
|||||||
package electrosphere.entity.types.creature.creaturemap;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author amaterasu
|
|
||||||
*/
|
|
||||||
public class CreatureType {
|
|
||||||
int id;
|
|
||||||
boolean isCreature;
|
|
||||||
boolean isItem;
|
|
||||||
String modelPath;
|
|
||||||
List<HitboxData> hitboxes;
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getModelPath() {
|
|
||||||
return modelPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModelPath(String modelPath) {
|
|
||||||
this.modelPath = modelPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<HitboxData> getHitboxes() {
|
|
||||||
return hitboxes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHitboxes(List<HitboxData> hitboxes) {
|
|
||||||
this.hitboxes = hitboxes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIsCreature() {
|
|
||||||
return isCreature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIsItem() {
|
|
||||||
return isItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsCreature(boolean isCreature) {
|
|
||||||
this.isCreature = isCreature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsItem(boolean isItem) {
|
|
||||||
this.isItem = isItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
package electrosphere.entity.types.creature.creaturemap;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author amaterasu
|
|
||||||
*/
|
|
||||||
public class CreatureTypeList {
|
|
||||||
List<CreatureType> types;
|
|
||||||
|
|
||||||
public List<CreatureType> getTypes() {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,9 +1,6 @@
|
|||||||
package electrosphere.entity.types.creature.creaturemap;
|
package electrosphere.entity.types.hitbox;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author amaterasu
|
|
||||||
*/
|
|
||||||
public class HitboxData {
|
public class HitboxData {
|
||||||
String type;
|
String type;
|
||||||
String bone;
|
String bone;
|
||||||
@ -4,9 +4,10 @@ import electrosphere.entity.Entity;
|
|||||||
import electrosphere.entity.EntityDataStrings;
|
import electrosphere.entity.EntityDataStrings;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.state.MovementTree;
|
import electrosphere.entity.state.MovementTree;
|
||||||
import electrosphere.entity.types.creature.creaturemap.CreatureType;
|
import electrosphere.entity.types.hitbox.HitboxData;
|
||||||
import electrosphere.entity.types.creature.creaturemap.HitboxData;
|
|
||||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||||
|
import electrosphere.game.server.creature.type.CreatureType;
|
||||||
|
import electrosphere.game.server.item.type.Item;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.renderer.Actor;
|
import electrosphere.renderer.Actor;
|
||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
@ -18,17 +19,25 @@ import org.joml.Vector3f;
|
|||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class ItemUtils {
|
public class ItemUtils {
|
||||||
public static Entity spawnBasicItem(int itemId){
|
public static Entity spawnBasicItem(String name){
|
||||||
CreatureType rawType = Globals.entityTypeMap.get(itemId);
|
Item item = Globals.itemMap.getItem(name);
|
||||||
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
|
Entity rVal = EntityUtils.spawnDrawableEntity(item.getModelPath());
|
||||||
for(HitboxData hitboxdata : rawType.getHitboxes()){
|
for(HitboxData hitboxdata : item.getHitboxes()){
|
||||||
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
|
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
|
||||||
}
|
}
|
||||||
|
for(String token : item.getTokens()){
|
||||||
|
switch(token){
|
||||||
|
case "BLENDER_TRANSFORM":
|
||||||
|
Actor entityActor = EntityUtils.getActor(rVal);
|
||||||
|
entityActor.setAnimationScalar(0.4f);
|
||||||
|
EntityUtils.getScale(rVal).set(0.005f);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
|
||||||
rVal.putData(EntityDataStrings.ITEM_TYPE, itemId);
|
rVal.putData(EntityDataStrings.ITEM_TYPE, name);
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, itemId);
|
// rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f));
|
// rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2)));
|
||||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2)));
|
|
||||||
Globals.entityManager.registerItemEntity(rVal);
|
Globals.entityManager.registerItemEntity(rVal);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
@ -47,4 +56,8 @@ public class ItemUtils {
|
|||||||
public static boolean isItem(Entity item){
|
public static boolean isItem(Entity item){
|
||||||
return item.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM);
|
return item.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getType(Entity item){
|
||||||
|
return (String)item.getData(EntityDataStrings.ITEM_TYPE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,41 @@
|
|||||||
package electrosphere.game.server.creature.type;
|
package electrosphere.game.server.creature.type;
|
||||||
|
|
||||||
|
import electrosphere.entity.types.hitbox.HitboxData;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CreatureType {
|
public class CreatureType {
|
||||||
|
String name;
|
||||||
|
List<BodyPart> bodyParts;
|
||||||
|
List<HitboxData> hitboxes;
|
||||||
|
List<String> tokens;
|
||||||
|
List<MovementSystem> movementSystems;
|
||||||
|
String modelPath;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BodyPart> getBodyParts() {
|
||||||
|
return bodyParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HitboxData> getHitboxes() {
|
||||||
|
return hitboxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTokens() {
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModelPath() {
|
||||||
|
return modelPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MovementSystem> getMovementSystems() {
|
||||||
|
return movementSystems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,21 @@
|
|||||||
|
package electrosphere.game.server.creature.type;
|
||||||
|
|
||||||
|
public class MovementSystem {
|
||||||
|
String type;
|
||||||
|
float acceleration;
|
||||||
|
float maxVelocity;
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getAcceleration() {
|
||||||
|
return acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getMaxVelocity() {
|
||||||
|
return maxVelocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,21 @@
|
|||||||
package electrosphere.game.server.creature.type.model;
|
package electrosphere.game.server.creature.type.model;
|
||||||
|
|
||||||
|
import electrosphere.game.server.creature.type.CreatureType;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CreatureTypeMap {
|
public class CreatureTypeMap {
|
||||||
|
|
||||||
|
List<CreatureType> creatures;
|
||||||
|
|
||||||
|
public CreatureType getCreature(String name){
|
||||||
|
CreatureType rVal = null;
|
||||||
|
for(CreatureType type : creatures){
|
||||||
|
if(type.getName().equals(name)){
|
||||||
|
rVal = type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/main/java/electrosphere/game/server/item/type/Item.java
Normal file
29
src/main/java/electrosphere/game/server/item/type/Item.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package electrosphere.game.server.item.type;
|
||||||
|
|
||||||
|
import electrosphere.entity.types.hitbox.HitboxData;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
String name;
|
||||||
|
String modelPath;
|
||||||
|
List<HitboxData> hitboxes;
|
||||||
|
List<String> tokens;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModelPath() {
|
||||||
|
return modelPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<HitboxData> getHitboxes() {
|
||||||
|
return hitboxes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTokens() {
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package electrosphere.game.server.item.type.model;
|
||||||
|
|
||||||
|
import electrosphere.game.server.item.type.Item;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ItemTypeMap {
|
||||||
|
List<Item> items;
|
||||||
|
|
||||||
|
public List<Item> getItems() {
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item getItem(String name){
|
||||||
|
Item rVal = null;
|
||||||
|
for(Item item : items){
|
||||||
|
if(item.getName().equals(name)){
|
||||||
|
rVal = item;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -11,8 +11,6 @@ import electrosphere.controls.ControlHandler;
|
|||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityManager;
|
import electrosphere.entity.EntityManager;
|
||||||
import electrosphere.game.collision.CollisionEngine;
|
import electrosphere.game.collision.CollisionEngine;
|
||||||
import electrosphere.entity.types.creature.creaturemap.CreatureType;
|
|
||||||
import electrosphere.entity.types.creature.creaturemap.CreatureTypeList;
|
|
||||||
import electrosphere.entity.types.hitbox.HitboxManager;
|
import electrosphere.entity.types.hitbox.HitboxManager;
|
||||||
import electrosphere.game.client.drawcell.DrawCellManager;
|
import electrosphere.game.client.drawcell.DrawCellManager;
|
||||||
import electrosphere.game.client.player.ClientPlayerData;
|
import electrosphere.game.client.player.ClientPlayerData;
|
||||||
@ -21,6 +19,8 @@ import electrosphere.game.client.world.ClientWorldData;
|
|||||||
import electrosphere.game.collision.CommonWorldData;
|
import electrosphere.game.collision.CommonWorldData;
|
||||||
import electrosphere.entity.types.life.AliveManager;
|
import electrosphere.entity.types.life.AliveManager;
|
||||||
import electrosphere.engine.LoadingThread;
|
import electrosphere.engine.LoadingThread;
|
||||||
|
import electrosphere.game.server.creature.type.model.CreatureTypeMap;
|
||||||
|
import electrosphere.game.server.item.type.model.ItemTypeMap;
|
||||||
import electrosphere.game.state.MacroSimulation;
|
import electrosphere.game.state.MacroSimulation;
|
||||||
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||||
import electrosphere.game.server.world.ServerWorldData;
|
import electrosphere.game.server.world.ServerWorldData;
|
||||||
@ -99,12 +99,8 @@ public class Globals {
|
|||||||
//current world
|
//current world
|
||||||
//
|
//
|
||||||
public static ServerWorldData serverWorldData;
|
public static ServerWorldData serverWorldData;
|
||||||
|
public static CreatureTypeMap creatureMap;
|
||||||
|
public static ItemTypeMap itemMap;
|
||||||
//
|
|
||||||
//Entity Types Map
|
|
||||||
//
|
|
||||||
public static HashMap<Integer,CreatureType> entityTypeMap = new HashMap();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -245,8 +241,10 @@ public class Globals {
|
|||||||
textureMapDefault = FileLoadingUtils.loadObjectFromAssetPath("Textures/default_texture_map.json", TextureMap.class);
|
textureMapDefault = FileLoadingUtils.loadObjectFromAssetPath("Textures/default_texture_map.json", TextureMap.class);
|
||||||
// textureMapDefault = gson.fromJson(Files.newBufferedReader(new File(Thread.currentThread().getContextClassLoader().getResource("Textures/default_texture_map.json").getFile()).toPath()), TextureMap.class); //only the best of coding practices :)
|
// textureMapDefault = gson.fromJson(Files.newBufferedReader(new File(Thread.currentThread().getContextClassLoader().getResource("Textures/default_texture_map.json").getFile()).toPath()), TextureMap.class); //only the best of coding practices :)
|
||||||
// } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm:
|
// } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm:
|
||||||
//entity type map
|
//init creature type map
|
||||||
initEntityTypeMap();
|
initCreatureTypeMap();
|
||||||
|
//init item type map
|
||||||
|
initItemTypeMap();
|
||||||
//create entity manager
|
//create entity manager
|
||||||
entityManager = new EntityManager();
|
entityManager = new EntityManager();
|
||||||
//temporary hold for skybox colors
|
//temporary hold for skybox colors
|
||||||
@ -294,10 +292,11 @@ public class Globals {
|
|||||||
Globals.assetManager.loadAssetsInQueue();
|
Globals.assetManager.loadAssetsInQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initEntityTypeMap(){
|
static void initCreatureTypeMap(){
|
||||||
CreatureTypeList typeList = FileLoadingUtils.loadObjectFromAssetPath("Data/entity_map.json", CreatureTypeList.class);
|
creatureMap = FileLoadingUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class);
|
||||||
for(CreatureType type : typeList.getTypes()){
|
}
|
||||||
entityTypeMap.put(type.getId(), type);
|
|
||||||
}
|
static void initItemTypeMap(){
|
||||||
|
itemMap = FileLoadingUtils.loadObjectFromAssetPath("Data/items.json", ItemTypeMap.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,7 +132,6 @@ public class Main {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//main loop
|
//main loop
|
||||||
while (running) {
|
while (running) {
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import electrosphere.entity.EntityUtils;
|
|||||||
import electrosphere.entity.types.creature.CreatureUtils;
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
import electrosphere.game.client.world.ClientWorldData;
|
import electrosphere.game.client.world.ClientWorldData;
|
||||||
import electrosphere.entity.types.attach.AttachUtils;
|
import electrosphere.entity.types.attach.AttachUtils;
|
||||||
|
import electrosphere.entity.types.item.ItemUtils;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.main.Globals;
|
import electrosphere.main.Globals;
|
||||||
import electrosphere.main.Main;
|
import electrosphere.main.Main;
|
||||||
@ -51,12 +52,23 @@ public class ClientProtocol {
|
|||||||
LoggerInterface.loggerNetworking.DEBUG("Parse entity message of type " + message.getMessageSubtype());
|
LoggerInterface.loggerNetworking.DEBUG("Parse entity message of type " + message.getMessageSubtype());
|
||||||
switch(message.getMessageSubtype()){
|
switch(message.getMessageSubtype()){
|
||||||
case CREATE:
|
case CREATE:
|
||||||
LoggerInterface.loggerNetworking.DEBUG("Spawn ID " + message.getentityID() + " of type " + message.getcreatureType());
|
LoggerInterface.loggerNetworking.DEBUG("Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype());
|
||||||
Entity newlySpawnedEntity = EntityUtils.spawnEntityFromEntityMap(message.getcreatureType());;
|
Entity newlySpawnedEntity;
|
||||||
|
switch(message.getentityCategory()){
|
||||||
|
case 0:
|
||||||
|
newlySpawnedEntity = CreatureUtils.spawnBasicCreature(message.getentitySubtype());
|
||||||
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
|
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
|
||||||
EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
|
EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
|
||||||
EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
|
EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
|
||||||
break;
|
break;
|
||||||
|
case 1:
|
||||||
|
newlySpawnedEntity = ItemUtils.spawnBasicItem(message.getentitySubtype());
|
||||||
|
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
|
||||||
|
EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
|
||||||
|
EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DESTROY:
|
case DESTROY:
|
||||||
break;
|
break;
|
||||||
case MOVE:
|
case MOVE:
|
||||||
|
|||||||
@ -19,7 +19,8 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EntityMessageType messageType;
|
EntityMessageType messageType;
|
||||||
int creatureType;
|
int entityCategory;
|
||||||
|
String entitySubtype;
|
||||||
int entityID;
|
int entityID;
|
||||||
float positionX;
|
float positionX;
|
||||||
float positionY;
|
float positionY;
|
||||||
@ -47,12 +48,20 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
return this.messageType;
|
return this.messageType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getcreatureType() {
|
public int getentityCategory() {
|
||||||
return creatureType;
|
return entityCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setcreatureType(int creatureType) {
|
public void setentityCategory(int entityCategory) {
|
||||||
this.creatureType = creatureType;
|
this.entityCategory = entityCategory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getentitySubtype() {
|
||||||
|
return entitySubtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setentitySubtype(String entitySubtype) {
|
||||||
|
this.entitySubtype = entitySubtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getentityID() {
|
public int getentityID() {
|
||||||
@ -199,11 +208,7 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
public static boolean canParseMessage(List<Byte> byteStream, byte secondByte){
|
public static boolean canParseMessage(List<Byte> byteStream, byte secondByte){
|
||||||
switch(secondByte){
|
switch(secondByte){
|
||||||
case TypeBytes.ENTITY_MESSAGE_TYPE_CREATE:
|
case TypeBytes.ENTITY_MESSAGE_TYPE_CREATE:
|
||||||
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_CREATE_SIZE){
|
return EntityMessage.canParseCreateMessage(byteStream);
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION:
|
case TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION:
|
||||||
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE){
|
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE){
|
||||||
return true;
|
return true;
|
||||||
@ -252,21 +257,57 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean canParseCreateMessage(List<Byte> byteStream){
|
||||||
|
int currentStreamLength = byteStream.size();
|
||||||
|
List<Byte> temporaryByteQueue = new LinkedList();
|
||||||
|
if(currentStreamLength < 6){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(currentStreamLength < 10){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int entitySubtypeSize = 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));
|
||||||
|
entitySubtypeSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||||
|
}
|
||||||
|
if(currentStreamLength < 14 + entitySubtypeSize){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(currentStreamLength < 14){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(currentStreamLength < 18){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(currentStreamLength < 22){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static EntityMessage parseCreateMessage(List<Byte> byteStream){
|
public static EntityMessage parseCreateMessage(List<Byte> byteStream){
|
||||||
EntityMessage rVal = new EntityMessage(EntityMessageType.CREATE);
|
EntityMessage rVal = new EntityMessage(EntityMessageType.CREATE);
|
||||||
stripPacketHeader(byteStream);
|
stripPacketHeader(byteStream);
|
||||||
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||||
rVal.setcreatureType(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
rVal.setentityCategory(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||||
|
rVal.setentitySubtype(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||||
rVal.setpositionX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
rVal.setpositionX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
rVal.setpositionY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
rVal.setpositionY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
rVal.setpositionZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
rVal.setpositionZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EntityMessage constructCreateMessage(int entityID,int creatureType,float positionX,float positionY,float positionZ){
|
public static EntityMessage constructCreateMessage(int entityID,int entityCategory,String entitySubtype,float positionX,float positionY,float positionZ){
|
||||||
EntityMessage rVal = new EntityMessage(EntityMessageType.CREATE);
|
EntityMessage rVal = new EntityMessage(EntityMessageType.CREATE);
|
||||||
rVal.setentityID(entityID);
|
rVal.setentityID(entityID);
|
||||||
rVal.setcreatureType(creatureType);
|
rVal.setentityCategory(entityCategory);
|
||||||
|
rVal.setentitySubtype(entitySubtype);
|
||||||
rVal.setpositionX(positionX);
|
rVal.setpositionX(positionX);
|
||||||
rVal.setpositionY(positionY);
|
rVal.setpositionY(positionY);
|
||||||
rVal.setpositionZ(positionZ);
|
rVal.setpositionZ(positionZ);
|
||||||
@ -475,7 +516,7 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
byte[] stringBytes;
|
byte[] stringBytes;
|
||||||
switch(this.messageType){
|
switch(this.messageType){
|
||||||
case CREATE:
|
case CREATE:
|
||||||
rawBytes = new byte[2+4+4+4+4+4];
|
rawBytes = new byte[2+4+4+4+entitySubtype.length()+4+4+4];
|
||||||
//message header
|
//message header
|
||||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
|
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
|
||||||
//entity messaage header
|
//entity messaage header
|
||||||
@ -484,19 +525,27 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
rawBytes[2+i] = intValues[i];
|
rawBytes[2+i] = intValues[i];
|
||||||
}
|
}
|
||||||
intValues = ByteStreamUtils.serializeIntToBytes(creatureType);
|
intValues = ByteStreamUtils.serializeIntToBytes(entityCategory);
|
||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
rawBytes[6+i] = intValues[i];
|
rawBytes[6+i] = intValues[i];
|
||||||
}
|
}
|
||||||
intValues = ByteStreamUtils.serializeFloatToBytes(positionX);
|
intValues = ByteStreamUtils.serializeIntToBytes(entitySubtype.length());
|
||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
rawBytes[10+i] = intValues[i];
|
rawBytes[10+i] = intValues[i];
|
||||||
|
}
|
||||||
|
stringBytes = entitySubtype.getBytes();
|
||||||
|
for(int i = 0; i < entitySubtype.length(); i++){
|
||||||
|
rawBytes[14+i] = stringBytes[i];
|
||||||
|
}
|
||||||
|
intValues = ByteStreamUtils.serializeFloatToBytes(positionX);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[14+entitySubtype.length()+i] = intValues[i];
|
||||||
} intValues = ByteStreamUtils.serializeFloatToBytes(positionY);
|
} intValues = ByteStreamUtils.serializeFloatToBytes(positionY);
|
||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
rawBytes[14+i] = intValues[i];
|
rawBytes[18+entitySubtype.length()+i] = intValues[i];
|
||||||
} intValues = ByteStreamUtils.serializeFloatToBytes(positionZ);
|
} intValues = ByteStreamUtils.serializeFloatToBytes(positionZ);
|
||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
rawBytes[18+i] = intValues[i];
|
rawBytes[22+entitySubtype.length()+i] = intValues[i];
|
||||||
} break;
|
} break;
|
||||||
case SETPOSITION:
|
case SETPOSITION:
|
||||||
rawBytes = new byte[2+4+8+4+4+4];
|
rawBytes = new byte[2+4+8+4+4+4];
|
||||||
|
|||||||
@ -58,7 +58,6 @@ Message categories
|
|||||||
/*
|
/*
|
||||||
Entity packet sizes
|
Entity packet sizes
|
||||||
*/
|
*/
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_CREATE_SIZE = 22;
|
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 26;
|
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 26;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 26;
|
public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 26;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 46;
|
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 46;
|
||||||
|
|||||||
@ -93,13 +93,12 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
//spawn player in world
|
//spawn player in world
|
||||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.05f);
|
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Goblin");
|
||||||
playerCharacterID = newPlayerCharacter.getId();
|
playerCharacterID = newPlayerCharacter.getId();
|
||||||
EntityUtils.getScale(newPlayerCharacter).set(0.005f);
|
|
||||||
EntityUtils.getPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z);
|
EntityUtils.getPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z);
|
||||||
//spawn player sword
|
//spawn player sword
|
||||||
Entity sword = ItemUtils.spawnBasicItem(2);
|
// Entity sword = ItemUtils.spawnBasicItem("Katana");
|
||||||
AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020");
|
// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020");
|
||||||
//set controller id
|
//set controller id
|
||||||
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
|
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
|
||||||
if(Globals.RUN_SERVER && Main.playerId == -1){
|
if(Globals.RUN_SERVER && Main.playerId == -1){
|
||||||
@ -140,7 +139,8 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
networkParser.addOutgoingMessage(
|
networkParser.addOutgoingMessage(
|
||||||
EntityMessage.constructCreateMessage(
|
EntityMessage.constructCreateMessage(
|
||||||
currentEntity.getId(),
|
currentEntity.getId(),
|
||||||
CreatureUtils.getCreatureType(currentEntity),
|
0, //0 for creatures
|
||||||
|
CreatureUtils.getType(currentEntity),
|
||||||
EntityUtils.getPosition(currentEntity).x,
|
EntityUtils.getPosition(currentEntity).x,
|
||||||
EntityUtils.getPosition(currentEntity).y,
|
EntityUtils.getPosition(currentEntity).y,
|
||||||
EntityUtils.getPosition(currentEntity).z
|
EntityUtils.getPosition(currentEntity).z
|
||||||
@ -157,7 +157,8 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
networkParser.addOutgoingMessage(
|
networkParser.addOutgoingMessage(
|
||||||
EntityMessage.constructCreateMessage(
|
EntityMessage.constructCreateMessage(
|
||||||
currentEntity.getId(),
|
currentEntity.getId(),
|
||||||
CreatureUtils.getCreatureType(currentEntity),
|
1, //1 for items
|
||||||
|
ItemUtils.getType(currentEntity),
|
||||||
EntityUtils.getPosition(currentEntity).x,
|
EntityUtils.getPosition(currentEntity).x,
|
||||||
EntityUtils.getPosition(currentEntity).y,
|
EntityUtils.getPosition(currentEntity).y,
|
||||||
EntityUtils.getPosition(currentEntity).z
|
EntityUtils.getPosition(currentEntity).z
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public class Actor {
|
|||||||
String animation;
|
String animation;
|
||||||
double animationTime;
|
double animationTime;
|
||||||
boolean playingAnimation;
|
boolean playingAnimation;
|
||||||
|
float animationScalar = 1.0f;
|
||||||
|
|
||||||
public Actor(String modelPath){
|
public Actor(String modelPath){
|
||||||
playingAnimation = false;
|
playingAnimation = false;
|
||||||
@ -24,7 +25,7 @@ public class Actor {
|
|||||||
public void incrementAnimationTime(double deltaTime){
|
public void incrementAnimationTime(double deltaTime){
|
||||||
Model model = Globals.assetManager.fetchModel(modelPath);
|
Model model = Globals.assetManager.fetchModel(modelPath);
|
||||||
if(playingAnimation){
|
if(playingAnimation){
|
||||||
animationTime = animationTime + deltaTime;
|
animationTime = animationTime + deltaTime * animationScalar;
|
||||||
}
|
}
|
||||||
if(model != null){
|
if(model != null){
|
||||||
if(animation != null){
|
if(animation != null){
|
||||||
@ -55,6 +56,10 @@ public class Actor {
|
|||||||
return playingAnimation;
|
return playingAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAnimationScalar(float animationScalar) {
|
||||||
|
this.animationScalar = animationScalar;
|
||||||
|
}
|
||||||
|
|
||||||
public void applyModelMatrix(Matrix4f modelMatrix){
|
public void applyModelMatrix(Matrix4f modelMatrix){
|
||||||
Model model = Globals.assetManager.fetchModel(modelPath);
|
Model model = Globals.assetManager.fetchModel(modelPath);
|
||||||
if(model != null){
|
if(model != null){
|
||||||
|
|||||||
@ -14,4 +14,10 @@ public class ActorUtils {
|
|||||||
Globals.assetManager.addModelPathToQueue(modelPath);
|
Globals.assetManager.addModelPathToQueue(modelPath);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void applyBlenderTransformer(Actor a){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -276,9 +276,13 @@
|
|||||||
"categoryName" : "Entity",
|
"categoryName" : "Entity",
|
||||||
"data" : [
|
"data" : [
|
||||||
{
|
{
|
||||||
"name" : "creatureType",
|
"name" : "entityCategory",
|
||||||
"type" : "FIXED_INT"
|
"type" : "FIXED_INT"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name" : "entitySubtype",
|
||||||
|
"type" : "VAR_STRING"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name" : "entityID",
|
"name" : "entityID",
|
||||||
"type" : "FIXED_INT"
|
"type" : "FIXED_INT"
|
||||||
@ -353,7 +357,8 @@
|
|||||||
"messageName" : "Create",
|
"messageName" : "Create",
|
||||||
"data" : [
|
"data" : [
|
||||||
"entityID",
|
"entityID",
|
||||||
"creatureType",
|
"entityCategory",
|
||||||
|
"entitySubtype",
|
||||||
"positionX",
|
"positionX",
|
||||||
"positionY",
|
"positionY",
|
||||||
"positionZ"
|
"positionZ"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user