Check with other modules if there are restrictions that might not allow this module to be activated. Returns True if state is allowed, or max state module can have if current state is invalid.
(self, state=None, projectedOnto=None)
| 753 | return state |
| 754 | |
| 755 | def canHaveState(self, state=None, projectedOnto=None): |
| 756 | """ |
| 757 | Check with other modules if there are restrictions that might not allow this module to be activated. |
| 758 | Returns True if state is allowed, or max state module can have if current state is invalid. |
| 759 | """ |
| 760 | # If we're going to set module to offline, it should be fine for all cases |
| 761 | item = self.item |
| 762 | if state <= FittingModuleState.OFFLINE: |
| 763 | return True |
| 764 | |
| 765 | # Check if the local module is over it's max limit; if it's not, we're fine |
| 766 | maxGroupOnline = self.getModifiedItemAttr("maxGroupOnline", None) |
| 767 | maxGroupActive = self.getModifiedItemAttr("maxGroupActive", None) |
| 768 | if not maxGroupOnline and not maxGroupActive and projectedOnto is None: |
| 769 | return True |
| 770 | |
| 771 | # Following is applicable only to local modules, we do not want to limit projected |
| 772 | if projectedOnto is None: |
| 773 | currOnline = 0 |
| 774 | currActive = 0 |
| 775 | group = item.group.name |
| 776 | maxState = None |
| 777 | for mod in self.owner.modules: |
| 778 | currItem = getattr(mod, "item", None) |
| 779 | if currItem is not None and currItem.group.name == group: |
| 780 | if mod.state >= FittingModuleState.ONLINE: |
| 781 | currOnline += 1 |
| 782 | if mod.state >= FittingModuleState.ACTIVE: |
| 783 | currActive += 1 |
| 784 | if maxGroupOnline and currOnline > maxGroupOnline: |
| 785 | if maxState is None or maxState > FittingModuleState.OFFLINE: |
| 786 | maxState = FittingModuleState.OFFLINE |
| 787 | break |
| 788 | if maxGroupActive and currActive > maxGroupActive: |
| 789 | if maxState is None or maxState > FittingModuleState.ONLINE: |
| 790 | maxState = FittingModuleState.ONLINE |
| 791 | return True if maxState is None else maxState |
| 792 | # For projected, we're checking if ship is vulnerable to given item |
| 793 | else: |
| 794 | # Do not allow to apply offensive modules on ship with offensive module immunite, with few exceptions |
| 795 | # (all effects which apply instant modification are exception, generally speaking) |
| 796 | if item.offensive and projectedOnto.ship.getModifiedItemAttr("disallowOffensiveModifiers") == 1: |
| 797 | offensiveNonModifiers = {"energyDestabilizationNew", |
| 798 | "leech", |
| 799 | "energyNosferatuFalloff", |
| 800 | "energyNeutralizerFalloff"} |
| 801 | if not offensiveNonModifiers.intersection(set(item.effects)): |
| 802 | return FittingModuleState.OFFLINE |
| 803 | # If assistive modules are not allowed, do not let to apply these altogether |
| 804 | if item.assistive and projectedOnto.ship.getModifiedItemAttr("disallowAssistance") == 1: |
| 805 | return FittingModuleState.OFFLINE |
| 806 | return True |
| 807 | |
| 808 | def isValidCharge(self, charge): |
| 809 | # Check sizes, if 'charge size > module volume' it won't fit |
no test coverage detected