mirror of
https://github.com/pandorabox-io/spacecannon.git
synced 2024-12-30 09:37:29 +01:00
particles, on_blast(), luacheckrc
This commit is contained in:
parent
655d4bb191
commit
b60bc6328f
22
.luacheckrc
Normal file
22
.luacheckrc
Normal file
@ -0,0 +1,22 @@
|
||||
unused_args = false
|
||||
allow_defined_top = true
|
||||
|
||||
globals = {
|
||||
"minetest",
|
||||
"spacecannon"
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
-- Stdlib
|
||||
string = {fields = {"split"}},
|
||||
table = {fields = {"copy", "getn"}},
|
||||
|
||||
-- mod deps
|
||||
"technic", "default",
|
||||
|
||||
-- Minetest
|
||||
"minetest",
|
||||
"vector", "ItemStack",
|
||||
"dump"
|
||||
|
||||
}
|
13
cannon.lua
13
cannon.lua
@ -57,13 +57,13 @@ local register_spacecannon = function(def)
|
||||
end
|
||||
|
||||
if collided then
|
||||
spacecannon.destroy(pos, def.range)
|
||||
spacecannon.destroy(pos, def.range, def.intensity)
|
||||
self.object:remove()
|
||||
end
|
||||
|
||||
elseif node.name ~= "air" and node.name ~= "vacuum:vacuum" then
|
||||
-- collision
|
||||
spacecannon.destroy(pos, def.range)
|
||||
spacecannon.destroy(pos, def.range, def.intensity)
|
||||
self.object:remove()
|
||||
|
||||
end
|
||||
@ -71,8 +71,8 @@ local register_spacecannon = function(def)
|
||||
|
||||
on_activate = function(self, staticdata)
|
||||
minetest.after(def.timeout,
|
||||
function(self)
|
||||
self.object:remove()
|
||||
function(me)
|
||||
me.object:remove()
|
||||
end,
|
||||
self)
|
||||
end
|
||||
@ -143,8 +143,6 @@ local register_spacecannon = function(def)
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos);
|
||||
|
||||
if fields.fire then
|
||||
spacecannon.fire(pos, def.color, def.speed, def.range)
|
||||
end
|
||||
@ -170,6 +168,7 @@ end
|
||||
register_spacecannon({
|
||||
color = "green",
|
||||
range = 1,
|
||||
intensity = 1,
|
||||
timeout = 8,
|
||||
speed = 10,
|
||||
desc = "fast,low damage",
|
||||
@ -179,6 +178,7 @@ register_spacecannon({
|
||||
register_spacecannon({
|
||||
color = "yellow",
|
||||
range = 3,
|
||||
intensity = 2,
|
||||
timeout = 8,
|
||||
speed = 5,
|
||||
desc = "medium speed, medium damage",
|
||||
@ -188,6 +188,7 @@ register_spacecannon({
|
||||
register_spacecannon({
|
||||
color = "red",
|
||||
range = 5,
|
||||
intensity = 4,
|
||||
timeout = 15,
|
||||
speed = 3,
|
||||
desc = "slow, heavy damage",
|
||||
|
50
util.lua
50
util.lua
@ -20,7 +20,6 @@ spacecannon.fire = function(pos, color, speed, range)
|
||||
|
||||
-- check fuel/power
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
if meta:get_int("powerstorage") < spacecannon.config.powerstorage * range then
|
||||
-- not enough power
|
||||
@ -45,12 +44,14 @@ end
|
||||
|
||||
-- destroy stuff in range
|
||||
-- TODO: resilient material list
|
||||
spacecannon.destroy = function(pos,range)
|
||||
spacecannon.destroy = function(pos, range, intensity)
|
||||
|
||||
if not spacecannon.can_destroy(pos) then
|
||||
return
|
||||
end
|
||||
|
||||
local particle_texture = nil
|
||||
|
||||
for x=-range,range do
|
||||
for y=-range,range do
|
||||
for z=-range,range do
|
||||
@ -64,14 +65,28 @@ spacecannon.destroy = function(pos,range)
|
||||
local n = minetest.get_node_or_nil(np)
|
||||
|
||||
if n and n.name ~= "air" then
|
||||
minetest.set_node(np, {name="air"})
|
||||
local itemstacks = minetest.get_node_drops(n.name)
|
||||
for _, itemname in ipairs(itemstacks) do
|
||||
if math.random(5) == 5 then
|
||||
-- chance drop
|
||||
minetest.add_item(np, itemname)
|
||||
local node_def = minetest.registered_nodes[n.name]
|
||||
|
||||
if node_def and node_def.tiles and node_def.tiles[1] then
|
||||
particle_texture = node_def.tiles[1]
|
||||
end
|
||||
|
||||
if node_def.on_blast then
|
||||
-- custom on_blast
|
||||
node_def.on_blast(np, intensity)
|
||||
|
||||
else
|
||||
-- default behavior
|
||||
minetest.set_node(np, {name="air"})
|
||||
local itemstacks = minetest.get_node_drops(n.name)
|
||||
for _, itemname in ipairs(itemstacks) do
|
||||
if math.random(5) == 5 then
|
||||
-- chance drop
|
||||
minetest.add_item(np, itemname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -98,6 +113,25 @@ spacecannon.destroy = function(pos,range)
|
||||
glow = 5
|
||||
})
|
||||
|
||||
if particle_texture then
|
||||
minetest.add_particlespawner({
|
||||
amount = 64,
|
||||
time = 0.5,
|
||||
minpos = vector.subtract(pos, radius / 2),
|
||||
maxpos = vector.add(pos, radius / 2),
|
||||
minvel = {x = -10, y = -10, z = -10},
|
||||
maxvel = {x = 10, y = 10, z = 10},
|
||||
minacc = vector.new(),
|
||||
maxacc = vector.new(),
|
||||
minexptime = 1,
|
||||
maxexptime = 2.5,
|
||||
minsize = radius * 3,
|
||||
maxsize = radius * 5,
|
||||
texture = particle_texture,
|
||||
glow = 5
|
||||
})
|
||||
end
|
||||
|
||||
minetest.sound_play("tnt_explode", {pos = pos, gain = 1.5, max_hear_distance = math.min(radius * 20, 128)})
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user