@Override public void onPreBuild(Location loc) throws CivException { TownHall oldTownHall = this.getTown().getTownHall(); if (oldTownHall != null) { ChunkCoord coord = new ChunkCoord(loc); TownChunk tc = CivGlobal.getTownChunk(coord); if (tc == null || tc.getTown() != this.getTown()) { throw new CivException("Cannot rebuild your town hall outside of your town borders."); } if (War.isWarTime()) { throw new CivException("Cannot rebuild your town hall during war time."); } this.getTown().clearBonusGoods(); try { this.getTown().demolish(oldTownHall, true); } catch (CivException e) { e.printStackTrace(); } CivMessage.sendTown( this.getTown(), "Your old town hall or capitol was demolished to make way for your new one."); this.autoClaim = false; } else { this.autoClaim = true; } }
public void start(Town town) { this.town = town; /* Show message to town */ CivMessage.sendTownHeading(town, "Event: " + this.configRandomEvent.name); for (String str : this.configRandomEvent.message) { CivMessage.sendTown(town, str); savedMessages.add(str); } town.setActiveEvent(this); this.start(); }
public void onControlBlockHit(ControlPoint cp, World world, Player player, StructureBlock hit) { world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1); world.playEffect(hit.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0); CivMessage.send( player, CivColor.LightGray + "Damaged Control Block (" + cp.getHitpoints() + " / " + cp.getMaxHitpoints() + ")"); CivMessage.sendTown( hit.getTown(), CivColor.Yellow + "One of our Town Hall's Control Points is under attack!"); }
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()); } }
/* * Private for now, since we only allow random events on towns atm. */ private void start() { /* Loop through all components for onStart() */ for (RandomEventComponent comp : this.actions.values()) { comp.onStart(); } for (RandomEventComponent comp : this.requirements.values()) { comp.onStart(); } for (RandomEventComponent comp : this.success.values()) { comp.onStart(); } for (RandomEventComponent comp : this.failure.values()) { comp.onStart(); } /* Start by processing all of the action components. */ boolean requireActivation = false; for (RandomEventComponent comp : this.actions.values()) { if (!comp.requiresActivation()) { comp.process(); } else { requireActivation = true; CivMessage.sendTown( this.town, CivColor.Yellow + "This event requires activation! use '/town event activate' to activate it."); } } if (!requireActivation) { this.active = true; } /* Register this random event with the sweeper until complete. */ RandomEventSweeper.register(this); /* Setup start date. */ this.startDate = new Date(); this.save(); }
@Override public void onInvalidPunish() { int invalid_respawn_penalty; try { invalid_respawn_penalty = CivSettings.getInteger(CivSettings.warConfig, "war.invalid_respawn_penalty"); } catch (InvalidConfiguration e) { e.printStackTrace(); return; } CivMessage.sendTown( this.getTown(), CivColor.Rose + CivColor.BOLD + "Our town's town hall cannot be supported by the blocks underneath!" + " It will take us an extra " + invalid_respawn_penalty + " mins to respawn during war if its not fixed in time!"); }
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!"); } }
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!"); } }
public void processAction(Town town) throws CivException { if (this.action == null) return; String[] args = this.action.split(","); Structure struct; switch (args[0]) { case "set_town_level": if (town.getLevel() < Integer.valueOf(args[1].trim())) { town.setLevel(Integer.valueOf(args[1].trim())); CivMessage.global(town.getName() + " is now a " + town.getLevelTitle() + "!"); } break; case "set_bank_level": struct = town.getStructureByType("s_bank"); if (struct != null && (struct instanceof Bank)) { Bank bank = (Bank) struct; if (bank.getLevel() < Integer.valueOf(args[1].trim())) { bank.setLevel(Integer.valueOf(args[1].trim())); bank.updateSignText(); town.saved_bank_level = bank.getLevel(); CivMessage.sendTown(town, "The bank is now level " + bank.getLevel()); } } break; case "set_bank_interest": struct = town.getStructureByType("s_bank"); if (struct != null && (struct instanceof Bank)) { Bank bank = (Bank) struct; if (bank.getInterestRate() < Double.valueOf(args[1].trim())) { bank.setInterestRate(Double.valueOf(args[1].trim())); town.saved_bank_interest_amount = bank.getInterestRate(); DecimalFormat df = new DecimalFormat(); CivMessage.sendTown( town, "The bank is now provides a " + df.format(bank.getInterestRate() * 100) + "% interest rate."); } } break; case "set_store_level": struct = town.getStructureByType("s_store"); if (struct != null && (struct instanceof Store)) { Store store = (Store) struct; if (store.getLevel() < Integer.valueOf(args[1].trim())) { store.setLevel(Integer.valueOf(args[1].trim())); store.updateSignText(); CivMessage.sendTown(town, "The store is now level " + store.getLevel()); } } break; case "set_store_material": struct = town.getStructureByType("s_store"); if (struct != null && (struct instanceof Store)) { Store store = (Store) struct; StoreMaterial mat = new StoreMaterial(args[1].trim(), args[2].trim(), args[3].trim(), args[4].trim()); store.addStoreMaterial(mat); store.updateSignText(); } break; case "set_library_level": struct = town.getStructureByType("s_library"); if (struct != null && (struct instanceof Library)) { Library library = (Library) struct; if (library.getLevel() < Integer.valueOf(args[1].trim())) { library.setLevel(Integer.valueOf(args[1].trim())); library.updateSignText(); CivMessage.sendTown(town, "The library is now level " + library.getLevel()); } } break; case "enable_library_enchantment": struct = town.getStructureByType("s_library"); if (struct != null && (struct instanceof Library)) { Library library = (Library) struct; LibraryEnchantment enchant = new LibraryEnchantment( args[1].trim(), Integer.valueOf(args[2].trim()), Double.valueOf(args[3].trim())); library.addEnchant(enchant); library.updateSignText(); CivMessage.sendTown( town, "The library now offers the " + args[1].trim() + " enchantment at level " + args[2] + "!"); } break; case "set_grocer_level": struct = town.getStructureByType("s_grocer"); if (struct != null && (struct instanceof Grocer)) { Grocer grocer = (Grocer) struct; if (grocer.getLevel() < Integer.valueOf(args[1].trim())) { grocer.setLevel(Integer.valueOf(args[1].trim())); grocer.updateSignText(); CivMessage.sendTown(town, "The grocer is now level " + grocer.getLevel()); } } break; } }