Improve class shooter modifications

This commit is contained in:
rubenwardy 2020-03-13 23:26:53 +00:00
parent 02d527eaf5
commit eee6cfcbec
6 changed files with 57 additions and 35 deletions

View file

@ -31,7 +31,7 @@ function ctf_classes.get(player)
player = minetest.get_player_by_name(player) player = minetest.get_player_by_name(player)
end 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] return ctf_classes.__classes[cname]
end end

View file

@ -2,7 +2,7 @@ function ctf_classes.show_gui(name, player)
player = player or minetest.get_player_by_name(name) player = player or minetest.get_player_by_name(name)
assert(player.get_player_name) assert(player.get_player_name)
if not ctf_classes.can_change(player) then 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 return
end end

View file

@ -1,6 +1,8 @@
ctf_classes = { ctf_classes = {
__classes = {}, __classes = {},
__classes_ordered = {}, __classes_ordered = {},
default_class = "knight",
} }
dofile(minetest.get_modpath("ctf_classes") .. "/api.lua") dofile(minetest.get_modpath("ctf_classes") .. "/api.lua")
@ -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") .. "/ranged.lua")
dofile(minetest.get_modpath("ctf_classes") .. "/items.lua") dofile(minetest.get_modpath("ctf_classes") .. "/items.lua")
ctf_classes.register("knight", { ctf_classes.register("knight", {
description = "Knight", description = "Knight",
pros = { "+50% Health Points" }, pros = { "+50% Health Points" },
@ -18,6 +21,12 @@ ctf_classes.register("knight", {
max_hp = 30, max_hp = 30,
speed = 0.90, speed = 0.90,
allowed_guns = {
"shooter:pistol",
"shooter:smg",
"shooter:shotgun",
},
items = { items = {
"default:sword_steel", "default:sword_steel",
}, },
@ -33,7 +42,19 @@ ctf_classes.register("shooter", {
items = { items = {
"shooter:rifle", "shooter:rifle",
"shooter:grapple_gun_loaded", "shooter:grapple_gun_loaded",
} },
allowed_guns = {
"shooter:pistol",
"shooter:rifle",
"shooter:smg",
"shooter:shotgun",
},
shooter_multipliers = {
range = 1.5,
full_punch_interval = 0.8,
},
}, },
}) })
@ -48,6 +69,12 @@ ctf_classes.register("medic", {
items = { items = {
"ctf_bandages:bandage 20", "ctf_bandages:bandage 20",
}, },
allowed_guns = {
"shooter:pistol",
"shooter:smg",
"shooter:shotgun",
},
}, },
}) })
@ -76,7 +103,7 @@ minetest.register_chatcommand("class", {
end end
if not ctf_classes.can_change(player) then 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 end
local cname = params:trim() local cname = params:trim()

View file

@ -1,50 +1,51 @@
local shooter_specs = {} local specs_cache = {}
local function get_shooter_specs(weapon_name, multiplier)
shooter.get_weapon_spec = function(_, user, name) local spec = shooter.registered_weapons[weapon_name]
local spec = shooter.registered_weapons[name]
if not spec then if not spec then
return nil return nil
end end
spec = spec.spec spec = spec.spec
spec.name = user:get_player_name()
if not user then -- this will convert the multipler to a table pointer
return spec local idx = ("%s:%s"):format(multiplier or "nil", weapon_name)
end
local class = ctf_classes.get(user) if specs_cache[idx] then
if class.name ~= "shooter" then return specs_cache[idx]
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]
end end
spec = table.copy(spec) spec = table.copy(spec)
shooter_specs[name] = spec specs_cache[idx] = spec
spec.range = spec.range * 1.5 spec.range = spec.range * 1.5
spec.tool_caps.full_punch_interval = spec.tool_caps.full_punch_interval * 0.8 spec.tool_caps.full_punch_interval = spec.tool_caps.full_punch_interval * 0.8
return spec return spec
end 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 function check_grapple(itemname)
local def = minetest.registered_items[itemname] local def = minetest.registered_items[itemname]
local old_func = def.on_use local old_func = def.on_use
minetest.override_item(itemname, { minetest.override_item(itemname, {
description = def.description .. "\n\nCan only be used by Shooters",
on_use = function(itemstack, user, ...) on_use = function(itemstack, user, ...)
if ctf_classes.get(user).name ~= "shooter" then if ctf_classes.get(user).name ~= "shooter" then
minetest.chat_send_player(user:get_player_name(), 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 return itemstack
end end
@ -63,7 +64,3 @@ end
check_grapple("shooter:grapple_gun_loaded") check_grapple("shooter:grapple_gun_loaded")
check_grapple("shooter:grapple_gun") check_grapple("shooter:grapple_gun")
minetest.override_item("shooter:rifle", {
description = "Rifle\n\nCan only be used by Shooters",
})

View file

@ -75,7 +75,7 @@ function random_messages.read_messages()
"Use /summary to check scores of the current match and the previous match.", "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.", "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.", "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 end

View file

@ -89,9 +89,7 @@ minetest.register_tool("shooter:grapple_gun", {
end end
local inv = user:get_inventory() local inv = user:get_inventory()
if inv:contains_item("main", "shooter:grapple_hook") and if inv:contains_item("main", "shooter:grapple_hook") then
true then --inv:contains_item("main", "tnt:gunpowder") then
-- inv:remove_item("main", "tnt:gunpowder")
minetest.sound_play("shooter_reload", {object=user}) minetest.sound_play("shooter_reload", {object=user})
local stack = inv:remove_item("main", "shooter:grapple_hook") local stack = inv:remove_item("main", "shooter:grapple_hook")
itemstack = ItemStack("shooter:grapple_gun_loaded 1 "..stack:get_wear()) itemstack = ItemStack("shooter:grapple_gun_loaded 1 "..stack:get_wear())