PageRenderTime 26ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/GameServer/src/gameserver/itemengine/actions/EnchantItemAction.java

http://aionxemu.googlecode.com/
Java | 88 lines | 55 code | 13 blank | 20 comment | 5 complexity | 3d1496a21be3ac445c1ea1cf8c4d8def MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-2-Clause
  1. /**
  2. * This file is part of Aion X Emu <aionxemu.com>
  3. *
  4. * This is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser Public License
  15. * along with this software. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package gameserver.itemengine.actions;
  18. import gameserver.model.TaskId;
  19. import gameserver.model.gameobjects.Item;
  20. import gameserver.model.gameobjects.player.Player;
  21. import gameserver.network.aion.serverpackets.SM_ITEM_USAGE_ANIMATION;
  22. import gameserver.network.aion.serverpackets.SM_SYSTEM_MESSAGE;
  23. import gameserver.services.EnchantService;
  24. import gameserver.utils.PacketSendUtility;
  25. import gameserver.utils.ThreadPoolManager;
  26. import javax.xml.bind.annotation.XmlAccessType;
  27. import javax.xml.bind.annotation.XmlAccessorType;
  28. import javax.xml.bind.annotation.XmlAttribute;
  29. import javax.xml.bind.annotation.XmlType;
  30. /**
  31. * @author Nemiroff Date: 16.12.2009
  32. */
  33. @XmlAccessorType(XmlAccessType.FIELD)
  34. @XmlType(name = "EnchantItemAction")
  35. public class EnchantItemAction extends AbstractItemAction {
  36. @XmlAttribute(name = "count")
  37. protected int sub_enchant_material_many;
  38. public int getEnchantCount() {
  39. return sub_enchant_material_many;
  40. }
  41. @Override
  42. public boolean canAct(Player player, Item parentItem, Item targetItem) {
  43. if (targetItem == null) { // no item selected.
  44. PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_ITEM_ERROR);
  45. return false;
  46. }
  47. return true;
  48. }
  49. @Override
  50. public void act(final Player player, final Item parentItem, final Item targetItem) {
  51. act(player, parentItem, targetItem, null, 1);
  52. }
  53. //necessary overloading to not change AbstractItemAction
  54. public void act(final Player player, final Item parentItem, final Item targetItem, final Item supplementItem, final int targetWeapon) {
  55. PacketSendUtility.sendPacket(player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(),
  56. parentItem.getObjectId(), parentItem.getItemTemplate().getTemplateId(), 5000, 0, 0));
  57. player.getController().cancelTask(TaskId.ITEM_USE);
  58. player.getController().addNewTask(TaskId.ITEM_USE,
  59. ThreadPoolManager.getInstance().schedule(new Runnable() {
  60. @Override
  61. public void run() {
  62. int itemId = parentItem.getItemTemplate().getTemplateId();
  63. if (itemId > 166000000 && itemId < 167000000) {
  64. boolean result = EnchantService.enchantItem(player, parentItem, targetItem, supplementItem);
  65. PacketSendUtility.sendPacket(player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), parentItem
  66. .getObjectId(), parentItem.getItemTemplate().getTemplateId(), 0, result ? 1 : 2, 0));
  67. } else {
  68. boolean result = EnchantService.socketManastone(player, parentItem, targetItem, supplementItem, targetWeapon);
  69. PacketSendUtility.sendPacket(player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), parentItem
  70. .getObjectId(), parentItem.getItemTemplate().getTemplateId(), 0, result ? 1 : 2, 0));
  71. }
  72. }
  73. }, 5000));
  74. }
  75. }