summaryrefslogtreecommitdiff
path: root/npc/functions/crafting.txt
blob: fa5fa84e475b95359a4efc7d19f019ddc6f9a842 (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
// Moubootaur Legends Script
// Author:
//  Jesusalva
//  Gumi
// Description:
//  Smith System (Unified)
// Notes:
//  Modified for The Mana World: rEvolt
//
// This one is more crazy. Cannot be equipping target craft.
// After successful craft, we use CraftDB return code to equip() the
// new item and apply a random option bonus based on crafter skills
// eg. setequipoption(EQI_HAND_R, 1, VAR_STRAMOUNT, 5)

// Usage: SmithSystem ({scope=CRAFT_SMITHERY, checks=True})
// Returns true on success, false on failure
function	script	SmithSystem	{
    .@scope=getarg(0, CRAFT_SMITHERY);
    mesc l("WARNING: Strange bugs may happen if you attempt to craft an item you already have on inventory!"), 1;
    setskin "craft4";
    .@var$ = requestcraft(4);
    .@craft = initcraft(.@var$);
    .@entry = findcraftentry(.@craft, .@scope);
    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 (!getarg(1, true) || RECIPES[.@entry]) {
            // Player craft item and setup base variables
            usecraft .@craft;
            .@it=getcraftcode(.@entry);
            .@lv=getiteminfo(.@it, ITEMINFO_ELV);
            .@skill=getskilllv(EVOL_CRAFTING);

            // Update your CRAFTING_SCORE
            CRAFTING_SCORE+=.@lv;

            // Obtain the item. No bounds or restrictions applied.
            getitem(.@it, 1);

            // This is where we add options - this is oversimplified
            // delinventorylist() is needed, because we'll rely on rfind()
            delinventorylist();
            getinventorylist();
            .@index=array_rfind(@inventorylist_id, .@it);

            // Prepare the options
            .@isweapon=(getiteminfo(.@it, ITEMINFO_TYPE) == IT_WEAPON);
            .@bonus=(.@isweapon ? VAR_ATTPOWER : VAR_ITEMDEFPOWER);
            .@magic=(.@isweapon ? VAR_ATTMPOWER : VAR_MDEFPOWER);
            .@buffs=(.@isweapon ? VAR_HITSUCCESSVALUE : VAR_AVOIDSUCCESSVALUE);
            .@heals=(.@isweapon ? VAR_MAXSPAMOUNT : VAR_MAXHPAMOUNT);

            // Now we need to randomly decide what will be .@opt1 and .@opt2
            // Would be better to not rely on rand here, though.
            .@opt1=any(.@bonus, .@magic);
            .@opt2=any(.@buffs, .@heals);

            // Apply the bonuses. They're capped by equip level and based on:
            // Equip level, crafting experience and crafting skill
            .@val=min(.@lv, (.@skill*CRAFTING_SCORE)/100+.@skill);

            // MDEF rule range is 99 while DEF rule range is 399
            // This is a really hackish way, for the record
            if (.@opt1 == VAR_MDEFPOWER)
                .@val=.@val/4;

            // First option will always succeed
            .@val1=rand2(.@val);
            setitemoptionbyindex(.@index, 0, .@opt1, .@val1);

            // Lucky roll (5% per skill level, capped at 50%)
            // The lucky roll will add the extra attributes
            if (rand2(20) < .@skill) {
                .@val2=rand2(.@val);
                setitemoptionbyindex(.@index, 1, .@opt2, .@val2);
            }

            // Get experience for the craft
            // I'm using the same EXP formula from Moubootaur Legends
            // Which is based on the item sell price
            .@xp=getiteminfo(.@it, ITEMINFO_SELLPRICE);
            quest_xp(.@lv+10, .@xp+BaseLevel);
            quest_jxp(.@lv+10, (.@xp/3)+BaseLevel+JobLevel);
            .success=true;
        } else {
            .success=false;
        }
    }
    deletecraft .@craft;
    setskin "";
    return .success;
}

-	script	@craft	FAKE_NPC,{
    public function DoTailoring {
        SmithSystem(CRAFT_TAILORING);
        end;
    }

    public function DoSmithery {
        SmithSystem(CRAFT_SMITHERY);
        end;
    }

    public function OnInit {
        if (debug < 1) {
            end;
        }

        bindatcmd("@tailoring", sprintf("%s::%s", .name$, "DoTailoring"));
        bindatcmd("@tailor", sprintf("%s::%s", .name$, "DoTailoring"));
        bindatcmd("@smithery", sprintf("%s::%s", .name$, "DoSmithery"));
        bindatcmd("@smith", sprintf("%s::%s", .name$, "DoSmithery"));
        bindatcmd("@blacksmithery", sprintf("%s::%s", .name$, "DoSmithery"));
        end;
    }
}