Beispiel #1
0
 public GoalData(
     AccumulatedFrame match,
     Player player,
     LastScore lastScore,
     float gameClock,
     Vector2 goalPos,
     float angleIntoGoal,
     bool backboard,
     Team.TeamColor goalColor,
     bool?leftHanded,
     float?underhandedness,
     List <Vector3> discTrajectory)
 {
     eventType            = EventType.goal;
     matchData            = match;
     GameClock            = gameClock;
     Player               = player;
     LastScore            = lastScore;
     GoalPos              = goalPos;
     GoalAngle            = angleIntoGoal;
     Backboard            = backboard;
     GoalColor            = goalColor;
     LeftHanded           = leftHanded;
     this.underhandedness = underhandedness;
     DiscTrajectory       = new List <Vector3>(discTrajectory);
 }
Beispiel #2
0
        public AccumulatedFrame(Frame baseFrame, AccumulatedFrame lastRound = null)
        {
            frame          = baseFrame;
            this.lastRound = lastRound;
            players        = new Dictionary <long, MatchPlayer>();
            matchTime      = baseFrame.recorded_time;
            if (matchTime == DateTime.MinValue)
            {
                matchTime = DateTime.UtcNow;
            }

            teams = new Dictionary <Team.TeamColor, TeamData>
            {
                { Team.TeamColor.blue, new TeamData() },
                { Team.TeamColor.orange, new TeamData() },
                { Team.TeamColor.spectator, new TeamData() },
            };
            if (frame.client_name != "anonymous")
            {
                SparkSettings.instance.client_name = frame.client_name;
            }

            teams[Team.TeamColor.blue].FindTeamNamesFromPlayerList(frame.teams[0]);
            teams[Team.TeamColor.orange].FindTeamNamesFromPlayerList(frame.teams[1]);

            if (lastRound != null)
            {
                // Loop through teams.
                foreach (Team team in frame.teams)
                {
                    // Loop through players on team.
                    foreach (Player player in team.players)
                    {
                        MatchPlayer oldPlayer = lastRound.GetPlayerData(player);
                        if (oldPlayer != null)
                        {
                            // copy the old player for now
                            MatchPlayer newPlayer = new MatchPlayer(oldPlayer)
                            {
                                matchData = this
                            };
                            // if stats didn't get reset
                            if (player.stats.Sum() >= oldPlayer.currentStats.Sum())
                            {
                                newPlayer.oldRoundStats += player.stats;
                            }
                            else
                            {
                                Debug.WriteLine("Skipped assigning old round stats");
                            }

                            newPlayer.currentStats = player.stats;
                            players.Add(player.userid, newPlayer);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public EventData(AccumulatedFrame round, EventType eventType, float gameClock, Team team, Player player, LastThrow lastThrow)
        {
            eventTime      = DateTime.UtcNow;
            this.round     = round;
            this.eventType = eventType;
            this.gameClock = gameClock;
            this.player    = player;
            this.team      = team;

            position = new Vector3(lastThrow.total_speed, lastThrow.speed_from_arm, lastThrow.speed_from_wrist);
            vec2     = new Vector3(lastThrow.speed_from_movement, lastThrow.arm_speed, lastThrow.rot_per_sec);
        }
Beispiel #4
0
 public EventData(AccumulatedFrame round, EventType eventType, float gameClock, Team team, Player player, Player otherPlayer, Vector3 position, Vector3 vec2)
 {
     eventTime        = DateTime.UtcNow;
     this.round       = round;
     this.eventType   = eventType;
     this.gameClock   = gameClock;
     this.player      = player;
     this.otherPlayer = otherPlayer;
     this.position    = position;
     this.vec2        = vec2;
     this.team        = team;
 }
Beispiel #5
0
        //
        // public MatchPlayer(MatchData match, Player player)
        // {
        //  matchData = match;
        //  Id = player.userid;
        //  Name = player.name;
        //  playspaceLocation = player.head.Position;
        //  PlayspaceAbuses = 0;
        // }

        /// <summary>
        /// Copy constructor
        /// </summary>
        public MatchPlayer(AccumulatedFrame round, Player player)
        {
            matchData         = round;
            Id                = player.userid;
            Name              = player.name;
            Level             = player.level;
            Number            = player.number;
            currentStats      = player.stats;
            cachedStats       = new Stats();
            oldRoundStats     = new Stats();
            PlayTime          = 0;
            InvertedTime      = 0;
            GoalsNum          = 0;
            TwoPointers       = 0;
            ThreePointers     = 0;
            Passes            = 0;
            Catches           = 0;
            Won               = 0;
            Turnovers         = 0;
            playspaceLocation = player.head.Position;
        }
Beispiel #6
0
        public void UploadMatchBatch(AccumulatedFrame round, bool final = false)
        {
            if (!SparkSettings.instance.uploadToIgniteDB)
            {
                Console.WriteLine("Won't upload right now.");
            }

            BatchOutputFormat data = new BatchOutputFormat
            {
                final      = final,
                match_data = round.ToDict()
            };

            round.players.Values.ToList().ForEach(e =>
            {
                if (e.Name != "anonymous")
                {
                    data.match_players.Add(e.ToDict());
                }
            });

            round.events.ForEach(e =>
            {
                if (!e.inDB)
                {
                    data.events.Add(e.ToDict());
                }
                e.inDB = true;
            });
            round.goals.ForEach(e =>
            {
                if (!e.inDB)
                {
                    data.goals.Add(e.ToDict());
                }
                e.inDB = true;
            });
            round.throws.ForEach(e =>
            {
                if (!e.inDB)
                {
                    data.throws.Add(e.ToDict());
                }
                e.inDB = true;
            });

            string dataString = JsonConvert.SerializeObject(data);
            string hash;

            using (SHA256 sha = SHA256.Create())
            {
                byte[] rawHash = sha.ComputeHash(Encoding.ASCII.GetBytes(dataString + round.frame.client_name));

                // Convert the byte array to hexadecimal string
                StringBuilder sb = new StringBuilder();
                foreach (byte b in rawHash)
                {
                    sb.Append(b.ToString("X2"));
                }

                hash = sb.ToString().ToLower();
            }

            if (SparkSettings.instance.uploadToIgniteDB || DiscordOAuth.AccessCode.series_name.Contains("vrml"))
            {
                _ = DoUploadMatchBatchIgniteDB(dataString, hash, round.frame.client_name);
            }

            // upload tablet stats as well
            if (round.frame?.private_match == false)
            {
                Program.AutoUploadTabletStats();
            }
        }