Example #1
0
File: place.py Project: rrpg/engine
	def getFromEntranceArea(idArea, t):
		if t not in types:
			raise exception(_('ERROR_UNKNOWN_PLACE_TYPE'))

		if t == _('PLACE_TYPE_DUNGEON'):
			return dungeon.getAvailable(idArea)
		elif t == _('PLACE_TYPE_CAVE'):
			return cave.getAvailable(idArea)
Example #2
0
    def connect(self, login):
        self._login = login
        self._model = model.loadByLogin(self._login)

        if len(self._model) == 0:
            self._login = None
            raise exception(_("ERROR_CONNECT_INVALID_CREDENTIALS"))

        return True
Example #3
0
File: place.py Project: rrpg/engine
	def generate(cls, place):
		"""
		Generate a place using an external generating tool

		@param place Place entity representing the place
		"""

		p = subprocess.Popen(
			core.config.generator['dungeon']['generator'],
			shell=True,
			stdout=subprocess.PIPE,
			stderr=subprocess.PIPE
		)

		result = p.communicate()

		if len(result[1]) is not 0: # pragma: no cover
			raise exception(_('ERROR_PLACE_GENERATION'))
		d = result[0].decode('utf-8').strip().split('\n')

		# Import an external check class from the generator
		sys.path.insert(0, core.config.generator['dungeon']['path'])
		import checks

		containerName = cls.areaType + '_' + str(place['id_place'])
		idRegion = area.model.loadById(place['id_area'], ('id_region'))['id_region']

		db = Model.connect()
		c = db.cursor()
		query = "INSERT INTO area\
			(id_area_type, x, y, directions, container, id_region)\
			VALUES (:id_area_type, :x, :y, :directions, :container, :id_region)"
		for index, room in enumerate(d):
			if int(room) == 0:
				continue

			params = {
				'id_area_type': place['id_area_type'],
				'x': index % 10,
				'y': index / 10,
				'directions': checks.getDirections(room) >> 2,
				'container': containerName,
				'id_region': idRegion
			}
			Model.executeQuery(c, query, params)

			if checks.isEntrance(int(room)):
				entrance = c.lastrowid
		Model.disconnect(db)

		model.update(
			{'entrance_id': entrance},
			('id_place = ?', [place['id_place']])
		)
		place['entrance_id'] = entrance
		return place
Example #4
0
    def createNewPlayer(self, login, speciesId, genderId):
        if len(model.loadBy({"login": login})):
            raise exception(_("ERROR_SIGNUP_LOGIN_ALREADY_USED"))

        if gender.model.loadById(genderId) == {}:
            raise exception(_("ERROR_SIGNUP_INVALID_GENDER"))

        if species.model.loadById(speciesId) == {}:
            raise exception(_("ERROR_SIGNUP_INVALID_SPECIES"))

        m = {
            "login": login,
            "name": login,
            "id_species": speciesId,
            "id_gender": genderId,
            "id_area": settings.get("START_CELL_ID"),
        }

        m["id_character"] = character.model.insert(m)
        model.insert(m)
        self._model = model.loadByLogin(login)
Example #5
0
	def getAllFromIdAreaAndType(idArea, containerType):
		itemContainerTypes = model.getTypes()
		containerTypeId = None
		for k in itemContainerTypes:
			if itemContainerTypes[k] == containerType:
				containerTypeId = k
				break

		if containerTypeId is None:
			raise exception(_('ERROR_UNKNOWN_ITEM_CONTAINER_TYPE_LABEL'))

		containers = model.loadBy({
			'id_area': idArea,
			'id_item_container_type': containerTypeId
		})

		for k, c in enumerate(containers):
			containers[k] = container.getMemoizedItems(containers[k])

		return containers