コード例 #1
0
  public void bankrupt_cmd() throws CivException {
    Civilization civ = getNamedCiv(1);

    if (args.length < 3) {
      CivMessage.send(
          sender,
          CivColor.Yellow
              + ChatColor.BOLD
              + CivSettings.localize.localizedString("adcmd_civ_bankruptConfirmPrompt"));
      CivMessage.send(sender, CivSettings.localize.localizedString("adcmd_civ_bankruptConfirmCmd"));
    }

    civ.getTreasury().setBalance(0);

    for (Town town : civ.getTowns()) {
      town.getTreasury().setBalance(0);
      town.save();

      for (Resident resident : town.getResidents()) {
        resident.getTreasury().setBalance(0);
        resident.save();
      }
    }

    civ.save();
    CivMessage.sendSuccess(
        sender,
        CivSettings.localize.localizedString("var_adcmd_civ_bankruptSuccess", civ.getName()));
  }
コード例 #2
0
 private void showPermCmdHelp() {
   CivMessage.send(
       sender, CivColor.LightGray + CivSettings.localize.localizedString("cmd_plot_perm_help1"));
   CivMessage.send(
       sender,
       CivColor.LightGray + "    " + CivSettings.localize.localizedString("cmd_plot_perm_help2"));
   CivMessage.send(
       sender,
       CivColor.LightGray + "    " + CivSettings.localize.localizedString("cmd_plot_perm_help3"));
 }
コード例 #3
0
ファイル: TownHall.java プロジェクト: help3r/CivCraft
  @Override
  public void onDamage(
      int amount, World world, Player player, BlockCoord coord, BuildableDamageBlock hit) {

    ControlPoint cp = this.controlPoints.get(coord);
    Resident resident = CivGlobal.getResident(player);

    if (!resident.canDamageControlBlock()) {
      CivMessage.send(
          player,
          CivColor.Rose
              + "Cannot damage control blocks due to missing/invalid Town Hall or Capitol structure.");
      return;
    }

    if (cp != null) {
      if (!cp.isDestroyed()) {

        if (resident.isControlBlockInstantBreak()) {
          cp.damage(cp.getHitpoints());
        } else {
          cp.damage(amount);
        }

        if (cp.isDestroyed()) {
          onControlBlockDestroy(cp, world, player, (StructureBlock) hit);
        } else {
          onControlBlockHit(cp, world, player, (StructureBlock) hit);
        }
      } else {
        CivMessage.send(player, CivColor.Rose + "Control Block already destroyed.");
      }

    } else {
      CivMessage.send(
          player,
          CivColor.Rose
              + "Cannot Damage "
              + this.getDisplayName()
              + ", go after the control points!");
    }
  }
コード例 #4
0
      @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());
      }
コード例 #5
0
ファイル: TownHall.java プロジェクト: help3r/CivCraft
  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!");
  }
コード例 #6
0
ファイル: MissionBook.java プロジェクト: JonnyD/civcraft
  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());
    }
  }
コード例 #7
0
  public void markAsUsed(Resident resident) {
    this.getParent().count--;
    if (this.getParent().count <= 0) {
      resident.perks.remove(this.getParent().getIdent());
    }

    try {
      CivGlobal.perkManager.markAsUsed(resident, this.getParent());
    } catch (SQLException e) {
      e.printStackTrace();
    } catch (NotVerifiedException e) {
      CivMessage.send(
          resident,
          CivColor.Rose + CivSettings.localize.localizedString("PerkComponent_notValidated"));
      e.printStackTrace();
    }
  }
コード例 #8
0
  @Override
  public void run() {

    for (Resident resident : CivGlobal.getResidents()) {
      if (!resident.isProtected()) {
        continue;
      }

      int mins;
      try {
        mins = CivSettings.getInteger(CivSettings.civConfig, "global.pvp_timer");
        if (DateUtil.isAfterMins(new Date(resident.getRegistered()), mins)) {
          // if (DateUtil.isAfterSeconds(new Date(resident.getRegistered()), mins)) {
          resident.setisProtected(false);
          CivMessage.send(
              resident, CivColor.LightGray + CivSettings.localize.localizedString("pvpTimerEnded"));
        }
      } catch (InvalidConfiguration e) {
        e.printStackTrace();
        return;
      }
    }
  }
コード例 #9
0
  @Override
  public void run() {

    if (playerName == null) {
      return;
    }
    Player player = Bukkit.getPlayer(playerName);
    if (dmgBlock.allowDamageNow(player)) {
      /* Do our damage. */
      int damage = 1;
      LoreMaterial material = LoreMaterial.getMaterial(player.getItemInHand());
      if (material != null) {
        damage = material.onStructureBlockBreak(dmgBlock, damage);
      }

      if (player.getItemInHand() != null
          && !player.getItemInHand().getType().equals(Material.AIR)) {
        AttributeUtil attrs = new AttributeUtil(player.getItemInHand());
        for (LoreEnhancement enhance : attrs.getEnhancements()) {
          damage = enhance.onStructureBlockBreak(dmgBlock, damage);
        }
      }

      if (damage > 1) {
        CivMessage.send(
            player, CivColor.LightGray + "Punchout does " + (damage - 1) + " extra damage!");
      }

      dmgBlock.getOwner().onDamage(damage, world, player, dmgBlock.getCoord(), dmgBlock);
    } else {
      CivMessage.sendErrorNoRepeat(
          player,
          "This block belongs to a "
              + dmgBlock.getOwner().getDisplayName()
              + " and cannot be destroyed right now.");
    }
  }
コード例 #10
0
  @Override
  public void onDefense(EntityDamageByEntityEvent event) {
    double damage = event.getDamage();

    damage -= this.defense;
    if (damage < 0.5) {
      damage = 0.0;

      Player player = null;
      if (event.getDamager() instanceof Arrow) {
        Arrow arrow = (Arrow) event.getDamager();
        if (arrow.getShooter() instanceof Player) {
          player = (Player) arrow.getShooter();
        }
      } else if (event.getDamager() instanceof Player) {
        player = (Player) event.getDamager();
      }

      if (player != null) {
        CivMessage.send(player, CivColor.LightGray + "Our attack was ineffective");
      }
    }
    event.setDamage(damage);
  }
コード例 #11
0
  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.");
  }
コード例 #12
0
ファイル: MissionBook.java プロジェクト: JonnyD/civcraft
  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!");
    }
  }
コード例 #13
0
ファイル: MissionBook.java プロジェクト: JonnyD/civcraft
  private static void performSabotage(Player player, ConfigMission mission) throws CivException {
    Resident resident = CivGlobal.getResident(player);

    // 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.
    Buildable buildable = cc.getTown().getNearestBuildable(player.getLocation());
    if (buildable instanceof TownHall) {
      throw new CivException("Nearest structure is a town hall which cannot be destroyed.");
    }
    if (buildable instanceof Wonder) {
      if (buildable.isComplete()) {
        throw new CivException("Cannot sabotage completed wonders.");
      }
    }

    double distance = player.getLocation().distance(buildable.getCorner().getLocation());
    if (distance > mission.range) {
      throw new CivException("Too far away the " + buildable.getDisplayName() + " to sabotage it");
    }

    if (buildable instanceof Structure) {
      if (!buildable.isComplete()) {
        throw new CivException("Cannot sabotage incomplete structures.");
      }

      if (buildable.isDestroyed()) {
        throw new CivException(buildable.getDisplayName() + " is already destroyed.");
      }
    }

    if (buildable instanceof Wonder) {
      // Create a new mission and with the penalties.
      mission = CivSettings.missions.get("spy_sabotage_wonder");
    }

    double failMod = 1.0;
    if (resident.getTown().getBuffManager().hasBuff("buff_sabotage")) {
      failMod = resident.getTown().getBuffManager().getEffectiveDouble("buff_sabotage");
      CivMessage.send(
          player, CivColor.LightGray + "Your goodie buff 'Sabotage' will come in handy here.");
    }

    if (processMissionResult(player, cc.getTown(), mission, failMod, 1.0)) {
      CivMessage.global(
          CivColor.Yellow
              + "DISASTER!"
              + CivColor.White
              + " A "
              + buildable.getDisplayName()
              + " has been destroyed! Foul play is suspected.");
      buildable.setHitpoints(0);
      buildable.fancyDestroyStructureBlocks();
      buildable.save();

      if (buildable instanceof Wonder) {
        Wonder wonder = (Wonder) buildable;
        wonder.unbindStructureBlocks();
        try {
          wonder.delete();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #14
0
ファイル: MissionBook.java プロジェクト: JonnyD/civcraft
  private static boolean processMissionResult(
      Player player,
      Town target,
      ConfigMission mission,
      double failModifier,
      double compromiseModifier) {

    int fail_rate =
        (int) ((MissionBook.getMissionFailChance(mission, target) * failModifier) * 100);
    int compromise_rate =
        (int)
            ((MissionBook.getMissionCompromiseChance(mission, target) * compromiseModifier) * 100);
    Resident resident = CivGlobal.getResident(player);

    if (resident == null || !resident.hasTown()) {
      return false;
    }

    if (!resident.getTown().getTreasury().hasEnough(mission.cost)) {
      CivMessage.send(
          player,
          CivColor.Rose
              + "Suddenly, your town doesn't have enough cash to follow through with the mission.");
      return false;
    }

    resident.getTown().getTreasury().withdraw(mission.cost);

    Random rand = new Random();
    String result = "";
    int failnext = rand.nextInt(100);
    if (failnext < fail_rate) {
      int next = rand.nextInt(100);
      result += "Failed";

      if (next < compromise_rate) {
        CivMessage.global(
            CivColor.Yellow
                + "INTERNATIONAL INCIDENT!"
                + CivColor.White
                + " "
                + player.getName()
                + " was caught trying to perform a "
                + mission.name
                + " spy mission in "
                + target.getName()
                + "!");
        CivMessage.send(
            player,
            CivColor.Rose
                + "You've been compromised! (Rolled "
                + next
                + " vs "
                + compromise_rate
                + ") Spy unit was destroyed!");
        Unit.removeUnit(player);
        result += ", COMPROMISED";
      }

      MissionLogger.logMission(resident.getTown(), target, player.getName(), mission.name, result);
      CivMessage.send(
          player, CivColor.Rose + "Mission Failed! (Rolled " + failnext + " vs " + fail_rate + ")");
      return false;
    }

    MissionLogger.logMission(resident.getTown(), target, player.getName(), mission.name, "Success");
    return true;
  }
コード例 #15
0
  @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;
  }