Example #1
0
        public ReadyGump(Mobile from, DuelContext context, int count) : base(50, 50)
        {
            m_From    = from;
            m_Context = context;
            m_Count   = count;

            ArrayList parts = context.Participants;

            int height = 25 + 20;

            for (int i = 0; i < parts.Count; ++i)
            {
                Participant p = (Participant)parts[i];

                height += 4;

                if (p.Players.Length > 1)
                {
                    height += 22;
                }

                height += (p.Players.Length * 22);
            }

            height += 25;

            Closable = false;
            Dragable = false;

            AddPage(0);

            AddBackground(0, 0, 260, height, 9250);
            AddBackground(10, 10, 240, height - 20, 0xDAC);

            if (count == -1)
            {
                AddHtml(35, 25, 190, 20, Center("Ready"), false, false);
            }
            else
            {
                AddHtml(35, 25, 190, 20, Center("Starting"), false, false);
                AddHtml(35, 25, 190, 20, "<DIV ALIGN=RIGHT>" + count.ToString(), false, false);
            }

            int y = 25 + 20;

            for (int i = 0; i < parts.Count; ++i)
            {
                Participant p = (Participant)parts[i];

                y += 4;

                bool isAllReady = true;
                int  yStore     = y;
                int  offset     = 0;

                if (p.Players.Length > 1)
                {
                    AddHtml(35 + 14, y, 176, 20, String.Format("Participant #{0}", i + 1), false, false);
                    y     += 22;
                    offset = 10;
                }

                for (int j = 0; j < p.Players.Length; ++j)
                {
                    DuelPlayer pl = p.Players[j];

                    if (pl != null && pl.Ready)
                    {
                        AddImage(35 + offset, y + 4, 0x939);
                    }
                    else
                    {
                        AddImage(35 + offset, y + 4, 0x938);
                        isAllReady = false;
                    }

                    string name = (pl == null ? "(Empty)" : pl.Mobile.Name);

                    AddHtml(35 + offset + 14, y, 166, 20, name, false, false);

                    y += 22;
                }

                if (p.Players.Length > 1)
                {
                    AddImage(35, yStore + 4, isAllReady ? 0x939 : 0x938);
                }
            }
        }
        private void Finish_Callback()
        {
            ArrayList teams = new ArrayList();

            for (int i = 0; i < m_Context.Participants.Count; ++i)
            {
                KHTeamInfo teamInfo = m_Controller.TeamInfo[i % m_Controller.TeamInfo.Length];

                if (teamInfo == null)
                {
                    continue;
                }

                teams.Add(teamInfo);
            }

            teams.Sort();

            Tournament tourny = m_Context.m_Tournament;

            StringBuilder sb = new StringBuilder();

            if (tourny != null && tourny.TournyType == TournyType.FreeForAll)
            {
                sb.Append(m_Context.Participants.Count * tourny.PlayersPerParticipant);
                sb.Append("-man FFA");
            }
            else if (tourny != null && tourny.TournyType == TournyType.RandomTeam)
            {
                sb.Append(tourny.ParticipantsPerMatch);
                sb.Append("-team");
            }
            else if (tourny != null && tourny.TournyType == TournyType.RedVsBlue)
            {
                sb.Append("Red v Blue");
            }
            else if (tourny != null)
            {
                for (int i = 0; i < tourny.ParticipantsPerMatch; ++i)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append('v');
                    }

                    sb.Append(tourny.PlayersPerParticipant);
                }
            }

            if (m_Controller != null)
            {
                sb.Append(' ').Append(m_Controller.Title);
            }

            string title = sb.ToString();

            KHTeamInfo winner = (KHTeamInfo)(teams.Count > 0 ? teams[0] : null);

            for (int i = 0; i < teams.Count; ++i)
            {
                TrophyRank rank = TrophyRank.Bronze;

                if (i == 0)
                {
                    rank = TrophyRank.Gold;
                }
                else if (i == 1)
                {
                    rank = TrophyRank.Silver;
                }

                KHPlayerInfo leader = ((KHTeamInfo)teams[i]).Leader;

                foreach (KHPlayerInfo pl in ((KHTeamInfo)teams[i]).Players.Values)
                {
                    Mobile mob = pl.Player;

                    if (mob == null)
                    {
                        continue;
                    }

                    sb = new StringBuilder();

                    sb.Append(title);

                    if (pl == leader)
                    {
                        sb.Append(" Leader");
                    }

                    if (pl.Score > 0)
                    {
                        sb.Append(": ");

                        sb.Append(pl.Score.ToString("N0"));
                        sb.Append(pl.Score == 1 ? " point" : " points");

                        sb.Append(", ");
                        sb.Append(pl.Kills.ToString("N0"));
                        sb.Append(pl.Kills == 1 ? " kill" : " kills");

                        if (pl.Captures > 0)
                        {
                            sb.Append(", ");
                            sb.Append(pl.Captures.ToString("N0"));
                            sb.Append(pl.Captures == 1 ? " capture" : " captures");
                        }
                    }

                    Item item = new Trophy(sb.ToString(), rank);

                    if (pl == leader)
                    {
                        item.ItemID = 4810;
                    }

                    item.Name = String.Format("{0}, {1}", item.Name, ((KHTeamInfo)teams[i]).Name.ToLower());

                    if (!mob.PlaceInBackpack(item))
                    {
                        mob.BankBox.DropItem(item);
                    }

                    int cash = pl.Score * 250;

                    if (cash > 0)
                    {
                        item = new BankCheck(cash);

                        if (!mob.PlaceInBackpack(item))
                        {
                            mob.BankBox.DropItem(item);
                        }

                        mob.SendMessage("You have been awarded a {0} trophy and {1:N0}gp for your participation in this game.", rank.ToString().ToLower(), cash);
                    }
                    else
                    {
                        mob.SendMessage("You have been awarded a {0} trophy for your participation in this game.", rank.ToString().ToLower());
                    }
                }
            }

            for (int i = 0; i < m_Context.Participants.Count; ++i)
            {
                Participant p = m_Context.Participants[i] as Participant;

                if (p == null || p.Players == null)
                {
                    continue;
                }

                for (int j = 0; j < p.Players.Length; ++j)
                {
                    DuelPlayer dp = p.Players[j];

                    if (dp != null && dp.Mobile != null)
                    {
                        dp.Mobile.CloseGump(typeof(KHBoardGump));
                        dp.Mobile.SendGump(new KHBoardGump(dp.Mobile, this));
                    }
                }

                if (i == winner.TeamID)
                {
                    continue;
                }

                if (p != null && p.Players != null)
                {
                    for (int j = 0; j < p.Players.Length; ++j)
                    {
                        if (p.Players[j] != null)
                        {
                            p.Players[j].Eliminated = true;
                        }
                    }
                }
            }

            m_Context.Finish(m_Context.Participants[winner.TeamID] as Participant);
        }