summaryrefslogtreecommitdiff
path: root/npc/functions/marriage.txt
blob: 7bcd69cc36dae223cd08fce0a0c2c111fcc947d1 (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
// TMW-2 Script
// Evol functions.
// Author:
//    4144
//    Jesusalva
// Description:
//    Functions for marriage

// check is player is near marriage npc
// args:
//   0 - player name
// returns:
//   true if player located near npc.
function	script	marriagecheckname	{
    .@name$ = getarg(0);
    if (.@name$ == "")
    {
        // no other registrand
        return false;
    }
    .@id = getcharid(0, .@name$);
    .@accoundId = getcharid(3, .@name$);
    if (isloggedin(.@accoundId, .@id) == false)
    {
        // registrant not logged in
        return false;
    }
    getmapxy(.@mapname$, .@x, .@y, 0, .@name$);
    if (.@mapname$ != strnpcinfo(4))
    {
        // registrant on other map
        return false;
    }
    if (distance(.@x, .@y, .x, .y) > .distance)
    {
        // registrant too far
        return false;
    }
    return true;
}

// return player name registered with same gender like attached player
function	script	getmarriageregistrant	{
    if (Sex)
    {
        .@name$ = getvariableofnpc(.maleName$, strnpcinfo(3));
    }
    else
    {
        .@name$ = getvariableofnpc(.femaleName$, strnpcinfo(3));
    }
    return .@name$;
}

// return registered marriage partner name
function	script	getmarriagepartner	{
    if (Sex)
    {
        .@name$ = getvariableofnpc(.femaleName$, strnpcinfo(3));
    }
    else
    {
        .@name$ = getvariableofnpc(.maleName$, strnpcinfo(3));
    }
    if (marriagecheckname(.@name$))
        return .@name$;
    return "";
}

// register attached player as partner for marriage
function	script	marriageregisterself	{
    if (Sex)
    {
        set getvariableofnpc(.maleName$, strnpcinfo(3)), strcharinfo(0);
        set getvariableofnpc(.maleName_partner$, strnpcinfo(3)), "";
    }
    else
    {
        set getvariableofnpc(.femaleName$, strnpcinfo(3)), strcharinfo(0);
        set getvariableofnpc(.femaleName_partner$, strnpcinfo(3)), "";
    }
    return;
}

// return player name what was accepted by partner
function	script	getmarriagepartneraccepted	{
    if (Sex)
    {
        .@name$ = getvariableofnpc(.femaleName_partner$, strnpcinfo(3));
    }
    else
    {
        .@name$ = getvariableofnpc(.maleName_partner$, strnpcinfo(3));
    }
    return .@name$;
}

// return true if partner present near and partner accepted you
function	script	ismarriagepartneraccepted	{
    .@partner$ = getmarriagepartner();
    if (.@partner$ == "")
        return false;
    if (readparam(Sex, strcharinfo(0)) == readparam(Sex, .@partner$)) {
        // Blame Jesusalva. I am sensing various other possible bugs. Let's play safe.
        return false;
    }
    .@name$ = getmarriagepartneraccepted();
    if (.@name$ == strcharinfo(0))
        return true;
    return false;
}

// accept for attached player his/her partner
// args:
//   0 - partner name
function	script	marriageacceptpartner	{
    .@name$ = getarg(0);
    if (Sex)
    {
        set getvariableofnpc(.maleName_partner$, strnpcinfo(3)), .@name$;
    }
    else
    {
        set getvariableofnpc(.femaleName_partner$, strnpcinfo(3)), .@name$;
    }
    return;
}

function	script	askmarry	{
    speech l("Do you want to marry @@?", getarg(0));
    if (askyesno() == ASK_YES)
        return true;
    return false;
}

// start marriage registration process
function	script	marriageregister	{
    .@partner$ = getmarriagepartner();
    if (.@partner$ == "")
    {   // no partner registered
        speech l("Ok I add your name... @@...", strcharinfo(0));
        marriageregisterself();
        next;
        speech lg("Now wait for your partner, then talk to me again.");
        npctalk l("@@ waits for their loved one.", strcharinfo(0));
        close;
    }
    else
    {   // partner already registered
        if (askmarry(.@partner$) == true)
        {
            marriageregisterself();
            marriageacceptpartner(.@partner$);
            npctalk3 l("@@ registered for marriage and accepted partner @@!", strcharinfo(0), .@partner$);
            npctalk3 l("Waiting for @@...", .@partner$);
            close;
        }
        else
        {
            close;
        }
    }
    return;
}

// remove all marriage registations
function	script	marriageclear	{
    set getvariableofnpc(.maleName$, strnpcinfo(3)), "";
    set getvariableofnpc(.femaleName$, strnpcinfo(3)), "";
    set getvariableofnpc(.maleName_partner$, strnpcinfo(3)), "";
    set getvariableofnpc(.femaleName_partner$, strnpcinfo(3)), "";
    return;
}

// do actual marriage
function	script	domarriage	{
    .@name$ = strcharinfo(0);
    .@partner$ = getarg(0);
    if (marriage(.@partner$))
    {
        speech l("You got married to @@!", .@partner$);
        mapannounce "009-1", l("@@ and @@ just got married!", .@name$, .@partner$), bc_map;
        specialeffect 6;
    }
    else
    {
        speech l("Marriage failed.");
    }
    marriageclear();
    return;
}

// marry main code
function	script	marriagemarry	{
    .@registrant$ = getmarriageregistrant();
    if (marriagecheckname(.@registrant$) == true)
    {
        if (.@registrant$ == strcharinfo(0))
        {
            if (ismarriagepartneraccepted())
            {
                .@partner$ = getmarriagepartner();
                if (marriagecheckname(.@partner$) == false)
                {
                    speech l("Partner not ready.");
                }
                else if (askmarry(.@partner$) == true)
                {
                    domarriage(.@partner$);
                }
            }
            else
            {
                speech l("You already registered. Waiting for your partner...");
            }
        }
        else
        {
            speech l("Sorry, I'm busy with other registrations."),
                l("Come after a little while.");
        }
        close;
    }

    speech l("What can I do for you?");
    switch (select(l("I want to register for marriage."),
            l("Nothing")))
    {
        case 1:
            marriageregister;
            break;
        case 2:
            break;
    }
    return;
}

// divorce main code
function	script	marriagedivorce	{
    speech l("What can I do for you?");
    switch (select(l("I want to divorce."),
            l("Nothing")))
    {
        case 1:
            speech lg("Are you sure? It costs 800 GP.");
            if (askyesno() == ASK_YES)
            {
                if (Zeny < 800)
                    return;
                if (divorce()) {
                    Zeny=Zeny-800;
                    speech l("You are now divorced!");
                    npctalk l("@@ divorced!", strcharinfo(0));
                }
                else
                {
                    speech l("Divorce error!");
                }
            }
            break;
        case 2:
            break;
    }
    return;
}

// main function for marriage
function	script	marriagemain	{
    if (Sex > 1)
    {
        speech l("Sorry, I can't help you. Go away!");
        close;
    }

    if (getpartnerid() != 0)
    {   // have partner
        marriagedivorce();
    }
    else
    {   // no partner
        marriagemarry();
    }

    return;
}

// check registration list by timer
function	script	marriagecheck	{
    .@name$ = getvariableofnpc(.maleName$, strnpcinfo(3));
    if (.@name$ != "" && marriagecheckname(.@name) == false)
    {
        set getvariableofnpc(.maleName$, strnpcinfo(3)), "";
        set getvariableofnpc(.maleName_partner$, strnpcinfo(3)), "";
    }
    .@name$ = getvariableofnpc(.femaleName$, strnpcinfo(3));
    if (.@name$ != "" && marriagecheckname(.@name) == false)
    {
        set getvariableofnpc(.femaleName$, strnpcinfo(3)), "";
        set getvariableofnpc(.femaleName_partner$, strnpcinfo(3)), "";
    }
}