def testCharacter(self): holder = CharacterItem(self.ch.type_(typeId=1, effects=(self.effect,), attributes={self.tgtAttr.id: 100, self.srcAttr.id: 20})) self.fit.items.add(holder) self.assertNotAlmostEqual(holder.attributes[self.tgtAttr.id], 100) self.fit.items.remove(holder) self.assertEqual(len(self.log), 0) self.assertLinkBuffersEmpty(self.fit)
def testOther(self): influenceTarget = CharacterItem(self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100})) self.fit.items.add(influenceTarget) self.assertAlmostEqual(influenceTarget.attributes[self.tgtAttr.id], 100) self.fit.items.remove(self.influenceSource) self.fit.items.remove(influenceTarget) self.assertEqual(len(self.log), 0) self.assertLinkBuffersEmpty(self.fit)
def testOther(self): # Here we check that self-reference modifies only carrier-item, # and nothing else is affected. We position item as character and # check character item to also check that items 'belonging' to self # are not affected too influenceSource = IndependentItem(self.ch.type_(typeId=1, effects=(self.effect,), attributes={self.tgtAttr.id: 100, self.srcAttr.id: 20})) self.fit.character = influenceSource influenceTarget = CharacterItem(self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100})) self.fit.items.add(influenceTarget) self.assertAlmostEqual(influenceTarget.attributes[self.tgtAttr.id], 100) self.fit.character = None self.fit.items.remove(influenceTarget) self.assertEqual(len(self.log), 0) self.assertLinkBuffersEmpty(self.fit)
def testAttribute(self): attr1 = self.ch.attribute(attributeId=1) attr2 = self.ch.attribute(attributeId=2) attr3 = self.ch.attribute(attributeId=3) modifier1 = Modifier() modifier1.state = State.offline modifier1.context = Context.local modifier1.sourceAttributeId = attr1.id modifier1.operator = Operator.postMul modifier1.targetAttributeId = attr2.id modifier1.location = Location.ship modifier1.filterType = None modifier1.filterValue = None effect1 = self.ch.effect(effectId=1, categoryId=EffectCategory.passive) effect1.modifiers = (modifier1, ) holder1 = CharacterItem( self.ch.type_(typeId=1, effects=(effect1, ), attributes={attr1.id: 5})) modifier2 = Modifier() modifier2.state = State.offline modifier2.context = Context.local modifier2.sourceAttributeId = attr2.id modifier2.operator = Operator.postPercent modifier2.targetAttributeId = attr3.id modifier2.location = Location.ship modifier2.filterType = FilterType.all_ modifier2.filterValue = None effect2 = self.ch.effect(effectId=2, categoryId=EffectCategory.passive) effect2.modifiers = (modifier2, ) holder2 = IndependentItem( self.ch.type_(typeId=2, effects=(effect2, ), attributes={attr2.id: 7.5})) holder3 = ShipItem(self.ch.type_(typeId=3, attributes={attr3.id: 0.5})) self.fit.items.add(holder1) self.fit.ship = holder2 self.fit.items.add(holder3) self.assertAlmostEqual(holder3.attributes[attr3.id], 0.6875) holder1.attributes[attr1.id] = 4 # Manually changed attribute must trigger damaging whole chain # of attributes, effectively allowing us to recalculate its new value self.assertAlmostEqual(holder3.attributes[attr3.id], 0.65) self.fit.items.remove(holder1) self.fit.ship = None self.fit.items.remove(holder3) self.assertEqual(len(self.log), 0) self.assertLinkBuffersEmpty(self.fit)
def testAttribute(self): attr1 = self.ch.attribute(attributeId=1) attr2 = self.ch.attribute(attributeId=2) attr3 = self.ch.attribute(attributeId=3) modifier1 = Modifier() modifier1.state = State.offline modifier1.context = Context.local modifier1.sourceAttributeId = attr1.id modifier1.operator = Operator.postMul modifier1.targetAttributeId = attr2.id modifier1.location = Location.ship modifier1.filterType = None modifier1.filterValue = None effect1 = self.ch.effect(effectId=1, categoryId=EffectCategory.passive) effect1.modifiers = (modifier1, ) holder1 = CharacterItem( self.ch.type_(typeId=1, effects=(effect1, ), attributes={attr1.id: 5})) modifier2 = Modifier() modifier2.state = State.offline modifier2.context = Context.local modifier2.sourceAttributeId = attr2.id modifier2.operator = Operator.postPercent modifier2.targetAttributeId = attr3.id modifier2.location = Location.ship modifier2.filterType = FilterType.all_ modifier2.filterValue = None effect2 = self.ch.effect(effectId=2, categoryId=EffectCategory.passive) effect2.modifiers = (modifier2, ) holder2 = IndependentItem( self.ch.type_(typeId=2, effects=(effect2, ), attributes={attr2.id: 7.5})) holder3 = ShipItem(self.ch.type_(typeId=3, attributes={attr3.id: 0.5})) self.fit.ship = holder2 self.fit.items.add(holder3) self.assertAlmostEqual(holder3.attributes[attr3.id], 0.5375) self.fit.items.add(holder1) # Added holder must clean all already calculated attributes # which are now affected by it, to allow recalculation self.assertAlmostEqual(holder3.attributes[attr3.id], 0.6875) self.fit.items.remove(holder1) self.fit.ship = None self.fit.items.remove(holder3) self.assertEqual(len(self.log), 0) self.assertLinkBuffersEmpty(self.fit)
def testCalculation(self): attr1 = self.ch.attribute(attributeId=1) attr2 = self.ch.attribute(attributeId=2) attr3 = self.ch.attribute(attributeId=3) attr4 = self.ch.attribute(attributeId=4) modifier1 = Modifier() modifier1.state = State.offline modifier1.context = Context.local modifier1.sourceAttributeId = attr1.id modifier1.operator = Operator.postMul modifier1.targetAttributeId = attr2.id modifier1.location = Location.self_ modifier1.filterType = None modifier1.filterValue = None effect1 = self.ch.effect(effectId=1, categoryId=EffectCategory.passive) effect1.modifiers = (modifier1, ) modifier2 = Modifier() modifier2.state = State.offline modifier2.context = Context.local modifier2.sourceAttributeId = attr2.id modifier2.operator = Operator.postPercent modifier2.targetAttributeId = attr3.id modifier2.location = Location.ship modifier2.filterType = None modifier2.filterValue = None effect2 = self.ch.effect(effectId=2, categoryId=EffectCategory.passive) effect2.modifiers = (modifier2, ) holder1 = CharacterItem( self.ch.type_(typeId=1, effects=(effect1, effect2), attributes={ attr1.id: 5, attr2.id: 20 })) modifier3 = Modifier() modifier3.state = State.offline modifier3.context = Context.local modifier3.sourceAttributeId = attr3.id modifier3.operator = Operator.postPercent modifier3.targetAttributeId = attr4.id modifier3.location = Location.ship modifier3.filterType = FilterType.all_ modifier3.filterValue = None effect3 = self.ch.effect(effectId=3, categoryId=EffectCategory.passive) effect3.modifiers = (modifier3, ) holder2 = IndependentItem( self.ch.type_(typeId=2, effects=(effect3, ), attributes={attr3.id: 150})) holder3 = ShipItem(self.ch.type_(typeId=3, attributes={attr4.id: 12.5})) self.fit.items.add(holder1) self.fit.ship = holder2 self.fit.items.add(holder3) # If everything is processed properly, holder1 will multiply attr2 by attr1 # on self, resulting in 20 * 5 = 100, then apply it as percentage modifier # on ship's (holder2) attr3, resulting in 150 + 100% = 300, then it is applied # to all entities assigned to ship, including holder3, to theirs attr4 as # percentage modifier again - so final result is 12.5 + 300% = 50 self.assertAlmostEqual(holder3.attributes[attr4.id], 50) self.fit.items.remove(holder1) self.fit.ship = None self.fit.items.remove(holder3) self.assertEqual(len(self.log), 0) self.assertLinkBuffersEmpty(self.fit)