Guest User

Untitled

a guest
Jun 24th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. package org.dementhium.content.skills.magic;
  2.  
  3. import org.dementhium.model.Item;
  4. import org.dementhium.model.World;
  5. import org.dementhium.model.mask.Animation;
  6. import org.dementhium.model.mask.Graphic;
  7. import org.dementhium.model.player.Player;
  8. import org.dementhium.model.player.Skills;
  9. import org.dementhium.net.ActionSender;
  10. import org.dementhium.tickable.Tick;
  11.  
  12. /**
  13. * @author Wolfey
  14. */
  15. public class Enchant {
  16. private static final Item COSMIC_RUNE = new Item(564, 1);
  17.  
  18. /**
  19. *
  20. * @param player
  21. * the player to handle.
  22. * @param childId
  23. * the childId of the spell, this will be used to retrieve the
  24. * enchant level.
  25. * @param itemId
  26. * the itemId of our item to enchant.
  27. * @param slot
  28. * the slot of the item.
  29. * @return
  30. */
  31. public static boolean enchant(Player player, int childId, int itemId,
  32. int slot) {
  33. if (player.getSettings().getSpellBook() == 192) {
  34. EnchantLevel level = EnchantLevel.forChild(childId);
  35. if (level != null) {
  36. if (handle(player, level, new Item(itemId), slot)) {
  37. return true;
  38. }
  39. ActionSender
  40. .sendMessage(
  41. player,
  42. "This spell can only be cast in "
  43. + level.name().toLowerCase()
  44. + " amulets, rings, necklaces, bracelets and on");
  45. ActionSender.sendMessage(player,
  46. "shapes in the Mage Training Arena");
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52.  
  53. private static boolean handle(final Player player,
  54. final EnchantLevel level, final Item item, final int slot) {
  55. if (player.getSkills().getLevelForExperience(Skills.MAGIC) < level
  56. .getLevelReq()) {
  57. ActionSender.sendMessage(player,
  58. "Your Magic level is not high enough to cast this spell.");
  59. return true;
  60. }
  61. if (!player.getInventory().contains(COSMIC_RUNE)) {
  62. ActionSender.sendMessage(player,
  63. "You do not have enough Cosmic Runes to cast this spell.");
  64. return true;
  65. }
  66. for (Item rune : level.getRunes()) {
  67. if (!player.getInventory().contains(rune)) {
  68. ActionSender.sendMessage(player, "You do not have enough "
  69. + rune.getDefinition().getName()
  70. + "s to cast this spell.");
  71. return true;
  72. }
  73. }
  74. final int enchantedId = getEnchantedID(level, item);
  75. if (enchantedId == -1)
  76. return false;
  77. for (Item rune : level.getRunes()) {
  78. player.getInventory().deleteItem(rune);
  79. }
  80. player.setAttribute("cantMove", Boolean.TRUE);
  81. player.setAttribute("enchanting", Boolean.TRUE);
  82. player.animate(Animation.create(getAnimId(level, enchantedId)));
  83. player.graphics(Graphic.create(getGraphicId(level, enchantedId),
  84. 100 << 16));
  85. player.getMask().setApperanceUpdate(true);
  86. World.getWorld().submit(new Tick(3) {
  87. @Override
  88. public void execute() {
  89. player.getInventory().set(slot, new Item(enchantedId));
  90. player.getSkills().addExperience(Skills.MAGIC,
  91. level.getExperience());
  92. player.removeAttribute("cantMove");
  93. player.removeAttribute("enchanting");
  94. player.getInventory().refresh();
  95. stop();
  96. }
  97. });
  98. return true;
  99. }
  100.  
  101. private static int getEnchantedID(EnchantLevel level, Item item) {
  102. switch (level) {
  103. case SAPPHIRE:
  104. switch (item.getId()) {
  105. case 1694:// Amulet of Magic
  106. return 1727;
  107. case 1637:// Ring of Recoil
  108. return 2550;
  109. case 1658:// Games Necklace
  110. return 3853;
  111. case 11072:// Bracelet of Clay
  112. return 11074;
  113. }
  114. case EMERALD:
  115. switch (item.getId()) {
  116. case 1639:// Ring of Duelling
  117. return 2552;
  118. case 1658:// Farming Necklace
  119. return 12622;
  120. case 1696:// Amulet of Defence
  121. return 1729;
  122. case 11076:// Castle wars bracelet
  123. return 11079;
  124. }
  125. case RUBY:
  126. switch (item.getId()) {
  127. case 1641:// Ring of Forging
  128. return 2568;
  129. case 1660:// Digsite Pendant
  130. return 11194;
  131. case 1698:// Amulet of Strength
  132. return 1725;
  133. case 11086:// Inoculation Bracelet
  134. return 11088;
  135. }
  136. case DIAMOND:
  137. switch (item.getId()) {
  138. case 1643:// Ring of Life
  139. return 2570;
  140. case 1662:// Phoenix Necklace
  141. return 11090;
  142. case 1700:// Amulet of Power
  143. return 1731;
  144. case 11092:// Forinthry brace
  145. return 11095;
  146. }
  147. case DRAGONSTONE:
  148. switch (item.getId()) {
  149. case 1645:// Ring of Wealth
  150. return 2572;
  151. case 1702:// Amulet of Glory
  152. return 1712;
  153. case 11115:// Combat Bracelet
  154. return 11118;
  155. }
  156. case ONYX:
  157. switch (item.getId()) {
  158. case 6575:// Ring of Stone
  159. return 6583;
  160. case 6582:// Amulet of Fury
  161. return 6585;
  162. case 11130:// Regen Bracelet
  163. return 11133;
  164. }
  165. break;
  166. }
  167. return -1;
  168. }
  169.  
  170. public static int getAnimId(EnchantLevel level, int id) {
  171. String name = new Item(id).getDefinition().getName();
  172. System.out.println(name);
  173. if (name.contains("Amulet")) {
  174. switch (level) {
  175. case SAPPHIRE:
  176. return 719;
  177. case EMERALD:
  178. return 720;
  179. case RUBY:
  180. return 721;
  181. case DIAMOND:
  182. return 719;
  183. case DRAGONSTONE:
  184. return 720;
  185. case ONYX:
  186. return 720;// TODO correct GFX.
  187. }
  188. }
  189. if (name.contains("Ring")) {
  190. return 931;
  191. }
  192. return -1;
  193. }
  194.  
  195. public static int getGraphicId(EnchantLevel level, int id) {
  196. String name = new Item(id).getDefinition().getName();
  197. System.out.println(name);
  198. if (name.contains("Amulet")) {
  199. switch (level) {
  200. case SAPPHIRE:
  201. return 114;
  202. case EMERALD:
  203. return 115;
  204. case RUBY:
  205. return 115;
  206. case DIAMOND:
  207. return 153;
  208. case DRAGONSTONE:
  209. return 154;
  210. case ONYX:
  211. return 154;// TODO correct GFX.
  212. }
  213. }
  214. if (name.contains("Ring")) {
  215. return -1;
  216. }
  217. return -1;
  218. }
  219. }
Add Comment
Please, Sign In to add comment