FusionSkill.java 3.0 KB

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