FusionSkill.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. effect.increaseEffect();
  55. else
  56. {
  57. L2Skill force = SkillTable.getInstance().getInfo(_fusionId, _fusionLevel);
  58. if (force != null)
  59. force.getEffects(_caster, _target, null);
  60. else
  61. _log.warning("Triggered skill ["+_fusionId+";"+_fusionLevel+"] not found!");
  62. }
  63. _geoCheckTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new GeoCheckTask(), 1000, 1000);
  64. }
  65. public void onCastAbort()
  66. {
  67. _caster.setFusionSkill(null);
  68. L2Effect effect = _target.getFirstEffect(_fusionId);
  69. if (effect != null)
  70. effect.decreaseForce();
  71. _geoCheckTask.cancel(true);
  72. }
  73. public class GeoCheckTask implements Runnable
  74. {
  75. @Override
  76. public void run()
  77. {
  78. try
  79. {
  80. if (!Util.checkIfInRange(_skillCastRange, _caster, _target, true))
  81. _caster.abortCast();
  82. if (!GeoData.getInstance().canSeeTarget(_caster, _target))
  83. _caster.abortCast();
  84. }
  85. catch (Exception e)
  86. {
  87. // ignore
  88. }
  89. }
  90. }
  91. }