mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-03-17 20:58:13 +02:00
Merge branch 'develop' into junkyard-fix
This commit is contained in:
commit
eba5098af9
@ -19,6 +19,10 @@ local Task = require 'utils.task'
|
||||
local Score = require 'comfy_panel.score'
|
||||
local Token = require 'utils.token'
|
||||
local HS = require 'maps.mountain_fortress_v3.highscore'
|
||||
local Discord = require 'utils.discord'
|
||||
local Core = require "utils.core"
|
||||
local Diff = require "modules.difficulty_vote_by_amount"
|
||||
local format_number = require 'util'.format_number
|
||||
|
||||
-- tables
|
||||
local WPT = require 'maps.mountain_fortress_v3.table'
|
||||
@ -32,6 +36,15 @@ local abs = math.abs
|
||||
local sqrt = math.sqrt
|
||||
local round = math.round
|
||||
|
||||
-- Use these settings for live
|
||||
local send_ping_to_channel = Discord.channel_names.mtn_channel
|
||||
-- Use these settings for testing
|
||||
-- bot-lounge
|
||||
-- local send_ping_to_channel = Discord.channel_names.bot_quarters
|
||||
-- dev
|
||||
-- local send_ping_to_channel = Discord.channel_names.bot_quarters
|
||||
-- local role_to_mention = Discord.role_mentions.test_role
|
||||
|
||||
local chests = {
|
||||
'wooden-chest',
|
||||
'iron-chest',
|
||||
@ -1185,6 +1198,28 @@ local function show_mvps(player)
|
||||
table.insert(result, mvp.mined_entities.name .. ' mined a total of ' .. mvp.mined_entities.score .. ' entities!\\n')
|
||||
local message = table.concat(result)
|
||||
Server.to_discord_embed(message)
|
||||
local wave = WD.get_wave()
|
||||
local threat = WD.get('threat')
|
||||
local collapse_speed = Collapse.get_speed()
|
||||
local collapse_amount = Collapse.get_amount()
|
||||
|
||||
local diff = Diff.get()
|
||||
local time_played = Core.format_time(game.ticks_played)
|
||||
local total_players = #game.players
|
||||
local pickaxe_tiers = WPT.pickaxe_upgrades
|
||||
local tier = WPT.get("pickaxe_tier")
|
||||
local pick_tier = pickaxe_tiers[tier]
|
||||
|
||||
Server.to_discord_named_embed(send_ping_to_channel, '**Statistics!**\\n\\n'
|
||||
.. 'Time played: '..time_played..'\\n'
|
||||
.. 'Game Difficulty: '..diff.name..'\\n'
|
||||
.. 'Highest wave: '..format_number(wave, true)..'\\n'
|
||||
.. 'Total connected players: '..total_players..'\\n'
|
||||
.. 'Threat: '..format_number(threat, true)..'\\n'
|
||||
.. 'Pickaxe Upgrade: '..pick_tier..' (' ..tier.. ')\\n'
|
||||
.. 'Collapse Speed: '..collapse_speed..'\\n'
|
||||
.. 'Collapse Amount: '..collapse_amount..'\\n'
|
||||
)
|
||||
WPT.set('sent_to_discord', true)
|
||||
end
|
||||
end
|
||||
|
@ -59,8 +59,6 @@ local role_to_mention = Discord.role_mentions.mtn_fortress
|
||||
-- Use these settings for testing
|
||||
-- bot-lounge
|
||||
-- local send_ping_to_channel = Discord.channel_names.bot_quarters
|
||||
-- dev
|
||||
-- local send_ping_to_channel = Discord.channel_names.dev
|
||||
-- local role_to_mention = Discord.role_mentions.test_role
|
||||
|
||||
local Public = {}
|
||||
@ -522,4 +520,17 @@ end
|
||||
Event.on_nth_tick(10, on_tick)
|
||||
Event.on_init(on_init)
|
||||
|
||||
local gMeta = getmetatable(_ENV)
|
||||
if not gMeta then
|
||||
gMeta = {}
|
||||
setmetatable(_ENV, gMeta)
|
||||
end
|
||||
|
||||
gMeta.__newindex = function(_, n, v)
|
||||
log('Desync warning: attempt to write to undeclared var ' .. n)
|
||||
global[n] = v
|
||||
end
|
||||
gMeta.__index = function(_, n)
|
||||
return global[n]
|
||||
end
|
||||
return Public
|
||||
|
@ -14,14 +14,22 @@ local Timers = require 'maps.planet_prison.mod.timers'
|
||||
local ClaimsFunctions = require 'maps.planet_prison.mod.claims'
|
||||
local MapConfig = require 'maps.planet_prison.config'
|
||||
local Token = require 'utils.token'
|
||||
require 'modules.thirst'
|
||||
local Color = require 'utils.color_presets'
|
||||
-- require 'modules.thirst'
|
||||
|
||||
local this = {}
|
||||
local this = {
|
||||
remove_offline_players = {
|
||||
players = {},
|
||||
time = 18000,
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
local floor = math.floor
|
||||
local ceil = math.ceil
|
||||
local Public = {}
|
||||
local insert = table.insert
|
||||
local remove = table.remove
|
||||
local random = math.random
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
@ -240,8 +248,7 @@ local industrial_zone_layers = {
|
||||
name = 'hostile',
|
||||
objects = {
|
||||
'character',
|
||||
'gun-turret',
|
||||
'small-biter'
|
||||
'gun-turret'
|
||||
},
|
||||
elevation = 0.92,
|
||||
resolution = 0.99,
|
||||
@ -325,8 +332,7 @@ local swampy_rivers_layers = {
|
||||
name = 'hostile',
|
||||
objects = {
|
||||
'character',
|
||||
'gun-turret',
|
||||
'small-biter'
|
||||
'gun-turret'
|
||||
},
|
||||
elevation = 0.92,
|
||||
resolution = 0.99,
|
||||
@ -731,7 +737,15 @@ local function on_gui_click(e)
|
||||
return
|
||||
end
|
||||
|
||||
if elem.name == 'chat_toggle' then
|
||||
if elem.name == 'comfy_panel_top_button' then
|
||||
if not p.admin then
|
||||
if p.gui.left['comfy_panel'] and p.gui.left['comfy_panel'].valid then
|
||||
p.gui.left['comfy_panel'].destroy()
|
||||
end
|
||||
redraw_gui(p)
|
||||
return p.print('Comfy panel is disabled in this scenario.', Color.fail)
|
||||
end
|
||||
elseif elem.name == 'chat_toggle' then
|
||||
if perks.chat_global then
|
||||
elem.caption = 'NAP chat'
|
||||
perks.chat_global = false
|
||||
@ -793,6 +807,8 @@ local function init_player(p)
|
||||
p.force = pf
|
||||
end
|
||||
p.force.set_friend('neutral', true)
|
||||
p.force.set_friend('player', false)
|
||||
p.force.share_chart = false
|
||||
this.perks[p.name] = {
|
||||
flashlight_enable = true,
|
||||
minimap = false,
|
||||
@ -830,8 +846,33 @@ local function init_player(p)
|
||||
do_spawn_point(p)
|
||||
end
|
||||
|
||||
local function player_reconnected(connected)
|
||||
local offline_players = this.remove_offline_players
|
||||
if not offline_players then
|
||||
return
|
||||
end
|
||||
if not offline_players.enabled then
|
||||
return
|
||||
end
|
||||
if #offline_players.players > 0 then
|
||||
for i = 1, #offline_players.players do
|
||||
if offline_players.players[i] then
|
||||
local player = game.get_player(offline_players.players[i].index)
|
||||
if player and player.valid and player.index == connected.index then
|
||||
offline_players.players[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(e)
|
||||
local p = game.players[e.player_index]
|
||||
player_reconnected(p)
|
||||
|
||||
if this.perks and this.perks[p.name] then
|
||||
return
|
||||
end
|
||||
init_player(p)
|
||||
end
|
||||
|
||||
@ -1050,6 +1091,61 @@ local function populate_raid_event(surf)
|
||||
return status
|
||||
end
|
||||
|
||||
local function on_pre_player_left_game(event)
|
||||
local offline_players = this.remove_offline_players
|
||||
if not offline_players then
|
||||
return
|
||||
end
|
||||
if not offline_players.enabled then
|
||||
return
|
||||
end
|
||||
local player = game.players[event.player_index]
|
||||
local ticker = game.tick
|
||||
if player.character then
|
||||
offline_players.players[#offline_players.players + 1] = {
|
||||
index = event.player_index,
|
||||
name = player.name,
|
||||
tick = ticker
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local function remove_offline_players()
|
||||
local offline_players = this.remove_offline_players
|
||||
if not offline_players then
|
||||
return
|
||||
end
|
||||
if not offline_players.enabled then
|
||||
return
|
||||
end
|
||||
if #offline_players.players > 0 then
|
||||
for i = 1, #offline_players.players, 1 do
|
||||
if offline_players.players[i] then
|
||||
local player = game.get_player(offline_players.players[i].index)
|
||||
if player and player.valid then
|
||||
if player.connected then
|
||||
offline_players.players[i] = nil
|
||||
else
|
||||
if offline_players.players[i].tick < game.tick - offline_players.time then
|
||||
if this.perks and this.perks[player.name] then
|
||||
this.perks[player.name] = nil
|
||||
end
|
||||
ClaimsFunctions.on_player_died(player)
|
||||
ClaimsFunctions.clear_player_base(player)
|
||||
|
||||
if game.forces[player.name] then
|
||||
game.merge_forces(player.name, 'neutral')
|
||||
end
|
||||
game.remove_offline_players({player})
|
||||
offline_players.players[i] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function raid_event(surf)
|
||||
local raid_groups = this.events.raid_groups
|
||||
if this.events.raid_init then
|
||||
@ -1133,19 +1229,24 @@ local function on_tick()
|
||||
return
|
||||
end
|
||||
|
||||
local tick = game.tick
|
||||
|
||||
local surf = this.surface
|
||||
if game.tick % 4 == 0 then
|
||||
if tick % 4 == 0 then
|
||||
AIFunctions.do_job(surf, AIFunctions.command.seek_and_destroy_player)
|
||||
end
|
||||
|
||||
LayersFunctions.do_job(surf)
|
||||
cause_event(s)
|
||||
|
||||
if (game.tick + 1) % 100 == 0 then
|
||||
if (tick + 1) % 60 == 0 then
|
||||
Timers.do_job()
|
||||
end
|
||||
if (tick + 1) % 100 == 0 then
|
||||
AfkFunctions.on_inactive_players(90, kill_player)
|
||||
end
|
||||
if (game.tick + 1) % 60 == 0 then
|
||||
Timers.do_job()
|
||||
if (tick + 1) % 500 == 0 then
|
||||
remove_offline_players()
|
||||
end
|
||||
end
|
||||
|
||||
@ -1241,6 +1342,7 @@ local function on_player_died(e)
|
||||
if game.forces[p.name] then
|
||||
game.merge_forces(p.name, 'neutral')
|
||||
end
|
||||
p.force = 'player'
|
||||
if p.connected then
|
||||
return
|
||||
end
|
||||
@ -1291,7 +1393,9 @@ local function on_player_dropped_item(e)
|
||||
|
||||
if this.last_friend[peer.name] == p.name then
|
||||
p.force.set_cease_fire(peer.name, true)
|
||||
p.force.set_friend(peer.name, true)
|
||||
peer.force.set_cease_fire(p.name, true)
|
||||
peer.force.set_friend(p.name, true)
|
||||
p.print(string.format('The NAP was formed with %s', peer.name))
|
||||
peer.print(string.format('The NAP was formed with %s', p.name))
|
||||
this.last_friend[p.name] = ''
|
||||
@ -1333,7 +1437,9 @@ local function on_player_dropped_item(e)
|
||||
end
|
||||
|
||||
p.force.set_cease_fire(peer.name, false)
|
||||
p.force.set_friend(peer.name, false)
|
||||
peer.force.set_cease_fire(p.name, false)
|
||||
peer.force.set_friend(p.name, false)
|
||||
|
||||
this.last_friend[p.name] = ''
|
||||
this.last_friend[peer.name] = ''
|
||||
@ -1422,18 +1528,19 @@ local function merchant_death(e)
|
||||
return true
|
||||
end
|
||||
|
||||
local coin_drops = {
|
||||
['character'] = true,
|
||||
['gun-turret'] = true
|
||||
}
|
||||
|
||||
local function hostile_death(e)
|
||||
local ent = e.entity
|
||||
local loot = e.loot
|
||||
if ent.name ~= 'character' then
|
||||
if not coin_drops[ent.name] then
|
||||
return false
|
||||
end
|
||||
|
||||
if ent.player then
|
||||
loot.insert({name = 'coin', count = 70})
|
||||
else
|
||||
loot.insert({name = 'coin', count = 10})
|
||||
end
|
||||
loot.insert({name = 'coin', count = random(30, 70)})
|
||||
|
||||
return true
|
||||
end
|
||||
@ -1657,9 +1764,9 @@ Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
|
||||
Event.add(defines.events.on_player_died, on_player_died)
|
||||
Event.add(defines.events.on_player_kicked, on_player_died)
|
||||
Event.add(defines.events.on_player_banned, on_player_died)
|
||||
Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game)
|
||||
Event.add(defines.events.on_player_respawned, on_player_respawned)
|
||||
Event.add(defines.events.on_player_dropped_item, on_player_dropped_item)
|
||||
Event.add(defines.events.on_pre_player_left_game, on_player_died)
|
||||
Event.add(defines.events.on_entity_damaged, on_entity_damaged)
|
||||
Event.add(defines.events.on_entity_died, on_entity_died)
|
||||
Event.add(defines.events.on_market_item_purchased, on_market_item_purchased)
|
||||
|
@ -72,6 +72,26 @@ local function _move_to(ent, trgt, min_distance)
|
||||
return state.walking
|
||||
end
|
||||
|
||||
local function refill_ammo(ent)
|
||||
if not ent or not ent.valid then
|
||||
return
|
||||
end
|
||||
local weapon = ent.get_inventory(defines.inventory.character_guns)[ent.selected_gun_index]
|
||||
if weapon and weapon.valid_for_read then
|
||||
local selected_ammo = ent.get_inventory(defines.inventory.character_ammo)[ent.selected_gun_index]
|
||||
if selected_ammo then
|
||||
if not selected_ammo.valid_for_read then
|
||||
if weapon.name == 'shotgun' then
|
||||
ent.insert({name = 'shotgun-shell', count = 20})
|
||||
end
|
||||
if weapon.name == 'pistol' then
|
||||
ent.insert({name = 'firearm-magazine', count = 20})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function _shoot_at(ent, trgt)
|
||||
ent.shooting_state = {
|
||||
state = defines.shooting.shooting_enemies,
|
||||
@ -88,31 +108,26 @@ end
|
||||
|
||||
local function _do_job_seek_and_destroy_player(surf)
|
||||
for _, player in pairs(game.players) do
|
||||
if player.character == nil then
|
||||
goto continue
|
||||
end
|
||||
if player and player.valid and player.character then
|
||||
local search_info = {
|
||||
name = 'character',
|
||||
position = player.character.position,
|
||||
radius = 20,
|
||||
force = 'enemy'
|
||||
}
|
||||
|
||||
local search_info = {
|
||||
name = 'character',
|
||||
position = player.character.position,
|
||||
radius = 20,
|
||||
force = 'enemy'
|
||||
}
|
||||
|
||||
local ents = surf.find_entities_filtered(search_info)
|
||||
if not ents or #ents == 0 then
|
||||
goto continue
|
||||
end
|
||||
|
||||
for _, e in pairs(ents) do
|
||||
if not _move_to(e, player.character, CommonFunctions.rand_range(5, 10)) then
|
||||
_shoot_at(e, player.character)
|
||||
else
|
||||
_shoot_stop(e)
|
||||
local ents = surf.find_entities_filtered(search_info)
|
||||
if ents and #ents > 0 then
|
||||
for _, e in pairs(ents) do
|
||||
refill_ammo(e)
|
||||
if not _move_to(e, player.character, CommonFunctions.rand_range(5, 10)) then
|
||||
_shoot_at(e, player.character)
|
||||
else
|
||||
_shoot_stop(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -5,6 +5,7 @@ local Public = {}
|
||||
local this = {}
|
||||
local insert = table.insert
|
||||
local remove = table.remove
|
||||
local random = math.random
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
@ -184,7 +185,10 @@ Public.clear_player_base = function(player)
|
||||
for i = 1, #entities do
|
||||
local e = entities[i]
|
||||
if e and e.valid then
|
||||
e.destroy()
|
||||
e.health = e.health - random(30, 180)
|
||||
if e.health <= 0 then
|
||||
e.die('enemy')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user