ForceBuff.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.model;
  16. import java.util.concurrent.Future;
  17. import net.sf.l2j.gameserver.GeoData;
  18. import net.sf.l2j.gameserver.ThreadPoolManager;
  19. import net.sf.l2j.gameserver.datatables.SkillTable;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.skills.effects.EffectForce;
  22. import net.sf.l2j.gameserver.util.Util;
  23. /**
  24. * @author kombat, Forsaiken
  25. */
  26. public final class ForceBuff
  27. {
  28. final int _skillCastRange;
  29. final int _forceId;
  30. L2PcInstance _caster;
  31. L2PcInstance _target;
  32. Future<?> _geoCheckTask;
  33. public L2PcInstance getCaster()
  34. {
  35. return _caster;
  36. }
  37. public L2PcInstance getTarget()
  38. {
  39. return _target;
  40. }
  41. public ForceBuff(L2PcInstance caster, L2PcInstance target, L2Skill skill)
  42. {
  43. _skillCastRange = skill.getCastRange();
  44. _caster = caster;
  45. _target = target;
  46. _forceId = skill.getForceId();
  47. L2Effect effect = _target.getFirstEffect(_forceId);
  48. if (effect != null)
  49. ((EffectForce)effect).increaseForce();
  50. else
  51. SkillTable.getInstance().getInfo(_forceId, 1).getEffects(_caster, _target);
  52. _geoCheckTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new GeoCheckTask(), 1000, 1000);
  53. }
  54. public void delete()
  55. {
  56. _caster.setForceBuff(null);
  57. L2Effect effect = _target.getFirstEffect(_forceId);
  58. if (effect != null)
  59. ((EffectForce)effect).decreaseForce();
  60. _geoCheckTask.cancel(true);
  61. }
  62. class GeoCheckTask implements Runnable
  63. {
  64. public void run()
  65. {
  66. try
  67. {
  68. if (!Util.checkIfInRange(_skillCastRange, _caster, _target, true))
  69. delete();
  70. if (!GeoData.getInstance().canSeeTarget(_caster, _target))
  71. delete();
  72. }
  73. catch (Exception e)
  74. {
  75. // ignore
  76. }
  77. }
  78. }
  79. }