Beispiel #1
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());
    }
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!War.isWarTime()) {
      return;
    }

    coord.setFromLocation(event.getBlock().getLocation());
    CultureChunk cc = CivGlobal.getCultureChunk(coord);

    if (cc == null) {
      return;
    }

    if (!cc.getCiv().getDiplomacyManager().isAtWar()) {
      return;
    }

    if (event.getBlock().getType().equals(Material.DIRT)
        || event.getBlock().getType().equals(Material.GRASS)
        || event.getBlock().getType().equals(Material.SAND)
        || event.getBlock().getType().equals(Material.GRAVEL)
        || event.getBlock().getType().equals(Material.TORCH)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_OFF)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON)
        || event.getBlock().getType().equals(Material.REDSTONE)
        || event.getBlock().getType().equals(Material.TNT)
        || event.getBlock().getType().equals(Material.LADDER)
        || event.getBlock().getType().equals(Material.VINE)
        || event.getBlock().getType().equals(Material.IRON_BLOCK)
        || event.getBlock().getType().equals(Material.GOLD_BLOCK)
        || event.getBlock().getType().equals(Material.DIAMOND_BLOCK)
        || event.getBlock().getType().equals(Material.EMERALD_BLOCK)
        || !event.getBlock().getType().isSolid()) {
      return;
    }

    CivMessage.sendError(event.getPlayer(), CivSettings.localize.localizedString("war_mustUseTNT"));
    event.setCancelled(true);
  }
Beispiel #3
0
  private static void performSabotage(Player player, ConfigMission mission) throws CivException {
    Resident resident = CivGlobal.getResident(player);

    // 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.
    Buildable buildable = cc.getTown().getNearestBuildable(player.getLocation());
    if (buildable instanceof TownHall) {
      throw new CivException("Nearest structure is a town hall which cannot be destroyed.");
    }
    if (buildable instanceof Wonder) {
      if (buildable.isComplete()) {
        throw new CivException("Cannot sabotage completed wonders.");
      }
    }

    double distance = player.getLocation().distance(buildable.getCorner().getLocation());
    if (distance > mission.range) {
      throw new CivException("Too far away the " + buildable.getDisplayName() + " to sabotage it");
    }

    if (buildable instanceof Structure) {
      if (!buildable.isComplete()) {
        throw new CivException("Cannot sabotage incomplete structures.");
      }

      if (buildable.isDestroyed()) {
        throw new CivException(buildable.getDisplayName() + " is already destroyed.");
      }
    }

    if (buildable instanceof Wonder) {
      // Create a new mission and with the penalties.
      mission = CivSettings.missions.get("spy_sabotage_wonder");
    }

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

    if (processMissionResult(player, cc.getTown(), mission, failMod, 1.0)) {
      CivMessage.global(
          CivColor.Yellow
              + "DISASTER!"
              + CivColor.White
              + " A "
              + buildable.getDisplayName()
              + " has been destroyed! Foul play is suspected.");
      buildable.setHitpoints(0);
      buildable.fancyDestroyStructureBlocks();
      buildable.save();

      if (buildable instanceof Wonder) {
        Wonder wonder = (Wonder) buildable;
        wonder.unbindStructureBlocks();
        try {
          wonder.delete();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
  }
Beispiel #4
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());
    }
  }
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!War.isWarTime()) {
      return;
    }

    coord.setFromLocation(event.getBlock().getLocation());
    CultureChunk cc = CivGlobal.getCultureChunk(coord);

    if (cc == null) {
      return;
    }

    if (!cc.getCiv().getDiplomacyManager().isAtWar()) {
      return;
    }

    if (event.getBlock().getType().equals(Material.DIRT)
        || event.getBlock().getType().equals(Material.GRASS)
        || event.getBlock().getType().equals(Material.SAND)
        || event.getBlock().getType().equals(Material.GRAVEL)
        || event.getBlock().getType().equals(Material.TORCH)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_OFF)
        || event.getBlock().getType().equals(Material.REDSTONE_TORCH_ON)
        || event.getBlock().getType().equals(Material.REDSTONE)
        || event.getBlock().getType().equals(Material.LADDER)
        || event.getBlock().getType().equals(Material.VINE)
        || event.getBlock().getType().equals(Material.TNT)) {

      if (event.getBlock().getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) {
        return;
      }

      event
          .getBlock()
          .getWorld()
          .spawnFallingBlock(event.getBlock().getLocation(), event.getBlock().getType(), (byte) 0);
      event.getBlock().setType(Material.AIR);

      return;
    }

    if (event.getBlock().getType().equals(Material.IRON_BLOCK)
        || event.getBlock().getType().equals(Material.GOLD_BLOCK)
        || event.getBlock().getType().equals(Material.DIAMOND_BLOCK)
        || event.getBlock().getType().equals(Material.EMERALD_BLOCK)) {

      if (event.getBlock().getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) {
        return;
      }

      return;
    }

    CivMessage.sendError(
        event.getPlayer(), CivSettings.localize.localizedString("war_onlyBuildCertainBlocks"));
    CivMessage.sendError(
        event.getPlayer(), CivSettings.localize.localizedString("war_canAlsoPlaceBridgeBlocks"));
    event.setCancelled(true);
  }