code improvements

This commit is contained in:
Juraj Vajda 2022-10-05 20:54:07 -04:00
parent 50eab4ef13
commit 4529b2edf8
6 changed files with 79 additions and 14 deletions

15
.luacheckrc Normal file
View File

@ -0,0 +1,15 @@
globals = {
'x_bows'
}
read_globals = {
'minetest',
'default',
'vector',
'table',
'ItemStack',
'armor',
'playerphysics',
'hb',
'mesecon'
}

View File

@ -40,7 +40,17 @@ function x_bows.poison_effect(tick, time, time_left, arrow_obj, target_obj, old_
time_left = time_left + tick
if time_left <= time then
minetest.after(tick, x_bows.poison_effect, tick, time, time_left, arrow_obj, target_obj, old_damage_texture_modifier, punch_def)
minetest.after(
tick,
x_bows.poison_effect,
tick,
time,
time_left,
arrow_obj,
target_obj,
old_damage_texture_modifier,
punch_def
)
elseif target_obj:is_player() then
if x_bows.hbhunger then
-- Reset HUD bar color
@ -135,7 +145,7 @@ minetest.register_entity('x_bows:arrow_entity', {
})
end,
on_death = function(self, killer)
on_death = function(self, killer) --luacheck:ignore
if not self._old_pos then
self.object:remove()
return
@ -221,7 +231,14 @@ minetest.register_entity('x_bows:arrow_entity', {
if pointed_thing.type == 'object'
and pointed_thing.ref ~= self.object
and pointed_thing.ref:get_hp() > 0
and ((pointed_thing.ref:is_player() and pointed_thing.ref:get_player_name() ~= self.user:get_player_name()) or (pointed_thing.ref:get_luaentity() and pointed_thing.ref:get_luaentity().physical and pointed_thing.ref:get_luaentity().name ~= '__builtin:item'))
and (
(pointed_thing.ref:is_player() and pointed_thing.ref:get_player_name() ~= self.user:get_player_name())
or (
pointed_thing.ref:get_luaentity()
and pointed_thing.ref:get_luaentity().physical
and pointed_thing.ref:get_luaentity().name ~= '__builtin:item'
)
)
and self.object:get_attach() == nil
then
if pointed_thing.ref:is_player() then
@ -402,12 +419,20 @@ minetest.register_entity('x_bows:arrow_entity', {
-- @TODO missing `active` posion arrow check for player (see lua_ent below)
if x_bows.hbhunger then
-- Set poison bar
hb.change_hudbar(pointed_thing.ref, 'health', nil, nil, 'hbhunger_icon_health_poison.png', nil, 'hbhunger_bar_health_poison.png')
hb.change_hudbar(
pointed_thing.ref,
'health',
nil,
nil,
'hbhunger_icon_health_poison.png',
nil,
'hbhunger_bar_health_poison.png'
)
end
x_bows.poison_effect(1, 5, 0, self, pointed_thing.ref, old_damage_texture_modifier, punch_def)
else
local lua_ent = pointed_thing.ref:get_luaentity()
-- local lua_ent = pointed_thing.ref:get_luaentity()
-- if not lua_ent[self.arrow .. '_active'] or lua_ent[self.arrow .. '_active'] == 'false' then
-- lua_ent[self.arrow .. '_active'] = true
x_bows.poison_effect(1, 5, 0, self, pointed_thing.ref, old_damage_texture_modifier, punch_def)
@ -493,7 +518,7 @@ minetest.register_entity('x_bows:arrow_entity', {
-- remove last arrow when too many already attached
local children = {}
for k, object in ipairs(minetest.get_objects_inside_radius(pointed_thing.under, 1)) do
for _, object in ipairs(minetest.get_objects_inside_radius(pointed_thing.under, 1)) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == 'x_bows:arrow_entity' then
table.insert(children ,object)
end

13
bitbucket-pipelines.yml Normal file
View File

@ -0,0 +1,13 @@
image: python:3.8
pipelines:
pull-requests:
"**":
- step:
name: Lint code
caches:
- pip
script:
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- sudo apt install lua5.1
- luacheck .

View File

@ -32,7 +32,8 @@ function x_bows.register_bow(name, def)
-- not charged bow
minetest.register_tool(def.name, {
description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: ' .. (1 / def.crit_chance) * 100 .. '%'),
description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: '
.. (1 / def.crit_chance) * 100 .. '%'),
inventory_image = def.inventory_image or 'x_bows_bow_wood.png',
-- on_use = function(itemstack, user, pointed_thing)
-- end,
@ -44,7 +45,8 @@ function x_bows.register_bow(name, def)
-- charged bow
minetest.register_tool(def.name_charged, {
description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: ' .. (1 / def.crit_chance) * 100 .. '%'),
description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Critical Arrow Chance: '
.. (1 / def.crit_chance) * 100 .. '%'),
inventory_image = def.inventory_image_charged or 'x_bows_bow_wood_charged.png',
on_use = x_bows.shoot,
groups = {bow = 1, flammable = 1, not_in_creative_inventory = 1},
@ -70,7 +72,9 @@ function x_bows.register_arrow(name, def)
x_bows.registered_arrows[def.name] = def
minetest.register_craftitem('x_bows:' .. name, {
description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Damage: ' .. def.tool_capabilities.damage_groups.fleshy) .. '\n' .. minetest.colorize('#00BFFF', 'Charge Time: ' .. def.tool_capabilities.full_punch_interval .. 's'),
description = def.description .. '\n' .. minetest.colorize('#00FF00', 'Damage: '
.. def.tool_capabilities.damage_groups.fleshy) .. '\n' .. minetest.colorize('#00BFFF', 'Charge Time: '
.. def.tool_capabilities.full_punch_interval .. 's'),
inventory_image = def.inventory_image,
groups = {arrow = 1, flammable = 1}
})
@ -101,7 +105,7 @@ function x_bows.load(itemstack, user, pointed_thing)
end
end
for k, st in ipairs(inv_list) do
for _, st in ipairs(inv_list) do
if not st:is_empty() and x_bows.registered_arrows[st:get_name()] then
table.insert(itemstack_arrows, st)
end
@ -154,7 +158,7 @@ function x_bows.load(itemstack, user, pointed_thing)
end
end
function x_bows.shoot(itemstack, user, pointed_thing)
function x_bows.shoot(itemstack, user, pointed_thing) --luacheck:ignore
local time_shoot = minetest.get_us_time();
local meta = itemstack:get_meta()
local meta_arrow = meta:get_string('arrow')
@ -196,13 +200,20 @@ function x_bows.shoot(itemstack, user, pointed_thing)
local pos = user:get_pos()
local dir = user:get_look_dir()
local obj = minetest.add_entity({x = pos.x, y = pos.y + 1.5, z = pos.z}, 'x_bows:arrow_entity', minetest.serialize(staticdata))
local obj = minetest.add_entity(
{
x = pos.x,
y = pos.y + 1.5,
z = pos.z
},
'x_bows:arrow_entity',
minetest.serialize(staticdata)
)
if not obj then
return itemstack
end
local lua_ent = obj:get_luaentity()
local strength_multiplier = tflp
if strength_multiplier > _tool_capabilities.full_punch_interval then

View File

@ -32,7 +32,7 @@ minetest.register_node('x_bows:target', {
groups = {snappy=3, flammable=4, fall_damage_add_percent=-30},
sounds = default.node_sound_leaves_defaults(),
mesecons = {receptor = {state = 'off'}},
on_timer = function (pos, elapsed)
on_timer = function (pos, elapsed) --luacheck:ignore
mesecon.receptor_off(pos)
return false
end,

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
luarocks