FusionSkill.java 2.8 KB

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