Example #1
0
    //-------------------------------------------------------------------------------------------------------

    /**
     * @brief 构建实体创建数据
     * @param type 实体类型
     * @param data 服务器数据
     */
    public static EntityCreateData BuildCreateEntityData(EntityType type, GameCmd.t_MapUserData data)
    {
        EntityCreateData entityData = new EntityCreateData();

        // 构建EntityCreateData
        entityData.ID = data.userdata.dwUserID;

        if (UserData.IsMainRoleID(data.userdata.dwUserID))
        {
            entityData.strName = UserData.CurrentRole.name;
        }
        else
        {
            entityData.strName = "";
        }

        switch (type)
        {
        case EntityType.EntityType_Player:
        {
            entityData.PropList = new EntityAttr[(int)PlayerProp.End - (int)EntityProp.Begin];
            entityData.ViewList = new EntityViewProp[(int)Client.EquipPos.EquipPos_Max];
            BuildPlayerPropList(data, ref entityData.PropList);
            // 根据时装数据决定是否使用外观
            BuildPlayerViewProp(data, ref entityData.ViewList);
            break;
        }
        }

        return(entityData);
    }
Example #2
0
    //-------------------------------------------------------------------------------------------------------
    private static void BuildPlayerViewProp(GameCmd.t_MapUserData 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;
        }

        // 处理时装外观数据
        int index = 0;

        propList[index++] = new EntityViewProp((int)Client.EquipPos.EquipPos_Body, 0);
        propList[index++] = new EntityViewProp((int)Client.EquipPos.EquipPos_Weapon, 0);

        if (data.userdata.equip_suit == null)
        {
            return;
        }

        if (data.userdata.equip_suit.Count > 0)
        {
            for (int i = 0; i < data.userdata.equip_suit.Count; ++i)
            {
                if (data.userdata.equip_suit[i] == null)
                {
                    continue;
                }

                // 忽略萌宠
                if (GameCmd.EquipSuitType.Magic_Pet_Type == data.userdata.equip_suit[i].suit_type)
                {
                    continue;
                }

                int pos = GetPropPos((Client.EquipPos)data.userdata.equip_suit[i].suit_type, propList);
                if (pos >= 0)
                {
                    propList[pos] = new EntityViewProp((int)data.userdata.equip_suit[i].suit_type, (int)data.userdata.equip_suit[i].baseid);
                }
                else
                {
                    Client.EquipPos equipPos = (Client.EquipPos)data.userdata.equip_suit[i].suit_type;
                    propList[index++] = new EntityViewProp((int)equipPos, (int)data.userdata.equip_suit[i].baseid);
                }
            }
        }
    }
Example #3
0
    //-------------------------------------------------------------------------------------------------------

    /**
     * @brief  构建玩家属性列表
     * @param
     */
    private static void BuildPlayerPropList(GameCmd.t_MapUserData data, ref EntityAttr[] propList)
    {
        if (propList.Length < 0 || propList.Length > (int)PlayerProp.End - (int)EntityProp.Begin)
        {
            Engine.Utility.Log.Error("BuildPlayerPropList:属性列表长度非法");
            return;
        }
        int index = 0;

        propList[index++] = new EntityAttr((int)EntityProp.BaseID, 1); // 玩家没有模板ID 0则使用默认数据 需要根据职业和性别来获取 需要读取配置表
        propList[index++] = new EntityAttr((int)CreatureProp.Hp, (int)data.userdata.curhp);
        propList[index++] = new EntityAttr((int)CreatureProp.MaxHp, (int)data.userdata.maxhp);
        propList[index++] = new EntityAttr((int)CreatureProp.Level, (int)data.userdata.level);
        propList[index++] = new EntityAttr((int)WorldObjProp.MoveSpeed, (int)data.userdata.movespeed);
        propList[index++] = new EntityAttr((int)PlayerProp.Job, (int)data.userdata.type);
        propList[index++] = new EntityAttr((int)PlayerProp.Country, (int)1);
        propList[index++] = new EntityAttr((int)CreatureProp.Face, (int)1);
        propList[index++] = new EntityAttr((int)PlayerProp.Sex, (int)FaceToSex(1));
        propList[index++] = new EntityAttr((int)PlayerProp.GoodNess, (int)data.userdata.goodstate);
        propList[index++] = new EntityAttr((int)PlayerProp.RideBaseId, (int)data.userdata.ride_base_id);
        propList[index++] = new EntityAttr((int)PlayerProp.TransModelResId, (int)data.userdata.trans_model_id);
        propList[index++] = new EntityAttr((int)PlayerProp.StateBit, (int)0);
        propList[index++] = new EntityAttr((int)EntityProp.EntityState, (int)0);
        //氏族id
        //propList[index++] = new EntityAttr((int)CreatureProp.ClanId, (int)data.userdata.clan_id);
        propList[index++] = new EntityAttr((int)PlayerProp.TitleId, (int)data.userdata.title_id);   //称号Id
        propList[index++] = new EntityAttr((int)PlayerProp.GodLevel, (int)data.userdata.god_level); //神魔等级
        propList[index++] = new EntityAttr((int)CreatureProp.Camp, (int)data.userdata.camp);
        propList[index++] = new EntityAttr((int)PlayerProp.SkillStatus, (int)(data.userdata.skill_status + 1));

        //氏族ID分为两个存
        uint clanId     = data.userdata.clan_id;
        int  clanIdLow  = (int)(clanId & 0x0000ffff);
        int  clanIdHigh = (int)(clanId >> 16);

        propList[index++] = new EntityAttr((int)CreatureProp.ClanIdLow, clanIdLow);
        propList[index++] = new EntityAttr((int)CreatureProp.ClanIdHigh, clanIdHigh);

        //验证代码

        uint low       = (uint)clanIdLow;
        uint high      = (uint)clanIdHigh;
        uint newhigh   = high << 16;
        uint newClanId = newhigh | low;

        Engine.Utility.Log.Error("--->>> 服务器发的:" + data.userdata.clan_id);
        Engine.Utility.Log.Error("--->>> 客户端存的:" + newClanId);
        Engine.Utility.Log.Error("---客户端存的低位:" + low);
        Engine.Utility.Log.Error("---客户端存的高位:" + newhigh);
    }
Example #4
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);
        }