Esempio n. 1
0
File: move.py Progetto: rrpg/engine
	def run(self):
		"""
		c.run()

		Move the player in the desired direction.
		"""
		if len(self._args) == 0:
			raise core.command.exception(_('ERROR_MOVE_NO_DIRECTION_GIVEN'))

		direction = self._args[0]
		if direction not in area.area.getDirections():
			raise core.command.exception(_('ERROR_MOVE_INVALID_DIRECTION_%s') % direction)
		curAreaId = self._player.getAreaId()
		curArea = area.model.loadById(curAreaId)

		a = area.area.getNeighbourFromDirection(curAreaId, direction)

		if area.area.canGoTo(curArea['directions'], direction) is False or a is None:
			raise core.command.exception(_('ERROR_MOVE_DIRECTION_NOT_AVAILABLE'))

		ret = {'direction': direction, 'x': a._model['x'], 'y': a._model['y']}
		wasFighting = self._player.isFighting()
		f = fight.getFight()
		if wasFighting:
			enemy = f.enemy

			if not fight.canFlee(self._player._model, enemy):
				raise core.fight.exception(_('ERROR_FLEE_FIGHT_FAILS'))

			fight.stopFight()
			ret['flee'] = True
			ret['enemy'] = enemy['name']

		self._player.goTo(a._model['id_area'])

		# let's be fair, if the player succesfully ran away from a
		# fight, he probably does not want to arrive right away in a
		# new one
		enemy = None
		if not wasFighting:
			probability = randint(0, 1000) / 1000.0
			enemy = creature.creature.getFromAreaType(
				a._model['id_area_type'],
				probability
			)

		if enemy is not None:
			ret['enemy'] = enemy['name']
			f = fight.startFight(self._player, enemy)
			# Deal with enemy attacking first
			damages = f.enemyTriesToAttackFirst(self._player)
			if damages is not None:
				ret['damages'] = damages

		return ret
Esempio n. 2
0
	def run(self):
		"""
		Attack someone in the same area
		"""
		f = fight.getFight()

		if f is None:
			raise core.command.exception(_('ERROR_FIGHT_NOT_FIGHTING'))

		enemy = f.getEnemy()
		attackResult = f.attack()

		return {
			'enemy': enemy,
			'attackResult': attackResult
		}