Esempio n. 1
0
        private void InitializeTester()
        {
            if (!PREDEFINED_TEST)
            {
                return;
            }

            if (BeatmapManager.Beatmaps.Count > 0)
            {
                if (USE_LAST_PLAYED_BEATMAP)
                {
                    List <Beatmap> temp = new List <Beatmap>(BeatmapManager.Beatmaps);
                    temp.Sort((a, b) => { return(a.DateLastPlayed.CompareTo(b.DateLastPlayed)); });
                    BeatmapManager.Current = temp[temp.Count - 1];
                }
                else //Choose a random beatmap
                {
                    BeatmapManager.Current = BeatmapManager.Beatmaps[RNG.Next(0, BeatmapManager.Beatmaps.Count)];
                }
            }

            if (MULTIPLAYER_MATCH)
            {
                if (BeatmapManager.Current == null)
                {
                    NotificationManager.ShowMessage("Couldn't start in specified test mode because no beatmaps were available.");
                    return;
                }

                BanchoClient.Start();

                Mode = OsuModes.MatchSetup;

                const int player_count = 8;

                while (!BanchoClient.Connected || !BanchoClient.InitializationComplete)
                {
                    Scheduler.Update();
                }

                PresenceCache.QueryAll();

                while (User.Id <= 0 || BanchoClient.Users.Count < player_count)
                {
                    Scheduler.Update();
                }

                List <User> users = BanchoClient.Users.FindAll(u => u.InitialLoadComplete && u.Id != User.Id);
                users.Insert(0, User); //we are the first user.

                MatchSetup.Match = new ClientSideMatch(new bMatch(MatchTypes.Standard,
                                                                  MatchScoringTypes.Score,
                                                                  MatchTeamTypes.TeamVs,
                                                                  PlayModes.Osu,
                                                                  @"My test game",
                                                                  string.Empty,
                                                                  player_count,
                                                                  BeatmapManager.Current.SortTitle,
                                                                  BeatmapManager.Current.BeatmapChecksum,
                                                                  BeatmapManager.Current.BeatmapId,
                                                                  MODS_TO_USE,
                                                                  2,
                                                                  MultiSpecialModes.FreeMod
                                                                  ));

                for (int i = 0; i < player_count; i++)
                {
                    MatchSetup.Match.slotId[i]    = users[i].Id;
                    MatchSetup.Match.UserSlots[i] = users[i];

                    MatchSetup.Match.slotStatus[i] = SlotStatus.Playing;
                    switch (MatchSetup.Match.matchTeamType)
                    {
                    case MatchTeamTypes.TagTeamVs:
                    case MatchTeamTypes.TeamVs:
                        MatchSetup.Match.slotTeam[i] = i % 2 == 0 ? SlotTeams.Blue : SlotTeams.Red;
                        break;
                    }
                }

                bScoreFrame[] frames = new bScoreFrame[player_count];
                for (int i = 0; i < player_count; i++)
                {
                    frames[i] = new bScoreFrame {
                        id = (byte)i, pass = true, currentHp = 200
                    }
                }
                ;

                RunBackgroundThread(delegate
                {
                    Thread.Sleep(5000);

                    for (int i = 0; i < player_count; i++)
                    {
                        PlayerVs.MatchPlayerSkipped(i);
                        Thread.Sleep(100);
                    }

                    Thread.Sleep(2000);

                    Player.QueueSkip();
                    Player.Instance?.DoSkip();

                    PlayerVs.AllPlayersLoaded    = true;
                    PlayerVs.AllPlayersCompleted = true;

                    while (true)
                    {
                        byte player = (byte)RNG.Next(0, player_count);

                        switch (RNG.Next(0, 30))
                        {
                        default:
                            frames[player].count300 += 1;
                            frames[player].currentCombo++;
                            frames[player].currentHp += 3;
                            break;

                        case 1:
                        case 2:
                        case 3:
                            frames[player].count100 += 1;
                            frames[player].currentCombo++;
                            frames[player].currentHp += 2;
                            break;

                        case 4:
                        case 5:
                            frames[player].count50   += 1;
                            frames[player].currentHp += 1;
                            frames[player].currentCombo++;
                            break;

                        case 6:
                            frames[player].countMiss   += 1;
                            frames[player].currentHp   -= 50;
                            frames[player].currentCombo = 0;
                            break;
                        }

                        frames[player].currentHp = OsuMathHelper.Clamp(frames[player].currentHp, 0, 200);

                        if (frames[player].currentHp == 0)
                        {
                            frames[player].pass = false;
                        }
                        else if (frames[player].currentHp > 100)
                        {
                            frames[player].pass = true;
                        }

                        frames[player].totalScore += frames[player].currentCombo * 300;
                        frames[player].maxCombo    = Math.Max(frames[player].maxCombo, frames[player].currentCombo);


                        PlayerVs.MatchScoreUpdate(frames[player]);

                        Thread.Sleep(50);
                    }
                });
            }

            switch (INITIAL_MODE)
            {
            case OsuModes.Play:
                if (BeatmapManager.Current == null)
                {
                    NotificationManager.ShowMessage("Couldn't start in specified test mode because no beatmaps were available.");
                    return;
                }

                ModManager.ModStatus = MODS_TO_USE;

                if (AUTOMATIC_SKIP)
                {
                    GameBase.RunBackgroundThread(delegate
                    {
                        while (true)
                        {
                            if (Player.Instance != null && Player.Instance.Status != PlayerStatus.Busy)
                            {
                                Scheduler.Add(delegate { Player.Instance?.DoSkip(); });
                                if (Player.HasSkipped)
                                {
                                    break;
                                }
                            }

                            Thread.Sleep(200);
                        }
                    });
                }

                if (AUTOPLAY)
                {
                    ModManager.ModStatus |= Mods.Autoplay;
                }

                break;
            }

            QueuedMode  = INITIAL_MODE;
            Player.Mode = INITIAL_PLAY_MODE;
        }
    }