From 6f679ced7dbea2fea96f749cf11bc597bfa83154 Mon Sep 17 00:00:00 2001 From: Jayefuu Date: Sun, 19 Dec 2021 14:38:49 +0000 Subject: [PATCH] Add Diggy automatic restart (#1264) - Added a discord role to automatically ping diggy users - Added role to role reactions on carlbot - Added diggy specific restart command --- locale/en/redmew_command_text.cfg | 1 + .../maps/diggy/feature/restart_command.lua | 67 +++++++++++++++++++ map_gen/maps/diggy/scenario.lua | 6 +- resources/discord.lua | 3 +- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 map_gen/maps/diggy/feature/restart_command.lua diff --git a/locale/en/redmew_command_text.cfg b/locale/en/redmew_command_text.cfg index b95f1a3a..0d8e2bb4 100644 --- a/locale/en/redmew_command_text.cfg +++ b/locale/en/redmew_command_text.cfg @@ -7,6 +7,7 @@ diggy_clear_void=Clears the void in a given area but still triggers all events D restart=Restarts the map. abort=Aborts a restart. danger_ore_restart_condition_not_met=Not enough [item=satellite] have been launched to restart the map. +diggy_restart_condition_not_met=Mine harder dwarf! You must reach Mining Productivity __1__ to start a new mining venture! crash_site_restart=Restarts the crashsite scenario. crash_site_restart_abort=Aborts the restart of the crashsite scenario. crash_site_spy=Spend coins to send a fish to spy on the enemy for a short time. diff --git a/map_gen/maps/diggy/feature/restart_command.lua b/map_gen/maps/diggy/feature/restart_command.lua new file mode 100644 index 00000000..10ba9524 --- /dev/null +++ b/map_gen/maps/diggy/feature/restart_command.lua @@ -0,0 +1,67 @@ +local Discord = require 'resources.discord' +local Server = require 'features.server' +local Core = require 'utils.core' +local Restart = require 'features.restart_command' +local Global = require 'utils.global' +local Color = require 'resources.color_presets' + +local restart_difficulty + +Global.register_init({}, +function(tbl) + tbl.restart_difficulty = math.random(5, 15) -- mining productivity 5 costs 5k of each science (1x tech multiplier), mining productivity 15 costs 30k of each science. +end, +function(tbl) + restart_difficulty = tbl.restart_difficulty +end) + +return function(config) + -- Use these on live to ping @diggy role in #map-promotion channel + local map_promotion_channel = Discord.channel_names.map_promotion + local diggy_role_mention = Discord.role_mentions.diggy + + -- Use these instead if testing new restart features so as to not ping @diggy role: + --local map_promotion_channel = Discord.channel_names.bot_playground + --local diggy_role_mention = Discord.role_mentions.test + + Restart.set_start_game_data({type = Restart.game_types.scenario, name = config.scenario_name or 'diggy-next'}) + + local function can_restart(player) + local adjusted_difficulty = restart_difficulty - 1 --because the labels in game are different from the technologies[].level. This adjusts the printed messages so it's correct for player. + if player.admin then + if game.forces.player.technologies["mining-productivity-4"].level < restart_difficulty then + player.print("Victory condition overriden. Did not reach Mining Productivity "..adjusted_difficulty,Color.fail) + else + player.print("Victory condition reached: Mining Productivity: "..adjusted_difficulty,Color.success) + end + return true + end + if game.forces.player.technologies["mining-productivity-4"].level < restart_difficulty then + player.print({'command_description.diggy_restart_condition_not_met', adjusted_difficulty},Color.fail) + return false + end + return true + end + + local function restart_callback() + local start_game_data = Restart.get_start_game_data() + local new_map_name = start_game_data.name + + local time_string = Core.format_time(game.ticks_played) + + local message = { + diggy_role_mention, + ' **Diggy has just restarted! Previous map lasted: ', + time_string, + '!\\n', + 'Next map: ', + new_map_name, + '**' + } + message = table.concat(message) + + Server.to_discord_named_raw(map_promotion_channel, message) + end + + Restart.register(can_restart, restart_callback) +end diff --git a/map_gen/maps/diggy/scenario.lua b/map_gen/maps/diggy/scenario.lua index ae86f59f..6c73f64f 100644 --- a/map_gen/maps/diggy/scenario.lua +++ b/map_gen/maps/diggy/scenario.lua @@ -3,8 +3,11 @@ local Config = require 'map_gen.maps.diggy.config' local ScenarioInfo = require 'features.gui.info' local RS = require 'map_gen.shared.redmew_surface' local Event = require 'utils.event' -local type = type local pairs = pairs +local type = type + +local restart_command = require 'map_gen.maps.diggy.feature.restart_command' +restart_command({scenario_name = 'diggy'}) require 'utils.table' require 'utils.core' @@ -79,4 +82,5 @@ function Scenario.register() global.diggy_scenario_registered = true end + return Scenario diff --git a/resources/discord.lua b/resources/discord.lua index 2b2783bc..10feadef 100644 --- a/resources/discord.lua +++ b/resources/discord.lua @@ -14,6 +14,7 @@ return { test = '<@&593534612051984431>', crash_site = '<@&762441731194748958>', danger_ore = '<@&793231011144007730>', - moderator = '<@&454192594633883658>' + moderator = '<@&454192594633883658>', + diggy = '<@&921476458076061718>' } }