Mr.MoZa لبيع السورسات المدفوعه جميع الاصدارات
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.


Mr.MoZa لجميع بيع السورسات واي اضافات تخص كونكر مابات + جيرمنتات + موينتات + اكسسوار جميع الحاجات للاستفسار يرجي الاتصال بنا علي رقم 01129854192 By Mr.MoZa
 
الرئيسيةاليوميةأحدث الصورس .و .جبحـثالأعضاءالمجموعاتالتسجيلدخول

 

 اضافة Golden Tree

اذهب الى الأسفل 
كاتب الموضوعرسالة
Mr.MoOoZa




المساهمات : 28
تاريخ التسجيل : 20/03/2022

اضافة Golden Tree Empty
مُساهمةموضوع: اضافة Golden Tree   اضافة Golden Tree Emptyالأحد مارس 20, 2022 1:03 am

السلام عليكم ورحمة الله وبركاته

اضافة Golden tree

والي مش عارفه

ده حدث كان في كونكر 2d وده الاضافات

قبل ما نبداء حقوق الاضافه

Copyright Zahran Joe Lotfy



اول كده اعمل كلاس جديد باسم
MsgGlobalLottery

وحط دول فيه


كود:

الكود:
using ProtoBuf;
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Concurrent;
using System.Text;
using LordsRoad;
using LordsRoad.Database;
using System.Threading.Tasks;

namespace LordsRoad.Network.GamePackets
{
    public class MsgGlobalLottery
    {
        public MsgGlobalLottery() { }
        public MsgGlobalLotteryProtoBlossom Info;
        [ProtoContract]
        public class MsgGlobalLotteryProtoBlossom
        {
            [ProtoMember(1, IsRequired = true)]
            public uint Type;
            [ProtoMember(2, IsRequired = true)]
            public uint PrizesType;
            [ProtoMember(3, IsRequired = true)]
            ///0 = Not Opened, 1 = Ready, 2 = Opened, 3 = Ranking
            public uint GUI;
            [ProtoMember(4, IsRequired = true)]
            public uint Time;
            [ProtoMember(5, IsRequired = true)]
            public uint Remain;
            [ProtoMember(6, IsRequired = true)]
            public uint TotalCount;
        }
        [ProtoContract]
        public class MsgGlobalLotteryProtoPick
        {
            [ProtoMember(1, IsRequired = true)]
            public uint Type;
            [ProtoMember(2, IsRequired = true)]
            public uint UID;
            [ProtoMember(3, IsRequired = true)]
            public uint GUI;
            [ProtoMember(4, IsRequired = true)]
            public uint PickItemID;
            [ProtoMember(5, IsRequired = true)]
            public string Name;
            [ProtoMember(6, IsRequired = true)]
            public uint Remain;
            [ProtoMember(7, IsRequired = true)]
            public uint TotalCount;
        }
        public bool Read(byte[] packet)
        {
            using (var memoryStream = new MemoryStream(packet))
            {
                Info = Serializer.DeserializeWithLengthPrefix<MsgGlobalLotteryProtoBlossom>(memoryStream, PrefixStyle.Fixed32);
            }
            return true;
        }
        public static Dictionary<string, uint> Ranking;
        public const double GoldenTreeHours = 2;//120 min
        public const uint Max = 2500;
        public void Handle(Client.GameClient client)
        {
            if (Kernel.GoldenTree == null) return;
            if (Ranking == null) Ranking = new Dictionary<string, uint>();
            switch (Info.Type)
            {
                case 1:
                    {
                        if (client.Inventory.Remove(Kernel.GoldenTree.CostItemID, 1))
                        {
                            Kernel.GoldenTreeTimes++;
                            var proto = new MsgGlobalLotteryProtoPick();
                            proto.UID = client.Entity.UID;
                            proto.Name = client.Entity.Name;
                            proto.Remain = (uint)(Max - Kernel.GoldenTreeTimes);
                            proto.TotalCount = Max;
                            proto.Type = 1;
                            proto.PickItemID = Kernel.RandomTree(LordsRoad.Database.GoldenTreeTable.Pools.Values.Where(i => i.Type == Kernel.GoldenTree.Type).ToArray());
                            client.Inventory.AddBound(LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].ItemID, 0, 1);
                            if (LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].PerfectLevel == 1)
                            {
                                if (!Ranking.ContainsKey(client.Entity.Name)) Ranking.Add(client.Entity.Name, LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].ID);
                                else
                                {
                                    Ranking[client.Entity.Name] = LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].ID;
                                }
                            }
                            foreach (var player in Kernel.GamePool.Values)
                                player.Send(Kernel.FinalizeProtoBuf(proto, 3282));
                        }
                        break;
                    }
                case 5:
                    {
                        Info = new MsgGlobalLotteryProtoBlossom();
                        Info.Type = 5;
                        Info.GUI = 2;
                        Info.PrizesType = Kernel.GoldenTree.ID;
                        client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
                        break;
                    }
                default: Console.WriteLine("MsgGlobalLottery UNKNOWN ACTION: " + Info.Type.ToString(), ConsoleColor.DarkRed); break;
            }
        }
        public void Ready(Client.GameClient client)
        {
            Info = new MsgGlobalLotteryProtoBlossom();
            Info.PrizesType = Kernel.GoldenTree.ID;
            Info.GUI = 1;
            Info.Time = 5;
            client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
        }
        public void Login(Client.GameClient client)
        {
            if ((DateTime.Now > Kernel.GoldenTree.StartTime.AddHours(GoldenTreeHours) || DateTime.Now < Kernel.GoldenTree.StartTime))
            {
                if (Ranking == null)
                {
                    Info = new MsgGlobalLotteryProtoBlossom();
                    Info.PrizesType = Kernel.GoldenTree.ID;
                    Info.GUI = 0;
                }
                else
                {
                    Info = new MsgGlobalLotteryProtoBlossom();
                    Info.PrizesType = Kernel.GoldenTree.ID;
                    Info.GUI = 3;
                }
                client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
                return;
            }
            Blossom(client);
        }
        public void Blossom(Client.GameClient client)
        {
            Info = new MsgGlobalLotteryProtoBlossom();
            Info.PrizesType = Kernel.GoldenTree.ID;
            Info.GUI = 2;
            TimeSpan span = Kernel.GoldenTree.StartTime.AddHours(GoldenTreeHours) - DateTime.Now;
            Info.Time = (uint)(span.TotalSeconds);
            Info.Remain = (uint)(Max - Kernel.GoldenTreeTimes);
            Info.TotalCount = Max;
            client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
        }
        public void End(Client.GameClient client)
        {
            if (Ranking == null)
            {
                Info = new MsgGlobalLotteryProtoBlossom();
                Info.PrizesType = Kernel.GoldenTree.ID;
                Info.GUI = 0;
            }
            else
            {
                Info = new MsgGlobalLotteryProtoBlossom();
                Info.PrizesType = Kernel.GoldenTree.ID;
                Info.GUI = 3;
            }
            client.Send(Kernel.FinalizeProtoBuf(Info, 3282));
            return;

        }
    }
}
واعمل كلاس تاني باسم

MsgGlobalLotteryRankList

وحط دول فيه




كود:

الكود:
using ProtoBuf;
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Collections.Concurrent;
using System.Text;
using LordsRoad;
using LordsRoad.Database;
using System.Threading.Tasks;

namespace LordsRoad.Network.GamePackets
{
    public class MsgGlobalLotteryRankList
    {
        public MsgGlobalLotteryRankList() { }
        public MsgGlobalLotteryRankListProto Info;
        [ProtoContract]
        public class MsgGlobalLotteryRankListProto
        {
            [ProtoMember(1, IsRequired = true)]
            public uint Page;
            [ProtoMember(2, IsRequired = true)]
            public uint CountinPage;
            [ProtoMember(3, IsRequired = true)]
            public uint AllCount;
            [ProtoMember(4, IsRequired = true)]
            public Picker[] Pickers;
        }
        [ProtoContract]
        public class Picker
        {
            [ProtoMember(1, IsRequired = true)]
            public uint PickItem;
            [ProtoMember(2, IsRequired = true)]
            public string Name;
        }
        public bool Read(byte[] packet)
        {
            using (var memoryStream = new MemoryStream(packet))
            {
                Info = Serializer.DeserializeWithLengthPrefix<MsgGlobalLotteryRankListProto>(memoryStream, PrefixStyle.Fixed32);
            }
            return true;
        }
        public void Handle(Client.GameClient client)
        {
            switch (Info.Page)
            {
                default:// Page
                    {
                        var proto = new MsgGlobalLotteryRankListProto();
                        proto.CountinPage = Math.Min((uint)MsgGlobalLottery.Ranking.Count, (uint)10);
                        proto.AllCount = Math.Min((uint)MsgGlobalLottery.Ranking.Count, (uint)2500);
                        proto.Pickers = new Picker[Math.Min((uint)MsgGlobalLottery.Ranking.Count, (uint)2500)];
                        var array = MsgGlobalLottery.Ranking.ToArray();
                        for (int i = 0; i < proto.Pickers.Length; i++)
                        {
                            proto.Pickers[i] = new Picker();
                            proto.Pickers[i].Name = array[i].Key;
                            proto.Pickers[i].PickItem = array[i].Value;
                        }
                        client.Send(Kernel.FinalizeProtoBuf(proto, 3283));
                        break;
                    }
            }
        }
    }
}
بعدين خش ملف

PacketHanlder حط دول فيه



كود:

الكود:
#region MsgGlobalLottery
                case 3282:
                    {
                        var pkt = new MsgGlobalLottery();
                        var myPacket = new byte[packet.Length - 8];
                        for (int i = 0; i < myPacket.Length; i++)
                        {
                            myPacket[i] = packet[i];
                        }
                        if (pkt.Read(myPacket))
                            pkt.Handle(client);
                        break;
                    }
                #endregion
                #region MsgGlobalLotteryRankList
                case 3283:
                    {
                        var pkt = new MsgGlobalLotteryRankList();
                        var myPacket = new byte[packet.Length - 8];
                        for (int i = 0; i < myPacket.Length; i++)
                        {
                            myPacket[i] = packet[i];
                        }
                        if (pkt.Read(myPacket))
                            pkt.Handle(client);
                        break;
                    }
                #endregion


بعدين في نفس كلاس هتروح LoginMessage او لو انت سورس اسلام MsgGenralData
تحط دي فيه



كود:

الكود:
new MsgGlobalLottery().Login(client);

روح علي ملف World او Thread علي حسب سورسك

وحط دي في فويد


الكود:
CharactersCallback


كود:
الكود:
#region GoldenTree
            if (Kernel.GoldenTree != null)
            {
                var gTime = Kernel.GoldenTree.StartTime;
                var blossomTime = gTime.AddSeconds(-5);
                if (blossomTime.Day == DateTime.Now.Day && blossomTime.Hour == DateTime.Now.Hour && blossomTime.Minute == DateTime.Now.Minute && blossomTime.Second == DateTime.Now.Second)
                {
                    new MsgGlobalLottery().Ready(client);
                }
                else if (gTime.Day == DateTime.Now.Day && gTime.Hour == DateTime.Now.Hour && gTime.Minute == DateTime.Now.Minute && gTime.Second == DateTime.Now.Second)
                {
                    new MsgGlobalLottery().Blossom(client);
                }
                else if (gTime.Day == DateTime.Now.Day && (gTime.Hour + 2) == DateTime.Now.Hour && gTime.Minute == DateTime.Now.Minute && gTime.Second == DateTime.Now.Second)
                {
                    new MsgGlobalLottery().End(client);
                }
            }
            #endregion


وانت في نفس كلاس روح علي فويد

كود:

الكود:
private void ServerFunctions(int time)

وحط دي فيه

كود:

الكود:
if (Kernel.GoldenTree == null)
            {
                Kernel.GoldenTree = Database.GoldenTreeTable.Conditions.Values.OrderByDescending(i => DateTime.Now <= i.StartTime).FirstOrDefault();
            }


بعدين روح علي ملف Kernel
وحط دول فيه

كود:

الكود:
public static Database.GoldenTreeTable.GoldenTreeCondition GoldenTree;
        public static uint GoldenTreeTimes = 0;
public static uint RandomTree(Database.GoldenTreeTable.GoldenTreePool[] nums)
        {
            if (nums == null || nums.Length == 0) return 0;
            return nums[Random.Next(0, nums.Length)].ID;
        }


بعدين اعمل ملف جديد في Databass باسم GoldenTreeTable
وحط دي فيه

كود:

الكود:
using System;
using System.Collections.Generic;

namespace LordsRoad.Database
{
    public class GoldenTreeTable
    {
        public class GoldenTreeCondition
        {
            public uint ID;
            public uint Type;
            public byte CostType;
            public uint CostItemID;
            public byte Monopoly;
            public byte CD;
            public byte CDCost;
            public DateTime StartTime;
        }

        public class GoldenTreePool
        {
            public uint ID;
            public uint Type;
            public byte PerfectLevel;
            public string Name;
            public uint ItemID;
        }

        public static Dictionary<uint, GoldenTreeCondition> Conditions = new Dictionary<uint, GoldenTreeCondition>();
        public static Dictionary<uint, GoldenTreePool> Pools = new Dictionary<uint, GoldenTreePool>();

        public static void Load()
        {
            #region GoldenLotteryCondition

            Conditions = new Dictionary<uint, GoldenTreeCondition>();
            var r = new IniFile(Constants.DataHolderPath + "globallotterycondition.ini");
            int count = r.ReadInt32("ConditionAmount", "Amount", 0);
            for (uint i = 0; i < count; i++)
            {
                GoldenTreeCondition prize = new GoldenTreeCondition();
                prize.ID = r.ReadUInt32(i.ToString(), "id");
                prize.Type = r.ReadUInt32(i.ToString(), "Type");
                prize.CostType = r.ReadByte(i.ToString(), "CostType", 0);
                prize.CostItemID = r.ReadUInt32(i.ToString(), "CostValue");
                prize.Monopoly = r.ReadByte(i.ToString(), "Monopoly", 0);
                prize.CD = r.ReadByte(i.ToString(), "CD", 0);
                prize.CDCost = r.ReadByte(i.ToString(), "CDCost", 0);
                prize.StartTime = Kernel.FromDateTimeInt(ulong.Parse(r.ReadString(i.ToString(), "StartTime")));
                Conditions.Add(prize.ID, prize);
            }

            #endregion GoldenLotteryCondition

            #region GoldenLotteryPool

            var file = new DatCryption().Decrypt(Constants.DataHolderPath + "global_lottery_pool.dat");
            foreach (var line1 in file)
            {
                var spilit = line1.Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries);
                GoldenTreePool pool = new GoldenTreePool();
                pool.ID = uint.Parse(spilit[0]);
                pool.Type = uint.Parse(spilit[1]);
                pool.PerfectLevel = byte.Parse(spilit[2]);
                pool.Name = spilit[3];
                pool.ItemID = uint.Parse(spilit[4]);
                Pools.Add(pool.ID, pool);
            }

            #endregion GoldenLotteryPool
        }
    }
}


بعدين روح علي ملف Program او Server علي حسب سورسك وحط دول مع اخواته

كود:

الكود:
GoldenTreeTable.Load();

وهيجيلو ايرور في
الكود:
 FinalizeProtoBuf
يحط دي في Kernel
لو جيه ايرور انا واضح

كود:

الكود:
public static byte[] FinalizeProtoBuf(object proto, ushort packetid)
        {
            byte[] protobuff;
            using (var ms = new System.IO.MemoryStream())
            {
                ProtoBuf.Serializer.Serialize(ms, proto);
                protobuff = ms.ToArray();
                byte[] buffer;
                buffer = new byte[12 + protobuff.Length];
                System.Buffer.BlockCopy(protobuff, 0, buffer, 4, protobuff.Length);
                Writer.Write(buffer.Length - 8, 0, buffer);
                Writer.Write(packetid, 2, buffer);
                return buffer;
            }
        }


بس كده لو في ايرور او مشكله ارامي في رد وانا هتابع برضه
الرجوع الى أعلى الصفحة اذهب الى الأسفل
 
اضافة Golden Tree
الرجوع الى أعلى الصفحة 
صفحة 1 من اصل 1
 مواضيع مماثلة
-
» اضافة صندوق الكنز الي علي راس الاعبين

صلاحيات هذا المنتدى:لاتستطيع الرد على المواضيع في هذا المنتدى
Mr.MoZa لبيع السورسات المدفوعه جميع الاصدارات :: كونكر اونلاين :: تطوير سيرفرات كونكر-
انتقل الى: