Example #1
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)
Example #2
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))
Example #4
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))))
Example #5
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)))
Example #6
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()
Example #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))))
Example #8
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)
Example #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)
Example #10
0
    def _onAvatarSaved(self, success, avatar):
        """
		New role write database callback
		"""
        INFO_MSG(
            'Account::onAvatarSaved:(%i) Create Avatar Success: %i, Name: %s, DBID: %i'
            % (self.id, success, avatar.cellData["name"], avatar.databaseID))

        # If the account has been destroyed at this time, the role can no longer be recorded, then we clear the role.
        if self.isDestroyed:
            if avatar:
                avatar.destroy(True)

            return

        avatarData = TAvatarData().createFromDict({"param1": 0, "param2": b''})

        avatarinfo = TAvatarInfo()
        avatarinfo.extend([0, "", 0, 0, 0, 0, avatarData])

        INFO_MSG('success: %i, %s %i' %
                 (success, str(bool(success)), int(success)))
        if bool(success) is True or success == 1:
            info = TAvatarInfo()
            info.extend([
                avatar.databaseID, avatar.cellData["name"], avatar.roleType, 1,
                avatar.gender, avatar.hairStyle, avatarData
            ])
            self.avatars[avatar.databaseID] = info
            avatarinfo[0] = avatar.databaseID
            avatarinfo[1] = avatar.cellData["name"]
            avatarinfo[2] = avatar.roleType
            avatarinfo[3] = 1
            avatarinfo[4] = avatar.gender
            avatarinfo[5] = avatar.hairStyle
            avatarData[6] = avatarData

            self.writeToDB()
        else:
            avatarinfo[1] = "Creation Failed"

        avatar.destroy()

        if self.client:
            self.client.onCreateAvatarResult(success, avatarinfo)
Example #11
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))))
Example #12
0
    def reqCreateAvatar(self, name, roleType, gender, hairStyle):
        """
		exposed.
		The client requests to create a role
		"""

        avatarData = TAvatarData().createFromDict({"param1": 0, "param2": b''})
        avatarinfo = TAvatarInfo()
        avatarinfo.extend([0, "", 0, 0, 0, 0, avatarData])
        """
		if name in all_avatar_names:
			retcode = 2
			self.client.onCreateAvatarResult(retcode, avatarinfo)
			return
		"""

        if len(self.avatars) >= 3:
            DEBUG_MSG("Account[%i].reqCreateAvatar:%s. avatars=%s.\n" %
                      (self.id, name, self.avatars))
            self.client.onCreateAvatarResult(3, avatarinfo)
            return
        """ Give a birth point based on the front end category
		UNKNOWN_CLIENT_COMPONENT_TYPE	= 0,
		CLIENT_TYPE_MOBILE				= 1,	// Mobile phone
		CLIENT_TYPE_PC					= 2,	// pc, Generally exe client
		CLIENT_TYPE_BROWSER				= 3,	// Web application, html5,flash
		CLIENT_TYPE_BOTS				= 4,	// bots
		CLIENT_TYPE_MINI				= 5,	// Micro client
		"""
        """
		# If the robot is logged in, randomly throw in a scene
		if self.getClientType() == 6:
			while True:
				spaceName = random.choice(list(GlobalConst.idmo_maps.keys()))
				if len(spaceName) > 0:
					spaceUType = GlobalConst.idmo_maps[spaceName]
					break
		"""

        spaceUType = GlobalConst.idmo_maps.get(self.getClientDatas()[0], 1)
        spaceData = data_spaces.data.get(spaceUType)
        #spaceData.get("spawnPos")

        #"direction"		: (0, 0, data_avatar_initial.data[roleType]["spawnYaw"])

        props = {
            "name":
            name,
            "roleType":
            roleType,
            "gender":
            gender,
            "spaceUType":
            spaceUType,
            "hairStyle":
            hairStyle,
            "direction":
            data_avatar_initial.data[roleType]["spawnDir"],
            "position":
            data_avatar_initial.data[roleType]["spawnPos"],

            # ----------cell---------
            "roleTypeCell":
            roleType,
            # ---------properties
            "level":
            data_avatar_initial.data[roleType]["level"],
            "experience":
            data_avatar_initial.data[roleType]["experience"],
            "currency":
            data_avatar_initial.data[roleType]["currency"],
            "strength":
            data_avatar_initial.data[roleType]["strength"],
            "endurance":
            data_avatar_initial.data[roleType]["endurance"],
            "will":
            data_avatar_initial.data[roleType]["will"],
            "attack_Max":
            data_avatar_initial.data[roleType]["strength"] * 2,
            "attack_Min":
            data_avatar_initial.data[roleType]["strength"] * 1,
            "defence":
            int(data_avatar_initial.data[roleType]["endurance"] / 4),
            "rating":
            int(data_avatar_initial.data[roleType]["endurance"] / 15 + 100),
            "dodge":
            int(data_avatar_initial.data[roleType]["endurance"] / 15 + 100),
            "HP":
            int(data_avatar_initial.data[roleType]["hp"]),
            "HP_Max":
            int(data_avatar_initial.data[roleType]["hpMax"]),
            "EG":
            int(data_avatar_initial.data[roleType]["eg"]),
            "EG_Max":
            int(data_avatar_initial.data[roleType]["egMax"]),
            "abilityPoints":
            data_avatar_initial.data[roleType]["abilityPoints"],
            "abilities":
            data_avatar_initial.data[roleType]["abilities"],
            # ---------properties
        }
        DEBUG_MSG('PROPS', props['HP'], props['HP_Max'], props['EG'],
                  props['EG_Max'])

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

        DEBUG_MSG(
            "Account[%i].reqCreateAvatar:%s, spaceUType=%i, spawnPos=%s.\n spawnDir=%s."
            % (self.id, name, avatar.cellData["spaceUType"],
               data_avatar_initial.data[roleType]["spawnPos"],
               data_avatar_initial.data[roleType]["spawnDir"]))