Defining entities
When to define an entity:
需要进行数据存储。能够方便的远程访问。需要引擎管理和监控, 例如: AOI、Trap、等等。当灾难发生后服务端可以自动进行灾难的恢复。
When to define attributes for an entity:
需要进行数据存储。实体被迁移后数据仍然有效(仅cellapp会迁移实体,比如跳转场景)。当灾难发生后服务端可以自动进行灾难的恢复。
When to define a method for an entity:
能够方便的远程访问。
You need to perform the following steps:
Registering entities
Directory Address:demo/scripts/entities.xml
Example:
<root> <Account/> <Avatar/> <Spaces/> <Space/> <Monster/> <NPC/> <Gate/> </root>
demo/scripts/entity_defsCreate a definition file under the directory
Example: Account.def
You may need to define some properties and methods
demo/scripts/There are three subdirectories (base, cell, client) under the directory, and you can add account.py as needed.
Not every entity exists (client, base, cell) These three parts, you can make some choices as needed.
Define the format of the file
<root><properties>//Property Name <accountname>//property type <type>unicode</type>//(optional)// The custom protocol ID of the property, if the client does not use the KBE Companion SDK to develop, the client needs to develop the protocol with KBE docking,//developers can define the ID of the attribute is easy to identify, the C + + protocol layer uses a uint16 to describe, if the ID is not defined the engine will use// The protocol ID generated by the rule itself, which must be scoped to the unique <utype>1000</utype>//attribute in all def files (see below: Attribute scope section) <flags>base</flags >//(optional)//whether to store to database <persistent>true</persistent>//(optional)//maximum length to be stored in the database <DatabaseLength> 100< /databaselength>//(optional, not clear best not set)//default value <default>kbengine</default>//(optional)//database index, support unique and index <index>unique</index></accountname>......</properties><clientmethods>// The remote method name exposed by the client <onreqavatarlist>//the parameters of the remote method <arg>avatar_infos_list</arg><utype>1001</ utype></onreqavatarlist>......</clientmethods><basemethods>//Baseapp Exposed Remote method name < reqavatarlist>//cell exposure method must present this marker <Exposed/> <utype>1002</utype></reqavatarlist> </basemethods>< cellmethods>//Cellapp Exposed Remote method name
Example: Call the base method in the client to get the list of roles (account.py):
self.base.reqAvatarList()
Attribute scope[类型][client][base][cell]BASE-*-BASE_AND_CLIENT**-CELL_PRIVATE--*(cell)CELL_PUBLIC--*(cells)CELL_PUBLIC_AND_OWN*(client)-*(cells)ALL_CLIENTS*(clients)-*(cells)OWN_CLIENT*(client)-*(cell)OTHER_CLIENTS*(other clients)-*(cells)
Kbengine Defining entities