You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
3.7 KiB
150 lines
3.7 KiB
'''
|
|
Commands and command set related to Mechs
|
|
'''
|
|
|
|
from evennia import Command, CmdSet
|
|
from evennia.utils.utils import list_to_string
|
|
|
|
# TODO: Pullout disconnected characters
|
|
class CmdPilot(Command):
|
|
'''
|
|
Pilot a thing
|
|
|
|
Usage:
|
|
pilot [target]
|
|
'''
|
|
|
|
key = 'pilot'
|
|
aliases = ['enter']
|
|
locks = 'cmd:not cmdinside()'
|
|
|
|
def func(self):
|
|
'''
|
|
Implement the command
|
|
'''
|
|
caller = self.caller
|
|
location = caller.location
|
|
|
|
if not self.args:
|
|
message = "You must give a target"
|
|
caller.msg(message)
|
|
return
|
|
|
|
target = caller.search(self.args.strip())
|
|
if not target:
|
|
return
|
|
|
|
drivers = list(filter(lambda x: x.is_connected, self.obj.contents))
|
|
|
|
if drivers:
|
|
caller.msg(f"This mech is currently piloted by {drivers[0]}, you cannot enter")
|
|
return
|
|
|
|
caller_msg = "You climb into the %s" % target.name
|
|
location_msg = "%s climbs into the %s" % (caller.name, target.name)
|
|
caller.msg(caller_msg)
|
|
location.msg_contents(location_msg, exclude=[caller])
|
|
self.caller.move_to(self.obj, quiet=True)
|
|
|
|
class CmdLeave(Command):
|
|
'''
|
|
Leave a thing
|
|
|
|
Usage:
|
|
leave
|
|
'''
|
|
|
|
key = 'leave'
|
|
aliases = ['exit']
|
|
locks = 'cmd:cmdinside()'
|
|
|
|
def func(self):
|
|
'''
|
|
Implement the command
|
|
'''
|
|
caller = self.caller
|
|
|
|
caller_msg = "You climb out of the %s" % self.obj.name
|
|
location_msg = "%s climbs out of the %s" % (caller.name, self.obj.name)
|
|
caller.msg(caller_msg)
|
|
self.obj.location.msg_contents(location_msg, exclude=[caller, self.obj])
|
|
self.caller.move_to(self.obj.location, quiet=True)
|
|
|
|
class CmdHUD(Command):
|
|
'''
|
|
Look outside the mech
|
|
|
|
Usage:
|
|
hud
|
|
'''
|
|
|
|
key = 'HUD'
|
|
aliases = ['hud']
|
|
locks = 'cmd:cmdinside()'
|
|
|
|
def func(self):
|
|
'Implement the command'
|
|
caller = self.caller
|
|
outside = self.obj.location
|
|
|
|
caller.msg(outside.return_appearance(self.caller, exclude=[self.obj]))
|
|
|
|
class CmdDrive(Command):
|
|
'''
|
|
Drive the mech
|
|
|
|
Usage:
|
|
drive to [location]
|
|
'''
|
|
|
|
key = 'drive'
|
|
locks = 'cmd:cmdinside()'
|
|
|
|
def parse(self):
|
|
if self.args:
|
|
parsed_args = [x for x in self.args.split() if x not in ('to', 'the', 'into')]
|
|
self.args = ' '.join(parsed_args)
|
|
|
|
def func(self):
|
|
'Implement the command'
|
|
if not self.args:
|
|
self.caller.msg('You must provide a location to drive to')
|
|
return
|
|
|
|
search_results = self.obj.search(self.args, quiet=True)
|
|
if not search_results:
|
|
self.caller.msg(f"The mech doesn't understand how to drive to '{self.args}'")
|
|
return
|
|
|
|
if len(search_results) > 1:
|
|
self.caller.msg('More than one result found, please be more specific')
|
|
self.caller.msg(f"Results: {list_to_string(list(search_results))}")
|
|
return
|
|
|
|
result = search_results[0]
|
|
if result == self.caller.location:
|
|
self.caller.msg('You cannot drive into yourself')
|
|
return
|
|
|
|
# Only exits should have a '.destination'
|
|
if not result.destination:
|
|
self.caller.msg(f"You cannot drive into {self.args}")
|
|
return
|
|
|
|
self.caller.msg(f"Driving to {result.destination}")
|
|
self.obj.move_to(result)
|
|
self.caller.execute_cmd('HUD')
|
|
|
|
class CmdSetMech(CmdSet):
|
|
'''
|
|
Commands for mechs
|
|
'''
|
|
|
|
def at_cmdset_creation(self):
|
|
'Attach commands to the command set'
|
|
self.add(CmdDrive())
|
|
self.add(CmdHUD())
|
|
self.add(CmdLeave())
|
|
self.add(CmdPilot())
|
|
|
|
|
|
|