2018-10-11 22:48:46 +02:00
|
|
|
# This file is distributed under the terms of the GNU General Public license.
|
|
|
|
|
# Copyright (C) 1999 Aloril (See the file COPYING for details).
|
2001-08-16 17:59:05 +00:00
|
|
|
from atlas import *
|
|
|
|
|
from types import *
|
|
|
|
|
from mind.panlingua import interlinguish
|
2018-10-11 22:48:46 +02:00
|
|
|
|
|
|
|
|
il = interlinguish
|
2001-08-16 17:59:05 +00:00
|
|
|
|
2010-09-12 15:12:54 +01:00
|
|
|
import server
|
|
|
|
|
|
2018-10-11 22:48:46 +02:00
|
|
|
|
2001-08-16 17:59:05 +00:00
|
|
|
class editor:
|
2011-12-01 10:11:00 +00:00
|
|
|
def __init__(self, client, avatar):
|
2018-10-11 22:48:46 +02:00
|
|
|
self.client = client
|
|
|
|
|
self.avatar = avatar
|
|
|
|
|
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()
|
2018-10-11 22:48:46 +02:00
|
|
|
|
2001-08-16 17:59:05 +00:00
|
|
|
def call_list_args(self, *args):
|
2018-10-11 22:48:46 +02:00
|
|
|
# indent='\t'*self.cl_depth
|
2001-08-16 17:59:05 +00:00
|
|
|
for i in range(self.cl_args[1]):
|
2018-10-11 22:48:46 +02:00
|
|
|
if type(args[i]) == list:
|
|
|
|
|
# print indent,"LIST!"
|
|
|
|
|
# print indent,self.cl_args,args
|
|
|
|
|
# self.cl_depth=self.cl_depth+1
|
2001-08-16 17:59:05 +00:00
|
|
|
for a in args[i]:
|
2018-10-11 22:48:46 +02:00
|
|
|
self.call_list_args(*args[:i] + (a,) + args[i + 1:])
|
|
|
|
|
# self.cl_depth=self.cl_depth-1
|
2001-08-16 17:59:05 +00:00
|
|
|
return
|
2018-10-11 22:48:46 +02:00
|
|
|
# print indent,"SINGLE!"
|
|
|
|
|
# print indent,self.cl_args,args
|
2012-07-26 23:28:56 +01:00
|
|
|
self.cl_args[0](self, *args)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
2001-08-16 17:59:05 +00:00
|
|
|
def __getattr__(self, name):
|
2018-05-02 15:27:55 +02:00
|
|
|
if name in self.list_call:
|
2018-10-11 22:48:46 +02:00
|
|
|
self.cl_args = self.list_call[name]
|
|
|
|
|
# self.cl_depth=0
|
2001-08-16 17:59:05 +00:00
|
|
|
return self.call_list_args
|
2018-05-02 15:27:55 +02:00
|
|
|
raise AttributeError(name)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
2011-12-02 01:04:39 +00:00
|
|
|
def create(self, avatar_type):
|
|
|
|
|
return self.client.create_avatar(avatar_type)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
2007-11-27 18:59:33 +00:00
|
|
|
def make(self, type, **kw):
|
2018-10-11 22:48:46 +02:00
|
|
|
kw['type'] = type
|
2007-11-27 18:59:33 +00:00
|
|
|
# if not kw.has_key('type'):
|
2018-10-11 22:48:46 +02:00
|
|
|
# kw['type']=name
|
|
|
|
|
ent = Entity(*(), **kw)
|
|
|
|
|
# ent=Entity(kw)
|
|
|
|
|
## if hasattr(ent,"copy"):
|
|
|
|
|
## foo
|
2010-12-01 10:06:55 +00:00
|
|
|
return self.avatar.make(ent)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
2002-06-14 13:56:58 +00:00
|
|
|
def set(self, _id, **kw):
|
2018-10-11 22:48:46 +02:00
|
|
|
kw['id'] = _id
|
|
|
|
|
ent = Entity(*(), **kw)
|
|
|
|
|
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)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
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):
|
2018-10-11 22:48:46 +02:00
|
|
|
ent = Entity(*(), **kw)
|
2010-12-01 10:06:55 +00:00
|
|
|
return self.avatar.look_for(ent)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
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)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
2016-03-12 13:14:31 +01:00
|
|
|
def sanitizeKnowledge(self, knowledge):
|
2018-10-11 22:48:46 +02:00
|
|
|
if type(knowledge) == object:
|
|
|
|
|
return knowledge.id
|
|
|
|
|
elif type(knowledge) == tuple:
|
|
|
|
|
return repr(knowledge)
|
|
|
|
|
elif type(knowledge) == str:
|
|
|
|
|
return knowledge
|
|
|
|
|
else:
|
|
|
|
|
return knowledge.id
|
|
|
|
|
|
|
|
|
|
def _say(self, target, verb, subject, object, predicate=None):
|
|
|
|
|
## es=Entity(verb=verb,subject=subject,object=object)
|
|
|
|
|
## self.avatar.send(Operation("talk",es,to=target))
|
|
|
|
|
if type(subject) == object:
|
|
|
|
|
subject = subject.id
|
|
|
|
|
elif type(subject) == tuple:
|
|
|
|
|
subject = repr(subject)
|
|
|
|
|
elif type(subject) == str:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
subject = subject.id
|
|
|
|
|
if type(object) == object:
|
|
|
|
|
object = object.id
|
|
|
|
|
elif type(object) == tuple:
|
|
|
|
|
object = repr(object)
|
|
|
|
|
elif type(object) == str:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
object = object.id
|
2004-06-20 19:24:36 +00:00
|
|
|
if predicate:
|
2018-10-11 22:48:46 +02:00
|
|
|
string, interlinguish = il.verb_subject_predicate_object(verb, subject, predicate, object)
|
2004-06-20 19:24:36 +00:00
|
|
|
else:
|
2018-10-11 22:48:46 +02:00
|
|
|
string, interlinguish = il.verb_subject_object(verb, subject, object)
|
|
|
|
|
self._tell(target, string, interlinguish)
|
|
|
|
|
|
|
|
|
|
def _own(self, target, object):
|
|
|
|
|
self._say(target, 'own', target, object)
|
|
|
|
|
|
|
|
|
|
def _know(self, target, know):
|
2016-03-12 13:14:31 +01:00
|
|
|
subject = know[0]
|
2018-10-11 22:48:46 +02:00
|
|
|
|
|
|
|
|
if len(know) == 2:
|
2016-03-12 13:14:31 +01:00
|
|
|
predicate = 'location'
|
|
|
|
|
object = know[1]
|
2004-06-20 19:24:36 +00:00
|
|
|
else:
|
2016-03-12 13:14:31 +01:00
|
|
|
predicate = know[1]
|
|
|
|
|
object = know[2]
|
|
|
|
|
|
2018-10-11 22:48:46 +02:00
|
|
|
es = Entity(subject=self.sanitizeKnowledge(subject), object=self.sanitizeKnowledge(object), predicate=predicate)
|
|
|
|
|
|
|
|
|
|
set = Operation("set")
|
|
|
|
|
set.set_args([es])
|
|
|
|
|
think = Operation("think", to=target)
|
|
|
|
|
think.set_args([set])
|
2016-03-12 13:14:31 +01:00
|
|
|
self.avatar.send(think)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
|
|
|
|
def _learn(self, target, goal):
|
|
|
|
|
es = Entity(id=goal[1], goal=goal[1])
|
|
|
|
|
set = Operation("set")
|
|
|
|
|
set.set_args([es])
|
|
|
|
|
think = Operation("think", to=target)
|
|
|
|
|
think.set_args([set])
|
|
|
|
|
|
2016-03-12 00:15:29 +01:00
|
|
|
self.avatar.send(think)
|
2018-10-11 22:48:46 +02:00
|
|
|
|
|
|
|
|
# Interlinguish
|
|
|
|
|
def _tell(self, target, string, interlinguish):
|
|
|
|
|
es = Entity(say=string)
|
|
|
|
|
self.avatar.send(Operation("talk", es, to=target))
|
|
|
|
|
|
|
|
|
|
def tell_importance(self, target, sub, cmp, obj):
|
|
|
|
|
s, i = il.importance(sub, cmp, obj)
|
|
|
|
|
self.tell(target, s, i)
|
|
|
|
|
|
2001-08-16 17:59:05 +00:00
|
|
|
|
2011-11-30 19:27:11 +00:00
|
|
|
def create_editor(host, account, password, avatar='creator'):
|
2018-10-11 22:48:46 +02: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)
|