CharChangePotions.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.handler.itemhandlers;
  16. import net.sf.l2j.gameserver.handler.IItemHandler;
  17. import net.sf.l2j.gameserver.model.L2ItemInstance;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  21. import net.sf.l2j.gameserver.model.base.Race;
  22. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  23. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  24. import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  25. /**
  26. * Itemhandler for Character Appearance Change Potions
  27. *
  28. * @author Tempy
  29. */
  30. public class CharChangePotions implements IItemHandler
  31. {
  32. private static final int[] ITEM_IDS =
  33. {
  34. 5235, 5236, 5237, // Face
  35. 5238, 5239, 5240, 5241, // Hair Color
  36. 5242, 5243, 5244, 5245, 5246, 5247, 5248 // Hair Style
  37. };
  38. /**
  39. *
  40. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  41. */
  42. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  43. {
  44. int itemId = item.getItemId();
  45. L2PcInstance activeChar;
  46. if (playable instanceof L2PcInstance)
  47. activeChar = (L2PcInstance) playable;
  48. else if (playable instanceof L2PetInstance)
  49. activeChar = ((L2PetInstance) playable).getOwner();
  50. else
  51. return;
  52. if (activeChar.isAllSkillsDisabled())
  53. {
  54. ActionFailed af = ActionFailed.STATIC_PACKET;
  55. activeChar.sendPacket(af);
  56. return;
  57. }
  58. switch (itemId)
  59. {
  60. case 5235:
  61. activeChar.getAppearance().setFace(0);
  62. break;
  63. case 5236:
  64. activeChar.getAppearance().setFace(1);
  65. break;
  66. case 5237:
  67. activeChar.getAppearance().setFace(2);
  68. break;
  69. case 5238:
  70. activeChar.getAppearance().setHairColor(0);
  71. break;
  72. case 5239:
  73. activeChar.getAppearance().setHairColor(1);
  74. break;
  75. case 5240:
  76. activeChar.getAppearance().setHairColor(2);
  77. break;
  78. case 5241:
  79. if (activeChar.getRace() == Race.Kamael)
  80. return;
  81. activeChar.getAppearance().setHairColor(3);
  82. break;
  83. case 5242:
  84. activeChar.getAppearance().setHairStyle(0);
  85. break;
  86. case 5243:
  87. activeChar.getAppearance().setHairStyle(1);
  88. break;
  89. case 5244:
  90. activeChar.getAppearance().setHairStyle(2);
  91. break;
  92. case 5245:
  93. activeChar.getAppearance().setHairStyle(3);
  94. break;
  95. case 5246:
  96. activeChar.getAppearance().setHairStyle(4);
  97. break;
  98. case 5247:
  99. activeChar.getAppearance().setHairStyle(5);
  100. break;
  101. case 5248:
  102. activeChar.getAppearance().setHairStyle(6);
  103. break;
  104. }
  105. // Create a summon effect!
  106. MagicSkillUse MSU = new MagicSkillUse(playable, activeChar, 2003, 1, 1, 0);
  107. activeChar.broadcastPacket(MSU);
  108. // Update the changed stat for the character in the DB.
  109. activeChar.store();
  110. // Remove the item from inventory.
  111. activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false);
  112. // Broadcast the changes to the char and all those nearby.
  113. UserInfo ui = new UserInfo(activeChar);
  114. activeChar.broadcastPacket(ui);
  115. }
  116. /**
  117. *
  118. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  119. */
  120. public int[] getItemIds()
  121. {
  122. return ITEM_IDS;
  123. }
  124. }