mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 20:16:38 +09:00
Feature Update (#237)
See PR for details, there are too many to be included here.
This commit is contained in:
@@ -5,29 +5,39 @@
|
||||
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
local config = require 'config.bonuses' --- @dep config.bonuses
|
||||
local config = require 'config.bonus' --- @dep config.bonuses
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
--- Stores the bonus for the player
|
||||
-- Stores the bonus for the player
|
||||
local PlayerData = require 'expcore.player_data' --- @dep expcore.player_data
|
||||
local PlayerBonus = PlayerData.Settings:combine('Bonus')
|
||||
PlayerBonus:set_default(0)
|
||||
PlayerBonus:set_metadata{
|
||||
permission = 'command/bonus',
|
||||
stringify = function(value)
|
||||
if not value or value == 0 then return 'None set' end
|
||||
return (value*100)..'%'
|
||||
if not value or value == 0 then
|
||||
return 'None set'
|
||||
end
|
||||
|
||||
return value
|
||||
end
|
||||
}
|
||||
|
||||
--- Apply a bonus amount to a player
|
||||
local function apply_bonus(player, amount)
|
||||
if not amount then return end
|
||||
if not player.character then return end
|
||||
for bonus, min_max in pairs(config) do
|
||||
local increase = min_max[2]*amount
|
||||
player[bonus] = min_max[1]+increase
|
||||
--- Apply a bonus to a player
|
||||
local function apply_bonus(player, stage)
|
||||
if not player.character then
|
||||
return
|
||||
end
|
||||
|
||||
for _, v in pairs(config.player_bonus) do
|
||||
if v.enabled then
|
||||
if stage == 0 then
|
||||
player[v.name] = v.min
|
||||
else
|
||||
player[v.name] = v.min + (v.max - v.min) * stage / 10
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,14 +48,25 @@ end)
|
||||
|
||||
--- Changes the amount of bonus you receive
|
||||
-- @command bonus
|
||||
-- @tparam number amount range 0-50 the percent increase for your bonus
|
||||
-- @tparam number amount range 0-10 the increase for your bonus
|
||||
Commands.new_command('bonus', 'Changes the amount of bonus you receive')
|
||||
:add_param('amount', 'integer-range', 0,50)
|
||||
:add_param('amount', 'integer-range', 0, 10)
|
||||
:register(function(player, amount)
|
||||
local percent = amount/100
|
||||
PlayerBonus:set(player, percent)
|
||||
if amount > config.player_bonus_level then
|
||||
if not Roles.player_allowed(player, 'command/bonus/2') then
|
||||
Commands.print{'expcom-bonus.perm', 2}
|
||||
return
|
||||
end
|
||||
elseif amount <= config.player_bonus_level then
|
||||
if not Roles.player_allowed(player, 'command/bonus') then
|
||||
Commands.print{'expcom-bonus.perm', 1}
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
PlayerBonus:set(player, amount)
|
||||
|
||||
Commands.print{'expcom-bonus.set', amount}
|
||||
Commands.print({'expcom-bonus.wip'}, 'orange')
|
||||
end)
|
||||
|
||||
--- When a player respawns re-apply bonus
|
||||
@@ -54,21 +75,40 @@ Event.add(defines.events.on_player_respawned, function(event)
|
||||
apply_bonus(player, PlayerBonus:get(player))
|
||||
end)
|
||||
|
||||
--- When a player dies allow them to have instant respawn
|
||||
Event.add(defines.events.on_player_died, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
if Roles.player_has_flag(player, 'instance-respawn') then
|
||||
player.ticks_to_respawn = 120
|
||||
end
|
||||
end)
|
||||
|
||||
--- Remove bonus if a player no longer has access to the command
|
||||
local function role_update(event)
|
||||
local player = game.players[event.player_index]
|
||||
if not Roles.player_allowed(player, 'command/bonus') then
|
||||
PlayerBonus:remove(player)
|
||||
apply_bonus(player, 0)
|
||||
end
|
||||
end
|
||||
|
||||
--- When a player dies allow them to have instant respawn
|
||||
Event.add(defines.events.on_player_died, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if Roles.player_has_flag(player, 'instant-respawn') then
|
||||
player.ticks_to_respawn = 120
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
if event.player_index ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
for _, v in pairs(config.force_bonus) do
|
||||
if v.enabled then
|
||||
game.players[event.player_index].force[v.name] = game.players[event.player_index].force[v.name] + v.max
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs(config.surface_bonus) do
|
||||
if v.enabled then
|
||||
game.players[event.player_index].surface[v.name] = game.players[event.player_index].surface[v.name] + v.max
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.add(Roles.events.on_role_assigned, role_update)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update)
|
||||
Event.add(Roles.events.on_role_unassigned, role_update)
|
||||
|
||||
76
modules/data/personal-logistic.lua
Normal file
76
modules/data/personal-logistic.lua
Normal file
@@ -0,0 +1,76 @@
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local config = require 'config.personal_logistic' --- @dep config.personal-logistic
|
||||
|
||||
--[[
|
||||
Command 2:
|
||||
add filter based of inventory
|
||||
|
||||
Command 3:
|
||||
add filter of those not in inventory: all 0
|
||||
game.item_prototypes
|
||||
|
||||
Command 4:
|
||||
Spidertron request
|
||||
]]
|
||||
|
||||
local function pl(player, amount)
|
||||
local c = player.clear_personal_logistic_slot
|
||||
|
||||
for k, v in pairs(config.request) do
|
||||
c(config.start + v.key)
|
||||
end
|
||||
|
||||
if (amount == 0) then
|
||||
return
|
||||
else
|
||||
local stats = player.force.item_production_statistics
|
||||
local s = player.set_personal_logistic_slot
|
||||
|
||||
for k, v in pairs(config.request) do
|
||||
local v_min = math.ceil(v.min * amount)
|
||||
local v_max = math.ceil(v.max * amount)
|
||||
|
||||
if v.stack ~= nil and v.stack ~= 1 and v.type ~= 'weapon' then
|
||||
v_min = math.floor(v_min / v.stack) * v.stack
|
||||
v_max = math.ceil(v_max / v.stack) * v.stack
|
||||
end
|
||||
|
||||
if v.upgrade_of == nil then
|
||||
if v.type ~= nil then
|
||||
if stats.get_input_count(k) < config.production_required[v.type] then
|
||||
v_min = 0
|
||||
end
|
||||
end
|
||||
|
||||
s(config.start + v.key, {name=k, min=v_min, max=v_max})
|
||||
|
||||
else
|
||||
if v.type ~= nil then
|
||||
if stats.get_input_count(k) >= config.production_required[v.type] then
|
||||
s(config.start + v.key, {name=k, min=v_min, max=v_max})
|
||||
local vuo = v.upgrade_of
|
||||
|
||||
while (vuo ~= nil) do
|
||||
s(config.start + config.request[vuo].key, {name=vuo, min=0, max=0})
|
||||
vuo = config.request[vuo].upgrade_of
|
||||
end
|
||||
else
|
||||
s(config.start + v.key, {name=k, min=0, max=v_max})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Commands.new_command('personal-logistic', 'Set Personal Logistic (0 to cancel all)')
|
||||
:add_param('amount', 'integer-range', 0, 10)
|
||||
:add_alias('pl')
|
||||
:register(function(player, amount)
|
||||
if player.force.technologies['logistic-robotics'].researched then
|
||||
pl(player, amount / 10)
|
||||
return Commands.success
|
||||
else
|
||||
player.print('Player logistic not researched')
|
||||
end
|
||||
end)
|
||||
@@ -175,4 +175,4 @@ for statistic, event_name in pairs(config.counters) do
|
||||
if not player.valid or not player.connected then return end
|
||||
stat:increment(player)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user