1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2024-12-30 23:17:53 +02:00

mtn v3 - changes

This commit is contained in:
Gerkiz 2020-12-29 00:09:18 +01:00
parent 53aa78896e
commit b64561bbef
7 changed files with 336 additions and 93 deletions

View File

@ -1000,10 +1000,6 @@ local function get_mvps(force)
if score.players[p.name].killscore then
killscore = score.players[p.name].killscore
end
local deaths = 0
if score.players[p.name].deaths then
deaths = score.players[p.name].deaths
end
local built_entities = 0
if score.players[p.name].built_entities then
built_entities = score.players[p.name].built_entities
@ -1012,14 +1008,14 @@ local function get_mvps(force)
if score.players[p.name].mined_entities then
mined_entities = score.players[p.name].mined_entities
end
table.insert(score_list, {name = p.name, killscore = killscore, deaths = deaths, built_entities = built_entities, mined_entities = mined_entities})
table.insert(score_list, {name = p.name, killscore = killscore, built_entities = built_entities, mined_entities = mined_entities})
end
end
local mvp = {}
score_list = get_sorted_list('killscore', score_list)
mvp.killscore = {name = score_list[1].name, score = score_list[1].killscore}
score_list = get_sorted_list('deaths', score_list)
mvp.deaths = {name = score_list[1].name, score = score_list[1].deaths}
score_list = get_sorted_list('mined_entities', score_list)
mvp.mined_entities = {name = score_list[1].name, score = score_list[1].mined_entities}
score_list = get_sorted_list('built_entities', score_list)
mvp.built_entities = {name = score_list[1].name, score = score_list[1].built_entities}
return mvp
@ -1052,23 +1048,23 @@ local function show_mvps(player)
local defender_label = t.add({type = 'label', caption = 'Defender >> '})
defender_label.style.font = 'default-listbox'
defender_label.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local defender_label_text = t.add({type = 'label', caption = mvp.killscore.name .. ' with a score of ' .. mvp.killscore.score})
local defender_label_text = t.add({type = 'label', caption = mvp.killscore.name .. ' with a killing score of ' .. mvp.killscore.score .. ' kills!'})
defender_label_text.style.font = 'default-bold'
defender_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local builder_label = t.add({type = 'label', caption = 'Builder >> '})
builder_label.style.font = 'default-listbox'
builder_label.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local builder_label_text = t.add({type = 'label', caption = mvp.built_entities.name .. ' built ' .. mvp.built_entities.score .. ' things'})
local builder_label_text = t.add({type = 'label', caption = mvp.built_entities.name .. ' built ' .. mvp.built_entities.score .. ' things!'})
builder_label_text.style.font = 'default-bold'
builder_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local death_label = t.add({type = 'label', caption = 'Deaths >> '})
death_label.style.font = 'default-listbox'
death_label.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local death_label_text = t.add({type = 'label', caption = mvp.deaths.name .. ' died ' .. mvp.deaths.score .. ' times'})
death_label_text.style.font = 'default-bold'
death_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local miners_label = t.add({type = 'label', caption = 'Miners >> '})
miners_label.style.font = 'default-listbox'
miners_label.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local miners_label_text = t.add({type = 'label', caption = mvp.mined_entities.name .. ' mined a total of ' .. mvp.mined_entities.score .. ' entities!'})
miners_label_text.style.font = 'default-bold'
miners_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local sent_to_discord = WPT.get('sent_to_discord')
@ -1078,13 +1074,13 @@ local function show_mvps(player)
table.insert(result, wave_defense_table.wave_number .. '\\n')
table.insert(result, '\\n')
table.insert(result, 'MVP Defender: \\n')
table.insert(result, mvp.killscore.name .. ' with a score of ' .. mvp.killscore.score .. '\\n')
table.insert(result, mvp.killscore.name .. ' with a killing score of ' .. mvp.killscore.score .. ' kills!\\n')
table.insert(result, '\\n')
table.insert(result, 'MVP Builder: \\n')
table.insert(result, mvp.built_entities.name .. ' built ' .. mvp.built_entities.score .. ' things\\n')
table.insert(result, mvp.built_entities.name .. ' built ' .. mvp.built_entities.score .. ' things!\\n')
table.insert(result, '\\n')
table.insert(result, 'MVP Deaths: \\n')
table.insert(result, mvp.deaths.name .. ' died ' .. mvp.deaths.score .. ' times')
table.insert(result, 'MVP Miners: \\n')
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)
WPT.set('sent_to_discord', true)

View File

@ -809,8 +809,8 @@ function Public.set_difficulty()
-- local amount = player_count * 0.40 + 2 -- too high?
local amount = player_count * 0.25 + 2
amount = floor(amount)
if amount > 20 then
amount = 20
if amount > 8 then
amount = 8 -- lowered from 20 to 8
end
wave_defense_table.wave_interval = 3600 - player_count * 60
@ -1165,6 +1165,13 @@ function Public.is_creativity_mode_on()
end
end
function Public.disable_creative()
local creative_enabled = Commands.get('creative_enabled')
if creative_enabled then
Commands.set('creative_enabled', false)
end
end
function Public.on_pre_player_left_game(event)
local offline_players_enabled = WPT.get('offline_players_enabled')
if not offline_players_enabled then

View File

@ -3,9 +3,13 @@ local Global = require 'utils.global'
local Server = require 'utils.server'
local Token = require 'utils.token'
local Tabs = require 'comfy_panel.main'
local Score = require 'comfy_panel.score'
local WPT = require 'maps.mountain_fortress_v3.table'
local WD = require 'modules.wave_defense.table'
local Core = require 'utils.core'
local score_dataset = 'highscores'
local score_key = 'mountain_fortress_v3_scores'
local set_data = Server.set_data
local try_get_data = Server.try_get_data
@ -34,6 +38,134 @@ local biters = {
'big-spitter',
'behemoth-spitter'
}
local function get_sorted_list(column_name, score_list, limit)
local i = 0
for _ = 1, #score_list, 1 do
for y = 1, #score_list, 1 do
if not score_list[y + 1] then
break
end
if score_list[y][column_name] < score_list[y + 1][column_name] then
local key = score_list[y]
score_list[y] = score_list[y + 1]
score_list[y + 1] = key
i = i + 1
if limit and i == limit then
return score_list
end
end
end
end
return score_list
end
local function get_mvps()
local new_score_table = Score.get_table().score_table
if not new_score_table['player'] then
return false
end
local old_score = this.score_table['player']
local score = new_score_table['player']
local score_list = {}
local mvp = old_score.players
for _, p in pairs(game.players) do
if score.players[p.name] then
local killscore = 0
if score.players[p.name].killscore then
killscore = score.players[p.name].killscore
end
local built_entities = 0
if score.players[p.name].built_entities then
built_entities = score.players[p.name].built_entities
end
local mined_entities = 0
if score.players[p.name].mined_entities then
mined_entities = score.players[p.name].mined_entities
end
local deaths = 0
if score.players[p.name].deaths then
deaths = score.players[p.name].deaths
end
insert(score_list, {name = p.name, killscore = killscore, built_entities = built_entities, deaths = deaths, mined_entities = mined_entities})
end
end
local score_list_k = get_sorted_list('killscore', score_list, 20)
local score_list_m = get_sorted_list('mined_entities', score_list, 20)
local score_list_b = get_sorted_list('built_entities', score_list, 20)
local score_list_d = get_sorted_list('deaths', score_list, 20)
for i = 1, 20 do
if score_list_k[i] then
local killscore = score_list_k[i].killscore
local mined_ents = score_list_m[i].mined_entities
local build_ents = score_list_b[i].built_entities
local deaths = score_list_d[i].deaths
if old_score.players[score_list[i].name] and score.players[score_list[i].name] then
if not mvp[score_list[i].name] then
mvp[score_list[i].name] = {}
end
local old_score_p = old_score.players[score_list[i].name]
if killscore > old_score_p.killscore then
mvp[score_list[i].name].killscore = killscore
else
mvp[score_list[i].name].killscore = old_score_p.killscore
end
if mined_ents > old_score_p.mined_entities then
mvp[score_list[i].name].mined_entities = mined_ents
else
mvp[score_list[i].name].mined_entities = old_score_p.mined_entities
end
if build_ents > old_score_p.built_entities then
mvp[score_list[i].name].built_entities = build_ents
else
mvp[score_list[i].name].built_entities = old_score_p.built_entities
end
if deaths > old_score_p.deaths then
mvp[score_list[i].name].deaths = deaths
else
mvp[score_list[i].name].deaths = old_score_p.deaths
end
end
end
end
if #mvp <= 0 then
for i = 1, 20 do
if score_list_k[i] and not mvp[score_list[i].name] then
local killscore = score_list_k[i].killscore
local mined_ents = score_list_m[i].mined_entities
local build_ents = score_list_b[i].built_entities
local deaths = score_list_d[i].deaths
if not mvp[score_list[i].name] then
mvp[score_list[i].name] = {}
end
mvp[score_list[i].name].killscore = killscore
mvp[score_list[i].name].mined_entities = mined_ents
mvp[score_list[i].name].built_entities = build_ents
mvp[score_list[i].name].deaths = deaths
end
end
if mvp['GodGamer'] then
mvp['GodGamer'] = nil
end
end
if #mvp <= 0 then
return false
end
return mvp
end
local function get_total_biter_killcount(force)
local count = 0
for _, biter in pairs(biters) do
@ -42,24 +174,56 @@ local function get_total_biter_killcount(force)
return count
end
local function get_additional_stats(key)
if not this.score_table['player'] then
this.score_table['player'] = {}
end
local function write_additional_stats(key)
local player = game.forces.player
local breached_zone = WPT.get('breached_wall')
local c = get_total_biter_killcount(player)
local new_breached_zone = WPT.get('breached_wall')
local new_wave_number = WD.get('wave_number')
local new_biters_killed = get_total_biter_killcount(player)
local new_rockets_launched = player.rockets_launched
local new_total_time = game.ticks_played
local t = this.score_table['player']
t.rockets_launched = player.rockets_launched
t.biters_killed = c
if breached_zone == 1 then
t.breached_zone = breached_zone
else
t.breached_zone = breached_zone - 1
if this.score_table['player'] then
local old_wave = this.score_table['player'].wave_number
local old_biters_killed = this.score_table['player'].biters_killed
local old_breached_zone = this.score_table['player'].breached_zone
local old_rockets_launched = this.score_table['player'].rockets_launched
local old_total_time = this.score_table['player'].total_time
if new_wave_number > old_wave then
t.wave_number = new_wave_number
else
t.wave_number = old_wave
end
if new_biters_killed > old_biters_killed then
t.biters_killed = new_biters_killed
else
t.biters_killed = old_biters_killed
end
if new_breached_zone > old_breached_zone then
t.breached_zone = new_breached_zone
else
t.breached_zone = old_breached_zone
end
if new_rockets_launched > old_rockets_launched then
t.rockets_launched = new_rockets_launched
else
t.rockets_launched = old_rockets_launched
end
if new_total_time > old_total_time then
t.total_time = new_total_time
else
t.total_time = old_total_time
end
local new_stats = get_mvps()
if new_stats then
t.players = new_stats
end
end
set_data(score_dataset, key, t)
if key then
set_data(score_dataset, key, t)
end
end
local get_scores =
@ -76,21 +240,27 @@ local get_scores =
function Public.get_scores()
local secs = Server.get_current_time()
local key = 'mountain_fortress_v3_scores'
if not secs then
return
else
try_get_data(score_dataset, key, get_scores)
try_get_data(score_dataset, score_key, get_scores)
end
end
function Public.set_scores(key)
function Public.set_scores()
local secs = Server.get_current_time()
key = tostring(key)
if not secs then
return
else
get_additional_stats(key)
write_additional_stats(score_key)
end
end
local function on_init()
local secs = Server.get_current_time()
if not secs then
write_additional_stats()
return
end
end
@ -110,50 +280,35 @@ local function get_score_list()
return score_list
end
for p, _ in pairs(score_force.players) do
if score_force.players[p] then
local score = score_force.players[p]
insert(
score_list,
{
name = p,
killscore = score.killscore or 0,
deaths = score.deaths or 0,
built_entities = score.built_entities or 0,
mined_entities = score.mined_entities or 0
}
)
end
local score = score_force.players[p]
insert(
score_list,
{
name = p,
killscore = score and score.killscore or 0,
deaths = score and score.deaths or 0,
built_entities = score and score.built_entities or 0,
mined_entities = score and score.mined_entities or 0
}
)
end
return score_list
end
local function get_sorted_list(method, column_name, score_list)
local comparators = {
['ascending'] = function(a, b)
return a[column_name] < b[column_name]
end,
['descending'] = function(a, b)
return a[column_name] > b[column_name]
end
}
table.sort(score_list, comparators[method])
return score_list
end
local function add_global_stats(frame)
local score = this.score_table['player']
local t = frame.add {type = 'table', column_count = 6}
local l = t.add {type = 'label', caption = 'Rockets launched: '}
local l = t.add {type = 'label', caption = 'Rockets: '}
l.style.font = 'default-game'
l.style.font_color = {r = 175, g = 75, b = 255}
l.style.minimal_width = 140
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = score.rockets_launched}
l.style.font = 'default-listbox'
l.style.font = 'heading-2'
l.style.font_color = {r = 0.9, g = 0.9, b = 0.9}
l.style.minimal_width = 123
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = 'Dead bugs: '}
l.style.font = 'default-game'
@ -161,19 +316,42 @@ local function add_global_stats(frame)
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = score.biters_killed}
l.style.font = 'default-listbox'
l.style.font = 'heading-2'
l.style.font_color = {r = 0.9, g = 0.9, b = 0.9}
l.style.minimal_width = 145
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = 'Breached zones: '}
l.style.font = 'default-game'
l.style.font_color = {r = 0, g = 128, b = 0}
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = score.breached_zone - 1}
l.style.font = 'default-listbox'
local zone = score.breached_zone - 1
if score.breached_zone == 0 then
zone = 0
end
local l = t.add {type = 'label', caption = zone}
l.style.font = 'heading-2'
l.style.font_color = {r = 0.9, g = 0.9, b = 0.9}
l.style.minimal_width = 145
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = 'Highest wave: '}
l.style.font = 'default-game'
l.style.font_color = {r = 128, g = 128, b = 0.9}
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = score.wave_number}
l.style.font = 'heading-2'
l.style.font_color = {r = 0.9, g = 0.9, b = 0.9}
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = 'Last run total time: '}
l.style.font = 'default-game'
l.style.font_color = {r = 0.9, g = 128, b = 128}
l.style.minimal_width = 100
local l = t.add {type = 'label', caption = Core.format_time(score.total_time)}
l.style.font = 'heading-2'
l.style.font_color = {r = 0.9, g = 0.9, b = 0.9}
l.style.minimal_width = 100
end
local show_score = (function(player, frame)
@ -297,8 +475,6 @@ local show_score = (function(player, frame)
end -- foreach entry
end) -- show_score
comfy_panel_tabs['HighScore'] = {gui = show_score, admin = false}
local function on_gui_click(event)
if not event then
return
@ -362,6 +538,20 @@ local function on_player_left_game(event)
end
end
Server.on_data_set_changed(
score_dataset,
function(data)
if data.key == score_key then
if data.value then
this.score_table['player'] = data.value
end
end
end
)
comfy_panel_tabs['Last Run'] = {gui = show_score, admin = false, only_server_sided = false}
Event.on_init(on_init)
Event.add(defines.events.on_player_left_game, on_player_left_game)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_gui_click, on_gui_click)

View File

@ -3,6 +3,7 @@ local Color = require 'utils.color_presets'
local Task = require 'utils.task'
local Token = require 'utils.token'
local IC_Gui = require 'maps.mountain_fortress_v3.ic.gui'
local WPT = require 'maps.mountain_fortress_v3.table'
local Public = {}
local main_tile_name = 'black-refined-concrete'
@ -517,10 +518,14 @@ local function get_player_data(ic, player)
if ic.players[player.index] then
return player_data
end
local fallback = WPT.get('active_surface_index')
if not fallback then
fallback = 1
end
ic.players[player.index] = {
surface = 1,
fallback_surface = 1,
fallback_surface = tonumber(fallback),
notified = false
}
return ic.players[player.index]

View File

@ -305,9 +305,14 @@ local function get_player_data(icw, player)
return player_data
end
local fallback = WPT.get('active_surface_index')
if not fallback then
fallback = 1
end
icw.players[player.index] = {
surface = 1,
fallback_surface = 1,
fallback_surface = tonumber(fallback),
zoom = 0.30,
map_size = 360
}

View File

@ -561,6 +561,10 @@ local function redraw_market_items(gui, player, search_text)
local inventory = player.get_main_inventory()
local player_item_count
if not (gui and gui.valid) then
return
end
gui.add(
{
type = 'label',
@ -1476,7 +1480,7 @@ local function on_built_entity(event)
if linked_to == chest_limit_outside_upgrades then
return
end
outside_chests[entity.unit_number] = entity
outside_chests[entity.unit_number] = {chest = entity, position = entity.position, linked = train.unit_number}
if not increased then
chests_linked_to[train.unit_number].count = linked_to + 1
@ -1485,7 +1489,7 @@ local function on_built_entity(event)
goto continue
end
else
outside_chests[entity.unit_number] = entity
outside_chests[entity.unit_number] = {chest = entity, position = entity.position, linked = train.unit_number}
chests_linked_to[train.unit_number] = {count = 1}
end
@ -1508,7 +1512,7 @@ local function on_built_entity(event)
end
if next(outside_chests) == nil then
outside_chests[entity.unit_number] = entity
outside_chests[entity.unit_number] = {chest = entity, position = entity.position, linked = train.unit_number}
chests_linked_to[train.unit_number] = {count = 1}
chests_linked_to[train.unit_number][entity.unit_number] = true
@ -1553,22 +1557,47 @@ end
local function divide_contents()
local outside_chests = WPT.get('outside_chests')
local chests_linked_to = WPT.get('chests_linked_to')
local target_chest
for key, chest in pairs(outside_chests) do
if not chest or not chest.valid then
return
if not next(outside_chests) then
goto final
end
for key, data in pairs(outside_chests) do
local chest = data.chest
local area = {
left_top = {x = data.position.x - 4, y = data.position.y - 4},
right_bottom = {x = data.position.x + 4, y = data.position.y + 4}
}
if not (chest and chest.valid) then
if chests_linked_to[data.linked] then
if chests_linked_to[data.linked][key] then
chests_linked_to[data.linked][key] = nil
chests_linked_to[data.linked].count = chests_linked_to[data.linked].count - 1
if chests_linked_to[data.linked].count <= 0 then
chests_linked_to[data.linked] = nil
end
end
end
outside_chests[key] = nil
goto continue
end
local area = {
left_top = {x = chest.position.x - 4, y = chest.position.y - 4},
right_bottom = {x = chest.position.x + 4, y = chest.position.y + 4}
}
local success, entity = contains_positions(area)
if success then
target_chest = entity
else
return
if chests_linked_to[data.linked] then
if chests_linked_to[data.linked][key] then
chests_linked_to[data.linked][key] = nil
chests_linked_to[data.linked].count = chests_linked_to[data.linked].count - 1
if chests_linked_to[data.linked].count <= 0 then
chests_linked_to[data.linked] = nil
end
end
end
goto continue
end
local chest1 = chest.get_inventory(defines.inventory.chest)
@ -1581,7 +1610,9 @@ local function divide_contents()
chest1.remove({name = item, count = c})
end
end
::continue::
end
::final::
end
local function place_market()

View File

@ -3,7 +3,7 @@ require 'modules.rpg.main'
local Functions = require 'maps.mountain_fortress_v3.functions'
local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies'
-- local HS = require 'maps.mountain_fortress_v3.highscore'
local HS = require 'maps.mountain_fortress_v3.highscore'
local IC = require 'maps.mountain_fortress_v3.ic.table'
local Autostash = require 'modules.autostash'
local Group = require 'comfy_panel.group'
@ -31,6 +31,7 @@ local Token = require 'utils.token'
local Alert = require 'utils.alert'
local AntiGrief = require 'antigrief'
local Commands = require 'commands.misc'
local Modifiers = require 'player_modifiers'
require 'maps.mountain_fortress_v3.rocks_yield_ore_veins'
require 'maps.mountain_fortress_v3.generate'
@ -155,11 +156,14 @@ function Public.reset_map()
PL.show_roles_in_list(true)
Score.reset_tbl()
local players = game.connected_players
for i = 1, #players do
local player = players[i]
Score.init_player_table(player)
Score.init_player_table(player, true)
Commands.insert_all_items(player)
Modifiers.reset_player_modifiers(player)
if player.gui.left['mvps'] then
player.gui.left['mvps'].destroy()
end
@ -199,6 +203,7 @@ function Public.reset_map()
WD.set_disable_threat_below_zero(true)
Functions.set_difficulty()
Functions.disable_creative()
if not surface.is_chunk_generated({-20, 22}) then
surface.request_to_generate_chunks({-20, 22}, 0.1)
@ -210,6 +215,8 @@ function Public.reset_map()
Task.start_queue()
Task.set_queue_speed(16)
HS.get_scores()
this.chunk_load_tick = game.tick + 1200
this.game_lost = false
end
@ -260,8 +267,10 @@ local has_the_game_ended = function()
game.print(({'main.reset_in', cause_msg, this.game_reset_tick / 60}), {r = 0.22, g = 0.88, b = 0.22})
end
if this.soft_reset and this.game_reset_tick == 0 then
this.game_reset_tick = nil
HS.set_scores()
Public.reset_map()
return
end