Esempio n. 1
0
        public bool ScoreGoal(TableSide side)
        {
            if (IsFinished)
            {
                return(false);
            }

            var goal = new Goal
            {
                Side = side,
                Time = DateTime.Now
            };

            Goals.Add(goal);

            var lastGoal = Goals.Count(g => g.Side == goal.Side) >= GoalsToVictory;

            if (lastGoal)
            {
                IsFinished = true;
                EndTime    = DateTime.Now;
            }

            return(true);
        }
Esempio n. 2
0
        public object Summary()
        {
            var redTeam = new
            {
                Name         = RedTeam.GetNameOrDefault(),
                FirstPlayer  = RedTeam.FirstPlayer.Name,
                SecondPlayer = RedTeam.SecondPlayer != null ? RedTeam.SecondPlayer.Name : "",
                Color        = Table.SideOneColor.ToString()
            };

            var blueTeam = new
            {
                Name         = BlueTeam.GetNameOrDefault(),
                FirstPlayer  = BlueTeam.FirstPlayer.Name,
                SecondPlayer = BlueTeam.SecondPlayer != null ? BlueTeam.SecondPlayer.Name : "",
                Color        = Table.SideTwoColor.ToString()
            };

            return(new
            {
                Teams = new
                {
                    RedTeam = redTeam,
                    BlueTeam = blueTeam
                },
                Score = new
                {
                    RedGoals = Goals.Count(g => g.Side == TableSide.Red),
                    BlueGoals = Goals.Count(g => g.Side == TableSide.Blue)
                },
                VanityString = _tauntTexts[CurrentTaunt()]
            });
        }
Esempio n. 3
0
        public Embed GetEmbed()
        {
            bool firstFieldInline = Roles.Count() + Descriptors.Count() + Goals.Count() <= 3;
            List <EmbedFieldBuilder> rolesField = new List <EmbedFieldBuilder>();

            for (int i = 0; i < Roles.Length; i++)
            {
                if (i == 0)
                {
                    rolesField.Add(new EmbedFieldBuilder().WithIsInline(firstFieldInline).WithName(NPCResources.Role).WithValue(Roles[i]));
                }
                else
                {
                    rolesField.Add(new EmbedFieldBuilder().WithIsInline(true).WithName(NPCResources.Role).WithValue(Roles[i]));
                }
            }

            List <EmbedFieldBuilder> goalFields = new List <EmbedFieldBuilder>();

            for (int i = 0; i < Goals.Length; i++)
            {
                if (i == 0)
                {
                    goalFields.Add(new EmbedFieldBuilder().WithIsInline(firstFieldInline).WithName(NPCResources.Goal).WithValue(Goals[i]));
                }
                else
                {
                    goalFields.Add(new EmbedFieldBuilder().WithIsInline(true).WithName(NPCResources.Goal).WithValue(Goals[i]));
                }
            }

            List <EmbedFieldBuilder> descFields = new List <EmbedFieldBuilder>();

            for (int i = 0; i < Descriptors.Length; i++)
            {
                if (i == 0)
                {
                    descFields.Add(new EmbedFieldBuilder().WithIsInline(firstFieldInline).WithName(NPCResources.Descriptor).WithValue(Descriptors[i]));
                }
                else
                {
                    descFields.Add(new EmbedFieldBuilder().WithIsInline(true).WithName(NPCResources.Descriptor).WithValue(Descriptors[i]));
                }
            }

            return(new EmbedBuilder()
                   .WithTitle($"__{NPCResources.NPC}__")
                   .WithFields(new EmbedFieldBuilder().WithName(NPCResources.Name).WithValue(Name).WithIsInline(false))
                   .WithFields(rolesField)
                   .WithFields(goalFields)
                   .WithFields(descFields)
                   .Build());
        }
Esempio n. 4
0
        public int ConcededForGoalie(Player goalie)
        {
            if (!GoaliePlayed(goalie))
            {
                return(0);
            }

            if (goalie == homeGoalie)
            {
                return(Goals.Count(goal => goal.Team == AwayTeam));
            }

            return(Goals.Count(goal => goal.Team == HomeTeam));
        }
Esempio n. 5
0
        public Taunt CurrentTaunt()
        {
            var blueGoals = Goals.Count(g => g.Side == TableSide.Blue);
            var redGoals  = Goals.Count(g => g.Side == TableSide.Red);

            if (IsFinished)
            {
                var redWinsNoBlueGoals = Goals.Count(g => g.Side == TableSide.Red) == GoalsToVictory &&
                                         Goals.Count(g => g.Side == TableSide.Blue) == 0;
                var blueWinsNoRedGoals = Goals.Count(g => g.Side == TableSide.Blue) == GoalsToVictory &&
                                         Goals.Count(g => g.Side == TableSide.Red) == 0;
                if (redWinsNoBlueGoals || blueWinsNoRedGoals)
                {
                    return(Taunt.UnderTheTable);
                }

                if (Math.Abs(blueGoals - redGoals) >= GoalsToCrush)
                {
                    return(Taunt.CrushingWin);
                }

                return(Taunt.GameOver);
            }

            if (Goals.Count >= GoalsToDominate)
            {
                var lastGoals = LastGoals(GoalsToDominate);
                if (lastGoals.ElementAt(0).Side == lastGoals.ElementAt(1).Side &&
                    lastGoals.ElementAt(1).Side == lastGoals.ElementAt(2).Side)
                {
                    return(Taunt.Dominating);
                }
            }

            if (Goals.Count >= 2)
            {
                var lastTwoGoals = LastGoals(2);
                if (lastTwoGoals.ElementAt(0).Time - lastTwoGoals.ElementAt(1).Time >= TimeSpan.FromMinutes(2))
                {
                    return(Taunt.Finally);
                }
            }

            if (redGoals == blueGoals)
            {
                return(Taunt.Equalizer);
            }

            return(Taunt.PlayOn);
        }
Esempio n. 6
0
        private static void LoadGoals()
        {
            FileInfo f = new FileInfo(goalsFile);

            if (f.Exists)
            {
                StreamReader sr = new StreamReader(goalsFile);

                var goalsJson = sr.ReadToEnd();

                var GoalsBD = JsonConvert.DeserializeObject <ObservableCollection <Goal> >(goalsJson);

                Goals = GoalsBD;

                sr.Dispose();
                sr.Close();
            }

            var verify = false;

            if (Goals.Count(g => g.Name.Equals("Essencial") && g.IsCategory) == 0)
            {
                Goals.Add(new Goal("Essencial"));
                verify = true;
            }
            if (Goals.Count(g => g.Name.Equals("Educação") && g.IsCategory) == 0)
            {
                Goals.Add(new Goal("Educação"));
                verify = true;
            }
            if (Goals.Count(g => g.Name.Equals("Investimento") && g.IsCategory) == 0)
            {
                Goals.Add(new Goal("Investimento"));
                verify = true;
            }
            if (Goals.Count(g => g.Name.Equals("Foda-se") && g.IsCategory) == 0)
            {
                Goals.Add(new Goal("Foda-se"));
                verify = true;
            }

            if (verify)
            {
                SaveGoals();
            }
        }
Esempio n. 7
0
        internal MatchStatistics(Team homeTeam, Team awayTeam, int amountOfChallenges)
        {
            Challenges = new List <Challenge>();

            for (int i = 0; i < amountOfChallenges; i++)
            {
                Challenges.Add(new Challenge(homeTeam, awayTeam));
            }

            for (int i = 0; i < amountOfChallenges; i++)
            {
                Challenges.Add(new Challenge(awayTeam, homeTeam));
            }

            Goals = Challenges.Where(c => c.IsGoal).Select(c => new Goal(c.Challenger)).ToList();

            HomeGoals = Goals.Count(g => g.ScoringTeam == homeTeam);

            AwayGoals = Goals.Count(g => g.ScoringTeam == awayTeam);
        }