Skip to content

Commit

Permalink
Merge branch 'develop' into stylua-ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmartin0 authored Nov 1, 2024
2 parents 11d4012 + 6f5e8a7 commit c8c52e9
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 51 deletions.
4 changes: 2 additions & 2 deletions maps/mountain_fortress_v3/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ local artillery_target_entities = {
'car',
'radar',
'lab',
'furnace',
'stone-furnace',
'locomotive',
'cargo-wagon',
'fluid-wagon',
Expand All @@ -120,7 +120,7 @@ local artillery_target_entities = {
'laser-turret',
'gun-turret',
'flamethrower-turret',
'silo',
'rocket-silo',
'spidertron'
}

Expand Down
8 changes: 8 additions & 0 deletions maps/mountain_fortress_v3/ic/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,17 @@ local function construct_doors(car)
for _, x in pairs({ area.left_top.x - 1.5, area.right_bottom.x + 1.5 }) do
local p = { x = x, y = area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5) }
if p.x < 0 then
surface.set_tiles({ { name = main_tile_name, position = { x = p.x, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x + 0.5, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x + 0.5, y = p.y - 0.5 } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x + 0.5, y = p.y - 1 } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 0.5, y = p.y - 1 } } }, true)
else
surface.set_tiles({ { name = main_tile_name, position = { x = p.x, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 0.5, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 1, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x, y = p.y - 0.5 } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 1, y = p.y - 0.5 } } }, true)
end
local e =
surface.create_entity(
Expand Down
8 changes: 8 additions & 0 deletions maps/mountain_fortress_v3/icw/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,17 @@ local function construct_wagon_doors(icw, wagon)
for _, x in pairs({ area.left_top.x - 1.5, area.right_bottom.x + 1.5 }) do
local p = { x = x, y = area.left_top.y + ((area.right_bottom.y - area.left_top.y) * 0.5) }
if p.x < 0 then
surface.set_tiles({ { name = main_tile_name, position = { x = p.x, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x + 0.5, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x + 0.5, y = p.y - 0.5 } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x + 0.5, y = p.y - 1 } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 0.5, y = p.y - 1 } } }, true)
else
surface.set_tiles({ { name = main_tile_name, position = { x = p.x, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 0.5, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 1, y = p.y } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x, y = p.y - 0.5 } } }, true)
surface.set_tiles({ { name = main_tile_name, position = { x = p.x - 1, y = p.y - 0.5 } } }, true)
end
local e =
surface.create_entity(
Expand Down
20 changes: 10 additions & 10 deletions maps/mountain_fortress_v3/stateful/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,8 @@ local function update_raw()
stateful.objectives_completed.randomized_zone = true
stateful.objectives_time_spent.randomized_zone = tick
play_achievement_unlocked()
Alert.alert_all_players(100, 'Objective: **breach zone** has been complete!')
Server.to_discord_embed('Objective: **breach zone** has been complete!')
Alert.alert_all_players(100, 'Objective: [color=blue]Breach zone[/color] has been completed!')
Server.to_discord_embed('Objective: **Breach zone** has been completed!')
stateful.objectives_completed_count = stateful.objectives_completed_count + 1
end
end
Expand All @@ -1044,8 +1044,8 @@ local function update_raw()
stateful.objectives_time_spent.randomized_wave = tick

play_achievement_unlocked()
Alert.alert_all_players(100, 'Objective: **survive until wave** has been complete!')
Server.to_discord_embed('Objective: **survive until wave** has been complete!')
Alert.alert_all_players(100, 'Objective: [color=blue]Wave survival[/color] has been completed!')
Server.to_discord_embed('Objective: **Wave survival** has been completed!')
stateful.objectives_completed_count = stateful.objectives_completed_count + 1
end
end
Expand All @@ -1069,8 +1069,8 @@ local function update_raw()
if not stateful.objectives_completed.supplies then
stateful.objectives_completed.supplies = true
stateful.objectives_time_spent.supplies = tick
Alert.alert_all_players(100, 'Objective: **produce 3 items multiple times** has been complete!')
Server.to_discord_embed('Objective: **produce 3 items multiple times** has been complete!')
Alert.alert_all_players(100, 'Objective: [color=blue]Produce items[/color] has been completed!')
Server.to_discord_embed('Objective: **Produce items** has been completed!')
play_achievement_unlocked()
stateful.objectives_completed_count = stateful.objectives_completed_count + 1
end
Expand All @@ -1097,8 +1097,8 @@ local function update_raw()
stateful.objectives_completed.single_item = true
stateful.objectives_time_spent.single_item = tick
play_achievement_unlocked()
Alert.alert_all_players(100, 'Objective: **produce an item multiple times** has been completed!')
Server.to_discord_embed('Objective: **produce an item multiple times** has been completed!')
Alert.alert_all_players(100, 'Objective: [color=blue]Produce item[/color] has been completed!')
Server.to_discord_embed('Objective: **Produce item** has been completed!')
stateful.objectives_completed_count = stateful.objectives_completed_count + 1
end
end
Expand Down Expand Up @@ -1194,8 +1194,8 @@ local function update_raw()
if completed and completed == true and not stateful.objectives_completed[objective_name] then
stateful.objectives_completed[objective_name] = true
stateful.objectives_time_spent[objective_name] = tick
Alert.alert_all_players(100, 'Objective: **' .. objective_name .. '** has been completed!')
Server.to_discord_embed('Objective: **' .. objective_name .. '** has been completed!')
Alert.alert_all_players(100, 'Objective: [color=blue]' .. objective.discord .. '[/color] has been completed!')
Server.to_discord_embed('Objective: **' .. objective.discord .. '** has been completed!')
play_achievement_unlocked()
stateful.objectives_completed_count = stateful.objectives_completed_count + 1
end
Expand Down
36 changes: 24 additions & 12 deletions maps/mountain_fortress_v3/stateful/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -958,51 +958,63 @@ local function get_random_objectives()
local items = {
{
name = 'single_item',
token = empty_token
token = empty_token,
discord = 'Produce item'
},
{
name = 'killed_enemies',
token = killed_enemies_token
token = killed_enemies_token,
discord = 'Kill enemies'
},
{
name = 'killed_enemies_type',
token = killed_enemies_type_token
token = killed_enemies_type_token,
discord = 'Kill enemies of a specific type'
},
{
name = 'handcrafted_items',
token = handcrafted_items_token
token = handcrafted_items_token,
discord = 'Craft items'
},
{
name = 'handcrafted_items_any',
token = handcrafted_items_any_token
token = handcrafted_items_any_token,
discord = 'Craft any items'
},
{
name = 'cast_spell',
token = cast_spell_token
token = cast_spell_token,
discord = 'Cast a spell'
},
{
name = 'launch_item',
token = launch_item_token
token = launch_item_token,
discord = 'Launch an item'
},
{
name = 'cast_spell_any',
token = cast_spell_any_token
token = cast_spell_any_token,
discord = 'Cast any spell'
},
{
name = 'research_level_selection',
token = research_level_selection_token
token = research_level_selection_token,
discord = 'Research a specific technology'
},
{
name = 'locomotive_market_coins_spent',
token = locomotive_market_coins_spent_token
token = locomotive_market_coins_spent_token,
discord = 'Spend coins at the market'
},
{
name = 'minerals_farmed',
token = minerals_farmed_token
token = minerals_farmed_token,
discord = 'Mine minerals'
},
{
name = 'rockets_launched',
token = rockets_launched_token
token = rockets_launched_token,
discord = 'Launch rockets'
}
}

Expand Down
48 changes: 28 additions & 20 deletions modules/clear_vacant_players.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ local this = {
settings = {
is_enabled = false,
offline_players_surface_removal = false,
active_surface_index = nil, -- needs to be set else this will fail
required_online_time = 18000, -- nearest prime to 5 minutes in ticks
active_surface_index = nil, -- needs to be set else this will fail
required_online_time = 18000, -- nearest prime to 5 minutes in ticks
clear_player_after_tick = 108000 -- nearest prime to 30 minutes in ticks
},
offline_players = {}
}

Global.register(
this,
function(tbl)
function (tbl)
this = tbl
end
)
Expand All @@ -43,8 +43,6 @@ function Public.dump_expired_players()
if not surface or not surface.valid then
return
end
local player_inv = {}
local items = {}
if #this.offline_players > 0 then
for i = 1, #this.offline_players, 1 do
if this.offline_players[i] and this.offline_players[i].index then
Expand All @@ -54,8 +52,11 @@ function Public.dump_expired_players()
remove(this.offline_players, i)
else
if this.offline_players[i].tick < tick then
local name = this.offline_players[i].name
player_inv[1] = target.get_inventory(defines.inventory.character_main)
local player_inv = {}
local items = {}

local name = target.name
player_inv[1] = target.get_main_inventory()
player_inv[2] = target.get_inventory(defines.inventory.character_armor)
player_inv[3] = target.get_inventory(defines.inventory.character_guns)
player_inv[4] = target.get_inventory(defines.inventory.character_ammo)
Expand All @@ -64,35 +65,42 @@ function Public.dump_expired_players()
Event.raise(this.events.remove_surface, { target = target })
end

if target.get_item_count() == 0 then -- if the player has zero items, don't do anything
local found_items = false
for index = 1, 5, 1 do
if player_inv[index] and player_inv[index].valid and player_inv[index].get_item_count() ~= 0 then
found_items = true
end
end

if not found_items then -- if the player has zero items, don't do anything
remove(this.offline_players, i)
goto final
end

local pos = game.forces.player.get_spawn_position(surface)
local e =
surface.create_entity(
{
name = 'character',
position = pos,
force = 'neutral'
}
)
surface.create_entity(
{
name = 'character',
position = pos,
force = 'neutral'
}
)
if not e or not e.valid then
break
end

local inv = e.get_inventory(defines.inventory.character_main)
local inv = e.get_main_inventory()
if not inv then
break
end

---@diagnostic disable-next-line: assign-type-mismatch
e.character_inventory_slots_bonus = #player_inv[1]
for ii = 1, 5, 1 do
if player_inv[ii].valid then
if player_inv[ii] and player_inv[ii].valid then
for iii = 1, #player_inv[ii], 1 do
if player_inv[ii][iii].valid then
if player_inv[ii][iii] and player_inv[ii][iii].valid then
insert(items, player_inv[ii][iii])
end
end
Expand All @@ -117,7 +125,7 @@ function Public.dump_expired_players()
end

for ii = 1, 5, 1 do
if player_inv[ii].valid then
if player_inv[ii] and player_inv[ii].valid then
player_inv[ii].clear()
end
end
Expand Down Expand Up @@ -184,7 +192,7 @@ Event.on_nth_tick(tick_frequency, Public.dump_expired_players)

Event.add(
defines.events.on_pre_player_left_game,
function(event)
function (event)
if not this.settings.is_enabled then
return
end
Expand Down
17 changes: 11 additions & 6 deletions utils/alert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,21 @@ local function zoom_to_pos(event)
if is_spamming then
return
end
local player = event.player
local player = event.player
local element = event.element
local target = Gui.get_data(element)
local data = Gui.get_data(element)
if not data then return end

if not target or not target.valid then
if player.controller_type == defines.controllers.remote then
return
end

if target.character ~= nil then target = target.character end
player.centered_on = target
player.set_controller({
type = defines.controllers.remote,
position = data.position,
surface = player.surface,
zoom = 4
})
end

local close_alert = Public.close_alert
Expand Down Expand Up @@ -290,7 +295,7 @@ function Public.alert_all_players_location(player, message, color, duration)
style = 'slot_button'
}

Gui.set_data(sprite, player)
Gui.set_data(sprite, player.position)

local label =
container.add {
Expand Down
21 changes: 20 additions & 1 deletion utils/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,25 @@ function Public:callback(func)
end
end

local directions = {
[0] = 'defines.direction.north',
[1] = 'defines.direction.northnortheast',
[2] = 'defines.direction.northeast',
[3] = 'defines.direction.eastnortheast',
[4] = 'defines.direction.east',
[5] = 'defines.direction.eastsoutheast',
[6] = 'defines.direction.southeast',
[7] = 'defines.direction.southsoutheast',
[8] = 'defines.direction.south',
[9] = 'defines.direction.southsouthwest',
[10] = 'defines.direction.southwest',
[11] = 'defines.direction.westsouthwest',
[12] = 'defines.direction.west',
[13] = 'defines.direction.westnorthwest',
[14] = 'defines.direction.northwest',
[15] = 'defines.direction.northnorthwest',
}

Public.new('get', 'Hover over an object to get its name.')
:require_admin()
:add_parameter('die', true, 'string')
Expand All @@ -602,7 +621,7 @@ Public.new('get', 'Hover over an object to get its name.')
player.print('[color=orange]Name:[/color] ' .. entity.name)
player.print('[color=orange]Type:[/color] ' .. entity.type)
player.print('[color=orange]Force:[/color] ' .. entity.force.name)
player.print('[color=orange]Direction:[/color] ' .. entity.direction)
player.print('[color=orange]Direction:[/color] ' .. entity.direction .. ' (' .. directions[entity.direction] .. ')')
player.print('[color=orange]Destructible:[/color] ' .. (entity.destructible and 'true' or 'false'))
player.print('[color=orange]Minable:[/color] ' .. (entity.minable and 'true' or 'false'))
player.print('[color=orange]Unit Number:[/color] ' .. (entity.unit_number or 'nil'))
Expand Down

0 comments on commit c8c52e9

Please sign in to comment.