summaryrefslogblamecommitdiff
path: root/world/map/npc/functions/vault.txt
blob: ee30863c8693bc49d7c14af7ba376f22a5ab146b (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                
                                                 


                   
                     
 

                        


















                                              






                                                                                                      

                                                                                



































































                                              

 


























































                                                                              













                                                                
// Mirror Lake Protocol and The Mana World Vault utilities
// TMWA is hopelessy broken, so most helpers simply don't exist.
//
// Author: jesusalva

function|script|VaultLogin
{
    if (##VAULT < 1) goto L_Return;
    // TODO: Or #VAULT ? Which of the two is set?

    callsub S_Exp;
    callsub S_Gold;
    callsub S_Preset;

    // Clean up
    set @last_preset, 0;
    return; // go back to global handler

S_Return: // this is to end execution of a sub
    return;

L_Return:
    return;

S_Exp:
    if (##ADD_LVL < 1) goto S_Return;
    getexp ##ADD_LVL, 0;
    set ##ADD_LVL, 0;
    return;

S_Gold:
    if (##ADD_GP < 1) goto S_Return;
    set Zeny, Zeny + ##ADD_GP;
    set ##ADD_GP, 0;
    return;

S_Preset:
    if (##PRESET < 1) goto S_Return;
    set @last_preset, (#X21 & BYTE_3_MASK) >> BYTE_3_SHIFT;
    set #X21, (#X21 & ~(BYTE_3_MASK)) | (##PRESET << BYTE_3_SHIFT);

    // Each preset is 5 levels (Preset 1 = Lv 5, Preset 10 = Lv 50, Max Preset 20 - hard limit is 127)
    // TODO: Give more ammo, iron powder, sulphur powder, etc. instead of equips
    // Give also some bug legs and maggot slime if applicable?
    /* Handle weapons */
    if (##PRESET >= 1 && @last_preset < 1)
        getitem "SharpKnife",1;
    if (##PRESET >= 2 && @last_preset < 2)
        getitem "Dagger",1;
    if (##PRESET >= 3 && @last_preset < 3)
        getitem "Bow",1;
    if (##PRESET >= 3 && @last_preset < 3)
        getitem "Arrow",500;
    if (##PRESET >= 4 && @last_preset < 4)
        getitem "Arrow",500;
    if (##PRESET >= 5 && @last_preset < 5)
        getitem "Scythe",1;
    if (##PRESET >= 6 && @last_preset < 6)
        getitem "ShortBow",1;
    if (##PRESET >= 7 && @last_preset < 7)
        getitem "IronArrow",500;
    if (##PRESET >= 8 && @last_preset < 8)
        getitem "ShortSword",1;
    if (##PRESET >= 9 && @last_preset < 9)
        getitem "BoneArrows",100;
    if (##PRESET >= 10 && @last_preset < 10)
        getitem "ForestBow",1;
    if (##PRESET >= 11 && @last_preset < 11)
        getitem "IronArrow",500;
    if (##PRESET >= 12 && @last_preset < 12)
        getitem "IceGladius",1;
    if (##PRESET >= 13 && @last_preset < 13)
        getitem "Arrow",500;
    if (##PRESET >= 14 && @last_preset < 14)
        getitem "TerraniteArrow",100;
    if (##PRESET >= 15 && @last_preset < 15)
        getitem "BoneArrows",100;
    if (##PRESET >= 16 && @last_preset < 16)
        getitem "BoneKnife",1;
    if (##PRESET >= 17 && @last_preset < 17)
        getitem "TerraniteArrow",100;
    if (##PRESET >= 18 && @last_preset < 18)
        getitem "Setzer",1;
    if (##PRESET >= 19 && @last_preset < 19)
        getitem "TerraniteArrow",250;
    //if (##PRESET >= 20 && @last_preset < 20)
    //    getitem "BansheeBow",1;

    /* Handle equipment */
    if (##PRESET >= 2 && @last_preset < 2)
        getitem "SilkHeadband",1;
    if (##PRESET >= 4 && @last_preset < 4)
        getitem "LeatherShirt",1;
    if (##PRESET >= 6 && @last_preset < 6)
        getitem "JeansShorts",1;
    if (##PRESET >= 8 && @last_preset < 8)
        getitem "SilkRobe",1;
    if (##PRESET >= 10 && @last_preset < 10)
        getitem "InfantryHelmet",1;
    if (##PRESET >= 12 && @last_preset < 12)
        getitem "ChainmailShirt",1;
    if (##PRESET >= 14 && @last_preset < 14)
        getitem "CottonBoots",1;
    if (##PRESET >= 16 && @last_preset < 16)
        getitem "JeansChaps",1;
    if (##PRESET >= 18 && @last_preset < 18)
        getitem "CottonGloves",1;
    if (##PRESET >= 20 && @last_preset < 20)
        getitem "LightPlatemail",1;

    set ##PRESET, 0;
    return;
}


// Remember: ##VAULT_EXP, ##VAULT_GOTO, ##VAULT_MLTO for Mirror Lake Protocol
// However, without kick(7), it is not really worth anything
// Remember: Quote symbols are illegal, simple or double, except for parameter
// To reset the database:
//    cleararray $EXPORT_DATA$[0], "", 254;
//    set $EXPORT_MAX_ID, 0;

// Schemas:
//API_VAULT: "UID", ##VAULT, "GID", getcharid(3)
//API_SENDMAIL: "UID": ##VAULT, "MSG": "message", "TITLE": "subject line"
//
// Using the API_EXPORT hack for TMWA:
//
// set $@API_PROTOCOL, API_SENDMAIL;
// set $@API_DATA$, "'UID': 0, 'TITLE': 'About TMWA', 'MSG': 'I hate it!'";
// callfunc "FlushAPI";
//
// (The curly brace is added to DATA on its own)
function|script|FlushAPI
{
    // Function called improperly
    // DATA cannot be null or the array order will crash
    if ($@API_PROTO <= 0) goto L_Dumb;
    if ($@API_DATA$ == "") goto L_Dumb;

    // Save it to mapreg
    // The script will strip "##"
    // and convert the part after to a JSON dict
    set $EXPORT_DATA$[$EXPORT_MAX_ID], $@API_PROTO + "##" + $@API_DATA$;
    set $@API_PROTO, "";
    set $@API_DATA$, "";

    // Update TMWA tracker
    set $EXPORT_MAX_ID, $EXPORT_MAX_ID + 1;

    // Keep in mind an array can only go up to 255
    // Trying to go past that, causes a SIGSEGV and map server dies
    // So we periodically truncate the table when it's full
    if ($EXPORT_MAX_ID > 240) goto L_Flush;
    if ($EXPORT_MAX_ID == 120) goto L_Flush2;
    return;

L_Dumb:
    debugmes "FlushAPI called without enough arguments";
    debugmes " - $@API_PROTO, API_* constant";
    debugmes " - $@API_DATA$, json dict without curly braces";
    return;

L_Flush:
    cleararray $EXPORT_DATA$[0], "", 220;
    set $EXPORT_MAX_ID, 0;
    return;

L_Flush2:
    cleararray $EXPORT_DATA$[220], "", 25;
    return;
}

function|script|VaultLogout
{
    if (##VAULT < 1) goto L_Return;
    // TODO: Or #VAULT ? Which of the two is set?
    set $@API_PROTOCOL, API_VAULT;
    set $@API_DATA$, "'UID': "+##VAULT+", 'GID': "+getcharid(3);
    callfunc "FlushAPI";

    return;

L_Return:
    return;
}