Advertisement
ereinion

PirateRealm

Jun 20th, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int[string] currencies;
  2. currencies["Guns"] = 0;
  3. currencies["Grub"] = 0;
  4. currencies["Grog"] = 0;
  5. currencies["Glue"] = 0;
  6. currencies["Gold"] = 0;
  7. currencies["Fun"] = 0;
  8.  
  9. string chosen_crew;
  10.  
  11. void update_currencies() {
  12.     string s = visit_url("charpane.php");
  13.     matcher m = create_matcher(">([GF]\\w+)[<>\\/:= \\w]+?(\\d+)", s);
  14.    
  15.     while (find(m)) {
  16.         if (currencies contains group(m, 1)) {
  17.             currencies[group(m, 1)] = to_int(group(m, 2));
  18.         }
  19.     }
  20. }
  21.  
  22. boolean handle_sea_advs() {
  23.     string s = visit_url("adventure.php?snarfblat=530");
  24.     string[int] choices = available_choice_options();
  25.     int best_choice = 0;
  26.     string preferred_currency;
  27.     int i = 0;
  28.     boolean return_value = true;
  29.    
  30.     switch (last_choice()) {
  31.         case 1352: # Island #1, Who Are You?
  32.             print_html("</br><font color=008000>Choosing island #1...</font>");
  33.             best_choice = 1; # Crab Island
  34.             foreach key in choices {
  35.                 if (choices[key] == "Skull Island") {
  36.                     best_choice = key;
  37.                     break;
  38.                 }
  39.             }
  40.             break;
  41.         case 1353:  # What's Behind Island #2?
  42.             print_html("</br><font color=008000>Choosing island #2...</font>");
  43.             if (item_amount($item[tomb-opener]) > 0) {
  44.                 best_choice = 3; # Cemetery Island
  45.             } else {
  46.                 best_choice = 2; # Isla Gublar
  47.             }
  48.             break;
  49.         case 1354: # Third Island's the Charm
  50.             print_html("</br><font color=008000>Choosing island #3...</font>");
  51.             foreach key in choices {
  52.                 best_choice = 3; # Storm Island
  53.                 if (choices[key].contains_text("Red Roger")) { # Red Roger's Fortress
  54.                     best_choice = key;
  55.                     break;
  56.                 } else if (choices[key].contains_text("Glass Jack")) { # Glass Jack's Hideout‎
  57.                     best_choice = key;
  58.                 }
  59.             }
  60.             break;
  61.         case 1355: # Land Ho!
  62.             print_html("</br><font color=008000>Found an island.</font>");
  63.             best_choice = 1; # Head Inland
  64.             return_value = false;
  65.             break;
  66.         case 1356: # Smooth Sailing
  67.             print_html("</br><font color=008000>Smooth sailing.</font>");
  68.             if (chosen_crew.contains_text("Cuisinier") && currencies["Grub"] > 0) {
  69.                 best_choice = 1;
  70.             } else if (chosen_crew.contains_text("Mixologist") && currencies["Grog"] > 0) {
  71.                 best_choice = 2;
  72.             } else if (chosen_crew.contains_text("Wide-Eyed")) {
  73.                 best_choice = 3;
  74.             } else if (currencies["Grub"] > 0 && currencies["Grub"] > currencies["Grog"]) {
  75.                 best_choice = 1;
  76.             } else if (currencies["Grog"] > 0) {
  77.                 best_choice = 2;
  78.             } else {
  79.                 best_choice = 3;
  80.             }
  81.             break;
  82.         case 1357: # High Tide, Low Morale
  83.             print_html("</br><font color=008000>High Tide, Low Morale.</font>");
  84.             if (currencies["Grub"] >= 10 && currencies["Grub"] > currencies["Grog"]) {
  85.                 best_choice = 1;
  86.             } else if (currencies["Grog"] > 10) {
  87.                 best_choice = 2;
  88.             } else if (currencies["Gold"] > 30) {
  89.                 best_choice = 3;
  90.             } else {
  91.                 best_choice = 4;
  92.             }
  93.             break;
  94.         case 1358: # The Starboard is Bare
  95.             print_html("</br><font color=FF0000>Out of food, collecting...</font>");
  96.             if (chosen_crew.contains_text("Gluttonous")) {
  97.                 best_choice = 2;
  98.             } else {
  99.                 best_choice = 1;
  100.             }
  101.             break;
  102.         case 1359: # Grog for the Grogless
  103.             print_html("</br><font color=FF0000>Out of booze, collecting...</font>");
  104.             if (chosen_crew.contains_text("Cryptobotanist")) {
  105.                 best_choice = 2;
  106.             } else {
  107.                 best_choice = 1;
  108.             }
  109.             break;
  110.         case 1360: # Like Shops in the Night
  111.             print_html("</br><font color=0000FF>Shopping...</font>");
  112.             if (item_amount($item[cursed compass]) > 0) {
  113.                 # sell compass
  114.             }
  115.             while(currencies["Gold"] > 10 && i < 100) {
  116.                 if (currencies["Grub"] < 5) {
  117.                     print_html("</br><font color=008000>Getting some grub...</font>");
  118.                     run_choice(1);
  119.                     currencies["Grub"] = currencies["Grub"] + 5;
  120.                     currencies["Gold"] = currencies["Gold"] - 10;
  121.                 } else if (currencies["Grog"] < 5) {
  122.                     print_html("</br><font color=008000>Getting some grog...</font>");
  123.                     run_choice(2);
  124.                     currencies["Grog"] = currencies["Grog"] + 5;
  125.                     currencies["Gold"] = currencies["Gold"] - 10;
  126.                 } else if (currencies["Grub"] < 10) {
  127.                     print_html("</br><font color=008000>Getting some grub...</font>");
  128.                     run_choice(1);
  129.                     currencies["Grub"] = currencies["Grub"] + 5;
  130.                     currencies["Gold"] = currencies["Gold"] - 10;
  131.                 } else if (currencies["Grog"] < 10) {
  132.                     print_html("</br><font color=008000>Getting some grog...</font>");
  133.                     run_choice(2);
  134.                     currencies["Grog"] = currencies["Grog"] + 5;
  135.                     currencies["Gold"] = currencies["Gold"] - 10;
  136.                 } else if (currencies["Glue"] < 2) {
  137.                     print_html("</br><font color=008000>Getting some glue...</font>");
  138.                     run_choice(3);
  139.                     currencies["Glue"] = currencies["Glue"] + 1;
  140.                     currencies["Gold"] = currencies["Gold"] - 10;
  141.                 } else if (currencies["Grub"] < 15) {
  142.                     print_html("</br><font color=008000>Getting some grub...</font>");
  143.                     run_choice(1);
  144.                     currencies["Grub"] = currencies["Grub"] + 5;
  145.                     currencies["Gold"] = currencies["Gold"] - 10;
  146.                 } else if (currencies["Grog"] < 15) {
  147.                     print_html("</br><font color=008000>Getting some grog...</font>");
  148.                     run_choice(2);
  149.                     currencies["Grog"] = currencies["Grog"] + 5;
  150.                     currencies["Gold"] = currencies["Gold"] - 10;
  151.                 } else if (currencies["Gold"] >= 200) {
  152.                     print_html("</br><font color=008000>Purchasing a cannon!</font>");
  153.                     run_choice(4);
  154.                     currencies["Gold"] = currencies["Gold"] - 200;
  155.                 } else if (currencies["Glue"] < 3) {
  156.                     print_html("</br><font color=008000>Getting some glue...</font>");
  157.                     run_choice(3);
  158.                     currencies["Glue"] = currencies["Glue"] + 1;
  159.                     currencies["Gold"] = currencies["Gold"] - 10;
  160.                 } else if (currencies["Grub"] < 20) {
  161.                     print_html("</br><font color=008000>Getting some grub...</font>");
  162.                     run_choice(1);
  163.                     currencies["Grub"] = currencies["Grub"] + 5;
  164.                     currencies["Gold"] = currencies["Gold"] - 10;
  165.                 } else if (currencies["Grog"] < 20) {
  166.                     print_html("</br><font color=008000>Getting some grog...</font>");
  167.                     run_choice(2);
  168.                     currencies["Grog"] = currencies["Grog"] + 5;
  169.                     currencies["Gold"] = currencies["Gold"] - 10;
  170.                 } else {
  171.                     break;
  172.                 }
  173.                 i = i + 1;
  174.             }
  175.             i = 0;
  176.             # Sail away
  177.             choices = available_choice_options();
  178.             foreach key in choices {
  179.                 if (choices[key].contains_text("Sail away")) {
  180.                     print_html("</br><font color=0000FF>Done shopping, continuing journey...</font>");
  181.                     best_choice = key;
  182.                 }
  183.             }
  184.             break;
  185.         case 1361: # Avast, a Mast!
  186.             print_html("</br><font color=008000>Diving for bounty!</font>");
  187.             best_choice = 1;
  188.             break;
  189.         case 1362: # Stormy Weather
  190.             if (currencies["Glue"] > 0) {
  191.                 print_html("</br><font color=008000>Stormy weather, let's outrun it!</font>");
  192.                 best_choice = 2;
  193.             } else {
  194.                 print_html("</br><font color=008000>Stormy weather, let's hunker down since we don't have <b>glue</b>.</font>");
  195.                 best_choice = 1;
  196.             }
  197.             break;
  198.         case 1363: # Who Pirates the Pirates?
  199.         case 1364: # An Opportunity for Dastardly Do
  200.         case 1365: # A Sea Monster!
  201.             print_html("</br><font color=008000>Let's do some fighting!</font>");
  202.             best_choice = 1; # Attack
  203.             break;
  204.         case 1367: # The Ship is Wrecked
  205.             if (currencies["Glue"] > 0) {
  206.                 print_html("</br><font color=008000>Shipwreck! Let's fix it with glue.</font>");
  207.                 best_choice = 1;
  208.             } else {
  209.                 print_html("</br><font color=FF0000>Shipwreck! We'll have to wait for help...</font>");
  210.                 best_choice = 2;
  211.             }
  212.             break;
  213.         default:
  214.             print_html("</br><font color=FF0000>Unhandled choiceadventure #" + last_choice() + " on the PirateRealm seas!</font>");
  215.     }
  216.     run_choice(best_choice);
  217.     return return_value;
  218. }
  219.  
  220. void prep_ship() {
  221.     string s;
  222.     string[int] pirates;
  223.     item eyepatch = $item[PirateRealm eyepatch];
  224.     int i;
  225.     int pirateChoice;
  226.     matcher m;
  227.    
  228.     if (item_amount(eyepatch) <= 0 && !have_equipped(eyepatch)) {
  229.         print_html("</br><font color=008000>Acquiring eyepatch...</font>");
  230.         visit_url("place.php?whichplace=realm_pirate&action=pr_port");
  231.     }
  232.    
  233.     if (item_amount($item[PirateRealm eyepatch]) > 0 || have_equipped(eyepatch)) {
  234.         if (outfit("PirateRealm")) {
  235.             s = visit_url("place.php?whichplace=realm_pirate&action=pr_port");
  236.             if (s.contains_text("Head to Groggy's")) {
  237.                 // Head to Groggy's
  238.                 s = run_choice(1);
  239.                 // Crew
  240.                 print_html("</br><font color=008000>Choosing crew...</font>");
  241.                 m = create_matcher("submit value=\"the ([-\\w]+)\\s+(\\w+)\\s*\"><\\/form>", s);
  242.                 while (find(m)) {
  243.                     i = i + 1;
  244.                     // Group 1 = adjective, group 2 = noun
  245.                     pirates[i] = group(m, 1) + " " + group(m, 2);
  246.                     print_html(pirates[i]);
  247.                     if (group(m, 2) == "Harquebusier") {
  248.                         pirateChoice = i;
  249.                         break;
  250.                     }
  251.                     if (group(m, 1) == "Wide-Eyed") {
  252.                         pirateChoice = i;
  253.                     }
  254.                 }
  255.                 if (pirateChoice == 0) {
  256.                     pirateChoice = 1+random(3);
  257.                 }
  258.                 chosen_crew = pirates[pirateChoice];
  259.                 print_html("</br><font color=008000>Choosing the <b>" + chosen_crew + "</b> as crew.</font>");
  260.                 s = run_choice(pirateChoice);
  261.                 // Curio
  262.                 print_html("</br><font color=008000>Selecting curio...</font>");
  263.                 if (!pirates[pirateChoice].contains_text("Wide-Eyed") && !pirates[pirateChoice].contains_text("Harquebusier")) {
  264.                     // Compass
  265.                     print_html("</br><font color=008000>Choosing the compass.</font>");
  266.                     s = run_choice(2);
  267.                 } else {
  268.                     // Red Roger's Flag
  269.                     m = create_matcher("option value=(\\d{1,2})[\\-\"=><\\w\\s\\d]+?Red Roger's flag", s);
  270.                     if (find(m)) {
  271.                         print_html("</br><font color=008000>Choosing Red Roger's flag.</font>");
  272.                         s = run_choice(to_int(group(m,1)));
  273.                     // Harpoon
  274.                     } else {
  275.                         print_html("</br><font color=008000>Choosing harpoon.</font>");
  276.                         s = run_choice(1);
  277.                     }
  278.                 }
  279.                 // Ship
  280.                 print_html("</br><font color=008000>Choosing ship...</font>");
  281.                 m = create_matcher("option value=(\\d{1,2})[\\-\"=><\\w\\s\\d]+?The Menacing Man", s);
  282.                 // The Menacing Man o' War
  283.                 if (find(m)) {
  284.                     print_html("</br><font color=008000>Getting the Menacing Man o' War.</font>");
  285.                     s = run_choice(to_int(group(m,1)));
  286.                 // The Intimidating Galleon
  287.                 } else {
  288.                     print_html("</br><font color=008000>Getting the Intimidating Galleon.</font>");
  289.                     s = run_choice(2);
  290.                 }
  291.                 // Head for the sea
  292.                 run_choice(1);
  293.             }
  294.         }
  295.     }
  296. }
  297.  
  298. boolean handle_island_advs() {
  299.     while (adventure(1, $location[PirateRealm Island])) {}
  300.     return false;
  301. }
  302.  
  303. void main() {
  304.     int starting_fun;
  305.     boolean island_complete = false;
  306.     int i;
  307.     int j;
  308.     int[string] previous_choices;
  309.    
  310.     print_html("</br><font color=0000FF>Preparing for adventure...</font>");
  311.     foreach key in $ints[1368, 1370, 1375, 1377, 1381, 1382, 1384] { # Possible choices at the end of islands
  312.         if (get_property("choiceAdventure" + to_string(key)) != 1) {
  313.             previous_choices["choiceAdventure" + to_string(key)] = to_int(get_property("choiceAdventure" + to_string(key)));
  314.             set_property("choiceAdventure" + to_string(key), 1);
  315.         }
  316.     }
  317.    
  318.     update_currencies();
  319.     starting_fun = currencies["Fun"];
  320.    
  321.     print_html("</br><font color=0000FF>Preparing our ship...</font>");
  322.     prep_ship();
  323.    
  324.     while (!island_complete && i < 50 && my_adventures() > 0) {
  325.         while (handle_sea_advs() && j < 100) {
  326.             print_html("</br><font color=0000FF>Exploring the PirateRealm seas...</font>");
  327.             update_currencies();
  328.             j = j + 1;
  329.         }
  330.         j = 0;
  331.         while (adventure(1, $location[PirateRealm Island]) && j < 100) {
  332.             print_html("</br><font color=0000FF>Adventuring on the islands...</font>");
  333.             j = j + 1;
  334.         }
  335.         update_currencies();
  336.         if (last_choice() >= 1381 && last_choice() <= 1384) {
  337.             island_complete = true;
  338.         }
  339.         j = 0;
  340.         i = i + 1;
  341.     }
  342.    
  343.     print_html("</br><font color=0000FF>Cleaning up our settings...</font>");
  344.     foreach key in previous_choices {
  345.         set_property(key, previous_choices[key]);
  346.     }
  347.    
  348.     if (island_complete) {
  349.         print_html("</br><font color=0000FF>Our island adventure is complete!</font>");
  350.         print_html("</br><font color=0000FF>Gained <b>" + to_string(currencies["Fun"] - starting_fun) + "</b> funpoints.</font>");
  351.     } else {
  352.         print_html("</br><font color=FF0000>Couldn't finish our island adventure!</font>");
  353.     }
  354. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement