Advertisement
Kovitikus

InstanceHandler Progress

Mar 28th, 2021
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.71 KB | None | 0 0
  1. import random
  2. from evennia.utils import create
  3.  
  4. from evennia.utils.create import create_object
  5. from evennia.utils.evmenu import EvMenu
  6.  
  7.  
  8. class InstanceHandler:
  9.     randomize_room_type = False
  10.  
  11.     def __init__(self, owner):
  12.         self.owner = owner
  13.  
  14.     # The instance handler should check for currently owned instances of the same request.
  15.     # If an instance conflict is found, the player is prompted to choose between the old instance and new.
  16.  
  17.     # Need to generate 3-5 new rooms. Exits never connect back to previous rooms > 1 room prior.
  18.     # Room location will be set to none and typeclass will be Room.
  19.  
  20.     # A portal will open in the owner's current location, leading to the first room.
  21.     # Another portal is added to the final room that returns to the original location.
  22.  
  23. #-------------
  24. # Instance Options
  25.     # Called by rooms.instance_menu
  26.     def instance_menu(self, instance):
  27.         if instance == 'random':
  28.             self.randomize_room_type = True
  29.         else:
  30.             self.randomize_room_type = False
  31.             if instance == 'forest':
  32.                 self.room_type = 'forest'
  33.             elif instance == 'sewer':
  34.                 self.room_type = 'sewer'
  35.             elif instance == 'cave':
  36.                 self.room_type = 'cave'
  37.             elif instance == 'alley':
  38.                 self.room_type = 'alley'
  39.            
  40.         self._generate_instance()
  41.  
  42. #-------------
  43. # Instance Creation
  44.     def _generate_instance(self):
  45.         # Save the data to the handler.
  46.         self.rooms_list = []
  47.         self.exits_list = []
  48.  
  49.         self._get_room_qty()
  50.  
  51.         for _ in range(1, self.room_qty):
  52.             if self.randomize_room_type:
  53.                 self._get_room_type()
  54.             self._get_room_key()
  55.             self._get_exit_type()
  56.             self._get_exit_key()
  57.  
  58.             self.room = create_object(typeclass='rooms.rooms.Room', key=self.room_key)
  59.             self.rooms_list.append(self.room)
  60.  
  61.             self.rm_exit = create_object(typeclass='rooms.rooms.Room', key=self.exit_key)
  62.             self.exits_list.append(self.rm_exit)
  63.        
  64.         # Generate the exits for each room by tracking the current room and the previous room.
  65.  
  66. #-------------
  67. # Helpers
  68.     def _get_room_qty(self):
  69.         # Each instance will, for now, contain a possibility of 3-5 rooms.
  70.         self.room_qty = random.randrange(3-5)
  71.  
  72.     def _get_room_type(self):
  73.         room_types = ['forest', 'sewer', 'cave', 'alley']
  74.         self.room_type = random.choice(room_types)
  75.  
  76.     def _get_room_key(self):
  77.         room_type = self.room_type
  78.         forest = ['a sacred grove of ancient wood', 'a sparsely-populated fledgling forest', 'a cluster of conifer trees']
  79.         sewer = ['a poorly-maintained sewage tunnel', 'a sewer tunnel constructed of ancient brick', 'a wide walkway along sewage']
  80.         cave = ['an uncertain rock bridge', 'a wide opening between', 'a damp rock shelf']
  81.         alley = ['a dark alleyway', 'a filthy alleyway', 'a narrow alleyway']
  82.  
  83.         if room_type == 'forest':
  84.             self.room_key = random.choice(forest)
  85.         elif room_type == 'sewer':
  86.             self.room_key = random.choice(sewer)
  87.         elif room_type == 'cave':
  88.             self.room_key = random.choice(cave)
  89.         elif room_type == 'alley':
  90.             self.room_key = random.choice(alley)
  91.  
  92.     def _get_exit_type(self):
  93.         exit_types = ['stairs', 'door', 'portal']
  94.         self.exit_type = random.choice(exit_types)
  95.  
  96.     def _get_exit_key(self):
  97.         room_key = self.room_key
  98.         if room_key == 'forest':
  99.             pass
  100.         elif room_key == 'sewer':
  101.             pass
  102.         elif room_key == 'cave':
  103.             pass
  104.         pass
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement