public override void OnMovement(Mobile m, Point3D oldLocation)
        {
            base.OnMovement(m, oldLocation);

            Tournament tourney = Tournament?.Tournament;

            if (InRange(m, 4) && !InRange(oldLocation, 4) && tourney != null && tourney.Stage == TournamentStage.Signup &&
                m.CanBeginAction(this))
            {
                Ladder ladder = Ladder.Instance;

                LadderEntry entry = ladder?.Find(m);

                if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement)
                {
                    return;
                }

                if (tourney.IsFactionRestricted && Faction.Find(m) == null)
                {
                    return;
                }

                if (tourney.HasParticipant(m))
                {
                    return;
                }

                PrivateOverheadMessage(MessageType.Regular, 0x35, false,
                                       $"Hello m'{(m.Female ? "Lady" : "Lord")}. Dost thou wish to enter this tournament? You need only to write your name in this book.",
                                       m.NetState);
                m.BeginAction(this);
                Timer.DelayCall(TimeSpan.FromSeconds(10.0), ReleaseLock_Callback, m);
            }
        }
Esempio n. 2
0
        public ArenaGump(Mobile from, ArenasMoongate gate) : base(50, 50)
        {
            m_From   = from;
            m_Gate   = gate;
            m_Arenas = Arena.Arenas;

            AddPage(0);

            int height = 12 + 20 + (m_Arenas.Count * 31) + 24 + 12;

            AddBackground(0, 0, 499 + 40, height, 0x2436);

            List <Arena> list = m_Arenas;

            for (int i = 1; i < list.Count; i += 2)
            {
                AddImageTiled(12, 32 + (i * 31), 475 + 40, 30, 0x2430);
            }

            AddAlphaRegion(10, 10, 479 + 40, height - 20);

            AddColumnHeader(35, null);
            AddColumnHeader(115, "Arena");
            AddColumnHeader(325, "Participants");
            AddColumnHeader(40, "Obs");

            AddButton(499 + 40 - 12 - 63 - 4 - 63, height - 12 - 24, 247, 248, 1, GumpButtonType.Reply, 0);
            AddButton(499 + 40 - 12 - 63, height - 12 - 24, 241, 242, 2, GumpButtonType.Reply, 0);

            for (int i = 0; i < list.Count; ++i)
            {
                Arena ar = list[i];

                string name = ar.Name;

                if (name == null)
                {
                    name = "(no name)";
                }

                int x = 12;
                int y = 32 + (i * 31);

                int color = (ar.Players.Count > 0 ? 0xCCFFCC : 0xCCCCCC);

                AddRadio(x + 3, y + 1, 9727, 9730, false, i);
                x += 35;

                AddBorderedText(x + 5, y + 5, 115 - 5, name, color, 0);
                x += 115;

                StringBuilder sb = new StringBuilder();

                if (ar.Players.Count > 0)
                {
                    Ladder ladder = Ladder.Instance;

                    if (ladder == null)
                    {
                        continue;
                    }

                    LadderEntry p1 = null, p2 = null, p3 = null, p4 = null;

                    for (int j = 0; j < ar.Players.Count; ++j)
                    {
                        Mobile      mob = ar.Players[j];
                        LadderEntry c   = ladder.Find(mob);

                        if (p1 == null || c.Index < p1.Index)
                        {
                            p4 = p3;
                            p3 = p2;
                            p2 = p1;
                            p1 = c;
                        }
                        else if (p2 == null || c.Index < p2.Index)
                        {
                            p4 = p3;
                            p3 = p2;
                            p2 = c;
                        }
                        else if (p3 == null || c.Index < p3.Index)
                        {
                            p4 = p3;
                            p3 = c;
                        }
                        else if (p4 == null || c.Index < p4.Index)
                        {
                            p4 = c;
                        }
                    }

                    Append(sb, p1);
                    Append(sb, p2);
                    Append(sb, p3);
                    Append(sb, p4);

                    if (ar.Players.Count > 4)
                    {
                        sb.Append(", ...");
                    }
                }
                else
                {
                    sb.Append("Empty");
                }

                AddBorderedText(x + 5, y + 5, 325 - 5, sb.ToString(), color, 0);
                x += 325;

                AddBorderedText(x, y + 5, 40, Center(ar.Spectators.ToString()), color, 0);
            }
        }
Esempio n. 3
0
        public TournamentBracketGump(Mobile from, Tournament tourney, TourneyBracketGumpType type,
                                     List <object> list = null, int page = 0, object obj = null) : base(50, 50)
        {
            m_From       = from;
            m_Tournament = tourney;
            m_Type       = type;
            m_List       = list;
            m_Page       = page;
            m_Object     = obj;
            m_PerPage    = 12;

            switch (type)
            {
            case TourneyBracketGumpType.Index:
            {
                AddPage(0);
                AddBackground(0, 0, 300, 300, 9380);

                StringBuilder sb = new StringBuilder();

                if (tourney.TourneyType == TourneyType.FreeForAll)
                {
                    sb.Append("FFA");
                }
                else if (tourney.TourneyType == TourneyType.RandomTeam)
                {
                    sb.Append(tourney.ParticipantsPerMatch);
                    sb.Append("-Team");
                }
                else if (tourney.TourneyType == TourneyType.RedVsBlue)
                {
                    sb.Append("Red v Blue");
                }
                else if (tourney.TourneyType == TourneyType.Faction)
                {
                    sb.Append(tourney.ParticipantsPerMatch);
                    sb.Append("-Team Faction");
                }
                else
                {
                    for (int i = 0; i < tourney.ParticipantsPerMatch; ++i)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append('v');
                        }

                        sb.Append(tourney.PlayersPerParticipant);
                    }
                }

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

                sb.Append(" Tournament Bracket");

                AddHtml(25, 35, 250, 20, Center(sb.ToString()));

                AddRightArrow(25, 53, ToButtonID(0, 4), "Rules");
                AddRightArrow(25, 71, ToButtonID(0, 1), "Participants");

                if (m_Tournament.Stage == TournamentStage.Signup)
                {
                    TimeSpan until = m_Tournament.SignupStart + m_Tournament.SignupPeriod - DateTime.UtcNow;
                    string   text;
                    int      secs = (int)until.TotalSeconds;

                    if (secs > 0)
                    {
                        int mins = secs / 60;
                        secs %= 60;

                        if (mins > 0 && secs > 0)
                        {
                            text =
                                $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")} and {secs} second{(secs == 1 ? "" : "s")}.";
                        }
                        else if (mins > 0)
                        {
                            text = $"The tournament will begin in {mins} minute{(mins == 1 ? "" : "s")}.";
                        }
                        else if (secs > 0)
                        {
                            text = $"The tournament will begin in {secs} second{(secs == 1 ? "" : "s")}.";
                        }
                        else
                        {
                            text = "The tournament will begin shortly.";
                        }
                    }
                    else
                    {
                        text = "The tournament will begin shortly.";
                    }

                    AddHtml(25, 92, 250, 40, text);
                }
                else
                {
                    AddRightArrow(25, 89, ToButtonID(0, 2), "Rounds");
                }

                break;
            }

            case TourneyBracketGumpType.Rules_Info:
            {
                Ruleset ruleset = tourney.Ruleset;
                Ruleset basedef = ruleset.Base;

                BitArray defs;

                if (ruleset.Flavors.Count > 0)
                {
                    defs = new BitArray(basedef.Options);

                    for (int i = 0; i < ruleset.Flavors.Count; ++i)
                    {
                        defs.Or(ruleset.Flavors[i].Options);
                    }
                }
                else
                {
                    defs = basedef.Options;
                }

                int changes = 0;

                BitArray opts = ruleset.Options;

                for (int i = 0; i < opts.Length; ++i)
                {
                    if (defs[i] != opts[i])
                    {
                        ++changes;
                    }
                }

                AddPage(0);
                AddBackground(0, 0, 300,
                              60 + 18 + 20 + 20 + 20 + 8 + 20 + ruleset.Flavors.Count * 18 + 4 + 20 + changes * 22 + 6, 9380);

                AddLeftArrow(25, 11, ToButtonID(0, 0));
                AddHtml(25, 35, 250, 20, Center("Rules"));

                int y = 53;

                var groupText = tourney.GroupType switch
                {
                    GroupingType.HighVsLow => "High vs Low",
                    GroupingType.Nearest => "Closest opponent",
                    GroupingType.Random => "Random",
                    _ => null
                };

                AddHtml(35, y, 190, 20, $"Grouping: {groupText}");
                y += 20;

                var tieText = tourney.TieType switch
                {
                    TieType.Random => "Random",
                    TieType.Highest => "Highest advances",
                    TieType.Lowest => "Lowest advances",
                    TieType.FullAdvancement => (tourney.ParticipantsPerMatch == 2 ? "Both advance" : "Everyone advances"),
                    TieType.FullElimination => (tourney.ParticipantsPerMatch == 2 ? "Both eliminated" : "Everyone eliminated"),
                    _ => null
                };

                AddHtml(35, y, 190, 20, $"Tiebreaker: {tieText}");
                y += 20;

                string sdText = "Off";

                if (tourney.SuddenDeath > TimeSpan.Zero)
                {
                    sdText = $"{(int)tourney.SuddenDeath.TotalMinutes}:{tourney.SuddenDeath.Seconds:D2}";

                    if (tourney.SuddenDeathRounds > 0)
                    {
                        sdText = $"{sdText} (first {tourney.SuddenDeathRounds} rounds)";
                    }
                    else
                    {
                        sdText = $"{sdText} (all rounds)";
                    }
                }

                AddHtml(35, y, 240, 20, $"Sudden Death: {sdText}");
                y += 20;

                y += 8;

                AddHtml(35, y, 190, 20, $"Ruleset: {basedef.Title}");
                y += 20;

                for (int i = 0; i < ruleset.Flavors.Count; ++i, y += 18)
                {
                    AddHtml(35, y, 190, 20, $" + {ruleset.Flavors[i].Title}");
                }

                y += 4;

                if (changes > 0)
                {
                    AddHtml(35, y, 190, 20, "Modifications:");
                    y += 20;

                    for (int i = 0; i < opts.Length; ++i)
                    {
                        if (defs[i] != opts[i])
                        {
                            string name = ruleset.Layout.FindByIndex(i);

                            if (name != null) // sanity
                            {
                                AddImage(35, y, opts[i] ? 0xD3 : 0xD2);
                                AddHtml(60, y, 165, 22, name);
                            }

                            y += 22;
                        }
                    }
                }
                else
                {
                    AddHtml(35, y, 190, 20, "Modifications: None");
                }

                break;
            }

            case TourneyBracketGumpType.Participant_List:
            {
                AddPage(0);
                AddBackground(0, 0, 300, 300, 9380);

                List <TourneyParticipant> pList = m_List != null
            ? Utility.CastListCovariant <object, TourneyParticipant>(m_List)
            : new List <TourneyParticipant>(tourney.Participants);

                AddLeftArrow(25, 11, ToButtonID(0, 0));
                AddHtml(25, 35, 250, 20, Center($"{pList.Count} Participant{(pList.Count == 1 ? "" : "s")}"));

                StartPage(out int index, out int count, out int y, 12);

                for (int i = 0; i < count; ++i, y += 18)
                {
                    TourneyParticipant part = pList[index + i];
                    string             name = part.NameList;

                    if (m_Tournament.TourneyType != TourneyType.Standard && part.Players.Count == 1)
                    {
                        if (part.Players[0] is PlayerMobile pm && pm.DuelPlayer != null)
                        {
                            name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666);
                        }
                    }

                    AddRightArrow(25, y, ToButtonID(2, index + i), name);
                }

                break;
            }

            case TourneyBracketGumpType.Participant_Info:
            {
                if (!(obj is TourneyParticipant part))
                {
                    break;
                }

                AddPage(0);
                AddBackground(0, 0, 300, 60 + 18 + 20 + part.Players.Count * 18 + 20 + 20 + 160, 9380);

                AddLeftArrow(25, 11, ToButtonID(0, 1));
                AddHtml(25, 35, 250, 20, Center("Participants"));

                int y = 53;

                AddHtml(25, y, 200, 20, part.Players.Count == 1 ? "Players" : "Team");
                y += 20;

                for (int i = 0; i < part.Players.Count; ++i)
                {
                    Mobile mob  = part.Players[i];
                    string name = mob.Name;

                    if (m_Tournament.TourneyType != TourneyType.Standard)
                    {
                        if (mob is PlayerMobile pm && pm.DuelPlayer != null)
                        {
                            name = Color(name, pm.DuelPlayer.Eliminated ? 0x6633333 : 0x336666);
                        }
                    }

                    AddRightArrow(35, y, ToButtonID(4, i), name);
                    y += 18;
                }

                AddHtml(25, y, 200, 20,
                        $"Free Advances: {(part.FreeAdvances == 0 ? "None" : part.FreeAdvances.ToString())}");
                y += 20;

                AddHtml(25, y, 200, 20, "Log:");
                y += 20;

                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < part.Log.Count; ++i)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("<br>");
                    }

                    sb.Append(part.Log[i]);
                }

                if (sb.Length == 0)
                {
                    sb.Append("Nothing logged yet.");
                }

                AddHtml(25, y, 250, 150, Color(sb.ToString(), BlackColor32), false, true);

                break;
            }

            case TourneyBracketGumpType.Player_Info:
            {
                AddPage(0);
                AddBackground(0, 0, 300, 300, 9380);

                AddLeftArrow(25, 11, ToButtonID(0, 3));
                AddHtml(25, 35, 250, 20, Center("Participants"));

                if (!(obj is Mobile mob))
                {
                    break;
                }

                Ladder      ladder = Ladder.Instance;
                LadderEntry entry  = ladder?.Find(mob);

                AddHtml(25, 53, 250, 20, $"Name: {mob.Name}");
                AddHtml(25, 73, 250, 20,
                        $"Guild: {(mob.Guild == null ? "None" : $"{mob.Guild.Name} [{mob.Guild.Abbreviation}]")}");
                AddHtml(25, 93, 250, 20, $"Rank: {(entry == null ? "N/A" : LadderGump.Rank(entry.Index + 1))}");
                AddHtml(25, 113, 250, 20, $"Level: {(entry == null ? 0 : Ladder.GetLevel(entry.Experience))}");
                AddHtml(25, 133, 250, 20, $"Wins: {entry?.Wins ?? 0:N0}");
                AddHtml(25, 153, 250, 20, $"Losses: {entry?.Losses ?? 0:N0}");

                break;
            }
Esempio n. 4
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            if (info.ButtonID == 1 && info.IsSwitched(1))
            {
                Tournament tourney = m_Tournament;
                Mobile     from    = m_From;

                switch (tourney.Stage)
                {
                case TournamentStage.Fighting:
                {
                    if (m_Registrar != null)
                    {
                        if (m_Tournament.HasParticipant(from))
                        {
                            m_Registrar.PrivateOverheadMessage(MessageType.Regular,
                                                               0x35, false, "Excuse me? You are already signed up.", from.NetState);
                        }
                        else
                        {
                            m_Registrar.PrivateOverheadMessage(MessageType.Regular,
                                                               0x22, false, "The tournament has already begun. You are too late to signup now.",
                                                               from.NetState);
                        }
                    }

                    break;
                }

                case TournamentStage.Inactive:
                {
                    m_Registrar?.PrivateOverheadMessage(MessageType.Regular,
                                                        0x35, false, "The tournament is closed.", from.NetState);

                    break;
                }

                case TournamentStage.Signup:
                {
                    if (m_Players.Count != tourney.PlayersPerParticipant)
                    {
                        m_Registrar?.PrivateOverheadMessage(MessageType.Regular,
                                                            0x35, false, "You have not yet chosen your team.", from.NetState);

                        m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
                        break;
                    }

                    Ladder ladder = Ladder.Instance;

                    for (int i = 0; i < m_Players.Count; ++i)
                    {
                        Mobile mob = m_Players[i];

                        LadderEntry entry = ladder?.Find(mob);

                        if (entry != null && Ladder.GetLevel(entry.Experience) < tourney.LevelRequirement)
                        {
                            if (m_Registrar != null)
                            {
                                if (mob == from)
                                {
                                    m_Registrar.PrivateOverheadMessage(MessageType.Regular,
                                                                       0x35, false, "You have not yet proven yourself a worthy dueler.", from.NetState);
                                }
                                else
                                {
                                    m_Registrar.PrivateOverheadMessage(MessageType.Regular,
                                                                       0x35, false, $"{mob.Name} has not yet proven themselves a worthy dueler.",
                                                                       from.NetState);
                                }
                            }

                            m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
                            return;
                        }

                        if (tourney.IsFactionRestricted && Faction.Find(mob) == null)
                        {
                            m_Registrar?.PrivateOverheadMessage(MessageType.Regular,
                                                                0x35, false, "Only those who have declared their faction allegiance may participate.",
                                                                from.NetState);

                            m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
                            return;
                        }

                        if (tourney.HasParticipant(mob))
                        {
                            if (m_Registrar != null)
                            {
                                if (mob == from)
                                {
                                    m_Registrar.PrivateOverheadMessage(MessageType.Regular,
                                                                       0x35, false, "You have already entered this tournament.", from.NetState);
                                }
                                else
                                {
                                    m_Registrar.PrivateOverheadMessage(MessageType.Regular,
                                                                       0x35, false, $"{mob.Name} has already entered this tournament.", from.NetState);
                                }
                            }

                            m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
                            return;
                        }

                        if (mob is PlayerMobile mobile && mobile.DuelContext != null)
                        {
                            if (mob == from)
                            {
                                m_Registrar?.PrivateOverheadMessage(MessageType.Regular,
                                                                    0x35, false,
                                                                    "You are already assigned to a duel. You must yield it before joining this tournament.",
                                                                    from.NetState);
                            }
                            else
                            {
                                m_Registrar?.PrivateOverheadMessage(MessageType.Regular,
                                                                    0x35, false,
                                                                    $"{mobile.Name} is already assigned to a duel. They must yield it before joining this tournament.",
                                                                    from.NetState);
                            }

                            m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
                            return;
                        }
                    }

                    if (m_Registrar != null)
                    {
                        string fmt;

                        if (tourney.PlayersPerParticipant == 1)
                        {
                            fmt =
                                "As you say m'{0}. I've written your name to the bracket. The tournament will begin {1}.";
                        }
                        else if (tourney.PlayersPerParticipant == 2)
                        {
                            fmt =
                                "As you wish m'{0}. The tournament will begin {1}, but first you must name your partner.";
                        }
                        else
                        {
                            fmt = "As you wish m'{0}. The tournament will begin {1}, but first you must name your team.";
                        }

                        string timeUntil;
                        int    minutesUntil = (int)Math.Round((tourney.SignupStart + tourney.SignupPeriod - DateTime.UtcNow)
                                                              .TotalMinutes);

                        if (minutesUntil == 0)
                        {
                            timeUntil = "momentarily";
                        }
                        else
                        {
                            timeUntil = $"in {minutesUntil} minute{(minutesUntil == 1 ? "" : "s")}";
                        }

                        m_Registrar.PrivateOverheadMessage(MessageType.Regular,
                                                           0x35, false, string.Format(fmt, from.Female ? "Lady" : "Lord", timeUntil), from.NetState);
                    }

                    TourneyParticipant part = new TourneyParticipant(from);
                    part.Players.Clear();
                    part.Players.AddRange(m_Players);

                    tourney.Participants.Add(part);

                    break;
                }
                }
            }
            else if (info.ButtonID > 1)
            {
                int index = info.ButtonID - 1;

                if (index > 0 && index < m_Players.Count)
                {
                    m_Players.RemoveAt(index);
                    m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
                }
                else if (m_Players.Count < m_Tournament.PlayersPerParticipant)
                {
                    m_From.BeginTarget(12, false, TargetFlags.None, AddPlayer_OnTarget);
                    m_From.SendGump(new ConfirmSignupGump(m_From, m_Registrar, m_Tournament, m_Players));
                }
            }
        }