Esempio n. 1
0
        public void RPC_OnClientEnterMapOver(RPC.RPCForwardInfo fwd)
        {
            var retPkg = new RPC.PackageWriter();

            retPkg.SetSinglePkg();

            // 通知客户端周围玩家及NPC
            if (!mHostMap.IsNullMap)
            {
                retPkg.Write((sbyte)1);
                mHostMap.OnClientEnterMapOver(this);
                var loc = GetPosition();
                List <RoleActor> roleList = new List <RoleActor>();

                // 先同步NPC(todo: 如果同步压力过大则区分功能NPC和其他NPC进行同步,以便减小同步压力)
                //RPC.DataWriter sceneDW = new RPC.DataWriter();
                UInt32 actorTypes = (1 << (Int32)eActorGameType.Npc);// | (1<<(Int32)CSCommon.Component.EActorGameType.Player);
                mHostMap.TourRoles(ref loc, RPC.RPCNetworkMgr.Sync2ClientRange, actorTypes, this.OnTellClientNPC, roleList);
                Byte npcCount = (Byte)(roleList.Count);
                retPkg.Write(npcCount);
                foreach (NPCInstance npc in roleList)
                {
                    retPkg.Write(npc.NPCData);
                }

                // 同步玩家镜像
                roleList.Clear();
                actorTypes = (1 << (Int32)eActorGameType.PlayerImage);
                mHostMap.TourRoles(ref loc, RPC.RPCNetworkMgr.Sync2ClientRange, actorTypes, this.OnTellClientPlayer, roleList);
                Byte imageCount = (Byte)(roleList.Count);
                retPkg.Write(imageCount);
                foreach (var image in roleList)
                {
                    CSCommon.Data.RoleSyncInfo info = new CSCommon.Data.RoleSyncInfo((PlayerImage)image);
                    retPkg.Write(info);
                }

                // 再同步玩家
                roleList.Clear();
                actorTypes = (1 << (Int32)eActorGameType.Player);
                mHostMap.TourRoles(ref loc, RPC.RPCNetworkMgr.Sync2ClientRange, actorTypes, this.OnTellClientPlayer, roleList);
                Byte playerCount = (Byte)(roleList.Count - 1);//需要去掉自己
                if (playerCount < 0)
                {
                    Log.Log.Server.Error("怎么可能!至少有自己吧!");
                }
                retPkg.Write(playerCount);
                foreach (var player in roleList)
                {
                    if (player.Id == this.Id)
                    {
                        continue;
                    }

                    CSCommon.Data.RoleSyncInfo info = new CSCommon.Data.RoleSyncInfo((PlayerInstance)player);
                    retPkg.Write(info);
                }

                //RPC.DataWriter stateParamDW = new RPC.DataWriter();
                //stateParamDW.Write(this.CurrentState.Parameter, true);
            }
            else
            {
                retPkg.Write((sbyte)0);
            }


            retPkg.DoReturnPlanes2Client(fwd);
        }
Esempio n. 2
0
        // 生成代码
        private void button4_Click(object sender, EventArgs e)
        {
            bool bIsClient = this.textBox_Callee.Text == Config.Instance.CurProjectConfig.ClientCallee;

            if (System.IO.File.Exists(this.textBox_Callee.Text))
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(this.textBox_Callee.Text);
                if (sw != null)
                {
                    if (bIsClient)
                    {
                        sw.Write(this.textBoxCallee.Text.Replace("SlimDX", "UnityEngine"));
                    }
                    else
                    {
                        sw.Write(this.textBoxCallee.Text);
                    }
                    sw.Close();
                }
            }

            if (System.IO.File.Exists(this.textBox_Caller.Text))
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(this.textBox_Caller.Text);
                if (sw != null)
                {
                    if (bIsClient)
                    {
                        sw.Write(this.textBoxCaller.Text.Replace("SlimDX", "UnityEngine"));
                    }
                    else
                    {
                        sw.Write(this.textBoxCaller.Text);
                    }
                    sw.Close();
                }
            }

            if (bIsClient)
            {
                if (System.IO.File.Exists(Config.Instance.CurProjectConfig.ServCppCaller))
                {
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(Config.Instance.CurProjectConfig.ServCppCaller);
                    if (sw != null)
                    {
                        sw.Write(this.textBoxCaller.Text.Replace("UnityEngine", "SlimDX"));
                        sw.Close();
                    }
                }
            }
            else
            {
                if (System.IO.File.Exists(Config.Instance.CurProjectConfig.ClientServCaller))
                {
                    System.IO.StreamWriter sw = new System.IO.StreamWriter(Config.Instance.CurProjectConfig.ClientServCaller);
                    if (sw != null)
                    {
                        sw.Write(ServCallerToClient.Replace("SlimDX", "UnityEngine"));
                        sw.Close();
                    }
                }
            }

            //====================== 客户端同步服务器的类结构 ======================

            string outStruct = "";

            //GetCppStructureDefine只发送基础属性 byte[] x = new byte[3], list<int> y = new list<int>();类似属性都将不发送
            outStruct += new CSCommon.Data.RoleInfo().GetCppStructureDefine();
            outStruct += new CSCommon.Data.NPCData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.RoleDetail().GetCppStructureDefine();
            outStruct += new CSCommon.Data.RoleSyncInfo().GetCppStructureDefine();
            outStruct += new CSCommon.Data.ItemData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.SocialData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.SocialRoleInfo().GetCppStructureDefine();
            outStruct += new CSCommon.Data.GiftData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.TaskData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.MailData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.GuildCom().GetCppStructureDefine();
            outStruct += new CSCommon.Data.RoleCom().GetCppStructureDefine();
            outStruct += new CSCommon.Data.Message().GetCppStructureDefine();
            outStruct += new CSCommon.Data.SkillData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.MartialData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.AchieveData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.AttrStruct().GetCppStructureDefine();
            outStruct += new CSCommon.Data.CityForceData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.EfficiencyData().GetCppStructureDefine();
            outStruct += new CSCommon.Data.CampForceData().GetCppStructureDefine();
            //===================================================================

            if (System.IO.File.Exists(Config.Instance.CurProjectConfig.ClientHeader))
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(Config.Instance.CurProjectConfig.ClientHeader);
                if (sw != null)
                {
                    sw.Write(outStruct);
                    sw.Close();
                }
            }
        }