Beispiel #1
0
    def __init__(self, defenders, attackers):
        self.attackers = FrontCollection(inDefence=False)
        self.defenders = FrontCollection(inDefence=True)

        self.location = None

        serviceArmy = Service_Army()

        self.defendersCollection = []
        for defender in defenders:
            for i in self.parseDetailLoad(
                    serviceArmy.loadDetail(None, defender)):
                self.defendersCollection += i

        self.attackersCollection = []
        for attacker in attackers:
            for i in self.parseDetailLoad(
                    serviceArmy.loadDetail(None, attacker)):
                self.attackersCollection += i

        self.createFronts()
        self.getLocation(defenders[0])

        self.attackers.setLocation(self.location)
        self.defenders.setLocation(self.location)
    def updateUnitsOnMap(self, user, unitsList):
        serviceArmyJsonPack = Service_Army().getDecorateClass(
            Service_Army.JSONPACK)

        user.getTransfer().forceSend(
            '/delivery/unitsUpdateOnMap', {
                'done': True,
                'units':
                [serviceArmyJsonPack.pack(unit) for unit in unitsList]
            })
        def parseArmy(mapCoordinate, army):
            armyJsonPack = Service_Army().getDecorateClass(
                Service_Army.JSONPACK)

            for userId in army:
                army[userId]['user'].getTransfer().forceSend(
                    '/delivery/askAboutBattle', {
                        'mapPosition':
                        mapCoordinate.getPosId(),
                        'army': [
                            armyJsonPack.pack(unit)
                            for unit in army[userId]['units']
                        ],
                        'state':
                        'attack'
                    })
    def moveOneUnit(self, general):
        user = general.getUser()

        user.getTransfer().forceSend(
            '/delivery/moveUnit', {
                'done':
                True,
                'general':
                Service_Army().getDecorateClass(
                    Service_Army.JSONPACK).pack(general)
            })
    def testMergeGenerals(self):
        self.dragNDrop(self._getArmyInList(self.general_2),
                       self._getArmyInList(self.general_1))
        self.waitForSocket()
        self._armyNotInList(self.general_2)

        unitDetail = Service_Army().loadDetail(self.user,
                                               self.general_1.getId())
        self.assertEqual(len(unitDetail['sub_army']), 1)
        self.assertEqual(unitDetail['sub_army'][0]['current'].getId(),
                         self.general_2.getId())
    def testAddSoliderToGeneral(self):
        self._selectArmyInList(self.general_1)
        self._selectArmyInList(self.solider_1)
        self._selectArmyInList(self.solider_2)
        self._armyAction('add_soliders_to_general')

        self.waitForSocket()

        unitDetail = Service_Army().loadDetail(self.user,
                                               self.general_1.getId())
        self.assertEqual(len(unitDetail['sub_army']), 2)
    def moveUnit(self, general):
        posId = general.getLocation()
        usersCollection = Service_MapUserVisible().decorate(
            Service_MapUserVisible.PARAMS).getUsersWhoSeePosition(posId)
        armyPack = Service_Army().getDecorateClass(
            Service_Army.JSONPACK).pack(general)

        for user in usersCollection:
            user.getTransfer().forceSend('/delivery/moveUnit', {
                'done': True,
                'general': armyPack
            })
Beispiel #8
0
    def fastMove(self, general, x, y):
        general.setMovePath([{
            'pos_id': MapCoordinate(x=x, y=y).getPosId(),
            'direction': '',
            'code': '',
            'power': 0,
            'start_at': 0,
            'complete_after': 1
        }])

        general.getMapper().save(general)

        Service_Army()._moveUnitPosition(general)
    def openRegion(self, user, mapCollection):
        serviceJsonpackMap = Service_Map().getDecorateClass(Service_Map.JSONPACK)
        result = serviceJsonpackMap.fromCollectionToList(mapCollection)
        units = Service_Army().decorate(Service_Army.JSONPACK).loadByMapCollectionWithoutUser(user, mapCollection)

        user.getTransfer().forceSend('/map/show', {
            'done': True,
            'result': {
                'data': result
            }
        })

        if (len(units)):
            controller.ArmyController.DeliveryController().updateUnitsOnMap(user, units)
    def testSplitUnits(self):
        self._selectArmyInList(self.solider_1)
        self._armyAction('split')

        self.selectRange(
            self.byCssSelector('.split-block input[type="range"]'), 25)
        self.byCssSelector('.confirm-split').click()
        self.waitForSocket()

        self.solider_1.extract(True)
        result = Service_Army().load(self.user,
                                     self.town.getMap().getPosition(),
                                     {'inBuild': True})
        self.assertEqual(len(result), 13)
        self.assertEqual(self.solider_1.getCount(), 25)
    def load_chunks(self, transfer, data):
        userCollectionChunks = self._getAclMapService().getByVisibleCollection(
            self._getMapUserVisibleService().getByChunks(
                transfer.getUser(),
                data['chunkList']
            )
        )

        userChunksList = Service_Map().getDecorateClass(Service_Map.JSONPACK).fromCollectionToList(userCollectionChunks)
        units = Service_Army().decorate(Service_Army.JSONPACK).loadByMapCollection(userCollectionChunks)

        transfer.send('/map/load_chunks', {
            'done': True,
            'result': {
                'data': userChunksList
            }
        })

        controller.ArmyController.DeliveryController().updateUnitsOnMap(transfer.getUser(), units)
 def _getParamsArmyService(self):
     return Service_Army().decorate(Service_Army.PARAMS)
 def _getArmyService(self):
     return Service_Army()
Beispiel #14
0
 def createArmy(self, town, unit, count=100):
     return Service_Army().create(unit, town, count)
Beispiel #15
0
    def getLocation(self, defender):
        armyDomain = Service_Army().get(defender)
        mapDomain = armyDomain.getMap()

        self.location = PlacesFactory.getPlace(mapDomain)