Skip to content
Permalink
Browse files

Missions finished

  • Loading branch information...
YogurtTheHorse committed Sep 9, 2016
1 parent 74e9c74 commit a0e2f9ade8b92c1599c44553c075eaad7dcad5ab
@@ -1,6 +1,18 @@
class Mission(object):
def __init__(self, name, path_length=10):
def __init__(self, name, room_name, path_length=10):
super(Mission, self).__init__()
self.name = name
self.room_name = room_name
self.path_length = path_length


def is_ready(self):
return self.path_length <= 0

def room_opened(self):
self.path_length -= 1

def get_room_type(self):
return 'missions/{0}'.format(self.name)

def get_room_name(self):
return self.room_name
@@ -2,21 +2,12 @@

actions = [ 'Помолчать', 'Уйти' ]

next_story_room_range = (20, 30)
next_story_room = 'second'

def get_actions(user):
return actions

def enter(user, reply):
reply('Опасно идти одному! Возьми это.')

user.add_item('story', 'gun')
user.add_item('story', 'map')
user.add_item('neutral', 'bullet')
user.add_item('story', 'glasses')

reply('_Какой-то сверток..\nПосмотрю потом, как выйду отсюда. Этот старик подозрительно молчит_')
user.new_mission('main', 'second', 10)

def action(user, reply, text):
if text == actions[0]:
@@ -2,9 +2,6 @@

actions = [ 'Помолчать', 'Уйти' ]

next_story_room_range = (15, 25)
next_story_room = 'third'

def get_actions(user):
return actions

@@ -14,9 +11,10 @@ def enter(user, reply):

if user.charisma > 10:
reply('В общем-то ты можешь идти дальше')
next_story_room = 'second'
user.new_mission('main', 'third', 15)
else:
reply('Ты какой-то некрасивый. Я тебя не пущу. Ты себя в зеркале видел?')
user.new_mission('main', 'second', 15)

def action(user, reply, text):
if text == actions[0]:
@@ -2,9 +2,6 @@

actions = [ 'Разбить', 'Уйти с миром' ]

next_story_room_range = (100000000000000, 200000000000000)
next_story_room = 'none'

def get_actions(user):
return actions

@@ -18,7 +18,7 @@ def enter(user, reply):
'Очень надеюсь что {} не обратит на нас внимание.'.format(name)
)

if user.story_level < 25:
if user.rooms_count < 500:
reply(
'Кажется он вас не заметил.\n'
'Вот и славненько, пойдем отсюда скорее, не будем мешать'
@@ -10,6 +10,6 @@
def enter(user, reply):
reply('Большой и красный, как в сказке')

if user.story_level < 1:
if user.rooms_count < 50:
reply('Он не заметил тебя и прошел мимо. Мелкий еще.')
user.leave(reply)
@@ -12,7 +12,7 @@
def enter(user, reply):
reply('Весь в доспехах')

if user.story_level < 3:
if user.rooms_count < 100:
reply('Я не бью маленьких девочек типа тебя')
user.leave(reply)

@@ -29,7 +29,7 @@ def action(user, reply, text):
user.fight_action(reply, text)
else:
if text == actions[0]:
if user.story_level < 1:
if user.rooms_count < 25:
reply('Не открывается')
user.leave(reply)
else:
@@ -11,7 +11,7 @@
def enter(user, reply):
reply('Эй, Приятель! Ты случайно историей не ошибся?')

if user.story_level < 5:
if user.rooms_count < 75:
reply('{} обиженно уходит'.format(name))
user.leave(reply)

@@ -10,7 +10,7 @@
def enter(user, reply):
reply('Ты видишь лысого азиата в желтом костюме и красных перчатках')

if user.story_level < 15:
if user.rooms_count < 1000:
reply('Он быстро куда-то убежал, кажется он опаздывает на распродажу')
user.leave(reply)
else:
@@ -32,10 +32,7 @@ def check_room(room, name, room_type):

required = [ 'name', 'get_actions', 'action' ]

if room_type == 'story':
required.append('next_story_room_range')
required.append('next_story_room')
elif room_type == 'monster':
if room_type == 'monster':
required.append('damage_range')

def get_actions(user):
@@ -262,7 +259,12 @@ def make_damage(user, reply, dmg):

return room

def get_next_room():
def get_next_room(user=None):
if user is not None:
if user.get_last_mission().is_ready():
mission = user.pop_mission()
return (mission.get_room_type(), mission.get_room_name())

p = random.random()

if p < 1 / 100:
@@ -20,7 +20,7 @@ def enter(user, reply):
rooms = [ ]

while len(rooms) < 3:
rm = roomloader.get_next_room()
rm = roomloader.get_next_room(user)
if rm[1] != 'empty':
rooms.append(rm)

@@ -11,7 +11,7 @@ def foo(*v, **kw):

class Tests(unittest.TestCase):
def test_rooms(self):
ROOM_TYPES = [ 'usual', 'special', 'boss', 'monster', 'story' ]
ROOM_TYPES = [ 'usual', 'special', 'boss', 'monster', 'missions/main' ]
for t in ROOM_TYPES:
for r in roomloader.get_all_rooms(t):
room = roomloader.load_room(r, t)
@@ -58,10 +58,6 @@ def __init__(self, uid):
self.reborn_answer = None
self.dead = False

self.rooms_to_story = random.randint(5, 25)
self.next_story_room = 'first'
self.story_level = 0

self.last_message = datetime.now()
self.rooms_count = 0
self.monsters_killed = 0
@@ -74,6 +70,8 @@ def __init__(self, uid):
self.variables = dict()
self.missions = SortedList(key=mission_sort_key)

self.new_mission('main', path_len=1)

def message(self, reply, text):
self.last_message = datetime.now()

@@ -99,7 +97,7 @@ def message(self, reply, text):
self.dice(reply, text)
elif self.state.startswith('pet'):
self.on_pet(reply, text)
elif self.state == 'reborned':
elif self.state == 'rebornd':
reply(self.reborn_answer, [ '/start' ])

from user.corridor_defenition import open_corridor, corridor
@@ -120,4 +118,5 @@ def message(self, reply, text):
from user.stats_defenition import get_mana_damage, has_aura, heal, mana, get_stats, add_tag, has_tag, remove_tag
from user.stats_defenition import show_characteristics, set_variable, get_variable
from user.pets_defenition import new_pet, on_pet, get_pet, pet_gone
from user.missions_defenition import new_mission, get_last_mission, pop_mission

@@ -64,7 +64,7 @@ def get_active_items(self):
return self.get_items()

def get_active_slots_len(self):
return 10 + self.story_level * 3 + self.rooms_count // 15
return 10 + self.rooms_count // 15

def has_item(self, code_name):
for i in self.items:
@@ -1,8 +1,19 @@
from missions.mission import Mission
from missions import mission_sort_key

def new_mission(mission_name, path_len=10):
def new_mission(self, mission_name, room_name='first', path_len=10):
for m in self.missions:
if m.mission_name == mission_name:
return

mission = Mission(mission_name, path_len)
mission = Mission(mission_name, room_name, path_len)
self.missions.add(mission)

def get_last_mission(self):
if len(self.missions) > 0:
return self.missions[0]
else:
return Mission('none', 10 ** 9 + 7) # Cool number!

def pop_mission(self):
return self.missions.pop(0)
@@ -43,27 +43,17 @@ def open_room(self, reply, room_type=None, room_name=None):

self.state = 'room'

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

if not (room_type and room_name):
if self.rooms_to_story < 1:
room_type, room_name = 'story', self.next_story_room
else:
room_type, room_name = roomloader.get_next_room()
room_type, room_name = roomloader.get_next_room(self)

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

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

if room_type == 'story':
self.story_level += 1
self.next_story_room = room.next_story_room

mn, mx = room.next_story_room_range
self.rooms_to_story = random.randint(mn, mx)

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

@@ -31,10 +31,6 @@ def save(self):

save['reborn_answer'] = copy.copy(self.reborn_answer)

save['rooms_to_story'] = copy.copy(self.rooms_to_story)
save['next_story_room'] = copy.copy(self.next_story_room)
save['story_level'] = copy.copy(self.story_level)

save['last_message'] = copy.copy(self.last_message)
save['rooms_count'] = copy.copy(self.rooms_count)
save['monsters_killed'] = copy.copy(self.monsters_killed)
@@ -75,10 +71,6 @@ def recover(self, reply):

self.reborn_answer = save['reborn_answer']

self.rooms_to_story = save['rooms_to_story']
self.next_story_room = save['next_story_room']
self.story_level = save['story_level']

self.last_message = save['last_message']
self.rooms_count = save['rooms_count']
self.monsters_killed = save['monsters_killed']

0 comments on commit a0e2f9a

Please sign in to comment.
You can’t perform that action at this time.