obsidianmese/tools.lua

235 lines
6.8 KiB
Lua
Raw Normal View History

--
-- Tools
--
-- sword
minetest.register_tool("obsidianmese:sword", {
description = "Obsidian Mese Sword",
inventory_image = "obsidianmese_sword.png",
wield_scale = {x=1.5, y=2, z=1},
tool_capabilities = {
full_punch_interval = 0.45,
max_drop_level=1,
groupcaps={
fleshy={times={[1]=2.00, [2]=0.65, [3]=0.25}, uses=400, maxlevel=3},
snappy={times={[1]=1.90, [2]=0.70, [3]=0.25}, uses=350, maxlevel=3},
choppy={times={[3]=0.65}, uses=300, maxlevel=0}
},
damage_groups = {fleshy=8},
sound = {breaks = "default_tool_breaks"},
}
})
-- boss sword - balrog
-- minetest.register_tool("obsidianmese:sword_balrog_boss", {
-- description = "Balrog Boss Sword",
-- inventory_image = "obsidianmese_sword_balrog_boss.png",
-- wield_scale = {x=2.0, y=2.5, z=1.5},
-- tool_capabilities = {
-- full_punch_interval = 3,
-- max_drop_level=1,
-- groupcaps={
-- snappy={times={[1]=3.80, [2]=1.80, [3]=0.60}, uses=20, maxlevel=3},
-- },
-- -- wield_scale = {x=2.5, y=3, z=2},
-- damage_groups = {fleshy=200},
-- sound = {breaks = "default_tool_breaks"},
-- }
-- })
-- sword engraved - bullet entity
minetest.register_entity("obsidianmese:sword_bullet", {
physical = false,
visual = "sprite",
visual_size = { x = 1, y = 1 },
textures = { "obsidianmese_shard.png" },
collisionbox = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
_lifetime = 9, -- seconds before removing
_timer = 0, -- initial value
_owner = "unknown", -- initial value
_trigger_sd = 0,
on_activate = function(self, staticdata, dtime_s)
local table = minetest.deserialize(staticdata)
-- check - initial values are empty
if table then
self._owner = table._owner
self._timer = table._timer
end
self.object:set_armor_groups({ immortal = 1 })
end,
-- should return a string that will be passed to `on_activate` when the object is instantiated the next time
get_staticdata = function(self)
self._trigger_sd = self._trigger_sd + 1
-- staticdata are triggered before object appears and before it hides from the World, so remove it before it hides
if self._trigger_sd % 2 == 0 then
self.object:remove()
obsidianmese.sync_fired_table(self._owner)
end
-- insurance - makes sure staticdata are updated when objects activates again (because somehow wasn't removed yet)
local table = {
_owner = self._owner,
_timer = self._timer
}
return minetest.serialize(table)
end,
-- when the entity gets punched
on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
local full_punch_interval = tool_capabilities.full_punch_interval or 1
-- only on full punch
if time_from_last_punch < full_punch_interval then return end
local v = math.random(1, 8)
local velocity = dir
velocity.x = velocity.x * v
velocity.y = velocity.y * v
velocity.z = velocity.z * v
self.object:setvelocity(velocity)
end,
on_step = function(self, dtime)
local pos = self.object:getpos()
local node = minetest.get_node_or_nil(pos)
-- print("self._owner: ", self._owner)
-- print("self._timer: ", self._timer)
self._timer = self._timer + dtime
if self._timer > self._lifetime or
not obsidianmese.within_limits(pos, 0) then
self.object:remove()
obsidianmese.sync_fired_table(self._owner)
return
end
-- hit node
if node
and minetest.registered_nodes[node.name]
and minetest.registered_nodes[node.name].walkable then
self.object:remove()
obsidianmese.sync_fired_table(self._owner)
return
end
-- hit player or mob
for k, obj in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
-- punch player
if obj:is_player() then
obj:punch(self.object, 1.0, {
full_punch_interval = full_punch_interval,
damage_groups = {fleshy = 8},
}, nil)
self.object:remove()
obsidianmese.sync_fired_table(self._owner)
-- jail time
if minetest.global_exists("city_block") then
city_block.register_on_punchplayer(
obj, -- player
minetest.get_player_by_name(self._owner), --hitter
1.0, -- time_from_last_punch
{
full_punch_interval = full_punch_interval,
damage_groups = {fleshy = 8},
}, -- tool_capabilities
nil, -- dir
8 -- damage i.e. {fleshy = 8}
)
end
break
-- punch entity
elseif not obj:is_player() and
obj:get_luaentity() and
obj:get_luaentity().name ~= "__builtin:item" then
local entity = obj:get_luaentity()
if entity.name ~= self.object:get_luaentity().name then
obj:punch(self.object, 1.0, {
full_punch_interval = full_punch_interval,
damage_groups = {fleshy = 8},
}, nil)
self.object:remove()
obsidianmese.sync_fired_table(self._owner)
break
end
end
end
end
})
-- sword engraved
minetest.register_tool("obsidianmese:sword_engraved", {
description = "Obsidian Mese Sword Engraved - right click shoot 1 shot",
inventory_image = "obsidianmese_sword_diamond_engraved.png",
wield_scale = {x=1.5, y=2, z=1},
tool_capabilities = {
full_punch_interval = 0.6,
max_drop_level=1,
groupcaps={
snappy={times={[1]=1.90, [2]=0.90, [3]=0.30}, uses=300, maxlevel=3},
},
damage_groups = {fleshy=8},
sound = {breaks = "default_tool_breaks"},
},
on_secondary_use = obsidianmese.fire_sword
})
-- pick axe
minetest.register_tool("obsidianmese:pick", {
description = "Obsidian Mese Pickaxe",
inventory_image = "obsidianmese_pick.png",
tool_capabilities = {
full_punch_interval = 0.9,
max_drop_level=3,
groupcaps={
cracky={times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=250, maxlevel=3},
crumbly={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=350, maxlevel=3},
snappy={times={[1]=2.0, [2]=1.0, [3]=0.5}, uses=300, maxlevel=3}
},
damage_groups = {fleshy=5},
sound = {breaks = "default_tool_breaks"},
},
})
-- pick axe engraved
minetest.register_tool("obsidianmese:pick_engraved", {
description = "Obsidian Mese Pickaxe Engraved - right click to place item next to the pickaxe in your inventory slot",
inventory_image = "obsidianmese_pick_engraved.png",
tool_capabilities = {
full_punch_interval = 0.9,
max_drop_level=3,
groupcaps={
cracky={times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=200, maxlevel=3}
},
damage_groups = {fleshy=5},
sound = {breaks = "default_tool_breaks"},
},
on_place = obsidianmese.pick_engraved_place
})
-- shovel
minetest.register_tool("obsidianmese:shovel", {
description = "ObsidianMese Shovel - right click (secondary click) for creating a path",
inventory_image = "obsidianmese_shovel.png",
wield_image = "obsidianmese_shovel.png^[transformR90",
wield_scale = {x=1.5, y=1.5, z=1.5},
tool_capabilities = {
full_punch_interval = 0.9,
max_drop_level=1,
groupcaps={
crumbly = {times={[1]=1.10, [2]=0.50, [3]=0.30}, uses=50, maxlevel=3},
},
damage_groups = {fleshy=4},
},
sound = {breaks = "default_tool_breaks"},
on_place = obsidianmese.shovel_place
})