SummonCubic.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2004-2015 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.util.Rnd;
  27. /**
  28. * Summon Cubic effect implementation.
  29. * @author Zoey76
  30. */
  31. public final class SummonCubic extends AbstractEffect
  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(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  46. {
  47. super(attachCond, applyCond, set, params);
  48. _cubicId = params.getInt("cubicId", -1);
  49. // Custom AI data.
  50. _cubicPower = params.getInt("cubicPower", 0);
  51. _cubicDuration = params.getInt("cubicDuration", 0);
  52. _cubicDelay = params.getInt("cubicDelay", 0);
  53. _cubicMaxCount = params.getInt("cubicMaxCount", -1);
  54. _cubicSkillChance = params.getInt("cubicSkillChance", 0);
  55. }
  56. @Override
  57. public boolean isInstant()
  58. {
  59. return true;
  60. }
  61. @Override
  62. public void onStart(BuffInfo info)
  63. {
  64. if ((info.getEffected() == null) || !info.getEffected().isPlayer() || info.getEffected().isAlikeDead() || info.getEffected().getActingPlayer().inObserverMode())
  65. {
  66. return;
  67. }
  68. if (_cubicId < 0)
  69. {
  70. _log.warning(SummonCubic.class.getSimpleName() + ": Invalid Cubic ID:" + _cubicId + " in skill ID: " + info.getSkill().getId());
  71. return;
  72. }
  73. final L2PcInstance player = info.getEffected().getActingPlayer();
  74. if (player.inObserverMode() || player.isMounted())
  75. {
  76. return;
  77. }
  78. // Gnacik: TODO: Make better method of calculation.
  79. // If skill is enchanted calculate cubic skill level based on enchant
  80. // 8 at 101 (+1 Power)
  81. // 12 at 130 (+30 Power)
  82. // Because 12 is max 5115-5117 skills
  83. int _cubicSkillLevel = info.getSkill().getLevel();
  84. if (_cubicSkillLevel > 100)
  85. {
  86. _cubicSkillLevel = ((info.getSkill().getLevel() - 100) / 7) + 8;
  87. }
  88. // If cubic is already present, it's replaced.
  89. final L2CubicInstance cubic = player.getCubicById(_cubicId);
  90. if (cubic != null)
  91. {
  92. cubic.stopAction();
  93. cubic.cancelDisappear();
  94. player.getCubics().remove(_cubicId);
  95. }
  96. else
  97. {
  98. // If maximum amount is reached, random cubic is removed.
  99. // Players with no mastery can have only one cubic.
  100. final int allowedCubicCount = info.getEffected().getActingPlayer().getStat().getMaxCubicCount();
  101. final int currentCubicCount = player.getCubics().size();
  102. // Extra cubics are removed, one by one, randomly.
  103. for (int i = 0; i <= (currentCubicCount - allowedCubicCount); i++)
  104. {
  105. final int removedCubicId = (int) player.getCubics().keySet().toArray()[Rnd.get(currentCubicCount)];
  106. final L2CubicInstance removedCubic = player.getCubicById(removedCubicId);
  107. removedCubic.stopAction();
  108. removedCubic.cancelDisappear();
  109. player.getCubics().remove(removedCubic.getId());
  110. }
  111. }
  112. // Adding a new cubic.
  113. player.addCubic(_cubicId, _cubicSkillLevel, _cubicPower, _cubicDelay, _cubicSkillChance, _cubicMaxCount, _cubicDuration, info.getEffected() != info.getEffector());
  114. player.broadcastUserInfo();
  115. }
  116. }