From b807e2a36bdd55d0b913dc0448f755784a7d6f18 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Wed, 30 Oct 2024 20:09:26 +0100 Subject: [PATCH] Add on-fit pilot security attribute, and use it in effects --- eos/db/migrations/upgrade48.py | 15 +++++++++++++++ eos/db/saveddata/fit.py | 3 ++- eos/effects.py | 22 ++++++++++++---------- eos/saveddata/fit.py | 13 +++++++++++++ 4 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 eos/db/migrations/upgrade48.py diff --git a/eos/db/migrations/upgrade48.py b/eos/db/migrations/upgrade48.py new file mode 100644 index 0000000000..e72bcc1933 --- /dev/null +++ b/eos/db/migrations/upgrade48.py @@ -0,0 +1,15 @@ +""" +Migration 48 + +- added pilot security column (CONCORD ships) +""" + + +import sqlalchemy + + +def upgrade(saveddata_engine): + try: + saveddata_engine.execute("SELECT pilotSecurity FROM fits LIMIT 1") + except sqlalchemy.exc.DatabaseError: + saveddata_engine.execute("ALTER TABLE fits ADD COLUMN pilotSecurity FLOAT") diff --git a/eos/db/saveddata/fit.py b/eos/db/saveddata/fit.py index 3979286d5e..c1fa9cd4c2 100644 --- a/eos/db/saveddata/fit.py +++ b/eos/db/saveddata/fit.py @@ -63,7 +63,8 @@ Column("ignoreRestrictions", Boolean, default=0), Column("created", DateTime, nullable=True, default=datetime.datetime.now), Column("modified", DateTime, nullable=True, default=datetime.datetime.now, onupdate=datetime.datetime.now), - Column("systemSecurity", Integer, nullable=True) + Column("systemSecurity", Integer, nullable=True), + Column("pilotSecurity", Float, nullable=True), ) projectedFits_table = Table("projectedFits", saveddata_meta, diff --git a/eos/effects.py b/eos/effects.py index 222ec4b607..79a68f51ad 100644 --- a/eos/effects.py +++ b/eos/effects.py @@ -32121,22 +32121,24 @@ class Effect6871(BaseEffect): type = 'passive' @staticmethod - def handler(fit, src, context, projectionRange, **kwargs): + def handler(fit, ship, context, projectionRange, **kwargs): # Get pilot sec status bonus directly here, instead of going through the intermediary effects # via https://forums.eveonline.com/default.aspx?g=posts&t=515826 try: - bonus = max(0, min(50.0, (src.owner.character.secStatus * 10))) + sec_status = ship.owner.getPilotSecurity(low_limit=0, high_limit=5) except (KeyboardInterrupt, SystemExit): raise except: - bonus = None + return - if bonus is not None: - fit.modules.filteredItemBoost(lambda mod: mod.item.requiresSkill('Repair Systems'), - 'armorDamageAmount', bonus, **kwargs) - fit.modules.filteredItemBoost(lambda mod: mod.item.requiresSkill('Shield Operation'), - 'shieldBonus', bonus, **kwargs) + bonus = sec_status * 10 + fit.modules.filteredItemBoost( + lambda mod: mod.item.requiresSkill('Repair Systems'), + 'armorDamageAmount', bonus, **kwargs) + fit.modules.filteredItemBoost( + lambda mod: mod.item.requiresSkill('Shield Operation'), + 'shieldBonus', bonus, **kwargs) class Effect6872(BaseEffect): @@ -40869,12 +40871,12 @@ def handler(fit, ship, context, projectionRange, **kwargs): # Get pilot sec status bonus directly here, instead of going through the intermediary effects try: - capped_ss = max(-10, min(0, (ship.owner.character.secStatus))) + sec_status = ship.owner.getPilotSecurity(low_limit=-10, high_limit=0) except (KeyboardInterrupt, SystemExit): raise except: return - bonus = ship.getModifiedItemAttr('ATFrigDmgBonus') * capped_ss + bonus = ship.getModifiedItemAttr('ATFrigDmgBonus') * sec_status fit.modules.filteredItemBoost( lambda mod: (mod.item.requiresSkill('Small Energy Turret') or mod.item.requiresSkill('Small Hybrid Turret') diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index 60733a4650..69859ec4ab 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -1743,6 +1743,18 @@ def getSystemSecurity(self): secstatus = FitSystemSecurity.NULLSEC return secstatus + def getPilotSecurity(self, low_limit=-10, high_limit=5): + secstatus = self.pilotSecurity + # Not defined -> use character SS, with 0.0 fallback if it fails + if secstatus is None: + try: + secstatus = self.character.secStatus + except (SystemExit, KeyboardInterrupt): + raise + except: + secstatus = 0 + return max(low_limit, min(high_limit, secstatus)) + def activeModulesIter(self): for mod in self.modules: if mod.state >= FittingModuleState.ACTIVE: @@ -1824,6 +1836,7 @@ def __deepcopy__(self, memo=None): fitCopy.targetProfile = self.targetProfile fitCopy.implantLocation = self.implantLocation fitCopy.systemSecurity = self.systemSecurity + fitCopy.pilotSecurity = self.pilotSecurity fitCopy.notes = self.notes for i in self.modules: