Ejemplo n.º 1
0
 private IFight GetOrAddFight(Character mob)
 {
     return(Fights
            .Where(x => IsValidFight(x, mob))
            .FirstOrDefault()
            ?? CreateNewFight());
 }
Ejemplo n.º 2
0
        public void AddFight(Fight fight)
        {
            Fight fightToChange;

            if (fight.FightId == 0)
            {
                var TimeParam     = new SqlParameter("@Time", fight.Time);
                var RoundsPram    = new SqlParameter("@Rounds", fight.Rounds);
                var WinnerIdParam = new SqlParameter("@WinnerId", fight.Winner.Id);
                var LosserIdParam = new SqlParameter("@LosserId", fight.Losser.Id);
                var Judge1Param   = new SqlParameter("@Judge1", fight.Judge1);
                var Judge2Param   = new SqlParameter("@Judge2", fight.Judge2);
                var Judge3Param   = new SqlParameter("@Judge3", fight.Judge3);

                Database.ExecuteSqlCommand("exec AddFight @Time, @Rounds, @WinnerId, @LosserId," +
                                           "@Judge1, @Judge2, @Judge3", TimeParam, RoundsPram, WinnerIdParam, LosserIdParam, Judge1Param,
                                           Judge2Param, Judge3Param);
            }
            else if ((fightToChange = Fights.Where(f => f.FightId == fight.FightId).FirstOrDefault()) != null)
            {
                fightToChange.Judge1 = fight.Judge1;
                fightToChange.Judge2 = fight.Judge2;
                fightToChange.Judge3 = fight.Judge3;
                fightToChange.Time   = fight.Time;
                fightToChange.Winner = fight.Winner;
                fightToChange.Losser = fight.Losser;
                fightToChange.Rounds = fight.Rounds;
                this.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        private IFight GetAppropriateFight(Character char1, Character char2)
        {
            if (!Fights.Any())
            {
                CreateNewFight();
            }

            // If the primary mob isn't established yet, use the first fight
            var fight = Fights.First();

            if (IsValidFight(fight, Character.Unknown))
            {
                return(fight);
            }

            var firstActiveFight = Fights.Where(x => !x.IsFightOver);

            // If either one of the characters is Unknown, just use the first active fight
            if ((char1 == Character.Unknown || char2 == Character.Unknown) && firstActiveFight.Any())
            {
                return(firstActiveFight.First());
            }

            // If the char is a MOB, find the matching fight or create a new one
            if (CharResolver.WhichType(char1) == CharacterResolver.Type.NonPlayerCharacter)
            {
                return(GetOrAddFight(char1));
            }
            if (CharResolver.WhichType(char2) == CharacterResolver.Type.NonPlayerCharacter)
            {
                return(GetOrAddFight(char2));
            }

            // See if either character is already the primary mob (we can't tell if a named mob w/ a single name is a mob, so this may catch that)
            var primaryMobMatch = Fights.Where(x => IsValidFight(x, char1) || IsValidFight(x, char2));

            if (primaryMobMatch.Any())
            {
                return(primaryMobMatch.First());
            }

            // Either the characters are not MOBs or one of them is a named Mob and we don't know it, just use the first fight that's still ongoing
            if (firstActiveFight.Any())
            {
                return(firstActiveFight.First());
            }

            return(CreateNewFight());
        }