FortUpdater.java 3.0 KB

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