summaryrefslogtreecommitdiff
path: root/npc/craft/alchemy.txt
blob: 9022edb84d337ed20abfdd9ec7cb0d19c1b2f5a2 (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
// TMW2 Script
// Author:
//  Jesusalva
// Description:
//  Alchemy System (Player, Guild, NPC)
// Notes:
//  Base for Evol MR

// Usage: AlchemySystem ({scope})
// Scopes: CRAFT_NPC, CRAFT_PLAYER, CRAFT_GUILD
// If an invalid scope is passed, .knowledge won't be set but will be required
// Returns true on success, false on failure
function	script	AlchemySystem	{
    // Set .scope, .knowledge and .success
    .scope=getarg(0, CRAFT_PLAYER);
    if (.scope == CRAFT_PLAYER)
    {
        copyarray(.knowledge,RECIPES_ALCHEMY,getarraysize(RECIPES_ALCHEMY));
    }
    else if (.scope == CRAFT_GUILD)
    {
       copyarray( .knowledge,getd("$RECIPES_ALCHEMY_"+getcharid(2)),getarraysize(getd("$RECIPES_ALCHEMY_"+getcharid(2))) );
    }
    .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 (debug || $@GM_OVERRIDE) mes "knowledge value: " + .knowledge[.@entry];
    if (.@entry < 0) {
            .success=false;
    } else {
        if (.scope == CRAFT_NPC || .knowledge[.@entry]) {
            if (GSET_FIXED_ALCHEMY) {
                .@m=limit(1, GSET_FIXED_ALCHEMY, 25);
            } else {
                .@max=(is_sponsor() ? 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("Not crafting - insufficient materials!"), 1;
                    break;
                }
                .@s=usecraft(.@craft);
                .@i++;
                // Exploiting?!
                if (!.@s)
                    break;
            }
            .success=true;
        } else {
            .success=false;
        }
    }
    deletecraft .@craft;
    setskin "";
    return .success;
}