Rework melee damage (#878)
This commit is contained in:
parent
f06eca30f0
commit
84dc7da461
9 changed files with 45 additions and 66 deletions
|
@ -8,7 +8,7 @@ ctf_classes.register("knight", {
|
|||
properties = {
|
||||
max_hp = 30,
|
||||
speed = 0.90,
|
||||
melee_bonus = 1,
|
||||
sword_modifier = 1,
|
||||
|
||||
initial_stuff = {
|
||||
"ctf_classes:sword_bronze",
|
||||
|
|
|
@ -69,3 +69,16 @@ ctf_classes.register_on_changed(function(player, old, new)
|
|||
ctf.chat_send_team(ctf.player(pname).team,
|
||||
minetest.colorize("#ABCDEF", pname .. " is now a " .. new.description))
|
||||
end)
|
||||
|
||||
local old_get_damage_modifier = ctf.get_damage_modifier
|
||||
function ctf.get_damage_modifier(player, tool_capabilities)
|
||||
local modifier = 0
|
||||
if tool_capabilities.damage_groups.sword then
|
||||
local class = ctf_classes.get(player)
|
||||
if class.properties.sword_modifier then
|
||||
modifier = class.properties.sword_modifier
|
||||
end
|
||||
end
|
||||
|
||||
return modifier + old_get_damage_modifier(player, tool_capabilities)
|
||||
end
|
||||
|
|
|
@ -1,33 +1,3 @@
|
|||
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
|
||||
local change = hp_change - class.properties.melee_bonus
|
||||
|
||||
if player:get_hp() + change <= 0 and player:get_hp() + hp_change > 0 then
|
||||
local wielded_item = reason.object:get_wielded_item()
|
||||
|
||||
for i = 1, #ctf.registered_on_killedplayer do
|
||||
ctf.registered_on_killedplayer[i](
|
||||
player:get_player_name(),
|
||||
reason.object:get_player_name(),
|
||||
wielded_item,
|
||||
wielded_item:get_tool_capabilities()
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
return change
|
||||
end
|
||||
|
||||
return hp_change
|
||||
end, true)
|
||||
|
||||
|
||||
local sword_special_timer = {}
|
||||
local SWORD_SPECIAL_COOLDOWN = 20
|
||||
local function sword_special_timer_func(pname, timeleft)
|
||||
|
@ -68,7 +38,6 @@ minetest.register_tool("ctf_classes:sword_bronze", {
|
|||
end
|
||||
|
||||
local pteam = ctf.player(pname).team
|
||||
|
||||
if not pteam then -- can be nil during map change
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue