mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-02-01 13:08:05 +02:00
rpg - add callbacks instead of messy function
This commit is contained in:
parent
3b02582750
commit
8c50414566
@ -1,5 +1,8 @@
|
||||
local Public = require 'modules.rpg.table'
|
||||
|
||||
local Spells = require 'modules.rpg.spells'
|
||||
Public.spells = Spells
|
||||
|
||||
local Bullets = require 'modules.rpg.explosive_gun_bullets'
|
||||
Public.explosive_bullet = Bullets
|
||||
|
||||
@ -15,9 +18,6 @@ Public.gui = Gui
|
||||
local Settings = require 'modules.rpg.settings'
|
||||
Public.settings = Settings
|
||||
|
||||
local Spells = require 'modules.rpg.spells'
|
||||
Public.spells = Spells
|
||||
|
||||
local Commands = require 'modules.rpg.commands'
|
||||
Public.commands = Commands
|
||||
|
||||
|
@ -569,9 +569,16 @@ function Public.cast_spell(player, failed)
|
||||
}
|
||||
player.surface.create_entity({name = 'flying-text', position = p, text = '✔️', color = {255, math.random(0, 100), 0}})
|
||||
end
|
||||
player.play_sound {path = 'utility/scenario_message', volume_modifier = 0.50}
|
||||
player.play_sound {path = 'utility/scenario_message', volume_modifier = 1}
|
||||
else
|
||||
player.play_sound {path = 'utility/cannot_build', volume_modifier = 0.50}
|
||||
for _ = 1, 3, 1 do
|
||||
local p = {
|
||||
(position.x + 0.4) + (b * -1 + math.random(0, b * 20) * 0.1),
|
||||
position.y + (b * -1 + math.random(0, b * 20) * 0.1)
|
||||
}
|
||||
player.surface.create_entity({name = 'flying-text', position = p, text = '✖', color = {255, math.random(0, 100), 0}})
|
||||
end
|
||||
player.play_sound {path = 'utility/cannot_build', volume_modifier = 1}
|
||||
end
|
||||
end
|
||||
|
||||
@ -852,6 +859,7 @@ function Public.rpg_reset_all_players()
|
||||
rpg_extra.global_pool = 0
|
||||
end
|
||||
|
||||
-- local Public = require 'modules.rpg.table' Public.gain_xp(game.players['Gerkiz'], 5012, true)
|
||||
function Public.gain_xp(player, amount, added_to_pool, text)
|
||||
if not Public.validate_player(player) then
|
||||
return
|
||||
|
@ -1009,33 +1009,6 @@ local function on_player_joined_game(event)
|
||||
Public.update_player_stats(player)
|
||||
end
|
||||
|
||||
local function create_projectile(surface, name, position, force, target, max_range)
|
||||
if max_range then
|
||||
surface.create_entity(
|
||||
{
|
||||
name = name,
|
||||
position = position,
|
||||
force = force,
|
||||
source = position,
|
||||
target = target,
|
||||
max_range = max_range,
|
||||
speed = 0.4
|
||||
}
|
||||
)
|
||||
else
|
||||
surface.create_entity(
|
||||
{
|
||||
name = name,
|
||||
position = position,
|
||||
force = force,
|
||||
source = position,
|
||||
target = target,
|
||||
speed = 0.4
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_near_coord_modifier(range)
|
||||
local coord = {x = (range * -1) + random(0, range * 2), y = (range * -1) + random(0, range * 2)}
|
||||
for i = 1, 5, 1 do
|
||||
@ -1117,7 +1090,7 @@ local function on_player_used_capsule(event)
|
||||
return
|
||||
end
|
||||
|
||||
local conjure_items = Public.get_spells()
|
||||
local conjure_items = Public.spells
|
||||
local projectile_types = Public.get_projectiles
|
||||
|
||||
local player = game.players[event.player_index]
|
||||
@ -1215,100 +1188,21 @@ local function on_player_used_capsule(event)
|
||||
force = 'player'
|
||||
end
|
||||
|
||||
if object.entityName == 'suicidal_comfylatron' then
|
||||
Public.suicidal_comfylatron(position, surface)
|
||||
Public.cast_spell(player)
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
elseif object.entityName == 'repair_aoe' then
|
||||
Public.repair_aoe(player, position)
|
||||
Public.cast_spell(player)
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
elseif object.entityName == 'pointy_explosives' then
|
||||
local entities =
|
||||
player.surface.find_entities_filtered {
|
||||
force = player.force,
|
||||
type = 'container',
|
||||
area = {{position.x - 1, position.y - 1}, {position.x + 1, position.y + 1}}
|
||||
}
|
||||
local data = {
|
||||
self = object,
|
||||
player = player,
|
||||
damage_entity = damage_entity,
|
||||
position = position,
|
||||
surface = surface,
|
||||
force = force,
|
||||
target_pos = target_pos,
|
||||
range = range,
|
||||
mana = rpg_t.mana,
|
||||
tame_unit_effects = tame_unit_effects,
|
||||
explosives = Explosives
|
||||
}
|
||||
|
||||
local detonate_chest
|
||||
for i = 1, #entities do
|
||||
local e = entities[i]
|
||||
detonate_chest = e
|
||||
end
|
||||
if detonate_chest and detonate_chest.valid then
|
||||
local success = Explosives.detonate_chest(detonate_chest)
|
||||
if success then
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
end
|
||||
Public.cast_spell(player)
|
||||
end
|
||||
elseif object.entityName == 'warp-gate' then
|
||||
local pos = surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(surface), 3, 0, 5)
|
||||
if pos then
|
||||
player.teleport(pos, surface)
|
||||
else
|
||||
pos = game.forces.player.get_spawn_position(surface)
|
||||
player.teleport(pos, surface)
|
||||
end
|
||||
Public.remove_mana(player, 999999)
|
||||
Public.damage_player_over_time(player, random(8, 16))
|
||||
player.play_sound {path = 'utility/armor_insert', volume_modifier = 1}
|
||||
Public.cast_spell(player)
|
||||
elseif object.capsule then -- spawn in capsules i.e objects that are usable with mouse-click
|
||||
player.insert({name = object.entityName, count = object.amount})
|
||||
Public.cast_spell(player)
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
elseif projectile_types[object.entityName] then -- projectiles
|
||||
for i = 1, object.amount do
|
||||
local damage_area = {
|
||||
left_top = {x = position.x - 2, y = position.y - 2},
|
||||
right_bottom = {x = position.x + 2, y = position.y + 2}
|
||||
}
|
||||
create_projectile(surface, projectile_types[object.entityName].name, position, force, target_pos, range)
|
||||
if object.damage then
|
||||
for _, e in pairs(surface.find_entities_filtered({area = damage_area})) do
|
||||
damage_entity(e)
|
||||
end
|
||||
end
|
||||
end
|
||||
Public.cast_spell(player)
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
else
|
||||
if object.target then -- rockets and such
|
||||
surface.create_entity({name = object.entityName, position = position, force = force, target = target_pos, speed = 1})
|
||||
Public.cast_spell(player)
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
elseif surface.can_place_entity {name = object.entityName, position = position} then
|
||||
if object.biter then
|
||||
local e = surface.create_entity({name = object.entityName, position = position, force = force})
|
||||
tame_unit_effects(player, e)
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
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 = object.entityName, position = pos} then
|
||||
if object.mana_cost > rpg_t.mana then
|
||||
break
|
||||
end
|
||||
local e = surface.create_entity({name = object.entityName, position = pos, force = force})
|
||||
e.direction = player.character.direction
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local e = surface.create_entity({name = object.entityName, position = position, force = force})
|
||||
e.direction = player.character.direction
|
||||
Public.remove_mana(player, object.mana_cost)
|
||||
end
|
||||
Public.cast_spell(player)
|
||||
else
|
||||
Public.cast_spell(player, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
object.callback(data)
|
||||
|
||||
local msg = player.name .. ' casted ' .. object.entityName .. '. '
|
||||
|
||||
@ -1323,8 +1217,6 @@ local function on_player_used_capsule(event)
|
||||
Public.gain_xp(player, reward_xp)
|
||||
|
||||
AntiGrief.insert_into_capsule_history(player, position, msg)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local function on_player_changed_surface(event)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,11 @@
|
||||
-- one table to rule them all!
|
||||
local Global = require 'utils.global'
|
||||
local Spells = require 'modules.rpg.spells'
|
||||
local Event = require 'utils.event'
|
||||
local Gui = require 'utils.gui'
|
||||
|
||||
local this = {
|
||||
rpg_extra = {},
|
||||
rpg_t = {},
|
||||
rpg_spells = Spells.conjure_items()
|
||||
rpg_t = {}
|
||||
}
|
||||
|
||||
--! Gui Frames
|
||||
@ -151,7 +149,7 @@ function Public.reset_table()
|
||||
end
|
||||
|
||||
--- Gets value from table
|
||||
---@param key <string>
|
||||
---@param key string
|
||||
function Public.get(key)
|
||||
if key then
|
||||
return this[key]
|
||||
@ -161,8 +159,8 @@ function Public.get(key)
|
||||
end
|
||||
|
||||
--- Gets value from player rpg_t table
|
||||
---@param key <string>
|
||||
---@param value <string>
|
||||
---@param key string
|
||||
---@param value string
|
||||
function Public.get_value_from_player(key, value)
|
||||
if key and value then
|
||||
if (this.rpg_t[key] and this.rpg_t[key][value]) then
|
||||
@ -180,9 +178,9 @@ function Public.get_value_from_player(key, value)
|
||||
end
|
||||
|
||||
--- Sets value to player rpg_t table
|
||||
---@param key <string>
|
||||
---@param value <string>
|
||||
---@param setter <string>
|
||||
---@param key string
|
||||
---@param value string
|
||||
---@param setter string
|
||||
function Public.set_value_to_player(key, value, setter)
|
||||
if key and value then
|
||||
if (this.rpg_t[key] and this.rpg_t[key][value]) then
|
||||
@ -194,8 +192,8 @@ function Public.set_value_to_player(key, value, setter)
|
||||
end
|
||||
|
||||
--- Sets a new table to rpg_t table
|
||||
---@param key <string>
|
||||
---@param tbl <string>
|
||||
---@param key string
|
||||
---@param tbl string
|
||||
function Public.set_new_player_tbl(key, tbl)
|
||||
if key and tbl then
|
||||
if type(tbl) ~= 'table' then
|
||||
@ -208,7 +206,7 @@ function Public.set_new_player_tbl(key, tbl)
|
||||
end
|
||||
|
||||
--- Removes a player from rpg_t table
|
||||
---@param key <LuaPlayerIndex>
|
||||
---@param index number
|
||||
function Public.remove_player(index)
|
||||
if index then
|
||||
if this.rpg_t[index] then
|
||||
@ -218,7 +216,7 @@ function Public.remove_player(index)
|
||||
end
|
||||
|
||||
--- Sets value to table
|
||||
---@param key <string>
|
||||
---@param key string
|
||||
function Public.set(key)
|
||||
if key then
|
||||
return this[key]
|
||||
@ -250,7 +248,7 @@ function Public.toggle_debug_aoe_punch()
|
||||
end
|
||||
|
||||
--- Debug only - when you need to troubleshoot.
|
||||
---@param str <string>
|
||||
---@param str string
|
||||
function Public.debug_log(str)
|
||||
if not this.rpg_extra.debug then
|
||||
return
|
||||
@ -259,7 +257,7 @@ function Public.debug_log(str)
|
||||
end
|
||||
|
||||
--- Sets surface name for rpg_v2 to use
|
||||
---@param name <string>
|
||||
---@param name string
|
||||
function Public.set_surface_name(name)
|
||||
if name then
|
||||
this.rpg_extra.surface_name = name
|
||||
@ -272,7 +270,7 @@ end
|
||||
|
||||
--- Enables the bars that shows above the player character.
|
||||
--- If you disable mana but enable <enable_health_and_mana_bars> then only health will be shown
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_health_and_mana_bars(value)
|
||||
this.rpg_extra.enable_health_and_mana_bars = value or false
|
||||
|
||||
@ -280,7 +278,7 @@ function Public.enable_health_and_mana_bars(value)
|
||||
end
|
||||
|
||||
--- Enables the mana feature that allows players to spawn entities.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_mana(value)
|
||||
this.rpg_extra.enable_mana = value or false
|
||||
|
||||
@ -289,7 +287,7 @@ end
|
||||
|
||||
--- This should only be enabled if wave_defense is enabled.
|
||||
--- It boosts the amount of xp the players get after x amount of waves.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_wave_defense(value)
|
||||
this.rpg_extra.enable_wave_defense = value or false
|
||||
|
||||
@ -297,7 +295,7 @@ function Public.enable_wave_defense(value)
|
||||
end
|
||||
|
||||
--- Enables/disabled flame boots.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_flame_boots(value)
|
||||
this.rpg_extra.enable_flame_boots = value or false
|
||||
|
||||
@ -305,7 +303,7 @@ function Public.enable_flame_boots(value)
|
||||
end
|
||||
|
||||
--- Enables/disabled explosive bullets globally.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_explosive_bullets_globally(value)
|
||||
this.rpg_extra.enable_explosive_bullets_globally = value or false
|
||||
|
||||
@ -323,7 +321,7 @@ function Public.get_explosive_bullets()
|
||||
end
|
||||
|
||||
--- Enables/disabled explosive bullets.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_explosive_bullets(value)
|
||||
this.rpg_extra.enable_explosive_bullets = value or false
|
||||
|
||||
@ -336,7 +334,7 @@ function Public.get_range_buffs()
|
||||
end
|
||||
|
||||
--- Enables/disabled range buffs.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_range_buffs(value)
|
||||
this.rpg_extra.enable_range_buffs = value or false
|
||||
|
||||
@ -344,7 +342,7 @@ function Public.enable_range_buffs(value)
|
||||
end
|
||||
|
||||
--- Enables/disabled personal tax.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.personal_tax_rate(value)
|
||||
this.rpg_extra.personal_tax_rate = value or false
|
||||
|
||||
@ -352,7 +350,7 @@ function Public.personal_tax_rate(value)
|
||||
end
|
||||
|
||||
--- Enables/disabled stone-path-tile creation on mined.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_stone_path(value)
|
||||
this.rpg_extra.enable_stone_path = value or false
|
||||
|
||||
@ -360,7 +358,7 @@ function Public.enable_stone_path(value)
|
||||
end
|
||||
|
||||
--- Enables/disabled auto-allocations of skill-points.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_auto_allocate(value)
|
||||
this.rpg_extra.enable_auto_allocate = value or false
|
||||
|
||||
@ -368,7 +366,7 @@ function Public.enable_auto_allocate(value)
|
||||
end
|
||||
|
||||
--- Enables/disabled aoe_punch.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_aoe_punch(value)
|
||||
this.rpg_extra.enable_aoe_punch = value or false
|
||||
|
||||
@ -376,127 +374,13 @@ function Public.enable_aoe_punch(value)
|
||||
end
|
||||
|
||||
--- Enables/disabled aoe_punch.
|
||||
---@param value <boolean>
|
||||
---@param value boolean
|
||||
function Public.enable_aoe_punch_globally(value)
|
||||
this.rpg_extra.enable_aoe_punch_globally = value or false
|
||||
|
||||
return this.rpg_extra.enable_aoe_punch_globally
|
||||
end
|
||||
|
||||
--- Retrieves the spells table or a given spell.
|
||||
---@param key <string>
|
||||
function Public.get_spells(key)
|
||||
if this.rpg_spells[key] then
|
||||
return this.rpg_spells[key]
|
||||
else
|
||||
return this.rpg_spells
|
||||
end
|
||||
end
|
||||
|
||||
--- Disables a spell.
|
||||
---@param key <string/table>
|
||||
-- Table would look like:
|
||||
-- Public.disable_spell({1, 2, 3, 4, 5, 6, 7, 8})
|
||||
function Public.disable_spell(key)
|
||||
if type(key) == 'table' then
|
||||
for _, k in pairs(key) do
|
||||
this.rpg_spells[k].enabled = false
|
||||
end
|
||||
elseif this.rpg_spells[key] then
|
||||
this.rpg_spells[key].enabled = false
|
||||
end
|
||||
end
|
||||
|
||||
--- Clears the spell table.
|
||||
function Public.clear_spell_table()
|
||||
this.rpg_spells = {}
|
||||
end
|
||||
|
||||
--- Adds a spell to the rpg_spells
|
||||
---@param tbl <table>
|
||||
function Public.set_new_spell(tbl)
|
||||
if tbl then
|
||||
if not tbl.name then
|
||||
return error('A spell requires a name. <string>', 2)
|
||||
end
|
||||
if not tbl.entityName then
|
||||
return error('A spell requires an object to create. <string>', 2)
|
||||
end
|
||||
if not tbl.target then
|
||||
return error('A spell requires position. <boolean>', 2)
|
||||
end
|
||||
if not tbl.amount then
|
||||
return error('A spell requires an amount of creation. <integer>', 2)
|
||||
end
|
||||
if not tbl.range then
|
||||
return error('A spell requires a range. <integer>', 2)
|
||||
end
|
||||
if not tbl.damage then
|
||||
return error('A spell requires damage. <damage-area=true/false>', 2)
|
||||
end
|
||||
if not tbl.force then
|
||||
return error('A spell requires a force. <string>', 2)
|
||||
end
|
||||
if not tbl.level then
|
||||
return error('A spell requires a level. <integer>', 2)
|
||||
end
|
||||
if not tbl.type then
|
||||
return error('A spell requires a type. <item/entity/special>', 2)
|
||||
end
|
||||
if not tbl.mana_cost then
|
||||
return error('A spell requires mana_cost. <integer>', 2)
|
||||
end
|
||||
if not tbl.tick then
|
||||
return error('A spell requires tick. <integer>', 2)
|
||||
end
|
||||
if not tbl.enabled then
|
||||
return error('A spell requires enabled. <boolean>', 2)
|
||||
end
|
||||
|
||||
this.rpg_spells[#this.rpg_spells + 1] = tbl
|
||||
end
|
||||
end
|
||||
|
||||
--- This rebuilds all spells. Make sure to make changes on_init if you don't
|
||||
-- want all spells enabled.
|
||||
function Public.rebuild_spells(rebuild)
|
||||
local spells = this.rpg_spells
|
||||
|
||||
local new_spells = {}
|
||||
local spell_names = {}
|
||||
|
||||
for i = 1, #spells do
|
||||
if spells[i].enabled then
|
||||
new_spells[#new_spells + 1] = spells[i]
|
||||
spell_names[#spell_names + 1] = spells[i].name
|
||||
end
|
||||
end
|
||||
|
||||
if rebuild then
|
||||
this.rpg_spells = new_spells
|
||||
end
|
||||
|
||||
return new_spells, spell_names
|
||||
end
|
||||
|
||||
--- This will disable the cooldown of all spells.
|
||||
function Public.disable_cooldowns_on_spells()
|
||||
local spells = this.rpg_spells
|
||||
|
||||
local new_spells = {}
|
||||
|
||||
for i = 1, #spells do
|
||||
if spells[i].enabled then
|
||||
spells[i].tick = 0
|
||||
new_spells[#new_spells + 1] = spells[i]
|
||||
end
|
||||
end
|
||||
|
||||
this.rpg_spells = new_spells
|
||||
|
||||
return new_spells
|
||||
end
|
||||
|
||||
function Public.tweaked_crafting_items(tbl)
|
||||
if not tbl then
|
||||
return
|
||||
@ -511,7 +395,6 @@ function Public.tweaked_crafting_items(tbl)
|
||||
return this.tweaked_crafting_items
|
||||
end
|
||||
|
||||
Public.get_projectiles = Spells.projectile_types
|
||||
Public.settings_frame_name = settings_frame_name
|
||||
Public.save_button_name = save_button_name
|
||||
Public.discard_button_name = discard_button_name
|
||||
|
Loading…
x
Reference in New Issue
Block a user