Example #1
0
        public int NoteClicked(
            TimeSpan expectedTimePosition,
            int channel, int eventId, bool countAsMiss,
            TimeSpan sliceStart, TimeSpan sliceEnd,
            bool hasSound = true, TimeSpan?endNotePos = null)
        {
            if (!isStarted || isPaused)
            {
                return(-2);
            }
            var timeDiff = TimePosition - expectedTimePosition;

            int resultFlag = -1;

            if (!countAsMiss)
            {
                for (int i = 0, count = noteOffsetThesholds.Length; i < count - 1; i++)
                {
                    if (timeDiff.TotalSeconds < noteOffsetThesholds[i])
                    {
                        break;
                    }
                    resultFlag = Mathf.Abs(i + 1 - count / 2);
                }
                accuracy = (float)timeDiff.TotalMilliseconds;
            }
            if (IsValidFlag(resultFlag))
            {
                int addScore = 0;
                if (tightMode)
                {
                    float seconds = (float)timeDiff.TotalSeconds;
                    float temp    = 1 - seconds / (seconds < 0 ? noteOffsetThesholds[0] : noteOffsetThesholds.Last());
                    addScore = Mathf.FloorToInt(scorePerNote * temp) + comboBonus[combos];
                }
                else
                {
                    addScore = Mathf.FloorToInt(scorePerNote * scoreWeight[resultFlag]) + comboBonus[combos];
                }
                if (endNotePos.HasValue)
                {
                    var lnHolder = GetHolder(channel);
                    lnHolder.ResetRemainTime();
                    lnHolder.StartTime = timePosition;
                    lnHolder.Duration  = endNotePos.Value - timePosition;
                    lnHolder.Score     = addScore;
                }
                else
                {
                    score += addScore;
                    if (resultFlag == 0)
                    {
                        AddRemainTime(channel);
                    }
                    else
                    {
                        ResetHolder(channel);
                    }
                }
                noteScoreCount[resultFlag]++;
            }
            else
            {
                if (combos > 1)
                {
                    comboPools.Add(combos);
                }
                combos = -1;
                noteScoreCount[noteScoreCount.Length - 1]++;
                ResetHolder(channel);
            }
            if (score + extraScore >= maxScore)
            {
                score = maxScore;
            }
            combos++;
            maxCombos  = Mathf.Max(combos, maxCombos);
            rankSynced = false;

            if (hasSound && IsValidFlag(resultFlag))
            {
                PlayWAV(eventId, sliceStart, sliceEnd, true, detuneEnabled && resultFlag > 0 ? Mathf.Clamp(1 + accuracy / 500, 0.5F, 1.5F) : 1);
            }

            if (OnNoteClicked != null)
            {
                OnNoteClicked.Invoke(expectedTimePosition, timePosition, channel, eventId, resultFlag);
            }

            return(resultFlag);
        }
Example #2
0
        void HandleNoteEvent(int channel, bool isClicking, bool isDown)
        {
            var      ch             = GetChannelQueue(channel);
            var      lns            = GetLongNoteState(channel);
            TimeSpan offsetPosition = bmsManager.RealTimePosition + endTimeOffset;
            KeyFrame keyFrame;
            int      flag = -1;

            while (ch.Count > 0)
            {
                keyFrame = ch.Peek();
                if (keyFrame.timePosition > offsetPosition)
                {
                    break;
                }
                ch.Dequeue();
                if (keyFrame.type != NoteType.LongEnd || !lns.isMissed)
                {
                    flag = bmsManager.NoteClicked(keyFrame.timePosition, channel, keyFrame.dataId, true, keyFrame.sliceStart, keyFrame.sliceEnd);
                }
                else
                {
                    flag = -1;
                }
                if (OnNoteClicked != null)
                {
                    OnNoteClicked.Invoke(keyFrame.timePosition, channel, keyFrame.dataId, flag);
                }
            }
            if (isClicking)
            {
                if (ch.Count > 0)
                {
                    keyFrame = ch.Peek();
                    bool     handle = true, skip = false, hasSound = true;
                    TimeSpan?endNote = null;
                    switch (keyFrame.type)
                    {
                    case NoteType.Normal:
                        if (!isDown)
                        {
                            handle = false;
                        }
                        lns.longNoteId = -1;
                        break;

                    case NoteType.LongStart:
                        if (!isDown)
                        {
                            handle = false;
                        }
                        lns.longNoteId     = keyFrame.longNoteId;
                        lns.longNoteDataId = keyFrame.dataId;
                        endNote            = keyFrame.lnEndPosition;
                        break;

                    case NoteType.LongEnd:
                        if (isDown)
                        {
                            handle = false;
                        }
                        if (lns.longNoteId != keyFrame.longNoteId)
                        {
                            skip = true;
                        }
                        lns.longNoteId = -1;
                        hasSound       = lns.longNoteDataId != keyFrame.dataId;
                        break;
                    }
                    lns.isDown = keyFrame.type == NoteType.Normal ? false : isDown;
                    longNoteStates[channel] = lns;
                    if (handle || skip)
                    {
                        ch.Dequeue();
                    }
                    if (handle)
                    {
                        flag = bmsManager.NoteClicked(keyFrame.timePosition, channel, keyFrame.dataId, false, keyFrame.sliceStart, keyFrame.sliceEnd, hasSound, endNote);
                        if (OnNoteClicked != null)
                        {
                            OnNoteClicked.Invoke(keyFrame.timePosition, channel, keyFrame.dataId, flag);
                        }
                        lns.isMissed = flag < 0;
                        if (flag < 0)
                        {
                            lns.longNoteId = -1;
                        }
                        longNoteStates[channel] = lns;
                    }
                }
                else if (lns.isDown)
                {
                    lns.isDown   = false;
                    lns.isMissed = true;
                    bmsManager.NoteClicked(TimeSpan.Zero, channel, 0, true, TimeSpan.Zero, TimeSpan.MaxValue, false, null);
                    if (OnLongNoteMissed != null)
                    {
                        OnLongNoteMissed.Invoke(channel);
                    }
                    longNoteStates[channel] = lns;
                }
            }
        }