2001-08-16 17:59:05 +00:00
|
|
|
#This file is distributed under the terms of the GNU General Public license.
|
|
|
|
|
#Copyright (C) 1999 Aloril (See the file COPYING for details).
|
|
|
|
|
from atlas import *
|
|
|
|
|
from types import *
|
|
|
|
|
from mind.panlingua import interlinguish
|
|
|
|
|
il=interlinguish
|
|
|
|
|
|
2010-09-12 15:12:54 +01:00
|
|
|
import server
|
|
|
|
|
|
2001-08-16 17:59:05 +00:00
|
|
|
class editor:
|
2011-12-01 10:11:00 +00:00
|
|
|
def __init__(self, client, avatar):
|
|
|
|
|
self.client=client
|
|
|
|
|
self.avatar=avatar
|
2012-07-26 23:28:56 +01:00
|
|
|
self.list_call={"say":(editor._say,1),
|
|
|
|
|
"own":(editor._own,2),
|
|
|
|
|
"know":(editor._know,2),
|
|
|
|
|
"learn":(editor._learn,2),
|
|
|
|
|
"tell":(editor._tell,1)}
|
2012-07-27 09:44:28 +01:00
|
|
|
def __del__(self):
|
|
|
|
|
self.client.teardown()
|
2001-08-16 17:59:05 +00:00
|
|
|
def call_list_args(self, *args):
|
|
|
|
|
#indent='\t'*self.cl_depth
|
|
|
|
|
for i in range(self.cl_args[1]):
|
|
|
|
|
if type(args[i])==ListType:
|
|
|
|
|
#print indent,"LIST!"
|
|
|
|
|
#print indent,self.cl_args,args
|
|
|
|
|
#self.cl_depth=self.cl_depth+1
|
|
|
|
|
for a in args[i]:
|
2012-07-26 23:28:56 +01:00
|
|
|
self.call_list_args(*args[:i]+(a,)+args[i+1:])
|
2001-08-16 17:59:05 +00:00
|
|
|
#self.cl_depth=self.cl_depth-1
|
|
|
|
|
return
|
|
|
|
|
#print indent,"SINGLE!"
|
|
|
|
|
#print indent,self.cl_args,args
|
2012-07-26 23:28:56 +01:00
|
|
|
self.cl_args[0](self, *args)
|
2001-08-16 17:59:05 +00:00
|
|
|
def __getattr__(self, name):
|
|
|
|
|
if self.list_call.has_key(name):
|
|
|
|
|
self.cl_args=self.list_call[name]
|
|
|
|
|
#self.cl_depth=0
|
|
|
|
|
return self.call_list_args
|
|
|
|
|
raise AttributeError,name
|
2011-12-02 01:04:39 +00:00
|
|
|
def create(self, avatar_type):
|
|
|
|
|
return self.client.create_avatar(avatar_type)
|
2007-11-27 18:59:33 +00:00
|
|
|
def make(self, type, **kw):
|
|
|
|
|
kw['type']=type
|
|
|
|
|
# if not kw.has_key('type'):
|
|
|
|
|
# kw['type']=name
|
2001-08-16 17:59:05 +00:00
|
|
|
ent=apply(Entity,(),kw)
|
|
|
|
|
#ent=Entity(kw)
|
|
|
|
|
## if hasattr(ent,"copy"):
|
|
|
|
|
## foo
|
2010-12-01 10:06:55 +00:00
|
|
|
return self.avatar.make(ent)
|
2002-06-14 13:56:58 +00:00
|
|
|
def set(self, _id, **kw):
|
|
|
|
|
kw['id']=_id
|
|
|
|
|
ent=apply(Entity,(),kw)
|
2010-12-01 10:06:55 +00:00
|
|
|
return self.avatar.set(_id,ent)
|
2002-06-14 13:56:58 +00:00
|
|
|
def look(self, _id=""):
|
2010-12-01 10:06:55 +00:00
|
|
|
return self.avatar.look(_id)
|
2002-08-30 Al Riddoch <alriddoch@zepler.org>
* common/globals.cpp: Only persist this sessions command line
options if the user is overriding the installation directory.
* cyphesis.vconf, client/Py_CreatorClient.cpp,
client/Py_CreatorClient.h, client/client.cpp:
Add client functionality to allow diferent scripts to be run to
perform different functions on the server.
* client/CharacterClient.cpp: Add debug option.
* rulesets/Character.h: Make mind operation functions virtual,
so they can be overridden.
* common/BaseWorld.h, server/WorldRouter.cpp,
server/WorldRouter.h: Add server functions to search for
entities by name or type.
* rulesets/Creator.h, rulesets/Creator.cpp: Allow creator to
specify a look without an id to search for entities with
a given name or type.
* client/CreatorClient.cpp, client/CreatorClient.h,
client/ObserverClient.cpp, client/ObserverClient.h,
client/Py_CreatorClient.cpp, rulesets/basic/editor.py,
rulesets/mason/define_world.py:
Add support for looking for entities in the world by name or
type from client script, so client scripts can modify existing
world.
* rulesets/Entity.cpp, rulesets/Movement.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/Thing.cpp,
rulesets/World.cpp, server/Account.cpp,
server/CommServer.cpp, server/Connection.cpp,
server/Player.cpp, server/ServerRouting.cpp,
server/server.cpp, tools/cycmd.cpp,
tools/cywatchdog.cpp: Code formatting cleanups.
* rulesets/basic/world/objects/tools/Bow.py: Fix up bow so it now
fires correctly.
2002-08-30 13:48:39 +00:00
|
|
|
def look_for(self, **kw):
|
|
|
|
|
ent=apply(Entity,(),kw)
|
2010-12-01 10:06:55 +00:00
|
|
|
return self.avatar.look_for(ent)
|
2008-12-15 18:47:48 +00:00
|
|
|
def delete(self, id):
|
2010-12-01 10:06:55 +00:00
|
|
|
return self.avatar.delete(id)
|
2004-06-20 19:24:36 +00:00
|
|
|
def _say(self,target,verb,subject,object,predicate=None):
|
2001-08-16 17:59:05 +00:00
|
|
|
## es=Entity(verb=verb,subject=subject,object=object)
|
2010-12-01 10:06:55 +00:00
|
|
|
## self.avatar.send(Operation("talk",es,to=target))
|
2001-08-16 17:59:05 +00:00
|
|
|
if type(subject)==InstanceType: subject=subject.id
|
|
|
|
|
elif type(subject)==TupleType: subject=`subject`
|
2001-08-19 18:37:38 +00:00
|
|
|
elif type(subject)==StringType: pass
|
|
|
|
|
else: subject=subject.id
|
2001-08-16 17:59:05 +00:00
|
|
|
if type(object)==InstanceType: object=object.id
|
|
|
|
|
elif type(object)==TupleType: object=`object`
|
2001-08-19 18:37:38 +00:00
|
|
|
elif type(object)==StringType: pass
|
|
|
|
|
else: object=object.id
|
2004-06-20 19:24:36 +00:00
|
|
|
if predicate:
|
|
|
|
|
string,interlinguish=il.verb_subject_predicate_object(verb,subject,predicate,object)
|
|
|
|
|
else:
|
|
|
|
|
string,interlinguish=il.verb_subject_object(verb,subject,object)
|
2001-08-16 17:59:05 +00:00
|
|
|
self._tell(target,string,interlinguish)
|
|
|
|
|
def _own(self,target,object):
|
|
|
|
|
self._say(target,'own',target,object)
|
|
|
|
|
def _know(self,target,know):
|
2004-06-20 19:24:36 +00:00
|
|
|
if len(know)==2:
|
|
|
|
|
self._say(target,'know',know[0],know[1],predicate='location')
|
|
|
|
|
else:
|
|
|
|
|
self._say(target,'know',know[0],know[2],predicate=know[1])
|
2001-08-16 17:59:05 +00:00
|
|
|
def _learn(self,target,goal):
|
|
|
|
|
self._say(target,'learn',goal[0],goal[1])
|
|
|
|
|
#Interlinguish
|
|
|
|
|
def _tell(self,target,string,interlinguish):
|
2007-11-28 20:51:43 +00:00
|
|
|
es=Entity(say=string)
|
2010-12-01 10:06:55 +00:00
|
|
|
self.avatar.send(Operation("talk",es,to=target))
|
2001-08-16 17:59:05 +00:00
|
|
|
def tell_importance(self,target,sub,cmp,obj):
|
|
|
|
|
s,i=il.importance(sub,cmp,obj)
|
|
|
|
|
self.tell(target,s,i)
|
|
|
|
|
|
2011-11-30 19:27:11 +00:00
|
|
|
def create_editor(host, account, password, avatar='creator'):
|
2011-12-01 10:11:00 +00:00
|
|
|
client=server.ObserverClient()
|
2010-09-12 15:12:54 +01:00
|
|
|
|
2011-12-01 10:11:00 +00:00
|
|
|
client.server = host
|
2010-09-12 15:12:54 +01:00
|
|
|
|
2011-12-01 10:11:00 +00:00
|
|
|
client.setup(account, password, avatar)
|
2010-09-12 15:12:54 +01:00
|
|
|
|
2011-12-01 10:27:13 +00:00
|
|
|
avatar = client.create_avatar(avatar)
|
2011-12-01 10:11:00 +00:00
|
|
|
|
|
|
|
|
return editor(client, avatar)
|