summaryrefslogtreecommitdiff
path: root/npc/001-14/hocus.txt
blob: 93b21c643e07c77f151e49da4413f496409821c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// TMW2 script
// Author:
//   Jesusalva
// Description:
//    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");
    mes "";
    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)+" ("+fnum(SCH(.@v$, 0))+")");
	    mes("2."+SCH(.@n$, 1)+" ("+fnum(SCH(.@v$, 1))+")");
	    mes("3."+SCH(.@n$, 2)+" ("+fnum(SCH(.@v$, 2))+")");
	    mes("4."+SCH(.@n$, 3)+" ("+fnum(SCH(.@v$, 3))+")");
	    mes("5."+SCH(.@n$, 4)+" ("+fnum(SCH(.@v$, 4))+")");
	    mes("6."+SCH(.@n$, 5)+" ("+fnum(SCH(.@v$, 5))+")");
	    mes("7."+SCH(.@n$, 6)+" ("+fnum(SCH(.@v$, 6))+")");
	    mes("8."+SCH(.@n$, 7)+" ("+fnum(SCH(.@v$, 7))+")");
	    mes("9."+SCH(.@n$, 8)+" ("+fnum(SCH(.@v$, 8))+")");
	    mes("10."+SCH(.@n$, 9)+" ("+fnum(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;
}