summaryrefslogtreecommitdiff
path: root/npc/025-1/ctrl.c
blob: 9817f1077203cfbd344849a9cc81118a4aa5c528 (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
// TMW2 Script
// Notes: The Monster King will retake the town every
// OnTue0000
// (Tuesday, midnight)
// Only the world hero may begin a siege.
// Only one siege per day is allowed
// Writes to MK Temp Var. This variable will unlock the castle gates
// Then the inner gates, and finally, will be a co-requisite to the floors
// Variables:
//      $FORTRESS_STATE = int
//          0 - Locked
//          1 - Unlocked
//      $@FORTRESS_STATUE = bitmask
//          1,2,4,8,16 - broken statues
//          1024 - Fortress Gate
//          2048 - Siege started
//      $@FORT_BLACKLIST = int array
//          Char ID which already raided this week
// TODO: Use bg() - maybe with dummysd? What will increase allies count?
// TODO: Gate control during siege (not $FORTRESS_STATE). Gate monster.
// TODO: Spawn the monster general for each statue. Count their deaths.
// TODO: Spawn Monster Governor (and add it) once statue is broken. ::OnConquest
// TODO: Record nº of victories. Strengthen the governor.
// TODO: Provide a way to resume failed attempts. Move Phoenix inside.
// TODO: Testing.
//       Use setwall() instead of builtin collision? (Deprecates out NPC)
// TODO: NPCs from inside: Bank. Barber. Aeros Shop. Etc.
// TODO: Spawn inside and outside when siege begins.
// TODO: Heartbeat - (Re)Spawn monsters inside every X seconds

// MAPFLAGS
025-1	mapflag	zone	SuperMMO
025-3	mapflag	zone	SuperMMO
026-0	mapflag	zone	SuperMMO
026-1	mapflag	zone	SuperMMO

/////////////////////////////////////////
// FUNCTIONS

// FTCleanup(status)
function	script	FTCleanup	{
    $FORTRESS_STATE=getarg(0);
    // TODO: Magic Statues (FTStatue)
    $@FORTRESS_STATUE=0;
    //enablenpc "Magic Statue#F_1";
    //enablenpc "Magic Statue#F_2";
    //enablenpc "Magic Statue#F_4";
    //enablenpc "Magic Statue#F_8";
    //enablenpc "Magic Statue#F_16";
    // TODO: Gate
    // TODO: ::OnConquest
    // TODO: Kill stray monsters
    //killmonsterall
    // Main gate
    if ($FORTRESS_STATE) {
        disablenpc "Fortress";
        donpcevent "#025-1_99_112::OnDisable";
    } else {
        enablenpc "Fortress";
        donpcevent "#025-1_99_112::OnEnable";
        mapwarp("025-1", "025-2", 100, 27);
    }
    deletearray $@FORT_BLACKLIST;
    enablenpc "#025-1_100_123";
    return;
}

// FTStatue(id)
function	script	FTStatue	{
    .@id=getarg(0);
    mesn l("Magic Statue");
    mes l("There is a reading: The Mana Source. The Moubootaur. The Monster King.");
    mes l("The war. The blood. The inspiration. The mana. The world. The defiance.");
    mes l("The guard. The heir. The originals. The races. The later. The seal.");
    mes l("The fragments. The war. The Terranite. AEGIS MAGNA PROTECTIVE SCUTUM.");
    next;
    mesc l("It seems to be a defensive spell.");
    if ($FORTRESS_STATE)
        return;

    // Break the statues?
    mesc l("Break the Statue?"), 1;
    next;
    if (askyesno() == ASK_YES) {
        if ($@FORTRESS_STATUE & .@id)
            return;
        sc_start SC_STUN, 10000, 1;
        //getmapxy();
        //areamonster();
        //mapannounce();
        //maybe spawn monster governor
        $@FORTRESS_STATUE=$@FORTRESS_STATUE|.@id;
    }

    return;
}










/////////////////////////////////////////
// NPC SCRIPTS

// Main gate - Also where the World Hero can begin the siege
025-1,99,112,0	script	Fortress	NPC_NO_SPRITE,{
    // Main Story block - WHAT
    if ($GAME_STORYLINE < 3)
        die();
    // Still open
    if ($FORTRESS_STATE)
        end;
    // Only World Hero may interact
    if (strcharinfo(0) !=  $MOST_HEROIC$) {
        dispbottom l("I will not assault the Fortress Island. I'll wait for %s.",  $MOST_HEROIC$);
        end;
    }

    // Hey, you can assault the town!
    mesc ".:: "+l("THE FORTRESS ISLAND TOWN") + " ::.", 1;
    mes l("Behind this gate, lies the Fortress Island Town.");
    next;
    mesc ".:: "+l("THE FORTRESS ISLAND TOWN") + " ::.", 1;
    mes l("Assault?");
    mesc l("Lorem ipsum dolor sit amet"), 1;
    next;
    if (askyesno() == ASK_NO)
        close;

    // FIRE THE EVENT
    disablenpc .name$;
    disablenpc "#025-1_100_123";
    initnpctimer;

    // Reset variables
    $@FORTRESS_STATUE=2048;

    // Spawn the gate
    monster("025-1", 99, 113, "Fortress Gate", FortressGate, 1, .name$+"::OnOpenGate");

    // TODO: Initial defending waves
    // TODO: Enable the statues
    // Player blacklist (unable to use 025-2 warp)
    maptimer2("025-1", 10, "Fortress::OnMPBlacklist");
    close;

/////////////////////////////////////////////////////////
OnOpenGate:
    // FIXME Broken
    $@FORTRESS_STATUE = $@FORTRESS_STATUE|1024;
    donpcevent "#025-1_99_112::OnDisable";
    kamibroadcast("The Fortress Town Gate has been breached!");
    close;

OnTimer30000:
    .@breach=($@FORTRESS_STATUE & 1024);
    .@ppl=getmapusers("025-1");

    // Fail condition
    if (.@ppl <= 0) {
        kamibroadcast("Players failed to conquest the Fortress Island!");
        FTCleanup($FORTRESS_STATE);
        end;
    }

    // TODO: Spawn mobs

    // Summon reinforcements
    maptimer2("025-1", 10, "Fortress::OnMPReinforce");

    // Restart timer
    initnpctimer;
    end;
/////////////////////////////////////////////////////////
OnMPBlacklist:
    array_push($@FORT_BLACKLIST, getcharid(0));
    goto OnMPReinforce;

OnMPReinforce:
    // Dispose dead bodies
    if (ispcdead()) {
        warp "025-2", 96, 25;
        end;
    }
    // Summon allies
    // Last a whole minute
    summon("Allied Guard", any(FallenGuard1, FallenGuard2, FallenGuard3));
    end;

/////////////////////////////////////////////////////////
OnInit:
    FTCleanup($FORTRESS_STATE);
    end;

OnTue0000:
    FTCleanup(false);
    end;

OnConquest:
    $MK_TEMPVAR+=1;
    FTCleanup(true);
    end;
}



/////////////////////////////////////////////////////////
// This exit must work even if gate is closed (bugfix)
025-1,99,111,0	script	#FortressTownOut	NPC_HIDDEN,1,0,{
    end;

OnTouch:
    if (!$FORTRESS_STATE)
        slide 100, 114;
    end;
}

// TODO: 100,20 - The Impregnable Fortress Gate
// And don't forget the curse timer



/////////////////////////////////////////////////////////
// Real access to 025-1 map
025-2,96,24,0	script	Fortress Town Access	NPC_HIDDEN,8,0,{
    end;
OnTouch:
    // Disabled
    if ($GAME_STORYLINE < 3 || !is_admin() || $@FORTRESS_STATUE)
        end;
    // Blacklisted
    if (array_find($@FORT_BLACKLIST, getcharid(0)) != -1)
        end;
    // Not blacklisted
    warp "025-1", 99, 122;
    end;
}