Magic Wands system now uses new projectile system

This commit is contained in:
IamPyu 2024-12-21 13:32:02 -06:00
parent 556f976797
commit 2e91cbb1f4
4 changed files with 44 additions and 120 deletions

View File

@ -42,7 +42,7 @@ PyuTest.make_projectile = function (name, properties, options, functions)
initial_properties = PyuTest.util.tableconcat({
visual = "cube",
visual_size = {x=0.5, y=0.5},
collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2,},
collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2},
use_texture_alpha = false,
pointable = false,
glow = core.LIGHT_MAX,

View File

@ -167,3 +167,12 @@ core.register_craft({
{"pyutest_tools:basalt_stick"},
}
})
core.register_craft({
output = "pyutest_magic:explosions_wand",
recipe = {
{"pyutest_blocks:tnt"},
{"pyutest_tools:basalt_stick"},
{"pyutest_tools:basalt_stick"},
}
})

View File

@ -1,41 +1,11 @@
PyuTest.make_wand = function (id, desc, texture, mana, properties, fns)
local e_id = id .. "_entity"
local e_id = id .. "_projectile"
core.register_entity(e_id, {
initial_properties = PyuTest.util.tableconcat({
physical = false,
visual = "cube",
visual_size = {x=0.5, y=0.5},
collisionbox = {-0.2, -0.2, -0.2, 0.2, 0.2, 0.2,},
use_texture_alpha = false,
pointable = false,
glow = core.LIGHT_MAX,
}, properties or {}),
_timer = 0,
_owner = nil,
on_step = function (self, dtime, moveresult)
self._timer = self._timer + dtime
local vel = self.object:get_velocity()
vel = vector.multiply(vel, 0.98)
self.object:set_velocity(vel)
if self._timer > 5 then
self.object:remove()
return
end
if fns.predicate(self) then
core.sound_play("pyutest_special1", {
gain = 1,
pos = self.object:get_pos()
})
fns.action(self)
self.object:remove()
end
end
PyuTest.make_projectile(e_id, properties, {
_slowdown = false
}, {
on_hit_node = fns.on_hit_node,
on_hit_object = fns.on_hit_object
})
PyuTest.make_item(id, desc, {
@ -48,20 +18,7 @@ PyuTest.make_wand = function (id, desc, texture, mana, properties, fns)
return
end
local dir = user:get_look_dir()
local pos = user:get_pos()
pos = vector.offset(pos, 0, 1.3, 0)
pos = vector.add(pos, dir)
local object = core.add_entity(pos, e_id)
object:set_velocity(vector.multiply(dir, 30))
object:get_luaentity()._owner = user
core.sound_play("pyutest_magic_action", {
gain = 1,
pos = pos
})
PyuTest.shoot_projectile_from_object(e_id, user)
return itemstack
end
@ -78,15 +35,7 @@ PyuTest.make_wand("pyutest_magic:ice_wand", "Ice Wand", "pyutest-ice-wand.png",
"pyutest-ice.png",
}
}, {
predicate = function (entity)
local pos = entity.object:get_pos()
local node = core.get_node(pos)
return node.name ~= "air"
end,
action = function (entity)
local pos = entity.object:get_pos()
on_hit_node = function (entity, pos, node)
for e in core.objects_inside_radius(pos, 2) do
if e ~= entity._owner then
PyuTest.deal_damage(e, 6, PyuTest.DAMAGE_TYPES.freezing())
@ -121,15 +70,8 @@ PyuTest.make_wand("pyutest_magic:fire_wand", "Fire Wand", "pyutest-fire-wand.png
"pyutest-lava.png",
}
}, {
predicate = function (entity)
local pos = entity.object:get_pos()
local node = core.get_node(pos)
local walkable = core.registered_nodes[node.name].walkable
return walkable
end,
action = function (entity)
on_hit_node = function (entity, pos, node)
-- TODO: Fix behaviour
PyuTest.dorange(entity.object:get_pos(), 1, function (p)
local node = core.get_node(p)
local walkable = core.registered_nodes[node.name].walkable
@ -155,50 +97,13 @@ PyuTest.make_wand("pyutest_magic:arcane_wand", "Arcane Wand", "pyutest-arcane-wa
"pyutest-crystal-lantern.png",
}
}, {
predicate = function (entity)
local pos = entity.object:get_pos()
local node = core.get_node(pos)
local walkable = core.registered_nodes[node.name].walkable
return walkable
end,
action = function (entity)
on_hit_node = function (entity, pos, node)
PyuTest.lightning_strike(entity.object:get_pos(), 3)
end
})
PyuTest.make_wand("pyutest_magic:water_wand", "Water Wand", "pyutest-water-wand.png", 15, {
textures = {
"pyutest-water.png",
"pyutest-water.png",
"pyutest-water.png",
"pyutest-water.png",
"pyutest-water.png",
"pyutest-water.png",
}
}, {
predicate = function (entity)
local pos = entity.object:get_pos()
local node = core.get_node(pos)
local walkable = core.registered_nodes[node.name].walkable
return walkable
end,
action = function (entity)
PyuTest.dorange(entity.object:get_pos(), 1, function (p)
local node = core.get_node(p)
local walkable = core.registered_nodes[node.name].walkable
if walkable then return end
core.set_node(p, {name = "pyutest_blocks:water_source"})
end)
end
})
PyuTest.make_wand("pyutest_magic:teleportation_wand", "Teleportation Wand", "pyutest-teleportation-wand.png",
40, {
PyuTest.make_wand("pyutest_magic:teleportation_wand", "Teleportation Wand",
"pyutest-teleportation-wand.png", 40, {
textures = {
"pyutest-crystal-lantern.png",
"pyutest-crystal-lantern.png",
@ -208,16 +113,26 @@ PyuTest.make_wand("pyutest_magic:teleportation_wand", "Teleportation Wand", "pyu
"pyutest-crystal-lantern.png",
}
}, {
predicate = function (entity)
local pos = entity.object:get_pos()
local node = core.get_node(pos)
local walkable = core.registered_nodes[node.name].walkable
return walkable
end,
action = function (entity)
entity._owner:set_pos(entity.object:get_pos() + vector.new(0, 1, 0))
on_hit_node = function (entity, pos, node)
entity._owner:set_pos(entity.object:get_pos())
end
})
PyuTest.make_wand("pyutest_magic:explosions_wand", "Explosions Wand",
"pyutest-explosions-wand.png", 33, {
textures = {
"pyutest-tnt-top-bottom.png",
"pyutest-tnt-top-bottom.png",
"pyutest-tnt-side.png",
"pyutest-tnt-side.png",
"pyutest-tnt-side.png",
"pyutest-tnt-side.png",
}
}, {
on_hit_node = function(self, pos, node)
PyuTest.create_explosion(pos, 2, false, 10, {}, 4)
end,
on_hit_object = function(self, object)
PyuTest.create_explosion(object:get_pos(), 2, false, 10, {}, 4)
end
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B