Example #1
0
  protected void randomRotate(Unit U) {
    // random rotate while exploring

    didsomething = true;
    rando = (int) (Math.random() * 2);
    if (rando == 0) U.rotateLeft();
    else U.rotateRight();

    U.usePoints(U.getRotationCost());
  }
Example #2
0
  protected void useMovement(Unit U) {
    // if movement forward is possible, move forward 1 square
    // otherwise, rotate left or right

    movementPoints = Movement.getMovement(map, U);

    if (movementPoints[1].length == 0) {
      randomRotate(U);
    } else {
      U.setXYCoordinate(movementPoints[1][0], map);
      U.usePoints(U.getMovementCost());
    }
  }
Example #3
0
  protected void useAbility(Unit U, Ability A, GPoint T) {
    // uses the selected ability on the selected target
    // code copied from player class

    // decrement action points
    U.usePoints(A.getCost());

    // get the tiles that were affected by the attack
    List<AttackedTile> tilesAffected = A.getTilesAffected(U, T, map);

    for (int j = 0; j < tilesAffected.size(); j++) {
      MapTile tile = map.getTile(tilesAffected.get(j).tile);

      if (tile.hasUnit()) { // there is a unit on the tile
        int unitId = tile.getUnit_id();
        Unit unit = map.getUnit(unitId);

        // reduce unit health by attack dmg
        if (unit != null) {
          DamageDealt damageDone = unit.takeDamage(tilesAffected.get(j).damageTaken, map);
          healthIndicators.add(
              new HealthIndicator(
                  map,
                  new GPoint(tilesAffected.get(j).tile.row, tilesAffected.get(j).tile.col),
                  30,
                  damageDone.healthDamage,
                  indicatorPaint,
                  false));
          if (damageDone.isAttack && damageDone.armorDamage < 0) {
            healthIndicators.add(
                new HealthIndicator(
                    map,
                    new GPoint(tilesAffected.get(j).tile.row, tilesAffected.get(j).tile.col),
                    0,
                    damageDone.armorDamage,
                    indicatorPaint,
                    true));
          }
          if (U != unit && damageDone.isAttack) // don't send indicator for heals
          map.sendHitIndicator(new HitIndicator(U, A, unit, tilesAffected.get(j).tile, map), unit);
        }
      }
    }
  }
Example #4
0
  protected void reconAction(Unit U, int I) {
    // recon tries trick shot and then runs away, or does normal attack, or basic movement

    didsomething = false;

    if (U.pointsLeft >= U.abilities[1].getCost()) {
      defaultAction(U, U.abilities[1], I);

      if (U.pointsLeft > 0) {
        rando = (int) (Math.random() * 2);
        if (rando == 0) U.rotateLeft();
        else U.rotateRight();
      }
    }

    if (!didsomething) {
      if (U.pointsLeft >= U.abilities[0].getCost()) defaultAction(U, U.abilities[0], I);
    }

    if (!didsomething) useMovement(U);
  }
Example #5
0
  protected void strategize(Unit U) {
    // cheat peek. 1/30 chance to look left and right to see if there are any enemies there
    // without spending points. Then rotate using points if enemies found
    // helps prevent the npc from just walking straight across the map
    // seaching simulator

    rando = (int) (Math.random() * 30);
    if (rando == 0) {
      U.rotateLeft();
      target = findTarget(U.abilities[0], U);
      if (target != null) U.usePoints(U.getRotationCost());
      else {
        U.rotateRight();
        U.rotateRight();
        target = findTarget(U.abilities[0], U);
        if (target != null) U.usePoints(U.getRotationCost());
        else U.rotateLeft();
      }
    }
  }
Example #6
0
  protected void rotateToHits(Unit U, HitIndicator I) {
    // rotate unit to face indicator direction

    // 0 up, 1 right, 2 down, 3 left

    while (!(U.getDirectionFacing() == I.getDirection())) {
      if (U.getDirectionFacing() == 0) {
        if (I.getDirection() == 3) U.rotateLeft();
        else U.rotateRight();
      } else if (U.getDirectionFacing() == 1) {
        if (I.getDirection() == 0) U.rotateLeft();
        else U.rotateRight();
      } else if (U.getDirectionFacing() == 2) {
        if (I.getDirection() == 1) U.rotateLeft();
        else U.rotateRight();
      } else if (U.getDirectionFacing() == 3) {
        if (I.getDirection() == 2) U.rotateLeft();
        else U.rotateRight();
      } else return; // error

      U.usePoints(U.getRotationCost());
    }
  }