From ea9d9ad2d88f7a578300c96204af7c375078f6c0 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Fri, 3 Sep 2021 16:20:18 -0700 Subject: [PATCH] Revert "Rework melee damage (#878)" (#925) This reverts commit 84dc7da461c8c08481c072ad72631b5dd02c5414. --- mods/ctf/ctf/teams.lua | 46 ++++++++++++++++---------------- mods/ctf/ctf_classes/classes.lua | 2 +- mods/ctf/ctf_classes/init.lua | 13 --------- mods/ctf/ctf_classes/melee.lua | 31 +++++++++++++++++++++ mods/ctf/ctf_events/init.lua | 2 +- mods/ctf/ctf_metrics/init.lua | 2 +- mods/pvp/anticoward/init.lua | 4 ++- mods/pvp/kill_assist/init.lua | 2 +- mods/pvp/medkits/init.lua | 9 ++++--- 9 files changed, 66 insertions(+), 45 deletions(-) diff --git a/mods/ctf/ctf/teams.lua b/mods/ctf/ctf/teams.lua index a81efbd..b62469e 100644 --- a/mods/ctf/ctf/teams.lua +++ b/mods/ctf/ctf/teams.lua @@ -450,10 +450,6 @@ function ctf.can_attack(player, hitter, time_from_last_punch, tool_capabilities, return true end -function ctf.get_damage_modifier(player, tool_capabilities) - return 0 -end - ctf.registered_on_attack = {} function ctf.register_on_attack(func) if ctf._mt_loaded then @@ -462,8 +458,15 @@ function ctf.register_on_attack(func) table.insert(ctf.registered_on_attack, func) end +local dead_players = {} +minetest.register_on_respawnplayer(function(player) + dead_players[player:get_player_name()] = nil +end) +minetest.register_on_joinplayer(function(player) + dead_players[player:get_player_name()] = nil +end) minetest.register_on_punchplayer(function(player, hitter, - time_from_last_punch, tool_capabilities, dir, orig_damage, ...) + time_from_last_punch, tool_capabilities, dir, damage, ...) if player and hitter then local pname = player:get_player_name() local hname = hitter:get_player_name() @@ -471,6 +474,10 @@ minetest.register_on_punchplayer(function(player, hitter, local to = ctf.player(pname) local from = ctf.player(hname) + if dead_players[pname] then + return + end + if to.team == from.team and to.team ~= "" and to.team ~= nil and to.name ~= from.name then hud_event.new(hname, { @@ -484,38 +491,31 @@ minetest.register_on_punchplayer(function(player, hitter, end if ctf.can_attack(player, hitter, time_from_last_punch, tool_capabilities, - dir, orig_damage, ...) == false + dir, damage, ...) == false then return true end local hp = player:get_hp() - if hp <= 0 then - return true + if hp == 0 then + return false end - if tool_capabilities and tool_capabilities.damage_groups and tool_capabilities.damage_groups.fleshy then - local modifier = ctf.get_damage_modifier(hitter, tool_capabilities) - tool_capabilities.damage_groups.fleshy = math.max(1, tool_capabilities.damage_groups.fleshy + modifier) + if hp - damage <= 0 then + dead_players[pname] = true + local wielded = hitter:get_wielded_item() + for i = 1, #ctf.registered_on_killedplayer do + ctf.registered_on_killedplayer[i](pname, hname, + wielded, tool_capabilities) + end + return false end - local damage = minetest.get_hit_params(player:get_armor_groups(), tool_capabilities, time_from_last_punch).hp - damage = math.min(damage, hp) - for i = 1, #ctf.registered_on_attack do ctf.registered_on_attack[i]( player, hitter, time_from_last_punch, tool_capabilities, dir, damage, ... ) end - - if hp <= damage then - for i = 1, #ctf.registered_on_killedplayer do - ctf.registered_on_killedplayer[i](pname, hname, tool_capabilities) - end - end - - player:set_hp(hp - damage) - return true end end) diff --git a/mods/ctf/ctf_classes/classes.lua b/mods/ctf/ctf_classes/classes.lua index fbc69fb..bdbff8a 100644 --- a/mods/ctf/ctf_classes/classes.lua +++ b/mods/ctf/ctf_classes/classes.lua @@ -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", diff --git a/mods/ctf/ctf_classes/init.lua b/mods/ctf/ctf_classes/init.lua index ed946bf..f126c32 100644 --- a/mods/ctf/ctf_classes/init.lua +++ b/mods/ctf/ctf_classes/init.lua @@ -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 diff --git a/mods/ctf/ctf_classes/melee.lua b/mods/ctf/ctf_classes/melee.lua index 1dba648..8cd894c 100644 --- a/mods/ctf/ctf_classes/melee.lua +++ b/mods/ctf/ctf_classes/melee.lua @@ -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 diff --git a/mods/ctf/ctf_events/init.lua b/mods/ctf/ctf_events/init.lua index b8b96fe..18bf340 100644 --- a/mods/ctf/ctf_events/init.lua +++ b/mods/ctf/ctf_events/init.lua @@ -120,7 +120,7 @@ function ctf_events.update_all() end end -ctf.register_on_killedplayer(function(victim, killer, tool_caps) +ctf.register_on_killedplayer(function(victim, killer, stack, tool_caps) local victim_color = ctf_colors.get_color(ctf.player(victim)) local killer_color = ctf_colors.get_color(ctf.player(killer)) diff --git a/mods/ctf/ctf_metrics/init.lua b/mods/ctf/ctf_metrics/init.lua index aa555bf..6210ea3 100644 --- a/mods/ctf/ctf_metrics/init.lua +++ b/mods/ctf/ctf_metrics/init.lua @@ -15,7 +15,7 @@ end -- Kills -- local kill_counter = counter("ctf_kills", "Total kills") -ctf.register_on_killedplayer(function(victim, killer) +ctf.register_on_killedplayer(function(victim, killer, type) kill_counter:increment() end) diff --git a/mods/pvp/anticoward/init.lua b/mods/pvp/anticoward/init.lua index 9f851de..de93a2a 100644 --- a/mods/pvp/anticoward/init.lua +++ b/mods/pvp/anticoward/init.lua @@ -38,11 +38,12 @@ ctf.register_on_attack(function(player, hitter, potential_cowards[pname].timer = 0 potential_cowards[pname].puncher = hname + potential_cowards[pname].wielded_item = hitter:get_wielded_item() potential_cowards[pname].toolcaps = tool_capabilities end end) -ctf.register_on_killedplayer(function(victim, killer, toolcaps) +ctf.register_on_killedplayer(function(victim, killer, _, toolcaps) if toolcaps.damage_groups.combat_log or toolcaps.damage_groups.suicide then return end @@ -71,6 +72,7 @@ function handle_leave_or_die(pname, leave) ctf.registered_on_killedplayer[i]( pname, hname, + potential_cowards[pname].wielded_item, potential_cowards[pname].toolcaps ) end diff --git a/mods/pvp/kill_assist/init.lua b/mods/pvp/kill_assist/init.lua index 5315586..b813500 100644 --- a/mods/pvp/kill_assist/init.lua +++ b/mods/pvp/kill_assist/init.lua @@ -69,7 +69,7 @@ function kill_assist.reward_assists(victim, killer, reward) kill_assist.clear_assists(victim) end -ctf.register_on_killedplayer(function(victim, killer, toolcaps) +ctf.register_on_killedplayer(function(victim, killer, _, toolcaps) local reward = ctf_stats.calculateKillReward(victim, killer, toolcaps) reward = math.floor(reward * 100) / 100 kill_assist.reward_assists(victim, killer, reward) diff --git a/mods/pvp/medkits/init.lua b/mods/pvp/medkits/init.lua index 9a71e87..5848a0b 100644 --- a/mods/pvp/medkits/init.lua +++ b/mods/pvp/medkits/init.lua @@ -133,21 +133,22 @@ end) -- If player takes damage while healing, -- stop regen and revert back to original state -minetest.register_on_player_hpchange(function(player, hp_change, reason) +minetest.register_on_player_hpchange(function(player, hp, reason) local name = player:get_player_name() - if hp_change < 0 then + if hp < 0 then if players[name] then player:hud_remove(players[name].hud) players[name] = nil -- Don't use stop_healing(), it uses set_hp() and won't allocate deaths or score properly end - if reason.type == "punch" then + if reason and reason.type == "punch" then local hitter = reason.object if hitter and players[hitter:get_player_name()] then stop_healing(hitter, "attack") end end end -end) + return hp +end, true) minetest.register_on_leaveplayer(function(player) players[player:get_player_name()] = nil