Guest User

Mining.java by WaleedScape

a guest
Oct 8th, 2010
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.27 KB | None | 0 0
  1. class Mining {
  2.  
  3. private boolean AreXItemsInBag(client c, int ItemID, int Amount) {
  4. int ItemCount = 0;
  5. for (int i = 0; i < c.playerItems.length; i++) {
  6. if ((c.playerItems[i] - 1) == ItemID) {
  7. ItemCount++;
  8. }
  9. if (ItemCount == Amount) {
  10. return true;
  11. }
  12. }
  13. return false;
  14. }
  15.  
  16. public int GetPickAni(client c) {
  17. int PickAni = 0;
  18. int Pick = c.playerEquipment[c.playerWeapon];
  19. if (Pick == 1275) {
  20. PickAni = 624;
  21. } else if (Pick == 1265) {
  22. PickAni = 624;
  23. } else if (Pick == 1267) {
  24. PickAni = 624;
  25. } else if (Pick == 1269) {
  26. PickAni = 624;
  27. } else if (Pick == 1271) {
  28. PickAni = 624;
  29. } else if (Pick == 1273) {
  30. PickAni = 624;
  31. } else if (Pick == 1275) {
  32. PickAni = 624;
  33. }
  34. if (AreXItemsInBag(c, 1265, 1)) {
  35. PickAni = 624;
  36. } else if (AreXItemsInBag(c, 1267, 1)) {
  37. PickAni = 624;
  38. } else if (AreXItemsInBag(c, 1269, 1)) {
  39. PickAni = 624;
  40. } else if (AreXItemsInBag(c, 1271, 1)) {
  41. PickAni = 624;
  42. } else if (AreXItemsInBag(c, 1273, 1)) {
  43. PickAni = 624;
  44. } else if (AreXItemsInBag(c, 1275, 1)) {
  45. PickAni = 624;
  46. }
  47. return PickAni;
  48. }
  49.  
  50. public int CheckPick(client c) {
  51. int Pick = c.playerEquipment[c.playerWeapon];
  52. if (Pick == 1265) {
  53. return 0;
  54. } else if (Pick == 1267) {
  55. return 1;
  56. } else if (Pick == 1269) {
  57. return 2;
  58. } else if (Pick == 1271) {
  59. return 3;
  60. } else if (Pick == 1273) {
  61. return 4;
  62. } else if (Pick == 1275) {
  63. return 5;
  64. }
  65. if (AreXItemsInBag(c, 1265, 1)) {
  66. return 0;
  67. } else if (AreXItemsInBag(c, 1267, 1)) {
  68. return 1;
  69. } else if (AreXItemsInBag(c, 1269, 1)) {
  70. return 2;
  71. } else if (AreXItemsInBag(c, 1271, 1)) {
  72. return 3;
  73. } else if (AreXItemsInBag(c, 1273, 1)) {
  74. return 4;
  75. } else if (AreXItemsInBag(c, 1275, 1)) {
  76. return 5;
  77. }
  78. return -1;
  79. }
  80.  
  81. public final static int gems[] = { 1617, 1619, 1621, 1623, 1625, 1627, 1629, 1631, 6571 };
  82. public boolean Mining = false;
  83. public int MineTimer; //choptimer
  84. public int RockLevel; //Treelevel
  85. public int RockId; // TreeID
  86. public int RockXp; // TreeXp
  87. public int OreId; // LogId
  88. public int MinedId; //StumpId
  89. public int Gone2for; // Gonefor
  90. public int HowManyOre; //HowManyLogs
  91. public int RockX; //treex
  92. public int RockY; //treey
  93.  
  94. public void InitiateMI(client c, int rock, int x, int y) {
  95. int PickId = CheckPick(c);
  96. int Minus2Time = 0;
  97. RockId = rock;
  98. if (PickId == 1265) {
  99. Minus2Time = 0;
  100. } else if (PickId == 1267) {
  101. Minus2Time = 3;
  102. } else if (PickId == 1269) {
  103. Minus2Time = 6;
  104. } else if (PickId == 1271) {
  105. Minus2Time = 12;
  106. } else if (PickId == 1373) {
  107. Minus2Time = 18;
  108. } else if (PickId == 1375) {
  109. Minus2Time = 25;
  110. }
  111. if (RockId == 2491) { //Rune Essence
  112. MineTimer = 4 + misc.random(6);
  113. RockLevel = 1;
  114. HowManyOre = 1;
  115. RockXp = 40;
  116. OreId = 1436;
  117. MinedId = 450;
  118. Gone2for = 5 + misc.random(5);
  119. } else if (RockId == 2108 || RockId == 2109) { //Clay
  120. MineTimer = 8 + misc.random(4);
  121. RockLevel = 1;
  122. HowManyOre = 1;
  123. RockXp = 50;
  124. OreId = 434;
  125. MinedId = 450;
  126. Gone2for = 10 + misc.random(10);
  127. } else if (RockId == 2090 || RockId == 2091) { //Copper
  128. MineTimer = 8 + misc.random(6);
  129. RockLevel = 1;
  130. HowManyOre = 1;
  131. RockXp = 93;
  132. OreId = 436;
  133. MinedId = 450;
  134. Gone2for = 10 + misc.random(10);
  135. } else if (RockId == 2094 || RockId == 2095) { //Tin
  136. MineTimer = 8 + misc.random(6);
  137. RockLevel = 1;
  138. HowManyOre = 1;
  139. RockXp = 90;
  140. OreId = 438;
  141. MinedId = 450;
  142. Gone2for = 10 + misc.random(10);
  143. } else if (RockId == 10583 || RockId == 10584 || RockId == 2210) { //Blurite
  144. MineTimer = 20 + misc.random(15);
  145. RockLevel = 10;
  146. HowManyOre = 1;
  147. RockXp = 120;
  148. OreId = 668;
  149. MinedId = 450;
  150. Gone2for = 30 + misc.random(50);
  151. } else if (RockId == 4027) { //Limestone
  152. MineTimer = 30 + misc.random(30);
  153. RockLevel = 1;
  154. HowManyOre = 1;
  155. RockXp = 50;
  156. OreId = 3211;
  157. MinedId = 450;
  158. Gone2for = 30 + misc.random(70);
  159. } else if (RockId == 2098 || RockId == 2099) { //Gold
  160. MineTimer = 40 + misc.random(30);
  161. RockLevel = 40;
  162. HowManyOre = 1;
  163. RockXp = 600;
  164. OreId = 444;
  165. MinedId = 450;
  166. Gone2for = 30 + misc.random(30);
  167. } else if (RockId == 2100 || RockId == 2101) { //Silver
  168. MineTimer = 30 + misc.random(20);
  169. RockLevel = 20;
  170. HowManyOre = 1;
  171. RockXp = 400;
  172. OreId = 442;
  173. MinedId = 450;
  174. Gone2for = 20 + misc.random(20);
  175. } else if (RockId == 14856 || RockId == 2092 || RockId == 14858 || RockId == 2093) { //Iron
  176. MineTimer = 16 + misc.random(30);
  177. RockLevel = 15;
  178. HowManyOre = 1;
  179. RockXp = 350;
  180. OreId = 440;
  181. MinedId = 450;
  182. Gone2for = 10 + misc.random(30);
  183. } else if (RockId == 14850 || RockId == 2096 || RockId == 14851 || RockId == 2097) { //Coal
  184. MineTimer = 20 + misc.random(30);
  185. RockLevel = 30;
  186. HowManyOre = 1;
  187. RockXp = 856;
  188. OreId = 453;
  189. MinedId = 450;
  190. Gone2for = 40 + misc.random(30);
  191. } else if (RockId == 14854 || RockId == 2102 || RockId == 2103 || RockId == 14853) { //Mithril
  192. MineTimer = 30 + misc.random(50);
  193. RockLevel = 55;
  194. HowManyOre = 1;
  195. RockXp = 1527;
  196. OreId = 447;
  197. MinedId = 450;
  198. Gone2for = 60 + misc.random(50);
  199. } else if (RockId == 14863 || RockId == 2105 || RockId == 2104 || RockId == 14862) { //Addy
  200. MineTimer = 45 + misc.random(50);
  201. RockLevel = 70;
  202. HowManyOre = 1;
  203. RockXp = 4739;
  204. OreId = 449;
  205. MinedId = 450;
  206. Gone2for = 80 + misc.random(120);
  207. } else if (RockId == 14860 || RockId == 2106 || RockId == 2107 || RockId == 14859) { //Rune
  208. MineTimer = 70 + misc.random(70);
  209. RockLevel = 85;
  210. HowManyOre = 1;
  211. RockXp = 8318;
  212. OreId = 451;
  213. MinedId = 450;
  214. Gone2for = 120 + misc.random(240);
  215. } else if (RockId == 450 || RockId == 451 || RockId == 452 || RockId == 453) { //Empty
  216. resetMI(c);
  217. return;
  218. } else {
  219. resetMI(c);
  220. return;
  221. }
  222. if (c.freeSlots() == 0) {
  223. c.sM("You do not have enough inventory space to hold anymore ore!");
  224. resetMI(c);
  225. return;
  226. }
  227. if (PickId != -1) {
  228. if (c.getLevelForXP(c.playerXP[14]) < RockLevel) {
  229. c.sM("You are not a high enough level.");
  230. c.sM("You must atleast get a level of " + RockLevel + " to mine this rock.");
  231. resetMI(c);
  232. return;
  233. }
  234. if (!Mining) {
  235. c.sM("You start to mine the rock.");
  236. }
  237. RockX = x;
  238. RockY = y;
  239. MineTimer -= (c.playerLevel[14] / 3) + Minus2Time;
  240. Mining = true;
  241. } else {
  242. resetMI(c);
  243. c.sM("You need a pickaxe to mine this rock!");
  244. }
  245. }
  246.  
  247. public void resetMI(client c) {
  248. Mining = false;
  249. soundTimer = 0;
  250. MineTimer = 0;
  251. RockLevel = 0;
  252. RockId = 0;
  253. RockXp = 0;
  254. OreId = 0;
  255. MinedId = 0;
  256. Gone2for = 0;
  257. HowManyOre = 0;
  258. RockX = 0;
  259. RockY = 0;
  260. repeat2ani = 0;
  261. c.resetAnimation();
  262. }
  263. private int soundTimer = 0;
  264. public int repeat2ani = 0;
  265. public int PickAni = 0;
  266.  
  267. public void MIprocess(client c) {
  268. if (MineTimer > 0) {
  269. MineTimer--;
  270. }
  271. if (MineTimer < 0) {
  272. MineTimer = 1;
  273. }
  274. if (soundTimer > 0) {
  275. soundTimer--;
  276. } else {
  277. soundTimer = 1;
  278. c.frame174(432, 025, 000);
  279. }
  280. if (repeat2ani > 0) {
  281. repeat2ani--;
  282. } else {
  283. c.startAnimation(GetPickAni(c));
  284. server.playerHandler.players[c.playerId].updateRequired = true;
  285. server.playerHandler.players[c.playerId].appearanceUpdateRequired = true;
  286. repeat2ani = 3;
  287. }
  288. if (MineTimer == 0) {
  289. if (!Removeore(c)) {
  290. resetMI(c);
  291. return;
  292. } else {
  293. InitiateMI(c, RockId, RockX, RockY);
  294. }
  295. }
  296. }
  297.  
  298. public void SpawnRocks(client c) {
  299. for (int i = 0; i < server.Rocks; i++) {
  300. if (server.ROCKSPAWN[i] > 0) {
  301. c.AddGlobalObject(server.ROCKX[i], server.ROCKY[i],
  302. server.ROCKSTUMP[i], 0, 10);
  303. }
  304. }
  305. }
  306.  
  307. public boolean HasOre() {
  308. for (int i = 0; i < server.Rocks; i++) {
  309. if (server.ROCKX[i] == RockX && server.ROCKY[i] == RockY) {
  310. if (server.ROCKSPAWN[i] > 0) {
  311. return false;
  312. } else if (server.ROCKSPAWN[i] == 0) {
  313. return true;
  314. }
  315. }
  316. }
  317. return false;
  318. }
  319.  
  320. public boolean Removeore(client c) {
  321. boolean New = true;
  322. int Rockid = server.Rocks;
  323. for (int i = 0; i < server.Rocks; i++) {
  324. if (server.ROCKX[i] == RockX && server.ROCKY[i] == RockY) {
  325. if (!HasOre()) {
  326. resetMI(c);
  327. return false;
  328. }
  329. New = false;
  330. server.ORELEFT[i]--;
  331. c.addSkillXP(RockXp, 14);
  332. c.addItem(OreId, 1);
  333. if (misc.random(50) == 37) {
  334. c.addItem(gems[misc.random(8)], 1);
  335. c.sM("You find a gem in this rock.");
  336. }
  337. c.sM("You get some " + c.GetItemName(OreId) + ".");
  338. if (server.ORELEFT[i] <= 0) {
  339. server.ROCKSPAWN[i] = Gone2for;
  340. server.ORE[i] = HowManyOre;
  341. if (server.ORE[i] == 0) {
  342. server.ORE[i] = 1;
  343. }
  344. c.AddGlobalObj(RockX, RockY, MinedId, 0, 10);
  345. return false;
  346. }
  347. return true;
  348. }
  349. }
  350. if (New) {
  351. server.ROCKX[Rockid] = RockX;
  352. server.ROCKY[Rockid] = RockY;
  353. server.ROCKID[Rockid] = RockId;
  354. server.ROCKSTUMP[Rockid] = MinedId;
  355. server.ORELEFT[Rockid] = HowManyOre;
  356. if (server.ORELEFT[Rockid] == 0) {
  357. server.ORELEFT[Rockid] = 1;
  358. }
  359. server.Rocks++;
  360. return true;
  361. }
  362. return false;
  363. }
  364. }
Advertisement
Add Comment
Please, Sign In to add comment