Exemplo n.º 1
0
def in_room(self, reply, text):
	room = roomloader.load_room(self.room[1], self.room[0], self)
	room.action(self, reply, text)

	if self.state == 'room':
		reply(self.get_stats())
		room = roomloader.load_room(self.room[1], self.room[0], self)
		reply(locale_manager.get('YOUR_ACTIONS'), room.get_actions(self))
Exemplo n.º 2
0
def death(self, reply, reason=None):
	if self.state == 'room':
		room = roomloader.load_room(self.room[1], self.room[0], self)
		room.on_death(self, reply)
		reply(locale_manager.get('DEATH_PLACE').format(room.name))

	self.dead = True
	self.state = ''

	self.update_leaderbord(reason)
	track_stats = {
		'uid': self.uid, 
		'reason': reason, 
		'rooms_count': self.rooms_count,
		'gold': self.gold,
		'kills_count': self.monsters_killed,
		'damage': self.get_damage(),
		'defence': self.get_defence(),
		'charisma': self.get_charisma(),
		'mana_damage': self.get_mana_damage(),
		'live_time': self.get_live_time()
	}
	statistics.track(self.uid, track_stats, 'Death')

	reply(locale_manager.get('DEAD_MESSAGE').format(self.monsters_killed, self.rooms_count), [ '/start' ])

	if 'save' in self.variables:
		self.recover(reply)
Exemplo n.º 3
0
def won(self, reply, tornament=False, boss=None):
	room = roomloader.load_room(self.room[1], self.room[0], self)

	if room.code_name == 'tornament' and tornament:
		reply('Стоп. Это же турнир, тут все работает не так. Ты просто нанес огромный урон противникам. Примерно `100`')
		room.make_damage(self, reply, 100)
		return

	self.monsters_killed += 1
	room.on_won(self, reply)

	items = [ itemloader.load_item(i, 'loot') for i in room.loot ]
	loot = ', '.join([ item.name for item in items ]) if len(items) > 0 else 'Ничего.'

	for lt in room.loot:
		self.add_item('loot', lt)

	if room.room_type == 'boss' and boss is not None:
		total_damage = self.get_room_temp('user_damage', def_val=0)

		if total_damage >= 1:
			room.coins = round(total_damage / boss['max_hp'] * boss['coins'])

		else:
			room.coins = 0

	if room.coins > 0:
		reply(locale_manager.get('GOLD_FOUND').format(room.coins))

		self.give_gold(room.coins)

	reply(locale_manager.get('YOU_WON').format(loot))

	if room.room_type != 'boss':
		self.leave(reply)
Exemplo n.º 4
0
def fight_action(self, reply, text):
	room = roomloader.load_room(self.room[1], self.room[0], self)
	if text == locale_manager.get('KICK_ARM'):
		dmg = self.get_damage() + self.get_damage_bonus(reply)

		reply(locale_manager.get('MONSTER_DAMAGED').format(dmg))

		room.make_damage(self, reply, dmg)
	elif text == locale_manager.get('KICK_MAGIC'):
		dmg = self.get_mana_damage()

		if self.use_mana(5):
			reply(locale_manager.get('MAGIC_KICKED').format(dmg))

			room.make_damage(self, reply, dmg)
		else:
			reply('Маны то не хватает :(')
	elif text.startswith(locale_manager.get('USE')):
		name = 'foo'
		item = None

		if '(' in text:
			name = text[len(locale_manager.get('USE')):]
			name = name[:name.rindex('(')-1]

		for i in self.get_items():
			if i.name == name:
				item = i
				break

		if item:
			dmg = 0
			if item.can_use(self, reply, room):
				item.success(self, reply, room)
				dmg += item.fight_use(self, reply, room)
			else:
				item.failure(self, reply, room)

			if dmg != 0 and item.strengthoff is False:
				dmg += self.get_damage() + self.get_damage_bonus(reply)

			if item.disposable:
				self.remove_item(item.code_name)

			if self.state == 'room':
				reply(locale_manager.get('ITEM_USED').format(name, dmg))

				room.make_damage(self, reply, dmg)
		else:
			reply(locale_manager.get('NO_FIGHT_THING'))

			self.throw_dice(reply, 'noname')
	else:
		reply(locale_manager.get('DIDNT_UNDERSTAND'))

	if self.state == 'room':
		self.fight_answer(reply)
Exemplo n.º 5
0
def open_room(self, reply, room_type=None, room_name=None):
    if self.race == RAT_RACE:
        reply('Ты — крыса, у тебя не хватило сил сдвинуть дверь с места :(')
        self.open_corridor(reply)
        return

    self.state = 'room'

    self.rooms_count += 1
    for m in self.missions:
        m.room_opened()

    if not (room_type and room_name):
        room_type, room_name = roomloader.get_next_room(self)

    logger.info('room_opened ' + room_name)

    last_mission = self.get_last_mission()
    if last_mission.get_room_type(
    ) == room_type and last_mission.get_room_name() == room_name:
        self.pop_mission()

    self.room = (room_type, room_name)
    self.room_temp = {}

    room = roomloader.load_room(self.room[1], self.room[0])

    for i in self.get_items():
        i.on_room(self, reply, room)

    to_delete = []
    for i, b in enumerate(self.buffs):
        try:
            b.on_room(self, reply, room)
            if b.time <= 0:
                to_delete.append(i)
        except:
            pass

    for i in reversed(to_delete):
        self.buffs[i].on_end(self, reply, room)
        del self.buffs[i]

    if self.pet:
        self.get_pet().on_room(self, reply, room)

    if room.room_type == 'monster':
        self.set_room_temp('hp', room.hp)

    reply(locale_manager.get('ROOM_OPENED'))
    reply(room.name + '!')

    room.enter(self, reply)

    if self.state == 'room':
        reply(locale_manager.get('YOUR_ACTIONS'), room.get_actions(self))
Exemplo n.º 6
0
	def test_rooms(self):
		ROOM_TYPES = [ 'usual', 'special', 'boss', 'monster', 'missions/main' ]
		for t in ROOM_TYPES:
			for r in roomloader.get_all_rooms('default', t):
				if r == 'twi_monster':
					continue

				room = roomloader.load_room(r, t)

				self.assertFalse(room is None)
Exemplo n.º 7
0
def fight_dice(self, reply, result, subject=None):
	room = roomloader.load_room(self.room[1], self.room[0], self)
	if subject == 'noname':
		dmg = result + self.get_damage_bonus(reply) // 2

		reply(locale_manager.get('IMAGINATION_FIGHT').format(dmg))

		room.make_damage(self, reply, dmg)
		
		if self.state == 'room':
			self.fight_answer(reply)
			reply(self.get_stats())
Exemplo n.º 8
0
def action(user, reply, text):
	rooms = user.get_room_temp('rooms')
	for room_type, room_name in rooms:
		loaded_room = roomloader.load_room(room_name, room_type, user)
		if loaded_room.name == text or crypt(loaded_room.name) == text:
			if random.random() < 0.1:
				reply('Что-то пошло не так, ты увидел фезку пролетающую у тебя над головой. Ощущения будто был нарушен межпространственный континуум.')
				user.open_room(reply)
			else:
				user.open_room(reply, room_type, room_name)
			return

	reply('Такого выбора тебе не давали.')
Exemplo n.º 9
0
def enter(user, reply):
	rooms = [  ]

	while len(rooms) < 4:
		rm = roomloader.get_next_room(user)
		loaded_room = roomloader.load_room(rm[1], rm[0], user)

		if random.random() < 0.05:
			rm = ('special', 'rick_astley')

		if not loaded_room.not_for_sign:
			rooms.append(rm)

	user.set_room_temp('rooms', list(set(rooms)))
Exemplo n.º 10
0
def get_actions(user):
	all_visited_rooms = user.get_perma_variable('visited_rooms', [ ])

	rooms = user.get_room_temp('rooms')

	actions = [ ]

	for room_type, room_name in rooms:
		loaded_room = roomloader.load_room(room_name, room_type, user)
		name = loaded_room.name
		if room_name not in all_visited_rooms:
			name = crypt(name)
		actions.append([name])

	return actions
Exemplo n.º 11
0
def leave(self, reply):
	self.visited_shop = False
	self.shop_items = [ ]
	self.prayed = False

	room = roomloader.load_room(self.room[1], self.room[0], self)
	if room is not None:
		room.on_leave(self, reply)

	if self.hp < self.max_hp / 2:
		#reply('Ты слегка отдохнул')
		#self.hp = self.max_hp / 2
		pass

	self.open_corridor(reply)
Exemplo n.º 12
0
def dice(self, reply, text):
	if text == locale_manager.get('THOW_DICE'):
		self.state = 'room'

		res = sum(random.randint(1, 8) for n in range(0, DICE_MAX // 8))
		res += self.get_dice_bonus(reply)
		reply(locale_manager.get('DICE_RESULT').format(res))
		
		room = roomloader.load_room(self.room[1], self.room[0], self)
		room.dice(self, reply, res, self.subject)

		if self.state == 'room':
			reply(locale_manager.get('YOUR_ACTIONS'), room.get_actions(self))
	else:
		reply(locale_manager.get('DICE_CONFIDENCE'), [locale_manager.get('THOW_DICE')])
Exemplo n.º 13
0
def fight_answer(self, reply):
	room = roomloader.load_room(self.room[1], self.room[0], self)
	if room.code_name == 'tornament':
		return

	room_type, room_name = self.room
	if room_type == 'boss':
		boss = bossmanager.current()
		user_boss_id = self.get_room_temp('boss_id', def_val=0)

		if boss.get('alive') is False or boss.get('id') is not user_boss_id:
			return

	a, b = room.damage_range
	dmg = self.make_damage(a, b, reply, name=room.name)

	if not self.dead and dmg > 0.2:
		reply(locale_manager.get('USER_DAMAGED').format(dmg))
Exemplo n.º 14
0
def make_damage(self, mn, mx, reply, death=True, defence=True, name=None):
	old_hp = self.hp

	dmg = random.randint(mn, mx)
	if defence:
		defe = self.get_defence()

		# Пока не удаляю, так как надо подумать как это поменять
		# dmg = max(dmg + self.rooms_count // 20 - defe, 1)
		dmg *= 1 - (defe / ( 70 + defe))

	self.hp -= round(dmg)

	if not death:
		self.hp = max(self.hp, 1)
	elif self.hp <= 0:
		if name is None and self.state == 'room':
			room = roomloader.load_room(self.room[1], self.room[0], self)
			name = room.name

		self.death(reply, reason=name)

	return old_hp - self.hp
Exemplo n.º 15
0
def open_room(self, reply, room_type=None, room_name=None):
	if room_name != 'halloween_shop':
		self.set_variable('halloween_visited', False)

	if self.race == RAT_RACE:
		reply('Ты — крыса, у тебя не хватило сил сдвинуть дверь с места :(')
		self.open_corridor(reply)
		return

	self.state = 'room'

	self.rooms_count += 1
	for m in self.missions:
		m.room_opened()

	if not (room_type and room_name):
		room_type, room_name = roomloader.get_next_room(self)

	logger.info('room_opened ' + room_name)

	last_mission = self.get_last_mission()
	if last_mission.get_room_type() == room_type and last_mission.get_room_name() == room_name:
		self.pop_mission()

	self.room = (room_type, room_name)
	self.room_temp = { }

	visited = self.get_perma_variable('visited_rooms', def_val=[])
	if room_name not in visited:
		visited.append(room_name)
	self.set_perma_variable('visited_rooms', visited)
	statistics.track(self.uid, {'uid': self.uid, 'name': room_name, 'type': room_type}, 'Room opened')

	room = roomloader.load_room(self.room[1], self.room[0], self)

	for i in self.get_items():
		i.on_room(self, reply, room)

	to_delete = [ ]
	for i, b in enumerate(self.buffs):
		try:
			b.on_room(self, reply, room)
			if b.time <= 0:
				to_delete.append(i)
		except:
			pass

	for i in reversed(to_delete):
		self.buffs[i].on_end(self, reply, room)
		del self.buffs[i]

	if self.pet:
		self.get_pet().on_room(self, reply, room)

	if room.room_type == 'monster':
		self.set_room_temp('hp', room.hp)

	reply(locale_manager.get('ROOM_OPENED'))
	reply(room.name + '!')

	room.enter(self, reply)

	if self.state == 'room':
		reply(locale_manager.get('YOUR_ACTIONS'), room.get_actions(self))

	if not room.can_open(self, reply):
		room.open_failure(self, reply)

		self.open_corridor(reply)
		return
Exemplo n.º 16
0
def action(user, reply, text):
	if text == 'Посмотреть в шар':
		users = list(usermanager.get_telegram_users())
		random.shuffle(users)

		user_id = None
		found_user = None

		for usr_id in users:
			usr = usermanager.get_user(usr_id)
			if not usr.dead and usr.get_time_from_last_message() < 5 * 60 and usr.uid != user.uid:
				user_id = usr_id
				found_user = usr
				break

		if found_user is None:
			reply('Ничего не видно..')
		else:
			name = found_user.name
			if found_user.pet:
				pet = found_user.get_pet()
				name += ' и {0} {1}'.format(pet.name, pet.real_name)

			res = 'Вижу.. Вижу.. {0}... Ничего не видно..'

			if found_user.dead:
				res = '{0} валяется мертвым на краю мира..'
			elif found_user.state == 'corridor':
				res = '{0} пялится на коридор.'
			elif found_user.state == 'pray':
				res = '{0} молится Богам.'
			elif found_user.state == 'shop':
				res = '{0} затаривается вещичками.'
			elif found_user.state == 'inventory':
				res = '{0} копается в инвентаре.'
			elif found_user.state == 'room':
				res = (
					'{0} находится в комнате..\n\n'
					'И видит..\n'
				)

				room = roomloader.load_room(found_user.room[1], found_user.room[0], found_user)
				room_name = room.name

				res += room_name
			elif found_user.state == 'dice':
				res = (
					'{0} находится в комнате..\n\n'
					'И бросает кости в..\n'
				)

				room = roomloader.load_room(found_user.room[1], found_user.room[0], found_user)
				room_name = room.name

				res += room_name
			elif found_user.state == 'reborned':
				res = '{0} понимает, что «' + str(found_user.reborn_answer) + '»'

			reply(res.format(name))
	else:
		user.leave(reply)