public void TpResult(Player player, bool result) { if (State != GameState.Starting) { return; } if (player.Type != _startplayer) { return; } int opt = MasterRule << 16; if (EnablePriority) { opt += 0x08; } if (NoShuffleDeck) { opt += 0x10; } if (IsTag) { opt += 0x20; } if (result && player.Type == (IsTag ? 2 : 1) || !result && player.Type == 0) { opt += 0x80; } CurPlayers[0] = Players[0]; CurPlayers[1] = Players[IsTag ? 2 : 1]; State = GameState.Duel; int seed = Environment.TickCount; _duel = Duel.Create((uint)seed); Random rand = new Random(seed); _duel.SetAnalyzer(_analyser.Analyse); _duel.SetErrorHandler(HandleError); _duel.InitPlayers(StartLp, StartHand, DrawCount); Replay = new Replay((uint)seed, IsTag); Replay.Writer.WriteUnicode(Players[0].Name, 20); Replay.Writer.WriteUnicode(Players[1].Name, 20); if (IsTag) { Replay.Writer.WriteUnicode(Players[2].Name, 20); Replay.Writer.WriteUnicode(Players[3].Name, 20); } Replay.Writer.Write(StartLp); Replay.Writer.Write(StartHand); Replay.Writer.Write(DrawCount); Replay.Writer.Write(opt); for (int i = 0; i < Players.Length; i++) { Player dplayer = Players[i]; int pid = i; if (IsTag) { pid = i >= 2 ? 1 : 0; } if (!NoShuffleDeck) { List <int> cards = ShuffleCards(rand, dplayer.Deck.Main); Replay.Writer.Write(cards.Count); foreach (int id in cards) { if (IsTag && (i == 1 || i == 3)) { _duel.AddTagCard(id, pid, CardLocation.Deck); } else { _duel.AddCard(id, pid, CardLocation.Deck); } Replay.Writer.Write(id); } } else { Replay.Writer.Write(dplayer.Deck.Main.Count); for (int j = dplayer.Deck.Main.Count - 1; j >= 0; j--) { int id = dplayer.Deck.Main[j]; if (IsTag && (i == 1 || i == 3)) { _duel.AddTagCard(id, pid, CardLocation.Deck); } else { _duel.AddCard(id, pid, CardLocation.Deck); } Replay.Writer.Write(id); } } Replay.Writer.Write(dplayer.Deck.Extra.Count); foreach (int id in dplayer.Deck.Extra) { if (IsTag && (i == 1 || i == 3)) { _duel.AddTagCard(id, pid, CardLocation.Extra); } else { _duel.AddCard(id, pid, CardLocation.Extra); } Replay.Writer.Write(id); } } BinaryWriter packet = GamePacketFactory.Create(GameMessage.Start); packet.Write((byte)0); packet.Write((byte)MasterRule); packet.Write(StartLp); packet.Write(StartLp); packet.Write((short)_duel.QueryFieldCount(0, CardLocation.Deck)); packet.Write((short)_duel.QueryFieldCount(0, CardLocation.Extra)); packet.Write((short)_duel.QueryFieldCount(1, CardLocation.Deck)); packet.Write((short)_duel.QueryFieldCount(1, CardLocation.Extra)); SendToTeam(packet, 0); packet.BaseStream.Position = 2; packet.Write((byte)1); SendToTeam(packet, 1); packet.BaseStream.Position = 2; packet.Write((byte)0x10); SendToObservers(packet); RefreshExtra(0); RefreshExtra(1); _duel.Start(opt); TurnCount = 0; LifePoints[0] = StartLp; LifePoints[1] = StartLp; TimeReset(); Process(); }
public void TpResult(Player player, bool result) { if (State != GameState.Starting) { return; } if (player.Type != _startplayer) { return; } _swapped = false; if (result && player.Type == (IsTag ? 2 : 1) || !result && player.Type == 0) { _swapped = true; if (IsTag) { Player temp = Players[0]; Players[0] = Players[2]; Players[2] = temp; temp = Players[1]; Players[1] = Players[3]; Players[3] = temp; Players[0].Type = 0; Players[1].Type = 1; Players[2].Type = 2; Players[3].Type = 3; } else { Player temp = Players[0]; Players[0] = Players[1]; Players[1] = temp; Players[0].Type = 0; Players[1].Type = 1; } } CurPlayers[0] = Players[0]; CurPlayers[1] = Players[IsTag ? 3 : 1]; State = GameState.Duel; int seed = Environment.TickCount; _duel = Duel.Create((uint)seed); Random rand = new Random(seed); int startLp = Config.GetInt("StartLp", DEFAULT_LIFEPOINTS); int startHand = Config.GetInt("StartHand", DEFAULT_START_HAND); int drawCount = Config.GetInt("DrawCount", DEFAULT_DRAW_COUNT); bool enablePriority = Config.GetBool("EnablePriority"); bool noShuffleDeck = Config.GetBool("NoShuffleDeck"); _duel.SetAnalyzer(_analyser.Analyse); _duel.SetErrorHandler(HandleError); _duel.InitPlayers(startLp, startHand, drawCount); int opt = 0; if (enablePriority) { opt += 0x08; } if (noShuffleDeck) { opt += 0x10; } if (IsTag) { opt += 0x20; } Replay = new Replay((uint)seed, IsTag); Replay.Writer.WriteUnicode(Players[0].Name, 20); Replay.Writer.WriteUnicode(Players[1].Name, 20); if (IsTag) { Replay.Writer.WriteUnicode(Players[2].Name, 20); Replay.Writer.WriteUnicode(Players[3].Name, 20); } Replay.Writer.Write(startLp); Replay.Writer.Write(startHand); Replay.Writer.Write(drawCount); Replay.Writer.Write(opt); for (int i = 0; i < Players.Length; i++) { Player dplayer = Players[i == 2 ? 3 : (i == 3 ? 2 : i)]; int pid = i; if (IsTag) { pid = i >= 2 ? 1 : 0; } if (!noShuffleDeck) { List <int> cards = ShuffleCards(rand, dplayer.Deck.Main); Replay.Writer.Write(cards.Count); foreach (int id in cards) { if (IsTag && (i == 1 || i == 3)) { _duel.AddTagCard(id, pid, CardLocation.Deck); } else { _duel.AddCard(id, pid, CardLocation.Deck); } Replay.Writer.Write(id); } } else { Replay.Writer.Write(dplayer.Deck.Main.Count); for (int j = dplayer.Deck.Main.Count - 1; j >= 0; j--) { int id = dplayer.Deck.Main[j]; if (IsTag && (i == 1 || i == 3)) { _duel.AddTagCard(id, pid, CardLocation.Deck); } else { _duel.AddCard(id, pid, CardLocation.Deck); } Replay.Writer.Write(id); } } Replay.Writer.Write(dplayer.Deck.Extra.Count); foreach (int id in dplayer.Deck.Extra) { if (IsTag && (i == 1 || i == 3)) { _duel.AddTagCard(id, pid, CardLocation.Extra); } else { _duel.AddCard(id, pid, CardLocation.Extra); } Replay.Writer.Write(id); } } GamePacketWriter packet = GamePacketFactory.Create(GameMessage.Start); packet.Write((byte)0); packet.Write(startLp); packet.Write(startLp); packet.Write((short)_duel.QueryFieldCount(0, CardLocation.Deck)); packet.Write((short)_duel.QueryFieldCount(0, CardLocation.Extra)); packet.Write((short)_duel.QueryFieldCount(1, CardLocation.Deck)); packet.Write((short)_duel.QueryFieldCount(1, CardLocation.Extra)); SendToTeam(packet, 0); packet.SetPosition(2); packet.Write((byte)1); SendToTeam(packet, 1); packet.SetPosition(2); if (_swapped) { packet.Write((byte)0x11); } else { packet.Write((byte)0x10); } SendToObservers(packet); RefreshExtra(0); RefreshExtra(1); _duel.Start(opt); TurnCount = 0; LifePoints[0] = startLp; LifePoints[1] = startLp; TimeReset(); Process(); }