forked from VoxeLibre/VoxeLibre
Improved haste and fatigue effects
* fixed a few crashes related to unusual effect levels * added haste and fatigue combat functionality * added some cleanup to avoid hangover unstackable items * capped the slowdown from fatigue at 5 minutes digging time * (despite the above, if a tool has a longer time set in definition, that still works) * removed an unused "global" variable
This commit is contained in:
parent
1ac81e440c
commit
0c4094596e
|
@ -534,6 +534,8 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir)
|
||||||
if self.protected and minetest.is_protected(mob_pos, hitter:get_player_name()) then
|
if self.protected and minetest.is_protected(mob_pos, hitter:get_player_name()) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mcl_potions.update_haste_and_fatigue(hitter)
|
||||||
end
|
end
|
||||||
|
|
||||||
local time_now = minetest.get_us_time()
|
local time_now = minetest.get_us_time()
|
||||||
|
|
|
@ -841,38 +841,61 @@ mcl_potions.register_effect({
|
||||||
lvl2_factor = 0.09,
|
lvl2_factor = 0.09,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- implementation of haste and fatigue effects for digging
|
-- implementation of haste and fatigue effects
|
||||||
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
local LONGEST_MINING_TIME = 300
|
||||||
local item = puncher:get_wielded_item()
|
function mcl_potions.update_haste_and_fatigue(player)
|
||||||
|
local item = player:get_wielded_item()
|
||||||
local meta = item:get_meta()
|
local meta = item:get_meta()
|
||||||
local haste = EF.haste[puncher]
|
local haste = EF.haste[player]
|
||||||
local fatigue = EF.fatigue[puncher]
|
local fatigue = EF.fatigue[player]
|
||||||
local item_haste = meta:get_float("mcl_potions:haste")
|
local item_haste = meta:get_float("mcl_potions:haste")
|
||||||
local item_fatig = 1 - meta:get_float("mcl_potions:fatigue")
|
local item_fatig = 1 - meta:get_float("mcl_potions:fatigue")
|
||||||
local h_fac
|
local h_fac
|
||||||
if haste then h_fac = haste.factor
|
if haste then h_fac = haste.factor
|
||||||
else h_fac = 0 end
|
else h_fac = 0 end
|
||||||
|
if h_fac < 0 then h_fac = 0 end
|
||||||
local f_fac
|
local f_fac
|
||||||
if fatigue then f_fac = fatigue.factor
|
if fatigue then f_fac = fatigue.factor
|
||||||
else f_fac = 1 end
|
else f_fac = 1 end
|
||||||
if f_fac < 0 then f_fac = 0 end
|
if f_fac < 0 then f_fac = 0 end
|
||||||
if item_haste ~= h_fac or item_fatig ~= f_fac then
|
if item_haste ~= h_fac or item_fatig ~= f_fac then
|
||||||
meta:set_float("mcl_potions:haste", h_fac)
|
if h_fac ~= 0 then meta:set_float("mcl_potions:haste", h_fac)
|
||||||
meta:set_float("mcl_potions:fatigue", 1 - f_fac)
|
else meta:set_string("mcl_potions:haste", "") end
|
||||||
|
if f_fac ~= 1 then meta:set_float("mcl_potions:fatigue", 1 - f_fac)
|
||||||
|
else meta:set_string("mcl_potions:fatigue", "") end
|
||||||
meta:set_tool_capabilities()
|
meta:set_tool_capabilities()
|
||||||
|
mcl_enchanting.update_groupcaps(item)
|
||||||
|
if h_fac == 0 and f_fac == 1 then
|
||||||
|
player:set_wielded_item(item)
|
||||||
|
return
|
||||||
|
end
|
||||||
local toolcaps = item:get_tool_capabilities()
|
local toolcaps = item:get_tool_capabilities()
|
||||||
-- if not toolcaps or not toolcaps.groupcaps then return end
|
toolcaps.full_punch_interval = toolcaps.full_punch_interval / (1+h_fac) / f_fac
|
||||||
for name, group in pairs(toolcaps.groupcaps) do
|
for name, group in pairs(toolcaps.groupcaps) do
|
||||||
local t = group.times
|
local t = group.times
|
||||||
for i=1, #t do
|
for i=1, #t do
|
||||||
t[i] = t[i] / (1+h_fac) / f_fac
|
if f_fac == 0 then
|
||||||
|
t[i] = t[i] > LONGEST_MINING_TIME and t[i] or LONGEST_MINING_TIME
|
||||||
|
else
|
||||||
|
local old_time = t[i]
|
||||||
|
t[i] = t[i] / (1+h_fac) / f_fac
|
||||||
|
if old_time < LONGEST_MINING_TIME and t[i] > LONGEST_MINING_TIME then
|
||||||
|
t[i] = LONGEST_MINING_TIME
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- TODO attack speed change?
|
|
||||||
meta:set_tool_capabilities(toolcaps)
|
meta:set_tool_capabilities(toolcaps)
|
||||||
puncher:set_wielded_item(item)
|
player:set_wielded_item(item)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
|
||||||
|
mcl_potions.update_haste_and_fatigue(puncher)
|
||||||
end)
|
end)
|
||||||
|
minetest.register_on_punchplayer(function(player, hitter)
|
||||||
|
mcl_potions.update_haste_and_fatigue(hitter)
|
||||||
|
end)
|
||||||
|
-- update when hitting mob implemented in mcl_mobs/combat.lua
|
||||||
|
|
||||||
|
|
||||||
-- ██╗░░░██╗██████╗░██████╗░░█████╗░████████╗███████╗
|
-- ██╗░░░██╗██████╗░██████╗░░█████╗░████████╗███████╗
|
||||||
|
@ -1131,6 +1154,22 @@ end)
|
||||||
-- ███████╗╚█████╔╝██║░░██║██████╔╝██╔╝░░░██████╔╝██║░░██║░░╚██╔╝░░███████╗
|
-- ███████╗╚█████╔╝██║░░██║██████╔╝██╔╝░░░██████╔╝██║░░██║░░╚██╔╝░░███████╗
|
||||||
-- ╚══════╝░╚════╝░╚═╝░░╚═╝╚═════╝░╚═╝░░░░╚═════╝░╚═╝░░╚═╝░░░╚═╝░░░╚══════╝
|
-- ╚══════╝░╚════╝░╚═╝░░╚═╝╚═════╝░╚═╝░░░░╚═════╝░╚═╝░░╚═╝░░░╚═╝░░░╚══════╝
|
||||||
|
|
||||||
|
function mcl_potions._reset_haste_fatigue_item_meta(player)
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
if not inv then return end
|
||||||
|
local lists = inv:get_lists()
|
||||||
|
for _, list in pairs(lists) do
|
||||||
|
for _, item in pairs(list) do
|
||||||
|
local meta = item:get_meta()
|
||||||
|
meta:set_string("mcl_potions:haste", "")
|
||||||
|
meta:set_string("mcl_potions:fatigue", "")
|
||||||
|
meta:set_tool_capabilities()
|
||||||
|
mcl_enchanting.update_groupcaps(item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
inv:set_lists(lists)
|
||||||
|
end
|
||||||
|
|
||||||
function mcl_potions._clear_cached_player_data(player)
|
function mcl_potions._clear_cached_player_data(player)
|
||||||
for name, effect in pairs(EF) do
|
for name, effect in pairs(EF) do
|
||||||
effect[player] = nil
|
effect[player] = nil
|
||||||
|
@ -1288,6 +1327,7 @@ end)
|
||||||
minetest.register_on_joinplayer( function(player)
|
minetest.register_on_joinplayer( function(player)
|
||||||
mcl_potions._reset_player_effects(player, false) -- make sure there are no weird holdover effects
|
mcl_potions._reset_player_effects(player, false) -- make sure there are no weird holdover effects
|
||||||
mcl_potions._load_player_effects(player)
|
mcl_potions._load_player_effects(player)
|
||||||
|
mcl_potions._reset_haste_fatigue_item_meta(player)
|
||||||
potions_init_icons(player)
|
potions_init_icons(player)
|
||||||
potions_set_hud(player)
|
potions_set_hud(player)
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -213,7 +213,6 @@ function mcl_potions.register_potion(def)
|
||||||
local has_plus = false
|
local has_plus = false
|
||||||
if def._effect_list then
|
if def._effect_list then
|
||||||
for name, details in pairs(def._effect_list) do
|
for name, details in pairs(def._effect_list) do
|
||||||
no_effects = false
|
|
||||||
effect = mcl_potions.registered_effects[name]
|
effect = mcl_potions.registered_effects[name]
|
||||||
if effect then
|
if effect then
|
||||||
local ulvl
|
local ulvl
|
||||||
|
|
Loading…
Reference in New Issue