summaryrefslogtreecommitdiff
path: root/npc/craft/tweak.txt
blob: 07699bf2cb56e5c9839ba43f8a2cef5970f51a17 (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
142
143
144
145
146
// TMW2 Script
// Author:
//  Jesusalva
// Description:
//  Smith System (Player, Guild, NPC)
// Notes:
//  It's like smithing, but it only change an item options

// How many times more can you tweak?
// You regenerate 1 action per hour, capped at 6 actions total.
function	script	SmithTweakPointsLeft	{
    .@points = gettimeparam(GETTIME_HOUR) - SMITH_TWEAKS;
    if (.@points > 6) {
        .@points = 6;
        SMITH_TWEAKS = gettimeparam(GETTIME_HOUR) - 6;
    }
    return .@points;
}

function	script	SmithTweakPointsDecrement	{
    .@item_id = getarg(0, -1);
    if (.@item_id != Lightbringer)
        SMITH_TWEAKS += 1;
    return;
}

function	script	SmithTweakPointsExplain	{
    .@points = SmithTweakPointsLeft();
    mesc l("Note: You can only perform this operation @@/6 times.", .@points);
    mesc l("You recover a tweaking point every hour.");
    if (!.@points)
        mesc l("You currently have no Tweaking AP, so you will need to wait %02d minute(s).", 60-gettime(GETTIME_MINUTE)), 1;
    return .@points;
}


// Usage: SmithTweakReset ()
// Asks if player wants to remove an item options. And remove them.
function	script	SmithTweakReset	{
    mesc b(l("You are REMOVING an item option.")), 1;
    mesc l("Note: This action cannot be undone."), 1;
    mes l("Drag and drop here the item you want to remove the options.");

    .@id=requestitemindex();
    mes "";

    // Ask player to confirm
    mesc l("Are you sure?"), 1;
    mesc l("Note: This action cannot be undone."), 1;
    if (!csys_Confirm(.@id))
        return;

    csys_Check(.@id);
    return;
}

// Usage: SmithTweakSystem ({price=600, retries=1})
// Returns true on success, false on failure
function	script	SmithTweakSystem	{
    .@price=getarg(0, 600);
    .@retry=getarg(1, 1);

	// Adjust price (if relevant)
    if (.@retry == 1)
    	.@price=POL_AdjustPrice(.@price);

    mes l("Which item will you tweak?");
    .@points_left = SmithTweakPointsExplain();
    mesc l("EXPERTS ONLY - If you are not a talented crafter, avoid this."), 1;
    mesc l("The item must have a previous bonus, which WILL BE LOST!"), 1;
    mesc l("Note: You may fail to write skills to it."), 1;
    mesc l("Operation Cost: @@ GP", .@price), 3;

    // Do you have money or AP
    if (Zeny < .@price || !.@points_left) {
        mesc l("You lack money or Action Points."), 1;
        return false;
    }

    .@id=requestitemindex();
    mes "";

    // Ask player to confirm
    if (!csys_Confirm(.@id))
        return false;

    // Collect the item ID
    delinventorylist();
    getinventorylist();
    .@x=@inventorylist_id[.@id];

    // No duplicates
    if (countitem(.@x) > 1) {
        mesc l("You are carrying duplicates of the same item. Sorry, but I have no idea which one you want to tweak."), 1;
        return false;
    }

    // Skip equipped items
    if (isequipped(.@x)) {
        mesc l("You should unequip this item first."), 1;
        return false;
    }

    // If the item have no bonuses - fail
    setarray .@AlwaysTweaks, 65535, BlacksmithAxe, Dustynator, Lightbringer,
                             DemureAxe, Tyranny, Runestaff, AegisShield,
                             SaviorShield, SaviorArmor, SaviorBoots, SaviorPants,
                             Skypiercer;

    // Tweaked items
    if (getitemoptionidbyindex(.@id, 0) <= 0 && !is_master() && array_find(.@AlwaysTweaks, .@x) < 0) {
        mesc l("This item have no bonuses, and cannot be tweaked."), 1;
        return false;
    }

    // Take the money and AP away
	POL_PlayerMoney(.@price);
    SmithTweakPointsDecrement(.@x);

    // Apply the bonuses. This will only loop if `continue;` is cast.
    // `continue` will only be cast if .@retry is set
    do
    {
        .@retry-=1;
        // Check if you fail
        if (!csys_Check(.@id)) {
            mesc l("YOU FAIL! It is a simple item now."), 1;
            if (.@retry) {
                mesc l("...Automatically retrying...");
                continue;
            }
            return false;
        }

        csys_Apply(.@id);
        mesc l("SUCCESS! Congratulations, the item was improved!"), 3;
        if (.@retry) {
            next;
            mesc l("Do you want to re-roll?"), 1;
            if (askyesno() == ASK_YES) {
                continue;
            }
        }
        return true;
    } while (.@retry > 0);
}