mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Recommended Diggy bot mining update for Factorio .18.27 (#1064)
* Recommended Diggy bot mining update for Factorio .18.27 * Resolve conflicts in this PR with diggy_hole.lua in PR 1061 * Include recent updates made to diggy_hole.lua in PR 1061 * Mining delay and particle tweaks
This commit is contained in:
parent
3e08ea6b6c
commit
dbdd241c86
@ -56,8 +56,10 @@ local Config = {
|
||||
-- core feature
|
||||
diggy_hole = {
|
||||
enabled = true,
|
||||
-- initial damage per tick it damages a rock to mine, can be enhanced by robot_damage_per_mining_prod_level
|
||||
robot_initial_mining_damage = 4,
|
||||
-- delay in ticks between robot mining rock and rock being marked again for deconstruction
|
||||
robot_mining_delay = 6,
|
||||
-- This value is multiplied with robot_mining_delay to determine mining damage applied. Can be enhanced by robot_damage_per_mining_prod_level
|
||||
robot_per_tick_damage = 4,
|
||||
-- damage added per level of mining productivity level research
|
||||
robot_damage_per_mining_prod_level = 1,
|
||||
|
||||
|
@ -11,6 +11,9 @@ local ScoreTracker = require 'utils.score_tracker'
|
||||
local Command = require 'utils.command'
|
||||
local CreateParticles = require 'features.create_particles'
|
||||
local Ranks = require 'resources.ranks'
|
||||
local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local set_timeout_in_ticks = Task.set_timeout_in_ticks
|
||||
local random = math.random
|
||||
local tonumber = tonumber
|
||||
local pairs = pairs
|
||||
@ -19,6 +22,7 @@ local destroy_rock = CreateParticles.destroy_rock
|
||||
local mine_rock = CreateParticles.mine_rock
|
||||
local raise_event = script.raise_event
|
||||
local mine_size_name = 'mine-size'
|
||||
local ceil = math.ceil
|
||||
|
||||
-- this
|
||||
local DiggyHole = {}
|
||||
@ -32,8 +36,27 @@ local robot_mining = {
|
||||
damage = 0,
|
||||
active_modifier = 0,
|
||||
research_modifier = 0,
|
||||
delay = 0
|
||||
}
|
||||
|
||||
-- Used in conjunction with set_timeout_in_ticks(robot_mining_delay... to control bot mining frequency
|
||||
-- Robot_mining.damage is equal to robot_mining_delay * robot_per_tick_damage
|
||||
-- So for example if robot_mining delay is doubled, robot_mining.damage gets doubled to compensate.
|
||||
local metered_bot_mining = Token.register(function(params)
|
||||
local entity = params.entity
|
||||
local force = params.force
|
||||
local health_update = params.health_update
|
||||
if entity.valid then
|
||||
local health = entity.health
|
||||
--If health of entity didn't change during delay apply bot mining damage and re-order order_deconstruction
|
||||
--If rock was damaged during the delay the bot gets scared off and stops mining this particular rock.
|
||||
if health_update == health - robot_mining.damage then
|
||||
entity.health = health_update
|
||||
entity.order_deconstruction(force)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Global.register({
|
||||
full_inventory_mining_cache = full_inventory_mining_cache,
|
||||
bot_mining_damage = robot_mining,
|
||||
@ -156,7 +179,8 @@ function DiggyHole.register(cfg)
|
||||
global_to_show[#global_to_show + 1] = mine_size_name
|
||||
|
||||
config = cfg
|
||||
robot_mining.damage = cfg.robot_initial_mining_damage
|
||||
robot_mining.delay = cfg.robot_mining_delay
|
||||
robot_mining.damage = cfg.robot_per_tick_damage * robot_mining.delay
|
||||
|
||||
Event.add(defines.events.on_entity_died, function (event)
|
||||
local entity = event.entity
|
||||
@ -192,7 +216,7 @@ function DiggyHole.register(cfg)
|
||||
if not is_diggy_rock(name) then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
raise_event(defines.events.script_raised_destroy, {entity = entity, cause = "die_faster"})
|
||||
destroy_rock(entity.surface.create_particle, 10, entity.position)
|
||||
entity.destroy()
|
||||
@ -207,7 +231,7 @@ function DiggyHole.register(cfg)
|
||||
end
|
||||
|
||||
local health = entity.health
|
||||
health = health - robot_mining.damage
|
||||
local health_update = health - robot_mining.damage
|
||||
event.buffer.clear()
|
||||
|
||||
local graphics_variation = entity.graphics_variation
|
||||
@ -215,18 +239,21 @@ function DiggyHole.register(cfg)
|
||||
local create_particle = entity.surface.create_particle
|
||||
local position = entity.position
|
||||
local force = event.robot.force
|
||||
local delay = robot_mining.delay
|
||||
|
||||
if health < 1 then
|
||||
if health_update < 1 then
|
||||
entity.die(force)
|
||||
return
|
||||
end
|
||||
entity.destroy()
|
||||
|
||||
local rock = create_entity({name = name, position = position})
|
||||
mine_rock(create_particle, 1, position)
|
||||
mine_rock(create_particle, ceil(delay / 2), position)
|
||||
rock.graphics_variation = graphics_variation
|
||||
rock.order_deconstruction(force)
|
||||
rock.health = health
|
||||
--Mark replaced rock for de-construction and apply health_update after delay. Health verified and
|
||||
--update applied after delay to help prevent more rapid damage if someone were to spam deconstruction blueprints
|
||||
set_timeout_in_ticks(delay, metered_bot_mining, {entity = rock, force = force, health_update = health_update})
|
||||
end)
|
||||
|
||||
Event.add(defines.events.on_player_mined_entity, function (event)
|
||||
|
Loading…
Reference in New Issue
Block a user