Ejemplo n.º 1
0
        private static void PutEquipInPackage(PackInfo pi)
        {
            var pinfo = ServerData.Instance.playerInfo;

            PackInfo[] packList = new PackInfo[BackPack.MaxBackPackNumber];

            foreach (var p in pinfo.PackInfoList)
            {
                packList [p.PackEntry.Index] = p;
            }

            for (int i = 0; i < BackPack.MaxBackPackNumber; i++)
            {
                if (packList [i] == null)
                {
                    pi.PackEntry.Index = i;
                    pi.PackEntry.Count = 1;
                    pinfo.PackInfoList.Add(pi);

                    var push = GCPushPackInfo.CreateBuilder();
                    push.BackpackAdjust = false;
                    push.PackType       = PackType.DEFAULT_PACK;
                    push.PackInfoList.Add(pi);
                    ServerBundle.SendImmediatePush(push);
                    return;
                }
            }


            SendNotify("背包空间不足");
        }
Ejemplo n.º 2
0
        public void SendPacket(IBuilderLite retpb)
        {
            if (udpClient == null)
            {
                return;
            }
            if (IsClose)
            {
                return;
            }

            //LogHelper.Log("UDP", "SendPacket: "+retpb.ToString());

            ServerBundle bundle;
            var          bytes = ServerBundle.sendImmediateError(retpb, 0, 0, out bundle);

            ServerBundle.ReturnBundle(bundle);

            var mb = new MsgBuffer()
            {
                position = 0, buffer = bytes, bundle = bundle, remoteEnd = remoteEnd
            };

            socketServer.SendUDPPacket(mb);
        }
Ejemplo n.º 3
0
        public static bool ReduceItem(long userPropsId, int num)
        {
            var player = MyLib.ServerData.Instance.playerInfo;

            foreach (var pinfo in player.PackInfoList)
            {
                if (pinfo.PackEntry.Id == userPropsId)
                {
                    if (pinfo.PackEntry.Count < num)
                    {
                        SendNotify("道具数量不足");
                        return(false);
                    }
                    pinfo.PackEntry.Count -= num;
                    if (pinfo.PackEntry.Count <= 0)
                    {
                        player.PackInfoList.Remove(pinfo);
                    }


                    var push = GCPushPackInfo.CreateBuilder();
                    push.BackpackAdjust = false;
                    push.PackType       = PackType.DEFAULT_PACK;
                    push.PackInfoList.Add(pinfo);
                    ServerBundle.SendImmediatePush(push);

                    return(true);
                }
            }
            SendNotify("未找到该道具");
            return(false);
        }
Ejemplo n.º 4
0
        public static void GetProp(KBEngine.Packet g)
        {
            var pinfo   = ServerData.Instance.playerInfo;
            var getChar = g.protoBody as CGGetCharacterInfo;
            var au      = GCGetCharacterInfo.CreateBuilder();

            foreach (var k in getChar.ParamKeyList)
            {
                var att = RolesAttributes.CreateBuilder();
                var bd  = BasicData.CreateBuilder();
                att.AttrKey = k;
                bd.Indicate = 1;
                if (k == (int)CharAttribute.CharAttributeEnum.LEVEL)
                {
                    bd.TheInt32 = pinfo.Roles.Level;
                }
                else if (k == (int)CharAttribute.CharAttributeEnum.EXP)
                {
                    bd.TheInt32 = pinfo.Exp;
                }
                else if (k == (int)CharAttribute.CharAttributeEnum.GOLD_COIN)
                {
                    bd.TheInt32 = pinfo.Gold;
                }
                else if (k == (int)CharAttribute.CharAttributeEnum.JING_SHI)
                {
                    bd.TheInt32 = pinfo.JingShi;
                }
                att.BasicData = bd.Build();
                au.AddAttributes(att);
            }

            ServerBundle.SendImmediate(au, g.flowId);
        }
Ejemplo n.º 5
0
        public static void  SendNotify(string str)
        {
            Log.Sys("SendNotify: " + str);
            var no = GCPushNotify.CreateBuilder();

            no.Notify = str;
            ServerBundle.SendImmediatePush(no);
        }
Ejemplo n.º 6
0
        public static void AddExp(int add)
        {
            var pinfo = ServerData.Instance.playerInfo;

            pinfo.Exp += add;
            var push = GCPushExpChange.CreateBuilder();

            push.Exp = pinfo.Exp;
            ServerBundle.SendImmediatePush(push);
        }
Ejemplo n.º 7
0
        public static void UserDressEquip(KBEngine.Packet packet)
        {
            var inpb  = packet.protoBody as CGUserDressEquip;
            var pinfo = ServerData.Instance.playerInfo;

            PackInfo oldEquip = null;

            if (inpb.DestEquipId != 0)
            {
                foreach (var p in pinfo.DressInfoList)
                {
                    if (p.PackEntry.Id == inpb.DestEquipId)
                    {
                        oldEquip = p;
                        pinfo.DressInfoList.Remove(oldEquip);
                        break;
                    }
                }
            }
            PackInfo newEquip = null;

            if (inpb.SrcEquipId != 0)
            {
                foreach (var p in pinfo.PackInfoList)
                {
                    if (p.PackEntry.Id == inpb.SrcEquipId)
                    {
                        newEquip = p;
                        RemoveEquipFromPackage(inpb.SrcEquipId);
                        break;
                    }
                }
            }

            if (oldEquip != null)
            {
                PutEquipInPackage(oldEquip);
            }
            Log.Net("PutEquipInPackage " + oldEquip.PackEntry.Id);

            var newEquip2 = PackInfo.CreateBuilder(newEquip);

            newEquip2.PackEntry.Count = 1;

            pinfo.DressInfoList.Add(newEquip2.Build());

            var au = GCUserDressEquip.CreateBuilder();

            au.DressEquip = newEquip.PackEntry;
            if (oldEquip != null)
            {
                au.PackEquip = oldEquip.PackEntry;
            }
            ServerBundle.SendImmediate(au, packet.flowId);
        }
Ejemplo n.º 8
0
        public static void SetLevel(int v)
        {
            var pinfo = ServerData.Instance.playerInfo;

            pinfo.Roles.Level = v;

            var push = GCPushLevel.CreateBuilder();

            push.Level = pinfo.Roles.Level;
            ServerBundle.SendImmediatePush(push);
        }
Ejemplo n.º 9
0
        public static void CreateCharacter(KBEngine.Packet packet)
        {
            var inpb = packet.protoBody as CGCreateCharacter;
            var au   = GCCreateCharacter.CreateBuilder();
            var role = RolesInfo.CreateBuilder();

            role.Name     = inpb.PlayerName;
            role.PlayerId = 100;
            //playerId++;
            role.Level = 1;
            role.Job   = inpb.Job;

            var msg = role.Build();

            ServerData.Instance.playerInfo.Roles = RolesInfo.CreateBuilder(msg).Build();

            var dress = new int[]
            {
                97, 68, 69, 70, 71, 72,
            };
            int id    = 1;
            var pinfo = ServerData.Instance.playerInfo;

            foreach (var d in dress)
            {
                var pkinfo  = PackInfo.CreateBuilder();
                var pkEntry = PackEntry.CreateBuilder();
                pkEntry.Id        = id++;
                pkEntry.BaseId    = d;
                pkEntry.GoodsType = 1;
                pkEntry.Level     = 1;
                pkinfo.PackEntry  = pkEntry.Build();
                pinfo.AddDressInfo(pkinfo);
            }

            var cinfo = GCCopyInfo.CreateBuilder();
            var cin   = CopyInfo.CreateBuilder();

            cin.Id     = 209;
            cin.IsPass = true;
            cinfo.AddCopyInfo(cin);
            var msg2 = cinfo.Build();

            pinfo.CopyInfos = msg2;

            au.AddRolesInfos(msg);
            ServerBundle.SendImmediate(au, packet.flowId);

            //投掷 跳跃
            pinfo.Roles.Level = 10;
            AddSkillPoint(10);
            LevelUpSkill(3);
            LevelUpSkill(4);
        }
Ejemplo n.º 10
0
 public static void ReturnBundle(ServerBundle bundle)
 {
     if (bundle == null)
     {
         return;
     }
     lock (serverBundlePool)
     {
         bundle.Reset();
         serverBundlePool.Enqueue(bundle);
     }
 }
Ejemplo n.º 11
0
        public static byte[] sendImmediateError(IBuilderLite build, byte flowId, byte errorCode)
        {
            var data = build.WeakBuild();

            var bundle = new ServerBundle();

            bundle.newMessage(data.GetType());
            bundle.flowId = flowId;
            bundle.writePB(data, errorCode);

            return(bundle.stream.getbuffer());
        }
Ejemplo n.º 12
0
        public static byte[] MakePacket(IBuilderLite build, byte flowId)
        {
            var data = build.WeakBuild();

            var bundle = new ServerBundle();

            bundle.newMessage(data.GetType());
            bundle.flowId = flowId;
            bundle.writePB(data);

            return(bundle.stream.getbuffer());
        }
Ejemplo n.º 13
0
        public void SendPacket(IBuilderLite retpb, uint flowId, int errorCode)
        {
            if (currentCon == null || currentCon.isClose)
            {
                return;
            }
            var bytes = ServerBundle.sendImmediateError(retpb, flowId, errorCode);

            Debug.Log("DemoServer: Send Packet " + flowId);
            lock (currentCon.msgBuffer) {
                currentCon.msgBuffer.Add(bytes);
            }
        }
Ejemplo n.º 14
0
        private void BroadcastToAll(GCPlayerCmd.Builder cmd)  //广播消息
        {
            var          parr = players;
            ServerBundle bundle;
            var          bytes = ServerBundle.sendImmediateError(cmd, 0, 0, out bundle);

            ServerBundle.ReturnBundle(bundle);

            foreach (var p in parr)
            {
                p.GetAgent().SendBytes(bytes);
            }
        }
Ejemplo n.º 15
0
        private void InitPlayerId()          //初始化客户端Player的ID,为每个Actor的专属ID,由ActorManager统一管理
        {
            var cmd = GCPlayerCmd.CreateBuilder();

            cmd.Result = string.Format("Init {0}", Id);

            ServerBundle bundle;
            var          bytes = ServerBundle.sendImmediateError(cmd, 0, 0, out bundle);

            ServerBundle.ReturnBundle(bundle);

            agent.SendBytes(bytes);
        }
Ejemplo n.º 16
0
        public static void AddLevel(int add)
        {
            Log.Net("AddLevel " + add);
            var pinfo = ServerData.Instance.playerInfo;

            pinfo.Roles.Level += add;
            AddSkillPoint(1);

            var push = GCPushLevel.CreateBuilder();

            push.Level = pinfo.Roles.Level;
            ServerBundle.SendImmediatePush(push);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// First Chapter Lev
        /// </summary>
        /// <param name="openLev">Open lev.</param>
        public static void PassLev(int chapter, int openLev)
        {
            var pinfo = ServerData.Instance.playerInfo;

            if (!pinfo.HasCopyInfos)
            {
                var au  = GCCopyInfo.CreateBuilder();
                var cin = CopyInfo.CreateBuilder();
                cin.Id     = 101;
                cin.IsPass = false;
                au.AddCopyInfo(cin);
                var msg = au.Build();
                pinfo.CopyInfos = msg;
            }
            int levId = chapter * 100 + openLev;
            //int levId = -1;
            //int count = -1;
            bool find = false;

            foreach (var c in pinfo.CopyInfos.CopyInfoList)
            {
                if (c.Id == levId)
                {
                    c.IsPass = true;
                    find     = true;
                    break;
                }
            }
            if (!find)
            {
                var cinfo = CopyInfo.CreateBuilder();
                cinfo.Id     = levId;
                cinfo.IsPass = true;
                pinfo.CopyInfos.CopyInfoList.Add(cinfo.Build());
            }
            foreach (var c in pinfo.CopyInfos.CopyInfoList)
            {
                if (c.Id < levId)
                {
                    c.IsPass = true;
                }
            }

            var open = GCPushLevelOpen.CreateBuilder();

            open.Chapter = chapter;
            open.Level   = openLev;
            ServerBundle.SendImmediatePush(open);

            Log.Net("PassLevelData " + pinfo.Build().ToString());
        }
Ejemplo n.º 18
0
        public static void SetGold(int num)
        {
            ServerData.Instance.playerInfo.Gold = num;
            //Notify
            var gc = GoodsCountChange.CreateBuilder();

            gc.Type   = 0;
            gc.BaseId = (int)ItemData.ItemID.GOLD;
            gc.Num    = Mathf.Max(0, num);
            var n = GCPushGoodsCountChange.CreateBuilder();

            n.AddGoodsCountChange(gc);
            ServerBundle.SendImmediatePush(n);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 内部Actor将Agent要发送的消息推送给客户端
        /// SendPacket 应该以SendBuff行驶发送
        /// 同一个Socket的Write Read只能加入一次 epoll
        /// Read在初始化的时候加入
        /// Write在每次要写入的时候加入
        /// </summary>
        public void SendPacket(IBuilderLite retpb, byte flowId, byte errorCode)          //序列化Protobuff后发送数据
        {
            if (isClose)
            {
                return;
            }

            var          proto  = retpb as GCPlayerCmd.Builder;
            var          result = proto.Result;
            ServerBundle bundle;
            var          bytes = ServerBundle.sendImmediateError(retpb, flowId, errorCode, out bundle);

            //Debug.Log ("SendBytes: " + bytes.Length);
            mSendPacketCount     += 1;
            mSendPacketSizeCount += (ulong)bytes.Length;
            LogHelper.LogSendPacket(string.Format("actor={0} result={1} size={2}", id, result, bytes.Length));

            var mb = new MsgBuffer()
            {
                position = 0, buffer = bytes, bundle = bundle
            };
            var send = false;

            lock (msgBuffer)
            {
                msgBuffer.Add(mb);
                if (msgBuffer.Count == 1)                   //当msgBuffer为空并新加入一个消息时,我们才开始发送,不然在OnSend的回调中一直在发送buff,两边同时发送会有问题,
                {
                    send = true;
                }
            }
            if (send)
            {
                try
                {
                    mSocket.BeginSend(mb.buffer, mb.position, mb.Size, SocketFlags.None, OnSend, null);
                }
                catch (Exception exception)
                {
                    Debug.LogError(exception.Message);
                    Close();
                }
            }
        }
Ejemplo n.º 20
0
        public static void LoadPackInfo(KBEngine.Packet packet)
        {
            var inpb = packet.protoBody as CGLoadPackInfo;
            var au   = GCLoadPackInfo.CreateBuilder();

            if (inpb.PackType == PackType.DEFAULT_PACK)
            {
                au.PackType = PackType.DEFAULT_PACK;
                var pkInfo = ServerData.Instance.playerInfo.PackInfoList;
                au.AddRangePackInfo(pkInfo);
            }
            else if (inpb.PackType == PackType.DRESSED_PACK)
            {
                au.PackType = PackType.DRESSED_PACK;
                var pkInfo = ServerData.Instance.playerInfo.DressInfoList;
                au.AddRangePackInfo(pkInfo);
            }
            ServerBundle.SendImmediate(au, packet.flowId);
        }
Ejemplo n.º 21
0
        private static bool RemoveEquipFromPackage(long id)
        {
            var player = MyLib.ServerData.Instance.playerInfo;

            foreach (var pinfo in player.PackInfoList)
            {
                if (pinfo.PackEntry.Id == id)
                {
                    pinfo.PackEntry.Count = 0;
                    player.PackInfoList.Remove(pinfo);

                    var push = GCPushPackInfo.CreateBuilder();
                    push.BackpackAdjust = false;
                    push.PackType       = PackType.DEFAULT_PACK;
                    push.PackInfoList.Add(pinfo);
                    ServerBundle.SendImmediatePush(push);
                    return(true);
                }
            }
            SendNotify("未找到该道具");
            return(false);
        }
Ejemplo n.º 22
0
        public static void AddSkillPoint(int sp)
        {
            var pinfo = ServerData.Instance.playerInfo;

            if (!pinfo.HasSkill)
            {
                pinfo.Skill = GCLoadSkillPanel.CreateBuilder().Build();
            }
            pinfo.Skill.TotalPoint += sp;

            var psp = GCPushSkillPoint.CreateBuilder();

            psp.SkillPoint = pinfo.Skill.TotalPoint;
            ServerBundle.SendImmediatePush(psp);
            if (sp > 0)
            {
                //SendNotify("升级技能点+" + sp);
            }
            else
            {
                //SendNotify("技能点" + sp);
            }
        }
Ejemplo n.º 23
0
        public static void GetKeyValue(KBEngine.Packet packet)
        {
            var  playerInfo = ServerData.Instance.playerInfo;
            var  inpb       = packet.protoBody as CGGetKeyValue;
            var  key        = inpb.Key;
            var  get        = GCGetKeyValue.CreateBuilder();
            bool find       = false;

            foreach (var kv1 in playerInfo.GameStateList)
            {
                if (kv1.Key == key)
                {
                    get.Value = kv1.Value;
                    find      = true;
                    break;
                }
            }
            if (!find)
            {
                get.Value = "";
            }
            ServerBundle.SendImmediate(get, packet.flowId);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 默认前4种技能占用 1 2 3 4 的槽
        /// 当有技能设置了槽 则使用该技能占用 特定槽
        /// </summary>
        static void PushSkillShortcutsInfo()
        {
            var au    = GCPushShortcutsInfo.CreateBuilder();
            var pinfo = ServerData.Instance.playerInfo;

            if (pinfo.HasSkill)
            {
                var defaultSlot = GetShortCutsInfo();
                var ind         = 0;
                foreach (var sk in defaultSlot)
                {
                    if (sk != 0)
                    {
                        var sh = ShortCutInfo.CreateBuilder();
                        sh.Index  = ind;
                        sh.BaseId = sk;
                        au.AddShortCutInfo(sh);
                    }
                    ind++;
                }
            }
            ServerBundle.SendImmediatePush(au);
        }
Ejemplo n.º 25
0
        public static void GetShortCuts(KBEngine.Packet packet)
        {
            var au    = GCLoadShortcutsInfo.CreateBuilder();
            var pinfo = ServerData.Instance.playerInfo;

            if (pinfo.HasSkill)
            {
                var defaultSlot = GetShortCutsInfo();
                int ind         = 0;
                foreach (var sk in defaultSlot)
                {
                    if (sk != 0)
                    {
                        var sh = ShortCutInfo.CreateBuilder();
                        sh.Index  = ind;
                        sh.BaseId = sk;
                        au.AddShortCutInfo(sh);
                    }
                    ind++;
                }
            }
            ServerBundle.SendImmediate(au, packet.flowId);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 背包中增加新获得的武器
        /// 背包改造为无限长度 并且没有限制
        /// </summary>
        public static void AddEquipInPackage(int equipId, int initAttack, int initDefense)
        {
            Log.Sys("AddEquipInpackage " + equipId + " initAttack " + initAttack + " initDef " + initDefense);
            var pinfo    = ServerData.Instance.playerInfo;
            var itemData = Util.GetItemData((int)GoodsTypeEnum.Equip, equipId);

            PackInfo[] packList = new PackInfo[BackPack.MaxBackPackNumber];
            long       maxId    = 0;

            foreach (var p in pinfo.PackInfoList)
            {
                packList [p.PackEntry.Index] = p;
                maxId = (long)Mathf.Max(p.PackEntry.Id + 1, maxId);
            }

            foreach (var p in pinfo.DressInfoList)
            {
                maxId = (long)Mathf.Max(p.PackEntry.Id + 1, maxId);
            }

            if (maxId < 0)
            {
                maxId++;
            }
            for (int i = 0; i < BackPack.MaxBackPackNumber; i++)
            {
                if (packList [i] == null)
                {
                    var pkInfo  = PackInfo.CreateBuilder();
                    var pkentry = PackEntry.CreateBuilder();
                    pkInfo.CdTime = 0;

                    pkentry.Id         = maxId;
                    pkentry.BaseId     = equipId;
                    pkentry.GoodsType  = 1;
                    pkentry.Count      = 1;
                    pkentry.Index      = i;
                    pkentry.Level      = 1;
                    pkentry.RndAttack  = initAttack;
                    pkentry.RndDefense = initDefense;

                    pkInfo.PackEntry = pkentry.Build();
                    var msg = pkInfo.Build();
                    pinfo.PackInfoList.Add(msg);

                    var push = GCPushPackInfo.CreateBuilder();
                    push.BackpackAdjust = false;
                    push.PackType       = PackType.DEFAULT_PACK;
                    push.PackInfoList.Add(msg);
                    ServerBundle.SendImmediatePush(push);

                    SendNotify(string.Format("[ff0a0a]{0}+{1}[-]", itemData.ItemName, 1));
                    return;
                }
            }

            //PackFull
            var notify = GCPushNotify.CreateBuilder();

            notify.Notify = "[f00b00]背包已满[-]";
            ServerBundle.SendImmediatePush(notify);
        }
Ejemplo n.º 27
0
        //Notify
        //Props Stack
        /// <summary>
        /// 得到的道具装备都是白装,自己不断升级,类似怪物猎人
        /// </summary>
        /// <param name="itemId">Item identifier.</param>
        /// <param name="num">Number.</param>
        public static void AddItemInPackage(int itemId, int num)
        {
            var pinfo    = ServerData.Instance.playerInfo;
            var itemData = Util.GetItemData(0, itemId);

            if (itemData.UnitType == ItemData.UnitTypeEnum.GOLD)
            {
                PlayerData.AddGold(num);
                return;
            }

            //Has Such Objects
            if (itemData.MaxStackSize > 1)
            {
                Log.Sys("AddItemInStack");
                foreach (var p in pinfo.PackInfoList)
                {
                    if (p.PackEntry.BaseId == itemId && p.PackEntry.GoodsType == (int)ItemData.GoodsType.Props)
                    {
                        pinfo.PackInfoList.Remove(p);
                        var newPkinfo  = PackInfo.CreateBuilder(p);
                        var newPkEntry = PackEntry.CreateBuilder(p.PackEntry);
                        newPkEntry.Count   += num;
                        newPkinfo.PackEntry = newPkEntry.Build();
                        var msg = newPkinfo.Build();
                        pinfo.PackInfoList.Add(msg);


                        var push = GCPushPackInfo.CreateBuilder();
                        push.BackpackAdjust = false;
                        push.PackType       = PackType.DEFAULT_PACK;
                        push.PackInfoList.Add(msg);

                        ServerBundle.SendImmediatePush(push);

                        SendNotify(string.Format("[ff0a0a]{0}+{1}[-]", itemData.ItemName, num));
                        return;
                    }
                }
            }
            //new Item
            //all Slot
            PackInfo[] packList = new PackInfo[BackPack.MaxBackPackNumber];
            long       maxId    = 0;

            foreach (var p in pinfo.PackInfoList)
            {
                packList [p.PackEntry.Index] = p;
                maxId = (long)Mathf.Max(p.PackEntry.Id + 1, maxId);
            }

            foreach (var p in pinfo.DressInfoList)
            {
                maxId = (long)Mathf.Max(p.PackEntry.Id + 1, maxId);
            }

            if (maxId < 0)
            {
                maxId++;
            }

            for (int i = 0; i < BackPack.MaxBackPackNumber; i++)
            {
                if (packList [i] == null)
                {
                    var pkInfo  = PackInfo.CreateBuilder();
                    var pkentry = PackEntry.CreateBuilder();
                    pkInfo.CdTime = 0;

                    pkentry.Id        = maxId;
                    pkentry.BaseId    = itemId;
                    pkentry.GoodsType = 0;
                    pkentry.Count     = num;
                    pkentry.Index     = i;

                    pkInfo.PackEntry = pkentry.Build();
                    var msg = pkInfo.Build();
                    pinfo.PackInfoList.Add(msg);

                    var push = GCPushPackInfo.CreateBuilder();
                    push.BackpackAdjust = false;
                    push.PackType       = PackType.DEFAULT_PACK;
                    push.PackInfoList.Add(msg);
                    ServerBundle.SendImmediatePush(push);

                    SendNotify(string.Format("[ff0a0a]{0}+{1}[-]", itemData.ItemName, num));
                    return;
                }
            }

            //PackFull
            var notify = GCPushNotify.CreateBuilder();

            notify.Notify = "背包已满";
            ServerBundle.SendImmediatePush(notify);
        }
Ejemplo n.º 28
0
        public static void LevelUpSkill(int skId)
        {
            Debug.Log("LevelUpSkill: " + skId);
            var pinfo      = ServerData.Instance.playerInfo;
            int totalSP    = 0;
            int skillLevel = 0;

            if (pinfo.HasSkill)
            {
                totalSP = pinfo.Skill.TotalPoint;
                foreach (var s in pinfo.Skill.SkillInfosList)
                {
                    if (s.SkillInfoId == skId)
                    {
                        skillLevel = s.Level;
                        break;
                    }
                }
            }
            var skData    = Util.GetSkillData(skId, skillLevel);
            var maxLev    = skData.MaxLevel;
            var playerLev = pinfo.Roles.Level;
            var next      = Util.GetSkillData(skId, skillLevel + 1);
            var needLev   = next.LevelRequired;

            if (totalSP > 0 && skillLevel < maxLev && playerLev >= needLev)
            {
                Log.Sys("LearnSkill");
                AddSkillPoint(-1);

                bool find = false;
                foreach (var sk in pinfo.Skill.SkillInfosList)
                {
                    if (sk.SkillInfoId == skId)
                    {
                        sk.Level++;
                        find = true;
                        break;
                    }
                }
                if (!find)
                {
                    var newinfo = SkillInfo.CreateBuilder();
                    newinfo.SkillInfoId = skId;
                    newinfo.Level       = 1;
                    pinfo.Skill.SkillInfosList.Add(newinfo.Build());
                }

                //pinfo.Skill = newSk.Build();

                var activeSkill = GCPushActivateSkill.CreateBuilder();
                activeSkill.SkillId = skId;
                activeSkill.Level   = skillLevel + 1;
                ServerBundle.SendImmediatePush(activeSkill);
            }
            else if (totalSP <= 0)
            {
                SendNotify("剩余技能点不足");
            }
            else if (playerLev < needLev)
            {
                SendNotify("等级不足");
            }
            else
            {
                SendNotify("技能已经升到满级");
            }
            PushSkillShortcutsInfo();
        }
Ejemplo n.º 29
0
        private void OnSend(IAsyncResult result)
        {
            int num = 0;              //发送的字节数

            try
            {
                num = mSocket.EndSend(result);
            }
            catch (Exception exception)
            {
                num = 0;
                Close();
                Debug.LogError(exception.Message);
                return;
            }

            if (mSocket != null && mSocket.Connected)
            {
                MsgBuffer mb = null;
                lock (msgReader)
                {
                    mb = msgBuffer[0];
                }
                MsgBuffer nextBuffer = null;
                if (mb.Size == num)                  //发送成功
                {
                    lock (msgBuffer)
                    {
                        msgBuffer.RemoveAt(0);
                        if (msgBuffer.Count > 0)
                        {
                            nextBuffer = msgBuffer[0];
                        }
                    }
                    ServerBundle.ReturnBundle(mb.bundle);
                }
                else if (mb.Size > num)                  //发送了一部分,还有一部分没发
                {
                    mb.position += num;
                    nextBuffer   = msgBuffer[0];
                }
                else                  //出错了
                {
                    ServerBundle.ReturnBundle(mb.bundle);
                    lock (msgBuffer)
                    {
                        msgBuffer.RemoveAt(0);
                        if (msgBuffer.Count > 0)
                        {
                            nextBuffer = msgBuffer[0];
                        }
                    }
                }

                if (nextBuffer != null)
                {
                    try
                    {
                        mSocket.BeginSend(nextBuffer.buffer, nextBuffer.position, nextBuffer.Size, SocketFlags.None,
                                          new AsyncCallback(OnSend), null);                 //这里一直同步调用BeginSend和OnSend,直至nextBuffer == null,也就是所有消息全部发送完成,msgBuffer.Count == 0
                    }
                    catch (Exception exception)
                    {
                        Debug.LogError(exception.Message);
                        Close();
                    }
                }
            }
            else
            {
                Close();
            }
        }
Ejemplo n.º 30
0
        public static void LevelUpEquip(KBEngine.Packet packet)
        {
            var      playerInfo = ServerData.Instance.playerInfo;
            var      inpb       = packet.protoBody as CGLevelUpEquip;
            var      eid        = inpb.EquipId;
            var      curLev     = 0;
            PackInfo packInfo   = null;

            foreach (var e in playerInfo.DressInfoList)
            {
                if (e.PackEntry.Id == eid)
                {
                    packInfo = e;
                    break;
                }
            }
            if (packInfo != null)
            {
                curLev = packInfo.PackEntry.Level + 1;
                var levCost = GMDataBaseSystem.SearchIdStatic <EquipLevelData>(GameData.EquipLevel, curLev);
                if (levCost == null)
                {
                    SendNotify("装备已经升到顶级了");
                    return;
                }

                var myGold = playerInfo.Gold;
                if (levCost.gold > myGold)
                {
                    SendNotify("金币不足");
                    return;
                }
                AddGold(-levCost.gold);

                var extraAtt = 0;
                var extraDef = 0;
                foreach (var g in inpb.GemIdList)
                {
                    var pinfo    = GetItemInPack(g);
                    var itemData = Util.GetItemData(0, pinfo.PackEntry.BaseId);
                    extraAtt += itemData.GetRndAtk();
                    extraDef += itemData.GetRndDef();
                    ReduceItem(g, 1);
                }
                var rate = Random.Range(0, 100);
                if (rate < levCost.rate)
                {
                    packInfo.PackEntry.Level++;
                    packInfo.PackEntry.ExtraAttack  += extraAtt;
                    packInfo.PackEntry.ExtraDefense += extraDef;
                    SendNotify("装备升级成功, 本次概率" + rate);

                    var update = GCPushEquipDataUpdate.CreateBuilder();
                    update.PackInfo = packInfo;
                    ServerBundle.SendImmediatePush(update);
                }
                else
                {
                    SendNotify("装备升级失败, 本次概率" + rate + " 需要概率 " + levCost.rate);
                }
            }
        }