From 32c1faa9e87e9bca186e47979b27d7798b1af74e Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 14 Mar 2020 19:56:40 +0000 Subject: [PATCH] Split classes init.lua into multiple files --- mods/ctf/ctf_classes/classes.lua | 95 ++++++++++++++++++++++ mods/ctf/ctf_classes/flags.lua | 31 ++++++++ mods/ctf/ctf_classes/init.lua | 132 +------------------------------ 3 files changed, 128 insertions(+), 130 deletions(-) create mode 100644 mods/ctf/ctf_classes/classes.lua create mode 100644 mods/ctf/ctf_classes/flags.lua diff --git a/mods/ctf/ctf_classes/classes.lua b/mods/ctf/ctf_classes/classes.lua new file mode 100644 index 0000000..cd5aa7d --- /dev/null +++ b/mods/ctf/ctf_classes/classes.lua @@ -0,0 +1,95 @@ +ctf_classes.default_class = "knight" + +ctf_classes.register("knight", { + description = "Knight", + pros = { "+50% Health Points" }, + cons = { "-10% speed" }, + color = "#ccc", + properties = { + max_hp = 30, + speed = 0.90, + + initial_stuff = { + "default:sword_steel", + }, + + allowed_guns = { + "shooter:pistol", + "shooter:smg", + "shooter:shotgun", + }, + }, +}) + +ctf_classes.register("shooter", { + description = "Sharp Shooter", + pros = { "+50% range", "+20% faster shooting" }, + cons = {}, + color = "#c60", + properties = { + allow_grapples = true, + + initial_stuff = { + "shooter:rifle", + "shooter:grapple_gun_loaded", + }, + + additional_item_blacklist = { + "shooter:grapple_gun", + "shooter:grapple_hook", + }, + + allowed_guns = { + "shooter:pistol", + "shooter:rifle", + "shooter:smg", + "shooter:shotgun", + }, + + shooter_multipliers = { + range = 1.5, + full_punch_interval = 0.8, + }, + }, +}) + +ctf_classes.register("medic", { + description = "Medic", + pros = { "x2 regen for nearby friendlies" }, + cons = {}, + color = "#0af", + properties = { + initial_stuff = { + "ctf_bandages:bandage 20", + }, + + allowed_guns = { + "shooter:pistol", + "shooter:smg", + "shooter:shotgun", + }, + }, +}) + +ctf_classes.register("rocketeer", { + description = "Rocketeer", + pros = { "Can craft rockets" }, + cons = {}, + color = "#fa0", + properties = { + initial_stuff = { + "shooter:rocket_gun_loaded", + "shooter:rocket 4", + }, + + additional_item_blacklist = { + "shooter:rocket_gun", + }, + + allowed_guns = { + "shooter:pistol", + "shooter:smg", + "shooter:shotgun", + }, + }, +}) diff --git a/mods/ctf/ctf_classes/flags.lua b/mods/ctf/ctf_classes/flags.lua new file mode 100644 index 0000000..41874d6 --- /dev/null +++ b/mods/ctf/ctf_classes/flags.lua @@ -0,0 +1,31 @@ +ctf_flag.register_on_pick_up(function(name) + ctf_classes.update(minetest.get_player_by_name(name)) +end) + +ctf_flag.register_on_drop(function(name) + ctf_classes.update(minetest.get_player_by_name(name)) +end) + +local old_func = ctf_flag.on_punch +local function on_punch(pos, node, player, ...) + local class = ctf_classes.get(player) + if not class.properties.can_capture then + local pname = player:get_player_name() + local flag = ctf_flag.get(pos) + local team = ctf.player(pname).team + if flag and flag.team and team and team ~= flag.team then + minetest.chat_send_player(pname, + "You need to change classes to capture the flag!") + return + end + end + + return old_func(pos, node, player, ...) +end + +local function show(_, _, player) + ctf_classes.show_gui(player:get_player_name(), player) +end + +ctf_flag.on_rightclick = show +ctf_flag.on_punch = on_punch diff --git a/mods/ctf/ctf_classes/init.lua b/mods/ctf/ctf_classes/init.lua index b6bc99d..da28846 100644 --- a/mods/ctf/ctf_classes/init.lua +++ b/mods/ctf/ctf_classes/init.lua @@ -1,8 +1,6 @@ ctf_classes = { __classes = {}, __classes_ordered = {}, - - default_class = "knight", } dofile(minetest.get_modpath("ctf_classes") .. "/api.lua") @@ -10,102 +8,8 @@ dofile(minetest.get_modpath("ctf_classes") .. "/gui.lua") 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" }, - cons = { "-10% speed" }, - color = "#ccc", - properties = { - max_hp = 30, - speed = 0.90, - - initial_stuff = { - "default:sword_steel", - }, - - allowed_guns = { - "shooter:pistol", - "shooter:smg", - "shooter:shotgun", - }, - }, -}) - -ctf_classes.register("shooter", { - description = "Sharp Shooter", - pros = { "+50% range", "+20% faster shooting" }, - cons = {}, - color = "#c60", - properties = { - allow_grapples = true, - - initial_stuff = { - "shooter:rifle", - "shooter:grapple_gun_loaded", - }, - - additional_item_blacklist = { - "shooter:grapple_gun", - "shooter:grapple_hook", - }, - - allowed_guns = { - "shooter:pistol", - "shooter:rifle", - "shooter:smg", - "shooter:shotgun", - }, - - shooter_multipliers = { - range = 1.5, - full_punch_interval = 0.8, - }, - }, -}) - -ctf_classes.register("medic", { - description = "Medic", - pros = { "x2 regen for nearby friendlies" }, - cons = {}, - color = "#0af", - properties = { - initial_stuff = { - "ctf_bandages:bandage 20", - }, - - allowed_guns = { - "shooter:pistol", - "shooter:smg", - "shooter:shotgun", - }, - }, -}) - -ctf_classes.register("rocketeer", { - description = "Rocketeer", - pros = { "Can craft rockets" }, - cons = {}, - color = "#fa0", - properties = { - initial_stuff = { - "shooter:rocket_gun_loaded", - "shooter:rocket 4", - }, - - additional_item_blacklist = { - "shooter:rocket_gun", - }, - - allowed_guns = { - "shooter:pistol", - "shooter:smg", - "shooter:shotgun", - }, - }, -}) - +dofile(minetest.get_modpath("ctf_classes") .. "/flags.lua") +dofile(minetest.get_modpath("ctf_classes") .. "/classes.lua") minetest.register_on_joinplayer(function(player) @@ -116,14 +20,6 @@ minetest.register_on_joinplayer(function(player) end end) -ctf_flag.register_on_pick_up(function(name) - ctf_classes.update(minetest.get_player_by_name(name)) -end) - -ctf_flag.register_on_drop(function(name) - ctf_classes.update(minetest.get_player_by_name(name)) -end) - minetest.register_chatcommand("class", { func = function(name, params) local player = minetest.get_player_by_name(name) @@ -153,30 +49,6 @@ ctf_colors.set_skin = function(player, color) ctf_classes.set_skin(player, color, ctf_classes.get(player)) end -local old_func = ctf_flag.on_punch -local function on_punch(pos, node, player, ...) - local class = ctf_classes.get(player) - if not class.properties.can_capture then - local pname = player:get_player_name() - local flag = ctf_flag.get(pos) - local team = ctf.player(pname).team - if flag and flag.team and team and team ~= flag.team then - minetest.chat_send_player(pname, - "You need to change classes to capture the flag!") - return - end - end - - return old_func(pos, node, player, ...) -end - -local function show(_, _, player) - ctf_classes.show_gui(player:get_player_name(), player) -end - -ctf_flag.on_rightclick = show -ctf_flag.on_punch = on_punch - ctf_classes.register_on_changed(function(player, old, new) if not old then return