Skip to content

Commit

Permalink
Pirates - disable autojoin for now since everyone gets captain role
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerkiz committed Jul 23, 2024
1 parent bf3724f commit 972b8d4
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions maps/pirates/api_events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1531,58 +1531,61 @@ local function event_on_player_joined_game(event)
Common.ensure_chunks_at(surface, spawnpoint, 5)
end

Common.notify_player_expected(player, {'pirates.player_join_game_info'})
Common.notify_player_expected(player, { 'pirates.player_join_game_info' })

player.force = Common.lobby_force_name

-- Auto-join the oldest crew:
local ages = {}
for _, memory in pairs(global_memory.crew_memories) do
if Common.is_id_valid(memory.id)
and (not memory.run_is_private)
and memory.crewstatus == Crew.enum.ADVENTURING
and memory.capacity
and memory.crewplayerindices
and #memory.crewplayerindices < memory.capacity
and (not (memory.tempbanned_from_joining_data
and memory.tempbanned_from_joining_data[player.index]
and game.tick < memory.tempbanned_from_joining_data[player.index] + Common.ban_from_rejoining_crew_ticks)) then
ages[#ages+1] = {id = memory.id, age = memory.age, large = (memory.capacity >= Common.minimum_run_capacity_to_enforce_space_for)}
end
end
table.sort(
ages,
function(a, b) --true if a should be to the left of b
if a.large and (not b.large) then
return true
elseif (not a.large) and b.large then
return false
else
return a.age > b.age
end
end
)
if ages[1] then
Crew.join_crew(player)

local memory = global_memory.crew_memories[ages[1].id]
if (not memory.run_is_protected) and #memory.crewplayerindices <= 1 then
Roles.make_captain(player)
end

if ages[2] then
if ages[1].large and (not ages[#ages].large) then
Common.notify_player_announce(player, {'pirates.goto_oldest_crew_with_large_capacity'})
else
Common.notify_player_announce(player, {'pirates.goto_oldest_crew'})
end
end
-- It was suggested to always spawn players in lobby, in hopes that they may want to create their crew increasing the popularity of scenario.

if memory.run_is_protected and (not Roles.captain_exists()) then
Common.notify_player_expected(player, {'pirates.player_joins_protected_run_with_no_captain'})
Common.notify_player_expected(player, {'pirates.create_new_crew_tip'})
end
end
-- Auto-join the oldest crew:
-- local ages = {}
-- for _, memory in pairs(global_memory.crew_memories) do
-- if Common.is_id_valid(memory.id)
-- and (not memory.run_is_private)
-- and memory.crewstatus == Crew.enum.ADVENTURING
-- and memory.capacity
-- and memory.crewplayerindices
-- and #memory.crewplayerindices < memory.capacity
-- and (not (memory.tempbanned_from_joining_data
-- and memory.tempbanned_from_joining_data[player.index]
-- and game.tick < memory.tempbanned_from_joining_data[player.index] + Common.ban_from_rejoining_crew_ticks)) then
-- ages[#ages+1] = {id = memory.id, age = memory.age, large = (memory.capacity >= Common.minimum_run_capacity_to_enforce_space_for)}
-- end
-- end
-- table.sort(
-- ages,
-- function(a, b) --true if a should be to the left of b
-- if a.large and (not b.large) then
-- return true
-- elseif (not a.large) and b.large then
-- return false
-- else
-- return a.age > b.age
-- end
-- end
-- )
-- if ages[1] then
-- Crew.join_crew(player)

-- local memory = global_memory.crew_memories[ages[1].id]
-- if (not memory.run_is_protected) and #memory.crewplayerindices <= 1 then
-- Roles.make_captain(player)
-- end

-- if ages[2] then
-- if ages[1].large and (not ages[#ages].large) then
-- Common.notify_player_announce(player, {'pirates.goto_oldest_crew_with_large_capacity'})
-- else
-- Common.notify_player_announce(player, {'pirates.goto_oldest_crew'})
-- end
-- end

-- if memory.run_is_protected and (not Roles.captain_exists()) then
-- Common.notify_player_expected(player, {'pirates.player_joins_protected_run_with_no_captain'})
-- Common.notify_player_expected(player, {'pirates.create_new_crew_tip'})
-- end
-- end
end

if not _DEBUG then
Expand Down

0 comments on commit 972b8d4

Please sign in to comment.