mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Merge Game, FlyingText, Common and table
This commit is contained in:
@@ -2,12 +2,10 @@
|
||||
-- also displays a ping above users who are named in the message
|
||||
-- @addon Chat-Popups
|
||||
|
||||
local FloatingText = require("modules/exp_util/floating_text")
|
||||
local FlyingText = require("modules/exp_util/flying_text")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local config = require("modules.exp_legacy.config.popup_messages") --- @dep config.popup_messages
|
||||
|
||||
local send_text = FloatingText.print_as_player -- (player, text)
|
||||
|
||||
Event.add(defines.events.on_console_chat, function(event)
|
||||
if not event.player_index or event.player_index < 1 then return end
|
||||
local player = game.players[event.player_index]
|
||||
@@ -18,7 +16,10 @@ Event.add(defines.events.on_console_chat, function(event)
|
||||
|
||||
-- Sends the message as text above them
|
||||
if config.show_player_messages then
|
||||
send_text(player, { "chat-popup.message", player.name, event.message })
|
||||
FlyingText.create_as_player{
|
||||
target_player = player,
|
||||
text = { "chat-popup.message", player.name, event.message },
|
||||
}
|
||||
end
|
||||
|
||||
if not config.show_player_mentions then return end
|
||||
@@ -30,7 +31,10 @@ Event.add(defines.events.on_console_chat, function(event)
|
||||
for _, mentioned_player in pairs(game.connected_players) do
|
||||
if mentioned_player.index ~= player.index then
|
||||
if search_string:find(mentioned_player.name:lower(), 1, true) then
|
||||
send_text(mentioned_player, { "chat-popup.ping", player.name })
|
||||
FlyingText.create_as_player{
|
||||
target_player = mentioned_player,
|
||||
text = { "chat-popup.ping", player.name },
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
-- also shows player health when a player is attacked
|
||||
-- @addon Damage-Popups
|
||||
|
||||
local FloatingText = require("modules/exp_util/floating_text")
|
||||
local FlyingText = require("modules/exp_util/flying_text")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local config = require("modules.exp_legacy.config.popup_messages") --- @dep config.popup_messages
|
||||
|
||||
@@ -31,11 +31,10 @@ Event.add(defines.events.on_entity_damaged, function(event)
|
||||
|
||||
-- Outputs the message as floating text
|
||||
if message then
|
||||
FloatingText.print(
|
||||
entity.surface,
|
||||
position,
|
||||
message,
|
||||
text_colour
|
||||
)
|
||||
FlyingText.create{
|
||||
text = message,
|
||||
position = position,
|
||||
color = text_colour,
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
--- Makes markers on the map where places have died and reclaims items if not recovered
|
||||
-- @addon Death-Logger
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local config = require("modules.exp_legacy.config.death_logger") --- @dep config.death_logger
|
||||
local format_time, move_items = _C.format_time, _C.move_items_stack --- @dep expcore.common
|
||||
|
||||
-- Max amount of ticks a corpse can be alive
|
||||
local corpse_lifetime = 60 * 60 * 15
|
||||
@@ -17,12 +17,14 @@ Storage.register(deaths, function(tbl)
|
||||
deaths = tbl
|
||||
end)
|
||||
|
||||
local map_tag_time_format = ExpUtil.format_time_factory{ format = "short", hours = true, minutes = true }
|
||||
|
||||
--- Creates a new death marker and saves it to the given death
|
||||
local function create_map_tag(death)
|
||||
local player = game.players[death.player_name]
|
||||
local message = player.name .. " died"
|
||||
if config.include_time_of_death then
|
||||
local time = format_time(death.time_of_death, { hours = true, minutes = true, string = true })
|
||||
local time = map_tag_time_format(death.time_of_death)
|
||||
message = message .. " at " .. time
|
||||
end
|
||||
death.tag = player.force.add_chart_tag(player.surface, {
|
||||
@@ -60,14 +62,21 @@ local function check_map_tags()
|
||||
end
|
||||
|
||||
-- when a player dies a new death is added to the records and a map marker is made
|
||||
--- @param event EventData.on_player_died
|
||||
Event.add(defines.events.on_player_died, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
local corpse = player.surface.find_entity("character-corpse", player.position)
|
||||
if not corpse or not corpse.valid then return end
|
||||
if config.use_chests_as_bodies then
|
||||
local items = corpse.get_inventory(defines.inventory.character_corpse)
|
||||
local chest = move_items(items, corpse.surface, corpse.position)
|
||||
chest.destructible = false
|
||||
local inventory = assert(corpse.get_inventory(defines.inventory.character_corpse))
|
||||
local chest = ExpUtil.transfer_inventory_to_surface{
|
||||
inventory = inventory,
|
||||
surface = corpse.surface,
|
||||
position = corpse.position,
|
||||
name = "iron-chest",
|
||||
allow_creation = true,
|
||||
}
|
||||
|
||||
corpse.destroy()
|
||||
corpse = chest
|
||||
end
|
||||
@@ -139,10 +148,16 @@ if config.show_map_markers then
|
||||
end
|
||||
|
||||
if config.auto_collect_bodies then
|
||||
--- @param event EventData.on_character_corpse_expired
|
||||
Event.add(defines.events.on_character_corpse_expired, function(event)
|
||||
local corpse = event.corpse
|
||||
local items = corpse.get_inventory(defines.inventory.character_corpse)
|
||||
move_items(items, corpse.surface, { x = 0, y = 0 })
|
||||
local inventory = assert(corpse.get_inventory(defines.inventory.character_corpse))
|
||||
ExpUtil.transfer_inventory_to_surface{
|
||||
inventory = inventory,
|
||||
surface = corpse.surface,
|
||||
name = "iron-chest",
|
||||
allow_creation = true,
|
||||
}
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
--- Log certain actions into a file when events are triggered
|
||||
-- @addon Deconlog
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local format_time = _C.format_time --- @dep expcore.common
|
||||
local format_number = require("util").format_number --- @dep util
|
||||
local config = require("modules.exp_legacy.config.deconlog") --- @dep config.deconlog
|
||||
|
||||
local filepath = "log/decon.log"
|
||||
local seconds_time_format = ExpUtil.format_time_factory{ format = "short", hours = true, minutes = true, seconds = true }
|
||||
|
||||
local function add_log(data)
|
||||
game.write_file(filepath, data .. "\n", true, 0) -- write data
|
||||
end
|
||||
|
||||
local function get_secs()
|
||||
return format_time(game.tick, { hours = true, minutes = true, seconds = true, string = true })
|
||||
return seconds_time_format(game.tick)
|
||||
end
|
||||
|
||||
local function pos_to_string(pos)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
--- Sends alert messages to our discord server when certain events are triggered
|
||||
-- @addon Discord-Alerts
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Colors = require("modules/exp_util/include/color")
|
||||
local write_json, format_time = _C.write_json, _C.format_time --- @dep expcore.common
|
||||
local config = require("modules.exp_legacy.config.discord_alerts") --- @dep config.discord_alerts
|
||||
local write_json = ExpUtil.write_json
|
||||
|
||||
local playtime_format = { hours = true, minutes = true, short = true, string = true }
|
||||
local playtime_format = ExpUtil.format_time_factory{ format = "short", hours = true, minutes = true, seconds = true }
|
||||
local emit_event_time_format = ExpUtil.format_time_factory{ format = "short", hours = true, minutes = true }
|
||||
|
||||
local function append_playtime(player_name)
|
||||
if not config.show_playtime then
|
||||
@@ -19,7 +21,7 @@ local function append_playtime(player_name)
|
||||
return player_name
|
||||
end
|
||||
|
||||
return player.name .. " (" .. format_time(player.online_time, playtime_format) .. ")"
|
||||
return player.name .. " (" .. playtime_format(player.online_time) .. ")"
|
||||
end
|
||||
|
||||
local function get_player_name(event)
|
||||
@@ -48,7 +50,7 @@ local function emit_event(args)
|
||||
end
|
||||
|
||||
local tick = args.tick or game.tick
|
||||
local tick_formatted = format_time(tick, { days = false, hours = true, minutes = true, short = true, string = true })
|
||||
local tick_formatted = emit_event_time_format(tick)
|
||||
|
||||
local players_online = 0
|
||||
local admins_online = 0
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
--- Will move players items to spawn when they are banned or kicked, option to clear on leave
|
||||
-- @addon Inventory-Clear
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local events = require("modules.exp_legacy.config.inventory_clear") --- @dep config.inventory_clear
|
||||
local move_items_stack = _C.move_items_stack --- @dep expcore.common
|
||||
|
||||
local function clear_items(event)
|
||||
local player = game.players[event.player_index]
|
||||
local inv = player.get_main_inventory() --- @cast inv -nil
|
||||
move_items_stack(inv)
|
||||
inv.clear()
|
||||
local inventory = assert(player.get_main_inventory())
|
||||
ExpUtil.transfer_inventory_to_surface{
|
||||
inventory = inventory,
|
||||
surface = game.surfaces[1],
|
||||
name = "iron-chest",
|
||||
allow_creation = true,
|
||||
}
|
||||
end
|
||||
|
||||
for _, event_name in ipairs(events) do Event.add(event_name, clear_items) end
|
||||
|
||||
@@ -110,7 +110,7 @@ local function miner_check(entity)
|
||||
local entities = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, type = { "mining-drill", "pipe", "pipe-to-ground" } }
|
||||
local entities_t = es.find_entities_filtered{ area = { { ep.x - r, ep.y - r }, { ep.x + r, ep.y + r } }, ghost_type = { "pipe", "pipe-to-ground" } }
|
||||
|
||||
table.array_insert(entities, entities_t)
|
||||
table.insert_array(entities, entities_t)
|
||||
|
||||
for _, e in pairs(entities) do
|
||||
if (e.position.x > ep.x) and (e.position.y == ep.y) then
|
||||
|
||||
@@ -1,26 +1,36 @@
|
||||
--- Disable new players from having certain items in their inventory, most commonly nukes
|
||||
-- @addon Nukeprotect
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||
local config = require("modules.exp_legacy.config.nukeprotect") --- @dep config.nukeprotect
|
||||
local move_items_stack = _C.move_items_stack --- @dep expcore.common
|
||||
|
||||
--- Check all items in the given inventory
|
||||
---@param player LuaPlayer
|
||||
---@param type defines.inventory
|
||||
local function check_items(player, type)
|
||||
-- if the player has perms to be ignored, then they should be
|
||||
if config.ignore_permisison and Roles.player_allowed(player, config.ignore_permisison) then return end
|
||||
-- if the players
|
||||
if config.ignore_admins and player.admin then return end
|
||||
|
||||
local inventory = player.get_inventory(type)
|
||||
local items = {} --- @type LuaItemStack[]
|
||||
local inventory = assert(player.get_inventory(type))
|
||||
for i = 1, #inventory do
|
||||
local item = inventory[i]
|
||||
if item.valid and item.valid_for_read and config[tostring(type)][item.name] then
|
||||
player.print{ "nukeprotect.found", { "item-name." .. item.name } }
|
||||
-- insert the items into the table so all items are transferred at once
|
||||
move_items_stack{ item }
|
||||
items[#items + 1] = item
|
||||
end
|
||||
end
|
||||
|
||||
ExpUtil.move_items_to_surface{
|
||||
items = items,
|
||||
surface = player.surface,
|
||||
allow_creation = true,
|
||||
name = "iron-chest",
|
||||
}
|
||||
end
|
||||
|
||||
for _, inventory in ipairs(config.inventories) do
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
--- When a player triggers protection multiple times they are automatically jailed
|
||||
-- @addon protection-jail
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Storage = require("modules/exp_util/storage") --- @dep utils.global
|
||||
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
|
||||
local Protection = require("modules.exp_legacy.modules.control.protection") --- @dep modules.control.protection
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common
|
||||
|
||||
--- Stores how many times the repeat violation was triggered
|
||||
local repeat_count = {}
|
||||
@@ -29,7 +30,7 @@ Event.add(Protection.events.on_repeat_violation, function(event)
|
||||
return
|
||||
end
|
||||
|
||||
local player_name_color = format_chat_player_name(player)
|
||||
local player_name_color = format_player_name(player)
|
||||
Jail.jail_player(player, "<protection>", "Removed too many protected entities, please wait for a moderator.")
|
||||
game.print{ "protection-jail.jail", player_name_color }
|
||||
end)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
--- When a player is reported, the player is automatically jailed if the combined playtime of the reporters exceeds the reported player
|
||||
-- @addon report-jail
|
||||
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Jail = require("modules.exp_legacy.modules.control.jail") --- @dep modules.control.jail
|
||||
local Reports = require("modules.exp_legacy.modules.control.reports") --- @dep modules.control.reports
|
||||
local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common
|
||||
local format_player_name = ExpUtil.format_player_name_locale --- @dep expcore.common
|
||||
|
||||
--- Returns the playtime of the reporter. Used when calculating the total playtime of all reporters
|
||||
local function reporter_playtime(_, by_player_name, _)
|
||||
@@ -21,7 +22,7 @@ Event.add(Reports.events.on_player_reported, function(event)
|
||||
|
||||
-- player less than 30 min
|
||||
if (Reports.count_reports(player) > 1) and (total_playtime > math.max(player.online_time * 2, 108000)) then
|
||||
local player_name_color = format_chat_player_name(player)
|
||||
local player_name_color = format_player_name(player)
|
||||
Jail.jail_player(player, "<reports>", "Reported by too many players, please wait for a moderator.")
|
||||
game.print{ "report-jail.jail", player_name_color }
|
||||
end
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
-- @addon Scorched-Earth
|
||||
|
||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local print_grid_value, clear_flying_text = _C.print_grid_value, _C.clear_flying_text --- @dep expcore.common
|
||||
local config = require("modules.exp_legacy.config.scorched_earth") --- @dep config.scorched_earth
|
||||
|
||||
-- Loops over the config and finds the wile which has the highest value for strength
|
||||
@@ -14,12 +12,6 @@ for _, strength in pairs(config.strengths) do
|
||||
end
|
||||
end
|
||||
|
||||
-- Used for debugging the degrade chances
|
||||
local debug_players = {}
|
||||
Storage.register(debug_players, function(tbl)
|
||||
debug_players = tbl
|
||||
end)
|
||||
|
||||
-- Will degrade a tile down to the next tile when called
|
||||
local function degrade(surface, position)
|
||||
local tile = surface.get_tile(position)
|
||||
@@ -80,19 +72,6 @@ local function get_tile_strength(surface, position)
|
||||
return strength / 9
|
||||
end
|
||||
|
||||
-- Same as get_tile_strength but returns to a in game text rather than as a value
|
||||
local function debug_get_tile_strength(surface, position)
|
||||
for x = -3, 3 do -- x loop
|
||||
local px = position.x + x
|
||||
for y = -3, 3 do -- y loop
|
||||
local p = { x = px, y = position.y + y }
|
||||
local strength = get_tile_strength(surface, p) or 0
|
||||
local tile = surface.get_tile(p)
|
||||
print_grid_value(get_probability(strength) * config.weakness_value, surface, tile.position)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- When the player changes position the tile will have a chance to downgrade, debug check is here
|
||||
Event.add(defines.events.on_player_changed_position, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
@@ -103,9 +82,6 @@ Event.add(defines.events.on_player_changed_position, function(event)
|
||||
if get_probability(strength) > math.random() then
|
||||
degrade(surface, position)
|
||||
end
|
||||
if debug_players[player.name] then
|
||||
debug_get_tile_strength(surface, position)
|
||||
end
|
||||
end)
|
||||
|
||||
-- When an entity is build there is a much higher chance that the tiles will degrade
|
||||
@@ -131,10 +107,3 @@ Event.add(defines.events.on_robot_built_entity, function(event)
|
||||
degrade_entity(entity)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Used as a way to access the global table
|
||||
return function(player_name, state)
|
||||
local player = game.players[player_name]
|
||||
clear_flying_text(player.surface)
|
||||
debug_players[player_name] = state
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user