FusionSkill.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 com.l2jserver.gameserver.model;
  16. import java.util.concurrent.Future;
  17. import java.util.logging.Logger;
  18. import com.l2jserver.gameserver.GeoData;
  19. import com.l2jserver.gameserver.ThreadPoolManager;
  20. import com.l2jserver.gameserver.datatables.SkillTable;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.effects.L2Effect;
  23. import com.l2jserver.gameserver.model.skills.L2Skill;
  24. import com.l2jserver.gameserver.util.Util;
  25. /**
  26. * @author kombat, Forsaiken
  27. */
  28. public final class FusionSkill
  29. {
  30. protected static final Logger _log = Logger.getLogger(FusionSkill.class.getName());
  31. protected int _skillCastRange;
  32. protected int _fusionId;
  33. protected int _fusionLevel;
  34. protected L2Character _caster;
  35. protected L2Character _target;
  36. protected Future<?> _geoCheckTask;
  37. public L2Character getCaster()
  38. {
  39. return _caster;
  40. }
  41. public L2Character getTarget()
  42. {
  43. return _target;
  44. }
  45. public FusionSkill(L2Character caster, L2Character target, L2Skill skill)
  46. {
  47. _skillCastRange = skill.getCastRange();
  48. _caster = caster;
  49. _target = target;
  50. _fusionId = skill.getTriggeredId();
  51. _fusionLevel = skill.getTriggeredLevel();
  52. L2Effect effect = _target.getFirstEffect(_fusionId);
  53. if (effect != null)
  54. {
  55. effect.increaseEffect();
  56. }
  57. else
  58. {
  59. L2Skill force = SkillTable.getInstance().getInfo(_fusionId, _fusionLevel);
  60. if (force != null)
  61. {
  62. force.getEffects(_caster, _target, null);
  63. }
  64. else
  65. {
  66. _log.warning("Triggered skill [" + _fusionId + ";" + _fusionLevel + "] not found!");
  67. }
  68. }
  69. _geoCheckTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new GeoCheckTask(), 1000, 1000);
  70. }
  71. public void onCastAbort()
  72. {
  73. _caster.setFusionSkill(null);
  74. L2Effect effect = _target.getFirstEffect(_fusionId);
  75. if (effect != null)
  76. {
  77. effect.decreaseForce();
  78. }
  79. _geoCheckTask.cancel(true);
  80. }
  81. public class GeoCheckTask implements Runnable
  82. {
  83. @Override
  84. public void run()
  85. {
  86. try
  87. {
  88. if (!Util.checkIfInRange(_skillCastRange, _caster, _target, true))
  89. {
  90. _caster.abortCast();
  91. }
  92. if (!GeoData.getInstance().canSeeTarget(_caster, _target))
  93. {
  94. _caster.abortCast();
  95. }
  96. }
  97. catch (Exception e)
  98. {
  99. // ignore
  100. }
  101. }
  102. }
  103. }