Add life system
This commit is contained in:
parent
6096a36896
commit
955d773f0d
@ -99,6 +99,10 @@
|
||||
"damageEndFrame" : 50
|
||||
}
|
||||
],
|
||||
"healthSystem" : {
|
||||
"maxHealth" : 100,
|
||||
"onDamageIFrames" : 30
|
||||
},
|
||||
"modelPath" : "Models/person1animpass2.fbx"
|
||||
},
|
||||
|
||||
@ -203,6 +207,10 @@
|
||||
"damageEndFrame" : 30
|
||||
}
|
||||
],
|
||||
"healthSystem" : {
|
||||
"maxHealth" : 100,
|
||||
"onDamageIFrames" : 30
|
||||
},
|
||||
"modelPath" : "Models/goblin1.fbx"
|
||||
}
|
||||
|
||||
|
||||
@ -109,6 +109,11 @@ public class EntityDataStrings {
|
||||
public static final String ATTACK_MOVE_TYPE_ACTIVE = "attackMoveTypeActive";
|
||||
public static final String ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND = "MELEE_WEAPON_SWING_ONE_HAND";
|
||||
|
||||
/*
|
||||
Health System
|
||||
*/
|
||||
public static final String LIFE_STATE = "lifeState";
|
||||
|
||||
/*
|
||||
idle behavior tree
|
||||
*/
|
||||
|
||||
@ -22,6 +22,7 @@ public class EntityManager {
|
||||
static CopyOnWriteArrayList<Entity> attachList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> attackerList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> creatureList = new CopyOnWriteArrayList();
|
||||
static CopyOnWriteArrayList<Entity> lifeStateList = new CopyOnWriteArrayList();
|
||||
|
||||
public EntityManager(){
|
||||
|
||||
@ -96,6 +97,14 @@ public class EntityManager {
|
||||
return creatureList;
|
||||
}
|
||||
|
||||
public void registerLifeStateEntity(Entity e){
|
||||
lifeStateList.add(e);
|
||||
}
|
||||
|
||||
public CopyOnWriteArrayList<Entity> getLifeStateEntities(){
|
||||
return lifeStateList;
|
||||
}
|
||||
|
||||
public void deregisterEntity(Entity e){
|
||||
if(lightList.contains(e)){
|
||||
lightList.remove(e);
|
||||
@ -122,6 +131,9 @@ public class EntityManager {
|
||||
if(creatureList.contains(e)){
|
||||
creatureList.remove(e);
|
||||
}
|
||||
if(lifeStateList.contains(e)){
|
||||
lifeStateList.remove(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void overrideEntityId(Entity e, int id){
|
||||
|
||||
@ -10,6 +10,7 @@ import electrosphere.game.server.creature.type.CreatureType;
|
||||
import electrosphere.game.server.creature.type.MovementSystem;
|
||||
import electrosphere.entity.state.AttackTree;
|
||||
import electrosphere.entity.state.IdleTree;
|
||||
import electrosphere.entity.types.life.LifeState;
|
||||
import electrosphere.game.server.creature.type.AttackMove;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
@ -81,6 +82,7 @@ public class CreatureUtils {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//add all attack moves
|
||||
for(AttackMove attackMove : rawType.getAttackMoves()){
|
||||
switch(attackMove.getType()){
|
||||
case EntityDataStrings.ATTACK_MOVE_TYPE_MELEE_SWING_ONE_HAND:
|
||||
@ -88,6 +90,10 @@ public class CreatureUtils {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//add health system
|
||||
rVal.putData(EntityDataStrings.LIFE_STATE, new LifeState(rVal, rawType.getHealthSystem()));
|
||||
Globals.entityManager.registerLifeStateEntity(rVal);
|
||||
//idle tree & generic stuff all creatures have
|
||||
rVal.putData(EntityDataStrings.IDLE_TREE, new IdleTree(rVal));
|
||||
Globals.entityManager.registerCreatureEntity(rVal);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
|
||||
|
||||
@ -5,6 +5,7 @@ import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.entity.types.life.LifeUtils;
|
||||
import electrosphere.main.Globals;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
@ -116,10 +117,18 @@ public class HitboxUtils {
|
||||
|
||||
if(isItem){
|
||||
if(hitboxAttachParent != hurtboxParent){
|
||||
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
|
||||
LifeUtils.getLifeState(hurtboxParent).damage(20);
|
||||
if(!LifeUtils.getLifeState(hurtboxParent).isIsAlive()){
|
||||
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
|
||||
LifeUtils.getLifeState(hurtboxParent).revive();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
|
||||
LifeUtils.getLifeState(hurtboxParent).damage(20);
|
||||
if(!LifeUtils.getLifeState(hurtboxParent).isIsAlive()){
|
||||
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
|
||||
LifeUtils.getLifeState(hurtboxParent).revive();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
package electrosphere.entity.types.life;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class AliveManager {
|
||||
List<Entity> aliveList = new ArrayList();
|
||||
List<Entity> deadList = new ArrayList();
|
||||
List<Entity> invulnerableList = new ArrayList();
|
||||
|
||||
public List<Entity> getAliveEntities(){
|
||||
return aliveList;
|
||||
}
|
||||
|
||||
public List<Entity> getDeadEntities(){
|
||||
return deadList;
|
||||
}
|
||||
|
||||
public List<Entity> getInvulnerableEntities(){
|
||||
return invulnerableList;
|
||||
}
|
||||
|
||||
|
||||
public void registerAliveEntity(Entity e){
|
||||
aliveList.add(e);
|
||||
}
|
||||
|
||||
}
|
||||
112
src/main/java/electrosphere/entity/types/life/LifeState.java
Normal file
112
src/main/java/electrosphere/entity/types/life/LifeState.java
Normal file
@ -0,0 +1,112 @@
|
||||
package electrosphere.entity.types.life;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.game.server.creature.type.HealthSystem;
|
||||
|
||||
public class LifeState {
|
||||
|
||||
Entity parent;
|
||||
|
||||
boolean isAlive;
|
||||
boolean isInvincible;
|
||||
int lifeCurrent;
|
||||
int lifeMax;
|
||||
int iFrameMaxCount;
|
||||
int iFrameCurrent;
|
||||
|
||||
public LifeState(Entity parent, HealthSystem system){
|
||||
this.parent = parent;
|
||||
isAlive = true;
|
||||
isInvincible = false;
|
||||
lifeMax = system.getMaxHealth();
|
||||
lifeCurrent = lifeMax;
|
||||
iFrameMaxCount = system.getOnDamageIFrames();
|
||||
iFrameCurrent = 0;
|
||||
}
|
||||
|
||||
public LifeState(Entity parent, boolean isAlive, boolean isInvincible, int lifeCurrent, int lifeMax, int iFrameMaxCount) {
|
||||
this.parent = parent;
|
||||
this.isAlive = isAlive;
|
||||
this.isInvincible = isInvincible;
|
||||
this.lifeCurrent = lifeCurrent;
|
||||
this.lifeMax = lifeMax;
|
||||
this.iFrameMaxCount = iFrameMaxCount;
|
||||
}
|
||||
|
||||
public boolean isIsAlive() {
|
||||
return isAlive;
|
||||
}
|
||||
|
||||
public boolean isIsInvincible() {
|
||||
return isInvincible;
|
||||
}
|
||||
|
||||
public int getLifeCurrent() {
|
||||
return lifeCurrent;
|
||||
}
|
||||
|
||||
public int getLifeMax() {
|
||||
return lifeMax;
|
||||
}
|
||||
|
||||
public void setIsAlive(boolean isAlive) {
|
||||
this.isAlive = isAlive;
|
||||
}
|
||||
|
||||
public void setIsInvincible(boolean isInvincible) {
|
||||
this.isInvincible = isInvincible;
|
||||
}
|
||||
|
||||
public void setLifeCurrent(int lifeCurrent) {
|
||||
this.lifeCurrent = lifeCurrent;
|
||||
}
|
||||
|
||||
public void setLifeMax(int lifeMax) {
|
||||
this.lifeMax = lifeMax;
|
||||
}
|
||||
|
||||
public int getiFrameMaxCount() {
|
||||
return iFrameMaxCount;
|
||||
}
|
||||
|
||||
public int getiFrameCurrent() {
|
||||
return iFrameCurrent;
|
||||
}
|
||||
|
||||
public void setiFrameMaxCount(int iFrameMaxCount) {
|
||||
this.iFrameMaxCount = iFrameMaxCount;
|
||||
}
|
||||
|
||||
public void setiFrameCurrent(int iFrameCurrent) {
|
||||
this.iFrameCurrent = iFrameCurrent;
|
||||
}
|
||||
|
||||
public void damage(int damage){
|
||||
if(!isInvincible){
|
||||
lifeCurrent = lifeCurrent - damage;
|
||||
isInvincible = true;
|
||||
if(lifeCurrent < 0){
|
||||
lifeCurrent = 0;
|
||||
isAlive = false;
|
||||
} else {
|
||||
iFrameCurrent = iFrameMaxCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void revive(){
|
||||
isAlive = true;
|
||||
isInvincible = false;
|
||||
lifeCurrent = lifeMax;
|
||||
}
|
||||
|
||||
public void simulate(){
|
||||
if(iFrameCurrent > 0){
|
||||
iFrameCurrent--;
|
||||
if(iFrameCurrent == 0){
|
||||
isInvincible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
16
src/main/java/electrosphere/entity/types/life/LifeUtils.java
Normal file
16
src/main/java/electrosphere/entity/types/life/LifeUtils.java
Normal file
@ -0,0 +1,16 @@
|
||||
package electrosphere.entity.types.life;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class LifeUtils {
|
||||
|
||||
|
||||
public static LifeState getLifeState(Entity e){
|
||||
return (LifeState)e.getData(EntityDataStrings.LIFE_STATE);
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@ public class CreatureType {
|
||||
List<String> tokens;
|
||||
List<MovementSystem> movementSystems;
|
||||
List<AttackMove> attackMoves;
|
||||
HealthSystem healthSystem;
|
||||
String modelPath;
|
||||
|
||||
public String getName() {
|
||||
@ -39,6 +40,10 @@ public class CreatureType {
|
||||
public List<AttackMove> getAttackMoves() {
|
||||
return attackMoves;
|
||||
}
|
||||
|
||||
public HealthSystem getHealthSystem() {
|
||||
return healthSystem;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package electrosphere.game.server.creature.type;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class HealthSystem {
|
||||
int maxHealth;
|
||||
int onDamageIFrames;
|
||||
|
||||
public int getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public int getOnDamageIFrames() {
|
||||
return onDamageIFrames;
|
||||
}
|
||||
|
||||
public HealthSystem clone(){
|
||||
HealthSystem rVal = new HealthSystem();
|
||||
rVal.maxHealth = maxHealth;
|
||||
rVal.onDamageIFrames = onDamageIFrames;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
}
|
||||
@ -9,6 +9,8 @@ import electrosphere.entity.state.MovementTree;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.hitbox.HitboxUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.entity.types.life.LifeState;
|
||||
import electrosphere.entity.types.life.LifeUtils;
|
||||
import electrosphere.main.Globals;
|
||||
import static electrosphere.main.Main.deltaTime;
|
||||
import electrosphere.renderer.Actor;
|
||||
@ -53,6 +55,11 @@ public class MicroSimulation {
|
||||
IdleTree idleTree = CreatureUtils.getIdleTree(currentIdler);
|
||||
idleTree.simulate();
|
||||
}
|
||||
//life state updates
|
||||
for(Entity lifeStateEntity : Globals.entityManager.getLifeStateEntities()){
|
||||
LifeState lifeState = LifeUtils.getLifeState(lifeStateEntity);
|
||||
lifeState.simulate();
|
||||
}
|
||||
//update attached entity positions
|
||||
AttachUtils.updateAttachedEntityPositions();
|
||||
//update hitbox positions
|
||||
|
||||
@ -17,7 +17,6 @@ import electrosphere.game.client.player.ClientPlayerData;
|
||||
import electrosphere.game.client.terrain.manager.ClientTerrainManager;
|
||||
import electrosphere.game.client.world.ClientWorldData;
|
||||
import electrosphere.game.collision.CommonWorldData;
|
||||
import electrosphere.entity.types.life.AliveManager;
|
||||
import electrosphere.engine.LoadingThread;
|
||||
import electrosphere.game.server.creature.type.model.CreatureTypeMap;
|
||||
import electrosphere.game.server.item.type.model.ItemTypeMap;
|
||||
@ -207,9 +206,6 @@ public class Globals {
|
||||
//ui text box for loading text
|
||||
public static TextBox loadingBox;
|
||||
|
||||
//life status entity manager
|
||||
public static AliveManager aliveManager;
|
||||
|
||||
//collision world data
|
||||
public static CommonWorldData commonWorldData;
|
||||
|
||||
@ -255,8 +251,6 @@ public class Globals {
|
||||
widgetManager = new WidgetManager();
|
||||
//hitbox manager
|
||||
hitboxManager = new HitboxManager();
|
||||
//alive manager
|
||||
aliveManager = new AliveManager();
|
||||
}
|
||||
|
||||
public static void initDefaultGraphicalResources(){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user