Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from evennia.utils import create
- from evennia.utils.create import create_object
- from evennia.utils.evmenu import EvMenu
- class InstanceHandler:
- randomize_room_type = False
- def __init__(self, owner):
- self.owner = owner
- # The instance handler should check for currently owned instances of the same request.
- # If an instance conflict is found, the player is prompted to choose between the old instance and new.
- # Need to generate 3-5 new rooms. Exits never connect back to previous rooms > 1 room prior.
- # Room location will be set to none and typeclass will be Room.
- # A portal will open in the owner's current location, leading to the first room.
- # Another portal is added to the final room that returns to the original location.
- #-------------
- # Instance Options
- # Called by rooms.instance_menu
- def instance_menu(self, instance):
- if instance == 'random':
- self.randomize_room_type = True
- else:
- self.randomize_room_type = False
- if instance == 'forest':
- self.room_type = 'forest'
- elif instance == 'sewer':
- self.room_type = 'sewer'
- elif instance == 'cave':
- self.room_type = 'cave'
- elif instance == 'alley':
- self.room_type = 'alley'
- self._generate_instance()
- #-------------
- # Instance Creation
- def _generate_instance(self):
- # Save the data to the handler.
- self.rooms_list = []
- self.exits_list = []
- self._get_room_qty()
- for _ in range(1, self.room_qty):
- if self.randomize_room_type:
- self._get_room_type()
- self._get_room_key()
- self._get_exit_type()
- self._get_exit_key()
- self.room = create_object(typeclass='rooms.rooms.Room', key=self.room_key)
- self.rooms_list.append(self.room)
- self.rm_exit = create_object(typeclass='rooms.rooms.Room', key=self.exit_key)
- self.exits_list.append(self.rm_exit)
- # Generate the exits for each room by tracking the current room and the previous room.
- #-------------
- # Helpers
- def _get_room_qty(self):
- # Each instance will, for now, contain a possibility of 3-5 rooms.
- self.room_qty = random.randrange(3-5)
- def _get_room_type(self):
- room_types = ['forest', 'sewer', 'cave', 'alley']
- self.room_type = random.choice(room_types)
- def _get_room_key(self):
- room_type = self.room_type
- forest = ['a sacred grove of ancient wood', 'a sparsely-populated fledgling forest', 'a cluster of conifer trees']
- sewer = ['a poorly-maintained sewage tunnel', 'a sewer tunnel constructed of ancient brick', 'a wide walkway along sewage']
- cave = ['an uncertain rock bridge', 'a wide opening between', 'a damp rock shelf']
- alley = ['a dark alleyway', 'a filthy alleyway', 'a narrow alleyway']
- if room_type == 'forest':
- self.room_key = random.choice(forest)
- elif room_type == 'sewer':
- self.room_key = random.choice(sewer)
- elif room_type == 'cave':
- self.room_key = random.choice(cave)
- elif room_type == 'alley':
- self.room_key = random.choice(alley)
- def _get_exit_type(self):
- exit_types = ['stairs', 'door', 'portal']
- self.exit_type = random.choice(exit_types)
- def _get_exit_key(self):
- room_key = self.room_key
- if room_key == 'forest':
- pass
- elif room_key == 'sewer':
- pass
- elif room_key == 'cave':
- pass
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement