2021-08-02 17:31:56 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Database;
|
2021-11-11 15:39:59 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-11-30 16:09:32 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-08-03 16:08:19 +08:00
|
|
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
2021-08-02 17:31:56 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-08-05 19:52:40 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
2021-08-02 17:31:56 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
2021-08-03 16:26:10 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
2021-08-02 17:31:56 +08:00
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
|
|
|
public class TestSceneTeamVersus : ScreenTestScene
|
|
|
|
{
|
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
private BeatmapSetInfo importedSet;
|
|
|
|
|
2021-10-28 13:29:49 +08:00
|
|
|
private TestMultiplayerScreenStack multiplayerScreenStack;
|
|
|
|
|
|
|
|
private TestMultiplayerClient client => multiplayerScreenStack.Client;
|
2021-08-02 17:31:56 +08:00
|
|
|
|
|
|
|
[Cached(typeof(UserLookupCache))]
|
|
|
|
private UserLookupCache lookupCache = new TestUserLookupCache();
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
|
|
|
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
|
|
|
|
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("import beatmap", () =>
|
|
|
|
{
|
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).Wait();
|
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSetsEnumerable(IncludedDetails.All).First();
|
|
|
|
});
|
|
|
|
|
2021-10-28 13:29:49 +08:00
|
|
|
AddStep("load multiplayer", () => LoadScreen(multiplayerScreenStack = new TestMultiplayerScreenStack()));
|
|
|
|
AddUntilStep("wait for multiplayer to load", () => multiplayerScreenStack.IsLoaded);
|
2021-08-02 17:31:56 +08:00
|
|
|
AddUntilStep("wait for lounge to load", () => this.ChildrenOfType<MultiplayerLoungeSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:08:19 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCreateWithType()
|
|
|
|
{
|
|
|
|
createRoom(() => new Room
|
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Type = { Value = MatchType.TeamVersus },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-08 03:40:10 +08:00
|
|
|
AddUntilStep("room type is team vs", () => client.Room?.Settings.MatchType == MatchType.TeamVersus);
|
2021-08-03 16:08:19 +08:00
|
|
|
AddAssert("user state arrived", () => client.Room?.Users.FirstOrDefault()?.MatchState is TeamVersusUserState);
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:26:10 +08:00
|
|
|
[Test]
|
|
|
|
public void TestChangeTeamsViaButton()
|
|
|
|
{
|
|
|
|
createRoom(() => new Room
|
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Type = { Value = MatchType.TeamVersus },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("user on team 0", () => (client.Room?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
|
2021-11-11 15:39:59 +08:00
|
|
|
AddStep("add another user", () => client.AddUser(new APIUser { Username = "otheruser", Id = 44 }));
|
2021-08-03 16:26:10 +08:00
|
|
|
|
2021-11-11 15:39:59 +08:00
|
|
|
AddStep("press own button", () =>
|
2021-08-03 16:26:10 +08:00
|
|
|
{
|
2021-10-28 13:29:49 +08:00
|
|
|
InputManager.MoveMouseTo(multiplayerScreenStack.ChildrenOfType<TeamDisplay>().First());
|
2021-08-03 16:26:10 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
AddAssert("user on team 1", () => (client.Room?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 1);
|
|
|
|
|
2021-11-11 15:39:59 +08:00
|
|
|
AddStep("press own button again", () => InputManager.Click(MouseButton.Left));
|
2021-08-03 16:26:10 +08:00
|
|
|
AddAssert("user on team 0", () => (client.Room?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
|
2021-11-11 15:39:59 +08:00
|
|
|
|
|
|
|
AddStep("press other user's button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(multiplayerScreenStack.ChildrenOfType<TeamDisplay>().ElementAt(1));
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
AddAssert("user still on team 0", () => (client.Room?.Users.FirstOrDefault()?.MatchState as TeamVersusUserState)?.TeamID == 0);
|
2021-08-03 16:26:10 +08:00
|
|
|
}
|
|
|
|
|
2021-11-30 16:09:32 +08:00
|
|
|
[Test]
|
2021-11-30 16:16:30 +08:00
|
|
|
public void TestSettingsUpdatedWhenChangingMatchType()
|
2021-11-30 16:09:32 +08:00
|
|
|
{
|
|
|
|
createRoom(() => new Room
|
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
2021-12-01 03:57:02 +08:00
|
|
|
Type = { Value = MatchType.HeadToHead },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
2021-11-30 16:09:32 +08:00
|
|
|
});
|
|
|
|
|
2021-12-01 03:57:02 +08:00
|
|
|
AddUntilStep("match type head to head", () => client.APIRoom?.Type.Value == MatchType.HeadToHead);
|
2021-11-30 16:09:32 +08:00
|
|
|
|
|
|
|
AddStep("change match type", () => client.ChangeSettings(new MultiplayerRoomSettings
|
|
|
|
{
|
|
|
|
MatchType = MatchType.TeamVersus
|
|
|
|
}));
|
|
|
|
|
2021-12-01 03:57:02 +08:00
|
|
|
AddUntilStep("api room updated to team versus", () => client.APIRoom?.Type.Value == MatchType.TeamVersus);
|
2021-11-30 16:09:32 +08:00
|
|
|
}
|
|
|
|
|
2021-08-02 17:31:56 +08:00
|
|
|
[Test]
|
|
|
|
public void TestChangeTypeViaMatchSettings()
|
|
|
|
{
|
|
|
|
createRoom(() => new Room
|
|
|
|
{
|
|
|
|
Name = { Value = "Test Room" },
|
|
|
|
Playlist =
|
|
|
|
{
|
|
|
|
new PlaylistItem
|
|
|
|
{
|
|
|
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
|
|
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-08 03:40:10 +08:00
|
|
|
AddUntilStep("room type is head to head", () => client.Room?.Settings.MatchType == MatchType.HeadToHead);
|
2021-08-02 17:31:56 +08:00
|
|
|
|
2021-11-10 12:44:24 +08:00
|
|
|
AddUntilStep("team displays are not displaying teams", () => multiplayerScreenStack.ChildrenOfType<TeamDisplay>().All(d => d.DisplayedTeam == null));
|
|
|
|
|
2021-08-02 17:31:56 +08:00
|
|
|
AddStep("change to team vs", () => client.ChangeSettings(matchType: MatchType.TeamVersus));
|
|
|
|
|
2021-12-08 03:40:10 +08:00
|
|
|
AddUntilStep("room type is team vs", () => client.Room?.Settings.MatchType == MatchType.TeamVersus);
|
2021-11-10 12:44:24 +08:00
|
|
|
|
|
|
|
AddUntilStep("team displays are displaying teams", () => multiplayerScreenStack.ChildrenOfType<TeamDisplay>().All(d => d.DisplayedTeam != null));
|
2021-08-02 17:31:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void createRoom(Func<Room> room)
|
|
|
|
{
|
2021-10-28 13:29:49 +08:00
|
|
|
AddStep("open room", () => multiplayerScreenStack.ChildrenOfType<LoungeSubScreen>().Single().Open(room()));
|
2021-08-02 17:31:56 +08:00
|
|
|
|
|
|
|
AddUntilStep("wait for room open", () => this.ChildrenOfType<MultiplayerMatchSubScreen>().FirstOrDefault()?.IsLoaded == true);
|
|
|
|
AddWaitStep("wait for transition", 2);
|
|
|
|
|
2021-12-01 03:56:11 +08:00
|
|
|
AddUntilStep("create room button enabled", () => this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single().Enabled.Value);
|
2021-08-02 17:31:56 +08:00
|
|
|
AddStep("create room", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerMatchSettingsOverlay.CreateOrUpdateButton>().Single());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
2021-11-23 15:04:11 +08:00
|
|
|
AddUntilStep("wait for join", () => multiplayerScreenStack.RoomManager.RoomJoined);
|
2021-08-02 17:31:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|