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

651 lines
24 KiB
Lua
Raw Normal View History

2021-10-13 10:21:53 +02:00
2022-02-26 20:25:48 +02:00
local Session = require 'utils.datastore.session_data'
local Antigrief = require 'utils.antigrief'
2022-03-19 23:20:55 +02:00
-- local Balance = require 'maps.pirates.balance'
local _inspect = require 'utils.inspect'.inspect
2021-10-13 10:21:53 +02:00
local Memory = require 'maps.pirates.memory'
local Math = require 'maps.pirates.math'
local Common = require 'maps.pirates.common'
local Utils = require 'maps.pirates.utils_local'
local CoreData = require 'maps.pirates.coredata'
local Server = require 'utils.server'
local Classes = require 'maps.pirates.roles.classes'
2022-02-26 20:25:48 +02:00
local Public = {}
2022-02-27 01:33:19 +02:00
local privilege_levels = {
2022-02-26 20:25:48 +02:00
NORMAL = 1,
OFFICER = 2,
CAPTAIN = 3
}
2022-02-27 01:33:19 +02:00
Public.privilege_levels = privilege_levels
2021-10-13 10:21:53 +02:00
--== Roles — General ==--
2022-02-27 01:33:19 +02:00
function Public.reset_officers()
local memory = Memory.get_crew_memory()
memory.officers_table = {}
end
function Public.make_officer(captain, player)
local memory = Memory.get_crew_memory()
2022-03-04 19:57:58 +02:00
local force = memory.force
2022-03-19 23:20:55 +02:00
2022-03-09 01:36:03 +02:00
if Utils.contains(Common.crew_get_crew_members(), player) then
if (not (captain.index == player.index)) then
if Common.validate_player(player) then
memory.officers_table[player.index] = true
2022-03-19 23:20:55 +02:00
2022-03-09 01:36:03 +02:00
local message = (captain.name .. ' made ' .. player.name .. ' an officer.')
Common.notify_force_light(force, message)
Public.update_privileges(player)
else
2022-03-13 20:19:59 +02:00
Common.notify_player_error(captain, 'Command error: Player is invalid.')
2022-03-09 01:36:03 +02:00
return false
end
else
2022-03-13 20:19:59 +02:00
Common.notify_player_error(captain, 'Command error: Can\'t promote yourself to officer.')
2022-03-09 01:36:03 +02:00
return false
end
else
2022-03-13 20:19:59 +02:00
Common.notify_player_error(captain, 'Command error: Player is not a crewmember.')
2022-03-09 01:36:03 +02:00
return false
2022-02-27 01:33:19 +02:00
end
end
function Public.unmake_officer(captain, player)
local memory = Memory.get_crew_memory()
2022-03-04 19:57:58 +02:00
local force = memory.force
2022-03-19 23:20:55 +02:00
2022-03-09 01:36:03 +02:00
if Utils.contains(Common.crew_get_crew_members(), player) then
if memory.officers_table[player.index] then
memory.officers_table[player.index] = nil
2022-03-19 23:20:55 +02:00
2022-03-09 01:36:03 +02:00
local message = (captain.name .. ' unmade ' .. player.name .. ' an officer.')
Common.notify_force_light(force, message)
Public.update_privileges(player)
return true
else
2022-03-13 20:19:59 +02:00
Common.notify_player_error(captain, 'Command error: Player isn\'t an officer.')
2022-03-09 01:36:03 +02:00
return false
end
else
2022-03-13 20:19:59 +02:00
Common.notify_player_error(captain, 'Command error: Player is not a crewmember.')
2022-03-09 01:36:03 +02:00
return false
2022-02-27 01:33:19 +02:00
end
end
2022-03-07 11:50:25 +02:00
function Public.revoke_class(captain, player)
local memory = Memory.get_crew_memory()
local force = memory.force
if force and force.valid and player.index and memory.classes_table[player.index] then
memory.spare_classes[#memory.spare_classes + 1] = memory.classes_table[player.index]
memory.classes_table[player.index] = nil
2022-03-17 03:40:18 +02:00
Common.notify_force_light(force, string.format('%s revoked %s from %s.', captain.name, Classes.display_form[memory.classes_table[player.index]], player.name))
2022-03-07 11:50:25 +02:00
end
end
2021-10-13 10:21:53 +02:00
function Public.tag_text(player)
local memory = Memory.get_crew_memory()
2022-02-27 01:33:19 +02:00
local str = ''
2021-10-13 10:21:53 +02:00
local tags = {}
2022-03-01 23:59:48 +02:00
if memory.id ~= 0 and Common.is_captain(player) then
2022-02-27 01:33:19 +02:00
tags[#tags + 1] = 'Cap\'n'
2021-10-13 10:21:53 +02:00
elseif player.controller_type == defines.controllers.spectator then
tags[#tags + 1] = 'Spectating'
2022-02-26 15:55:36 +02:00
elseif memory.officers_table and memory.officers_table[player.index] then
2022-02-27 01:33:19 +02:00
tags[#tags + 1] = 'Officer'
2021-10-13 10:21:53 +02:00
end
2022-03-13 20:19:59 +02:00
local classes_table = memory.classes_table
if classes_table and classes_table[player.index] then
tags[#tags + 1] = Classes.display_form[classes_table[player.index]]
2021-10-13 10:21:53 +02:00
end
for i, t in ipairs(tags) do
if i>1 then str = str .. ', ' end
str = str .. t
end
if (not (str == '')) then str = '[' .. str .. ']' end
return str
end
2022-03-13 20:19:59 +02:00
function Public.update_tags(player)
local str = Public.tag_text(player)
player.tag = str
end
2022-02-27 18:42:25 +02:00
2022-03-09 01:36:03 +02:00
-- function Public.get_classes_print_string()
-- local str = 'Current class Descriptions:'
2022-02-27 18:42:25 +02:00
2022-03-09 01:36:03 +02:00
-- for i, class in ipairs(Classes.Class_List) do
-- str = str .. '\n' .. Classes.display_form[class] .. ': ' .. Classes.explanation[class] .. ''
-- end
2022-02-27 18:42:25 +02:00
2022-03-09 01:36:03 +02:00
-- return str
-- end
2022-02-27 18:42:25 +02:00
function Public.get_class_print_string(class)
for _, class2 in ipairs(Classes.Class_List) do
if Classes.display_form[class2]:lower() == class:lower() then
2022-03-09 01:36:03 +02:00
local str = ''
2022-03-09 23:39:47 +02:00
str = str .. Classes.display_form[class2] .. ': '
2022-03-09 01:36:03 +02:00
if Classes.class_purchase_requirement[class2] then
str = str .. 'An upgrade of ' .. Classes.display_form[Classes.class_purchase_requirement[class2]] .. '. '
end
2022-03-09 23:39:47 +02:00
str = str .. Classes.explanation[class2]
2022-03-09 01:36:03 +02:00
return str
2022-02-27 18:42:25 +02:00
end
end
2022-02-27 20:47:53 +02:00
if class:lower() == 'officer' then
return 'Officer: Assigned by the captain, officers can use the Captain\'s shop and access privileged chests.'
end
if class:lower() == 'captain' then
return 'Captain: Has executive power to undock the ship, purchase items, and various other special actions. When the game assigns a captain, it gives priority to those who have been playing the longest as a non-captain.'
end
2022-02-27 18:42:25 +02:00
return nil
end
2022-02-26 20:25:48 +02:00
function Public.player_privilege_level(player)
local memory = Memory.get_crew_memory()
2022-03-01 23:59:48 +02:00
if memory.id ~= 0 and Common.is_captain(player) then
2022-02-27 01:33:19 +02:00
return Public.privilege_levels.CAPTAIN
2022-02-26 20:25:48 +02:00
elseif memory.officers_table and memory.officers_table[player.index] then
2022-02-27 01:33:19 +02:00
return Public.privilege_levels.OFFICER
2022-02-26 20:25:48 +02:00
else
2022-02-27 01:33:19 +02:00
return Public.privilege_levels.NORMAL
2022-02-26 20:25:48 +02:00
end
end
2022-03-01 17:57:23 +02:00
function Public.make_captain(player)
local global_memory = Memory.get_global_memory()
local memory = Memory.get_crew_memory()
if memory.playerindex_captain then
Public.update_privileges(game.players[memory.playerindex_captain])
end
memory.playerindex_captain = player.index
global_memory.playerindex_to_captainhood_priority[player.index] = nil
memory.captain_acceptance_timer = nil
Public.reset_officers()
Public.update_privileges(player)
end
function Public.player_confirm_captainhood(player)
2021-10-13 10:21:53 +02:00
local memory = Memory.get_crew_memory()
local captain_index = memory.playerindex_captain
if not (player.index == captain_index) then
2022-03-13 20:19:59 +02:00
Common.notify_player_error(player, 'Command error: You\'re not the captain.')
2021-10-13 10:21:53 +02:00
else
if memory.captain_acceptance_timer then
memory.captain_acceptance_timer = nil
local force = player.force
if force and force.valid then
local message = (player.name .. ' accepted the role of captain.')
Common.notify_force(force, message)
Server.to_discord_embed_raw(CoreData.comfy_emojis.derp .. '[' .. memory.name .. '] ' .. message)
end
else
2022-03-13 20:19:59 +02:00
Common.notify_player_expected(player, 'Command error: You\'re not temporary, so you don\'t need to accept.')
2021-10-13 10:21:53 +02:00
end
end
end
function Public.player_left_so_redestribute_roles(player)
2022-03-19 23:20:55 +02:00
-- local memory = Memory.get_crew_memory()
2022-02-27 01:33:19 +02:00
if player and player.index then
2022-03-01 23:59:48 +02:00
if Common.is_captain(player) then
2022-02-27 01:33:19 +02:00
Public.assign_captain_based_on_priorities()
end
2022-03-19 23:20:55 +02:00
2022-02-28 22:35:45 +02:00
-- no need to do this, as long as officers get reset when the captainhood changes hands
-- if memory.officers_table and memory.officers_table[player.index] then
-- memory.officers_table[player.index] = nil
-- end
2021-10-13 10:21:53 +02:00
end
2022-03-19 23:20:55 +02:00
2022-03-14 14:44:30 +02:00
Classes.try_renounce_class(player, false, "A %s class is now spare.")
2021-10-13 10:21:53 +02:00
end
function Public.renounce_captainhood(player)
local global_memory = Memory.get_global_memory()
local memory = Memory.get_crew_memory()
if #Common.crew_get_crew_members() == 1 then
2022-03-13 20:19:59 +02:00
Common.notify_player_error(player, 'Command error: But you\'re the only crew member...')
2021-10-13 10:21:53 +02:00
else
2022-03-04 19:57:58 +02:00
local force = memory.force
2022-03-01 17:57:23 +02:00
global_memory.playerindex_to_captainhood_priority[player.index] = nil
2021-10-13 10:21:53 +02:00
if force and force.valid then
local message = (player.name .. ' renounces their title of captain.')
Common.notify_force(force, message)
Server.to_discord_embed_raw(CoreData.comfy_emojis.ree1 .. '[' .. memory.name .. '] ' .. message)
end
2022-03-19 23:20:55 +02:00
2021-10-13 10:21:53 +02:00
Public.assign_captain_based_on_priorities(player.index)
end
end
2022-02-27 18:42:25 +02:00
function Public.resign_as_officer(player)
local memory = Memory.get_crew_memory()
2022-03-04 19:57:58 +02:00
local force = memory.force
2022-02-27 18:42:25 +02:00
if memory.officers_table and memory.officers_table[player.index] then
memory.officers_table[player.index] = nil
local message = (player.name .. ' resigns as an officer.')
Common.notify_force(force, message)
Server.to_discord_embed_raw(CoreData.comfy_emojis.ree1 .. '[' .. memory.name .. '] ' .. message)
else
log('Error: player tried to resign as officer despite not being one.')
end
end
2021-10-13 10:21:53 +02:00
2022-02-28 18:36:46 +02:00
function Public.confirm_captain_exists(player_to_make_captain_otherwise)
local memory = Memory.get_crew_memory()
2022-03-19 23:20:55 +02:00
-- Currently this catches an issue where a crew drops to zero players, and then someone else joins.
2022-02-28 18:36:46 +02:00
2022-02-28 22:40:29 +02:00
if (memory.id and memory.id > 0 and memory.crewstatus and memory.crewstatus == 'adventuring') and (not (memory.playerindex_captain and game.players[memory.playerindex_captain] and Common.validate_player(game.players[memory.playerindex_captain]))) then --fixme: enum hacked
2022-02-28 18:36:46 +02:00
if player_to_make_captain_otherwise then
Public.make_captain(player_to_make_captain_otherwise)
2022-03-19 23:20:55 +02:00
-- game.print('Auto-reassigning captain.')
2022-02-28 18:36:46 +02:00
else
log('Error: Couldn\'t make a captain.')
end
end
end
2022-02-26 20:25:48 +02:00
function Public.pass_captainhood(player, player_to_pass_to)
2022-03-19 23:20:55 +02:00
-- local global_memory = Memory.get_global_memory()
2022-02-26 20:25:48 +02:00
local memory = Memory.get_crew_memory()
2021-10-13 10:21:53 +02:00
2022-03-04 19:57:58 +02:00
local force = memory.force
2021-10-13 10:21:53 +02:00
if not (force and force.valid) then return end
local message = string.format("%s has passed their captainhood to %s.", player.name, player_to_pass_to.name)
Common.notify_force(force, message)
Server.to_discord_embed_raw(CoreData.comfy_emojis.spurdo .. '[' .. memory.name .. '] ' .. message)
2022-02-26 20:25:48 +02:00
Public.make_captain(player_to_pass_to)
2021-10-13 10:21:53 +02:00
end
function Public.afk_player_tick(player)
2022-03-19 23:20:55 +02:00
-- local global_memory = Memory.get_global_memory()
2021-10-13 10:21:53 +02:00
local memory = Memory.get_crew_memory()
2022-03-19 23:20:55 +02:00
2022-03-01 23:59:48 +02:00
if Common.is_captain(player) and #Common.crew_get_nonafk_crew_members() > 0 then
2021-10-13 10:21:53 +02:00
2022-03-04 19:57:58 +02:00
local force = memory.force
2021-10-13 10:21:53 +02:00
if force and force.valid then
local message = string.format(player.name .. ' was afk.')
Common.notify_force(force, message)
Server.to_discord_embed_raw(CoreData.comfy_emojis.loops .. '[' .. memory.name .. '] ' .. message)
end
if #Common.crew_get_nonafk_crew_members() == 1 then --don't need to bounce it around
2022-02-26 20:25:48 +02:00
Public.make_captain(Common.crew_get_nonafk_crew_members()[1])
2021-10-13 10:21:53 +02:00
else
Public.assign_captain_based_on_priorities()
end
end
end
function Public.assign_captain_based_on_priorities(excluded_player_index)
excluded_player_index = excluded_player_index or nil
local global_memory = Memory.get_global_memory()
local memory = Memory.get_crew_memory()
local crew_members = memory.crewplayerindices
if not (crew_members and #crew_members > 0) then return end
local only_found_afk_players = true
local best_priority_so_far = -1
local captain_index = nil
local captain_name = nil
for _, player_index in pairs(crew_members) do
local player = game.players[player_index]
if Common.validate_player(player) and not (player.index == excluded_player_index) then
local player_active = Utils.contains(Common.crew_get_nonafk_crew_members(), player)
-- prefer non-afk players:
if only_found_afk_players or player_active then
only_found_afk_players = player_active
2022-03-19 23:20:55 +02:00
2022-03-01 17:57:23 +02:00
local player_priority = global_memory.playerindex_to_captainhood_priority[player_index]
2021-10-13 10:21:53 +02:00
if player_priority and player_priority > best_priority_so_far then
best_priority_so_far = player_priority
captain_index = player_index
captain_name = player.name
end
end
end
end
2022-03-04 19:57:58 +02:00
local force = memory.force
2021-10-13 10:21:53 +02:00
if not (force and force.valid) then return end
if not captain_index then
captain_index = crew_members[1]
captain_name = game.players[captain_index].name
Common.notify_force(force,'Looking for a suitable captain...')
end
2022-02-26 20:25:48 +02:00
if captain_index then
local player = game.players[captain_index]
if player and Common.validate_player(player) then
Public.make_captain(player)
-- this sets memory.captain_acceptance_timer = nil so now we must reset that after this function
end
end
2021-10-13 10:21:53 +02:00
if #Common.crew_get_crew_members() > 1 then
local messages = {
"would you like to be captain?",
"would you like to be captain?",
"captain?",
"is it your turn to be captain?",
}
local message = captain_name .. ', ' .. messages[Math.random(#messages)]
Common.notify_force_light(force, message .. ' If yes say /ok')
-- Server.to_discord_embed_raw('[' .. memory.name .. ']' .. CoreData.comfy_emojis.spurdo .. ' ' .. message)
memory.captain_acceptance_timer = 72 --tuned
2022-02-26 15:55:36 +02:00
else
memory.captain_acceptance_timer = nil
2021-10-13 10:21:53 +02:00
end
end
2022-05-06 14:43:59 +02:00
function Public.captain_tax(captain_index)
2022-02-24 21:39:03 +02:00
local memory = Memory.get_crew_memory()
2022-03-13 20:19:59 +02:00
local any_taken = false
local items_to_req = {'coin', 'rail-signal', 'uranium-235'}
2022-03-13 20:19:59 +02:00
local item_count_table = {}
for _, i in pairs(items_to_req) do
item_count_table[i] = 0
end
2022-02-24 21:39:03 +02:00
local crew_members = memory.crewplayerindices
local captain = game.players[captain_index]
2022-03-13 20:19:59 +02:00
if not (captain and crew_members) then return end
2022-03-19 23:20:55 +02:00
2022-02-24 21:39:03 +02:00
local captain_inv = captain.get_inventory(defines.inventory.character_main)
2022-02-27 20:47:53 +02:00
if captain_inv and captain_inv.valid then
for _, player_index in pairs(crew_members) do
if player_index ~= captain_index then
local player = game.players[player_index]
2022-03-13 20:19:59 +02:00
if player and player.valid and not (memory.officers_table and memory.officers_table[player.index]) then
2022-02-27 20:47:53 +02:00
local inv = player.get_inventory(defines.inventory.character_main)
if inv and inv.valid then
2022-03-13 20:19:59 +02:00
for _, i in pairs(items_to_req) do
local amount = inv.get_item_count(i)
2022-05-06 14:43:59 +02:00
if i == 'coin' then amount = Math.floor(amount/10) end
2022-03-13 20:19:59 +02:00
if amount and amount > 0 then
inv.remove{name=i, count=amount}
captain_inv.insert{name=i, count=amount}
item_count_table[i] = item_count_table[i] + amount
any_taken = true
end
2022-02-27 20:47:53 +02:00
end
end
2022-02-24 21:39:03 +02:00
2022-02-27 20:47:53 +02:00
local cursor_stack = player.cursor_stack
2022-03-13 20:19:59 +02:00
if cursor_stack and cursor_stack.valid_for_read then
for _, i in pairs(items_to_req) do
if cursor_stack.name == i then
local cursor_stack_count = cursor_stack.count
if cursor_stack_count > 0 then
cursor_stack.count = 0
captain_inv.insert{name=i, count = cursor_stack_count}
item_count_table[i] = item_count_table[i] + cursor_stack_count
any_taken = true
end
break
end
2022-02-27 20:47:53 +02:00
end
2022-02-27 18:42:25 +02:00
end
2022-02-26 15:55:36 +02:00
end
2022-02-24 21:39:03 +02:00
end
end
2022-03-13 20:19:59 +02:00
if any_taken then
local str = 'The captain taxed '
2022-03-15 20:50:19 +02:00
local j = 1
2022-03-13 20:19:59 +02:00
for i = 1, #items_to_req do
local item = items_to_req[i]
2022-03-14 23:38:44 +02:00
local count = item_count_table[item]
2022-03-15 20:50:19 +02:00
if count > 0 then
if j > 1 then
if i == #items_to_req then
str = str .. ' and '
else
str = str .. ', '
end
end
local display_name = item
if display_name == 'coin' then display_name = 'doubloons' end
if count >= 1000 then
str = str .. Utils.bignumber_abbrevform2(count) .. ' ' .. display_name
2022-03-13 20:19:59 +02:00
else
2022-03-15 20:50:19 +02:00
str = str .. count .. ' ' .. display_name
2022-03-13 20:19:59 +02:00
end
2022-03-15 20:50:19 +02:00
j = j + 1
2022-03-13 20:19:59 +02:00
end
end
str = str .. '.'
Common.notify_force(memory.force, str)
else
Common.notify_player_error(captain, 'No coins or game-critical found in crewmates\' inventories or cursor stacks.')
2022-02-27 20:47:53 +02:00
end
2022-02-27 18:42:25 +02:00
end
2022-02-24 21:39:03 +02:00
end
2022-02-26 20:25:48 +02:00
function Public.add_player_to_permission_group(player, group_override)
-- local jailed = Jailed.get_jailed_table()
-- local enable_permission_group_disconnect = WPT.get('disconnect_wagon')
local session = Session.get_session_table()
local AG = Antigrief.get()
local gulag = game.permissions.get_group('gulag')
local tbl = gulag and gulag.players
for i = 1, #tbl do
if tbl[i].index == player.index then
return
end
end
-- if player.admin then
-- return
-- end
local playtime = player.online_time
if session and session[player.name] then
playtime = player.online_time + session[player.name]
end
-- if jailed[player.name] then
-- return
-- end
if not game.permissions.get_group('restricted_area') then
local group = game.permissions.create_group('restricted_area')
group.set_allows_action(defines.input_action.edit_permission_group, false)
group.set_allows_action(defines.input_action.import_permissions_string, false)
group.set_allows_action(defines.input_action.delete_permission_group, false)
group.set_allows_action(defines.input_action.add_permission_group, false)
group.set_allows_action(defines.input_action.admin_action, false)
group.set_allows_action(defines.input_action.cancel_craft, false)
group.set_allows_action(defines.input_action.drop_item, false)
group.set_allows_action(defines.input_action.drop_blueprint_record, false)
group.set_allows_action(defines.input_action.build, false)
group.set_allows_action(defines.input_action.build_rail, false)
group.set_allows_action(defines.input_action.build_terrain, false)
group.set_allows_action(defines.input_action.begin_mining, false)
group.set_allows_action(defines.input_action.begin_mining_terrain, false)
2022-02-28 18:36:46 +02:00
-- group.set_allows_action(defines.input_action.deconstruct, false) --pick up dead players
2022-02-26 20:25:48 +02:00
group.set_allows_action(defines.input_action.activate_copy, false)
group.set_allows_action(defines.input_action.activate_cut, false)
group.set_allows_action(defines.input_action.activate_paste, false)
group.set_allows_action(defines.input_action.upgrade, false)
group.set_allows_action(defines.input_action.grab_blueprint_record, false)
2022-02-28 18:36:46 +02:00
if not CoreData.blueprint_library_allowed then
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
end
if not CoreData.blueprint_importing_allowed then
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
end
2022-02-26 20:25:48 +02:00
group.set_allows_action(defines.input_action.open_gui, false)
group.set_allows_action(defines.input_action.fast_entity_transfer, false)
group.set_allows_action(defines.input_action.fast_entity_split, false)
end
if not game.permissions.get_group('restricted_area_privileged') then
local group = game.permissions.create_group('restricted_area_privileged')
group.set_allows_action(defines.input_action.edit_permission_group, false)
group.set_allows_action(defines.input_action.import_permissions_string, false)
group.set_allows_action(defines.input_action.delete_permission_group, false)
group.set_allows_action(defines.input_action.add_permission_group, false)
group.set_allows_action(defines.input_action.admin_action, false)
group.set_allows_action(defines.input_action.cancel_craft, false)
group.set_allows_action(defines.input_action.drop_item, false)
group.set_allows_action(defines.input_action.drop_blueprint_record, false)
group.set_allows_action(defines.input_action.build, false)
group.set_allows_action(defines.input_action.build_rail, false)
group.set_allows_action(defines.input_action.build_terrain, false)
group.set_allows_action(defines.input_action.begin_mining, false)
group.set_allows_action(defines.input_action.begin_mining_terrain, false)
2022-02-28 18:36:46 +02:00
-- group.set_allows_action(defines.input_action.deconstruct, false) --pick up dead players
2022-02-26 20:25:48 +02:00
group.set_allows_action(defines.input_action.activate_copy, false)
group.set_allows_action(defines.input_action.activate_cut, false)
group.set_allows_action(defines.input_action.activate_paste, false)
group.set_allows_action(defines.input_action.upgrade, false)
2022-02-28 18:36:46 +02:00
if not CoreData.blueprint_library_allowed then
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
2022-04-29 18:43:46 +02:00
group.set_allows_action(defines.input_action.grab_blueprint_record, false)
2022-02-28 18:36:46 +02:00
end
if not CoreData.blueprint_importing_allowed then
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
end
2022-02-26 20:25:48 +02:00
end
if not game.permissions.get_group('plebs') then
local plebs_group = game.permissions.create_group('plebs')
if not _DEBUG then
plebs_group.set_allows_action(defines.input_action.edit_permission_group, false)
plebs_group.set_allows_action(defines.input_action.import_permissions_string, false)
plebs_group.set_allows_action(defines.input_action.delete_permission_group, false)
plebs_group.set_allows_action(defines.input_action.add_permission_group, false)
plebs_group.set_allows_action(defines.input_action.admin_action, false)
2022-02-28 18:36:46 +02:00
if not CoreData.blueprint_library_allowed then
plebs_group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
2022-04-29 18:43:46 +02:00
plebs_group.set_allows_action(defines.input_action.grab_blueprint_record, false)
2022-02-28 18:36:46 +02:00
end
if not CoreData.blueprint_importing_allowed then
plebs_group.set_allows_action(defines.input_action.import_blueprint_string, false)
plebs_group.set_allows_action(defines.input_action.import_blueprint, false)
end
2022-02-26 20:25:48 +02:00
end
end
if not game.permissions.get_group('not_trusted') then
local not_trusted = game.permissions.create_group('not_trusted')
-- not_trusted.set_allows_action(defines.input_action.cancel_craft, false)
not_trusted.set_allows_action(defines.input_action.edit_permission_group, false)
not_trusted.set_allows_action(defines.input_action.import_permissions_string, false)
not_trusted.set_allows_action(defines.input_action.delete_permission_group, false)
not_trusted.set_allows_action(defines.input_action.add_permission_group, false)
not_trusted.set_allows_action(defines.input_action.admin_action, false)
-- not_trusted.set_allows_action(defines.input_action.drop_item, false)
not_trusted.set_allows_action(defines.input_action.disconnect_rolling_stock, false)
not_trusted.set_allows_action(defines.input_action.connect_rolling_stock, false)
not_trusted.set_allows_action(defines.input_action.open_train_gui, false)
not_trusted.set_allows_action(defines.input_action.open_train_station_gui, false)
not_trusted.set_allows_action(defines.input_action.open_trains_gui, false)
not_trusted.set_allows_action(defines.input_action.change_train_stop_station, false)
not_trusted.set_allows_action(defines.input_action.change_train_wait_condition, false)
not_trusted.set_allows_action(defines.input_action.change_train_wait_condition_data, false)
not_trusted.set_allows_action(defines.input_action.drag_train_schedule, false)
not_trusted.set_allows_action(defines.input_action.drag_train_wait_condition, false)
not_trusted.set_allows_action(defines.input_action.go_to_train_station, false)
not_trusted.set_allows_action(defines.input_action.remove_train_station, false)
not_trusted.set_allows_action(defines.input_action.set_trains_limit, false)
not_trusted.set_allows_action(defines.input_action.set_train_stopped, false)
not_trusted.set_allows_action(defines.input_action.grab_blueprint_record, false)
2022-02-28 18:36:46 +02:00
if not CoreData.blueprint_library_allowed then
not_trusted.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
end
if not CoreData.blueprint_importing_allowed then
not_trusted.set_allows_action(defines.input_action.import_blueprint_string, false)
not_trusted.set_allows_action(defines.input_action.import_blueprint, false)
end
2022-02-26 20:25:48 +02:00
end
local group
if group_override then
group = game.permissions.get_group(group_override)
else
if AG.enabled and not player.admin and playtime < 5184000 then -- 24 hours
group = game.permissions.get_group('not_trusted')
else
group = game.permissions.get_group('plebs')
end
end
group.add_player(player)
end
function Public.update_privileges(player)
if not Common.validate_player_and_character(player) then
return
end
if string.sub(player.surface.name, 9, 17) == 'Crowsnest' or string.sub(player.surface.name, 9, 13) == 'Cabin' then
2022-02-27 01:33:19 +02:00
if Public.player_privilege_level(player) >= Public.privilege_levels.OFFICER then
2022-02-26 20:25:48 +02:00
return Public.add_player_to_permission_group(player, 'restricted_area_privileged')
else
return Public.add_player_to_permission_group(player, 'restricted_area')
end
else
return Public.add_player_to_permission_group(player)
end
end
2021-10-13 10:21:53 +02:00
return Public