diff --git a/config/_file_loader.lua b/config/_file_loader.lua index 23eb99dd..f1342f8a 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -23,6 +23,7 @@ return { 'modules.commands.spawn', 'modules.commands.warnings', 'modules.commands.find', + 'modules.commands.bonus', -- QoL Addons 'modules.addons.chat-popups', 'modules.addons.damage-popups', diff --git a/config/bonuses.lua b/config/bonuses.lua new file mode 100644 index 00000000..d74ddfbf --- /dev/null +++ b/config/bonuses.lua @@ -0,0 +1,9 @@ +--- Lists all bonuses which can be used, name followed by min max +return { + character_mining_speed_modifier={0,3}, + character_crafting_speed_modifier={0,3}, + character_running_speed_modifier={0,3}, + character_build_distance_bonus={0,20}, + character_reach_distance_bonus={0,20}, + character_inventory_slots_bonus={0,200} +} \ No newline at end of file diff --git a/config/roles.lua b/config/roles.lua index 83f5d728..c42e8e6f 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -34,6 +34,7 @@ Roles.new_role('System','SYS') :set_flag('is_admin') :set_flag('is_spectator') :set_flag('report-immune') +:set_flag('instance-respawn') :set_allow_all() Roles.new_role('Senior Administrator','SAdmin') @@ -41,6 +42,7 @@ Roles.new_role('Senior Administrator','SAdmin') :set_flag('is_admin') :set_flag('is_spectator') :set_flag('report-immune') +:set_flag('instance-respawn') :set_parent('Administrator') :allow{ 'command/interface', @@ -54,6 +56,7 @@ Roles.new_role('Administrator','Admin') :set_flag('is_admin') :set_flag('is_spectator') :set_flag('report-immune') +:set_flag('instance-respawn') :set_parent('Moderator') :allow{ } @@ -64,6 +67,7 @@ Roles.new_role('Moderator','Mod') :set_flag('is_admin') :set_flag('is_spectator') :set_flag('report-immune') +:set_flag('instance-respawn') :set_parent('Trainee') :allow{ 'command/assign-role', @@ -76,6 +80,7 @@ Roles.new_role('Moderator','Mod') 'command/clear-warnings', 'command/clear-temp-ban', 'command/clear-inventory', + 'command/bonus', 'gui/rocket-info/toggle-active', 'gui/rocket-info/remote_launch', } @@ -106,6 +111,7 @@ Roles.new_role('Sponsor','Spon') :set_custom_color{r=247,g=246,b=54} :set_flag('is_spectator') :set_flag('report-immune') +:set_flag('instance-respawn') :set_parent('Pay to Win') :allow{ } @@ -115,10 +121,12 @@ Roles.new_role('Pay to Win','P2W') :set_custom_color{r=238,g=172,b=44} :set_flag('is_spectator') :set_flag('report-immune') +:set_flag('instance-respawn') :set_parent('Donator') :allow{ 'gui/rocket-info/toggle-active', 'gui/rocket-info/remote_launch', + 'command/bonus', } Roles.new_role('Donator','Don') diff --git a/expcore/commands.lua b/expcore/commands.lua index feb40942..ffa13acd 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -427,7 +427,7 @@ end --- Adds a new param to the command this will be displayed in the help and used to parse the input -- @tparam string name the name of the new param that is being added to the command --- @tparam[opt=true] boolean optional is this param required for this command, these must be after all required params +-- @tparam[opt=false] boolean optional is this param required for this command, these must be after all required params -- @tparam[opt=pass function through] ?string|function parse this function will take the input and return a new (or same) value -- @param[opt] ... extra args you want to pass to the parse function; for example if the parse is general use -- parse param - input: string - the input given by the user for this param @@ -436,12 +436,17 @@ end -- parse return - the value that will be passed to the command callback, must not be nil and if reject then command is not run -- @treturn Commands._prototype pass through to allow more functions to be called function Commands._prototype:add_param(name,optional,parse,...) - if optional ~= false then optional = true end + local parse_args = {...} + if type(optional) ~= 'boolean' then + parse_args = {parse,...} + parse = optional + optional = false + end parse = parse or function(string) return string end self.params[name] = { optional=optional, parse=parse, - parse_args={...} + parse_args=parse_args } self.max_param_count = self.max_param_count+1 if not optional then diff --git a/modules/commands/bonus.lua b/modules/commands/bonus.lua new file mode 100644 index 00000000..2e02b706 --- /dev/null +++ b/modules/commands/bonus.lua @@ -0,0 +1,58 @@ +local Commands = require 'expcore.commands' +local Roles = require 'expcore.roles' +local Event = require 'utils.event' +local Game = require 'utils.game' +local Store = require 'expcore.store' +local config = require 'config.bonuses' +require 'config.expcore-commands.parse_general' + +local bonus_store = +Store.register(function(value,category) + local player = Game.get_player_from_any(category) + for bonus,min_max in pairs(config) do + local increase = min_max[2]*value + player[bonus] = min_max[1]+increase + end +end) + +Commands.new_command('bonus','Changes the amount of bonus you receive') +:add_param('amount','integer-range',0,50) +:register(function(player,amount) + local percent = amount/100 + Store.set(bonus_store,player.name,percent) +end) + +Event.add(defines.events.on_player_respawned,function(event) + local player = Game.get_player_by_index(event.player_index) + local value = Store.get(bonus_store,player.name) + if value then + for bonus,min_max in pairs(config) do + local increase = min_max[2]*value + player[bonus] = min_max[1]+increase + end + end +end) + +Event.add(defines.events.on_pre_player_died,function(event) + local player = Game.get_player_by_index(event.player_index) + if Roles.player_has_flag(player,'instance-respawn') then + player.ticks_to_respawn = 120 + -- manually dispatch death event because it is not fired when ticks_to_respawn is set pre death + Event.dispatch{ + name=defines.events.on_player_died, + tick=event.tick, + player_index=event.player_index, + cause = event.cause + } + end +end) + +local function role_update(event) + local player = Game.get_player_by_index(event.player_index) + if not Roles.player_allowed(player,'command/bonus') then + Store.clear(bonus_store,player.name) + end +end + +Event.add(Roles.player_role_assigned,role_update) +Event.add(Roles.player_role_unassigned,role_update) \ No newline at end of file diff --git a/old/modules/ExpGamingCommands/bonus/control.lua b/old/modules/ExpGamingCommands/bonus/control.lua deleted file mode 100644 index 97fc3f72..00000000 --- a/old/modules/ExpGamingCommands/bonus/control.lua +++ /dev/null @@ -1,87 +0,0 @@ ---- A full ranking system for factorio. --- @module ExpGamingCommands.bonus@^4.0.0 --- @author Cooldude2606 --- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE - -local global = {} -Global.register(global,function(tbl) global = tbl end) -local Game = require('FactorioStdLib.Game') - --- these are the settings which are changed with scale being as +100% -local settings = { - character_mining_speed_modifier=3, - character_crafting_speed_modifier=3, - character_running_speed_modifier=3, - character_build_distance_bonus=20, - character_reach_distance_bonus=20, - character_inventory_slots_bonus=200 -} - ---- Allows a player to set there bonus --- @command bonus --- @param bonus the amount of bonus there will get -commands.add_command('bonus', 'Set your player bonus (default is 20, guest has 0)', { - ['bonus'] = {true,'number-range-int',-1,50} -- -1 < math.floor(bonus) <= 50 -}, function(event,args) - local player = Game.get_player(event) - local bonus = args.bonus - for key,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end - global[player.index]=bonus - player_return('Bonus set to: '..math.floor(bonus)..'%') -end).default_admin_only = true - -Event.add(defines.events.on_player_respawned,function(event) - local player = Game.get_player(event) - local bonus = global[player.index] - if bonus then - for key,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end - end -end) - --- overridden by ExpGamingCore.Role if present -Event.add(defines.events.on_pre_player_died,function(event) - local player = Game.get_player(event) - if player.admin then - player.ticks_to_respawn = 120 - -- manually dispatch death event because it is not fired when ticks_to_respawn is set pre death - Event.dispatch{ - name=defines.events.on_player_died, - tick=event.tick, - player_index=event.player_index, - cause = event.cause - } - end -end) - -return { - on_init= function(self) - if loaded_modules['ExpGamingCore.Role'] then - local Role = require('ExpGamingCore.Role') - -- instant respawn - Event.add(defines.events.on_pre_player_died,function(event) - local player = Game.get_player(event) - if Role.allowed(player,'bonus-respawn') then - player.ticks_to_respawn = 120 - -- manually dispatch death event because it is not fired when ticks_to_respawn is set pre death - script.raise_event(defines.events.on_player_died,{ - name=defines.events.on_player_died, - tick=event.tick, - player_index=event.player_index, - cause = event.cause - }) - end - end) - -- either clears or adds default when rank changed - Event.add(defines.events.role_change,function(event) - local player = Game.get_player(event) - if Role.allowed(player,'bonus') then - for key,setting in pairs(settings) do player[key] = setting*0.2 end - global[player.index]=20 - else - for key in pairs(settings) do player[key] = 0 end - global[player.index]=nil - end - end) - end - end -} \ No newline at end of file diff --git a/old/modules/ExpGamingCommands/bonus/softmod.json b/old/modules/ExpGamingCommands/bonus/softmod.json deleted file mode 100644 index ddb09af9..00000000 --- a/old/modules/ExpGamingCommands/bonus/softmod.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "ExpGamingCommands.bonus", - "version": "4.0.0", - "description": "Allows a bonus to be applied to players and instant respawn.", - "location": "FSM_ARCHIVE", - "keywords": [ - "Instant Respawn", - "Bonus", - "Cheat", - "Commands", - "ExpGaming", - "Respawn" - ], - "dependencies": { - "FactorioStdLib.Game": "^0.8.0", - "ExpGamingLib": "^4.0.0", - "ExpGamingCore.Command": "^4.0.0", - "ExpGamingCore.Role": "?^4.0.0" - }, - "collection": "ExpGamingCommands@4.0.0", - "submodules": {} -}