Skip to content

Commit

Permalink
[lord_bows] Частичное исправление луков (#1297) Relates to #966 #76
Browse files Browse the repository at this point in the history
Partial fixes of #966, see #76
* Лук изнашивается при выстреле (bow wearing)
* При попадании по мобу, моб агрится на игрока (who shoot the arrow; mobs attacks)
* Исправления рикошета. Fix arrows in sky. Пояснение: из-за несовершенности физического движка МТ, стрела на высокой скорости может отрикошетить от блока и зависнусть в воздухе, посчитав, что она в этот самый блок "попала". Исправление заключается в том, что если стрела на момент рассчета оказалась слишком далеко от блока, с которым столкнулась, она теряет свою скорость в 15 раз, а не просто зависает в воздухе.
* Стрелы теперь удаляются, даже если были выгружены и загружены обратно (как сущность). You can break arrows in world. Примечание: те стрелы, что висят на полигоне НЕ ИСЧЕЗНУТ

---------

Co-authored-by: alek13 <[email protected]>
  • Loading branch information
2 people authored and Doloment committed May 4, 2024
1 parent 5bdd2f2 commit 05a92f4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
54 changes: 44 additions & 10 deletions mods/lord/_experimental/lord_bows/entities_projectiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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},
})
Expand All @@ -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
Expand Down Expand Up @@ -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,

Expand All @@ -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
6 changes: 4 additions & 2 deletions mods/lord/_experimental/lord_bows/mechanics_throwing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 05a92f4

Please sign in to comment.