Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.72 KB | None | 0 0
  1. package com.rs.game.player;
  2.  
  3. import java.io.Serializable;
  4.  
  5. import com.rs.cache.loaders.ItemDefinitions;
  6. import com.rs.game.item.Item;
  7. import com.rs.game.player.actions.PlayerCombat;
  8. import com.rs.utils.ItemBonuses;
  9.  
  10. public final class CombatDefinitions implements Serializable {
  11.  
  12.     private static final long serialVersionUID = 2102201264836121104L;
  13.     public static final int STAB_ATTACK = 0, SLASH_ATTACK = 1, CRUSH_ATTACK = 2, RANGE_ATTACK = 4, MAGIC_ATTACK = 3;
  14.     public static final int STAB_DEF = 5, SLASH_DEF = 6, CRUSH_DEF = 7, RANGE_DEF = 9, MAGIC_DEF = 8, SUMMONING_DEF = 10;
  15.     public static final int STRENGTH_BONUS = 14, RANGED_STR_BONUS = 15, MAGIC_DAMAGE = 17, PRAYER_BONUS = 16;
  16.     public static final int ABSORVE_MELEE_BONUS = 11, ABSORVE_RANGE_BONUS = 13, ABSORVE_MAGE_BONUS = 12;
  17.  
  18.     public static final int SHARED = -1;
  19.     private transient Player player;
  20.     private transient boolean usingSpecialAttack;
  21.     private transient int[] bonuses;
  22.  
  23.     // saving stuff
  24.  
  25.     private byte attackStyle;
  26.     private byte specialAttackPercentage;
  27.     private boolean autoRelatie;
  28.     private byte sortSpellBook;
  29.     private boolean showCombatSpells;
  30.     private boolean showSkillSpells;
  31.     private boolean showMiscallaneousSpells;
  32.     private boolean showTeleportSpells;
  33.     private boolean defensiveCasting;
  34.     private transient boolean instantAttack;
  35.     private transient boolean dungeonneringSpellBook;
  36.     private byte spellBook;
  37.     private byte autoCastSpell;
  38.  
  39.     public int getSpellId() {
  40.         Integer tempCastSpell = (Integer) player.getTemporaryAttributtes().get("tempCastSpell");
  41.         if (tempCastSpell != null)
  42.             return tempCastSpell + 256;
  43.         return autoCastSpell;
  44.     }
  45.  
  46.     public int getAutoCastSpell() {
  47.         return autoCastSpell;
  48.     }
  49.  
  50.     public void resetSpells(boolean removeAutoSpell) {
  51.         player.getTemporaryAttributtes().remove("tempCastSpell");
  52.         if (removeAutoSpell) {
  53.             setAutoCastSpell(0);
  54.             refreshAutoCastSpell();
  55.         }
  56.     }
  57.  
  58.     public void setAutoCastSpell(int id) {
  59.         autoCastSpell = (byte) id;
  60.         refreshAutoCastSpell();
  61.     }
  62.  
  63.     public void refreshAutoCastSpell() {
  64.         refreshAttackStyle();
  65.         player.getPackets().sendConfig(108, getSpellAutoCastConfigValue());
  66.     }
  67.  
  68.     public int getSpellAutoCastConfigValue() {
  69.         if (dungeonneringSpellBook)
  70.             return 0;
  71.         if (spellBook == 0) {
  72.             switch (autoCastSpell) {
  73.             case 25:
  74.                 return 3;
  75.             case 28:
  76.                 return 5;
  77.             case 30:
  78.                 return 7;
  79.             case 32:
  80.                 return 9;
  81.             case 34:
  82.                 return 11; // air bolt
  83.             case 39:
  84.                 return 13;// water bolt
  85.             case 42:
  86.                 return 15;// earth bolt
  87.             case 45:
  88.                 return 17; // fire bolt
  89.             case 49:
  90.                 return 19;// air blast
  91.             case 52:
  92.                 return 21;// water blast
  93.             case 58:
  94.                 return 23;// earth blast
  95.             case 63:
  96.                 return 25;// fire blast
  97.             case 66: // Saradomin Strike
  98.                 return 41;
  99.             case 67:// Claws of Guthix
  100.                 return 39;
  101.             case 68:// Flames of Zammorak
  102.                 return 43;
  103.             case 70:
  104.                 return 27;// air wave
  105.             case 73:
  106.                 return 29;// water wave
  107.             case 77:
  108.                 return 31;// earth wave
  109.             case 80:
  110.                 return 33;// fire wave
  111.             case 84:
  112.                 return 47;
  113.             case 87:
  114.                 return 49;
  115.             case 89:
  116.                 return 51;
  117.             case 91:
  118.                 return 53;
  119.             case 99:
  120.                 return 145;
  121.             default:
  122.                 return 0;
  123.             }
  124.         } else if (spellBook == 1) {
  125.             switch (autoCastSpell) {
  126.             case 28:
  127.                 return 63;
  128.             case 32:
  129.                 return 65;
  130.             case 24:
  131.                 return 67;
  132.             case 20:
  133.                 return 69;
  134.             case 30:
  135.                 return 71;
  136.             case 34:
  137.                 return 73;
  138.             case 26:
  139.                 return 75;
  140.             case 22:
  141.                 return 77;
  142.             case 29:
  143.                 return 79;
  144.             case 33:
  145.                 return 81;
  146.             case 25:
  147.                 return 83;
  148.             case 21:
  149.                 return 85;
  150.             case 31:
  151.                 return 87;
  152.             case 35:
  153.                 return 89;
  154.             case 27:
  155.                 return 91;
  156.             case 23:
  157.                 return 93;
  158.             case 36:
  159.                 return 95;
  160.             case 37:
  161.                 return 99;
  162.             case 38:
  163.                 return 97;
  164.             case 39:
  165.                 return 101;
  166.             default:
  167.                 return 0;
  168.             }
  169.         } else {
  170.             return 0;
  171.         }
  172.     }
  173.  
  174.     public CombatDefinitions() {
  175.         specialAttackPercentage = 100;
  176.         autoRelatie = true;
  177.         showCombatSpells = true;
  178.         showSkillSpells = true;
  179.         showMiscallaneousSpells = true;
  180.         showTeleportSpells = true;
  181.     }
  182.  
  183.     public void setSpellBook(int id) {
  184.         if (id == 3)
  185.             dungeonneringSpellBook = true;
  186.         else
  187.             spellBook = (byte) id;
  188.         refreshSpellBookScrollBar_DefCast();
  189.         player.getInterfaceManager().sendMagicBook();
  190.     }
  191.  
  192.     public void refreshSpellBookScrollBar_DefCast() {
  193.         player.getPackets().sendConfig(439, (dungeonneringSpellBook ? 3 : spellBook) + (defensiveCasting ? 0 : 1 << 8));
  194.     }
  195.  
  196.     public int getSpellBook() {
  197.         if (dungeonneringSpellBook)
  198.             return 950; // dung book
  199.         else {
  200.             if (spellBook == 0)
  201.                 return 192; // normal
  202.             else if (spellBook == 1)
  203.                 return 193; // ancients
  204.             else
  205.                 return 430; // lunar
  206.         }
  207.  
  208.     }
  209.  
  210.     public void switchShowCombatSpells() {
  211.         showCombatSpells = !showCombatSpells;
  212.         refreshSpellBook();
  213.     }
  214.  
  215.     public void switchShowSkillSpells() {
  216.         showSkillSpells = !showSkillSpells;
  217.         refreshSpellBook();
  218.     }
  219.  
  220.     public void switchShowMiscallaneousSpells() {
  221.         showMiscallaneousSpells = !showMiscallaneousSpells;
  222.         refreshSpellBook();
  223.     }
  224.  
  225.     public void switchShowTeleportSkillSpells() {
  226.         showTeleportSpells = !showTeleportSpells;
  227.         refreshSpellBook();
  228.     }
  229.  
  230.     public void switchDefensiveCasting() {
  231.         defensiveCasting = !defensiveCasting;
  232.         refreshSpellBookScrollBar_DefCast();
  233.     }
  234.  
  235.     public void setSortSpellBook(int sortId) {
  236.         this.sortSpellBook = (byte) sortId;
  237.         refreshSpellBook();
  238.     }
  239.  
  240.     public boolean isDefensiveCasting() {
  241.         return defensiveCasting;
  242.     }
  243.  
  244.     public void refreshSpellBook() {
  245.         if (spellBook == 0) {
  246.             player.getPackets().sendConfig(1376, sortSpellBook | (showCombatSpells ? 0 : 1 << 9) | (showSkillSpells ? 0 : 1 << 10) | (showMiscallaneousSpells ? 0 : 1 << 11) | (showTeleportSpells ? 0 : 1 << 12));
  247.         } else if (spellBook == 1) {
  248.             player.getPackets().sendConfig(1376, sortSpellBook << 3 | (showCombatSpells ? 0 : 1 << 16) | (showTeleportSpells ? 0 : 1 << 17));
  249.         } else if (spellBook == 2) {
  250.             player.getPackets().sendConfig(1376, sortSpellBook << 6 | (showCombatSpells ? 0 : 1 << 13) | (showMiscallaneousSpells ? 0 : 1 << 14) | (showTeleportSpells ? 0 : 1 << 15));
  251.         }
  252.     }
  253.  
  254.     public static final int getMeleeDefenceBonus(int bonusId) {
  255.         if (bonusId == STAB_ATTACK)
  256.             return STAB_DEF;
  257.         if (bonusId == SLASH_DEF)
  258.             return SLASH_DEF;
  259.         return CRUSH_DEF;
  260.     }
  261.  
  262.     public static final int getMeleeBonusStyle(int weaponId, int attackStyle) {
  263.         if (weaponId != -1) {
  264.             if (weaponId == -2) {
  265.                 return CRUSH_ATTACK;
  266.             }
  267.             String weaponName = ItemDefinitions.getItemDefinitions(weaponId).getName().toLowerCase();
  268.             if (weaponName.contains("whip"))
  269.                 return SLASH_ATTACK;
  270.             if (weaponName.contains("staff of light")) {
  271.                 switch (attackStyle) {
  272.                 case 0:
  273.                     return STAB_ATTACK;
  274.                 case 1:
  275.                     return SLASH_ATTACK;
  276.                 default:
  277.                     return CRUSH_ATTACK;
  278.                 }
  279.             }
  280.             if (weaponName.contains("staff") || weaponName.contains("granite mace") || weaponName.contains("warhammer") || weaponName.contains("tzhaar-ket-em") || weaponName.contains("tzhaar-ket-om") || weaponName.contains("maul"))
  281.                 return CRUSH_ATTACK;
  282.             if (weaponName.contains("godsword") || weaponName.contains("greataxe") || weaponName.contains("2h sword") || weaponName.equals("saradomin sword")) {
  283.                 switch (attackStyle) {
  284.                 case 2:
  285.                     return CRUSH_ATTACK;
  286.                 default:
  287.                     return SLASH_ATTACK;
  288.                 }
  289.             }
  290.             if (weaponName.contains("scimitar") || weaponName.contains("hatchet") || weaponName.contains("claws") || weaponName.contains(" sword") || weaponName.contains("longsword")) {
  291.                 switch (attackStyle) {
  292.                 case 2:
  293.                     return STAB_ATTACK;
  294.                 default:
  295.                     return SLASH_ATTACK;
  296.                 }
  297.             }
  298.             if (weaponName.contains("mace") || weaponName.contains("anchor")) {
  299.                 switch (attackStyle) {
  300.                 case 2:
  301.                     return STAB_ATTACK;
  302.                 default:
  303.                     return CRUSH_ATTACK;
  304.                 }
  305.             }
  306.             if (weaponName.contains("halberd")) {
  307.                 switch (attackStyle) {
  308.                 case 1:
  309.                     return SLASH_ATTACK;
  310.                 default:
  311.                     return STAB_ATTACK;
  312.                 }
  313.             }
  314.             if (weaponName.contains("spear")) {
  315.                 switch (attackStyle) {
  316.                 case 1:
  317.                     return SLASH_ATTACK;
  318.                 case 2:
  319.                     return CRUSH_ATTACK;
  320.                 default:
  321.                     return STAB_ATTACK;
  322.                 }
  323.             }
  324.             if (weaponName.contains("pickaxe")) {
  325.                 switch (attackStyle) {
  326.                 case 2:
  327.                     return CRUSH_ATTACK;
  328.                 default:
  329.                     return STAB_ATTACK;
  330.                 }
  331.             }
  332.  
  333.             if (weaponName.contains("dagger") || weaponName.contains("rapier")) {
  334.                 switch (attackStyle) {
  335.                 case 2:
  336.                     return SLASH_ATTACK;
  337.                 default:
  338.                     return STAB_ATTACK;
  339.                 }
  340.             }
  341.  
  342.         }
  343.         switch (weaponId) {
  344.         default:
  345.             return CRUSH_ATTACK;
  346.         }
  347.     }
  348.  
  349.     public static final int getXpStyle(int weaponId, int attackStyle) {
  350.         if (weaponId != -1 && weaponId != -2) {
  351.             String weaponName = ItemDefinitions.getItemDefinitions(weaponId).getName().toLowerCase();
  352.             if (weaponName.contains("whip")) {
  353.                 switch (attackStyle) {
  354.                 case 0:
  355.                     return Skills.ATTACK;
  356.                 case 1:
  357.                     return SHARED;
  358.                 case 2:
  359.                 default:
  360.                     return Skills.DEFENCE;
  361.                 }
  362.             }
  363.             if (weaponName.contains("halberd")) {
  364.                 switch (attackStyle) {
  365.                 case 0:
  366.                     return SHARED;
  367.                 case 1:
  368.                     return Skills.STRENGTH;
  369.                 case 2:
  370.                 default:
  371.                     return Skills.DEFENCE;
  372.                 }
  373.             }
  374.             if (weaponName.contains("staff")) {
  375.                 switch (attackStyle) {
  376.                 case 0:
  377.                     return Skills.ATTACK;
  378.                 case 1:
  379.                     return Skills.STRENGTH;
  380.                 case 2:
  381.                 default:
  382.                     return Skills.DEFENCE;
  383.                 }
  384.             }
  385.             if (weaponName.contains("godsword") || weaponName.contains("sword") || weaponName.contains("2h")) {
  386.                 switch (attackStyle) {
  387.                 case 0:
  388.                     return Skills.ATTACK;
  389.                 case 1:
  390.                     return Skills.STRENGTH;
  391.                 case 2:
  392.                     return Skills.STRENGTH;
  393.                 case 3:
  394.                 default:
  395.                     return Skills.DEFENCE;
  396.                 }
  397.             }
  398.         }
  399.         switch (weaponId) {
  400.         case -1:
  401.         case -2:
  402.             switch (attackStyle) {
  403.             case 0:
  404.                 return Skills.ATTACK;
  405.             case 1:
  406.                 return Skills.STRENGTH;
  407.             case 2:
  408.             default:
  409.                 return Skills.DEFENCE;
  410.             }
  411.         default:
  412.             switch (attackStyle) {
  413.             case 0:
  414.                 return Skills.ATTACK;
  415.             case 1:
  416.                 return Skills.STRENGTH;
  417.             case 2:
  418.                 return SHARED;
  419.             case 3:
  420.             default:
  421.                 return Skills.DEFENCE;
  422.             }
  423.         }
  424.     }
  425.  
  426.     public void setPlayer(Player player) {
  427.         this.player = player;
  428.         bonuses = new int[18];
  429.     }
  430.  
  431.     public int[] getBonuses() {
  432.         return bonuses;
  433.     }
  434.  
  435.     public void refreshBonuses() {
  436.         bonuses = new int[18];
  437.         for (Item item : player.getEquipment().getItems().getItems()) {
  438.             if (item == null)
  439.                 continue;
  440.             int[] bonuses = ItemBonuses.getItemBonuses(item.getId());
  441.             if (bonuses == null)
  442.                 continue;
  443.             for (int id = 0; id < bonuses.length; id++) {
  444.                 if (id == RANGED_STR_BONUS && this.bonuses[RANGED_STR_BONUS] != 0)
  445.                     continue;
  446.                 this.bonuses[id] += bonuses[id];
  447.             }
  448.         }
  449.     }
  450.  
  451.     public void resetSpecialAttack() {
  452.         desecreaseSpecialAttack(0);
  453.         specialAttackPercentage = 100;
  454.         refreshSpecialAttackPercentage();
  455.     }
  456.  
  457.     public void setSpecialAttack(int special) {
  458.         desecreaseSpecialAttack(0);
  459.         specialAttackPercentage = (byte) special;
  460.         refreshSpecialAttackPercentage();
  461.     }
  462.  
  463.     public void restoreSpecialAttack() {
  464.         if (player.getFamiliar() != null)
  465.             player.getFamiliar().restoreSpecialAttack(15);
  466.         if (specialAttackPercentage == 100)
  467.             return;
  468.         restoreSpecialAttack(10);
  469.         if (specialAttackPercentage == 100 || specialAttackPercentage == 50)
  470.             player.getPackets().sendGameMessage("<col=00FF00>Your special attack energy is now " + specialAttackPercentage + "%.", true);
  471.     }
  472.  
  473.     public void restoreSpecialAttack(int percentage) {
  474.         if (specialAttackPercentage >= 100 || player.getInterfaceManager().containsScreenInter())
  475.             return;
  476.         specialAttackPercentage += specialAttackPercentage > (100 - percentage) ? 100 - specialAttackPercentage : percentage;
  477.         refreshSpecialAttackPercentage();
  478.     }
  479.  
  480.     public void init() {
  481.         refreshUsingSpecialAttack();
  482.         refreshSpecialAttackPercentage();
  483.         refreshAutoRelatie();
  484.         refreshAttackStyle();
  485.         refreshSpellBook();
  486.         refreshAutoCastSpell();
  487.         refreshSpellBookScrollBar_DefCast();
  488.     }
  489.  
  490.     public void checkAttackStyle() {
  491.         if (autoCastSpell == 0)
  492.             setAttackStyle(attackStyle);
  493.     }
  494.  
  495.     public void setAttackStyle(int style) {
  496.         int maxSize = 3;
  497.         int weaponId = player.getEquipment().getWeaponId();
  498.         String name = weaponId == -1 ? "" : ItemDefinitions.getItemDefinitions(weaponId).getName().toLowerCase();
  499.         if (weaponId == -1 || PlayerCombat.isRanging(player) != 0 || name.contains("whip") || name.contains("halberd"))
  500.             maxSize = 2;
  501.         if (style > maxSize)
  502.             style = maxSize;
  503.         if (style != attackStyle) {
  504.             attackStyle = (byte) style;
  505.             if (autoCastSpell > 1)
  506.                 resetSpells(true);
  507.             else
  508.                 refreshAttackStyle();
  509.         } else if (autoCastSpell > 1)
  510.             resetSpells(true);
  511.     }
  512.  
  513.     public void refreshAttackStyle() {
  514.         player.getPackets().sendConfig(43, autoCastSpell > 0 ? 4 : attackStyle);
  515.     }
  516.  
  517.     public void sendUnlockAttackStylesButtons() {
  518.         for (int componentId = 7; componentId <= 10; componentId++)
  519.             player.getPackets().sendUnlockIComponentOptionSlots(884, componentId, -1, 0, 0);
  520.     }
  521.  
  522.     public void switchUsingSpecialAttack() {
  523.         usingSpecialAttack = !usingSpecialAttack;
  524.         refreshUsingSpecialAttack();
  525.     }
  526.  
  527.     public void desecreaseSpecialAttack(int ammount) {
  528.         usingSpecialAttack = false;
  529.         refreshUsingSpecialAttack();
  530.         if (ammount > 0) {
  531.             specialAttackPercentage -= ammount;
  532.             refreshSpecialAttackPercentage();
  533.         }
  534.     }
  535.  
  536.     public boolean hasRingOfVigour() {
  537.         return player.getEquipment().getRingId() == 19669;
  538.     }
  539.  
  540.     public int getSpecialAttackPercentage() {
  541.         return specialAttackPercentage;
  542.     }
  543.  
  544.     public void refreshUsingSpecialAttack() {
  545.         player.getPackets().sendConfig(301, usingSpecialAttack ? 1 : 0);
  546.     }
  547.  
  548.     public void refreshSpecialAttackPercentage() {
  549.         player.getPackets().sendConfig(300, specialAttackPercentage * 10);
  550.     }
  551.  
  552.     public void switchAutoRelatie() {
  553.         autoRelatie = !autoRelatie;
  554.         refreshAutoRelatie();
  555.     }
  556.  
  557.     public void refreshAutoRelatie() {
  558.         player.getPackets().sendConfig(172, autoRelatie ? 0 : 1);
  559.     }
  560.  
  561.     public boolean isUsingSpecialAttack() {
  562.         return usingSpecialAttack;
  563.     }
  564.  
  565.     public int getAttackStyle() {
  566.         return attackStyle;
  567.     }
  568.  
  569.     public boolean isAutoRelatie() {
  570.         return autoRelatie;
  571.     }
  572.  
  573.     public void setAutoRelatie(boolean autoRelatie) {
  574.         this.autoRelatie = autoRelatie;
  575.     }
  576.  
  577.     public boolean isDungeonneringSpellBook() {
  578.         return dungeonneringSpellBook;
  579.     }
  580.  
  581.     public void removeDungeonneringBook() {
  582.         if (dungeonneringSpellBook) {
  583.             dungeonneringSpellBook = false;
  584.             player.getInterfaceManager().sendMagicBook();
  585.         }
  586.     }
  587.  
  588.     public boolean isInstantAttack() {
  589.         return instantAttack;
  590.     }
  591.  
  592.     public void setInstantAttack(boolean instantAttack) {
  593.         this.instantAttack = instantAttack;
  594.     }
  595. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement