Skip to content

Commit

Permalink
only hook tag logic if the tag is used
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronoVortex committed Feb 21, 2023
1 parent 321e74a commit aea714a
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 238 deletions.
45 changes: 26 additions & 19 deletions data/vertex_module/tags/augEffects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ local customTagsWeapons = mods.vertexdata.customTagsWeapons
local customTagsDrones = mods.vertexdata.customTagsDrones
local Children = mods.vertexdata.Children
local parse_xml_bool = mods.vertexdata.parse_xml_bool
local tag_add_all = mods.vertexdata.tag_add_all
local tag_add_weapons = mods.vertexdata.tag_add_weapons
local tag_add_drones = mods.vertexdata.tag_add_drones

local vter = mods.vertexutil.vter
local under_mind_system = mods.vertexutil.under_mind_system
Expand All @@ -20,7 +23,7 @@ local crew_data = mods.vertexutil.crew_data
------------
-- PARSER --
------------
customTagsAll["augEffects"] = function(node)
local function parser(node)
local augEffects = {}
for augEffectNode in Children(node) do
local augEffect = {}
Expand All @@ -45,26 +48,30 @@ end
-----------
-- LOGIC --
-----------
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
local function logic()
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
end
end
end
end
return augBonusValue
end
return augBonusValue
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)

return Defines.Chain.CONTINUE, augValue
end)
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)

return Defines.Chain.CONTINUE, augValue
end)

tag_add_all("augEffects", parser, logic)
231 changes: 119 additions & 112 deletions data/vertex_module/tags/hack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ local customTagsWeapons = mods.vertexdata.customTagsWeapons
local customTagsDrones = mods.vertexdata.customTagsDrones
local Children = mods.vertexdata.Children
local parse_xml_bool = mods.vertexdata.parse_xml_bool
local tag_add_all = mods.vertexdata.tag_add_all
local tag_add_weapons = mods.vertexdata.tag_add_weapons
local tag_add_drones = mods.vertexdata.tag_add_drones

local vter = mods.vertexutil.vter
local under_mind_system = mods.vertexutil.under_mind_system
Expand All @@ -20,7 +23,7 @@ local crew_data = mods.vertexutil.crew_data
------------
-- PARSER --
------------
customTagsWeapons["hack"] = function(node)
local function parser(node)
local hack = {}

if not node:first_attribute("duration") then error("hack tag requires a duration!", 2) end
Expand All @@ -45,132 +48,136 @@ end
-----------
-- LOGIC --
-----------
local systemHackTimers = {}
systemHackTimers[0] = {}
systemHackTimers[1] = {}
local artilleryHackTimers = {}
artilleryHackTimers[0] = {}
artilleryHackTimers[1] = {}
local function logic()
local systemHackTimers = {}
systemHackTimers[0] = {}
systemHackTimers[1] = {}
local artilleryHackTimers = {}
artilleryHackTimers[0] = {}
artilleryHackTimers[1] = {}

-- Handle systems hacked by a weapon
local function handle_hack_for_ship(shipManager, clearShipId)
local shipId = nil
pcall(function() shipId = shipManager.iShipId end)
if shipId then
for systemId, hackTime in pairs(systemHackTimers[shipId]) do
if hackTime and hackTime > 0 then
systemHackTimers[shipId][systemId] = math.max(hackTime - Hyperspace.FPS.SpeedFactor/16, 0)
if systemHackTimers[shipId][systemId] == 0 then
local system = shipManager:GetSystem(systemId)
system.iHackEffect = 0
system.bUnderAttack = false
-- Handle systems hacked by a weapon
local function handle_hack_for_ship(shipManager, clearShipId)
local shipId = nil
pcall(function() shipId = shipManager.iShipId end)
if shipId then
for systemId, hackTime in pairs(systemHackTimers[shipId]) do
if hackTime and hackTime > 0 then
systemHackTimers[shipId][systemId] = math.max(hackTime - Hyperspace.FPS.SpeedFactor/16, 0)
if systemHackTimers[shipId][systemId] == 0 then
local system = shipManager:GetSystem(systemId)
system.iHackEffect = 0
system.bUnderAttack = false
end
end
end
end
for artyId, hackTime in pairs(artilleryHackTimers[shipId]) do
if hackTime and hackTime > 0 then
artilleryHackTimers[shipId][artyId] = math.max(hackTime - Hyperspace.FPS.SpeedFactor/16, 0)
if artilleryHackTimers[shipId][artyId] == 0 then
local system = shipManager.artillerySystems[artyId]
system.iHackEffect = 0
system.bUnderAttack = false
for artyId, hackTime in pairs(artilleryHackTimers[shipId]) do
if hackTime and hackTime > 0 then
artilleryHackTimers[shipId][artyId] = math.max(hackTime - Hyperspace.FPS.SpeedFactor/16, 0)
if artilleryHackTimers[shipId][artyId] == 0 then
local system = shipManager.artillerySystems[artyId]
system.iHackEffect = 0
system.bUnderAttack = false
end
end
end
end
else
if #(systemHackTimers[clearShipId]) > 0 then
for systemId in pairs(systemHackTimers[clearShipId]) do
systemHackTimers[clearShipId][systemId] = 0
else
if #(systemHackTimers[clearShipId]) > 0 then
for systemId in pairs(systemHackTimers[clearShipId]) do
systemHackTimers[clearShipId][systemId] = 0
end
end
end
if #(artilleryHackTimers[clearShipId]) > 0 then
for systemId in pairs(artilleryHackTimers[clearShipId]) do
artilleryHackTimers[clearShipId][systemId] = 0
if #(artilleryHackTimers[clearShipId]) > 0 then
for systemId in pairs(artilleryHackTimers[clearShipId]) do
artilleryHackTimers[clearShipId][systemId] = 0
end
end
end
end
end
script.on_internal_event(Defines.InternalEvents.ON_TICK, function()
-- Make sure the game isn't paused
if not Hyperspace.Global.GetInstance():GetCApp().world.space.gamePaused then
handle_hack_for_ship(Hyperspace.ships.player, 0)
handle_hack_for_ship(Hyperspace.ships.enemy, 1)
end
end)
script.on_internal_event(Defines.InternalEvents.ON_TICK, function()
-- Make sure the game isn't paused
if not Hyperspace.Global.GetInstance():GetCApp().world.space.gamePaused then
handle_hack_for_ship(Hyperspace.ships.player, 0)
handle_hack_for_ship(Hyperspace.ships.enemy, 1)
end
end)

-- General function for applying hack to a system on hit
local function apply_hack(hack, shipManager, system)
if system then
local durationSystem = hack.systemDurations[Hyperspace.ShipSystem.SystemIdToName(system:GetId())]
if system:GetId() == 11 then -- Special case for artillery
-- Find the index of the artillery system on the ship
artyIndex = 0
for arillery in vter(shipManager.artillerySystems) do
if system == arillery then break end
artyIndex = artyIndex + 1
end

-- Set hacking time for artillery
if durationSystem then
artilleryHackTimers[shipManager.iShipId][artyIndex] = math.max(
durationSystem,
artilleryHackTimers[shipManager.iShipId][artyIndex] or 0)
else
artilleryHackTimers[shipManager.iShipId][artyIndex] = math.max(
hack.duration,
artilleryHackTimers[shipManager.iShipId][artyIndex] or 0)
end
else
-- Set hacking time for non-artillery
if durationSystem then
systemHackTimers[shipManager.iShipId][system:GetId()] = math.max(
durationSystem,
systemHackTimers[shipManager.iShipId][system:GetId()] or 0)
-- General function for applying hack to a system on hit
local function apply_hack(hack, shipManager, system)
if system then
local durationSystem = hack.systemDurations[Hyperspace.ShipSystem.SystemIdToName(system:GetId())]
if system:GetId() == 11 then -- Special case for artillery
-- Find the index of the artillery system on the ship
artyIndex = 0
for arillery in vter(shipManager.artillerySystems) do
if system == arillery then break end
artyIndex = artyIndex + 1
end

-- Set hacking time for artillery
if durationSystem then
artilleryHackTimers[shipManager.iShipId][artyIndex] = math.max(
durationSystem,
artilleryHackTimers[shipManager.iShipId][artyIndex] or 0)
else
artilleryHackTimers[shipManager.iShipId][artyIndex] = math.max(
hack.duration,
artilleryHackTimers[shipManager.iShipId][artyIndex] or 0)
end
else
systemHackTimers[shipManager.iShipId][system:GetId()] = math.max(
hack.duration,
systemHackTimers[shipManager.iShipId][system:GetId()] or 0)
end

-- Stop mind control
if system:GetId() == 14 then
if shipManager.mindSystem.controlTimer.first < shipManager.mindSystem.controlTimer.second then
shipManager.mindSystem.controlTimer.first = shipManager.mindSystem.controlTimer.second - Hyperspace.FPS.SpeedFactor/16
-- Set hacking time for non-artillery
if durationSystem then
systemHackTimers[shipManager.iShipId][system:GetId()] = math.max(
durationSystem,
systemHackTimers[shipManager.iShipId][system:GetId()] or 0)
else
systemHackTimers[shipManager.iShipId][system:GetId()] = math.max(
hack.duration,
systemHackTimers[shipManager.iShipId][system:GetId()] or 0)
end

-- Stop mind control
if system:GetId() == 14 then
if shipManager.mindSystem.controlTimer.first < shipManager.mindSystem.controlTimer.second then
shipManager.mindSystem.controlTimer.first = shipManager.mindSystem.controlTimer.second - Hyperspace.FPS.SpeedFactor/16
end
end
end

-- Apply the actual hack effect
system.iHackEffect = 2
system.bUnderAttack = true
end

-- Apply the actual hack effect
system.iHackEffect = 2
system.bUnderAttack = true
end
end

-- Handle hacking beams
script.on_internal_event(Defines.InternalEvents.DAMAGE_BEAM, function(shipManager, projectile, location, damage, realNewTile, beamHitType)
hack = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["hack"]
if hack and hack.duration and hack.duration > 0 and beamHitType == Defines.BeamHit.NEW_ROOM then
apply_hack(hack, shipManager, shipManager:GetSystemInRoom(get_room_at_location(shipManager, location, true)))
end
return Defines.Chain.CONTINUE, beamHitType
end)
-- Handle hacking beams
script.on_internal_event(Defines.InternalEvents.DAMAGE_BEAM, function(shipManager, projectile, location, damage, realNewTile, beamHitType)
hack = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["hack"]
if hack and hack.duration and hack.duration > 0 and beamHitType == Defines.BeamHit.NEW_ROOM then
apply_hack(hack, shipManager, shipManager:GetSystemInRoom(get_room_at_location(shipManager, location, true)))
end
return Defines.Chain.CONTINUE, beamHitType
end)

-- Handle other hacking weapons
script.on_internal_event(Defines.InternalEvents.DAMAGE_AREA_HIT, function(shipManager, projectile, location, damage, shipFriendlyFire)
local hack = nil
pcall(function() hack = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["hack"] end)
if hack and hack.duration and hack.duration > 0 then
apply_hack(hack, shipManager, shipManager:GetSystemInRoom(get_room_at_location(shipManager, location, true)))
end
end)
-- Handle other hacking weapons
script.on_internal_event(Defines.InternalEvents.DAMAGE_AREA_HIT, function(shipManager, projectile, location, damage, shipFriendlyFire)
local hack = nil
pcall(function() hack = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["hack"] end)
if hack and hack.duration and hack.duration > 0 then
apply_hack(hack, shipManager, shipManager:GetSystemInRoom(get_room_at_location(shipManager, location, true)))
end
end)

-- Hack shields if shield bubble hit
script.on_internal_event(Defines.InternalEvents.SHIELD_COLLISION, function(shipManager, projectile, damage, response)
local hack = nil
pcall(function() hack = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["hack"] end)
if hack and hack.hitShieldDuration and hack.hitShieldDuration > 0 then
local shieldDuration = {}
shieldDuration["shields"] = hack.hitShieldDuration
apply_hack({systemDurations = shieldDuration}, shipManager, shipManager:GetSystem(0))
end
end)
-- Hack shields if shield bubble hit
script.on_internal_event(Defines.InternalEvents.SHIELD_COLLISION, function(shipManager, projectile, damage, response)
local hack = nil
pcall(function() hack = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["hack"] end)
if hack and hack.hitShieldDuration and hack.hitShieldDuration > 0 then
local shieldDuration = {}
shieldDuration["shields"] = hack.hitShieldDuration
apply_hack({systemDurations = shieldDuration}, shipManager, shipManager:GetSystem(0))
end
end)
end

tag_add_weapons("hack", parser, logic)
37 changes: 22 additions & 15 deletions data/vertex_module/tags/lockdownBeam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ local customTagsWeapons = mods.vertexdata.customTagsWeapons
local customTagsDrones = mods.vertexdata.customTagsDrones
local Children = mods.vertexdata.Children
local parse_xml_bool = mods.vertexdata.parse_xml_bool
local tag_add_all = mods.vertexdata.tag_add_all
local tag_add_weapons = mods.vertexdata.tag_add_weapons
local tag_add_drones = mods.vertexdata.tag_add_drones

local vter = mods.vertexutil.vter
local under_mind_system = mods.vertexutil.under_mind_system
Expand All @@ -20,7 +23,7 @@ local crew_data = mods.vertexutil.crew_data
------------
-- PARSER --
------------
customTagsWeapons["lockdownBeam"] = function(node)
local function parser(node)
local lockdown = {}
lockdown.doLockdown = true

Expand Down Expand Up @@ -48,19 +51,23 @@ end
-----------
-- LOGIC --
-----------
script.on_internal_event(Defines.InternalEvents.DAMAGE_BEAM, function(shipManager, projectile, location, damage, realNewTile, beamHitType)
local lockdown = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["lockdownBeam"]
if lockdown.doLockdown then
local doLockdown =
not lockdown.chance or
lockdown.chance >= 10 or
(lockdown.chance > 0 and lockdown.chance > Hyperspace.random32()%10)
if doLockdown and beamHitType == Defines.BeamHit.NEW_ROOM then
shipManager.ship:LockdownRoom(get_room_at_location(shipManager, location, true), location)
if #(lockdown.sounds) > 0 then
Hyperspace.Global.GetInstance():GetSoundControl():PlaySoundMix(lockdown.sounds[Hyperspace.random32()%#(lockdown.sounds) + 1], 1, false)
local function logic()
script.on_internal_event(Defines.InternalEvents.DAMAGE_BEAM, function(shipManager, projectile, location, damage, realNewTile, beamHitType)
local lockdown = weaponInfo[Hyperspace.Get_Projectile_Extend(projectile).name]["lockdownBeam"]
if lockdown.doLockdown then
local doLockdown =
not lockdown.chance or
lockdown.chance >= 10 or
(lockdown.chance > 0 and lockdown.chance > Hyperspace.random32()%10)
if doLockdown and beamHitType == Defines.BeamHit.NEW_ROOM then
shipManager.ship:LockdownRoom(get_room_at_location(shipManager, location, true), location)
if #(lockdown.sounds) > 0 then
Hyperspace.Global.GetInstance():GetSoundControl():PlaySoundMix(lockdown.sounds[Hyperspace.random32()%#(lockdown.sounds) + 1], 1, false)
end
end
end
end
return Defines.Chain.CONTINUE, beamHitType
end)
return Defines.Chain.CONTINUE, beamHitType
end)
end

tag_add_weapons("lockdownBeam", parser, logic)
Loading

0 comments on commit aea714a

Please sign in to comment.