using System; using System.Collections.Generic; using InnerNet; using UnityEngine; using UnityEngine.Analytics; namespace Assets.CoreScripts { public class Telemetry : DestroyableSingleton { private static readonly string[] ColorNames = new string[] { "Red", "Blue", "Green", "Pink", "Orange", "Yellow", "Black", "White", "Purple", "Brown" }; private bool amHost; private bool gameStarted; private DateTime timeStarted; public bool IsInitialized; public Guid CurrentGuid; public void Initialize() { this.Initialize(Guid.NewGuid()); } public void Initialize(Guid gameGuid) { this.IsInitialized = true; this.CurrentGuid = gameGuid; } public void StartGame(bool sendName, bool isHost, int playerCount, int impostorCount, GameModes gameMode, uint timesImpostor, uint gamesPlayed, uint crewStreak) { if (!SaveManager.SendTelemetry) { return; } this.gameStarted = true; this.amHost = isHost; this.timeStarted = DateTime.UtcNow; Dictionary dictionary = new Dictionary { { "Platform", (byte)Application.platform }, { "TimesImpostor", timesImpostor }, { "CrewStreak", crewStreak }, { "GamesPlayed", gamesPlayed }, { "GameMode", gameMode } }; if (this.amHost) { dictionary.Add("PlayerCount", playerCount); dictionary.Add("InfectedCount", impostorCount); } Analytics.CustomEvent("StartGame", dictionary); } public void WriteMeetingStarted(bool isEmergency) { if (!SaveManager.SendTelemetry) { return; } if (!this.amHost) { return; } Analytics.CustomEvent("MeetingStarted", new Dictionary { { "IsEmergency", isEmergency } }); } public void WriteMeetingEnded(byte[] results, float duration) { if (!SaveManager.SendTelemetry) { return; } if (!this.amHost) { return; } Analytics.CustomEvent("MeetingEnded", new Dictionary { { "IsEmergency", duration } }); } public void WritePosition(byte playerNum, Vector2 worldPos) { } public void WriteMurder(byte sourcePlayerNum, byte targetPlayerNum, Vector3 worldPos) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("Murder"); } public void WriteSabotageUsed(SystemTypes systemType) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("SabotageUsed", new Dictionary { { "SystemType", systemType } }); } public void WriteUse(byte playerNum, TaskTypes taskType, Vector3 worldPos) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("ConsoleUsed", new Dictionary { { "TaskType", taskType } }); } public void WriteCompleteTask(byte playerNum, TaskTypes taskType) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("TaskComplete", new Dictionary { { "TaskType", taskType } }); } internal void WriteDisconnect(DisconnectReasons reason) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("Disconnect", new Dictionary { { "Reason", reason } }); } public void EndGame(GameOverReason endReason) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Dictionary dictionary = new Dictionary { { "Reason", endReason } }; if (this.amHost) { dictionary.Add("DurationSec", (DateTime.UtcNow - this.timeStarted).TotalSeconds); } Analytics.CustomEvent("EndGame", dictionary); } public void SendWho() { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("SentWho"); } public void SelectInfected(int colorId, uint hatId) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("SelectInfected", new Dictionary { { "Color", Telemetry.ColorNames[colorId] }, { "Hat", DestroyableSingleton.Instance.GetHatById(hatId).name } }); } public void WonGame(int colorId, uint hatId) { if (!SaveManager.SendTelemetry) { return; } if (!this.gameStarted) { return; } Analytics.CustomEvent("WonGame", new Dictionary { { "Color", Telemetry.ColorNames[colorId] }, { "Hat", DestroyableSingleton.Instance.GetHatById(hatId).name } }); } } }