From 0c89664363cd75d758b1b590329265408de167ea Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Fri, 14 Jan 2022 10:35:31 -0300 Subject: Magic Olympics Scoreboards - And yes, it is twelve scoreboards. Extremely SQL intensive. --- npc/001-14/hocus.txt | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) (limited to 'npc/001-14') diff --git a/npc/001-14/hocus.txt b/npc/001-14/hocus.txt index 0508f7668..e1d1e886b 100644 --- a/npc/001-14/hocus.txt +++ b/npc/001-14/hocus.txt @@ -5,12 +5,246 @@ // Magic Olympics 001-14,89,89,0 script Hocus Pocus NPC_BLACKWIZARD,{ + function showScores; + function parseScores; + if ($EVENT$ != "Olympics") cwarp "Save", 0, 0; mesn; mesq l("Greetings, %s %s, I am Hocus Pocus the Grandmaster.", academicrank(), strcharinfo(0)); + do + { + next; + select + l("Scoreboards"), + l("Detailed Information"), + l("Thanks for your wise words."); + mes ""; + switch (@menu) { + case 1: + showScores(); + break; + case 2: + mesn; + mesq l("The Magic Olympics consist in twelve challenges with scoreboards."); + next; + mesn; + mesq l("Getting ranked #1 in a challenge yields you 10 points, getting ranked #2 yields you 9 points and so on."); + next; + mesn; + mesq l("Not participating in a challenge yields you zero points. In case of a tie, char creation date will be the decisive factor: Older adventurers will get the preference."); + next; + mesn; + mesq l("You also get points for participation, exchange them with Aurora back in Tulimshar before event ends."); + next; + mesn; + mesq l("The grand winner will get a %s. Both the first and second place will get a tuition at the Magic Academy.", getitemlink(BlackyCat)); + next; + mesn; + mesq l("The Magic Olympics happen roughly quarterly, but not always at the same dates. It begins on a monday and ends on the sunday. It usually happens two weeks after the Mining Union Research Request event."); + break; + } + } while (@menu != 3); close; +function t { + return gettimetick(2); +} + +function showScores { + parseScores("General Event Score", "$@moly_n$", "$@moly_v"); + mesc l("Reminder: "), 1; + mesc l("Scores are updated every 6 hours."), 1; + next; + parseScores("Energy Balls Challenge", "$@moly01_n$", "$@moly01_v"); + parseScores("Boss Fight Challenge", "$@moly02_n$", "$@moly02_v", 0); + parseScores("Fluffy Hunt Challenge", "$@moly03_n$", "$@moly03_v"); + parseScores("Chanting Challenge", "$@moly04_n$", "$@moly04_v"); + parseScores("Alchemy Master Challenge", "$@moly05_n$", "$@moly05_v"); + parseScores("Magic Power Challenge", "$@moly06_n$", "$@moly06_v"); + parseScores("Mana Exp Challenge", "$@moly07_n$", "$@moly07_v"); + parseScores("Obstacle Race Challenge", "$@moly08_n$", "$@moly08_v", t()); + parseScores("Hocus Commands Challenge", "$@moly09_n$", "$@moly09_v"); + parseScores("Survive! Challenge", "$@moly10_n$", "$@moly10_v", t()); + parseScores("Friendship Challenge", "$@moly11_n$", "$@moly11_v"); + parseScores("Intensive Mage Challenge", "$@moly12_n$", "$@moly12_v"); + mesc l("Reminder: "), 1; + mesc l("Scores close at Sunday 23:59 - No scores will be given for last minute rushes!"), 1; + return; +} + +function SCH { + .@n$ = getarg(0); + .@i = getarg(1); + return getd(sprintf("%s[%d]", .@n$, .@i)); +} + +function parseScores { + .@t$ = getarg(0); + .@n$ = getarg(1); + .@v$ = getarg(2); + .@tm = getarg(3, -1); + mes ""; + mes l("##B%s: TOP 10##b", .@t$); + if (.@tm < 0) { + mes("1."+SCH(.@n$, 0)+" ("+SCH(.@v$, 0)+")"); + mes("2."+SCH(.@n$, 1)+" ("+SCH(.@v$, 1)+")"); + mes("3."+SCH(.@n$, 2)+" ("+SCH(.@v$, 2)+")"); + mes("4."+SCH(.@n$, 3)+" ("+SCH(.@v$, 3)+")"); + mes("5."+SCH(.@n$, 4)+" ("+SCH(.@v$, 4)+")"); + mes("6."+SCH(.@n$, 5)+" ("+SCH(.@v$, 5)+")"); + mes("7."+SCH(.@n$, 6)+" ("+SCH(.@v$, 6)+")"); + mes("8."+SCH(.@n$, 7)+" ("+SCH(.@v$, 7)+")"); + mes("9."+SCH(.@n$, 8)+" ("+SCH(.@v$, 8)+")"); + mes("10."+SCH(.@n$, 9)+" ("+SCH(.@v$, 9)+")"); + } else { + mes("1."+SCH(.@n$, 0)+" ("+FuzzyTime(.@tm - SCH(.@v$, 0))+")"); + mes("2."+SCH(.@n$, 1)+" ("+FuzzyTime(.@tm - SCH(.@v$, 1))+")"); + mes("3."+SCH(.@n$, 2)+" ("+FuzzyTime(.@tm - SCH(.@v$, 2))+")"); + mes("4."+SCH(.@n$, 3)+" ("+FuzzyTime(.@tm - SCH(.@v$, 3))+")"); + mes("5."+SCH(.@n$, 4)+" ("+FuzzyTime(.@tm - SCH(.@v$, 4))+")"); + mes("6."+SCH(.@n$, 5)+" ("+FuzzyTime(.@tm - SCH(.@v$, 5))+")"); + mes("7."+SCH(.@n$, 6)+" ("+FuzzyTime(.@tm - SCH(.@v$, 6))+")"); + mes("8."+SCH(.@n$, 7)+" ("+FuzzyTime(.@tm - SCH(.@v$, 7))+")"); + mes("9."+SCH(.@n$, 8)+" ("+FuzzyTime(.@tm - SCH(.@v$, 8))+")"); + mes("10."+SCH(.@n$, 9)+" ("+FuzzyTime(.@tm - SCH(.@v$, 9))+")"); + } + dnext; + return; +} + OnInit: .distance=5; +// Scoreboards are refreshed every 6 hours +OnHour2359: +OnHour0559: +OnHour1159: +OnHour1759: + if ($EVENT$ != "Olympics") end; + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_ENBALL' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly01_n$, $@moly01_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_ICBOSS' AND i.value > 0 AND i.char_id=c.char_id ORDER BY i.value ASC LIMIT 10", $@moly02_n$, $@moly02_v); // Oddball: less is more + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_FLUFFY' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly03_n$, $@moly03_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_CHANTI' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly04_n$, $@moly04_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_ALCHMY' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly05_n$, $@moly05_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_MPWLVL' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly06_n$, $@moly06_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_MANAXP' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly07_n$, $@moly07_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_RACERS' AND i.value > 0 AND i.char_id=c.char_id ORDER BY i.value ASC LIMIT 10", $@moly08_n$, $@moly08_v); // Oddball: less is more + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_HOCUSM' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly09_n$, $@moly09_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_SURVIV' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly10_n$, $@moly10_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_FRIEND' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly11_n$, $@moly11_v); + .@nb = query_sql("SELECT c.name, i.value FROM `char_reg_num_db` AS i, `char` AS c WHERE i.key='FYMOLY_SPAMMY' AND i.char_id=c.char_id ORDER BY i.value DESC LIMIT 10", $@moly12_n$, $@moly12_v); + + /* Regenerate global scores */ + deletearray $@moly_n$; + deletearray $@moly_v; + deletearray .@moly_n$; + deletearray .@moly_v; + freeloop(true); + // Challenge 01: Energy Balls + for (.@i = 0; .@i < getarraysize($@moly01_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly01_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly01_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 02: Boss Fight + for (.@i = 0; .@i < getarraysize($@moly02_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly02_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly02_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 03: Hunt the Fluffies + for (.@i = 0; .@i < getarraysize($@moly03_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly03_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly03_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 04: Chanting + for (.@i = 0; .@i < getarraysize($@moly04_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly04_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly04_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 05: Alchemy Master + for (.@i = 0; .@i < getarraysize($@moly05_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly05_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly05_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 06: Magic Power + for (.@i = 0; .@i < getarraysize($@moly06_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly06_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly06_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 07: Mana Exp + for (.@i = 0; .@i < getarraysize($@moly07_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly07_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly07_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 08: Race + for (.@i = 0; .@i < getarraysize($@moly08_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly08_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly08_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 09: Hocus Said So + for (.@i = 0; .@i < getarraysize($@moly09_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly09_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly09_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 10: Survive! + for (.@i = 0; .@i < getarraysize($@moly10_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly10_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly10_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 11: Friendship Strength + for (.@i = 0; .@i < getarraysize($@moly11_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly11_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly11_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + // Challenge 12: Intensive Mage + for (.@i = 0; .@i < getarraysize($@moly12_v); .@i++) { + .@p = 10-.@i; + .@m = array_find(.@moly_n$, $@moly12_n$[.@i]); + if (.@m < 0) + .@m = array_push(.@moly_n$, $@moly12_n$[.@i]) - 1; + .@moly_v[.@m] += .@p; + } + freeloop(false); + /* Reorder the .@moly into $@moly */ + do + { + .@t = array_highest(.@moly_v); + if (.@t < 0 || getarraysize($@moly_v) > 10) break; + if (.@moly_v[.@t] < 1) break; + array_push($@moly_n$, .@moly_n$[.@t]); + array_push($@moly_v, .@moly_v[.@t]); + .@moly_v[.@t] = 0; + } while (true); end; } -- cgit v1.2.3-70-g09d2