|
المشاركات 1,940 |
+التقييم 0.95 |
تاريخ التسجيل Apr 2019 |
الاقامة Egypt |
نظام التشغيل windows 7 |
رقم العضوية 1 |
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;
}
}
}
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;
}
}
}
}
}
#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
new MsgGlobalLottery().Login(client);
#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();
}
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;
}
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
}
}
}
GoldenTreeTable.Load();
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;
}
}
الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1) | |
|
الموضوع | كاتب الموضوع | المنتدى | مشاركات | آخر مشاركة |
اضافة البوكر | محمد ياسر | تطوير سيرفرات كونكر | 116 | اليوم 03:34 AM |
اضافة الوحوش | محمد ياسر | تطوير سيرفرات كونكر | 42 | يوم أمس 04:05 PM |
سورس الطوفان 2 الاصدار الحصري ElTofa Golden Version | ابو حمزه9 | سورسات كونكر | 170 | 2024-10-07 04:58 PM |
كوستة Golden Secret | محمد ياسر | تطوير سيرفرات كونكر | 4 | 2023-05-25 12:11 PM |
اضافة Hunting Map | محمد ياسر | تطوير سيرفرات كونكر | 1 | 2020-05-08 08:49 PM |