Adjust lightning chances and update speed buff to new API

This commit is contained in:
Till Affeldt 2020-05-12 16:01:13 +02:00
parent 231642af2f
commit e874daa894
4 changed files with 18 additions and 8 deletions

View File

@ -1,15 +1,14 @@
--[[
# Lightning Effect
Use this effect to cause lightning strikes.
Requires lightning mod in order to function.
Uses default lightning configuration. Expects any non-nil parameter.
Requires lightning mod in order to function. Uses default lightning configuration.
Expects an integer indicating a chance (between 0 and 1) for lightning to strike (per cycle and player).
]]
if not minetest.get_modpath("lightning") then return end
local EFFECT_NAME = "regional_weather:lightning"
local LIGHTNING_CHANCE = 20
lightning.auto = false
local rng = PcgRandom(82492402425)
@ -39,8 +38,15 @@ end
local function handle_effect(player_data)
for playername, data in pairs(player_data) do
local random = rng:next(1, LIGHTNING_CHANCE)
if random == 1 then
local chance = 0
for weather, value in pairs(data) do
if type(value) ~= "number" then
value = 1/20
end
chance = chance + value - (chance * value)
end
local random = math.random()
if random <= chance then
local player = minetest.get_player_by_name(playername)
local ppos = player:get_pos()
local position = choose_pos(ppos)

View File

@ -13,14 +13,14 @@ local function handle_effect(player_data)
for weather, value in pairs(data) do
product = product * value
end
climate_api.utility.add_physics(EFFECT_NAME, player, "speed", product)
climate_api.player_physics.add(EFFECT_NAME, player, "speed", product)
end
end
local function remove_effect(player_data)
for playername, data in ipairs(player_data) do
local player = minetest.get_player_by_name(playername)
climate_api.utility.remove_physics(EFFECT_NAME, player, "speed")
climate_api.player_physics.remove(EFFECT_NAME, player, "speed")
end
end

View File

@ -26,13 +26,15 @@ effects["climate_api:sound"] = {
gain = 1
}
effects["regional_weather:lightning"] = 1 / 30
local textures = {}
for i = 1,5 do
textures[i] = "weather_hail" .. i .. ".png"
end
effects["climate_api:particles"] = {
boxsize = { x = 18, y = 0, z = 18},
boxsize = { x = 18, y = 0, z = 18 },
v_offset = 7,
velocity = 20,
amount = 6,

View File

@ -22,6 +22,8 @@ effects["climate_api:sound"] = {
gain = 1
}
effects["regional_weather:lightning"] = 1 / 20
effects["climate_api:particles"] = {
boxsize = { x = 18, y = 0, z = 18 },
v_offset = 7,