1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/features/donator_commands.lua

140 lines
4.3 KiB
Lua
Raw Normal View History

2019-02-03 06:58:33 +02:00
-- Dependencies
local Game = require 'utils.game'
local Command = require 'utils.command'
local Donator = require 'features.donator'
local Color = require 'resources.color_presets'
local Global = require 'utils.global'
2019-02-03 06:58:33 +02:00
2019-02-15 18:18:12 +02:00
local format = string.format
local config = global.config.donator.donator_perks
Global.register(
{
config = config
},
function()
config = global.config.donator.donator_perks
end
)
2019-02-15 18:18:12 +02:00
2019-02-03 06:58:33 +02:00
-- Local functions
2019-02-15 18:18:12 +02:00
--- Saves the player's message
2019-02-21 01:24:35 +02:00
local function add_message(args, player, table_name)
2019-02-23 18:06:23 +02:00
local str = args.value
2019-02-23 00:28:41 +02:00
if not str then
2019-02-21 01:24:35 +02:00
Game.player_print({'donator_commands.add_message_fail_not_string'}, Color.fail)
2019-02-15 18:18:12 +02:00
return
end
2019-02-23 00:28:41 +02:00
2019-02-21 01:24:35 +02:00
Donator.add_donator_message(player.name, table_name, str)
2019-02-23 00:28:41 +02:00
Game.player_print({'donator_commands.add_message_success', str}, Color.success)
2019-02-15 18:18:12 +02:00
end
--- Deletes one of the player's message
2019-02-21 01:24:35 +02:00
local function delete_message(args, player, table_name)
2019-02-15 18:18:12 +02:00
local num = tonumber(args.value)
if not num then
2019-02-21 01:24:35 +02:00
Game.player_print({'donator_commands.delete_message_fail_not_number'}, Color.fail)
2019-02-15 18:18:12 +02:00
return
end
2019-02-21 01:24:35 +02:00
local message = Donator.delete_donator_message(player.name, table_name, num)
2019-02-15 18:18:12 +02:00
if message then
2019-02-21 01:24:35 +02:00
Game.player_print({'donator_commands.delete_message_success', message}, Color.success)
2019-02-15 18:18:12 +02:00
else
2019-02-21 01:24:35 +02:00
Game.player_print({'donator_commands.delete_message_fail_no_message'}, Color.fail)
2019-02-15 18:18:12 +02:00
end
end
--- Lists the player's messages
2019-02-21 01:24:35 +02:00
local function list_messages(player, table_name)
local messages = Donator.get_donator_messages(player.name, table_name)
2019-02-23 00:28:41 +02:00
if messages and #messages > 0 then
2019-02-15 18:18:12 +02:00
for k, v in pairs(messages) do
Game.player_print(format('[%s] %s', k, v))
end
else
2019-02-23 00:28:41 +02:00
Game.player_print({'donator_commands.list_message_no_messages'}, Color.info)
2019-02-15 18:18:12 +02:00
end
end
2019-02-21 01:24:35 +02:00
local function command_path_decider(args, player, table_name)
2019-02-15 18:18:12 +02:00
local multi = args['add|delete|list']
if multi == 'add' then
2019-02-21 01:24:35 +02:00
add_message(args, player, table_name)
2019-02-15 18:18:12 +02:00
elseif multi == 'delete' then
2019-02-21 01:24:35 +02:00
delete_message(args, player, table_name)
2019-02-15 18:18:12 +02:00
elseif multi == 'list' then
2019-02-21 01:24:35 +02:00
list_messages(player, table_name)
2019-02-15 18:18:12 +02:00
else
2019-02-21 01:24:35 +02:00
Game.player_print({'donator_commands.donator_message_wrong_arg1'}, Color.white)
2019-02-15 18:18:12 +02:00
end
2019-02-03 06:58:33 +02:00
end
2019-02-21 01:24:35 +02:00
--- Decides which function to call depending on the first arg to the command
2019-02-23 00:28:41 +02:00
local function donator_welcome_message_command(args, player)
local table_name = 'welcome_messages'
2019-02-21 01:24:35 +02:00
command_path_decider(args, player, table_name)
end
--- Decides which function to call depending on the first arg to the command
local function donator_death_message_command(args, player)
local table_name = 'death_messages'
command_path_decider(args, player, table_name)
end
-- Prints a list of currently active perks to the player
local function print_perks(_, player)
local print = print
if player and player.valid then -- allows us to call print_perks from the server console OR in-game
print = player.print
end
if not config.enabled then
print("Donator perks have been disabled for this map.")
return
end
local donator_tiers = Donator.get_donator_perks_table()
print("Currently active team perks: +"..(donator_tiers[2].count*10).."% hand mining speed (max +"..(donator_tiers[2].max*10).."%), +"
..(donator_tiers[3].count*10).."% hand crafting speed (max +"..(donator_tiers[3].max*10).."%), +"
..(donator_tiers[4].count*10).."% run speed (max +"..(donator_tiers[4].max*10).."%) and +"
..(donator_tiers[5].count*5).." inventory slots (max +"..(donator_tiers[5].max*5).."%).")
end
2019-02-03 06:58:33 +02:00
-- Commands
Command.add(
2019-02-23 00:28:41 +02:00
'donator-welcome-message',
2019-02-03 06:58:33 +02:00
{
description = {'command_description.donator_welcome_message'},
2019-02-15 18:18:12 +02:00
arguments = {'add|delete|list', 'value'},
default_values = {value = false},
2019-02-03 06:58:33 +02:00
capture_excess_arguments = true,
donator_only = true
},
2019-02-23 00:28:41 +02:00
donator_welcome_message_command
2019-02-03 06:58:33 +02:00
)
2019-02-21 01:24:35 +02:00
Command.add(
'donator-death-message',
{
description = {'command_description.donator_death_message'},
2019-02-21 01:24:35 +02:00
arguments = {'add|delete|list', 'value'},
default_values = {value = false},
capture_excess_arguments = true,
donator_only = true
},
donator_death_message_command
)
Command.add(
'perks',
{
description = {'command_description.perks'},
},
print_perks
)