armark1ng

Untitled

Sep 22nd, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 KB | None | 0 0
  1. package com.rs.game.player.actions;
  2.  
  3. import com.rs.Settings;
  4. import com.rs.cache.loaders.ItemDefinitions;
  5. import com.rs.game.Animation;
  6. import com.rs.game.Graphics;
  7. import com.rs.game.TemporaryAtributtes.Key;
  8. import com.rs.game.item.Item;
  9. import com.rs.game.player.Player;
  10. import com.rs.game.player.Skills;
  11.  
  12. public class Smithing1 extends Action {
  13.  
  14. private static final int FORGING_INTERFACE = 300, DUNG_INTERFACE = 934;
  15. public static final int HAMMER = 2347, DUNG_HAMMER = 17883;
  16.  
  17. public static final int[][] COMPONENTS = {
  18. { 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122, 130, 138, 146, 154, 162, 170, 178, 186, 194,
  19. 202, 210, 218, 226, 234, 242, 267 },
  20. { 116, 112, 28, 33, 38, 43, 48, 53, 58, 63, 68, 72, 77, 82, 87, 92, 97, 102, 107 } };
  21. public static final int[][] BARS = { { 2349, 2351, 2353, 2359, 2361, 2363 },
  22. { 17650, 17652, 17654, 17656, 17658, 17660, 17662, 17664, 17666, 17668 } };
  23. private static final byte[][] BASE_LEVEL = { { 1, 15, 30, 50, 70, 85 }, { 1, 10, 20, 30, 40, 50, 60, 70, 80, 90 } };
  24. private static final int[][] LEVEL_INCREMENT = {
  25. { 0, 1, 2, 3, 3, 4, 4, 4, 4, 2, 6, 5, 5, 6, 6, 7, 7, 8, 19, 9, 9, 10, 11, 12, 13, 14, 16, 16, 18, 5 },
  26. { 1, 1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9 } };
  27. private static final int[][] BAR_DEPLETION = {
  28. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 2, 1, 1, 3, 3, 3, 3, 2, 3, 3, 3, 5, 1 },
  29. { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5 } };
  30. private static final String[][] NAMES = {
  31. { "Dagger", "Hatchet", "Mace", "Med Helm", "Crossbow Bolts", "Sword", "Dart Tip", "Nails", "Wire", "Split",
  32. "Studs", "Arrow Tips", "Scimitar", "Crossbow Limbs", "Longsword", "Throwing Knife", "Full Helm",
  33. "Square Shield", "Bullseye Lantern", "Grapple Tip", "Warhammer", "Battleaxe", "Chainbody",
  34. "Kiteshield", "Claws", "2H Sword", "Plateskirt", "Platelegs", "Platebody", "Pickaxe" },
  35. { "Arrowtips", "Dagger", "Boots", "Gauntlets", "Hatchet", "Pickaxe", "Warhammer", "Rapier", "Longsword",
  36. "Full Helm", "Battleaxe", "Kiteshield", "Chainbody", "Platelegs", "Plateskirt", "Spear", "Maul",
  37. "Two-handed Sword", "Platebody" }, };
  38.  
  39. public static final int[][] BUILDS = {
  40. { 1205, 1351, 1422, 1139, 877, 1277, 819, 4819, 1794, -1, -1, 39, 1321, 9420, 1291, 864, 1155, 1173, -1, -1,
  41. 1337, 1375, 1103, 1189, 3095, 1307, 1087, 1075, 1117, 1265 },
  42. { 1203, 1349, 1420, 1137, 9377, 1279, 820, 4820, -1, 7225, -1, 40, 1323, 9423, 1293, 863, 1153, 1175, 4540,
  43. -1, 1335, 1363, 1101, 1191, 3096, 1309, 1081, 1067, 1115, 1267 },
  44. { 1207, 1353, 1424, 1141, 9378, 1281, 821, 1539, -1, -1, 2370, 41, 1325, 9425, 1295, 865, 1157, 1177, 4544,
  45. -1, 1339, 1365, 1105, 1193, 3097, 1311, 1083, 1069, 1119, 1269 },
  46. { 1209, 1355, 1428, 1143, 9379, 1285, 822, 4822, -1, -1, -1, 42, 1329, 9427, 1299, 866, 1159, 1181, -1,
  47. 9416, 1343, 1369, 1109, 1197, 3099, 1315, 1085, 1071, 1121, 1273 },
  48. { 1211, 1357, 1430, 1145, 9380, 1287, 823, 4823, -1, -1, -1, 43, 1331, 9429, 1301, 867, 1161, 1183, -1, -1,
  49. 1345, 1371, 1111, 1199, 3100, 1317, 1091, 1073, 1123, 1271 },
  50. { 1213, 1359, 1432, 1147, 9381, 1289, 824, 4824, -1, -1, -1, 44, 1333, 9431, 1303, 868, 1163, 1185, -1, -1,
  51. 1347, 1373, 1113, 1201, 3101, 1319, 1093, 1079, 1127, 1275 },
  52. { 17885, 16757, 16339, 16273, 16361, 16295, 17019, 16935, 16383, 16691, 15753, 17341, 16713, 16669, 16647,
  53. 17063, 16405, 16889, 17239 },
  54. { 17890, 16765, 16341, 16275, 16363, 16297, 17021, 16937, 16385, 16693, 15755, 17343, 16715, 16671, 16649,
  55. 17071, 16407, 16891, 17241 },
  56. { 17895, 16773, 16343, 16277, 16365, 16299, 17023, 16939, 16387, 16695, 15757, 17345, 16717, 16673, 16651,
  57. 17079, 16409, 16893, 17243 },
  58. { 17900, 16781, 16345, 16279, 16367, 16301, 17025, 16941, 16389, 16697, 15759, 17347, 16719, 16675, 16653,
  59. 17087, 16411, 16895, 17245 },
  60. { 17905, 16789, 16347, 16281, 16369, 16303, 17027, 16943, 16391, 16699, 15761, 17349, 16721, 16677, 16655,
  61. 17095, 16413, 16897, 17247 },
  62. { 17910, 16797, 16349, 16283, 16371, 16305, 17029, 16945, 16393, 16701, 15763, 17351, 16723, 16679, 16657,
  63. 17103, 16415, 16899, 17249 },
  64. { 17915, 16805, 16351, 16285, 16373, 16307, 17031, 16947, 16395, 16703, 15765, 17353, 16725, 16681, 16659,
  65. 17111, 16417, 16901, 17251 },
  66. { 17920, 16813, 16353, 16287, 16375, 16309, 17033, 16949, 16397, 16705, 15767, 17355, 16727, 16683, 16661,
  67. 17119, 16419, 16903, 17253 },
  68. { 17925, 16821, 16355, 16289, 16377, 16311, 17035, 16951, 16399, 16707, 15769, 17357, 16729, 16685, 16663,
  69. 17127, 16421, 16905, 17255 },
  70. { 17930, 16829, 16357, 16291, 16379, 16313, 17037, 16953, 16401, 16709, 15771, 17359, 16731, 16687, 16665,
  71. 17135, 16423, 16907, 17257 } };
  72.  
  73. private final int index;
  74. private int cycles, type;
  75. private boolean dungeoneering;
  76.  
  77. public Smithing1(int index, int cycles, boolean dungeoneering) {
  78. this.index = index;
  79. this.cycles = cycles;
  80. this.dungeoneering = dungeoneering;
  81. }
  82.  
  83. @Override
  84. public boolean start(Player player) {
  85. type = (int) player.getTemporaryAttributtes().get(Key.FORGE_TYPE);
  86. int levelRequirement = BASE_LEVEL[dungeoneering ? 1 : 0][type] + LEVEL_INCREMENT[dungeoneering ? 1 : 0][index];
  87. if (levelRequirement > 99)
  88. levelRequirement = 99;
  89. if (player.getSkills().getLevel(Skills.SMITHING) < levelRequirement) {
  90. player.getDialogueManager().startDialogue("SimpleMessage",
  91. "You need a Smithing level of " + levelRequirement + " to forge this bar.");
  92. return false;
  93. }
  94. int calculatedAmount = player.getInventory().getAmountOf(BARS[dungeoneering ? 1 : 0][type])
  95. / BAR_DEPLETION[dungeoneering ? 1 : 0][index];
  96. if (calculatedAmount == 0)
  97. return false;
  98.  
  99. if (cycles > calculatedAmount)
  100. cycles = calculatedAmount;
  101.  
  102. return true;
  103. }
  104.  
  105. @Override
  106. public boolean process(Player player) {
  107. return cycles > 0;
  108. }
  109.  
  110. @Override
  111. public int processWithDelay(Player player) {
  112. cycles--;
  113.  
  114. player.setNextAnimation(new Animation(898));
  115. player.setNextGraphics(new Graphics(2123));
  116.  
  117. int depletedBars = BAR_DEPLETION[dungeoneering ? 1 : 0][index],
  118. forgedAmount = getForgedAmount(index, dungeoneering);
  119.  
  120. if (forgedAmount != 1)
  121. forgedAmount *= Settings.getCraftRate();
  122.  
  123. int barId = BARS[dungeoneering ? 1 : 0][type];
  124. player.getInventory().deleteItem(new Item(barId, depletedBars));
  125. if (!player.getInventory().addItem(new Item(BUILDS[type + (dungeoneering ? 6 : 0)][index], forgedAmount))) {
  126. player.getInventory().addItem(new Item(barId, depletedBars));
  127. return -1;
  128. }
  129.  
  130. player.getSkills().addXp(Skills.SMITHING, ((dungeoneering ? 10 : 12.5) * (type + 1)) * depletedBars);
  131.  
  132. if (cycles > 0)
  133. return 3;
  134. return -1;// stops the action
  135. }
  136.  
  137. @Override
  138. public void stop(Player player) {
  139. setActionDelay(player, 3);
  140. }
  141.  
  142. public static void sendForgingInterface(Player player, int type, boolean dungeoneering) {
  143. int baseLevel = BASE_LEVEL[dungeoneering ? 1 : 0][type];
  144. int currentLevel = player.getSkills().getLevel(Skills.SMITHING);
  145. if (currentLevel < baseLevel) {
  146. player.getDialogueManager().startDialogue("SimpleMessage",
  147. "You need a Smithing level of " + baseLevel + " to forge this bar.");
  148. return;
  149. } else if (!player.getInventory().containsItemToolBelt(dungeoneering ? DUNG_HAMMER : HAMMER)) {
  150. player.getDialogueManager().startDialogue("SimpleMessage", "You need a hammer to work the metal with.");
  151. return;
  152. }
  153. player.getTemporaryAttributtes().put(Key.FORGE_TYPE, type);
  154.  
  155. for (int index = 0; index < BUILDS[type + (dungeoneering ? 6 : 0)].length; index++) {
  156. int componentBase = COMPONENTS[dungeoneering ? 1 : 0][index];
  157. int build = BUILDS[type + (dungeoneering ? 6 : 0)][index];
  158. if (build == -1) {
  159. continue;
  160. }
  161. if (dungeoneering) {
  162. int componentId = index == 0 ? 22 : index == 1 ? 23 : (14 + index * 5);
  163.  
  164. player.getPackets().sendUnlockIComponentOptionSlots(DUNG_INTERFACE, componentId, 0, 5, 0, 1, 2, 3);
  165. player.getPackets().sendInterSetItemsOptionsScript(DUNG_INTERFACE, componentId, 143 + index, 4, 5,
  166. "Make-1", "Make-5", "Make-X", "Make-All");
  167.  
  168. player.getPackets().sendHideIComponent(DUNG_INTERFACE, componentBase - (index >= 11 ? 2 : 0), true);
  169. player.getPackets().sendItems(143 + index,
  170. new Item[] { new Item(build, getForgedAmount(index, true)) });
  171.  
  172. player.getPackets().sendIComponentText(DUNG_INTERFACE, componentBase - (index >= 11 ? 1 : 2),
  173. (currentLevel >= LEVEL_INCREMENT[1][index] + baseLevel ? "<col=FFFFFF>" : "")
  174. + NAMES[1][index]);
  175. player.getPackets().sendIComponentText(DUNG_INTERFACE, componentBase - (index >= 11 ? 0 : 1),
  176. (player.getInventory().getAmountOf(BARS[1][type]) >= BAR_DEPLETION[1][index] ? "<col=00FF00>"
  177. : "") + BAR_DEPLETION[1][index] + " Bars");
  178. } else {
  179. setComponents(player, componentBase, dungeoneering);
  180. player.getPackets().sendItemOnIComponent(FORGING_INTERFACE, componentBase, build,
  181. getForgedAmount(index, false));
  182. player.getPackets().sendIComponentText(FORGING_INTERFACE, componentBase + 1,
  183. (currentLevel >= LEVEL_INCREMENT[0][index] + baseLevel ? "<col=FFFFFF>" : "")
  184. + NAMES[0][index]);
  185. player.getPackets().sendIComponentText(FORGING_INTERFACE, componentBase + 2,
  186. (player.getInventory().getAmountOf(BARS[0][type]) >= BAR_DEPLETION[0][index] ? "<col=00FF00>"
  187. : "") + BAR_DEPLETION[dungeoneering ? 1 : 0][index] + " Bars");
  188. }
  189. }
  190. if (!dungeoneering)
  191. player.getPackets().sendIComponentText(FORGING_INTERFACE, 14,
  192. ItemDefinitions.getItemDefinitions(BARS[0][type]).getName().replace(" bar", "") + " Smithing");
  193. player.getInterfaceManager().sendCentralInterface(dungeoneering ? DUNG_INTERFACE : FORGING_INTERFACE);
  194. }
  195.  
  196. private static void setComponents(Player player, int componentBase, boolean dungeoneering) {
  197. for (int i = -1; i < 7; i++) {
  198. player.getPackets().sendHideIComponent(dungeoneering ? DUNG_INTERFACE : FORGING_INTERFACE,
  199. componentBase + i, false);
  200. }
  201. }
  202.  
  203. private static int getForgedAmount(int index, boolean dungeoneering) {
  204. if (dungeoneering) {
  205. if (index == 0)
  206. return 20;
  207. return 1;
  208. }
  209.  
  210. switch (index) {
  211. case 4:
  212. case 6:
  213. case 10:
  214. case 15:
  215. return 10;
  216. case 7:
  217. case 11:
  218. return 15;
  219. default:
  220. return 1;
  221. }
  222. }
  223. }
Advertisement
Add Comment
Please, Sign In to add comment