示例#1
0
  public void createControlPoint(BlockCoord absCoord) {

    Location centerLoc = absCoord.getLocation();

    /* Build the bedrock tower. */
    // for (int i = 0; i < 1; i++) {
    Block b = centerLoc.getBlock();
    ItemManager.setTypeId(b, CivData.FENCE);
    ItemManager.setData(b, 0);

    StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
    this.addStructureBlock(sb.getCoord(), true);
    // }

    /* Build the control block. */
    b = centerLoc.getBlock().getRelative(0, 1, 0);
    ItemManager.setTypeId(b, CivData.OBSIDIAN);
    sb = new StructureBlock(new BlockCoord(b), this);
    this.addStructureBlock(sb.getCoord(), true);

    int townhallControlHitpoints;
    try {
      townhallControlHitpoints =
          CivSettings.getInteger(CivSettings.warConfig, "war.control_block_hitpoints_townhall");
    } catch (InvalidConfiguration e) {
      e.printStackTrace();
      townhallControlHitpoints = 100;
    }

    BlockCoord coord = new BlockCoord(b);
    this.controlPoints.put(coord, new ControlPoint(coord, this, townhallControlHitpoints));
  }
示例#2
0
  public void build_trade_outpost_tower() throws CivException {
    /* Add trade good to town. */

    /* this.good is set by the good's load function or by the onBuild function. */
    TradeGood good = this.good;
    if (good == null) {
      throw new CivException("Couldn't find trade good at location:" + good);
    }

    /* Build the 'trade good tower' */
    /* This is always set on post build using the post build sync task. */
    if (tradeOutpostTower == null) {
      throw new CivException("Couldn't find trade outpost tower.");
    }

    Location centerLoc = tradeOutpostTower.getLocation();

    /* Build the bedrock tower. */
    for (int i = 0; i < 3; i++) {
      Block b = centerLoc.getBlock().getRelative(0, i, 0);
      ItemManager.setTypeId(b, CivData.BEDROCK);
      ItemManager.setData(b, 0);

      StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
      this.addStructureBlock(sb.getCoord(), false);
      // CivGlobal.addStructureBlock(sb.getCoord(), this);
    }

    /* Place the sign. */
    Block b = centerLoc.getBlock().getRelative(1, 2, 0);
    ItemManager.setTypeId(b, CivData.WALL_SIGN);
    ItemManager.setData(b, CivData.DATA_SIGN_EAST);
    Sign s = (Sign) b.getState();
    s.setLine(0, good.getInfo().name);
    s.update();
    StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
    // CivGlobal.addStructureBlock(sb.getCoord(), this);
    this.addStructureBlock(sb.getCoord(), false);

    /* Place the itemframe. */
    b = centerLoc.getBlock().getRelative(1, 1, 0);
    this.addStructureBlock(new BlockCoord(b), false);
    Block b2 = b.getRelative(0, 0, 0);
    Entity entity = CivGlobal.getEntityAtLocation(b2.getLocation());
    this.addStructureBlock(new BlockCoord(b2), false);

    if (entity == null || (!(entity instanceof ItemFrame))) {
      this.frameStore = new ItemFrameStorage(b.getLocation(), BlockFace.EAST);
    } else {
      this.frameStore = new ItemFrameStorage((ItemFrame) entity, b.getLocation());
    }

    this.frameStore.setBuildable(this);
  }
示例#3
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();
          }
        }
      }
    }
  }
示例#4
0
  public void regenControlBlocks() {
    for (BlockCoord coord : this.controlPoints.keySet()) {
      ItemManager.setTypeId(coord.getBlock(), CivData.OBSIDIAN);

      ControlPoint cp = this.controlPoints.get(coord);
      cp.setHitpoints(cp.getMaxHitpoints());
    }
  }
示例#5
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!");
    }
  }
示例#6
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!");
    }
  }
示例#7
0
  public void createGoodieItemFrame(BlockCoord absCoord, int slotId, int direction) {
    if (slotId >= MAX_GOODIE_FRAMES) {
      return;
    }

    /*
     * Make sure there isn't another frame here. We have the position of the sign, but the entity's
     * position is the block it's attached to. We'll use the direction from the sign data to determine
     * which direction to look for the entity.
     */
    Block attachedBlock;
    BlockFace facingDirection;

    switch (direction) {
      case CivData.DATA_SIGN_EAST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.WEST);
        facingDirection = BlockFace.EAST;
        break;
      case CivData.DATA_SIGN_WEST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.EAST);
        facingDirection = BlockFace.WEST;
        break;
      case CivData.DATA_SIGN_NORTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.SOUTH);
        facingDirection = BlockFace.NORTH;
        break;
      case CivData.DATA_SIGN_SOUTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.NORTH);
        facingDirection = BlockFace.SOUTH;
        break;
      default:
        CivLog.error("Bad sign data for /itemframe sign in town hall.");
        return;
    }

    Block itemFrameBlock = absCoord.getBlock();
    if (ItemManager.getId(itemFrameBlock) != CivData.AIR) {
      ItemManager.setTypeId(itemFrameBlock, CivData.AIR);
    }

    ItemFrameStorage itemStore;
    ItemFrame frame = null;
    Entity entity = CivGlobal.getEntityAtLocation(absCoord.getBlock().getLocation());
    if (entity == null || (!(entity instanceof ItemFrame))) {
      itemStore = new ItemFrameStorage(attachedBlock.getLocation(), facingDirection);
    } else {
      try {
        frame = (ItemFrame) entity;
        itemStore = new ItemFrameStorage(frame, attachedBlock.getLocation());
      } catch (CivException e) {
        e.printStackTrace();
        return;
      }
      if (facingDirection != BlockFace.EAST) {
        itemStore.setFacingDirection(facingDirection);
      }
    }

    itemStore.setBuildable(this);
    goodieFrames.add(itemStore);
  }