mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-14 10:13:13 +02:00
4258568c90
* Add creep spread mechanic * Added bot ore islands, use bool flag to turn on. * Added a noise based chest spawning system for artefacts * Added coin loot from biters and mining * Track artefacts launched into space * Add Creepy map preset * Update donators.lua * Add scenario info for crashsite (#291) * Split colors resources from colors code & catchup on donators (#288) * Split colors resources from colors code * Switch back to colors * Added jail button Moved parts of the jail command to report.lua Made jailing possible from a users report. closes #215 * Added sound for new reports Admins now get a sound when a new report is created. Useful for admins that doesn't have Factorio as active window. Currently set the sound_path as utility/tutorial_notice * Split chat triggers from control * Move cheat tracking outside of control.lua * Remove player-specific code * Split donator/on_join messages out of control * Move features into features folder * Indentation fix I aimed to fix the troublesome indentation. * Added a single indent * Make sure biter modifiers are accessible for mods * Consistency change regarding table access * Added NightTime.lua Split the time assignment into a new file NightTime.lua allowing for it to be disabled. (Restore normal day/night cycle) Also added a popup when a player places a solar panel informing that they are purely cosmetic Removed the recipe for portable solar panels because they are useless, but the technology is needed. * Fixed debug print grid value to show non-rounded value * added support for hidden tiles * Add newline to eof * Fixed no newline, indentation and scope of research * crash_site outposts set hidden tile to 'grass-1' * Log items spawned by crafting in cheat mode * Newline to eof * Put responses into table * Use trigger as table key * Change name of lattice to diagonal lattice (#297) * Add Diagonal Ribbon to map presets (#294) * Reorganize control (#312) * Check for config before disabling fish market (#311) * Force diggy biters to spawn, even if there's no space (#308) * Fixed some small things from feedback and issues (#313) * Update fractal_balls.lua * Add ALo's message and color (#314) * Add join message for ALo * Add ALo's color * Typo in donators.lua * fixed tile corruption issus closes #310 (#317) * Update player_list.lua * Update diagonal_ribbon.lua (#322) * Regulars: remove duplicates and sort alphabetically (#320)
144 lines
4.0 KiB
Lua
144 lines
4.0 KiB
Lua
local Event = require 'utils.event'
|
|
local Global = require 'utils.global'
|
|
local Game = require 'utils.game'
|
|
|
|
local player_last_position = {}
|
|
local player_walk_distances = {}
|
|
local player_coin_earned = {}
|
|
local player_coin_spent = {}
|
|
local player_deaths = {}
|
|
local total_players = {0}
|
|
|
|
Global.register(
|
|
{
|
|
player_last_position = player_last_position,
|
|
player_walk_distances = player_walk_distances,
|
|
player_coin_earned = player_coin_earned,
|
|
player_coin_spent = player_coin_spent,
|
|
player_deaths = player_deaths,
|
|
total_players = total_players
|
|
},
|
|
function(tbl)
|
|
player_last_position = tbl.player_last_position
|
|
player_walk_distances = tbl.player_walk_distances
|
|
player_coin_earned = tbl.player_coin_earned
|
|
player_coin_spent = tbl.player_coin_spent
|
|
player_deaths = tbl.player_deaths
|
|
total_players = tbl.total_players
|
|
end
|
|
)
|
|
|
|
local function player_created(event)
|
|
local index = event.player_index
|
|
|
|
player_last_position[index] = Game.get_player_by_index(index).position
|
|
player_walk_distances[index] = 0
|
|
player_coin_earned[index] = 0
|
|
player_coin_spent[index] = 0
|
|
player_deaths[index] = {causes = {}, count = 0}
|
|
total_players[1] = total_players[1] + 1
|
|
end
|
|
|
|
local function get_cause_name(cause)
|
|
if cause then
|
|
local name = cause.name
|
|
if name == 'player' then
|
|
local player = cause.player
|
|
if player and player.valid then
|
|
return player.name
|
|
end
|
|
else
|
|
return name
|
|
end
|
|
end
|
|
|
|
return 'No cause'
|
|
end
|
|
|
|
local function player_died(event)
|
|
local player_index = event.player_index
|
|
local cause = get_cause_name(event.cause)
|
|
|
|
local data = player_deaths[player_index]
|
|
data.count = data.count + 1
|
|
|
|
local causes = data.causes
|
|
local cause_count = causes[cause] or 0
|
|
causes[cause] = cause_count + 1
|
|
end
|
|
|
|
local function picked_up_item(event)
|
|
local stack = event.item_stack
|
|
|
|
if stack.name == 'coin' then
|
|
local player_index = event.player_index
|
|
player_coin_earned[player_index] = player_coin_earned[player_index] + stack.count
|
|
end
|
|
end
|
|
|
|
local function tick()
|
|
for _, p in ipairs(game.connected_players) do
|
|
if (p.afk_time < 30 or p.walking_state.walking) and p.vehicle == nil then
|
|
local index = p.index
|
|
local last_pos = player_last_position[index]
|
|
local pos = p.position
|
|
|
|
local d_x = last_pos.x - pos.x
|
|
local d_y = last_pos.y - pos.y
|
|
|
|
player_walk_distances[index] = player_walk_distances[index] + math.sqrt(d_x * d_x + d_y * d_y)
|
|
player_last_position[index] = pos
|
|
end
|
|
end
|
|
end
|
|
|
|
Event.add(defines.events.on_player_created, player_created)
|
|
Event.add(defines.events.on_player_died, player_died)
|
|
Event.add(defines.events.on_picked_up_item, picked_up_item)
|
|
Event.on_nth_tick(62, tick)
|
|
|
|
local Public = {}
|
|
|
|
function Public.get_walk_distance(player_index)
|
|
return player_walk_distances[player_index]
|
|
end
|
|
|
|
function Public.get_coin_earned(player_index)
|
|
return player_coin_earned[player_index]
|
|
end
|
|
|
|
function Public.set_coin_earned(player_index, value)
|
|
player_coin_earned[player_index] = value
|
|
end
|
|
|
|
function Public.change_coin_earned(player_index, amount)
|
|
player_coin_earned[player_index] = player_coin_earned[player_index] + amount
|
|
end
|
|
|
|
function Public.get_coin_spent(player_index)
|
|
return player_coin_spent[player_index]
|
|
end
|
|
|
|
function Public.set_coin_spent(player_index, value)
|
|
player_coin_spent[player_index] = value
|
|
end
|
|
|
|
function Public.change_coin_spent(player_index, amount)
|
|
player_coin_spent[player_index] = player_coin_spent[player_index] + amount
|
|
end
|
|
|
|
function Public.get_death_count(player_index)
|
|
return player_deaths[player_index].count
|
|
end
|
|
|
|
-- Returns a dictionary of casue_name -> count
|
|
function Public.get_all_death_counts_by_casue(player_index)
|
|
return player_deaths[player_index].causes or {}
|
|
end
|
|
|
|
function Public.get_total_player_count()
|
|
return total_players[1]
|
|
end
|
|
|
|
return Public
|