Example #1
0
  /** Starts up the attack. */
  public void startAttack() {
    // Nobody has attacked yet. The attacker goes first
    if (attackPhase == 0) {
      attackPhase = 1;
      attackerTurn = true;
      numAttacks = attacker.numAttacks();
      controlState = 3;
    }

    // Now it's the defender's turn
    else if (attackPhase == 1) {
      attackPhase = 2;
      attackerTurn = false;
      defenderTurn = true;
      numAttacks = defender.numAttacks();
      controlState = 3;
    }

    // Now the speed round
    else if (attackPhase == 2) {
      attackPhase = 3;
      attackerTurn = false;
      defenderTurn = false;

      int speedDef = attacker.getTotalSpd() - defender.getTotalSpd();

      // the attacker is fast enough. FIGHT
      if (speedDef >= 4) {
        attackerTurn = true;
        numAttacks = attacker.numAttacks();
        controlState = 3;
      }

      // the defender is fast enough. FIGHT
      else if (speedDef <= -4) {
        defenderTurn = true;
        numAttacks = defender.numAttacks();
        controlState = 3;
      }

      // they were the same-ish speed. No more fighting.
      else controlState = 1;
    }

    // We can't get to attack phase 4
    else controlState = 1;
  }
Example #2
0
  /**
   * Gets the chance a unit can hit its target
   *
   * @param a The attacking Unit
   * @param b The defending Unit
   * @param m The map it takes place on.
   * @return The hit chance.
   */
  public static int hitChance(Unit a, Unit b, Map m) {
    // Determine Hit Rate, Evasion, and Weapon Advantage.
    int hitRate = a.getTotalSkill() * 2 + a.getTotalLuck() + a.getEquppedWeapon().getHit();
    int evade =
        b.getTotalSpd() * 2 + b.getTotalLuck() + m.getTerrainAtPoint(b.getCoord()).getEvade();
    int weaponAdvantage = weaponAdvantageAccuracy(a.getEquppedWeapon(), b.getEquppedWeapon());

    return (hitRate + weaponAdvantage - evade);
  }