Exemplo n.º 1
0
  public void fancyDestroyStructureBlocks() {
    for (BlockCoord coord : this.structureBlocks.keySet()) {

      if (CivGlobal.getStructureChest(coord) != null) {
        continue;
      }

      if (CivGlobal.getStructureSign(coord) != null) {
        continue;
      }

      if (ItemManager.getId(coord.getBlock()) == CivData.BEDROCK
          || ItemManager.getId(coord.getBlock()) == CivData.AIR) {
        // Be a bit more careful not to destroy any of the item frames..
        continue;
      }

      Random rand = new Random();

      // Each block has a 10% chance to turn into gravel
      if (rand.nextInt(100) <= 10) {
        ItemManager.setTypeId(coord.getBlock(), CivData.GRAVEL);
        continue;
      }

      // Each block has a 50% chance of starting a fire
      if (rand.nextInt(100) <= 50) {
        ItemManager.setTypeId(coord.getBlock(), CivData.FIRE);
        continue;
      }

      // Each block has a 1% chance of launching an explosion effect
      if (rand.nextInt(100) <= 1) {
        FireworkEffect effect =
            FireworkEffect.builder()
                .with(org.bukkit.FireworkEffect.Type.BURST)
                .withColor(Color.ORANGE)
                .withColor(Color.RED)
                .withTrail()
                .withFlicker()
                .build();
        FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
        for (int i = 0; i < 3; i++) {
          try {
            fePlayer.playFirework(coord.getBlock().getWorld(), coord.getLocation(), effect);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }
  }
Exemplo n.º 2
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!");
    }
  }