Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public IBox AddBox(t_MapObjectData BoxData, uint nlefttime)
        {
            if (BoxData == null)
            {
                return(null);
            }
            //Engine.Utility.Log.Info("创建box{0}", BoxData.dwObjectID);
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

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

//            if (es.FindBox(BoxData.qwThisID) == null)
            {
                //AddPetEntity(petdata);
                // 创建box
                //MapVector2 mapPos = MapVector2.FromCoordinate(BoxData.x, BoxData.y);
                Vector3 pos = new Vector3(BoxData.cur_pos.x * 0.01f, 0, -BoxData.cur_pos.y * 0.01f); // 服务器到客户端坐标转换

                EntityCreateData data = RoleUtil.BuildCreateEntityData(EntityType.EntityType_Box, BoxData);
                IBox             box  = es.FindBox(BoxData.qwThisID);
                if (box != null)
                {
                    box.UpdateProp(data);
                }
                else
                {
                    box = es.CreateEntity(EntityType.EntityType_Box, data, true) as IBox;
                }

                box.SendMessage(EntityMessage.EntityCommand_SetPos, (object)pos);
                box.AddTrigger(new BoxOnTrigger());
                return(box);
            }
            return(null);
        }
Exemplo n.º 3
0
        IPet AddPetEntity(PetData petdata)
        {
            IEntitySystem es = ClientGlobal.Instance().GetEntitySystem();

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

            entityData.ID       = petdata.id;
            entityData.PropList = new EntityAttr[(int)PetProp.End - (int)EntityProp.Begin];
            RoleUtil.BuildPetPropListByPetData(petdata, ref entityData.PropList);
            IPet pet = es.CreateEntity(EntityType.EntityType_Pet, entityData) as IPet;

            if (pet != null)
            {
                pet.SetExtraData(petdata);
                return(pet);
            }

            return(null);
        }
Exemplo n.º 4
0
    public bool Create(List <GameCmd.SuitData> lstSuit, int nJob, int nSex, int nSize, GameObject parentObj, SkillSettingState eState = SkillSettingState.StateOne)
    {
        Engine.IRenderSystem rs = Engine.RareEngine.Instance().GetRenderSystem();
        if (rs == null)
        {
            Engine.Utility.Log.Error("获取RenderSystem失败!");
            return(false);
        }

        // 对象创建
        if (m_Root == null)
        {
            m_Root = new GameObject("RTObj");
            if (parentObj != null)
            {
                m_Root.transform.parent = parentObj.transform;
            }
        }

        //
        m_RenderObj = null;

        Client.IEntitySystem es = Client.ClientGlobal.Instance().GetEntitySystem();
        if (es == null)
        {
            return(false);
        }

        Client.EntityCreateData data = new Client.EntityCreateData();
        data.ID      = ++s_uPuppetID;
        data.strName = "";

        //int speed = player.GetProp((int)WorldObjProp.MoveSpeed);
        data.PropList = new EntityAttr[(int)PuppetProp.End - (int)EntityProp.Begin];
        int index = 0;

        data.PropList[index++] = new EntityAttr((int)PuppetProp.Job, nJob);
        data.PropList[index++] = new EntityAttr((int)PuppetProp.Sex, nSex);
        //data.PropList[index++] = new EntityAttr((int)EntityProp.BaseID, 0);
        //data.PropList[index++] = new EntityAttr((int)WorldObjProp.MoveSpeed, speed);
        data.eSkillState = eState;
        data.bViewModel  = true;
        // 处理时装外观数据
        EntityViewProp[] propList = new EntityViewProp[(int)Client.EquipPos.EquipPos_Max];
        index             = 0;
        propList[index++] = new EntityViewProp((int)Client.EquipPos.EquipPos_Body, 0);
        propList[index++] = new EntityViewProp((int)Client.EquipPos.EquipPos_Weapon, 0);

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

                int pos = GetPropPos((Client.EquipPos)lstSuit[i].suit_type, propList);
                if (pos >= 0)
                {
                    propList[pos] = new EntityViewProp((int)lstSuit[i].suit_type, (int)lstSuit[i].baseid);
                }
                else
                {
                    Client.EquipPos equipPos = (Client.EquipPos)lstSuit[i].suit_type;
                    propList[index++] = new EntityViewProp((int)equipPos, (int)lstSuit[i].baseid);
                }
            }
        }

        data.ViewList = propList;
        data.nLayer   = LayerMask.NameToLayer("ShowModel");

        m_PuppetObj = es.CreateEntity(Client.EntityType.EntityType_Puppet, data, true) as Client.IPuppet;
        if (m_PuppetObj == null)
        {
            Engine.Utility.Log.Error("创建Renderobj失败{0}!", "");
            return(false);
        }

        m_RenderObj = m_PuppetObj.renderObj;
        if (m_RenderObj == null)
        {
            return(false);
        }

        // 默认播放站立动作
        m_RenderObj.Play(Client.EntityAction.Stand);
        m_RenderObj.SetLayer((int)Engine.RenderLayer.ShowModel); // showModel

        // CreateCamera
        Camera cam = CreateCamera();

        m_RenderText = new RenderTexture(nSize, nSize, 24, RenderTextureFormat.ARGB32);
        if (m_RenderText == null)
        {
            return(false);
        }
        cam.targetTexture = m_RenderText;

        // 对象挂在父节点上
        if (m_Root != null)
        {
            m_RenderObj.GetNode().GetTransForm().parent = m_Root.transform;
            m_Camera.transform.parent = m_Root.transform;
        }

        return(true);
    }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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);
        }