summaryrefslogtreecommitdiff
path: root/world/map/npc/functions/vault.txt
blob: f2c51387c019019ed5b24eca84c42e13a1b05290 (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
// Mirror Lake Protocol and The Mana World Vault utilities
// TMWA is hopelessy broken, so most helpers simply don't exist.
//
// Author: jesusalva

function|script|VaultLogin
{
    if (##VAULT < 1) goto L_Return;

    // Imports & Vitals
    callsub S_Exp;
    callsub S_Gold;
    callsub S_Preset;

    // Quest Handlers
    callsub S_Quest_CR1;

    // Mirror lake
    callsub S_MirrorLake;

    // Clean up
    set @last_preset, 0;
    return; // go back to global handler

S_Return: // this is to end execution of a sub
    return;

L_Return:
    return;

S_Exp:
    if (##ADD_LVL < 1) goto S_Return;
    set #EXP_CREDIT, #EXP_CREDIT + ##ADD_LVL;
    set ##ADD_LVL, 0;
    return;

S_Gold:
    if (##ADD_GP < 1) goto S_Return;
    set Zeny, Zeny + ##ADD_GP;
    set ##ADD_GP, 0;
    return;

S_Preset:
    if (##PRESET < 1) goto S_Return;
    set @last_preset, (#X21 & BYTE_3_MASK) >> BYTE_3_SHIFT;
    set #X21, (#X21 & ~(BYTE_3_MASK)) | (##PRESET << BYTE_3_SHIFT);

    // Each preset is 5 levels (Preset 1 = Lv 5, Preset 10 = Lv 50, Max Preset 20 - hard limit is 127)
    // TODO: Give more ammo, iron powder, sulphur powder, etc. instead of equips
    // Give also some bug legs and maggot slime if applicable?
    /* Handle weapons */
    /*
    if (##PRESET >= 1 && @last_preset < 1)
        getitem "SharpKnife",1;
    if (##PRESET >= 2 && @last_preset < 2)
        getitem "SlingBullet",500;
    if (##PRESET >= 3 && @last_preset < 3)
        getitem "Bow",1;
    if (##PRESET >= 3 && @last_preset < 3)
        getitem "Arrow",500;
    if (##PRESET >= 4 && @last_preset < 4)
        getitem "Arrow",500;
    if (##PRESET >= 5 && @last_preset < 5)
        getitem "JeansShorts",1;
    if (##PRESET >= 6 && @last_preset < 6)
        getitem "IronArrow",500;
    if (##PRESET >= 7 && @last_preset < 7)
        getitem "IronArrow",500;
    if (##PRESET >= 8 && @last_preset < 8)
        getitem "IronPowder", 150;
    if (##PRESET >= 9 && @last_preset < 9)
        getitem "BoneArrows",150;
    if (##PRESET >= 10 && @last_preset < 10)
        getitem "BoneArrows",150;
    if (##PRESET >= 11 && @last_preset < 11)
        getitem "SilverArrow",200;
    if (##PRESET >= 12 && @last_preset < 12)
        getitem "ThornArrow",100;
    if (##PRESET >= 13 && @last_preset < 13)
        getitem "SilverArrow",200;
    if (##PRESET >= 14 && @last_preset < 14)
        getitem "TerraniteArrow",100;
    if (##PRESET >= 15 && @last_preset < 15)
        getitem "ArmorBreaker",100;
    if (##PRESET >= 16 && @last_preset < 16)
        getitem "ThornArrow",100;
    if (##PRESET >= 17 && @last_preset < 17)
        getitem "TerraniteArrow",100;
    if (##PRESET >= 18 && @last_preset < 18)
        getitem "IronPowder", 150;
    if (##PRESET >= 19 && @last_preset < 19)
        getitem "TerraniteArrow",250;
    */
    set ##PRESET, 0;
    return;

////////////////////////////////
S_Quest_CR1:
    if (!(##01_CRQUEST & 1)) goto S_Return;
    if (##03_TMWWORLD & MLP_CR_DEBUT) goto S_Return;
    // Check if you can receive the rewards
    getinventorylist;
    if (@inventorylist_count >= 96) goto S_Return;
    // Mark quest as done and issue rewards
    set BOSS_POINTS, BOSS_POINTS + 871;
    set ##03_TMWWORLD, ##03_TMWWORLD | MLP_CR_DEBUT;
    getitem WhiteCake, 1;
    getitem ChocolateCake, 1;
    getitem OrangeCake, 1;
    getitem AppleCake, 1;
    message strcharinfo(0), "Mirror Lake : You gained 871 boss points.";
    return;

////////////////////////////////
S_MirrorLake:
    // Wipe any existing TMWA internal mirror lake information
    set ##VAULT_GOTO, 0;
    set ##VAULT_MLTO, 0;
    // TODO: Put the Mirror Lake Portal into the shipwreck? (see portal #2)
    set .@gto, call("get_byte",   ##00_INFO, 3);
    set .@mlp, call("get_nibble", ##00_INFO, 5);
    // If we're moving from Mirror Lake to TMW
    if (.@gto != WORLD_ID) goto S_MirrorFix;
    debugmes "Vault User "+##VAULT+" moved to lake "+.@mlp;
    if (.@mlp == 1) warp "013-2", 37, 23; // Hurnscald Mirror Lake
    if (.@mlp == 2) warp "002-1", 30, 58; // Tulimshar Mirror Lake
    // Unset the target lake/world
    void call("set_byte",   ##00_INFO, 3, 0);
    void call("set_nibble", ##00_INFO, 5, 0);
    return;

// We've moved to the wrong world, so preserve it.
S_MirrorFix:
    set ##VAULT_GOTO, call("get_byte",   ##00_INFO, 3);
    set ##VAULT_MLTO, call("get_nibble", ##00_INFO, 5);
    return;
}


// Remember: ##VAULT_EXP, ##VAULT_GOTO, ##VAULT_MLTO for Mirror Lake Protocol
// However, without kick(7), it is not really worth anything - so I presumed 7
// Remember: Quote symbols are illegal, simple or double, except for parameter
// To reset the database:
//    cleararray $EXPORT_DATA$[0], "", 254;
//    set $EXPORT_MAX_ID, 0;

// Schemas:
//API_VAULT: "UID", ##VAULT, "GID", getcharid(3)
//API_SENDMAIL: "UID": ##VAULT, "MSG": "message", "TITLE": "subject line"
//
// Using the API_EXPORT hack for TMWA:
//
// set $@API_PROTOCOL, API_SENDMAIL;
// set $@API_DATA$, "'UID': 0, 'TITLE': 'About TMWA', 'MSG': 'I hate it!'";
// callfunc "FlushAPI";
//
// (The curly brace is added to DATA on its own)
function|script|FlushAPI
{
    // Function called improperly
    // DATA cannot be null or the array order will crash
    if ($@API_PROTO <= 0) goto L_Dumb;
    if ($@API_DATA$ == "") goto L_Dumb;

    // Save it to mapreg
    // The script will strip "##"
    // and convert the part after to a JSON dict
    set $EXPORT_DATA$[$EXPORT_MAX_ID], $@API_PROTO + "##" + $@API_DATA$;
    set $@API_PROTO, "";
    set $@API_DATA$, "";

    // Update TMWA tracker
    set $EXPORT_MAX_ID, $EXPORT_MAX_ID + 1;

    // Keep in mind an array can only go up to 255
    // Trying to go past that, causes a SIGSEGV and map server dies
    // So we periodically truncate the table when it's full
    if ($EXPORT_MAX_ID > 240) goto L_Flush;
    if ($EXPORT_MAX_ID == 120) goto L_Flush2;
    return;

L_Dumb:
    debugmes "FlushAPI called without enough arguments";
    debugmes " - $@API_PROTO, API_* constant";
    debugmes " - $@API_DATA$, json dict without curly braces";
    return;

L_Flush:
    cleararray $EXPORT_DATA$[0], "", 220;
    set $EXPORT_MAX_ID, 0;
    return;

L_Flush2:
    cleararray $EXPORT_DATA$[220], "", 25;
    return;
}

function|script|VaultLogout
{
    if (##VAULT < 1) goto L_Return;
    // TODO: Or #VAULT ? Which of the two is set?
    set $@API_PROTOCOL, API_VAULT;
    set $@API_DATA$, "'UID': "+##VAULT+", 'GID': "+getcharid(3);
    callfunc "FlushAPI";

    return;

L_Return:
    return;
}

// MirrorLakeSendTo(World)
function|script|MirrorLakeSendTo
{
    if (##VAULT < 1) goto L_Return;
    set ##VAULT_GOTO, getarg(0);
    // This is TMWA - so it'll always use Lake #0 for performance reasons
    set $@API_PROTOCOL, API_VAULT;
    set $@API_DATA$, "'UID': "+##VAULT+", 'GID': "+getcharid(3);
    callfunc "FlushAPI";
    message strcharinfo(0), "Darkness fills your vision...";
    // TODO: Misc effects
    // TODO: Sleep for 10~15 seconds (for mapreg)
    // TODO: Disconnect user
    return;

L_Return:
    return;
}