1
0
Fork 0

Added food poisoning and saturation effects

potions_api_redo
the-real-herowl 2024-01-14 10:19:19 +01:00 committed by the-real-herowl
parent b17fdf01e8
commit c45b0baa61
3 changed files with 59 additions and 14 deletions

View File

@ -525,6 +525,50 @@ mcl_potions.register_effect({
timer_uses_factor = true,
})
mcl_potions.register_effect({
name = "food_poisoning",
description = S("Food Poisoning"),
get_tt = function(factor)
return S("exhausts by @1 per second", factor)
end,
res_condition = function(object)
return (not object:is_player())
end,
on_start = function(object, factor)
hb.change_hudbar(object, "hunger", nil, nil, "mcl_hunger_icon_foodpoison.png", nil, "mcl_hunger_bar_foodpoison.png")
if mcl_hunger.debug then
hb.change_hudbar(object, "exhaustion", nil, nil, nil, nil, "mcl_hunger_bar_foodpoison.png")
end
end,
on_step = function(dtime, object, factor, duration)
mcl_hunger.exhaust(object:get_player_name(), dtime*factor)
end,
on_end = function(object)
mcl_hunger.reset_bars_poison_hunger(object)
end,
particle_color = "#83A061",
uses_factor = true,
lvl1_factor = 100,
lvl2_factor = 200,
})
mcl_potions.register_effect({
name = "saturation",
description = S("Saturation"),
get_tt = function(factor)
return S("saturates by @1 per second", factor)
end,
res_condition = function(object)
return (not object:is_player())
end,
on_step = function(dtime, object, factor, duration)
mcl_hunger.set_hunger(object, math.min(mcl_hunger.get_hunger(object)+dtime*factor, 20))
mcl_hunger.saturate(object:get_player_name(), dtime*factor)
end,
particle_color = "#CEAE29",
uses_factor = true,
})
-- ██╗░░░██╗██████╗░██████╗░░█████╗░████████╗███████╗
-- ██║░░░██║██╔══██╗██╔══██╗██╔══██╗╚══██╔══╝██╔════╝
@ -841,6 +885,14 @@ function mcl_potions.player_get_effect(player, effect_name)
return EF[effect_name][player]
end
function mcl_potions.player_get_effect_level(player, effect_name)
if not EF[effect_name] then return end
local effect = EF[effect_name][player]
if not effect then return 0 end
if not registered_effects[effect_name].uses_factor then return 1 end
return registered_effects[effect_name].factor_to_level(effect.factor)
end
function mcl_potions.player_clear_effect(player,effect)
EF[effect][player] = nil
potions_set_hud(player)

View File

@ -99,7 +99,7 @@ function mcl_hunger.reset_bars_poison_hunger(player)
end
end
-- Poison player
-- Poison player TODO remove this function
local function poisonp(tick, time, time_left, damage, exhaustion, name)
if not mcl_hunger.active then
return
@ -186,15 +186,8 @@ function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poiso
do_poison = true
end
if do_poison then
-- Set food poison bars
if exhaust and exhaust > 0 then
hb.change_hudbar(user, "hunger", nil, nil, "mcl_hunger_icon_foodpoison.png", nil, "mcl_hunger_bar_foodpoison.png")
if mcl_hunger.debug then
hb.change_hudbar(user, "exhaustion", nil, nil, nil, nil, "mcl_hunger_bar_foodpoison.png")
end
mcl_hunger.poison_hunger[name] = mcl_hunger.poison_hunger[name] + 1
end
poisonp(1, poisontime, 0, poison, exhaust, user:get_player_name())
local level = mcl_potions.player_get_effect_level(user, "food_poisoning")
mcl_potions.give_effect_by_level("food_poisoning", user, level+exhaust, poisontime)
end
end

View File

@ -1,7 +1,7 @@
-- Apply food poisoning effect as long there are no real status effect.
-- TODO: Remove this when food poisoning a status effect in mcl_potions.
-- TODO: Sanitize this now that Food Poisoning is now an effect in mcl_potions
-- Normal poison damage is set to 0 because it's handled elsewhere.
mcl_hunger.register_food("mcl_mobitems:rotten_flesh", 4, "", 30, 0, 100, 80)
mcl_hunger.register_food("mcl_mobitems:chicken", 2, "", 30, 0, 100, 30)
mcl_hunger.register_food("mcl_fishing:pufferfish_raw", 1, "", 15, 0, 300)
mcl_hunger.register_food("mcl_mobitems:rotten_flesh", 4, "", 30, 0, 1, 80)
mcl_hunger.register_food("mcl_mobitems:chicken", 2, "", 30, 0, 1, 30)
mcl_hunger.register_food("mcl_fishing:pufferfish_raw", 1, "", 15, 0, 3)