//------------------------------------------------------------------------------------------------------- /** * @brief 构建玩家属性列表 * @param */ private static void BuildNPCPropList(GameCmd.t_MapNpcDataPos data, ref EntityAttr[] propList, uint master_id = 0) { if (propList.Length < 0 || propList.Length > (int)NPCProp.End - (int)EntityProp.Begin) { Engine.Utility.Log.Error("BuildNPCPropList:属性列表长度非法"); return; } int index = 0; propList[index++] = new EntityAttr((int)EntityProp.BaseID, (int)data.mapnpcdata.npcdata.dwBaseID); // 怪物模板ID 0 propList[index++] = new EntityAttr((int)CreatureProp.Hp, (int)data.mapnpcdata.npcdata.curhp); propList[index++] = new EntityAttr((int)CreatureProp.MaxHp, (int)data.mapnpcdata.npcdata.maxhp); propList[index++] = new EntityAttr((int)CreatureProp.Level, (int)data.mapnpcdata.npcdata.level); propList[index++] = new EntityAttr((int)CreatureProp.Camp, (int)data.mapnpcdata.npcdata.camp); propList[index++] = new EntityAttr((int)WorldObjProp.MoveSpeed, (int)data.mapnpcdata.npcdata.movespeed); propList[index++] = new EntityAttr((int)NPCProp.Job, (int)data.mapnpcdata.npcdata.job); propList[index++] = new EntityAttr((int)NPCProp.Sex, (int)data.mapnpcdata.npcdata.sex); propList[index++] = new EntityAttr((int)NPCProp.ArenaNpcType, (int)data.mapnpcdata.npcdata.arenanpctype); propList[index++] = new EntityAttr((int)NPCProp.Masterid, (int)master_id); propList[index++] = new EntityAttr((int)NPCProp.SuitID, (int)data.mapnpcdata.npcdata.suitid); propList[index++] = new EntityAttr((int)NPCProp.SkillStatus, (int)data.mapnpcdata.npcdata.skill_status); // 技能形态 propList[index++] = new EntityAttr((int)NPCProp.MasterType, (int)data.mapnpcdata.npcdata.master_type); // 技能形态 }
private void CreateRobot(GameCmd.t_MapNpcDataPos npcdata, uint job) { Profiler.BeginSample("CreateRobot"); IEntitySystem es = ClientGlobal.Instance().GetEntitySystem(); if (es == null) { Engine.Utility.Log.Error("严重错误:EntitySystem is null!"); return; } Vector3 pos = new Vector3(npcdata.cur_pos.x * 0.01f, 0, -npcdata.cur_pos.y * 0.01f); // 服务器到客户端坐标转换 npcdata.mapnpcdata.npcdata.job = job; EntityCreateData data = RoleUtil.BuildCreateEntityData(EntityType.EntityTYpe_Robot, npcdata, 0); IRobot robot = es.FindRobot(npcdata.mapnpcdata.npcdata.dwTempID); if (robot != null) { robot.UpdateProp(data); } else { robot = es.CreateEntity(EntityType.EntityTYpe_Robot, data, !m_bDelayLoad) as IRobot; // 发送事件 CreateEntity if (robot != null) { PlayAni anim_param = new PlayAni(); anim_param.strAcionName = EntityAction.Stand; anim_param.fSpeed = 1; anim_param.nStartFrame = 0; anim_param.nLoop = -1; anim_param.fBlendTime = 0.2f; robot.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param); if (!string.IsNullOrEmpty(npcdata.mapnpcdata.npcdata.name) && !Application.isEditor) { robot.SendMessage(EntityMessage.EntityCommond_SetName, npcdata.mapnpcdata.npcdata.name); } else { string strName = string.Format("{0}(AI)", npcdata.mapnpcdata.npcdata.name); robot.SendMessage(EntityMessage.EntityCommond_SetName, npcdata.mapnpcdata.npcdata.name); } } } Engine.Utility.Log.Info("创建机器人 {0} pos {1}", robot.GetID(), pos); robot.SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos); Vector3 rot = GameUtil.S2CDirection(npcdata.mapnpcdata.npcdata.byDirect); robot.SendMessage(EntityMessage.EntityCommand_SetRotate, (object)rot); Profiler.EndSample(); }
//------------------------------------------------------------------------------------------------------- /** * @brief 构建实体创建数据 * @param type 实体类型 * @param data 服务器数据 */ public static EntityCreateData BuildCreateEntityData(EntityType type, GameCmd.t_MapNpcDataPos data, uint master_id) { if (type == EntityType.EntityTYpe_Robot) { t_NpcData npcdata = data.mapnpcdata.npcdata; return(BuildRobotEntityData(npcdata.dwTempID, npcdata.dwBaseID, npcdata.job, npcdata.level, npcdata.name, npcdata.movespeed)); } EntityCreateData entityData = new EntityCreateData(); // 构建EntityCreateData entityData.ID = data.mapnpcdata.npcdata.dwTempID; entityData.strName = data.mapnpcdata.npcdata.name; switch (type) { case EntityType.EntityType_Monster: { entityData.PropList = new EntityAttr[(int)NPCProp.End - (int)EntityProp.Begin]; entityData.ViewList = new EntityViewProp[(int)Client.EquipPos.EquipPos_Max]; BuildNPCPropList(data, ref entityData.PropList); break; } case EntityType.EntityType_NPC: { entityData.PropList = new EntityAttr[(int)NPCProp.End - (int)EntityProp.Begin]; entityData.ViewList = new EntityViewProp[(int)Client.EquipPos.EquipPos_Max]; BuildNPCPropList(data, ref entityData.PropList, master_id); // 根据时装数据决定是否使用外观 BuildNPCViewProp(data, ref entityData.ViewList); break; } } return(entityData); }
private static void BuildNPCViewProp(GameCmd.t_MapNpcDataPos data, ref EntityViewProp[] propList) { if (propList == null) { return; } if (propList.Length < 0 || propList.Length > (int)Client.EquipPos.EquipPos_Max) { Engine.Utility.Log.Error("BuildPlayerPropList:外观列表长度非法"); return; } // 处理时装外观数据 if (data.mapnpcdata.npcdata.arenanpctype == ArenaNpcType.ArenaNpcType_Player || data.mapnpcdata.npcdata.arenanpctype == ArenaNpcType.ArenaNpcType_Npc) { int index = 0; if (data.mapnpcdata.npcdata.sex == 0) { Engine.Utility.Log.Error("BuildPlayerPropList:性别数据{0}非法!", data.mapnpcdata.npcdata.sex); data.mapnpcdata.npcdata.sex = 1; } var table_data = table.SelectRoleDataBase.Where((GameCmd.enumProfession)data.mapnpcdata.npcdata.job, (GameCmd.enmCharSex)data.mapnpcdata.npcdata.sex); if (table_data == null) { Engine.Utility.Log.Error("BuildPlayerPropList:job{0}或者sex{1}数据非法!", data.mapnpcdata.npcdata.job, data.mapnpcdata.npcdata.sex); return; } uint uClothID = table_data.bodyPathID; uint uWeaponID = table_data.weaponPath; propList[index++] = new EntityViewProp((int)Client.EquipPos.EquipPos_Body, (int)uClothID); propList[index++] = new EntityViewProp((int)Client.EquipPos.EquipPos_Weapon, (int)uWeaponID); for (int i = 0; i < data.mapnpcdata.npcdata.suit_data.Count; ++i) { if (data.mapnpcdata.npcdata.suit_data[i] == null) { return; } uint nSultID = 0; int pos = GetPropPos((Client.EquipPos)data.mapnpcdata.npcdata.suit_data[i].suit_type, propList); if (pos >= 0) { if (data.mapnpcdata.npcdata.suit_data[i].suit_type == EquipSuitType.Clothes_Type && data.mapnpcdata.npcdata.suit_data[i].suit_type == 0) { nSultID = uClothID; } else { nSultID = data.mapnpcdata.npcdata.suit_data[i].baseid; } if (data.mapnpcdata.npcdata.suit_data[i].suit_type == EquipSuitType.Qibing_Type && data.mapnpcdata.npcdata.suit_data[i].suit_type == 0) { nSultID = uWeaponID; } else { nSultID = data.mapnpcdata.npcdata.suit_data[i].baseid; } propList[pos] = new EntityViewProp((int)data.mapnpcdata.npcdata.suit_data[i].suit_type, (int)nSultID); } else { Client.EquipPos equipPos = (Client.EquipPos)data.mapnpcdata.npcdata.suit_data[i].suit_type; propList[index++] = new EntityViewProp((int)equipPos, (int)nSultID); } } } else { propList = null; } }
//------------------------------------------------------------------------------------------------ private void CreateNPC(GameCmd.t_MapNpcDataPos npcdata, uint master_id) { Profiler.BeginSample("CreateNPC"); IEntitySystem es = ClientGlobal.Instance().GetEntitySystem(); if (es == null) { Engine.Utility.Log.Error("严重错误:EntitySystem is null!"); return; } //MapVector2 mapPos = MapVector2.FromCoordinate(npcdata.cur_pos.x * 0.01f, npcdata.cur_pos*0.01f); Vector3 pos = new Vector3(npcdata.cur_pos.x * 0.01f, 0, -npcdata.cur_pos.y * 0.01f); // 服务器到客户端坐标转换 EntityCreateData data = RoleUtil.BuildCreateEntityData(EntityType.EntityType_NPC, npcdata, master_id); INPC npc = es.FindNPC(npcdata.mapnpcdata.npcdata.dwTempID); if (npc != null) { npc.UpdateProp(data); NpcAscription.Instance.UpdateBelong(npc, npcdata.mapnpcdata.npcdata.owernuserid, npcdata.mapnpcdata.npcdata.owernteamid, npcdata.mapnpcdata.npcdata.owernclanid, npcdata.mapnpcdata.npcdata.ownername); } else { npc = es.CreateEntity(EntityType.EntityType_NPC, data, !m_bDelayLoad) as INPC; // 发送事件 CreateEntity if (npc != null) { NpcAscription.Instance.UpdateBelong(npc, npcdata.mapnpcdata.npcdata.owernuserid, npcdata.mapnpcdata.npcdata.owernteamid, npcdata.mapnpcdata.npcdata.owernclanid, npcdata.mapnpcdata.npcdata.ownername); table.NpcDataBase npctable = GameTableManager.Instance.GetTableItem <table.NpcDataBase>((uint)npcdata.mapnpcdata.npcdata.dwBaseID); if (npctable != null) { //Debug.LogError("********** npctable.dwID = " + npctable.dwID); if (npcdata.mapnpcdata.npcdata.arenanpctype == ArenaNpcType.ArenaNpcType_Player)//离线的真实玩家名字,用服务器的 { npc.SendMessage(EntityMessage.EntityCommond_SetName, npcdata.mapnpcdata.npcdata.name); } else { if (string.IsNullOrEmpty(npcdata.mapnpcdata.npcdata.name)) { npc.SendMessage(EntityMessage.EntityCommond_SetName, npctable.strName); } } if (npctable.dwType == (uint)GameCmd.enumNpcType.NPC_TYPE_TRANSFER)//传送阵 { EntityOnTrigger callback = new EntityOnTrigger(); npc.SetCallback(callback); } } if (npc != null) { PlayAni anim_param = new PlayAni(); anim_param.strAcionName = EntityAction.Stand; anim_param.fSpeed = 1; anim_param.nStartFrame = 0; anim_param.nLoop = -1; anim_param.fBlendTime = 0.2f; npc.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param); } } } if (npc != null) { npc.SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos); Vector3 rot = GameUtil.S2CDirection(npcdata.mapnpcdata.npcdata.byDirect); npc.SendMessage(EntityMessage.EntityCommand_SetRotate, (object)rot); IBuffPart buffpart = npc.GetPart(EntityPart.Buff) as IBuffPart; if (buffpart != null) { buffpart.ReceiveBuffList(npcdata.mapnpcdata.statelist.data); } } Profiler.EndSample(); }