|
|
using System;
using System.Linq;
using System.Collections.Generic;
using AlgbrooT.Network.GamePackets;
using System.IO;
namespace AlgbrooT.Game.ConquerStructures
{
public class Nobility : AlgbrooT.Network.Writer
{
public static ulong MaxDonation = 0;
public static ulong MaxDonation1 = 0;
public static ulong MaxDonation2 = 0;
public static SafeDictionary<uint, NobilityInformation> Board = new SafeDictionary<uint, NobilityInformation>(10000);
public static List<NobilityInformation> BoardList = new List<NobilityInformation>(10000);
public static void Handle(NobilityInfo information, Client.GameState client)
{
switch (information.Type)
{
case NobilityInfo.Donate:
{
if (client.NobilityTimer.Donation == 1 || client.NobilityTimer.Donation == 2 || client.NobilityTimer.Donation == 3)
{
client.MessageBox("Sorry U Can't Donate Now.", null, null, 60);
return;
}
if (client.Trade.InTrade)
return;
if (client.Player.PokerHack == true)
return;
ulong silvers = information.dwParam;
bool newDonator = false;
client.NobilityInformation.Gender = (byte)(client.Player.Body % 10);
if (client.NobilityInformation.Donation == 0)
newDonator = true;
if (information.MoneyType == 1)
{
ulong cps = silvers / 1;
if (client.Player.ConquerPoints >= cps)
{
client.Player.ConquerPoints -= (uint)cps;
client.NobilityInformation.Donation += silvers;
}
}
else
{
if (client.Player.Money >= cps)
{
client.Player.Money -= (ulong)cps;
client.NobilityInformation.Donation += cps;
}
}
if (!Board.ContainsKey(client.Player.UID) && client.NobilityInformation.Donation == silvers && newDonator)
{
Board.Add(client.Player.UID, client.NobilityInformation);
try
{
Database.NobilityTable.InsertNobilityInformation(client.NobilityInformation);
}
catch
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
}
else
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
Sort(client.Player.UID);
break;
}
case NobilityInfo.List:
{
byte[] packet = new byte[600 + 8];
WriteUInt16(600, 0, packet);
WriteUInt16(2064, 2, packet);
WriteUInt16(2, 4, packet);
WriteUInt16(5, 10, packet);
WriteUInt16(10, 12, packet);
int offset = 120;
for (int i = (int)(information.wParam1 * 10); i < information.wParam1 * 10 + 10 && i < BoardList.Count; i++)
{
var nob = BoardList[i];
WriteUInt32(nob.EntityUID, offset, packet);
offset += 4;
if (Kernel.GamePool.ContainsKey(nob.EntityUID))
{
WriteUInt32(1, offset, packet);
offset += 4;
WriteUInt32(nob.Mesh, offset, packet);
offset += 4;
}
else
{
offset += 8;
}
WriteString(nob.Name, offset, packet);
offset += 20;
WriteUInt64(nob.Donation, offset, packet);
offset += 8;
WriteUInt32((uint)nob.Rank, offset, packet);
offset += 4;
WriteUInt32((uint)i, offset, packet);
offset += 4;
}
client.Send(packet);
information.Type = NobilityInfo.NextRank;
ulong value = 0;
information.dwParam2 = 0;
lock (BoardList)
{
if (client.NobilityInformation.Rank == NobilityRank.Prince)
value = (ulong)(BoardList[02].Donation - client.NobilityInformation.Donation + 1);
if (client.NobilityInformation.Rank == NobilityRank.Duke)
value = (ulong)(BoardList[14].Donation - client.NobilityInformation.Donation + 1);
}
Network.Writer.WriteUInt64(value, 8, information.ToArray());
information.dwParam3 = 60;
information.dwParam4 = uint.MaxValue;
client.Send(information);
break;
}
}
}
public static void Donate(ulong silvers, Client.GameState client)
{
bool newDonator = false;
client.NobilityInformation.Gender = (byte)(client.Player.Body % 10);
if (client.NobilityInformation.Donation == 0)
newDonator = true;
client.NobilityInformation.Donation += silvers;
if (!Board.ContainsKey(client.Player.UID) && client.NobilityInformation.Donation == silvers && newDonator)
{
Board.Add(client.Player.UID, client.NobilityInformation);
try
{
Database.NobilityTable.InsertNobilityInformation(client.NobilityInformation);
}
catch
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
}
else
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
Sort(client.Player.UID);
}
public static void Sort(uint updateUID)
{
SafeDictionary<uint, NobilityInformation> sortedBoard = new SafeDictionary<uint, NobilityInformation>();
int Place = 0;
foreach (NobilityInformation entry in Board.Values.OrderByDescending((p) => p.Donation))
{
Client.GameState client = null;
try
{
int previousPlace = entry.Position;
entry.Position = Place;
NobilityRank Rank = NobilityRank.Serf;
if (Place >= 5000)
{
if (entry.Donation == 1)
{
Rank = NobilityRank.King;
}
else if (entry.Donation == 2)
{
Rank = NobilityRank.Prince;
}
else if (entry.Donation == 3)
{
Rank = NobilityRank.Duke;
}
else if (entry.Donation >= 5000)
{
Rank = NobilityRank.Earl;
}
else if (entry.Donation >= 1000)
{
Rank = NobilityRank.Baron;
}
else if (entry.Donation >= 300)
{
Rank = NobilityRank.Knight;
}
}
else
{
if (Place < 10||entry.Donation == 1)//serverrank
{
Rank = NobilityRank.King;
if (Place < (10))
{
MaxDonation = entry.Donation;
}
}
else if (Place < 32||entry.Donation == 2)
{
Rank = NobilityRank.Prince;
if (Place < (32))
{
MaxDonation1 = entry.Donation;
}
}
else if (Place < 5000||entry.Donation == 3)
{
Rank = NobilityRank.Duke;
if (Place < (5000))
{
MaxDonation2 = entry.Donation;
}
}
}
var oldRank = entry.Rank;
entry.Rank = Rank;
if (Kernel.GamePool.TryGetValue(entry.EntityUID, out client))
{
bool updateTheClient = false;
if (oldRank != Rank)
{
updateTheClient = true;
if (Rank == NobilityRank.Baron)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " For New Rank [ Baron ] In [Tyranny-Online].", System.Drawing.Color.White, Message.TopLeft), Program.Values);
}
if (Rank == NobilityRank.Earl)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " For New Rank [ Earl ] In [Tyranny-Online].", System.Drawing.Color.White, Message.TopLeft), Program.Values);
}
if (Rank == NobilityRank.Duke)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has the " + (string)(Network.PacketHandler.IsBoy(entry.Mesh % 10000) == true ? "Duke" : "Duchess") + " In [Tyranny-Online].", System.Drawing.Color.White, Message.Center), Program.Values);
}
if (Rank == NobilityRank.Prince)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has the " + (string)(Network.PacketHandler.IsBoy(entry.Mesh % 10000) == true ? "Prince" : "Princess") + " In [Tyranny-Online].", System.Drawing.Color.White, Message.Center), Program.Values);
}
if (Rank == NobilityRank.King)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has become the New " + (string)(Network.PacketHandler.IsBoy(entry.Mesh % 10000) == true ? "King" : "Queen") + " In [Tyranny-Online].", System.Drawing.Color.White, Message.Center), Program.Values);
}
if (Rank == NobilityRank.Knight)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has become a Knight By [Tyranny-Online].", System.Drawing.Color.White, Message.TopLeft), Program.Values);
}
}
else
{
if (previousPlace != Place)
{
updateTheClient = true;
}
}
if (updateTheClient || client.Player.UID == updateUID)
{
NobilityInfo update = new NobilityInfo(true);
update.Type = NobilityInfo.Icon;
update.dwParam = entry.EntityUID;
update.UpdateString(entry);
client.SendScreen(update, true);
client.Player.NobilityRank = entry.Rank;
}
}
sortedBoard.Add(entry.EntityUID, entry);
Place++;
}
catch { }
}
Board = sortedBoard;
lock (BoardList)
BoardList = Board.Values.ToList();
}
public static void Delet(Client.GameState client)
{
if (Game.ConquerStructures.Nobility.Board.ContainsKey(client.Player.UID))
{
Game.ConquerStructures.Nobility.Board.Remove(client.Player.UID);
Game.ConquerStructures.Nobility.Sort(0);
foreach (var clients in Program.GamePool)
{
if (Game.ConquerStructures.Nobility.Board.ContainsKey(clients.Player.UID))
Game.ConquerStructures.Nobility.Sort(client.Player.UID);
}
Database.MySqlCommand cmd = new Database.MySqlCommand(Database.MySqlCommandType.DELETE).Delete("nobility", "EntityUID", client.Player.UID);
cmd.Execute();
}
}
public static ulong cps { get; set; }
}
public class NobilityInformation
{
public string Name;
public uint EntityUID;
public uint Mesh;
public ulong Donation;
public byte Gender;
public int Position;
public NobilityRank Rank;
public bool king;
public DateTime KingDays;
}
public enum NobilityRank : byte
{
Serf = 0,
Knight = 1,
Baron = 3,
Earl = 5,
Duke = 7,
Prince = 9,
King = 12
}
}
if (Place < 10||entry.Donation == 1)//serverrank { Rank = NobilityRank.King; if (Place < (10)) { MaxDonation = entry.Donation; } } else if (Place < 32||entry.Donation == 2) { Rank = NobilityRank.Prince; if (Place < (32)) { MaxDonation1 = entry.Donation; } } else if (Place < 5000||entry.Donation == 3) { Rank = NobilityRank.Duke; if (Place < (5000)) { MaxDonation2 = entry.Donation; } } }
using System;
using System.Linq;
using System.Collections.Generic;
using AlgbrooT.Network.GamePackets;
using System.IO;
namespace AlgbrooT.Game.ConquerStructures
{
public class Nobility : AlgbrooT.Network.Writer
{
public static ulong MaxDonation = 0;
public static ulong MaxDonation1 = 0;
public static ulong MaxDonation2 = 0;
public static SafeDictionary<uint, NobilityInformation> Board = new SafeDictionary<uint, NobilityInformation>(10000);
public static List<NobilityInformation> BoardList = new List<NobilityInformation>(10000);
public static void Handle(NobilityInfo information, Client.GameState client)
{
switch (information.Type)
{
case NobilityInfo.Donate:
{
if (client.NobilityTimer.Donation == 1 || client.NobilityTimer.Donation == 2 || client.NobilityTimer.Donation == 3)
{
client.MessageBox("Sorry U Can't Donate Now.", null, null, 60);
return;
}
if (client.Trade.InTrade)
return;
if (client.Player.PokerHack == true)
return;
ulong silvers = information.dwParam;
bool newDonator = false;
client.NobilityInformation.Gender = (byte)(client.Player.Body % 10);
if (client.NobilityInformation.Donation == 0)
newDonator = true;
if (information.MoneyType == 1)
{
ulong cps = silvers / 1;
if (client.Player.ConquerPoints >= cps)
{
client.Player.ConquerPoints -= (uint)cps;
client.NobilityInformation.Donation += silvers;
}
}
else
{
if (client.Player.Money >= cps)
{
client.Player.Money -= (ulong)cps;
client.NobilityInformation.Donation += cps;
}
}
if (!Board.ContainsKey(client.Player.UID) && client.NobilityInformation.Donation == silvers && newDonator)
{
Board.Add(client.Player.UID, client.NobilityInformation);
try
{
Database.NobilityTable.InsertNobilityInformation(client.NobilityInformation);
}
catch
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
}
else
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
Sort(client.Player.UID);
break;
}
case NobilityInfo.List:
{
byte[] packet = new byte[600 + 8];
WriteUInt16(600, 0, packet);
WriteUInt16(2064, 2, packet);
WriteUInt16(2, 4, packet);
WriteUInt16(5, 10, packet);
WriteUInt16(10, 12, packet);
int offset = 120;
for (int i = (int)(information.wParam1 * 10); i < information.wParam1 * 10 + 10 && i < BoardList.Count; i++)
{
var nob = BoardList[i];
WriteUInt32(nob.EntityUID, offset, packet);
offset += 4;
if (Kernel.GamePool.ContainsKey(nob.EntityUID))
{
WriteUInt32(1, offset, packet);
offset += 4;
WriteUInt32(nob.Mesh, offset, packet);
offset += 4;
}
else
{
offset += 8;
}
WriteString(nob.Name, offset, packet);
offset += 20;
WriteUInt64(nob.Donation, offset, packet);
offset += 8;
WriteUInt32((uint)nob.Rank, offset, packet);
offset += 4;
WriteUInt32((uint)i, offset, packet);
offset += 4;
}
client.Send(packet);
information.Type = NobilityInfo.NextRank;
ulong value = 0;
information.dwParam2 = 0;
lock (BoardList)
{
if (client.NobilityInformation.Rank == NobilityRank.Prince)
value = (ulong)(BoardList[02].Donation - client.NobilityInformation.Donation + 1);
if (client.NobilityInformation.Rank == NobilityRank.Duke)
value = (ulong)(BoardList[14].Donation - client.NobilityInformation.Donation + 1);
}
Network.Writer.WriteUInt64(value, 8, information.ToArray());
information.dwParam3 = 60;
information.dwParam4 = uint.MaxValue;
client.Send(information);
break;
}
}
}
public static void Donate(ulong silvers, Client.GameState client)
{
bool newDonator = false;
client.NobilityInformation.Gender = (byte)(client.Player.Body % 10);
if (client.NobilityInformation.Donation == 0)
newDonator = true;
client.NobilityInformation.Donation += silvers;
if (!Board.ContainsKey(client.Player.UID) && client.NobilityInformation.Donation == silvers && newDonator)
{
Board.Add(client.Player.UID, client.NobilityInformation);
try
{
Database.NobilityTable.InsertNobilityInformation(client.NobilityInformation);
}
catch
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
}
else
{
Database.NobilityTable.UpdateNobilityInformation(client.NobilityInformation);
}
Sort(client.Player.UID);
}
public static void Sort(uint updateUID)
{
SafeDictionary<uint, NobilityInformation> sortedBoard = new SafeDictionary<uint, NobilityInformation>();
int Place = 0;
foreach (NobilityInformation entry in Board.Values.OrderByDescending((p) => p.Donation))
{
Client.GameState client = null;
try
{
int previousPlace = entry.Position;
entry.Position = Place;
NobilityRank Rank = NobilityRank.Serf;
if (Place >= 5000)
{
if (entry.Donation == 1)
{
Rank = NobilityRank.King;
}
else if (entry.Donation == 2)
{
Rank = NobilityRank.Prince;
}
else if (entry.Donation == 3)
{
Rank = NobilityRank.Duke;
}
else if (entry.Donation >= 5000)
{
Rank = NobilityRank.Earl;
}
else if (entry.Donation >= 1000)
{
Rank = NobilityRank.Baron;
}
else if (entry.Donation >= 300)
{
Rank = NobilityRank.Knight;
}
}
else
{
if (Place < 10||entry.Donation == 1)//serverrank
{
Rank = NobilityRank.King;
if (Place < (10))
{
MaxDonation = entry.Donation;
}
}
else if (Place < 32||entry.Donation == 2)
{
Rank = NobilityRank.Prince;
if (Place < (32))
{
MaxDonation1 = entry.Donation;
}
}
else if (Place < 5000||entry.Donation == 3)
{
Rank = NobilityRank.Duke;
if (Place < (5000))
{
MaxDonation2 = entry.Donation;
}
}
}
var oldRank = entry.Rank;
entry.Rank = Rank;
if (Kernel.GamePool.TryGetValue(entry.EntityUID, out client))
{
bool updateTheClient = false;
if (oldRank != Rank)
{
updateTheClient = true;
if (Rank == NobilityRank.Baron)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " For New Rank [ Baron ] In [Tyranny-Online].", System.Drawing.Color.White, Message.TopLeft), Program.Values);
}
if (Rank == NobilityRank.Earl)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " For New Rank [ Earl ] In [Tyranny-Online].", System.Drawing.Color.White, Message.TopLeft), Program.Values);
}
if (Rank == NobilityRank.Duke)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has the " + (string)(Network.PacketHandler.IsBoy(entry.Mesh % 10000) == true ? "Duke" : "Duchess") + " In [Tyranny-Online].", System.Drawing.Color.White, Message.Center), Program.Values);
}
if (Rank == NobilityRank.Prince)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has the " + (string)(Network.PacketHandler.IsBoy(entry.Mesh % 10000) == true ? "Prince" : "Princess") + " In [Tyranny-Online].", System.Drawing.Color.White, Message.Center), Program.Values);
}
if (Rank == NobilityRank.King)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has become the New " + (string)(Network.PacketHandler.IsBoy(entry.Mesh % 10000) == true ? "King" : "Queen") + " In [Tyranny-Online].", System.Drawing.Color.White, Message.Center), Program.Values);
}
if (Rank == NobilityRank.Knight)
{
Kernel.SendWorldMessage(new Message("Congratulation! " + client.Player.Name + " has become a Knight By [Tyranny-Online].", System.Drawing.Color.White, Message.TopLeft), Program.Values);
}
}
else
{
if (previousPlace != Place)
{
updateTheClient = true;
}
}
if (updateTheClient || client.Player.UID == updateUID)
{
NobilityInfo update = new NobilityInfo(true);
update.Type = NobilityInfo.Icon;
update.dwParam = entry.EntityUID;
update.UpdateString(entry);
client.SendScreen(update, true);
client.Player.NobilityRank = entry.Rank;
}
}
sortedBoard.Add(entry.EntityUID, entry);
Place++;
}
catch { }
}
Board = sortedBoard;
lock (BoardList)
BoardList = Board.Values.ToList();
}
public static void Delet(Client.GameState client)
{
if (Game.ConquerStructures.Nobility.Board.ContainsKey(client.Player.UID))
{
Game.ConquerStructures.Nobility.Board.Remove(client.Player.UID);
Game.ConquerStructures.Nobility.Sort(0);
foreach (var clients in Program.GamePool)
{
if (Game.ConquerStructures.Nobility.Board.ContainsKey(clients.Player.UID))
Game.ConquerStructures.Nobility.Sort(client.Player.UID);
}
Database.MySqlCommand cmd = new Database.MySqlCommand(Database.MySqlCommandType.DELETE).Delete("nobility", "EntityUID", client.Player.UID);
cmd.Execute();
}
}
public static ulong cps { get; set; }
}
public class NobilityInformation
{
public string Name;
public uint EntityUID;
public uint Mesh;
public ulong Donation;
public byte Gender;
public int Position;
public NobilityRank Rank;
public bool king;
public DateTime KingDays;
}
public enum NobilityRank : byte
{
Serf = 0,
Knight = 1,
Baron = 3,
Earl = 5,
Duke = 7,
Prince = 9,
King = 12
}
}
|
الذين يشاهدون محتوى الموضوع الآن : 12 ( الأعضاء 0 والزوار 12) | |
|
الموضوع | كاتب الموضوع | المنتدى | مشاركات | آخر مشاركة |
اوتو باتش من بدايه حتي تحميل باتشات[من طلبات الاعضاء] | Tefa | البرامج والودرات | 115 | 2024-10-28 03:55 AM |
معايا باتش عايز اعدل عليه والي يعدلي عليه ياخد الي هو عايزه | zorom | مشكلات السيرفيرات كونكر الشخصيه | 4 | 2020-05-09 11:05 PM |
برجاء دخول ونبي و انا اسف اني نزلت هنا بس محدش بيرود عليه | احمد التركي | مشكلات السيرفيرات كونكر الشخصيه | 10 | 2020-04-27 03:01 PM |
مشكله محدش حلهالي صح | AhmedGadd | مشكلات السيرفيرات كونكر الشخصيه | 2 | 2020-04-15 05:24 PM |
حاجه بردو بخصوص ايفكت معين | uncelsam | مشكلات السيرفيرات كونكر الشخصيه | 5 | 2019-07-14 01:13 AM |