summaryrefslogtreecommitdiff
path: root/npc/commands/rate-management.txt
blob: 8a95bfdeff1df3fabde997397887e8e61095cab8 (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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// Authors: Gumi, Jesusalva
-	script	@exprate	32767,{
    end;

    function rateCleanUp {
        stopnpctimer;
        .hours = 0;
        .max_hours = 0;
        .current_rate = .original_exp_rate;
        setbattleflag("base_exp_rate", .original_exp_rate);
        charcommand("@reloadmobdb"); // this is on purpose (callable without RID)
        SeasonReload(1);
        channelmes("#world", "The EXP Rate Bonus is now over.");
    }

    function remainingTime {
        .@total_seconds = (3600 * .max_hours);
        .@seconds_elapsed = (3600 * .hours) + (getnpctimer(0) / 1000);
        .@seconds_remaining = max(1, .@total_seconds - .@seconds_elapsed);
        return FuzzyTime(time_from_seconds(.@seconds_remaining), 2, 2);
    }

OnCall:
   if (!is_gm())
        end;

    .@special$ = strip(.@atcmd_parameters$[0]); // special value
    .@new_rate = min(atoi(.@special$), 1000); // or just a regular integer
    .@hours = min(0x7FFFFFFE, max(1, atoi(strip(.@atcmd_parameters$[1])))); // number of hours

    if (.@new_rate > 0) {

        // set new exp rate
        .hours = 0;
        .max_hours = .@hours;
        .current_rate = .@new_rate;
        setbattleflag("base_exp_rate", .@new_rate);
        //setbattleflag("quest_exp_rate", .@new_rate);
        charcommand("@reloadmobdb");
        //charcommand("@reloadquestdb");
        SeasonReload(1);
        initnpctimer; // start counting

        .@msg$=strcharinfo(0)+" increased experience rate to "+str(.@new_rate)+"%. It will only last "+str(FuzzyTime(time_from_hours(.max_hours), 2, 2))+"!";

        announce .@msg$, bc_all;
        channelmes("#world", .@msg$);

        //dispbottom l("You successfully set the exp rate to @@%. It will reset to @@% (default value) in @@.",
        //            .@new_rate, .original_exp_rate, FuzzyTime(time_from_hours(.max_hours), 2, 2));
        dispbottom l("You can also manually stop it at any time with: @exprate default");

    } else if (.@new_rate == 0 && .@special$ == "") {

        // get current exp rate
        if (.current_rate == .original_exp_rate) {
            dispbottom l("Current exp rate is set to @@% (default value).", .current_rate);
        } else {
            dispbottom l("Current exp rate is set to @@%, and will reset to @@% (default value) in @@.",
                        .current_rate, .original_exp_rate, remainingTime());

            dispbottom l("If you meant to reset the exp rate to its default value: @exprate default");
        }

    } else {

        // reset
        rateCleanUp;
        dispbottom l("Exp rate has been reset to @@% (default value).",
                    .original_exp_rate);
    }

    end;

OnPlayerCall:
    // GM calls take precedence at any time!
    if (.max_hours > 0 || .hours > 0)
        end;
    // $@EXP_EVENT will determine the boost and should not be above 25%
    // Default duration is one hour, or whatever $@EXP_EVENT_TIME is
    $@EXP_EVENT=max(0, min(150, $@EXP_EVENT));
    $@EXP_EVENT_TIME=max(1, min(6, $@EXP_EVENT_TIME));

    // Default duration is one hour, or whatever $@EXP_EVENT_TIME is
    .hours = 0;
    .max_hours = $@EXP_EVENT_TIME;
    .current_rate = $@EXP_EVENT;
    setbattleflag("base_exp_rate", $@EXP_EVENT);
    charcommand("@reloadmobdb");
    SeasonReload(1);
    initnpctimer; // start counting

    .@msg$="Experience Rate was modified to "+$@EXP_EVENT+"% for "+$@EXP_EVENT_TIME+" hour(s)!";

    announce .@msg$, bc_all;
    channelmes("#world", .@msg$);

    $@EXP_EVENT=0;
    $@EXP_EVENT_TIME=0;
    end;

OnTimer3600000:
    // runs every hour
    if (++.hours == .max_hours) {
        rateCleanUp;
        end;
    }
    initnpctimer;
    end;

OnPCLoginEvent:
    if (.max_hours > 0) {
        dispbottom col(l("Exp rate is set to @@% for the next @@.",
                        .current_rate, remainingTime()), 6);
    }
    end;

OnInit:
    bindatcmd "exprate", "@exprate::OnCall", 80, 80, 1; // change exp rate

    // WARNING: using @reloadscript will change the "original" value
    .original_exp_rate = 100;//getbattleflag("base_exp_rate");
    .current_rate = .original_exp_rate;

    // XXX: maybe in the future:
    //.original_job_rate = getbattleflag("base_job_rate");
    //.original_pk_mode = getbattleflag("pk_mode");
    //.original_death_penalty = getbattleflag("death_penalty_type");
    end;

OnReload:
    .@new_rate = .current_rate;
    setbattleflag("base_exp_rate", .@new_rate);
    //charcommand("@reloadmobdb");
    //SeasonReload(1); // TODO FIXME: We are casting this twice.
    end;
}


/////////////////////////////////////////////////////////////////////////////////
-	script	@droprate	32767,{
    end;

    function rateCleanUp {
        stopnpctimer;
        .hours = 0;
        .max_hours = 0;
        .current_rate = 100;
        setbattleflag("item_rate_common", 100);
        setbattleflag("item_rate_common_boss", 100);
        setbattleflag("item_rate_heal", 100);
        setbattleflag("item_rate_heal_boss", 100);
        setbattleflag("item_rate_use", 100);
        setbattleflag("item_rate_use_boss", 100);
        setbattleflag("item_rate_equip", 100);
        setbattleflag("item_rate_equip_boss", 100);
        setbattleflag("item_rate_card", 100);
        setbattleflag("item_rate_card_boss", 100);
        charcommand("@reloadmobdb"); // this is on purpose (callable without RID) - no idea what is the purpose
        SeasonReload(1);
        channelmes("#world", "The Drop Rate Bonus is now over.");
    }

    function remainingTime {
        .@total_seconds = (3600 * .max_hours);
        .@seconds_elapsed = (3600 * .hours) + (getnpctimer(0) / 1000);
        .@seconds_remaining = max(1, .@total_seconds - .@seconds_elapsed);
        return FuzzyTime(time_from_seconds(.@seconds_remaining), 2, 2);
    }

OnCall:
   if (!is_gm()) {
        end;
    }

    .@special$ = strip(.@atcmd_parameters$[0]); // special value
    .@new_rate = min(atoi(.@special$), 1000); // or just a regular integer
    .@hours = min(0x7FFFFFFE, max(1, atoi(strip(.@atcmd_parameters$[1])))); // number of hours

    if (.@new_rate > 0)
    {
        // set new exp rate
        .hours = 0;
        .max_hours = .@hours;
        .current_rate = .@new_rate;
        setbattleflag("item_rate_common", .@new_rate);
        setbattleflag("item_rate_common_boss", .@new_rate);
        setbattleflag("item_rate_heal", .@new_rate);
        setbattleflag("item_rate_heal_boss", .@new_rate);
        setbattleflag("item_rate_use", .@new_rate);
        setbattleflag("item_rate_use_boss", .@new_rate);
        setbattleflag("item_rate_equip", .@new_rate);
        setbattleflag("item_rate_equip_boss", .@new_rate);
        setbattleflag("item_rate_card", .@new_rate);
        setbattleflag("item_rate_card_boss", .@new_rate);
        charcommand("@reloadmobdb");
        SeasonReload(1);
        initnpctimer; // start counting

        .@msg$=strcharinfo(0)+" increased drop rates to "+str(.@new_rate)+"%. It will only last "+str(FuzzyTime(time_from_hours(.max_hours), 2, 2))+"!";

        announce .@msg$, bc_all;
        channelmes("#world", .@msg$);

        //dispbottom l("You successfully set the drop rate to @@%. It will reset to @@% (default value) in @@.",
        //            .@new_rate, .org_dcn, FuzzyTime(time_from_hours(.max_hours), 2, 2));
        dispbottom l("You can also manually stop it at any time with: @droprate default");
    } else if (.@new_rate == 0 && .@special$ == "") {
        // get current exp rate
        if (.current_rate == .org_dcn) {
            dispbottom l("Current drop rate is set to @@% (default value).", .current_rate);
        } else {
            dispbottom l("Current drop rate is set to @@%, and will reset to @@% (default value) in @@.",
                        .current_rate, .org_dcn, remainingTime());
            dispbottom l("If you meant to reset the drop rate to its default value: @droprate default");
        }
    }

    else
    {
        // reset
        rateCleanUp;
        dispbottom l("Drop rate has been reset to @@% (default value).",
                    .org_dcn);
    }

    end;

OnTimer3600000:
    // runs every hour
    if (++.hours == .max_hours) {
        rateCleanUp;
        end;
    }
    initnpctimer;
    end;

OnPCLoginEvent:
    if (.max_hours > 0) {
        dispbottom col(l("Drop rate is set to @@% for the next @@.",
                        .current_rate, remainingTime()), 6);
    }
    end;

OnInit:
    bindatcmd "droprate", "@droprate::OnCall", 80, 80, 1; // change drop rate

    // WARNING: using @reloadscript will change the "original" value, use @reloadbattleconf before!
    .org_dcn = 100;//getbattleflag("item_rate_common");
    .org_dcb = 100;//getbattleflag("item_rate_common_boss");
    .org_dhn = 100;//getbattleflag("item_rate_heal");
    .org_dhb = 100;//getbattleflag("item_rate_heal_boss");
    .org_dun = 100;//getbattleflag("item_rate_use");
    .org_dub = 100;//getbattleflag("item_rate_use_boss");
    .org_den = 100;//getbattleflag("item_rate_equip");
    .org_deb = 100;//getbattleflag("item_rate_equip_boss");
    .org_dxn = 100;//getbattleflag("item_rate_card");
    .org_dxb = 100;//getbattleflag("item_rate_card_boss");
    .current_rate = 100;

    // XXX: maybe in the future:
    //.original_job_rate = getbattleflag("base_job_rate");
    //.original_pk_mode = getbattleflag("pk_mode");
    //.original_death_penalty = getbattleflag("death_penalty_type");
    end;

OnReload:
    .@new_rate = .current_rate;
    setbattleflag("item_rate_common", .@new_rate);
    setbattleflag("item_rate_common_boss", .@new_rate);
    setbattleflag("item_rate_heal", .@new_rate);
    setbattleflag("item_rate_heal_boss", .@new_rate);
    setbattleflag("item_rate_use", .@new_rate);
    setbattleflag("item_rate_use_boss", .@new_rate);
    setbattleflag("item_rate_equip", .@new_rate);
    setbattleflag("item_rate_equip_boss", .@new_rate);
    setbattleflag("item_rate_card", .@new_rate);
    setbattleflag("item_rate_card_boss", .@new_rate);
    charcommand("@reloadmobdb");
    SeasonReload(1);
    debugmes("Drop rates were reloaded with success.");
    end;

}