summaryrefslogblamecommitdiff
path: root/npc/functions/marriage.txt
blob: a8be00493139570c48b2fb9cdb38dc108d4ed11a (plain) (tree)
1
2
3
4
5
               


                  
               
































































































                                                                          
                                                                       
                                                                                      

                     





































                                                                           
                                                                   







                                              

                                                                                                          

























                                                                  
                                                                                            
                        


        
                                     





































                                                                                
                                                                                                                                                          


















                                                         
                                                        
                                        




                                                      

















                                                              
                                                      





























                                                                      
// 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 getmap(), 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?");
    tutmes l("Marriage unlocks %s powers. The ring is sold in Tulimshar. It also lifts some very few item trade restrictions.", getitemlink(WeddingRing));
    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)), "";
    }
}