Esempio n. 1
0
 /** Removes the origin fighter if he has fled. */
 private void checkFlee() {
   if (lastAction instanceof yuuki.action.Flee) {
     if (lastAction.wasSuccessful()) {
       fled = true;
       removeFighter(lastAction.getOrigin());
     }
   }
 }
Esempio n. 2
0
 /** Removes the targeted fighter's team if there is no longer anyone on it. */
 private void checkTeamStatus() {
   int[] affectedTeams = lastAction.getAffectedTeams();
   for (int t : affectedTeams) {
     if (fighters.get(t).size() == 0) {
       removeTeam(t);
     }
   }
 }
Esempio n. 3
0
 /** Removes the targeted fighter if he is now dead. */
 private void checkDeath() {
   List<Character> targets = lastAction.getTargets();
   for (Character c : targets) {
     if (!c.isAlive()) {
       removeFighter(c);
     }
   }
 }
Esempio n. 4
0
  /**
   * Advances battle through the current execution state. Each state consists of only a few
   * operations that are carried out before the next state is reached. In between execution states
   * the user is free to query this Battle for information about the fight.
   *
   * @return True if more calls to advance() are required before the battle is over; otherwise,
   *     false.
   */
  public boolean advance() {
    boolean moreCallsNeeded = true;
    switch (state) {
      case STARTING_TURN:
        getCurrentFighter().removeExpiredBuffs();
        regenerateMana();
        switchState(State.GETTING_ACTION);
        break;

      case GETTING_ACTION:
        getCurrentFighter().emptyExpiredBuffs();
        lastAction = getCurrentFighter().getNextAction(fighters);
        if (lastAction != null) {
          // shouldn't happen unless thread is interrupted
          switchState(State.APPLYING_ACTION);
        }
        break;

      case APPLYING_ACTION:
        lastAction.apply();
        switchState(State.APPLYING_BUFFS);
        break;

      case APPLYING_BUFFS:
        checkFlee();
        if (!fled) {
          getCurrentFighter().applyBuffs();
        }
        switchState(State.CHECKING_DEATH);
        break;

      case CHECKING_DEATH:
        checkDeath();
        switchState(State.ENDING_TURN);
        break;

      case ENDING_TURN:
        emptyRemovedFighters();
        checkTeamStatus();
        switchState(State.CHECKING_VICTORY);
        break;

      case CHECKING_VICTORY:
        if (battleIsOver()) {
          switchState(State.LOOTING);
        } else {
          setNextPlayer();
          switchState(State.STARTING_TURN);
        }
        break;

      case LOOTING:
        calculateLoot();
        switchState(State.ENDING);
        break;

      case ENDING:
        moreCallsNeeded = false;
        break;
    }
    return moreCallsNeeded;
  }