1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-03 13:12:11 +02:00
This commit is contained in:
Gerkiz 2021-11-14 13:02:00 +01:00
parent 3681a4cd6d
commit 2501240d53
9 changed files with 224 additions and 44 deletions

View File

@ -4,7 +4,6 @@ local Server = require 'utils.server'
local WPT = require 'maps.mountain_fortress_v3.table'
local Collapse = require 'modules.collapse'
local WD = require 'modules.wave_defense.table'
local WDM = require 'modules.wave_defense.main'
local mapkeeper = '[color=blue]Mapkeeper:[/color]'
@ -206,28 +205,4 @@ if _DEBUG then
end
end
)
commands.add_command(
'spawn_wave',
'Enabled only on SP',
function()
local p
local player = game.player
if game.is_multiplayer() then
return
end
if player and player.valid then
p = player.print
if not player.admin then
p("[ERROR] You're not admin!", Color.fail)
return
end
WD.enable_debug()
WDM.spawn_unit_group(true)
p('Spawning wave!')
end
end
)
end

View File

@ -1,4 +1,4 @@
local RPG = require 'modules.rpg.table'
local Public = require 'modules.rpg.table'
local Utils = require 'utils.core'
local Color = require 'utils.color_presets'
@ -7,7 +7,7 @@ local round = math.round
local validate_args = function(data)
local player = data.player
local target = data.target
local rpg_t = RPG.get_value_from_player(target.index)
local rpg_t = Public.get_value_from_player(target.index)
if not target then
return false
@ -66,7 +66,7 @@ local print_stats = function(target)
if not target then
return
end
local rpg_t = RPG.get_value_from_player(target.index)
local rpg_t = Public.get_value_from_player(target.index)
if not rpg_t then
return
end
@ -126,3 +126,79 @@ commands.add_command(
end
end
)
if _DEBUG then
commands.add_command(
'debug_rpg_module',
'',
function()
local player = game.player
if not (player and player.valid) then
return
end
if not player.admin then
return
end
Public.toggle_debug()
end
)
commands.add_command(
'debug_rpg_one_punch',
'',
function()
local player = game.player
if not (player and player.valid) then
return
end
if not player.admin then
return
end
Public.toggle_debug_one_punch()
end
)
commands.add_command(
'debug_rpg_creative',
'',
function()
local player = game.player
if not (player and player.valid) then
return
end
if not player.admin then
return
end
local data = Public.get('rpg_t')
for k, _ in pairs(data) do
data[k].dexterity = 999
data[k].enable_entity_spawn = true
data[k].explosive_bullets = true
data[k].level = 500
data[k].magicka = 999
data[k].mana = 50000
data[k].mana_max = 50000
data[k].one_punch = true
data[k].stone_path = true
data[k].strength = 999
data[k].vitality = 999
data[k].xp = 456456
local p = game.get_player(k)
if p and p.valid then
Public.update_player_stats(p)
end
end
end
)
end
return Public

View File

@ -15,6 +15,7 @@ Public.settings = Settings
local Spells = require 'modules.rpg.spells'
Public.spells = Spells
require 'modules.rpg.commands'
local Commands = require 'modules.rpg.commands'
Public.commands = Commands
return Public

View File

@ -13,6 +13,7 @@ local points_per_level = Public.points_per_level
local settings_level = Public.gui_settings_levels
local floor = math.floor
local random = math.random
local round = math.round
--RPG Frames
local main_frame_name = Public.main_frame_name
@ -496,6 +497,21 @@ function Public.get_melee_modifier(player)
return (rpg_t.strength - 10) * 0.10
end
function Public.get_final_damage(player, entity, original_damage_amount)
local damage = original_damage_amount + original_damage_amount * Public.get_melee_modifier(player)
if entity.prototype.resistances then
if entity.prototype.resistances.physical then
damage = damage - entity.prototype.resistances.physical.decrease
damage = damage - damage * entity.prototype.resistances.physical.percent
end
end
damage = round(damage, 3)
if damage < 1 then
damage = 1
end
return damage
end
function Public.get_heal_modifier(player)
local rpg_t = Public.get_value_from_player(player.index)
return (rpg_t.vitality - 10) * 0.06

View File

@ -25,6 +25,14 @@ local round = math.round
local random = math.random
local abs = math.abs
local function log_one_punch(callback)
local debug = Public.get('rpg_extra').debug_one_punch
if not debug then
return
end
callback()
end
local function on_gui_click(event)
if not event then
return
@ -543,6 +551,7 @@ local function on_entity_damaged(event)
local entity = event.entity
local cause = event.cause
local original_damage_amount = event.original_damage_amount
if
cause.get_inventory(defines.inventory.character_ammo)[cause.selected_gun_index].valid_for_read or
@ -594,25 +603,26 @@ local function on_entity_damaged(event)
cause.health = cause.health + Public.get_life_on_hit(cause.player)
--Calculate modified damage.
local damage = event.original_damage_amount + event.original_damage_amount * Public.get_melee_modifier(cause.player)
if entity.prototype.resistances then
if entity.prototype.resistances.physical then
damage = damage - entity.prototype.resistances.physical.decrease
damage = damage - damage * entity.prototype.resistances.physical.percent
end
end
damage = round(damage, 3)
if damage < 1 then
damage = 1
end
local damage = Public.get_final_damage(cause.player, entity, original_damage_amount)
local enable_one_punch = Public.get('rpg_extra').enable_one_punch
local rpg_t = Public.get_value_from_player(cause.player.index)
--Cause a one punch.
if enable_one_punch then
if rpg_t.one_punch then
if random(0, 999) < Public.get_one_punch_chance(cause.player) * 10 then
local chance = Public.get_one_punch_chance(cause.player) * 10
local chance_to_hit = random(0, 999)
local success = chance_to_hit < chance
log_one_punch(
function()
if success then
log('[OnePunch]: Chance: ' .. chance .. ' Chance to hit: ' .. chance_to_hit .. ' Success: true' .. ' Damage: ' .. damage)
else
log('[OnePunch]: Chance: ' .. chance .. ' Chance to hit: ' .. chance_to_hit .. ' Success: false' .. ' Damage: ' .. damage)
end
end
)
if success then
one_punch(cause, entity, damage) -- only kill the biters if their health is below or equal to zero
return
end

View File

@ -235,6 +235,17 @@ function Public.toggle_debug()
return this.rpg_extra.debug
end
--- Toggle debug - when you need to troubleshoot.
function Public.toggle_debug_one_punch()
if this.rpg_extra.debug_one_punch then
this.rpg_extra.debug_one_punch = false
else
this.rpg_extra.debug_one_punch = true
end
return this.rpg_extra.debug_one_punch
end
--- Debug only - when you need to troubleshoot.
---@param str <string>
function Public.debug_log(str)

View File

@ -0,0 +1,57 @@
if _DEBUG then
local Public = require 'modules.wave_defense.table'
commands.add_command(
'debug_wd_module',
'',
function()
local player = game.player
if not (player and player.valid) then
return
end
if not player.admin then
return
end
Public.toggle_debug()
end
)
commands.add_command(
'debug_wd_health',
'',
function()
local player = game.player
if not (player and player.valid) then
return
end
if not player.admin then
return
end
Public.toggle_debug_health()
end
)
commands.add_command(
'debug_wd_spawn_wave',
'',
function()
local player = game.player
if not (player and player.valid) then
return
end
if not player.admin then
return
end
WDM.spawn_unit_group(true)
end
)
end

View File

@ -8,6 +8,7 @@ local update_gui = require 'modules.wave_defense.gui'
local threat_values = require 'modules.wave_defense.threat_values'
local WD = require 'modules.wave_defense.table'
local Alert = require 'utils.alert'
require 'modules.wave_defense.commands'
local Public = {}
local math_random = math.random
@ -50,6 +51,14 @@ local function debug_print(msg)
print('WaveDefense: ' .. msg)
end
local function debug_print_health(msg)
local debug = WD.get('debug_health')
if not debug then
return
end
print('[HEALTHBOOSTER]: ' .. msg)
end
local function valid(userdata)
if not (userdata and userdata.valid) then
return false
@ -575,16 +584,18 @@ local function increase_biters_health()
if modified_unit_health.current_value > modified_unit_health.limit_value then
modified_unit_health.current_value = modified_unit_health.limit_value
end
debug_print('[HEALTHBOOSTER] > Normal Units Health Boosted: ' .. modified_unit_health.current_value)
debug_print_health('modified_unit_health.current_value: ' .. modified_unit_health.current_value)
WD.set('modified_unit_health').current_value = modified_unit_health.current_value + modified_unit_health.health_increase_per_boss_wave
-- this sets boss units health
if boosted_health == 1 then
boosted_health = 1.25
end
boosted_health = boosted_health * (wave_number * 0.04)
debug_print_health('boosted_health: ' .. boosted_health)
local sum = boosted_health * 5
debug_print('[HEALTHBOOSTER] > Boss Health Boosted: ' .. sum)
debug_print_health('sum: ' .. sum)
if sum >= 300 then
sum = 300
end

View File

@ -32,6 +32,7 @@ function Public.reset_wave_defense()
this.average_unit_group_size = 35
this.biter_raffle = {}
this.debug = false
this.debug_health = false
this.paused = false
this.game_lost = false
this.get_random_close_spawner_attempts = 5
@ -232,6 +233,28 @@ function Public.pause(boolean)
this.paused = boolean or false
end
--- Toggle debug - when you need to troubleshoot.
function Public.toggle_debug()
if this.debug then
this.debug = false
else
this.debug = true
end
return this.debug
end
--- Toggle debug - when you need to troubleshoot.
function Public.toggle_debug_health()
if this.debug_health then
this.debug_health = false
else
this.debug_health = true
end
return this.debug_health
end
local on_init = function()
Public.reset_wave_defense()
end