Beispiel #1
0
 def test_battle_with_barbarians(self):
     world = World.objects.get(id=2)
     turn_processor = TurnProcessor(world)
     unit_of_kingrom_member = WorldUnit.objects.get(id=4)
     initialize_unit(unit_of_kingrom_member)
     kingdom_member = unit_of_kingrom_member.owner_character
     settlement = kingdom_member.location
     initialize_settlement(settlement)
     generate_barbarian_unit(30, settlement)
     turn_processor.trigger_battles()
     self.assertTrue(settlement.tile.get_current_battles().exists())
     battle = settlement.tile.get_current_battles()[0]
     start_battle(battle)
     battle_tick(battle)
     generate_barbarian_unit(30, settlement)
     battle_joins(battle)
     battle_tick(battle)
Beispiel #2
0
    def test_battle_create_from_units_with_allies_joining_during_battle2(self):
        self.unit_of_commonwealth.location_id = 1001
        self.unit_of_commonwealth.save()

        turn_processor = TurnProcessor(World.objects.get(id=2))
        turn_processor.trigger_battles()

        self.assertTrue(Battle.objects.exists())

        self.battle = Battle.objects.get(id=1)

        self.assertEqual(self.battle.battleside_set.count(), 2)

        self.assertTrue(
            BattleOrganization.objects.filter(
                side__battle=self.battle, organization=self.kingdom).exists())
        self.assertTrue(
            BattleOrganization.objects.filter(
                side__battle=self.battle, organization=self.horde).exists())
        self.assertFalse(
            BattleOrganization.objects.filter(
                side__battle=self.battle,
                organization=self.commonwealth).exists())
        self.assertEqual(BattleOrganization.objects.count(), 2)

        self.assertEqual(
            self.unit_of_commonwealth.owner_character.
            get_battle_participating_in(), None)

        self.assertTrue(
            BattleOrganization.objects.get(organization=self.kingdom).side.z !=
            BattleOrganization.objects.get(organization=self.horde).side.z)

        self.assertTrue(BattleCharacter.objects.exists())
        self.assertTrue(
            BattleCharacter.objects.filter(
                battle_organization__organization=self.kingdom, ).exists())
        self.assertTrue(
            BattleCharacter.objects.filter(
                battle_organization__organization=self.horde, ).exists())
        self.assertFalse(
            BattleCharacter.objects.filter(
                battle_organization__organization=self.commonwealth,
            ).exists())
        self.assertEqual(BattleCharacter.objects.count(), 2)

        self.assertTrue(BattleUnit.objects.exists())
        self.assertTrue(
            BattleUnit.objects.filter(world_unit=self.unit_of_warrior,
                                      starting_manpower=30).exists())
        self.assertFalse(
            BattleUnit.objects.filter(world_unit=self.unit_of_commonwealth,
                                      starting_manpower=30).exists())
        self.assertTrue(
            BattleUnit.objects.filter(world_unit=self.unit_of_warrior2,
                                      starting_manpower=60).exists())
        self.assertTrue(
            BattleUnit.objects.filter(world_unit=self.unit_of_kingdom,
                                      starting_manpower=100).exists())
        self.assertEqual(BattleUnit.objects.count(), 3)

        response = self.client.get(self.battle.get_absolute_url(), follow=True)
        self.assertEqual(response.status_code, 200)

        start_battle(self.battle)
        battle_tick(self.battle)

        self.unit_of_commonwealth.location_id = 1007
        self.unit_of_commonwealth.save()

        turn_processor.battle_joins()

        self.assertTrue(
            BattleOrganization.objects.filter(
                side__battle=self.battle,
                organization=self.commonwealth).exists())
        self.assertEqual(BattleOrganization.objects.count(), 3)

        self.assertTrue(
            BattleOrganization.objects.get(
                organization=self.commonwealth).side.z !=
            BattleOrganization.objects.get(organization=self.horde).side.z)

        self.assertTrue(
            BattleCharacter.objects.filter(
                battle_organization__organization=self.commonwealth,
            ).exists())
        self.assertEqual(BattleCharacter.objects.count(), 3)

        self.assertTrue(BattleUnit.objects.exists())
        self.assertTrue(
            BattleUnit.objects.filter(world_unit=self.unit_of_warrior,
                                      starting_manpower=30).exists())
        self.assertTrue(
            BattleUnit.objects.filter(world_unit=self.unit_of_commonwealth,
                                      starting_manpower=30).exists())
        self.assertTrue(
            BattleUnit.objects.filter(world_unit=self.unit_of_warrior2,
                                      starting_manpower=60).exists())
        self.assertTrue(
            BattleUnit.objects.filter(world_unit=self.unit_of_kingdom,
                                      starting_manpower=100).exists())
        self.assertEqual(BattleUnit.objects.count(), 4)

        self.assertEqual(
            self.unit_of_commonwealth.owner_character.
            get_battle_participating_in(), self.battle)

        battle_tick(self.battle)