-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patharmor.lua
More file actions
334 lines (320 loc) · 11.8 KB
/
armor.lua
File metadata and controls
334 lines (320 loc) · 11.8 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
local S = minetest.get_translator()
local armor_pieces = {
["exchangeclone:helmet_dark_matter"] = {material = "dark_matter", piece = "helmet", category = "weak"},
["exchangeclone:helmet_red_matter"] = {material = "red_matter", piece = "helmet", category = "weak"},
["exchangeclone:chestplate_dark_matter"] = {material = "dark_matter", piece = "chestplate", category = "strong"},
["exchangeclone:chestplate_red_matter"] = {material = "red_matter", piece = "chestplate", category = "strong"},
["exchangeclone:leggings_dark_matter"] = {material = "dark_matter", piece = "leggings", category = "strong"},
["exchangeclone:leggings_red_matter"] = {material = "red_matter", piece = "leggings", category = "strong"},
["exchangeclone:boots_dark_matter"] = {material = "dark_matter", piece = "boots", category = "weak"},
["exchangeclone:boots_red_matter"] = {material = "red_matter", piece = "boots", category = "weak"},
}
local armor_categories = {
weak = {dark_matter = exchangeclone.mcl and 0.16 or 0.13, red_matter = exchangeclone.mcl and 0.18 or 0.15},
strong = {dark_matter = exchangeclone.mcl and 0.24 or 0.18, red_matter = exchangeclone.mcl and 0.27 or 0.2}
}
local function damage_formula(armor_data, damage, reason)
local start
local threshold
local first_value
if armor_data.material == "dark_matter" then
if armor_data.category == "weak" then
if reason.type == "explosion" then
start = 70
else
start = 20
end
threshold = start + 6
first_value = 0.9
else
if reason.type == "explosion" then
start = 105
else
start = 45
end
threshold = start + 16
first_value = 0.7
end
else
if armor_data.category == "weak" then
if reason.type == "explosion" then
start = 100
else
start = 50
end
threshold = start + 6
first_value = 0.9
else
if reason.type == "explosion" then
start = 150
threshold = 162
first_value = 0.78
else
start = 70
threshold = 76
first_value = 0.9
end
end
end
if damage < start then
return damage
elseif damage <= threshold then
-- This formula took me unnecessarily long to figure out.
return damage-(first_value+((damage-1)*((0.03*(damage)/2)+first_value)))
else
return damage*0.05 -- Not exact (some armor pieces are 3%, some are 7%, but I don't care)
end
end
local function get_blocked_damage(itemstack, damage, reason)
local armor_data = armor_pieces[itemstack:get_name()]
if not armor_data then return 0 end
local base_block = armor_categories[armor_data.category][armor_data.material]
if reason.type == "lava" then
return damage
elseif reason.type == "fall" then
if armor_data.piece == "boots" then
if armor_data.material == "dark_matter" then
if damage < 31 then
return 5
end
elseif damage < 55 then
return 10
end
end
return base_block*damage
elseif reason.type == "explosion" or reason.type == "anvil" or (exchangeclone.mcl and reason.flags.is_projectile) then
return damage_formula(armor_data, damage, reason)
elseif reason.type == "drown" then
if armor_data.piece == "helmet" then
if damage < 10 then
return 2
end
end
return base_block*damage
end
return base_block*damage
end
-- Reset health (old versions increased HP with full RM armor)
function exchangeclone.check_armor_health(obj)
if obj:get_meta():get_int("exchangeclone_red_matter_armor") == 1 then
obj:set_hp(math.min(obj:get_hp(), 20))
obj:set_properties({hp_max = 20})
obj:get_meta():set_int("exchangeclone_red_matter_armor", 0)
end
end
minetest.register_on_joinplayer(function(ObjectRef, last_login)
exchangeclone.check_armor_health(ObjectRef)
end)
if exchangeclone.mcl then
mcl_armor.register_set({
name = "dark_matter",
description = "Dark Matter",
descriptions = exchangeclone.mcla and {
head = S("Dark Matter Helmet"),
torso = S("Dark Matter Chestplate"),
legs = S("Dark Matter Leggings"),
feet = S("Dark Matter Boots")
},
durability = -1,
enchantability = 0,
-- No armor points because I don't want MCL's armor code messing up the math.
points = {
head = 0,
torso = 0,
legs = 0,
feet = 0,
},
textures = {
head = "exchangeclone_dark_matter_helmet.png",
torso = "exchangeclone_dark_matter_chestplate.png",
legs = "exchangeclone_dark_matter_leggings.png",
feet = "exchangeclone_dark_matter_boots.png",
},
toughness = 4,
groups = {dark_matter_armor = 1, fire_immune = 1, exchangeclone_upgradable = 1},
craft_material = "exchangeclone:dark_matter",
cook_material = "mcl_core:diamondblock",
sound_equip = "mcl_armor_equip_diamond",
sound_unequip = "mcl_armor_unequip_diamond",
})
mcl_armor.register_set({
name = "red_matter",
description = "Red Matter",
descriptions = exchangeclone.mcla and {
head = S("Red Matter Helmet"),
torso = S("Red Matter Chestplate"),
legs = S("Red Matter Leggings"),
feet = S("Red Matter Boots")
},
durability = -1,
enchantability = 0,
-- No armor points because I don't want MCL's armor code messing up the math.
points = {
head = 0,
torso = 0,
legs = 0,
feet = 0,
},
textures = {
head = "exchangeclone_red_matter_helmet.png",
torso = "exchangeclone_red_matter_chestplate.png",
legs = "exchangeclone_red_matter_leggings.png",
feet = "exchangeclone_red_matter_boots.png",
},
toughness = 5,
groups = {red_matter_armor = 1, disable_repair = 1, fire_immune = 1, exchangeclone_upgradable = 1},
craft_material = "exchangeclone:red_matter",
cook_material = "exchangeclone:dark_matter",
sound_equip = "mcl_armor_equip_diamond",
sound_unequip = "mcl_armor_unequip_diamond",
})
for _, matter in pairs({"dark", "red"}) do
for _, type in pairs({"helmet", "chestplate", "leggings", "boots"}) do
minetest.override_item("exchangeclone:"..type.."_"..matter.."_matter", {
inventory_image = "exchangeclone_inv_"..matter.."_matter_"..type..".png",
})
end
end
-- Until Minetest fixes an issue, there's no way to make this work correctly.
mcl_damage.register_modifier(function(obj, damage, reason)
if not obj:is_player() then return end
local inv = mcl_util.get_inventory(obj)
local blocked = 0
if inv then
for name, element in pairs(mcl_armor.elements) do
local itemstack = inv:get_stack("armor", element.index)
local item_blocked = math.max(0,get_blocked_damage(itemstack, damage, reason))
blocked = blocked + item_blocked
end
return math.max(0, damage - blocked)
end
end, -100)
elseif exchangeclone.exile then
-- FIXME: add armor
else
assert(exchangeclone.mtg)
for _, matter in pairs({"Dark", "Red"}) do
for piece, place in pairs({Helmet = "head", Chestplate = "torso", Leggings = "legs", Boots = "feet"}) do
local matter_lower = matter:lower()
local piece_lower = piece:lower()
armor:register_armor("exchangeclone:"..piece_lower.."_"..matter_lower.."_matter", {
description = S("@1 Matter @2", matter, piece),
texture = "exchangeclone_"..matter_lower.."_matter_"..piece_lower..".png",
inventory_image = "exchangeclone_inv_"..matter_lower.."_matter_"..piece_lower..".png",
groups = {["armor_"..place] = 1, [matter_lower.."_matter_armor"] = 1, disable_repair = 1, exchangeclone_upgradable = 1}
})
end
end
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if hp_change < 0 then
local damage = -hp_change
local _, armor_inv = armor:get_valid_player(player, "3d_armor")
local blocked = 0
for i = 1, #armor_inv:get_list("armor") do
local itemstack = armor_inv:get_stack("armor", i)
blocked = blocked + get_blocked_damage(itemstack, damage, reason)
end
return -math.max(0, damage - blocked)
else
return hp_change
end
end, true)
end
local d = "exchangeclone:dark_matter"
local r = "exchangeclone:red_matter"
minetest.register_craft({
output = "exchangeclone:helmet_dark_matter",
recipe = {
{d,d,d},
{d,"",d}
}
})
minetest.register_craft({
output = "exchangeclone:chestplate_dark_matter",
recipe = {
{d,"",d},
{d,d,d},
{d,d,d},
}
})
minetest.register_craft({
output = "exchangeclone:leggings_dark_matter",
recipe = {
{d,d,d},
{d,"",d},
{d,"",d},
}
})
minetest.register_craft({
output = "exchangeclone:boots_dark_matter",
recipe = {
{d,"",d},
{d,"",d},
}
})
minetest.register_craft({
output = "exchangeclone:helmet_red_matter",
recipe = {
{r,r,r},
{r,"exchangeclone:helmet_dark_matter",r}
}
})
minetest.register_craft({
output = "exchangeclone:chestplate_red_matter",
recipe = {
{r,"exchangeclone:chestplate_dark_matter",r},
{r,r,r},
{r,r,r},
}
})
minetest.register_craft({
output = "exchangeclone:leggings_red_matter",
recipe = {
{r,r,r},
{r,"exchangeclone:leggings_dark_matter",r},
{r,"",r},
}
})
minetest.register_craft({
output = "exchangeclone:boots_red_matter",
recipe = {
{r,"exchangeclone:boots_dark_matter",r},
{r,"",r},
}
})
if exchangeclone.mtg then
minetest.register_tool("exchangeclone:shield_dark_matter", {
description = "Dark Matter Shield (deprecated)\nYou still have this so you can turn it into EMC.\nAnd no, it's not supposed to have a texture.",
groups = {disable_repair = 1, not_in_creative_inventory = 1, not_in_craft_guide = 1}
})
exchangeclone.register_craft({
output = "exchangeclone:shield_dark_matter",
type = "shapeless",
recipe = {
"exchangeclone:dark_matter",
"exchangeclone:dark_matter",
"exchangeclone:dark_matter",
"exchangeclone:dark_matter",
"exchangeclone:dark_matter",
"exchangeclone:dark_matter",
"exchangeclone:dark_matter",
}
})
minetest.register_tool("exchangeclone:shield_red_matter", {
description = "Red Matter Shield (deprecated)\nYou still have this so you can turn it into EMC.\nAnd no, it's not supposed to have a texture.",
groups = {disable_repair = 1, not_in_creative_inventory = 1, not_in_craft_guide = 1}
})
exchangeclone.register_craft({
output = "exchangeclone:shield_red_matter",
type = "shapeless",
recipe = {
"exchangeclone:shield_dark_matter",
"exchangeclone:red_matter",
"exchangeclone:red_matter",
"exchangeclone:red_matter",
"exchangeclone:red_matter",
"exchangeclone:red_matter",
"exchangeclone:red_matter",
}
})
end