Advertisement
yojimbos_law

new ALV WIP.ash

Aug 10th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.41 KB | None | 0 0
  1. int ascension_index = get_property("_ascension_index").to_int();
  2. boolean parse_current = false;
  3. //this is where we're going to put parsed session logs.
  4. //it'll be grouped further afterward.
  5. buffer[int][int] relevant_things_in_whole_run;
  6.  
  7. if(user_confirm("Do you want to parse your current run? If not, the run specified by the preference \"_ascension_index\" will be parsed instead.")){
  8. parse_current = true;
  9. abort("Nah, that's not a thing.");
  10. }
  11. else{
  12. if(ascension_index == 0){
  13. set_property("_user_told", get_property("_user_told").to_int()+1);
  14. if(get_property("_user_told").to_int() == 1){
  15. abort("Okay! Well, go ahead and \"set _ascension_index = \" to whichever run number (as shown in your ascension history) that you'd like parsed. I'll wait.");
  16. }
  17. else{
  18. abort("Well, we seem to have reached an impasse. You still haven't \"set _ascension_index = \" to anything useful. Give that another try. Maybe \"help set\" will help us move on with our lives?");
  19. }
  20. }
  21. }
  22.  
  23. //returns the lines of the user's ascension history that contain information about
  24. //the run to parse and the run immediately prior.
  25. //this information mostly lets the parser know which days to parse
  26. //along with the turn to stop parsing at.
  27. buffer relevant_ascension_history(int run_ID){
  28. buffer[int] ascension_history;
  29. //to do: check for existence of file,
  30. //subsequently whether it contains the run in question,
  31. //and only visit_url() if it doesn't.
  32. ascension_history[0] = ascension_history[0].append( visit_url("ascensionhistory.php?who="+my_id()));
  33. map_to_file(ascension_history,"ascension_history_"+my_id()+".txt");
  34.  
  35. string index_with_commas = run_ID.to_string();
  36. if(index_with_commas.length() == 4){
  37. index_with_commas = index_with_commas.substring(0,1)+"\\,"+index_with_commas.substring(1,4);
  38. //will break for cases where people want to parse their >10000th ascension.
  39. }
  40. string after_index_with_commas = (run_ID+1).to_string();
  41. if(after_index_with_commas.length() == 4){
  42. after_index_with_commas = after_index_with_commas.substring(0,1)+"\\,"+after_index_with_commas.substring(1,4);
  43. //will break for cases where people want to parse their >10000th ascension.
  44. }
  45. ascension_history[0].delete(0,ascension_history[0].index_of(group_string(ascension_history[0],"(valign=center>"+index_with_commas+"[^/\\d])")[0][1])-16);
  46. ascension_history[0].delete(ascension_history[0].index_of(group_string(ascension_history[0],"(valign=center>"+after_index_with_commas+"[^/\\d])")[0][1])-16, ascension_history[0].length());
  47.  
  48. return ascension_history[0];
  49. /*
  50. sample return value for run_ID = 35:
  51.  
  52. <td class=small valign=center>35   </td><td height=30 class=small valign=center>09/26/07  </td><td class=small valign=center><span title="Level at Ascension: 30">30</span>   </td><td class=small valign=center><img src="https://s3.amazonaws.com/images.kingdomofloathing.com/itemimages/club.gif" width=30 height=30 alt="Seal Clubber" title="Seal Clubber"></td><td class=small valign=center>Bad Moon  </td><td class=small valign=center><span title='Total Turns: 4,934'>4,934</span></td><td class=small valign=center><span title='Total Days: 88'>88</span></td><td><img src="https://s3.amazonaws.com/images.kingdomofloathing.com/itemimages/pictsie.gif" width=30 height=30 alt="Green Pixie (95.1%) - Total Run: Green Pixie (95.1%)" title="Green Pixie (95.1%) - Total Run: Green Pixie (95.1%)"></td><td class=small valign=center><img src="https://s3.amazonaws.com/images.kingdomofloathing.com/otherimages/spacer.gif" width=30 height=30><img src="https://s3.amazonaws.com/images.kingdomofloathing.com/itemimages/badmoon.gif" width=30 height=30 alt="Bad Moon" title="Bad Moon"></td></tr>
  53. */
  54. }
  55.  
  56.  
  57. //moving from one date to another is hard.
  58. //this goes back one day.
  59. string decrement_date(string date_to_change){
  60. int year_to_change = date_to_change.substring(0,4).to_int();
  61. int month_to_change = date_to_change.substring(4,6).to_int();
  62. int day_to_change = date_to_change.substring(6,8).to_int()-1;
  63. while(day_to_change <= 0){
  64. month_to_change += -1;
  65. if( ( ( month_to_change < 8 ) && ( month_to_change % 2 ) == 1 ) || ( month_to_change >= 8 && ( month_to_change % 2 ) == 0 ) ){
  66. day_to_change += 31;
  67. }
  68. else{
  69. if(month_to_change == 0){
  70. year_to_change += -1;
  71. month_to_change += 12;
  72. day_to_change += 31;
  73. }
  74. else{
  75. if(month_to_change == 2){
  76. //Jesus fuck. Leap years? Why does time suck so much?
  77. if((year_to_change %4) == 0){
  78. day_to_change += 29;
  79. }
  80. else{
  81. day_to_change += 28;
  82. }
  83. }
  84. else{
  85. day_to_change += 30;
  86. }
  87. }
  88. }
  89. }
  90.  
  91. string new_year_but_stringier = year_to_change.to_string();
  92. string new_month_but_stringier;
  93. string new_day_but_stringier;
  94.  
  95. if(month_to_change < 10){
  96. new_month_but_stringier = "0"+(month_to_change.to_string());
  97. }
  98. else{
  99. new_month_but_stringier = month_to_change.to_string();
  100. }
  101.  
  102. if(day_to_change < 10){
  103. new_day_but_stringier = "0"+(day_to_change.to_string());
  104. }
  105. else{
  106. new_day_but_stringier = day_to_change.to_string();
  107. }
  108.  
  109. return (new_year_but_stringier+new_month_but_stringier+new_day_but_stringier);
  110. }
  111.  
  112. //this goes forward one day.
  113. string increment_date(string date_to_change){
  114. int year_to_change = date_to_change.substring(0,4).to_int();
  115. int month_to_change = date_to_change.substring(4,6).to_int();
  116. int day_to_change = date_to_change.substring(6,8).to_int()+1;
  117.  
  118. //This sucks so much ass. Even using case-switch statements doesn't make it nice, so whatever. Ugh.
  119. if( day_to_change > 31 || ( day_to_change > 30 && ( ( ( month_to_change > 8 ) && ( month_to_change % 2 ) == 1 ) || ( month_to_change <= 8 && ( month_to_change % 2 ) == 0 ) ) ) || ( day_to_change > 29 && month_to_change == 2 ) || ( day_to_change > 28 && month_to_change == 2 && ( ( year_to_change % 4 ) != 0 ) ) ){
  120. if( ( ( month_to_change < 8 ) && ( month_to_change % 2 ) == 1 ) || ( month_to_change >= 8 && ( month_to_change % 2 ) == 0 ) ){
  121. day_to_change += -31;
  122. }
  123. else{
  124. if( month_to_change == 2 ){
  125. if( ( year_to_change % 4 ) == 0 ){
  126. day_to_change += -29;
  127. }
  128. else{
  129. day_to_change += -28;
  130. }
  131. }
  132. else{
  133. day_to_change += -30;
  134. }
  135. }
  136.  
  137. month_to_change += 1;
  138.  
  139. if(month_to_change > 12){
  140. month_to_change += -12;
  141. year_to_change += 1;
  142. }
  143. }
  144.  
  145. string new_year_but_stringier = year_to_change.to_string();
  146. string new_month_but_stringier;
  147. string new_day_but_stringier;
  148.  
  149. if(month_to_change < 10){
  150. new_month_but_stringier = "0"+(month_to_change.to_string());
  151. }
  152. else{
  153. new_month_but_stringier = month_to_change.to_string();
  154. }
  155.  
  156. if(day_to_change < 10){
  157. new_day_but_stringier = "0"+(day_to_change.to_string());
  158. }
  159. else{
  160. new_day_but_stringier = day_to_change.to_string();
  161. }
  162.  
  163. return (new_year_but_stringier+new_month_but_stringier+new_day_but_stringier);
  164. }
  165.  
  166.  
  167. buffer[int] parsed_day(string date){
  168. string[int] some_hypothetical_session_log = file_to_array("sessions/"+(my_name().to_lower_case().replace_string(" ","_"))+"_"+date+".txt");
  169. //item name[quantity][line number]
  170. item[int][int] item_lines;
  171. buffer[int] encounter_lines;
  172. monster[int] monster_lines;
  173. location[int] location_lines;
  174. int[int] turncount_lines;
  175. skill[int] skill_lines;
  176. //preference name [before value][after value][line number]
  177. string[string][string][int] preference_lines;
  178. //effect name[turns gained][line number]
  179. effect[int][int] effect_lines;
  180. familiar[int] familiar_lines;
  181. boolean[int] relevant_lines;
  182. int[int] meat_lines;
  183. string[int] relevant_items = file_to_array("data/ALV items.txt");
  184. string[int] relevant_effects = file_to_array("data/ALV effects.txt");
  185.  
  186. //now let's fill those things.
  187. foreach i in some_hypothetical_session_log{
  188. //let's check if it's an item giving message.
  189. if(some_hypothetical_session_log[i].contains_text("You acquire")){
  190. //let's check if it's an item we care about.
  191. foreach j in relevant_items{
  192. if(some_hypothetical_session_log[i].to_lower_case().contains_text(relevant_items[j].to_lower_case())){
  193. relevant_lines[i] = true;
  194. //group 4 of regex match is item quantity when it's present.
  195. //group 2 of regex match is item name.
  196. if(group_string(some_hypothetical_session_log[i],"You acquire( an item:)? (.*?)( \\((\\d+)\\))?$")[0][4] == ""){
  197. item_lines[1][i] = group_string(some_hypothetical_session_log[i],"You acquire( an item:)? (.*?)( \\((\\d+)\\))?$")[0][2].to_item();
  198. }
  199. else{
  200. item_lines[group_string(some_hypothetical_session_log[i],"You acquire( an item:)? (.*?)( \\((\\d+)\\))?$")[0][4].to_int()][i] = group_string(some_hypothetical_session_log[i],"You acquire( an item:)? (.*?)( \\((\\d+)\\))?$")[0][2].to_item();
  201. }
  202. break;
  203. }
  204. }
  205. continue;
  206. }
  207.  
  208. //let's see if it's an encounter.
  209. //check against preference_lines and turncount_lines later for freeness.
  210. if(some_hypothetical_session_log[i].contains_text("Encounter: ")){
  211. encounter_lines[i] = encounter_lines[i].append(some_hypothetical_session_log[i]);
  212. encounter_lines[i] = encounter_lines[i].delete(0,11);
  213. relevant_lines[i] = true;
  214. continue;
  215. }
  216.  
  217. //let's see if it's a turncount and location indicator.
  218. if(group_string(some_hypothetical_session_log[i],"^\\[(\\d+)\\]").count() > 0){
  219. turncount_lines[i] = group_string(some_hypothetical_session_log[i],"^\\[(\\d+)\\] (.*)$")[0][1].to_int();
  220. location_lines[i] = group_string(some_hypothetical_session_log[i],"^\\[(\\d+)\\] (.*)$")[0][2].to_location();
  221. relevant_lines[i] = true;
  222. continue;
  223. }
  224.  
  225. //let's see if it's a preference change.
  226. //2 spaces between "from" and "to" when original is blank.
  227. //trailing space when new value is blank.
  228. if(group_string(some_hypothetical_session_log[i],"^Preference (.*?) changed from (.*) to (.*)$").count() >0){
  229. preference_lines[group_string(some_hypothetical_session_log[i],"^Preference (.*?) changed from (.*) to (.*)$")[0][2]][group_string(some_hypothetical_session_log[i],"^Preference (.*?) changed from (.*) to (.*)$")[0][3]][i] = group_string(some_hypothetical_session_log[i],"^Preference (.*?) changed from (.*) to (.*)$")[0][1];
  230. continue;
  231. }
  232.  
  233. //let's see if it's an effect giving thing.
  234. if(some_hypothetical_session_log[i].contains_text("You acquire an effect: ") || some_hypothetical_session_log[i].contains_text("You lose some of an effect: ")){
  235. foreach j in relevant_effects{
  236. if(some_hypothetical_session_log[i].to_lower_case().contains_text(relevant_effects[j])){
  237. effect_lines[some_hypothetical_session_log[i].group_string("^You (?:acquire|lose some of) an effect: (.+) \\((\\-?\\d+)\\)$")[0][2].to_int()][i] = some_hypothetical_session_log[i].group_string("^You (?:acquire|lose some of) an effect: (.+) \\((\\-?\\d+)\\)$")[0][1].to_effect();
  238. relevant_lines[i] = true;
  239. break;
  240. }
  241. }
  242. continue;
  243. }
  244.  
  245. //let's see if it's a familiar changing thing.
  246. if(some_hypothetical_session_log[i].group_string("^Familiar (.*)\\(\\d+ lbs\\)$").count() > 0){
  247. familiar_lines[i] = some_hypothetical_session_log[i].group_string("^Familiar (.*)\\(\\d+ lbs\\)$")[0][1].to_familiar();
  248. relevant_lines[i] = true;
  249. continue;
  250. }
  251.  
  252. if(some_hypothetical_session_log[i].group_string("^You gain ([\\d\\,]+) Meat$").count() > 0){
  253. meat_lines[i] = some_hypothetical_session_log[i].group_string("^You gain ([\\d\\,]+) Meat$")[0][1].to_int();
  254. if(meat_lines[i] >= 1000){
  255. relevant_lines[i] = true;
  256. }
  257. }
  258. }
  259. //placeholder.
  260. return encounter_lines;
  261. }
  262.  
  263.  
  264.  
  265. buffer ascension_history_context = relevant_ascension_history(ascension_index);
  266.  
  267. /*
  268. regex backreference...reference:
  269. ascension number \1
  270. date of prism break \2\3\4
  271. class \5
  272. moonsign \6
  273. turns at ascension \7
  274. turns at prism break \8
  275. days at ascension \9
  276. days at prism break \10
  277. */
  278. //Have you accepted group_string() as your Lord and Savior recently? Now is a good time for that.
  279. string[int][int] holy_shit_what_even_is_this_shit = ascension_history_context.group_string("<td class=small valign=center>(\\d+)\\s*</td><td height=30 class=small valign=center>(\\d+)/(\\d+)/(\\d+)\s*</td><td class=small valign=center><span title=\"Level at Ascension: \\d+\">\\d+</span>\\s*</td><td class=small valign=center><img src=\"https:/\/s3\\.amazonaws\\.com/images\\.kingdomofloathing\\.com/itemimages/[^\"]*\\.gif\" width=30 height=30 alt=\"[^\"]*\" title=\"([^\"]*)\"></td><td class=small valign=center>(\\w+(?:\\s\\w+)*)\\s*</td><td class=small valign=center><span title=\'Total Turns: ([\\d\\,]+)\'>([\\d\\,]+)</span></td><td class=small valign=center><span title=\'Total Days: ([\\d\\,]+)\'>([\\d\\,]+)</span>");
  280.  
  281. int daycount = holy_shit_what_even_is_this_shit[0][10].to_int();
  282.  
  283. int turncount = holy_shit_what_even_is_this_shit[0][8].to_int();
  284.  
  285. //ascension history reports years as two digits. mafia logs use four.
  286. string likely_end_date = "20"+holy_shit_what_even_is_this_shit[0][4]+holy_shit_what_even_is_this_shit[0][3]+holy_shit_what_even_is_this_shit[0][2];
  287.  
  288.  
  289. string likely_start_date = likely_end_date;
  290. for i from 1 to daycount{
  291. likely_start_date = decrement_date(likely_start_date);
  292. }
  293.  
  294. //We'll import an extra day on both ends of the run
  295. //to catch discrepancies between ascension history date
  296. //and mafia session log date (resulting from mafia date updating
  297. //at rollover and in-game date updating 2-4 hours after).
  298. likely_end_date = increment_date(likely_end_date);
  299. likely_start_date = decrement_date(likely_start_date);
  300.  
  301. //now we'll try to find the real start date.
  302. boolean found_start = false;
  303. string[int] temporary_session = file_to_array("sessions/"+(my_name().to_lower_case().replace_string(" ","_"))+"_"+likely_start_date+".txt");
  304. string real_start_date;
  305. int starting_line;
  306. for i from 1 to 3{
  307. if(!found_start){
  308. foreach j in temporary_session{
  309. if(temporary_session[j].contains_text("Beginning New Ascension")){
  310. starting_line = j;
  311. for k from 1 to 50{
  312. if(temporary_session[k] == "Ascension #"+(ascension_index - 1).to_string()+":"){
  313. found_start = true;
  314. real_start_date = likely_start_date;
  315. break;
  316. }
  317. }
  318. if(found_start){
  319. break;
  320. }
  321. }
  322. }
  323. }
  324. if(!found_start){
  325. likely_start_date = increment_date(likely_start_date);
  326. clear(temporary_session);
  327. temporary_session = file_to_array("sessions/"+(my_name().to_lower_case().replace_string(" ","_"))+"_"+likely_start_date+".txt");
  328. }
  329. else{
  330. clear(temporary_session);
  331. }
  332. }
  333.  
  334. for i from 1 to daycount{
  335. relevant_things_in_whole_run[i] = parsed_day(real_start_date);
  336. date_increment(real_start_date);
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement