diff --git a/mods/lord/_experimental/lord_bows/entities_projectiles.lua b/mods/lord/_experimental/lord_bows/entities_projectiles.lua index 281cc0889..f31df8bd3 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}, }) @@ -45,21 +45,35 @@ local function hit_handling(entity, target, name, def) 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 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 + 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 + + (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 + local target = move_result.collisions[1].object hit_handling(entity, target, name, def) end @@ -89,9 +103,12 @@ 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