Example #1
0
 protected void AddDuke(Character givenDuke)
 {
     using (Database.DatabaseManager db = new Database.DatabaseManager())
     {
         Nobility currentTitle = new Nobility(this, givenDuke, Title.Duke);
         db.SaveChanges();
     }
 }
Example #2
0
 public void Coronate(Character givenKing)
 {
     using (Database.DatabaseManager db = new Database.DatabaseManager())
     {
         Nobility currentTitle = new Nobility(this, givenKing, Title.King);
         db.SaveChanges();
     }
 }
Example #3
0
 private void SetEmperor(Character givenEmperor)
 {
     using (Database.DatabaseManager db = new Database.DatabaseManager())
     {
         Nobility currentTitle = new Nobility(this, givenEmperor, Title.Emperor);
         db.SaveChanges();
     }
 }
        public static void UpdatePlayers()
        {
            Nobility packet;

            foreach (var player in PlayerManager.Players)
            {
                packet = Nobility.UpdateIcon(player.Value);
                player.Value.Send(packet);
            }
        }
Example #5
0
        public static void HandleNobility(Character pRole, MsgPeerage pMsg)
        {
            switch (pMsg.Action)
            {
                #region List
            case NobilityAction.LIST:
            {
                int maxPages   = 5;
                int page       = pMsg.Data;
                int maxPerPage = 10;
                int value      = 0;
                int amount     = 0;

                int minValue = page * maxPerPage;
                int maxValue = (page + 1) * maxPerPage;

                MsgPeerage nPacket = new MsgPeerage(32 + 48);
                nPacket.Action = NobilityAction.LIST;
                ushort maxCount = (ushort)Math.Ceiling((double)ServerKernel.Nobility.Count / 10);
                nPacket.DataShort = (ushort)(maxCount > maxPages ? maxPages : maxCount);

                foreach (DbDynaRankRec dynaRank in ServerKernel.Nobility.Values.OrderByDescending(x => x.Value))
                {
                    if (value >= maxPages * maxPerPage)
                    {
                        break;
                    }

                    if (value < minValue)
                    {
                        value++;
                        continue;
                    }
                    if (value >= maxValue)
                    {
                        break;
                    }

                    uint   lookface = 0;
                    Client pPlayer  = ServerKernel.Players.Values.FirstOrDefault(x => x.Identity == dynaRank.UserIdentity);
                    if (pPlayer != null && pPlayer.Character != null)
                    {
                        lookface = pPlayer.Character.Body;
                    }

                    NobilityLevel rank = Nobility.GetNobilityLevel((uint)value);

                    nPacket.WriteNobilityData(dynaRank.UserIdentity, lookface, dynaRank.Username,
                                              dynaRank.Value, rank, value);
                    value++;
                    amount++;
                }

                nPacket.DataHighLow = (ushort)amount;

                nPacket.WriteByte((byte)amount, 28);
                pRole.Send(nPacket);
                break;
            }

                #endregion
                #region Query Remaining Silver
            case NobilityAction.QUERY_REMAINING_SILVER:
            {
                var nPacket = new MsgPeerage
                {
                    Action   = NobilityAction.QUERY_REMAINING_SILVER,
                    DataLong = GetRemainingSilver((NobilityLevel)pMsg.Data,
                                                  pRole.NobilityDonation),
                    Data3 = 60,         // The max amount of players in the ranking
                    Data4 = (uint)pRole.Nobility.Level
                };
                pRole.Send(nPacket);
                break;
            }

                #endregion
                #region Donate
            case NobilityAction.DONATE:
            {
                if (pRole.Level < 70)
                {
                    pRole.Send(ServerString.STR_PEERAGE_DONATE_ERR_BELOW_LEVEL);
                    return;
                }

                long donation = pMsg.DataLong;

                if (donation < 3000000)
                {
                    pRole.Send(ServerString.STR_PEERAGE_DONATE_ERR_BELOW_UNDERLINE);
                    return;
                }

                if (donation > int.MaxValue)
                {
                    donation = int.MaxValue;
                }

                NobilityLevel oldRank = pRole.NobilityRank;
                int           oldPos  = pRole.Nobility.GetRanking;

                // donate cps
                if (pMsg.Data2 >= 1)
                {
                    uint cps = (uint)donation / 50000;
                    if (cps > pRole.Emoney)
                    {
                        pRole.Send(ServerString.STR_NOT_ENOUGH_EMONEY);
                        return;
                    }

                    if (!pRole.ReduceEmoney(cps, true))
                    {
                        return;
                    }

                    pRole.Nobility.Donate(donation);
                    //pRole.Send("You can only donate silvers to the empire.");
                    //return;
                }
                if (pMsg.Data2 == 0)         // donate silvers
                {
                    if (!pRole.ReduceMoney(donation, true))
                    {
                        return;
                    }

                    pRole.Nobility.Donate(donation);
                }

                if (!ServerKernel.Nobility.ContainsKey(pRole.Identity))
                {
                    ServerKernel.Nobility.TryAdd(pRole.Identity, pRole.Nobility.Database);
                }

                pRole.Nobility.UpdateRanking();
                pRole.Nobility.UpdateLevel();

                if (pRole.NobilityRank > NobilityLevel.EARL && oldPos > pRole.Nobility.GetRanking)
                {
                    foreach (var plr in ServerKernel.Players.Values.Where(x => x.Character.NobilityRank > NobilityLevel.EARL))
                    {
                        plr.Character.Nobility.SendNobilityIcon();
                    }
                }
                else if (pRole.NobilityRank > NobilityLevel.EARL)
                {
                    pRole.Nobility.SendNobilityIcon();
                }

                if (pRole.NobilityRank > oldRank)
                {
                    switch (pRole.NobilityRank)
                    {
                    case NobilityLevel.KING:
                        if (pRole.Gender == 1)
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_KING, pRole.Name), ChatTone.CENTER);
                        }
                        else
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_QUEEN, pRole.Name), ChatTone.CENTER);
                        }
                        break;

                    case NobilityLevel.PRINCE:
                        if (pRole.Gender == 1)
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_DUKE, pRole.Name), ChatTone.CENTER);
                        }
                        else
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_DUCHESS, pRole.Name), ChatTone.CENTER);
                        }
                        break;

                    case NobilityLevel.DUKE:
                        if (pRole.Gender == 1)
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_MARQUIS, pRole.Name), ChatTone.CENTER);
                        }
                        else
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_MARQUISE, pRole.Name), ChatTone.CENTER);
                        }
                        break;

                    case NobilityLevel.EARL:
                        if (pRole.Gender == 1)
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_EARL, pRole.Name), ChatTone.TOP_LEFT);
                        }
                        else
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_COUNTESS, pRole.Name), ChatTone.TOP_LEFT);
                        }
                        break;

                    case NobilityLevel.BARON:
                        if (pRole.Gender == 1)
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_VISCOUNT, pRole.Name), ChatTone.TOP_LEFT);
                        }
                        else
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_VISCOUNTESS, pRole.Name), ChatTone.TOP_LEFT);
                        }
                        break;

                    case NobilityLevel.KNIGHT:
                        if (pRole.Gender == 1)
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_BARON, pRole.Name), ChatTone.TOP_LEFT);
                        }
                        else
                        {
                            ServerKernel.SendMessageToAll(string.Format(ServerString.STR_PEERAGE_PROMPT_BARONESS, pRole.Name), ChatTone.TOP_LEFT);
                        }
                        break;
                    }
                }
                break;
            }
                #endregion
            }
        }