Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////
        private Client.IPlayer CreatePlayer(GameCmd.t_MapUserData userData)
        {
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

            if (es == null)
            {
                Engine.Utility.Log.Error("严重错误:EntitySystem is null!");
                return(null);
            }

            EntityCreateData data   = RoleUtil.BuildCreateEntityData(EntityType.EntityType_Player, userData);
            IPlayer          player = es.FindPlayer(userData.userdata.dwUserID);

            if (player != null)
            {
                uint clanIdLow  = (uint)player.GetProp((int)CreatureProp.ClanIdLow);
                uint clanIdHigh = (uint)player.GetProp((int)CreatureProp.ClanIdHigh);
                uint clanid     = (clanIdHigh << 16) | clanIdLow;

                //
                //uint clanid = (uint)player.GetProp((int)CreatureProp.ClanId);


                //玩家死亡 服务器会通过这里刷新 所以这里更新下玩家血条
                if (userData.userdata.curhp <= 0)
                {
                    stPropUpdate prop = new stPropUpdate();
                    prop.uid        = player.GetUID();
                    prop.nPropIndex = (int)CreatureProp.Hp;
                    prop.oldValue   = player.GetProp((int)CreatureProp.Hp);

                    player.UpdateProp(data);

                    prop.newValue = player.GetProp((int)CreatureProp.Hp);

                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_HPUPDATE, prop);
                }
                else
                {
                    stPropUpdate prop = new stPropUpdate();
                    prop.uid        = player.GetUID();
                    prop.nPropIndex = (int)CreatureProp.Hp;
                    prop.oldValue   = player.GetProp((int)CreatureProp.Hp);

                    player.UpdateProp(data);

                    prop.newValue = player.GetProp((int)CreatureProp.Hp);
                    if (prop.oldValue < prop.newValue)
                    {
                        Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_HPUPDATE, prop);
                    }
                }

                if (userData.userdata.clan_id != clanid)
                {
                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.CLANREFRESHID,
                                                                        new Client.stClanUpdate()
                    {
                        uid = player.GetUID(), clanId = userData.userdata.clan_id
                    });
                }
            }
            else
            {
                if (UserData.IsMainRoleID(userData.userdata.dwUserID))
                {
                    data.nLayer      = LayerMask.NameToLayer("MainPlayer");
                    data.bMainPlayer = true; // 设置主角标识
                    player           = es.CreateEntity(EntityType.EntityType_Player, data, true) as IPlayer;
                    if (player == null)
                    {
                        Engine.Utility.Log.Error("CreatePlayer:创建角色失败!");
                        return(null);
                    }
                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.ENTITYSYSTEM_MAINPLAYERCREATE,
                                                                        new Client.stCreateEntity()
                    {
                        uid = userData.userdata.dwUserID
                    });

                    // 设置控制对象
                    Client.IControllerSystem cs = ClientGlobal.Instance().GetControllerSystem();
                    if (cs != null)
                    {
                        cs.GetActiveCtrl().SetHost(player);
                    }

                    // 补丁 服务器没有金钱没有放在角色属性上
                    {
                        player.SetProp((int)PlayerProp.Money, (int)UserData.Money);
                        player.SetProp((int)PlayerProp.Coupon, (int)UserData.Coupon);
                        player.SetProp((int)PlayerProp.Cold, (int)UserData.Cold);
                        player.SetProp((int)PlayerProp.Reputation, (int)UserData.Reputation);
                        player.SetProp((int)PlayerProp.Score, (int)UserData.Score);
                        player.SetProp((int)PlayerProp.CampCoin, (int)UserData.CampCoin);
                        player.SetProp((int)PlayerProp.AchievePoint, (int)UserData.AchievePoint);
                        player.SetProp((int)PlayerProp.ShouLieScore, (int)UserData.ShouLieScore);
                        player.SetProp((int)PlayerProp.FishingMoney, (int)UserData.FishingMoney);
                        player.SetProp((int)PlayerProp.YinLiang, (int)UserData.YinLiang);
                    }

                    // 设置主像机参数
                    SetupMainCamera(player);

                    //玩家成功登陆回调
                    Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.PLAYER_LOGIN_SUCCESS, null);

                    //Client.stCreateEntity createEntity = new Client.stCreateEntity();
                    //createEntity.uid = player.GetUID();
                    //Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.ENTITYSYSTEM_CREATEENTITY, createEntity);
                    //set hp
                    DataManager.Manager <UIPanelManager>().SendMsg(PanelID.MainPanel, UIMsgID.eSetRoleProperty, player);

                    //预加载资源
                    //  PreLoadResource(player.GetProp((int)PlayerProp.Job));
                }
                else
                {
                    //Profiler.BeginSample("CreatePlayer");
                    player = es.CreateEntity(EntityType.EntityType_Player, data, !m_bDelayLoad) as IPlayer;
                    //Profiler.EndSample();
                    Protocol.Instance.RequestName(userData.userdata.dwUserID);
                }

                if (player != 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;
                    player.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param);
                }
            }
            IBuffPart buffpart = player.GetPart(EntityPart.Buff) as IBuffPart;

            if (buffpart != null)
            {
                buffpart.ReceiveBuffList(userData.statelist.data);
            }
            return(player);
        }