Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lord_bows] Частичное исправление луков #1297

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading