Example #1
0
		public ArenaController() : base( 0x1B7A )
		{
			Visible = false;
			Movable = false;

			m_Arena = new Arena();

			m_Instances.Add( this );
		}
Example #2
0
		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );

			int version = reader.ReadInt();

			switch ( version )
			{
				case 1:
				{
					m_IsPrivate = reader.ReadBool();

					goto case 0;
				}
				case 0:
				{
					m_Arena = new Arena( reader );
					break;
				}
			}

			m_Instances.Add( this );
		}
Example #3
0
        public void Start(Arena arena, Tournament tourny)
        {
            TournyParticipant first = (TournyParticipant)this.m_Participants[0];

            DuelContext dc = new DuelContext((Mobile)first.Players[0], tourny.Ruleset.Layout, false);
            dc.Ruleset.Options.SetAll(false);
            dc.Ruleset.Options.Or(tourny.Ruleset.Options);

            for (int i = 0; i < this.m_Participants.Count; ++i)
            {
                TournyParticipant tournyPart = (TournyParticipant)this.m_Participants[i];
                Participant duelPart = new Participant(dc, tournyPart.Players.Count);

                duelPart.TournyPart = tournyPart;

                for (int j = 0; j < tournyPart.Players.Count; ++j)
                    duelPart.Add((Mobile)tournyPart.Players[j]);

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

                dc.Participants.Add(duelPart);
            }

            if (tourny.EventController != null)
                dc.m_EventGame = tourny.EventController.Construct(dc);

            dc.m_Tournament = tourny;
            dc.m_Match = this;

            dc.m_OverrideArena = arena;

            if (tourny.SuddenDeath > TimeSpan.Zero && (tourny.SuddenDeathRounds == 0 || tourny.Pyramid.Levels.Count <= tourny.SuddenDeathRounds))
                dc.StartSuddenDeath(tourny.SuddenDeath);

            dc.SendReadyGump(0);

            if (dc.StartedBeginCountdown)
            {
                this.m_Context = dc;

                for (int i = 0; i < this.m_Participants.Count; ++i)
                {
                    TournyParticipant p = (TournyParticipant)this.m_Participants[i];

                    for (int j = 0; j < p.Players.Count; ++j)
                    {
                        Mobile mob = (Mobile)p.Players[j];

                        foreach (Mobile view in mob.GetMobilesInRange(18))
                        {
                            if (!mob.CanSee(view))
                                mob.Send(view.RemovePacket);
                        }

                        mob.LocalOverheadMessage(MessageType.Emote, 0x3B2, false, "* Your mind focuses intently on the fight and all other distractions fade away *");
                    }
                }
            }
            else
            {
                dc.Unregister();
                dc.StopCountdown();
            }
        }
Example #4
0
        public void HandleWon(Arena arena, TournyMatch match, TournyParticipant winner)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("The match is complete. ");
            sb.Append(winner.NameList);

            if (winner.Players.Count > 1)
                sb.Append(" have bested ");
            else
                sb.Append(" has bested ");

            if (match.Participants.Count > 2)
                sb.AppendFormat("{0} other {1}: ", match.Participants.Count - 1, winner.Players.Count == 1 ? "players" : "teams");

            bool hasAppended = false;

            for (int j = 0; j < match.Participants.Count; ++j)
            {
                TournyParticipant part = (TournyParticipant)match.Participants[j];

                if (part == winner)
                    continue;

                this.m_Undefeated.Remove(part);

                if (hasAppended)
                    sb.Append(", ");

                sb.Append(part.NameList);
                hasAppended = true;
            }

            sb.Append(".");

            if (this.m_TournyType == TournyType.Standard)
                this.Alert(arena, sb.ToString());
        }
Example #5
0
        public void HandleTie(Arena arena, TournyMatch match, ArrayList remaining)
        {
            if (remaining.Count == 1)
                this.HandleWon(arena, match, (TournyParticipant)remaining[0]);

            if (remaining.Count < 2)
                return;

            StringBuilder sb = new StringBuilder();

            sb.Append("The match has ended in a tie ");

            if (remaining.Count == 2)
                sb.Append("between ");
            else
                sb.Append("among ");

            sb.Append(remaining.Count);

            if (((TournyParticipant)remaining[0]).Players.Count == 1)
                sb.Append(" players: ");
            else
                sb.Append(" teams: ");

            bool hasAppended = false;

            for (int j = 0; j < match.Participants.Count; ++j)
            {
                TournyParticipant part = (TournyParticipant)match.Participants[j];

                if (remaining.Contains(part))
                {
                    if (hasAppended)
                        sb.Append(", ");

                    sb.Append(part.NameList);
                    hasAppended = true;
                }
                else
                {
                    this.m_Undefeated.Remove(part);
                }
            }

            sb.Append(". ");

            string whole = (remaining.Count == 2 ? "both" : "all");

            TieType tieType = this.m_TieType;

            if (tieType == TieType.FullElimination && remaining.Count >= this.m_Undefeated.Count)
                tieType = TieType.FullAdvancement;

            switch ( this.m_TieType )
            {
                case TieType.FullAdvancement:
                    {
                        sb.AppendFormat("In accordance with the rules, {0} parties are advanced.", whole);
                        break;
                    }
                case TieType.FullElimination:
                    {
                        for (int j = 0; j < remaining.Count; ++j)
                            this.m_Undefeated.Remove(remaining[j]);

                        sb.AppendFormat("In accordance with the rules, {0} parties are eliminated.", whole);
                        break;
                    }
                case TieType.Random:
                    {
                        TournyParticipant advanced = (TournyParticipant)remaining[Utility.Random(remaining.Count)];

                        for (int i = 0; i < remaining.Count; ++i)
                        {
                            if (remaining[i] != advanced)
                                this.m_Undefeated.Remove(remaining[i]);
                        }

                        if (advanced != null)
                            sb.AppendFormat("In accordance with the rules, {0} {1} advanced.", advanced.NameList, advanced.Players.Count == 1 ? "is" : "are");

                        break;
                    }
                case TieType.Highest:
                    {
                        TournyParticipant advanced = null;

                        for (int i = 0; i < remaining.Count; ++i)
                        {
                            TournyParticipant part = (TournyParticipant)remaining[i];

                            if (advanced == null || part.TotalLadderXP > advanced.TotalLadderXP)
                                advanced = part;
                        }

                        for (int i = 0; i < remaining.Count; ++i)
                        {
                            if (remaining[i] != advanced)
                                this.m_Undefeated.Remove(remaining[i]);
                        }

                        if (advanced != null)
                            sb.AppendFormat("In accordance with the rules, {0} {1} advanced.", advanced.NameList, advanced.Players.Count == 1 ? "is" : "are");

                        break;
                    }
                case TieType.Lowest:
                    {
                        TournyParticipant advanced = null;

                        for (int i = 0; i < remaining.Count; ++i)
                        {
                            TournyParticipant part = (TournyParticipant)remaining[i];

                            if (advanced == null || part.TotalLadderXP < advanced.TotalLadderXP)
                                advanced = part;
                        }

                        for (int i = 0; i < remaining.Count; ++i)
                        {
                            if (remaining[i] != advanced)
                                this.m_Undefeated.Remove(remaining[i]);
                        }

                        if (advanced != null)
                            sb.AppendFormat("In accordance with the rules, {0} {1} advanced.", advanced.NameList, advanced.Players.Count == 1 ? "is" : "are");

                        break;
                    }
            }

            this.Alert(arena, sb.ToString());
        }
Example #6
0
 public void Alert(Arena arena, params string[] alerts)
 {
     if (arena != null && arena.Announcer != null)
     {
         for (int j = 0; j < alerts.Length; ++j)
             Timer.DelayCall(TimeSpan.FromSeconds(Math.Max(j - 0.5, 0.0)), new TimerStateCallback(Alert_Callback), new object[] { arena.Announcer, alerts[j] });
     }
 }
Example #7
0
		public void SendReadyGump( int count )
		{
			if ( !m_Registered )
				return;

			if ( count != -1 )
				m_StartedReadyCountdown = true;

			m_ReadyCount = count;

			if ( count == 0 )
			{
				string error = ValidateStart();

				if ( error != null )
				{
					for ( int i = 0; i < m_Participants.Count; ++i )
					{
						Participant p = (Participant)m_Participants[i];

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

							if ( dp != null )
								dp.Mobile.SendMessage( "The duel could not be started because {0}.", error );
						}
					}

					StartCountdown( 10, new CountdownCallback( SendReadyGump ) );

					return;
				}

				m_ReadyWait = false;

				List<Mobile> players = new List<Mobile>();

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

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

						if ( dp != null )
							players.Add( dp.Mobile );
					}
				}

				Arena arena = m_OverrideArena;
				
				if ( arena == null )
					arena = Arena.FindArena( players );

				if ( arena == null )
				{
					for ( int i = 0; i < m_Participants.Count; ++i )
					{
						Participant p = (Participant)m_Participants[i];

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

							if ( dp != null )
								dp.Mobile.SendMessage( "The duel could not be started because there are no arenas. If you want to stop waiting for a free arena, yield the duel." );
						}
					}

					StartCountdown( 10, new CountdownCallback( SendReadyGump ) );
					return;
				}

				if ( !arena.IsOccupied )
				{
					m_Arena = arena;

					if ( m_Initiator.Map == Map.Internal )
					{
						m_GatePoint = m_Initiator.LogoutLocation;
						m_GateFacet = m_Initiator.LogoutMap;
					}
					else
					{
						m_GatePoint = m_Initiator.Location;
						m_GateFacet = m_Initiator.Map;
					}

					ExitTeleporter tp = arena.Teleporter as ExitTeleporter;

					if ( tp == null )
					{
						arena.Teleporter = tp = new ExitTeleporter();
						tp.MoveToWorld( arena.GateOut == Point3D.Zero ? arena.Outside : arena.GateOut, arena.Facet );
					}

					ArenaMoongate mg = new ArenaMoongate( arena.GateIn == Point3D.Zero ? arena.Outside : arena.GateIn, arena.Facet, tp );

					m_StartedBeginCountdown = true;

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

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

							if ( pl == null )
								continue;

							tp.Register( pl.Mobile );

							pl.Mobile.Frozen = false; // reset timer just in case
							pl.Mobile.Frozen = true;

							Debuff( pl.Mobile );
							CancelSpell( pl.Mobile );

							pl.Mobile.Delta( MobileDelta.Noto );
						}

						arena.MoveInside( p.Players, i );
					}

					if ( m_EventGame != null )
						m_EventGame.OnStart();

					StartCountdown( 10, new CountdownCallback( SendBeginGump ) );

					mg.Appear( m_GatePoint, m_GateFacet );
				}
				else
				{
					for ( int i = 0; i < m_Participants.Count; ++i )
					{
						Participant p = (Participant)m_Participants[i];

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

							if ( dp != null )
								dp.Mobile.SendMessage( "The duel could not be started because all arenas are full. If you want to stop waiting for a free arena, yield the duel." );
						}
					}

					StartCountdown( 10, new CountdownCallback( SendReadyGump ) );
				}

				return;
			}

			m_ReadyWait = true;

			bool isAllReady = true;

			Type[] types = new Type[]{ typeof( ReadyGump ) };

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

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

					if ( pl == null )
						continue;

					Mobile mob = pl.Mobile;

					if ( pl.Ready )
					{
						if ( m_Tournament == null )
							CloseAndSendGump( mob, new ReadyGump( mob, this, count ), types );
					}
					else
					{
						isAllReady = false;
					}
				}
			}

			if ( count == -1 && isAllReady )
				StartCountdown( 3, new CountdownCallback( SendReadyGump ) );
		}
Example #8
0
			public ArenaEntry( Arena arena )
			{
				m_Arena = arena;
			}
Example #9
0
 public ArenaEntry(Arena arena)
 {
     this.m_Arena = arena;
 }
Example #10
0
 public ArenaEntry(Arena arena)
 {
     m_Arena = arena;
 }
Example #11
0
        public static Arena FindArena(List <Mobile> players)
        {
            Preferences prefs = Preferences.Instance;

            if (prefs == null)
            {
                return(FindArena());
            }

            if (m_Arenas.Count == 0)
            {
                return(null);
            }

            if (players.Count > 0)
            {
                Mobile first = players[0];

                List <ArenaController> allControllers = ArenaController.Instances;

                for (int i = 0; i < allControllers.Count; ++i)
                {
                    ArenaController controller = allControllers[i];

                    if (controller != null && !controller.Deleted && controller.Arena != null && controller.IsPrivate && controller.Map == first.Map && first.InRange(controller, 24))
                    {
                        Multis.BaseHouse house   = Multis.BaseHouse.FindHouseAt(controller);
                        bool             allNear = true;

                        for (int j = 0; j < players.Count; ++j)
                        {
                            Mobile check = players[j];
                            bool   isNear;

                            if (house == null)
                            {
                                isNear = (controller.Map == check.Map && check.InRange(controller, 24));
                            }
                            else
                            {
                                isNear = (Multis.BaseHouse.FindHouseAt(check) == house);
                            }

                            if (!isNear)
                            {
                                allNear = false;
                                break;
                            }
                        }

                        if (allNear)
                        {
                            return(controller.Arena);
                        }
                    }
                }
            }

            List <ArenaEntry> arenas = new List <ArenaEntry>();

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

                if (!arena.IsOccupied)
                {
                    arenas.Add(new ArenaEntry(arena));
                }
            }

            if (arenas.Count == 0)
            {
                return(m_Arenas[0]);
            }

            int tc = 0;

            for (int i = 0; i < arenas.Count; ++i)
            {
                ArenaEntry ae = arenas[i];

                for (int j = 0; j < players.Count; ++j)
                {
                    PreferencesEntry pe = prefs.Find(players[j]);

                    if (pe.Disliked.Contains(ae.m_Arena.Name))
                    {
                        ++ae.m_VotesAgainst;
                    }
                    else
                    {
                        ++ae.m_VotesFor;
                    }
                }

                tc += ae.Value;
            }

            int rn = Utility.Random(tc);

            for (int i = 0; i < arenas.Count; ++i)
            {
                ArenaEntry ae = arenas[i];

                if (rn < ae.Value)
                {
                    return(ae.m_Arena);
                }

                rn -= ae.Value;
            }

            return(arenas[Utility.Random(arenas.Count)].m_Arena);
        }