public MyGame(DisboardGameInitData initData) : base(initData) { // 게임이 시작되었을 때의 로직을 입력합니다. // InitialPlayers에는 게임에 참가하는 인원들이 DisboardPlayer 타입으로 저장되어 있습니다. // 하지만 DisboardPlayer 타입에는 플레이어 이름 같은 것들만 있고, 게임에서 사용할 HP, MP와 같은 변수를 추가할 수 없습니다. // 그래서 플레이어가 가지는 정보를 관리할 수 있도록 MyPlayer 타입을 새롭게 정의하였습니다. // MyPlayer타입을 사용하려면, 기존 DisboardPlayer 타입으로 저장되어 있는 정보를 MyPlayer로 변환하는 과정이 필요합니다. _players = InitialPlayers.Select(disboardPlayer => new MyPlayer(disboardPlayer)).ToList(); _playerDict = _players.ToDictionary(keySelector: player => player.Disboard); // 새로 정의한 MyPlayer들의 NextPlayer를 지정합니다. foreach (var(index, player) in _players.Enumerate()) { int nextPlayerIndex = (index == _players.Count - 1) ? 0 : index + 1; player.NextPlayer = _players[nextPlayerIndex]; } _currentPlayer = _players.First(); // _currentPlayer = _players[0]; // 위 두 줄은 같은 코드입니다. // Send는 그룹 채팅에 메시지를 보내는 함수입니다. // SendImage, SendImages 함수도 사용할 수 있습니다. Send($"첫번째 플레이어: {_currentPlayer.Disboard.Mention}"); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); var dateTimeConverter = new DateTimeToBinaryConverter(); #region Team modelBuilder.Entity <TeamModel>() .HasKey((team) => team.Id); modelBuilder.Entity <TeamModel>() .Property((team) => team.CreatedUTC) .ValueGeneratedOnAdd() .HasDefaultValueSql("getutcdate()") .HasConversion(dateTimeConverter); modelBuilder.Entity <TeamModel>() .Property((team) => team.ModifiedUTC) .ValueGeneratedOnAdd() .HasDefaultValueSql("getutcdate()") .HasConversion(dateTimeConverter); SetAllDateTimePropertiesAsUTC(modelBuilder.Entity <TeamModel>().Metadata.GetProperties()); modelBuilder.Entity <TeamModel>().HasData(InitialTeams.Get()); #endregion Team #region Player modelBuilder.Entity <PlayerModel>() .HasKey((player) => player.Id); modelBuilder.Entity <PlayerModel>() .Property((player) => player.CreatedUTC) .HasDefaultValueSql("getutcdate()") .ValueGeneratedOnAdd() .HasConversion(dateTimeConverter); modelBuilder.Entity <PlayerModel>() .Property((player) => player.ModifiedUTC) .ValueGeneratedOnAdd() .HasDefaultValueSql("getutcdate()") .HasConversion(dateTimeConverter); modelBuilder.Entity <PlayerModel>() .HasOne((player) => player.SelectedTeam) .WithMany((team) => team.PastPlayers) .HasForeignKey((player) => player.SelectedTeamId); SetAllDateTimePropertiesAsUTC(modelBuilder.Entity <PlayerModel>().Metadata.GetProperties()); modelBuilder.Entity <PlayerModel>() .HasData(InitialPlayers.Get()); #endregion Player #region History modelBuilder.Entity <HistoryModel>() .HasKey((history) => history.Id); modelBuilder.Entity <HistoryModel>() .Property((history) => history.CreatedUTC) .ValueGeneratedOnAdd() .HasDefaultValueSql("getutcdate()") .HasConversion(dateTimeConverter); modelBuilder.Entity <HistoryModel>() .Property((history) => history.ModifiedUTC) .ValueGeneratedOnAdd() .HasDefaultValueSql("getutcdate()") .HasConversion(dateTimeConverter); modelBuilder.Entity <HistoryModel>() .Property((history) => history.GameDateUTC) .HasConversion(dateTimeConverter) .IsRequired(); modelBuilder.Entity <HistoryModel>() .HasOne((history) => history.HomeTeam) .WithMany((team) => team.HomeTeamHistories) .HasForeignKey((history) => history.HomeTeamId) .OnDelete(DeleteBehavior.NoAction); modelBuilder.Entity <HistoryModel>() .HasOne((history) => history.AwayTeam) .WithMany((team) => team.AwayTeamHistories) .HasForeignKey((history) => history.AwayTeamId) .OnDelete(DeleteBehavior.NoAction); modelBuilder.Entity <HistoryModel>() .HasOne((history) => history.PlayerHomeTeam) .WithMany((player) => player.HomeGameHistories) .HasForeignKey((history) => history.PlayerHomeTeamId) .OnDelete(DeleteBehavior.Restrict); modelBuilder.Entity <HistoryModel>() .HasOne((history) => history.PlayerAwayTeam) .WithMany((player) => player.AwayGameHistories) .HasForeignKey((history) => history.PlayerAwayTeamId) .OnDelete(DeleteBehavior.Restrict); SetAllDateTimePropertiesAsUTC(modelBuilder.Entity <HistoryModel>().Metadata.GetProperties()); #endregion History #region PlayerHistory modelBuilder.Entity <PlayerHistoryModel>() .HasNoKey() .Ignore("Id") .ToView("PlayerHistoriesView"); modelBuilder.Entity <ScoreBoardModel>() .HasNoKey() .ToView("ScoreBoardView"); #endregion PlayerHistory }