diff --git a/locale/en/rpg.cfg b/locale/en/rpg.cfg index 6af2b69d..b3617952 100644 --- a/locale/en/rpg.cfg +++ b/locale/en/rpg.cfg @@ -8,6 +8,9 @@ low_level=You lack the level to cast this spell. not_inside_pos=You wave your wand but realize that it´s out of reach. no_mana=You don´t have enough mana to cast this spell. suicidal_comfylatron=You wave your wand and __1__ is on the run! +detonate_chest=You wave your wand and chesty makes big BOOM! +detonate_chest_failed=You wave your wand but no not enough explosives were found inside the chest! +repair_aoe=You wave your wand and repaired __1__ entities! warped_ok=Warped home with minor bruises. object_spawned=You wave your wand and __1__ appears. out_of_reach=Can´t create entity at given location. @@ -118,6 +121,8 @@ raw_fish=Conjure Raw-fish comfylatron=Suicidal Comfylatron distractor=Distractor Capsule warp=Warp Gate +pointy_explosives=Detonate Chest +repair_aoe=Repair AOE [allocations] diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index 75c6ca0c..3be1277b 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -1,5 +1,6 @@ local Token = require 'utils.token' local Task = require 'utils.task' +local Color = require 'utils.color_presets' local ICW = require 'maps.mountain_fortress_v3.icw.main' local Event = require 'utils.event' local Global = require 'utils.global' @@ -772,6 +773,56 @@ local function calc_players() return total end +local retry_final_boost_movement_speed_on_respawn = + Token.register( + function(data) + local player = data.player + local old_speed = data.old_speed + if not player or not player.valid then + return + end + if not player.character or not player.character.valid then + return + end + player.character.character_running_speed_modifier = old_speed + player.print('Movement speed bonus removed!', Color.info) + end +) + +local retry_boost_movement_speed_on_respawn = + Token.register( + function(data) + local player = data.player + local old_speed = data.old_speed + if not player or not player.valid then + return + end + if not player.character or not player.character.valid then + Task.set_timeout_in_ticks(10, retry_final_boost_movement_speed_on_respawn, {player = player, old_speed = old_speed}) + return + end + player.character.character_running_speed_modifier = old_speed + player.print('Movement speed bonus removed!', Color.info) + end +) + +local boost_movement_speed_on_respawn = + Token.register( + function(data) + local player = data.player + local old_speed = data.old_speed + if not player or not player.valid then + return + end + if not player.character or not player.character.valid then + Task.set_timeout_in_ticks(10, retry_boost_movement_speed_on_respawn, {player = player, old_speed = old_speed}) + return + end + player.character.character_running_speed_modifier = old_speed + player.print('Movement speed bonus removed!', Color.info) + end +) + function Public.set_difficulty() local game_lost = WPT.get('game_lost') if game_lost then @@ -1205,6 +1256,20 @@ function Public.on_pre_player_left_game(event) end end +function Public.on_player_respawned(event) + local player = game.get_player(event.player_index) + if not player or not player.valid then + return + end + local old_speed = player.character_running_speed_modifier + local new_speed = player.character_running_speed_modifier + 1 + if player.character and player.character.valid then + player.character.character_running_speed_modifier = new_speed + Task.set_timeout_in_ticks(800, boost_movement_speed_on_respawn, {player = player, old_speed = old_speed}) + player.print('Movement speed bonus applied! Be quick and fetch your corpse!', Color.info) + end +end + function Public.on_player_changed_position(event) local active_surface_index = WPT.get('active_surface_index') if not active_surface_index then @@ -1338,12 +1403,14 @@ local on_player_left_game = Public.on_player_left_game local on_research_finished = Public.on_research_finished local on_player_changed_position = Public.on_player_changed_position local on_pre_player_left_game = Public.on_pre_player_left_game +local on_player_respawned = Public.on_player_respawned Event.add(defines.events.on_player_joined_game, on_player_joined_game) Event.add(defines.events.on_player_left_game, on_player_left_game) Event.add(defines.events.on_research_finished, on_research_finished) Event.add(defines.events.on_player_changed_position, on_player_changed_position) Event.add(defines.events.on_pre_player_left_game, on_pre_player_left_game) +Event.add(defines.events.on_player_respawned, on_player_respawned) Event.on_nth_tick(10, tick) -- Event.on_nth_tick(5, do_turret_energy) diff --git a/maps/mountain_fortress_v3/terrain.lua b/maps/mountain_fortress_v3/terrain.lua index de3c07fa..46b23518 100644 --- a/maps/mountain_fortress_v3/terrain.lua +++ b/maps/mountain_fortress_v3/terrain.lua @@ -383,8 +383,6 @@ local function wall(data) spawn_turret(entities, p, 4) elseif random(1, 2) == 1 then spawn_turret(entities, p, 5) - elseif random(1, 12) == 1 then - spawn_turret(entities, p, enable_arties) end end elseif abs(p.y) > Public.level_depth * 5.5 then diff --git a/modules/explosives.lua b/modules/explosives.lua index 420aacc6..181a2563 100644 --- a/modules/explosives.lua +++ b/modules/explosives.lua @@ -243,6 +243,43 @@ local function on_entity_died(event) ) end +function Public.detonate_chest(entity) + if not entity.valid then + return false + end + if not valid_container_types[entity.type] then + return false + end + if explosives.surface_whitelist then + if not explosives.surface_whitelist[entity.surface.name] then + return false + end + end + + local inventory = defines.inventory.chest + if entity.type == 'car' then + inventory = defines.inventory.car_trunk + end + + local i = entity.get_inventory(inventory) + local amount = i.get_item_count('explosives') + if not amount then + return false + end + if amount < 599 then + return false + end + + cell_birth( + entity.surface.index, + {x = entity.position.x, y = entity.position.y}, + game.tick, + {x = entity.position.x, y = entity.position.y}, + amount * explosives.damage_per_explosive + ) + return true +end + function Public.reset() explosives.cells = {} explosives.tiles = {} diff --git a/modules/rpg/functions.lua b/modules/rpg/functions.lua index 1f8bb2c8..404c24e9 100644 --- a/modules/rpg/functions.lua +++ b/modules/rpg/functions.lua @@ -154,6 +154,36 @@ local function add_to_global_pool(amount, personal_tax) return amount - fee end +local repair_buildings = + Token.register( + function(data) + local entity = data.entity + if entity and entity.valid then + local rng = 0.1 + if math.random(1, 5) == 1 then + rng = 0.2 + elseif math.random(1, 8) == 1 then + rng = 0.4 + end + local to_heal = entity.prototype.max_health * rng + entity.health = entity.health + to_heal + end + end +) + +function Public.repair_aoe(player, position) + local entities = player.surface.find_entities_filtered {force = player.force, area = {{position.x - 5, position.y - 5}, {position.x + 5, position.y + 5}}} + 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}) + end + end + return count +end + function Public.suicidal_comfylatron(pos, surface) local str = travelings[math.random(1, #travelings)] local symbols = {'', '!', '!', '!!', '..'} diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index e02e0813..d28cdef9 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -4,6 +4,7 @@ local AntiGrief = require 'antigrief' local Color = require 'utils.color_presets' local SpamProtection = require 'utils.spam_protection' local BiterHealthBooster = require 'modules.biter_health_booster_v2' +local Explosives = require 'modules.explosives' local WD = require 'modules.wave_defense.table' local Math2D = require 'math2d' @@ -1038,16 +1039,6 @@ local function on_player_used_capsule(event) return end - if rpg_t.level < object.level then - return p(({'rpg_main.low_level'}), Color.fail) - end - - if not object.enabled then - return - end - - local obj_name = object.obj_to_create - local position = event.position if not position then return @@ -1059,6 +1050,16 @@ local function on_player_used_capsule(event) right_bottom = {x = position.x + radius, y = position.y + radius} } + if rpg_t.level < object.level then + return p(({'rpg_main.low_level'}), Color.fail) + end + + if not object.enabled then + return + end + + local obj_name = object.obj_to_create + if not Math2D.bounding_box.contains_point(area, player.position) then player.print(({'rpg_main.not_inside_pos'}), Color.fail) return @@ -1090,17 +1091,41 @@ local function on_player_used_capsule(event) else force = 'player' end - if object.obj_to_create == 'suicidal_comfylatron' then + if obj_name == 'suicidal_comfylatron' then Functions.suicidal_comfylatron(position, surface) p(({'rpg_main.suicidal_comfylatron', 'Suicidal Comfylatron'}), Color.success) rpg_t.mana = rpg_t.mana - object.mana_cost - elseif object.obj_to_create == 'warp-gate' then + elseif obj_name == 'repair_aoe' then + local ents = Functions.repair_aoe(player, position) + p(({'rpg_main.repair_aoe', ents}), Color.success) + rpg_t.mana = rpg_t.mana - object.mana_cost + elseif obj_name == 'pointy_explosives' then + local entities = + player.surface.find_entities_filtered {force = player.force, type = 'container', area = {{position.x - 5, position.y - 5}, {position.x + 5, position.y + 5}}} + + local detonate_chest + for i = 1, #entities do + local e = entities[i] + detonate_chest = e + end + local success = Explosives.detonate_chest(detonate_chest) + if success then + player.print(({'rpg_main.detonate_chest'}), Color.success) + rpg_t.mana = rpg_t.mana - object.mana_cost + else + player.print(({'rpg_main.detonate_chest_failed'}), Color.fail) + end + elseif obj_name == 'warp-gate' then player.teleport(surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5), surface) rpg_t.mana = 0 Functions.damage_player_over_time(player, math.random(8, 16)) player.play_sound {path = 'utility/armor_insert', volume_modifier = 1} p(({'rpg_main.warped_ok'}), Color.info) rpg_t.mana = rpg_t.mana - object.mana_cost + elseif obj_name == 'fish' then -- spawn in some fish + player.insert({name = 'raw-fish', count = object.amount}) + p(({'rpg_main.object_spawned', 'raw-fish'}), Color.success) + rpg_t.mana = rpg_t.mana - object.mana_cost elseif projectile_types[obj_name] then -- projectiles for i = 1, object.amount do local damage_area = { @@ -1121,16 +1146,27 @@ local function on_player_used_capsule(event) surface.create_entity({name = obj_name, position = position, force = force, target = target_pos, speed = 1}) p(({'rpg_main.object_spawned', obj_name}), Color.success) rpg_t.mana = rpg_t.mana - object.mana_cost - elseif object.obj_to_create == 'fish' then -- spawn in some fish - player.insert({name = 'raw-fish', count = object.amount}) - p(({'rpg_main.object_spawned', 'raw-fish'}), Color.success) - rpg_t.mana = rpg_t.mana - object.mana_cost elseif surface.can_place_entity {name = obj_name, position = position} then if object.biter then local e = surface.create_entity({name = obj_name, position = position, force = force}) tame_unit_effects(player, e) + elseif object.aoe then + for x = 1, -1, -1 do + for y = 1, -1, -1 do + local pos = {x = position.x + x, y = position.y + y} + if surface.can_place_entity {name = obj_name, position = pos} then + if object.mana_cost > rpg_t.mana then + break + end + local e = surface.create_entity({name = obj_name, position = pos, force = force}) + e.direction = player.character.direction + rpg_t.mana = rpg_t.mana - object.mana_cost + end + end + end else - surface.create_entity({name = obj_name, position = position, force = force}) + local e = surface.create_entity({name = obj_name, position = position, force = force}) + e.direction = player.character.direction end p(({'rpg_main.object_spawned', obj_name}), Color.success) rpg_t.mana = rpg_t.mana - object.mana_cost @@ -1140,7 +1176,7 @@ local function on_player_used_capsule(event) end end - local msg = player.name .. ' casted ' .. object.obj_to_create .. '. ' + local msg = player.name .. ' casted ' .. obj_name .. '. ' rpg_t.last_spawned = game.tick + object.tick Functions.update_mana(player) diff --git a/modules/rpg/spells.lua b/modules/rpg/spells.lua index 4dc18f1e..1047c60e 100644 --- a/modules/rpg/spells.lua +++ b/modules/rpg/spells.lua @@ -10,10 +10,10 @@ function Public.conjure_items() type = 'item', mana_cost = 60, tick = 100, + aoe = true, enabled = true, sprite = 'recipe/stone-wall' } - spells[#spells + 1] = { name = {'entity-name.wooden-chest'}, obj_to_create = 'wooden-chest', @@ -21,6 +21,7 @@ function Public.conjure_items() type = 'item', mana_cost = 50, tick = 100, + aoe = true, enabled = true, sprite = 'recipe/wooden-chest' } @@ -31,6 +32,7 @@ function Public.conjure_items() type = 'item', mana_cost = 110, tick = 200, + aoe = true, enabled = true, sprite = 'recipe/iron-chest' } @@ -41,6 +43,7 @@ function Public.conjure_items() type = 'item', mana_cost = 150, tick = 300, + aoe = true, enabled = true, sprite = 'recipe/steel-chest' } @@ -51,6 +54,7 @@ function Public.conjure_items() type = 'item', mana_cost = 80, tick = 100, + aoe = true, enabled = true, sprite = 'recipe/transport-belt' } @@ -61,6 +65,7 @@ function Public.conjure_items() type = 'item', mana_cost = 110, tick = 200, + aoe = true, enabled = true, sprite = 'recipe/fast-transport-belt' } @@ -71,6 +76,7 @@ function Public.conjure_items() type = 'item', mana_cost = 150, tick = 300, + aoe = true, enabled = true, sprite = 'recipe/express-transport-belt' } @@ -81,6 +87,7 @@ function Public.conjure_items() type = 'item', mana_cost = 80, tick = 100, + aoe = true, enabled = true, sprite = 'recipe/underground-belt' } @@ -91,6 +98,7 @@ function Public.conjure_items() type = 'item', mana_cost = 110, tick = 200, + aoe = true, enabled = true, sprite = 'recipe/fast-underground-belt' } @@ -101,6 +109,7 @@ function Public.conjure_items() type = 'item', mana_cost = 150, tick = 300, + aoe = true, enabled = true, sprite = 'recipe/express-underground-belt' } @@ -111,6 +120,7 @@ function Public.conjure_items() type = 'entity', mana_cost = 80, tick = 350, + aoe = true, enabled = true, sprite = 'entity/sand-rock-big' } @@ -222,6 +232,36 @@ function Public.conjure_items() enabled = true, sprite = 'recipe/rocket' } + spells[#spells + 1] = { + name = {'spells.pointy_explosives'}, + obj_to_create = 'pointy_explosives', + target = true, + amount = 1, + range = 0, + damage = true, + force = 'player', + level = 70, + type = 'special', + mana_cost = 100, + tick = 100, + enabled = true, + sprite = 'recipe/explosives' + } + spells[#spells + 1] = { + name = {'spells.repair_aoe'}, + obj_to_create = 'repair_aoe', + target = true, + amount = 1, + range = 50, + damage = false, + force = 'player', + level = 50, + type = 'special', + mana_cost = 200, + tick = 100, + enabled = true, + sprite = 'recipe/repair_pack' + } spells[#spells + 1] = { name = {'spells.acid_stream'}, obj_to_create = 'acid-stream-spitter-big',