Remove false promises in class selection, add random messages

This commit is contained in:
rubenwardy 2019-03-22 04:31:57 +00:00
parent a77928c556
commit f610722b83
16 changed files with 107 additions and 60 deletions

View file

@ -4,10 +4,15 @@ function ctf_classes.register(cname, def)
ctf_classes.__classes[cname] = def
table.insert(ctf_classes.__classes_ordered, def)
def.max_hp = def.max_hp or 20
def.speed = def.speed or 1
def.pros = def.pros or {}
def.cons = def.cons or {}
def.properties = def.properties or {}
if def.properties.can_capture == nil then
def.properties.can_capture = true
end
def.properties.speed = def.properties.speed or 1
def.properties.max_hp = def.properties.max_hp or 20
end
function ctf_classes.set_skin(player, color, class)
@ -44,12 +49,17 @@ end
local function set_max_hp(player, max_hp)
local cur_hp = player:get_hp()
local new_hp = cur_hp + max_hp - player:get_properties().hp_max
local old_max = player:get_properties().hp_max
local new_hp = cur_hp + max_hp - old_max
player:set_properties({
hp_max = max_hp
})
assert(new_hp <= max_hp)
if new_hp > max_hp then
minetest.log("error", string.format("New hp %d is larger than new max %d, old max is %d", new_hp, max_hp, old_max))
new_hp = max_hp
end
if cur_hp > max_hp then
player:set_hp(max_hp)
elseif new_hp > cur_hp then
@ -59,12 +69,12 @@ end
function ctf_classes.update(player)
local class = ctf_classes.get(player)
local color, _ = ctf_colors.get_color(ctf.player(player:get_player_name()))
local color = ctf_colors.get_color(ctf.player(player:get_player_name())).text
set_max_hp(player, class.max_hp)
set_max_hp(player, class.properties.max_hp)
ctf_classes.set_skin(player, color, class)
physics.set(player:get_player_name(), "ctf_classes:speed", {
speed = class.speed,
speed = class.properties.speed,
})
end

View file

@ -66,9 +66,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
"Move closer to the flag to change classes!")
end
for _, class in pairs(ctf_classes.__classes_ordered) do
if fields["select_" .. class.name] then
ctf_classes.set(player, class.name)
for name in pairs(ctf_classes.__classes) do
if fields["select_" .. name] then
ctf_classes.set(player, name)
return true
end
end

View file

@ -10,29 +10,43 @@ dofile(minetest.get_modpath("ctf_classes") .. "/ranged.lua")
ctf_classes.register("knight", {
description = "Knight",
pros = { "+10 HP", "+10% melee skill" },
pros = { "+50% Health Points" },
cons = { "-10% speed" },
max_hp = 30,
color = "#ccc",
properties = {
max_hp = 30,
speed = 0.90,
},
})
ctf_classes.register("shooter", {
description = "Shooter",
pros = { "+10% ranged skill", "Can use sniper rifles", "Can use grapling hooks" },
cons = {},
speed = 1.1,
pros = { "+10% ranged skill", "Rifles and grappling hooks" },
cons = { "Can't capture the flag" },
color = "#c60",
properties = {
can_capture = false,
},
})
ctf_classes.register("medic", {
description = "Medic",
speed = 1.1,
pros = { "x2 regen for nearby friendlies", "Free bandages" },
cons = { "Can't capture the flag"},
pros = { "x2 regen for nearby friendlies" },
cons = { "-50% Health Points" },
color = "#0af",
properties = {
max_hp = 10,
},
})
minetest.register_on_joinplayer(ctf_classes.update)
minetest.register_on_joinplayer(function(player)
ctf_classes.update(player)
if minetest.check_player_privs(player, { interact = true }) then
ctf_classes.show_gui(player:get_player_name())
end
end)
minetest.register_chatcommand("class", {
func = function(name, params)
@ -72,12 +86,20 @@ local flags = {
for _, flagname in pairs(flags) do
local old_func = minetest.registered_nodes[flagname].on_punch
local function on_punch(pos, node, player, ...)
if ctf_classes.get(player).name == "medic" then
local flag = ctf_flag.get(pos)
local team = ctf.player(player:get_player_name()).team
if not flag or not flag.team or not team or team ~= flag.team then
minetest.chat_send_player(player:get_player_name(),
"Medics can't capture the flag!")
local fpos = pos
if node.name:sub(1, 18) == "ctf_flag:flag_top_" then
fpos = vector.new(pos)
fpos.y = fpos.y - 1
end
local class = ctf_classes.get(player)
if not class.properties.can_capture then
local pname = player:get_player_name()
local flag = ctf_flag.get(fpos)
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

View file

@ -1,2 +1,3 @@
name = ctf_classes
depends = ctf, ctf_flag, ctf_colors, physics, shooter
depends = ctf, ctf_flag, ctf_colors, physics, shooter, hpregen
description = Adds classes, including knight, shooter, and medic

View file

@ -40,7 +40,7 @@ local function check_grapple(itemname)
local def = minetest.registered_items[itemname]
local old_func = def.on_use
minetest.override_item(itemname, {
description = def.description .. "\nCan only be used by Shooters",
description = def.description .. "\n\nCan only be used by Shooters",
on_use = function(itemstack, user, ...)
if ctf_classes.get(user).name ~= "shooter" then
minetest.chat_send_player(user:get_player_name(),
@ -56,3 +56,7 @@ end
check_grapple("shooter:grapple_gun_loaded")
check_grapple("shooter:grapple_gun")
minetest.override_item("shooter:rifle", {
description = "Rifle\n\nCan only be used by Shooters",
})

View file

@ -1,13 +1,3 @@
local regen_interval = tonumber(minetest.settings:get("regen_interval"))
if regen_interval <= 0 then
regen_interval = 6
end
local regen_amount = tonumber(minetest.settings:get("regen_amount"))
if regen_amount <= 0 then
regen_amount = 1
end
local function regen_update()
local get = ctf_classes.get
local players = minetest.get_connected_players()
@ -54,7 +44,7 @@ local function regen_update()
local medics = medic_by_team[tname]
for j=1, #medics do
if sqdist(pos, medics[j]) < 100 then
hp = hp + regen_amount
hp = hp + hpregen.amount
player:set_hp(hp)
break
end
@ -63,13 +53,13 @@ local function regen_update()
end
end
local update = regen_interval / 2
local update = hpregen.interval / 2
minetest.register_globalstep(function(delta)
update = update + delta
if update < regen_interval then
if update < hpregen.interval then
return
end
update = update - regen_interval
update = update - hpregen.interval
regen_update()
end)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Before After
Before After