منتدي اكواد

منتدي اكواد (https://code.vpscairo.com/index.php)
-   تطوير سيرفرات كونكر (https://code.vpscairo.com/forumdisplay.php?f=11)
-   -   اضافة Golden Tree (https://code.vpscairo.com/showthread.php?t=61)

محمد ياسر 2019-04-19 09:43 PM

اضافة Golden Tree
 

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

اضافة Golden tree

والي مش عارفه

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

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

Copyright Zahran Joe Lotfy



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

وحط دول فيه

كود PHP:

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(1IsRequired true)]
            public 
uint Type;
            [
ProtoMember(2IsRequired true)]
            public 
uint PrizesType;
            [
ProtoMember(3IsRequired true)]
            
///0 = Not Opened, 1 = Ready, 2 = Opened, 3 = Ranking
            
public uint GUI;
            [
ProtoMember(4IsRequired true)]
            public 
uint Time;
            [
ProtoMember(5IsRequired true)]
            public 
uint Remain;
            [
ProtoMember(6IsRequired true)]
            public 
uint TotalCount;
        }
        [
ProtoContract]
        public class 
MsgGlobalLotteryProtoPick
        
{
            [
ProtoMember(1IsRequired true)]
            public 
uint Type;
            [
ProtoMember(2IsRequired true)]
            public 
uint UID;
            [
ProtoMember(3IsRequired true)]
            public 
uint GUI;
            [
ProtoMember(4IsRequired true)]
            public 
uint PickItemID;
            [
ProtoMember(5IsRequired true)]
            public 
string Name;
            [
ProtoMember(6IsRequired true)]
            public 
uint Remain;
            [
ProtoMember(7IsRequired true)]
            public 
uint TotalCount;
        }
        public 
bool Read(byte[] packet)
        {
            
using (var memoryStream = new MemoryStream(packet))
            {
                
Info Serializer.DeserializeWithLengthPrefix<MsgGlobalLotteryProtoBlossom>(memoryStreamPrefixStyle.Fixed32);
            }
            return 
true;
        }
        public static 
Dictionary<stringuintRanking;
        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 == nullRanking = new Dictionary<stringuint>();
            switch (
Info.Type)
            {
                case 
1:
                    {
                        if (
client.Inventory.Remove(Kernel.GoldenTree.CostItemID1))
                        {
                            
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.Type == Kernel.GoldenTree.Type).ToArray());
                            
client.Inventory.AddBound(LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].ItemID01);
                            if (
LordsRoad.Database.GoldenTreeTable.Pools[proto.PickItemID].PerfectLevel == 1)
                            {
                                if (!
Ranking.ContainsKey(client.Entity.Name)) Ranking.Add(client.Entity.NameLordsRoad.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(proto3282));
                        }
                        break;
                    }
                case 
5:
                    {
                        
Info = new MsgGlobalLotteryProtoBlossom();
                        
Info.Type 5;
                        
Info.GUI 2;
                        
Info.PrizesType Kernel.GoldenTree.ID;
                        
client.Send(Kernel.FinalizeProtoBuf(Info3282));
                        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(Info3282));
        }
        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(Info3282));
                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(Info3282));
        }
        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(Info3282));
            return;

        }
    }


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

MsgGlobalLotteryRankList

وحط دول فيه



كود PHP:

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(1IsRequired true)]
            public 
uint Page;
            [
ProtoMember(2IsRequired true)]
            public 
uint CountinPage;
            [
ProtoMember(3IsRequired true)]
            public 
uint AllCount;
            [
ProtoMember(4IsRequired true)]
            public 
Picker[] Pickers;
        }
        [
ProtoContract]
        public class 
Picker
        
{
            [
ProtoMember(1IsRequired true)]
            public 
uint PickItem;
            [
ProtoMember(2IsRequired true)]
            public 
string Name;
        }
        public 
bool Read(byte[] packet)
        {
            
using (var memoryStream = new MemoryStream(packet))
            {
                
Info Serializer.DeserializeWithLengthPrefix<MsgGlobalLotteryRankListProto>(memoryStreamPrefixStyle.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 0proto.Pickers.Lengthi++)
                        {
                            
proto.Pickers[i] = new Picker();
                            
proto.Pickers[i].Name = array[i].Key;
                            
proto.Pickers[i].PickItem = array[i].Value;
                        }
                        
client.Send(Kernel.FinalizeProtoBuf(proto3283));
                        break;
                    }
            }
        }
    }


بعدين خش ملف

PacketHanlder حط دول فيه


كود PHP:

#region MsgGlobalLottery
                
case 3282:
                    {
                        var 
pkt = new MsgGlobalLottery();
                        var 
myPacket = new byte[packet.Length 8];
                        for (
int i 0myPacket.Lengthi++)
                        {
                            
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 0myPacket.Lengthi++)
                        {
                            
myPacket[i] = packet[i];
                        }
                        if (
pkt.Read(myPacket))
                            
pkt.Handle(client);
                        break;
                    }
                
#endregion 

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


كود PHP:

new MsgGlobalLottery().Login(client); 

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

وحط دي في فويد

CharactersCallback

كود PHP:

#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 

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

private void ServerFunctions(int time

وحط دي فيه
كود PHP:

if (Kernel.GoldenTree == null)
            {
                
Kernel.GoldenTree Database.GoldenTreeTable.Conditions.Values.OrderByDescending(=> DateTime.Now <= i.StartTime).FirstOrDefault();
            } 

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

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(0nums.Length)].ID;
        } 

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

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<uintGoldenTreeConditionConditions = new Dictionary<uintGoldenTreeCondition>();
        public static 
Dictionary<uintGoldenTreePoolPools = new Dictionary<uintGoldenTreePool>();

        public static 
void Load()
        {
            
#region GoldenLotteryCondition

            
Conditions = new Dictionary<uintGoldenTreeCondition>();
            var 
= new IniFile(Constants.DataHolderPath "globallotterycondition.ini");
            
int count r.ReadInt32("ConditionAmount""Amount"0);
            for (
uint i 0counti++)
            {
                
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.IDprize);
            }

            
#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.IDpool);
            }

            
#endregion GoldenLotteryPool
        
}
    }


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

GoldenTreeTable.Load(); 

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

public static byte[] FinalizeProtoBuf(object protoushort packetid)
        {
            
byte[] protobuff;
            
using (var ms = new System.IO.MemoryStream())
            {
                
ProtoBuf.Serializer.Serialize(msproto);
                
protobuff ms.ToArray();
                
byte[] buffer;
                
buffer = new byte[12 protobuff.Length];
                
System.Buffer.BlockCopy(protobuff0buffer4protobuff.Length);
                
Writer.Write(buffer.Length 80buffer);
                
Writer.Write(packetid2buffer);
                return 
buffer;
            }
        } 

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


karem1q 2023-10-13 08:59 PM

رد: اضافة Golden Tree
 
تسلم


الساعة الآن 12:57 AM

مرحبا بكم في منتدي اكواد لتطوير الالعاب