public void givetech_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);

    if (args.length < 3) {
      throw new CivException(CivSettings.localize.localizedString("adcmd_civ_giveTechPrompt"));
    }

    ConfigTech tech = CivSettings.techs.get(args[2]);
    if (tech == null) {
      throw new CivException(
          CivSettings.localize.localizedString("adcmd_civ_giveTechInvalid") + args[2]);
    }

    if (civ.hasTechnology(tech.id)) {
      throw new CivException(
          CivSettings.localize.localizedString(
              "var_adcmd_civ_giveTechAlreadyhas", civ.getName(), tech.id));
    }

    civ.addTech(tech);
    civ.save();

    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString(
            "var_adcmd_civ_giveTechSuccess", tech.name, civ.getName()));
  }
  public void setgov_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);

    if (args.length < 3) {
      throw new CivException(CivSettings.localize.localizedString("adcmd_civ_setgovPrompt"));
    }

    ConfigGovernment gov = CivSettings.governments.get(args[2]);
    if (gov == null) {
      throw new CivException(
          CivSettings.localize.localizedString("adcmd_civ_setGovInvalidGov")
              + " gov_monarchy, gov_depostism... etc");
    }
    // Remove any anarchy timers
    String key = "changegov_" + civ.getId();
    CivGlobal.getSessionDB().delete_all(key);

    civ.setGovernment(gov.id);
    CivMessage.global(
        CivSettings.localize.localizedString(
            "var_adcmd_civ_setGovSuccessBroadcast",
            civ.getName(),
            CivSettings.governments.get(gov.id).displayName));
    CivMessage.sendSuccess(sender, CivSettings.localize.localizedString("adcmd_civ_setGovSuccess"));
  }
  public void bankrupt_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);

    if (args.length < 3) {
      CivMessage.send(
          sender,
          CivColor.Yellow
              + ChatColor.BOLD
              + CivSettings.localize.localizedString("adcmd_civ_bankruptConfirmPrompt"));
      CivMessage.send(sender, CivSettings.localize.localizedString("adcmd_civ_bankruptConfirmCmd"));
    }

    civ.getTreasury().setBalance(0);

    for (Town town : civ.getTowns()) {
      town.getTreasury().setBalance(0);
      town.save();

      for (Resident resident : town.getResidents()) {
        resident.getTreasury().setBalance(0);
        resident.save();
      }
    }

    civ.save();
    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString("var_adcmd_civ_bankruptSuccess", civ.getName()));
  }
 public void setvotes_cmd() throws CivException {
   Civilization civ = getNamedCiv(1);
   Integer votes = getNamedInteger(2);
   EndConditionDiplomacy.setVotes(civ, votes);
   CivMessage.sendSuccess(
       sender,
       CivSettings.localize.localizedString(
           "var_adcmd_civ_setVotesSuccess", civ.getName(), votes));
 }
  public void conquered_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);
    civ.setConquered(true);
    CivGlobal.removeCiv(civ);
    CivGlobal.addConqueredCiv(civ);
    civ.save();

    CivMessage.sendSuccess(
        sender, CivSettings.localize.localizedString("adcmd_civ_conqueredSuccess"));
  }
  public void toggleadminciv_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);

    civ.setAdminCiv(!civ.isAdminCiv());
    civ.save();
    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString(
            "var_adcmd_civ_toggleAdminCivSuccess", civ.getName(), civ.isAdminCiv()));
  }
  public void beakerrate_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);
    Double amount = getNamedDouble(2);

    civ.setBaseBeakers(amount);
    civ.save();

    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString(
            "var_adcmd_civ_beakerRateSuccess", civ.getName(), amount));
  }
  public void disband_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);

    CivMessage.sendCiv(civ, CivSettings.localize.localizedString("adcmd_civ_disbandAlert"));
    try {
      civ.delete();
    } catch (SQLException e) {
      e.printStackTrace();
    }

    CivMessage.sendSuccess(
        sender, CivSettings.localize.localizedString("adcmd_civ_disbandSuccess"));
  }
  public void addleader_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);
    Resident resident = getNamedResident(2);

    civ.getLeaderGroup().addMember(resident);
    civ.getLeaderGroup().save();
    civ.save();

    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString(
            "var_adcmd_civ_addLeaderSuccess", resident.getName(), civ.getName()));
  }
  public void alltech_cmd() throws CivException {

    Civilization civ = getNamedCiv(1);

    for (ConfigTech tech : CivSettings.techs.values()) {
      civ.addTech(tech);
    }

    civ.save();

    CivMessage.sendSuccess(
        sender, CivSettings.localize.localizedString("adcmd_civ_alltechSuccess"));
  }
  public void rename_cmd() throws CivException, InvalidNameException {
    Civilization civ = getNamedCiv(1);
    String name =
        getNamedString(2, CivSettings.localize.localizedString("adcmd_civ_newNamePrompt"));

    if (args.length < 3) {
      throw new CivException(
          CivSettings.localize.localizedString("adcmd_civ_renameUseUnderscores"));
    }

    civ.rename(name);
    CivMessage.sendSuccess(
        sender, CivSettings.localize.localizedString("adcmd_civ_renameCivSuccess"));
  }
Пример #12
0
  private static void performPirate(Player player, ConfigMission mission) throws CivException {
    Resident resident = CivGlobal.getResident(player);
    if (resident == null || !resident.hasTown()) {
      throw new CivException("Only residents of towns can perform spy missions.");
    }
    // Must be within enemy town borders.
    ChunkCoord coord = new ChunkCoord(player.getLocation());
    CultureChunk cc = CivGlobal.getCultureChunk(coord);
    if (cc == null || cc.getCiv() == resident.getTown().getCiv()) {
      throw new CivException("Must be in another civilization's borders.");
    }

    // Check that the player is within range of the town hall.
    Structure tradeoutpost = cc.getCiv().getNearestStructureInTowns(player.getLocation());
    if (!(tradeoutpost instanceof TradeOutpost)) {
      throw new CivException("The closest structure to you must be a trade outpost.");
    }

    double distance =
        player
            .getLocation()
            .distance(((TradeOutpost) tradeoutpost).getTradeOutpostTower().getLocation());
    if (distance > mission.range) {
      throw new CivException("Too far away from the trade outpost to pirate it.");
    }

    TradeOutpost outpost = (TradeOutpost) tradeoutpost;
    ItemStack stack = outpost.getItemFrameStore().getItem();

    if (stack == null || ItemManager.getId(stack) == CivData.AIR) {
      throw new CivException("No trade goodie item at this location.");
    }

    if (processMissionResult(player, cc.getTown(), mission)) {
      outpost.getItemFrameStore().clearItem();
      player.getWorld().dropItem(player.getLocation(), stack);

      CivMessage.sendSuccess(player, "Arg! Got the booty!");
      CivMessage.sendTown(
          cc.getTown(),
          CivColor.Rose
              + "Avast! Someone stole our trade goodie "
              + outpost.getGood().getInfo().name
              + " at "
              + outpost.getCorner());
    }
  }
Пример #13
0
  private static void performStealTreasury(Player player, ConfigMission mission)
      throws CivException {

    Resident resident = CivGlobal.getResident(player);
    if (resident == null || !resident.hasTown()) {
      throw new CivException("Only residents of towns can perform spy missions.");
    }

    // Must be within enemy town borders.
    ChunkCoord coord = new ChunkCoord(player.getLocation());
    TownChunk tc = CivGlobal.getTownChunk(coord);

    if (tc == null || tc.getTown().getCiv() == resident.getTown().getCiv()) {
      throw new CivException("Must be in another civilization's town's borders.");
    }

    // Check that the player is within range of the town hall.
    TownHall townhall = tc.getTown().getTownHall();
    if (townhall == null) {
      throw new CivException("This town doesnt have a town hall... that sucks.");
    }

    double distance = player.getLocation().distance(townhall.getCorner().getLocation());
    if (distance > mission.range) {
      throw new CivException("Too far away from town hall to steal treasury.");
    }

    double failMod = 1.0;
    if (resident.getTown().getBuffManager().hasBuff("buff_dirty_money")) {
      failMod = resident.getTown().getBuffManager().getEffectiveDouble("buff_dirty_money");
      CivMessage.send(
          player, CivColor.LightGray + "Your goodie buff 'Dirty Money' will come in handy here.");
    }

    if (processMissionResult(player, tc.getTown(), mission, failMod, 1.0)) {

      double amount = (int) (tc.getTown().getTreasury().getBalance() * 0.2);
      if (amount > 0) {
        tc.getTown().getTreasury().withdraw(amount);
        resident.getTown().getTreasury().deposit(amount);
      }

      CivMessage.sendSuccess(
          player, "Success! Stole " + amount + " coins from " + tc.getTown().getName());
    }
  }
  public void rmleader_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);
    Resident resident = getNamedResident(2);

    if (civ.getLeaderGroup().hasMember(resident)) {
      civ.getLeaderGroup().removeMember(resident);
      civ.save();
      CivMessage.sendSuccess(
          sender,
          CivSettings.localize.localizedString(
              "var_adcmd_civ_rmLeaderSuccess", resident.getName(), civ.getName()));
    } else {
      CivMessage.sendError(
          sender,
          CivSettings.localize.localizedString(
              "var_adcmd_civ_rmLeaderNotInGroup", resident.getName(), civ.getName()));
    }
  }
  public void unconquer_cmd() throws CivException {
    String conquerCiv = this.getNamedString(1, "conquered civ");

    Civilization civ = CivGlobal.getConqueredCiv(conquerCiv);
    if (civ == null) {
      civ = CivGlobal.getCiv(conquerCiv);
    }

    if (civ == null) {
      throw new CivException(
          CivSettings.localize.localizedString("var_adcmd_civ_NoCivByThatNane", conquerCiv));
    }

    civ.setConquered(false);
    CivGlobal.removeConqueredCiv(civ);
    CivGlobal.addCiv(civ);
    civ.save();

    CivMessage.sendSuccess(
        sender, CivSettings.localize.localizedString("adcmd_civ_unconquerSuccess"));
  }
  public void setrelation_cmd() throws CivException {
    if (args.length < 4) {
      throw new CivException(
          CivSettings.localize.localizedString("Usage")
              + " [civ] [otherCiv] [NEUTRAL|HOSTILE|WAR|PEACE|ALLY]");
    }

    Civilization civ = getNamedCiv(1);
    Civilization otherCiv = getNamedCiv(2);

    Relation.Status status = Relation.Status.valueOf(args[3].toUpperCase());

    CivGlobal.setRelation(civ, otherCiv, status);
    if (status.equals(Status.WAR)) {
      CivGlobal.setAggressor(civ, otherCiv, civ);
      CivGlobal.setAggressor(otherCiv, civ, civ);
    }
    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString(
            "var_adcmd_civ_setrelationSuccess", civ.getName(), otherCiv.getName(), status.name()));
  }
  public void liberate_cmd() throws CivException {
    Civilization motherCiv = getNamedCiv(1);

    /* Liberate the civ. */
    for (Town t : CivGlobal.getTowns()) {
      if (t.getMotherCiv() == motherCiv) {
        t.changeCiv(motherCiv);
        t.setMotherCiv(null);
        t.save();
      }
    }

    motherCiv.setConquered(false);
    CivGlobal.removeConqueredCiv(motherCiv);
    CivGlobal.addCiv(motherCiv);
    motherCiv.save();
    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString("adcmd_civ_liberateSuccess")
            + " "
            + motherCiv.getName());
  }
Пример #18
0
  @SuppressWarnings("deprecation")
  private static void performInvestigateTown(Player player, ConfigMission mission)
      throws CivException {

    Resident resident = CivGlobal.getResident(player);
    if (resident == null || !resident.hasTown()) {
      throw new CivException("Only residents of towns can perform spy missions.");
    }

    // Must be within enemy town borders.
    ChunkCoord coord = new ChunkCoord(player.getLocation());
    TownChunk tc = CivGlobal.getTownChunk(coord);

    if (tc == null || tc.getTown().getCiv() == resident.getTown().getCiv()) {
      throw new CivException("Must be in another civilization's town's borders.");
    }

    if (processMissionResult(player, tc.getTown(), mission)) {
      ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1);
      BookMeta meta = (BookMeta) book.getItemMeta();
      ArrayList<String> lore = new ArrayList<String>();
      lore.add("Mission Report");

      meta.setAuthor("Mission Reports");
      meta.setTitle("Investigate Town");

      //	ArrayList<String> out = new ArrayList<String>();
      String out = "";

      out += ChatColor.UNDERLINE + "Town:" + tc.getTown().getName() + "\n" + ChatColor.RESET;
      out +=
          ChatColor.UNDERLINE + "Civ:" + tc.getTown().getCiv().getName() + "\n\n" + ChatColor.RESET;

      SimpleDateFormat sdf = new SimpleDateFormat("M/dd h:mm:ss a z");
      out += "Time: " + sdf.format(new Date()) + "\n";
      out += ("Treasury: " + tc.getTown().getTreasury().getBalance() + "\n");
      out += ("Hammers: " + tc.getTown().getHammers().total + "\n");
      out += ("Culture: " + tc.getTown().getCulture().total + "\n");
      out += ("Growth: " + tc.getTown().getGrowth().total + "\n");
      out += ("Beakers(civ): " + tc.getTown().getBeakers().total + "\n");
      if (tc.getTown().getCiv().getResearchTech() != null) {
        out += ("Researching: " + tc.getTown().getCiv().getResearchTech().name + "\n");
      } else {
        out += ("Researching:Nothing" + "\n");
      }

      BookUtil.paginate(meta, out);

      out = ChatColor.UNDERLINE + "Upkeep Info\n\n" + ChatColor.RESET;
      try {
        out += "From Spread:" + tc.getTown().getSpreadUpkeep() + "\n";
        out += "From Structures:" + tc.getTown().getStructureUpkeep() + "\n";
        out += "Total:" + tc.getTown().getTotalUpkeep();
        BookUtil.paginate(meta, out);
      } catch (InvalidConfiguration e) {
        e.printStackTrace();
        throw new CivException("Internal configuration exception.");
      }

      meta.setLore(lore);
      book.setItemMeta(meta);

      HashMap<Integer, ItemStack> leftovers = player.getInventory().addItem(book);
      for (ItemStack stack : leftovers.values()) {
        player.getWorld().dropItem(player.getLocation(), stack);
      }

      player.updateInventory();

      CivMessage.sendSuccess(player, "Mission Accomplished");
    }
  }
Пример #19
0
  private static void performPosionGranary(Player player, ConfigMission mission)
      throws CivException {
    Resident resident = CivGlobal.getResident(player);
    if (resident == null || !resident.hasTown()) {
      throw new CivException("Only residents of towns can perform spy missions.");
    }

    // Must be within enemy town borders.
    ChunkCoord coord = new ChunkCoord(player.getLocation());
    TownChunk tc = CivGlobal.getTownChunk(coord);

    if (tc == null || tc.getTown().getCiv() == resident.getTown().getCiv()) {
      throw new CivException("Must be in another civilization's town's borders.");
    }

    // Check that the player is within range of the town hall.
    Structure granary = tc.getTown().getNearestStrucutre(player.getLocation());
    if (!(granary instanceof Granary)) {
      throw new CivException("The closest structure to you must be a granary.");
    }

    double distance = player.getLocation().distance(granary.getCorner().getLocation());
    if (distance > mission.range) {
      throw new CivException("Too far away from the granary to poison it.");
    }

    ArrayList<SessionEntry> entries =
        CivGlobal.getSessionDB().lookup("posiongranary:" + tc.getTown().getName());
    if (entries != null && entries.size() != 0) {
      throw new CivException("Cannot poison granary, already posioned.");
    }

    double failMod = 1.0;
    if (resident.getTown().getBuffManager().hasBuff("buff_espionage")) {
      failMod = resident.getTown().getBuffManager().getEffectiveDouble("buff_espionage");
      CivMessage.send(
          player, CivColor.LightGray + "Your goodie buff 'Espionage' will come in handy here.");
    }

    if (processMissionResult(player, tc.getTown(), mission, failMod, 1.0)) {
      int min;
      int max;
      try {
        min =
            CivSettings.getInteger(
                CivSettings.espionageConfig, "espionage.poison_granary_min_ticks");
        max =
            CivSettings.getInteger(
                CivSettings.espionageConfig, "espionage.poison_granary_max_ticks");
      } catch (InvalidConfiguration e) {
        e.printStackTrace();
        throw new CivException("Invalid configuration error.");
      }

      Random rand = new Random();
      int posion_ticks = rand.nextInt((max - min)) + min;
      String value = "" + posion_ticks;

      CivGlobal.getSessionDB()
          .add(
              "posiongranary:" + tc.getTown().getName(),
              value,
              tc.getTown().getId(),
              tc.getTown().getId(),
              granary.getId());

      try {
        double famine_chance =
            CivSettings.getDouble(
                CivSettings.espionageConfig, "espionage.poison_granary_famine_chance");

        if (rand.nextInt(100) < (int) (famine_chance * 100)) {

          for (Structure struct : tc.getTown().getStructures()) {
            if (struct instanceof Cottage) {
              ((Cottage) struct).delevel();
            }
          }

          CivMessage.global(
              CivColor.Yellow
                  + "DISASTER!"
                  + CivColor.White
                  + " The cottages in "
                  + tc.getTown().getName()
                  + " have suffered a famine from poison grain! Each cottage loses 1 level.");
        }
      } catch (InvalidConfiguration e) {
        e.printStackTrace();
        throw new CivException("Invalid configuration.");
      }

      CivMessage.sendSuccess(player, "Poisoned the granary for " + posion_ticks + " hours!");
    }
  }
  public void set_cmd() throws CivException {
    Player player = (Player) sender;

    TownChunk tc = CivGlobal.getTownChunk(player.getLocation());
    if (tc == null) {
      throw new CivException(CivSettings.localize.localizedString("cmd_plot_perm_setnotInTown"));
    }

    if (args.length < 4) {
      showPermCmdHelp();
      throw new CivException(CivSettings.localize.localizedString("cmd_plot_perm_setBadArg"));
    }

    PermissionNode node = null;
    switch (args[1].toLowerCase()) {
      case "build":
        node = tc.perms.build;
        break;
      case "destroy":
        node = tc.perms.destroy;
        break;
      case "interact":
        node = tc.perms.interact;
        break;
      case "itemuse":
        node = tc.perms.itemUse;
        break;
      case "reset":
        // TODO implement permissions reset.
        break;
      default:
        showPermCmdHelp();
        throw new CivException(CivSettings.localize.localizedString("cmd_plot_perm_setBadArg"));
    }

    if (node == null) {
      throw new CivException(
          CivSettings.localize.localizedString("cmd_plot_perm_setInternalError"));
    }

    boolean on;
    if (args[3].equalsIgnoreCase("on")
        || args[3].equalsIgnoreCase("yes")
        || args[3].equalsIgnoreCase("1")) {
      on = true;
    } else if (args[3].equalsIgnoreCase("off")
        || args[3].equalsIgnoreCase("no")
        || args[3].equalsIgnoreCase("0")) {
      on = false;
    } else {
      showPermCmdHelp();
      throw new CivException(CivSettings.localize.localizedString("cmd_plot_perm_setBadArg"));
    }

    switch (args[2].toLowerCase()) {
      case "owner":
        node.setPermitOwner(on);
        break;
      case "group":
        node.setPermitGroup(on);
        break;
      case "others":
        node.setPermitOthers(on);
    }

    tc.save();

    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString(
            "var_cmd_plot_perm_setSuccess", node.getType(), on, args[2]));
  }