2
0

FortUpdater.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 L2Clan _clan;
  30. private Fort _fort;
  31. private int _runCount;
  32. private 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. return;
  56. _fort.setBloodOathReward(_fort.getBloodOathReward() + Config.FS_BLOOD_OATH_COUNT);
  57. if (_fort.getFortState() == 2)
  58. {
  59. if (_clan.getWarehouse().getAdena() >= Config.FS_FEE_FOR_CASTLE)
  60. {
  61. _clan.getWarehouse().destroyItemByItemId("FS_fee_for_Castle", PcInventory.ADENA_ID, Config.FS_FEE_FOR_CASTLE, null, null);
  62. CastleManager.getInstance().getCastleById(_fort.getCastleId()).addToTreasuryNoTax(Config.FS_FEE_FOR_CASTLE);
  63. _fort.raiseSupplyLvL();
  64. }
  65. else
  66. _fort.setFortState(1, 0);
  67. }
  68. _fort.saveFortVariables();
  69. break;
  70. case MAX_OWN_TIME:
  71. if (_fort.getOwnerClan() == null || _fort.getOwnerClan() != _clan)
  72. return;
  73. if (_fort.getOwnedTime() > Config.FS_MAX_OWN_TIME * 3600)
  74. {
  75. _fort.removeOwner(true);
  76. _fort.setFortState(0, 0);
  77. }
  78. break;
  79. }
  80. }
  81. catch (Exception e)
  82. {
  83. _log.log(Level.WARNING, "", e);
  84. }
  85. }
  86. public int getRunCount()
  87. {
  88. return _runCount;
  89. }
  90. }