1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-11-25 22:32:18 +02:00

Entity: remove filter-inserter

This commit is contained in:
Gerkiz
2024-09-25 20:46:14 +02:00
parent b361d16c5d
commit a9531bda0f
21 changed files with 374 additions and 335 deletions

View File

@@ -8,7 +8,7 @@ local Token = require 'utils.token'
local Alert = require 'utils.alert'
local Math2D = require 'math2d'
local level_up_floating_text_color = {0, 205, 0}
local level_up_floating_text_color = { 0, 205, 0 }
local visuals_delay = Public.visuals_delay
local xp_floating_text_color = Public.xp_floating_text_color
local experience_levels = Public.experience_levels
@@ -47,44 +47,44 @@ local travelings = {
local restore_crafting_boost_token =
Token.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
function (event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
Public.restore_crafting_boost(player)
end
)
Public.restore_crafting_boost(player)
end
)
local desync =
Token.register(
function(data)
local entity = data.entity
if not entity or not entity.valid then
return
function (data)
local entity = data.entity
if not entity or not entity.valid then
return
end
local surface = data.surface
local fake_shooter = surface.create_entity({ name = 'character', position = entity.position, force = 'enemy' })
for _ = 1, 3 do
surface.create_entity(
{
name = 'explosive-rocket',
position = entity.position,
force = 'enemy',
speed = 1,
max_range = 1,
target = entity,
source = fake_shooter
}
)
end
if fake_shooter and fake_shooter.valid then
fake_shooter.destroy()
end
end
local surface = data.surface
local fake_shooter = surface.create_entity({name = 'character', position = entity.position, force = 'enemy'})
for _ = 1, 3 do
surface.create_entity(
{
name = 'explosive-rocket',
position = entity.position,
force = 'enemy',
speed = 1,
max_range = 1,
target = entity,
source = fake_shooter
}
)
end
if fake_shooter and fake_shooter.valid then
fake_shooter.destroy()
end
end
)
)
local function create_healthbar(player, size)
return rendering.draw_sprite(
@@ -95,7 +95,7 @@ local function create_healthbar(player, size)
y_scale = size - 0.2,
render_layer = 'light-effect',
target = player.character,
target_offset = {0, -2.5},
target_offset = { 0, -2.5 },
surface = player.surface
}
)
@@ -110,7 +110,7 @@ local function create_manabar(player, size)
y_scale = size - 0.2,
render_layer = 'light-effect',
target = player.character,
target_offset = {0, -2.0},
target_offset = { 0, -2.0 },
surface = player.surface
}
)
@@ -124,7 +124,7 @@ local function set_bar(min, max, id, mana)
local x_scale = rendering.get_y_scale(id) * 8
rendering.set_x_scale(id, x_scale * m)
if not mana then
rendering.set_color(id, {math.floor(255 - 255 * m), math.floor(200 * m), 0})
rendering.set_color(id, { math.floor(255 - 255 * m), math.floor(200 * m), 0 })
end
end
@@ -292,31 +292,31 @@ end
local repair_buildings =
Token.register(
function(data)
local entity = data.entity
if entity and entity.valid then
local rng = 0.1
if random(1, 5) == 1 then
rng = 0.2
elseif random(1, 8) == 1 then
rng = 0.4
end
local to_heal = entity.prototype.max_health * rng
if entity.health and to_heal then
entity.health = entity.health + to_heal
function (data)
local entity = data.entity
if entity and entity.valid then
local rng = 0.1
if random(1, 5) == 1 then
rng = 0.2
elseif random(1, 8) == 1 then
rng = 0.4
end
local to_heal = entity.prototype.max_health * rng
if entity.health and to_heal then
entity.health = entity.health + to_heal
end
end
end
end
)
)
function Public.repair_aoe(player, position)
local entities = player.surface.find_entities_filtered {force = player.force, area = {{position.x - 8, position.y - 8}, {position.x + 8, position.y + 8}}}
local entities = player.surface.find_entities_filtered { force = player.force, area = { { position.x - 8, position.y - 8 }, { position.x + 8, position.y + 8 } } }
local count = 0
for i = 1, #entities do
local e = entities[i]
if e.prototype.max_health ~= e.health then
count = count + 1
Task.set_timeout_in_ticks(10, repair_buildings, {entity = e})
Task.set_timeout_in_ticks(10, repair_buildings, { entity = e })
end
end
return count
@@ -324,26 +324,27 @@ end
function Public.suicidal_comfylatron(pos, surface)
local str = travelings[random(1, #travelings)]
local symbols = {'', '!', '!', '!!', '..'}
local symbols = { '', '!', '!', '!!', '..' }
str = str .. symbols[random(1, #symbols)]
local text = str
local e =
surface.create_entity(
{
name = 'compilatron',
position = {x = pos.x, y = pos.y + 2},
force = 'neutral'
}
)
{
name = 'compilatron',
position = { x = pos.x, y = pos.y + 2 },
force = 'neutral'
}
)
surface.create_entity(
{
name = 'compi-speech-bubble',
position = e.position,
source = e,
text = text
text = text,
lifetime = 30
}
)
local nearest_player_unit = surface.find_nearest_enemy({position = e.position, max_distance = 512, force = 'player'})
local nearest_player_unit = surface.find_nearest_enemy({ position = e.position, max_distance = 512, force = 'player' })
if nearest_player_unit and nearest_player_unit.active and nearest_player_unit.force.name ~= 'player' then
e.set_command(
@@ -359,13 +360,14 @@ function Public.suicidal_comfylatron(pos, surface)
}
Task.set_timeout_in_ticks(600, desync, data)
else
e.surface.create_entity({name = 'medium-explosion', position = e.position})
e.surface.create_entity({ name = 'medium-explosion', position = e.position })
e.surface.create_entity(
{
name = 'flying-text',
name = 'compi-speech-bubble',
position = e.position,
text = 'DeSyyNC - no target found!',
color = {r = 150, g = 0, b = 0}
source = e,
lifetime = 30
}
)
e.die()
@@ -428,8 +430,8 @@ function Public.get_last_spell_cast(player)
local position = player.position
local cast_radius = 1
local cast_area = {
left_top = {x = rpg_t.last_spell_cast.x - cast_radius, y = rpg_t.last_spell_cast.y - cast_radius},
right_bottom = {x = rpg_t.last_spell_cast.x + cast_radius, y = rpg_t.last_spell_cast.y + cast_radius}
left_top = { x = rpg_t.last_spell_cast.x - cast_radius, y = rpg_t.last_spell_cast.y - cast_radius },
right_bottom = { x = rpg_t.last_spell_cast.x + cast_radius, y = rpg_t.last_spell_cast.y + cast_radius }
}
if rpg_t.last_spell_cast then
@@ -669,13 +671,13 @@ function Public.aoe_punch(cause, entity, damage, final_damage_amount)
local get_health_pool = has_health_boost(entity, damage, final_damage_amount, cause)
local base_vector = {ent_position.x - cause.position.x, ent_position.y - cause.position.y}
local base_vector = { ent_position.x - cause.position.x, ent_position.y - cause.position.y }
local vector = {base_vector[1], base_vector[2]}
local vector = { base_vector[1], base_vector[2] }
vector[1] = vector[1] * 1000
vector[2] = vector[2] * 1000
cause.surface.create_entity({name = 'blood-explosion-huge', position = ent_position})
cause.surface.create_entity({ name = 'blood-explosion-huge', position = ent_position })
if abs(vector[1]) > abs(vector[2]) then
local d = abs(vector[1])
@@ -706,9 +708,9 @@ function Public.aoe_punch(cause, entity, damage, final_damage_amount)
for i = 1, 16, 1 do
for x = i * -1 * a, i * a, 1 do
for y = i * -1 * a, i * a, 1 do
local p = {cp.x + x + vector[1] * i, cp.y + y + vector[2] * i}
cs.create_trivial_smoke({name = 'train-smoke', position = p})
for _, e in pairs(cs.find_entities({{p[1] - a, p[2] - a}, {p[1] + a, p[2] + a}})) do
local p = { cp.x + x + vector[1] * i, cp.y + y + vector[2] * i }
cs.create_trivial_smoke({ name = 'train-smoke', position = p })
for _, e in pairs(cs.find_entities({ { p[1] - a, p[2] - a }, { p[1] + a, p[2] + a } })) do
if e.valid then
if e.health then
if e.destructible and e.minable and e.force.index ~= 3 then
@@ -751,7 +753,7 @@ function Public.add_tidal_wave(cause, ent_position, shape, length, max_spread)
local wave = {
cause = cause,
start_position = cause.position,
direction = {ent_position.x - cause.position.x, ent_position.y - cause.position.y},
direction = { ent_position.x - cause.position.x, ent_position.y - cause.position.y },
length = length or 18,
base_spread = 0.5,
max_spread = max_spread or 4,
@@ -759,7 +761,7 @@ function Public.add_tidal_wave(cause, ent_position, shape, length, max_spread)
tick = 0
}
local vector_length = math.sqrt(wave.direction[1] ^ 2 + wave.direction[2] ^ 2)
wave.direction = {wave.direction[1] / vector_length, wave.direction[2] / vector_length}
wave.direction = { wave.direction[1] / vector_length, wave.direction[2] / vector_length }
rpg_extra.tidal_waves = rpg_extra.tidal_waves or {}
rpg_extra.tidal_waves[#rpg_extra.tidal_waves + 1] = wave
@@ -797,18 +799,18 @@ function Public.update_tidal_wave()
for j = -wave.max_spread, wave.max_spread do
local offset_x = cause_position.x + wave.direction[1] * i + j * wave.direction[2]
local offset_y = cause_position.y + wave.direction[2] * i - j * wave.direction[1]
local position = {offset_x, offset_y}
local position = { offset_x, offset_y }
local next_offset_x = cause_position.x + wave.direction[1] * (i + 1) + j * wave.direction[2]
local next_offset_y = cause_position.y + wave.direction[2] * (i + 1) - j * wave.direction[1]
local next_position = {next_offset_x, next_offset_y}
local next_position = { next_offset_x, next_offset_y }
surface.create_entity({name = 'water-splash', position = position})
surface.create_entity({ name = 'water-splash', position = position })
-- surface.create_trivial_smoke({name = 'poison-capsule-smoke', position = position})
local sound = 'utility/build_small'
wave_player.play_sound {path = sound, volume_modifier = 1}
wave_player.play_sound { path = sound, volume_modifier = 1 }
for _, entity in pairs(surface.find_entities({{position[1] - 1, position[2] - 1}, {position[1] + 1, position[2] + 1}})) do
for _, entity in pairs(surface.find_entities({ { position[1] - 1, position[2] - 1 }, { position[1] + 1, position[2] + 1 } })) do
if entity.valid and entity.name ~= 'character' and entity.destructible and entity.type == 'unit' and entity.force.index ~= 3 then
local new_pos = surface.find_non_colliding_position('character', next_position, 3, 0.5)
if new_pos then
@@ -821,17 +823,17 @@ function Public.update_tidal_wave()
for j = -current_spread, current_spread, wave.base_spread do
local offset_x = cause_position.x + wave.direction[1] * i + j * wave.direction[2]
local offset_y = cause_position.y + wave.direction[2] * i - j * wave.direction[1]
local position = {offset_x, offset_y}
local position = { offset_x, offset_y }
local next_offset_x = cause_position.x + wave.direction[1] * (i + 1) + j * wave.direction[2]
local next_offset_y = cause_position.y + wave.direction[2] * (i + 1) - j * wave.direction[1]
local next_position = {next_offset_x, next_offset_y}
local next_position = { next_offset_x, next_offset_y }
-- surface.create_trivial_smoke({name = 'poison-capsule-smoke', position = position})
surface.create_entity({name = 'water-splash', position = position})
surface.create_entity({ name = 'water-splash', position = position })
local sound = 'utility/build_small'
wave_player.play_sound {path = sound, volume_modifier = 1}
wave_player.play_sound { path = sound, volume_modifier = 1 }
for _, entity in pairs(surface.find_entities({{position[1] - 1, position[2] - 1}, {position[1] + 1, position[2] + 1}})) do
for _, entity in pairs(surface.find_entities({ { position[1] - 1, position[2] - 1 }, { position[1] + 1, position[2] + 1 } })) do
if entity.valid and entity.name ~= 'character' and entity.destructible and entity.type == 'unit' and entity.force.index ~= 3 then
local new_pos = surface.find_non_colliding_position('character', next_position, 3, 0.5)
if new_pos then
@@ -914,21 +916,37 @@ function Public.update_player_stats(player)
end
function Public.level_up_effects(player)
local position = {x = player.position.x - 0.75, y = player.position.y - 1}
player.surface.create_entity({name = 'flying-text', position = position, text = '+LVL ', color = level_up_floating_text_color})
local position = { x = player.position.x - 0.75, y = player.position.y - 1 }
player.create_local_flying_text(
{
position = position,
text = '+LVL',
color = level_up_floating_text_color,
time_to_live = 300,
speed = 100
}
)
local b = 0.75
for _ = 1, 5, 1 do
local p = {
(position.x + 0.4) + (b * -1 + random(0, b * 20) * 0.1),
position.y + (b * -1 + random(0, b * 20) * 0.1)
}
player.surface.create_entity({name = 'flying-text', position = p, text = '', color = {255, random(0, 100), 0}})
player.create_local_flying_text(
{
position = p,
text = '',
color = { 255, random(0, 100), 0 },
time_to_live = 300,
speed = 100
}
)
end
player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.50}
player.play_sound { path = 'utility/achievement_unlocked', volume_modifier = 0.50 }
end
function Public.cast_spell(player, failed)
local position = {x = player.position.x - 0.75, y = player.position.y - 1}
local position = { x = player.position.x - 0.75, y = player.position.y - 1 }
local b = 0.75
if not failed then
for _ = 1, 3, 1 do
@@ -936,44 +954,84 @@ function Public.cast_spell(player, failed)
(position.x + 0.4) + (b * -1 + random(0, b * 20) * 0.1),
position.y + (b * -1 + random(0, b * 20) * 0.1)
}
player.surface.create_entity({name = 'flying-text', position = p, text = '✔️', color = {255, random(0, 100), 0}})
player.create_local_flying_text(
{
position = p,
text = '✔️',
color = { 255, random(0, 100), 0 },
time_to_live = 300,
speed = 100
}
)
end
player.play_sound {path = 'utility/scenario_message', volume_modifier = 1}
player.play_sound { path = 'utility/scenario_message', volume_modifier = 1 }
else
for _ = 1, 3, 1 do
local p = {
(position.x + 0.4) + (b * -1 + random(0, b * 20) * 0.1),
position.y + (b * -1 + random(0, b * 20) * 0.1)
}
player.surface.create_entity({name = 'flying-text', position = p, text = '', color = {255, random(0, 100), 0}})
player.create_local_flying_text(
{
position = p,
text = '',
color = { 255, random(0, 100), 0 },
time_to_live = 300,
speed = 100
}
)
end
player.play_sound {path = 'utility/cannot_build', volume_modifier = 1}
player.play_sound { path = 'utility/cannot_build', volume_modifier = 1 }
end
end
function Public.xp_effects(player)
local position = {x = player.position.x - 0.75, y = player.position.y - 1}
player.surface.create_entity({name = 'flying-text', position = position, text = '+XP', color = level_up_floating_text_color})
local position = { x = player.position.x - 0.75, y = player.position.y - 1 }
player.create_local_flying_text(
{
position = position,
text = '+XP',
color = level_up_floating_text_color,
time_to_live = 300,
speed = 100
}
)
local b = 0.75
for _ = 1, 5, 1 do
local p = {
(position.x + 0.4) + (b * -1 + random(0, b * 20) * 0.1),
position.y + (b * -1 + random(0, b * 20) * 0.1)
}
player.surface.create_entity({name = 'flying-text', position = p, text = '', color = {255, random(0, 100), 0}})
player.create_local_flying_text(
{
position = p,
text = '',
color = { 255, random(0, 100), 0 },
time_to_live = 300,
speed = 100
}
)
end
player.play_sound {path = 'utility/achievement_unlocked', volume_modifier = 0.50}
player.play_sound { path = 'utility/achievement_unlocked', volume_modifier = 0.50 }
end
function Public.boost_effects(player)
local position = {x = player.position.x - 0.75, y = player.position.y - 1}
local position = { x = player.position.x - 0.75, y = player.position.y - 1 }
local b = 0.75
for _ = 1, 10, 1 do
local p = {
(position.x + 0.4) + (b * -1 + random(0, b * 20) * 0.1),
position.y + (b * -1 + random(0, b * 20) * 0.1)
}
player.surface.create_entity({name = 'flying-text', position = p, text = '♻️', color = {random(0, 100), random(0, 100), 0}})
player.create_local_flying_text(
{
position = p,
text = '♻️',
color = { random(0, 100), random(0, 100), 0 },
time_to_live = 300,
speed = 100
}
)
end
end
@@ -994,7 +1052,7 @@ function Public.set_crafting_boost(player, get_dex_modifier)
rpg_t.old_character_crafting_speed_modifier = player.character_crafting_speed_modifier
Modifiers.update_single_modifier(player, 'character_crafting_speed_modifier', 'crafting_boost', rpg_t.crafting_boost)
Modifiers.update_player_modifiers(player)
Task.set_timeout_in_ticks(bonus_length, restore_crafting_boost_token, {player_index = player.index})
Task.set_timeout_in_ticks(bonus_length, restore_crafting_boost_token, { player_index = player.index })
end
function Public.increment_duped_crafted_items(player)
@@ -1131,18 +1189,19 @@ function Public.get_heal_modifier_from_using_fish(player)
local health = player.character_health_bonus + 250
local color
if char.health > (health * 0.50) then
color = {b = 0.2, r = 0.1, g = 1, a = 0.8}
color = { b = 0.2, r = 0.1, g = 1, a = 0.8 }
elseif char.health > (health * 0.25) then
color = {r = 1, g = 1, b = 0}
color = { r = 1, g = 1, b = 0 }
else
color = {b = 0.1, r = 1, g = 0, a = 0.8}
color = { b = 0.1, r = 1, g = 0, a = 0.8 }
end
player.surface.create_entity(
player.create_local_flying_text(
{
name = 'flying-text',
position = {position.x, position.y + 0.6},
position = { position.x, position.y + 0.6 },
text = '+' .. rng,
color = color
color = color,
time_to_live = 300,
speed = 100
}
)
char.health = char.health + rng
@@ -1249,88 +1308,88 @@ end
local show_cooldown_progressbar
show_cooldown_progressbar =
Token.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
local tick = event.tick
local now = game.tick
local element = Public.get_cooldown_progressbar_for_player(player)
if not element or not element.valid then
if now >= tick then
function (event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
else
Task.set_timeout_in_ticks(update_rate_progressbar, show_cooldown_progressbar, event)
end
return
end
if now >= tick then
element.value = 0
return
end
local tick = event.tick
local now = game.tick
local rpg_t = Public.get_value_from_player(player.index)
local element = Public.get_cooldown_progressbar_for_player(player)
if not element or not element.valid then
if now >= tick then
return
else
Task.set_timeout_in_ticks(update_rate_progressbar, show_cooldown_progressbar, event)
end
return
end
if now >= tick then
element.value = 0
return
end
local rpg_t = Public.get_value_from_player(player.index)
local active_spell = Public.get_spell_by_name(rpg_t, rpg_t.dropdown_select_name)
if event.name ~= active_spell.entityName then
Task.set_timeout_in_ticks(update_rate_progressbar, show_cooldown_progressbar, event)
return
end
local fade = ((tick - now) / event.delay)
element.value = fade
local active_spell = Public.get_spell_by_name(rpg_t, rpg_t.dropdown_select_name)
if event.name ~= active_spell.entityName then
Task.set_timeout_in_ticks(update_rate_progressbar, show_cooldown_progressbar, event)
return
end
local fade = ((tick - now) / event.delay)
element.value = fade
Task.set_timeout_in_ticks(update_rate_progressbar, show_cooldown_progressbar, event)
end
)
)
Public.show_cooldown_progressbar = show_cooldown_progressbar
local show_cooldown
show_cooldown =
Token.register(
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
function (event)
local player_index = event.player_index
local player = game.get_player(player_index)
if not player or not player.valid then
return
end
local tick = event.tick
local now = game.tick
if now >= tick then
local rpg_t = Public.get_value_from_player(player.index)
rpg_t.cooldown_enabled = nil
return
end
local fade = ((now - tick) / event.delay) + 1
if not player.character then
return
end
draw_arc(
{
color = { 1 - fade, fade, 0 },
max_radius = 0.5,
min_radius = 0.4,
start_angle = start_angle,
angle = fade * angle_multipler,
target = player.character,
target_offset = { x = 0, y = -2 },
surface = player.surface,
time_to_live = time_to_live
}
)
Task.set_timeout_in_ticks(update_rate, show_cooldown, event)
end
local tick = event.tick
local now = game.tick
if now >= tick then
local rpg_t = Public.get_value_from_player(player.index)
rpg_t.cooldown_enabled = nil
return
end
local fade = ((now - tick) / event.delay) + 1
if not player.character then
return
end
draw_arc(
{
color = {1 - fade, fade, 0},
max_radius = 0.5,
min_radius = 0.4,
start_angle = start_angle,
angle = fade * angle_multipler,
target = player.character,
target_offset = {x = 0, y = -2},
surface = player.surface,
time_to_live = time_to_live
}
)
Task.set_timeout_in_ticks(update_rate, show_cooldown, event)
end
)
)
Public.show_cooldown = show_cooldown
function Public.register_cooldown_for_player(player, spell)
@@ -1342,11 +1401,11 @@ function Public.register_cooldown_for_player(player, spell)
if not rpg_t.cooldown_enabled then
rpg_t.cooldown_enabled = true
end
Task.set_timeout_in_ticks(update_rate, show_cooldown, {player_index = player.index, tick = game.tick + spell.cooldown, delay = spell.cooldown})
Task.set_timeout_in_ticks(update_rate, show_cooldown, { player_index = player.index, tick = game.tick + spell.cooldown, delay = spell.cooldown })
end
function Public.register_cooldown_for_player_progressbar(player, spell)
Task.set_timeout_in_ticks(update_rate, show_cooldown_progressbar, {player_index = player.index, tick = game.tick + spell.cooldown, delay = spell.cooldown, name = spell.entityName})
Task.set_timeout_in_ticks(update_rate, show_cooldown_progressbar, { player_index = player.index, tick = game.tick + spell.cooldown, delay = spell.cooldown, name = spell.entityName })
end
--- Gives connected player some bonus xp if the map was preemptively shut down.
@@ -1393,7 +1452,7 @@ end
function Public.rpg_reset_player(player, one_time_reset)
if not player.character then
player.set_controller({type = defines.controllers.god})
player.set_controller({ type = defines.controllers.god })
player.create_character()
end
local rpg_t = Public.get_value_from_player(player.index)
@@ -1412,99 +1471,99 @@ function Public.rpg_reset_player(player, one_time_reset)
local old_xp = rpg_t.xp
rpg_t =
Public.set_new_player_tbl(
player.index,
{
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
mana = 0,
mana_max = 0,
cooldowns = {},
dropdown_select_index = 1,
dropdown_select_name = Public.all_spells[1].name[1],
dropdown_select_index_1 = 1,
dropdown_select_name_1 = Public.all_spells[1].name[1],
dropdown_select_index_2 = 2,
dropdown_select_name_2 = Public.all_spells[2].name[1],
dropdown_select_index_3 = 3,
dropdown_select_name_3 = Public.all_spells[3].name[1],
allocate_index = 1,
amount = 0,
explosive_bullets = false,
enable_entity_spawn = false,
health_bar = rpg_t.health_bar,
mana_bar = rpg_t.mana_bar,
points_left = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = true,
capped = false,
bonus = rpg_extra.breached_walls or 1,
rotated_entity_delay = 0,
repaired_entity_delay = 0,
last_mined_entity_position = {x = 0, y = 0},
last_spell_cast = {x = 0, y = 0},
show_bars = false,
stone_path = false,
aoe_punch = false,
auto_toggle_features = {
player.index,
{
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
mana = 0,
mana_max = 0,
cooldowns = {},
dropdown_select_index = 1,
dropdown_select_name = Public.all_spells[1].name[1],
dropdown_select_index_1 = 1,
dropdown_select_name_1 = Public.all_spells[1].name[1],
dropdown_select_index_2 = 2,
dropdown_select_name_2 = Public.all_spells[2].name[1],
dropdown_select_index_3 = 3,
dropdown_select_name_3 = Public.all_spells[3].name[1],
allocate_index = 1,
amount = 0,
explosive_bullets = false,
enable_entity_spawn = false,
health_bar = rpg_t.health_bar,
mana_bar = rpg_t.mana_bar,
points_left = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = true,
capped = false,
bonus = rpg_extra.breached_walls or 1,
rotated_entity_delay = 0,
repaired_entity_delay = 0,
last_mined_entity_position = { x = 0, y = 0 },
last_spell_cast = { x = 0, y = 0 },
show_bars = false,
stone_path = false,
aoe_punch = false
aoe_punch = false,
auto_toggle_features = {
stone_path = false,
aoe_punch = false
}
}
}
)
)
rpg_t.points_left = old_points_left + total
rpg_t.xp = round(old_xp)
rpg_t.level = old_level
else
rpg_t =
Public.set_new_player_tbl(
player.index,
{
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
mana = 0,
mana_max = 0,
cooldowns = {},
dropdown_select_index = 1,
dropdown_select_name = Public.all_spells[1].name[1],
dropdown_select_index_1 = 1,
dropdown_select_name_1 = Public.all_spells[1].name[1],
dropdown_select_index_2 = 2,
dropdown_select_name_2 = Public.all_spells[2].name[1],
dropdown_select_index_3 = 3,
dropdown_select_name_3 = Public.all_spells[3].name[1],
allocate_index = 1,
amount = 0,
explosive_bullets = false,
enable_entity_spawn = false,
points_left = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = false,
capped = false,
total = 0,
bonus = 1,
rotated_entity_delay = 0,
repaired_entity_delay = 0,
last_mined_entity_position = {x = 0, y = 0},
last_spell_cast = {x = 0, y = 0},
show_bars = false,
stone_path = false,
aoe_punch = false,
auto_toggle_features = {
player.index,
{
level = 1,
xp = 0,
strength = 10,
magicka = 10,
dexterity = 10,
vitality = 10,
mana = 0,
mana_max = 0,
cooldowns = {},
dropdown_select_index = 1,
dropdown_select_name = Public.all_spells[1].name[1],
dropdown_select_index_1 = 1,
dropdown_select_name_1 = Public.all_spells[1].name[1],
dropdown_select_index_2 = 2,
dropdown_select_name_2 = Public.all_spells[2].name[1],
dropdown_select_index_3 = 3,
dropdown_select_name_3 = Public.all_spells[3].name[1],
allocate_index = 1,
amount = 0,
explosive_bullets = false,
enable_entity_spawn = false,
points_left = 0,
last_floaty_text = visuals_delay,
xp_since_last_floaty_text = 0,
reset = false,
capped = false,
total = 0,
bonus = 1,
rotated_entity_delay = 0,
repaired_entity_delay = 0,
last_mined_entity_position = { x = 0, y = 0 },
last_spell_cast = { x = 0, y = 0 },
show_bars = false,
stone_path = false,
aoe_punch = false
aoe_punch = false,
auto_toggle_features = {
stone_path = false,
aoe_punch = false
}
}
}
)
)
if rpg_t and rpg_extra.grant_xp_level and not rpg_t.granted_xp_level then
rpg_t.granted_xp_level = true
@@ -1547,7 +1606,7 @@ function Public.gain_xp(player, amount, added_to_pool, text)
add_to_global_pool(amount, false)
if not rpg_t.capped then
rpg_t.capped = true
local message = ({'rpg_functions.max_level'})
local message = ({ 'rpg_functions.max_level' })
Alert.alert_player_warning(player, 10, message)
end
return
@@ -1650,7 +1709,7 @@ function Public.global_pool(players, count)
Public.debug_log('RPG - player capped: ' .. p.name .. '. Amount to pool:' .. share)
end
else
local message = ({'rpg_functions.pool_reward', p.name})
local message = ({ 'rpg_functions.pool_reward', p.name })
Alert.alert_player_warning(p, 10, message)
share = share / 10
rpg_extra.leftover_pool = rpg_extra.leftover_pool + share
@@ -1663,15 +1722,15 @@ end
local damage_player_over_time_token =
Token.register(
function(data)
local player = data.player
if not player.character or not player.character.valid then
return
function (data)
local player = data.player
if not player.character or not player.character.valid then
return
end
player.character.health = player.character.health - (player.character.health * 0.05)
player.character.surface.create_entity({ name = 'water-splash', position = player.position })
end
player.character.health = player.character.health - (player.character.health * 0.05)
player.character.surface.create_entity({name = 'water-splash', position = player.position})
end
)
)
--- Damages a player over time.
function Public.damage_player_over_time(player, amount)
@@ -1682,7 +1741,7 @@ function Public.damage_player_over_time(player, amount)
amount = amount or 10
local tick = 20
for _ = 1, amount, 1 do
Task.set_timeout_in_ticks(tick, damage_player_over_time_token, {player = player})
Task.set_timeout_in_ticks(tick, damage_player_over_time_token, { player = player })
tick = tick + 15
end
end