diff --git a/mods/ctf/ctf_classes/classes.lua b/mods/ctf/ctf_classes/classes.lua index 76698b3..718b04e 100644 --- a/mods/ctf/ctf_classes/classes.lua +++ b/mods/ctf/ctf_classes/classes.lua @@ -45,6 +45,8 @@ ctf_classes.register("shooter", { "shooter_guns:rifle", "shooter_guns:machine_gun", "shooter_guns:shotgun", + "sniper_rifles:rifle_762", + "sniper_rifles:rifle_magnum" }, shooter_multipliers = { diff --git a/mods/ctf/ctf_crafting/init.lua b/mods/ctf/ctf_crafting/init.lua index d4ef1de..a509841 100644 --- a/mods/ctf/ctf_crafting/init.lua +++ b/mods/ctf/ctf_crafting/init.lua @@ -150,6 +150,24 @@ crafting.register_recipe({ level = 1, }) +-- 7.62mm sniper rifle (unloaded) +crafting.register_recipe({ + type = "inv", + output = "sniper_rifles:rifle_762", + items = { "default:steelblock", "default:bronze_ingot 5", "default:mese_crystal", "default:wood" }, + always_known = true, + level = 1 +}) + +-- Magnum sniper rifle (unloaded) +crafting.register_recipe({ + type = "inv", + output = "sniper_rifles:rifle_magnum", + items = { "default:steelblock", "default:bronzeblock", "default:diamond", "default:wood" }, + always_known = true, + level = 1, +}) + -- Wooden ladder x4 crafting.register_recipe({ type = "inv", diff --git a/mods/ctf/ctf_treasure/init.lua b/mods/ctf/ctf_treasure/init.lua index 0a4542b..4041f2d 100644 --- a/mods/ctf/ctf_treasure/init.lua +++ b/mods/ctf/ctf_treasure/init.lua @@ -24,6 +24,9 @@ function ctf_treasure.get_default_treasures() { "shooter:ammo", 0.3, 2, { 1, 10 } }, { "shooter:arrow_white", 0.5, 2, { 2, 18 } }, + { "sniper_rifles:rifle_762_loaded", 0.1, 2, 1 }, + { "sniper_rifles:rifle_magnum_loaded", 0.01, 2, 1 }, + { "medkits:medkit", 0.8, 5, 2 }, } end diff --git a/mods/other/random_messages/init.lua b/mods/other/random_messages/init.lua index 3c62b70..52f25f4 100644 --- a/mods/other/random_messages/init.lua +++ b/mods/other/random_messages/init.lua @@ -77,6 +77,7 @@ function random_messages.read_messages() "Change your class in your base by right clicking the home flag or typing /class.", "Medics cause troops within 10 metres to regenerate health faster.", "Hitting your enemy does more damage than not hitting them.", + "Press right mouse button or double-tap the screen to activate scope while wielding a sniper rifle." } end diff --git a/mods/pvp/sniper_rifles/LICENSE b/mods/pvp/sniper_rifles/LICENSE new file mode 100644 index 0000000..d26fb25 --- /dev/null +++ b/mods/pvp/sniper_rifles/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Code : Copyright (c) 2019 Anand S, ClobberXD +Textures: Copyright (c) 2020 LoneWolfHT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/mods/pvp/sniper_rifles/README.md b/mods/pvp/sniper_rifles/README.md new file mode 100644 index 0000000..8eb56b2 --- /dev/null +++ b/mods/pvp/sniper_rifles/README.md @@ -0,0 +1,13 @@ +# Sniper Rifles + +This mod adds sniper rifles which behave like over-powered rifles, with the addition of the ability to toggle scoping using RMB (by default). + +## Licenses + +- Code license: MIT +- Media license: CC0 1.0 + +### Attributions + +- `sniper_rifles_rifle.ogg` (`CC0 1.0`) + - Converted from [Battle Rifle.wav](https://freesound.org/people/morganpurkis/sounds/391725/) by [morganpurkis](https://freesound.org/people/morganpurkishttps://freesound.org/people/morganpurkis/sounds/391725/). diff --git a/mods/pvp/sniper_rifles/init.lua b/mods/pvp/sniper_rifles/init.lua new file mode 100644 index 0000000..03db7ca --- /dev/null +++ b/mods/pvp/sniper_rifles/init.lua @@ -0,0 +1,104 @@ +------------------ +-- Private data -- +------------------ + +-- Keep track of players who are scoping in, and their wielded item +local scoped = {} + +-- Timer for scope-check globalstep +local timer = 0.2 + +------------- +-- Helpers -- +------------- + +local function show_scope(name, item_name, fov_mult) + local player = minetest.get_player_by_name(name) + if not player then + return + end + + scoped[name] = item_name + -- e.g. if fov_mult == 8, then FOV = 1/8 * current_FOV, a.k.a 8x zoom + player:set_fov(1 / fov_mult, true) + player:hud_set_flags({ wielditem = false }) +end + +local function hide_scope(name) + local player = minetest.get_player_by_name(name) + if not player then + return + end + + scoped[name] = nil + player:set_fov(0) + player:hud_set_flags({ wielditem = true }) +end + +local function on_rclick(item, placer, pointed_thing) + if pointed_thing.type == "object" then + return + end + + local name = placer:get_player_name() + if scoped[name] then + hide_scope(name) + else + -- Remove _loaded suffix added to item name by shooter + local item_name = item:get_name():gsub("_loaded", "") + local fov_mult = shooter.registered_weapons[item_name].fov_mult + show_scope(name, item_name, fov_mult) + end +end + +------------------ +-- Sccope-check -- +------------------ + +-- Hide scope if currently wielded item is not the same item +-- player wielded when scoping + +local time = 0 +minetest.register_globalstep(function(dtime) + time = time + dtime + if time < timer then + return + end + + time = 0 + for name, original_item in pairs(scoped) do + local player = minetest.get_player_by_name(name) + if not player then + scoped[name] = nil + else + local wielded_item = player:get_wielded_item():get_name():gsub("_loaded", "") + if wielded_item ~= original_item then + hide_scope(name) + end + end + end +end) + +---------------------------- +-- Rifle registration API -- +---------------------------- + +sniper_rifles = {} + +function sniper_rifles.register_rifle(name, def) + assert(def.fov_mult, "Rifle definition must contain FOV multiplier (fov_mult)!") + + shooter.register_weapon(name, def) + + -- Manually add extra fields to itemdef that shooter doesn't allow + -- Also modify the _loaded variant + local overrides = { + on_secondary_use = on_rclick, + wield_scale = vector.new(2, 2, 1.5) + } + minetest.override_item(name, overrides) + minetest.override_item(name .. "_loaded", overrides) + +end + +dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/rifles.lua") diff --git a/mods/pvp/sniper_rifles/mod.conf b/mods/pvp/sniper_rifles/mod.conf new file mode 100644 index 0000000..fb2ce85 --- /dev/null +++ b/mods/pvp/sniper_rifles/mod.conf @@ -0,0 +1,3 @@ +name = sniper_rifles +depends = shooter +description = This mod adds a couple of sniper rifles that make use of the zoom_fov player property to scope in. diff --git a/mods/pvp/sniper_rifles/rifles.lua b/mods/pvp/sniper_rifles/rifles.lua new file mode 100644 index 0000000..0b2c4ad --- /dev/null +++ b/mods/pvp/sniper_rifles/rifles.lua @@ -0,0 +1,37 @@ +-- Basic 7.62mm rifle +sniper_rifles.register_rifle("sniper_rifles:rifle_762", { + description = "Sniper rifle (7.62mm)", + inventory_image = "sniper_rifles_rifle_762.png", + fov_mult = 4, + spec = { + rounds = 30, + range = 300, + step = 30, + tool_caps = { full_punch_interval = 1.5, damage_groups = { fleshy = 12 } }, + sounds = { shot = "sniper_rifles_rifle" }, + particle = "shooter_bullet.png", + groups = { + cracky = 3, snappy = 2, crumbly = 2, choppy = 2, + fleshy = 1, oddly_breakable_by_hand = 1 + } + } +}) + +-- Magnum rifle +sniper_rifles.register_rifle("sniper_rifles:rifle_magnum", { + description = "Sniper rifle (Magnum)", + inventory_image = "sniper_rifles_rifle_magnum.png", + fov_mult = 8, + spec = { + rounds = 20, + range = 400, + step = 30, + tool_caps = { full_punch_interval = 2, damage_groups = { fleshy = 16 } }, + sounds = { shot = "sniper_rifles_rifle" }, + particle = "shooter_bullet.png", + groups = { + cracky = 2, snappy = 1, crumbly = 1, choppy = 1, + fleshy = 1, oddly_breakable_by_hand = 1 + } + } +}) diff --git a/mods/pvp/sniper_rifles/sounds/sniper_rifles_rifle.ogg b/mods/pvp/sniper_rifles/sounds/sniper_rifles_rifle.ogg new file mode 100644 index 0000000..56758d3 Binary files /dev/null and b/mods/pvp/sniper_rifles/sounds/sniper_rifles_rifle.ogg differ diff --git a/mods/pvp/sniper_rifles/textures/sniper_rifles_rifle_762.png b/mods/pvp/sniper_rifles/textures/sniper_rifles_rifle_762.png new file mode 100644 index 0000000..ae7b16f Binary files /dev/null and b/mods/pvp/sniper_rifles/textures/sniper_rifles_rifle_762.png differ diff --git a/mods/pvp/sniper_rifles/textures/sniper_rifles_rifle_magnum.png b/mods/pvp/sniper_rifles/textures/sniper_rifles_rifle_magnum.png new file mode 100644 index 0000000..ac99877 Binary files /dev/null and b/mods/pvp/sniper_rifles/textures/sniper_rifles_rifle_magnum.png differ