public void createTradeGood() throws CivException { if (!this.isActive()) { return; } /* Add custom item. * This function is called on reload. The constructor either loads * the good or creates a new one at the trade outpost if no good could * be found. * */ try { this.goodie = new BonusGoodie(this); if (this.goodie.getFrame() == null) { // goodie not in a frame, skip it. return; } TownHall townhall = this.goodie.getFrame().getTown().getTownHall(); if (townhall != null) { for (ItemFrameStorage ifs : townhall.getGoodieFrames()) { if (ifs.getFrameID() == this.goodie.getFrame().getFrameID()) { townhall.getTown().loadGoodiePlaceIntoFrame(townhall, goodie); } } } } catch (SQLException e) { e.printStackTrace(); throw new CivException("Internal database error."); } catch (InvalidNameException e) { e.printStackTrace(); throw new CivException("Invalid name exception."); } }
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()); } }
@EventHandler(priority = EventPriority.HIGH) public void onEntityExplode(EntityExplodeEvent event) { if (War.isWarTime()) { event.setCancelled(false); } else { event.setCancelled(true); return; } if (event.isCancelled()) { return; } if (event.getEntity() == null) { return; } if (event.getEntityType().equals(EntityType.UNKNOWN)) { return; } if (event.getEntityType().equals(EntityType.PRIMED_TNT) || event.getEntityType().equals(EntityType.MINECART_TNT)) { HashSet<Buildable> structuresHit = new HashSet<Buildable>(); for (int y = -yield; y <= yield; y++) { for (int x = -yield; x <= yield; x++) { for (int z = -yield; z <= yield; z++) { Location loc = event.getLocation().clone().add(new Vector(x, y, z)); Block b = loc.getBlock(); if (loc.distance(event.getLocation()) < yield) { BlockCoord bcoord = new BlockCoord(); bcoord.setFromLocation(loc); // StructureBlock sb = CivGlobal.getStructureBlock(bcoord); // if (sb == null) { // WarRegen.saveBlock(loc.getBlock(), Cannon.RESTORE_NAME, false); // } // if (sb.getTown() != null) { // WarRegen.destroyThisBlock(loc.getBlock(), sb.getTown()); // } else { // ItemManager.setTypeIdAndData(loc.getBlock(), CivData.AIR, 0, false); // } StructureBlock sb = CivGlobal.getStructureBlock(bcoord); CampBlock cb = CivGlobal.getCampBlock(bcoord); if (sb == null && cb == null) { explodeBlock(b); continue; } if (sb != null) { if (!sb.isDamageable()) { continue; } if (sb.getOwner() instanceof TownHall) { TownHall th = (TownHall) sb.getOwner(); if (th.getControlPoints().containsKey(bcoord)) { continue; } } if (!sb.getOwner().isDestroyed()) { if (!structuresHit.contains(sb.getOwner())) { structuresHit.add(sb.getOwner()); if (sb.getOwner() instanceof TownHall) { TownHall th = (TownHall) sb.getOwner(); if (th.getHitpoints() == 0) { explodeBlock(b); } else { th.onTNTDamage(structureDamage); } } else { sb.getOwner() .onDamage(structureDamage, b.getWorld(), null, sb.getCoord(), sb); CivMessage.sendCiv( sb.getCiv(), CivColor.Yellow + CivSettings.localize.localizedString( "var_war_tntMsg", sb.getOwner().getDisplayName(), (sb.getOwner().getCenterLocation().getX() + "," + sb.getOwner().getCenterLocation().getY() + "," + sb.getOwner().getCenterLocation().getZ() + ")"), (sb.getOwner().getHitpoints() + "/" + sb.getOwner().getMaxHitPoints()))); } } } else { explodeBlock(b); } continue; } } } } } event.setCancelled(true); } }