FortUpdater.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* This program is free software: you can redistribute it and/or modify it under
  2. * the terms of the GNU General Public License as published by the Free Software
  3. * Foundation, either version 3 of the License, or (at your option) any later
  4. * version.
  5. *
  6. * This program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  9. * details.
  10. *
  11. * You should have received a copy of the GNU General Public License along with
  12. * this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. package com.l2jserver.gameserver;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.instancemanager.CastleManager;
  19. import com.l2jserver.gameserver.model.L2Clan;
  20. import com.l2jserver.gameserver.model.entity.Fort;
  21. /**
  22. * Class managing periodical events with castle
  23. * @author Vice - 2008
  24. */
  25. public class FortUpdater implements Runnable
  26. {
  27. protected static Logger _log = Logger.getLogger(FortUpdater.class.getName());
  28. private L2Clan _clan;
  29. private Fort _fort;
  30. private int _runCount;
  31. private UpdaterType _updaterType;
  32. public enum UpdaterType
  33. {
  34. MAX_OWN_TIME, // gives fort back to NPC clan
  35. PERIODIC_UPDATE // raise blood oath/supply level
  36. }
  37. public FortUpdater(Fort fort, L2Clan clan, int runCount, UpdaterType ut)
  38. {
  39. _fort = fort;
  40. _clan = clan;
  41. _runCount = runCount;
  42. _updaterType = ut;
  43. }
  44. public void run()
  45. {
  46. try
  47. {
  48. switch(_updaterType)
  49. {
  50. case PERIODIC_UPDATE:
  51. _runCount++;
  52. if (_fort.getOwnerClan() == null || _fort.getOwnerClan() != _clan)
  53. return;
  54. _fort.setBloodOathReward(_fort.getBloodOathReward() + Config.FS_BLOOD_OATH_COUNT);
  55. if (_fort.getFortState() == 2)
  56. {
  57. if (_clan.getWarehouse().getAdena() >= Config.FS_FEE_FOR_CASTLE)
  58. {
  59. _clan.getWarehouse().destroyItemByItemId("FS_fee_for_Castle", 57, Config.FS_FEE_FOR_CASTLE, null, null);
  60. CastleManager.getInstance().getCastleById(_fort.getCastleId()).addToTreasuryNoTax(Config.FS_FEE_FOR_CASTLE);
  61. _fort.raiseSupplyLvL();
  62. }
  63. else
  64. _fort.setFortState(1, 0);
  65. }
  66. _fort.saveFortVariables();
  67. break;
  68. case MAX_OWN_TIME:
  69. if (_fort.getOwnerClan() == null || _fort.getOwnerClan() != _clan)
  70. return;
  71. if (_fort.getOwnedTime() > Config.FS_MAX_OWN_TIME * 3600)
  72. {
  73. _fort.removeOwner(true);
  74. _fort.setFortState(0, 0);
  75. }
  76. break;
  77. }
  78. }
  79. catch (Exception e)
  80. {
  81. _log.log(Level.WARNING, "", e);
  82. }
  83. }
  84. public int getRunCount()
  85. {
  86. return _runCount;
  87. }
  88. }