package electrosphere.entity.state.stance; import electrosphere.entity.btree.BehaviorTree; import electrosphere.engine.Globals; import electrosphere.entity.EntityDataStrings; import electrosphere.net.synchronization.server.ServerSynchronizationManager; import electrosphere.net.parser.net.message.SynchronizationMessage; import electrosphere.net.synchronization.enums.BehaviorTreeIdEnums; import electrosphere.entity.Entity; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizableEnum; import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; /** * Tracks the weapon/combat stance of the entity */ @SynchronizedBehaviorTree( name = "clientStanceComponent", isServer = false, correspondingTree = "serverStanceComponent", genStartInt = true ) public class ClientStanceComponent implements BehaviorTree { @SynchronizableEnum public static enum CombatStance { /** * Not in attacking stance */ IDLE, /** * No weapon equipped, in attacking stance */ UNARMED, /** * Weapon equipped, in attacking stance */ ARMED, } @SyncedField CombatStance state = CombatStance.IDLE; /** * The parent entity */ Entity 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 ClientStanceComponent attachTree(Entity parent, Object ... params){ ClientStanceComponent rVal = new ClientStanceComponent(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_CLIENTSTANCECOMPONENT, rVal); Globals.clientSceneWrapper.getScene().registerBehaviorTree(rVal); Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_CLIENTSTANCECOMPONENT_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_CLIENTSTANCECOMPONENT_ID); } /** *

(initially) Automatically generated

*

Private constructor to enforce using the attach methods

*

* Constructor *

* @param parent The parent entity of this tree * @param params Optional parameters that can be provided when attaching the tree. All custom data required for creating this tree should be passed in this varargs. */ public ClientStanceComponent(Entity parent, Object ... params){ this.parent = parent; } /** *

* Gets the ClientStanceComponent of the entity *

* @param entity the entity * @return The ClientStanceComponent */ public static ClientStanceComponent getClientStanceComponent(Entity entity){ return (ClientStanceComponent)entity.getData(EntityDataStrings.TREE_CLIENTSTANCECOMPONENT); } /** *

Automatically generated

*

* Requests that the server start this btree *

*/ public void start(){ Globals.clientConnection.queueOutgoingMessage( SynchronizationMessage.constructClientRequestBTreeActionMessage( Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), BehaviorTreeIdEnums.BTREE_CLIENTSTANCECOMPONENT_ID, ServerSynchronizationManager.SERVER_SYNC_START ) ); } /** *

Automatically generated

*

* Requests that the server start this btree *

*/ public void interrupt(){ Globals.clientConnection.queueOutgoingMessage( SynchronizationMessage.constructClientRequestBTreeActionMessage( Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), BehaviorTreeIdEnums.BTREE_CLIENTSTANCECOMPONENT_ID, ServerSynchronizationManager.SERVER_SYNC_INTERRUPT ) ); } /** *

Automatically generated

*

* Sets state and handles the synchronization logic for it. *

* @param state The value to set state to. */ public void setState(CombatStance state){ this.state = state; } /** *

Automatically generated

*

* Converts a short to the equivalent enum value *

* @param shortVal The short value * @return The enum value */ public static CombatStance getCombatStanceShortAsEnum(short shortVal){ switch(shortVal){ case 0: return CombatStance.IDLE; case 1: return CombatStance.UNARMED; case 2: return CombatStance.ARMED; default: return CombatStance.IDLE; } } /** *

Automatically generated

*

* Converts this enum type to an equivalent short value *

* @param enumVal The enum value * @return The short value */ public static short getCombatStanceEnumAsShort(CombatStance enumVal){ switch(enumVal){ case IDLE: return 0; case UNARMED: return 1; case ARMED: return 2; default: return 0; } } @Override public void simulate(float deltaTime) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'simulate'"); } /** *

Automatically generated

*

* Gets state. *

*/ public CombatStance getState(){ return state; } }