def getInstance(cls): global globalInstance_ if globalInstance_ is None: globalInstance_ = KBEngine.createEntityLocally(cls.__name__) return globalInstance_
def reqCreateAvatar(self, roleType, name): """ exposed. 客户端请求创建一个角色 """ avatarinfo = TAvatarInfos() avatarinfo.extend([ 0, "", 0, 0, TAvatarData().createFromDict({ "param1": 0, "param2": b'' }) ]) """ if name in all_avatar_names: retcode = 2 self.client.onCreateAvatarResult(retcode, avatarinfo) return """ if len(self.characters) >= 3: DEBUG_MSG("Account[%i].reqCreateAvatar:%s. character=%s.\n" % (self.id, name, self.characters)) self.client.onCreateAvatarResult(3, avatarinfo) return """ 根据前端类别给出出生点 Reference: http://www.kbengine.org/docs/programming/clientsdkprogramming.html, client types UNKNOWN_CLIENT_COMPONENT_TYPE = 0, CLIENT_TYPE_MOBILE = 1, // 手机类 CLIENT_TYPE_WIN = 2, // pc, 一般都是exe客户端 CLIENT_TYPE_LINUX = 3 // Linux Application program CLIENT_TYPE_MAC = 4 // Mac Application program CLIENT_TYPE_BROWSER = 5, // web应用, html5,flash CLIENT_TYPE_BOTS = 6, // bots CLIENT_TYPE_MINI = 7, // 微型客户端 """ spaceUType = GlobalConst.g_demoMaps.get(self.getClientDatas()[0], 1) # 如果是机器人登陆,随机扔进一个场景 if self.getClientType() == 6: while True: spaceName = random.choice(list(GlobalConst.g_demoMaps.keys())) if len(spaceName) > 0: spaceUType = GlobalConst.g_demoMaps[spaceName] break spaceData = d_spaces.datas.get(spaceUType) props = { "name": name, "roleType": roleType, "level": 1, "spaceUType": spaceUType, "direction": (0, 0, d_avatar_inittab.datas[roleType]["spawnYaw"]), "position": spaceData.get("spawnPos", (0, 0, 0)), "component1": { "bb": 1231, "state": 456 }, "component3": { "state": 888 }, } avatar = KBEngine.createEntityLocally('Avatar', props) if avatar: avatar.writeToDB(self._onAvatarSaved) DEBUG_MSG( "Account[%i].reqCreateAvatar:%s. spaceUType=%i, spawnPos=%s.\n" % (self.id, name, avatar.cellData["spaceUType"], spaceData.get("spawnPos", (0, 0, 0))))
def ReqCreateRole(self, RoleType, Name): """ 客户端请求创建一个角色 """ # 先创建空的RoleInfo角色信息类,用来给创建角色失败时作为创建角色回调函数的参数 RoleInfo = TRoleInfo() RoleInfo.extend([ 0, Name, RoleType, TRoleData().createFromDict({ "DataType": 0, "DataValue": b'' }) ]) # 检查是否能够创建角色,依据是是否有同名或者同类型的角色存在 for key, info in self.RoleList.items(): if info[1] is Name: if self.client: self.client.OnCreateRoleResult(1, RoleInfo) return if info[2] is RoleType: if self.client: self.client.OnCreateRoleResult(2, RoleInfo) return #获取场景并且声称角色,将角色写到数据库,数据库写入完成后再告诉客户端创建结果,第一次创建的角色要给初始技能,暂时只做了1个技能,并且先放到主背包 SkillBagProp = {"Value": []} #for Index in range(0,1): # SkillGoodProp = { # "BlockId": Index, # "GoodId": GetGoodIdByTypeKind(EGoodType.Skill.value, Index), # "Number": 1, # } # SkillBagProp["Value"].append(TGoodInfo().createFromDict(SkillGoodProp)) SkillBag = TBagInfo().createFromDict(SkillBagProp) # 这里把所有的物品都创建出来放到主背包作为测试用, 技能除外 # 装备物品 MainBagProp = {"Value": []} for Index in range(0, 3): EquipGoodProp = { "BlockId": Index, "GoodId": GetGoodIdByTypeKind(EGoodType.Equip.value, Index), "Number": 1, } MainBagProp["Value"].append( TGoodInfo().createFromDict(EquipGoodProp)) # buff物品 for Index in range(0, 3): BuffGoodProp = { "BlockId": Index + 3, "GoodId": GetGoodIdByTypeKind(EGoodType.Buff.value, Index), "Number": 20, } MainBagProp["Value"].append( TGoodInfo().createFromDict(BuffGoodProp)) for Index in range(0, 1): SkillGoodProp = { "BlockId": Index + 6, "GoodId": GetGoodIdByTypeKind(EGoodType.Skill.value, Index), "Number": 1, } MainBagProp["Value"].append( TGoodInfo().createFromDict(SkillGoodProp)) MainBag = TBagInfo().createFromDict(MainBagProp) # 创建PtRole Props = { "Name": Name, "RoleType": RoleType, "SkillBag": SkillBag, "MainBag": MainBag } Role = KBEngine.createEntityLocally("PtRole", Props) # 将角色写入数据库,再在回调函数通知客户端是否创建角色成功 if Role: Role.writeToDB(self._OnRoleSaved)
def baseappReady(signal, sender): if sender.groupIndex == 1: KBEngine.createEntityLocally('Equalization', dict())
def _getAsync(): global g_async if g_async is None: g_async = KBEngine.createEntityLocally('AsyncRequest', {}) return g_async
def createBots(self, count, name, data=None): for _ in range(count): account = KBEngine.createEntityLocally( settings_kbengine.dbmgr.account_system.accountEntityScriptType. value, dict(robotBackendName=name, robotBackendData=data)) self.__onCompleteAccount(account)
def EntryFBScene(self): INFO_MSG("client entry fb.") params = { "player" : self } fb = KBEngine.createEntityLocally("NormalFB", params)