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
|
-- Implements item-repair using the HOOK_CRAFTING_NO_RECIPE hook
-- Based on Fixies plugin v2 by Taugeshtu
-- how much "extra" points are healed per a repair operation (fraction)
BONUS = 0.1
function OnCraftingNoRecipe(Player, Grid, Recipe)
local _do_fix = false
local Items = {}
for x = 0, Grid:GetWidth() - 1 do
for y = 0, Grid:GetHeight() - 1 do
local Item = Grid:GetItem(x, y)
if (Item.m_ItemID ~= E_ITEM_EMPTY) then
table.insert(Items, Item)
end
end
end
if (#Items ~= 2) then
-- Only two items together can be fixed
return false
end
if (Items[1].m_ItemID ~= Items[2].m_ItemID) then
-- Only same items may be fixed
return false
end
local _ID = Items[1].m_ItemID
local _least_hp = math.max(Items[1].m_ItemHealth, Items[2].m_ItemHealth)
local _most_hp = math.min(Items[1].m_ItemHealth, Items[2].m_ItemHealth)
local _item_hp = 0
-- TODO: This could be refactored into better code, using an _ID-indexed table for _item_hp
if (
(_ID == E_ITEM_WOODEN_SHOVEL) or
(_ID == E_ITEM_WOODEN_AXE) or
(_ID == E_ITEM_WOODEN_PICKAXE) or
(_ID == E_ITEM_WOODEN_SWORD) or
(_ID == E_ITEM_WOODEN_HOE)
)
then
_item_hp = 60
_do_fix = true
end
if (
(_ID == E_ITEM_STONE_SHOVEL) or
(_ID == E_ITEM_STONE_AXE) or
(_ID == E_ITEM_STONE_PICKAXE) or
(_ID == E_ITEM_STONE_SWORD) or
(_ID == E_ITEM_STONE_HOE)
)
then
_item_hp = 132
_do_fix = true
end
if (
(_ID == E_ITEM_IRON_SHOVEL) or
(_ID == E_ITEM_IRON_AXE) or
(_ID == E_ITEM_IRON_PICKAXE) or
(_ID == E_ITEM_IRON_SWORD) or
(_ID == E_ITEM_IRON_HOE)
)
then
_item_hp = 251
_do_fix = true
end
if (
(_ID == E_ITEM_GOLD_SHOVEL) or
(_ID == E_ITEM_GOLD_AXE) or
(_ID == E_ITEM_GOLD_PICKAXE) or
(_ID == E_ITEM_GOLD_SWORD) or
(_ID == E_ITEM_GOLD_HOE)
)
then
_item_hp = 33
_do_fix = true
end
if (
(_ID == E_ITEM_DIAMOND_SHOVEL) or
(_ID == E_ITEM_DIAMOND_AXE) or
(_ID == E_ITEM_DIAMOND_PICKAXE) or
(_ID == E_ITEM_DIAMOND_SWORD) or
(_ID == E_ITEM_DIAMOND_HOE)
)
then
_item_hp = 1562
_do_fix = true
end
if (_ID == E_ITEM_LEATHER_CAP) then
_item_hp = 56
_do_fix = true
end
if (_ID == E_ITEM_LEATHER_TUNIC) then
_item_hp = 82
_do_fix = true
end
if (_ID == E_ITEM_LEATHER_PANTS) then
_item_hp = 76
_do_fix = true
end
if (_ID == E_ITEM_LEATHER_BOOTS) then
_item_hp = 66
_do_fix = true
end
if (_ID == E_ITEM_CHAIN_HELMET) then
_item_hp = 78
_do_fix = true
end
if (_ID == E_ITEM_CHAIN_CHESTPLATE) then
_item_hp = 114
_do_fix = true
end
if (_ID == E_ITEM_CHAIN_LEGGINGS) then
_item_hp = 106
_do_fix = true
end
if (_ID == E_ITEM_CHAIN_BOOTS) then
_item_hp = 92
_do_fix = true
end
if (_ID == E_ITEM_IRON_HELMET) then
_item_hp = 166
_do_fix = true
end
if (_ID == E_ITEM_IRON_CHESTPLATE) then
_item_hp = 242
_do_fix = true
end
if (_ID == E_ITEM_IRON_LEGGINGS) then
_item_hp = 226
_do_fix = true
end
if (_ID == E_ITEM_IRON_BOOTS) then
_item_hp = 196
_do_fix = true
end
if (_ID == E_ITEM_GOLD_HELMET) then
_item_hp = 78
_do_fix = true
end
if (_ID == E_ITEM_GOLD_CHESTPLATE) then
_item_hp = 114
_do_fix = true
end
if (_ID == E_ITEM_GOLD_LEGGINGS) then
_item_hp = 106
_do_fix = true
end
if (_ID == E_ITEM_GOLD_BOOTS) then
_item_hp = 92
_do_fix = true
end
if (_ID == E_ITEM_DIAMOND_HELMET) then
_item_hp = 364
_do_fix = true
end
if (_ID == E_ITEM_DIAMOND_CHESTPLATE)then
_item_hp = 529
_do_fix = true
end
if (_ID == E_ITEM_DIAMOND_LEGGINGS) then
_item_hp = 496
_do_fix = true
end
if (_ID == E_ITEM_DIAMOND_BOOTS) then
_item_hp = 430
_do_fix = true
end
-- /////////////////////////////////////////////////////
if (_do_fix == true) then
local _hp = _most_hp - (_item_hp - _least_hp) - _item_hp * BONUS
_hp = math.max(_hp, 0)
Recipe:SetResult(_ID, 1, _hp)
Recipe:SetIngredient(Items[1].x, Items[1].y, Items[1]);
Recipe:SetIngredient(Items[2].x, Items[2].y, Items[2]);
return true
end
return false
end
|