2022-06-01 19:50:36 +01:00
-- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/danielmartin0/ComfyFactorio-Pirates.
2021-10-13 09:21:53 +01:00
local Memory = require ' maps.pirates.memory '
local Common = require ' maps.pirates.common '
local Utils = require ' maps.pirates.utils_local '
local Roles = require ' maps.pirates.roles.roles '
local Crew = require ' maps.pirates.crew '
local GuiCommon = require ' maps.pirates.gui.common '
local CoreData = require ' maps.pirates.coredata '
local Server = require ' utils.server '
local Public = { }
local window_name = ' crew '
function Public . toggle_window ( player )
local memory = Memory.get_crew_memory ( )
2022-07-15 15:18:01 +03:00
local flow , flow2 , flow3
2022-07-07 23:01:45 +03:00
local window
2021-10-13 09:21:53 +01:00
--*** OVERALL FLOW ***--
if player.gui . screen [ window_name .. ' _piratewindow ' ] then player.gui . screen [ window_name .. ' _piratewindow ' ] . destroy ( ) return end
2022-07-07 23:01:45 +03:00
if not Common.is_id_valid ( memory.id ) then return end
2022-03-19 21:20:55 +00:00
2022-07-07 23:01:45 +03:00
window = GuiCommon.new_window ( player , window_name )
flow = window.add {
type = ' scroll-pane ' ,
name = ' scroll_pane ' ,
direction = ' vertical ' ,
horizontal_scroll_policy = ' never ' ,
vertical_scroll_policy = ' auto '
}
flow.style . maximal_height = 500
flow.style . bottom_padding = 20
2021-10-13 09:21:53 +01:00
2022-03-15 18:50:19 +00:00
--*** PARAMETERS OF RUN ***--
2022-03-19 21:20:55 +00:00
2021-10-13 09:21:53 +01:00
flow2 = flow.add ( {
2022-03-15 18:50:19 +00:00
name = ' crew_capacity_and_difficulty ' ,
2021-10-13 09:21:53 +01:00
type = ' label ' ,
} )
flow2.style . left_margin = 5
flow2.style . top_margin = 0
flow2.style . bottom_margin = - 3
2022-03-15 18:50:19 +00:00
flow2.style . single_line = false
flow2.style . maximal_width = 190
2021-10-13 09:21:53 +01:00
flow2.style . font = ' default '
2022-03-19 21:20:55 +00:00
2021-10-13 09:21:53 +01:00
flow2 = flow.add ( {
2022-03-15 18:50:19 +00:00
name = ' crew_age ' ,
2021-10-13 09:21:53 +01:00
type = ' label ' ,
} )
flow2.style . left_margin = 5
flow2.style . top_margin = - 3
flow2.style . bottom_margin = 0
2022-03-15 18:50:19 +00:00
flow2.style . single_line = true
flow2.style . maximal_width = 200
2021-10-13 09:21:53 +01:00
flow2.style . font = ' default '
2022-03-19 21:20:55 +00:00
2022-03-15 18:50:19 +00:00
-- flow2 = flow.add({
-- name = 'crew_difficulty',
-- type = 'label',
-- })
-- flow2.style.left_margin = 5
-- flow2.style.top_margin = -3
-- flow2.style.bottom_margin = 0
-- flow2.style.single_line = false
-- flow2.style.maximal_width = 190
-- flow2.style.font = 'default'
2021-10-13 09:21:53 +01:00
--*** MEMBERSHIP BUTTONS ***--
flow2 = flow.add ( {
name = ' membership_buttons ' ,
type = ' flow ' ,
direction = ' horizontal ' ,
} )
flow3 = flow2.add ( {
name = ' leave_crew ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_buttons_quit_crew ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_buttons_quit_crew_tooltip ' }
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' leave_spectators ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_buttons_quit_spectators ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
flow3 = flow2.add ( {
name = ' spectator_join_crew ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_buttons_join_crew ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
flow3 = flow2.add ( {
name = ' crewmember_join_spectators ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_buttons_join_spectators ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_buttons_join_spectators_tooltip ' }
2021-10-13 09:21:53 +01:00
--*** MEMBERS AND SPECTATORS ***--
2022-05-29 12:36:27 +01:00
flow2 = GuiCommon.flow_add_section ( flow , ' members ' , { ' pirates.gui_crew_window_crewmembers ' } )
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' members_listbox ' ,
type = ' list-box ' ,
} )
flow3.style . margin = 2
2022-02-26 23:33:19 +00:00
flow3.style . maximal_height = 350
2021-10-13 09:21:53 +01:00
2022-02-27 16:42:25 +00:00
flow3 = flow2.add ( {
name = ' officer_resign ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_crewmembers_resign_as_officer ' } ,
2022-02-27 16:42:25 +00:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_crewmembers_resign_as_officer_tooltip ' }
2021-10-13 09:21:53 +01:00
2022-05-29 12:36:27 +01:00
flow2 = GuiCommon.flow_add_section ( flow , ' spectators ' , { ' pirates.gui_crew_window_spectators ' } )
2022-05-29 12:43:31 +01:00
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' spectators_listbox ' ,
type = ' list-box ' ,
} )
flow3.style . margin = 2
flow3.style . maximal_height = 150
--*** DIFFICULTY VOTE ***--
2022-05-29 12:36:27 +01:00
flow2 = GuiCommon.flow_add_section ( flow , ' difficulty_vote ' , { ' pirates.gui_crew_window_vote_for_difficulty ' } )
2021-10-13 09:21:53 +01:00
for i , o in ipairs ( CoreData.difficulty_options ) do
flow3 = flow2.add ( {
name = ' difficulty_option_ ' .. i ,
type = ' button ' ,
caption = o.text ,
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
end
--*** CAPTAIN's ACTIONS ***--
2022-05-29 12:36:27 +01:00
flow2 = GuiCommon.flow_add_section ( flow , ' captain ' , { ' pirates.gui_crew_window_captains_actions ' } )
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' capn_disband_crew ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_disband_crew ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_disband_crew_tooltip ' }
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' capn_disband_are_you_sure ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_disband_crew_check ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_disband_crew_check_tooltip ' }
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' capn_renounce ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_renounce_title ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_renounce_title_tooltip ' }
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' capn_pass ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_pass_title ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_pass_title_tooltip ' }
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' capn_plank ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_plank ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_plank_tooltip ' }
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' line ' ,
type = ' line ' ,
} )
flow3.style . width = 50
flow3.style . left_margin = 20
flow3.style . top_margin = 4
flow3.style . bottom_margin = 4
2022-02-26 23:33:19 +00:00
-- flow3 = flow2.add({
-- name = 'capn_undock_normal',
-- type = 'button',
-- caption = 'Undock Boat',
-- })
-- flow3.style.minimal_width = 95
-- flow3.style.font = 'default-bold'
-- flow3.style.font_color = {r=0.10, g=0.10, b=0.10}
flow3 = flow2.add ( {
name = ' make_officer ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_make_officer ' } ,
2022-02-26 23:33:19 +00:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_make_officer_tooltip ' }
2022-02-26 23:33:19 +00:00
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
2022-02-26 23:33:19 +00:00
name = ' unmake_officer ' ,
2021-10-13 09:21:53 +01:00
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_unmake_officer ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_unmake_officer_tooltip ' }
2021-10-13 09:21:53 +01:00
flow3 = flow2.add ( {
name = ' capn_summon_crew ' ,
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_summon_crew ' } ,
2021-10-13 09:21:53 +01:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-05-29 12:36:27 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_summon_crew_tooltip ' }
2021-10-13 09:21:53 +01:00
2022-02-24 19:39:03 +00:00
flow3 = flow2.add ( {
2022-03-13 18:19:59 +00:00
name = ' capn_requisition ' ,
2022-02-24 19:39:03 +00:00
type = ' button ' ,
2022-05-29 12:36:27 +01:00
caption = { ' pirates.gui_crew_window_captains_actions_tax ' } ,
2022-02-24 19:39:03 +00:00
} )
flow3.style . minimal_width = 95
flow3.style . font = ' default-bold '
flow3.style . font_color = { r = 0.10 , g = 0.10 , b = 0.10 }
2022-06-01 19:50:36 +01:00
flow3.tooltip = { ' pirates.gui_crew_window_captains_actions_tax_tooltip ' , Common.coin_tax_percentage }
2022-02-24 19:39:03 +00:00
2022-02-26 23:33:19 +00:00
flow2 = flow.add ( {
name = ' undock_tip ' ,
type = ' label ' ,
} )
flow2.style . left_margin = 5
flow2.style . top_margin = - 8
flow2.style . bottom_margin = 7
flow2.style . single_line = false
flow2.style . maximal_width = 190
flow2.style . font = ' default '
2022-05-29 12:36:27 +01:00
flow2.caption = { ' pirates.gui_crew_window_captains_actions_undock_tip ' }
2022-02-26 23:33:19 +00:00
2021-10-13 09:21:53 +01:00
2022-07-07 23:01:45 +03:00
GuiCommon.flow_add_close_button ( window , window_name .. ' _piratebutton ' )
2021-10-13 09:21:53 +01:00
end
2022-03-19 21:20:55 +00:00
-- function Public.regular_update(player)
2022-03-13 01:44:32 +00:00
2022-03-19 21:20:55 +00:00
-- end
2022-03-13 01:44:32 +00:00
function Public . full_update ( player )
2022-03-20 11:41:23 +00:00
if Public.regular_update then Public.regular_update ( player ) end
2021-10-13 09:21:53 +01:00
if not player.gui . screen [ window_name .. ' _piratewindow ' ] then return end
2022-07-07 23:01:45 +03:00
local window = player.gui . screen [ window_name .. ' _piratewindow ' ]
local flow = window.scroll_pane
2021-10-13 09:21:53 +01:00
local memory = Memory.get_crew_memory ( )
2022-03-19 21:20:55 +00:00
local playercrew_status = GuiCommon.crew_overall_state_bools ( player.index )
2021-10-13 09:21:53 +01:00
--*** WHAT TO SHOW ***--
flow.difficulty_vote . visible = memory.overworldx and memory.overworldx == 0
2022-02-27 16:42:25 +00:00
flow.members . body.officer_resign . visible = memory.officers_table and memory.officers_table [ player.index ]
2022-02-26 23:33:19 +00:00
local other_player_selected = flow.members . body.members_listbox . selected_index ~= 0 and tonumber ( flow.members . body.members_listbox . get_item ( flow.members . body.members_listbox . selected_index ) [ 2 ] ) ~= player.index
2022-03-01 21:59:48 +00:00
flow.captain . visible = Common.is_captain ( player )
flow.undock_tip . visible = Common.is_captain ( player )
2022-02-27 16:42:25 +00:00
2022-02-26 23:33:19 +00:00
flow.captain . body.capn_pass . visible = other_player_selected
2021-10-13 09:21:53 +01:00
flow.captain . body.capn_plank . visible = flow.captain . body.capn_pass . visible
2022-02-26 23:33:19 +00:00
flow.captain . body.make_officer . visible = other_player_selected and ( not ( memory.officers_table and memory.officers_table [ tonumber ( flow.members . body.members_listbox . get_item ( flow.members . body.members_listbox . selected_index ) [ 2 ] ) ] ) )
flow.captain . body.unmake_officer . visible = other_player_selected and ( ( memory.officers_table and memory.officers_table [ tonumber ( flow.members . body.members_listbox . get_item ( flow.members . body.members_listbox . selected_index ) [ 2 ] ) ] ) )
-- flow.captain.body.capn_undock_normal.visible = memory.boat and memory.boat.state and ((memory.boat.state == Boats.enum_state.LANDED) or (memory.boat.state == Boats.enum_state.APPROACHING) or (memory.boat.state == Boats.enum_state.DOCKED))
2021-10-13 09:21:53 +01:00
flow.captain . body.capn_summon_crew . visible = false
2022-03-13 18:19:59 +00:00
flow.captain . body.capn_requisition . visible = true
2021-10-13 09:21:53 +01:00
-- flow.captain.body.capn_summon_crew.visible = memory.boat and memory.boat.state and (memory.boat.state == Boats.enum_state.RETREATING or memory.boat.state == Boats.enum_state.LEAVING_DOCK)
flow.captain . body.capn_disband_are_you_sure . visible = memory.disband_are_you_sure_ticks and memory.disband_are_you_sure_ticks [ player.index ] and memory.disband_are_you_sure_ticks [ player.index ] > game.tick - 60 * 2
flow.captain . body.capn_disband_crew . visible = not flow.captain . body.capn_disband_are_you_sure . visible
flow.members . visible = true
flow.spectators . visible = ( # memory.spectatorplayerindices > 0 )
-- flow.crew_age.visible = true
-- -- flow.crew_age.visible = memory.mode and memory.mode == 'speedrun'
-- flow.crew_difficulty.visible = true
2022-03-19 21:20:55 +00:00
2021-10-13 09:21:53 +01:00
local count = 0
if playercrew_status.spectating then
for _ , v in pairs ( memory.crewplayerindices ) do
if Common.validate_player ( game.players [ v ] ) then count = count + 1 end
end
end
flow.membership_buttons . spectator_join_crew.visible = playercrew_status.spectating and ( not ( count >= memory.capacity ) )
flow.membership_buttons . leave_crew.visible = playercrew_status.adventuring
2022-03-04 18:03:48 +00:00
-- flow.membership_buttons.crewmember_join_spectators.visible = playercrew_status.adventuring
flow.membership_buttons . crewmember_join_spectators.visible = false --disabled spectators for now... might not play well with maze world
2021-10-13 09:21:53 +01:00
flow.membership_buttons . leave_spectators.visible = playercrew_status.spectating
flow.membership_buttons . spectator_join_crew.visible = flow.membership_buttons . spectator_join_crew.visible and ( not ( memory.tempbanned_from_joining_data [ player.index ] and game.tick < memory.tempbanned_from_joining_data [ player.index ] + Common.ban_from_rejoining_crew_ticks ) )
--== UPDATE CONTENT ==--
2022-03-19 21:20:55 +00:00
2022-07-07 23:01:45 +03:00
if Common.is_id_valid ( memory.id ) then
window.caption = memory.name
2021-10-13 09:21:53 +01:00
2022-05-29 12:36:27 +01:00
flow.crew_age . caption = { ' pirates.gui_crew_window_crew_age ' , Utils.time_mediumform ( ( memory.age or 0 ) / 60 ) }
flow.crew_capacity_and_difficulty . caption = { ' pirates.gui_crew_window_crew_capacity_and_difficulty ' , CoreData.difficulty_options [ memory.difficulty_option ] . text , CoreData.capacity_options [ memory.capacity_option ] . text3 }
2021-10-13 09:21:53 +01:00
end
if flow.members . visible then
local wrappedcrew = { }
for _ , index in pairs ( memory.crewplayerindices ) do
local player2 = game.players [ index ]
local tag_text = Roles.tag_text ( player2 )
wrappedcrew [ # wrappedcrew + 1 ] = { ' pirates.crewmember_displayform ' , index , player2.color . r , player2.color . g , player2.color . b , player2.name , tag_text }
end
GuiCommon.update_listbox ( flow.members . body.members_listbox , wrappedcrew )
2022-05-29 12:36:27 +01:00
flow.members . header.caption = { ' pirates.gui_crew_window_crew_count ' , ( # memory.crewplayerindices or 0 ) }
2021-10-13 09:21:53 +01:00
end
if flow.spectators . visible then
local wrappedspectators = { }
for _ , index in pairs ( memory.spectatorplayerindices ) do
local player2 = game.players [ index ]
wrappedspectators [ # wrappedspectators + 1 ] = { ' pirates.crewmember_displayform ' , index , player2.color . r , player2.color . g , player2.color . b , player2.name , ' ' }
end
GuiCommon.update_listbox ( flow.spectators . body.spectators_listbox , wrappedspectators )
end
2022-02-26 23:33:19 +00:00
-- if flow.captain.body.capn_undock_normal.visible then
2022-03-04 17:57:58 +00:00
-- flow.captain.body.capn_undock_normal.enabled = ((memory.boat.state == Boats.enum_state.LANDED) and Common.query_can_pay_cost_to_leave()) or (memory.boat.state == Boats.enum_state.DOCKED)
2022-02-26 23:33:19 +00:00
-- end
2021-10-13 09:21:53 +01:00
end
function Public . click ( event )
2022-10-10 20:21:14 +03:00
-- This is only needed since we call click on every single GUI element and if element gets destroyed, it's no good (these checks wouldn't be needed (I think) if GUI was purely event driven)
if not event.element then return end
if not event.element . valid then return end
2021-10-13 09:21:53 +01:00
local player = game.players [ event.element . player_index ]
local eventname = event.element . name
if not player.gui . screen [ window_name .. ' _piratewindow ' ] then return end
2022-07-29 15:30:32 +01:00
local window = player.gui . screen [ window_name .. ' _piratewindow ' ]
local flow = window.scroll_pane
2021-10-13 09:21:53 +01:00
local memory = Memory.get_crew_memory ( )
if eventname == ' crewmember_join_spectators ' then
Crew.join_spectators ( player , memory.id )
return
end
if eventname == ' leave_spectators ' then
Crew.leave_spectators ( player )
return
end
if eventname == ' spectator_join_crew ' then
Crew.join_crew ( player , memory.id )
return
end
if eventname == ' leave_crew ' then
2022-03-08 23:36:03 +00:00
Crew.leave_crew ( player , true )
2021-10-13 09:21:53 +01:00
return
end
2022-02-25 00:01:28 +00:00
-- if eventname == 'promote_officer' then
-- Roles.promote_to_officer(player)
-- return
-- end
-- if eventname == 'demote_officer' then
-- Roles.demote_to_officer(player)
-- return
-- end
2021-10-13 09:21:53 +01:00
if string.sub ( eventname , 1 , 18 ) and string.sub ( eventname , 1 , 18 ) == ' difficulty_option_ ' then
2022-05-30 16:51:08 +01:00
Crew.difficulty_vote ( player.index , tonumber ( string.sub ( eventname , 19 , - 1 ) ) )
2021-10-13 09:21:53 +01:00
return
end
if eventname == ' capn_summon_crew ' then
--double check:
2022-02-26 23:33:19 +00:00
if Roles.player_privilege_level ( player ) >= Roles.privilege_levels . CAPTAIN then
2021-10-13 09:21:53 +01:00
Crew.summon_crew ( )
end
return
end
2022-03-13 18:19:59 +00:00
if eventname == ' capn_requisition ' then
2022-02-24 19:39:03 +00:00
--double check:
2022-02-26 23:33:19 +00:00
if Roles.player_privilege_level ( player ) >= Roles.privilege_levels . CAPTAIN then
2022-05-06 13:43:59 +01:00
Roles.captain_tax ( memory.playerindex_captain )
2022-02-24 19:39:03 +00:00
end
return
end
2021-10-13 09:21:53 +01:00
if eventname == ' capn_renounce ' then
Roles.renounce_captainhood ( player )
return
end
2022-02-27 16:42:25 +00:00
if eventname == ' officer_resign ' then
Roles.resign_as_officer ( player )
return
end
2021-10-13 09:21:53 +01:00
if eventname == ' capn_disband_crew ' then
--double check:
2022-02-26 23:33:19 +00:00
if Roles.player_privilege_level ( player ) >= Roles.privilege_levels . CAPTAIN then
2021-10-13 09:21:53 +01:00
if not memory.disband_are_you_sure_ticks then memory.disband_are_you_sure_ticks = { } end
memory.disband_are_you_sure_ticks [ player.index ] = game.tick
end
return
end
if eventname == ' capn_disband_are_you_sure ' then
--double check:
2022-02-26 23:33:19 +00:00
if Roles.player_privilege_level ( player ) >= Roles.privilege_levels . CAPTAIN then
2022-03-04 17:57:58 +00:00
local force = memory.force
2021-10-13 09:21:53 +01:00
if force and force.valid then
2022-05-29 12:36:27 +01:00
local message = { ' pirates.crew_disbanded ' , player.name , memory.name , Utils.time_longform ( ( memory.real_age or 0 ) / 60 ) }
2021-10-13 09:21:53 +01:00
Common.notify_game ( message )
2022-05-29 12:36:27 +01:00
Server.to_discord_embed_raw ( { ' ' , CoreData.comfy_emojis . trashbin .. ' [ ' .. memory.name .. ' ] ' , message } , true )
2021-10-13 09:21:53 +01:00
end
Crew.disband_crew ( true )
end
return
end
if eventname == ' capn_pass ' then
local other_id = tonumber ( flow.members . body.members_listbox . get_item ( flow.members . body.members_listbox . selected_index ) [ 2 ] )
Roles.pass_captainhood ( player , game.players [ other_id ] )
return
end
2022-02-26 23:33:19 +00:00
if eventname == ' make_officer ' then
local other_id = tonumber ( flow.members . body.members_listbox . get_item ( flow.members . body.members_listbox . selected_index ) [ 2 ] )
Roles.make_officer ( player , game.players [ other_id ] )
return
end
if eventname == ' unmake_officer ' then
local other_id = tonumber ( flow.members . body.members_listbox . get_item ( flow.members . body.members_listbox . selected_index ) [ 2 ] )
Roles.unmake_officer ( player , game.players [ other_id ] )
return
end
2021-10-13 09:21:53 +01:00
if eventname == ' capn_plank ' then
local other_id = tonumber ( flow.members . body.members_listbox . get_item ( flow.members . body.members_listbox . selected_index ) [ 2 ] )
2022-03-08 23:36:03 +00:00
Crew.plank ( player , game.players [ other_id ] )
2021-10-13 09:21:53 +01:00
return
end
end
return Public