احصائياتى

الردود
1

المشاهدات
1113
 
Hazem
.:: المدير العام::.

    غير متواجد

المشاركات
2,315

+التقييم
0.84

تاريخ التسجيل
Apr 2019

الاقامة
Egypt

نظام التشغيل
windows 7

رقم العضوية
1
2019-04-19, 09:43 PM
المشاركة 1
2019-04-19, 09:43 PM
المشاركة 1
افتراضي اضافة Golden Tree

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

اضافة 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;
            }
        } 

بس كده لو في ايرور او مشكله ارامي في رد وانا هتابع برضه



قديم 2020-09-15, 03:30 AM
المشاركة 2
karem1q
.:: عضو نشيط ::.
  • غير متواجد
افتراضي رد: اضافة Golden Tree
تسلم كوستيه جميله جدا


العلامات المرجعية



الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1)
 

الانتقال السريع

المواضيع المتشابهه للموضوع: اضافة Golden Tree
الموضوع كاتب الموضوع المنتدى مشاركات آخر مشاركة
سورس الطوفان 2 الاصدار الحصري ElTofa Golden Version virus7x سورسات كونكر 113 2021-09-04 04:19 PM
اضافة الوحوش Hazem تطوير سيرفرات كونكر 34 2021-02-15 04:27 PM
اضافة البوكر Hazem تطوير سيرفرات كونكر 96 2021-02-12 03:32 AM
كوستة Golden Secret Hazem تطوير سيرفرات كونكر 4 2020-09-27 02:07 PM
اضافة Hunting Map Hazem تطوير سيرفرات كونكر 4 2020-08-21 11:56 PM


الساعة الآن 12:11 PM