0
0
Fork 0

Added mcl_luck API

Luck and Bad Luck effects use the mcl_luck API now
The API is unused for now
This commit is contained in:
the-real-herowl 2024-03-21 01:27:11 +01:00
parent c503a5fb8c
commit b28467d348
3 changed files with 46 additions and 4 deletions

View File

@ -610,10 +610,13 @@ mcl_potions.register_effect({
return (not object:is_player())
end,
on_start = function(object, factor)
-- mcl_luck.add_luck_modifier(object, "mcl_potions:luck", factor)
mcl_luck.apply_luck_modifier(object:get_player_name(), "mcl_potions:luck", factor)
end,
on_load = function(object, factor)
mcl_luck.apply_luck_modifier(object:get_player_name(), "mcl_potions:luck", factor)
end,
on_end = function(object)
-- mcl_luck.remove_luck_modifier(object, "mcl_potions:luck")
mcl_luck.remove_luck_modifier(object:get_player_name(), "mcl_potions:luck")
end,
uses_factor = true,
})
@ -626,10 +629,13 @@ mcl_potions.register_effect({
return (not object:is_player())
end,
on_start = function(object, factor)
-- mcl_luck.add_luck_modifier(object, "mcl_potions:bad_luck", -factor)
mcl_luck.apply_luck_modifier(object:get_player_name(), "mcl_potions:bad_luck", -factor)
end,
on_load = function(object, factor)
mcl_luck.apply_luck_modifier(object:get_player_name(), "mcl_potions:bad_luck", -factor)
end,
on_end = function(object)
-- mcl_luck.remove_luck_modifier(object, "mcl_potions:bad_luck")
mcl_luck.remove_luck_modifier(object:get_player_name(), "mcl_potions:bad_luck")
end,
uses_factor = true,
})

View File

@ -0,0 +1,33 @@
mcl_luck = {}
-- table indexed by player name
-- each entry for each player contains list of modifiers applied to the player
-- modifiers are listed by their name (defined when applying them)
-- all modifiers are dynamic (they are removed when the player leaves game and on server shutdown)
local applied_luck = {}
function mcl_luck.apply_luck_modifier(player_name, modifier_name, amount)
applied_luck[player_name][modifier_name] = amount
end
function mcl_luck.remove_luck_modifier(player_name, modifier_name)
applied_luck[player_name][modifier_name] = nil
end
function mcl_luck.get_luck(player_name)
local luck = 0
for _, amount in pairs(applied_luck[player_name]) do
luck = luck + amount
end
return luck
end
minetest.register_on_joinplayer(function(player)
local player_name = player:get_player_name()
applied_luck[player_name] = {}
end)
minetest.register_on_leaveplayer(function(player)
local player_name = player:get_player_name()
applied_luck[player_name] = nil
end)

View File

@ -0,0 +1,3 @@
name = mcl_luck
author = Herowl
description = An API for handling luck, it can be polled by random events.