Advertisement
bombar

crimboMining.ash

Dec 9th, 2014
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.41 KB | None | 0 0
  1. script "crimboMining.ash";
  2. notify bombar;
  3. since r15029;
  4.  
  5. string version = "1.14";
  6.  
  7. int maxFailsAllowed = 1; //How much bigger a set of continout interesting points can be more then 6, if you were to explore all in bigger chains, you are guarnteed a cave in
  8. int maxCaves = 200; //Max caves to check against, mainly to solve for infinite loops just in case
  9. boolean requireFreeMining = true; //Whether to force no turn used
  10. boolean useDynamite = false;//Whether to use minin' dynamite
  11. int numTurnsToLeave = 0;//How many turns you want to have left when finished mining, only applies if requireFreeMining=false
  12.  
  13. int delayBetweenMines = 0;//In seconds, This will allow you to add delays after each mining attempt, used to spread out server load espically if you are starting script and letting it run while you go do other things and don't care when it finishes
  14.  
  15. int maxExtraNuggets = -1;//Set to -1 if you don't want to use this value and just mine as many nuggets as you can
  16.  
  17. boolean mineOnlyPeppermints = false;//With this you can skip mining nuggets entirely since Jick has stated you will only need enough nuggets as you have molds
  18. int minNumberTailingsPerCave = 3;//Number of tailing you want to get from each cave at a mininum, set to 26 if you want to get all of them (6 nuggets, 4 cave ins, 26 tailings per cave)
  19.  
  20. boolean useMafiaRestore = false;//Whether to use kol's healing script, if set to false will attempt custom logic to heal a point
  21.  
  22. //Determines if you will use a healing skill or just go to docs, a value of $skill[none] means goto doc, otherwise attempt to use skill provided, if that doesn't work then it will still go to docs
  23. skill healingSkill = $skill[none];//Note only used if useMafiaRestore = false;
  24. //copy and paste one of these skills over $skill[none] to try to use that skill before heading to docs, should work with non-listed skills just adding them for ease of use
  25. //$skill[saucy salve], $skill[lasagna bandages], $skill[tongue of the walrus], $skill[cannelloni cocoon], $skill[shake it off]
  26.  
  27. record Spot {
  28. int row;
  29. int col;
  30. int counter;
  31. boolean isInteresting;
  32. boolean checkedForChain;
  33. int numDirects;
  34. int costToGetTo;
  35. boolean isCaveIn;
  36. string shortestRoute;
  37. boolean mined;
  38. };
  39.  
  40. record Chain {
  41. int numSpotsInChain;
  42. Spot[int] spotsInChain;
  43. Spot entryPoint;
  44. };
  45.  
  46. record Mine {
  47. Chain currentLongestChain;
  48. Spot[int] interestingSpots;
  49. Spot[int][int] spots;
  50. int nuggetsFound;
  51. int tailingsFound;
  52. Spot[int] tailingSpotsChecked;
  53. };
  54.  
  55. record MiningOperation {
  56. int startingNumNuggets;
  57. int startingNumTailings;
  58. int numCavesSkipped;
  59. int numCavesFullyExplored;
  60. int numCaveIns;
  61. int numOilyLegsAtStart;
  62. int startTime;
  63. };
  64.  
  65. Spot newSpot(int counter, int col, int row) {
  66. Spot result = new Spot();
  67. result.col = col;
  68. result.row = row;
  69. result.counter = counter;
  70. result.isInteresting = false;
  71. result.numDirects = 0;
  72. result.costToGetTo = 10000;
  73. result.isCaveIn = false;
  74. result.checkedForChain = false;
  75. result.shortestRoute = "";
  76. result.mined = false;
  77. return result;
  78. }
  79.  
  80. Chain newChain() {
  81. Chain newChain = new Chain();
  82. newChain.numSpotsInChain = 0;
  83. clear(newChain.spotsInChain);
  84. return newChain;
  85. }
  86.  
  87.  
  88. Mine newMine() {
  89. Mine result = new Mine();
  90. result.currentLongestChain = newChain();
  91. clear(result.interestingSpots);
  92. clear(result.spots);
  93. result.nuggetsFound = 0;
  94. result.tailingsFound = 0;
  95. return result;
  96. }
  97.  
  98. Mine currentMine;
  99. MiningOperation currentOperation;
  100.  
  101. string printSpot(Spot currentSpot) {
  102. buffer result;
  103. result.append("(");
  104. result.append(currentSpot.col);
  105. result.append(",");
  106. result.append(currentSpot.row);
  107. result.append(")");
  108. return result;
  109. }
  110.  
  111. void restoreMinHP() {
  112. if (useMafiaRestore) {
  113. restore_hp(1);
  114. } else if (healingSkill != $skill[none]) {
  115. //Attempt to use skill
  116. if (my_mp() > mp_cost(healingSkill))
  117. use_skill(healingSkill);
  118. }
  119.  
  120. if (my_hp() == 0) {
  121. if (my_meat() < 10)
  122. abort("Don't have enought meat to heal");
  123.  
  124. cli_execute("galaktik hp 1"); //Thanks to Ezandora for pointing this out.
  125. }
  126. }
  127.  
  128. void restore_outfit(){
  129. outfit("Backup");
  130. }
  131.  
  132. void endMiningOperation() {
  133. restore_outfit();
  134. int numNuggets = item_amount($item[nugget of Crimbonium]) - currentOperation.startingNumNuggets;
  135. int numTailings = item_amount($item[peppermint tailings]) - currentOperation.startingNumTailings;
  136.  
  137. int numMSTaken = gametime_to_int() - currentOperation.startTime;
  138. float numSecondsTaken = numMSTaken / 1000;
  139.  
  140. print("Number of Fully Explored Caves: " + currentOperation.numCavesFullyExplored, "blue");
  141. print("Number of Caves Skipped because chain to large: " + currentOperation.numCavesSkipped, "blue");
  142. print("Number of Cave Ins that occurred: " + currentOperation.numCaveIns, "blue");
  143. print("Number of " + $item[peppermint tailings] + " found: " + numTailings, "blue");
  144. print("Number of " + $item[nugget of Crimbonium] + " found: " + numNuggets, "blue");
  145. print("Number of seconds it took: " + numSecondsTaken, "blue");
  146. }
  147.  
  148. void abortMining(string reason) {
  149. endMiningOperation();
  150. abort(reason);
  151. }
  152. void processSpotForChain(Chain currentChain, Spot currentSpot) {
  153. //Add to chain, marked off as being checked
  154. int numInChain = count(currentChain.spotsInChain);
  155. currentChain.spotsInChain[numInChain] = currentSpot;
  156. currentSpot.checkedForChain = true;
  157.  
  158. int row = currentSpot.row;
  159. int col = currentSpot.col;
  160.  
  161. //Check Left
  162. if (col != 1) {
  163. Spot checkSpot = currentMine.spots[col - 1][row];
  164. if (checkSpot.isInteresting) {
  165. currentSpot.numDirects += 1;
  166. if (!checkSpot.checkedForChain)
  167. processSpotForChain(currentChain, checkSpot);
  168. }
  169. }
  170.  
  171. //Check Right
  172. if (col != 6) {
  173. Spot checkSpot = currentMine.spots[col + 1][row];
  174. if (checkSpot.isInteresting) {
  175. currentSpot.numDirects += 1;
  176. if (!checkSpot.checkedForChain)
  177. processSpotForChain(currentChain, checkSpot);
  178. }
  179. }
  180.  
  181. //Check Above
  182. if (row != 1) {
  183. Spot checkSpot = currentMine.spots[col][row - 1];
  184. if (checkSpot.isInteresting) {
  185. currentSpot.numDirects += 1;
  186. if (!checkSpot.checkedForChain)
  187. processSpotForChain(currentChain, checkSpot);
  188. }
  189. }
  190.  
  191. //Check Below
  192. if (row != 6) {
  193. Spot checkSpot = currentMine.spots[col][row + 1];
  194. if (checkSpot.isInteresting) {
  195. currentSpot.numDirects += 1;
  196. if (!checkSpot.checkedForChain)
  197. processSpotForChain(currentChain, checkSpot);
  198. }
  199. }
  200.  
  201.  
  202. }
  203.  
  204. void calculateLongestChain() {
  205. Chain currentChain = newChain();
  206. Spot currentSpot;
  207. foreach spotNdx in currentMine.interestingSpots {
  208. currentSpot = currentMine.interestingSpots[spotNdx];
  209. if (currentSpot.isInteresting && !currentSpot.checkedForChain) {
  210. processSpotForChain(currentChain, currentSpot);
  211. }
  212.  
  213. if (count(currentChain.spotsInChain) >= 6) // Found the chain we need, only chains 6 and longer here are the ones we are looking for
  214. break;
  215. else {
  216. foreach tmpSpotNdx in currentChain.spotsInChain {
  217. Spot tmpSpot = currentChain.spotsInChain[tmpSpotNdx];
  218. tmpSpot.isCaveIn = true;
  219. }
  220. }
  221. }
  222.  
  223. currentMine.currentLongestChain = currentChain;
  224.  
  225. foreach spotNdx in currentMine.interestingSpots {
  226. currentSpot = currentMine.interestingSpots[spotNdx];
  227. if (currentSpot.isInteresting && !currentSpot.checkedForChain)
  228. currentSpot.isCaveIn = true;
  229. }
  230. }
  231.  
  232. void parseMine() {
  233. //string page = visit_url("place.php?whichplace=desertbeach&action=db_crimbo14mine");
  234. buffer page = visit_url("mining.php?mine=5");
  235. if (page.contains_text("<table cellpadding=0 cellspacing=0 border=0 background=")) {
  236. page.substring(page.index_of("<table cellpadding=0 cellspacing=0 border=0 background="));
  237. for counter from 0 to 54 {
  238. int rowNdx = counter / 8;
  239. int colNdx = counter % 8;
  240. if (rowNdx > 0 && rowNdx < 7) {
  241. if (colNdx > 0 && colNdx < 7) {
  242. Spot newSpot = newSpot(counter, colNdx, rowNdx);
  243. currentMine.spots[colNdx][rowNdx] = newSpot;
  244.  
  245. if (page.contains_text("Promising Chunk of Wall (" + colNdx + "," + rowNdx + ")")) {
  246. currentMine.interestingSpots[count(currentMine.interestingSpots)] = newSpot;
  247. newSpot.isInteresting = true;
  248. if (rowNdx >= 5)
  249. newSpot.isCaveIn = true;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256.  
  257. void figureRoute() {
  258. int cheapestPath = 100000;
  259. Spot firstSpot;
  260.  
  261. foreach spotNdx in currentMine.currentLongestChain.spotsInChain {
  262. Spot currentSpot = currentMine.currentLongestChain.spotsInChain[spotNdx];
  263. if (currentSpot.costToGetTo < cheapestPath){
  264. cheapestPath = currentSpot.costToGetTo;
  265. firstSpot = currentSpot;
  266. currentMine.currentLongestChain.entryPoint = currentSpot;
  267. }
  268. }
  269.  
  270. //print("Starting point will be: " + printSpot(firstSpot) + " path: " + firstSpot.shortestRoute);
  271. }
  272.  
  273. void printMine() {
  274. for rowNdx from 1 to 6 {
  275. if (rowNdx == 1)
  276. print("=======================================");
  277. else
  278. print("----------------------------------------");
  279. buffer row;
  280. row.append("| ");
  281.  
  282. for colNdx from 1 to 6 {
  283. if (currentMine.spots[colNdx][rowNdx].isCaveIn)
  284. row.append(" c ");
  285. else if (currentMine.spots[colNdx][rowNdx].isInteresting)
  286. row.append(" " + currentMine.spots[colNdx][rowNdx].numDirects + " ");
  287. else
  288. row.append(" X ");
  289. row.append(" |");
  290. }
  291. print(row);
  292.  
  293. }
  294. }
  295.  
  296. void printPaths() {
  297. for rowNdx from 1 to 6 {
  298. if (rowNdx == 1)
  299. print("=======================================");
  300. else
  301. print("----------------------------------------");
  302. buffer row;
  303. row.append("| ");
  304.  
  305. for colNdx from 1 to 6 {
  306. row.append(" " + currentMine.spots[colNdx][rowNdx].costToGetTo + " ");
  307. row.append(" |");
  308. }
  309. print(row);
  310.  
  311. }
  312.  
  313. }
  314.  
  315. void calcPathsFromSpot(Spot currentSpot, string pathSoFar, int lengthSoFar) {
  316. int increment = 1;
  317. if (currentSpot.isCaveIn)
  318. increment = 6;
  319.  
  320. int tmpLength = lengthSoFar + increment;
  321. if (tmpLength < currentSpot.costToGetTo) {
  322. currentSpot.costToGetTo = tmpLength;
  323. pathSoFar = pathSoFar + currentSpot.counter + ";";
  324. currentSpot.shortestRoute = pathSoFar;
  325. if (currentSpot.col > 1)
  326. calcPathsFromSpot(currentMine.spots[currentSpot.col - 1][currentSpot.row], pathSoFar, currentSpot.costToGetTo);
  327. if (currentSpot.row > 1)
  328. calcPathsFromSpot(currentMine.spots[currentSpot.col][currentSpot.row - 1], pathSoFar, currentSpot.costToGetTo);
  329. if (currentSpot.col < 6)
  330. calcPathsFromSpot(currentMine.spots[currentSpot.col + 1][currentSpot.row], pathSoFar, currentSpot.costToGetTo);
  331. }
  332. }
  333.  
  334. void calcShortestPathsToAllSpots() {
  335. for colNdx from 1 to 6 by 1 {
  336. Spot startSpot = currentMine.spots[colNdx][6];
  337. calcPathsFromSpot(startSpot, "", 0);
  338. }
  339. }
  340.  
  341.  
  342. void gotoNextMine() {
  343. visit_url("mining.php?mine=5&reset=1&pwd");
  344. currentMine = newMine();
  345. }
  346.  
  347. void mineSpot(Spot spotToMine) {
  348. if (my_hp() == 0) {
  349. restoreMinHP();
  350. }
  351.  
  352. int numDynamite = item_amount($item[minin' dynamite]);
  353. int numTurnsOilyLegs = have_effect($effect[oily legs]);
  354.  
  355. if (requireFreeMining && numDynamite == 0 && numTurnsOilyLegs == 0) {
  356. abortMining("Currently no free mining attempts left, stopping script");
  357. }
  358.  
  359. if (requireFreeMining && spotToMine.isInteresting && numTurnsOilyLegs == 0) {
  360. abortMining("No turns remaining of Oily Legs, and you have specified to only use free mining");
  361. }
  362.  
  363. if (!requireFreeMining && my_adventures() <= numTurnsToLeave)
  364. abortMining("At mininum number of turns left");
  365.  
  366. string result = visit_url("mining.php?mine=5&which=" + spotToMine.counter + "&pwd");
  367. int[item] itemsFound = extract_items(result);
  368. if (count(itemsFound) > 0) {
  369. foreach itemFound in itemsFound {
  370. if (itemFound == $item[nugget of Crimbonium])
  371. currentMine.nuggetsFound += 1;
  372. if (itemFound == $item[peppermint tailings])
  373. currentMine.tailingsFound += 1;
  374. }
  375. } else {
  376. currentOperation.numCaveIns += 1;
  377. }
  378.  
  379.  
  380. spotToMine.mined = true;
  381.  
  382. if ( delayBetweenMines > 0 )
  383. waitq(delayBetweenMines);
  384. }
  385.  
  386. void mineChainSpot(Spot spotToMine) {
  387. if (spotToMine.mined)
  388. return;
  389. if (!spotToMine.isInteresting)
  390. return;
  391. if (currentMine.nuggetsFound >= 6)
  392. return;//Already found 6 nuggets here so rest of chain is cave ins
  393.  
  394. if (spotToMine.isInteresting) {
  395. if (!spotToMine.mined)
  396. mineSpot(spotToMine);
  397. if (spotToMine.row != 1)
  398. mineChainSpot(currentMine.spots[spotToMine.col][spotToMine.row - 1]);
  399. if (spotToMine.col != 1)
  400. mineChainSpot(currentMine.spots[spotToMine.col - 1][spotToMine.row]);
  401. if (spotToMine.col != 6)
  402. mineChainSpot(currentMine.spots[spotToMine.col + 1][spotToMine.row]);
  403. if (spotToMine.row != 4)
  404. mineChainSpot(currentMine.spots[spotToMine.col][spotToMine.row + 1]);
  405. }
  406.  
  407. }
  408.  
  409. Spot findSpotByCounter(string counterString) {
  410. int counter = to_int(counterString);
  411. int row = counter / 8;
  412. int col = counter % 8;
  413.  
  414. return currentMine.spots[col][row];
  415. }
  416.  
  417. void handleRoute() {
  418. Spot entryPoint = currentMine.currentLongestChain.entryPoint;
  419. string routeToEntry = entryPoint.shortestRoute;
  420. string[int] spots = split_string(routeToEntry, ";");
  421. foreach ndx in spots {
  422. if (entryPoint.counter != to_int(spots[ndx]))
  423. mineSpot(findSpotByCounter(spots[ndx]));
  424.  
  425. }
  426.  
  427. mineChainSpot(entryPoint);
  428. }
  429. /*
  430. void useTestMine(int testMineNumber) {
  431. int ndxISpots = 0;
  432. buffer testMineBuffer;
  433. switch (testMineNumber) {
  434. case 1:
  435. testMineBuffer.append("WWWWWWWW");
  436. testMineBuffer.append("W00IIIIW");
  437. testMineBuffer.append("W00000IW");
  438. testMineBuffer.append("W00000IW");
  439. testMineBuffer.append("W000II0W");
  440. testMineBuffer.append("W000000W");
  441. testMineBuffer.append("W0000IIW");
  442. break;
  443. default:
  444. testMineBuffer.append("WWWWWWWW");
  445. testMineBuffer.append("WIIII00W");
  446. testMineBuffer.append("W0II000W");
  447. testMineBuffer.append("W00I000W");
  448. testMineBuffer.append("W000000W");
  449. testMineBuffer.append("W00000IW");
  450. testMineBuffer.append("W000II0W");
  451. break;
  452. }
  453. for counter from 0 to 54 {
  454. int rowNdx = counter / 8;
  455. int colNdx = counter % 8;
  456. if (rowNdx > 0 && rowNdx < 7) {
  457. if (colNdx > 0 && colNdx < 7) {
  458. Spot newSpot = newSpot(counter, colNdx, rowNdx);
  459. currentMine.spots[colNdx][rowNdx] = newSpot;
  460. if (testMineBuffer.char_at(counter) == 'I') {
  461. currentMine.interestingSpots[ndxISpots] = newSpot;
  462. newSpot.isInteresting = true;
  463. ndxISpots += 1;
  464. if (rowNdx >= 5)
  465. newSpot.isCaveIn = true;
  466. }
  467. }
  468. }
  469. }
  470. }
  471. */
  472.  
  473. void mineSingleSpot() {
  474. Spot singleSpot = currentMine.spots[1][6];
  475. while (singleSpot.isCaveIn) {
  476. singleSpot = currentMine.spots[singleSpot.col + 1][6];
  477. }
  478. mineSpot(singleSpot);
  479. }
  480.  
  481.  
  482. void mineTailingSpot(Spot currentSpot) {
  483.  
  484. if (!currentSpot.mined && !currentSpot.isInteresting) {
  485. mineSpot(currentSpot);
  486. }
  487.  
  488. currentMine.tailingSpotsChecked[currentSpot.counter] = currentSpot;
  489.  
  490. if (currentSpot.mined) {
  491. Spot nextSpot;
  492. if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.col != 1) {
  493. nextSpot = currentMine.spots[currentSpot.col - 1][currentSpot.row];
  494. if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
  495. mineTailingSpot(nextSpot);
  496. }
  497.  
  498. if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.row != 1) {
  499. nextSpot = currentMine.spots[currentSpot.col][currentSpot.row - 1];
  500. if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
  501. mineTailingSpot(nextSpot);
  502. }
  503.  
  504. if (currentMine.tailingsFound < minNumberTailingsPerCave && currentSpot.col != 6) {
  505. nextSpot = currentMine.spots[currentSpot.col + 1][currentSpot.row];
  506. if (!(currentMine.tailingSpotsChecked contains nextSpot.counter))
  507. mineTailingSpot(nextSpot);
  508. }
  509. }
  510. }
  511.  
  512. void mineTailings() {
  513. Spot startSpot = currentMine.spots[1][6];
  514.  
  515. while (startSpot.isCaveIn) {
  516. startSpot = currentMine.spots[startSpot.col + 1][6];
  517. }
  518. int colCounter = startSpot.col;
  519. while (colCounter <= 6 && currentMine.tailingsFound < minNumberTailingsPerCave) {
  520. mineTailingSpot(startSpot);
  521.  
  522. if (colCounter != 6)
  523. startSpot = currentMine.spots[startSpot.col + 1][6];
  524.  
  525. colCounter += 1;
  526. }
  527. }
  528.  
  529. void handleCurrentMine() {
  530. if (have_effect($effect[Crimbonar]) == 0 && have_effect($effect[object detection]) == 0) {
  531. abortMining("This script requires that you have the " + $effect[Crimbonar] + " or " + $effect[object detection] + " effect active while starting the mining process");
  532. }
  533.  
  534. if ( maxExtraNuggets >= 0 && item_amount( $ item[nugget of crimbonium] ) > (( item_amount( $ item[cylindrical mold])) + maxExtraNuggets)){
  535. mineOnlyPeppermints = true;
  536. } else {
  537. mineOnlyPeppermints = false;
  538. }
  539.  
  540. if (mineOnlyPeppermints) {
  541. if (minNumberTailingsPerCave < 12) {
  542. print("You have selected to only mine peppermints, but the min number of peppermints is quite low, setting min number ot peppermints to a higher number to reduce kol server load of getting new cave walls.", "red");
  543. minNumberTailingsPerCave = 20;
  544. }
  545. maxFailsAllowed = 5;//If only mining peppermints all caves are valid.
  546. }
  547.  
  548. parseMine(); //First thing to do is parse the mine
  549. //useTestMine(0);
  550. calculateLongestChain(); //Then calculate longest chain
  551.  
  552. //printMine();
  553.  
  554. int numAllowedAttempts = 6 + maxFailsAllowed;
  555. if (count(currentMine.currentLongestChain.spotsInChain) > numAllowedAttempts || count(currentMine.currentLongestChain.spotsInChain) < 6 ) {
  556. print("Would fail too many times on this mine, need to go to next");
  557. mineSingleSpot();
  558. currentOperation.numCavesSkipped += 1;
  559. } else {
  560. if (!mineOnlyPeppermints) {
  561. calcShortestPathsToAllSpots();
  562. //Figure route to mine
  563. figureRoute();
  564. handleRoute();
  565. }
  566. if (currentMine.tailingsFound < minNumberTailingsPerCave) {
  567. mineTailings();
  568. }
  569.  
  570. currentOperation.numCavesFullyExplored += 1;
  571. }
  572. }
  573.  
  574. void initMiningOperations() {
  575. cli_execute("outfit save Backup");
  576. outfit("High-Radiation Mining Gear");
  577.  
  578. if (item_amount($item[Xiblaxian holo-wrist-puter]) > 0) {
  579. equip($slot[acc2], $item[Xiblaxian holo-wrist-puter]);
  580. }
  581.  
  582. currentOperation = new MiningOperation();
  583. currentOperation.startingNumNuggets = item_amount($item[nugget of Crimbonium]);
  584. currentOperation.startingNumTailings = item_amount($item[peppermint tailings]);
  585. currentOperation.numCaveIns = 0;
  586. currentOperation.numCavesSkipped = 0;
  587. currentOperation.numCavesFullyExplored = 0;
  588. currentOperation.startTime = gametime_to_int();
  589.  
  590. if (!useDynamite) {
  591. put_closet(item_amount($item[minin' dynamite]), $item[minin' dynamite]);
  592. }
  593. }
  594. void main() {
  595. initMiningOperations();
  596.  
  597. int counter = 0;
  598.  
  599. while(counter < maxCaves && my_adventures() > 0) {
  600. gotoNextMine();
  601. handleCurrentMine();
  602. counter += 1;
  603. }
  604. endMiningOperation();
  605. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement