summaryrefslogblamecommitdiff
path: root/npc/functions/alchemy.txt
blob: ea77011ed788fb3a74dbb695558c78b22e281db9 (plain) (tree)


























































































                                                                                      
// TMW2 Script
// Author:
//  Jesusalva
// Description:
//  Alchemy System (oversimplified)

// Usage: AlchemySystem ()
// Returns true on success, false on failure
function	script	AlchemySystem	{
    .success=false;

    setskin "craft2";
    .@var$ = requestcraft(2);
    .@craft = initcraft(.@var$);
    .@entry = findcraftentry(.@craft, CRAFT_ALCHEMY);
    if (debug || $@GM_OVERRIDE) mes "found craft entry: " + .@entry;
    if (.@entry < 0) {
            .success=false;
    } else {
        // Determine how many units to make
        // This code comes from Moubootaur Legends
        // Where sponsors could make up to 25 units
        // And you could configure a fixed number to
        // avoid prompts...
        // ...
        // PS. This is not using freeloop()
        // Max amount is limited for performance.
        if (GSET_FIXED_ALCHEMY) {
            .@m=limit(1, GSET_FIXED_ALCHEMY, 25);
        } else {
            .@max=(is_trusted() ? 25 : 10);
            mesc l("How many to brew? (%d-%d)", 1, .@max);
            input(.@m, 1, .@max);
        }
        // Alchemy loop
        .@i=0;
        while (.@i < .@m) {
            .@s=validatecraft(.@craft);
            // Could not validate (not enough resources)
            if (!.@s) {
                mesc l("Insufficient materials to continue."), 1;
                if (.@i)
                    mesc l("Only %d/%d units were produced.", .@i, .@m), 1;
                break;
            }
            .@s=usecraft(.@craft);
            .@i++;
            // Exploiting?!
            if (!.@s)
                break;
        }
        .success=true;
    }
    deletecraft .@craft;
    setskin "";
    return .success;
}

////////////////////////////////////////////////////////////////////////////////
// Build the various crafting tables on the world
001-2,92,76,0	script	#AlchemyTable000	NPC_NO_SPRITE,{
    title l("Alchemy Lab");
    mes l("This is an alchemy lab.");
    mes l("With it, you can combine reagents together to create powerful potions.");
    next;
    mes b(l("Drag & drop 2 items from your inventory. All items used will be lost."));
    if (AlchemySystem())
        mesc l("Success!"), 3;
    else
        mesc l("That didn't work!"), 1;
    close;

OnInit:
    .distance=2;
    end;
}

// Tonori Region (0~99)
001-2,92,89,0	duplicate(#AlchemyTable000)	#AlchemyTable001	NPC_NO_SPRITE
001-2,98,76,0	duplicate(#AlchemyTable000)	#AlchemyTable002	NPC_NO_SPRITE
001-2,98,89,0	duplicate(#AlchemyTable000)	#AlchemyTable003	NPC_NO_SPRITE

// Argaes Region (100~199)
026-2,35,117,0	duplicate(#AlchemyTable000)	#AlchemyTable100	NPC_NO_SPRITE

// Candor Region (200~299)
029-2,113,57,0	duplicate(#AlchemyTable000)	#AlchemyTable200	NPC_NO_SPRITE