mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 13:53:45 +01:00
Reimplemented /effect heal and fixed bugs
-heal subcommand to the /effect reimplemented -healing_func() from old API standardized, included in new API -(the last point is due to it being substantially different from others) -fixed a few bugs, potential crashes -fixed incorrect withering effect progression -standardized variable naming
This commit is contained in:
parent
d1ca0f23f0
commit
5827a7638d
@ -9,8 +9,8 @@ local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
|
||||
minetest.register_chatcommand("effect",{
|
||||
params = S("<effect> <duration> [<level>] [<factor>]"),
|
||||
description = S("Add a status effect to yourself. Arguments: <effect>: name of status effect, e.g. poison. <duration>: duration in seconds. <level>: effect power determinant, bigger level results in more powerful effect for effects that depend on the level, defaults to 1, pass F to use low-level factor instead. <factor>: effect strength modifier, can mean different things depending on the effect."),
|
||||
params = S("<effect>|heal|list <duration|heal-amount> [<level>] [<factor>]"),
|
||||
description = S("Add a status effect to yourself. Arguments: <effect>: name of status effect, e.g. poison. Passing list as effect name lists available effects. Passing heal as effect name heals (or harms) by amount designed by the next parameter. <duration>: duration in seconds. (<heal-amount>: amount of healing when the effect is heal, passing a negative value subtracts health.) <level>: effect power determinant, bigger level results in more powerful effect for effects that depend on the level, defaults to 1, pass F to use low-level factor instead. <factor>: effect strength modifier, can mean different things depending on the effect."),
|
||||
privs = {server = true},
|
||||
func = function(name, params)
|
||||
|
||||
@ -30,6 +30,20 @@ minetest.register_chatcommand("effect",{
|
||||
effects = effects .. ", " .. name
|
||||
end
|
||||
return true, effects
|
||||
elseif P[1] == "heal" then
|
||||
local hp = tonumber(P[2])
|
||||
if not hp or hp == 0 then
|
||||
return false, S("Missing or invalid heal amount parameter!")
|
||||
else
|
||||
mcl_potions.healing_func(minetest.get_player_by_name(name), hp)
|
||||
if hp > 0 then
|
||||
if hp < 1 then hp = 1 end
|
||||
return true, S("Player @1 healed by @2 HP.", name, hp)
|
||||
else
|
||||
if hp > -1 then hp = -1 end
|
||||
return true, S("Player @1 harmed by @2 HP.", name, hp)
|
||||
end
|
||||
end
|
||||
elseif not tonumber(P[2]) then
|
||||
return false, S("Missing or invalid duration parameter!")
|
||||
elseif P[3] and not tonumber(P[3]) and P[3] ~= "F" then
|
||||
|
@ -330,7 +330,7 @@ mcl_potions.register_effect({
|
||||
particle_color = "#000000",
|
||||
uses_factor = true,
|
||||
lvl1_factor = 2,
|
||||
lvl2_factor = 0.5,
|
||||
lvl2_factor = 1,
|
||||
timer_uses_factor = true,
|
||||
})
|
||||
|
||||
@ -444,7 +444,7 @@ minetest.register_globalstep(function(dtime)
|
||||
end
|
||||
end
|
||||
|
||||
if EF[name][object].timer >= vals.dur then
|
||||
if not EF[name][object] or EF[name][object].timer >= vals.dur then
|
||||
if effect.on_end then effect.on_end(object) end
|
||||
EF[name][object] = nil
|
||||
if object:is_player() then
|
||||
@ -684,13 +684,13 @@ function mcl_potions.make_invisible(obj_ref, hide)
|
||||
mcl_player.player_set_visibility(obj_ref, true)
|
||||
obj_ref:set_nametag_attributes({ color = { r = 255, g = 255, b = 255, a = 255 } })
|
||||
end
|
||||
else
|
||||
else -- TODO make below section (and preferably other effects on mobs) rely on metadata
|
||||
if hide then
|
||||
local luaentity = obj_ref:get_luaentity()
|
||||
EF.invisible[obj_ref].old_size = luaentity.visual_size
|
||||
EF.invisibility[obj_ref].old_size = luaentity.visual_size
|
||||
obj_ref:set_properties({ visual_size = { x = 0, y = 0 } })
|
||||
else
|
||||
obj_ref:set_properties({ visual_size = EF.invisible[obj_ref].old_size })
|
||||
obj_ref:set_properties({ visual_size = EF.invisibility[obj_ref].old_size })
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -814,11 +814,11 @@ function mcl_potions.give_effect_by_level(name, object, level, duration)
|
||||
return mcl_potions.give_effect(name, object, factor, duration)
|
||||
end
|
||||
|
||||
function mcl_potions.healing_func(player, hp)
|
||||
if not player or player:get_hp() <= 0 then return false end
|
||||
local obj = player:get_luaentity()
|
||||
function mcl_potions.healing_func(object, hp)
|
||||
if not object or object:get_hp() <= 0 then return false end
|
||||
local ent = object:get_luaentity()
|
||||
|
||||
if obj and obj.harmed_by_heal then hp = -hp end
|
||||
if ent and ent.harmed_by_heal then hp = -hp end
|
||||
|
||||
if hp > 0 then
|
||||
-- at least 1 HP
|
||||
@ -826,10 +826,10 @@ function mcl_potions.healing_func(player, hp)
|
||||
hp = 1
|
||||
end
|
||||
|
||||
if obj and obj.is_mob then
|
||||
obj.health = math.max(obj.health + hp, obj.hp_max)
|
||||
elseif player:is_player() then
|
||||
player:set_hp(math.min(player:get_hp() + hp, player:get_properties().hp_max), { type = "set_hp", other = "healing" })
|
||||
if ent and ent.is_mob then
|
||||
ent.health = math.min(ent.health + hp, ent.hp_max)
|
||||
elseif object:is_player() then
|
||||
object:set_hp(math.min(object:get_hp() + hp, object:get_properties().hp_max), { type = "set_hp", other = "healing" })
|
||||
end
|
||||
|
||||
elseif hp < 0 then
|
||||
@ -837,57 +837,57 @@ function mcl_potions.healing_func(player, hp)
|
||||
hp = -1
|
||||
end
|
||||
|
||||
mcl_util.deal_damage(player, -hp, {type = "magic"})
|
||||
mcl_util.deal_damage(object, -hp, {type = "magic"})
|
||||
end
|
||||
end
|
||||
|
||||
function mcl_potions.strength_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("strength", player, factor, duration)
|
||||
function mcl_potions.strength_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("strength", object, factor, duration)
|
||||
end
|
||||
function mcl_potions.leaping_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("leaping", player, factor, duration)
|
||||
function mcl_potions.leaping_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("leaping", object, factor, duration)
|
||||
end
|
||||
function mcl_potions.weakness_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("weakness", player, factor, duration)
|
||||
function mcl_potions.weakness_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("weakness", object, factor, duration)
|
||||
end
|
||||
function mcl_potions.swiftness_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("swiftness", player, factor, duration)
|
||||
function mcl_potions.swiftness_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("swiftness", object, factor, duration)
|
||||
end
|
||||
function mcl_potions.slowness_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("slowness", player, factor, duration)
|
||||
function mcl_potions.slowness_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("slowness", object, factor, duration)
|
||||
end
|
||||
|
||||
function mcl_potions.withering_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("withering", player, factor, duration)
|
||||
function mcl_potions.withering_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("withering", object, factor, duration)
|
||||
end
|
||||
|
||||
|
||||
function mcl_potions.poison_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("poison", player, factor, duration)
|
||||
function mcl_potions.poison_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("poison", object, factor, duration)
|
||||
end
|
||||
|
||||
|
||||
function mcl_potions.regeneration_func(player, factor, duration)
|
||||
return mcl_potions.give_effect("regeneration", player, factor, duration)
|
||||
function mcl_potions.regeneration_func(object, factor, duration)
|
||||
return mcl_potions.give_effect("regeneration", object, factor, duration)
|
||||
end
|
||||
|
||||
|
||||
function mcl_potions.invisiblility_func(player, null, duration)
|
||||
return mcl_potions.give_effect("invisibility", player, null, duration)
|
||||
function mcl_potions.invisiblility_func(object, null, duration)
|
||||
return mcl_potions.give_effect("invisibility", object, null, duration)
|
||||
end
|
||||
|
||||
function mcl_potions.water_breathing_func(player, null, duration)
|
||||
return mcl_potions.give_effect("water_breathing", player, null, duration)
|
||||
function mcl_potions.water_breathing_func(object, null, duration)
|
||||
return mcl_potions.give_effect("water_breathing", object, null, duration)
|
||||
end
|
||||
|
||||
|
||||
function mcl_potions.fire_resistance_func(player, null, duration)
|
||||
return mcl_potions.give_effect("fire_resistance", player, null, duration)
|
||||
function mcl_potions.fire_resistance_func(object, null, duration)
|
||||
return mcl_potions.give_effect("fire_resistance", object, null, duration)
|
||||
end
|
||||
|
||||
|
||||
function mcl_potions.night_vision_func(player, null, duration)
|
||||
return mcl_potions.give_effect("night_vision", player, null, duration)
|
||||
function mcl_potions.night_vision_func(object, null, duration)
|
||||
return mcl_potions.give_effect("night_vision", object, null, duration)
|
||||
end
|
||||
|
||||
function mcl_potions._extinguish_nearby_fire(pos, radius)
|
||||
@ -941,18 +941,6 @@ function mcl_potions._extinguish_nearby_fire(pos, radius)
|
||||
return exting
|
||||
end
|
||||
|
||||
function mcl_potions.bad_omen_func(player, factor, duration)
|
||||
mcl_potions.give_effect("bad_omen", player, factor, duration)
|
||||
-- if not EF.bad_omen[player] then
|
||||
-- EF.bad_omen[player] = {dur = duration, timer = 0, factor = factor}
|
||||
-- else
|
||||
-- local victim = EF.bad_omen[player]
|
||||
-- victim.dur = math.max(duration, victim.dur - victim.timer)
|
||||
-- victim.timer = 0
|
||||
-- victim.factor = factor
|
||||
-- end
|
||||
--
|
||||
-- if player:is_player() then
|
||||
-- potions_set_icons(player)
|
||||
-- end
|
||||
function mcl_potions.bad_omen_func(object, factor, duration)
|
||||
mcl_potions.give_effect("bad_omen", object, factor, duration)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user