From 9666b03ea3e1e58c0ee84810e9613964356fcb22 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 13 Oct 2020 08:42:41 -0700 Subject: [PATCH] Increase sword damage dealt by knights (#684) * Extra sword damage for knights * Make steel sword craftable --- mods/ctf/ctf_classes/classes.lua | 3 ++- mods/ctf/ctf_classes/init.lua | 1 + mods/ctf/ctf_classes/melee.lua | 13 +++++++++++++ mods/ctf/ctf_crafting/init.lua | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 mods/ctf/ctf_classes/melee.lua diff --git a/mods/ctf/ctf_classes/classes.lua b/mods/ctf/ctf_classes/classes.lua index 2344050..d8ecbf6 100644 --- a/mods/ctf/ctf_classes/classes.lua +++ b/mods/ctf/ctf_classes/classes.lua @@ -2,12 +2,13 @@ ctf_classes.default_class = "knight" ctf_classes.register("knight", { description = "Knight", - pros = { "+50% health points" }, + pros = { "Skilled with swords", "+50% health points" }, cons = { "-10% speed" }, color = "#ccc", properties = { max_hp = 30, speed = 0.90, + melee_bonus = 1, initial_stuff = { "default:sword_steel", diff --git a/mods/ctf/ctf_classes/init.lua b/mods/ctf/ctf_classes/init.lua index 40da1ff..d5ccfea 100644 --- a/mods/ctf/ctf_classes/init.lua +++ b/mods/ctf/ctf_classes/init.lua @@ -7,6 +7,7 @@ dofile(minetest.get_modpath("ctf_classes") .. "/api.lua") dofile(minetest.get_modpath("ctf_classes") .. "/gui.lua") dofile(minetest.get_modpath("ctf_classes") .. "/medic.lua") dofile(minetest.get_modpath("ctf_classes") .. "/ranged.lua") +dofile(minetest.get_modpath("ctf_classes") .. "/melee.lua") dofile(minetest.get_modpath("ctf_classes") .. "/items.lua") dofile(minetest.get_modpath("ctf_classes") .. "/flags.lua") dofile(minetest.get_modpath("ctf_classes") .. "/classes.lua") diff --git a/mods/ctf/ctf_classes/melee.lua b/mods/ctf/ctf_classes/melee.lua new file mode 100644 index 0000000..1689566 --- /dev/null +++ b/mods/ctf/ctf_classes/melee.lua @@ -0,0 +1,13 @@ +minetest.register_on_player_hpchange(function(player, hp_change, reason) + if reason.type ~= "punch" or not reason.object or not reason.object:is_player() then + return hp_change + end + + local class = ctf_classes.get(reason.object) + + if class.properties.melee_bonus and reason.object:get_wielded_item():get_name():find("sword") then + return hp_change - class.properties.melee_bonus + end + + return hp_change +end, true) diff --git a/mods/ctf/ctf_crafting/init.lua b/mods/ctf/ctf_crafting/init.lua index 2ac10d2..3fb04a0 100644 --- a/mods/ctf/ctf_crafting/init.lua +++ b/mods/ctf/ctf_crafting/init.lua @@ -7,6 +7,7 @@ local full_ores = { } local sword_materials = { + steel = "default:steel_ingot", mese = "default:mese_crystal", diamond = "default:diamond", }