コード例 #1
0
ファイル: creature.py プロジェクト: rrpg/engine
	def getFromAreaType(idAreaType, probability):
		"""
		emeny.model.getFromArea(area) -> dict()

		Return a random enemy that the player can encounter in a given
		area type

		@param idAreaType dict area where the enemy can be found
		@param probability float the probability of finding an enemy

		@return dict an enemy or None if no enemy can be found in the
		given area type
		"""
		query = "\
			SELECT\
				name,\
				stat_current_hp,\
				stat_max_hp,\
				stat_attack,\
				stat_defence,\
				stat_speed,\
				stat_luck\
			FROM\
				creature\
				JOIN creature_area_type ON creature.id_creature = creature_area_type.id_creature\
			WHERE\
				creature_area_type.id_area_type = ?\
				AND creature_area_type.probability >= ?\
			ORDER BY RANDOM() LIMIT 1\
		"

		return Model.fetchOneRow(query, [idAreaType, probability])
コード例 #2
0
ファイル: place.py プロジェクト: rrpg/engine
	def getOneFromTypeAndExitId(areaType, idArea):
		"""
		Method to get the informations of a place in a given area
		"""

		query = "\
			SELECT\
				*\
			FROM\
				place AS p\
				JOIN area_type AS at ON p.id_area_type = at.id_area_type\
			WHERE\
				entrance_id = ?\
				AND at.name = ?\
		"

		return Model.fetchOneRow(query, [idArea, areaType])
コード例 #3
0
ファイル: area.py プロジェクト: rrpg/engine
	def getRegionNameFromAreaId(idArea):
		"""
		area.model.getRegionNameFromAreaId(idArea) -> string

		Returns the name of the current area's region.

		@param idArea integer id of the reference area

		@return string name of the region
		"""

		query = "\
			SELECT\
				r.region_name\
			FROM\
				area AS a\
				JOIN region AS r\
			WHERE\
				a.id_area = ?\
		"

		return Model.fetchOneRow(query, [idArea])['region_name']
コード例 #4
0
ファイル: area.py プロジェクト: rrpg/engine
	def getSurroundingAreas(idArea):
		"""
		area.model.getSurroundingAreas(idArea) -> dict()

		Return the available neighbour areas of the area given in argument.

		@param idArea integer id of the reference area

		@return dict a list of directions, with for each direction, True if
			there is an area in this direction, False else.
		"""
		query = "\
			SELECT\
				orig.directions\
			FROM\
				area AS orig\
				JOIN area AS dest ON (dest.x = orig.x - 1 OR dest.x = orig.x + 1 OR dest.x = orig.x)\
					AND (dest.y = orig.y - 1 OR dest.y = orig.y + 1 OR dest.y = orig.y)\
					AND orig.id_area <> dest.id_area\
			WHERE\
				orig.id_area = ?\
		"

		return Model.fetchOneRow(query, [idArea])
コード例 #5
0
ファイル: area.py プロジェクト: rrpg/engine
	def getFromDirection(direction):
		"""
		area.model.getFromDirection(direction) -> dict()

		Returns the neighbour of the area given in arguments from a given
		direction.

		@direction tuple of the area to return, represented by its relative
			values of x and y from idArea ((-1, 0) for example)

		@return dict informations of the found area, empty dict if not found.
		"""

		query = "\
			SELECT\
				%s\
			FROM\
				area\
			WHERE\
				x = ?\
				AND y = ?\
		" % (', '.join(model.fields))

		return Model.fetchOneRow(query, direction)