summaryrefslogtreecommitdiff
path: root/world/map/npc/029-2/alchemy.txt
blob: f8f1c0ddc60888ebd2b7d54624a43c899118664b (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
-|script|_N-Alchemy|32767
{
    set @npc_distance, 1;
    callfunc "PCtoNPCRange";
    if (@npc_check) end;

    title "Alchemy Lab";
    mes "This is an alchemy lab.";
    mes "With it, you can combine reagents together to create powerful potions.";
    next;
    clear;
    mes "##BDrag & drop 2 items from your inventory. All items used will be lost.##b";
    cleararray @alchlab_items$[0], "", 2; // since we're not using a scoped (.@) array, we need to clean it
    requestitem @alchlab_items$[0], 2; // TODO: add a craft builtin (npc action 12)
    clear;
    if (@alchlab_items$[0] == "" || @alchlab_items$[1] == "")
        goto L_NoItems;

    mes "You are about to combine the following:";
    mes "     ["+ getitemlink(@alchlab_items$[0]) +"]";
    mes "     ["+ getitemlink(@alchlab_items$[1]) +"]";
    mes;
    mes "##BWarning! This will permanently destroy the selected items.##b";
    // can not use a scope variable to store item names because menu is a script terminator (destroys the scope)
    menu
        "Abort Mission.", L_Abort,
        "Proceed.", L_Proceed,
        "I want to make several.", L_Multi;

L_Proceed:
    // XXX: here we could make it wait a little, while the potion is boiling (and show an animation/particles/sound)
    if (countitem(@alchlab_items$[0]) < 1 || countitem(@alchlab_items$[1]) < 1) // this shouldn't happen, but just to be safe..
        goto L_NoItems;
    delitem @alchlab_items$[0], 1;
    delitem @alchlab_items$[1], 1;
    if (@alchlab_items$[0] == "BottleOfWater" || @alchlab_items$[1] == "BottleOfWater") // give back used bottles
        getitem "EmptyBottle", if_then_else(@alchlab_items$[0] == "BottleOfWater" && @alchlab_items$[1] == "BottleOfWater",2,1);

    set .@n, -3;
    goto L_CheckRecipes;

L_CheckRecipes:
    set .@n, .@n+3;
    if (.@n == get(.rsize, "_N-Alchemy"))
        goto L_Failed;
    if (!(get(.recipes$[.@n], "_N-Alchemy") == @alchlab_items$[0] && get(.recipes$[.@n+1], "_N-Alchemy") == @alchlab_items$[1]) &&
        !(get(.recipes$[.@n], "_N-Alchemy") == @alchlab_items$[1] && get(.recipes$[.@n+1], "_N-Alchemy") == @alchlab_items$[0]))
        goto L_CheckRecipes;

    getitem get(.recipes$[.@n+2], "_N-Alchemy"), 1; // XXX: here we could also make it fail sometimes depending on your expertise

    // XXX: here we could make it give profession/crafting exp
    clear;
    mes "You combined the following:";
    mes "     ["+ getitemlink(@alchlab_items$[0]) +"]";
    mes "     ["+ getitemlink(@alchlab_items$[1]) +"]";
    mes;
    mes "You obtained:";
    mes "     ["+ getitemlink(get(.recipes$[.@n+2], "_N-Alchemy")) +"]";
    close;

L_NoItems:
    mes "You must put exactly 2 items.";
    close;

L_Failed:
    mes "The potion bubbles violently and evaporates."; // XXX: here we could have random failure messages
    close;

L_Abort:
    close;

// Bikeshedding starts here
L_Multi:
    mes "How many?";
    mes "##BWarning! This will permanently destroy the selected items.##b";
    input @count;
    if (@count == 0)
        close;

    if (countitem(@alchlab_items$[0]) < @count || countitem(@alchlab_items$[1]) < @count)
        goto L_NoItems;
    delitem @alchlab_items$[0], @count;
    delitem @alchlab_items$[1], @count;
    if (@alchlab_items$[0] == "BottleOfWater" || @alchlab_items$[1] == "BottleOfWater")
        getitem "EmptyBottle", if_then_else(@alchlab_items$[0] == "BottleOfWater" && @alchlab_items$[1] == "BottleOfWater",2*@count,@count);

    set .@n, -3;
    goto L_CheckRecipesMulti;

L_CheckRecipesMulti:
    set .@n, .@n+3;
    if (.@n == get(.rsize, "_N-Alchemy"))
        goto L_Failed;
    if (!(get(.recipes$[.@n], "_N-Alchemy") == @alchlab_items$[0] && get(.recipes$[.@n+1], "_N-Alchemy") == @alchlab_items$[1]) &&
        !(get(.recipes$[.@n], "_N-Alchemy") == @alchlab_items$[1] && get(.recipes$[.@n+1], "_N-Alchemy") == @alchlab_items$[0]))
        goto L_CheckRecipesMulti;

    getitem get(.recipes$[.@n+2], "_N-Alchemy"), @count;

    clear;
    mes "You combined the following:";
    mes "     ["+ getitemlink(@alchlab_items$[0]) +"]";
    mes "     ["+ getitemlink(@alchlab_items$[1]) +"]";
    mes;
    mes "You obtained:";
    mes "     ["+ getitemlink(get(.recipes$[.@n+2], "_N-Alchemy")) +"]";
    close;
// Bikeshedding ends here

S_Spawn:
    set .@s, getarraysize(.x1);
    if (.spawned >= .@s)
        goto S_Return;
    set .@n$, "#_Al-lab"+chr(3)+.spawned;
    if (puppet(.m$[.spawned], .x1[.spawned], .y1[.spawned], .@n$, 399) < 1) mapexit;
    set .spawned, .spawned + 1;
    if (.spawned < .@s)
        goto S_Spawn;
    return;

S_Return:
    return;

OnMaybeStart:
    callsub S_Spawn;
    if (.started == 0)
        goto L_InitVars;
    end;

L_InitVars:
    setarray .recipes$[0], 0,
        "DilutedConcentrationPot", "DarkConcentrationPotion", "ConcentrationPotion",
        "CactusDrink", "CactusDrink", "CactusPotion",
        "MountainSnakeTongue", "BottleOfWater", "SlowPoisonPotion",
        "SmallMushroom", "BottleOfWater", "IronPotion",
        "ManaDust", "BottleOfWater", "EnlighteningElixir",
        "PinkPetal", "BottleOfWater", "ConcentrationPotion";
    set .rsize, getarraysize(.recipes$);
    end;
}