diff --git a/mods/ctf/ctf_modes/ctf_mode_classes/classes.lua b/mods/ctf/ctf_modes/ctf_mode_classes/classes.lua index dd8208b0a..a06ce8a3c 100644 --- a/mods/ctf/ctf_modes/ctf_mode_classes/classes.lua +++ b/mods/ctf/ctf_modes/ctf_mode_classes/classes.lua @@ -5,7 +5,7 @@ local CLASS_SWITCH_COOLDOWN = 30 local classes = {} -local class_list = {"knight", "ranged", "support"} +local class_list = {"knight", "ranged", "support", "thief"} local class_props = { knight = { name = "Knight", @@ -55,6 +55,26 @@ local class_props = { disallowed_items_markup = { ["ctf_melee:"] = "default_tool_steelsword.png^ctf_modebase_group.png", }, + }, + thief = { + name = "Thief", + description = "Criminal class, punch enemies with a bare hand to have a chance of stealing an item from them", + visual_size = vector.new(0.8, 0.9, 0.8), + physics = {speed = 1.2}, + items = { + "ctf_mode_classes:scaling_ladder", + "default:cobble 99" + }, + disallowed_items = { + "ctf_melee:", + "ctf_ranged:rifle", + "ctf_ranged:smg", + "ctf_ranged:sniper_magnum", + "ctf_ranged:shotgun", + }, + disallowed_items_markup = { + ["ctf_melee:"] = "default_tool_steelsword.png^ctf_modebase_group.png" + }, } } diff --git a/mods/ctf/ctf_modes/ctf_mode_classes/init.lua b/mods/ctf/ctf_modes/ctf_mode_classes/init.lua index 4ae92222a..ffbd4462f 100644 --- a/mods/ctf/ctf_modes/ctf_mode_classes/init.lua +++ b/mods/ctf/ctf_modes/ctf_mode_classes/init.lua @@ -2,9 +2,10 @@ local rankings = ctf_rankings.init() local recent_rankings = ctf_modebase.recent_rankings(rankings) local features = ctf_modebase.features(rankings, recent_rankings) -local classes = ctf_core.include_files( +classes = ctf_core.include_files( "paxel.lua", - "classes.lua" + "classes.lua", + "thief.lua" ) local old_bounty_reward_func = ctf_modebase.bounties.bounty_reward_func diff --git a/mods/ctf/ctf_modes/ctf_mode_classes/textures/ctf_mode_classes_thief_overlay.png b/mods/ctf/ctf_modes/ctf_mode_classes/textures/ctf_mode_classes_thief_overlay.png new file mode 100644 index 000000000..cffaa9ff2 Binary files /dev/null and b/mods/ctf/ctf_modes/ctf_mode_classes/textures/ctf_mode_classes_thief_overlay.png differ diff --git a/mods/ctf/ctf_modes/ctf_mode_classes/thief.lua b/mods/ctf/ctf_modes/ctf_mode_classes/thief.lua new file mode 100644 index 000000000..3cba69b53 --- /dev/null +++ b/mods/ctf/ctf_modes/ctf_mode_classes/thief.lua @@ -0,0 +1,49 @@ +local robbery_cooldown = ctf_core.init_cooldowns() +local ROBBERY_INTERVAL = 5 + +local function rob_player(player, robber) + local inv = player:get_inventory() + local stack = inv:get_stack("main", math.random(1, inv:get_size("main"))) + local mode = ctf_modebase:get_current_mode() + if mode and mode.stuff_provider then + for _, item in ipairs(classes.get(player).items) do + if stack:get_name() == item or stack:get_name() == "" then + return "You didn't find anything to rob." + end + end + if robber:get_inventory():room_for_item("main", stack) then + inv:remove_item("main", stack) + robber:get_inventory():add_item("main", stack) + else + local pos = player:get_pos() + inv:remove_item("main", stack) + minetest.add_item(pos, stack) + end + return string.format("You stole %s %s", stack:get_count(), stack:get_description()) + end +end + +minetest.register_on_punchplayer(function(punched, puncher) + if puncher and puncher:is_player() and punched and punched:is_player() then + local wielded_item = puncher:get_wielded_item() + if puncher:get_wielded_item():get_name() == "" then + if robbery_cooldown:get(puncher:get_player_name()) then + hud_events.new(puncher, { + text = "You can only rob every "..ROBBERY_INTERVAL.." seconds", + color = "warning", + quick = true, + }) + return + end + local msg = rob_player(punched, puncher) + if msg then + hud_events.new(puncher, { + text = msg, + color = "warning", + quick = true, + }) + end + robbery_cooldown:set(puncher, ROBBERY_INTERVAL) + end + end +end)