SummonCubic.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2004-2014 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.StatsSet;
  21. import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.conditions.Condition;
  24. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  25. import com.l2jserver.gameserver.model.skills.BuffInfo;
  26. import com.l2jserver.gameserver.model.skills.CommonSkill;
  27. import com.l2jserver.util.Rnd;
  28. /**
  29. * Summon Cubic effect implementation.
  30. * @author Zoey76
  31. */
  32. public final class SummonCubic extends AbstractEffect
  33. {
  34. /** Cubic ID. */
  35. private final int _cubicId;
  36. /** Cubic power. */
  37. private final int _cubicPower;
  38. /** Cubic duration. */
  39. private final int _cubicDuration;
  40. /** Cubic activation delay. */
  41. private final int _cubicDelay;
  42. /** Cubic maximum casts before going idle. */
  43. private final int _cubicMaxCount;
  44. /** Cubic activation chance. */
  45. private final int _cubicSkillChance;
  46. public SummonCubic(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  47. {
  48. super(attachCond, applyCond, set, params);
  49. _cubicId = params.getInt("cubicId", -1);
  50. // Custom AI data.
  51. _cubicPower = params.getInt("cubicPower", 0);
  52. _cubicDuration = params.getInt("cubicDuration", 0);
  53. _cubicDelay = params.getInt("cubicDelay", 0);
  54. _cubicMaxCount = params.getInt("cubicMaxCount", -1);
  55. _cubicSkillChance = params.getInt("cubicSkillChance", 0);
  56. }
  57. @Override
  58. public boolean isInstant()
  59. {
  60. return true;
  61. }
  62. @Override
  63. public void onStart(BuffInfo info)
  64. {
  65. if ((info.getEffected() == null) || !info.getEffected().isPlayer() || info.getEffected().isAlikeDead() || info.getEffected().getActingPlayer().inObserverMode())
  66. {
  67. return;
  68. }
  69. if (_cubicId < 0)
  70. {
  71. _log.warning(SummonCubic.class.getSimpleName() + ": Invalid Cubic ID:" + _cubicId + " in skill ID: " + info.getSkill().getId());
  72. return;
  73. }
  74. final L2PcInstance player = info.getEffected().getActingPlayer();
  75. if (player.inObserverMode() || player.isMounted())
  76. {
  77. return;
  78. }
  79. // Gnacik: TODO: Make better method of calculation.
  80. // If skill is enchanted calculate cubic skill level based on enchant
  81. // 8 at 101 (+1 Power)
  82. // 12 at 130 (+30 Power)
  83. // Because 12 is max 5115-5117 skills
  84. int _cubicSkillLevel = info.getSkill().getLevel();
  85. if (_cubicSkillLevel > 100)
  86. {
  87. _cubicSkillLevel = ((info.getSkill().getLevel() - 100) / 7) + 8;
  88. }
  89. // If cubic is already present, it's replaced.
  90. final L2CubicInstance cubic = player.getCubicById(_cubicId);
  91. if (cubic != null)
  92. {
  93. cubic.stopAction();
  94. cubic.cancelDisappear();
  95. player.getCubics().remove(_cubicId);
  96. }
  97. else
  98. {
  99. // If maximum amount is reached, random cubic is removed.
  100. // Players with no mastery can have only one cubic.
  101. int allowedCubicCount = 1;
  102. // TODO: Unhardcode skill ID check so effect could work on any skill.
  103. if (player.isAffectedBySkill(CommonSkill.CUBIC_MASTERY.getId()))
  104. {
  105. final BuffInfo cubicMastery = player.getEffectList().getBuffInfoBySkillId(CommonSkill.CUBIC_MASTERY.getId());
  106. for (AbstractEffect effect : cubicMastery.getEffects())
  107. {
  108. allowedCubicCount = effect != null ? (int) effect.getValue() : 1;
  109. }
  110. }
  111. final int currentCubicCount = player.getCubics().size();
  112. // Extra cubics are removed, one by one, randomly.
  113. for (int i = 0; i <= (currentCubicCount - allowedCubicCount); i++)
  114. {
  115. final int removedCubicId = (int) player.getCubics().keySet().toArray()[Rnd.get(currentCubicCount)];
  116. final L2CubicInstance removedCubic = player.getCubicById(removedCubicId);
  117. removedCubic.stopAction();
  118. removedCubic.cancelDisappear();
  119. player.getCubics().remove(removedCubic.getId());
  120. }
  121. }
  122. // Adding a new cubic.
  123. player.addCubic(_cubicId, _cubicSkillLevel, _cubicPower, _cubicDelay, _cubicSkillChance, _cubicMaxCount, _cubicDuration, info.getEffected() != info.getEffector());
  124. player.broadcastUserInfo();
  125. }
  126. }