summaryrefslogtreecommitdiff
path: root/npc/commands/debug-preset.txt
blob: 92d9314b840969177693f8f2ee028033c45c5dfe (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
// Preset / routine system
// Author:
//    gumi
// Description:
//    allows to execute multiple commands in a single step
//    to ease testing and debugging
//
// usage: @pre [options] <instruction>[, <instruction>...]
// usage: DoRoutine "[options] <instruction>[, <instruction>...]";
//
// example: @pre -s a22 v14
//          resets all stats, gives 22 agi, gives 14 vit
//
// ^ actual documentation may come one day, when I feel like it
//   *hides*
// Note from Jesusalva: I do not trust this script works well for TMW2.

function	script	DoRoutine	{

    function parsev {
        // parsev(base, patterns{, min{, max}}) => value
        .@value = getarg(0, 0);
        .@raw$ = getarg(1, "");
        .@patterns = explode(.@patterns$, .@raw$, "|");

        for (.@pattern = 0; .@pattern < .@patterns; ++.@pattern)
        {
            .@pattern$ = .@patterns$[.@pattern];
            .@len = getstrlen(.@pattern$);

            if (charat(.@pattern$, 0) == "=" && .@len >= 2)
            {
                .@value = atoi(delchar(.@pattern$, 0));
                break;
            }

            else if (charat(.@pattern$, 0) == "+" && .@len >= 2)
            {
                if (charat(.@pattern$, 1) == "+" && getargcount() >= 4)
                    .@value = getarg(3);
                else
                    .@value += atoi(delchar(.@pattern$, 0));
            }

            else if (charat(.@pattern$, 0) == "-" && .@len >= 2)
            {
                if (charat(.@pattern$, 1) == "-" && getargcount() >= 3)
                    .@value = getarg(2);
                else
                    .@value -= atoi(delchar(.@pattern$, 0));
            }

            else if (charat(.@pattern$, 0) == ">" && .@len >= 2)
            {
                if (charat(.@pattern$, 1) == "=" && .@len >= 3)
                    .@value = max(atoi(substr(.@pattern$, 2, .@len - 1)), .@value);
                else
                    .@value = max(atoi(delchar(.@pattern$, 0)) + 1, .@value);
            }

            else if (charat(.@pattern$, 0) == "<" && .@len >= 2)
            {
                if (charat(.@pattern$, 1) == "=" && .@len >= 3)
                    .@value = min(atoi(substr(.@pattern$, 2, .@len - 1)), .@value);
                else
                    .@value = min(atoi(delchar(.@pattern$, 0)) - 1, .@value);
            }

            else if (.@len >= 1)
            {
                .@value = atoi(.@pattern$);
                break;
            }
        }

        if (getargcount() >= 3)
            .@value = max(getarg(2), .@value);

        if (getargcount() >= 4)
            .@value = min(getarg(3), .@value);

        return .@value;
    }

    .@routine$ = strip(getarg(0,""));
    .@m = explode(.@routine$[0], .@routine$, " "); // prep the base array

    if (charat(.@routine$[0], 0) == "-")
    {
        if (compare(.@routine$[0], "t"))
        {
            clearitem;
        }

        if (compare(.@routine$[0], "e"))
        {
            nude;
        }

        if (compare(.@routine$[0], "k"))
        {
            resetskill;
        }

        if (compare(.@routine$[0], "s"))
        {
            resetstatus;
        }

        if (compare(.@routine$[0], "x"))
        {
            resetlvl 2;
        }

        if (compare(.@routine$[0], "q"))
        {
            //doevent "::OnGlobalQuestReset"; // executes in all quest npcs // FIXME: maybe have a `resetquest` buildin?
            // FIXME: ^ need a buildin that can run *right now* instead of on script end
        }

        if (compare(.@routine$[0], "n"))
        {
            closeclientdialog;
        }

        .@i = 1;
    }

    for (; .@i < .@m; ++.@i)
    {
        .@type = ord(charat(strip(.@routine$[.@i]), 0));

        if (.@type > 0)
        {
            .@raw$ = delchar(.@routine$[.@i], 0);
            .@args = explode(.@args$, .@raw$, ",");
            .@a = atoi(.@args$[0]);
            .@b = atoi(.@args$[1]);
            .@c = atoi(.@args$[2]);
            .@d = atoi(.@args$[3]);
            .@e = atoi(.@args$[4]);

            switch (.@type)
            {
            case 97: /* a => Agi */
                .@base = readparam(bAgi);
                statusup2 bAgi, parsev(.@base, .@args$[0], 1, 99) - .@base;
                break;
            /* (b) */
            case 99: /* c => job */
                jobchange max(0, min(6, .@a));
                break;
            case 100: /* d => Dex */
                .@base = readparam(bDex);
                statusup2 bDex, parsev(.@base, .@args$[0], 1, 99) - .@base;
                break;
            case 101: /* e => equip */
                equip max(1, min(32767, .@a));
                break;
            /* (f) */
            /* (g) => gender (reserved) */
            /* (h) */
            case 105: /* i => Int */
                .@base = readparam(bInt);
                statusup2 bInt, parsev(.@base, .@args$[0], 1, 99) - .@base;
                break;
            /* (j) */
            case 107: /* k => skill */
                .@k = max(1, min(32767, .@a));
                skill .@k, parsev(getskilllv(.@k), .@args$[1], 0, 10), 0;
                break;
            case 108: /* l => luk */
                .@base = readparam(bLuk);
                statusup2 bLuk, parsev(.@base, .@args$[0], 1, 99) - .@base;
                break;
            /* (m) => mercenary (reserved) */
            /* (n) => talk to npc (reserved) */
            /* (o) */
            case 112: /* p => pet */
                makepet max(1002, min(32767, .@a));
                break;
            case 113: /* q => quest */
                .@q = max(0, min(32767, .@a));
                setq .@q, parsev(getq(.@q), .@args$[1]),
                          parsev(getq2(.@q), .@args$[2]),
                          parsev(getq3(.@q), .@args$[3]),
                          parsev(getqtime(.@q), .@args$[4]);
                break;
            /* (r) */
            case 115: /* s => Str */
                .@base = readparam(bStr);
                statusup2 bStr, parsev(.@base, .@args$[0], 1, 99) - .@base;
                break;
            case 116: /* t => item */
                .@t = max(1, min(32767, .@a));
                .@c = countitem(.@t);
                .@v = parsev(.@c, .@args$[1], 0, 32767);
                if (.@c > .@v)
                    delitem .@t, .@c - .@v;
                else if (.@c < .@v)
                    getitem .@t, .@v - .@c;
                break;
            /* (u) */
            case 118: /* v => vit */
                .@base = readparam(bVit);
                statusup2 bVit, parsev(.@base, .@args$[0], 1, 99) - .@base;
                break;
            case 119: /* w => warp */
                warp .@args$[0], .@b, .@c;
                break;
            case 120: /* x => base level */
                BaseLevel = parsev(BaseLevel, .@args$[0], 1, 99);
                BaseExp = parsev(BaseExp, .@args$[1], 0);
                break;
            case 121: /* y => job level */
                JobLevel = parsev(JobLevel, .@args$[0], 1, 255);
                JobExp = parsev(JobExp, .@args$[1], 0);
                break;
            case 122: /* z => zeny */
                Zeny = parsev(Zeny, .@args$[0], 0, 0x7FFFFFFE);
                BankVault = parsev(BankVault, .@args$[1], 0, MAX_BANK_ZENY);
                break;
            }
        }
    }

    return;
}

-	script	@pre	32767,{
    end;

OnCall:
    if (!debug && !is_admin())
    {
        end;
    }
    if (.@atcmd_parameters$[0] != "")
    {
        .@atcmd_parameters$[0] = implode(.@atcmd_parameters$[0], " ");
    }
    DoRoutine strip(.@atcmd_parameters$[0]);
    end;

OnInit:
    bindatcmd "pre", "@pre::OnCall", 99, 99, 1;
}