2019-10-02 21:13:14 +02:00
|
|
|
--Central to add all player modifiers together.
|
2020-01-01 19:25:14 +02:00
|
|
|
--Will overwrite character stats from other mods.
|
2019-10-02 21:13:14 +02:00
|
|
|
|
2020-05-09 10:04:24 +02:00
|
|
|
local Global = require 'utils.global'
|
2019-11-10 23:02:45 +02:00
|
|
|
|
2020-07-21 14:41:39 +02:00
|
|
|
local this = {
|
|
|
|
disabled_modifier = {}
|
|
|
|
}
|
2019-11-10 23:02:45 +02:00
|
|
|
|
2020-05-09 10:04:24 +02:00
|
|
|
Global.register(
|
|
|
|
this,
|
|
|
|
function(t)
|
|
|
|
this = t
|
|
|
|
end
|
|
|
|
)
|
2019-11-10 23:02:45 +02:00
|
|
|
|
2019-10-28 18:38:36 +02:00
|
|
|
local Public = {}
|
|
|
|
|
2019-11-10 23:02:45 +02:00
|
|
|
function Public.get_table()
|
2020-05-09 10:04:24 +02:00
|
|
|
return this
|
2019-11-10 23:02:45 +02:00
|
|
|
end
|
|
|
|
|
2019-10-02 21:13:14 +02:00
|
|
|
local modifiers = {
|
2020-05-09 10:04:24 +02:00
|
|
|
'character_build_distance_bonus',
|
|
|
|
'character_crafting_speed_modifier',
|
|
|
|
'character_health_bonus',
|
|
|
|
'character_inventory_slots_bonus',
|
|
|
|
'character_item_drop_distance_bonus',
|
|
|
|
'character_item_pickup_distance_bonus',
|
|
|
|
'character_loot_pickup_distance_bonus',
|
|
|
|
'character_mining_speed_modifier',
|
|
|
|
'character_reach_distance_bonus',
|
|
|
|
'character_resource_reach_distance_bonus',
|
2020-05-19 23:00:52 +02:00
|
|
|
'character_maximum_following_robot_count_bonus',
|
2020-05-09 10:04:24 +02:00
|
|
|
'character_running_speed_modifier'
|
2019-10-02 21:13:14 +02:00
|
|
|
}
|
|
|
|
|
2019-10-28 18:38:36 +02:00
|
|
|
function Public.update_player_modifiers(player)
|
2020-05-09 10:04:24 +02:00
|
|
|
for _, modifier in pairs(modifiers) do
|
|
|
|
local sum_value = 0
|
|
|
|
for _, value in pairs(this[player.index][modifier]) do
|
|
|
|
sum_value = sum_value + value
|
|
|
|
end
|
|
|
|
if player.character then
|
2020-07-21 14:41:39 +02:00
|
|
|
if this.disabled_modifier[player.index] and this.disabled_modifier[player.index][modifier] then
|
|
|
|
player[modifier] = 0
|
|
|
|
else
|
|
|
|
player[modifier] = sum_value
|
|
|
|
end
|
2020-05-09 10:04:24 +02:00
|
|
|
end
|
|
|
|
end
|
2019-10-02 21:13:14 +02:00
|
|
|
end
|
|
|
|
|
2020-12-29 01:02:31 +02:00
|
|
|
function Public.reset_player_modifiers(player)
|
|
|
|
if player and player.valid then
|
|
|
|
this[player.index] = {}
|
|
|
|
if this.disabled_modifier[player.index] then
|
|
|
|
this.disabled_modifier[player.index] = {}
|
|
|
|
end
|
|
|
|
for _, modifier in pairs(modifiers) do
|
|
|
|
this[player.index][modifier] = {}
|
|
|
|
end
|
|
|
|
Public.update_player_modifiers(player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-02 21:13:14 +02:00
|
|
|
local function on_player_joined_game(event)
|
2020-12-29 01:02:31 +02:00
|
|
|
local player = game.get_player(event.player_index)
|
|
|
|
if this[player.index] then
|
|
|
|
Public.update_player_modifiers(player)
|
2020-05-09 10:04:24 +02:00
|
|
|
return
|
|
|
|
end
|
2020-12-29 01:02:31 +02:00
|
|
|
Public.reset_player_modifiers(player)
|
2019-10-02 21:13:14 +02:00
|
|
|
end
|
|
|
|
|
2020-05-09 10:04:24 +02:00
|
|
|
local function on_player_respawned(event)
|
|
|
|
Public.update_player_modifiers(game.players[event.player_index])
|
2020-01-01 19:25:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local Event = require 'utils.event'
|
2019-11-10 23:02:45 +02:00
|
|
|
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
2020-01-01 19:25:14 +02:00
|
|
|
Event.add(defines.events.on_player_respawned, on_player_respawned)
|
2019-10-28 18:38:36 +02:00
|
|
|
|
2020-01-03 21:46:18 +02:00
|
|
|
return Public
|