SHARE
TWEET

Untitled

a guest Aug 12th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.apollo.game.model.combat;
  2.  
  3. import org.apollo.game.action.Action;
  4. import org.apollo.game.model.Animation;
  5. import org.apollo.game.model.Character;
  6. import org.apollo.game.model.Position;
  7.  
  8. /**
  9.  * Represents a character attacking another character.
  10.  * @author Michael Bull (Scu11)
  11.  *
  12.  */
  13. public class CombatAction extends Action<Character> {
  14.    
  15.     /**
  16.      * Combat action constant.
  17.      */
  18.     public static final CombatAction COMBAT_ACTION = new CombatAction(null, null, false);
  19.    
  20.     /**
  21.      * The opponent this character is attacking.
  22.      */
  23.     private final Character opponent;
  24.  
  25.     /**
  26.      * Default constructor.
  27.      * @param character The character who is attacking.
  28.      * @param opponent The character being attacked.
  29.      * @param retaliating The auto retaliate flag.
  30.      */
  31.     public CombatAction(Character character, Character opponent, boolean retaliating) {
  32.         super(retaliating ? 4 : 0, true, true, character);
  33.         this.opponent = opponent;
  34.     }
  35.  
  36.     /**
  37.      * Gets the opponent this character is attacking.
  38.      * @return The opponent this character is attacking.
  39.      */
  40.     public Character getOpponent() {
  41.         return opponent;
  42.     }
  43.  
  44.     @Override
  45.     public void execute() {
  46.         if (getCharacter() == null || getOpponent() == null) {
  47.             stop();
  48.         }
  49.        
  50.         setDelay(getCharacter().getCombatState().getCombatDelay() - 1); // we take 1 pusle off as all actions require at least one pulse
  51.         getCharacter().setInteractingCharacter(getOpponent());
  52.         getCharacter().playAnimation(new Animation(getCharacter().getCombatState().getAttackAnimation()));
  53.         getOpponent().playAnimation(new Animation(getOpponent().getCombatState().getDefendAnimation()));
  54.        
  55.         if(getOpponent().getCombatState().isAutoRetaliating()) {
  56.             if (getOpponent().getAction() == null ||
  57.                     (getOpponent().getAction().isCancellable() &&
  58.                             (!getOpponent().actionEquals(COMBAT_ACTION) ||
  59.                                     ((CombatAction) getOpponent().getAction()).getOpponent() != getCharacter()))) {
  60.                 getOpponent().startAction(new CombatAction(getOpponent(), getCharacter(), true));
  61.                 getOpponent().setInteractingCharacter(getCharacter());
  62.             }
  63.         }
  64.        
  65.     }
  66.  
  67.     @Override
  68.     public boolean equals(Object obj) {
  69.         if (this == obj) {
  70.             return true;
  71.         }
  72.         if (obj == null) {
  73.             return false;
  74.         }
  75.         if (getClass() != obj.getClass()) {
  76.             return false;
  77.         }
  78.         CombatAction other = (CombatAction) obj;
  79.         if (other.getOpponent() != this.opponent) {
  80.             return false;
  81.         }
  82.         return true;
  83.     }
  84.  
  85. }
RAW Paste Data
Top