From e874daa894be415c654914d6d396e27b90695ca2 Mon Sep 17 00:00:00 2001 From: Till Affeldt Date: Tue, 12 May 2020 16:01:13 +0200 Subject: [PATCH] Adjust lightning chances and update speed buff to new API --- ca_effects/lightning.lua | 16 +++++++++++----- ca_effects/speed_buff.lua | 4 ++-- ca_weathers/hail.lua | 4 +++- ca_weathers/rain_heavy.lua | 2 ++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ca_effects/lightning.lua b/ca_effects/lightning.lua index f0416e3..2914d3d 100644 --- a/ca_effects/lightning.lua +++ b/ca_effects/lightning.lua @@ -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) diff --git a/ca_effects/speed_buff.lua b/ca_effects/speed_buff.lua index b8e4565..8450898 100644 --- a/ca_effects/speed_buff.lua +++ b/ca_effects/speed_buff.lua @@ -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 diff --git a/ca_weathers/hail.lua b/ca_weathers/hail.lua index cb8beb0..14722cd 100644 --- a/ca_weathers/hail.lua +++ b/ca_weathers/hail.lua @@ -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, diff --git a/ca_weathers/rain_heavy.lua b/ca_weathers/rain_heavy.lua index 7cfbc04..4230cb0 100644 --- a/ca_weathers/rain_heavy.lua +++ b/ca_weathers/rain_heavy.lua @@ -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,