diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index c7c3027f..ca8d7386 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -209,6 +209,8 @@ public class EntityDataStrings { public static final String ITEM_WEAPON_DATA_RAW = "itemWeaponDataRaw"; public static final String ITEM_IS_IN_INVENTORY = "itemIsInInventory"; public static final String ITEM_CONTAINING_PARENT = "itemContainingParent"; + public static final String TREE_SERVERCHARGESTATE = "treeServerChargeState"; + public static final String TREE_CLIENTCHARGESTATE = "treeClientChargeState"; /* diff --git a/src/main/java/electrosphere/entity/state/item/ClientChargeState.java b/src/main/java/electrosphere/entity/state/item/ClientChargeState.java new file mode 100644 index 00000000..badc1af6 --- /dev/null +++ b/src/main/java/electrosphere/entity/state/item/ClientChargeState.java @@ -0,0 +1,117 @@ +package electrosphere.entity.state.item; + + +import electrosphere.entity.Entity; +import electrosphere.entity.btree.BehaviorTree; +import electrosphere.engine.Globals; +import electrosphere.entity.EntityDataStrings; +import electrosphere.net.synchronization.enums.BehaviorTreeIdEnums; +import electrosphere.net.synchronization.annotation.SyncedField; +import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; + + +@SynchronizedBehaviorTree(name = "clientChargeState", isServer = false, correspondingTree="serverChargeState") +/** + * Item charge state + */ +public class ClientChargeState implements BehaviorTree { + + /** + * The charges on the item + */ + @SyncedField + int charges; + + /** + * The parent of this state + */ + Entity parent; + + /** + * Constructor + * @param parent The parent of this state + * @param params The params + */ + private ClientChargeState(Entity parent, Object ... params){ + this.parent = parent; + } + + /** + *

(initially) Automatically generated

+ *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + * @param params Optional parameters that will be provided to the constructor + */ + public static ClientChargeState attachTree(Entity parent, Object ... params){ + ClientChargeState rVal = new ClientChargeState(parent,params); + //!!WARNING!! from here below should not be touched + //This was generated automatically to properly alert various systems that the btree exists and should be tracked + parent.putData(EntityDataStrings.TREE_CLIENTCHARGESTATE, rVal); + Globals.clientSceneWrapper.getScene().registerBehaviorTree(rVal); + Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_CLIENTCHARGESTATE_ID); + return rVal; + } + + /** + *

Automatically generated

+ *

+ * Detatches this tree from the entity. + *

+ * @param entity The entity to detach to + * @param tree The behavior tree to detach + */ + public static void detachTree(Entity entity, BehaviorTree tree){ + Globals.entityValueTrackingService.detatchTreeFromEntity(entity, BehaviorTreeIdEnums.BTREE_CLIENTCHARGESTATE_ID); + } + + /** + *

+ * Gets the ClientChargeState of the entity + *

+ * @param entity the entity + * @return The ClientChargeState + */ + public static ClientChargeState getClientChargeState(Entity entity){ + return (ClientChargeState)entity.getData(EntityDataStrings.TREE_CLIENTCHARGESTATE); + } + + /** + *

+ * Checks if the entity has a ClientChargeState component + *

+ * @param entity the entity + * @return true if the entity contains the component, false otherwise + */ + public static boolean hasClientChargeState(Entity entity){ + return entity.containsKey(EntityDataStrings.TREE_CLIENTCHARGESTATE); + } + + /** + *

Automatically generated

+ *

+ * Sets charges and handles the synchronization logic for it. + *

+ * @param charges The value to set charges to. + */ + public void setCharges(int charges){ + this.charges = charges; + } + + /** + *

Automatically generated

+ *

+ * Gets charges. + *

+ */ + public int getCharges(){ + return charges; + } + + @Override + public void simulate(float deltaTime) { + } + +} diff --git a/src/main/java/electrosphere/entity/state/item/ServerChargeState.java b/src/main/java/electrosphere/entity/state/item/ServerChargeState.java new file mode 100644 index 00000000..31d810ff --- /dev/null +++ b/src/main/java/electrosphere/entity/state/item/ServerChargeState.java @@ -0,0 +1,124 @@ +package electrosphere.entity.state.item; + + +import electrosphere.entity.btree.BehaviorTree; +import electrosphere.engine.Globals; +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.net.synchronization.enums.FieldIdEnums; +import electrosphere.server.datacell.utils.DataCellSearchUtils; +import electrosphere.net.parser.net.message.SynchronizationMessage; +import electrosphere.net.synchronization.enums.BehaviorTreeIdEnums; +import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; +import electrosphere.net.synchronization.annotation.SyncedField; +import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; + + +@SynchronizedBehaviorTree(name = "serverChargeState", isServer = true, correspondingTree="clientChargeState") +/** + * Item charge state + */ +public class ServerChargeState implements BehaviorTree { + + /** + * The charges on the item + */ + @SyncedField + int charges; + + /** + * The parent of this state + */ + Entity parent; + + /** + * Constructor + * @param parent The parent of this state + * @param params The params + */ + private ServerChargeState(Entity parent, Object ... params){ + this.parent = parent; + } + + /** + *

(initially) Automatically generated

+ *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + * @param params Optional parameters that will be provided to the constructor + */ + public static ServerChargeState attachTree(Entity parent, Object ... params){ + ServerChargeState rVal = new ServerChargeState(parent,params); + //!!WARNING!! from here below should not be touched + //This was generated automatically to properly alert various systems that the btree exists and should be tracked + ServerBehaviorTreeUtils.attachBTreeToEntity(parent, rVal); + parent.putData(EntityDataStrings.TREE_SERVERCHARGESTATE, rVal); + Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_SERVERCHARGESTATE_ID); + return rVal; + } + + /** + *

Automatically generated

+ *

+ * Detatches this tree from the entity. + *

+ * @param entity The entity to detach to + * @param tree The behavior tree to detach + */ + public static void detachTree(Entity entity, BehaviorTree tree){ + Globals.entityValueTrackingService.detatchTreeFromEntity(entity, BehaviorTreeIdEnums.BTREE_SERVERCHARGESTATE_ID); + } + + /** + *

+ * Gets the ServerChargeState of the entity + *

+ * @param entity the entity + * @return The ServerChargeState + */ + public static ServerChargeState getServerChargeState(Entity entity){ + return (ServerChargeState)entity.getData(EntityDataStrings.TREE_SERVERCHARGESTATE); + } + + /** + *

+ * Checks if the entity has a ServerChargeState component + *

+ * @param entity the entity + * @return true if the entity contains the component, false otherwise + */ + public static boolean hasServerChargeState(Entity entity){ + return entity.containsKey(EntityDataStrings.TREE_SERVERCHARGESTATE); + } + + /** + *

Automatically generated

+ *

+ * Sets charges and handles the synchronization logic for it. + *

+ * @param charges The value to set charges to. + */ + public void setCharges(int charges){ + this.charges = charges; + if(DataCellSearchUtils.getEntityDataCell(parent) != null){ + DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientIntStateMessage(parent.getId(), BehaviorTreeIdEnums.BTREE_SERVERCHARGESTATE_ID, FieldIdEnums.TREE_SERVERCHARGESTATE_SYNCEDFIELD_CHARGES_ID, charges)); + } + } + + /** + *

Automatically generated

+ *

+ * Gets charges. + *

+ */ + public int getCharges(){ + return charges; + } + + @Override + public void simulate(float deltaTime) { + } + +} diff --git a/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java b/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java index 37af878c..136c7a8b 100644 --- a/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java +++ b/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java @@ -1,7 +1,7 @@ package electrosphere.net.synchronization.client; -import electrosphere.util.Utilities; +import electrosphere.entity.state.item.ClientChargeState; import electrosphere.entity.state.movement.editor.ClientEditorMovementTree; import electrosphere.entity.state.equip.ClientToolbarState; import electrosphere.entity.state.stance.ClientStanceComponent; @@ -213,6 +213,14 @@ public class ClientSynchronizationManager { } break; } } break; + case BehaviorTreeIdEnums.BTREE_SERVERCHARGESTATE_ID: { + switch(message.getfieldId()){ + case FieldIdEnums.TREE_SERVERCHARGESTATE_SYNCEDFIELD_CHARGES_ID:{ + ClientChargeState tree = ClientChargeState.getClientChargeState(entity); + tree.setCharges(message.getintValue()); + } break; + } + } break; case BehaviorTreeIdEnums.BTREE_SERVERLIFETREE_ID: { switch(message.getfieldId()){ case FieldIdEnums.TREE_SERVERLIFETREE_SYNCEDFIELD_STATE_ID:{ diff --git a/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java b/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java index cf081b92..277ac8b1 100644 --- a/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java +++ b/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java @@ -17,6 +17,8 @@ public class BehaviorTreeIdEnums { public static final int BTREE_SERVERGRAVITY_ID = 7; public static final int BTREE_IDLE_ID = 8; public static final int BTREE_SERVERIDLE_ID = 9; + public static final int BTREE_CLIENTCHARGESTATE_ID = 26; + public static final int BTREE_SERVERCHARGESTATE_ID = 27; public static final int BTREE_CLIENTLIFETREE_ID = 6; public static final int BTREE_SERVERLIFETREE_ID = 13; public static final int BTREE_CLIENTSTANCECOMPONENT_ID = 20; diff --git a/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java b/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java index 13986e02..c852d500 100644 --- a/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java +++ b/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java @@ -21,6 +21,8 @@ public class FieldIdEnums { public static final int TREE_SERVERGRAVITY_SYNCEDFIELD_STATE_ID = 11; public static final int TREE_IDLE_SYNCEDFIELD_STATE_ID = 12; public static final int TREE_SERVERIDLE_SYNCEDFIELD_STATE_ID = 13; + public static final int TREE_CLIENTCHARGESTATE_SYNCEDFIELD_CHARGES_ID = 34; + public static final int TREE_SERVERCHARGESTATE_SYNCEDFIELD_CHARGES_ID = 35; public static final int TREE_CLIENTLIFETREE_SYNCEDFIELD_STATE_ID = 10; public static final int TREE_SERVERLIFETREE_SYNCEDFIELD_STATE_ID = 17; public static final int TREE_CLIENTSTANCECOMPONENT_SYNCEDFIELD_STATE_ID = 28; diff --git a/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java b/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java index 95d5c957..1d060b6b 100644 --- a/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java +++ b/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java @@ -1,7 +1,8 @@ package electrosphere.net.synchronization.transport; -import electrosphere.util.Utilities; +import electrosphere.entity.state.item.ServerChargeState; +import electrosphere.entity.state.item.ClientChargeState; import electrosphere.entity.state.movement.editor.ServerEditorMovementTree; import electrosphere.entity.state.movement.editor.ClientEditorMovementTree; import electrosphere.entity.state.equip.ServerToolbarState; @@ -96,6 +97,10 @@ public class StateCollection { ServerIdleTree tree = ServerIdleTree.getServerIdleTree(entity); collection.setValue(new SynchronizedFieldValue(BehaviorTreeIdEnums.BTREE_SERVERIDLE_ID,FieldIdEnums.TREE_SERVERIDLE_SYNCEDFIELD_STATE_ID,ClientIdleTree.getIdleTreeStateEnumAsShort(tree.getState()))); } break; + case BehaviorTreeIdEnums.BTREE_SERVERCHARGESTATE_ID: { + ServerChargeState tree = ServerChargeState.getServerChargeState(entity); + collection.setValue(new SynchronizedFieldValue(BehaviorTreeIdEnums.BTREE_SERVERCHARGESTATE_ID,FieldIdEnums.TREE_SERVERCHARGESTATE_SYNCEDFIELD_CHARGES_ID,tree.getCharges())); + } break; case BehaviorTreeIdEnums.BTREE_SERVERLIFETREE_ID: { ServerLifeTree tree = ServerLifeTree.getServerLifeTree(entity); collection.setValue(new SynchronizedFieldValue(BehaviorTreeIdEnums.BTREE_SERVERLIFETREE_ID,FieldIdEnums.TREE_SERVERLIFETREE_SYNCEDFIELD_STATE_ID,ClientLifeTree.getLifeStateEnumEnumAsShort(tree.getState()))); @@ -192,6 +197,14 @@ public class StateCollection { } break; } } break; + case BehaviorTreeIdEnums.BTREE_SERVERCHARGESTATE_ID: { + ClientChargeState tree = ClientChargeState.getClientChargeState(entity); + switch(syncedValue.getFieldId()){ + case(FieldIdEnums.TREE_SERVERCHARGESTATE_SYNCEDFIELD_CHARGES_ID): { + tree.setCharges(((Double)syncedValue.getValue()).intValue()); + } break; + } + } break; case BehaviorTreeIdEnums.BTREE_SERVERLIFETREE_ID: { ClientLifeTree tree = ClientLifeTree.getClientLifeTree(entity); switch(syncedValue.getFieldId()){