2020-03-14 21:51:24 +00:00
|
|
|
local function recursive_multiply(source, multiplier)
|
|
|
|
for key, value in pairs(multiplier) do
|
|
|
|
assert(type(source[key]) == type(value))
|
|
|
|
if type(value) == "table" then
|
|
|
|
recursive_multiply(source[key], value)
|
|
|
|
else
|
|
|
|
source[key] = source[key] * value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-03-22 04:01:36 +00:00
|
|
|
|
2020-03-13 23:26:53 +00:00
|
|
|
local function get_shooter_specs(weapon_name, multiplier)
|
|
|
|
local spec = shooter.registered_weapons[weapon_name]
|
2019-03-22 04:01:36 +00:00
|
|
|
if not spec then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2020-03-14 21:51:24 +00:00
|
|
|
spec = table.copy(spec.spec)
|
2019-03-22 04:01:36 +00:00
|
|
|
|
2020-03-14 21:51:24 +00:00
|
|
|
if multiplier then
|
|
|
|
recursive_multiply(spec, multiplier)
|
2020-03-14 17:22:55 +00:00
|
|
|
end
|
|
|
|
|
2019-03-22 04:01:36 +00:00
|
|
|
return spec
|
|
|
|
end
|
|
|
|
|
2020-03-14 21:51:24 +00:00
|
|
|
shooter.get_weapon_spec = function(user, weapon_name)
|
2020-03-13 23:26:53 +00:00
|
|
|
local class = ctf_classes.get(user)
|
|
|
|
|
|
|
|
if table.indexof(class.properties.allowed_guns or {}, weapon_name) == -1 then
|
|
|
|
minetest.chat_send_player(user:get_player_name(),
|
2021-02-17 22:01:25 +00:00
|
|
|
"Your class can't use that weapon! Change your class at base")
|
2020-03-13 23:26:53 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local spec = get_shooter_specs(weapon_name, class.properties.shooter_multipliers)
|
2020-03-14 21:51:24 +00:00
|
|
|
if not spec then
|
|
|
|
return nil
|
|
|
|
end
|
2020-03-13 23:26:53 +00:00
|
|
|
|
|
|
|
return spec
|
|
|
|
end
|
|
|
|
|
2019-03-22 04:01:36 +00:00
|
|
|
|
|
|
|
local function check_grapple(itemname)
|
|
|
|
local def = minetest.registered_items[itemname]
|
|
|
|
local old_func = def.on_use
|
|
|
|
minetest.override_item(itemname, {
|
|
|
|
on_use = function(itemstack, user, ...)
|
2020-03-14 19:37:31 +00:00
|
|
|
if not ctf_classes.get(user).properties.allow_grapples then
|
2019-03-22 04:01:36 +00:00
|
|
|
minetest.chat_send_player(user:get_player_name(),
|
2021-02-25 14:27:49 +00:00
|
|
|
"Your class can't use that weapon! Change your class at base")
|
2019-03-22 04:01:36 +00:00
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2020-03-13 21:58:42 +00:00
|
|
|
if ctf_flag.has_flag(user:get_player_name()) then
|
|
|
|
minetest.chat_send_player(user:get_player_name(),
|
|
|
|
"You can't use grapples whilst carrying the flag")
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2019-03-22 04:01:36 +00:00
|
|
|
return old_func(itemstack, user, ...)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2021-04-29 20:17:13 +00:00
|
|
|
local function check_rocket(itemname)
|
|
|
|
local def = minetest.registered_items[itemname]
|
|
|
|
local old_func = def.on_use
|
|
|
|
minetest.override_item(itemname, {
|
|
|
|
on_use = function(itemstack, user, ...)
|
|
|
|
if not ctf_classes.get(user).properties.allow_rockets then
|
|
|
|
minetest.chat_send_player(user:get_player_name(),
|
2021-04-30 17:08:03 +00:00
|
|
|
"You can't use that weapon! Change your class at base.")
|
2021-04-29 20:17:13 +00:00
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
return old_func(itemstack, user, ...)
|
|
|
|
end,
|
|
|
|
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2020-03-14 21:51:24 +00:00
|
|
|
check_grapple("shooter_hook:grapple_gun_loaded")
|
|
|
|
check_grapple("shooter_hook:grapple_gun")
|
|
|
|
check_grapple("shooter_hook:grapple_hook")
|
2020-05-19 07:20:22 +00:00
|
|
|
|
2021-04-29 20:17:13 +00:00
|
|
|
check_rocket("shooter_rocket:rocket_gun_loaded")
|
|
|
|
check_rocket("shooter_rocket:rocket_gun")
|
|
|
|
|
2020-05-19 07:20:22 +00:00
|
|
|
-- Override grappling hook entity to check if player has flag before teleporting
|
|
|
|
local old_grapple_step = minetest.registered_entities["shooter_hook:hook"].on_step
|
|
|
|
minetest.registered_entities["shooter_hook:hook"].on_step = function(self, dtime, ...)
|
2021-03-15 15:30:54 +00:00
|
|
|
-- User left the game. Life is no longer worth living for this poor hook
|
2021-03-19 15:31:52 +00:00
|
|
|
if not self.user or not minetest.get_player_by_name(self.user) then
|
2021-03-15 15:30:54 +00:00
|
|
|
self.object:remove()
|
2021-03-16 23:41:34 +00:00
|
|
|
return
|
2021-03-15 15:30:54 +00:00
|
|
|
end
|
|
|
|
|
2020-05-19 07:20:22 +00:00
|
|
|
-- Remove entity if player has flag
|
|
|
|
-- This is to prevent players from firing the hook, and then punching the flag
|
|
|
|
if ctf_flag.has_flag(self.user) then
|
|
|
|
local player = minetest.get_player_by_name(self.user)
|
|
|
|
if player then
|
|
|
|
player:get_inventory():add_item("main", "shooter_hook:grapple_hook")
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(self.user,
|
|
|
|
"You can't use grapples whilst carrying the flag")
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
2021-01-08 01:35:34 +00:00
|
|
|
|
|
|
|
-- Remove hook if player changes class after throwing it
|
|
|
|
if not ctf_classes.get(self.user).properties.allow_grapples then
|
|
|
|
minetest.chat_send_player(self.user,
|
|
|
|
"Grapples don't work if you change class!")
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-05-19 07:20:22 +00:00
|
|
|
return old_grapple_step(self, dtime, ...)
|
|
|
|
end
|