From 3fec837ff2111c2da7c5ad454f63bc8ce07a9c82 Mon Sep 17 00:00:00 2001 From: ChronoVortex Date: Wed, 22 Feb 2023 09:39:43 -0800 Subject: [PATCH] added nostack attribute for augEffect --- data/vertex_module/tags/augEffects.lua | 18 ++++++++++++++++-- mod-appendix/metadata.xml | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/data/vertex_module/tags/augEffects.lua b/data/vertex_module/tags/augEffects.lua index d35758a..5f8b0fb 100644 --- a/data/vertex_module/tags/augEffects.lua +++ b/data/vertex_module/tags/augEffects.lua @@ -39,6 +39,11 @@ local function parser(node) else augEffect.needsPower = parse_xml_bool(augEffectNode:first_attribute("needsPower"):value()) end + if not augEffectNode:first_attribute("nostack") then + augEffect.nostack = false -- augEffects stack by default + else + augEffect.nostack = parse_xml_bool(augEffectNode:first_attribute("nostack"):value()) + end table.insert(augEffects, augEffect) end @@ -49,26 +54,35 @@ end -- LOGIC -- ----------- local function logic() + local possibleValues = {} + local function get_aug_bonus(system, equipmentInfo, augName) local augBonusValue = 0 if system then for equipment in vter(system) do for _, augEffect in ipairs(equipmentInfo[equipment.blueprint.name]["augEffects"]) do if augEffect.effect == augName and (not augEffect.needsPower or equipment.powered) then - augBonusValue = augBonusValue + augEffect.amount + if augEffect.nostack then + table.insert(possibleValues, augEffect.amount) + else + augBonusValue = augBonusValue + augEffect.amount + end end end end end return augBonusValue end + script.on_internal_event(Defines.InternalEvents.GET_AUGMENTATION_VALUE, function(shipManager, augName, augValue) local weapons, drones pcall(function() weapons = shipManager.weaponSystem.weapons end) pcall(function() drones = shipManager.droneSystem.drones end) - augValue = augValue + get_aug_bonus(weapons, weaponInfo, augName) + get_aug_bonus(drones, droneInfo, augName) + local total = augValue + get_aug_bonus(weapons, weaponInfo, augName) + get_aug_bonus(drones, droneInfo, augName) + augValue = math.max(total, table.unpack(possibleValues)) + for i in ipairs(possibleValues) do possibleValues[i] = nil end return Defines.Chain.CONTINUE, augValue end) diff --git a/mod-appendix/metadata.xml b/mod-appendix/metadata.xml index d6c987d..d7681e1 100644 --- a/mod-appendix/metadata.xml +++ b/mod-appendix/metadata.xml @@ -2,7 +2,7 @@ <![CDATA[ Vertex Tags and Utility Functions ]]> - +