Rework how effect-blocking modules (scram) work to properly support undoing

This commit is contained in:
DarkPhoenix
2019-04-29 20:25:28 +03:00
parent 72fe52e560
commit 4eb8973c31
16 changed files with 195 additions and 106 deletions

View File

@@ -10027,16 +10027,16 @@ class Effect3380(BaseEffect):
@staticmethod
def handler(fit, module, context):
if 'projected' in context:
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
if module.charge is not None and module.charge.ID == 45010:
for mod in fit.modules:
if not mod.isEmpty and mod.item.requiresSkill('High Speed Maneuvering') and mod.state > FittingModuleState.ONLINE:
mod.state = FittingModuleState.ONLINE
if not mod.isEmpty and mod.item.requiresSkill('Micro Jump Drive Operation') and mod.state > FittingModuleState.ONLINE:
mod.state = FittingModuleState.ONLINE
if module.charge is not None:
if module.charge.ID in (29003, 45010):
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
if module.charge.ID == 45010:
fit.modules.filteredItemIncrease(
lambda mod: mod.item.requiresSkill('High Speed Maneuvering') or mod.item.requiresSkill('Micro Jump Drive Operation'),
'activationBlocked', 1)
else:
fit.ship.forceItemAttr('disallowAssistance', 1)
if module.charge is None:
fit.ship.boostItemAttr('mass', module.getModifiedItemAttr('massBonusPercentage'))
fit.ship.boostItemAttr('signatureRadius', module.getModifiedItemAttr('signatureRadiusBonus'))
@@ -10045,8 +10045,6 @@ class Effect3380(BaseEffect):
fit.modules.filteredItemBoost(lambda mod: mod.item.group.name == 'Propulsion Module',
'speedFactor', module.getModifiedItemAttr('speedFactorBonus'))
fit.ship.forceItemAttr('disallowAssistance', 1)
class Effect3392(BaseEffect):
"""
@@ -23394,16 +23392,9 @@ class Effect5934(BaseEffect):
return
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
# this is such a dirty hack
for mod in fit.modules:
if not mod.isEmpty and mod.state > FittingModuleState.ONLINE and (
mod.item.requiresSkill('Micro Jump Drive Operation') or
mod.item.requiresSkill('High Speed Maneuvering')
):
mod.state = FittingModuleState.ONLINE
if not mod.isEmpty and mod.item.requiresSkill('Micro Jump Drive Operation') and mod.state > FittingModuleState.ONLINE:
mod.state = FittingModuleState.ONLINE
fit.modules.filteredItemIncrease(
lambda mod: mod.item.requiresSkill('High Speed Maneuvering') or mod.item.requiresSkill('Micro Jump Drive Operation'),
'activationBlocked', module.getModifiedItemAttr('activationBlockedStrenght'))
class Effect5938(BaseEffect):
@@ -25292,12 +25283,9 @@ class Effect6222(BaseEffect):
def handler(fit, module, context):
if 'projected' in context:
fit.ship.increaseItemAttr('warpScrambleStatus', module.getModifiedItemAttr('warpScrambleStrength'))
if module.charge is not None and module.charge.ID == 47336:
for mod in fit.modules:
if not mod.isEmpty and mod.item.requiresSkill('High Speed Maneuvering') and mod.state > FittingModuleState.ONLINE:
mod.state = FittingModuleState.ONLINE
if not mod.isEmpty and mod.item.requiresSkill('Micro Jump Drive Operation') and mod.state > FittingModuleState.ONLINE:
mod.state = FittingModuleState.ONLINE
fit.modules.filteredItemIncrease(
lambda mod: mod.item.requiresSkill('High Speed Maneuvering') or mod.item.requiresSkill('Micro Jump Drive Operation'),
'activationBlocked', module.getModifiedItemAttr('activationBlockedStrenght'))
class Effect6230(BaseEffect):
@@ -34149,6 +34137,7 @@ class Effect7026(BaseEffect):
@staticmethod
def handler(fit, src, context, *args, **kwargs):
src.boostItemAttr('maxRange', src.getModifiedChargeAttr('warpScrambleRangeBonus'))
src.forceItemAttr('activationBlockedStrenght', src.getModifiedChargeAttr('activationBlockedStrenght'))
class Effect7027(BaseEffect):

View File

@@ -601,7 +601,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
# Check if we're within bounds
if state < -1 or state > 2:
return False
elif state >= FittingModuleState.ACTIVE and not self.item.isType("active"):
elif state >= FittingModuleState.ACTIVE and (not self.item.isType("active") or self.getModifiedItemAttr('activationBlocked') > 0):
return False
elif state == FittingModuleState.OVERHEATED and not self.item.isType("overheat"):
return False
@@ -771,28 +771,26 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut):
context = ("module",)
projected = False
# if gang:
# context += ("commandRun",)
if self.charge is not None:
# fix for #82 and it's regression #106
if not projected or (self.projected and not forceProjected) or gang:
for effect in self.charge.effects.values():
if effect.runTime == runTime and \
effect.activeByDefault and \
(effect.isType("offline") or
(effect.isType("passive") and self.state >= FittingModuleState.ONLINE) or
(effect.isType("active") and self.state >= FittingModuleState.ACTIVE)) and \
(not gang or (gang and effect.isType("gang"))):
chargeContext = ("moduleCharge",)
# For gang effects, we pass in the effect itself as an argument. However, to avoid going through
# all the effect files and defining this argument, do a simple try/catch here and be done with it.
if (
effect.runTime == runTime and
effect.activeByDefault and (
effect.isType("offline") or
(effect.isType("passive") and self.state >= FittingModuleState.ONLINE) or
(effect.isType("active") and self.state >= FittingModuleState.ACTIVE)) and
(not gang or (gang and effect.isType("gang")))
):
contexts = ("moduleCharge",)
# For gang effects, we pass in the effect itself as an argument. However, to avoid going through all
# the effect definitions and defining this argument, do a simple try/catch here and be done with it.
# @todo: possibly fix this
try:
effect.handler(fit, self, chargeContext, effect=effect)
effect.handler(fit, self, contexts, effect=effect)
except:
effect.handler(fit, self, chargeContext)
effect.handler(fit, self, contexts)
if self.item:
if self.state >= FittingModuleState.OVERHEATED: