Beispiel #1
0
        /// <summary>
        /// Constructor for a new record.
        /// </summary>
        public Record(IPlayableMap map, IUser user, IScoreProcessor scoreProcessor, int playTime)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            InitializeAsNew();

            UserId    = user.Id;
            Username  = user.Username;
            AvatarUrl = user.OnlineUser?.AvatarImage ?? "";

            MapHash  = map.Detail.Hash;
            GameMode = map.PlayableMode;
            Rank     = scoreProcessor.Ranking.Value;
            Score    = scoreProcessor.Score.Value;
            MaxCombo = scoreProcessor.HighestCombo.Value;
            Accuracy = (float)scoreProcessor.Accuracy.Value;
            Time     = playTime;
            Date     = DateTime.Now;

            IsClear = scoreProcessor.IsFinished && !scoreProcessor.IsFailed;

            ExtractJudgements(scoreProcessor.Judgements);
        }
Beispiel #2
0
        public void SelectMap(IPlayableMap map)
        {
            if (map == null)
            {
                UnloadMusic();
                UnloadBackground();
                bindableMap.Value = null;
                return;
            }

            // Set map only if different.
            if (map != bindableMap.Value)
            {
                IPlayableMap prevMap = bindableMap.Value;
                SetCurMap(map, true);

                // Change background / audio assets when necessary.
                if (prevMap == null || !prevMap.Detail.IsSameBackground(map.Detail))
                {
                    UnloadBackground();
                    LoadBackground();
                }
                if (prevMap == null || !prevMap.Detail.IsSameAudio(map.Detail))
                {
                    UnloadMusic();
                    LoadMusic();
                }
            }
        }
Beispiel #3
0
        public override void ApplyMap(IPlayableMap map)
        {
            base.ApplyMap(map);

            // Get total number of judgements
            maxJudgements = 0;
            foreach (var obj in map.HitObjects)
            {
                if (obj is HitCircle)
                {
                    maxJudgements++;
                    continue;
                }
                if (obj is Dragger dragger)
                {
                    maxJudgements += dragger.NestedObjects.Count + 1;
                    continue;
                }
            }

            // Get HP difficulty value.
            // TODO: Apply mod
            hpDrainRate      = map.Detail.Difficulty.HpDrainRate;
            healthPerPerfect = 1f / Mathf.Min((int)(hpDrainRate * 25f + 40f), map.ObjectCount);
        }
Beispiel #4
0
 /// <summary>
 /// Checks whether the game load parameters are valid and returns whether validation is a success.
 /// </summary>
 private bool ValidateLoadParams(IPlayableMap map, IModeService modeService)
 {
     // If invalid parameters, loading must fail.
     if (map == null)
     {
         NotificationBox?.Add(new Notification()
         {
             Message = "Map is not specified!",
             Type    = NotificationType.Error
         });
         loadState.Value = GameLoadState.Fail;
         return(false);
     }
     if (modeService == null)
     {
         NotificationBox?.Add(new Notification()
         {
             Message = "Game mode is not specified!",
             Type    = NotificationType.Error
         });
         loadState.Value = GameLoadState.Fail;
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// Applies DB query selection of records for the specified map.
        /// </summary>
        private void ApplyFilterMap(IDatabaseQuery <Record> query, IPlayableMap map)
        {
            var mapHash  = map.Detail.Hash;
            var gameMode = ((int)map.PlayableMode).ToString();

            query.Where(d => d["MapHash"].ToString().Equals(mapHash, StringComparison.Ordinal))
            .Where(d => d["GameMode"].ToString().Equals(gameMode, StringComparison.Ordinal));
        }
Beispiel #6
0
 public int GetPlayCount(IPlayableMap map)
 {
     if (RecordStore != null && User != null)
     {
         return(RecordStore.GetRecordCount(map, User));
     }
     return(0);
 }
 public void DeleteRecords(IPlayableMap map)
 {
     using (var records = Database.Query())
     {
         ApplyFilterMap(records, map);
         Database.Edit().RemoveRange(records.GetResult()).Commit();
     }
 }
Beispiel #8
0
        public virtual void ApplyMap(IPlayableMap map)
        {
            // Get difficulty multiplier.
            difficultyMultiplier = map.Difficulty.Scale;

            // TODO: Apply mod multiplier.
            modMultiplier = 1f;
        }
        /// <summary>
        /// Initializes states for specified map and record.
        /// </summary>
        public void Setup(IPlayableMap map, IRecord record, bool allowRetry = true)
        {
            allowsRetry.Value = allowRetry;

            SetMap(map);
            SetRecord(record);

            hasReplay.Value = RecordStore.HasReplayData(record);
        }
 public int GetRecordCount(IPlayableMap map, IUser user)
 {
     using (var results = Database.Query())
     {
         ApplyFilterMap(results, map);
         ApplyFilterUser(results, user);
         return(results.GetResult().Count);
     }
 }
Beispiel #11
0
        /// <summary>
        /// Sets current map state.
        /// </summary>
        private void SetCurMap(IPlayableMap map, bool onlyIfDifferent)
        {
            var previousMap = bindableMap.Value;

            if (onlyIfDifferent && previousMap == map)
            {
                return;
            }

            bindableMap.SetWithoutTrigger(map);
            this.MapConfig.Value = mapConfiguration?.GetConfig(map);
            bindableMap.TriggerWithPrevious(previousMap);
        }
Beispiel #12
0
 /// <summary>
 /// Event called on map change.
 /// </summary>
 private void OnMapChange(IPlayableMap map)
 {
     if (map == null)
     {
         source.Content = "";
         tags.Content   = "";
     }
     else
     {
         source.Content = map.Metadata.Source;
         tags.Content   = map.Metadata.Tags;
     }
 }
 /// <summary>
 /// Sets label values.
 /// </summary>
 private void SetLabels(IPlayableMap map, bool preferUnicode)
 {
     if (map == null)
     {
         titleLabel.Text  = "";
         artistLabel.Text = "";
     }
     else
     {
         titleLabel.Text  = map.Metadata.GetTitle(preferUnicode);
         artistLabel.Text = map.Metadata.GetArtist(preferUnicode);
     }
 }
 /// <summary>
 /// Event called when the current map instance has changed.
 /// </summary>
 private void OnMapChanged(IPlayableMap map)
 {
     if (map == null)
     {
         foreach (var sprite in rangeSprites)
         {
             sprite.Active = false;
         }
     }
     else
     {
         SetupRanges();
     }
 }
        protected override Rulesets.Difficulty.DifficultyInfo CreateDifficultyInfo(IPlayableMap map, Skill[] skills, float clockRate)
        {
            if (!map.HitObjects.Any())
            {
                return(new DifficultyInfo());
            }

            float speedStrain = skills[0].GetDifficultyScale() * StrainAdjustment;

            return(new DifficultyInfo()
            {
                Scale = speedStrain,
                SpeedStrain = speedStrain
            });
        }
 /// <summary>
 /// Event called on map selection change.
 /// </summary>
 private void OnMapChange(IPlayableMap map)
 {
     if (map == null)
     {
         timeInfo.LabelText    = "0:00";
         objectsInfo.LabelText = "0";
     }
     else
     {
         int duration = map.Duration / 1000;
         int minutes  = duration / 60;
         int seconds  = duration % 60;
         timeInfo.LabelText    = $"{minutes}:{seconds.ToString("00")}";
         objectsInfo.LabelText = map.ObjectCount.ToString("N0");
     }
 }
        public Task <List <IRecord> > GetTopRecords(IPlayableMap map, int?limit = null, TaskListener <List <IRecord> > listener = null)
        {
            return(Task.Run(() =>
            {
                using (var query = Database.Query())
                {
                    ApplyFilterMap(query, map);

                    List <IRecord> records = query.GetResult().Cast <IRecord>().ToList();
                    records.SortByTop();
                    ApplyLimit(records, limit);

                    listener?.SetFinished(records);
                    return records;
                }
            }));
        }
        /// <summary>
        /// Event called on map selection change.
        /// </summary>
        private void OnMapChange(IPlayableMap map)
        {
            ClearCells();
            if (map == null)
            {
                difficultyScale.Active = false;
            }
            else
            {
                var difficulty = map.Difficulty;
                if (difficulty == null)
                {
                    throw new ArgumentException($"Missing DifficultyInfo for specified map ({map.ToString()}). Perhaps it is not a playable map?");
                }

                SetupDifficulty(map, difficulty);
            }
        }
        /// <summary>
        /// Displays difficulty info scales.
        /// </summary>
        private void SetupDifficulty(IPlayableMap map, DifficultyInfo difficulty)
        {
            var mapDifficulty = map.Detail.Difficulty;

            switch (map.PlayableMode)
            {
            // TODO: Handle other modes that should display different label values.

            default:
                GetCell().Setup("AR", mapDifficulty.ApproachRate, 10f);
                GetCell().Setup("CS", mapDifficulty.CircleSize, 10f);
                GetCell().Setup("HP", mapDifficulty.HpDrainRate, 10f);
                GetCell().Setup("OD", mapDifficulty.OverallDifficulty, 10f);
                break;
            }

            // Display BPM value
            bpmInfo.Setup("BPM", map.ControlPoints.CommonBpm.ToString("N0"));

            // Display overall scale
            difficultyScale.Setup("Diff. scale", difficulty.Scale, 10f);
            difficultyScale.Active = true;
        }
Beispiel #20
0
        public void SelectMapset(IMapset mapset, IPlayableMap map = null)
        {
            if (mapset == null)
            {
                UnloadMusic();
                UnloadBackground();
                return;
            }

            // Apply default map.
            if (map == null)
            {
                // Make sure the maps are sorted for the current game mode.
                mapset.SortMapsByMode(currentMode);
                map = mapset.Maps[0].GetPlayable(currentMode);
            }

            // Set mapset only if different.
            SetCurMapset(mapset, true);

            // Select the map.
            SelectMap(map);
        }
        /// <summary>
        /// Applies sample points to the hitobjects.
        /// </summary>
        private void ApplySamplePoint(IPlayableMap map)
        {
            Action <BaseHitObject> applyPoint = (hitObj) => {
                var samplePoint = hitObj.SamplePoint;
                if (samplePoint != null)
                {
                    if (hitObj.Samples != null)
                    {
                        for (int i = 0; i < hitObj.Samples.Count; i++)
                        {
                            samplePoint.ApplySample(hitObj.Samples[i]);
                        }
                    }
                    var curve = hitObj as IHasCurve;
                    if (curve != null)
                    {
                        foreach (var samples in curve.NodeSamples)
                        {
                            for (int i = 0; i < samples.Count; i++)
                            {
                                samplePoint.ApplySample(samples[i]);
                            }
                        }
                    }
                }
            };

            foreach (var hitObject in map.HitObjects)
            {
                applyPoint(hitObject);
                foreach (var nested in hitObject.NestedObjects)
                {
                    applyPoint(nested);
                }
            }
        }
 /// <summary>
 /// Event called on map change.
 /// </summary>
 private void OnMapChange(IPlayableMap map) => SetupCounters();
        protected override IEnumerable <Rulesets.Difficulty.Objects.DifficultyHitObject> CreateHitObjects(IPlayableMap beatmap, float clockRate)
        {
            var map = beatmap as Maps.Map;

            if (map != null)
            {
                bool           isFirst    = true;
                HitObject      prevObject = null;
                List <Dragger> draggers   = new List <Dragger>();
                foreach (var obj in map.HitObjects)
                {
                    // Remove draggers that would have ended at current object's start time.
                    for (int i = draggers.Count - 1; i >= 0; i--)
                    {
                        if (draggers[i].EndTime + DraggerRemovalDelay < obj.StartTime)
                        {
                            draggers.RemoveAt(i);
                        }
                    }

                    // Create hit object.
                    if (!isFirst)
                    {
                        yield return(new DifficultyHitObject(obj, prevObject, draggers.Count, clockRate));
                    }
                    isFirst = false;

                    // Store previous object.
                    prevObject = obj;

                    // Add dragger.
                    Dragger dragger = obj as Dragger;
                    if (dragger != null)
                    {
                        draggers.Add(dragger);
                    }
                }
            }
        }
Beispiel #24
0
 /// <summary>
 /// Event called on map selection change.
 /// </summary>
 private void OnMapChange(IPlayableMap map) => SetupLabels();
        private const float DraggerRemovalDelay = 100;         // 150 BPM


        public DifficultyCalculator(IPlayableMap map) : base(map)
        {
        }
Beispiel #26
0
 // TODO:
 public override Rulesets.Difficulty.IDifficultyCalculator CreateDifficultyCalculator(IPlayableMap map) => null;
Beispiel #27
0
 // TODO:
 public override Rulesets.Maps.IMapProcessor CreateProcessor(IPlayableMap map) => null;
 public MapAssetStore(IPlayableMap map, ISoundTable fallbackSoundTable) : base(map.Detail.Mapset.Directory)
 {
     Map        = map;
     SoundTable = new MapSoundTable(fallbackSoundTable);
 }
Beispiel #29
0
 public override Rulesets.Maps.IMapProcessor CreateProcessor(IPlayableMap map) => new Standard.Maps.MapProcessor(map);
 /// <summary>
 /// Event called on map selection change.
 /// </summary>
 private void OnMapChange(IPlayableMap map) => RefreshDisplays();