Skip to content

Commit

Permalink
Add the "Thief" class
Browse files Browse the repository at this point in the history
Fixes MT-CTF#1172, I nerfed it a little to make it more balanced, and hopefully farooq can use it to add his score thingy, but I tested it, and it works.
  • Loading branch information
Infernia829 committed Jul 3, 2023
1 parent 48fcab4 commit bbf1561
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
22 changes: 21 additions & 1 deletion mods/ctf/ctf_modes/ctf_mode_classes/classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
}
}

Expand Down
5 changes: 3 additions & 2 deletions mods/ctf/ctf_modes/ctf_mode_classes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions mods/ctf/ctf_modes/ctf_mode_classes/thief.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit bbf1561

Please sign in to comment.