SummonCubic.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.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.L2Skill;
  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 = getParameters().getInt("cubicId", -1);
  50. // Custom AI data.
  51. _cubicPower = getParameters().getInt("cubicPower", 0);
  52. _cubicDuration = getParameters().getInt("cubicDuration", 0);
  53. _cubicDelay = getParameters().getInt("cubicDelay", 0);
  54. _cubicMaxCount = getParameters().getInt("cubicMaxCount", -1);
  55. _cubicSkillChance = getParameters().getInt("cubicSkillChance", 0);
  56. }
  57. @Override
  58. public boolean isInstant()
  59. {
  60. return true;
  61. }
  62. @Override
  63. public boolean onStart(BuffInfo info)
  64. {
  65. if ((info.getEffected() == null) || !info.getEffected().isPlayer() || info.getEffected().isAlikeDead() || info.getEffected().getActingPlayer().inObserverMode())
  66. {
  67. return false;
  68. }
  69. if (_cubicId < 0)
  70. {
  71. _log.warning(SummonCubic.class.getSimpleName() + ": Invalid Cubic ID:" + _cubicId + " in skill ID: " + info.getSkill().getId());
  72. return false;
  73. }
  74. final L2PcInstance player = info.getEffected().getActingPlayer();
  75. if (player.inObserverMode() || player.isMounted())
  76. {
  77. return false;
  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. final BuffInfo cubicMastery = player.getEffectList().getBuffInfoBySkillId(L2Skill.SKILL_CUBIC_MASTERY);
  101. // Players with no mastery can have only one cubic.
  102. int allowedCubicCount = 1;
  103. for (AbstractEffect effect : cubicMastery.getEffects())
  104. {
  105. allowedCubicCount += effect != null ? effect.getValue() : 0;
  106. }
  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, info.getEffected() != info.getEffector());
  120. player.broadcastUserInfo();
  121. return true;
  122. }
  123. }