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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
// TMW2 scripts.
// Authors:
// Jesusalva
// Description:
// Controls world seasons. RESPECT MASK_* VARS ON CONSTANTS DB
// is_night(set=False)
function script is_night {
// If we're not configuring, retrieve the variable (cache)
// It is more efficient this way
.@set=getarg(0, false);
if (!.@set)
return $@WEATHER_NIGHT;
/*
// Night time depends on season.
// Summer: Day > Night
// Winter: Night > Day
// Autumn/Spring: Day = Night
//
// But we have TWO SUNS, meaning night is always smaller.
//
// 2 = GETTIME_MINUTE
// 3 = GETTIME_HOUR
// Summer: 5h day. 1h night. (4 cycles, 8 updates)
// Others: 3h day. 1h night. (6 cycles, 12 updates)
// Winter: 2h day. 1h night. (8 cycles, 16 updates)
*/
// NEW Unified Rule: Day last 3 hours. Night lasts 1 hour. Always.
.@t=(season() == SUMMER ? 6 : (season() == WINTER ? 3 : 4));
return (gettime(3) % .@t == 1);
}
000-0,0,0,0 script #WeatherCore NPC_HIDDEN,{
end;
/*
* removemapflag("<map name>", <flag>)
* setmapflag("<map name>", <flag>{, <val>})
* getmapflag("<map name>", <flag>)
mf_snow: 16
mf_jexp: 39
mf_bexp: 40
*/
OnInit:
// This is weather startup
.@init=true;
$@WEATHER_NIGHT=is_night(true);
.tpc=0;
.tcl=0;
// Bind commands
bindatcmd "wsnow", "#WeatherCore::OnSnow", 80, 80, 1;
bindatcmd "wrain", "#WeatherCore::OnRain", 80, 80, 1;
bindatcmd "wsand", "#WeatherCore::OnSand", 80, 80, 1;
bindatcmd "wevil", "#WeatherCore::OnEvil", 80, 80, 1;
bindatcmd "wnight", "#WeatherCore::OnNight", 80, 80, 1;
bindatcmd "wclear", "#WeatherCore::OnClear", 80, 80, 1;
bindatcmd "wreset", "#WeatherCore::OnReset", 99, 99, 1;
bindatcmd "wset", "#WeatherCore::OnManual", 99, 99, 1;
// Determine which maps are subject to weather, and how weather works:
// eg. it will never snow on a desert, or a sandstorm on icelands.
.wcore = htnew;
// Deserts
htput(.wcore, "003-1", "desert");
htput(.wcore, "004-1", "desert");
htput(.wcore, "004-2", "desert");
htput(.wcore, "009-1", "desert");
htput(.wcore, "010-1", "desert");
htput(.wcore, "010-2", "desert");
// Woodlands
htput(.wcore, "001-4", "woodland");
htput(.wcore, "001-11", "woodland");
htput(.wcore, "001-12", "woodland");
htput(.wcore, "005-1", "woodland");
htput(.wcore, "012-1", "woodland");
htput(.wcore, "014-1", "woodland");
htput(.wcore, "014-2", "woodland");
htput(.wcore, "014-3", "woodland");
htput(.wcore, "014-4", "woodland");
htput(.wcore, "014-5", "woodland");
htput(.wcore, "017-1", "woodland");
htput(.wcore, "018-1", "woodland");
htput(.wcore, "018-2", "woodland");
htput(.wcore, "018-4", "woodland");
htput(.wcore, "018-5", "woodland");
htput(.wcore, "027-1", "woodland");
// Icelands
htput(.wcore, "001-7", "iceland");
htput(.wcore, "019-1", "iceland");
htput(.wcore, "019-2", "iceland");
htput(.wcore, "019-3", "iceland");
htput(.wcore, "019-4", "iceland");
htput(.wcore, "020-1", "iceland");
htput(.wcore, "022-1", "iceland");
htput(.wcore, "024-1", "iceland");
htput(.wcore, "031-1", "iceland");
// Special
htput(.wcore, "011-3", "special");
consoleinfo "[Weather.sys] Total Maps = " + htsize(.wcore);
// No "end" here, so server starts with weather
OnMinute00:
OnMinute15:
OnMinute30:
OnMinute45:
// There is no weather in test servers
if (debug && !$@GM_OVERRIDE)
end;
//debugmes "[Weather.sys] Starting to regen";
.tpc+=getusers(1);
.tcl+=1;
.@hti = htiterator(.wcore);
for(.@key$ = htinextkey(.@hti); hticheck(.@hti); .@key$ = htinextkey(.@hti)) {
// Local variables: .@key$ .@type .@r
.@type$=htget(.wcore, .@key$);
.@r=rand(0,10000);
// Clear weather map masks
.@mk=getmapmask(.@key$);
if (.@mk & MASK_RAIN)
.@mk=.@mk^MASK_RAIN;
if (.@mk & MASK_SANDSTORM)
.@mk=.@mk^MASK_SANDSTORM;
if (.@mk & MASK_SNOW)
.@mk=.@mk^MASK_SNOW;
if (.@mk & MASK_NIGHT)
.@mk=.@mk^MASK_NIGHT;
if (.@mk & MASK_EVILSANCTUM)
.@mk=.@mk^MASK_EVILSANCTUM;
// Monster King Sieges (can be weird, siege last 10mn and mask last 15)
if ($@MK_SCENE)
.@mk=.@mk|MASK_EVILSANCTUM;
if (.@mk & (MASK_MATTACK|MASK_EVILSANCTUM))
.@mk=.@mk^MASK_EVILSANCTUM;
// Remove all current masks, and add rain/snow/sand
if (.@type$ == "desert") {
if (.@r < 10)
.@mk=.@mk|MASK_RAIN;
else if (.@r < 300)
.@mk=.@mk|MASK_SANDSTORM;
} else if (.@type$ == "woodland") {
if (.@r < 300)
.@mk=.@mk|MASK_RAIN;
if ($EVENT$ == "Christmas")
.@mk=.@mk|MASK_SNOW;
else if (season() == WINTER && .@r >= 9250)
.@mk=.@mk|MASK_SNOW;
} else if (.@type$ == "iceland") {
if (.@r < 30)
.@mk=.@mk|MASK_RAIN;
else if (.@r < 300)
.@mk=.@mk|MASK_SNOW;
} else if (.@type$ == "special") {
// This biom is too hot for snow. But it may rain.
if (.@r < 300)
.@mk=.@mk|MASK_RAIN;
// Fog? (Evil Sanctum and Monster Attack) Or Sandstorm?
if (.@r % 4 == 2)
.@mk=.@mk|MASK_EVILSANCTUM;
else if (.@r % 4 == 1)
.@mk=.@mk|MASK_SANDSTORM;
else if (.@r % 4 == 3)
.@mk=.@mk|MASK_MATTACK;
} else {
consolebug "Warning warning, blame Saulc! Weather system error on map "+.@key$;
announce("ERROR BLAME SAULC! WEATHER SYSTEM CORRUPTED.", bc_all);
}
// Bugfix
if (!(.@mk & MASK_NONE))
.@mk=.@mk|MASK_NONE;
setmapmask .@key$, .@mk;
// Is it night time?
if (is_night()) {
setmapflag(.@key$, mf_nightenabled);
addmapmask .@key$, MASK_NIGHT;
} else if (getmapmask(.@key$) & MASK_NIGHT) {
removemapflag(.@key$, mf_nightenabled);
removemapmask .@key$, MASK_NIGHT;
}
}
htidelete(.@hti);
//debugmes "[Weather.sys] Regenerated";
// Hardcore: Skip day/night cycles
if ($HARDCORE || $@GM_OVERRIDE) {
$@WEATHER_NIGHT=is_night(true);
end;
}
// During night, normal monsters respawn 30% faster. (Bifs and Bosses are immune)
//
// Also, announce to players about day/night cycle changes
// The fastest you'll get is 30 minutes for night cycle.
// It's 2 messages every 3 hours. (r7.5)
// Player might be on cave, and this will help them tracking time.
.@current=is_night(true);
.@update = (.@current != $@WEATHER_NIGHT);
if (.@update) {
$@WEATHER_NIGHT=.@current;
if (.tcl > 0) {
.tpc = .tpc / .tcl;
// Monsters spawn faster based on average player count of previous
// cycle, 2% faster per player, capped at 2/3 of the lowest rate
// Default lowest is 70%, so it can go down up to 45% reduction
// For a total of (70-45 = 25%) or monsters spawning 4× faster
// when server is at "full" load (22 players or so)
.@bon = min(.tpc * 2, min($BCONFN_SPAWN, $BCONFD_SPAWN) * 2 / 3);
}
.tpc=0;
.tcl=0;
}
if (is_night() && .@update) {
.@c = getunits(BL_PC, .@players, MAX_CYCLE_PC);
for (.@i = 0; .@i < .@c; .@i++) {
attachrid(.@players[.@i]);
callfunc("SC_Bonus", 180, SC_INCMHPRATE, 10, 10);
percentheal 100, 100;
message(.@players[.@i], "The night falls.");
detachrid();
}
setbattleflag("mob_spawn_delay", $BCONFN_SPAWN - .@bon);
setbattleflag("monster_hp_rate", $BCONFN_MOBHP);
//charcommand("@reloadbattleconf"); // Careful!
donpcevent("@exprate::OnInheirtedReload");
//donpcevent("@droprate::OnReload");
} else if (!is_night() && .@update) {
.@c = getunits(BL_PC, .@players, MAX_CYCLE_PC);
for (.@i = 0; .@i < .@c; .@i++) {
attachrid(.@players[.@i]);
callfunc("SC_Bonus", 180, SC_INCMHPRATE, 10, 10);
percentheal 100, 100;
message(.@players[.@i], "The day rises.");
detachrid();
}
setbattleflag("mob_spawn_delay", $BCONFD_SPAWN - .@bon);
setbattleflag("monster_hp_rate", $BCONFD_MOBHP);
//charcommand("@reloadbattleconf"); // Careful!
donpcevent("@exprate::OnInheirtedReload");
//donpcevent("@droprate::OnReload");
}
debugmes "[Weather.sys] Weather reloaded";
end;
// Function to check stuff
// WeatherSwitch ( MASK, MAP )
function WeatherSwitch {
// Get map
getmapxy(.@key$,.@a,.@b,0);
// Sanitize
.@m$ = htget(.wcore, .@key$, "Not found");
// Change Weather or abort
if (.@m$ == "Not found")
dispbottom l("Command not permitted on this map! Check npc/functions/weather.conf");
else
addmapmask(.@key$, getarg(0));
return;
}
// Some commands, for GMs manually override weather
OnRain:
WeatherSwitch(MASK_RAIN);
end;
OnSand:
WeatherSwitch(MASK_SANDSTORM);
end;
OnSnow:
WeatherSwitch(MASK_SNOW);
end;
OnNight:
WeatherSwitch(MASK_NIGHT);
end;
OnEvil:
WeatherSwitch(MASK_EVILSANCTUM);
end;
OnManual:
if (!.@atcmd_numparameters) {
dispbottom l("Syntax: @wset <map_mask>");
end;
}
// Never allow negative numbers, or to disable map mask 1 (never, EVER, do such insane thing)
.@rq = atoi(.@atcmd_parameters$[0]);
if (.@rq <= 1 || .@rq % 2 == 1) {
dispbottom l("Invalid map mask");
end;
}
// <Insert a helpful comment here>
getmapxy(.@key$,.@a,.@b,0);
.@mk=getmapmask(.@key$);
.@mk=.@mk^.@rq;
setmapmask(.@key$, .@mk);
end;
// Clear works on any map
OnClear:
getmapxy(.@key$,.@a,.@b,0);
.@mk=getmapmask(.@key$);
if (.@mk & MASK_RAIN)
.@mk=.@mk^MASK_RAIN;
if (.@mk & MASK_SANDSTORM)
.@mk=.@mk^MASK_SANDSTORM;
if (.@mk & MASK_SNOW)
.@mk=.@mk^MASK_SNOW;
if (.@mk & MASK_NIGHT)
.@mk=.@mk^MASK_NIGHT;
setmapmask(.@key$, .@mk);
end;
// Reset the whole map, including season, event and weather masks
OnReset:
getmapxy(.@key$,.@a,.@b,0);
setmapmask(.@key$, MASK_NONE);
end;
}
|