private void OnJoinGame(GameServerPacket packet) { uint banlist = packet.ReadUInt32(); int rule = packet.ReadByte(); int mode = packet.ReadByte(); //TODO tag _room.IsTag = mode == 2; Logger.WriteLine("istag = " + _room.IsTag); GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck); deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count); deck.Write(Deck.SideCards.Count); foreach (Card card in Deck.Cards) { deck.Write(card.Id); } foreach (Card card in Deck.ExtraCards) { deck.Write(card.Id); } foreach (Card card in Deck.SideCards) { deck.Write(card.Id); } Connection.Send(deck); }
private void OnSelectEffectYn(GameServerPacket packet) { packet.ReadByte(); // player int cardId = packet.ReadInt32(); int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); packet.ReadByte(); ClientCard card = _duel.GetCard(player, loc, seq); if (card == null) { Connection.Send(CtosMessage.Response, 0); return; } if (card.Id == 0) { card.SetId(cardId); } int reply = _ai.OnSelectEffectYn(card) ? (1) : (0); Connection.Send(CtosMessage.Response, reply); }
private void OnAnnounceAttrib(GameServerPacket packet) { IList <CardAttribute> attributes = new List <CardAttribute>(); packet.ReadByte(); // player int count = packet.ReadByte(); int available = packet.ReadInt32(); int filter = 0x1; for (int i = 0; i < 7; ++i) { if ((available & filter) != 0) { attributes.Add((CardAttribute)filter); } filter <<= 1; } attributes = m_ai.OnAnnounceAttrib(count, attributes); int reply = 0; for (int i = 0; i < count; ++i) { reply += (int)attributes[i]; } Connection.Send(CtosMessage.Response, reply); }
private void OnAnnounceRace(GameServerPacket packet) { IList <CardRace> races = new List <CardRace>(); packet.ReadByte(); // player int count = packet.ReadByte(); int available = packet.ReadInt32(); int filter = 0x1; for (int i = 0; i < 23; ++i) { if ((available & filter) != 0) { races.Add((CardRace)filter); } filter <<= 1; } races = _ai.OnAnnounceRace(count, races); int reply = 0; for (int i = 0; i < count; ++i) { reply += (int)races[i]; } Connection.Send(CtosMessage.Response, reply); }
private void OnSelectPosition(GameServerPacket packet) { packet.ReadByte(); // player int cardId = packet.ReadInt32(); int pos = packet.ReadByte(); if (pos == 0x1 || pos == 0x2 || pos == 0x4 || pos == 0x8) { Connection.Send(CtosMessage.Response, pos); return; } IList <CardPosition> positions = new List <CardPosition>(); if ((pos & (int)CardPosition.FaceUpAttack) != 0) { positions.Add(CardPosition.FaceUpAttack); } if ((pos & (int)CardPosition.FaceDownAttack) != 0) { positions.Add(CardPosition.FaceDownAttack); } if ((pos & (int)CardPosition.FaceUpDefence) != 0) { positions.Add(CardPosition.FaceUpDefence); } if ((pos & (int)CardPosition.FaceDownDefence) != 0) { positions.Add(CardPosition.FaceDownDefence); } Connection.Send(CtosMessage.Response, (int)_ai.OnSelectPosition(cardId, positions)); }
private void OnShuffleHand(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); packet.ReadByte(); foreach (ClientCard card in _duel.Fields[player].Hand) { card.SetId(packet.ReadInt32()); } }
private void OnUpdateData(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); IList <ClientCard> cards = null; switch (loc) { case CardLocation.Hand: cards = _duel.Fields[player].Hand; break; case CardLocation.MonsterZone: cards = _duel.Fields[player].MonsterZone; break; case CardLocation.SpellZone: cards = _duel.Fields[player].SpellZone; break; case CardLocation.Grave: cards = _duel.Fields[player].Graveyard; break; case CardLocation.Removed: cards = _duel.Fields[player].Banished; break; case CardLocation.Deck: cards = _duel.Fields[player].Deck; break; case CardLocation.Extra: cards = _duel.Fields[player].ExtraDeck; break; } if (cards != null) { foreach (ClientCard card in cards) { try{ int len = packet.ReadInt32(); if (len < 8) { continue; } long pos = packet.GetPosition(); card.Update(packet, _duel); packet.SetPosition(pos + len - 4); }catch (Exception) { } } } }
private void OnDraw(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { _duel.Fields[player].Deck.RemoveAt(_duel.Fields[player].Deck.Count - 1); _duel.Fields[player].Hand.Add(new ClientCard(0, CardLocation.Hand)); } }
private void OnMove(GameServerPacket packet) { int cardId = packet.ReadInt32(); int pc = GetLocalPlayer(packet.ReadByte()); int pl = packet.ReadByte(); int ps = packet.ReadSByte(); packet.ReadSByte(); // pp int cc = GetLocalPlayer(packet.ReadByte()); int cl = packet.ReadByte(); int cs = packet.ReadSByte(); int cp = packet.ReadSByte(); packet.ReadInt32(); // reason ClientCard card = _duel.GetCard(pc, (CardLocation)pl, ps); if ((pl & (int)CardLocation.Overlay) != 0) { pl = pl & 0x7f; card = _duel.GetCard(pc, (CardLocation)pl, ps); if (card != null) { card.Overlays.Remove(cardId); } } else { _duel.RemoveCard((CardLocation)pl, card, pc, ps); } if ((cl & (int)CardLocation.Overlay) != 0) { cl = cl & 0x7f; card = _duel.GetCard(cc, (CardLocation)cl, cs); if (card != null) { card.Overlays.Add(cardId); } } else { _duel.AddCard((CardLocation)cl, cardId, cc, cs, cp); if ((pl & (int)CardLocation.Overlay) == 0 && card != null) { ClientCard newcard = _duel.GetCard(cc, (CardLocation)cl, cs); if (newcard != null) { newcard.Overlays.AddRange(card.Overlays); } } } }
private void OnChaining(GameServerPacket packet) { packet.ReadInt32(); // card id int pcc = GetLocalPlayer(packet.ReadByte()); int pcl = packet.ReadByte(); int pcs = packet.ReadSByte(); int subs = packet.ReadSByte(); ClientCard card = _duel.GetCard(pcc, pcl, pcs, subs); int cc = GetLocalPlayer(packet.ReadByte()); _ai.OnChaining(card, cc); }
private void OnAnnounceNumber(GameServerPacket packet) { IList <int> numbers = new List <int>(); packet.ReadByte(); // player int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { numbers.Add(packet.ReadInt32()); } Connection.Send(CtosMessage.Response, _ai.OnAnnounceNumber(numbers)); }
private void OnChaining(GameServerPacket packet) { packet.ReadInt32(); // card id int pcc = GetLocalPlayer(packet.ReadByte()); int pcl = packet.ReadByte(); int pcs = packet.ReadSByte(); packet.ReadSByte(); // subs ClientCard card = m_duel.GetCard(pcc, (CardLocation)pcl, pcs); int cc = GetLocalPlayer(packet.ReadByte()); m_ai.OnChaining(card, cc); }
private void OnSelectOption(GameServerPacket packet) { IList <int> options = new List <int>(); packet.ReadByte(); // player int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { options.Add(packet.ReadInt32()); } Connection.Send(CtosMessage.Response, _ai.OnSelectOption(options)); }
private void OnSelectYesNo(GameServerPacket packet) { packet.ReadByte(); // player int reply = _ai.OnSelectYesNo(packet.ReadInt32()) ? (1) : (0); Connection.Send(CtosMessage.Response, reply); }
private void OnStart(GameServerPacket packet) { int type = packet.ReadByte(); m_duel.IsFirst = (type & 0xF) == 0; m_duel.LifePoints[GetLocalPlayer(0)] = packet.ReadInt32(); m_duel.LifePoints[GetLocalPlayer(1)] = packet.ReadInt32(); int deck = packet.ReadInt16(); int extra = packet.ReadInt16(); m_duel.Fields[GetLocalPlayer(0)].Init(deck, extra); deck = packet.ReadInt16(); extra = packet.ReadInt16(); m_duel.Fields[GetLocalPlayer(1)].Init(deck, extra); if (!Game.IsCheckmate && m_room.Names[0] != Program.Config.Username && m_room.Names[1] != Program.Config.Username) { Connection.Close(); return; } Logger.WriteLine("Duel started! " + m_room.Names[0] + " versus " + m_room.Names[1] + "."); m_ai.OnStart(); if (Game.IsCheckmate) { Game.CheckmateClient.OnStart(); } }
private void OnPosChange(GameServerPacket packet) { packet.ReadInt32(); // card id int pc = GetLocalPlayer(packet.ReadByte()); int pl = packet.ReadByte(); int ps = packet.ReadSByte(); packet.ReadSByte(); // pp int cp = packet.ReadSByte(); ClientCard card = _duel.GetCard(pc, (CardLocation)pl, ps); if (card != null) { card.Position = cp; } }
private void OnUpdateCard(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); int loc = packet.ReadByte(); int seq = packet.ReadByte(); packet.ReadInt32(); // ??? ClientCard card = _duel.GetCard(player, (CardLocation)loc, seq); if (card == null) { return; } card.Update(packet, _duel); }
private void OnSelectSum(GameServerPacket packet) { packet.ReadByte(); // mode packet.ReadByte(); // player int sumval = packet.ReadInt32(); int min = packet.ReadByte(); int max = packet.ReadByte(); IList <ClientCard> cards = new List <ClientCard>(); int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { int cardId = packet.ReadInt32(); int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); ClientCard card = _duel.GetCard(player, loc, seq); if (card != null) { if (cardId != 0 && card.Id != cardId) { card.SetId(cardId); } cards.Add(card); } packet.ReadInt32(); } IList <ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max); byte[] result = new byte[selected.Count + 1]; result[0] = (byte)selected.Count; for (int i = 0; i < selected.Count; ++i) { int id = 0; for (int j = 0; j < count; ++j) { if (cards[j] == null) { continue; } if (cards[j].Equals(selected[i])) { id = j; break; } } result[i + 1] = (byte)id; } GameClientPacket reply = new GameClientPacket(CtosMessage.Response); reply.Write(result); Connection.Send(reply); }
private void OnSelectCounter(GameServerPacket packet) { packet.ReadByte(); // player int type = packet.ReadInt16(); int quantity = packet.ReadByte(); IList <ClientCard> cards = new List <ClientCard>(); IList <int> counters = new List <int>(); int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // card id int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); int num = packet.ReadByte(); cards.Add(_duel.GetCard(player, loc, seq)); counters.Add(num); } IList <int> used = _ai.OnSelectCounter(type, quantity, cards, counters); byte[] result = new byte[used.Count]; for (int i = 0; i < quantity; ++i) { result[i] = (byte)used[i]; } GameClientPacket reply = new GameClientPacket(CtosMessage.Response); reply.Write(result); Connection.Send(reply); }
private void OnWin(GameServerPacket packet) { int result = GetLocalPlayer(packet.ReadByte()); string otherName = _room.Names[0] == Game.Username ? _room.Names[1] : _room.Names[0]; string textResult = (result == 2 ? "Draw" : result == 0 ? "Win" : "Lose"); Logger.WriteLine("Duel finished against " + otherName + ", result: " + textResult); }
private void OnTimeLimit(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); if (player == 0) { Connection.Send(CtosMessage.TimeConfirm); } }
private void OnPlayerEnter(GameServerPacket packet) { string name = packet.ReadUnicode(20); int pos = packet.ReadByte(); if (pos < 8) { _room.Names[pos] = name; } }
private void OnMove(GameServerPacket packet) { int cardId = packet.ReadInt32(); int pc = GetLocalPlayer(packet.ReadByte()); int pl = packet.ReadByte(); int ps = packet.ReadSByte(); packet.ReadSByte(); // pp int cc = GetLocalPlayer(packet.ReadByte()); int cl = packet.ReadByte(); int cs = packet.ReadSByte(); int cp = packet.ReadSByte(); packet.ReadInt32(); // reason ClientCard card = m_duel.GetCard(pc, (CardLocation)pl, ps); m_duel.RemoveCard((CardLocation)pl, card, pc, ps); m_duel.AddCard((CardLocation)cl, cardId, cc, cs, cp); }
private void OnDamage(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); int final = _duel.LifePoints[player] - packet.ReadInt32(); if (final < 0) { final = 0; } _duel.LifePoints[player] = final; }
private void OnWin(GameServerPacket packet) { int result = GetLocalPlayer(packet.ReadByte()); string otherName = m_room.Names[0] == Program.Config.Username ? m_room.Names[1] : m_room.Names[0]; string textResult = (result == 2 ? "Draw" : result == 0 ? "Win" : "Lose"); Logger.WriteLine("Duel finished against " + otherName + "! Result: " + textResult + "."); if (Game.IsCheckmate) { Game.CheckmateClient.OnStart(); } }
private void OnTypeChange(GameServerPacket packet) { int type = packet.ReadByte(); int pos = type & 0xF; if (pos != 0 && pos != 1) { Connection.Close(); return; } _room.IsHost = ((type >> 4) & 0xF) != 0; _room.IsReady[pos] = true; Connection.Send(CtosMessage.HsReady); }
private void OnPlayerEnter(GameServerPacket packet) { string name = packet.ReadUnicode(20); if (name.StartsWith("[err]")) { Logger.WriteLine(name); Connection.Close(); return; } int pos = packet.ReadByte(); if (pos < 8) { _room.Names[pos] = name; } }
private void OnStart(GameServerPacket packet) { int type = packet.ReadByte(); _duel.IsFirst = (type & 0xF) == 0; _duel.LifePoints[GetLocalPlayer(0)] = packet.ReadInt32(); _duel.LifePoints[GetLocalPlayer(1)] = packet.ReadInt32(); int deck = packet.ReadInt16(); int extra = packet.ReadInt16(); _duel.Fields[GetLocalPlayer(0)].Init(deck, extra); deck = packet.ReadInt16(); extra = packet.ReadInt16(); _duel.Fields[GetLocalPlayer(1)].Init(deck, extra); Logger.WriteLine("Duel started: " + _room.Names[0] + " versus " + _room.Names[1]); _ai.OnStart(); }
private void OnSelectChain(GameServerPacket packet) { packet.ReadByte(); // player int count = packet.ReadByte(); packet.ReadByte(); // specount bool forced = packet.ReadByte() != 0; packet.ReadInt32(); // hint1 packet.ReadInt32(); // hint2 IList <ClientCard> cards = new List <ClientCard>(); IList <int> descs = new List <int>(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // card id int con = GetLocalPlayer(packet.ReadByte()); int loc = packet.ReadByte(); int seq = packet.ReadByte(); int sseq = 0; //packet.ReadByte(); int desc = packet.ReadInt32(); cards.Add(_duel.GetCard(con, loc, seq, sseq)); descs.Add(desc); } if (cards.Count == 0) { Connection.Send(CtosMessage.Response, -1); return; } if (cards.Count == 1 && forced) { Connection.Send(CtosMessage.Response, 0); return; } Connection.Send(CtosMessage.Response, _ai.OnSelectChain(cards, descs, forced)); }
private void OnPlayerChange(GameServerPacket packet) { int change = packet.ReadByte(); int pos = (change >> 4) & 0xF; int state = change & 0xF; //TODO tag if (pos > 3) { return; } if (state < 8) { string oldname = _room.Names[pos]; _room.Names[pos] = null; _room.Names[state] = oldname; _room.IsReady[pos] = false; _room.IsReady[state] = false; } else if (state == (int)PlayerChange.Ready) { _room.IsReady[pos] = true; } else if (state == (int)PlayerChange.NotReady) { _room.IsReady[pos] = false; } else if (state == (int)PlayerChange.Leave || state == (int)PlayerChange.Observe) { _room.IsReady[pos] = false; _room.Names[pos] = null; } if (_room.IsHost && _room.IsReady[0] && _room.IsReady[1]) { Connection.Send(CtosMessage.HsStart); } }