Revert "Rework melee damage (#878)" (#925)

This reverts commit 84dc7da461.
This commit is contained in:
LoneWolfHT 2021-09-03 16:20:18 -07:00 committed by GitHub
parent 84dc7da461
commit ea9d9ad2d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 66 additions and 45 deletions

View file

@ -8,7 +8,7 @@ ctf_classes.register("knight", {
properties = {
max_hp = 30,
speed = 0.90,
sword_modifier = 1,
melee_bonus = 1,
initial_stuff = {
"ctf_classes:sword_bronze",

View file

@ -69,16 +69,3 @@ 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

View file

@ -1,3 +1,33 @@
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)
@ -38,6 +68,7 @@ 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