Various adjustments and fixes

This commit is contained in:
Till Affeldt
2020-05-12 16:00:24 +02:00
parent 4df9a61374
commit f42b4183e5
15 changed files with 298 additions and 76 deletions

View File

@ -3,7 +3,7 @@
Use this effect to damage a player during dangerous weather events.
Expects a table as the parameter containing the following values:
- value <int> [1]: The amount of damage to be applied per successful roll.
- chance <int> [1]: Defines a 1/x roll per cycle for the player to get damaged. Higher values result in less frequent damage.
- rarity <int> [1]: Defines a 1/x chance per cycle for the player to get damaged. Higher values result in less frequent damage.
- check <table> [nil]: Use an additional outdoors check before applying damage. Consists of the following values:
- type <"light"|"raycast"> ["light"] (Whether the light level should be used a raycast should be performed)
- height <number> [0] (Height offset of weather origin from the player. Only used for raycasts)
@ -58,9 +58,9 @@ end
local function calc_damage(player, dmg)
if dmg.value == nil then dmg.value = 1 end
if dmg.chance == nil then dmg.chance = 1 end
if dmg.rarity == nil then dmg.rarity = 1 end
-- check if damage should be applied
if rng:next(1, dmg.chance) ~= 1 then return 0 end
if rng:next(1, dmg.rarity) ~= 1 then return 0 end
if dmg.check ~= nil then
-- check for obstacles in the way
if not check_hit(player, dmg.check) then return 0 end
@ -81,4 +81,3 @@ local function handle_effect(player_data)
end
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.MEDIUM_CYCLE)

View File

@ -95,4 +95,3 @@ end
climate_api.register_effect(EFFECT_NAME, start_effect, "start")
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.register_effect(EFFECT_NAME, stop_effect, "stop")
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.MEDIUM_CYCLE)

View File

@ -10,29 +10,33 @@ Furthermore, the following default values have been changed:
- collisiondetection <bool> [true]
- collision_removal <bool> [true]
- playername <string> [current player] (Set to empty string to show for everyone)
- vertical <bool> [nil] (Unless explicitly set, particle facing rotation will be automatically set based on direction of velocity)
The following optional values have been introduced or expanded for convenience:
- size <int> [nil] (Overrides both minsize and maxsize if set)
The following optional values have been introduced for convenience:
- boxsize <vector> [nil] (Overrides minpos and maxpos based on specified sizes per direction with the player in the center)
- boxsize <number> [nil] (If set to a number, the resulting vector will have the specified size in all directions)
- v_offset <int> [0] (Use in conjunctin with boxsize. Adds specified height to minpos and maxpos y-coordinates)
- attach_to_player <bool> [false] (Overrides attached object with current player)
The following optional values have been expanded with additional value types for convenience:
- size <int> [nil] (Overrides both minsize and maxsize if set)
- minvel <int> [nil] (Overrides minvel with a downward facing vector of specified length)
- maxvel <int> [nil] (Overrides maxvel with a downward facing vector of specified length)
- velocity <vector | int> [nil] (Overrides both minvel and maxvel if set)
- minacc <int> [nil] (Overrides minacc with a downward facing vector of specified length)
- maxacc <int> [nil] (Overrides maxacc with a downward facing vector of specified length)
- acceleration <vector | int> [nil] (Overrides both minacc and maxacc if set)
- attach_to_player <bool> [false] (Overrides attached object with current player)
The following new behaviours have been introduced:
- use_wind <bool> [true] (Adjusts velocity and position for current windspeed)
- detached <bool> [false] (Unless enabled, considers positions as relative to current player like being attached)
- vertical <bool> [nil] (Unless explicitly set, will be automatically set based on direction of velocity)
- detach <bool> [false] (Unless enabled, considers positions as relative to current player as if spawner's position would be attached)
- adjust_for_velocity <bool> [true] (Corrects position of particle spawner by player's movement speed. Only applicable if detach = false and not manually attached)
]]
if not climate_mod.settings.particles then return end
local EFFECT_NAME = "climate_api:particles"
local CYCLE_LENGTH = climate_api.SHORT_CYCLE
-- parse config by injecting default values and adding additional parameters
local function parse_config(player, particles)
@ -44,7 +48,8 @@ local function parse_config(player, particles)
playername = player:get_player_name(),
use_wind = true,
attach_to_player = false,
detached = false
detach = false,
adjust_for_velocity = true
}
-- inject missing default values into specified config
@ -153,12 +158,20 @@ local function parse_config(player, particles)
config.attach_to_player = nil
-- attach coordinates to player unless specified or already attached
if (not config.detached) and config.attached == nil then
if (not config.detach) and config.attached == nil then
local ppos = player:get_pos()
config.minpos = vector.add(config.minpos, ppos)
config.maxpos = vector.add(config.maxpos, ppos)
-- correct spawn coordinates to adjust for player movement
if config.adjust_for_velocity then
local velocity = player:get_player_velocity()
config.minpos = vector.add(config.minpos, velocity)
config.maxpos = vector.add(config.maxpos, velocity)
end
end
config.detached = nil
config.detach = nil
config.adjust_for_velocity = nil
-- move particles in wind direction
if config.use_wind then
@ -198,4 +211,4 @@ local function handle_effect(player_data)
end
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.SHORT_CYCLE)
climate_api.set_effect_cycle(EFFECT_NAME, CYCLE_LENGTH)

View File

@ -18,26 +18,26 @@ local function handle_effect(player_data, prev_data)
for playername, data in pairs(prev_data) do
for weather, _ in pairs(data) do
if player_data[playername] == nil or player_data[playername][weather] == nil then
climate_api.skybox.remove_layer(playername, weather)
climate_api.skybox.remove(playername, weather)
end
end
end
for playername, data in pairs(player_data) do
for weather, value in pairs(data) do
climate_api.skybox.add_layer(playername, weather, value)
climate_api.skybox.add(playername, weather, value)
end
climate_api.skybox.update_skybox(playername)
climate_api.skybox.update(playername)
end
end
local function remove_effect(player_data)
for playername, data in pairs(player_data) do
for weather, _ in pairs(data) do
climate_api.skybox.remove_layer(playername, weather)
climate_api.skybox.remove(playername, weather)
end
climate_api.skybox.update(playername)
end
end
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.register_effect(EFFECT_NAME, remove_effect, "stop")
climate_api.set_effect_cycle("climate_api:skybox", climate_api.MEDIUM_CYCLE)

View File

@ -60,4 +60,3 @@ end
climate_api.register_effect(EFFECT_NAME, start_effect, "start")
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.register_effect(EFFECT_NAME, stop_effect, "stop")
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.MEDIUM_CYCLE)