Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ascension_index = get_property("_ascension_index").to_int();
- boolean parse_current = false;
- //this is where we're going to put parsed session logs.
- //it'll be grouped further afterward.
- buffer[int][int] relevant_things_in_whole_run;
- 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.")){
- parse_current = true;
- abort("Nah, that's not a thing.");
- }
- else{
- if(ascension_index == 0){
- set_property("_user_told", get_property("_user_told").to_int()+1);
- if(get_property("_user_told").to_int() == 1){
- 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.");
- }
- else{
- 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?");
- }
- }
- }
- //returns the lines of the user's ascension history that contain information about
- //the run to parse and the run immediately prior.
- //this information mostly lets the parser know which days to parse
- //along with the turn to stop parsing at.
- buffer relevant_ascension_history(int run_ID){
- buffer[int] ascension_history;
- //to do: check for existence of file,
- //subsequently whether it contains the run in question,
- //and only visit_url() if it doesn't.
- ascension_history[0] = ascension_history[0].append( visit_url("ascensionhistory.php?who="+my_id()));
- map_to_file(ascension_history,"ascension_history_"+my_id()+".txt");
- string index_with_commas = run_ID.to_string();
- if(index_with_commas.length() == 4){
- index_with_commas = index_with_commas.substring(0,1)+"\\,"+index_with_commas.substring(1,4);
- //will break for cases where people want to parse their >10000th ascension.
- }
- string after_index_with_commas = (run_ID+1).to_string();
- if(after_index_with_commas.length() == 4){
- after_index_with_commas = after_index_with_commas.substring(0,1)+"\\,"+after_index_with_commas.substring(1,4);
- //will break for cases where people want to parse their >10000th ascension.
- }
- ascension_history[0].delete(0,ascension_history[0].index_of(group_string(ascension_history[0],"(valign=center>"+index_with_commas+"[^/\\d])")[0][1])-16);
- 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());
- return ascension_history[0];
- /*
- sample return value for run_ID = 35:
- <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>
- */
- }
- //moving from one date to another is hard.
- //this goes back one day.
- string decrement_date(string date_to_change){
- int year_to_change = date_to_change.substring(0,4).to_int();
- int month_to_change = date_to_change.substring(4,6).to_int();
- int day_to_change = date_to_change.substring(6,8).to_int()-1;
- while(day_to_change <= 0){
- month_to_change += -1;
- if( ( ( month_to_change < 8 ) && ( month_to_change % 2 ) == 1 ) || ( month_to_change >= 8 && ( month_to_change % 2 ) == 0 ) ){
- day_to_change += 31;
- }
- else{
- if(month_to_change == 0){
- year_to_change += -1;
- month_to_change += 12;
- day_to_change += 31;
- }
- else{
- if(month_to_change == 2){
- //Jesus fuck. Leap years? Why does time suck so much?
- if((year_to_change %4) == 0){
- day_to_change += 29;
- }
- else{
- day_to_change += 28;
- }
- }
- else{
- day_to_change += 30;
- }
- }
- }
- }
- string new_year_but_stringier = year_to_change.to_string();
- string new_month_but_stringier;
- string new_day_but_stringier;
- if(month_to_change < 10){
- new_month_but_stringier = "0"+(month_to_change.to_string());
- }
- else{
- new_month_but_stringier = month_to_change.to_string();
- }
- if(day_to_change < 10){
- new_day_but_stringier = "0"+(day_to_change.to_string());
- }
- else{
- new_day_but_stringier = day_to_change.to_string();
- }
- return (new_year_but_stringier+new_month_but_stringier+new_day_but_stringier);
- }
- //this goes forward one day.
- string increment_date(string date_to_change){
- int year_to_change = date_to_change.substring(0,4).to_int();
- int month_to_change = date_to_change.substring(4,6).to_int();
- int day_to_change = date_to_change.substring(6,8).to_int()+1;
- //This sucks so much ass. Even using case-switch statements doesn't make it nice, so whatever. Ugh.
- 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 ) ) ){
- if( ( ( month_to_change < 8 ) && ( month_to_change % 2 ) == 1 ) || ( month_to_change >= 8 && ( month_to_change % 2 ) == 0 ) ){
- day_to_change += -31;
- }
- else{
- if( month_to_change == 2 ){
- if( ( year_to_change % 4 ) == 0 ){
- day_to_change += -29;
- }
- else{
- day_to_change += -28;
- }
- }
- else{
- day_to_change += -30;
- }
- }
- month_to_change += 1;
- if(month_to_change > 12){
- month_to_change += -12;
- year_to_change += 1;
- }
- }
- string new_year_but_stringier = year_to_change.to_string();
- string new_month_but_stringier;
- string new_day_but_stringier;
- if(month_to_change < 10){
- new_month_but_stringier = "0"+(month_to_change.to_string());
- }
- else{
- new_month_but_stringier = month_to_change.to_string();
- }
- if(day_to_change < 10){
- new_day_but_stringier = "0"+(day_to_change.to_string());
- }
- else{
- new_day_but_stringier = day_to_change.to_string();
- }
- return (new_year_but_stringier+new_month_but_stringier+new_day_but_stringier);
- }
- buffer[int] parsed_day(string date){
- string[int] some_hypothetical_session_log = file_to_array("sessions/"+(my_name().to_lower_case().replace_string(" ","_"))+"_"+date+".txt");
- //item name[quantity][line number]
- item[int][int] item_lines;
- buffer[int] encounter_lines;
- monster[int] monster_lines;
- location[int] location_lines;
- int[int] turncount_lines;
- skill[int] skill_lines;
- //preference name [before value][after value][line number]
- string[string][string][int] preference_lines;
- //effect name[turns gained][line number]
- effect[int][int] effect_lines;
- familiar[int] familiar_lines;
- boolean[int] relevant_lines;
- int[int] meat_lines;
- string[int] relevant_items = file_to_array("data/ALV items.txt");
- string[int] relevant_effects = file_to_array("data/ALV effects.txt");
- //now let's fill those things.
- foreach i in some_hypothetical_session_log{
- //let's check if it's an item giving message.
- if(some_hypothetical_session_log[i].contains_text("You acquire")){
- //let's check if it's an item we care about.
- foreach j in relevant_items{
- if(some_hypothetical_session_log[i].to_lower_case().contains_text(relevant_items[j].to_lower_case())){
- relevant_lines[i] = true;
- //group 4 of regex match is item quantity when it's present.
- //group 2 of regex match is item name.
- if(group_string(some_hypothetical_session_log[i],"You acquire( an item:)? (.*?)( \\((\\d+)\\))?$")[0][4] == ""){
- item_lines[1][i] = group_string(some_hypothetical_session_log[i],"You acquire( an item:)? (.*?)( \\((\\d+)\\))?$")[0][2].to_item();
- }
- else{
- 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();
- }
- break;
- }
- }
- continue;
- }
- //let's see if it's an encounter.
- //check against preference_lines and turncount_lines later for freeness.
- if(some_hypothetical_session_log[i].contains_text("Encounter: ")){
- encounter_lines[i] = encounter_lines[i].append(some_hypothetical_session_log[i]);
- encounter_lines[i] = encounter_lines[i].delete(0,11);
- relevant_lines[i] = true;
- continue;
- }
- //let's see if it's a turncount and location indicator.
- if(group_string(some_hypothetical_session_log[i],"^\\[(\\d+)\\]").count() > 0){
- turncount_lines[i] = group_string(some_hypothetical_session_log[i],"^\\[(\\d+)\\] (.*)$")[0][1].to_int();
- location_lines[i] = group_string(some_hypothetical_session_log[i],"^\\[(\\d+)\\] (.*)$")[0][2].to_location();
- relevant_lines[i] = true;
- continue;
- }
- //let's see if it's a preference change.
- //2 spaces between "from" and "to" when original is blank.
- //trailing space when new value is blank.
- if(group_string(some_hypothetical_session_log[i],"^Preference (.*?) changed from (.*) to (.*)$").count() >0){
- 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];
- continue;
- }
- //let's see if it's an effect giving thing.
- 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: ")){
- foreach j in relevant_effects{
- if(some_hypothetical_session_log[i].to_lower_case().contains_text(relevant_effects[j])){
- 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();
- relevant_lines[i] = true;
- break;
- }
- }
- continue;
- }
- //let's see if it's a familiar changing thing.
- if(some_hypothetical_session_log[i].group_string("^Familiar (.*)\\(\\d+ lbs\\)$").count() > 0){
- familiar_lines[i] = some_hypothetical_session_log[i].group_string("^Familiar (.*)\\(\\d+ lbs\\)$")[0][1].to_familiar();
- relevant_lines[i] = true;
- continue;
- }
- if(some_hypothetical_session_log[i].group_string("^You gain ([\\d\\,]+) Meat$").count() > 0){
- meat_lines[i] = some_hypothetical_session_log[i].group_string("^You gain ([\\d\\,]+) Meat$")[0][1].to_int();
- if(meat_lines[i] >= 1000){
- relevant_lines[i] = true;
- }
- }
- }
- //placeholder.
- return encounter_lines;
- }
- buffer ascension_history_context = relevant_ascension_history(ascension_index);
- /*
- regex backreference...reference:
- ascension number \1
- date of prism break \2\3\4
- class \5
- moonsign \6
- turns at ascension \7
- turns at prism break \8
- days at ascension \9
- days at prism break \10
- */
- //Have you accepted group_string() as your Lord and Savior recently? Now is a good time for that.
- 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>");
- int daycount = holy_shit_what_even_is_this_shit[0][10].to_int();
- int turncount = holy_shit_what_even_is_this_shit[0][8].to_int();
- //ascension history reports years as two digits. mafia logs use four.
- 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];
- string likely_start_date = likely_end_date;
- for i from 1 to daycount{
- likely_start_date = decrement_date(likely_start_date);
- }
- //We'll import an extra day on both ends of the run
- //to catch discrepancies between ascension history date
- //and mafia session log date (resulting from mafia date updating
- //at rollover and in-game date updating 2-4 hours after).
- likely_end_date = increment_date(likely_end_date);
- likely_start_date = decrement_date(likely_start_date);
- //now we'll try to find the real start date.
- boolean found_start = false;
- string[int] temporary_session = file_to_array("sessions/"+(my_name().to_lower_case().replace_string(" ","_"))+"_"+likely_start_date+".txt");
- string real_start_date;
- int starting_line;
- for i from 1 to 3{
- if(!found_start){
- foreach j in temporary_session{
- if(temporary_session[j].contains_text("Beginning New Ascension")){
- starting_line = j;
- for k from 1 to 50{
- if(temporary_session[k] == "Ascension #"+(ascension_index - 1).to_string()+":"){
- found_start = true;
- real_start_date = likely_start_date;
- break;
- }
- }
- if(found_start){
- break;
- }
- }
- }
- }
- if(!found_start){
- likely_start_date = increment_date(likely_start_date);
- clear(temporary_session);
- temporary_session = file_to_array("sessions/"+(my_name().to_lower_case().replace_string(" ","_"))+"_"+likely_start_date+".txt");
- }
- else{
- clear(temporary_session);
- }
- }
- for i from 1 to daycount{
- relevant_things_in_whole_run[i] = parsed_day(real_start_date);
- date_increment(real_start_date);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement