mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-11 14:49:24 +02:00
new modules and refactor
This commit is contained in:
parent
376fbbd569
commit
e38baa3085
@ -3,12 +3,12 @@
|
||||
--as an admin, write either /trust or /untrust and the players name in the chat to grant/revoke immunity from protection
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local session = require 'utils.session_data'
|
||||
local session = require 'utils.datastore.session_data'
|
||||
local Global = require 'utils.global'
|
||||
local Utils = require 'utils.core'
|
||||
local Color = require 'utils.color_presets'
|
||||
local Server = require 'utils.server'
|
||||
local Jail = require 'utils.jail_data'
|
||||
local Jail = require 'utils.datastore.jail_data'
|
||||
|
||||
local Public = {}
|
||||
local match = string.match
|
||||
@ -209,7 +209,7 @@ local function on_player_ammo_inventory_changed(event)
|
||||
playtime = player.online_time + tracker[player.name]
|
||||
end
|
||||
if playtime < 1296000 then
|
||||
if this.enable_capsule_warning then
|
||||
if this.enable_capsule_cursor_warning then
|
||||
local nukes = player.remove_item({name = 'atomic-bomb', count = 1000})
|
||||
if nukes > 0 then
|
||||
Utils.action_warning('{Nuke}', player.name .. ' tried to equip nukes but was not trusted.')
|
||||
|
@ -1,5 +1,5 @@
|
||||
local Event = require 'utils.event'
|
||||
local session = require 'utils.session_data'
|
||||
local session = require 'utils.datastore.session_data'
|
||||
local Timestamp = require 'utils.timestamp'
|
||||
local Server = require 'utils.server'
|
||||
local Color = require 'utils.color_presets'
|
||||
|
@ -1,7 +1,7 @@
|
||||
--antigrief things made by mewmew
|
||||
|
||||
local Event = require 'utils.event'
|
||||
local Jailed = require 'utils.jail_data'
|
||||
local Jailed = require 'utils.datastore.jail_data'
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
local AntiGrief = require 'antigrief'
|
||||
|
||||
|
@ -13,8 +13,8 @@ to your scenario control.lua.
|
||||
Minor changes by ~~~Gerkiz~~~
|
||||
--]]
|
||||
local Event = require 'utils.event'
|
||||
local Session = require 'utils.session_data'
|
||||
local Jailed = require 'utils.jail_data'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Jailed = require 'utils.datastore.jail_data'
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
|
@ -4,7 +4,7 @@ local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
local Server = require 'utils.server'
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
local session = require 'utils.session_data'
|
||||
local session = require 'utils.datastore.session_data'
|
||||
|
||||
local Class = {}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
local Session = require 'utils.session_data'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Modifiers = require 'player_modifiers'
|
||||
local Server = require 'utils.server'
|
||||
local Color = require 'utils.color_presets'
|
||||
|
13
control.lua
13
control.lua
@ -1,15 +1,18 @@
|
||||
require 'utils.data_stages'
|
||||
_LIFECYCLE = _STAGE.control -- Control stage
|
||||
_DEBUG = false
|
||||
_DEBUG = true
|
||||
_DUMP_ENV = false
|
||||
|
||||
require 'utils.server'
|
||||
require 'utils.server_commands'
|
||||
require 'utils.utils'
|
||||
require 'utils.table'
|
||||
require 'utils.color_data'
|
||||
require 'utils.session_data'
|
||||
require 'utils.jail_data'
|
||||
require 'utils.datastore.color_data'
|
||||
require 'utils.datastore.session_data'
|
||||
require 'utils.datastore.jail_data'
|
||||
require 'utils.datastore.quickbar_data'
|
||||
require 'utils.datastore.message_on_join_data'
|
||||
require 'utils.datastore.player_tag_data'
|
||||
require 'chatbot'
|
||||
require 'commands'
|
||||
require 'antigrief'
|
||||
@ -76,7 +79,7 @@ require 'modules.autostash'
|
||||
--require 'maps.fish_defender_v2.main'
|
||||
--require 'maps.fish_defender.main'
|
||||
--require 'maps.biter_battles_v2.main'
|
||||
require 'maps.mountain_fortress_v3.main'
|
||||
--require 'maps.mountain_fortress_v3.main'
|
||||
--require 'maps.mountain_fortress_v2.main'
|
||||
--require 'maps.lumberjack.main'
|
||||
--require 'maps.dungeons.main'
|
||||
|
@ -747,7 +747,6 @@ end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.on_load(on_load)
|
||||
event.on_nth_tick(2, tick)
|
||||
event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
||||
@ -763,7 +762,7 @@ event.add(defines.events.on_gui_click, Gui.on_gui_click)
|
||||
|
||||
|
||||
if _DEBUG then
|
||||
local Session = require 'utils.session_data'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Color = require 'utils.color_presets'
|
||||
|
||||
commands.add_command(
|
||||
|
@ -1,5 +1,5 @@
|
||||
local Event = require 'utils.event'
|
||||
local play_time = require 'utils.session_data'
|
||||
local play_time = require 'utils.datastore.session_data'
|
||||
local Tabs = require 'comfy_panel.main'
|
||||
local RPG = require 'maps.lumberjack.rpg'
|
||||
|
||||
|
@ -4,9 +4,9 @@ local Market = require 'maps.mountain_fortress_v3.basic_markets'
|
||||
local ICW = require 'maps.mountain_fortress_v3.icw.main'
|
||||
local WPT = require 'maps.mountain_fortress_v3.table'
|
||||
local WD = require 'modules.wave_defense.table'
|
||||
local Session = require 'utils.session_data'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Difficulty = require 'modules.difficulty_vote'
|
||||
local Jailed = require 'utils.jail_data'
|
||||
local Jailed = require 'utils.datastore.jail_data'
|
||||
local RPG_Settings = require 'modules.rpg.table'
|
||||
local Functions = require 'modules.rpg.functions'
|
||||
local Gui = require 'utils.gui'
|
||||
|
@ -1,7 +1,7 @@
|
||||
local RPG = require 'modules.rpg.table'
|
||||
local Gui = require 'utils.gui'
|
||||
local P = require 'player_modifiers'
|
||||
local Session = require 'utils.session_data'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local reset_tooltip = 'ONE-TIME reset if you picked the wrong path (this will keep your points)'
|
||||
|
||||
local Public = {}
|
||||
|
@ -1,4 +1,5 @@
|
||||
local Token = require 'utils.token'
|
||||
local Color = require 'utils.color_presets'
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local Print = require('utils.print_override')
|
||||
@ -7,7 +8,7 @@ local raw_print = Print.raw_print
|
||||
local color_data_set = 'colors'
|
||||
local set_data = Server.set_data
|
||||
local try_get_data = Server.try_get_data
|
||||
local error_offline = '[ERROR] Webpanel is offline.'
|
||||
local error_offline = '[ERROR] Datastore is offline.'
|
||||
|
||||
local Public = {}
|
||||
|
||||
@ -89,7 +90,7 @@ Event.add(
|
||||
for word in param:gmatch('%S+') do
|
||||
if color_table[word] then
|
||||
set_data(color_data_set, player.name, {color = {color}, chat = {chat}})
|
||||
player.print('Your color was globally saved!', {r = 0.22, g = 0.99, b = 0.99})
|
||||
player.print('Your color has been saved.', Color.success)
|
||||
return true
|
||||
end
|
||||
end
|
@ -1,5 +1,5 @@
|
||||
local Global = require 'utils.global'
|
||||
local Session = require 'utils.session_data'
|
||||
local Session = require 'utils.datastore.session_data'
|
||||
local Game = require 'utils.game'
|
||||
local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
@ -11,6 +11,10 @@ local jailed_data_set = 'jailed'
|
||||
local jailed = {}
|
||||
local votejail = {}
|
||||
local votefree = {}
|
||||
local settings = {
|
||||
playtime_for_vote = 25920000, -- 5 days
|
||||
playtime_for_instant_jail = 103680000 -- 20 days
|
||||
}
|
||||
local votejail_count = 5
|
||||
local set_data = Server.set_data
|
||||
local try_get_data = Server.try_get_data
|
||||
@ -25,12 +29,14 @@ Global.register(
|
||||
{
|
||||
jailed = jailed,
|
||||
votejail = votejail,
|
||||
votefree = votefree
|
||||
votefree = votefree,
|
||||
settings = settings
|
||||
},
|
||||
function(t)
|
||||
jailed = t.jailed
|
||||
votejail = t.votejail
|
||||
votefree = t.votefree
|
||||
settings = t.settings
|
||||
end
|
||||
)
|
||||
|
||||
@ -315,8 +321,6 @@ Event.add(
|
||||
defines.events.on_console_command,
|
||||
function(event)
|
||||
local cmd = event.command
|
||||
local five_days = 25920000 -- 5 days
|
||||
local twenty_days = 103680000 -- 20 days
|
||||
|
||||
if not valid_commands[cmd] then
|
||||
return
|
||||
@ -342,11 +346,14 @@ Event.add(
|
||||
griefer = game.players[griefer].name
|
||||
end
|
||||
|
||||
if not trusted and not player.admin or playtime <= five_days and not player.admin then
|
||||
if not trusted and not player.admin or playtime <= settings.playtime_for_vote and not player.admin then
|
||||
return Utils.print_to(player, 'You are not trusted enough to run this command.')
|
||||
end
|
||||
|
||||
if trusted and playtime >= five_days and playtime < twenty_days and not player.admin then
|
||||
if
|
||||
trusted and playtime >= settings.playtime_for_vote and playtime < settings.playtime_for_instant_jail and
|
||||
not player.admin
|
||||
then
|
||||
if cmd == 'jail' then
|
||||
vote_to_jail(player, griefer)
|
||||
return
|
||||
@ -356,7 +363,7 @@ Event.add(
|
||||
end
|
||||
end
|
||||
|
||||
if player.admin or playtime >= twenty_days then
|
||||
if player.admin or playtime >= settings.playtime_for_instant_jail then
|
||||
if cmd == 'jail' then
|
||||
Public.try_ul_data(griefer, true, player.name)
|
||||
return
|
||||
@ -398,4 +405,18 @@ commands.add_command(
|
||||
end
|
||||
)
|
||||
|
||||
function Public.required_playtime_for_instant_jail(value)
|
||||
if value then
|
||||
settings.playtime_for_instant_jail = value
|
||||
end
|
||||
return settings.playtime_for_instant_jail
|
||||
end
|
||||
|
||||
function Public.required_playtime_for_vote(value)
|
||||
if value then
|
||||
settings.playtime_for_vote = value
|
||||
end
|
||||
return settings.playtime_for_vote
|
||||
end
|
||||
|
||||
return Public
|
97
utils/datastore/message_on_join_data.lua
Normal file
97
utils/datastore/message_on_join_data.lua
Normal file
@ -0,0 +1,97 @@
|
||||
local Token = require 'utils.token'
|
||||
local Color = require 'utils.color_presets'
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local Print = require('utils.print_override')
|
||||
local raw_print = Print.raw_print
|
||||
|
||||
local message_dataset = 'regulars'
|
||||
local set_data = Server.set_data
|
||||
local try_get_data = Server.try_get_data
|
||||
local error_offline = '[ERROR] Datastore is offline.'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local fetch =
|
||||
Token.register(
|
||||
function(data)
|
||||
local key = data.key
|
||||
local value = data.value
|
||||
local player = game.players[key]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
if type(value) == 'table' then
|
||||
game.print('>> ' .. player.name .. ' << ' .. value.msg, value.color)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
--- Tries to get data from the webpanel and applies the value to the player.
|
||||
-- @param data_set player token
|
||||
function Public.fetch(key)
|
||||
local secs = Server.get_current_time()
|
||||
if not secs then
|
||||
local player = game.players[key]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
raw_print(error_offline)
|
||||
return
|
||||
else
|
||||
try_get_data(message_dataset, key, fetch)
|
||||
end
|
||||
end
|
||||
|
||||
commands.add_command(
|
||||
'save-message',
|
||||
'Sets your custom join message.',
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local param = cmd.parameter
|
||||
if param then
|
||||
if param == '' and param == 'Name' then
|
||||
return player.print('You did not specify a message.', Color.warning)
|
||||
end
|
||||
if string.len(param) > 64 then
|
||||
return player.print('Message is too long. 64 characters maximum.', {r = 0.90, g = 0.0, b = 0.0})
|
||||
end
|
||||
set_data(message_dataset, player.name, {msg = param, color = player.color})
|
||||
player.print('You message has been saved.', Color.success)
|
||||
else
|
||||
player.print('You did not specify a message.', Color.warning)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'remove-message',
|
||||
'Removes your custom join message.',
|
||||
function()
|
||||
local player = game.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
set_data(message_dataset, player.name, nil)
|
||||
player.print('Your message has been removed.', Color.success)
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
Public.fetch(player.name)
|
||||
end
|
||||
)
|
||||
|
||||
return Public
|
108
utils/datastore/player_tag_data.lua
Normal file
108
utils/datastore/player_tag_data.lua
Normal file
@ -0,0 +1,108 @@
|
||||
local Token = require 'utils.token'
|
||||
local Color = require 'utils.color_presets'
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local Print = require('utils.print_override')
|
||||
local raw_print = Print.raw_print
|
||||
|
||||
local tag_dataset = 'tags'
|
||||
local set_data = Server.set_data
|
||||
local try_get_data = Server.try_get_data
|
||||
local error_offline = '[ERROR] Datastore is offline.'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local fetch =
|
||||
Token.register(
|
||||
function(data)
|
||||
local key = data.key
|
||||
local value = data.value
|
||||
local player = game.players[key]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
if type(value) == 'string' then
|
||||
player.tag = '[' .. value .. ']'
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
local alphanumeric = function(str)
|
||||
return (string.match(str, '[^%w]') ~= nil)
|
||||
end
|
||||
|
||||
--- Tries to get data from the webpanel and applies the value to the player.
|
||||
-- @param data_set player token
|
||||
function Public.fetch(key)
|
||||
local secs = Server.get_current_time()
|
||||
if not secs then
|
||||
local player = game.players[key]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
raw_print(error_offline)
|
||||
return
|
||||
else
|
||||
try_get_data(tag_dataset, key, fetch)
|
||||
end
|
||||
end
|
||||
|
||||
commands.add_command(
|
||||
'save-tag',
|
||||
'Sets your custom tag that is persistent.',
|
||||
function(cmd)
|
||||
local player = game.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local param = cmd.parameter
|
||||
|
||||
if param then
|
||||
if param ~= '' and param ~= 'Name' then
|
||||
if alphanumeric(param) then
|
||||
player.print('Tag is not valid.', {r = 0.90, g = 0.0, b = 0.0})
|
||||
return
|
||||
end
|
||||
end
|
||||
if string.len(param) > 32 then
|
||||
player.print('Tag is too long. 64 characters maximum.', {r = 0.90, g = 0.0, b = 0.0})
|
||||
return
|
||||
end
|
||||
|
||||
set_data(tag_dataset, player.name, param)
|
||||
player.print('Your tag has been saved.', Color.success)
|
||||
else
|
||||
player.print('You did not specify a tag.', Color.warning)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'remove-tag',
|
||||
'Removes your custom tag.',
|
||||
function()
|
||||
local player = game.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
set_data(tag_dataset, player.name, nil)
|
||||
player.print('Your tag has been removed.', Color.success)
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
Public.fetch(player.name)
|
||||
end
|
||||
)
|
||||
|
||||
return Public
|
100
utils/datastore/quickbar_data.lua
Normal file
100
utils/datastore/quickbar_data.lua
Normal file
@ -0,0 +1,100 @@
|
||||
local Token = require 'utils.token'
|
||||
local Color = require 'utils.color_presets'
|
||||
local Server = require 'utils.server'
|
||||
local Event = require 'utils.event'
|
||||
local Print = require('utils.print_override')
|
||||
local raw_print = Print.raw_print
|
||||
|
||||
local quickbar_dataset = 'quickbar'
|
||||
local set_data = Server.set_data
|
||||
local try_get_data = Server.try_get_data
|
||||
local error_offline = '[ERROR] Datastore is offline.'
|
||||
|
||||
local Public = {}
|
||||
|
||||
local fetch =
|
||||
Token.register(
|
||||
function(data)
|
||||
local key = data.key
|
||||
local value = data.value
|
||||
local player = game.players[key]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
if value then
|
||||
for i, item_name in pairs(value) do
|
||||
if item_name ~= nil and item_name ~= '' then
|
||||
player.set_quick_bar_slot(i, item_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
--- Tries to get data from the webpanel and applies the value to the player.
|
||||
-- @param data_set player token
|
||||
function Public.fetch(key)
|
||||
local secs = Server.get_current_time()
|
||||
if not secs then
|
||||
local player = game.players[key]
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
raw_print(error_offline)
|
||||
return
|
||||
else
|
||||
try_get_data(quickbar_dataset, key, fetch)
|
||||
end
|
||||
end
|
||||
|
||||
commands.add_command(
|
||||
'save-quickbar',
|
||||
'Save your quickbar preset so it´s always the same.',
|
||||
function()
|
||||
local player = game.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local slots = {}
|
||||
|
||||
for i = 1, 100 do
|
||||
local slot = player.get_quick_bar_slot(i)
|
||||
if slot ~= nil then
|
||||
slots[i] = slot.name
|
||||
end
|
||||
end
|
||||
if next(slots) then
|
||||
set_data(quickbar_dataset, player.name, slots)
|
||||
player.print('Your quickbar has been saved.', Color.success)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
commands.add_command(
|
||||
'remove-quickbar',
|
||||
'Removes your quickbar preset from the datastore.',
|
||||
function()
|
||||
local player = game.player
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
set_data(quickbar_dataset, player.name, nil)
|
||||
player.print('Your quickbar has been removed.', Color.success)
|
||||
end
|
||||
)
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
Public.fetch(player.name)
|
||||
end
|
||||
)
|
||||
|
||||
return Public
|
@ -8,7 +8,7 @@ local Print = require('utils.print_override')
|
||||
local raw_print = Print.raw_print
|
||||
|
||||
local session_data_set = 'sessions'
|
||||
local error_offline = '[ERROR] Webpanel is offline.'
|
||||
local error_offline = '[ERROR] Datastore is offline.'
|
||||
local session = {}
|
||||
local online_track = {}
|
||||
local trusted = {}
|
Loading…
x
Reference in New Issue
Block a user