Esempio n. 1
0
 public static void SetHistory(bool front = false, bool back = false, bool init = false)
 {
     if (init)
     {
         if (PlayHistory.Count == 0)
         {
             PlayHistory.Add(CurrentSet.GetHash());
             _historyPointer = 0;
         }
     }
     else if (front)
     {
         if (_historyPointer == -1)
         {
             _historyPointer = 0;
         }
         PlayHistory.Insert(0, CurrentSet.GetHash());
     }
     else
     {
         _historyPointer++;
         if (back)
         {
             PlayHistory.RemoveRange(_historyPointer, PlayHistory.Count - _historyPointer);
         }
         PlayHistory.Add(CurrentSet.GetHash());
     }
 }
Esempio n. 2
0
        public void AnonSetTrackToStop(int PlayHistoryId)
        {
            var         repo = _uow.GetRepo <PlayHistory>();
            PlayHistory ph   = repo.GetByQuery(i => i.PlayHistoryId == PlayHistoryId).FirstOrDefault();

            ph.IsPlaying     = false;
            ph.PlayCompleted = true;
            repo.Update(ph);
            repo.SaveChanges();
        }
    public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
    {
        PlayHistory ph = (PlayHistory)obj;
        int         x  = 0;

        while (x < ph.plays.Count)
        {
            info.AddValue(x.ToString(), ph.plays[x]);
            x++;
        }
    }
Esempio n. 4
0
        public void SetTrackToPlay(int PlayHistoryId)
        {
            var         repo = _uow.GetRepo <PlayHistory>();
            PlayHistory ph   = repo.GetByQuery()
                               .ToList()
                               .Find(i => i.PlayHistoryId == PlayHistoryId);

            ph.IsPlaying     = true;
            ph.PlayCompleted = false;
            repo.Update(ph);
            repo.SaveChanges();
        }
        public void PlayedAtDateTime_IsoDateTime_ReturnsEquivalentDateTimeOffsetValue()
        {
            // arrange
            var playHistory = new PlayHistory {
                PlayedAt = "2020-07-14T07:43:21.064Z"
            };

            // act & assert
            Assert.AreEqual(
                new DateTimeOffset(2020, 7, 14, 7, 43, 21, 64, TimeSpan.FromHours(0)),
                playHistory.PlayedAtDateTime());
        }
    public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
    {
        PlayHistory ph = (PlayHistory)obj;
        int         x  = 0;

        while (x < ph.plays.Count)
        {
            ph.plays[x] = (PlayData)info.GetValue(x.ToString(), typeof(PlayData));
            x++;
        }
        obj = ph;
        return(obj);
    }
Esempio n. 7
0
    void Start()
    {
        //deal with currency
        this.currency = new Currency();

        //deal with play history
        this.playHistory = new PlayHistory();



        level_scores[0] = 0;

        for (int i = 1; i < 24; i++)
        {
            level_scores[i] = -1;//未解锁
        }

        if (PlayerPrefs.HasKey("total_star"))
        {
            total_star = PlayerPrefs.GetInt("total_star");
        }
        else
        {
            PlayerPrefs.SetInt("total_star", 0);
        }

        if (PlayerPrefs.HasKey("top_level"))
        {
            top_level = PlayerPrefs.GetInt("top_level");
        }
        else
        {
            top_level = 0;
            PlayerPrefs.SetInt("top_level", 0);
            PlayerPrefs.SetInt("level_score_0", 0);//解锁
        }
        for (int i = 0; i <= top_level; i++)
        {
            string str = "level_score_" + i;
            if (PlayerPrefs.HasKey(str))
            {
                level_scores[i] = PlayerPrefs.GetInt(str);
            }
            else
            {
                Debug.Log("pass but fail to load level score, level = " + i);
            }
        }
        levelUnlock();
    }
Esempio n. 8
0
        public void FinishedSoundFile(Guid userId, Guid soundFileId, bool playedToEnd)
        {
            var soundFile = _library.GetSoundFile(soundFileId);

            var history = new PlayHistory
            {
                Filename    = soundFile.Filename,
                Ended       = DateTime.UtcNow,
                PlayedToEnd = playedToEnd,
                UserId      = userId
            };

            _playHistoryRepo.Save(history);
        }
Esempio n. 9
0
        public bool SetTrackToStop(int PlayHistoryId)
        {
            bool        _state  = false;
            AuthHelper  _ah     = new AuthHelper(_uow);
            var         _userId = _ah.SetupUser();
            var         repo    = _uow.GetRepo <PlayHistory>();
            PlayHistory ph      = repo.GetByQuery(i => i.PlayHistoryId == PlayHistoryId && (i.UserId == _userId || i.User.UserName.ToLower() == "jukeBox auto queue")).FirstOrDefault();

            if (ph != null)
            {
                ph.IsPlaying     = false;
                ph.PlayCompleted = true;
                repo.Update(ph);
                repo.SaveChanges();
                _state = true;
            }
            return(_state);
        }
Esempio n. 10
0
 public static PlayHistoryViewModel ToModel(this PlayHistory item)
 {
     if (item == null)
     {
         return(null);
     }
     return(new PlayHistoryViewModel
     {
         PlayHistoryId = item.PlayHistoryId,
         TrackId = item.TrackId,
         UserId = item.UserId,
         TimePlayed = item.TimePlayed,
         UserName = item.User.UserName,
         TrackName = item.Track.TrackName,
         PlayCompleted = item.PlayCompleted
                         //  AlbumName = item.Track.Album.AlbumName
     });
 }
Esempio n. 11
0
        /// <summary>
        ///     获得下一首音乐
        /// </summary>
        /// <returns>下一首Set的Playlist编号</returns>
        public static int GetNext()
        {
            if (_historyPointer != PlayHistory.Count - 1)
            {
                _historyPointer++;
                var nextsong = PlayList.IndexOf(PlayHistory[_historyPointer]);
                if (nextsong != -1)
                {
                    return(nextsong);
                }
                PlayHistory.RemoveRange(_historyPointer, PlayHistory.Count - _historyPointer);
                _historyPointer--;
            }
            int next;
            var now = CurrentSetIndex;

            if (CurrentSetIndex == -1)
            {
                now = 0;
            }
            switch (Settings.Default.NextMode)
            {
            case 1:
                next = (now + 1) % PlayList.Count;
                break;

            case 2:
                next = now;
                break;

            case 3:
                next = new Random().Next() % PlayList.Count;
                break;

            default:
                next = 0;
                break;
            }
            CurrentSet     = Allsets[PlayList[next]];
            CurrentBeatmap = CurrentSet.GetBeatmaps()[0];
            SetHistory();
            return(next);
        }
Esempio n. 12
0
 public static PlayHistoryViewModel ToModel(this PlayHistory item)
 {
     if (item == null)
     {
         return(null);
     }
     return(new PlayHistoryViewModel
     {
         PlayHistoryId = item.PlayHistoryId,
         TrackId = item.TrackId,
         UserId = item.UserId,
         TimePlayed = item.TimePlayed,
         UserName = item.User.UserName,
         TrackName = item.Track != null ? item.Track.TrackName : "Unknown",
         PlayCompleted = item.PlayCompleted,
         IsPlaying = item.IsPlaying,
         Track = item.Track,
         User = item.User
                //  AlbumName = item.Track.Album.AlbumName
     });
 }
Esempio n. 13
0
    void UpdateRecords()
    {
        if (Input.GetButtonDown("MenuCancel"))
        {
            chartExpand = !chartExpand;
            if (chartExpand)
            {
                chartsUI.SetActive(false);
                recordsUi.SetActive(true);
                GameObject.Find("EventSystem").GetComponent <EventSystem>().SetSelectedGameObject(null);
                ChartButton cb = lastChartSelected.GetComponent <ChartButton>();
                PlayHistory ph = SaveDataManager.current.saveData.playerChartRecordData[cb.chart.songID].playHistory;

                spawnedRecords = new List <GameObject>();
                GameObject hard = Instantiate(hardButtonPrefab) as GameObject;
                hard.transform.SetParent(chartRecordContainer.transform);
                hard.transform.localScale = new Vector3(1f, 1f, 1f);
                hard.GetComponent <Button>().onClick.AddListener(() => HardModePressed());
                GameObject.Find("EventSystem").GetComponent <EventSystem>().SetSelectedGameObject(hard);
                spawnedRecords.Add(hard);
                hardModeButton = hard;

                ph.plays.Sort((b, a) => a.score.CompareTo(b.score));
                int x = 0;
                foreach (PlayData playData in ph.plays)
                {
                    if (x < (ph.plays.Count - 1))
                    {
                        GameObject button = Instantiate(chartRecordPrefab) as GameObject;
                        button.transform.SetParent(chartRecordContainer.transform);
                        button.transform.localScale = new Vector3(1f, 1f, 1f);
                        button.GetComponent <ChartRecordButton>().data = playData;
                        button.GetComponent <ChartRecordButton>().rank = (x + 1);
                        spawnedRecords.Add(button);
                        x++;
                    }
                }
            }
            else
            {
                foreach (GameObject record in spawnedRecords)
                {
                    Destroy(record);
                }

                chartsUI.SetActive(true);
                recordsUi.SetActive(false);
                GameObject.Find("EventSystem").GetComponent <EventSystem>().SetSelectedGameObject(null);
                GameObject.Find("EventSystem").GetComponent <EventSystem>().SetSelectedGameObject(lastChartSelected);
            }
        }
        if (chartExpand)
        {
            if (hardMode)
            {
                hardModeButton.GetComponent <Image>().color = hardClearedBackground.color;
            }
            else
            {
                hardModeButton.GetComponent <Image>().color = normalBackground.color;
            }
        }
    }
Esempio n. 14
0
 public ChartRecordData()
 {
     playerBest  = new PlayData(Cleared.Fail, Grade.U, 0, 0, 0, 0, 0, 0, 0);
     playHistory = new PlayHistory(playerBest);
 }
Esempio n. 15
0
        public void Create(CreateActionDto input)
        {
            var isValidAction = ActionsEnum.All.Contains(input.MahjongActionName);

            if (!isValidAction)
            {
                throw new UserFriendlyException("Invalid action.");
            }

            var tableExist = _tableRepository.GetAll().Any(x => x.Id == input.TableId);

            if (!tableExist)
            {
                throw new UserFriendlyException("Invalid table id.");
            }

            var isValidOperator = _cardRepository.GetAll().Any(x => x.Id == input.OperatorCardId && x.CardType == CardTypes.Staff);

            if (!isValidOperator)
            {
                throw new UserFriendlyException("Invalid operator id.");
            }

            var table = _tableRepository.GetAllIncluding(x => x.Seats).FirstOrDefault(x => x.Id == input.TableId);

            var playHistory = _playHistoryRepository.GetAll().FirstOrDefault(x => x.TableId == input.TableId && x.Round == table.Round && x.IsPlaying == true);

            var isNewRound = playHistory == null;

            var playerEntities = new List <PlayHistoryDetailPlayer>();

            var relatedSeats = table.Seats.Where(x => input.Players.Any(m => m.Position == x.Position)).ToList();

            foreach (var seat in relatedSeats)
            {
                var player = new PlayHistoryDetailPlayer()
                {
                    PlayerCardId = seat.PlayerCardId,
                    PlayerType   = seat.PlayerType,
                    Position     = seat.Position,
                    StaffCardId  = seat.StaffCardId,
                    WinOrLose    = input.Players.FirstOrDefault(x => x.Position == seat.Position).WinOrLose,
                    Bonus        = input.Players.FirstOrDefault(x => x.Position == seat.Position).Bonus ?? 1
                };
                playerEntities.Add(player);
            }


            if (isNewRound)
            {
                playHistory = new PlayHistory()
                {
                    IsPlaying = true,
                    TableId   = table.Id,
                    Round     = table.Round
                };

                _playHistoryRepository.Insert(playHistory);
                CurrentUnitOfWork.SaveChanges();
            }

            var newPlayHistoryDetail = new PlayHistoryDetail()
            {
                OperatorCardId    = input.OperatorCardId,
                MohjongActionName = input.MahjongActionName,
                Players           = playerEntities,
                PlayHistoryId     = playHistory.Id
            };

            _playHistoryDetailRepository.Insert(newPlayHistoryDetail);

            var actionDto      = _objectMapper.Map <PlayHistoryDetailDto>(newPlayHistoryDetail);
            var playHistoryDto = new PlayHistoryDto()
            {
                TableId            = table.Id,
                Round              = table.Round,
                PlayHistoryDetails = new List <PlayHistoryDetailDto>()
                {
                    actionDto
                }
            };

            //結束當前回合的標誌Action
            if (ActionsEnum.RoundEndActions.Contains(input.MahjongActionName))
            {
                table.Round += 1;
            }

            PushNewRecord(playHistoryDto);

            foreach (var seat in relatedSeats)
            {
                var player = playerEntities.FirstOrDefault(x => x.Position == seat.Position);


                var winners = playerEntities.Where(x => x.WinOrLose == "Win").Count();
                var amount  = EvaluateWinOrLoseAmount(input.MahjongActionName, table, player.WinOrLose, winners);

                if (player.PlayerType == PlayerTypesEnum.戥脚)
                {
                    var staffCardId = string.IsNullOrEmpty(seat.StaffCardId) ? seat.PlayerCardId : seat.StaffCardId;
                    var staffCard   = _cardRepository.Get(staffCardId);
                    staffCard.Total += amount;
                }
                else
                {
                    var playerCard = _cardRepository.Get(player.PlayerCardId);
                    playerCard.Total += amount;

                    if (player.IsWinner)
                    {
                        //計算Commission
                        var commission = EvaluateCommission(input.MahjongActionName, table, player.Bonus);

                        playerCard.Commission += commission;

                        PushCommission(table.Id, player.Position, playerCard.Commission);
                    }
                }

                //計算代打輸贏
                if (seat.PlayerType == PlayerTypesEnum.代打)
                {
                    if (ActionsEnum.RoundEndActions.Contains(input.MahjongActionName))
                    {
                        seat.Round += 1;
                    }

                    seat.HelpPlayAmount += amount;

                    PushHelpPlayInfo(table.Id, seat.Position, seat.Round, seat.HelpPlayAmount);
                }
            }

            CurrentUnitOfWork.SaveChanges();
        }