SHARE
TWEET

Untitled

a guest Mar 26th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.ruse.world.content.skill.impl.magic;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. import com.ruse.GameSettings;
  7. import com.ruse.model.Animation;
  8. import com.ruse.model.Graphic;
  9. import com.ruse.model.GraphicHeight;
  10. import com.ruse.model.Skill;
  11. import com.ruse.world.entity.impl.player.Player;
  12.  
  13. public class Magic {
  14.  
  15.     public enum Enchant {
  16.  
  17.         SAPPHIRERING(1637, 2550, 7, 18, 719, 114, 1, 1),
  18.         SAPPHIREAMULET(1694, 1727, 7, 18, 719, 114, 1, 1),
  19.         SAPPHIRENECKLACE(1656, 3853, 7, 18, 719, 114, 1, 1),
  20.         SAPPHIREBOLTS(9337, 9240, 7, 18, 712, 238, 1, 10),
  21.  
  22.         EMERALDRING(1639, 2552, 27, 37, 719, 114, 2, 1),
  23.         EMERALDAMULET(1696, 1729, 27, 37, 719, 114, 2, 1),
  24.         EMERALDNECKLACE(1658, 5521, 27, 37, 719, 114, 2, 1),
  25.         EMERALDBOLTS(9338, 9241, 27, 37, 712, 238, 2, 10),
  26.  
  27.         RUBYRING(1641, 2568, 47, 59, 720, 115, 3, 1),
  28.         RUBYAMULET(1698, 1725, 47, 59, 720, 115, 3, 1),
  29.         RUBYNECKLACE(1660, 11194, 47, 59, 720, 115, 3, 1),
  30.         RUBYBOLTS(9339, 9242, 27, 59, 712, 238, 3, 10),
  31.  
  32.         DIAMONDRING(1643, 2570, 57, 67, 720, 115, 4, 1),
  33.         DIAMONDAMULET(1700, 1731, 57, 67, 720, 115, 4, 1),
  34.         DIAMONDNECKLACE(1662, 11090, 57, 67, 720, 115, 4, 1),
  35.         DIAMONDBOLTS(9340, 9243, 27, 67, 712, 238, 4, 10),
  36.  
  37.         DRAGONSTONERING(1645, 22045, 68, 78, 721, 116, 5, 1),
  38.         DRAGONSTONEAMULET(1702, 1712, 68, 78, 721, 116, 5, 1),
  39.         DRAGONSTONENECKLACE(1664, 11113, 68, 78, 721, 116, 5, 1),
  40.         DRAGONBOLTS(9341, 9244, 27, 78, 712, 238, 5, 10),
  41.  
  42.         ONYXRING(6575, 6583, 87, 97, 721, 452, 6, 1),
  43.         ONYXAMULET(6581, 6585, 87, 97, 721, 452, 6, 1),
  44.         ONYXNECKLACE(6577, 11128, 87, 97, 721, 452, 6, 1),
  45.         ONYXBOLTS(9342, 9245, 27, 97, 712, 238, 6, 10)
  46.         ;
  47.  
  48.         int unenchanted, enchanted, levelReq, xpGiven, anim, gfx, reqEnchantmentLevel, amount;
  49.         private Enchant(int unenchanted, int enchanted, int levelReq, int xpGiven, int anim, int gfx, int reqEnchantmentLevel, int amount) {
  50.             this.unenchanted = unenchanted;
  51.             this.enchanted = enchanted;
  52.             this.levelReq = levelReq;
  53.             this.xpGiven = xpGiven;
  54.             this.anim = anim;
  55.             this.gfx = gfx;
  56.             this.reqEnchantmentLevel = reqEnchantmentLevel;
  57.             this.amount = amount;
  58.         }
  59.  
  60.         public int getUnenchanted() {
  61.             return unenchanted;
  62.         }
  63.  
  64.         public int getEnchanted() {
  65.             return enchanted;
  66.         }
  67.  
  68.         public int getLevelReq() {
  69.             return levelReq;
  70.         }
  71.  
  72.         public int getXp() {
  73.             return xpGiven;
  74.         }
  75.  
  76.         public int getAnim() {
  77.             return anim;
  78.         }
  79.  
  80.         public int getGFX() {
  81.             return gfx;
  82.         }
  83.  
  84.         public int getELevel() {
  85.             return reqEnchantmentLevel;
  86.         }
  87.  
  88.         public int getAmount() { return amount; }
  89.  
  90.         private static final Map <Integer,Enchant> enc = new HashMap<Integer,Enchant>();
  91.  
  92.         public static Enchant forId(int itemID) {
  93.             return enc.get(itemID);
  94.         }
  95.  
  96.         static {
  97.             for (Enchant en : Enchant.values()) {
  98.                 enc.put(en.getUnenchanted(), en);
  99.             }
  100.         }
  101.     }
  102.  
  103.     private enum EnchantSpell {
  104.  
  105.         SAPPHIRE(1155, 555, 1, 564, 1, -1, 0),
  106.         EMERALD(1165, 556, 3, 564, 1, -1, 0),
  107.         RUBY(1176, 554, 5, 564, 1, -1, 0),
  108.         DIAMOND(1180, 557, 10, 564, 1, -1, 0),
  109.         DRAGONSTONE(1187, 555, 15, 557, 15, 564, 1),
  110.         ONYX(6003, 557, 20, 554, 20, 564, 1);
  111.  
  112.         int spell, reqRune1, reqAmtRune1, reqRune2, reqAmtRune2, reqRune3, reqAmtRune3;
  113.         private EnchantSpell(int spell, int reqRune1, int reqAmtRune1, int reqRune2, int reqAmtRune2, int reqRune3, int reqAmtRune3) {
  114.             this.spell = spell;
  115.             this.reqRune1 = reqRune1;
  116.             this.reqAmtRune1 = reqAmtRune1;
  117.             this.reqRune2 = reqRune2;
  118.             this.reqAmtRune2 = reqAmtRune2;
  119.             this.reqRune3 = reqRune3;
  120.             this.reqAmtRune3 = reqAmtRune3;
  121.         }
  122.  
  123.         public int getSpell() {
  124.             return spell;
  125.         }
  126.  
  127.         public int getReq1() {
  128.             return reqRune1;
  129.         }
  130.  
  131.         public int getReqAmt1() {
  132.             return reqAmtRune1;
  133.         }
  134.  
  135.         public int getReq2() {
  136.             return reqRune2;
  137.         }
  138.  
  139.         public int getReqAmt2() {
  140.             return reqAmtRune2;
  141.         }
  142.  
  143.         public int getReq3() {
  144.             return reqRune3;
  145.         }
  146.  
  147.         public int getReqAmt3() {
  148.             return reqAmtRune3;
  149.         }
  150.  
  151.  
  152.         public static final Map<Integer, EnchantSpell> ens = new HashMap<Integer, EnchantSpell>();
  153.  
  154.         public static EnchantSpell forId(int id) {
  155.             return ens.get(id);
  156.         }
  157.  
  158.         static {
  159.             for (EnchantSpell en : EnchantSpell.values()) {
  160.                 ens.put(en.getSpell(), en);
  161.             }
  162.         }
  163.  
  164.     }
  165.  
  166.     private static boolean hasRunes(Player player, int spellID) {
  167.         if (player.getEquipment().contains(17293) || player.getEquipment().contains(15835)) {
  168.             return true;
  169.         }
  170.         EnchantSpell ens = EnchantSpell.forId(spellID);
  171.         if (ens.getReq3() == 0) {
  172.             return player.getInventory().contains(ens.getReq1()) && player.getInventory().getAmount(ens.getReq1()) >= ens.getReqAmt1() && player.getInventory().contains(ens.getReq2()) && player.getInventory().getAmount(ens.getReq2()) >= ens.getReqAmt2() && player.getInventory().contains(ens.getReq3()) && player.getInventory().getAmount(ens.getReq3()) >= ens.getReqAmt3();
  173.         } else {
  174.             return player.getInventory().contains(ens.getReq1()) && player.getInventory().getAmount(ens.getReq1()) >= ens.getReqAmt1() && player.getInventory().contains(ens.getReq2()) && player.getInventory().getAmount(ens.getReq2()) >= ens.getReqAmt2();
  175.         }
  176.     }
  177.  
  178.     private static int getEnchantmentLevel(int spellID) {
  179.         switch (spellID) {
  180.         case 1155: //Lvl-1 enchant sapphire
  181.             return 1;
  182.         case 1165: //Lvl-2 enchant emerald
  183.             return 2;
  184.         case 1176: //Lvl-3 enchant ruby
  185.             return 3;
  186.         case 1180: //Lvl-4 enchant diamond
  187.             return 4;
  188.         case 1187: //Lvl-5 enchant dragonstone
  189.             return 5;
  190.         case 6003: //Lvl-6 enchant onyx
  191.             return 6;
  192.         }
  193.         return 0;
  194.     }
  195.     public static void enchantItem(Player player, int itemID, int spellID) {
  196.         Enchant enc = Enchant.forId(itemID);
  197.         EnchantSpell ens = EnchantSpell.forId(spellID);
  198.         if (enc == null || ens == null) {
  199.             return;
  200.         }
  201.         if (player.getSkillManager().getCurrentLevel(Skill.MAGIC) >= enc.getLevelReq()) {
  202.             if (player.getInventory().contains(enc.getUnenchanted())) {
  203.                 int toMake = enc.getAmount();
  204.                 int materials = player.getInventory().getAmount(enc.getUnenchanted());
  205.                
  206.                 if (materials < toMake) {
  207.                     toMake = materials;
  208.                 }
  209.  
  210.                 if (hasRunes(player, spellID)) {
  211.                     if (getEnchantmentLevel(spellID) == enc.getELevel()) {
  212.                         player.getInventory().delete(enc.getUnenchanted(), toMake);
  213.                         player.getInventory().add(enc.getEnchanted(), toMake);
  214.                         player.getSkillManager().addExperience(Skill.MAGIC, enc.getXp());
  215.                         player.getInventory().delete(ens.getReq1(), ens.getReqAmt1());
  216.                         player.getInventory().delete(ens.getReq2(), ens.getReqAmt2());
  217.                         player.performAnimation(new Animation(enc.getAnim()));
  218.                         player.performGraphic(new Graphic(enc.getGFX(), GraphicHeight.HIGH));
  219.                         if (ens.getReq3() != -1) {
  220.                             player.getInventory().delete(ens.getReq3(), ens.getReqAmt3());
  221.                         }
  222.                         player.getPacketSender().sendTab(GameSettings.MAGIC_TAB);
  223.                     } else {
  224.                         player.getPacketSender().sendMessage("You can only enchant this jewelry using a level-"+enc.getELevel()+" enchantment spell!");
  225.                     }
  226.                 } else {
  227.                     player.getPacketSender().sendMessage("You do not have enough runes to cast this spell.");
  228.                 }
  229.             }
  230.         } else {
  231.             player.getPacketSender().sendMessage("You need a Magic level of at least "+enc.getLevelReq()+" to cast this spell.");  
  232.         }
  233.     }
  234.  
  235. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top