summaryrefslogtreecommitdiff
path: root/npc/052-1/channelling.txt
blob: 174cbb405d5ce27957a9c08ac468e89de0f4ad1a (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
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
052-1,25,44,0	script	#EnchantDoorTrigger	NPC32767,3,4,{
    @step = 4;
    if ($@illia_progress < @step) goto L_ShouldNotBeHere;
    if (strcharinfo(0) == $@iLLIA_HERO$ &&
        $@illia_level_4_progress == 0) goto L_EnchantDoor;
    end;

L_EnchantDoor:
    enablenpc "#Enchanted Door";
    end;

L_ShouldNotBeHere:
    die();
    end;

}

052-1,57,29,0	script	#Enchanted Door	NPC369,1,1,{
    if ($@illia_level_4_progress != 2) goto L_PushBack;
    end;

L_PushBack:
    warp "052-1", 57, 34;
    heal ((MaxHp/100) * -20), 0;
    message strcharinfo(0), "You are pushed back violently. There is probably some way to break this barrier.";
    mes "You are pushed back violently.";
    mes "There is probably some way to break this barrier.";
    close;

OnCommandDS:
    areamonster "052-1", 56, 30, 60, 31, "", 1101, 2 + rand(3), "#Enchanted Door::OnSpawn";
    misceffect FX_EVIL_SUMMON;
    end;

OnSpawn:
    end;

}

052-1,57,29,0	script	#Enchanted Door2	NPC400,1,1,{
    if ($@illia_level_4_progress == 2) goto L_Warp;
    end;

L_Warp:
    warp "052-2", 33, 40;
    end;

OnCommandDestroy:
    misceffect FX_ENCHANTED_DOOR_BROKEN;
    end;

}

052-1,51,38,0	script	Engravings	NPC400,{
wind and time:");
    next;
    mes l("\".. can use this .. power..´. . .´. . . amplify a spell ..´.");
    mes l(" . ´´. Don't let .. spell power .´..´ . .. fade away ...");
    mes l("´ .Use lazurite stones ´..´. they will appear. ..´ .. drop them inside .. this circle.");
    mes l(". ´ power.. drains .. life..´. .´  focus . .not move at all´. .\"");
    next;
    mes l("Below this strange writing, you notice a word still deeply engraved in the stone:");
    next;
    mesq b("catalazuli");
    next;
    mes "... that looks like an incantation or something.";
    if ($@illia_level_4_progress == 0)
        goto L_SuggestChannelling;
    close;

L_SuggestChannelling:
    next;
    mes "I think this blue circle right here can be helpful to break the enchantment that blocks the door of the Inn.";
    next;
    mes "Let's see how I can activate it...";
    mes "But I should probably get inside it, first.";
    close;
}

function	script	StartChannelling	{
    if (isat("052-1", 53, 38) == 0)
        goto L_Return;
    if ($@illia_level_4_progress > 0)
        goto L_Return;
    $@illia_level_4_progress = 1;
    $@illia_char_channelling$ = strcharinfo(0);

    @bonus = (Int+1) / 25;
    // Lazurite Stones power, will also depend on the Int of the channelling character
    setarray $@illia_lazurites_power,
        12 + @bonus, // small
        32 + @bonus, // regular
        65 + @bonus; // large

    // coordinates where stones will appear
    setarray $@illia_small_lazurites, 50,41, 44,33, 61,42;
    setarray $@illia_regular_lazurites, 68,29, 47,25, 38,45, 70,40;
    setarray $@illia_large_lazurites, 21,40, 34,25;

    // amount of initial magic power
    $@illia_magic_power = 1811 + Int*2;
    // Channelling required power depends on the base Int of the character
    $@illia_magic_power_required = 5707 - 2*Int;
    // magic power loss depends also on Int
    $@illia_magic_power_loss = 53 - ((Int+1)*2)/10;

    // register the power status to display hints to the players
    // Statuses: 0=critical(below 300), 1=neutral, 2=almost there (max-300)
    $@illia_magic_power_status = 1;

    message strcharinfo(0), "Ok, let's stay focused now!";
    donpcevent "#Power Circle::OnCommandSt";
    goto L_Return;

L_Return:
    return;
}

052-1,53,38,0	script	#Power Circle	NPC368,{
    @step = 4;
    if ($@illia_progress < @step)
        goto L_ShouldNotBeHere;
    if (isat("052-1",53,38) == 0)
        goto L_Hint;
    end;

OnCommandSt:
    initnpctimer;
    end;

L_Hint:
    mes "Magic seems to be flowing from this place. I should find out what it is.";
    close;

OnTimer2000:
    callsub S_CheckChannelling;
    end;

OnTimer4000:
    callsub S_CheckChannelling;
    end;

OnTimer6000:
    // Spawn items at specific place
    callsub S_ItemSpawn;
    callsub S_CheckChannelling;
    end;

OnTimer8000:
    callsub S_CheckChannelling;
    end;

OnTimer10000:
    // Spawn items at specific place
    callsub S_ItemSpawn;
    callsub S_CheckChannelling;
    end;

OnTimer11000:
    setnpctimer 0;
    // Spawn monsters (demonic spirits) near the enchanted door
    donpcevent "#Enchanted Door::OnCommandDS";
    end;

S_ItemSpawn:
    if (!(attachrid(getcharid(3, $@illia_char_channelling$))))
        goto L_Return;
    // spawn items at random
    $@illia_item_spawn_i = rand(getarraysize($@illia_small_lazurites)/2);
    $@illia_item_spawn_x = $@illia_small_lazurites[$@illia_item_spawn_i*2];
    $@illia_item_spawn_y = $@illia_small_lazurites[($@illia_item_spawn_i*2)+1];
    if (rand(10) > 0)
        makeitem 873, rand(4,7), "052-1", $@illia_item_spawn_x, $@illia_item_spawn_y;

    $@illia_item_spawn_i = rand(getarraysize($@illia_regular_lazurites)/2);
    $@illia_item_spawn_x = $@illia_regular_lazurites[$@illia_item_spawn_i*2];
    $@illia_item_spawn_y = $@illia_regular_lazurites[($@illia_item_spawn_i*2)+1];
    if (rand(8) > 0)
        makeitem 874, rand(3,4), "052-1", $@illia_item_spawn_x, $@illia_item_spawn_y;

    $@illia_item_spawn_i = rand(getarraysize($@illia_large_lazurites)/2);
    $@illia_item_spawn_x = $@illia_large_lazurites[$@illia_item_spawn_i*2];
    $@illia_item_spawn_y = $@illia_large_lazurites[($@illia_item_spawn_i*2)+1];
    if (rand(4) > 0)
        makeitem 875, rand(1,2), "052-1", $@illia_item_spawn_x, $@illia_item_spawn_y;

    $@illia_item_spawn_i = 0;
    $@illia_item_spawn_x = 0;
    $@illia_item_spawn_y = 0;

    detachrid;
    goto L_Return;

L_Return:
    return;

S_CheckChannelling:
    // Remove stones inside the circle
    set $@illia_magic_power, $@illia_magic_power +
        getareadropitem("052-1", 52, 37, 54, 39, 873, 1)*$@illia_lazurites_power[0] +
        getareadropitem("052-1", 52, 37, 54, 39, 874, 1)*$@illia_lazurites_power[1] +
        getareadropitem("052-1", 52, 37, 54, 39, 875, 1)*$@illia_lazurites_power[2];

    // magic power fades over time
    $@illia_magic_power = $@illia_magic_power - $@illia_magic_power_loss;

    $@illia_magic_power_last_status = $@illia_magic_power_status;
    $@illia_magic_power_status = 1;
    if ($@illia_magic_power < 300)
        $@illia_magic_power_status = 0;
    if ($@illia_magic_power > $@illia_magic_power_required - 300)
        $@illia_magic_power_status = 2;

    // Player loses a part of his health while channelling
    if (!(attachrid(getcharid(3, $@illia_char_channelling$))))
        goto L_ChannellingFail;
    // Display an effect showing the drain
    misceffect FX_CHANNELLING_RAISE;
    heal ((MaxHp/100) * -4), 0;

    if (ispcdead())
        goto L_ChannellingDead;
    if (isat("052-1",53,38) == 0)
        goto L_ChannellingMoved;
    // check the magic power
    if ($@illia_magic_power <= 0)
        goto L_ChPwrVanish;
    if ($@illia_magic_power >= $@illia_magic_power_required)
        goto L_ChannellingComplete;

    detachrid;

    $@illia_channelling_status_msg$ = "";

    if ($@illia_magic_power_last_status == 0 && $@illia_magic_power_status == 1)
        $@illia_channelling_status_msg$ = $@illia_char_channelling$ + ": I think I'm controlling the spell again now. Keep up!";
    if ($@illia_magic_power_last_status == 1 && $@illia_magic_power_status == 0)
        $@illia_channelling_status_msg$ = $@illia_char_channelling$ + ": Guys I'm loosing it! Hurry up!";
    if ($@illia_magic_power_last_status == 1 && $@illia_magic_power_status == 2)
        $@illia_channelling_status_msg$ = $@illia_char_channelling$ + ": I almost have the power to cast it! One last effort!";
    if ($@illia_magic_power_last_status == 2 && $@illia_magic_power_status == 1)
        $@illia_channelling_status_msg$ = $@illia_char_channelling$ + ": Damn! It faded a little.";

    if ($@illia_channelling_status_msg$ != "")
        areatimer 0, "052-1", 1, 1, 100, 80, 0, "#Power Circle::OnMPSC";

    return;

OnMPSC:
    message strcharinfo(0), $@illia_channelling_status_msg$;
    $@illia_channelling_status_msg$ = "";
    end;

L_ChannellingComplete:
    message strcharinfo(0), "You successfully cast the spell and broke the door's enchantment!";
    detachrid;
    stopnpctimer;
    setnpctimer 0;
    $@illia_magic_power = 0;
    $@illia_magic_power_required = 0;
    $@illia_magic_power_last_status = 0;
    $@illia_magic_power_status = 0;
    $@illia_magic_power_loss = 0;
    $@illia_char_channelling$ = "";
    $@illia_level_4_progress = 2;
    $@illia_progress = 5;
    callfunc "UpdateIlliaProgress";
    $@illia_max_time = $@illia_max_time + 600;
    // Effect to display the disenchant is cast
    misceffect FX_CHANNELLING_CAST;
    // move away the enchanted door
    donpcevent "#Enchanted Door2::OnCommandDestroy";
    disablenpc "#Enchanted Door";
    end;

L_ChannellingDead:
    misceffect FX_MAGIC_DARK_EXPLOSION, strcharinfo(0);
    goto L_ChannellingFail;

L_ChannellingMoved:
    // kill the player as part of the process: the magic process drained his life.
    // But only if he is still in the island (otherwise, he probably got warped
    // and does not need being killed)
    if (isin("052-1",1,1,100,80) == 0)
        goto L_ChannellingFail;
    die();
    misceffect FX_MAGIC_DARK_EXPLOSION, strcharinfo(0);
    message strcharinfo(0), "You moved out of the power circle. The magic power you accumulated backfires at you!";
    goto L_ChannellingFail;

L_ChPwrVanish:
    // kill the player as part of the process: the magic process drained his life.
    die();
    misceffect FX_MAGIC_DARK_EXPLOSION, strcharinfo(0);
    message strcharinfo(0), "The magic power vanished, and your spell backfires at you!";
    goto L_ChannellingFail;

L_ChannellingFail:
    detachrid;
    stopnpctimer;
    setnpctimer 0;
    $@illia_magic_power = 0;
    $@illia_magic_power_required = 0;
    $@illia_magic_power_last_status = 0;
    $@illia_magic_power_status = 0;
    $@illia_magic_power_loss = 0;
    $@illia_char_channelling$ = "";
    $@illia_level_4_progress = 0;
    end;

L_ShouldNotBeHere:
    die();
    end;

OnInit:
    // In theory, pattern ID must be between 1~9
    // To set $@p1$~$@p9$ with the PERL expression
    // But as we're only using $@p0$ (full string)
    // the value itself is meaningless
    .pid=getnpcid();
    debugmes "Catalazuli: Pattern %d", .pid;
    //I'm not going to learn PERL just for that
    defpattern(.pid, "^(.*)$", "OnTalkNearby");
    activatepset(.pid);
    end;

OnTalkNearby:
    // not very obvious stuff by gumi, $@p0$ contains the whole string
    // so we must cut it. Could use $@p1$ if perl was proper but... meh.
    .@no_nick$ = strip(substr($@p0$, getstrlen(strcharinfo(PC_NAME)) + 3, getstrlen($@p0$) - 1));
    .@message$ = strtoupper(.@no_nick$);

    // Only react if the message is what we want to hear
    if (.@message$ == "CATALAZULI") {
        StartChannelling();
    }
    end;
}