Work on goblin enemy

This commit is contained in:
austin 2021-11-14 19:52:15 -05:00
parent c2380b0bdc
commit 841add17c6
25 changed files with 435 additions and 107 deletions

View File

@ -12,8 +12,8 @@
"graphicsPerformanceEnableVSync" : false,
"graphicsPerformanceDrawShadows" : true,
"graphicsDebugDrawCollisionSpheres" : true,
"graphicsDebugDrawPhysicsObjects" : true,
"graphicsDebugDrawCollisionSpheres" : false,
"graphicsDebugDrawPhysicsObjects" : false,
"graphicsDebugDrawMovementVectors" : false,
"graphicsDebugDrawNavmesh" : false

View File

@ -90,7 +90,22 @@
{
"type" : "GROUND",
"acceleration" : 16.0,
"maxVelocity" : 3.0
"maxVelocity" : 3.0,
"animationStartup" : {
"name" : "Armature|WalkStart",
"length" : 1,
"loops" : false
},
"animationLoop" : {
"name" : "Armature|Walk",
"length" : 1,
"loops" : false
},
"animationWindDown" : {
"name" : "Armature|WalkStart",
"length" : 1,
"loops" : false
}
}
],
"collidable" : {
@ -214,8 +229,23 @@
"movementSystems" : [
{
"type" : "GROUND",
"acceleration" : 0.001,
"maxVelocity" : 0.025
"acceleration" : 13.0,
"maxVelocity" : 2.8,
"animationStartup" : {
"name" : "Walk",
"length" : 1,
"loops" : false
},
"animationLoop" : {
"name" : "Walk",
"length" : 1,
"loops" : false
},
"animationWindDown" : {
"name" : "Armature|WalkForwardStart",
"length" : 1,
"loops" : false
}
}
],
"collidable" : {

Binary file not shown.

View File

@ -15,6 +15,8 @@ import org.lwjgl.openal.ALC;
//import org.lwjgl.openal.*;
import org.lwjgl.openal.ALC10;
import org.lwjgl.openal.ALCCapabilities;
import static org.lwjgl.openal.ALC10.alcDestroyContext;
import static org.lwjgl.openal.ALC10.alcCloseDevice;
import static org.lwjgl.system.MemoryUtil.NULL;
public class AudioEngine {
@ -70,8 +72,8 @@ public class AudioEngine {
}
public void shutdown(){
ALC10.alcDestroyContext(context);
ALC10.alcCloseDevice(device);
alcDestroyContext(context);
alcCloseDevice(device);
}

View File

@ -241,7 +241,7 @@ public class ControlHandler {
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue()) == GLFW_PRESS){
Vector3f newFacingVector = new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
Vector3d newFacingVector = new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
CreatureUtils.setMovementVector(Globals.playerCharacter, newFacingVector);
// System.out.println("Movement vector: " + newFacingVector);
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
@ -270,7 +270,7 @@ public class ControlHandler {
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD)){
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(cameraEyeVector.x,0,cameraEyeVector.z).normalize());
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3d(cameraEyeVector.x,0,cameraEyeVector.z).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
@ -297,7 +297,7 @@ public class ControlHandler {
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT)){
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(90 * Math.PI / 180)).normalize());
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
@ -324,7 +324,7 @@ public class ControlHandler {
*/
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT)){
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(-90 * Math.PI / 180)).normalize());
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY((float)(-90 * Math.PI / 180)).normalize());
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start();
}
@ -388,7 +388,7 @@ public class ControlHandler {
if(controls.get(DATA_STRING_INPUT_CODE_IN_GAME_MAIN_MENU).isState() == true){
//make menu dialog visible
//change control scheme to in game main menu scheme
System.out.println("Press main menu");
// System.out.println("Press main menu");
Globals.currentMenu = MenuUtils.createInGameMainMenu();
MenuUtils.makeMenuDrawable(Globals.currentMenu);
Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU);

View File

@ -46,6 +46,7 @@ import electrosphere.game.client.targeting.crosshair.Crosshair;
import electrosphere.game.server.pathfinding.NavMeshPathfinder;
import electrosphere.game.server.pathfinding.navmesh.NavCube;
import electrosphere.game.server.pathfinding.navmesh.NavMesh;
import electrosphere.game.server.unit.UnitUtils;
import electrosphere.renderer.ui.Widget;
import electrosphere.renderer.ui.WidgetUtils;
import java.util.Random;
@ -622,6 +623,8 @@ public class LoadingThread extends Thread {
// //attach ai to evil goblin
// MindlessAttacker.attachToCreature(goblin);
// UnitUtils.spawnTextGoblin(10, 0, 10);
// StructureUtils.spawnBasicStructure("building1", new Vector3f(5,2.4f,5), new Quaternionf());
// Entity bow = ItemUtils.spawnBasicItem("Bow");

View File

@ -78,7 +78,7 @@ public class AttackTree {
float velocity = CreatureUtils.getVelocity(parent);
Actor entityActor = EntityUtils.getActor(parent);
Vector3d position = EntityUtils.getPosition(parent);
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
Vector3d movementVector = CreatureUtils.getMovementVector(parent);
//parse attached network messages
for(EntityMessage message : networkMessageQueue){
@ -113,7 +113,7 @@ public class AttackTree {
}
}
EntityUtils.getPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
CreatureUtils.setMovementVector(parent, new Vector3f(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
CreatureUtils.setMovementVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
break;
}
}

View File

@ -11,6 +11,7 @@ import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.renderer.Actor;
import electrosphere.renderer.anim.Animation;
import java.util.concurrent.CopyOnWriteArrayList;
import org.joml.Vector3d;
import org.joml.Vector3f;
public class IdleTree {
@ -83,7 +84,7 @@ public class IdleTree {
break;
}
EntityUtils.getPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
CreatureUtils.setMovementVector(parent, new Vector3f(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
CreatureUtils.setMovementVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
break;
}
}

View File

@ -0,0 +1,9 @@
package electrosphere.entity.state.equip;
/**
*
* @author amaterasu
*/
public class EquipState {
}

View File

@ -0,0 +1,9 @@
package electrosphere.entity.state.equip;
/**
*
* @author amaterasu
*/
public class EquipTree {
}

View File

@ -43,6 +43,10 @@ public class GroundMovementTree {
static final double STATE_DIFFERENCE_SOFT_UPDATE_THRESHOLD = 0.2;
static final double SOFT_UPDATE_MULTIPLIER = 0.1;
String animationStartUp = Animation.ANIMATION_MOVEMENT_STARTUP;
String animationMain = Animation.ANIMATION_MOVEMENT_MOVE;
String animationSlowDown = Animation.ANIMATION_MOVEMENT_MOVE;
MovementTreeState state;
Entity parent;
@ -84,9 +88,9 @@ public class GroundMovementTree {
Actor entityActor = EntityUtils.getActor(parent);
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
Vector3d position = EntityUtils.getPosition(parent);
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
Vector3d movementVector = CreatureUtils.getMovementVector(parent);
// float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera);
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize();
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z)).normalize();
Quaternionf rotation = EntityUtils.getRotation(parent);
Vector3d newPosition;
@ -145,7 +149,7 @@ public class GroundMovementTree {
} else if(position.distance(message.getpositionX(),message.getpositionY(),message.getpositionZ()) > STATE_DIFFERENCE_SOFT_UPDATE_THRESHOLD){
EntityUtils.getPosition(parent).add(new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()).mul(SOFT_UPDATE_MULTIPLIER));
}
CreatureUtils.setMovementVector(parent, new Vector3f(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
CreatureUtils.setMovementVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
// EntityUtils.getEntityRotation(parent).set(message.getrotationX(), message.getrotationY(), message.getrotationZ(), message.getrotationW()).normalize();
// velocity = message.getvelocity();
break;
@ -161,8 +165,8 @@ public class GroundMovementTree {
velocity = velocity + acceleration * Main.deltaTime;
CreatureUtils.setVelocity(parent, velocity);
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(Animation.ANIMATION_MOVEMENT_STARTUP)){
entityActor.playAnimation(Animation.ANIMATION_MOVEMENT_STARTUP);
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(animationStartUp)){
entityActor.playAnimation(animationStartUp);
entityActor.incrementAnimationTime(0.01);
}
}
@ -238,8 +242,8 @@ public class GroundMovementTree {
//check if can restart animation
//if yes, restart animation
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(Animation.ANIMATION_MOVEMENT_MOVE)){
entityActor.playAnimation(Animation.ANIMATION_MOVEMENT_MOVE);
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(animationMain)){
entityActor.playAnimation(animationMain);
entityActor.incrementAnimationTime(0.01);
}
}
@ -310,8 +314,8 @@ public class GroundMovementTree {
velocity = velocity - acceleration * Main.deltaTime;
CreatureUtils.setVelocity(parent, velocity);
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(Animation.ANIMATION_MOVEMENT_STARTUP)){
entityActor.playAnimation(Animation.ANIMATION_MOVEMENT_STARTUP);
if(!entityActor.isPlayingAnimation() || !entityActor.getCurrentAnimation().equals(animationSlowDown)){
entityActor.playAnimation(animationSlowDown);
entityActor.incrementAnimationTime(0.01);
}
}
@ -321,7 +325,7 @@ public class GroundMovementTree {
state = MovementTreeState.IDLE;
}
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity)));
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z));
//move the entity
// newPosition = new Vector3d(position).add(new Vector3d(movementVector).mul(velocity).mul(Main.deltaTime));
// if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
@ -329,7 +333,7 @@ public class GroundMovementTree {
// }
collidable.addImpulse(new Impulse(new Vector3d(movementVector), velocity * Main.deltaTime, "movement"));
// position.set(newPosition);
rotation.rotationTo(new Vector3f(0,0,1), movementVector);
rotation.rotationTo(new Vector3f(0,0,1), new Vector3f((float)movementVector.x,(float)movementVector.y,(float)movementVector.z));
activateGravityTree();
@ -409,5 +413,17 @@ public class GroundMovementTree {
tree.start();
}
}
public void setAnimationStartUp(String animationStartUp) {
this.animationStartUp = animationStartUp;
}
public void setAnimationMain(String animationMain) {
this.animationMain = animationMain;
}
public void setAnimationSlowDown(String animationSlowDown) {
this.animationSlowDown = animationSlowDown;
}
}

View File

@ -53,8 +53,8 @@ public class AttachUtils {
//set rotation
// Quaternionf rotation = parentActor.getBoneRotation(targetBone);
// EntityUtils.getRotation(currentEntity).set(rotation).normalize();
Vector3f facingAngle = CreatureUtils.getMovementVector(parent);
EntityUtils.getRotation(currentEntity).rotationTo(new Vector3f(0,0,1), facingAngle).mul(parentActor.getBoneRotation(targetBone)).normalize();
Vector3d facingAngle = CreatureUtils.getMovementVector(parent);
EntityUtils.getRotation(currentEntity).rotationTo(new Vector3f(0,0,1), new Vector3f((float)facingAngle.x,(float)facingAngle.y,(float)facingAngle.z)).mul(parentActor.getBoneRotation(targetBone)).normalize();
}
}
}

View File

@ -94,7 +94,17 @@ public class CreatureUtils {
for(MovementSystem movementSystem : rawType.getMovementSystems()){
switch(movementSystem.getType()){
case "GROUND":
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new GroundMovementTree(rVal,CollisionObjUtils.getCollidable(rVal)));
GroundMovementTree moveTree = new GroundMovementTree(rVal,CollisionObjUtils.getCollidable(rVal));
if(movementSystem.getAnimationStartup() != null){
moveTree.setAnimationStartUp(movementSystem.getAnimationStartup().getName());
}
if(movementSystem.getAnimationLoop() != null){
moveTree.setAnimationMain(movementSystem.getAnimationLoop().getName());
}
if(movementSystem.getAnimationWindDown()!= null){
moveTree.setAnimationSlowDown(movementSystem.getAnimationWindDown().getName());
}
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, moveTree);
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, movementSystem.getMaxVelocity());
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, movementSystem.getAcceleration());
@ -146,7 +156,7 @@ public class CreatureUtils {
Globals.entityManager.registerCreatureEntity(rVal);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,1));
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3d(0,0,1));
rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true);
return rVal;
}
@ -163,12 +173,12 @@ public class CreatureUtils {
}
}
public static void setMovementVector(Entity e, Vector3f vector){
public static void setMovementVector(Entity e, Vector3d vector){
e.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, vector);
}
public static Vector3f getMovementVector(Entity e){
return (Vector3f)e.getData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR);
public static Vector3d getMovementVector(Entity e){
return (Vector3d)e.getData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR);
}
public static float getAcceleration(Entity e){

View File

@ -0,0 +1,25 @@
package electrosphere.game.data.creature.type;
/**
*
* @author amaterasu
*/
public class Animation {
String name;
int length;
boolean loops;
public String getName() {
return name;
}
public int getLength() {
return length;
}
public boolean isLoops() {
return loops;
}
}

View File

@ -4,7 +4,10 @@ public class MovementSystem {
String type;
float acceleration;
float maxVelocity;
Animation animationStartup;
Animation animationLoop;
Animation animationWindDown;
public String getType() {
return type;
}
@ -16,6 +19,18 @@ public class MovementSystem {
public float getMaxVelocity() {
return maxVelocity;
}
public Animation getAnimationStartup() {
return animationStartup;
}
public Animation getAnimationLoop() {
return animationLoop;
}
public Animation getAnimationWindDown() {
return animationWindDown;
}
}

View File

@ -0,0 +1,162 @@
package electrosphere.game.server.ai.creature;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.server.ai.AI;
import electrosphere.main.Globals;
import java.util.Random;
import org.joml.Vector3d;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class MillAbout extends AI {
Entity character;
// float aggroRange = 10.0f;
// float attackRange = 1.0f;
//
// int attackCooldownMax = 250;
// int attackCooldown = 0;
boolean millAbout = true;
int millMoveTimer = 0;
int millMoveTimerTimeout = 100;
int MILL_MOVE_TIMEOUT_LOWER = 1500;
int MILL_MOVE_TIMEOUT_UPPER = 2000;
float millTargetMaxDist = 3;
boolean moveToTarget = false;
Vector3d moveTargetPosition;
public MillAbout(Entity character){
this.character = character;
}
public static void attachToCreature(Entity creature){
MillAbout ai = new MillAbout(creature);
Globals.aiManager.registerAI(ai);
}
@Override
public void simulate(){
Vector3d position = EntityUtils.getPosition(character);
//mill aboud
if(millAbout){
if(millMoveTimer >= millMoveTimerTimeout){
Random rand = new Random();
millMoveTimer = 0;
millMoveTimerTimeout = rand.nextInt(MILL_MOVE_TIMEOUT_UPPER - MILL_MOVE_TIMEOUT_LOWER) + MILL_MOVE_TIMEOUT_LOWER;
Vector3d moveVector = new Vector3d();
//search for a spot to mill to
// while(true){
moveVector.set(
rand.nextFloat() - 0.5,
rand.nextFloat() - 0.5,
rand.nextFloat() - 0.5
).normalize().mul(millTargetMaxDist);
moveVector.y = Globals.commonWorldData.getElevationAtPoint(new Vector3d(position).add(moveVector));
//TODO: search in navmeshmanager to make sure navigable, otherwise generate new pos
// }
moveTargetPosition = new Vector3d(position).add(moveVector);
millAbout = false;
moveToTarget = true;
} else {
millMoveTimer++;
}
}
if(moveToTarget){
if(moveTargetPosition.distance(position) > 0.4){
Vector3d moveVector = new Vector3d(moveTargetPosition).sub(position).normalize();
CreatureUtils.setMovementVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
characterMoveTree.start();
}
} else {
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
characterMoveTree.slowdown();
System.out.println("Made it to destination");
moveToTarget = false;
millAbout = true;
}
}
// if(target != null){
// if(inAttackRange()){
// attack();
// } else {
// if(inAggroRange()){
// moveToTarget();
// } else {
// target = null;
// }
// }
// } else {
// searchForTarget();
// }
}
// void attack(){
// if(attackCooldown == 0){
// attackCooldown = attackCooldownMax;
// AttackTree attackTree = CreatureUtils.getAttackTree(character);
// attackTree.start(EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND);
// } else {
// attackCooldown--;
// }
// }
// void moveToTarget(){
// Vector3d targetPosition = EntityUtils.getPosition(target);
// Vector3d characterPosition = EntityUtils.getPosition(character);
// Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
// CreatureUtils.setMovementVector(character, new Vector3f((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
// GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
// if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
// characterMoveTree.start();
// }
// }
// boolean inAttackRange(){
// boolean rVal = false;
// Vector3d position = EntityUtils.getPosition(character);
// Vector3d targetPosition = EntityUtils.getPosition(target);
// if(new Vector3d(position).distance(targetPosition) < attackRange){
// rVal = true;
// }
// return rVal;
// }
// boolean inAggroRange(){
// boolean rVal = false;
// Vector3d position = EntityUtils.getPosition(character);
// Vector3d targetPosition = EntityUtils.getPosition(target);
// if(new Vector3d(position).distance(targetPosition) < aggroRange){
// rVal = true;
// }
// return rVal;
// }
// void searchForTarget(){
// Vector3d position = EntityUtils.getPosition(character);
// for(Entity current : Globals.entityManager.getLifeStateEntities()){
// if(current != character){
// Vector3d potentialTargetPosition = EntityUtils.getPosition(current);
// if(position.distance(potentialTargetPosition) < aggroRange){
// target = current;
// break;
// }
// }
// }
// }
}

View File

@ -69,7 +69,7 @@ public class MindlessAttacker extends AI{
Vector3d targetPosition = EntityUtils.getPosition(target);
Vector3d characterPosition = EntityUtils.getPosition(character);
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
CreatureUtils.setMovementVector(character, new Vector3f((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
CreatureUtils.setMovementVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
GroundMovementTree characterMoveTree = CreatureUtils.getEntityMovementTree(character);
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
characterMoveTree.start();

View File

@ -29,7 +29,7 @@ public class ServerTerrainChunk {
long[][] randomizer = new long[5][5];
float[][] heightmap = new float[width + 1][width + 1];
ServerTerrainChunk rVal = new ServerTerrainChunk(x, y, heightmap, macroValues, randomizer);
rVal.addModification(new TerrainModification(x, y, 3, 3, 5));
// rVal.addModification(new TerrainModification(x, y, 3, 3, 5));
return rVal;
}

View File

@ -0,0 +1,30 @@
package electrosphere.game.server.unit;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.server.ai.creature.MillAbout;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class UnitUtils {
public static void spawnTextGoblin(float posX, float posY, float posZ){
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin");
CollisionObjUtils.positionCharacter(goblin, new Vector3f(posX, posY, posZ));
EntityUtils.getScale(goblin).set(0.005f);
//give evil goblin sword
Entity goblinSword = ItemUtils.spawnBasicItem("Katana");
AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031");
//attach ai to evil goblin
MillAbout.attachToCreature(goblin);
// MindlessAttacker.attachToCreature(goblin);
}
}

View File

@ -173,9 +173,9 @@ public class Main {
//uncomment to test loading a model into engine
// if(1==1){
// Globals.assetManager.addModelPathToQueue("/Models/arrow1.fbx");
// Globals.assetManager.addModelPathToQueue("/Models/goblin1.fbx");
// Globals.assetManager.loadAssetsInQueue();
// Model bowModel = Globals.assetManager.fetchModel("/Models/arrow1.fbx");
// Model bowModel = Globals.assetManager.fetchModel("/Models/goblin1.fbx");
// bowModel.describeHighLevel();
// System.exit(0);
// }

View File

@ -27,10 +27,10 @@ public class EntityMessage extends NetworkMessage {
double positionY;
double positionZ;
float rotationW;
float rotationX;
float rotationY;
float rotationZ;
float velocity;
double rotationX;
double rotationY;
double rotationZ;
double velocity;
int treeState;
int propertyType;
int propertyValue;
@ -105,35 +105,35 @@ public class EntityMessage extends NetworkMessage {
this.rotationW = rotationW;
}
public float getrotationX() {
public double getrotationX() {
return rotationX;
}
public void setrotationX(float rotationX) {
public void setrotationX(double rotationX) {
this.rotationX = rotationX;
}
public float getrotationY() {
public double getrotationY() {
return rotationY;
}
public void setrotationY(float rotationY) {
public void setrotationY(double rotationY) {
this.rotationY = rotationY;
}
public float getrotationZ() {
public double getrotationZ() {
return rotationZ;
}
public void setrotationZ(float rotationZ) {
public void setrotationZ(double rotationZ) {
this.rotationZ = rotationZ;
}
public float getvelocity() {
public double getvelocity() {
return velocity;
}
public void setvelocity(float velocity) {
public void setvelocity(double velocity) {
this.velocity = velocity;
}
@ -349,13 +349,13 @@ public class EntityMessage extends NetworkMessage {
stripPacketHeader(byteStream);
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
rVal.settime(ByteStreamUtils.popLongFromByteQueue(byteStream));
rVal.setrotationX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
return rVal;
}
public static EntityMessage constructsetFacingMessage(int entityID,long time,float rotationX,float rotationY,float rotationZ){
public static EntityMessage constructsetFacingMessage(int entityID,long time,double rotationX,double rotationY,double rotationZ){
EntityMessage rVal = new EntityMessage(EntityMessageType.SETFACING);
rVal.setentityID(entityID);
rVal.settime(time);
@ -374,15 +374,15 @@ public class EntityMessage extends NetworkMessage {
rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setvelocity(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setvelocity(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.settreeState(ByteStreamUtils.popIntFromByteQueue(byteStream));
return rVal;
}
public static EntityMessage constructmoveUpdateMessage(int entityID,long time,double positionX,double positionY,double positionZ,float rotationX,float rotationY,float rotationZ,float velocity,int treeState){
public static EntityMessage constructmoveUpdateMessage(int entityID,long time,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double velocity,int treeState){
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVEUPDATE);
rVal.setentityID(entityID);
rVal.settime(time);
@ -406,15 +406,15 @@ public class EntityMessage extends NetworkMessage {
rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setvelocity(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrotationX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrotationZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setvelocity(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.settreeState(ByteStreamUtils.popIntFromByteQueue(byteStream));
return rVal;
}
public static EntityMessage constructattackUpdateMessage(int entityID,long time,double positionX,double positionY,double positionZ,float rotationX,float rotationY,float rotationZ,float velocity,int treeState){
public static EntityMessage constructattackUpdateMessage(int entityID,long time,double positionX,double positionY,double positionZ,double rotationX,double rotationY,double rotationZ,double velocity,int treeState){
EntityMessage rVal = new EntityMessage(EntityMessageType.ATTACKUPDATE);
rVal.setentityID(entityID);
rVal.settime(time);
@ -617,7 +617,7 @@ public class EntityMessage extends NetworkMessage {
}
break;
case SETFACING:
rawBytes = new byte[2+4+8+4+4+4];
rawBytes = new byte[2+4+8+8+8+8];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
//entity messaage header
@ -630,18 +630,21 @@ public class EntityMessage extends NetworkMessage {
for(int i = 0; i < 8; i++){
rawBytes[6+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeFloatToBytes(rotationX);
for(int i = 0; i < 4; i++){
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationX);
for(int i = 0; i < 8; i++){
rawBytes[14+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationY);
for(int i = 0; i < 4; i++){
rawBytes[18+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationZ);
for(int i = 0; i < 4; i++){
}
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationY);
for(int i = 0; i < 8; i++){
rawBytes[22+i] = intValues[i];
} break;
}
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationZ);
for(int i = 0; i < 8; i++){
rawBytes[30+i] = intValues[i];
}
break;
case MOVEUPDATE:
rawBytes = new byte[2+4+8+8+8+8+4+4+4+4+4];
rawBytes = new byte[2+4+8+8+8+8+8+8+8+8+4];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
//entity messaage header
@ -666,25 +669,29 @@ public class EntityMessage extends NetworkMessage {
for(int i = 0; i < 8; i++){
rawBytes[30+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeFloatToBytes(rotationX);
for(int i = 0; i < 4; i++){
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationX);
for(int i = 0; i < 8; i++){
rawBytes[38+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationY);
for(int i = 0; i < 4; i++){
rawBytes[42+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationZ);
for(int i = 0; i < 4; i++){
}
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationY);
for(int i = 0; i < 8; i++){
rawBytes[46+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(velocity);
for(int i = 0; i < 4; i++){
rawBytes[50+i] = intValues[i];
} intValues = ByteStreamUtils.serializeIntToBytes(treeState);
for(int i = 0; i < 4; i++){
}
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationZ);
for(int i = 0; i < 8; i++){
rawBytes[54+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeDoubleToBytes(velocity);
for(int i = 0; i < 8; i++){
rawBytes[62+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeIntToBytes(treeState);
for(int i = 0; i < 4; i++){
rawBytes[70+i] = intValues[i];
}
break;
case ATTACKUPDATE:
rawBytes = new byte[2+4+8+8+8+8+4+4+4+4+4];
rawBytes = new byte[2+4+8+8+8+8+8+8+8+8+4];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
//entity messaage header
@ -709,22 +716,26 @@ public class EntityMessage extends NetworkMessage {
for(int i = 0; i < 8; i++){
rawBytes[30+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeFloatToBytes(rotationX);
for(int i = 0; i < 4; i++){
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationX);
for(int i = 0; i < 8; i++){
rawBytes[38+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationY);
for(int i = 0; i < 4; i++){
rawBytes[42+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationZ);
for(int i = 0; i < 4; i++){
}
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationY);
for(int i = 0; i < 8; i++){
rawBytes[46+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(velocity);
for(int i = 0; i < 4; i++){
rawBytes[50+i] = intValues[i];
} intValues = ByteStreamUtils.serializeIntToBytes(treeState);
for(int i = 0; i < 4; i++){
}
intValues = ByteStreamUtils.serializeDoubleToBytes(rotationZ);
for(int i = 0; i < 8; i++){
rawBytes[54+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeDoubleToBytes(velocity);
for(int i = 0; i < 8; i++){
rawBytes[62+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeIntToBytes(treeState);
for(int i = 0; i < 4; i++){
rawBytes[70+i] = intValues[i];
}
break;
case MOVE:
rawBytes = new byte[2+4+8+8+8+8];

View File

@ -64,9 +64,9 @@ Message categories
Entity packet sizes
*/
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 38;
public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 26;
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 58;
public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE_SIZE = 58;
public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 38;
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 74;
public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE_SIZE = 74;
public static final byte ENTITY_MESSAGE_TYPE_MOVE_SIZE = 38;
public static final byte ENTITY_MESSAGE_TYPE_DESTROY_SIZE = 6;
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE_SIZE = 22;

View File

@ -97,7 +97,7 @@ public class ServerConnectionHandler implements Runnable {
Player newPlayerObject = new Player(this);
Globals.playerManager.addPlayer(newPlayerObject);
//spawn player in world
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Human");
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Goblin");
playerCharacterID = newPlayerCharacter.getId();
CollisionObjUtils.positionCharacter(newPlayerCharacter, new Vector3f(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
//attach player object to player character

View File

@ -208,6 +208,11 @@ public class Model {
}
}
if(currentAnimation != null){
// if(s.contains("Walk")){
// currentAnimation.describeAnimation();
//// currentAnimation.fullDescribeAnimation();
// System.exit(0);
// }
currentAnimation.timeCurrent = 0;
Iterator<AnimChannel> channelIterator = currentAnimation.channels.iterator();
while(channelIterator.hasNext()){

View File

@ -495,19 +495,19 @@
},
{
"name" : "rotationX",
"type" : "FIXED_FLOAT"
"type" : "FIXED_DOUBLE"
},
{
"name" : "rotationY",
"type" : "FIXED_FLOAT"
"type" : "FIXED_DOUBLE"
},
{
"name" : "rotationZ",
"type" : "FIXED_FLOAT"
"type" : "FIXED_DOUBLE"
},
{
"name" : "velocity",
"type" : "FIXED_FLOAT"
"type" : "FIXED_DOUBLE"
},
{
"name" : "treeState",