Exemple #1
0
	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 reqCreateAvatar(self, roleType, name):
        """
		exposed.
		客户端请求创建一个角色
		"""
        avatarinfo = TAvatarInfos()
        avatarinfo.extend([
            0, "", 0, 0,
            TAvatarData().createFromDict({
                "param1": 0,
                "param2": b''
            })
        ])

        props = {
            "name": name,
            "roleType": roleType,
            "level": 1,
            "direction": (0, 0, 0),
            "position": (0, 0, 0)
        }

        avatar = KBEngine.createEntityLocally('Avatar', props)
        if avatar:
            avatar.writeToDB(self._onAvatarSaved)

        DEBUG_MSG("Account[%i].reqCreateAvatar:%s.\n" % (self.id, name))
Exemple #3
0
    def reqCreateAvatar(self, name, raceType):
        """
        客户端请求创建角色
        :param name: 角色名
        :param raceType: 角色种族
        :return:角色spaceUType
        """
        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.max!!!\n" %
                      (self.id, name, self.characters))
            self.client.onCreateAvatarResult(3, avatarInfo)
            return

        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,
            "raceType": raceType,
            "level": 1,
            "spaceUType": spaceUType,
            "direction": (0, 0, 0),
            "position": spaceData.get("spawnPos", (100, 100, 100)),
        }

        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))))
Exemple #4
0
	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(), 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))
			}
			
		avatar = KBEngine.createBaseLocally('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 accountCharacter(self, weaponId):
        infos = self.characters[self.databaseID].asDict()
        DEBUG_MSG("weaponChanged__infos::%s !" % (infos))
        infos["weaponId"] = weaponId

        avatarinfo = TAvatarInfos()
        self.characters[self.databaseID] = avatarinfo.createFromDict(infos)
        DEBUG_MSG("weaponChanged__infos::%s !" % (self.characters))
        pass
Exemple #6
0
    def reqCreateAvatar(self, roleType, name, level):
        """
        exposed.
        客户端请求创建一个角色
        """
        avatarinfo = TAvatarInfos()
        avatarinfo.extend([
            0, "", 0, 0,
            TAvatarData().createFromDict({
                "param1": 0,
                "param2": b''
            })
        ])

        if len(self.characters) >= 3:
            DEBUG_MSG(
                "Account[%i].size = %i,reqCreateAvatar:%s. character=%s.\n" %
                (self.id, len(self.characters), name, self.characters))
            #            self.client.onCreateAvatarResult(3, avatarinfo)
            return

        avatar_datas = d_avatar_inittab.datas.get(roleType, {})
        avatar_level = level
        exp_max = d_avatar_inittab.upgrade_props.get(avatar_level,
                                                     {}).get("exp", 0)

        props = {
            "name": name,
            "roleType": roleType,
            "level": avatar_level,
            "spaceUType": 2,  # 玩家登录进入副本进行匹配
            "direction": (0, 0, avatar_datas["spawnYaw"]),
            "position": (0, 0, 0),
            "HP": avatar_datas["hp"],
            "MP": avatar_datas["mp"],
            "HP_Max": avatar_datas["hp_max"],
            "MP_Max": avatar_datas["mp_max"],
            "EXP_Max": exp_max,
            "uid": roleType,
            "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"], (0, 0, 0)))
Exemple #7
0
	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
		
		""" 根据前端类别给出出生点
		UNKNOWN_CLIENT_COMPONENT_TYPE	= 0,
		CLIENT_TYPE_MOBILE				= 1,	// 手机类
		CLIENT_TYPE_PC					= 2,	// pc, 一般都是exe客户端
		CLIENT_TYPE_BROWSER				= 3,	// web应用, html5,flash
		CLIENT_TYPE_BOTS				= 4,	// bots
		CLIENT_TYPE_MINI				= 5,	// 微型客户端
		"""
		spaceUType = 1
		
		if self.getClientType() == 2:
			spaceUType = 2
		elif self.getClientType() == 5:
			spaceUType = 3
		else:
			spaceUType = 1
		
		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))
			}
			
		avatar = KBEngine.createBaseLocally('Avatar', props)
		if avatar:
			avatar.writeToDB(self._onCharacterSaved)
		
		DEBUG_MSG("Account[%i].reqCreateAvatar:%s. spaceUType=%i, spawnPos=%s.\n" % (self.id, name, avatar.cellData["spaceUType"], spaceData.get("spawnPos", (0,0,0))))
Exemple #8
0
	def _onAvatarSaved(self, success, avatar):
		"""
		新建角色写入数据库回调
		"""
		INFO_MSG('Account::_onAvatarSaved:(%i) create avatar state: %i, %s, %i' % (self.id, success, avatar.cellData["name"], avatar.databaseID))
		
		# 如果此时账号已经销毁, 角色已经无法被记录则我们清除这个角色
		if self.isDestroyed:
			if avatar:
				avatar.destroy(True)
				
			return
			
		avatarinfo = TAvatarInfos()
		avatarinfo.extend([0, "", 0, 0, TAvatarData().createFromDict({"param1" : 0, "param2" :b''})])

		if success:
			info = TAvatarInfos()
			info.extend([avatar.databaseID, avatar.cellData["name"], avatar.roleType, 1, TAvatarData().createFromDict({"param1" : 1, "param2" :b'1'})])
			self.characters[avatar.databaseID] = info
			avatarinfo[0] = avatar.databaseID
			avatarinfo[1] = avatar.cellData["name"]
			avatarinfo[2] = avatar.roleType
			avatarinfo[3] = 1
			self.writeToDB()
		else:
			avatarinfo[1] = "创建失败了"

		avatar.destroy()
		
		if self.client:
			self.client.onCreateAvatarResult(0, avatarinfo)
Exemple #9
0
    def reqAvatarList(self):
        """
		exposed.
		客户端请求查询角色列表
		"""
        info = TAvatarInfos()
        info.extend([
            23422, 'fancy', 1, 1,
            TAvatarData().createFromDict({
                "param1": 1,
                "param2": b'1'
            })
        ])
        self.characters[23422] = info
        DEBUG_MSG("Account[%i].reqAvatarList: size=%i." %
                  (self.id, len(self.characters)))
        self.client.onReqAvatarList(self.characters)
Exemple #10
0
	def _onCharacterSaved(self, success, avatar):
		"""
		新建角色写入数据库回调
		"""
		INFO_MSG('Account::_onCharacterSaved:(%i) create avatar state: %i, %s, %i' % (self.id, success, avatar.cellData["name"], avatar.databaseID))
		
		# 如果此时账号已经销毁, 角色已经无法被记录则我们清除这个角色
		if self.isDestroyed:
			if avatar:
				avatar.destroy(True)
				
			return
			
		avatarinfo = TAvatarInfos()
		avatarinfo.extend([0, "", 0, 0, TAvatarData().createFromDict({"param1" : 0, "param2" :b''})])

		if success:
			info = TAvatarInfos()
			info.extend([avatar.databaseID, avatar.cellData["name"], avatar.roleType, 1, TAvatarData().createFromDict({"param1" : 1, "param2" :b'1'})])
			self.characters[avatar.databaseID] = info
			avatarinfo[0] = avatar.databaseID
			avatarinfo[1] = avatar.cellData["name"]
			avatarinfo[2] = avatar.roleType
			avatarinfo[3] = 1
			self.writeToDB()

			avatar.destroy()
		
		if self.client:
			self.client.onCreateAvatarResult(0, avatarinfo)
    def _onAvatarSaved(self, success, avatar):
        """
		新建角色写入数据库回调
		"""
        INFO_MSG(
            'Account::_onAvatarSaved:(%i) create avatar state: %i, %s, %i' %
            (self.id, success, avatar.cellData["name"], avatar.databaseID))

        # 如果此时账号已经销毁, 角色已经无法被记录则我们清除这个角色
        if self.isDestroyed:
            if avatar:
                avatar.destroy(True)
            return

        avatarinfo = TAvatarInfos()
        avatarinfo.extend([0, "", 0, 0])
        INFO_MSG('_onAvatarSaved::success_(%i)' % success)
        if success:
            info = TAvatarInfos()
            info.extend([
                avatar.databaseID, avatar.cellData["name"],
                avatar.cellData["roleType"], avatar.cellData["weaponID"]
            ])
            self.characters[avatar.databaseID] = info
            avatarinfo[0] = avatar.databaseID
            avatarinfo[1] = avatar.cellData["name"]
            avatarinfo[2] = avatar.cellData["roleType"]
            avatarinfo[3] = avatar.cellData["weaponID"]
            INFO_MSG('create avatar state:%i, %s, %i' %
                     (success, avatar.cellData["name"],
                      avatar.cellData["weaponID"]))
            self.writeToDB()
        else:
            avatarinfo[1] = "创建失败了"

        avatar.destroy()

        if self.client:
            INFO_MSG('Account::onCreateAvatarResult: create avatar state: %i' %
                     (self.id))
            self.client.onCreateAvatarResult(avatarinfo)
        else:
            DEBUG_MSG(
                "Account[%i].client(Fun::Account_onCreateAvatarResult) is None!"
                % (self.id))
Exemple #12
0
    def _onAvatarSaved(self, success, avatar):
        """
        这个可选参数是当数据库操作完成后的回调函数。它有两个参数。第一个是boolean类型标志成功或失败,第二个是base实体
        """
        INFO_MSG(
            'Account::_onAvatarSaved:(%i) create avatar state: %i, %s, %i' %
            (self.id, success, avatar.cellData["name"], avatar.databaseID))

        if self.isDestroyed:
            if avatar:
                avatar.destroy(True)
            return

        avatarinfo = TAvatarInfos()
        avatarinfo.extend([
            0, "", 0, 0,
            TAvatarData().createFromDict({
                "param1": 0,
                "param2": b''
            })
        ])

        if success:
            info = TAvatarInfos()
            info.extend([
                avatar.databaseID, avatar.cellData["name"], avatar.roleType, 1,
                TAvatarData().createFromDict({
                    "param1": 1,
                    "param2": b'1'
                })
            ])
            self.characters[avatar.databaseID] = info
            avatarinfo[0] = avatar.databaseID
            avatarinfo[1] = avatar.cellData["name"]
            avatarinfo[2] = avatar.roleType
            avatarinfo[3] = 1
            self.writeToDB()
        else:
            avatarinfo[1] = "创建失败了"

        avatar.destroy()
Exemple #13
0
	def _onCharacterSaved(self, success, avatar):
		"""
		新建角色写入数据库回调
		"""
		INFO_MSG('Account::_onCharacterSaved:(%i) create avatar state: %i, %s, %i' % (self.id, success, avatar.cellData["name"], avatar.databaseID))
		
		avatarinfo = TAvatarInfos()
		avatarinfo.extend([0, "", 0, 0, TAvatarData().createFromDict({"param1" : 0, "param2" :b''})])

		if success:
			info = TAvatarInfos()
			info.extend([avatar.databaseID, avatar.cellData["name"], avatar.roleType, 1, TAvatarData().createFromDict({"param1" : 1, "param2" :b'1'})])
			self.characters[avatar.databaseID] = info
			avatarinfo[0] = avatar.databaseID
			avatarinfo[1] = avatar.cellData["name"]
			avatarinfo[2] = avatar.roleType
			avatarinfo[3] = 1
			self.writeToDB()

			avatar.destroy()
		
		if not self.isDestroyed and self.client:
			self.client.onCreateAvatarResult(0, avatarinfo)
Exemple #14
0
    def reqCreateAvatar(self, roleType, name):
        """
		exposed.
		客户端请求创建一个角色
		"""
        """
		if name in all_avatar_names:
			retcode = 2
			self.client.onCreateAvatarResult(retcode, avatarinfo)
			return
		"""

        #创建的角色数量满了
        if len(self.characters) >= GlobalConst.MAX_AVATAR_NUM:
            DEBUG_MSG("Account[%i].reqCreateAvatar:%s. character=%s.\n" %
                      (self.id, name, self.characters))
            #在需要的时候创建,而不是一开始就创建
            avatarinfo = TAvatarInfos()
            avatarinfo.extend([
                0, "", 0, 0,
                TAvatarData().createFromDict({
                    "param1": 0,
                    "param2": b''
                })
            ])

            self.client.onCreateAvatarResult(3, avatarinfo)
            return

        # 如果是机器人登陆,随机扔进一个场景
        #todo:重新规划机器人的行为
        """
		if self.getClientType() == 6:
			while True:
				spaceName = random.choice(list(GlobalConst.g_demoMaps.keys()))
				if len(spaceName) > 0:
					spaceUType = GlobalConst.g_demoMaps[spaceName]
					break
		"""
        #根据角色类型来获取出生点(可以配置一样,也可以不一样)
        ERROR_MSG("roleType:%i" % (roleType))
        spaceData = d_newplayermapinfo.datas.get(roleType)
        careerinitData = d_careerinit.datas.get(roleType)
        props = {
            "name": name,
            "roleType": roleType,
            "spaceUType": spaceData["mapID"],
            "direction": spaceData["rotation"],
            "position": spaceData["position"],
            #----------cell---------
            "roleTypeCell": roleType,
            #---------propertys
            "level": 1,
            "exp": 0,
            "equipLvl": 0,
            "money": 0,
            "buyBagNum": 0,
            "buyWarehouseNum": 0,
            "strength": careerinitData['strength'],
            "dexterity": careerinitData['dexterity'],
            "intelligence": careerinitData['intelligence'],
            "stamina": careerinitData['stamina'],
            "HP_Max": careerinitData['HPMax'],
            "HP": careerinitData['HPMax'],
            "MP_Max": careerinitData['MPMax'],
            "MP": careerinitData['MPMax'],
            "damageMin": careerinitData['damageMin'],
            "damageMax": careerinitData['damageMax'],
            "defence": careerinitData['defence'],
            #---------propertys
        }

        avatar = KBEngine.createBaseLocally('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))))