Пример #1
0
        //------------------------------------------------------------------------------------------------

        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();
        }