SummonCubic.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /** Cubic ID. */
  34. private final int _cubicId;
  35. /** Cubic power. */
  36. private final int _cubicPower;
  37. /** Cubic duration. */
  38. private final int _cubicDuration;
  39. /** Cubic activation delay. */
  40. private final int _cubicDelay;
  41. /** Cubic maximum casts before going idle. */
  42. private final int _cubicMaxCount;
  43. /** Cubic activation chance. */
  44. private final int _cubicSkillChance;
  45. public SummonCubic(Env env, EffectTemplate template)
  46. {
  47. super(env, template);
  48. _cubicId = template.getParameters().getInt("cubicId", -1);
  49. // Custom AI data.
  50. _cubicPower = template.getParameters().getInt("cubicPower", 0);
  51. _cubicDuration = template.getParameters().getInt("cubicDuration", 0);
  52. _cubicDelay = template.getParameters().getInt("cubicDelay", 0);
  53. _cubicMaxCount = template.getParameters().getInt("cubicMaxCount", -1);
  54. _cubicSkillChance = template.getParameters().getInt("cubicSkillChance", 0);
  55. }
  56. @Override
  57. public L2EffectType getEffectType()
  58. {
  59. return L2EffectType.NONE;
  60. }
  61. @Override
  62. public boolean isInstant()
  63. {
  64. return true;
  65. }
  66. @Override
  67. public boolean onStart()
  68. {
  69. if ((getEffected() == null) || !getEffected().isPlayer() || getEffected().isAlikeDead() || getEffected().getActingPlayer().inObserverMode())
  70. {
  71. return false;
  72. }
  73. if (_cubicId < 0)
  74. {
  75. _log.warning(SummonCubic.class.getSimpleName() + ": Invalid Cubic Id:" + _cubicId + " in skill Id: " + getSkill().getId());
  76. return false;
  77. }
  78. final L2PcInstance player = getEffected().getActingPlayer();
  79. if (player.inObserverMode() || player.isMounted())
  80. {
  81. return false;
  82. }
  83. // Gnacik: TODO: Make better method of calculation.
  84. // If skill is enchanted calculate cubic skill level based on enchant
  85. // 8 at 101 (+1 Power)
  86. // 12 at 130 (+30 Power)
  87. // Because 12 is max 5115-5117 skills
  88. int _cubicSkillLevel = getSkill().getLevel();
  89. if (_cubicSkillLevel > 100)
  90. {
  91. _cubicSkillLevel = ((getSkill().getLevel() - 100) / 7) + 8;
  92. }
  93. // If cubic is already present, it's replaced.
  94. final L2CubicInstance cubic = player.getCubicById(_cubicId);
  95. if (cubic != null)
  96. {
  97. cubic.stopAction();
  98. cubic.cancelDisappear();
  99. player.getCubics().remove(_cubicId);
  100. }
  101. else
  102. {
  103. // If maximum amount is reached, random cubic is removed.
  104. final L2Effect cubicMastery = player.getFirstPassiveEffect(L2EffectType.CUBIC_MASTERY);
  105. // Players with no mastery can have only one cubic.
  106. final int allowedCubicCount = (int) (cubicMastery != null ? cubicMastery.calc() : 1);
  107. final int currentCubicCount = player.getCubics().size();
  108. // Extra cubics are removed, one by one, randomly.
  109. for (int i = 0; i <= (currentCubicCount - allowedCubicCount); i++)
  110. {
  111. final int removedCubicId = (int) player.getCubics().keySet().toArray()[Rnd.get(currentCubicCount)];
  112. final L2CubicInstance removedCubic = player.getCubicById(removedCubicId);
  113. removedCubic.stopAction();
  114. removedCubic.cancelDisappear();
  115. player.getCubics().remove(removedCubic.getId());
  116. }
  117. }
  118. // Adding a new cubic.
  119. player.addCubic(_cubicId, _cubicSkillLevel, _cubicPower, _cubicDelay, _cubicSkillChance, _cubicMaxCount, _cubicDuration, getEffected() != getEffector());
  120. player.broadcastUserInfo();
  121. return true;
  122. }
  123. }