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 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 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 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 OnSelectYesNo(GameServerPacket packet) { packet.ReadByte(); // player int reply = _ai.OnSelectYesNo(packet.ReadInt32()) ? (1) : (0); 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 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 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 OnSelectBattleCmd(GameServerPacket packet) { packet.ReadByte(); // player _duel.BattlePhase = new BattlePhase(); BattlePhase battle = _duel.BattlePhase; int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // card id int con = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); int desc = packet.ReadInt32(); ClientCard card = _duel.GetCard(con, loc, seq); if (card != null) { card.ActionIndex[0] = i; battle.ActivableCards.Add(card); battle.ActivableDescs.Add(desc); } } count = packet.ReadByte(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // card id int con = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); packet.ReadByte(); // diratt ClientCard card = _duel.GetCard(con, loc, seq); if (card != null) { card.ActionIndex[1] = i; battle.AttackableCards.Add(_duel.GetCard(con, loc, seq)); } } battle.CanMainPhaseTwo = packet.ReadByte() != 0; battle.CanEndPhase = packet.ReadByte() != 0; Connection.Send(CtosMessage.Response, _ai.OnSelectBattleCmd(battle).ToValue()); }
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 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 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 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 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 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 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 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 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 OnSelectIdleCmd(GameServerPacket packet) { packet.ReadByte(); // player _duel.MainPhase = new MainPhase(); MainPhase main = _duel.MainPhase; int count; for (int k = 0; k < 5; k++) { count = packet.ReadByte(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // card id int con = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); ClientCard card = _duel.GetCard(con, loc, seq); if (card == null) { continue; } card.ActionIndex[k] = i; switch (k) { case 0: main.SummonableCards.Add(card); break; case 1: main.SpecialSummonableCards.Add(card); break; case 2: main.ReposableCards.Add(card); break; case 3: main.MonsterSetableCards.Add(card); break; case 4: main.SpellSetableCards.Add(card); break; } } } count = packet.ReadByte(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // card id int con = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); int desc = packet.ReadInt32(); ClientCard card = _duel.GetCard(con, loc, seq); if (card == null) { continue; } card.ActionIndex[5] = i; if (card.ActionActivateIndex.ContainsKey(desc)) { card.ActionActivateIndex.Remove(desc); } card.ActionActivateIndex.Add(desc, i); main.ActivableCards.Add(card); main.ActivableDescs.Add(desc); } main.CanBattlePhase = packet.ReadByte() != 0; main.CanEndPhase = packet.ReadByte() != 0; packet.ReadByte(); // CanShuffle Connection.Send(CtosMessage.Response, _ai.OnSelectIdleCmd(main).ToValue()); }
private void OnRecover(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); m_duel.LifePoints[player] += packet.ReadInt32(); }
private void InternalOnSelectCard(GameServerPacket packet, Func <IList <ClientCard>, int, int, bool, IList <ClientCard> > func) { packet.ReadByte(); // player bool cancelable = packet.ReadByte() != 0; 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 id = packet.ReadInt32(); int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); packet.ReadByte(); // pos ClientCard card; if (((int)loc & (int)CardLocation.Overlay) != 0) { card = new ClientCard(id, CardLocation.Overlay); } else { card = _duel.GetCard(player, loc, seq); } if (card == null) { continue; } if (card.Id == 0) { card.SetId(id); } cards.Add(card); } IList <ClientCard> selected = func(cards, min, max, cancelable); if (selected.Count == 0 && cancelable) { Connection.Send(CtosMessage.Response, -1); return; } 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); }
public void Update(GameServerPacket packet, Duel duel) { int flag = packet.ReadInt32(); if ((flag & (int)Query.Code) != 0) { SetId(packet.ReadInt32()); } if ((flag & (int)Query.Position) != 0) { Controller = duel.GetLocalPlayer(packet.ReadByte()); packet.ReadByte(); packet.ReadByte(); Position = packet.ReadByte(); } if ((flag & (int)Query.Alias) != 0) { Alias = packet.ReadInt32(); } if ((flag & (int)Query.Type) != 0) { Type = packet.ReadInt32(); } if ((flag & (int)Query.Level) != 0) { Level = packet.ReadInt32(); } if ((flag & (int)Query.Rank) != 0) { Rank = packet.ReadInt32(); } if ((flag & (int)Query.Attribute) != 0) { Attribute = packet.ReadInt32(); } if ((flag & (int)Query.Race) != 0) { Race = packet.ReadInt32(); } if ((flag & (int)Query.Attack) != 0) { Attack = packet.ReadInt32(); } if ((flag & (int)Query.Defence) != 0) { Defense = packet.ReadInt32(); } if ((flag & (int)Query.BaseAttack) != 0) { BaseAttack = packet.ReadInt32(); } if ((flag & (int)Query.BaseDefence) != 0) { BaseDefense = packet.ReadInt32(); } if ((flag & (int)Query.Reason) != 0) { packet.ReadInt32(); } if ((flag & (int)Query.ReasonCard) != 0) { packet.ReadInt32(); // Int8 * 4 } if ((flag & (int)Query.EquipCard) != 0) { packet.ReadInt32(); // Int8 * 4 } if ((flag & (int)Query.TargetCard) != 0) { int count = packet.ReadInt32(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // Int8 * 4 } } if ((flag & (int)Query.OverlayCard) != 0) { Overlays.Clear(); int count = packet.ReadInt32(); for (int i = 0; i < count; ++i) { Overlays.Add(packet.ReadInt32()); } } if ((flag & (int)Query.Counters) != 0) { int count = packet.ReadInt32(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // Int16 * 2 } } if ((flag & (int)Query.Owner) != 0) { Owner = duel.GetLocalPlayer(packet.ReadInt32()); } if ((flag & (int)Query.IsDisabled) != 0) { packet.ReadInt32(); } if ((flag & (int)Query.IsPublic) != 0) { packet.ReadInt32(); } if ((flag & (int)Query.LScale) != 0) { packet.ReadInt32(); } if ((flag & (int)Query.RScale) != 0) { packet.ReadInt32(); } }
private void OnSelectPlace(GameServerPacket packet) { packet.ReadByte(); // player packet.ReadByte(); // min int field = ~packet.ReadInt32(); byte[] resp = new byte[3]; bool pendulumZone = false; int filter; if ((field & 0x1f) != 0) { resp[0] = (byte)GetLocalPlayer(0); resp[1] = 0x4; filter = field & 0x1f; } else if ((field & 0x1f00) != 0) { resp[0] = (byte)GetLocalPlayer(0); resp[1] = 0x8; filter = (field >> 8) & 0x1f; } else if ((field & 0xc000) != 0) { resp[0] = (byte)GetLocalPlayer(0); resp[1] = 0x8; filter = (field >> 14) & 0x3; pendulumZone = true; } else if ((field & 0x1f0000) != 0) { resp[0] = (byte)GetLocalPlayer(1); resp[1] = 0x4; filter = (field >> 16) & 0x1f; } else if ((field & 0x1f000000) != 0) { resp[0] = (byte)GetLocalPlayer(1); resp[1] = 0x8; filter = (field >> 24) & 0x1f; } else { resp[0] = (byte)GetLocalPlayer(1); resp[1] = 0x8; filter = (field >> 30) & 0x3; pendulumZone = true; } if (!pendulumZone) { if ((filter & 0x4) != 0) { resp[2] = 2; } else if ((filter & 0x2) != 0) { resp[2] = 1; } else if ((filter & 0x8) != 0) { resp[2] = 3; } else if ((filter & 0x1) != 0) { resp[2] = 0; } else if ((filter & 0x10) != 0) { resp[2] = 4; } } else { if ((filter & 0x1) != 0) { resp[2] = 6; } if ((filter & 0x2) != 0) { resp[2] = 7; } } GameClientPacket reply = new GameClientPacket(CtosMessage.Response); reply.Write(resp); Connection.Send(reply); }
private void OnLpUpdate(GameServerPacket packet) { int player = GetLocalPlayer(packet.ReadByte()); _duel.LifePoints[player] = packet.ReadInt32(); }