Move Lingering potion generation into single call
This commit is contained in:
parent
e3becf443e
commit
a6dac52797
|
@ -14,6 +14,7 @@ mcl_potions.DURATION_2 = mcl_potions.DURATION / mcl_potions.II_FACTOR
|
|||
|
||||
mcl_potions.INV_FACTOR = 0.50
|
||||
mcl_potions.SPLASH_FACTOR = 0.75
|
||||
mcl_potions.LINGERING_FACTOR = 0.25
|
||||
|
||||
|
||||
local modpath = minetest.get_modpath("mcl_potions")
|
||||
|
|
|
@ -66,7 +66,7 @@ end)
|
|||
|
||||
|
||||
|
||||
local function register_lingering(name, descr, color, def)
|
||||
function mcl_potions.register_lingering(name, descr, color, def)
|
||||
|
||||
local id = "mcl_potions:"..name.."_lingering"
|
||||
minetest.register_craftitem(id, {
|
||||
|
@ -134,186 +134,32 @@ local function register_lingering(name, descr, color, def)
|
|||
})
|
||||
end
|
||||
|
||||
local function time_string(dur)
|
||||
return math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))
|
||||
end
|
||||
|
||||
register_lingering("water", S("Lingering Water Bottle"), "#0000FF", {
|
||||
potion_fun = function(player) end,
|
||||
tt = S("No effect")
|
||||
})
|
||||
|
||||
register_lingering("river_water", S("Lingering River Water Bottle"), "#0044FF", {
|
||||
potion_fun = function(player) end,
|
||||
tt = S("No effect")
|
||||
})
|
||||
|
||||
register_lingering("awkward", S("Lingering Awkward Potion"), "#0000FF", {
|
||||
potion_fun = function(player) end,
|
||||
tt = S("No effect")
|
||||
})
|
||||
|
||||
register_lingering("mundane", S("Lingering Mundane Potion"), "#0000FF", {
|
||||
potion_fun = function(player) end,
|
||||
tt = S("No effect")
|
||||
})
|
||||
|
||||
register_lingering("thick", S("Lingering Thick Potion"), "#0000FF", {
|
||||
potion_fun = function(player) end,
|
||||
tt = S("No effect")
|
||||
})
|
||||
|
||||
register_lingering("healing", S("Lingering Healing Potion"), "#AA0000", {
|
||||
potion_fun = function(player) mcl_potions.healing_func(player, 2) end,
|
||||
tt = S("+2 HP")
|
||||
})
|
||||
|
||||
register_lingering("healing_2", S("Lingering Healing Potion II"), "#DD0000", {
|
||||
potion_fun = function(player) mcl_potions.healing_func(player, 4) end,
|
||||
tt = S("+4 HP")
|
||||
})
|
||||
|
||||
register_lingering("harming", S("Lingering Harming Potion"), "#660099", {
|
||||
potion_fun = function(player) mcl_potions.healing_func(player, -3) end,
|
||||
tt = S("-3 HP")
|
||||
})
|
||||
|
||||
register_lingering("harming_2", S("Lingering Harming Potion II"), "#330066", {
|
||||
potion_fun = function(player) mcl_potions.healing_func(player, -6) end,
|
||||
tt = S("-6 HP")
|
||||
})
|
||||
|
||||
register_lingering("leaping", S("Lingering Leaping Potion"), "#00CC33", {
|
||||
potion_fun = function(player) mcl_potions.leaping_func(player, 1.2, mcl_potions.DURATION*0.25) end,
|
||||
tt = S("120% | @1", time_string(mcl_potions.DURATION*0.25))
|
||||
})
|
||||
|
||||
register_lingering("leaping_2", S("Lingering Leaping Potion II"), "#00EE33", {
|
||||
potion_fun = function(player) mcl_potions.leaping_func(player, 1.4, mcl_potions.DURATION_2*0.25) end,
|
||||
tt = S("140% | @1", time_string(mcl_potions.DURATION_2*0.25))
|
||||
})
|
||||
|
||||
register_lingering("leaping_plus", S("Lingering Leaping Potion +"), "#00DD33", {
|
||||
potion_fun = function(player) mcl_potions.leaping_func(player, 1.2, mcl_potions.DURATION_PLUS*0.25) end,
|
||||
tt = S("120% | @1", time_string(mcl_potions.DURATION_PLUS*0.25))
|
||||
})
|
||||
|
||||
register_lingering("swiftness", S("Lingering Swiftness Potion"), "#009999", {
|
||||
potion_fun = function(player) mcl_potions.swiftness_func(player, 1.2, mcl_potions.DURATION*0.25) end,
|
||||
tt = S("120% | @1", time_string(mcl_potions.DURATION*0.25))
|
||||
})
|
||||
|
||||
register_lingering("swiftness_2", S("Lingering Swiftness Potion II"), "#00BBBB", {
|
||||
potion_fun = function(player) mcl_potions.swiftness_func(player, 1.4, mcl_potions.DURATION_2*0.25) end,
|
||||
tt = S("140% | @1", time_string(mcl_potions.DURATION_2*0.25))
|
||||
})
|
||||
|
||||
register_lingering("swiftness_plus", S("Lingering Swiftness Potion +"), "#00BBBB", {
|
||||
potion_fun = function(player) mcl_potions.swiftness_func(player, 1.2, mcl_potions.DURATION_PLUS*0.25) end,
|
||||
tt = S("120% | @1", time_string(mcl_potions.DURATION_PLUS*0.25))
|
||||
})
|
||||
|
||||
register_lingering("slowness", S("Lingering Slowness Potion"), "#000080", {
|
||||
potion_fun = function(player) mcl_potions.swiftness_func(player, 0.85, mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25) end,
|
||||
tt = S("85% | @1", time_string(mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25))
|
||||
})
|
||||
|
||||
register_lingering("slowness_plus", S("Lingering Slowness Potion +"), "#000066", {
|
||||
potion_fun = function(player) mcl_potions.swiftness_func(player, 0.85, mcl_potions.DURATION_PLUS*mcl_potions.INV_FACTOR*0.25) end,
|
||||
tt = S("85% | @1", time_string(mcl_potions.DURATION_PLUS*mcl_potions.INV_FACTOR*0.25))
|
||||
})
|
||||
|
||||
register_lingering("slowness_2", S("Lingering Slowness Potion IV"), "#000066", {
|
||||
potion_fun = function(player) mcl_potions.swiftness_func(player, 0.4, 20*0.25) end,
|
||||
tt = S("40% | @1", time_string(20*0.25))
|
||||
})
|
||||
|
||||
register_lingering("poison", S("Lingering Poison Potion"), "#335544", {
|
||||
potion_fun = function(player) mcl_potions.poison_func(player, 2.5, 45*0.25) end,
|
||||
tt = S("-1 HP / 2.5s | @1", time_string(45*0.25))
|
||||
})
|
||||
|
||||
register_lingering("poison_2", S("Lingering Poison Potion II"), "#446655", {
|
||||
potion_fun = function(player) mcl_potions.poison_func(player, 1.2, 21*0.25) end,
|
||||
tt = S("-1 HP / 1.2s | @1", time_string(21*0.25))
|
||||
})
|
||||
|
||||
register_lingering("poison_plus", S("Lingering Poison Potion +"), "#557766", {
|
||||
potion_fun = function(player) mcl_potions.poison_func(player, 2.5, 90*0.25) end,
|
||||
tt = S("-1 HP / 2.5s | @1", time_string(90*0.25))
|
||||
})
|
||||
|
||||
register_lingering("regeneration", S("Lingering Regeneration Potion"), "#A52BB2", {
|
||||
potion_fun = function(player) mcl_potions.regeneration_func(player, 2.5, 45*0.25) end,
|
||||
tt = S("+1 HP / 2.5s | @1", time_string(45*0.25))
|
||||
})
|
||||
|
||||
register_lingering("regeneration_2", S("Lingering Regeneration Potion II"), "#B52CC2", {
|
||||
potion_fun = function(player) mcl_potions.regeneration_func(player, 1.2, 22*0.25) end,
|
||||
tt = S("+1 HP / 1.2s | @1", time_string(22*0.25))
|
||||
})
|
||||
|
||||
register_lingering("regeneration_plus", S("Lingering Regeneration Potion +"), "#C53DD3", {
|
||||
potion_fun = function(player) mcl_potions.regeneration_func(player, 2.5, 90*0.25) end,
|
||||
tt = S("+1 HP / 2.5s | @1", time_string(90*0.25))
|
||||
})
|
||||
|
||||
register_lingering("invisibility", S("Lingering Invisibility Potion"), "#B0B0B0", {
|
||||
potion_fun = function(player) mcl_potions.invisiblility_func(player, nil, mcl_potions.DURATION*0.25) end,
|
||||
tt = time_string(mcl_potions.DURATION*0.25)
|
||||
})
|
||||
|
||||
register_lingering("invisibility_plus", S("Lingering Invisibility Potion +"), "#A0A0A0", {
|
||||
potion_fun = function(player) mcl_potions.invisiblility_func(player, nil, mcl_potions.DURATION_PLUS*0.25) end,
|
||||
tt = time_string(mcl_potions.DURATION_PLUS*0.25)
|
||||
})
|
||||
|
||||
-- register_lingering("weakness", S("Lingering Weakness Potion"), "#6600AA", {
|
||||
-- potion_fun = function(player) mcl_potions.weakness_func(player, -4, mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25) end,
|
||||
-- -- TODO: Fix tooltip
|
||||
-- tt = time_string(mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25)
|
||||
-- })
|
||||
--
|
||||
-- register_lingering("weakness_plus", S("Lingering Weakness Potion +"), "#7700BB", {
|
||||
-- potion_fun = function(player) mcl_potions.weakness_func(player, -4, mcl_potions.DURATION_PLUS*mcl_potions.INV_FACTOR*0.25) end,
|
||||
-- -- TODO: Fix tooltip
|
||||
-- tt = time_string(mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25)
|
||||
-- })
|
||||
|
||||
register_lingering("fire_resistance", S("Lingering Fire Resistance Potion"), "#D0A040", {
|
||||
potion_fun = function(player) mcl_potions.fire_resistance_func(player, nil, mcl_potions.DURATION*0.25) end,
|
||||
tt = time_string(mcl_potions.DURATION*0.25)
|
||||
})
|
||||
|
||||
register_lingering("fire_resistance_plus", S("Lingering Fire Resistance Potion +"), "#E0B050", {
|
||||
potion_fun = function(player) mcl_potions.fire_resistance_func(player, nil, mcl_potions.DURATION_PLUS*0.25) end,
|
||||
tt = time_string(mcl_potions.DURATION_PLUS*0.25)
|
||||
})
|
||||
|
||||
-- register_lingering("strength", S("Lingering Strength Potion"), "#D444D4", {
|
||||
-- potion_fun = function(player) mcl_potions.strength_func(player, 3, mcl_potions.DURATION*0.25) end,
|
||||
-- -- TODO: Fix tooltip
|
||||
-- tt = time_string(mcl_potions.DURATION*0.25)
|
||||
-- })
|
||||
--
|
||||
-- register_lingering("strength_2", S("Lingering Strength Potion II"), "#D444F4", {
|
||||
-- potion_fun = function(player) mcl_potions.strength_func(player, 6, smcl_potions.DURATION_2*0.25) end,
|
||||
-- -- TODO: Fix tooltip
|
||||
-- tt = time_string(mcl_potions.DURATION_2*0.25)
|
||||
-- })
|
||||
--
|
||||
-- register_lingering("strength_plus", S("Lingering Strength Potion +"), "#D444E4", {
|
||||
-- potion_fun = function(player) mcl_potions.strength_func(player, 3, mcl_potions.DURATION_PLUS*0.25) end,
|
||||
-- -- TODO: Fix tooltip
|
||||
-- tt = time_string(mcl_potions.DURATION_PLUS*0.25)
|
||||
-- })
|
||||
|
||||
register_lingering("night_vision", S("Lingering Night Vision Potion"), "#1010AA", {
|
||||
potion_fun = function(player) mcl_potions.night_vision_func(player, nil, mcl_potions.DURATION*0.25) end,
|
||||
tt = time_string(mcl_potions.DURATION*0.25)
|
||||
})
|
||||
|
||||
register_lingering("night_vision_plus", S("Lingering Night Vision Potion +"), "#2020BA", {
|
||||
potion_fun = function(player) mcl_potions.night_vision_func(player, nil, mcl_potions.DURATION_PLUS*0.25) end,
|
||||
tt = time_string(mcl_potions.DURATION_PLUS*0.25)
|
||||
})
|
||||
-- -- register_lingering("weakness", S("Lingering Weakness Potion"), "#6600AA", {
|
||||
-- -- potion_fun = function(player) mcl_potions.weakness_func(player, -4, mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25) end,
|
||||
-- -- -- TODO: Fix tooltip
|
||||
-- -- tt = time_string(mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25)
|
||||
-- -- })
|
||||
-- --
|
||||
-- -- register_lingering("weakness_plus", S("Lingering Weakness Potion +"), "#7700BB", {
|
||||
-- -- potion_fun = function(player) mcl_potions.weakness_func(player, -4, mcl_potions.DURATION_PLUS*mcl_potions.INV_FACTOR*0.25) end,
|
||||
-- -- -- TODO: Fix tooltip
|
||||
-- -- tt = time_string(mcl_potions.DURATION*mcl_potions.INV_FACTOR*0.25)
|
||||
-- -- })
|
||||
-- --
|
||||
-- -- register_lingering("strength", S("Lingering Strength Potion"), "#D444D4", {
|
||||
-- -- potion_fun = function(player) mcl_potions.strength_func(player, 3, mcl_potions.DURATION*0.25) end,
|
||||
-- -- -- TODO: Fix tooltip
|
||||
-- -- tt = time_string(mcl_potions.DURATION*0.25)
|
||||
-- -- })
|
||||
-- --
|
||||
-- -- register_lingering("strength_2", S("Lingering Strength Potion II"), "#D444F4", {
|
||||
-- -- potion_fun = function(player) mcl_potions.strength_func(player, 6, smcl_potions.DURATION_2*0.25) end,
|
||||
-- -- -- TODO: Fix tooltip
|
||||
-- -- tt = time_string(mcl_potions.DURATION_2*0.25)
|
||||
-- -- })
|
||||
-- --
|
||||
-- -- register_lingering("strength_plus", S("Lingering Strength Potion +"), "#D444E4", {
|
||||
-- -- potion_fun = function(player) mcl_potions.strength_func(player, 3, mcl_potions.DURATION_PLUS*0.25) end,
|
||||
-- -- -- TODO: Fix tooltip
|
||||
-- -- tt = time_string(mcl_potions.DURATION_PLUS*0.25)
|
||||
-- -- })
|
||||
|
|
|
@ -40,6 +40,8 @@ local function register_potion(def)
|
|||
if def.name == "poison" or def.name == "regeneration" then
|
||||
_tt = "1/2 Heart/"..effect.."sec | "..time_string(dur)
|
||||
end
|
||||
elseif def.name == "healing" or def.name == "harming" then
|
||||
_tt = (effect / 2).." Hearts"
|
||||
else
|
||||
_tt = tt or time_string(dur) or S("No effect")
|
||||
end
|
||||
|
@ -47,13 +49,21 @@ local function register_potion(def)
|
|||
end
|
||||
|
||||
local function get_splash_fun(effect, sp_dur)
|
||||
if def.dur then
|
||||
if def.is_dur then
|
||||
return function(player, redx) def.on_use(player, effect, sp_dur*redx) end
|
||||
else
|
||||
return function(player, redx) def.on_use(player, effect*redx, sp_dur) end
|
||||
end
|
||||
end
|
||||
|
||||
local function get_lingering_fun(effect, sp_dur)
|
||||
if def.is_dur then
|
||||
return function(player, redx) def.on_use(player, effect, sp_dur) end
|
||||
else
|
||||
return function(player, redx) def.on_use(player, effect*0.5, sp_dur) end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_craftitem("mcl_potions:"..def.name, {
|
||||
description = S(def.description),
|
||||
_tt_help = get_tt(def._tt, def.effect, dur),
|
||||
|
@ -67,18 +77,23 @@ local function register_potion(def)
|
|||
on_secondary_use = on_use,
|
||||
})
|
||||
|
||||
-- Register Splash
|
||||
-- Register Splash and Lingering
|
||||
local splash_dur = dur * mcl_potions.SPLASH_FACTOR
|
||||
local ling_dur = dur * mcl_potions.LINGERING_FACTOR
|
||||
|
||||
local splash_def = {
|
||||
tt = get_tt(def._tt, def.effect, splash_dur),
|
||||
potion_fun = get_splash_fun(def.effect, splash_dur),
|
||||
}
|
||||
local ling_def = {
|
||||
tt = get_tt(def._tt, def.effect, ling_dur),
|
||||
potion_fun = get_lingering_fun(def.effect, ling_dur),
|
||||
}
|
||||
if def.color then
|
||||
mcl_potions.register_splash(def.name, S("Splash "..def.description), def.color, splash_def)
|
||||
mcl_potions.register_lingering(def.name, S("Lingering "..def.description), def.color, ling_def)
|
||||
end
|
||||
|
||||
|
||||
if def.is_II then
|
||||
|
||||
local desc_mod = " II"
|
||||
|
@ -121,15 +136,21 @@ local function register_potion(def)
|
|||
on_secondary_use = on_use,
|
||||
})
|
||||
|
||||
-- Register Splash
|
||||
-- Register Splash and Lingering
|
||||
local splash_dur_2 = dur_2 * mcl_potions.SPLASH_FACTOR
|
||||
local ling_dur_2 = dur_2 * mcl_potions.LINGERING_FACTOR
|
||||
|
||||
local splash_def_2 = {
|
||||
tt = get_tt(def._tt_2, effect_II, splash_dur_2),
|
||||
potion_fun = get_splash_fun(effect_II, splash_dur_2),
|
||||
}
|
||||
local ling_def_2 = {
|
||||
tt = get_tt(def._tt_2, effect_II, ling_dur_2),
|
||||
potion_fun = get_lingering_fun(effect_II, ling_dur_2),
|
||||
}
|
||||
if def.color then
|
||||
mcl_potions.register_splash(def.name.."_2", S("Splash "..def.description..desc_mod), def.color, splash_def_2)
|
||||
mcl_potions.register_lingering(def.name.."_2", S("Lingering "..def.description..desc_mod), def.color, ling_def_2)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -163,13 +184,19 @@ local function register_potion(def)
|
|||
|
||||
-- Register Splash
|
||||
local splash_dur_pl = dur_pl * mcl_potions.SPLASH_FACTOR
|
||||
local ling_dur_pl = dur_pl * mcl_potions.LINGERING_FACTOR
|
||||
|
||||
local splash_def_pl = {
|
||||
tt = get_tt(def._tt_plus, def.effect, splash_dur_pl),
|
||||
potion_fun = get_splash_fun(def.effect, splash_dur_pl),
|
||||
}
|
||||
local ling_def_pl = {
|
||||
tt = get_tt(def._tt_plus, def.effect, ling_dur_pl),
|
||||
potion_fun = get_lingering_fun(def.effect, ling_dur_pl),
|
||||
}
|
||||
if def.color then
|
||||
mcl_potions.register_splash(def.name.."_plus", S("Splash "..def.description.." +"), def.color, splash_def_pl)
|
||||
mcl_potions.register_lingering(def.name.."_plus", S("Lingering "..def.description.." +"), def.color, ling_def_pl)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -225,10 +252,8 @@ local healing_def = {
|
|||
_longdesc = S("Drink to heal yourself"),
|
||||
color = "#CC0000",
|
||||
effect = 4,
|
||||
dur = nil,
|
||||
on_use = mcl_potions.healing_func,
|
||||
is_II = true,
|
||||
effect_sq = false,
|
||||
}
|
||||
|
||||
|
||||
|
@ -240,9 +265,9 @@ local harming_def = {
|
|||
_longdesc = S("Drink to heal yourself"),
|
||||
color = "#660099",
|
||||
effect = -6,
|
||||
dur = nil,
|
||||
on_use = mcl_potions.healing_func,
|
||||
is_II = true,
|
||||
is_inv = true,
|
||||
}
|
||||
|
||||
local night_vision_def = {
|
||||
|
|
Loading…
Reference in New Issue