L2SkillChangeWeapon.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package net.sf.l2j.gameserver.skills.l2skills;
  16. import net.sf.l2j.gameserver.model.Inventory;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.network.SystemMessageId;
  23. import net.sf.l2j.gameserver.serverpackets.InventoryUpdate;
  24. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  25. import net.sf.l2j.gameserver.templates.L2Weapon;
  26. import net.sf.l2j.gameserver.templates.StatsSet;
  27. /**
  28. *
  29. * @author nBd
  30. */
  31. public class L2SkillChangeWeapon extends L2Skill
  32. {
  33. /**
  34. * @param set
  35. */
  36. public L2SkillChangeWeapon(StatsSet set)
  37. {
  38. super(set);
  39. }
  40. /**
  41. * @see net.sf.l2j.gameserver.model.L2Skill#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Object[])
  42. */
  43. @Override
  44. public void useSkill(L2Character caster, L2Object[] targets)
  45. {
  46. if(caster.isAlikeDead())
  47. return;
  48. if (!(caster instanceof L2PcInstance))
  49. return;
  50. L2PcInstance player = (L2PcInstance)caster;
  51. L2Weapon weaponItem = player.getActiveWeaponItem();
  52. if (weaponItem == null)
  53. return;
  54. L2ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  55. if (wpn == null)
  56. wpn = player.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
  57. if (wpn != null)
  58. {
  59. if (wpn.isWear())
  60. return;
  61. if (wpn.isAugmented())
  62. return;
  63. int newItemId = 0;
  64. int enchantLevel = 0;
  65. if (weaponItem.getChangeWeaponId() != 0)
  66. {
  67. newItemId = weaponItem.getChangeWeaponId();
  68. enchantLevel = wpn.getEnchantLevel();
  69. if (newItemId == -1)
  70. return;
  71. L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndRecord(wpn.getItem().getBodyPart());
  72. InventoryUpdate iu = new InventoryUpdate();
  73. for (int i = 0; i < unequiped.length; i++)
  74. iu.addModifiedItem(unequiped[i]);
  75. player.sendPacket(iu);
  76. if (unequiped.length > 0)
  77. {
  78. byte count = 0;
  79. for (int i = 0; i < unequiped.length; i++)
  80. {
  81. if (!(unequiped[i].getItem() instanceof L2Weapon))
  82. {
  83. count++;
  84. continue;
  85. }
  86. SystemMessage sm = null;
  87. if (unequiped[i].getEnchantLevel() > 0)
  88. {
  89. sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
  90. sm.addNumber(unequiped[i].getEnchantLevel());
  91. sm.addItemName(unequiped[i].getItemId());
  92. }
  93. else
  94. {
  95. sm = new SystemMessage(SystemMessageId.S1_DISARMED);
  96. sm.addItemName(unequiped[i].getItemId());
  97. }
  98. player.sendPacket(sm);
  99. }
  100. if (count == unequiped.length)
  101. return;
  102. }
  103. else
  104. {
  105. return;
  106. }
  107. L2ItemInstance destroyItem = player.getInventory().destroyItem("ChangeWeapon", wpn, player, null);
  108. if (destroyItem == null)
  109. return;
  110. L2ItemInstance newItem = player.getInventory().addItem("ChangeWeapon", newItemId, 1, player, destroyItem);
  111. if (newItem == null)
  112. return;
  113. newItem.setEnchantLevel(enchantLevel);
  114. player.getInventory().equipItem(newItem);
  115. SystemMessage msg = null;
  116. if (newItem.getEnchantLevel() > 0)
  117. {
  118. msg = new SystemMessage(SystemMessageId.S1_S2_EQUIPPED);
  119. msg.addNumber(newItem.getEnchantLevel());
  120. msg.addItemName(newItem.getItemId());
  121. }
  122. else
  123. {
  124. msg = new SystemMessage(SystemMessageId.S1_EQUIPPED);
  125. msg.addItemName(newItem.getItemId());
  126. }
  127. player.sendPacket(msg);
  128. InventoryUpdate u = new InventoryUpdate();
  129. u.addRemovedItem(destroyItem);
  130. player.sendPacket(u);
  131. player.broadcastUserInfo();
  132. }
  133. }
  134. }
  135. }