@Override public void respond(String message, Resident resident) { Player player; try { player = CivGlobal.getPlayer(resident); } catch (CivException e) { return; } resident.clearInteractiveMode(); if (!message.equalsIgnoreCase("yes")) { CivMessage.sendError(player, "Mission Aborted."); return; } if (!TaskMaster.hasTask("missiondelay:" + playerName)) { TaskMaster.asyncTask( "missiondelay:" + playerName, (new EspionageMissionTask(mission, playerName, playerLocation, target, mission.length)), 0); } else { CivMessage.sendError(player, "Waiting on countdown to start mission."); return; } }
public void onCannonDamage(int damage, CannonProjectile projectile) throws CivException { this.hitpoints -= damage; Resident resident = projectile.whoFired; if (hitpoints <= 0) { for (BlockCoord coord : this.controlPoints.keySet()) { ControlPoint cp = this.controlPoints.get(coord); if (cp != null) { if (cp.getHitpoints() > CannonProjectile.controlBlockHP) { cp.damage(cp.getHitpoints() - 1); this.hitpoints = this.getMaxHitPoints() / 2; StructureBlock hit = CivGlobal.getStructureBlock(coord); onControlBlockCannonDestroy(cp, CivGlobal.getPlayer(resident), hit); CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has been hit by a cannon and a control block was set to " + CannonProjectile.controlBlockHP + " HP!"); CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has regenerated " + this.getMaxHitPoints() / 2 + " HP! If it drops to zero, we will lose another Control Point."); return; } } } CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " is out of hitpoints, walls can be destroyed by cannon and TNT blasts!"); hitpoints = 0; } CivMessage.sendCiv( getCiv(), "Our " + this.getDisplayName() + " has been hit by a cannon! (" + this.hitpoints + "/" + this.getMaxHitPoints() + ")"); }
public static void performMission(ConfigMission mission, String playerName) { Player player; try { player = CivGlobal.getPlayer(playerName); } catch (CivException e1) { return; } try { Resident resident = CivGlobal.getResident(playerName); if (!resident.getTown().getTreasury().hasEnough(mission.cost)) { throw new CivException( "Your town requires " + mission.cost + " coins to perform this mission."); } switch (mission.id) { case "spy_investigate_town": performInvestigateTown(player, mission); break; case "spy_steal_treasury": performStealTreasury(player, mission); break; case "spy_incite_riots": performInciteRiots(player, mission); break; case "spy_poison_granary": performPosionGranary(player, mission); break; case "spy_pirate": performPirate(player, mission); break; case "spy_sabotage": performSabotage(player, mission); break; } } catch (CivException e) { CivMessage.sendError(player, e.getMessage()); } }
@Override public void run() { Player player; try { player = CivGlobal.getPlayer(playerName); } catch (CivException e) { return; } Resident resident = CivGlobal.getResident(playerName); if (resident == null) { return; } CivMessage.send(player, TownCommand.survey(player.getLocation())); CivMessage.send(player, ""); CivMessage.send( player, CivColor.LightGreen + ChatColor.BOLD + CivSettings.localize.localizedString("interactive_capitol_confirmPrompt")); resident.setInteractiveMode(new InteractiveConfirmCivCreation()); }
@EventHandler(priority = EventPriority.MONITOR) public void onChannelChatEvent(ChannelChatEvent event) { Resident resident = CivGlobal.getResident(event.getSender().getName()); if (resident == null) { event.setResult(Result.FAIL); return; } if (!resident.isInteractiveMode()) { if (resident.isMuted()) { event.setResult(Result.MUTED); return; } } if (event.getChannel().getDistance() > 0) { for (String name : Resident.allchatters) { Player player; try { player = CivGlobal.getPlayer(name); } catch (CivException e) { continue; } Chatter you = Herochat.getChatterManager().getChatter(player); if (!event.getSender().isInRange(you, event.getChannel().getDistance())) { player.sendMessage( CivColor.White + event.getSender().getName() + CivSettings.localize.localizedString("hc_prefix_far") + " " + event.getMessage()); } } } }
public void displayQuestion() { Player player; try { player = CivGlobal.getPlayer(playerName); } catch (CivException e) { return; } CivMessage.sendHeading(player, "Mission: " + mission.name); double failChance = MissionBook.getMissionFailChance(mission, target); double compChance = MissionBook.getMissionCompromiseChance(mission, target); DecimalFormat df = new DecimalFormat(); String successChance = df.format((1 - failChance) * 100) + "%"; String compromiseChance = df.format(compChance) + "%"; String length = ""; int mins = mission.length / 60; int seconds = mission.length % 60; if (mins > 0) { length += mins + " mins"; if (seconds > 0) { length += " and "; } } if (seconds > 0) { length += seconds + " seconds"; } CivMessage.send( player, CivColor.Green + CivColor.BOLD + "We have a " + CivColor.LightGreen + successChance + CivColor.Green + CivColor.BOLD + " chance of success."); CivMessage.send( player, CivColor.Green + CivColor.BOLD + "If we fail, the chance of being compromised is " + CivColor.LightGreen + compromiseChance); CivMessage.send( player, CivColor.Green + CivColor.BOLD + "It will cost our town " + CivColor.Yellow + mission.cost + CivColor.Green + CivColor.BOLD + " Coins to perform this mission."); CivMessage.send( player, CivColor.Green + CivColor.BOLD + "The mission will take " + CivColor.Yellow + length + CivColor.Green + CivColor.BOLD + " to complete."); CivMessage.send( player, CivColor.Green + CivColor.BOLD + "You must remain within the civ's borders during the mission, otherwise you'll fail the mission."); CivMessage.send( player, CivColor.Green + CivColor.BOLD + "If these conditions are acceptible, type " + CivColor.Yellow + "yes"); CivMessage.send(player, CivColor.Green + ChatColor.BOLD + "Type anything else to abort."); }
@Override public void respond(String message, Resident resident) { Player player; try { player = CivGlobal.getPlayer(resident); } catch (CivException e) { return; } if (message.equalsIgnoreCase("cancel")) { CivMessage.send(player, CivSettings.localize.localizedString("interactive_capitol_cancel")); resident.clearInteractiveMode(); return; } if (!StringUtils.isAlpha(message) || !StringUtils.isAsciiPrintable(message)) { CivMessage.send( player, CivColor.Rose + ChatColor.BOLD + CivSettings.localize.localizedString("interactive_capitol_invalidname")); return; } message = message.replace(" ", "_"); message = message.replace("\"", ""); message = message.replace("\'", ""); resident.desiredCapitolName = message; CivMessage.send( player, CivColor.LightGreen + CivSettings.localize.localizedString( "var_interactive_capitol_confirm1", CivColor.Yellow + resident.desiredCivName + CivColor.LightGreen, CivColor.Yellow + resident.desiredCapitolName + CivColor.LightGreen)); CivMessage.sendHeading( player, CivSettings.localize.localizedString("interactive_capitol_confirmSurvey")); class SyncTask implements Runnable { String playerName; public SyncTask(String name) { this.playerName = name; } @Override public void run() { Player player; try { player = CivGlobal.getPlayer(playerName); } catch (CivException e) { return; } Resident resident = CivGlobal.getResident(playerName); if (resident == null) { return; } CivMessage.send(player, TownCommand.survey(player.getLocation())); CivMessage.send(player, ""); CivMessage.send( player, CivColor.LightGreen + ChatColor.BOLD + CivSettings.localize.localizedString("interactive_capitol_confirmPrompt")); resident.setInteractiveMode(new InteractiveConfirmCivCreation()); } } TaskMaster.syncTask(new SyncTask(resident.getName())); return; }