(self)
| 17 | self.ignoreRestrictions = ignoreRestrictions |
| 18 | |
| 19 | def Do(self): |
| 20 | pyfalog.debug('Doing addition of fighter {} to fit {}'.format(self.fighterInfo, self.fitID)) |
| 21 | fighter = self.fighterInfo.toFighter() |
| 22 | if fighter is None: |
| 23 | return False |
| 24 | |
| 25 | fit = Fit.getInstance().getFit(self.fitID) |
| 26 | if not self.ignoreRestrictions and not fighter.fits(fit): |
| 27 | pyfalog.warning('Fighter does not fit') |
| 28 | return False |
| 29 | |
| 30 | # If we were not asked to set specific state, figure it out based on available tubes |
| 31 | if self.fighterInfo.state is None: |
| 32 | typeUsed = fit.getSlotsUsed(fighter.slot) |
| 33 | typeTotal = fit.getNumSlots(fighter.slot) |
| 34 | |
| 35 | if fit.fighterTubesUsed >= fit.fighterTubesTotal or typeUsed >= typeTotal: |
| 36 | fighter.active = False |
| 37 | else: |
| 38 | fighter.active = True |
| 39 | |
| 40 | if self.position is None: |
| 41 | fit.fighters.append(fighter) |
| 42 | if fighter not in fit.fighters: |
| 43 | pyfalog.warning('Failed to append to list') |
| 44 | return False |
| 45 | self.position = fit.fighters.index(fighter) |
| 46 | else: |
| 47 | fit.fighters.insert(self.position, fighter) |
| 48 | if fighter not in fit.fighters: |
| 49 | pyfalog.warning('Failed to insert to list') |
| 50 | return False |
| 51 | return True |
| 52 | |
| 53 | def Undo(self): |
| 54 | pyfalog.debug('Undoing addition of fighter {} to fit {}'.format(self.fighterInfo, self.fitID)) |
no test coverage detected