On feb 11, 2021
13:23 Griatch wrote:
> The only reason we have #2 for Limbo is because it's needed as a minimum starting
> point when building the database (like #1 will be user #1). I'd suggest using tagging to
> find and identify your 'permanent' room instead.
So I'm trying to learn how to do just that. I've created a room called Euze in my as_initial_setup.py using the following code and tagged with a tag called "euze".
def at_initial_setup():
""" This is the final touches on Setup"""
logger.log_info("Eunoia initial setup: Euze and other objects ...")
room_typeclass = settings.BASE_ROOM_TYPECLASS
euze_obj = create.create_object(room_typeclass, "Euze", nohome=True)
#
limbo_obj.id = 7
euze_obj.tags.add("Euze")
euze_obj.save()
euze_obj.db.desc = "This is the Euze"
euze_obj.save()
Euze is important because it is the default start location and home for a type of character object that players will create in game using a command called "ib" (see below).
class CmdIB(BaseCommand):
# This is here b/c its a character command and can't go
# in the body_commands file with causing trouble
"""
Go into your body, in the Euze and play Eunoia.
Usage:
ib
This command is available to your character in Limbo and adjacent rooms.
If you already have a 'body' in the Euze then your puppet it immediately.
If you do not presently have a live body then one will be created for you.
"""
key = "ib"
def func(self):
from evennia.objects.models import ObjectDB
from typeclasses.euzebody import Body
caller = self.caller
account = self.account
session = self.session
# if you do not have a body, create one
if not caller.db.body:
typeclass = Body
start_location = evennia.search_tag("euze")[0]
# crazy how does this identify a unique room?
# start_location = ObjectDB.objects.get_id("#7") # TODO: make this
# more dynamic, or make it work at least
# This is likely causing me testing problems since testing doesn't
# have the Euze. How do I create that?
# Okay Griatch says to use tags.
default_home = start_location
permissions = "body"
key = "Nebody"
# create the body
new_body = create.create_object(typeclass, key=key,
location=start_location,
home=default_home,
permissions=permissions
)
# only creator can puppet
new_body.tags.add(caller.account.key) # this links the body to the
caller.db.body = new_body
new_body.db.char = caller
# return some sort of message
# caller.msg(f"Created new body: {key} for {
caller.id}")
logger.log_sec(
f"Body created: {key} (Caller: {account},"
f"IP:{self.session.address}"
)
# if you have a body, puppet it.
if caller.db.body:
body = caller.db.body
# self.msg(f"You have a body: #{
body.id}")
# try to puppet it
try:
account.puppet_object(session, caller.db.body)
logger.log_sec(
f"Puppet success: (Caller: {caller}, Body:{body}, "
f"IP: {self.session.address}"
)
body.location.msg(f"Your {body} has arrived in {body.room}")
except RuntimeError as exc:
self.msg("|rThat failed|n {msg}")
self.msg(exc)
logger.log_sec(
f"Puppet failed: (Caller: {caller}, Body:{body}, "
f"IP: {self.session.address}"
)
body.msg(f"you have entered your body {caller.key}")
return
This seems to work:
> ib
You become Nebody.
Euze
This is the Euze
But is this what you intended to advise? Is this the best way to write code around permanent objects in the db? My concern with the tags method is that in a production mud, builders could tag rooms with "euze" and they would be added to the search results of search_tags. At least with dbrefs I know that no one will ever over-write #3.
...