2022-10-12 20:13:06 -05:00
|
|
|
-- X Bows
|
|
|
|
-- by SaKeL
|
|
|
|
|
2022-10-09 21:24:36 -05:00
|
|
|
minetest = minetest--[[@as Minetest]]
|
|
|
|
ItemStack = ItemStack--[[@as ItemStack]]
|
|
|
|
vector = vector--[[@as Vector]]
|
|
|
|
default = default--[[@as MtgDefault]]
|
2022-10-25 20:19:31 -05:00
|
|
|
sfinv = sfinv--[[@as Sfinv]]
|
2022-10-09 21:24:36 -05:00
|
|
|
|
2022-10-16 15:02:04 -05:00
|
|
|
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 9))--[[@as number]])
|
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
local path = minetest.get_modpath('x_bows')
|
2021-03-13 20:39:42 -06:00
|
|
|
local mod_start_time = minetest.get_us_time()
|
|
|
|
local bow_charged_timer = 0
|
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
dofile(path .. '/api.lua')
|
|
|
|
dofile(path .. '/particle_effects.lua')
|
|
|
|
dofile(path .. '/nodes.lua')
|
|
|
|
dofile(path .. '/arrow.lua')
|
|
|
|
dofile(path .. '/items.lua')
|
|
|
|
dofile(path .. '/quiver.lua')
|
2022-10-08 18:47:11 -05:00
|
|
|
|
2022-10-26 08:45:59 -05:00
|
|
|
|
|
|
|
if minetest.get_modpath('i3') then
|
|
|
|
XBowsQuiver:i3_register_page()
|
|
|
|
elseif minetest.get_modpath('unified_inventory') then
|
|
|
|
XBowsQuiver:ui_register_page()
|
|
|
|
else
|
|
|
|
XBowsQuiver:sfinv_register_page()
|
|
|
|
end
|
2022-10-25 20:19:31 -05:00
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local inv_quiver = player:get_inventory()--[[@as InvRef]]
|
|
|
|
local inv_arrow = player:get_inventory()--[[@as InvRef]]
|
|
|
|
|
|
|
|
inv_quiver:set_size('x_bows:quiver_inv', 1 * 1)
|
|
|
|
inv_arrow:set_size('x_bows:arrow_inv', 1 * 1)
|
2022-10-26 08:45:59 -05:00
|
|
|
|
|
|
|
local quiver = player:get_inventory():get_stack('x_bows:quiver_inv', 1)
|
|
|
|
|
|
|
|
if quiver and not quiver:is_empty() then
|
|
|
|
local st_meta = quiver:get_meta()
|
|
|
|
local quiver_id = st_meta:get_string('quiver_id')
|
|
|
|
|
|
|
|
XBowsQuiver:get_or_create_detached_inv(
|
|
|
|
quiver_id,
|
|
|
|
player:get_player_name(),
|
|
|
|
st_meta:get_string('quiver_items')
|
|
|
|
)
|
|
|
|
end
|
2022-10-25 20:19:31 -05:00
|
|
|
end)
|
|
|
|
|
2022-10-21 12:37:35 -05:00
|
|
|
---backwards compatibility
|
|
|
|
minetest.register_alias('x_bows:arrow_diamond_tipped_poison', 'x_bows:arrow_diamond')
|
|
|
|
|
2022-10-08 18:47:11 -05:00
|
|
|
minetest.register_on_joinplayer(function(player)
|
2022-10-20 08:13:35 -05:00
|
|
|
XBows:reset_charged_bow(player, true)
|
|
|
|
XBowsQuiver:close_quiver(player)
|
2022-10-08 18:47:11 -05:00
|
|
|
end)
|
|
|
|
|
2021-03-13 20:39:42 -06:00
|
|
|
-- sneak, fov adjustments when bow is charged
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2022-10-16 15:02:04 -05:00
|
|
|
bow_charged_timer = bow_charged_timer + dtime
|
|
|
|
|
|
|
|
if bow_charged_timer > 0.5 then
|
|
|
|
for _, player in ipairs(minetest.get_connected_players()) do
|
2022-10-20 08:13:35 -05:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
local wielded_stack = player:get_wielded_item()
|
|
|
|
local wielded_stack_name = wielded_stack:get_name()
|
2022-10-16 15:02:04 -05:00
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
if not wielded_stack_name then
|
2022-10-16 15:02:04 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
if not XBows.player_bow_sneak[player_name] then
|
|
|
|
XBows.player_bow_sneak[player_name] = {}
|
2022-10-16 15:02:04 -05:00
|
|
|
end
|
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
if minetest.get_item_group(wielded_stack_name, 'bow_charged') ~= 0 and not XBows.player_bow_sneak[player_name].sneak then
|
2022-10-24 15:31:23 -05:00
|
|
|
--charged weapon
|
2022-10-20 08:13:35 -05:00
|
|
|
if XBows.playerphysics then
|
|
|
|
playerphysics.add_physics_factor(player, 'speed', 'x_bows:bow_charged_speed', 0.25)
|
|
|
|
elseif XBows.player_monoids then
|
|
|
|
player_monoids.speed:add_change(player, 0.25, 'x_bows:bow_charged_speed')
|
2022-10-16 15:02:04 -05:00
|
|
|
end
|
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
XBows.player_bow_sneak[player_name].sneak = true
|
2022-10-16 15:02:04 -05:00
|
|
|
player:set_fov(0.9, true, 0.4)
|
2022-10-20 08:13:35 -05:00
|
|
|
elseif minetest.get_item_group(wielded_stack_name, 'bow_charged') == 0 and XBows.player_bow_sneak[player_name].sneak then
|
|
|
|
if XBows.playerphysics then
|
|
|
|
playerphysics.remove_physics_factor(player, 'speed', 'x_bows:bow_charged_speed')
|
|
|
|
elseif XBows.player_monoids then
|
|
|
|
player_monoids.speed:del_change(player, 'x_bows:bow_charged_speed')
|
2022-10-16 15:02:04 -05:00
|
|
|
end
|
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
XBows.player_bow_sneak[player_name].sneak = false
|
2022-10-16 15:02:04 -05:00
|
|
|
player:set_fov(0, true, 0.4)
|
|
|
|
end
|
|
|
|
|
2022-10-20 08:13:35 -05:00
|
|
|
XBows:reset_charged_bow(player)
|
2022-10-16 15:02:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
bow_charged_timer = 0
|
|
|
|
end
|
2021-03-13 20:39:42 -06:00
|
|
|
end)
|
2021-03-01 12:44:27 -06:00
|
|
|
|
2021-03-13 20:39:42 -06:00
|
|
|
local mod_end_time = (minetest.get_us_time() - mod_start_time) / 1000000
|
2021-03-01 12:44:27 -06:00
|
|
|
|
2021-03-13 20:39:42 -06:00
|
|
|
print('[Mod] x_bows loaded.. ['.. mod_end_time ..'s]')
|