Improves the random choice of players.
This commit is contained in:
1 parent
143b3303f0
commit
cfca322fcd
2 files changed
+17
-129
No files matched your search
@@ -107,8 +107,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
public int Team;
|
||||
public List<Guid> ProfileIDsTeam1;
|
||||
public List<Guid> ProfileIDsTeam2;
|
||||
public List<int> PlayerTeam1;
|
||||
public List<int> PlayerTeam2;
|
||||
|
||||
public ESongSource SongSource;
|
||||
public ESongSorting Sorting;
|
||||
@@ -152,8 +150,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
NumFields = 9,
|
||||
ProfileIDsTeam1 = new List<Guid>(),
|
||||
ProfileIDsTeam2 = new List<Guid>(),
|
||||
PlayerTeam1 = new List<int>(),
|
||||
PlayerTeam2 = new List<int>(),
|
||||
CurrentRoundNr = 0,
|
||||
FieldNr = 0,
|
||||
Sorting = CBase.Config.GetSongSorting(),
|
||||
@@ -184,8 +180,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
|
||||
GameData.Songs.Clear();
|
||||
GameData.Rounds.Clear();
|
||||
GameData.PlayerTeam1.Clear();
|
||||
GameData.PlayerTeam2.Clear();
|
||||
}
|
||||
|
||||
public override bool Init()
|
||||
@@ -248,7 +242,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
GameData.CurrentRoundNr = 1;
|
||||
_CreateRounds();
|
||||
_SetNumJokers();
|
||||
_PreparePlayerList(0);
|
||||
break;
|
||||
case EStage.Main:
|
||||
_Stage = EStage.Singing;
|
||||
@@ -257,7 +250,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
case EStage.Singing:
|
||||
_Stage = EStage.Main;
|
||||
GameData.Team = GameData.Team == 1 ? 0 : 1;
|
||||
_UpdatePlayerList();
|
||||
if (GameData.RefillJokers == EOffOn.TR_CONFIG_ON)
|
||||
_SetNumJokers();
|
||||
break;
|
||||
@@ -338,101 +330,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
}
|
||||
}
|
||||
|
||||
private void _PreparePlayerList(int team)
|
||||
{
|
||||
switch (team)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
GameData.PlayerTeam1 = new List<int>();
|
||||
GameData.PlayerTeam2 = new List<int>();
|
||||
|
||||
//Prepare Player-IDs
|
||||
var ids1 = new List<int>();
|
||||
var ids2 = new List<int>();
|
||||
//Add IDs to team-list
|
||||
while (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0] &&
|
||||
GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1])
|
||||
{
|
||||
if (ids1.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < GameData.NumPlayerTeam1; i++)
|
||||
ids1.Add(i);
|
||||
}
|
||||
if (ids2.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < GameData.NumPlayerTeam2; i++)
|
||||
ids2.Add(i);
|
||||
}
|
||||
int num;
|
||||
if (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0])
|
||||
{
|
||||
num = CBase.Game.GetRandom(ids1.Count);
|
||||
if (num >= ids1.Count)
|
||||
num = ids1.Count - 1;
|
||||
GameData.PlayerTeam1.Add(ids1[num]);
|
||||
ids1.RemoveAt(num);
|
||||
}
|
||||
if (GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1])
|
||||
{
|
||||
num = CBase.Game.GetRandom(ids2.Count);
|
||||
if (num >= ids2.Count)
|
||||
num = ids2.Count - 1;
|
||||
GameData.PlayerTeam2.Add(ids2[num]);
|
||||
ids2.RemoveAt(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
//Prepare Player-IDs
|
||||
var ids = new List<int>();
|
||||
//Add IDs to team-list
|
||||
while (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0] && ids.Count == 0)
|
||||
{
|
||||
if (ids.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < GameData.NumPlayerTeam1; i++)
|
||||
ids.Add(i);
|
||||
}
|
||||
if (GameData.PlayerTeam1.Count < GameData.NumFields + GameData.NumJokerRetry[0])
|
||||
{
|
||||
int num = CBase.Game.GetRandom(ids.Count);
|
||||
if (num >= ids.Count)
|
||||
num = ids.Count - 1;
|
||||
GameData.PlayerTeam1.Add(ids[num]);
|
||||
ids.RemoveAt(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
//Prepare Player-IDs
|
||||
var ids = new List<int>();
|
||||
//Add IDs to team-list
|
||||
while (GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1] && ids.Count == 0)
|
||||
{
|
||||
if (ids.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < GameData.NumPlayerTeam2; i++)
|
||||
ids.Add(i);
|
||||
}
|
||||
if (GameData.PlayerTeam2.Count < GameData.NumFields + GameData.NumJokerRetry[1])
|
||||
{
|
||||
int num = CBase.Game.GetRandom(ids.Count);
|
||||
if (num >= ids.Count)
|
||||
num = ids.Count - 1;
|
||||
GameData.PlayerTeam2.Add(ids[num]);
|
||||
ids.RemoveAt(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateSongList()
|
||||
{
|
||||
if (GameData.Songs.Count > 0)
|
||||
@@ -466,14 +363,6 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
GameData.Songs.Shuffle();
|
||||
}
|
||||
|
||||
private void _UpdatePlayerList()
|
||||
{
|
||||
if (GameData.PlayerTeam1.Count == 0)
|
||||
_PreparePlayerList(1);
|
||||
if (GameData.PlayerTeam2.Count == 0)
|
||||
_PreparePlayerList(2);
|
||||
}
|
||||
|
||||
private void _StartRound(int roundNr)
|
||||
{
|
||||
CBase.Game.Reset();
|
||||
|
||||
@@ -84,6 +84,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
int idPlayer1 = 0;
|
||||
int idPlayer2 = 0;
|
||||
|
||||
private static readonly Random random = new Random();
|
||||
private static readonly object syncLock = new object();
|
||||
|
||||
private int _OldSelectedField = -1;
|
||||
|
||||
private int[,] _Possibilities;
|
||||
@@ -98,7 +101,7 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
_ThemeButtons = new string[]
|
||||
{
|
||||
_ButtonNextRound, _ButtonBack, _ButtonExit, _ButtonPopupYes, _ButtonPopupNo, _ButtonField, _ButtonJokerRandomT1, _ButtonJokerRandomT2, _ButtonJokerRetryT1,
|
||||
_ButtonJokerRetryT2
|
||||
_ButtonJokerRetryT2, _ButtonSwitchPlayerT1, _ButtonSwitchPlayerT2
|
||||
};
|
||||
_ThemeStatics = new string[] { _StaticPopupBG, _StaticAvatarT1, _StaticAvatarT2, _StaticTeam1, _StaticTeam2 };
|
||||
|
||||
@@ -517,53 +520,49 @@ namespace VocaluxeLib.PartyModes.TicTacToe
|
||||
|
||||
private int _GetRamdom(int max)
|
||||
{
|
||||
var rnd = new Random();
|
||||
return Enumerable
|
||||
.Range(1, max)
|
||||
.OrderBy(x => rnd.Next())
|
||||
.ToArray()[0];
|
||||
lock (syncLock)
|
||||
{
|
||||
return random.Next(max+1);
|
||||
}
|
||||
}
|
||||
|
||||
private void _ChangePlayer(int teamNr = -1, bool next = false)
|
||||
{
|
||||
int singerTeam1 = 0;
|
||||
int singerTeam2 = 0;
|
||||
|
||||
if (_PartyMode.GameData.PlayerTeam1.Count > 0 && (teamNr == 0 || teamNr == -1))
|
||||
if (_PartyMode.GameData.ProfileIDsTeam1.Count > 0 && (teamNr == 0 || teamNr == -1))
|
||||
{
|
||||
if (next == true)
|
||||
{
|
||||
idPlayer1++;
|
||||
if (idPlayer1 >= _PartyMode.GameData.PlayerTeam1.Count)
|
||||
if (idPlayer1 >= _PartyMode.GameData.ProfileIDsTeam1.Count)
|
||||
{
|
||||
idPlayer1 = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
idPlayer1 = _GetRamdom(_PartyMode.GameData.PlayerTeam1.Count - 1);
|
||||
idPlayer1 = _GetRamdom(_PartyMode.GameData.ProfileIDsTeam1.Count - 1);
|
||||
}
|
||||
|
||||
singerTeam1 = _PartyMode.GameData.PlayerTeam1[idPlayer1];
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = singerTeam1;
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam1 = idPlayer1;
|
||||
}
|
||||
|
||||
if (_PartyMode.GameData.PlayerTeam2.Count > 0 && (teamNr == 1 || teamNr == -1))
|
||||
if (_PartyMode.GameData.ProfileIDsTeam2.Count > 0 && (teamNr == 1 || teamNr == -1))
|
||||
{
|
||||
if (next == true)
|
||||
{
|
||||
idPlayer2++;
|
||||
if (idPlayer2 >= _PartyMode.GameData.PlayerTeam2.Count)
|
||||
if (idPlayer2 >= _PartyMode.GameData.ProfileIDsTeam2.Count)
|
||||
{
|
||||
idPlayer2 = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
idPlayer2 = _GetRamdom(_PartyMode.GameData.PlayerTeam2.Count - 1);
|
||||
idPlayer2 = _GetRamdom(_PartyMode.GameData.ProfileIDsTeam2.Count - 1);
|
||||
}
|
||||
singerTeam2 = _PartyMode.GameData.PlayerTeam2[idPlayer2];
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = singerTeam2;
|
||||
|
||||
_PartyMode.GameData.Rounds[_PartyMode.GameData.FieldNr].SingerTeam2 = idPlayer2;
|
||||
}
|
||||
|
||||
_UpdatePlayerInformation();
|
||||
|
||||
Reference in new issue
Block a user