public static double getHammerRate(Town town) { ArrayList<SessionEntry> entries = CivGlobal.getSessionDB().lookup(HammerRate.getKey(town)); double hammerrate = 1.0; ArrayList<SessionEntry> removed = new ArrayList<SessionEntry>(); for (SessionEntry entry : entries) { String[] split = entry.value.split(":"); double rate = Double.valueOf(split[0]); int duration = Integer.valueOf(split[1]); Date start = new Date(entry.time); Date now = new Date(); if (now.getTime() > (start.getTime() + (duration * RandomEventSweeper.MILLISECONDS_PER_HOUR))) { /* Entry is expired, delete it and continue. */ removed.add(entry); continue; } hammerrate *= rate; } /* Remove any expired entries */ for (SessionEntry entry : removed) { CivGlobal.getSessionDB().delete(entry.request_id, entry.key); } return hammerrate; }
public void setgov_cmd() throws CivException { Civilization civ = getNamedCiv(1); if (args.length < 3) { throw new CivException(CivSettings.localize.localizedString("adcmd_civ_setgovPrompt")); } ConfigGovernment gov = CivSettings.governments.get(args[2]); if (gov == null) { throw new CivException( CivSettings.localize.localizedString("adcmd_civ_setGovInvalidGov") + " gov_monarchy, gov_depostism... etc"); } // Remove any anarchy timers String key = "changegov_" + civ.getId(); CivGlobal.getSessionDB().delete_all(key); civ.setGovernment(gov.id); CivMessage.global( CivSettings.localize.localizedString( "var_adcmd_civ_setGovSuccessBroadcast", civ.getName(), CivSettings.governments.get(gov.id).displayName)); CivMessage.sendSuccess(sender, CivSettings.localize.localizedString("adcmd_civ_setGovSuccess")); }
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!"); } }