public void ShowFinalDialog(Character winner, Character loser)
        {
            MsgQualifyingInteractive pMsg = new MsgQualifyingInteractive
            {
                Type   = ArenaType.END_DIALOG,
                Option = 1 // win
            };

            try
            {
                winner.Send(pMsg);
            }
            catch
            {
            }

            pMsg      = new MsgQualifyingInteractive();
            pMsg.Type = ArenaType.END_DIALOG;
            try
            {
                loser.Send(pMsg);
            }
            catch
            {
            }
            winner.SendArenaStatus();
            loser.SendArenaStatus();
        }
        public bool Notify()
        {
            if (m_pMap == null || ReadyToStart())
            {
                return(false);
            }

            m_pPlayer1.ArenaQualifier.Status = ArenaWaitStatus.WAITING_INACTIVE;
            m_pPlayer2.ArenaQualifier.Status = ArenaWaitStatus.WAITING_INACTIVE;

            m_tInvite.Startup(60);

            MsgQualifyingInteractive pMsg = new MsgQualifyingInteractive
            {
                Type     = ArenaType.START_COUNT_DOWN,
                Identity = (uint)ArenaWaitStatus.WAITING_INACTIVE
            };

            m_pPlayer1.Send(pMsg);
            m_pPlayer2.Send(pMsg);
            return(true);
        }
        public void Start()
        {
            m_tStartup.Startup(10);
            m_pStatus = ArenaStatus.NOT_STARTED;

            m_pPlayer1.DetachBadlyStatus(m_pPlayer1);
            m_pPlayer2.DetachBadlyStatus(m_pPlayer2);

            //Console.WriteLine("Players {0} vs {1} has been sent to map {2}", m_pPlayer1.Name, m_pPlayer2.Name, m_pMap.Identity);

            if (m_pPlayer1.Map.IsRecordDisable())
            {
                uint  dwMapId = m_pPlayer1.RecordMapIdentity;
                Point pos     = new Point(m_pPlayer1.RecordMapX, m_pPlayer1.RecordMapY);

                m_pPlayer1.Map.GetRebornMap(ref dwMapId, ref pos);
                m_pPlayer1.SetRecordPos(dwMapId, (ushort)pos.X, (ushort)pos.Y);
            }
            else
            {
                m_pPlayer1.SetRecordPos(m_pPlayer1.MapIdentity, m_pPlayer1.MapX, m_pPlayer1.MapY);
            }

            if (m_pPlayer2.Map.IsRecordDisable())
            {
                uint  dwMapId = m_pPlayer2.RecordMapIdentity;
                Point pos     = new Point(m_pPlayer2.RecordMapX, m_pPlayer2.RecordMapY);

                m_pPlayer2.Map.GetRebornMap(ref dwMapId, ref pos);
                m_pPlayer2.SetRecordPos(dwMapId, (ushort)pos.X, (ushort)pos.Y);
            }
            else
            {
                m_pPlayer2.SetRecordPos(m_pPlayer2.MapIdentity, m_pPlayer2.MapX, m_pPlayer2.MapY);
            }

            if (!m_pPlayer1.IsAlive)
            {
                m_pPlayer1.Reborn(false, true);
            }
            if (!m_pPlayer2.IsAlive)
            {
                m_pPlayer2.Reborn(false, true);
            }

            try
            {
                m_pPlayer1.ChangeMap((ushort)ThreadSafeRandom.RandGet(35, 70),
                                     (ushort)ThreadSafeRandom.RandGet(35, 70), m_pMap.Identity);
            }
            catch
            {
                Finish(m_pPlayer2, m_pPlayer1, true);
                return;
            }
            try
            {
                m_pPlayer2.ChangeMap((ushort)ThreadSafeRandom.RandGet(35, 70),
                                     (ushort)ThreadSafeRandom.RandGet(35, 70), m_pMap.Identity);
            }
            catch
            {
                Finish(m_pPlayer1, m_pPlayer2, true);
                return;
            }

            SendToMap();

            m_pPkMode1 = m_pPlayer1.PkMode;
            m_pPkMode2 = m_pPlayer2.PkMode;

            m_pPlayer1.PkMode = PkModeType.PK_MODE;
            m_pPlayer2.PkMode = PkModeType.PK_MODE;

            m_pPlayer1.SendArenaInformation(m_pPlayer2);
            m_pPlayer2.SendArenaInformation(m_pPlayer1);

            MsgQualifyingInteractive pMsg = new MsgQualifyingInteractive();

            pMsg.Type   = ArenaType.MATCH;
            pMsg.Option = 5; // Match On
            m_pPlayer1.Send(pMsg);
            m_pPlayer2.Send(pMsg);

            m_pPlayer1.DetachStatus(FlagInt.RIDING);
            m_pPlayer2.DetachStatus(FlagInt.RIDING);

            m_pPlayer1.FillLife();
            m_pPlayer1.FillMana();
            m_pPlayer2.FillLife();
            m_pPlayer2.FillMana();
        }
        public void Finish(Character pWinner, Character pLoser, bool bDispose)
        {
            if (pWinner == m_pPlayer1)
            {
                Win1 = true;
            }
            else
            {
                Win2 = true;
            }

            pWinner.ArenaQualifier.Points = (uint)(pWinner.ArenaQualifier.Points * 1.03f);
            pLoser.ArenaQualifier.Points  = (uint)(pLoser.ArenaQualifier.Points * .97f);

            pWinner.ArenaQualifier.TodayWins += 1;
            pWinner.ArenaQualifier.TotalWins += 1;
            pLoser.ArenaQualifier.TodayLoses += 1;
            pLoser.ArenaQualifier.TotalLoses += 1;

            int todayMatch0 = (int)(pWinner.ArenaQualifier.TodayWins + pWinner.ArenaQualifier.TodayLoses);
            int todayMatch1 = (int)(pLoser.ArenaQualifier.TodayWins + pLoser.ArenaQualifier.TodayLoses);

            if (pWinner.ArenaQualifier.TodayWins == 9)
            {
                pWinner.ArenaQualifier.TotalHonorPoints += 5000;
                pWinner.ArenaQualifier.HonorPoints      += 5000;
            }
            if (todayMatch0 == 20)
            {
                pWinner.ArenaQualifier.TotalHonorPoints += 5000;
                pWinner.ArenaQualifier.HonorPoints      += 5000;
            }
            if (todayMatch1 == 20)
            {
                pLoser.ArenaQualifier.TotalHonorPoints += 5000;
                pLoser.ArenaQualifier.HonorPoints      += 5000;
            }

            MsgQualifyingInteractive pMsg = new MsgQualifyingInteractive
            {
                Type   = ArenaType.DIALOG,
                Option = 3 // lose
            };

            try
            {
                pLoser.Send(pMsg);
            }
            catch
            {
            }
            pMsg.Option = 1; // win
            try
            {
                pWinner.Send(pMsg);
            }
            catch
            {
            }

            pWinner.ArenaQualifier.Save();
            pLoser.ArenaQualifier.Save();

            if (pWinner.Syndicate != null && pLoser.Syndicate != null)
            {
                ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END3,
                                                            pWinner.SyndicateName, pWinner.Name, pLoser.SyndicateName, pLoser.Name,
                                                            pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER);
            }
            else if (pWinner.Syndicate != null && pLoser.Syndicate == null)
            {
                ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END1,
                                                            pWinner.SyndicateName, pWinner.Name, pLoser.Name,
                                                            pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER);
            }
            else if (pWinner.Syndicate == null && pLoser.Syndicate != null)
            {
                ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END2,
                                                            pWinner.Name, pLoser.SyndicateName, pLoser.Name,
                                                            pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER);
            }
            else
            {
                ServerKernel.SendMessageToAll(string.Format(ServerString.STR_ARENIC_MATCH_END0,
                                                            pWinner.Name,
                                                            pLoser.Name,
                                                            pWinner.ArenaQualifier.Ranking), ChatTone.QUALIFIER);
            }

            if (bDispose)
            {
                m_pStatus = ArenaStatus.DISPOSED;
                ShowFinalDialog(pWinner, pLoser);
            }
            else
            {
                m_tStartup.Startup(3);
                m_pStatus = ArenaStatus.FINISHED;
            }
        }
        public static void HandleQualifyingInteractive(Character pUser, MsgQualifyingInteractive pMsg)
        {
            switch (pMsg.Type)
            {
            case ArenaType.ARENA_ICON_ON:
            {
                if (ServerKernel.ArenaQualifier.Inscribe(pUser))
                {
                    pUser.SendArenaStatus();
                }
                else
                {
                    ServerKernel.ArenaQualifier.Uninscribe(pUser);
                    pUser.SendArenaStatus();
                }
                break;
            }

            case ArenaType.ARENA_ICON_OFF:
            {
                if (ServerKernel.ArenaQualifier.Uninscribe(pUser))
                {
                    pUser.SendArenaStatus();
                }
                break;
            }

            case ArenaType.ACCEPT_DIALOG:
            {
                ArenaMatch pMatch = ServerKernel.ArenaQualifier.FindUser(pUser.Identity);

                if (pMatch == null)
                {
                    pUser.Send(ServerString.STR_ARENIC_NOT_JOINED);
                    if (ServerKernel.ArenaQualifier.IsWaitingMatch(pUser.Identity))
                    {
                        ServerKernel.ArenaQualifier.Uninscribe(pUser);
                    }
                    pUser.SendArenaStatus();
                    return;
                }

                if (pMsg.Option == 1)     // accept
                {
                    pMatch.Accept(pUser);
                    if (pMatch.ReadyToStart())
                    {
                        pMatch.Start();
                    }
                    pUser.SendArenaStatus();
                }
                else if (pMsg.Option == 2)     // give up
                {
                    pMatch.GiveUp(pUser);
                    pUser.SendArenaStatus();
                }
                break;
            }

            case ArenaType.OPPONENT_GAVE_UP:
            {
                ArenaMatch pMatch = ServerKernel.ArenaQualifier.FindUser(pUser.Identity);

                if (pMatch == null)
                {
                    return;
                }

                //Client pTarget;
                //uint idTarget = pMatch.Identity1 == pUser.Identity ? pMatch.Identity2 : pMatch.Identity1;
                //if (ServerKernel.Players.TryGetValue(idTarget, out pTarget))
                {
                    if (pUser.Identity == pMatch.Identity1)
                    {
                        pMatch.Points2 = uint.MaxValue;
                    }
                    else
                    {
                        pMatch.Points1 = uint.MaxValue;
                    }
                    pMatch.Finish(/*pUser, pTarget.Character*/);
                    pUser.SendArenaStatus();
                }
                break;
            }

            case ArenaType.END_MATCH_JOIN:     // rejoin
            {
                if (ServerKernel.ArenaQualifier.Uninscribe(pUser))
                {
                    ServerKernel.ArenaQualifier.Inscribe(pUser);
                    pUser.SendArenaStatus();
                }
                break;
            }

            default:
            {
                pUser.Send(string.Format("The request {0} is not handled. Please contact the admin and provide an screenshot of the error.", pMsg.Type));
                ServerKernel.Log.SaveLog(string.Format("MsgQualifyingInteractive::{0}", pMsg.Type), true);
                GamePacketHandler.Report(pMsg);
                break;
            }
            }
        }