Beispiel #1
0
  @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;
    }
  }
Beispiel #2
0
 @Override
 public void run() {
   try {
     createTradeGood();
   } catch (CivException e) {
     e.printStackTrace();
   }
 }
Beispiel #3
0
  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());
    }
  }
Beispiel #4
0
  @Override
  public void onDamage(
      EntityCreature e,
      DamageSource damagesource,
      PathfinderGoalSelector goalSelector,
      PathfinderGoalSelector targetSelector) {

    if (!(damagesource instanceof EntityDamageSource)) {
      return;
    }

    if (this.getLevel() == null) {
      this.setLevel(MobSpawner.CustomMobLevel.valueOf(getData("level")));
      if (this.getLevel() == null) {
        try {
          throw new CivException("Level was null after retry.");
        } catch (CivException e2) {
          CivLog.error("getData(level):" + getData("level"));
          e2.printStackTrace();
        }
      }
    }

    if (!angry) {
      angry = true;
      goalSelector.a(2, new PathfinderGoalMeleeAttack(e, EntityHuman.class, 1.0D, false));
      for (int i = 0; i < 4; i++) {
        try {
          this.minions.add(
              MobSpawner.spawnCustomMob(
                      MobSpawner.CustomMobType.ANGRYYOBO, this.getLevel(), getLocation(e))
                  .entity);
        } catch (CivException e1) {
          e1.printStackTrace();
        }
      }
    }
  }
Beispiel #5
0
  @Override
  public void onInteract(PlayerInteractEvent event) {

    try {

      if (War.isWarTime()) {
        throw new CivException("Cannot use spy missions during war time.");
      }

      ConfigMission mission = CivSettings.missions.get(this.getId());
      if (mission == null) {
        throw new CivException("Unknown mission " + this.getId());
      }

      Resident resident = CivGlobal.getResident(event.getPlayer());
      if (resident == null || !resident.hasTown()) {
        throw new CivException("Only residents of towns can perform spy missions.");
      }

      Date now = new Date();

      if (!event.getPlayer().isOp()) {
        try {
          int spyRegisterTime =
              CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_register_time");
          int spyOnlineTime =
              CivSettings.getInteger(CivSettings.espionageConfig, "espionage.spy_online_time");

          long expire = resident.getRegistered() + (spyRegisterTime * 60 * 1000);
          if (now.getTime() <= expire) {
            throw new CivException(
                "You cannot use a spy yet, you must play CivCraft a bit longer before you can use it.");
          }

          expire = resident.getLastOnline() + (spyOnlineTime * 60 * 1000);
          if (now.getTime() <= expire) {
            throw new CivException("You must be online longer before you can use a spy.");
          }
        } catch (InvalidConfiguration e) {
          e.printStackTrace();
        }
      }

      ConfigUnit unit = Unit.getPlayerUnit(event.getPlayer());
      if (unit == null || !unit.id.equals("u_spy")) {
        event.getPlayer().getInventory().remove(event.getItem());
        throw new CivException("Only spies can use mission books.");
      }

      ChunkCoord coord = new ChunkCoord(event.getPlayer().getLocation());
      CultureChunk cc = CivGlobal.getCultureChunk(coord);
      TownChunk tc = CivGlobal.getTownChunk(coord);

      if (cc == null || cc.getCiv() == resident.getCiv()) {
        throw new CivException(
            "You must be in a civilization's culture that's not your own to spy on them.");
      }

      if ((cc != null && cc.getCiv().isAdminCiv())
          || (tc != null && tc.getTown().getCiv().isAdminCiv())) {
        throw new CivException("You cannot spy on an admin civ.");
      }

      if (CivGlobal.isCasualMode()) {
        if (!cc.getCiv().getDiplomacyManager().isHostileWith(resident.getCiv())
            && !cc.getCiv().getDiplomacyManager().atWarWith(resident.getCiv())) {
          throw new CivException(
              "You must be hostile or at war with "
                  + cc.getCiv().getName()
                  + " in order to perform spy missions in casual mode.");
        }
      }

      resident.setInteractiveMode(
          new InteractiveSpyMission(
              mission, event.getPlayer().getName(), event.getPlayer().getLocation(), cc.getTown()));
    } catch (CivException e) {
      CivMessage.sendError(event.getPlayer(), e.getMessage());
    }
  }
Beispiel #6
0
  public void createGoodieItemFrame(BlockCoord absCoord, int slotId, int direction) {
    if (slotId >= MAX_GOODIE_FRAMES) {
      return;
    }

    /*
     * Make sure there isn't another frame here. We have the position of the sign, but the entity's
     * position is the block it's attached to. We'll use the direction from the sign data to determine
     * which direction to look for the entity.
     */
    Block attachedBlock;
    BlockFace facingDirection;

    switch (direction) {
      case CivData.DATA_SIGN_EAST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.WEST);
        facingDirection = BlockFace.EAST;
        break;
      case CivData.DATA_SIGN_WEST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.EAST);
        facingDirection = BlockFace.WEST;
        break;
      case CivData.DATA_SIGN_NORTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.SOUTH);
        facingDirection = BlockFace.NORTH;
        break;
      case CivData.DATA_SIGN_SOUTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.NORTH);
        facingDirection = BlockFace.SOUTH;
        break;
      default:
        CivLog.error("Bad sign data for /itemframe sign in town hall.");
        return;
    }

    Block itemFrameBlock = absCoord.getBlock();
    if (ItemManager.getId(itemFrameBlock) != CivData.AIR) {
      ItemManager.setTypeId(itemFrameBlock, CivData.AIR);
    }

    ItemFrameStorage itemStore;
    ItemFrame frame = null;
    Entity entity = CivGlobal.getEntityAtLocation(absCoord.getBlock().getLocation());
    if (entity == null || (!(entity instanceof ItemFrame))) {
      itemStore = new ItemFrameStorage(attachedBlock.getLocation(), facingDirection);
    } else {
      try {
        frame = (ItemFrame) entity;
        itemStore = new ItemFrameStorage(frame, attachedBlock.getLocation());
      } catch (CivException e) {
        e.printStackTrace();
        return;
      }
      if (facingDirection != BlockFace.EAST) {
        itemStore.setFacingDirection(facingDirection);
      }
    }

    itemStore.setBuildable(this);
    goodieFrames.add(itemStore);
  }