Ejemplo n.º 1
0
    def test_homeland_defense(self):
        """Make sure homeland defense buffs work properly"""
        self.conf["game"]["homeland_defense"] = "100/50/25"
        self.assertEqual(None, self.sapphire.owner)
        battle = self.battle
        sess = self.sess

        # Skirmish 1
        s1 = battle.create_skirmish(self.alice, 10)  # Attack 10
        s1a = s1.react(self.carol, 4, hinder=False)  # --Support 4
        s1a.react(self.bob, 3)                       # ----Attack 3
        s1.react(self.dave, 8)                       # --Attack 8
        # Winner will be team orangered, 11 VP

        # Skirmish 2
        battle.create_skirmish(self.bob, 5)         # Attack 5
        # Winner will be team periwinkle, 10 VP for unopposed

        # End fight
        self.battle.ends = self.battle.begins
        sess.commit()
        self.assert_(battle.past_end_time())

        updates = Battle.update_all(sess, conf=self.conf)
        sess.commit()

        # Overall winner would ordinarily be orangered, but this should get
        # modified by the homeland defense buffs - Sapphire is right next to
        # the test capital, and so will get an extra 50%
        self.assertEqual(battle.victor, 1)
        self.assertEqual(battle.score1, 15)
        # OR should get 25% bonus
        self.assertEqual(battle.score0, 13)
Ejemplo n.º 2
0
    def end_battle(self, battle=None, conf=None):
        if battle is None:
            battle = self.battle
        sess = self.sess

        battle.ends = battle.begins
        sess.commit()
        updates = Battle.update_all(sess, conf)
        sess.commit()

        self.assertNotEqual(len(updates['ended']), 0)
        self.assertEqual(updates["ended"][0], battle)
        return battle
Ejemplo n.º 3
0
    def test_allow_scheduled_invasion(self):
        """Can move somewhere that's not yours if you are invading"""
        londo = self.get_region("Orange Londo")
        # For testing purposes, londo is now neutral
        londo.owner = None

        battle = Battle(region=londo)
        self.sess.add(battle)
        self.sess.commit()

        self.alice.move(100, londo, 0)

        self.assertEqual(self.alice.region, londo)
Ejemplo n.º 4
0
    def test_orangered_victory(self):
        """Make sure orangered victories actually count"""
        self.assertEqual(None, self.sapphire.owner)
        sess = self.sess
        self.battle.create_skirmish(self.alice, 5)

        self.battle.ends = self.battle.begins
        sess.commit()
        updates = Battle.update_all(sess)
        sess.commit()

        self.assertNotEqual(len(updates['ended']), 0)
        self.assertEqual(updates["ended"][0], self.battle)
        self.assertEqual(0, self.sapphire.owner)
Ejemplo n.º 5
0
    def test_full_battle(self):
        """Full battle"""
        battle = self.battle
        sess = self.sess

        oldowner = self.sapphire.owner

        # Battle should be ready and started
        self.assert_(battle.is_ready())
        self.assert_(battle.has_started())

        # Still going, right?
        self.assertFalse(battle.past_end_time())

        # Skirmish 1
        s1 = battle.create_skirmish(self.alice, 10)  # Attack 10
        s1a = s1.react(self.carol, 4, hinder=False)  # --Support 4
        s1a.react(self.bob, 3)                       # ----Attack 3
        s1.react(self.dave, 8)                       # --Attack 8
        # Winner will be team orangered, 11 VP

        # Skirmish 2
        battle.create_skirmish(self.bob, 15)         # Attack 15
        # Winner will be team periwinkle, 30 VP for unopposed

        # Skirmish 3
        s3 = battle.create_skirmish(self.carol, 10)  # Attack 10
        s3.react(self.bob, 5)                        # --Attack 5
        # Winner will be team orangered, 5 VP
        # Overall winner should be team periwinkle, 30 to 16

        # End this bad boy
        self.battle.ends = self.battle.begins
        sess.commit()
        self.assert_(battle.past_end_time())

        updates = Battle.update_all(sess)
        sess.commit()

        self.assertNotEqual(len(updates['ended']), 0)
        self.assertEqual(updates["ended"][0], battle)
        self.assertEqual(battle.victor, 1)
        self.assertEqual(battle.score0, 16)
        self.assertEqual(battle.score1, 30)

        self.assertNotEqual(oldowner, battle.region.owner)
        self.assertEqual(battle.region.owner, 1)
Ejemplo n.º 6
0
 def end_skirmish(self, skirmish):
     sess = self.sess
     skirmish.ends = 1
     Battle.update_all(sess)
     return skirmish