Skip to content

Commit

Permalink
added nostack attribute for augEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronoVortex committed Feb 22, 2023
1 parent aea714a commit 3fec837
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions data/vertex_module/tags/augEffects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion mod-appendix/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<title><![CDATA[ Vertex Tags and Utility Functions ]]></title>
<threadUrl><![CDATA[ https://github.com/ChronoVortex/FTL-HS-Vertex ]]></threadUrl>
<author><![CDATA[ Vertaalfout, Chrono Vortex ]]></author>
<version><![CDATA[ 1.9 ]]></version>
<version><![CDATA[ 1.10 ]]></version>
<description>
<![CDATA[
This mod has no content, instead adding new tags and LUA utility functions for other mods to build off of.
Expand Down

0 comments on commit 3fec837

Please sign in to comment.