示例#1
0
  /**
   * Issue the specific mission changes once task is completed.
   *
   * @param traderSurvived did the trader survive?
   * @param task the current task id
   */
  void completeTaskN(boolean traderSurvived, int task) {
    if (!traderSurvived) {
      addTimeout("Mission-2-Task-" + task + "-Failed", 3000);
      clearMission("Mission-2-Task-" + task + "-Timeout");
    } else {
      addTimeout("Mission-2-Task-" + task + "-Success", 3000);
      clearMission("Mission-2-Task-" + task + "-Timeout");
    }

    Fleet tf = findTaggedFleet(MISSION_2_TRADER, player("Traders"));
    if (tf != null) {
      removeScripted(tf);
      for (InventoryItem ii : tf.inventory.iterable()) {
        ii.tag = null;
      }
      tf.task = FleetTask.IDLE;
      tf.moveTo(ModelUtils.random(planet("Achilles"), planet("Naxos"), planet("San Sterling")));
    }
    Fleet pf = findTaggedFleet(MISSION_2_PIRATE, player("Pirates"));
    if (pf != null) {
      removeScripted(pf);
      world.removeFleet(pf);
    }

    cleanupScriptedFleets();
    missionAttack = false;
  }
示例#2
0
  /** Check the starting conditions for mission 2 tasks. */
  void checkMission2Tasks() {
    Objective m2 = objective("Mission-2");
    if (!m2.visible) {
      return;
    }
    if (m2.isActive()) {
      scheduleTasks();
      for (int i = 1; i <= 3; i++) {
        String m2tio = String.format("Mission-2-Task-%d-Timeout", i);
        String m2ti = String.format("Mission-2-Task-%d", i);
        if (checkMission(m2tio)) {
          setObjectiveState(m2ti, ObjectiveState.FAILURE);
          cleanupShips();
        }
        if (checkMission(m2ti)) {
          List<Fleet> fs = findVisibleFleets(player, false, player("Traders"), 8);
          fs =
              filterByRange(
                  fs,
                  world.params().groundRadarUnitSize() - 2,
                  "Naxos",
                  "San Sterling",
                  "Achilles");
          if (!fs.isEmpty()) {
            Fleet f = ModelUtils.random(fs);

            int fidx = ((AITrader) f.owner.ai).fleetIndex(f);

            traderMessage = 1 + fidx % 7;

            incomingMessage("Merchant-Under-Attack-" + traderMessage, m2ti);

            world.env.speed1();
            f.stop();
            f.task = FleetTask.SCRIPT;

            // create simple pirate fleet
            Fleet pf =
                createFleet(label("pirates.fleet_name"), player("Pirates"), f.x + 1, f.y + 1);

            if (i == 1) {
              addInventory(pf, "PirateFighter", 2);
            } else if (i == 2) {
              addInventory(pf, "PirateFighter", 3);
            } else {
              switch (world.difficulty) {
                case NORMAL:
                  addInventory(pf, "PirateFighter", 1);
                  break;
                case HARD:
                  addInventory(pf, "PirateFighter", 3);
                  break;
                default:
              }
              addInventory(pf, "PirateDestroyer", 1);
            }

            tagFleet(pf, MISSION_2_PIRATE);
            tagFleet(f, MISSION_2_TRADER);

            addScripted(f);
            addScripted(pf);

            // set failure timeout
            addMission(m2tio, 48);
          } else {
            addMission(m2ti, 0);
          }
        }
      }
      int done = 0;
      int success = 0;
      for (int i = 1; i <= 3; i++) {
        String m2ti = String.format("Mission-2-Task-%d", i);
        Objective o = objective(m2ti);
        if (o.state != ObjectiveState.ACTIVE) {
          done++;
          if (o.state == ObjectiveState.SUCCESS) {
            success++;
          }
        }
      }
      if (done == 3) {
        if (success == 0) {
          setObjectiveState("Mission-2", ObjectiveState.FAILURE);
          addTimeout("Mission-2-Failed", 13000);
        } else if (success == 3) {
          setObjectiveState("Mission-2", ObjectiveState.SUCCESS);
          addTimeout("Mission-2-Success", 13000);
        } else {
          setObjectiveState("Mission-2", ObjectiveState.SUCCESS);
          addTimeout("Mission-2-Success-But", 13000);
          incomingMessage("Douglas-Pirates");
        }
      }
      for (int i = 1; i <= 3; i++) {
        if (checkTimeout("Mission-2-Task-" + i + "-Failed")) {
          setObjectiveState("Mission-2-Task-" + i, ObjectiveState.FAILURE);
        } else if (checkTimeout("Mission-2-Task-" + i + "-Success")) {
          setObjectiveState("Mission-2-Task-" + i, ObjectiveState.SUCCESS);

          // Reward
          int m = moneyReward[i];
          player.addMoney(m);
          player.statistics.moneyIncome.value += m;
          world.statistics.moneyIncome.value += m;
        }
      }
    }

    if (checkTimeout("Mission-2-Failed")) {
      objective("Mission-2").visible = false;
      loseGameMessageAndMovie("Douglas-Fire-Lost-Merchants", "lose/fired_level_1");
    } else if (checkTimeout("Mission-2-Success")) {
      objective("Mission-2").visible = false;
    } else if (checkTimeout("Mission-2-Success-But")) {
      objective("Mission-2").visible = false;
    }
  }