mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 02:21:06 +01:00
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:
parent
c503a5fb8c
commit
b28467d348
3 changed files with 46 additions and 4 deletions
|
@ -610,10 +610,13 @@ mcl_potions.register_effect({
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
on_start = function(object, factor)
|
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,
|
end,
|
||||||
on_end = function(object)
|
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,
|
end,
|
||||||
uses_factor = true,
|
uses_factor = true,
|
||||||
})
|
})
|
||||||
|
@ -626,10 +629,13 @@ mcl_potions.register_effect({
|
||||||
return (not object:is_player())
|
return (not object:is_player())
|
||||||
end,
|
end,
|
||||||
on_start = function(object, factor)
|
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,
|
end,
|
||||||
on_end = function(object)
|
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,
|
end,
|
||||||
uses_factor = true,
|
uses_factor = true,
|
||||||
})
|
})
|
||||||
|
|
33
mods/PLAYER/mcl_luck/init.lua
Normal file
33
mods/PLAYER/mcl_luck/init.lua
Normal 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)
|
3
mods/PLAYER/mcl_luck/mod.conf
Normal file
3
mods/PLAYER/mcl_luck/mod.conf
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
name = mcl_luck
|
||||||
|
author = Herowl
|
||||||
|
description = An API for handling luck, it can be polled by random events.
|
Loading…
Reference in a new issue