0
0
Fork 0

Merge pull request 'Combat rebalancing' (#4036) from combat_rebalancing into master

Reviewed-on: MineClone2/MineClone2#4036
This commit is contained in:
the-real-herowl 2023-12-08 22:06:06 +00:00
commit bb66f81999
7 changed files with 57 additions and 33 deletions

View File

@ -516,6 +516,28 @@ end
-- deal damage and effects when mob punched
function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
local is_player = hitter:is_player()
local mob_pos = self.object:get_pos()
local player_pos = hitter:get_pos()
if is_player then
-- is mob out of reach?
if vector.distance(mob_pos, player_pos) > 3 then
return
end
-- is mob protected?
if self.protected and minetest.is_protected(mob_pos, hitter:get_player_name()) then
return
end
end
local time_now = minetest.get_us_time()
local time_diff = time_now - self.invul_timestamp
-- check for invulnerability time in microseconds (0.5 second)
if time_diff <= 500000 and time_diff >= 0 then
return
end
-- custom punch function
if self.do_punch then
@ -534,29 +556,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
local time_now = minetest.get_us_time()
local is_player = hitter:is_player()
if is_player then
local time_diff = time_now - self.invul_timestamp
-- check for invulnerability time in microseconds (0.5 second)
if time_diff <= 500000 and time_diff >= 0 then
return
end
local mob_pos = self.object:get_pos()
local player_pos = hitter:get_pos()
-- is mob out of reach?
if vector.distance(mob_pos, player_pos) > 3 then
return
end
-- is mob protected?
if self.protected and minetest.is_protected(mob_pos, hitter:get_player_name()) then
return
end
if minetest.is_creative_enabled(hitter:get_player_name()) then
self.health = 0
end
@ -719,12 +719,12 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
end
if hitter and is_player then
local wielditem = hitter:get_wielded_item()
kb = kb + 9 * mcl_enchanting.get_enchantment(wielditem, "knockback")
-- add player velocity to mob knockback
local hv = hitter:get_velocity()
local dir_dot = (hv.x * dir.x) + (hv.z * dir.z)
local player_mag = math.sqrt((hv.x * hv.x) + (hv.z * hv.z))
local mob_mag = math.sqrt((v.x * v.x) + (v.z * v.z))
kb = kb + 9 * mcl_enchanting.get_enchantment(wielditem, "knockback")
-- add player velocity to mob knockback
if dir_dot > 0 and mob_mag <= player_mag * 0.625 then
kb = kb + ((math.abs(hv.x) + math.abs(hv.z)) * r)
end

View File

@ -156,7 +156,6 @@ mcl_death_messages = {
plain = "@1 died a sweet death",
assist = "@1 was poked to death by a sweet berry bush whilst trying to escape @2",
},
-- Missing snowballs: The Minecraft wiki mentions them but the MC source code does not.
},
}

View File

@ -278,9 +278,21 @@ function minetest.calculate_knockback(player, hitter, time_from_last_punch, tool
end
if hitter and hitter:is_player() then
local wielditem = hitter:get_wielded_item()
knockback = knockback + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback")
knockback = knockback + 5 * mcl_enchanting.get_enchantment(wielditem, "knockback")
-- add player velocity to knockback
local hv = hitter:get_velocity()
local dir_dot = (hv.x * dir.x) + (hv.z * dir.z)
if dir_dot > 0 then
knockback = knockback + dir_dot * 2
end
elseif luaentity and luaentity._knockback then
knockback = knockback + luaentity._knockback
local kb = knockback + luaentity._knockback / 4
local punch_dir = dir
punch_dir.y = 0
punch_dir = vector.normalize(punch_dir) * kb
punch_dir.y = 4
player:add_velocity(punch_dir)
knockback = 0
end
return knockback
end

View File

@ -23,8 +23,7 @@ mcl_damage.register_modifier(function(obj, damage, reason)
texture = "mcl_particles_crit.png^[colorize:#bc7a57:127",
})
minetest.sound_play("mcl_criticals_hit", {object = obj})
-- the minecraft wiki is actually wrong about a crit dealing 150% damage, see minecraft source code
return damage + math.random(0, math.floor(damage * 1.5 + 2))
return damage * math.random(1.5, 2.5)
end
end
end, -100)

View File

@ -146,9 +146,9 @@ minetest.register_globalstep(function(dtime)
local food_level = mcl_hunger.get_hunger(player)
local food_saturation_level = mcl_hunger.get_saturation(player)
local player_health = player:get_hp()
local max_tick_timer = tonumber(minetest.settings:get("mcl_health_regen_delay")) or 4
local max_tick_timer = tonumber(minetest.settings:get("mcl_health_regen_delay")) or 0.5
if food_tick_timer > max_tick_timer then
if food_tick_timer > 4 then
food_tick_timer = 0
-- let hunger work always

View File

@ -727,6 +727,20 @@ mcl_damage.register_modifier(function(obj, damage, reason)
end
end, -200)
-- damage invulnerability
mcl_damage.register_modifier(function(obj, damage, reason)
local invul = obj:get_meta():get_int("mcl_damage:invulnerable")
if invul > 0 then
return 0
else
obj:get_meta():set_int("mcl_damage:invulnerable", 1)
minetest.after(0.5, function()
obj:get_meta():set_int("mcl_damage:invulnerable", 0)
end)
return damage
end
end, -1000)
minetest.register_on_respawnplayer(function(player)
local pos = player:get_pos()
minetest.add_particlespawner({

View File

@ -99,8 +99,8 @@ mcl_creative_dig_speed (Creative mode dig speed) float 0.2
mcl_enable_hunger (Hunger mechanic) bool true
# Health regeneration delay when hunger bar is full
# Default:4
mcl_health_regen_delay (Health regen delay) float 4 0
# Default: 0.5 s
mcl_health_regen_delay (Health regen delay) float 0.5 0
[Mobs]
# If enabled, mobs will spawn naturally. This does not affect