FortUpdater.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  22. /**
  23. * Class managing periodical events with castle
  24. * @author Vice - 2008
  25. */
  26. public class FortUpdater implements Runnable
  27. {
  28. protected static Logger _log = Logger.getLogger(FortUpdater.class.getName());
  29. private final L2Clan _clan;
  30. private final Fort _fort;
  31. private int _runCount;
  32. private final UpdaterType _updaterType;
  33. public enum UpdaterType
  34. {
  35. MAX_OWN_TIME, // gives fort back to NPC clan
  36. PERIODIC_UPDATE // raise blood oath/supply level
  37. }
  38. public FortUpdater(Fort fort, L2Clan clan, int runCount, UpdaterType ut)
  39. {
  40. _fort = fort;
  41. _clan = clan;
  42. _runCount = runCount;
  43. _updaterType = ut;
  44. }
  45. @Override
  46. public void run()
  47. {
  48. try
  49. {
  50. switch (_updaterType)
  51. {
  52. case PERIODIC_UPDATE:
  53. _runCount++;
  54. if ((_fort.getOwnerClan() == null) || (_fort.getOwnerClan() != _clan))
  55. {
  56. return;
  57. }
  58. _fort.setBloodOathReward(_fort.getBloodOathReward() + Config.FS_BLOOD_OATH_COUNT);
  59. if (_fort.getFortState() == 2)
  60. {
  61. if (_clan.getWarehouse().getAdena() >= Config.FS_FEE_FOR_CASTLE)
  62. {
  63. _clan.getWarehouse().destroyItemByItemId("FS_fee_for_Castle", PcInventory.ADENA_ID, Config.FS_FEE_FOR_CASTLE, null, null);
  64. CastleManager.getInstance().getCastleById(_fort.getCastleId()).addToTreasuryNoTax(Config.FS_FEE_FOR_CASTLE);
  65. _fort.raiseSupplyLvL();
  66. }
  67. else
  68. {
  69. _fort.setFortState(1, 0);
  70. }
  71. }
  72. _fort.saveFortVariables();
  73. break;
  74. case MAX_OWN_TIME:
  75. if ((_fort.getOwnerClan() == null) || (_fort.getOwnerClan() != _clan))
  76. {
  77. return;
  78. }
  79. if (_fort.getOwnedTime() > (Config.FS_MAX_OWN_TIME * 3600))
  80. {
  81. _fort.removeOwner(true);
  82. _fort.setFortState(0, 0);
  83. }
  84. break;
  85. }
  86. }
  87. catch (Exception e)
  88. {
  89. _log.log(Level.WARNING, "", e);
  90. }
  91. }
  92. public int getRunCount()
  93. {
  94. return _runCount;
  95. }
  96. }