SummonCubic.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.effecthandlers;
  20. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.effects.EffectTemplate;
  23. import com.l2jserver.gameserver.model.effects.L2Effect;
  24. import com.l2jserver.gameserver.model.effects.L2EffectType;
  25. import com.l2jserver.gameserver.model.stats.Env;
  26. import com.l2jserver.util.Rnd;
  27. /**
  28. * Summon Cubic effect implementation.
  29. * @author Zoey76
  30. */
  31. public class SummonCubic extends L2Effect
  32. {
  33. private final int _npcId;
  34. /** Cubic power. */
  35. private final int _cubicPower;
  36. /** Cubic duration. */
  37. private final int _cubicDuration;
  38. /** Cubic activation delay. */
  39. private final int _cubicDelay;
  40. /** Cubic maximum casts before going idle. */
  41. private final int _cubicMaxCount;
  42. /** Cubic activation chance. */
  43. private final int _cubicSkillChance;
  44. public SummonCubic(Env env, EffectTemplate template)
  45. {
  46. super(env, template);
  47. _npcId = template.getParameters().getInteger("npcId", 0);
  48. // Custom AI data.
  49. _cubicPower = template.getParameters().getInteger("cubicPower", 0);
  50. _cubicDuration = template.getParameters().getInteger("cubicDuration", 0);
  51. _cubicDelay = template.getParameters().getInteger("cubicDelay", 0);
  52. _cubicMaxCount = template.getParameters().getInteger("cubicMaxCount", -1);
  53. _cubicSkillChance = template.getParameters().getInteger("cubicSkillChance", 0);
  54. }
  55. @Override
  56. public L2EffectType getEffectType()
  57. {
  58. return L2EffectType.NONE;
  59. }
  60. @Override
  61. public boolean isInstant()
  62. {
  63. return true;
  64. }
  65. @Override
  66. public boolean onStart()
  67. {
  68. if ((getEffected() == null) || !getEffected().isPlayer() || getEffected().isAlikeDead() || getEffected().getActingPlayer().inObserverMode())
  69. {
  70. return false;
  71. }
  72. if (_npcId <= 0)
  73. {
  74. _log.warning(SummonCubic.class.getSimpleName() + ": Invalid NPC Id:" + _npcId + " in skill Id: " + getSkill().getId());
  75. return false;
  76. }
  77. final L2PcInstance player = getEffected().getActingPlayer();
  78. if (player.inObserverMode() || player.isMounted())
  79. {
  80. return false;
  81. }
  82. // Gnacik: TODO: Make better method of calculation.
  83. // If skill is enchanted calculate cubic skill level based on enchant
  84. // 8 at 101 (+1 Power)
  85. // 12 at 130 (+30 Power)
  86. // Because 12 is max 5115-5117 skills
  87. int _cubicSkillLevel = getSkill().getLevel();
  88. if (_cubicSkillLevel > 100)
  89. {
  90. _cubicSkillLevel = ((getSkill().getLevel() - 100) / 7) + 8;
  91. }
  92. // If cubic is already present, it's replaced.
  93. final L2CubicInstance cubic = player.getCubicById(_npcId);
  94. if (cubic != null)
  95. {
  96. cubic.stopAction();
  97. cubic.cancelDisappear();
  98. player.getCubics().remove(cubic);
  99. }
  100. else
  101. {
  102. // If maximum amount is reached, random cubic is removed.
  103. final L2Effect cubicMastery = player.getFirstPassiveEffect(L2EffectType.CUBIC_MASTERY);
  104. final int cubicCount = (int) (cubicMastery != null ? cubicMastery.calc() : 0);
  105. if (player.getCubics().size() > cubicCount)
  106. {
  107. player.getCubics().remove(Rnd.get(player.getCubics().size()));
  108. }
  109. }
  110. player.addCubic(_npcId, _cubicSkillLevel, _cubicPower, _cubicDelay, _cubicSkillChance, _cubicMaxCount, _cubicDuration, getEffected() != getEffector());
  111. player.broadcastUserInfo();
  112. return true;
  113. }
  114. }