From 304423cf1fb103edce770891e10c82af48df0ece Mon Sep 17 00:00:00 2001 From: Vanic Date: Thu, 25 Apr 2024 21:47:20 +0000 Subject: [PATCH 1/3] Bows fix --- .../lord_bows/entities_projectiles.lua | 46 ++++++++++++++++--- .../lord_bows/mechanics_throwing.lua | 6 ++- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/mods/lord/_experimental/lord_bows/entities_projectiles.lua b/mods/lord/_experimental/lord_bows/entities_projectiles.lua index 281cc0889..c0e1aed92 100644 --- a/mods/lord/_experimental/lord_bows/entities_projectiles.lua +++ b/mods/lord/_experimental/lord_bows/entities_projectiles.lua @@ -20,7 +20,7 @@ end -- Нанесение урона цели local function punch_target(entity, target, damage) - target:punch(entity.object, 1.0, { + target:punch(entity.shooter, 1.0, { full_punch_interval = 1.0, damage_groups = {fleshy = damage}, }) @@ -46,18 +46,32 @@ end -- Обработка столкновения local function collision_handling(entity, moveresult, name, def) - entity.object:set_velocity({x = 0, y = 0, z = 0}) - entity.object:set_acceleration({x = 0, y = 0, z = 0}) - - entity.timer_is_start = true +local vel = entity.object:get_velocity() +entity.object:set_velocity({x = vel.x/15, y = vel.y/15, z = vel.z/15}) if not moveresult.collisions[1] then return end if moveresult.collisions[1].type == "node" then + local node_pos = moveresult.collisions[1].node_pos + local arrow_pos = entity.object:get_pos() + + local dist = sqr( (node_pos.x - arrow_pos.x)^2 + + (node_pos.y - arrow_pos.y)^2 + + (node_pos.z - arrow_pos.z)^2 + ) + + if dist < 0.9 then + entity.object:set_velocity({x = 0, y = 0, z = 0}) + entity.object:set_acceleration({x = 0, y = 0, z = 0}) + entity.timer_is_start = true + end return end + entity.object:set_velocity({x = 0, y = 0, z = 0}) + entity.object:set_acceleration({x = 0, y = 0, z = 0}) + entity.timer_is_start = true local target = moveresult.collisions[1].object @@ -89,8 +103,11 @@ projectiles.register_projectile_arrow_type = function(name, item, def) collisionbox = {-0.15, -0.15, -0.15, 0.15, 0.15, 0.15}, -- Таймер жизни: - life_timer = 20, + life_timer = 10, timer_is_start = false, + + -- Стрелок + shooter, -- Зависящие от def параметры textures = def.textures, @@ -112,5 +129,22 @@ projectiles.register_projectile_arrow_type = function(name, item, def) self.object:remove() minetest.add_item(pos, item) end, + + on_activate = function(self, staticdata, dtime_s) + if staticdata == "timer_is_start" then + self.timer_is_start = true + else + return + end + update_life_timer(self, dtime_s) + end, + + get_staticdata = function(self) + if self.timer_is_start then + return "timer_is_start" + else + return "" + end + end, }) end diff --git a/mods/lord/_experimental/lord_bows/mechanics_throwing.lua b/mods/lord/_experimental/lord_bows/mechanics_throwing.lua index 71017b26f..7fa427cb9 100644 --- a/mods/lord/_experimental/lord_bows/mechanics_throwing.lua +++ b/mods/lord/_experimental/lord_bows/mechanics_throwing.lua @@ -93,7 +93,7 @@ local function player_reset_slowdown(player) end -- Выстрел -local function arrow_shot(player) +local function arrow_shot(player, stack) local inv = player:get_inventory() local look_dir = player:get_look_dir() local player_pos = player:get_pos() @@ -108,6 +108,8 @@ local function arrow_shot(player) z = look_dir.z * value[2] * charge, }) arrow:set_acceleration({x = 0, y = GRAVITY * (-1), z = 0}) + arrow:get_luaentity().shooter = player + stack:add_wear(5000) inv:remove_item("main", key) return end @@ -161,7 +163,7 @@ lord.register_on_release(function(player, control_name) return end - arrow_shot(player) + arrow_shot(player, stack) throwing.charges[player:get_player_name()] = 0 From f1e193dab59dcc1163500b1e2f7d048f808d6720 Mon Sep 17 00:00:00 2001 From: Vanic Date: Thu, 25 Apr 2024 21:58:19 +0000 Subject: [PATCH 2/3] Luacheck fix --- mods/lord/_experimental/lord_bows/entities_projectiles.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mods/lord/_experimental/lord_bows/entities_projectiles.lua b/mods/lord/_experimental/lord_bows/entities_projectiles.lua index c0e1aed92..6685334b4 100644 --- a/mods/lord/_experimental/lord_bows/entities_projectiles.lua +++ b/mods/lord/_experimental/lord_bows/entities_projectiles.lua @@ -105,9 +105,9 @@ projectiles.register_projectile_arrow_type = function(name, item, def) -- Таймер жизни: life_timer = 10, timer_is_start = false, - + -- Стрелок - shooter, + shooter = {}, -- Зависящие от def параметры textures = def.textures, From bc5b612ea976172aa8dc853afc2b1500277a1b7e Mon Sep 17 00:00:00 2001 From: alek13 Date: Sun, 28 Apr 2024 03:07:10 +0300 Subject: [PATCH 3/3] Fix tabs in code; var rename. Relates to #966 #76 --- .../lord_bows/entities_projectiles.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mods/lord/_experimental/lord_bows/entities_projectiles.lua b/mods/lord/_experimental/lord_bows/entities_projectiles.lua index 6685334b4..f31df8bd3 100644 --- a/mods/lord/_experimental/lord_bows/entities_projectiles.lua +++ b/mods/lord/_experimental/lord_bows/entities_projectiles.lua @@ -45,16 +45,16 @@ local function hit_handling(entity, target, name, def) end -- Обработка столкновения -local function collision_handling(entity, moveresult, name, def) -local vel = entity.object:get_velocity() -entity.object:set_velocity({x = vel.x/15, y = vel.y/15, z = vel.z/15}) +local function collision_handling(entity, move_result, name, def) + local vel = entity.object:get_velocity() + entity.object:set_velocity({x = vel.x/15, y = vel.y/15, z = vel.z/15}) - if not moveresult.collisions[1] then + if not move_result.collisions[1] then return end - if moveresult.collisions[1].type == "node" then - local node_pos = moveresult.collisions[1].node_pos + if move_result.collisions[1].type == "node" then + local node_pos = move_result.collisions[1].node_pos local arrow_pos = entity.object:get_pos() local dist = sqr( (node_pos.x - arrow_pos.x)^2 + @@ -73,7 +73,7 @@ entity.object:set_velocity({x = vel.x/15, y = vel.y/15, z = vel.z/15}) entity.object:set_acceleration({x = 0, y = 0, z = 0}) entity.timer_is_start = true - local target = moveresult.collisions[1].object + local target = move_result.collisions[1].object hit_handling(entity, target, name, def) end