1
0
Fork 0

Added effect stacking option to the potions API

Also:
* Frost and Food Poisoning potion now stack their effects
* fixed a crash related to tipped arrows
potions_api_redo
the-real-herowl 2024-04-22 04:51:01 +02:00 committed by the-real-herowl
parent bb127da8cd
commit c15319c59f
5 changed files with 38 additions and 16 deletions

View File

@ -162,6 +162,7 @@ tt.register_snippet(function(itemstring, _, itemstack)
if effect.uses_factor then factor = effect.level_to_factor(ef_level) end if effect.uses_factor then factor = effect.level_to_factor(ef_level) end
if effect.get_tt then ef_tt = minetest.colorize("grey", effect.get_tt(factor)) else ef_tt = "" end if effect.get_tt then ef_tt = minetest.colorize("grey", effect.get_tt(factor)) else ef_tt = "" end
if ef_tt ~= "" then s = s.. ef_tt.. "\n" end if ef_tt ~= "" then s = s.. ef_tt.. "\n" end
if details.effect_stacks then s = s.. minetest.colorize("grey", S("...stacks")).. "\n" end
end end
end end
return s:trim() return s:trim()

View File

@ -90,6 +90,9 @@ minetest.register_globalstep(function(dtime)
else else
dur = details.dur dur = details.dur
end end
if details.effect_stacks then
ef_level = ef_level + mcl_potions.get_effect_level(obj, name)
end
if mcl_potions.give_effect_by_level(name, obj, ef_level, dur) then if mcl_potions.give_effect_by_level(name, obj, ef_level, dur) then
applied = true applied = true
end end
@ -97,7 +100,7 @@ minetest.register_globalstep(function(dtime)
end end
if vals.def.custom_effect if vals.def.custom_effect
and vals.def.custom_effect(obj, (vals.potency+1) * mcl_potions.LINGERING_FACTOR) then and vals.def.custom_effect(obj, (vals.potency+1) * mcl_potions.LINGERING_FACTOR, plus) then
applied = true applied = true
end end

View File

@ -64,7 +64,7 @@ function return_on_use(def, effect, dur)
--def.on_use(user, effect, dur) -- Will do effect immediately but not reduce item count until eating delay ends which makes it exploitable by deliberately not finishing delay --def.on_use(user, effect, dur) -- Will do effect immediately but not reduce item count until eating delay ends which makes it exploitable by deliberately not finishing delay
-- Wrapper for handling mcl_hunger delayed eating -- Wrapper for handling mcl_hunger delayed eating TODO migrate to the new function
local name = user:get_player_name() local name = user:get_player_name()
mcl_hunger.eat_internal[name]._custom_itemstack = itemstack -- Used as comparison to make sure the custom wrapper executes only when the same item is eaten mcl_hunger.eat_internal[name]._custom_itemstack = itemstack -- Used as comparison to make sure the custom wrapper executes only when the same item is eaten
mcl_hunger.eat_internal[name]._custom_var = { mcl_hunger.eat_internal[name]._custom_var = {
@ -122,11 +122,14 @@ local function generate_on_use(effects, color, on_use, custom_effect)
else else
dur = details.dur dur = details.dur
end end
if details.effect_stacks then
ef_level = ef_level + mcl_potions.get_effect_level(user, name)
end
mcl_potions.give_effect_by_level(name, user, ef_level, dur) mcl_potions.give_effect_by_level(name, user, ef_level, dur)
end end
if on_use then on_use(user, potency+1) end if on_use then on_use(user, potency+1) end
if custom_effect then custom_effect(user, potency+1) end if custom_effect then custom_effect(user, potency+1, plus) end
itemstack = minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, user, pointed_thing) itemstack = minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, user, pointed_thing)
if itemstack then mcl_potions._use_potion(user, color) end if itemstack then mcl_potions._use_potion(user, color) end
@ -162,6 +165,7 @@ end
-- -- -- dur_variable - bool - whether variants of the potion should have the length of this effect changed - -- -- -- dur_variable - bool - whether variants of the potion should have the length of this effect changed -
-- -- -- - defaults to true -- -- -- - defaults to true
-- -- -- - if at least one effect has this set to true, the potion has a "plus" variant -- -- -- - if at least one effect has this set to true, the potion has a "plus" variant
-- -- -- effect_stacks - bool - whether the effect stacks - defaults to false
-- uses_level - bool - whether the potion should come at different levels - -- uses_level - bool - whether the potion should come at different levels -
-- - defaults to true if uses_level is true for at least one effect, else false -- - defaults to true if uses_level is true for at least one effect, else false
-- drinkable - bool - defaults to true -- drinkable - bool - defaults to true
@ -172,7 +176,7 @@ end
-- default_potent_level - int - potion level used for the default potent variant - defaults to 2 -- default_potent_level - int - potion level used for the default potent variant - defaults to 2
-- default_extend_level - int - extention level (amount of +) used for the default extended variant - defaults to 1 -- default_extend_level - int - extention level (amount of +) used for the default extended variant - defaults to 1
-- custom_on_use - function(user, level) - called when the potion is drunk, returns true on success -- custom_on_use - function(user, level) - called when the potion is drunk, returns true on success
-- custom_effect - function(object, level) - called when the potion effects are applied, returns true on success -- custom_effect - function(object, level, plus) - called when the potion effects are applied, returns true on success
-- custom_splash_effect - function(pos, level) - called when the splash potion explodes, returns true on success -- custom_splash_effect - function(pos, level) - called when the splash potion explodes, returns true on success
-- custom_linger_effect - function(pos, radius, level) - called on the lingering potion step, returns true on success -- custom_linger_effect - function(pos, radius, level) - called on the lingering potion step, returns true on success
function mcl_potions.register_potion(def) function mcl_potions.register_potion(def)
@ -195,6 +199,9 @@ function mcl_potions.register_potion(def)
pdef.description = S("Strange Potion") pdef.description = S("Strange Potion")
end end
pdef._tt_help = def._tt pdef._tt_help = def._tt
if def._tt and def.effect_stacks then
pdef._tt_help = pdef._tt_help .. "\n" .. S("Stacks the effect")
end
pdef._dynamic_tt = def._dynamic_tt pdef._dynamic_tt = def._dynamic_tt
local potion_longdesc = def._longdesc local potion_longdesc = def._longdesc
if def._effect_list then if def._effect_list then
@ -230,6 +237,7 @@ function mcl_potions.register_potion(def)
level_scaling = details.level_scaling or 1, level_scaling = details.level_scaling or 1,
dur = details.dur or mcl_potions.DURATION, dur = details.dur or mcl_potions.DURATION,
dur_variable = durvar, dur_variable = durvar,
effect_stacks = details.effect_stacks and true or false
} }
else else
error("Unable to register potion: effect not registered") error("Unable to register potion: effect not registered")
@ -727,10 +735,12 @@ mcl_potions.register_potion({
_longdesc = S("Freezes..."), _longdesc = S("Freezes..."),
color = "#5B7DAA", color = "#5B7DAA",
_effect_list = { _effect_list = {
frost = {}, frost = {
dur = mcl_potions.DURATION_POISON,
effect_stacks = true,
},
}, },
has_arrow = true, has_arrow = true,
-- TODO implement effect stacking?
}) })
mcl_potions.register_potion({ mcl_potions.register_potion({
@ -764,10 +774,12 @@ mcl_potions.register_potion({
_longdesc = S("Moves bowels too fast."), _longdesc = S("Moves bowels too fast."),
color = "#83A061", color = "#83A061",
_effect_list = { _effect_list = {
food_poisoning = {dur=mcl_potions.DURATION_POISON}, food_poisoning = {
dur = mcl_potions.DURATION_POISON,
effect_stacks = true,
},
}, },
has_arrow = true, has_arrow = true,
-- TODO implement effect stacking?
}) })
mcl_potions.register_potion({ mcl_potions.register_potion({

View File

@ -151,6 +151,9 @@ function mcl_potions.register_splash(name, descr, color, def)
else else
dur = details.dur dur = details.dur
end end
if details.effect_stacks then
ef_level = ef_level + mcl_potions.get_effect_level(obj, name)
end
if rad > 0 then if rad > 0 then
mcl_potions.give_effect_by_level(name, obj, ef_level, redux_map[rad]*dur) mcl_potions.give_effect_by_level(name, obj, ef_level, redux_map[rad]*dur)
else else
@ -162,9 +165,9 @@ function mcl_potions.register_splash(name, descr, color, def)
if def.custom_effect then if def.custom_effect then
local power = (potency+1) * mcl_potions.SPLASH_FACTOR local power = (potency+1) * mcl_potions.SPLASH_FACTOR
if rad > 0 then if rad > 0 then
def.custom_effect(obj, redux_map[rad] * power) def.custom_effect(obj, redux_map[rad] * power, plus)
else else
def.custom_effect(obj, power) def.custom_effect(obj, power, plus)
end end
end end
end end

View File

@ -301,10 +301,14 @@ function mcl_potions.register_arrow(name, desc, color, def)
else else
dur = details.dur dur = details.dur
end end
dur = dur * mcl_potions.SPLASH_FACTOR
if details.effect_stacks then
ef_level = ef_level + mcl_potions.get_effect_level(obj, name)
end
mcl_potions.give_effect_by_level(name, obj, ef_level, dur) mcl_potions.give_effect_by_level(name, obj, ef_level, dur)
end end
end end
if def.custom_effect then def.custom_effect(obj, potency+1) end if def.custom_effect then def.custom_effect(obj, potency+1, plus) end
end end
else else
obj:punch(self.object, 1.0, { obj:punch(self.object, 1.0, {
@ -329,14 +333,13 @@ function mcl_potions.register_arrow(name, desc, color, def)
dur = details.dur dur = details.dur
end end
dur = dur * mcl_potions.SPLASH_FACTOR dur = dur * mcl_potions.SPLASH_FACTOR
if rad > 0 then if details.effect_stacks then
mcl_potions.give_effect_by_level(name, obj, ef_level, redux_map[rad]*dur) ef_level = ef_level + mcl_potions.get_effect_level(obj, name)
else end
mcl_potions.give_effect_by_level(name, obj, ef_level, dur) mcl_potions.give_effect_by_level(name, obj, ef_level, dur)
end end
end end
end if def.custom_effect then def.custom_effect(obj, potency+1, plus) end
if def.custom_effect then def.custom_effect(obj, potency+1) end
end end
if is_player then if is_player then