1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/player_modifiers.lua

52 lines
1.2 KiB
Lua
Raw Normal View History

2019-10-02 21:13:14 +02:00
--Central to add all player modifiers together.
local Global = require "utils.global"
local Event = require 'utils.event'
local this = {}
Global.register(this, function(t) this = t end)
2019-10-28 18:38:36 +02:00
local Public = {}
function Public.get_table()
return this
end
2019-10-02 21:13:14 +02:00
local modifiers = {
"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",
"character_running_speed_modifier",
}
2019-10-28 18:38:36 +02:00
function Public.update_player_modifiers(player)
2019-10-02 21:13:14 +02:00
for _, modifier in pairs(modifiers) do
local sum_value = 0
for _, value in pairs(this[player.index][modifier]) do
2019-10-02 21:13:14 +02:00
sum_value = sum_value + value
end
2019-10-17 00:06:18 +02:00
if player.character then
player[modifier] = sum_value
end
2019-10-02 21:13:14 +02:00
end
end
local function on_player_joined_game(event)
if this[event.player_index] then return end
this[event.player_index] = {}
2019-10-02 21:13:14 +02:00
for _, modifier in pairs(modifiers) do
this[event.player_index][modifier] = {}
2019-10-02 21:13:14 +02:00
end
end
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
2019-10-28 18:38:36 +02:00
return Public