Package org.timerescue.element.agent

Examples of org.timerescue.element.agent.StateHolder


  @Override
  protected InformationParameters executeAgent() {
    Agent target = null, attacker = null;
    int range = 0, target_life, attacker_attack, target_defense, speed;
    PropertyHolder target_property_holder, attacker_property_holder;
    StateHolder target_state_holder, attacker_state_holder;
   
    //Get target and the attacker
    target = getTarget();
    attacker = getAttacker();
    //states holders
    target_state_holder = target.getState_holder();
    attacker_state_holder = attacker.getState_holder();
    //Range
    range = getRange();
    Coordinate target_position = target.getCoordinate(),
        attacker_position = attacker.getCoordinate();
    //Properties
    target_property_holder = target.getProperty_holder();
    attacker_property_holder = attacker.getProperty_holder();
    //TODO Is the target visible?
    int visibility = attacker.getVisibility();
    if(target_position.isClose(attacker_position, visibility)){
      //If the target is close enough for a close range attack
      if (target_position.isClose(attacker_position, range)){
        //Attack the target properties!     
        target_life = target.getLife();     
        if(target_life > 0) {//is it alive?         
          //TODO define a method to obtain the properties casted
          //TODO Define a practical formulas, this is just for testing
          target_defense = target.getArmor();
          attacker_attack = attacker.getStrength()* 2;
          target_life -= attacker_attack - target_defense;
          target.setLife(target_life);
          //Add states       
          target_state_holder.addState(this);
          attacker_state_holder.addState(this);
          return this;
        }else{
          //Remove states if the target is dead
          removeStates();
View Full Code Here


  }
 
  @Override
  public boolean removeStates() {
    Agent target = null, attacker = null;
    StateHolder target_state_holder, attacker_state_holder;
    try {
      target = getTarget();
      attacker = getAttacker();
      target_state_holder = target.getState_holder();
      attacker_state_holder = attacker.getState_holder();
      target_state_holder.removeState(this);
      attacker_state_holder.removeState(this);
    } catch (Exception e) {
      // TODO Log this
      return false;
    }
View Full Code Here

  /**
   * @throws java.lang.Exception
   */
  @Before
  public void setUp() throws Exception {
    holder = new StateHolder();
    ///While fighting
    //holder.addState();
  }
View Full Code Here

TOP

Related Classes of org.timerescue.element.agent.StateHolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.