|
المشاركات 91 |
+التقييم 0.05 |
تاريخ التسجيل Sep 2019 |
الاقامة |
نظام التشغيل |
رقم العضوية 1363 |
using System;
using System.IO;
using System.Linq;
using Viorx.Client;
using System.Collections.Generic;
using Viorx.Network.GamePackets;
namespace Viorx.Game.ConquerStructures
{
public class Nobility : Network.Writer
{
public static SafeDictionary<uint, NobilityInformation> Board = new SafeDictionary<uint, NobilityInformation>(10000);
public static void Handle(NobilityInfo information, Client.GameState client)
{
switch (information.Type)
{
case NobilityInfo.Donate:
{
if (client.Trade.InTrade)
return;
if (client.Entity.PokerHack == true)
return;
ulong silvers = information.dwParam;
bool newDonator = false;
client.NobilityInformation.Gender = (byte)(client.Entity.Body % 10);
if (client.NobilityInformation.Donation == 0)
newDonator = true;
if (information.MoneyType == 1)
{
ulong cps = silvers / 1;
if (client.Entity.ConquerPoints >= cps)
{
client.Entity.ConquerPoints -= (uint)cps;
client.NobilityInformation.Donation += silvers;
}
}
else
{
if (client.Entity.Money >= silvers)
{
client.Entity.Money -= (ulong)silvers;
client.NobilityInformation.Donation += silvers;
}
}
if (!Board.ContainsKey(client.Entity.UID) && client.NobilityInformation.Donation == silvers && newDonator)
{
Board.Add(client.Entity.UID, client.NobilityInformation);
try
{
Database.NobilityTable.InsertNobilityInformation(c lient.NobilityInformation);
}
catch
{
Database.NobilityTable.UpdateNobilityInformation(c lient.NobilityInformation);
}
}
else
{
Database.NobilityTable.UpdateNobilityInformation(c lient.NobilityInformation);
}
Sort(client.Entity.UID);
break;
}
case NobilityInfo.List:
{
byte[] packet = new byte[608];
WriteUInt16((ushort)(packet.Length - 8), 0, packet);
WriteUInt16(2064, 2, packet);
WriteUInt16(2, 4, packet);
WriteUInt16((ushort)(Board.Count > 50 ? 5 : (Board.Count / 10) + 1), 10, packet);
int offset = 120;
ushort rank = 0;
rank = (ushort)(information.wParam1 * 10);
foreach (var entity in Board.Values.OrderByDescending(e => e.Donation).Skip(information.wParam1 * 10).Take(10))
{
WriteUInt32(entity.EntityUID, offset, packet);
offset += 4;
WriteUInt32(1, offset, packet);
offset += 4;
WriteUInt32(entity.Mesh, offset, packet);
offset += 4;
WriteString(entity.Name, offset, packet);
offset += 20;
WriteUInt64(entity.Donation, offset, packet);
offset += 8;
entity.Rank = getMyRank(entity.Donation, rank);
WriteUInt32((uint)entity.Rank, offset, packet);
offset += 4;
WriteUInt32((uint)rank, offset, packet);
offset += 4;
rank++;
}
WriteUInt16(rank, 12, packet);
client.Send(packet);
break;
}
}
}
private static void Sort(uint p)
{
throw new NotImplementedException();
}
private static NobilityRank getMyRank(ulong donation, int currentRank)
{
if (currentRank >= 0 && currentRank < 999999)
{
return NobilityRank.King;
}
else if (currentRank >= 10 && currentRank < 0)
{
return NobilityRank.Prince;
}
else if (currentRank >= 50 && currentRank < 0)
{
return NobilityRank.Duke;
}
else
{
return NobilityRank.Serf;
}
}
public static void Donate(ulong silvers, Client.GameState client)
{
bool newDonator = false;
client.NobilityInformation.Gender = (byte)(client.Entity.Body % 10);
if (client.NobilityInformation.Donation == 0) newDonator = true;
client.NobilityInformation.Donation += silvers;
int oldpos = client.NobilityInformation.Position;
if (!Board.ContainsKey(client.Entity.UID) && client.NobilityInformation.Donation == silvers && newDonator)
{
Board.Add(client.Entity.UID, client.NobilityInformation);
try
{
Database.NobilityTable.InsertNobilityInformation(c lient.NobilityInformation);
}
catch
{
Database.NobilityTable.UpdateNobilityInformation(c lient.NobilityInformation);
}
}
else
{
Database.NobilityTable.UpdateNobilityInformation(c lient.NobilityInformation);
}
updateOthers(oldpos, client);
}
private static void updateOthers(int oldPosition, GameState client)
{
int newpos = getPosition(client.Entity.UID);
var Rank = getMyRank(client.NobilityInformation.Donation, newpos);
if (oldPosition != newpos)
{
if (Rank == NobilityRank.King || Rank == NobilityRank.Prince || Rank == NobilityRank.Duke)
foreach (var p in Board.Values.OrderByDescending(e => e.Donation).Skip(newpos).Take(50 - newpos))
{
GameState cl = null;
if (Kernel.GamePool.TryGetValue(p.EntityUID, out cl))
SendIconToClient(cl);
}
}
SendIconToClient(client);
}
private static int getPosition(uint entityuid)
{
int currentPos = -1, post = -1;
if (Board.ContainsKey(entityuid))
{
foreach (var p in Board.Values.OrderByDescending(e => e.Donation))
{
currentPos++;
if (entityuid == p.EntityUID)
{
post = currentPos;
break;
}
}
}
return post;
}
public static void SendIconToClient(Client.GameState client)
{
if (client != null && client.NobilityInformation != null)
{
int pos = getPosition(client.Entity.UID);
client.Entity.NobilityRank = client.NobilityInformation.Rank = getMyRank(client.NobilityInformation.Donation, pos);
NobilityInfo update = new NobilityInfo(true);
update.Type = NobilityInfo.Icon;
update.dwParam = client.Entity.UID;
client.NobilityInformation.Position = pos;
update.UpdateString(client.NobilityInformation);
client.SendScreen(update, true);
}
}
}
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 enum NobilityRank : byte
{
Serf = 0,
Knight = 1,
Baron = 3,
Earl = 5,
Duke = 7,
Prince = 9,
King = 12,
}
}
الذين يشاهدون محتوى الموضوع الآن : 1 ( الأعضاء 0 والزوار 1) | |
|
الموضوع | كاتب الموضوع | المنتدى | مشاركات | آخر مشاركة |
حل لو سمحتو للمشكله دى | ابو مروان | مشكلات السيرفيرات كونكر الشخصيه | 4 | 2020-05-16 02:44 AM |
عايز حل للمشكله دى لانى غلبت فيها نجوم الاسلحه | ابو مروان | مشكلات السيرفيرات كونكر الشخصيه | 1 | 2020-05-07 10:51 AM |
ياريت حل للمشكله دى تبع سورس Rayzo | koko1 | مشكلات السيرفيرات كونكر الشخصيه | 3 | 2020-04-21 11:17 AM |
حل للمشكله دي يشباب مجناني خش وافهم | uncelsam | مشكلات السيرفيرات كونكر الشخصيه | 5 | 2020-02-25 03:52 PM |
حل للمشكله دى يرجاله معلش | taha | مشكلات السيرفيرات كونكر الشخصيه | 6 | 2019-11-29 03:11 PM |