Advertisement
kolpastebin

Capital.ash

Apr 12th, 2017
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. //This script is in the public domain.
  2.  
  3. string __version = "1.0";
  4.  
  5. int __backoffice_script_requests_made = 0;
  6. int [item] __minimum_price_cache;
  7. int minimumMallPrice(item it, boolean allow_limited, boolean allow_cache)
  8. {
  9. //Safety:
  10. if (allow_cache)
  11. {
  12. if (__minimum_price_cache contains it)
  13. return __minimum_price_cache[it];
  14. }
  15. __backoffice_script_requests_made += 1;
  16. if (__backoffice_script_requests_made >= 10000) //there are about that many items in the game
  17. {
  18. abort("Script made too many server requests; aborting as a safety feature.");
  19. return -1;
  20. }
  21. print_html("Looking up price for " + it + "...");
  22. buffer page_text = visit_url("backoffice.php?iid=" + it.to_int() + "&action=prices&ajax=1");
  23.  
  24. string unlimited = page_text.group_string("<tr><td>unlimited:</td><td><b>([^<]*)</b>")[0][1];
  25. string limited = page_text.group_string("<tr><td>limited:</td><td><b>([^<]*)</b>")[0][1];
  26.  
  27. int price = -1;
  28. if (unlimited != "")
  29. price = unlimited.to_int();
  30. if (limited != "" && allow_limited)
  31. {
  32. int value = limited.to_int();
  33. if (price == -1 || price > value)
  34. price = value;
  35. }
  36. __minimum_price_cache[it] = price;
  37. return price;
  38. }
  39.  
  40. int minimumMallPrice(item it, boolean allow_limited)
  41. {
  42. return minimumMallPrice(it, allow_limited, false);
  43. }
  44.  
  45. string convertIntegerToStringWithCommas(int value)
  46. {
  47. string step_1 = value.to_string();
  48. //Is ln() in mafia...?
  49. int integer_count = 0;
  50. for i from 0 to step_1.length() - 1
  51. {
  52. string s = step_1.char_at(i);
  53. if (is_integer(s) && s != "-")
  54. integer_count += 1;
  55. }
  56. if (integer_count <= 3)
  57. return step_1;
  58.  
  59. buffer result;
  60. int counter = 0;
  61. if (integer_count % 3 == 1)
  62. counter = 2;
  63. if (integer_count % 3 == 2)
  64. counter = 1;
  65. if (integer_count % 3 == 0)
  66. counter = 0;
  67. for i from 0 to step_1.length() - 1
  68. {
  69. string c = step_1.char_at(i);
  70. result.append(c);
  71. if (is_integer(c) && c != "-")
  72. counter += 1;
  73. if (counter >= 3 && i != step_1.length() - 1)
  74. {
  75. result.append(",");
  76. counter = 0;
  77. }
  78. }
  79.  
  80. return result;
  81. }
  82.  
  83. void main()
  84. {
  85. if (false)
  86. {
  87. //minor test:
  88. foreach i in $ints[1, 10, 100, 1000, 50000, 200123123, 3125235, 40365669, 4575705693, -123456789]
  89. print_html(convertIntegerToStringWithCommas(i));
  90. return;
  91. }
  92. print_html("Capital.ash version " + __version);
  93.  
  94. refresh_shop(); //won't load by default
  95. item [int] owned_items;
  96. int [item] owned_items_amount;
  97. int [item] owned_items_price;
  98.  
  99. int liquid_meat = my_meat() + my_storage_meat() + my_closet_meat();
  100. int total_meat_value = liquid_meat;
  101. int display_case_meat_value = 0;
  102. int store_meat_value = 0;
  103.  
  104. int [item] items_equipped_on_familiars;
  105. //equipped_amount() does not take into account familiars we aren't running at the moment:
  106. foreach f in $familiars[]
  107. {
  108. if (!f.have_familiar())
  109. continue;
  110. if (my_familiar() == f)
  111. continue;
  112. item equipped_item = f.familiar_equipped_equipment();
  113. if (equipped_item != $item[none])
  114. items_equipped_on_familiars[equipped_item] += 1;
  115. }
  116.  
  117. foreach it in $items[]
  118. {
  119. if (!it.tradeable) continue;
  120. int amount_own = it.item_amount() + it.equipped_amount() + it.closet_amount() + it.shop_amount() + it.storage_amount() + it.display_amount();
  121. if (items_equipped_on_familiars contains it)
  122. amount_own += items_equipped_on_familiars[it];
  123. if (amount_own == 0)
  124. continue;
  125.  
  126. owned_items[owned_items.count()] = it;
  127. owned_items_amount[it] = amount_own;
  128.  
  129. owned_items_price[it] = -1;
  130.  
  131. }
  132.  
  133. boolean [item] additional_items_to_search;
  134. //Find zappables/foldables:
  135. foreach it in owned_items_price
  136. {
  137. foreach it2 in it.get_related("fold")
  138. {
  139. additional_items_to_search[it2] = true;
  140. }
  141. foreach it2 in it.get_related("zap")
  142. {
  143. additional_items_to_search[it2] = true;
  144. }
  145. }
  146. //Add them to prices to search:
  147. foreach it in additional_items_to_search
  148. {
  149. owned_items_price[it] = -1;
  150. }
  151. //Discover prices:
  152. foreach it in owned_items_price
  153. {
  154. int price = 0;
  155.  
  156. int age_limit = 60;
  157. int historical_price = it.historical_price();
  158. if (historical_price > 100000)
  159. age_limit = 15;
  160. if (historical_price < 1000)
  161. age_limit = 120;
  162. if (historical_price > 100000000)
  163. age_limit = 3;
  164.  
  165. int historical_age = it.historical_age();
  166.  
  167. if (historical_age > age_limit)
  168. price = it.mall_price();
  169. else
  170. price = historical_price;
  171.  
  172. if (price >= 1000000 || price * owned_items_amount[it] >= 2000000)
  173. {
  174. boolean allow_limited = true;
  175. if (owned_items_amount[it] >= 20)
  176. allow_limited = false;
  177. price = minimumMallPrice(it, allow_limited);
  178. }
  179. int theoretical_mall_minimum = MAX(100, it.autosell_price() * 2);
  180. if (price == theoretical_mall_minimum)
  181. {
  182. //assume mall minimum is essentially worthless (this may not be true for some things, like bricko bricks?)
  183. if (it.autosell_price() > 0)
  184. price = it.autosell_price();
  185. else
  186. price = 1;
  187. }
  188. owned_items_price[it] = price;
  189. }
  190. //Make the price of an item equal to the minimum of its related:
  191. //(i.e., a radio free baseball cap, pants, and foil should all be the same "value", since they're zappable)
  192. foreach it, price in owned_items_price
  193. {
  194. foreach it2 in it.get_related("fold")
  195. {
  196. price = min(price, owned_items_price[it2]);
  197. }
  198. foreach it2 in it.get_related("zap")
  199. {
  200. price = min(price, owned_items_price[it2]);
  201. }
  202. owned_items_price[it] = price;
  203. }
  204.  
  205. //Calculate total meat value:
  206. foreach it, price in owned_items_price
  207. {
  208. total_meat_value += price * owned_items_amount[it];
  209. display_case_meat_value += price * it.display_amount();
  210. store_meat_value += price * it.shop_amount();
  211. }
  212.  
  213. sort owned_items by owned_items_amount[value] * owned_items_price[value];
  214.  
  215. //Display:
  216. foreach key, it in owned_items
  217. {
  218. string line;
  219. line = owned_items_amount[it] + " ";
  220. if (owned_items_amount[it] > 1)
  221. line += it.plural;
  222. else
  223. line += it;
  224. line += " worth ";
  225. line += convertIntegerToStringWithCommas(owned_items_price[it]);
  226. line += " each for a total of ";
  227. line += convertIntegerToStringWithCommas(owned_items_price[it] * owned_items_amount[it]);
  228. print_html(line);
  229. }
  230. print_html("Liquid meat: " + convertIntegerToStringWithCommas(liquid_meat));
  231. if (display_case_meat_value > 0)
  232. print_html("Display case worth: " + convertIntegerToStringWithCommas(display_case_meat_value));
  233. if (store_meat_value > 0)
  234. print_html("Mall store worth: " + convertIntegerToStringWithCommas(store_meat_value));
  235. print_html("Total net worth: " + convertIntegerToStringWithCommas(total_meat_value));
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement