FortUpdater.java 2.7 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. /**
  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. @Override
  45. public void run()
  46. {
  47. try
  48. {
  49. switch(_updaterType)
  50. {
  51. case PERIODIC_UPDATE:
  52. _runCount++;
  53. if (_fort.getOwnerClan() == null || _fort.getOwnerClan() != _clan)
  54. return;
  55. _fort.setBloodOathReward(_fort.getBloodOathReward() + Config.FS_BLOOD_OATH_COUNT);
  56. if (_fort.getFortState() == 2)
  57. {
  58. if (_clan.getWarehouse().getAdena() >= Config.FS_FEE_FOR_CASTLE)
  59. {
  60. _clan.getWarehouse().destroyItemByItemId("FS_fee_for_Castle", 57, Config.FS_FEE_FOR_CASTLE, null, null);
  61. CastleManager.getInstance().getCastleById(_fort.getCastleId()).addToTreasuryNoTax(Config.FS_FEE_FOR_CASTLE);
  62. _fort.raiseSupplyLvL();
  63. }
  64. else
  65. _fort.setFortState(1, 0);
  66. }
  67. _fort.saveFortVariables();
  68. break;
  69. case MAX_OWN_TIME:
  70. if (_fort.getOwnerClan() == null || _fort.getOwnerClan() != _clan)
  71. return;
  72. if (_fort.getOwnedTime() > Config.FS_MAX_OWN_TIME * 3600)
  73. {
  74. _fort.removeOwner(true);
  75. _fort.setFortState(0, 0);
  76. }
  77. break;
  78. }
  79. }
  80. catch (Exception e)
  81. {
  82. _log.log(Level.WARNING, "", e);
  83. }
  84. }
  85. public int getRunCount()
  86. {
  87. return _runCount;
  88. }
  89. }