Example #1
0
    def changeMoveType(self, general, move, user=None):
        generalDomain = Army_Factory.get(general)
        move = int(move)

        if move not in [1,2,3,4]:
            raise exceptions.args.EnumError("Wrong move mode")

        return super().changeMoveType(generalDomain, move, user)
Example #2
0
    def load(self, armyUser, position, config=None, user=None):
        if config is None:
            config = dict()

        detail = config['detail'] if 'detail' in config else False
        inBuild = config['inBuild'] if 'inBuild' in config else None

        return Army_Factory.getByPosition(armyUser,
                                          position,
                                          detail=detail,
                                          inBuild=inBuild)
Example #3
0
        def load(leader):
            suite = leader.getSuite()
            army = Army_Factory.getCollectionByGeneral(leader)
            # army.extract()

            armyData = []

            for domain in army:
                if not suite or suite.getId() != domain.getId():
                    armyData.append(load(domain))

            return {'current': leader, 'suite': suite, 'sub_army': armyData}
Example #4
0
    def move(self, general, path, user=None):
        general = Army_Factory.get(general)
        mapPath = []
        for coordinate in path:
            try:
                x, y, direction = coordinate
            except ValueError:
                raise WrongArgumentType()

            mapPath.append({
                'pos_id': helpers.MapCoordinate.MapCoordinate(x=x, y=y).getPosId(),
                'direction': direction
            })

        return super().move(general, mapPath, user)
Example #5
0
    def loadDetail(self, armyUser, _id, user=None):
        def load(leader):
            suite = leader.getSuite()
            army = Army_Factory.getCollectionByGeneral(leader)
            # army.extract()

            armyData = []

            for domain in army:
                if not suite or suite.getId() != domain.getId():
                    armyData.append(load(domain))

            return {'current': leader, 'suite': suite, 'sub_army': armyData}

        commander = Army_Factory.get(_id)
        return load(commander)
Example #6
0
    def _calculateUnitsSize(self, armyDomain):
        size = 0

        if armyDomain.getUnit().getType() == Common.TYPE_SOLIDER:
            return armyDomain.getCount()

        suiteArmy = armyDomain.getSuite()
        if suiteArmy:
            size += suiteArmy.getCount()

        armyCollection = Army_Factory.getCollectionByGeneral(armyDomain)

        for army in armyCollection:
            if army.getUnit().getType() == Common.TYPE_GENERAL:
                size += self._calculateUnitsSize(army)
                continue

            size += army.getCount()

        return size
Example #7
0
    def _create(self, unit, town, count):
        data = {
            'unit': unit,
            'user': town.getUser(),
            'count': count,
            'commander': None,
            'map': town.getMap(),
            'in_build': True,
            'power': 100,
            'mode': 1,
            'move_path': [],
            'suite': None,
            'is_general': unit.getType() == Common.TYPE_GENERAL,
            'last_power_update': int(time.time()),
            'formation_attack': Front.TYPE_AVANGARD,
            'formation_defence': Front.TYPE_AVANGARD
        }

        domain = Army_Factory.getDomainFromData(data)
        domain.getMapper().save(domain)
        return domain
Example #8
0
 def removeSolidersFromGeneral(self, generalArmy, solidersCollection, user=None):
     solidersCollection = [objectId(i) for i in solidersCollection]
     domain = Army_Factory.get(generalArmy)
     collection = Army_Factory.getByIds(solidersCollection)
     return super().removeSolidersFromGeneral(domain, collection, user)
Example #9
0
 def removeSuite(self, generalArmy, solidersArmy, user=None):
     generalDomain = Army_Factory.get(generalArmy)
     soliderDomain = Army_Factory.get(solidersArmy)
     return super().removeSuite(generalDomain, soliderDomain, user)
Example #10
0
 def updatePathMove(self, general):
     general = Army_Factory.get(general)
     return super().updatePathMove(general)
Example #11
0
 def dissolution(self, armyDomain, user=None):
     domain = Army_Factory.get(armyDomain)
     return super().dissolution(domain, user)
Example #12
0
 def _hasDeepGeneral(self, armyDomain):
     collection = Army_Factory.getSubGenerals(armyDomain)
     return bool(len(collection))
Example #13
0
 def loadByMapCollectionWithoutUser(self, user, collection):
     return Army_Factory.loadByMapCollectionWithoutUser(user, collection)
Example #14
0
 def loadByMapCollection(self, collection):
     """
     :type collection: collection.MapCollection.Map_Collection
     """
     return Army_Factory.loadByMapCollection(collection)
Example #15
0
 def get(self, _id, user=None):
     return Army_Factory.get(_id)
Example #16
0
 def moveOutBuild(self, armyDomain, user=None):
     domain = Army_Factory.get(armyDomain)
     return super().moveOutBuild(domain, user)
Example #17
0
 def merge(self, armyCollection, user=None):
     armyCollection = [objectId(i) for i in armyCollection]
     collection = Army_Factory.getByIds(armyCollection)
     return super().merge(collection, user)
Example #18
0
 def split(self, armyDomain, size, user=None):
     domain = Army_Factory.get(armyDomain)
     size = int(size)
     return super().split(domain, size, user)