FortUpdater.java 2.9 KB

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