1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-13 13:49:33 +02:00

Merge pull request #95 from Gerkiz/dev

command update and player_modifier removed from global
This commit is contained in:
Gerkiz 2019-11-10 22:04:22 +01:00 committed by GitHub
commit e3f04cbd64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 129 additions and 68 deletions

View File

@ -1,10 +1,15 @@
local Session = require 'utils.session_data'
local Modifiers = require 'player_modifiers'
local Server = require 'utils.server'
local Color = require 'utils.color_presets'
commands.add_command(
'spaghetti',
'Does spaghett.',
function(cmd)
local p_modifer = Modifiers.get_table()
local player = game.player
local _a = p_modifer
local param = tostring(cmd.parameter)
local force = game.forces["player"]
local p
@ -13,16 +18,23 @@ commands.add_command(
if player ~= nil then
p = player.print
if not player.admin then
p("You're not admin!", {r = 1, g = 0.5, b = 0.1})
p("[ERROR] You're not admin!", Color.fail)
return
end
else
p = log
end
end
if param == nil then player.print("Arguments are true/false", {r=0.22, g=0.99, b=0.99}) return end
if param == nil then player.print("[ERROR] Arguments are true/false", Color.yellow) return end
if param == "true" then
game.print("The world has been spaghettified!", {r = 1, g = 0.5, b = 0.1})
if not _a.spaghetti_are_you_sure then
_a.spaghetti_are_you_sure = true
player.print("Spaghetti is not enabled, run this command again to enable spaghett", Color.yellow)
return
end
if _a.spaghetti_enabled == true then player.print("Spaghetti is already enabled.", Color.yellow) return end
game.print("The world has been spaghettified!", Color.success)
force.technologies["logistic-system"].enabled = false
force.technologies["construction-robotics"].enabled = false
force.technologies["logistic-robotics"].enabled = false
@ -47,8 +59,10 @@ commands.add_command(
force.technologies["worker-robots-speed-4"].enabled = false
force.technologies["worker-robots-speed-5"].enabled = false
force.technologies["worker-robots-speed-6"].enabled = false
_a.spaghetti_enabled = true
elseif param == "false" then
game.print("The world is no longer spaghett!", {r = 1, g = 0.5, b = 0.1})
if _a.spaghetti_enabled == false or _a.spaghetti_enabled == nil then player.print("Spaghetti is already disabled.", Color.yellow) return end
game.print("The world is no longer spaghett!", Color.yellow)
force.technologies["logistic-system"].enabled = true
force.technologies["construction-robotics"].enabled = true
force.technologies["logistic-robotics"].enabled = true
@ -73,6 +87,7 @@ commands.add_command(
force.technologies["worker-robots-speed-4"].enabled = true
force.technologies["worker-robots-speed-5"].enabled = true
force.technologies["worker-robots-speed-6"].enabled = true
_a.spaghetti_enabled = false
end
end)
@ -80,6 +95,8 @@ commands.add_command(
'generate_map',
'Pregenerates map.',
function(cmd)
local p_modifer = Modifiers.get_table()
local _a = p_modifer
local player = game.player
local param = tonumber(cmd.parameter)
local p
@ -88,18 +105,26 @@ commands.add_command(
if player ~= nil then
p = player.print
if not player.admin then
p("You're not admin!", {r = 1, g = 0.5, b = 0.1})
p("[ERROR] You're not admin!", Color.fail)
return
end
else
p = log
end
end
if param == nil then player.print("Must specify radius!", {r=0.22, g=0.99, b=0.99}) return end
if param > 50 then player.print("[ERROR] Value is too big.", Color.fail) return end
if param == nil then player.print("[ERROR] Must specify radius!", Color.fail) return end
if not _a.generate_map then
_a.generate_map = true
player.print("[WARNING] This command will make the server LAG, run this command again if you really want to do this!", Color.yellow)
return
end
local radius = param
local surface = game.players[1].surface
if surface.is_chunk_generated({radius, radius}) then
game.print("Map generation done!", {r=0.22, g=0.99, b=0.99})
game.print("Map generation done!", Color.success)
_a.generate_map = nil
return
end
surface.request_to_generate_chunks({0,0}, radius)
@ -107,13 +132,16 @@ commands.add_command(
for _, pl in pairs(game.connected_players) do
pl.play_sound{path="utility/new_objective", volume_modifier=1}
end
game.print("Map generation done!", {r=0.22, g=0.99, b=0.99})
game.print("Map generation done!", Color.success)
_a.generate_map = nil
end)
commands.add_command(
'dump_layout',
'Dump the current map-layout.',
function()
local p_modifer = Modifiers.get_table()
local _a = p_modifer
local player = game.player
local p
@ -121,12 +149,17 @@ commands.add_command(
if player ~= nil then
p = player.print
if not player.admin then
p("You're not admin!", {r = 1, g = 0.5, b = 0.1})
p("[ERROR] You're not admin!", Color.warning)
return
end
else
p = log
end
end
if not _a.dump_layout then
_a.dump_layout = true
player.print("[WARNING] This command will make the server LAG, run this command again if you really want to do this!", Color.yellow)
return
end
local surface = game.players[1].surface
game.write_file("layout.lua", "" , false)
@ -167,14 +200,17 @@ commands.add_command(
str = str .. t.name
str = str .. '"},'
game.write_file("layout.lua", str .. '\n' , true)
player.print("Dumped layout as file: layout.lua")
player.print("Dumped layout as file: layout.lua", Color.success)
end
_a.dump_layout = false
end)
commands.add_command(
'creative',
'Enables creative_mode.',
function()
local p_modifer = Modifiers.get_table()
local _a = p_modifer
local player = game.player
local p
@ -182,40 +218,54 @@ commands.add_command(
if player ~= nil then
p = player.print
if not player.admin then
p("You're not admin!", {r = 1, g = 0.5, b = 0.1})
p("[ERROR] You're not admin!", Color.fail)
return
end
else
p = log
end
end
game.print(player.name .. " has activated creative-mode!", {r=0.22, g=0.99, b=0.99})
log(player.name .. " has activated creative-mode!")
player.cheat_mode = true
player.insert{name="power-armor-mk2", count = 1}
local p_armor = player.get_inventory(5)[1].grid
p_armor.put({name = "fusion-reactor-equipment"})
p_armor.put({name = "fusion-reactor-equipment"})
p_armor.put({name = "fusion-reactor-equipment"})
p_armor.put({name = "exoskeleton-equipment"})
p_armor.put({name = "exoskeleton-equipment"})
p_armor.put({name = "exoskeleton-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "personal-roboport-mk2-equipment"})
p_armor.put({name = "night-vision-equipment"})
p_armor.put({name = "battery-mk2-equipment"})
p_armor.put({name = "battery-mk2-equipment"})
local item = game.item_prototypes
local i = 0
for k, v in pairs(item) do
i = i + 1
if k and v.type ~= "mining-tool" then
player.force.character_inventory_slots_bonus = tonumber(i)
player.insert{name=k, count=v.stack_size}
player.print("Inserted all items")
if not _a.creative_are_you_sure then
_a.creative_are_you_sure = true
player.print("[WARNING] This command will enable creative/cheat-mode for all connected players, run this command again if you really want to do this!", Color.yellow)
return
end
if _a.creative_enabled == true then player.print("[ERROR] Creative/cheat-mode is already active!", Color.fail) return end
game.print(player.name .. " has activated creative-mode!", Color.warning)
Server.to_discord_bold(table.concat{'[Creative] ' .. player.name .. ' has activated creative-mode!'})
for k, v in pairs(game.connected_players) do
v.cheat_mode = true
v.insert{name="power-armor-mk2", count = 1}
if v.character ~= nil then
local p_armor = v.get_inventory(5)[1].grid
p_armor.put({name = "fusion-reactor-equipment"})
p_armor.put({name = "fusion-reactor-equipment"})
p_armor.put({name = "fusion-reactor-equipment"})
p_armor.put({name = "exoskeleton-equipment"})
p_armor.put({name = "exoskeleton-equipment"})
p_armor.put({name = "exoskeleton-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "energy-shield-mk2-equipment"})
p_armor.put({name = "personal-roboport-mk2-equipment"})
p_armor.put({name = "night-vision-equipment"})
p_armor.put({name = "battery-mk2-equipment"})
p_armor.put({name = "battery-mk2-equipment"})
local item = game.item_prototypes
local i = 0
for _k, _v in pairs(item) do
i = i + 1
if _k and _v.type ~= "mining-tool" then
_a[k].character_inventory_slots_bonus["creative"] = tonumber(i)
v.character_inventory_slots_bonus = _a[k].character_inventory_slots_bonus["creative"]
v.insert{name=_k, count=_v.stack_size}
v.print("Inserted all base items.", Color.success)
_a.creative_enabled = true
end
end
end
end
end)
@ -234,7 +284,7 @@ commands.add_command(
p = player.print
if not trusted[player.name] then
if not player.admin then
p("Only admins and trusted weebs are allowed to run this command!", {r = 1, g = 0.5, b = 0.1})
p("[ERROR] Only admins and trusted weebs are allowed to run this command!", Color.fail)
return
end
end
@ -242,10 +292,11 @@ commands.add_command(
p = log
end
end
if param == nil then player.print("Must specify radius!", {r=0.22, g=0.99, b=0.99}) return end
if param > 500 then player.print("[ERROR] Value is too big.", Color.warning) return end
if param == nil then player.print("[ERROR] Must specify radius!", Color.warning) return end
local radius = {{x = -param, y = -param}, {x = param, y = param}} or {{x = -1, y = -1}, {x = 1, y = 1}}
for _, entity in pairs(player.surface.find_entities_filtered{area = radius, type = "corpse"}) do
player.print("Cleared biter-corpses.")
player.print("Cleared biter-corpses.", Color.success)
entity.destroy()
end
end)

View File

@ -253,6 +253,7 @@ end
local function set_difficulty()
local wave_defense_table = WD.get_table()
wave_defense_table.threat_gain_multiplier = 2 + #game.connected_players * 0.1
--20 Players for fastest wave_interval
wave_defense_table.wave_interval = 3600 - #game.connected_players * 90
@ -260,6 +261,7 @@ local function set_difficulty()
end
local function on_player_joined_game(event)
local player_modifiers = Modifier.get_table()
local player = game.players[event.player_index]
set_difficulty()
@ -283,7 +285,7 @@ local function on_player_joined_game(event)
end
end
global.player_modifiers[player.index].character_mining_speed_modifier["mountain_fortress"] = 0.5
player_modifiers[player.index].character_mining_speed_modifier["mountain_fortress"] = 0.5
Modifier.update_player_modifiers(player)
end

View File

@ -260,6 +260,7 @@ local function on_player_left_game(event)
end
local function on_player_joined_game(event)
local player_modifiers = Modifier.get_table()
local surface = game.surfaces[global.active_surface_index]
local player = game.players[event.player_index]
@ -272,7 +273,7 @@ local function on_player_joined_game(event)
end
end
global.player_modifiers[player.index].character_mining_speed_modifier["scrapyard"] = 0
player_modifiers[player.index].character_mining_speed_modifier["scrapyard"] = 0
Modifier.update_player_modifiers(player)
if global.first_load then return end
Public.reset_map()

View File

@ -80,6 +80,7 @@ local function update_hunger_gui(player)
end
function hunger_update(player, food_value)
local player_modifiers = P.get_table()
if not player.character then return end
if food_value == -1 and player.character.driving == true then return end
@ -117,11 +118,11 @@ function hunger_update(player, food_value)
if not player.character then return end
if player_hunger_buff[global.player_hunger[player.name]] < 0 then
global.player_modifiers[player.index].character_running_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] * 0.75
player_modifiers[player.index].character_running_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] * 0.75
else
global.player_modifiers[player.index].character_running_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] * 0.15
player_modifiers[player.index].character_running_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]] * 0.15
end
global.player_modifiers[player.index].character_mining_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]]
player_modifiers[player.index].character_mining_speed_modifier["hunger"] = player_hunger_buff[global.player_hunger[player.name]]
P.update_player_modifiers(player)
update_hunger_gui(player)

View File

@ -99,24 +99,25 @@ local function update_char_button(player)
end
local function update_player_stats(player)
local player_modifiers = P.get_table()
local strength = rpg_t[player.index].strength - 10
global.player_modifiers[player.index].character_inventory_slots_bonus["rpg"] = math.round(strength * 0.2, 3)
global.player_modifiers[player.index].character_mining_speed_modifier["rpg"] = math.round(strength * 0.008, 3)
player_modifiers[player.index].character_inventory_slots_bonus["rpg"] = math.round(strength * 0.2, 3)
player_modifiers[player.index].character_mining_speed_modifier["rpg"] = math.round(strength * 0.008, 3)
local magic = rpg_t[player.index].magic - 10
local v = magic * 0.15
global.player_modifiers[player.index].character_build_distance_bonus["rpg"] = math.round(v, 3)
global.player_modifiers[player.index].character_item_drop_distance_bonus["rpg"] = math.round(v, 3)
global.player_modifiers[player.index].character_reach_distance_bonus["rpg"] = math.round(v, 3)
global.player_modifiers[player.index].character_loot_pickup_distance_bonus["rpg"] = math.round(v * 0.5, 3)
global.player_modifiers[player.index].character_item_pickup_distance_bonus["rpg"] = math.round(v * 0.25, 3)
global.player_modifiers[player.index].character_resource_reach_distance_bonus["rpg"] = math.round(v * 0.15, 3)
player_modifiers[player.index].character_build_distance_bonus["rpg"] = math.round(v, 3)
player_modifiers[player.index].character_item_drop_distance_bonus["rpg"] = math.round(v, 3)
player_modifiers[player.index].character_reach_distance_bonus["rpg"] = math.round(v, 3)
player_modifiers[player.index].character_loot_pickup_distance_bonus["rpg"] = math.round(v * 0.5, 3)
player_modifiers[player.index].character_item_pickup_distance_bonus["rpg"] = math.round(v * 0.25, 3)
player_modifiers[player.index].character_resource_reach_distance_bonus["rpg"] = math.round(v * 0.15, 3)
local dexterity = rpg_t[player.index].dexterity - 10
global.player_modifiers[player.index].character_running_speed_modifier["rpg"] = math.round(dexterity * 0.002, 3)
global.player_modifiers[player.index].character_crafting_speed_modifier["rpg"] = math.round(dexterity * 0.015, 3)
player_modifiers[player.index].character_running_speed_modifier["rpg"] = math.round(dexterity * 0.002, 3)
player_modifiers[player.index].character_crafting_speed_modifier["rpg"] = math.round(dexterity * 0.015, 3)
global.player_modifiers[player.index].character_health_bonus["rpg"] = math.round((rpg_t[player.index].vitality - 10) * 6, 3)
player_modifiers[player.index].character_health_bonus["rpg"] = math.round((rpg_t[player.index].vitality - 10) * 6, 3)
P.update_player_modifiers(player)
end

View File

@ -1,7 +1,18 @@
--Central to add all player modifiers together.
local Global = require "utils.global"
local Event = require 'utils.event'
local this = {}
Global.register(this, function(t) this = t end)
local Public = {}
function Public.get_table()
return this
end
local modifiers = {
"character_build_distance_bonus",
"character_crafting_speed_modifier",
@ -19,7 +30,7 @@ local modifiers = {
function Public.update_player_modifiers(player)
for _, modifier in pairs(modifiers) do
local sum_value = 0
for _, value in pairs(global.player_modifiers[player.index][modifier]) do
for _, value in pairs(this[player.index][modifier]) do
sum_value = sum_value + value
end
if player.character then
@ -29,19 +40,13 @@ function Public.update_player_modifiers(player)
end
local function on_player_joined_game(event)
if global.player_modifiers[event.player_index] then return end
global.player_modifiers[event.player_index] = {}
if this[event.player_index] then return end
this[event.player_index] = {}
for _, modifier in pairs(modifiers) do
global.player_modifiers[event.player_index][modifier] = {}
this[event.player_index][modifier] = {}
end
end
local function on_init(event)
global.player_modifiers = {}
end
local event = require 'utils.event'
event.on_init(on_init)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
return Public