summaryrefslogtreecommitdiff
path: root/npc/functions/alchemy.txt
blob: ea77011ed788fb3a74dbb695558c78b22e281db9 (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
// 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