Skip to content

Commit

Permalink
Improve class shooter modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Mar 13, 2020
1 parent 81bd77c commit 5e346d3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion mods/ctf/ctf_classes/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function ctf_classes.get(player)
player = minetest.get_player_by_name(player)
end

local cname = player:get_meta():get("ctf_classes:class") or "knight"
local cname = player:get_meta():get("ctf_classes:class") or ctf_classes.default_class
return ctf_classes.__classes[cname]
end

Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_classes/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function ctf_classes.show_gui(name, player)
player = player or minetest.get_player_by_name(name)
assert(player.get_player_name)
if not ctf_classes.can_change(player) then
minetest.chat_send_player(name, "Move closer to the flag to change classes!")
minetest.chat_send_player(name, "Move closer to your flag to change classes!")
return
end

Expand Down
31 changes: 29 additions & 2 deletions mods/ctf/ctf_classes/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ctf_classes = {
__classes = {},
__classes_ordered = {},

default_class = "knight",
}

dofile(minetest.get_modpath("ctf_classes") .. "/api.lua")
Expand All @@ -9,6 +11,7 @@ dofile(minetest.get_modpath("ctf_classes") .. "/regen.lua")
dofile(minetest.get_modpath("ctf_classes") .. "/ranged.lua")
dofile(minetest.get_modpath("ctf_classes") .. "/items.lua")


ctf_classes.register("knight", {
description = "Knight",
pros = { "+50% Health Points" },
Expand All @@ -18,6 +21,12 @@ ctf_classes.register("knight", {
max_hp = 30,
speed = 0.90,

allowed_guns = {
"shooter:pistol",
"shooter:smg",
"shooter:shotgun",
},

items = {
"default:sword_steel",
},
Expand All @@ -33,7 +42,19 @@ ctf_classes.register("shooter", {
items = {
"shooter:rifle",
"shooter:grapple_gun_loaded",
}
},

allowed_guns = {
"shooter:pistol",
"shooter:rifle",
"shooter:smg",
"shooter:shotgun",
},

shooter_multipliers = {
range = 1.5,
full_punch_interval = 0.8,
},
},
})

Expand All @@ -48,6 +69,12 @@ ctf_classes.register("medic", {
items = {
"ctf_bandages:bandage 20",
},

allowed_guns = {
"shooter:pistol",
"shooter:smg",
"shooter:shotgun",
},
},
})

Expand Down Expand Up @@ -76,7 +103,7 @@ minetest.register_chatcommand("class", {
end

if not ctf_classes.can_change(player) then
return false, "Move closer to the flag to change classes!"
return false, "Move closer to your flag to change classes!"
end

local cname = params:trim()
Expand Down
47 changes: 24 additions & 23 deletions mods/ctf/ctf_classes/ranged.lua
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
local shooter_specs = {}
local specs_cache = {}


shooter.get_weapon_spec = function(_, user, name)
local spec = shooter.registered_weapons[name]
local function get_shooter_specs(weapon_name, multiplier)
local spec = shooter.registered_weapons[weapon_name]
if not spec then
return nil
end
spec = spec.spec
spec.name = user:get_player_name()

if not user then
return spec
end
-- this will convert the multipler to a table pointer
local idx = ("%s:%s"):format(multiplier or "nil", weapon_name)

local class = ctf_classes.get(user)
if class.name ~= "shooter" then
if name == "shooter:rifle" then
minetest.chat_send_player(user:get_player_name(),
"Only Shooters are skilled enough for rifles! Change your class at spawn")
return nil
end
return spec
end

if shooter_specs[name] then
return shooter_specs[name]
if specs_cache[idx] then
return specs_cache[idx]
end

spec = table.copy(spec)
shooter_specs[name] = spec
specs_cache[idx] = spec

spec.range = spec.range * 1.5
spec.tool_caps.full_punch_interval = spec.tool_caps.full_punch_interval * 0.8
return spec
end

shooter.get_weapon_spec = function(_, user, weapon_name)
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(),
"Your class can't use that weapon! Change your class at spawn")
return nil
end

local spec = get_shooter_specs(weapon_name, class.properties.shooter_multipliers)
spec.name = user and user:get_player_name()

return spec
end


local function check_grapple(itemname)
local def = minetest.registered_items[itemname]
local old_func = def.on_use
minetest.override_item(itemname, {
description = def.description .. "\n\nCan only be used by Shooters",
on_use = function(itemstack, user, ...)
if ctf_classes.get(user).name ~= "shooter" then
minetest.chat_send_player(user:get_player_name(),
"Only Shooters are skilled enough for grapples! Change your class at spawn")
"Your class can't use that weapon! Change your class at spawn")

return itemstack
end
Expand Down
2 changes: 1 addition & 1 deletion mods/other/random_messages/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function random_messages.read_messages()
"Use /summary to check scores of the current match and the previous match.",
"Use /maps to view the maps catalog. It also contains license info and attribution details.",
"Change your class in your base by right clicking the home flag or typing /class.",
"Medics cause nearby troops to regenerate health faster.",
"Medics cause troops within 10 metres to regenerate health faster.",
}
end

Expand Down
4 changes: 1 addition & 3 deletions mods/pvp/shooter/grapple.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ minetest.register_tool("shooter:grapple_gun", {
end

local inv = user:get_inventory()
if inv:contains_item("main", "shooter:grapple_hook") and
true then --inv:contains_item("main", "tnt:gunpowder") then
-- inv:remove_item("main", "tnt:gunpowder")
if inv:contains_item("main", "shooter:grapple_hook") then
minetest.sound_play("shooter_reload", {object=user})
local stack = inv:remove_item("main", "shooter:grapple_hook")
itemstack = ItemStack("shooter:grapple_gun_loaded 1 "..stack:get_wear())
Expand Down

0 comments on commit 5e346d3

Please sign in to comment.