Пример #1
0
        /// <summary>
        /// Converts the player record type to string.
        /// </summary>
        /// <param name="recordType">Type of the player record to convert.</param>
        /// <returns>A nice string name</returns>
        public static string ConvertRecordTypeToString(Player.RecordType recordType)
        {
            switch (recordType)
            {
            case Player.RecordType.ShipsDestroyed:
                return("Opponent's Destroyed");

            case Player.RecordType.ForcedSurrenders:
                return("Surrendered Opponents");

            case Player.RecordType.ForcedFlees:
                return("Fled Opponents");

            case Player.RecordType.CargoLootedWorth:
                return("Captured Cargo");

            case Player.RecordType.SurrenderCount:
                return("Times Surrendered");

            case Player.RecordType.FleeCount:
                return("Times Fled");

            case Player.RecordType.CargoLostWorth:
                return("Lost Cargo");

            default:
                return(Regex.Replace(recordType.ToString(), "([A-Z])", " $1", RegexOptions.Compiled).Trim());
            }
        }
Пример #2
0
        public ActionResult ListRecords(Player.RecordType recordType)
        {
            // Build the record type selection list
            var recordTypes = from Player.RecordType s in Enum.GetValues(typeof(Player.RecordType))
                              select new { ID = s, Name = PlayerTopRecord.ConvertRecordTypeToString(s) };

            ViewData["recordType"] = new SelectList(recordTypes, "ID", "Name", recordType);

            // Format the current record type nicely
            ViewData["SelectedRecordType"] = PlayerTopRecord.ConvertRecordTypeToString(recordType);

            // Fetch the records
            ViewData["TopRecords"] = this.ControllerGame.GetTopPlayers(recordType, 10);

            return(View());
        }
Пример #3
0
        /// <summary>
        /// This Action will take a record type and build an array of previous records for the current player.
        /// Each array entry is a pair, { TimePlayer, RecordValue }
        /// </summary>
        /// <param name="recordType">Type of the record to fetch for the current player.</param>
        /// <returns>
        /// A JSON of the player record history array.
        /// </returns>
        public JsonResult GetRecordHistory(Player.RecordType recordType)
        {
            // Fetch the records
            ArrayList dataSet = new ArrayList();

            int playerId = this.ControllerGame.CurrentPlayer.PlayerId;

            PlayerRecord[] recordHistory = this.ControllerGame.GetPlayerRecords(playerId);

            FastDynamicPropertyAccessor.PropertyAccessor prop = new FastDynamicPropertyAccessor.PropertyAccessor(typeof(PlayerRecord), recordType.ToString());
            foreach (PlayerRecord record in recordHistory)
            {
                dataSet.Add(new object[] { record.TimePlayed / 60, prop.Get(record) });
            }

            return(Json(dataSet));
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PlayerTopRecord"/> class.
 /// </summary>
 /// <param name="player">The player.</param>
 /// <param name="recordType">Type of the record.</param>
 /// <param name="recordValue">The record value.</param>
 public PlayerTopRecord(Player player, Player.RecordType recordType, object recordValue)
 {
     this.player      = player;
     this.recordType  = recordType;
     this.recordValue = recordValue;
 }
Пример #5
0
        /// <summary>
        /// Fetches the top records of players based on the recordType argument.
        /// If the recordType is invalid an ArgumentException is thrown.
        /// The returned value pairs have the record value nicely formated with the Player as the key.
        /// </summary>
        /// <param name="recordType">Type of the record.</param>
        /// <param name="limit">The number of top players to return</param>
        /// <returns>Array of PlayerTopRecord objects</returns>
        public virtual PlayerTopRecord[] GetTopPlayers(Player.RecordType recordType, int limit)
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Fetch the top player records
            switch (recordType)
            {
            case Player.RecordType.NetWorth:
                return((from p in db.Players
                        orderby p.NetWorth descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.NetWorth))
                       .ToArray());

            case Player.RecordType.ShipsDestroyed:
                return((from p in db.Players
                        orderby p.ShipsDestroyed descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.ShipsDestroyed))
                       .ToArray());

            case Player.RecordType.ForcedSurrenders:
                return((from p in db.Players
                        orderby p.ForcedSurrenders descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.ForcedSurrenders))
                       .ToArray());

            case Player.RecordType.ForcedFlees:
                return((from p in db.Players
                        orderby p.ForcedFlees descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.ForcedFlees))
                       .ToArray());

            case Player.RecordType.CargoLootedWorth:
                return((from p in db.Players
                        orderby p.CargoLootedWorth descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.CargoLootedWorth))
                       .ToArray());

            case Player.RecordType.ShipsLost:
                return((from p in db.Players
                        orderby p.ShipsLost descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.ShipsLost))
                       .ToArray());

            case Player.RecordType.SurrenderCount:
                return((from p in db.Players
                        orderby p.SurrenderCount descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.SurrenderCount))
                       .ToArray());

            case Player.RecordType.FleeCount:
                return((from p in db.Players
                        orderby p.FleeCount descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.FleeCount))
                       .ToArray());

            case Player.RecordType.CargoLostWorth:
                return((from p in db.Players
                        orderby p.CargoLostWorth descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.CargoLostWorth))
                       .ToArray());

            case Player.RecordType.DistanceTraveled:
                return((from p in db.Players
                        orderby p.DistanceTraveled descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.DistanceTraveled))
                       .ToArray());

            case Player.RecordType.GoodsTraded:
                return((from p in db.Players
                        orderby p.GoodsTraded descending,
                        p.Name
                        select p)
                       .Take(limit)
                       .Select(p => new PlayerTopRecord(p, recordType, p.GoodsTraded))
                       .ToArray());

            default:
                throw new ArgumentException("Unhandled recordType in GetTopPlayers", "recordType");
            }
        }