private static string GetMatchStatus(ArenaMatch match)
        {
            var teams   = GetTeamsSummary(match.Players);
            var mapDesc = match.Status == ArenaMatch.MatchStatus.InProgress
                ? $"{match.Players.Length:00} / {match.Players.Length:00}"
                : $"{match.TakenSeats:00} / {match.TotalSeats:00}";

            return($"{match.Port}  -  {mapDesc}  -  {teams}");
        }
예제 #2
0
        public void Setup()
        {
            _arenaMatch = JsonConvert.DeserializeObject <ArenaMatch>(File.ReadAllText(Config.ArenaMatchJsonPath));

            var mock = new Mock <IHaloSession>();

            mock.Setup(m => m.Get <ArenaMatch>(It.IsAny <string>()))
            .ReturnsAsync(_arenaMatch);

            _mockSession = mock.Object;
        }
예제 #3
0
        public static bool IsSuitableForOnlineGame(this ArenaMatch match)
        {
            // Arena is "Waiting for punters."
            return(match.Status == ArenaMatch.MatchStatus.Waiting

                   // ...and there're no "kontur.ru_*" bots already connected to arena
                   && match.Players.All(x => !x.IsOurBot())

                   // ...and it's not a map fully populated with organizers' bots
                   && match.Players.Count(x => orgBoxNames.Contains(x)) != match.TotalSeats - 1);
        }
예제 #4
0
        private async Task <MatchResult> GetMatchResult(ArenaMatch match, string gamerTag, MatchEvents matchEvents)
        {
            MatchResult result  = Mapper.Map <MatchResult>(match);
            var         players = new List <ArenaPlayer>();

            foreach (var playerStat in match.PlayerStats)
            {
                var p = await GetArenaPlayer(playerStat, matchEvents);

                players.Add(p);
            }
            SetTeams(match, players, result, gamerTag);
            return(result);
        }
예제 #5
0
        public static int DetermineMobileNotoriety(Mobile source, Mobile target, bool useVengeance)
        {
            BaseCreature bc_Source = source as BaseCreature;
            PlayerMobile pm_Source = source as PlayerMobile;

            Mobile       m_SourceController  = null;
            BaseCreature bc_SourceController = null;
            PlayerMobile pm_SourceController = null;

            BaseCreature bc_Target = target as BaseCreature;
            PlayerMobile pm_Target = target as PlayerMobile;

            Mobile       m_TargetController  = null;
            BaseCreature bc_TargetController = null;
            PlayerMobile pm_TargetController = null;

            if (bc_Source != null)
            {
                m_SourceController  = bc_Source.ControlMaster as Mobile;
                bc_SourceController = bc_Source.ControlMaster as BaseCreature;
                pm_SourceController = bc_Source.ControlMaster as PlayerMobile;
            }

            if (bc_Target != null)
            {
                m_TargetController  = bc_Target.ControlMaster as Mobile;
                bc_TargetController = bc_Target.ControlMaster as BaseCreature;
                pm_TargetController = bc_Target.ControlMaster as PlayerMobile;
            }

            ArenaController fromArenaController   = ArenaController.GetArenaAtLocation(source.Location, source.Map);
            ArenaController targetArenaController = ArenaController.GetArenaAtLocation(target.Location, target.Map);

            if (fromArenaController != null && targetArenaController != null && fromArenaController == targetArenaController)
            {
                if (fromArenaController.m_ArenaFight != null)
                {
                    if (fromArenaController.m_ArenaFight.m_FightPhase == ArenaFight.FightPhaseType.Fight)
                    {
                        if (fromArenaController.m_ArenaFight.m_ArenaMatch != null)
                        {
                            ArenaMatch arenaMatch = fromArenaController.m_ArenaFight.m_ArenaMatch;

                            if (ArenaMatch.IsValidArenaMatch(arenaMatch, null, false))
                            {
                                PlayerMobile rootPlayerFrom   = null;
                                PlayerMobile rootPlayerTarget = null;

                                if (pm_Source != null)
                                {
                                    rootPlayerFrom = pm_Source;
                                }

                                if (pm_Target != null)
                                {
                                    rootPlayerTarget = pm_Target;
                                }

                                if (pm_SourceController != null)
                                {
                                    rootPlayerFrom = pm_SourceController;
                                }

                                if (pm_TargetController != null)
                                {
                                    rootPlayerTarget = pm_TargetController;
                                }

                                ArenaParticipant fromArenaParticipant   = fromArenaController.m_ArenaFight.m_ArenaMatch.GetParticipant(rootPlayerFrom);
                                ArenaParticipant targetArenaParticipant = fromArenaController.m_ArenaFight.m_ArenaMatch.GetParticipant(rootPlayerTarget);

                                if (fromArenaParticipant != null && targetArenaParticipant != null)
                                {
                                    if (fromArenaParticipant.m_FightStatus == ArenaParticipant.FightStatusType.Alive && targetArenaParticipant.m_FightStatus == ArenaParticipant.FightStatusType.Alive)
                                    {
                                        ArenaTeam fromTeam   = null;
                                        ArenaTeam targetTeam = null;

                                        foreach (ArenaTeam team in arenaMatch.m_Teams)
                                        {
                                            if (team == null)
                                            {
                                                continue;
                                            }
                                            if (team.Deleted)
                                            {
                                                continue;
                                            }

                                            ArenaParticipant participant = team.GetPlayerParticipant(rootPlayerFrom);

                                            if (participant != null)
                                            {
                                                fromTeam = team;
                                            }

                                            participant = team.GetPlayerParticipant(rootPlayerTarget);

                                            if (participant != null)
                                            {
                                                targetTeam = team;
                                            }
                                        }

                                        if (fromTeam != null && targetTeam != null)
                                        {
                                            if (fromTeam == targetTeam)
                                            {
                                                return(Notoriety.Ally);
                                            }

                                            if (fromTeam != targetTeam)
                                            {
                                                return(Notoriety.Enemy);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Berserk Creatures
            if (bc_Source != null && (source is BladeSpirits || source is EnergyVortex))
            {
                if (bc_Source.ControlMaster != null && pm_Target != null)
                {
                    //Blade Spirits + Energy Vortexes Can Freely Attack Their Control Master Without Causing Criminal Action
                    if (bc_Source.ControlMaster == pm_Target)
                    {
                        return(Notoriety.CanBeAttacked);
                    }
                }

                if (bc_Source.ControlMaster != null && bc_Target != null)
                {
                    //Blade Spirits + Energy Vortexes Can Freely Attack Other Followers Of Their Control Master Without Causing Criminal Action
                    if (bc_Source.ControlMaster == bc_Target.ControlMaster)
                    {
                        return(Notoriety.CanBeAttacked);
                    }
                }
            }

            if (target is BladeSpirits || target is EnergyVortex)
            {
                return(Notoriety.Murderer);
            }

            //Staff Members Always Attackable
            if (target.AccessLevel > AccessLevel.Player)
            {
                return(Notoriety.CanBeAttacked);
            }

            if (m_TargetController != null)
            {
                //Creature Controlled By Staff Member
                if (m_TargetController.AccessLevel > AccessLevel.Player)
                {
                    return(Notoriety.CanBeAttacked);
                }
            }

            //Enemy of One
            if (pm_Source != null && bc_Target != null)
            {
                if (!bc_Target.Summoned && !bc_Target.Controlled && pm_Source.EnemyOfOneType == target.GetType())
                {
                    return(Notoriety.Enemy);
                }
            }

            //Justice Free Zone
            if (SpellHelper.InBuccs(target.Map, target.Location) || SpellHelper.InYewOrcFort(target.Map, target.Location) || SpellHelper.InYewCrypts(target.Map, target.Location))
            {
                return(Notoriety.CanBeAttacked);
            }

            //Grey Zone Totem Nearby
            if (GreyZoneTotem.InGreyZoneTotemArea(target.Location, target.Map))
            {
                return(Notoriety.CanBeAttacked);
            }

            //Hotspot Nearby
            if (Custom.Hotspot.InHotspotArea(target.Location, target.Map, true))
            {
                return(Notoriety.CanBeAttacked);
            }

            //Player Notoriety
            if (pm_Target != null)
            {
                //Friendly
                if (pm_SourceController != null)
                {
                    if (pm_SourceController == pm_Target)
                    {
                        return(Notoriety.Ally);
                    }
                }

                //Murderer
                if (pm_Target.Murderer && !pm_Target.HideMurdererStatus)
                {
                    return(Notoriety.Murderer);
                }

                //Criminal
                if (pm_Target.Criminal)
                {
                    return(Notoriety.Criminal);
                }

                //Perma-Grey
                if (SkillHandlers.Stealing.ClassicMode && pm_Target.PermaFlags.Contains(source))
                {
                    return(Notoriety.CanBeAttacked);
                }

                if (pm_SourceController != null)
                {
                    //Target is Perma-Grey to Source Creature's Controller
                    if (SkillHandlers.Stealing.ClassicMode && pm_Target.PermaFlags.Contains(pm_SourceController))
                    {
                        return(Notoriety.CanBeAttacked);
                    }
                }
            }

            //Guilds
            //TEST: GUILD

            /*
             * Guild sourceGuild = GetGuildFor(source.Guild as Guild, source);
             * Guild targetGuild = GetGuildFor(target.Guild as Guild, target);
             *
             * if (sourceGuild != null && targetGuild != null)
             * {
             *  if (sourceGuild == targetGuild || sourceGuild.IsAlly(targetGuild))
             *      return Notoriety.Ally;
             *
             *  else if (sourceGuild.IsEnemy(targetGuild))
             *      return Notoriety.Enemy;
             * }
             */

            //Creature Notoriety
            if (bc_Target != null)
            {
                //Friendly
                if (m_TargetController != null)
                {
                    //Target is Source's Controller
                    if (source == m_TargetController)
                    {
                        return(Notoriety.Ally);
                    }
                }

                if (m_SourceController != null)
                {
                    //Source is Target's Controller
                    if (m_SourceController == bc_Target)
                    {
                        return(Notoriety.Ally);
                    }
                }

                //Murderer
                if (bc_Target.IsMurderer())
                {
                    return(Notoriety.Murderer);
                }

                if (pm_TargetController != null)
                {
                    if (pm_TargetController.Murderer)
                    {
                        return(Notoriety.Murderer);
                    }
                }

                if (bc_TargetController != null)
                {
                    if (bc_TargetController.IsMurderer())
                    {
                        return(Notoriety.Murderer);
                    }
                }

                //Criminal
                if (bc_Target.Criminal)
                {
                    return(Notoriety.Criminal);
                }

                if (pm_TargetController != null)
                {
                    if (pm_TargetController.Criminal)
                    {
                        return(Notoriety.Criminal);
                    }
                }

                if (bc_TargetController != null)
                {
                    if (bc_TargetController.Criminal)
                    {
                        return(Notoriety.Criminal);
                    }
                }

                //Perma-Grey
                if (pm_TargetController != null)
                {
                    if (SkillHandlers.Stealing.ClassicMode && pm_TargetController.PermaFlags.Contains(source))
                    {
                        return(Notoriety.CanBeAttacked);
                    }

                    if (pm_SourceController != null)
                    {
                        //Target is Perma-Grey to Source Creature's Controller
                        if (SkillHandlers.Stealing.ClassicMode && pm_TargetController.PermaFlags.Contains(pm_SourceController))
                        {
                            return(Notoriety.CanBeAttacked);
                        }
                    }
                }
            }

            //Housing
            if (CheckHouseFlag(source, target, target.Location, target.Map))
            {
                return(Notoriety.CanBeAttacked);
            }

            //Aggressor: Source to Target
            if (CheckAggressor(source.Aggressors, target))
            {
                return(Notoriety.CanBeAttacked);
            }

            if (CheckAggressed(source.Aggressed, target) && useVengeance)
            {
                return(Notoriety.CanBeAttacked);
            }

            //Aggressor: Source Controller to Target
            if (m_SourceController != null)
            {
                if (CheckAggressor(m_SourceController.Aggressors, target))
                {
                    return(Notoriety.CanBeAttacked);
                }

                if (CheckAggressed(m_SourceController.Aggressed, target) && useVengeance)
                {
                    return(Notoriety.CanBeAttacked);
                }
            }

            //Aggressor: Source to Target's Controller
            if (m_TargetController != null)
            {
                if (CheckAggressor(source.Aggressors, m_TargetController))
                {
                    return(Notoriety.CanBeAttacked);
                }

                if (CheckAggressed(source.Aggressed, m_TargetController) && useVengeance)
                {
                    return(Notoriety.CanBeAttacked);
                }
            }

            //Aggressor: Source Controller to Target's Controller
            if (m_SourceController != null && m_TargetController != null)
            {
                if (CheckAggressor(m_SourceController.Aggressors, m_TargetController))
                {
                    return(Notoriety.CanBeAttacked);
                }

                if (CheckAggressed(m_SourceController.Aggressed, m_TargetController) && useVengeance)
                {
                    return(Notoriety.CanBeAttacked);
                }
            }

            //Player Followers: If A Player or Any of Their Followers Have been Aggressed or Barded, the Player and All Other Followers Can Attack the Aggressor
            PlayerMobile pm_Player = null;

            if (pm_Source != null)
            {
                pm_Player = pm_Source;
            }

            if (pm_SourceController != null)
            {
                pm_Player = pm_SourceController;
            }

            if (pm_Player != null)
            {
                if (pm_Player.AllFollowers.Count > 0)
                {
                    //Any of the Player's Other Followers
                    foreach (Mobile follower in pm_Player.AllFollowers)
                    {
                        BaseCreature bc_Follower = follower as BaseCreature;

                        if (bc_Follower == null)
                        {
                            continue;
                        }

                        //Follower Has Been Aggressed/Aggresor to Target
                        if (CheckAggressor(bc_Follower.Aggressors, target))
                        {
                            return(Notoriety.CanBeAttacked);
                        }

                        if (CheckAggressed(bc_Follower.Aggressed, target) && useVengeance)
                        {
                            return(Notoriety.CanBeAttacked);
                        }

                        //Follower Has Been Aggressed/Aggresor by/to Target's Controller
                        if (m_TargetController != null)
                        {
                            if (CheckAggressor(bc_Follower.Aggressors, m_TargetController))
                            {
                                return(Notoriety.CanBeAttacked);
                            }

                            if (CheckAggressed(bc_Follower.Aggressed, m_TargetController) && useVengeance)
                            {
                                return(Notoriety.CanBeAttacked);
                            }
                        }
                    }
                }
            }

            //Ships: Players and Creatures Friendly to a Ship Can Freely Attack Non-Friendly Mobiles on their Ship
            BaseShip sourceShip = null;

            if (bc_Source != null)
            {
                if (bc_Source.ShipOccupied != null)
                {
                    sourceShip = bc_Source.ShipOccupied;
                }
            }

            if (pm_Source != null)
            {
                if (pm_Source.ShipOccupied != null)
                {
                    sourceShip = pm_Source.ShipOccupied;
                }
            }

            if (sourceShip != null)
            {
                BaseShip targetShip = null;

                if (bc_Target != null)
                {
                    if (bc_Target.ShipOccupied != null)
                    {
                        targetShip = bc_Target.ShipOccupied;
                    }
                }

                if (pm_Target != null)
                {
                    if (pm_Target.ShipOccupied != null)
                    {
                        targetShip = pm_Target.ShipOccupied;
                    }
                }

                //On Same Ship
                if (sourceShip != null && targetShip != null && !sourceShip.Deleted && !targetShip.Deleted && sourceShip == targetShip)
                {
                    bool sourceBelongs = false;
                    bool targetBelongs = false;

                    //Source Belongs n the Ship
                    if (sourceShip.Crew.Contains(source) || sourceShip.IsFriend(source) || sourceShip.IsCoOwner(source) || sourceShip.IsOwner(source))
                    {
                        sourceBelongs = true;
                    }

                    //Source's Owner Belongs on the Ship
                    else if (bc_Source != null)
                    {
                        if (m_SourceController != null)
                        {
                            if (sourceShip.Crew.Contains(m_SourceController) || sourceShip.IsFriend(m_SourceController) || sourceShip.IsCoOwner(m_SourceController) || sourceShip.IsOwner(m_SourceController))
                            {
                                sourceBelongs = true;
                            }
                        }
                    }

                    //Target Belongs On The Ship
                    if (sourceShip.Crew.Contains(target) || sourceShip.IsFriend(target) || sourceShip.IsCoOwner(target) || sourceShip.IsOwner(target))
                    {
                        targetBelongs = true;
                    }

                    //Target's Owner Belongs On the Ship
                    else if (bc_Target != null)
                    {
                        if (m_TargetController != null)
                        {
                            if (sourceShip.Crew.Contains(m_TargetController) || sourceShip.IsFriend(m_TargetController) || sourceShip.IsCoOwner(m_TargetController) || sourceShip.IsOwner(m_TargetController))
                            {
                                targetBelongs = true;
                            }
                        }
                    }

                    //Target May Be Freely Attacked on Ship
                    if (sourceBelongs && !targetBelongs)
                    {
                        return(Notoriety.CanBeAttacked);
                    }
                }
            }

            //Polymorph or Body Transformation
            if (!(bc_Target != null && bc_Target.InitialInnocent))
            {
                if (target.Player && target.BodyMod > 0)
                {
                }

                else if (!target.Body.IsHuman && !target.Body.IsGhost && !IsPet(bc_Target) && !TransformationSpellHelper.UnderTransformation(target))
                {
                    return(Notoriety.CanBeAttacked);
                }
            }

            //If somehow a player is attacking us with their tamed creatures, and their creatures are flagged to us but the player isn't
            //if (pm_Source != null && pm_Target != null)
            //{
            //    if (pm_Target.AllFollowers.Count > 0)
            //    {
            //        //Any of the Player's Other Followers
            //        foreach (Mobile follower in pm_Target.AllFollowers)
            //        {
            //            int notorietyResult = Notoriety.Compute(source, follower);

            //            //Enemy Tamer Adopts Notoriety of Their Creature (Anything other than Innocent)
            //            if (notorietyResult != 1)
            //            {
            //                foreach(var aggressor in source.Aggressors)
            //                {
            //                    if (aggressor.Attacker == follower)
            //                        return notorietyResult;
            //                }
            //            }
            //        }
            //    }
            //}

            return(Notoriety.Innocent);
        }
예제 #6
0
        private async Task <ArenaMatchResult> GetMatchResult(ArenaMatch match, string gamerTag)
        {
            ArenaMatchResult result = Mapper.Map <ArenaMatchResult>(match);
            var players             = new List <ArenaPlayer>();

            foreach (var playerStat in match.PlayerStats)
            {
                var p = await GetArenaPlayer(playerStat);

                players.Add(p);
            }
            SetTeams(match, players, result, gamerTag);

            //result.Teams = new List<Team>();
            //foreach (var teamStat in match.TeamStats.OrderBy(t => t.Rank))
            //{
            //    var team = Mapper.Map<Team>(teamStat);
            //    team.Players = players.Where(p => p.TeamId == teamStat.TeamId).OrderBy(p => p.Rank).ToList();

            //    var minKills = team.Players.Min(p => p.TotalKills);
            //    var maxKills = team.Players.Max(p => p.TotalKills) - minKills;
            //    var minDeaths = team.Players.Min(p => p.TotalDeaths);
            //    var maxDeaths = team.Players.Max(p => p.TotalDeaths) - minDeaths;
            //    var minAssists = team.Players.Min(p => p.TotalAssists);
            //    var maxAssists = team.Players.Max(p => p.TotalAssists) - minAssists;
            //    var maxKda = team.Players.Max(p =>p.Kda);
            //    var minKda = team.Players.Min(p => p.Kda);

            //    foreach (var p in team.Players)
            //    {
            //        p.KillPercent = p.TotalKills.Percent(minKills,maxKills);
            //        p.DeathPercent = p.TotalDeaths.Percent(minDeaths, maxDeaths);
            //        p.AssistPercent = p.TotalAssists.Percent(minAssists,maxAssists);
            //        p.KdaPercent = p.Kda.Percent(p.Kda < 0 ? minKda : maxKda);
            //    }

            //    result.Teams.Add(team);
            //}

            //var player = players.FirstOrDefault(p => p.GamerTag.ToUpper() == gamerTag.ToUpper());
            //var playersTeam = result.Teams.FirstOrDefault(t => t.TeamId == player?.TeamId);
            //if (playersTeam != null && player != null)
            //{
            //    if (player.DNF)
            //    {
            //        result.Result = Enumeration.ResultType.DidNotFinish;
            //    }
            //    else if (playersTeam.Rank == 0)
            //    {
            //        result.Result = result.Teams.Any(t => t.TeamId != playersTeam.TeamId && t.Rank == 0) ? Enumeration.ResultType.Tied : Enumeration.ResultType.Won;
            //    }
            //    else
            //    {
            //        result.Result = Enumeration.ResultType.Lost;
            //    }
            //    result.PlayerTeamColor = playersTeam.TeamColor;
            //}


            return(result);
        }
        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;
            }
            }
        }