Esempio n. 1
0
  @Override
  public void onPreBuild(Location loc) throws CivException {
    TownHall oldTownHall = this.getTown().getTownHall();
    if (oldTownHall != null) {
      ChunkCoord coord = new ChunkCoord(loc);
      TownChunk tc = CivGlobal.getTownChunk(coord);
      if (tc == null || tc.getTown() != this.getTown()) {
        throw new CivException("Cannot rebuild your town hall outside of your town borders.");
      }

      if (War.isWarTime()) {
        throw new CivException("Cannot rebuild your town hall during war time.");
      }

      this.getTown().clearBonusGoods();

      try {
        this.getTown().demolish(oldTownHall, true);
      } catch (CivException e) {
        e.printStackTrace();
      }
      CivMessage.sendTown(
          this.getTown(),
          "Your old town hall or capitol was demolished to make way for your new one.");
      this.autoClaim = false;
    } else {
      this.autoClaim = true;
    }
  }
Esempio n. 2
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());
    }
  }
Esempio n. 3
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");
    }
  }
Esempio n. 4
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!");
    }
  }
Esempio n. 5
0
  @Override
  public void onInteract(PlayerInteractEvent event) {

    try {

      if (War.isWarTime()) {
        throw new CivException("Cannot use spy missions during war time.");
      }

      ConfigMission mission = CivSettings.missions.get(this.getId());
      if (mission == null) {
        throw new CivException("Unknown mission " + this.getId());
      }

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

      Date now = new Date();

      if (!event.getPlayer().isOp()) {
        try {
          int spyRegisterTime =
              CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_register_time");
          int spyOnlineTime =
              CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_online_time");

          long expire = resident.getRegistered() + (spyRegisterTime * 60 * 1000);
          if (now.getTime() <= expire) {
            throw new CivException(
                "You cannot use a spy yet, you must play CivCraft a bit longer before you can use it.");
          }

          expire = resident.getLastOnline() + (spyOnlineTime * 60 * 1000);
          if (now.getTime() <= expire) {
            throw new CivException("You must be online longer before you can use a spy.");
          }
        } catch (InvalidConfiguration e) {
          e.printStackTrace();
        }
      }

      ConfigUnit unit = Unit.getPlayerUnit(event.getPlayer());
      if (unit == null || !unit.id.equals("u_spy")) {
        event.getPlayer().getInventory().remove(event.getItem());
        throw new CivException("Only spies can use mission books.");
      }

      ChunkCoord coord = new ChunkCoord(event.getPlayer().getLocation());
      CultureChunk cc = CivGlobal.getCultureChunk(coord);
      TownChunk tc = CivGlobal.getTownChunk(coord);

      if (cc == null || cc.getCiv() == resident.getCiv()) {
        throw new CivException(
            "You must be in a civilization's culture that's not your own to spy on them.");
      }

      if ((cc != null && cc.getCiv().isAdminCiv())
          || (tc != null && tc.getTown().getCiv().isAdminCiv())) {
        throw new CivException("You cannot spy on an admin civ.");
      }

      if (CivGlobal.isCasualMode()) {
        if (!cc.getCiv().getDiplomacyManager().isHostileWith(resident.getCiv())
            && !cc.getCiv().getDiplomacyManager().atWarWith(resident.getCiv())) {
          throw new CivException(
              "You must be hostile or at war with "
                  + cc.getCiv().getName()
                  + " in order to perform spy missions in casual mode.");
        }
      }

      resident.setInteractiveMode(
          new InteractiveSpyMission(
              mission, event.getPlayer().getName(), event.getPlayer().getLocation(), cc.getTown()));
    } catch (CivException e) {
      CivMessage.sendError(event.getPlayer(), e.getMessage());
    }
  }
  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]));
  }