1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/modules/biter_player_count_difficulty.lua

48 lines
1.4 KiB
Lua
Raw Normal View History

2019-03-06 18:30:59 +02:00
-- biters gain strength scaling with player amount in the game -- by mewmew
2021-03-24 21:14:55 +02:00
local Event = require 'utils.event'
2019-03-06 18:30:59 +02:00
local function refresh_difficulty()
2021-03-24 17:46:00 +02:00
global.connected_players = #game.connected_players
if global.connected_players > 75 then
global.connected_players = 75
end
local f = game.forces.enemy
local m = #game.connected_players * 0.05
f.set_ammo_damage_modifier('melee', m)
f.set_ammo_damage_modifier('biological', m * 0.5)
f.set_ammo_damage_modifier('artillery-shell', m * 0.5)
f.set_ammo_damage_modifier('flamethrower', m * 0.5)
f.set_ammo_damage_modifier('laser-turret', m * 0.5)
2019-03-06 18:30:59 +02:00
end
local function on_entity_damaged(event)
2021-03-24 17:46:00 +02:00
if not event.entity.valid then
return
end
if event.entity.type ~= 'unit' then
return
end
if math.random(1, 100) >= global.connected_players then
return
end
if event.final_damage_amount > event.entity.prototype.max_health then
return
end
event.entity.health = event.entity.health + event.final_damage_amount
2019-03-06 18:30:59 +02:00
end
2021-03-24 21:14:55 +02:00
local function on_player_joined_game()
2021-03-24 17:46:00 +02:00
refresh_difficulty()
2019-03-06 18:30:59 +02:00
end
2021-03-24 21:14:55 +02:00
local function on_player_left_game()
2021-03-24 17:46:00 +02:00
refresh_difficulty()
2019-03-06 18:30:59 +02:00
end
2021-03-24 21:14:55 +02:00
Event.add(defines.events.on_player_left_game, on_player_left_game)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_entity_damaged, on_entity_damaged)