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 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()));
  }
Ejemplo n.º 3
0
  @Override
  public void respond(String message, Resident resident) {
    Player player;
    try {
      player = CivGlobal.getPlayer(resident);
    } catch (CivException e) {
      return;
    }
    resident.clearInteractiveMode();

    if (!message.equalsIgnoreCase("yes")) {
      CivMessage.sendError(player, "Mission Aborted.");
      return;
    }

    if (!TaskMaster.hasTask("missiondelay:" + playerName)) {
      TaskMaster.asyncTask(
          "missiondelay:" + playerName,
          (new EspionageMissionTask(mission, playerName, playerLocation, target, mission.length)),
          0);
    } else {
      CivMessage.sendError(player, "Waiting on countdown to start mission.");
      return;
    }
  }
Ejemplo n.º 4
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());
    }
  }
  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()));
    }
  }
Ejemplo n.º 6
0
  @Override
  public void onDamage(
      int amount, World world, Player player, BlockCoord coord, BuildableDamageBlock hit) {

    ControlPoint cp = this.controlPoints.get(coord);
    Resident resident = CivGlobal.getResident(player);

    if (!resident.canDamageControlBlock()) {
      CivMessage.send(
          player,
          CivColor.Rose
              + "Cannot damage control blocks due to missing/invalid Town Hall or Capitol structure.");
      return;
    }

    if (cp != null) {
      if (!cp.isDestroyed()) {

        if (resident.isControlBlockInstantBreak()) {
          cp.damage(cp.getHitpoints());
        } else {
          cp.damage(amount);
        }

        if (cp.isDestroyed()) {
          onControlBlockDestroy(cp, world, player, (StructureBlock) hit);
        } else {
          onControlBlockHit(cp, world, player, (StructureBlock) hit);
        }
      } else {
        CivMessage.send(player, CivColor.Rose + "Control Block already destroyed.");
      }

    } else {
      CivMessage.send(
          player,
          CivColor.Rose
              + "Cannot Damage "
              + this.getDisplayName()
              + ", go after the control points!");
    }
  }
Ejemplo n.º 7
0
  public static void performMission(ConfigMission mission, String playerName) {
    Player player;
    try {
      player = CivGlobal.getPlayer(playerName);
    } catch (CivException e1) {
      return;
    }

    try {
      Resident resident = CivGlobal.getResident(playerName);
      if (!resident.getTown().getTreasury().hasEnough(mission.cost)) {
        throw new CivException(
            "Your town requires " + mission.cost + " coins to perform this mission.");
      }

      switch (mission.id) {
        case "spy_investigate_town":
          performInvestigateTown(player, mission);
          break;
        case "spy_steal_treasury":
          performStealTreasury(player, mission);
          break;
        case "spy_incite_riots":
          performInciteRiots(player, mission);
          break;
        case "spy_poison_granary":
          performPosionGranary(player, mission);
          break;
        case "spy_pirate":
          performPirate(player, mission);
          break;
        case "spy_sabotage":
          performSabotage(player, mission);
          break;
      }

    } catch (CivException e) {
      CivMessage.sendError(player, e.getMessage());
    }
  }
Ejemplo n.º 8
0
  @Override
  public void run() {

    for (Resident resident : CivGlobal.getResidents()) {
      if (!resident.isProtected()) {
        continue;
      }

      int mins;
      try {
        mins = CivSettings.getInteger(CivSettings.civConfig, "global.pvp_timer");
        if (DateUtil.isAfterMins(new Date(resident.getRegistered()), mins)) {
          // if (DateUtil.isAfterSeconds(new Date(resident.getRegistered()), mins)) {
          resident.setisProtected(false);
          CivMessage.send(
              resident, CivColor.LightGray + CivSettings.localize.localizedString("pvpTimerEnded"));
        }
      } catch (InvalidConfiguration e) {
        e.printStackTrace();
        return;
      }
    }
  }
      @Override
      public void run() {
        Player player;
        try {
          player = CivGlobal.getPlayer(playerName);
        } catch (CivException e) {
          return;
        }

        Resident resident = CivGlobal.getResident(playerName);
        if (resident == null) {
          return;
        }

        CivMessage.send(player, TownCommand.survey(player.getLocation()));
        CivMessage.send(player, "");
        CivMessage.send(
            player,
            CivColor.LightGreen
                + ChatColor.BOLD
                + CivSettings.localize.localizedString("interactive_capitol_confirmPrompt"));
        resident.setInteractiveMode(new InteractiveConfirmCivCreation());
      }
  @EventHandler(priority = EventPriority.MONITOR)
  public void onChannelChatEvent(ChannelChatEvent event) {
    Resident resident = CivGlobal.getResident(event.getSender().getName());
    if (resident == null) {
      event.setResult(Result.FAIL);
      return;
    }

    if (!resident.isInteractiveMode()) {
      if (resident.isMuted()) {
        event.setResult(Result.MUTED);
        return;
      }
    }

    if (event.getChannel().getDistance() > 0) {
      for (String name : Resident.allchatters) {
        Player player;
        try {
          player = CivGlobal.getPlayer(name);
        } catch (CivException e) {
          continue;
        }

        Chatter you = Herochat.getChatterManager().getChatter(player);
        if (!event.getSender().isInRange(you, event.getChannel().getDistance())) {
          player.sendMessage(
              CivColor.White
                  + event.getSender().getName()
                  + CivSettings.localize.localizedString("hc_prefix_far")
                  + " "
                  + event.getMessage());
        }
      }
    }
  }
Ejemplo n.º 11
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());
    }
  }
Ejemplo n.º 12
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");
    }
  }
Ejemplo n.º 13
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!");
    }
  }
Ejemplo n.º 14
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();
        }
      }
    }
  }
Ejemplo n.º 15
0
  private static boolean processMissionResult(
      Player player,
      Town target,
      ConfigMission mission,
      double failModifier,
      double compromiseModifier) {

    int fail_rate =
        (int) ((MissionBook.getMissionFailChance(mission, target) * failModifier) * 100);
    int compromise_rate =
        (int)
            ((MissionBook.getMissionCompromiseChance(mission, target) * compromiseModifier) * 100);
    Resident resident = CivGlobal.getResident(player);

    if (resident == null || !resident.hasTown()) {
      return false;
    }

    if (!resident.getTown().getTreasury().hasEnough(mission.cost)) {
      CivMessage.send(
          player,
          CivColor.Rose
              + "Suddenly, your town doesn't have enough cash to follow through with the mission.");
      return false;
    }

    resident.getTown().getTreasury().withdraw(mission.cost);

    Random rand = new Random();
    String result = "";
    int failnext = rand.nextInt(100);
    if (failnext < fail_rate) {
      int next = rand.nextInt(100);
      result += "Failed";

      if (next < compromise_rate) {
        CivMessage.global(
            CivColor.Yellow
                + "INTERNATIONAL INCIDENT!"
                + CivColor.White
                + " "
                + player.getName()
                + " was caught trying to perform a "
                + mission.name
                + " spy mission in "
                + target.getName()
                + "!");
        CivMessage.send(
            player,
            CivColor.Rose
                + "You've been compromised! (Rolled "
                + next
                + " vs "
                + compromise_rate
                + ") Spy unit was destroyed!");
        Unit.removeUnit(player);
        result += ", COMPROMISED";
      }

      MissionLogger.logMission(resident.getTown(), target, player.getName(), mission.name, result);
      CivMessage.send(
          player, CivColor.Rose + "Mission Failed! (Rolled " + failnext + " vs " + fail_rate + ")");
      return false;
    }

    MissionLogger.logMission(resident.getTown(), target, player.getName(), mission.name, "Success");
    return true;
  }
Ejemplo n.º 16
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());
    }
  }
Ejemplo n.º 17
0
  public void onControlBlockCannonDestroy(ControlPoint cp, Player player, StructureBlock hit) {
    // Should always have a resident and a town at this point.
    Resident attacker = CivGlobal.getResident(player);

    ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR);

    boolean allDestroyed = true;
    for (ControlPoint c : this.controlPoints.values()) {
      if (c.isDestroyed() == false) {
        allDestroyed = false;
        break;
      }
    }
    CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f);

    if (allDestroyed) {

      if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) {
        CivMessage.global(
            CivColor.LightBlue
                + ChatColor.BOLD
                + "The civilization of "
                + this.getTown().getCiv().getName()
                + " has been conquered by "
                + attacker.getCiv().getName()
                + "!");
        for (Town town : this.getTown().getCiv().getTowns()) {
          town.defeated = true;
        }

        War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv());
        WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv());
        War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv());

        if (CivGlobal.isCasualMode()) {
          HashMap<Integer, ItemStack> leftovers =
              player
                  .getInventory()
                  .addItem(
                      this.getCiv()
                          .getRandomLeaderSkull("Victory Over " + this.getCiv().getName() + "!"));
          for (ItemStack stack : leftovers.values()) {
            player.getWorld().dropItem(player.getLocation(), stack);
          }
        }

      } else {
        CivMessage.global(
            CivColor.Yellow
                + ChatColor.BOLD
                + "The town of "
                + getTown().getName()
                + " in "
                + this.getCiv().getName()
                + " has been conquered by "
                + attacker.getCiv().getName()
                + "!");
        // this.getTown().onDefeat(attacker.getTown().getCiv());
        this.getTown().defeated = true;
        // War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv());
        WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown());
        War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv());
      }

    } else {
      CivMessage.sendTown(
          hit.getTown(),
          CivColor.Rose + "One of our Town Hall's Control Points has been destroyed!");
      CivMessage.sendCiv(
          attacker.getTown().getCiv(),
          CivColor.LightGreen
              + "We've destroyed a control block in "
              + hit.getTown().getName()
              + "!");
      CivMessage.sendCiv(
          hit.getTown().getCiv(),
          CivColor.Rose + "A control block in " + hit.getTown().getName() + " has been destroyed!");
    }
  }
Ejemplo n.º 18
0
  public void onControlBlockDestroy(
      ControlPoint cp, World world, Player player, StructureBlock hit) {
    // Should always have a resident and a town at this point.
    Resident attacker = CivGlobal.getResident(player);

    ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR);
    world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
    world.playSound(hit.getCoord().getLocation(), Sound.EXPLODE, 1.0f, 1.0f);

    FireworkEffect effect =
        FireworkEffect.builder()
            .with(Type.BURST)
            .withColor(Color.YELLOW)
            .withColor(Color.RED)
            .withTrail()
            .withFlicker()
            .build();
    FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
    for (int i = 0; i < 3; i++) {
      try {
        fePlayer.playFirework(world, hit.getCoord().getLocation(), effect);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    boolean allDestroyed = true;
    for (ControlPoint c : this.controlPoints.values()) {
      if (c.isDestroyed() == false) {
        allDestroyed = false;
        break;
      }
    }
    CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f);

    if (allDestroyed) {

      if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) {
        CivMessage.global(
            CivColor.LightBlue
                + ChatColor.BOLD
                + "The civilization of "
                + this.getTown().getCiv().getName()
                + " has been conquered by "
                + attacker.getCiv().getName()
                + "!");
        for (Town town : this.getTown().getCiv().getTowns()) {
          town.defeated = true;
        }

        War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv());
        WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv());
        War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv());

        if (CivGlobal.isCasualMode()) {
          HashMap<Integer, ItemStack> leftovers =
              player
                  .getInventory()
                  .addItem(
                      this.getCiv()
                          .getRandomLeaderSkull("Victory Over " + this.getCiv().getName() + "!"));
          for (ItemStack stack : leftovers.values()) {
            player.getWorld().dropItem(player.getLocation(), stack);
          }
        }

      } else {
        CivMessage.global(
            CivColor.Yellow
                + ChatColor.BOLD
                + "The town of "
                + getTown().getName()
                + " in "
                + this.getCiv().getName()
                + " has been conquered by "
                + attacker.getCiv().getName()
                + "!");
        // this.getTown().onDefeat(attacker.getTown().getCiv());
        this.getTown().defeated = true;
        // War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv());
        WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown());
        War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv());
      }

    } else {
      CivMessage.sendTown(
          hit.getTown(),
          CivColor.Rose + "One of our Town Hall's Control Points has been destroyed!");
      CivMessage.sendCiv(
          attacker.getTown().getCiv(),
          CivColor.LightGreen
              + "We've destroyed a control block in "
              + hit.getTown().getName()
              + "!");
      CivMessage.sendCiv(
          hit.getTown().getCiv(),
          CivColor.Rose + "A control block in " + hit.getTown().getName() + " has been destroyed!");
    }
  }
  @Override
  public void respond(String message, Resident resident) {

    Player player;
    try {
      player = CivGlobal.getPlayer(resident);
    } catch (CivException e) {
      return;
    }

    if (message.equalsIgnoreCase("cancel")) {
      CivMessage.send(player, CivSettings.localize.localizedString("interactive_capitol_cancel"));
      resident.clearInteractiveMode();
      return;
    }

    if (!StringUtils.isAlpha(message) || !StringUtils.isAsciiPrintable(message)) {
      CivMessage.send(
          player,
          CivColor.Rose
              + ChatColor.BOLD
              + CivSettings.localize.localizedString("interactive_capitol_invalidname"));
      return;
    }

    message = message.replace(" ", "_");
    message = message.replace("\"", "");
    message = message.replace("\'", "");

    resident.desiredCapitolName = message;
    CivMessage.send(
        player,
        CivColor.LightGreen
            + CivSettings.localize.localizedString(
                "var_interactive_capitol_confirm1",
                CivColor.Yellow + resident.desiredCivName + CivColor.LightGreen,
                CivColor.Yellow + resident.desiredCapitolName + CivColor.LightGreen));
    CivMessage.sendHeading(
        player, CivSettings.localize.localizedString("interactive_capitol_confirmSurvey"));

    class SyncTask implements Runnable {
      String playerName;

      public SyncTask(String name) {
        this.playerName = name;
      }

      @Override
      public void run() {
        Player player;
        try {
          player = CivGlobal.getPlayer(playerName);
        } catch (CivException e) {
          return;
        }

        Resident resident = CivGlobal.getResident(playerName);
        if (resident == null) {
          return;
        }

        CivMessage.send(player, TownCommand.survey(player.getLocation()));
        CivMessage.send(player, "");
        CivMessage.send(
            player,
            CivColor.LightGreen
                + ChatColor.BOLD
                + CivSettings.localize.localizedString("interactive_capitol_confirmPrompt"));
        resident.setInteractiveMode(new InteractiveConfirmCivCreation());
      }
    }

    TaskMaster.syncTask(new SyncTask(resident.getName()));

    return;
  }