summaryrefslogtreecommitdiff
path: root/npc/functions/refine.txt
blob: fb1cfb57ef83d18a4501f0c7d74dd38d7f8a02e6 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// TMW2 Script
// Author:
//      Jesusalva
//      Pyndragon (inspiration)
//      Scall (inspiration)
// Description:
//      Refine functions. Includes equipment repair. In future use getequippercentrefinery(.@it, REFINE_CHANCE_TYPE_ENRICHED) too

// (No arguments)
function	script	refineMaster	{
    mesn;
    mesq l("Ah, hello there, funny face! Do you want to refine items?");
    mesc l("There's always some chance that THE ITEM WILL BREAK, beware!");
    next;
    mesn;
    mesq l("First - item must be equipped.");
    mesq l("If you succeed, the defense and/or attack will raise. If you fail, refine level goes down.");
    //mesq l("And if the item breaks, that is definitive - no repair is possible. What to refine?");
    mesq l("And if the item breaks, that's your loss. What to refine?");
    next;

    // Dark magic from hercules used, take care
    menuint
        l("Nothing, thanks"), 0,
        rif(getequipisequiped(EQI_HEAD_MID), l("My chestplate, @@", getequipname(EQI_HEAD_MID))), EQI_HEAD_MID,
        rif(getequipisequiped(EQI_HAND_R), l("My weapon, @@", getequipname(EQI_HAND_R))), EQI_HAND_R,
        rif(getequipisequiped(EQI_HAND_L) && getequipid(EQI_HAND_L) != getequipid(EQI_HAND_R), l("My shield, @@", getequipname(EQI_HAND_L))), EQI_HAND_L,
        rif(getequipisequiped(EQI_HEAD_TOP), l("My helmet, @@", getequipname(EQI_HEAD_TOP))), EQI_HEAD_TOP,
        l("Item break? Too dangerous! I don't want it!!"), 0;


	if (@menuret == 0) {
        mesn;
        //mesq l("Wait a moment - you are naked! YOU WILL DIE IN THE FREEZE! o.o");
        mesq l("Well... we'll see around!");
		close;
	}
    .@it=@menuret;
    .@item=getequipid(.@it);

    /*
    mes "##B" + l("Drag and drop an item from your inventory.") + "##b";
    .@item = requestitem();

    // Check if we received an item
    if (.@item < 1) {
        mesn;
        mesq l("Well, no risk, no gain.");
        close;
        return;
    }
    */

    // Not all items are refinable
	if (!getequipisenableref(.@it)) {
		mesn;
		mesq l("Well, sorry, but only some items can be refined.");
        mesq l("There may be some exceptions. Anyway, this item clearly cannot be refined.");
        next;
		return;
	}

    // Max refining level: 10
	if (getequiprefinerycnt(.@it) >= 10) {
		mesn;
		mesq l("This item cannot be refined further.");
        return;
	}

    .@rlv=getequiprefinerycnt(.@it);
    .@price=(.@rlv+1)*1000;
	.@price=POL_AdjustPrice(.@price);
    .@amount=(.@rlv/2)+1;
    // required item
    switch (.@rlv) {
        case 0:
        case 1:
        case 2:
        case 3:
            .@rg=Wurtzite; break;
        case 4:
        case 5:
        case 6:
        case 7:
            .@amount=((.@rlv-4)/2)+1;
            .@rg=Graphene; break;
        case 8:
        case 9:
        case 10:
        default:
            .@amount=((.@rlv-8)/2)+1;
            .@rg=Arcanum; break;
    }
    mesn;
    mesq l("This @@ is a nice stuff. I can refine it for @@ GP and @@ @@.", getitemlink(.@item), .@price, .@amount, getitemlink(.@rg));
    mesc l("Success ratio is of aprox. @@ %", (100-(.@rlv*7))+rand2(-6,6));
    next;
    if (askyesno() != ASK_YES)
        close;

    // Anti-Crazyfefe™ System
    // No money
    if (Zeny < .@price) {
        mesn;
        mesq l("Where's the money? Go away.");
        close;
    }
    // No reagents
    if (countitem(.@rg) < .@amount) {
        mesn;
        mesq l("Where's the reagent? You don't expect me to find it, right? Go bring them!");
        close;
    }
    // Item removed
	if (getequipisequiped(.@it) == 0) {
        mesn;
        mesc l("All cheaters must die."), 1;
        percentheal -100, -100;
        close;
    }
    // Item changed
	if (getequiprefinerycnt(.@it) != .@rlv || getequipid(.@it) != .@item) {
        mesn;
        mesc l("All cheaters must die."), 1;
        percentheal -100, -100;
        close;
    }
    ///// This should cover most of Crazyfefe tricks ¬.¬ I hope ¬.¬
    mesn;
    mesq l("HA, HA, HA! The blacksmiths from the Land of Fire are the best from the world! There's no challenge too big for us!");
    mesq l("It's time to show this shiny @@ who is the boss! HAHAHAHAHAHAHAH!", getitemlink(.@item));
    next;
    // Cheater should be locked for eternity.
	if (getequiprefinerycnt(.@it) != .@rlv || getequipid(.@it) != .@item || getequipisequiped(.@it) == 0) {
        atcommand "@jail "+strcharinfo(0);
        close;
    }
    // If you cheat somewhere along the way, the script will explode
	POL_PlayerMoney(.@price);

    // Were we successful?
	if (getequippercentrefinery(.@it) > rand2(100)) {
	    successrefitem .@it;
        mesn;
        mesq l("HAHAHAHAH! Shiny as new, and stronger than ever! Have fun!");
        mesc l("Weapons: +8 attack, +8 magic attack");
        mesc l("Armors: +3~5 defense");
        next;
    // Item is weakened. (1% per refine level)
    } else if (rand2(100) < .@rlv) {
		downrefitem .@it, 1;
        mesn;
        mesq l("A masterpiece!... Whaaaat, this stuff got ##Bweaker##b??");
        next;
        mesn;
        mesq l("Well, I did my best, but this had been so refined, that it was difficult to find my way.");
        next;
        mesn;
        mesq l("I'm sure I could refine this again, if you bring me the payment and the reagents again.");
        next;
    // Perhaps the item has broken? (~0.1% chance/refine level)
    } else if (rand2(10000) <= 10*(.@rlv+1)) {
		failedrefitem .@it;
        mesc l("*CRASH*");
        next;
        mesn;
        mesq l("Ops... I hammered this stuff too hard... It's junk now.");
        next;
        mesn;
        mesq l("Well, you were warned. Do you have any other stuff for me?");
        next;
    // Nothing happens
    } else {
        mesn;
        mesq l("Well, I did my best, but this had been so refined, that it was difficult to find my way.");
        next;
        mesn;
        mesq l("I'm sure I could refine this again, if you bring me the payment and the reagents again.");
        next;
    }
    delitem .@rg, .@amount; // We delete last, to prevent IDX changes
    return;
}


// (No arguments)
function	script	repairMaster	{
    mesn;
    mesq l("I am a really good blacksmith. In fact, there is no stuff I can't fix.");
    next;
    mesn;
	if (getbrokenid(1) == 0) {
		mesq l("I don't think you have any broken item, but if a friend of mine break your stuff, come talk to me!");
        close;
	} else {
        // Print the name of the first broken item
		mesq l("You seem to have @@ broken items and... Oh, I see you have a broken @@ here! I wanna repair it!", getbrokencount(), getitemname(getbrokenid(1)));
        .@save=getbrokenid(1);
        next;
    }
    .@price=getiteminfo(getbrokenid(1), ITEMINFO_SELLPRICE)+getiteminfo(getbrokenid(1), ITEMINFO_ELV)-(getbrokencount()*15);
    if (.@price < 100 || getbrokenid(1) == BronzeGladius)
        .@price=100;
    mesn;
    mesq l("I can fix this for you. Just pay me @@ GP and a @@. It'll take no time at all!", .@price, getitemlink(IronIngot));
    next;
    if (Zeny < .@price || countitem(IronIngot) < 1 || askyesno() != ASK_YES) {
        mes "";
        mesn;
        mesq l("Ahh, that's a pity... Well, just talk to me with enough money and I'll gladly fix that for you! %%0");
        close;
    }
    // Cheating? Well, let's try to be innovative this time
    if (.@save != getbrokenid(1)) {
        mesn;
        mesq l("Ah...! POLICE! POLICE! Quick, send this cheating thief to jail!!");
        atcommand "@jailfor 20mn "+strcharinfo(0);
        close;
    }
    Zeny=Zeny-.@price;
    delitem IronIngot, 1;
    repair(1);
    mesn;
    mesq l("Here, sparking new! Nice!!");
    if (getbrokencount() > 0) {
        next;
        return;
    } else {
        close;
    }
}