/** * @param State.<br> * 0 - not decided yet<br> * 1 - independent<br> * 2 - contracted with castle<br> * <br> * @param CastleId.<br> * set Castle Id for contracted fort */ public final void setFortState(int state, int castleId) { if (_castleId != 0) { Castle castle = CastleManager.getInstance().getCastleById(_castleId); if (castle != null) castle.removeContractFort(getFortId()); } if (state == 2 && castleId != 0) { Castle castle = CastleManager.getInstance().getCastleById(castleId); if (castle != null) castle.addContractFort(getFortId()); } _state = state; _castleId = castleId; Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement; statement = con.prepareStatement("UPDATE fort SET state=?, castleId=? WHERE id = ?"); statement.setInt(1, getFortState()); statement.setInt(2, getCastleId()); statement.setInt(3, getFortId()); statement.execute(); statement.close(); } catch (Exception e) { _log.warn("Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage(), e); } finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } }
/** Method chanceCycle. */ @Override public void chanceCycle() { super.chanceCycle(); if (getCycle() >= REMOVE_CYCLE) { getOwner() .broadcastToOnlineMembers(SystemMsg.ENEMY_BLOOD_PLEDGES_HAVE_INTRUDED_INTO_THE_FORTRESS); changeOwner(null); return; } setPaidCycle(getPaidCycle() + 1); if ((getPaidCycle() % REWARD_CYCLE) == 0) { setPaidCycle(0); setRewardCount(getRewardCount() + 1); if (getContractState() == CONTRACT_WITH_CASTLE) { Castle castle = ResidenceHolder.getInstance().getResidence(Castle.class, _castleId); if ((castle.getOwner() == null) || (castle.getOwner().getReputationScore() < 2) || (_owner.getWarehouse().getCountOf(ItemTemplate.ITEM_ID_ADENA) > CASTLE_FEE)) { setSupplyCount(0); setFortState(INDEPENDENT, 0); clearFacility(); } else { if (_supplyCount < 6) { castle.getOwner().incReputation(-2, false, "Fortress:chanceCycle():" + getId()); _owner.getWarehouse().destroyItemByItemId(ItemTemplate.ITEM_ID_ADENA, CASTLE_FEE); _supplyCount++; } } } } }
private String getBuildingQuantities(BuildingType buildingType) { int numberOfBuildings = 0; int maxNumberOfBuildings = 0; if (castle != null) { numberOfBuildings = castle.getNumberOfBuildings(buildingType); maxNumberOfBuildings = castle.getMaximumNumberOfBuildings(buildingType); } boolean exceeded = numberOfBuildings > maxNumberOfBuildings; boolean maximum = numberOfBuildings == maxNumberOfBuildings; StringBuilder s = new StringBuilder(); if (exceeded | maximum) s.append("<html>"); if (exceeded) s.append("<font color=\"red\"><b>"); else if (maximum) s.append("<font color=\"#008800\"/>"); s.append(numberOfBuildings); if (exceeded) s.append("</b></font>"); else if (maximum) s.append("</font>"); s.append('/'); s.append(maxNumberOfBuildings); if (exceeded | maximum) s.append("</html>"); return s.toString(); }
protected void updateMaximumBuildingsPerAge() { if (castle != null) { castle.setMaxBuildings(); updateBuildingQuantities(); castle.updateDesignStats(); Editor.updateErrorPanel(); } }
private void load() { Connection con = null; try { PreparedStatement statement; ResultSet rs; con = L2DatabaseFactory.getInstance().getConnection(con); statement = con.prepareStatement("SELECT * FROM fort WHERE id = ?"); statement.setInt(1, getFortId()); rs = statement.executeQuery(); while (rs.next()) { _name = rs.getString("name"); _siegeDate = Calendar.getInstance(); _siegeDate.setTimeInMillis(rs.getLong("siegeDate")); _lastOwnedTime = rs.getLong("lastOwnedTime"); _ownerId = rs.getInt("owner"); _fortType = rs.getInt("fortType"); _state = rs.getInt("state"); _castleId = rs.getInt("castleId"); } rs.close(); statement.close(); if (_ownerId > 0) { L2Clan clan = ClanTable.getInstance().getClan(_ownerId); // Try to find clan instance if (clan != null) { setOwnerClan(clan); clan.setHasFort(getFortId()); ThreadPoolManager.getInstance() .scheduleGeneral( new FortUpdater(clan, 1), 3600000); // Schedule owner tasks to start running } else setOwnerClan(null); } else setOwnerClan(null); if (_state == 2 && _castleId != 0) { Castle castle = CastleManager.getInstance().getCastleById(_castleId); if (castle != null) castle.addContractFort(getFortId()); } } catch (Exception e) { _log.warn("Exception: loadFortData(): " + e.getMessage(), e); } finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } }
public void loadDiary(int charId) { final List<StatsSet> _diary = new FastList<>(); int diaryentries = 0; try (Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT * FROM heroes_diary WHERE charId=? ORDER BY time ASC")) { statement.setInt(1, charId); try (ResultSet rset = statement.executeQuery()) { while (rset.next()) { StatsSet _diaryentry = new StatsSet(); long time = rset.getLong("time"); int action = rset.getInt("action"); int param = rset.getInt("param"); String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(time)); _diaryentry.set("date", date); if (action == ACTION_RAID_KILLED) { L2NpcTemplate template = NpcData.getInstance().getTemplate(param); if (template != null) { _diaryentry.set("action", template.getName() + " was defeated"); } } else if (action == ACTION_HERO_GAINED) { _diaryentry.set("action", "Gained Hero status"); } else if (action == ACTION_CASTLE_TAKEN) { Castle castle = CastleManager.getInstance().getCastleById(param); if (castle != null) { _diaryentry.set("action", castle.getName() + " Castle was successfuly taken"); } } _diary.add(_diaryentry); diaryentries++; } } _herodiary.put(charId, _diary); _log.info( "Hero System: Loaded " + diaryentries + " diary entries for Hero: " + CharNameTable.getInstance().getNameById(charId)); } catch (SQLException e) { _log.log(Level.WARNING, "Hero System: Couldnt load Hero Diary for CharId: " + charId, e); } }
private void updateTotalBuildingTime() { if (castle != null) { int researchDiscount = constructionBonuses[constructionSpeed.getValue()]; int buildingTime = (int) (castle.getTotalBuildingTime() * (1 - (((double) researchDiscount) / 100))); timeLabel.setText(formatTime(buildingTime)); } else timeLabel.setText("0s"); }
public void setCastleTaken(int charId, int castleId) { setDiaryData(charId, ACTION_CASTLE_TAKEN, castleId); Castle castle = CastleManager.getInstance().getCastleById(castleId); if ((castle != null) && _herodiary.containsKey(charId)) { // Get Data List<StatsSet> _list = _herodiary.get(charId); // Clear old data _herodiary.remove(charId); // Prepare new data StatsSet _diaryentry = new StatsSet(); String date = (new SimpleDateFormat("yyyy-MM-dd HH")).format(new Date(System.currentTimeMillis())); _diaryentry.set("date", date); _diaryentry.set("action", castle.getName() + " Castle was successfuly taken"); // Add to old list _list.add(_diaryentry); // Put new list into diary _herodiary.put(charId, _list); } }
/** * Method changeOwner. * * @param clan Clan */ @Override public void changeOwner(Clan clan) { if (clan != null) { if (clan.getHasFortress() != 0) { Fortress oldFortress = ResidenceHolder.getInstance().getResidence(Fortress.class, clan.getHasFortress()); if (oldFortress != null) { oldFortress.changeOwner(null); } } if (clan.getCastle() != 0) { Castle oldCastle = ResidenceHolder.getInstance().getResidence(Castle.class, clan.getCastle()); if (oldCastle != null) { oldCastle.changeOwner(null); } } } if ((getOwnerId() > 0) && ((clan == null) || (clan.getClanId() != getOwnerId()))) { removeSkills(); Clan oldOwner = getOwner(); if (oldOwner != null) { oldOwner.setHasFortress(0); } cancelCycleTask(); clearFacility(); } if (clan != null) { clan.setHasFortress(getId()); } updateOwnerInDB(clan); rewardSkills(); setFortState(NOT_DECIDED, 0); setJdbcState(JdbcEntityState.UPDATED); update(); }
/** * Constructs a new game by parsing given array of string as an array of FEN primitives. * * <p>FEN parsing is permissive and uses best-effort approach i.e. anything, that is salvaged of * given input, is used as best as possible, and for the rest, reasonable default values are * assumed. * * @param fenArray An array of FEN primitives used to initialize a game. Only the six first array * elements are used and the are discarded if provided. */ public Chess(String[] fenArray) { turn = true; enpassant = null; halfmove = 0; fullmove = 1; if (fenArray.length >= 4) { try { enpassant = new Coord(fenArray[3]); } catch (Exception pass) { } } if (fenArray.length >= 1) { board = new Board(fenArray[0], enpassant); } else { board = new Board(); } if (fenArray.length >= 2) { if (fenArray[1].equals("b")) { turn = false; } } if (fenArray.length >= 3) { castling = new Castle(fenArray[2]); } else { castling = new Castle(); } castling.crop(board.getState()); if (fenArray.length >= 6) { try { halfmove = Integer.parseInt(fenArray[4]); fullmove = Integer.parseInt(fenArray[5]); } catch (NumberFormatException pass) { } } }
/** * Make a move. * * @param algebraic Move in Algebraic chess notation. * @throws MoveException If move cannot be executed. */ public void move(String algebraic) throws MoveException { Rebound rebound; Move move = new Move(algebraic, turn); if (move.isCastling()) { /* Castlings are tricky and handled separately */ rebound = board.castling(move, castling); } else { /* If no need to castle, then a regular move */ rebound = board.move(move, enpassant); } if (turn) { turn = false; } else { turn = true; fullmove++; } castling.disable(rebound.castlingObstacle()); enpassant = rebound.getEnpassant(); checked = rebound.isKingChecked(); /* The fifty-move rule: a player can claim a draw if no capture * has been made and no pawn has been moved in the last 50 * consecutive moves. * * So, if halfmove counter hits 100, aforementioned condition * becomes true. */ if (move.isCapturing() || move.piece().isPawn()) { halfmove = 0; } else { halfmove++; } }
private String getBuildingResources(BuildingResource buildingResource) { if (castle != null) { return String.valueOf(castle.getTotalResource(buildingResource)); } else return "0"; }
/** @return a string of castling possibilities or a dash. */ public String getCastling() { return castling.toString(); }