Пример #1
0
        public static void DonateCPs(Entities.GameClient client, long Amount)
        {
            uint cps = (uint)(Amount / 50000);

            if (client.CPs < cps)
            {
                return;
            }
            if (Amount < 3000000)
            {
                return;
            }
            if (Amount > 999999999)
            {
                return;
            }

            if (Donations.ContainsKey(client.DatabaseUID))
            {
                NobilityDonation donation;
                if (Donations.TryGetValue(client.DatabaseUID, out donation))
                {
                    if (donation.Donation >= Core.NumericConst.MaxNobilityDonation)
                    {
                        return;
                    }
                    client.CPs       -= cps;
                    donation.Donation = Math.Min(Core.NumericConst.MaxNobilityDonation, (long)(donation.Donation + Amount));
                    GetTop50();

                    client.SendNobility();

                    donation.UpdateDonation();
                }
            }
            else
            {
                client.CPs -= cps;

                NobilityDonation donation = new NobilityDonation();
                donation.Rank     = Enums.NobilityRank.Serf;
                donation.Donation = Amount;
                if (Donations.TryAdd(client.DatabaseUID, donation))
                {
                    donation.DatabaseID = client.DatabaseUID;
                    donation.Name       = client.Name;
                    donation.Client     = client;
                    client.Nobility     = donation;
                    GetTop50();

                    client.SendNobility();

                    donation.CreateDatabase();
                    donation.UpdateDonation();
                }
            }
        }
Пример #2
0
        public static void Donate(Entities.GameClient client, long Amount)
        {
            if (client.Money < Amount)
                return;
            if (Amount < 3000000)
                return;
            if (Amount > 999999999)
                return;

            if (Donations.ContainsKey(client.DatabaseUID))
            {
                NobilityDonation donation;
                if (Donations.TryGetValue(client.DatabaseUID, out donation))
                {
                    if (donation.Donation >= Core.NumericConst.MaxNobilityDonation)
                        return;

                    client.Money -= (uint)Amount;
                    donation.Donation = Math.Min(Core.NumericConst.MaxNobilityDonation, (long)(donation.Donation + Amount));
                    GetTop50();

                    client.SendNobility();

                    donation.UpdateDonation();
                }
            }
            else
            {
                NobilityDonation donation = new NobilityDonation();
                donation.Rank = Enums.NobilityRank.Serf;
                donation.Donation = Amount;
                if (Donations.TryAdd(client.DatabaseUID, donation))
                {
                    client.Money -= (uint)Amount;
                    donation.DatabaseID = client.DatabaseUID;
                    donation.Name = client.Name;
                    donation.Client = client;
                    client.Nobility = donation;
                    GetTop50();

                    client.SendNobility();

                    donation.CreateDatabase();
                    donation.UpdateDonation();
                }
            }
        }
Пример #3
0
        public static NobilityDonation[] GetPage(int page, out int PageMax)
        {
            ConcurrentDictionary <int, NobilityDonation> Donations = NobilityBoard.Donations;

            PageMax = 0;
            if (Donations.Count == 0)
            {
                return(null);
            }
            if (page > 5 || page < 0)
            {
                return(null);
            }

            PageMax = (Donations.Count / 10);
            if (page <= PageMax)
            {
                NobilityDonation[] Page         = new NobilityDonation[10];
                NobilityDonation[] TopDonations = GetTop50();
                int counter      = 0;
                int to_counter   = ((page + 1) * 10);
                int from_counter = (to_counter - 10);
                for (int i = from_counter; i < to_counter; i++)
                {
                    if (TopDonations[i] != null)
                    {
                        Page[counter] = TopDonations[i];
                    }
                    counter++;
                }
                int realsize = 0;
                foreach (var n in Page)
                {
                    if (n != null)
                    {
                        realsize++;
                    }
                }
                Array.Resize(ref Page, realsize);
                return(Page);
            }
            return(null);
        }
Пример #4
0
        public static NobilityDonation[] GetTop50()
        {
            System.Collections.Generic.KeyValuePair <int, NobilityDonation>[]
            OrderDonations = Donations.OrderBy(don => don.Value.Donation).ToArray();

            Array.Reverse(OrderDonations);

            NobilityDonation[] TopDonation = new NobilityDonation[50];
            for (int i = 0; i < OrderDonations.Length; i++)
            {
                OrderDonations[i].Value.OldRank = OrderDonations[i].Value.Rank;

                if (i < 3)
                {
                    TopDonation[i]      = OrderDonations[i].Value;
                    TopDonation[i].Rank = Enums.NobilityRank.King;
                }
                else if (i < 15)
                {
                    TopDonation[i]      = OrderDonations[i].Value;
                    TopDonation[i].Rank = Enums.NobilityRank.Prince;
                }
                else if (i < 50)
                {
                    TopDonation[i]      = OrderDonations[i].Value;
                    TopDonation[i].Rank = Enums.NobilityRank.Duke;
                }
                else
                {
                    if (OrderDonations[i].Value.Donation >= 200000000)
                    {
                        OrderDonations[i].Value.Rank = Enums.NobilityRank.Earl;
                    }
                    else if (OrderDonations[i].Value.Donation >= 100000000)
                    {
                        OrderDonations[i].Value.Rank = Enums.NobilityRank.Baron;
                    }
                    else if (OrderDonations[i].Value.Donation >= 30000000)
                    {
                        OrderDonations[i].Value.Rank = Enums.NobilityRank.Knight;
                    }
                }
                OrderDonations[i].Value.Ranking = i;

                if (OrderDonations[i].Value.Client != null && OrderDonations[i].Value.OldRank != OrderDonations[i].Value.Rank)
                {
                    switch (OrderDonations[i].Value.Rank)
                    {
                    case Enums.NobilityRank.King:
                    {
                        if (OrderDonations[i].Value.Client.Sex == Enums.Sex.Male)
                        {
                            using (var msg = Packets.Message.MessageCore.CreateCenter(
                                       string.Format(Core.MessageConst.NEW_KING, OrderDonations[i].Value.Client.Name)))
                            {
                                Packets.Message.MessageCore.SendGlobalMessage(msg);
                            }
                        }
                        else
                        {
                            using (var msg = Packets.Message.MessageCore.CreateCenter(
                                       string.Format(Core.MessageConst.NEW_QUEEN, OrderDonations[i].Value.Client.Name)))
                            {
                                Packets.Message.MessageCore.SendGlobalMessage(msg);
                            }
                        }
                        break;
                    }

                    case Enums.NobilityRank.Prince:
                    {
                        if (OrderDonations[i].Value.Client.Sex == Enums.Sex.Male)
                        {
                            using (var msg = Packets.Message.MessageCore.CreateCenter(
                                       string.Format(Core.MessageConst.NEW_PRINCE, OrderDonations[i].Value.Client.Name)))
                            {
                                Packets.Message.MessageCore.SendGlobalMessage(msg);
                            }
                        }
                        else
                        {
                            using (var msg = Packets.Message.MessageCore.CreateCenter(
                                       string.Format(Core.MessageConst.NEW_PRINCESS, OrderDonations[i].Value.Client.Name)))
                            {
                                Packets.Message.MessageCore.SendGlobalMessage(msg);
                            }
                        }
                        break;
                    }
                    }
                    OrderDonations[i].Value.Client.SendNobility();
                }
            }
            return(TopDonation);
        }
Пример #5
0
 public static bool AddNobility(NobilityDonation donation)
 {
     return(Donations.TryAdd(donation.DatabaseID, donation));
 }
Пример #6
0
 public static NobilityDonation[] GetTop3()
 {
     NobilityDonation[] TopDonations = new NobilityDonation[3];
     System.Buffer.BlockCopy(GetTop50(), 0, TopDonations, 0, 3);
     return(TopDonations);
 }
Пример #7
0
 public static bool AddNobility(NobilityDonation donation)
 {
     return Donations.TryAdd(donation.DatabaseID, donation);
 }
Пример #8
0
        public static NobilityDonation[] GetTop50()
        {
            System.Collections.Generic.KeyValuePair<int, NobilityDonation>[]
                OrderDonations = Donations.OrderBy(don => don.Value.Donation).ToArray();

            Array.Reverse(OrderDonations);

            NobilityDonation[] TopDonation = new NobilityDonation[50];
            for (int i = 0; i < OrderDonations.Length; i++)
            {
                OrderDonations[i].Value.OldRank = OrderDonations[i].Value.Rank;

                if (i < 3)
                {
                    TopDonation[i] = OrderDonations[i].Value;
                    TopDonation[i].Rank = Enums.NobilityRank.King;
                }
                else if (i < 15)
                {
                    TopDonation[i] = OrderDonations[i].Value;
                    TopDonation[i].Rank = Enums.NobilityRank.Prince;
                }
                else if (i < 50)
                {
                    TopDonation[i] = OrderDonations[i].Value;
                    TopDonation[i].Rank = Enums.NobilityRank.Duke;
                }
                else
                {
                    if (OrderDonations[i].Value.Donation >= 200000000)
                            OrderDonations[i].Value.Rank = Enums.NobilityRank.Earl;
                        else if (OrderDonations[i].Value.Donation >= 100000000)
                            OrderDonations[i].Value.Rank = Enums.NobilityRank.Baron;
                        else if (OrderDonations[i].Value.Donation >= 30000000)
                            OrderDonations[i].Value.Rank = Enums.NobilityRank.Knight;
                }
                OrderDonations[i].Value.Ranking = i;

                if (OrderDonations[i].Value.Client != null && OrderDonations[i].Value.OldRank != OrderDonations[i].Value.Rank)
                {
                    switch (OrderDonations[i].Value.Rank)
                    {
                        case Enums.NobilityRank.King:
                            {
                                if (OrderDonations[i].Value.Client.Sex == Enums.Sex.Male)
                                {
                                    using (var msg = Packets.Message.MessageCore.CreateCenter(
                                        string.Format(Core.MessageConst.NEW_KING, OrderDonations[i].Value.Client.Name)))
                                    {
                                        Packets.Message.MessageCore.SendGlobalMessage(msg);
                                    }
                                }
                                else
                                {
                                    using (var msg = Packets.Message.MessageCore.CreateCenter(
                                        string.Format(Core.MessageConst.NEW_QUEEN, OrderDonations[i].Value.Client.Name)))
                                    {
                                        Packets.Message.MessageCore.SendGlobalMessage(msg);
                                    }
                                }
                                break;
                            }
                        case Enums.NobilityRank.Prince:
                            {
                                if (OrderDonations[i].Value.Client.Sex == Enums.Sex.Male)
                                {
                                    using (var msg = Packets.Message.MessageCore.CreateCenter(
                                        string.Format(Core.MessageConst.NEW_PRINCE, OrderDonations[i].Value.Client.Name)))
                                    {
                                        Packets.Message.MessageCore.SendGlobalMessage(msg);
                                    }
                                }
                                else
                                {
                                    using (var msg = Packets.Message.MessageCore.CreateCenter(
                                        string.Format(Core.MessageConst.NEW_PRINCESS, OrderDonations[i].Value.Client.Name)))
                                    {
                                        Packets.Message.MessageCore.SendGlobalMessage(msg);
                                    }
                                }
                                break;
                            }
                    }
                    OrderDonations[i].Value.Client.SendNobility();
                }
            }
            return TopDonation;
        }
Пример #9
0
 public static NobilityDonation[] GetTop3()
 {
     NobilityDonation[] TopDonations = new NobilityDonation[3];
     System.Buffer.BlockCopy(GetTop50(), 0, TopDonations, 0, 3);
     return TopDonations;
 }
Пример #10
0
        public static NobilityDonation[] GetPage(int page, out int PageMax)
        {
            ConcurrentDictionary<int, NobilityDonation> Donations = NobilityBoard.Donations;

            PageMax = 0;
            if (Donations.Count == 0)
                return null;
            if (page > 5 || page < 0)
                return null;

            PageMax = (Donations.Count / 10);
            if (page <= PageMax)
            {
                NobilityDonation[] Page = new NobilityDonation[10];
                NobilityDonation[] TopDonations = GetTop50();
                int counter = 0;
                int to_counter = ((page + 1) * 10);
                int from_counter = (to_counter - 10);
                for (int i = from_counter; i < to_counter; i++)
                {
                    if (TopDonations[i] != null)
                    {
                        Page[counter] = TopDonations[i];
                    }
                    counter++;
                }
                int realsize = 0;
                foreach (var n in Page)
                {
                    if (n != null)
                        realsize++;
                }
                Array.Resize(ref Page, realsize);
                return Page;
            }
            return null;
        }