store damage counter in item.json
This commit is contained in:
parent
e303ac4a03
commit
2764522b16
@ -8,6 +8,7 @@
|
||||
"modelPath" : "Models/katana1alt.fbx",
|
||||
"weaponData" : {
|
||||
"weaponClass" : "sword1h",
|
||||
"damage" : 10,
|
||||
"hitboxes" : [
|
||||
{
|
||||
"type": "hit",
|
||||
@ -51,6 +52,7 @@
|
||||
"modelPath": "Models/bow1.fbx",
|
||||
"weaponData" : {
|
||||
"weaponClass" : "bow2h",
|
||||
"damage" : 10,
|
||||
"projectileModel" : "Models/arrow1.fbx"
|
||||
},
|
||||
"tokens" : [
|
||||
|
||||
@ -154,6 +154,12 @@
|
||||
"positionZ"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "Kill",
|
||||
"data" : [
|
||||
"entityID"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "Destroy",
|
||||
"data" : [
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
package electrosphere.entity.state.life;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.game.data.creature.type.HealthSystem;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
|
||||
public class LifeState {
|
||||
|
||||
@ -88,6 +93,16 @@ public class LifeState {
|
||||
if(lifeCurrent < 0){
|
||||
lifeCurrent = 0;
|
||||
isAlive = false;
|
||||
if(Globals.RUN_SERVER){
|
||||
Vector3d position = EntityUtils.getPosition(parent);
|
||||
Globals.dataCellManager.sendNetworkMessageToChunk(
|
||||
EntityMessage.constructKillMessage(
|
||||
parent.getId()
|
||||
),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(position.x),
|
||||
Globals.serverWorldData.convertRealToChunkSpace(position.z)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
iFrameCurrent = iFrameMaxCount;
|
||||
}
|
||||
|
||||
@ -121,14 +121,15 @@ public class HitboxUtils {
|
||||
|
||||
//if the entity is attached to is an item, we need to compare with the parent of the item
|
||||
//to make sure you don't stab yourself for instance
|
||||
boolean isItem = hitboxParent.containsKey(EntityDataStrings.ITEM_IS_ITEM);
|
||||
boolean isItem = ItemUtils.isItem(hitboxParent);//hitboxParent.containsKey(EntityDataStrings.ITEM_IS_ITEM);
|
||||
Entity hitboxAttachParent = AttachUtils.getParent(hitboxParent);
|
||||
|
||||
if(isItem){
|
||||
if(hitboxAttachParent != hurtboxParent){
|
||||
LifeState lifeState = LifeUtils.getLifeState(hurtboxParent);
|
||||
int currentHp = lifeState.getLifeCurrent();
|
||||
LifeUtils.getLifeState(hurtboxParent).damage(20);
|
||||
int damage = ItemUtils.getWeaponDataRaw(hitboxParent).getDamage();
|
||||
LifeUtils.getLifeState(hurtboxParent).damage(damage);
|
||||
if(currentHp > lifeState.getLifeCurrent()){
|
||||
Vector3d hurtboxPos = EntityUtils.getPosition(hurtbox);
|
||||
ParticleEffects.spawnBloodsplats(new Vector3f((float)hurtboxPos.x,(float)hurtboxPos.y,(float)hurtboxPos.z).add(0,0.1f,0), 20, 40);
|
||||
@ -139,7 +140,8 @@ public class HitboxUtils {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LifeUtils.getLifeState(hurtboxParent).damage(20);
|
||||
int damage = ItemUtils.getWeaponDataRaw(hitboxParent).getDamage();
|
||||
LifeUtils.getLifeState(hurtboxParent).damage(damage);
|
||||
if(!LifeUtils.getLifeState(hurtboxParent).isIsAlive()){
|
||||
EntityUtils.getPosition(hurtboxParent).set(Globals.spawnPoint);
|
||||
LifeUtils.getLifeState(hurtboxParent).revive();
|
||||
|
||||
@ -8,6 +8,7 @@ public class WeaponData {
|
||||
|
||||
String weaponClass;
|
||||
List<HitboxData> hitboxes;
|
||||
int damage;
|
||||
String projectileModel;
|
||||
|
||||
public String getWeaponClass(){
|
||||
@ -22,4 +23,8 @@ public class WeaponData {
|
||||
return projectileModel;
|
||||
}
|
||||
|
||||
public int getDamage(){
|
||||
return damage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ public class EntityMessage extends NetworkMessage {
|
||||
MOVEUPDATE,
|
||||
ATTACKUPDATE,
|
||||
MOVE,
|
||||
KILL,
|
||||
DESTROY,
|
||||
SETBEHAVIORTREE,
|
||||
SETPROPERTY,
|
||||
@ -240,6 +241,12 @@ public class EntityMessage extends NetworkMessage {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_KILL:
|
||||
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_KILL_SIZE){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_DESTROY:
|
||||
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_DESTROY_SIZE){
|
||||
return true;
|
||||
@ -452,6 +459,20 @@ public class EntityMessage extends NetworkMessage {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static EntityMessage parseKillMessage(List<Byte> byteStream){
|
||||
EntityMessage rVal = new EntityMessage(EntityMessageType.KILL);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static EntityMessage constructKillMessage(int entityID){
|
||||
EntityMessage rVal = new EntityMessage(EntityMessageType.KILL);
|
||||
rVal.setentityID(entityID);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static EntityMessage parseDestroyMessage(List<Byte> byteStream){
|
||||
EntityMessage rVal = new EntityMessage(EntityMessageType.DESTROY);
|
||||
stripPacketHeader(byteStream);
|
||||
@ -764,6 +785,17 @@ public class EntityMessage extends NetworkMessage {
|
||||
rawBytes[30+i] = intValues[i];
|
||||
}
|
||||
break;
|
||||
case KILL:
|
||||
rawBytes = new byte[2+4];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_KILL;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(entityID);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
break;
|
||||
case DESTROY:
|
||||
rawBytes = new byte[2+4];
|
||||
//message header
|
||||
|
||||
@ -67,6 +67,11 @@ AUTH_MESSAGE,
|
||||
rVal = EntityMessage.parseMoveMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_KILL:
|
||||
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = EntityMessage.parseKillMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_DESTROY:
|
||||
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = EntityMessage.parseDestroyMessage(byteStream);
|
||||
|
||||
@ -21,10 +21,11 @@ Message categories
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 3;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE = 4;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 5;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 7;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 8;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 9;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_KILL = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 7;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 8;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 9;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 10;
|
||||
/*
|
||||
Entity packet sizes
|
||||
*/
|
||||
@ -33,6 +34,7 @@ Message categories
|
||||
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_KILL_SIZE = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY_SIZE = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE_SIZE = 22;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY_SIZE = 22;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user